#
luxiaotao1123
2021-03-23 357de6228f120de8072c482d04bd7577e4f5db0b
src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java
@@ -9,9 +9,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zy.cloud.wms.common.model.BillDto;
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.erp.ErpService;
import zy.cloud.wms.common.utils.VersionUtils;
import zy.cloud.wms.manager.entity.*;
import zy.cloud.wms.manager.entity.param.*;
@@ -46,6 +48,8 @@
    private MatService matService;
    @Autowired
    private AsrsService asrsService;
    @Autowired
    private ErpService erpService;
    @Override
    @Transactional
@@ -59,6 +63,17 @@
            return R.error("物料不存在");
        }
        Date now = new Date();
        String docNum = String.valueOf(snowflakeIdWorker.nextId());
        switch (param.getDocType()) {
            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;
        }
        for (Comb comb : combs) {
            // 改变组托档状态
            comb.setIoStatus(4);
@@ -77,6 +92,8 @@
                locDetl.setZpallet(param.getZpallet());
                locDetl.setAnfme(comb.getAnfme());
                VersionUtils.setLocDetl(locDetl, comb);
                locDetl.setDocId(param.getDocType().longValue());
                locDetl.setDocNum(docNum);
                locDetl.setStatus(1);
                locDetl.setCreateBy(userId);
                locDetl.setCreateTime(now);
@@ -94,6 +111,19 @@
            }
        }
        // 上报给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();
    }
@@ -174,6 +204,21 @@
        // 修改单据状态
        if (!custOrderService.updateStatus(param.getNumber(), 4)) {
            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");
            }
        }
        return R.ok();
    }
@@ -317,6 +362,7 @@
                    null,    // 经手人编号[空]
                    dto.getMatnr(),    // 商品编号
                    dto.getCount(),    // 商品数量
                    dto.getCount(),    // 总数量
                    Cools.isEmpty(mat.getName())?0.0D:Double.parseDouble(mat.getName()),    // 商品单价
                    null,    // 商品备注[空]
                    1,    // 状态
@@ -332,9 +378,10 @@
    }
    @Override
    @Transactional
    public R stockTransfer(String number, Long userId) {
        List<CustOrder> custOrders = custOrderService.selectList(new EntityWrapper<CustOrder>().eq("number", number).eq("status", 1));
        boolean error = false;
        boolean asrs = false;
        List<StockTransferParam> params = new ArrayList<>();
        for (CustOrder custOrder : custOrders) {
            Double count = locDetlService.selectCountByMatnr(custOrder.getUserCode());
@@ -342,21 +389,25 @@
                count = 0.0D;
            }
            if (count < custOrder.getQty()) {
                if (!error) {
                    error = true;
                }
                if (!asrs) { asrs = true; }
                StockTransferParam param = new StockTransferParam();
                param.setMatnr(custOrder.getUserCode());
                param.setAnfme(custOrder.getQty() - count);
                params.add(param);
            }
        }
        if (error) {
            if (asrsService.stockTransfer(params)) {
                return R.ok("库存调拨成功");
            } else {
                return R.error("立库调拨失败,请联系管理员");
            }
        if (asrs) {
//            if (asrsService.stockTransfer(params)) {
//                for (StockTransferParam param : params) {
//                    // 修改销售订单待出数量
//                    if (!custOrderService.updateQty(number, param.getMatnr(), param.getAnfme())) {
//                        throw new CoolException("修改销售订单待出数量失败");
//                    }
//                }
//                return R.ok("库存调拨成功");
//            } else {
//                return R.error("立库调拨失败,请联系管理员");
//            }
        }
        return R.error("暂不缺货,不需要立库调拨");
    }