| | |
| | | import com.zy.asrs.service.WorkService; |
| | | import com.zy.asrs.utils.VersionUtils; |
| | | import com.zy.common.service.erp.ErpService; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.zy.common.service.erp.entity.OutStockBill; |
| | | import com.zy.common.service.erp.entity.OutStockBillEntry; |
| | | import com.zy.common.web.BaseController; |
| | |
| | | public R outStockQueryList(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "10")Integer limit, |
| | | @RequestParam Map<String, Object> param){ |
| | | return R.ok(outStockService.queryOutStock(toPage(curr, limit, param, OutStockBillEntry.class))); |
| | | Page<OutStockBillEntry> page = outStockService.queryOutStock(toPage(curr, limit, param, OutStockBillEntry.class)); |
| | | log.info("outStock/query/list 查询条件 FBillNo={}, FSourceBillNo={}, curr={}, limit={}, 结果 total={}, 本页条数={}(数据来源:WMS库xtyasrs,条件:Fflag_finish!=1 且 FQty>FAmount)", |
| | | param.get("FBillNo"), param.get("FSourceBillNo"), curr, limit, page.getTotal(), page.getRecords() != null ? page.getRecords().size() : 0); |
| | | return R.ok(page); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.dao.DeadlockLoserDataAccessException; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | return Math.abs(d1 - d2) < 0.0001; |
| | | } |
| | | |
| | | /** 死锁重试次数 */ |
| | | private static final int CUST_WAIT_PAKIN_DEADLOCK_RETRIES = 2; |
| | | /** 死锁重试间隔(毫秒) */ |
| | | private static final int CUST_WAIT_PAKIN_RETRY_DELAY_MS = 80; |
| | | |
| | | /** |
| | | * 销售订单数量更新后,顺带更新 cust_wait_pakin 的 anfme/nqty(mobile/bill/query 的 count 取自 anfme)。 |
| | | * 仅按 matnr+mnemonic 更新,不插入;无匹配或异常不影响主流程。 |
| | | * 发生死锁时自动重试,减少并发更新导致的死锁牺牲。 |
| | | */ |
| | | private void updateWaitPakinQuantity(Map<String, Object> data) { |
| | | try { |
| | | String invCode = data.get("invCode") != null ? String.valueOf(data.get("invCode")).trim() : null; |
| | | String orderCode = data.get("orderCode") != null ? String.valueOf(data.get("orderCode")).trim() : null; |
| | | if (Cools.isEmpty(invCode) || Cools.isEmpty(orderCode)) { |
| | |
| | | updateEntity.setNqty(productQty); |
| | | updateEntity.setModiTime(new Date()); |
| | | Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>().eq("matnr", invCode).eq("mnemonic", orderCode); |
| | | |
| | | for (int attempt = 0; attempt <= CUST_WAIT_PAKIN_DEADLOCK_RETRIES; attempt++) { |
| | | try { |
| | | boolean updated = waitPakinService.update(updateEntity, wrapper); |
| | | if (updated) { |
| | | logger.info("cust_wait_pakin 更新成功:订单号={},物料编码={},数量={}", orderCode, invCode, productQty); |
| | | } else { |
| | | logger.warn("cust_wait_pakin 更新未影响行(可能无匹配记录):订单号={},物料编码={}", orderCode, invCode); |
| | | } |
| | | return; |
| | | } catch (Exception e) { |
| | | if (e instanceof DeadlockLoserDataAccessException || (e.getCause() != null && e.getCause().getClass().getSimpleName().contains("Deadlock"))) { |
| | | if (attempt < CUST_WAIT_PAKIN_DEADLOCK_RETRIES) { |
| | | try { |
| | | Thread.sleep(CUST_WAIT_PAKIN_RETRY_DELAY_MS); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | logger.warn("cust_wait_pakin 更新死锁,第{}次重试:订单号={},物料编码={}", attempt + 1, orderCode, invCode); |
| | | continue; |
| | | } |
| | | } |
| | | logger.error("cust_wait_pakin 更新异常:orderCode={},invCode={},error={}", data.get("orderCode"), data.get("invCode"), e.getMessage(), e); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public Page<OutStockBillEntry> queryOutStock(Page<OutStockBillEntry> page) { |
| | | page.setRecords(baseMapper.queryOutStock(page.getCondition())); |
| | | page.setTotal(baseMapper.queryOutStockCount(page.getCondition())); |
| | | Map<String, Object> cond = page.getCondition(); |
| | | page.setRecords(baseMapper.queryOutStock(cond)); |
| | | page.setTotal(baseMapper.queryOutStockCount(cond)); |
| | | if (log.isDebugEnabled()) { |
| | | log.debug("queryOutStock 条件 FBillNo={}, FSourceBillNo={}, 查询结果 total={}", cond.get("FBillNo"), cond.get("FSourceBillNo"), page.getTotal()); |
| | | } |
| | | return page; |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public List<OutStockBill> syncOutStock() { |
| | | return erpSqlServer.select("SELECT * FROM xtyasrs_dual.dbo.OutStockBill where Fflag_rw=0", OutStockBill.class); |
| | | // return erpSqlServer.select("SELECT * FROM xtyasrs_dual.dbo.OutStockBill where Fflag_rw=0", OutStockBill.class); |
| | | List<OutStockBill> list = erpSqlServer.select("SELECT * FROM xtyasrs_dual.dbo.OutStockBill where Fflag_rw=0", OutStockBill.class); |
| | | log.info("outStock同步来源:ERP库xtyasrs_dual未读出库单数={}", list != null ? list.size() : 0); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public List<OutStockBillEntry> syncOutStockDetail(Integer FInterID) { |
| | | // String sql = "SELECT * FROM xtyasrs_dual.dbo.OutStockBillEntry where FSourceBillNo!='' and FAuxCommitQty=0 and FInterID=" + FInterID; |
| | | String sql = "SELECT * FROM xtyasrs_dual.dbo.OutStockBillEntry where FAuxCommitQty=0 and FInterID=" + FInterID; |
| | | return erpSqlServer.select(sql, OutStockBillEntry.class); |
| | | List<OutStockBillEntry> list = erpSqlServer.select(sql, OutStockBillEntry.class); |
| | | log.info("outStock同步来源:ERP出库明细 FInterID={}, 条数={}", FInterID, list != null ? list.size() : 0); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Transactional |
| | | public void syncOutStock(){ |
| | | List<OutStockBill> outStockBills = erpService.syncOutStock(); |
| | | log.info("出库同步开始,ERP未读单数={}", outStockBills != null ? outStockBills.size() : 0); |
| | | if (outStockBills == null || outStockBills.isEmpty()) { |
| | | return; |
| | | } |
| | | for (Integer i = 0; i < outStockBills.size(); i++) { |
| | | OutStockBill outStockBill = outStockBills.get(i); |
| | | |
| | | //同一单号存在相同物料编码数据,该单号不予处理 |
| | | Number fnumberCount = erpService.QueryFnumberOutCount(outStockBill.getFInterID()); |
| | | if(fnumberCount.intValue() > 1){ |
| | | log.info("出库通知单存在物料相同数据[FBillNo={},FInterID={},]", outStockBill.getFBillNo(), outStockBill.getFInterID()); |
| | | log.info("出库同步跳过:同一单号存在相同物料[FBillNo={},FInterID={}],不予同步", outStockBill.getFBillNo(), outStockBill.getFInterID()); |
| | | if (!erpService.haveReadOutBill(outStockBill.getFBillNo(),outStockBill.getFInterID(),-1)) { |
| | | log.error("更新出库通知单读取状态为-1失败[FBrNo={},FInterID={}]", outStockBill.getFBrNo(),outStockBill.getFInterID()); |
| | | } |
| | |
| | | |
| | | OutStockBill main = outStockMainService.selectOne(new EntityWrapper<OutStockBill>().eq("FBillNo",outStockBill.getFBillNo()).and().eq("FInterID", outStockBill.getFInterID())); |
| | | if (null == main) { |
| | | log.info("出库同步新单:FBillNo={}, FInterID={},从ERP同步到WMS", outStockBill.getFBillNo(), outStockBill.getFInterID()); |
| | | outStockBill.setFflag_rw(1); |
| | | if (!outStockMainService.insert(outStockBill)) { |
| | | log.info("同步出库通知主表OutStockBill失败"); |
| | | log.error("出库同步失败:同步出库通知主表OutStockBill失败[FBillNo={},FInterID={}]", outStockBill.getFBillNo(), outStockBill.getFInterID()); |
| | | exceptionHandle("同步出库通知主表OutStockBill失败[FBillNo={0},FInterID={1}]",outStockBill.getFBillNo(),outStockBill.getFInterID()); |
| | | }; |
| | | List<OutStockBillEntry> outStockBillEntries = erpService.syncOutStockDetail(outStockBill.getFInterID()); |
| | | if (outStockBillEntries == null || outStockBillEntries.isEmpty()) { |
| | | log.warn("出库同步:ERP该单明细数为0,FBillNo={}, FInterID={}(可能ERP条件FAuxCommitQty=0无数据)", outStockBill.getFBillNo(), outStockBill.getFInterID()); |
| | | } |
| | | if (outStockBillEntries != null) { |
| | | for (Integer j = 0; j < outStockBillEntries.size(); j++) { |
| | | OutStockBillEntry outStockBillEntry = outStockBillEntries.get(j); |
| | | Wrapper<OutStockBillEntry> wrapper = new EntityWrapper<OutStockBillEntry>().eq("FInterID", outStockBillEntry.getFInterID()). |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | |
| | | log.debug("出库同步:WMS已存在该单,跳过同步明细 FBillNo={}, FInterID={}", outStockBill.getFBillNo(), outStockBill.getFInterID()); |
| | | } |
| | | |
| | | if (!erpService.haveReadOutBill(outStockBill.getFBillNo(),outStockBill.getFInterID(),1)) { |