#
tqs
2023-12-05 a0b733a8b19b1db43395a96408098596ac3d2a86
src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java
@@ -17,6 +17,7 @@
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.ErpR;
import zy.cloud.wms.common.service.erp.ErpService;
import zy.cloud.wms.common.utils.VersionUtils;
import zy.cloud.wms.manager.entity.*;
@@ -61,13 +62,19 @@
    private ErpService erpService;
    @Autowired
    private AsrsService asrsService;
    @Autowired
    private PakinService pakinService;
    @Override
    @Transactional
    public R stockPakin(PakinParam param, Long userId) {
        Node node = nodeService.selectByUuid(param.getNodeId());
        if (node == null) {
            node = nodeService.selectById(param.getNodeId());
            try {
                node = nodeService.selectById(param.getNodeId());
            } catch (Exception e) {
                return R.error("货位不存在");
            }
        }
        if (node == null) {
            return R.error("货位不存在");
@@ -75,11 +82,56 @@
        if (Cools.isEmpty(param.getMats())) {
            return R.error("入库物料不能为空");
        }
        Integer docId = Optional.ofNullable(param.getDocType()).orElse(34);
        String docNum = String.valueOf(snowflakeIdWorker.nextId());
        switch (docId) {
            case 34:    // 采购单
                docNum = "PU-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
                break;
            case 45:    // 销售退货单
                docNum = "SR-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
                break;
            default:
                break;
        }
        Date now = new Date();
        for (MatnrDto dto : param.getMats()) {
            Mat mat = matService.selectByMatnr(dto.getMatnr());
            if (mat == null) {
                throw new CoolException("物料数据错误,请联系管理员");
            }
            // 保存入库记录
            Pakin pakin = new Pakin(
                    "I" + String.valueOf(snowflakeIdWorker.nextId()),    // 任务号[非空]
                    null,    // 工作状态
                    null,    // 托盘号
                    dto.getCount(),    // 入库数量
                    node.getId(),    // 关联货位[非空]
                    node.getUuid(),    // 货位[非空]
                    mat.getMatnr(),    // 商品编码[非空]
                    null,    // 商品名称
                    null,    // 名称
                    null,    // 尺码
                    null,    // 型号
                    null,    // 批号
                    null,    // 单位
                    null,    // SKC
                    null,    // 单据类型
                    null,    // 单据编号
                    null,    // 客户名称
                    null,    // 品项数
                    null,    // 数量
                    null,    // 重量
                    1,    // 状态
                    userId,    // 添加人员
                    now,    // 添加时间
                    userId,    // 修改人员
                    now,    // 修改时间
                    null    // 备注
            );
            VersionUtils.setPakin(pakin, mat);
            if (!pakinService.insert(pakin)) {
                throw new CoolException("保存入库记录失败");
            }
            LocDetl locDetl = locDetlService.getLocDetl(node.getId(), dto.getMatnr());
            if (locDetl == null) {
@@ -90,8 +142,8 @@
                locDetl.setZpallet("");
                locDetl.setAnfme(dto.getCount());
                VersionUtils.setLocDetl(locDetl, mat);
//                locDetl.setDocId(param.getDocType().longValue());
//                locDetl.setDocNum(docNum);
                locDetl.setDocId(docId.longValue());
                locDetl.setDocNum(docNum);
                locDetl.setStatus(1);
                locDetl.setCreateBy(userId);
                locDetl.setCreateTime(now);
@@ -116,23 +168,68 @@
            billDto.setQty(dto.getCount());
            dtos.add(billDto);
        }
        Integer docId = Optional.ofNullable(param.getDocType()).orElse(34);
        String docNum = String.valueOf(snowflakeIdWorker.nextId());
        switch (docId) {
            case 34:    // 采购单
                docNum = "PU-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
                break;
            case 45:    // 销售退货单
                docNum = "SR-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
                break;
            default:
                break;
        }
        if (!erpService.uploadBill(dtos, docId, docNum)) {
            throw new CoolException("无法上报至erp");
        ErpR erpR = erpService.uploadBill(dtos, docId, docNum);
        if (!erpR.getSuccess()) {
            throw new CoolException("无法上报至erp:"+erpR.getMsg());
        }
        return R.ok("入库成功");
    }
    @Override
    @Transactional
    public R stockPakout(PakoutParam param, Long userId) {
        Mat mat = matService.selectByMatnr(param.getMatnr());
        Node node = nodeService.selectByUuid(param.getNodeUuid());
        LocDetl locDetl = locDetlService.getLocDetl(node.getId(), mat.getMatnr());
        if (locDetl == null || locDetl.getAnfme() < param.getCount()) {
            return R.error(mat.getMaktx() + "库存不足");
        }
        Pakout pakout = new Pakout(
                String.valueOf(snowflakeIdWorker.nextId()),    // 任务号[非空]
                3L,    // 工作状态
                null,    // 托盘号
                param.getCount(),    // 出库数量
                node.getId(),    // 关联货位[非空]
                node.getUuid(),    // 货位[非空]
                mat.getMatnr(),    // 商品编码[非空]
                null,    // 商品名称
                null,    // 名称
                null,    // 尺码
                null,    // 型号
                null,    // 批号
                null,    // 单位
                null,    // SKC
                null,    // 单据类型
                null,    // 单据编号
                null,    // 客户名称
                null,    // 品项数
                null,    // 数量
                null,    // 重量
                1,    // 状态
                userId,    // 添加人员
                new Date(),    // 添加时间
                userId,    // 修改人员
                new Date(),    // 修改时间
                null    // 备注
        );
        VersionUtils.setPakout(pakout, mat);
        // 保存出库通知单
        if (!pakoutService.insert(pakout)) {
            throw new CoolException("保存出库通知单失败");
        }
        if (param.getCount()>=locDetl.getAnfme()) {
            // 删除库存明细
            if (!locDetlService.removeStock(node.getId(), mat.getMatnr())) {
                throw new CoolException("删除库存明细失败");
            }
        } else {
            // 修改库存明细数量
            if (!locDetlService.reduceStock(node.getId(), mat.getMatnr(), param.getCount())) {
                throw new CoolException("修改库存明细数量失败");
            }
        }
        return R.ok();
    }
    @Override
@@ -204,8 +301,9 @@
            billDto.setQty(comb.getAnfme());
            dtos.add(billDto);
        }
        if (!erpService.uploadBill(dtos, param.getDocType(), docNum)) {
            throw new CoolException("无法上报至erp");
        ErpR erpR = erpService.uploadBill(dtos, param.getDocType(), docNum);
        if (!erpR.getSuccess()) {
            throw new CoolException("无法上报至erp:"+erpR.getMsg());
        }
        return R.ok();
    }
@@ -261,6 +359,7 @@
        for (Pakout pakout : pakouts) {
            total = pakout.getAnfme() + total;
        }
        StoPrintVo vo = new StoPrintVo();
        vo.setDocNum(param.getOrderNo());
        vo.setList(pakouts);
@@ -462,6 +561,15 @@
        Date now = new Date();
        Item item = itemService.selectByName(param.getItem());
        Cstmr cstmr = cstmrService.selectByName(param.getCstmr());
        // 采购退货单检验
        if (param.getDocType() == 6) {
            for (MatnrDto dto : param.getList()) {
                if (locDetlService.getStockByDocType34(dto.getMatnr()) < dto.getCount()) {
                    return R.error(dto.getMatnr() + "采购量不足以生成退货单!");
                }
            }
        }
        // 新增订单表头
        order = new Order(
                String.valueOf(snowflakeIdWorker.nextId()),    // 编号[非空]
@@ -551,32 +659,61 @@
            }
        }
        // 直接增加库存
        LocDetl locDetl = locDetlService.getLocDetl(param.getNode_id(), param.getMatnr());
        if (locDetl == null) {
            // 更新货位库存明细
            locDetl = new LocDetl();
            locDetl.setLocNo(node.getName());
            locDetl.setNodeId(node.getId());
            locDetl.setAnfme(anfme);
            VersionUtils.setLocDetl(locDetl, mat);
            locDetl.setStatus(1);
            locDetl.setCreateBy(userId);
            locDetl.setCreateTime(new Date());
            locDetl.setUpdateBy(userId);
            locDetl.setUpdateTime(new Date());
            boolean insert = locDetlService.insert(locDetl);
            if (!insert) {
                throw new CoolException("新增库存明细档失败");
            }
        } else {
            if (!locDetlService.incrementStock(node.getId(), param.getMatnr(), anfme)) {
                throw new CoolException("新增库存明细档失败");
//        LocDetl locDetl = locDetlService.getLocDetl(param.getNode_id(), param.getMatnr());
//        if (locDetl == null) {
//            // 更新货位库存明细
//            locDetl = new LocDetl();
//            locDetl.setLocNo(node.getName());
//            locDetl.setNodeId(node.getId());
//            locDetl.setAnfme(anfme);
//            VersionUtils.setLocDetl(locDetl, mat);
//            locDetl.setStatus(1);
//            locDetl.setCreateBy(userId);
//            locDetl.setCreateTime(new Date());
//            locDetl.setUpdateBy(userId);
//            locDetl.setUpdateTime(new Date());
//            boolean insert = locDetlService.insert(locDetl);
//            if (!insert) {
//                throw new CoolException("新增库存明细档失败");
//            }
//        } else {
//            if (!locDetlService.incrementStock(node.getId(), param.getMatnr(), anfme)) {
//                throw new CoolException("新增库存明细档失败");
//            }
//        }
        return R.ok("补仓成功,等待立库调拨");
    }
    @Override
    public R asrsStockTransferLocMode(AsrsTransferParam param, Long userId) {
        if (Cools.isEmpty(param.getNode_id(), param.getMatnr(), param.getSafe_qua(), param.getAmount())) {
            return R.error("数量错误");
        }
        Node node = nodeService.selectById(param.getNode_id());
        Mat mat = matService.selectByMatnr(param.getMatnr());
        if (node == null || mat == null) {
            return R.error();
        }
        double anfme = Arith.subtract(2, param.getSafe_qua(), param.getAmount());
        List<StockTransferParam> params = new ArrayList<>();
        StockTransferParam transferParam = new StockTransferParam();
        transferParam.setMatnr(param.getMatnr());
        transferParam.setAnfme(anfme);
        transferParam.setAllotNo(param.getNode_id()+ "_" +param.getMatnr());
        transferParam.setLocNo(param.getLocNo());
        params.add(transferParam);
        Result1 result = asrsService.stockTransferLocMode(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
    public R stockCheck(StoCheckParam param, Long userId) {
@@ -699,7 +836,7 @@
    @Transactional
    public R stockCheckAuditing(Long checkId, Long userId) {
        Check check = checkService.selectById(checkId);
        if (null == check) {
        if (null == check || check.getStatus() != 1) {
            return R.error("盘点记录已失效");
        }
        Date now = new Date();
@@ -751,9 +888,11 @@
        String docNum = null;
        Long docId = null;
        switch (check.getSettle()) {
            case 1:    // 盘盈
                docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
                docId = 14L; // 报溢单
            case 1:    // 盘盈 todo 前期用采购单上报
//                docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
//                docId = 14L; // 报溢单
                docNum = "PU-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
                docId = 34L; // 采购单
                break;
            case 2:    // 盘亏
                docNum = "CD-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
@@ -777,8 +916,9 @@
        billDto.setMatnr(check.getMatnr());
        billDto.setQty(Math.abs(check.getDiffQty()));
        dtos.add(billDto);
        if (!erpService.uploadBill(dtos, docId.intValue(), docNum)) {
            throw new CoolException("无法上报至erp");
        ErpR erpR = erpService.uploadBill(dtos, docId.intValue(), docNum);
        if (!erpR.getSuccess()) {
            throw new CoolException("无法上报至erp:"+erpR.getMsg());
        }
        return R.ok();
    }