自动化立体仓库 - WMS系统
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -4,12 +4,17 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.*;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.SnowflakeIdWorker;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.entity.param.MobileAdjustParam;
import com.zy.asrs.entity.param.OffSaleParam;
import com.zy.asrs.entity.param.OpenOrderPakinParam;
import com.zy.asrs.mapper.ManLocDetlMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.MatUtils;
import com.zy.common.constant.MesConstant;
@@ -18,15 +23,21 @@
import com.zy.common.model.MesCombParam;
import com.zy.common.service.CommonService;
import com.zy.common.utils.HttpHandler;
import com.zy.third.entity.ExdInstockSource;
import com.zy.third.entity.ExdStock;
import com.zy.third.entity.ExdvYanbu;
import com.zy.third.mapper.ExdMaterialMapper;
import com.zy.third.mapper.ExdStockMapper;
import com.zy.third.service.ExdInstockSourceService;
import com.zy.third.service.ExdMaterialService;
import com.zy.third.service.ExdStockService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.*;
/**
 * 移动端服务核心类
@@ -44,6 +55,8 @@
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private OrderDetl1Service orderDetl1Service;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
@@ -68,27 +81,91 @@
    private StaDescService staDescService;
    @Autowired
    private CommonService commonService;
    @Autowired
    private NodeService nodeService;
    @Autowired
    private ManLocDetlService manLocDetlService;
    @Autowired
    private ManLocDetlMapper manLocDetlMapper;
    @Autowired
    private ExdMaterialMapper exdMaterialMapper;
    @Autowired
    private ExdStockMapper exdStockMapper;
    @Autowired
    private ExdStockService exdStockService;
    @Autowired
    private ExdInstockSourceService  exdInstockSourceService;
    @Override
    @Transactional
    public void comb(CombParam param, Long userId) {
    public void comb(CombParam param, Long userId, String fxId) {
        if (Cools.isEmpty(fxId)){
            throw new CoolException("请用自己的账号组托");
        }
        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
            throw new CoolException(BaseRes.PARAM);
        }
        // 判断是否有相同条码的数据
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
            throw new CoolException(param.getBarcode() + "数据正在进行入库");
            throw new CoolException(param.getBarcode() + "数据组托档中已存在");
        }
        int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode()));
        int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode()));
//        int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode())
//                                            .last(" wrk_no IN ( SELECT wrk_no FROM asr_wrk_mast WHERE wrk_sts != 15 )"));
        if (countLoc > 0) {
            throw new CoolException("库存条码数据已存在===>>" + param.getBarcode());
        }
        if (countWrk > 0) {
            throw new CoolException("工作档条码数据已存在===>>" + param.getBarcode());
        }
        Date now = new Date();
        //进行批号筛选,批号只能唯一
        Set<String> batchs = new HashSet<>();
        List<String> strings = new ArrayList<>();
        long time = new Date().getTime();
        //生产入库对一坨物料进行绑定。唯一值
        String fbillno = param.getBarcode()+"--"+time;
        for (CombParam.CombMat mat : param.getCombMats()) {
            if (Cools.isEmpty(mat.getBatch())) {
                continue;
            }
            batchs.add(mat.getBatch());
            strings.add(mat.getBatch());
            WaitPakin waitPakin = waitPakinService.selectOne(new EntityWrapper<WaitPakin>().eq("batch", mat.getBatch()));
            WrkDetl batch = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("batch", mat.getBatch()));
            LocDetl batch1 = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("batch", mat.getBatch()));
            if (!Cools.isEmpty(batch) || !Cools.isEmpty(batch1) || !Cools.isEmpty(waitPakin)) {
                throw new CoolException("该物料批号" + mat.getBatch() + "已在入库通知档、任务明细和库存中存在");
            }
        }
        if (batchs.size() < strings.size()) {
            throw new CoolException("有重复的物料批号");
        }
        int i = 1;
        // 无单组托
        if (Cools.isEmpty(param.getOrderNo())) {
            // 生成入库通知档
            List<DetlDto> detlDtos = new ArrayList<>();
            param.getCombMats().forEach(elem -> {
                // 判断是否有相同条码的数据
                if (!Cools.isEmpty(elem.getBc())){
                    if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                            eq("three_code", elem.getBc())) > 0) {
                        throw new CoolException( elem.getBc() + "数据组托档中已存在");
                    }
                }
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
                detlDto.setBc(elem.getBc());
                if (DetlDto.has(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch());
                    assert one != null;
@@ -101,12 +178,16 @@
            for (DetlDto detlDto : detlDtos) {
                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                if (Cools.isEmpty(detlDto.getBatch())) {
                    detlDto.setBatch("");
                }
                if (Cools.isEmpty(mat)) {
                    throw new CoolException(detlDto.getMatnr() + "商品档案不存在");
                }
                WaitPakin waitPakin = new WaitPakin();
                waitPakin.sync(mat);
                waitPakin.setBatch(detlDto.getBatch());
                waitPakin.setBatch(detlDto.getBc());
                waitPakin.setThreeCode(detlDto.getBc());
                waitPakin.setZpallet(param.getBarcode());   // 托盘码
                waitPakin.setIoStatus("N");     // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme());  // 数量
@@ -114,12 +195,41 @@
                waitPakin.setAppeUser(userId);
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
                waitPakin.setColor(userId+"");
                waitPakin.setModiTime(now);
                //生产入库对一坨物料进行绑定。唯一值
                waitPakin.setOrigin(fbillno);
                ExdvYanbu barcode1 = exdMaterialMapper.getBacode(detlDto.getBc());
                String pid="03.98";
                if(!Cools.isEmpty(barcode1)&&!Cools.isEmpty(barcode1.getProdinkind())){
                    pid=barcode1.getProdinkind();
                }
                ExdStock id = exdStockService.selectOne(new EntityWrapper<ExdStock>().eq("Fnumber", pid));
                waitPakin.setBrand(id.getFname());//仓库
                waitPakin.setInspect(param.isType() ? 1 : 0);
                if (i == 1) {
//                0:不需要补空托盘
//                1:小托盘
//                2:大托盘
                    waitPakin.setItemNum(param.getBarcodeSize());
                    waitPakin.setMemo(Cools.isEmpty(param.getRsta()) ? "" : param.getRsta());//源站点
                    /**
                     * agv状态
                     * 0:无需调用AGV
                     * 1:等待调用AGV
                     * 2:AGV任务下发成功
                     * 3:AGV任务完成
                     * 4:给输送线下发入库指令
                     */
                    waitPakin.setBeBatch(Cools.isEmpty(param.getRsta())?0:1);
                    waitPakin.setSuppCode(param.getBarcode());
                }
                i++;
                if (!waitPakinService.insert(waitPakin)) {
                    throw new CoolException("保存入库通知档失败");
                }
            }
        // 关联组托
            // 关联组托
        } else {
            Order order = orderService.selectByNo(param.getOrderNo());
            if (order.getSettle() > 2) {
@@ -135,7 +245,11 @@
                    throw new CoolException(orderDetl.getMatnr() + "入库数量不合法");
                }
                // 修改订单作业数量
                if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) {
                if (!orderDetlService.increaseWorkQty2(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme(), userId)) {
                    throw new CoolException("修改单据作业数量失败");
                }
                // 修改子单订单作业数量
                if (!orderDetl1Service.increaseWorkQty2(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme(), userId)) {
                    throw new CoolException("修改单据作业数量失败");
                }
@@ -156,7 +270,7 @@
                WaitPakin waitPakin = new WaitPakin();
                waitPakin.sync(mat);
                waitPakin.setOrderNo(order.getOrderNo());   // 单据编号
                waitPakin.setBatch(detlDto.getBatch());     // 序列码
                waitPakin.setBatch(detlDto.getBatch());     // 批号
                waitPakin.setZpallet(param.getBarcode());   // 托盘码
                waitPakin.setIoStatus("N");     // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme());  // 数量
@@ -165,14 +279,102 @@
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
                waitPakin.setModiTime(now);
                waitPakin.setColor(userId+"");
                OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>()
                        .eq("matnr", detlDto.getMatnr()).eq("order_no", order.getOrderNo())
                        .eq("batch", detlDto.getBatch()));
                waitPakin.setBrand(orderDetl.getBrand());//仓库
                waitPakin.setInspect(param.isType() ? 1 : 0);
                if (i == 1) {
//                0:不需要补空托盘
//                1:小托盘
//                2:大托盘
                    waitPakin.setItemNum(param.getBarcodeSize());
                    waitPakin.setMemo(Cools.isEmpty(param.getRsta()) ? "" : param.getRsta());//源站点
                    /**
                     * agv状态
                     * 0:无需调用AGV
                     * 1:等待调用AGV
                     * 2:AGV任务下发成功
                     * 3:AGV任务完成
                     * 4:给输送线下发入库指令
                     */
                    waitPakin.setBeBatch(param.getBeBatch());
                    waitPakin.setSuppCode(param.getBarcode());
                }
                i++;
                if (!waitPakinService.insert(waitPakin)) {
                    throw new CoolException("保存入库通知档失败");
                }
            }
            orderService.updateSettle(order.getId(), 2L, userId);
            List<ExdInstockSource> fBillNo = exdInstockSourceService.selectList(new EntityWrapper<ExdInstockSource>().eq("FBillNo", order.getOrderNo()));
            if(fBillNo != null){
                for(ExdInstockSource exdInstockSource : fBillNo){
                    exdInstockSource.setStatus(10);
                    exdInstockSourceService.updateById(exdInstockSource);
                }
            }
        }
    }
    // 商品上架
    @Override
    public void onSale(CombParam param) {
        Date now = new Date();
        // 获取库位号
        String locno = param.getLocno();
        Node node = nodeService.selectByUuid(locno);
        if (Cools.isEmpty(node)) {
            throw new CoolException(param.getLocno() + ":库位不存在");
        }
        // 获取商品列表
        for (CombParam.CombMat combMat : param.getCombMats()) {
            Mat mat = matService.selectByMatnr(combMat.getMatnr());
            if (Cools.isEmpty(mat)) {
                throw new CoolException(combMat.getMatnr() + ":商品档案不存在!");
            }
            if (Cools.isEmpty(combMat.getAnfme()) || combMat.getAnfme() == 0) {
                throw new CoolException(combMat.getMatnr() + ":商品数量有误!");
            }
            if (Cools.isEmpty(combMat.getBatch())) {
//                throw new CoolException(combMat.getMatnr() + ":商品批号有误!");
            }
            ManLocDetl manLocDetl = new ManLocDetl();
            manLocDetl.setLocNo(locno);
            manLocDetl.setNodeId(node.getId());
            manLocDetl.setMaktx(mat.getMaktx());
            manLocDetl.setMatnr(mat.getMatnr());
            manLocDetl.setBatch(Cools.isEmpty(combMat.getBatch()) ? "" : combMat.getBatch());
            manLocDetl.setAnfme(combMat.getAnfme());
            manLocDetl.setModiTime(now);
            if (!manLocDetlService.insert(manLocDetl)) {
                throw new CoolException("商品上架失败!");
            }
        }
    }
    // 商品下架
    @Override
    public void offSale(OffSaleParam offSaleParam) {
        ManLocDetl manLocDetl = manLocDetlMapper.selectLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr());
        if (Cools.isEmpty(manLocDetl)) {
            throw new CoolException("无此商品!");
        }
        double anfme = manLocDetl.getAnfme() - offSaleParam.getAnfme();
        if (anfme < 0) {
            throw new CoolException("商品库存不足!");
        } else if (anfme == 0) {
            manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr());
        }
        manLocDetlMapper.updateAnfme0(anfme, manLocDetl.getNodeId());
    }
    // 查找商品
    @Override
    @Transactional
@@ -227,7 +429,9 @@
        // 添加明细
        for (WrkDetl wrkDetl : list) {
            if (wrkDetl.getAnfme() == 0.0D) { continue; }
            if (wrkDetl.getAnfme() == 0.0D) {
                continue;
            }
            // todo 盘点记录、保存调整记录
            String orderNo = wrkDetl.getOrderNo();
            Mat mat = matService.selectByMatnr(wrkDetl.getMatnr());
@@ -243,7 +447,7 @@
        }
        // 修改盘点任务主档状态
        wrkMast.setFullPlt(wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()).size() != 0?"Y":"N");
        wrkMast.setFullPlt(wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()).size() != 0 ? "Y" : "N");
        wrkMast.setModiTime(now);
        wrkMast.setModiUser(userId);
        if (!wrkMastService.updateById(wrkMast)) {
@@ -320,10 +524,10 @@
                    if (jsonObject.getInteger("code").equals(200)) {
                        success = true;
                    } else if (jsonObject.getInteger("code").equals(500)) {
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                        throw new CoolException(jsonObject.getString("msg"));
                    } else {
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                        throw new CoolException("上报mes系统失败");
                    }
                } catch (Exception e) {
@@ -341,7 +545,9 @@
                                response,
                                success
                        );
                    } catch (Exception e) { log.error("", e); }
                    } catch (Exception e) {
                        log.error("", e);
                    }
                }
            }
@@ -418,15 +624,19 @@
        BasDevp sta = basDevpService.checkSiteStatus(staNo);
        //根据订单号生成出库任务工作档
        Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo));
        if (order.getSettle() != 1 && order.getSettle() != 2) {
            throw new CoolException("该订单已处理");
        }
        List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo));
        Date now = new Date();
        for(OrderDetl orderDetl : orderDetls){
        for (OrderDetl orderDetl : orderDetls) {
            //查询所有库位状态为F的库位信息
            List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch(),orderDetl.getOrderNo(),null);
            List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, null);
            if (locDetls.size() == 0) {
                throw new CoolException("库存中没有该物料");
            }
            for(LocDetl locDetl : locDetls){
            for (LocDetl locDetl : locDetls) {
                //如果该库位出库路线所用的堆垛机out_enable不为Y,跳过该循环
                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                        .eq("loc_no", locDetl.getLocNo()));
@@ -435,13 +645,13 @@
                }
                BasCrnp crn_no = basCrnpService.selectOne(new EntityWrapper<BasCrnp>()
                        .eq("crn_no", locMast.getCrnNo()));
                if (Cools.isEmpty(crn_no) || !crn_no.getOutEnable().equals("Y")){
                if (Cools.isEmpty(crn_no) || !crn_no.getOutEnable().equals("Y")) {
                    continue;
                }
                //可出库数量 = 订单数量 - 作业中数量
                Double outQty = orderDetl.getAnfme() - orderDetl.getWorkQty();
                if(outQty <= 0){
                if (outQty <= 0) {
                    break;
                }
                // 判断入出库类型:101.全板出库 or 103.拣料出库
@@ -453,18 +663,18 @@
                order.setSettle(2L);
                order.setUpdateBy(userId);
                order.setUpdateTime(now);
                if(orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){
                if (!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))) {
                    throw new CoolException("更新订单状态失败");
                }
                orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty);
                orderDetl.setUpdateBy(userId);
                orderDetl.setUpdateTime(now);
                Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo)
                        .eq("matnr",orderDetl.getMatnr());
                if(!Cools.isEmpty(orderDetl.getBatch())){
                        .eq("matnr", orderDetl.getMatnr());
                if (!Cools.isEmpty(orderDetl.getBatch())) {
                    wrapper.eq("batch", orderDetl.getBatch());
                }
                if(orderDetlService.update(orderDetl, wrapper)){
                if (!orderDetlService.update(orderDetl, wrapper)) {
                    throw new CoolException("更新订单明细失败");
                }
            }