| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.LocNormal; |
| | | import com.zy.asrs.entity.WaitPakin; |
| | | import com.zy.asrs.entity.WaitPakinLog; |
| | | import com.zy.asrs.mapper.LocNormalMapper; |
| | | import com.zy.asrs.mapper.OutStockMapper; |
| | | import com.zy.asrs.service.LocNormalService; |
| | | import com.zy.asrs.service.WaitPakinLogService; |
| | | import com.zy.asrs.service.WaitPakinService; |
| | | import com.zy.common.service.erp.ErpSqlServer; |
| | | import com.zy.common.service.erp.entity.CPICMO; |
| | | import com.zy.common.service.erp.entity.OutStockBillEntry; |
| | |
| | | ErpSqlServer erpSqlServer; |
| | | @Autowired |
| | | OutStockMapper outStockMapper; |
| | | @Autowired |
| | | LocNormalService locNormalService; |
| | | @Autowired |
| | | WaitPakinService waitPakinService; |
| | | @Autowired |
| | | WaitPakinLogService waitPakinLogService; |
| | | |
| | | @Override |
| | | public List<LocNormal> getLocNormalData() { |
| | |
| | | // 平仓入库后更新中间表数据,Fflag_finish改为1,表示平仓入库成功 |
| | | if (list.size() > 0) { |
| | | for (Integer i = 0; i < list.size(); i++) { |
| | | List<LocNormal> addList = new ArrayList<>(); |
| | | List<LocNormal> updateList = new ArrayList<>(); |
| | | if (!Cools.isEmpty(list.get(i).getSupplier())) { // 存在入库单号的才进行erp更新 |
| | | String sqlSelect = "select * from CPICMO where 1=1 and Fnumber = ''{0}'' and FBillNo = ''{1}''"; |
| | | sqlSelect = MessageFormat.format(sqlSelect, list.get(i).getMatnr(), list.get(i).getSupplier()); |
| | | List<CPICMO> CPICMOList = erpSqlServer.select(sqlSelect,CPICMO.class); |
| | | if (CPICMOList.size() > 0) { // 说明erp有对应的入库单 |
| | | String sql = "update CPICMO set FAuxCommitQty = (FAuxCommitQty + {0,number,#}) where 1=1 and Fnumber = ''{1}'' and FBillNo = ''{2}''"; |
| | | sql = MessageFormat.format(sql, list.get(i).getAnfme(), list.get(i).getMatnr(), list.get(i).getSupplier()); |
| | | if (erpSqlServer.update(sql) > 0) { |
| | | sql = "select * from CPICMO where 1=1 and Fnumber = ''{0}'' and FBillNo = ''{1}''"; |
| | | sql = MessageFormat.format(sql, list.get(i).getMatnr(), list.get(i).getSupplier()); |
| | | List<CPICMO> select = erpSqlServer.select(sql, CPICMO.class); |
| | | CPICMO cpicmo = select.get(0); |
| | | boolean complete = false; |
| | | if (cpicmo.getFQty() > 0) { |
| | | if (Double.doubleToLongBits(cpicmo.getFAuxCommitQty()) == Double.doubleToLongBits(cpicmo.getFQty())) { |
| | | complete = true; |
| | | // 判断原先平仓是否存在有货,如果有货数量进行累加 |
| | | LocNormal oldLocList = locNormalService.selectOne(new EntityWrapper<LocNormal>().eq("supplier", list.get(i).getSupplier()).and().eq("state", "1").eq("warehouse", list.get(i).getWarehouse())); |
| | | if (!Cools.isEmpty(oldLocList)) { |
| | | // erp更新 |
| | | updateCPICMO(list.get(i)); |
| | | Double updateAnfme = new Double(list.get(i).getAnfme().doubleValue()); |
| | | // 平仓入库(更新)逻辑 |
| | | list.get(i).setAnfme(oldLocList.getAnfme().add(list.get(i).getAnfme())); |
| | | updateList.add(list.get(i)); |
| | | if (baseMapper.pdaLocNormalUpdate(updateList) > 0) { |
| | | // cust_wait_pakin转cust_wait_pakin_log,并更新数量 |
| | | custWaitPakinToLog(list.get(i), updateAnfme); |
| | | } |
| | | } else { |
| | | if (Double.doubleToLongBits(cpicmo.getFAuxCommitQty()) == Double.doubleToLongBits(cpicmo.getFAuxQty())) { |
| | | complete = true; |
| | | // erp更新 |
| | | updateCPICMO(list.get(i)); |
| | | // 平仓入库逻辑 |
| | | addList.add(list.get(i)); |
| | | if (baseMapper.pdaLocNormalIn(addList) > 0) { |
| | | // cust_wait_pakin转cust_wait_pakin_log,并更新数量 |
| | | custWaitPakinToLog(list.get(i), list.get(i).getAnfme().doubleValue()); |
| | | } |
| | | } |
| | | if (complete) { |
| | | if (!completeCPakIn(list.get(i).getSupplier(), list.get(i).getMatnr())) { |
| | | log.error("{}平仓入库单标记完成失败", list.get(i).getSupplier()); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | throw new CoolException("ERP查询不到对应通知单"); |
| | | } |
| | | } else { |
| | | throw new CoolException("通知单号不可为空"); |
| | | } |
| | | } |
| | | // 平仓入库逻辑 |
| | | baseMapper.locNormalIn(list); |
| | | } |
| | | } |
| | | |
| | |
| | | // 平仓入库后更新中间表数据,Fflag_finish改为1,表示平仓入库成功 |
| | | if (list.size() > 0) { |
| | | for (Integer i = 0; i < list.size(); i++) { |
| | | List<LocNormal> addList = new ArrayList<>(); |
| | | List<LocNormal> updateList = new ArrayList<>(); |
| | | if (!Cools.isEmpty(list.get(i).getSupplier())) { // 存在入库单号的才进行erp更新 |
| | | // 判断原先平仓是否存在有货,如果有货数量进行累加 |
| | | LocNormal oldLocList = locNormalService.selectOne(new EntityWrapper<LocNormal>().eq("supplier", list.get(i).getSupplier()).and().eq("state", "1").and().eq("warehouse", list.get(i).getWarehouse())); |
| | | if (!Cools.isEmpty(oldLocList)) { |
| | | // erp更新 |
| | | updateCPICMO(list.get(i)); |
| | | Double updateAnfme = new Double(list.get(i).getAnfme().doubleValue()); |
| | | // 平仓入库(更新逻辑) |
| | | list.get(i).setAnfme(oldLocList.getAnfme().add(list.get(i).getAnfme())); |
| | | updateList.add(list.get(i)); |
| | | if (baseMapper.pdaLocNormalUpdate(updateList) > 0) { |
| | | // cust_wait_pakin转cust_wait_pakin_log,并更新数量 |
| | | custWaitPakinToLog(list.get(i), updateAnfme); |
| | | } |
| | | } else { |
| | | // erp更新 |
| | | updateCPICMO(list.get(i)); |
| | | // 平仓入库逻辑 |
| | | addList.add(list.get(i)); |
| | | if (baseMapper.pdaLocNormalIn(addList) > 0){ |
| | | // cust_wait_pakin转cust_wait_pakin_log,并更新数量 |
| | | custWaitPakinToLog(list.get(i), list.get(i).getAnfme().doubleValue()); |
| | | } |
| | | } |
| | | } else { |
| | | throw new CoolException("通知单号不可为空"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | /* cust_wait_pakin转cust_wait_pakin_log,并更新数量 */ |
| | | private boolean custWaitPakinToLog(LocNormal list, Double updateAnfme) { |
| | | WaitPakin waitPakin = waitPakinService.selectOne(new EntityWrapper<WaitPakin>().eq("supplier", list.getSupplier()).and().eq("matnr", list.getMatnr())); |
| | | WaitPakinLog waitPakinLog = new WaitPakinLog(); |
| | | waitPakinLog.setAnfme(updateAnfme); |
| | | waitPakinLog.setMatnr(waitPakin.getMatnr()); |
| | | waitPakinLog.setMaktx(waitPakin.getMaktx()); |
| | | waitPakinLog.setLgnum(waitPakin.getLgnum()); |
| | | waitPakinLog.setType(waitPakin.getType()); |
| | | waitPakinLog.setMnemonic(waitPakin.getMnemonic()); |
| | | waitPakinLog.setSupplier(waitPakin.getSupplier()); |
| | | waitPakinLog.setWarehouse(waitPakin.getWarehouse()); |
| | | waitPakinLog.setBrand(waitPakin.getBrand()); |
| | | waitPakinLog.setAltme(waitPakin.getAltme()); |
| | | waitPakinLog.setZpallet(waitPakin.getZpallet()); |
| | | waitPakinLog.setBname(waitPakin.getBname()); |
| | | waitPakinLog.setLocNo(waitPakin.getLocNo()); |
| | | waitPakinLog.setStatus(waitPakin.getStatus()); |
| | | waitPakinLog.setIoStatus(waitPakin.getIoStatus()); |
| | | waitPakinLog.setMemo(waitPakin.getMemo()); |
| | | waitPakinLog.setModiTime(waitPakin.getModiTime()); |
| | | waitPakinLog.setModiUser(waitPakin.getModiUser()); |
| | | waitPakinLog.setAppeTime(waitPakin.getAppeTime()); |
| | | waitPakinLog.setAppeUser(waitPakin.getAppeUser()); |
| | | // 转入库通知历史档 |
| | | waitPakinLogService.insert(waitPakinLog); |
| | | // 修改入库同志档物料数量 |
| | | Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>(); |
| | | wrapper.eq("supplier", list.getSupplier()) |
| | | .eq("matnr", list.getMatnr()) |
| | | .isNull("zpallet"); |
| | | WaitPakin pakin = new WaitPakin(); |
| | | pakin.setAnfme(waitPakin.getAnfme() - updateAnfme); |
| | | waitPakinService.update(pakin, wrapper); |
| | | return true; |
| | | } |
| | | |
| | | /* 更新erp入库表 */ |
| | | private boolean updateCPICMO(LocNormal list) { |
| | | String sqlSelect = "select * from CPICMO where 1=1 and Fnumber = ''{0}'' and FBillNo = ''{1}''"; |
| | | sqlSelect = MessageFormat.format(sqlSelect, list.get(i).getMatnr(), list.get(i).getSupplier()); |
| | | sqlSelect = MessageFormat.format(sqlSelect, list.getMatnr(), list.getSupplier()); |
| | | List<CPICMO> CPICMOList = erpSqlServer.select(sqlSelect,CPICMO.class); |
| | | if (CPICMOList.size() > 0) { // 说明erp有对应的入库单 |
| | | String sql = "update CPICMO set FAuxCommitQty = (FAuxCommitQty + {0,number,#}) where 1=1 and Fnumber = ''{1}'' and FBillNo = ''{2}''"; |
| | | sql = MessageFormat.format(sql, list.get(i).getAnfme(), list.get(i).getMatnr(), list.get(i).getSupplier()); |
| | | sql = MessageFormat.format(sql, list.getAnfme(), list.getMatnr(), list.getSupplier()); |
| | | if (erpSqlServer.update(sql) > 0) { |
| | | sql = "select * from CPICMO where 1=1 and Fnumber = ''{0}'' and FBillNo = ''{1}''"; |
| | | sql = MessageFormat.format(sql, list.get(i).getMatnr(), list.get(i).getSupplier()); |
| | | sql = MessageFormat.format(sql, list.getMatnr(), list.getSupplier()); |
| | | List<CPICMO> select = erpSqlServer.select(sql, CPICMO.class); |
| | | CPICMO cpicmo = select.get(0); |
| | | boolean complete = false; |
| | |
| | | } |
| | | } |
| | | if (complete) { |
| | | if (!completeCPakIn(list.get(i).getSupplier(), list.get(i).getMatnr())) { |
| | | log.error("{}平仓入库单标记完成失败", list.get(i).getSupplier()); |
| | | if (!completeCPakIn(list.getSupplier(), list.getMatnr())) { |
| | | log.error("{}平仓入库单标记完成失败", list.getSupplier()); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | throw new CoolException("ERP查询不到对应通知单"); |
| | | } |
| | | } else { |
| | | throw new CoolException("通知单号不可为空"); |
| | | } |
| | | } |
| | | // 平仓入库逻辑 |
| | | baseMapper.pdaLocNormalIn(list); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Override |