自动化立体仓库 - WMS系统
#
Junjie
3 天以前 b87fd470a866ffcf50bb5c5d55ff9b2dd11fc20c
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -1,5 +1,6 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
@@ -18,14 +19,16 @@
import com.zy.common.model.DetlDto;
import com.zy.common.model.enums.WorkNoType;
import com.zy.common.service.CommonService;
import com.zy.common.utils.Synchro;
import com.zy.common.utils.HttpHandler;
import com.zy.nc.service.NccJcQilibcBarcodeflowWmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@@ -36,6 +39,9 @@
@Slf4j
@Service
public class MobileServiceImpl implements MobileService {
    @Value("${wcs.url}")
    private String wcsUrl;
    @Autowired
    private MatService matService;
@@ -77,6 +83,8 @@
    private ManLocDetlService manLocDetlService;
    @Autowired
    private ManLocDetlMapper manLocDetlMapper;
    @Autowired
    private ReportToThirdService reportToThirdService;
    @Autowired
    private InventoryCheckOrderService inventoryCheckOrderService;
@@ -596,10 +604,12 @@
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
                detlDto.setWeight(elem.getWeight());
                detlDto.setCstateid(elem.getCstateid());
                if (DetlDto.has(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                    assert one != null;
                    one.setAnfme(one.getAnfme() + detlDto.getAnfme());
                    one.setWeight(one.getWeight() + detlDto.getWeight());
                } else {
                    detlDtos.add(detlDto);
                }
@@ -629,9 +639,8 @@
                waitPakin.setStandby1(detlDto.getStandby1());
                waitPakin.setStandby2(detlDto.getStandby2());
                waitPakin.setStandby3(detlDto.getStandby3());
                if ("Y".equals(param.getTkFlag())) {
                    waitPakin.setTkFlag(detlDto.getTkFlag());
                }
                waitPakin.setTkFlag(param.getTkFlag());
                waitPakin.setCstateid(detlDto.getCstateid());
                if (!waitPakinService.insert(waitPakin)) {
                    throw new CoolException("保存入库通知档失败");
                }
@@ -668,10 +677,12 @@
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
                detlDto.setOrderNo(elem.getOrderNo());
                detlDto.setWeight(elem.getWeight());
                detlDto.setCstateid(elem.getCstateid());
                if (DetlDto.has(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                    assert one != null;
                    one.setAnfme(one.getAnfme() + detlDto.getAnfme());
                    one.setWeight(one.getWeight() + detlDto.getWeight());
                } else {
                    detlDtos.add(detlDto);
                }
@@ -702,6 +713,7 @@
                waitPakin.setStandby2(detlDto.getStandby2());
                waitPakin.setStandby3(detlDto.getStandby3());
                waitPakin.setWeight(detlDto.getWeight());
                waitPakin.setCstateid(detlDto.getCstateid());
                if (!waitPakinService.insert(waitPakin)) {
                    throw new CoolException("保存入库通知档失败");
                }
@@ -710,6 +722,53 @@
        }
    }
    @Override
    public void combCancel(CombCancelParam param, Long userId) {
        if (Cools.isEmpty(param.getBarcode())) {
            throw new CoolException(BaseRes.PARAM);
        }
        List<WaitPakin> waitPakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().
                eq("zpallet", param.getBarcode()));
        if (waitPakins.isEmpty()) {
            throw new CoolException("托盘未组托");
        }
        for (WaitPakin waitPakin : waitPakins) {
            if (!Cools.isEmpty(waitPakin.getOrderNo())) {
                Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, waitPakin.getOrderNo());
                if (Cools.isEmpty(order)) {
                    throw new CoolException("单据编号不存在");
                }
                if (order.getSettle() > 2) {
                    throw new CoolException("单据编号已作业完成");
                }
                // 订单明细数量校验
                OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectItem(order.getId(), waitPakin.getMatnr(), waitPakin.getBatch(), waitPakin.getBrand(), waitPakin.getStandby1(), waitPakin.getStandby2(), waitPakin.getStandby3(),
                        waitPakin.getBoxType1(), waitPakin.getBoxType2(), waitPakin.getBoxType3());
                if (orderDetlPakin == null) {
                    continue;
                }
                Double workQty = orderDetlPakin.getWorkQty();
                BigDecimal workQtyDecimal = new BigDecimal(workQty);
                workQtyDecimal = workQtyDecimal.subtract(BigDecimal.valueOf(waitPakin.getAnfme()));
                double newWorkQty = workQtyDecimal.doubleValue();
                if (newWorkQty <= 0) {
                    newWorkQty = 0D;
                }
                orderDetlPakin.setWorkQty(newWorkQty);
                orderDetlPakinService.updateById(orderDetlPakin);
            }
        }
        waitPakinService.delete(new EntityWrapper<WaitPakin>()
                .eq("zpallet", param.getBarcode()));
    }
    // 商品上架
@@ -785,11 +844,7 @@
        Date now = new Date();
        List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
        List<WrkDetl> list = param.getWrkDetls();
        LocDetlAdjustParam adjustParam = new LocDetlAdjustParam();
        List<LocDetlAdjustParam.LocDetlAdjust> locDetlAdjusts = new ArrayList<>();
        adjustParam.setLocNo(wrkMast.getSourceLocNo());
        List<WrkDetl> list = JSON.parseArray(JSON.toJSONString(param.getWrkDetls()), WrkDetl.class);
        // 修改数量
        Iterator<WrkDetl> iterator = wrkDetls.iterator();
        while (iterator.hasNext()) {
@@ -840,37 +895,31 @@
            if (!wrkDetlService.insert(wrkDetl)) {
                throw new CoolException("添加" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号任务明细失败");
            }
        }
        List<WrkDetl> paramWrkDetls = JSON.parseArray(JSON.toJSONString(param.getWrkDetls()), WrkDetl.class);
        for (WrkDetl wrkDetl : paramWrkDetls) {
            String locNo = Cools.isEmpty(wrkMast.getLocNo()) ? wrkMast.getSourceLocNo() : wrkMast.getLocNo();
            List<InventoryCheckOrderDetl> checkOrderDetls = inventoryCheckOrderDetlService.selectList(new EntityWrapper<InventoryCheckOrderDetl>().eq("loc_no", locNo));
            List<InventoryCheckOrderDetl> checkOrderDetls = inventoryCheckOrderDetlService.selectList(new EntityWrapper<InventoryCheckOrderDetl>()
                    .eq("loc_no", locNo)
                    .eq("area", wrkDetl.getWrkNo())
            );
            for (InventoryCheckOrderDetl checkOrderDetl : checkOrderDetls) {
                if (wrkDetl.getMatnr().equals(checkOrderDetl.getMatnr()) && Cools.eq(wrkDetl.getBatch(), checkOrderDetl.getBatch())) {
                    checkOrderDetl.setCheckAnfme(wrkDetl.getAnfme());
                    checkOrderDetl.setStatus("2");
                } else {
                    InventoryCheckOrderDetl newDetl = new InventoryCheckOrderDetl();
                    Synchro.Copy(wrkDetl, newDetl);
                    newDetl.setAnfme(0D);
                    newDetl.setCheckAnfme(wrkDetl.getAnfme());
                    newDetl.setOrderNo(checkOrderDetl.getOrderNo());
                    newDetl.setStatus("2");
                    inventoryCheckOrderDetlService.updateById(checkOrderDetl);
                }
            }
        }
        List<WrkDetl> wrkDetls1 = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
        for (WrkDetl wrkDetl : wrkDetls1) {
            LocDetlAdjustParam.LocDetlAdjust locDetlAdjust = new LocDetlAdjustParam.LocDetlAdjust(wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme());
            locDetlAdjusts.add(locDetlAdjust);
        }
        // 修改盘点任务主档状态
        wrkMast.setFullPlt(wrkDetls1.size() != 0 ? "Y" : "N");
        wrkMast.setFullPlt("Y");
        wrkMast.setModiTime(now);
        wrkMast.setModiUser(userId);
        if (!wrkMastService.updateById(wrkMast)) {
            throw new CoolException("修改盘点任务主档失败");
        }
        adjustParam.setList(locDetlAdjusts);
        workService.adjustLocDetl2(adjustParam, userId);
    }
    @Override
@@ -1182,4 +1231,106 @@
            throw new CoolException(locDetl.getLocNo() + "库位不是在库状态");
        }
    }
    @Override
    public void checkOutSubmit(Integer orderId, Long userId) {
        InventoryCheckOrder inventoryCheckOrder = inventoryCheckOrderService.selectOne(new EntityWrapper<InventoryCheckOrder>()
                .eq("id", orderId));
        if (inventoryCheckOrder == null) {
            throw new CoolException("盘点单不存在");
        }
        if (!inventoryCheckOrder.getStatus().equals("1")) {
            throw new CoolException("盘点单状态已上报");
        }
        List<InventoryCheckOrderDetl> checkOrderDetlList = inventoryCheckOrderDetlService.selectList(new EntityWrapper<InventoryCheckOrderDetl>()
                .eq("order_no", inventoryCheckOrder.getOrderNo())
        );
        if (checkOrderDetlList.isEmpty()) {
            throw new CoolException("盘点单无物料明细");
        }
        InventoryCheckOrderDetl orderDetl = checkOrderDetlList.get(0);
        List<InventoryCheckOrderDetl> checkOrderDetls = inventoryCheckOrderDetlService.selectList(new EntityWrapper<InventoryCheckOrderDetl>()
                .eq("matnr", orderDetl.getMatnr())
                .eq("batch", orderDetl.getBatch())
        );
        boolean complete = true;
        for (InventoryCheckOrderDetl checkOrderDetl : checkOrderDetls) {
            if (!checkOrderDetl.getStatus().equals("2")) {
                complete = false;
            }
        }
        if (complete) {
            boolean result = reportToThirdService.reportCheckOrder(orderDetl.getMatnr(), orderDetl.getBatch());
            if (!result) {
                throw new CoolException("盘点单上报失败");
            }
        }else {
            throw new CoolException("盘点未完成无法上报");
        }
    }
    @Override
    public void toOutSta(PalletToOutStaParam param, Long userId) {
        WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode());
        if (wrkMast == null) {
            throw new CoolException("工作档不存在");
        }
        if (wrkMast.getIoType() != 103) {
            throw new CoolException("工作档类型不是拣料出库");
        }
        if (wrkMast.getWrkSts() != 14) {
            throw new CoolException("工作状态未处于已出库");
        }
        String response = "";
        try {
            HashMap<String, Object> map = new HashMap<>();
            map.put("wrkNo", wrkMast.getWrkNo());
            map.put("sourceStaNo", wrkMast.getStaNo());
            map.put("staNo", 1075);
            response = new HttpHandler.Builder()
                    .setUri(wcsUrl)
                    .setPath("/open/toOutSta")
                    .setJson(JSON.toJSONString(map))
                    .build()
                    .doPost();
            log.info("toOutSta:{}", response);
        } catch (Exception e) {
            log.error("fail", e);
        }
    }
    @Override
    public void toAllOut(PalletToAllOutParam param, Long userId) {
        WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode());
        if (wrkMast == null) {
            throw new CoolException("工作档不存在");
        }
        if (wrkMast.getIoType() != 103) {
            throw new CoolException("工作档类型不是拣料出库");
        }
        if (wrkMast.getWrkSts() != 14) {
            throw new CoolException("工作状态未处于已出库");
        }
        wrkMast.setBarcode(param.getNewBarcode());
        wrkMast.setModiTime(new Date());
        wrkMast.setModiUser(userId);
        wrkMastService.updateById(wrkMast);
        WrkDetl wrkDetl = new WrkDetl();
        wrkDetl.setZpallet(param.getNewBarcode());
        wrkDetl.setModiTime(new Date());
        wrkDetl.setModiUser(userId);
        wrkDetlService.update(wrkDetl, new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
    }
}