| | |
| | | package zy.cloud.wms.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.common.*; |
| | | import com.core.exception.CoolException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import zy.cloud.wms.common.config.CodeCoolException; |
| | | import zy.cloud.wms.common.model.BillDto; |
| | | import zy.cloud.wms.common.model.MatnrDto; |
| | | import zy.cloud.wms.common.model.OrderStoDto; |
| | | import zy.cloud.wms.common.service.MainService; |
| | | import zy.cloud.wms.common.service.asrs.AsrsService; |
| | | import zy.cloud.wms.common.service.asrs.entity.Result1; |
| | | import zy.cloud.wms.common.service.erp.ErpService; |
| | | import zy.cloud.wms.common.utils.VersionUtils; |
| | | import zy.cloud.wms.manager.entity.*; |
| | |
| | | private ErpService erpService; |
| | | @Autowired |
| | | private CheckService checkService; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R stockPakin(PakinParam param, Long userId) { |
| | | Node node = nodeService.selectByUuid(param.getNodeId()); |
| | | if (node == null) { |
| | | return R.error("货位不存在"); |
| | | } |
| | | if (Cools.isEmpty(param.getMats())) { |
| | | return R.error("入库物料不能为空"); |
| | | } |
| | | Date now = new Date(); |
| | | for (MatnrDto dto : param.getMats()) { |
| | | Mat mat = matService.selectByMatnr(dto.getMatnr()); |
| | | if (mat == null) { |
| | | throw new CoolException("物料数据错误,请联系管理员"); |
| | | } |
| | | LocDetl locDetl = locDetlService.getLocDetl(node.getId(), dto.getMatnr()); |
| | | if (locDetl == null) { |
| | | // 更新货位库存明细 |
| | | locDetl = new LocDetl(); |
| | | locDetl.setLocNo(node.getName()); |
| | | locDetl.setNodeId(node.getId()); |
| | | locDetl.setZpallet(""); |
| | | locDetl.setAnfme(dto.getCount()); |
| | | VersionUtils.setLocDetl(locDetl, mat); |
| | | // locDetl.setDocId(param.getDocType().longValue()); |
| | | // locDetl.setDocNum(docNum); |
| | | locDetl.setStatus(1); |
| | | locDetl.setCreateBy(userId); |
| | | locDetl.setCreateTime(now); |
| | | locDetl.setUpdateBy(userId); |
| | | locDetl.setUpdateTime(now); |
| | | boolean insert = locDetlService.insert(locDetl); |
| | | if (!insert) { |
| | | throw new CoolException("新增库存明细档失败"); |
| | | } |
| | | } else { |
| | | if (!locDetlService.incrementStock(node.getId(), dto.getMatnr(), dto.getCount())) { |
| | | throw new CoolException("新增库存明细档失败"); |
| | | } |
| | | } |
| | | } |
| | | return R.ok("入库成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | throw new CoolException("修改单据状态失败"); |
| | | } |
| | | // 采购退货单 |
| | | if (param.getNumber().startsWith("PR-")) { |
| | | List<BillDto> dtos = new ArrayList<>(); |
| | | for (Pakout pakout : pakouts) { |
| | | BillDto billDto = new BillDto(); |
| | | billDto.setMatnr(pakout.getMatnr()); |
| | | billDto.setQty(pakout.getAnfme()); |
| | | dtos.add(billDto); |
| | | } |
| | | // erp单据上传 -- 采购退货单 |
| | | if (!erpService.uploadBill(dtos, 6, pakouts.get(0).getDocNum())) { |
| | | throw new CoolException("无法上报至erp"); |
| | | // if (param.getNumber().startsWith("PR-")) { |
| | | // erp单据上传 |
| | | Long docId = pakouts.get(0).getDocId(); |
| | | if (null != docId) { |
| | | List<BillDto> dtos = new ArrayList<>(); |
| | | for (Pakout pakout : pakouts) { |
| | | BillDto billDto = new BillDto(); |
| | | billDto.setMatnr(pakout.getMatnr()); |
| | | billDto.setQty(pakout.getAnfme()); |
| | | dtos.add(billDto); |
| | | } |
| | | if (!erpService.uploadBill(dtos, docId.intValue() , pakouts.get(0).getDocNum())) { |
| | | throw new CoolException("无法上报至erp"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | // } |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | dto.getCount(), // 商品数量 |
| | | dto.getCount(), // 总数量 |
| | | Cools.isEmpty(mat.getName())?0.0D:Double.parseDouble(mat.getName()), // 商品单价 |
| | | null, // 商品明细行号 |
| | | null, // 商品备注[空] |
| | | 1, // 状态 |
| | | now, // 添加时间 |
| | |
| | | // } |
| | | } |
| | | return R.error("暂不缺货,不需要立库调拨"); |
| | | } |
| | | |
| | | @Override |
| | | public R asrsStockTransfer(AsrsTransferParam param, Long userId) { |
| | | if (Cools.isEmpty(param.getNode_id(), param.getMatnr(), param.getSafe_qua(), param.getAmount())) { |
| | | return R.error("数量错误"); |
| | | } |
| | | List<StockTransferParam> params = new ArrayList<>(); |
| | | StockTransferParam transferParam = new StockTransferParam(); |
| | | transferParam.setMatnr(param.getMatnr()); |
| | | transferParam.setAnfme(Arith.subtract(2, param.getSafe_qua(), param.getAmount())); |
| | | transferParam.setAllotNo(param.getNode_id()+ "_" +param.getMatnr()); |
| | | params.add(transferParam); |
| | | Result1 result = asrsService.stockTransfer(params); |
| | | if (result.getCode() == 500) { |
| | | if (Cools.isEmpty(result.getData())) { |
| | | throw new CoolException(result.getMsg()); |
| | | } else { |
| | | throw new CodeCoolException("20001-" + result.getData()); |
| | | } |
| | | } |
| | | return R.ok("补仓成功,等待立库调拨"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R stockCheckAuditing(Long checkId, Long userId) { |
| | | Check check = checkService.selectById(checkId); |
| | | if (null == check) { |
| | | return R.error("盘点记录已失效"); |
| | | } |
| | | Date now = new Date(); |
| | | // 1.修改库存数量 |
| | | if (check.getOriQty() != 0 && check.getCekQty() != 0) { |
| | | // 更新库存明细 |
| | | if (check.getSettle() == 1) { |
| | | if (!locDetlService.incrementStock(check.getNodeId(), check.getMatnr(), Math.abs(check.getDiffQty()))) { |
| | | throw new CoolException("修改库存明细数量失败"); |
| | | } |
| | | } else if (check.getSettle() == 2) { |
| | | if (!locDetlService.reduceStock(check.getNodeId(), check.getMatnr(), Math.abs(check.getDiffQty()))) { |
| | | throw new CoolException("修改库存明细数量失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 2.删除库存 |
| | | if (check.getOriQty() != 0 && check.getCekQty() == 0) { |
| | | if (!locDetlService.delete(new EntityWrapper<LocDetl>().eq("node_id", check.getNodeId()).eq("matnr", check.getMatnr()))) { |
| | | throw new CoolException("删除库存明细数量失败"); |
| | | } |
| | | } |
| | | |
| | | // 3.新增库存 |
| | | if (check.getOriQty() == 0 && check.getCekQty() != 0) { |
| | | Mat mat = matService.selectByMatnr(check.getMatnr()); |
| | | if (mat == null) { |
| | | throw new CoolException("商品数据异常,请联系管理员"); |
| | | } |
| | | // 更新货位库存明细 |
| | | LocDetl locDetl = new LocDetl(); |
| | | locDetl.setLocNo(check.getLocNo()); |
| | | locDetl.setNodeId(check.getNodeId()); |
| | | // locDetl.setZpallet(param.getZpallet()); |
| | | locDetl.setAnfme(check.getCekQty()); |
| | | VersionUtils.setLocDetl(locDetl, mat); |
| | | locDetl.setStatus(1); |
| | | locDetl.setCreateBy(userId); |
| | | locDetl.setCreateTime(now); |
| | | locDetl.setUpdateBy(userId); |
| | | locDetl.setUpdateTime(now); |
| | | if (!locDetlService.insert(locDetl)) { |
| | | throw new CoolException("新增库存明细失败"); |
| | | } |
| | | } |
| | | |
| | | // 修改盘点记录 |
| | | String docNum = null; |
| | | Long docId = null; |
| | | switch (check.getSettle()) { |
| | | case 1: // 盘盈 |
| | | docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); |
| | | docId = 14L; // 报溢单 |
| | | break; |
| | | case 2: // 盘亏 |
| | | docNum = "CD-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); |
| | | docId = 9L; // 报损单 |
| | | break; |
| | | default: |
| | | throw new CoolException("盘点记录盈亏情况异常"); |
| | | } |
| | | check.setStatus(2); |
| | | check.setDocId(docId); |
| | | check.setDocNum(docNum); |
| | | check.setUpdateBy(userId); |
| | | check.setUpdateTime(now); |
| | | if (!checkService.updateById(check)) { |
| | | throw new CoolException("修改盘点记录状态失败"); |
| | | } |
| | | |
| | | // 上报给erp |
| | | List<BillDto> dtos = new ArrayList<>(); |
| | | BillDto billDto = new BillDto(); |
| | | billDto.setMatnr(check.getMatnr()); |
| | | billDto.setQty(Math.abs(check.getDiffQty())); |
| | | dtos.add(billDto); |
| | | if (!erpService.uploadBill(dtos, docId.intValue(), docNum)) { |
| | | throw new CoolException("无法上报至erp"); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |