#
luxiaotao1123
2021-04-22 7fd1dc4865b941ec8c6c1215fe5adecab80381d9
src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java
@@ -1,6 +1,7 @@
package zy.cloud.wms.manager.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Arith;
import com.core.common.Cools;
import com.core.common.R;
import com.core.common.SnowflakeIdWorker;
@@ -9,9 +10,14 @@
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.*;
import zy.cloud.wms.manager.entity.param.*;
@@ -51,6 +57,10 @@
    private ItemService itemService;
    @Autowired
    private CstmrService cstmrService;
    @Autowired
    private ErpService erpService;
    @Autowired
    private AsrsService asrsService;
    @Override
    @Transactional
@@ -96,6 +106,30 @@
                    throw new CoolException("新增库存明细档失败");
                }
            }
        }
        // 上报给erp
        List<BillDto> dtos = new ArrayList<>();
        for (MatnrDto dto : param.getMats()) {
            BillDto billDto = new BillDto();
            billDto.setMatnr(dto.getMatnr());
            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");
        }
        return R.ok("入库成功");
@@ -160,6 +194,18 @@
            }
        }
        // 上报给erp
        List<BillDto> dtos = new ArrayList<>();
        for (Comb comb : combs) {
            BillDto billDto = new BillDto();
            billDto.setMatnr(comb.getMatnr());
            billDto.setQty(comb.getAnfme());
            dtos.add(billDto);
        }
        if (!erpService.uploadBill(dtos, param.getDocType(), docNum)) {
            throw new CoolException("无法上报至erp");
        }
        return R.ok();
    }
@@ -475,6 +521,59 @@
    }
    @Override
    public R asrsStockTransfer(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());
        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());
            }
        }
        // 直接增加库存
        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 stockCheck(StoCheckParam param, Long userId) {
        if (Cools.isEmpty(param.getLocNo())) {
            return R.error("请选择货位");
@@ -666,6 +765,16 @@
        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();
    }