自动化立体仓库 - WMS系统
pang.jiabao
2024-12-02 57936e11434f6614f818a0a0a495918dc1af6dd6
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -12,6 +12,7 @@
import com.zy.asrs.entity.param.OffSaleParam;
import com.zy.asrs.entity.param.OpenOrderPakinParam;
import com.zy.asrs.mapper.ManLocDetlMapper;
import com.zy.asrs.mapper.OrderDetlMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.MatUtils;
import com.zy.asrs.utils.SaasUtils;
@@ -26,6 +27,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
@@ -43,6 +46,10 @@
    private MatService matService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Resource
    private WaitPakinLogService waitPakinLogService;
    @Autowired
    private OrderService orderService;
    @Autowired
@@ -78,6 +85,182 @@
    @Autowired
    private ManLocDetlMapper manLocDetlMapper;
    @Resource
    private OrderDetlMapper orderDetlMapper;
    @Override
    @Transactional
    public R WarehouseOut(CombParam combParam, Long userId) {
        //查询库存数据
        for (CombParam.CombMat combMat : combParam.getCombMats()) {
            ManLocDetl locDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>()
                            .eq("loc_no", combParam.getLocno())
                            .eq("zpallet", combMat.getZpallet())
                            .eq("matnr", combMat.getMatnr())
//                    .eq(LocDetl::getBatch, combMat.getBatch())
            );
            if (Cools.isEmpty(locDetl)) {
                return R.error("未查询到库存数据");
            }
            if (combMat.getAnfme() > locDetl.getAnfme()) {
                return R.error("下架数量错误,超出库存数量");
            }
            if (!Cools.isEmpty(combParam.getOrderNo())) {
                Order order = orderService.selectByNo(combParam.getOrderNo());
                if (Cools.isEmpty(order)) {
                    continue;
                }
                if (order.getSettle() == 1) {
                    orderService.updateSettle(order.getId(), 2L, userId);
                }
                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), combMat.getMatnr(), combMat.getBatch());
                if (Cools.isEmpty(orderDetl)) {
                    continue;
                }
                if (orderDetl.getAnfme() < orderDetl.getWorkQty() + combMat.getAnfme()) {
                    combMat.setAnfme(orderDetl.getAnfme() - orderDetl.getWorkQty());
                }
                // 修改订单明细作业数量
                if (orderDetlMapper.increaseWorkQtyByOrderNo(combParam.getOrderNo(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme()) <= 0) {
                    throw new CoolException("修改单据明细工作数量失败");
                }
                // 修改订单明细完成数量
                if (!orderDetlService.increase(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme())) {
                    throw new CoolException("修改单据明细完成数量失败");
                }
                // 修改订单状态 作业中 ===>> 已完成
                orderService.checkComplete(combParam.getOrderNo());
            }
            try {
                double i = 0.0;
                double j = locDetl.getAnfme();
                //处理库存信息
                if (combMat.getAnfme().equals(locDetl.getAnfme())) {
                    //库存相等删除数据
                    manLocDetlMapper.deleteLocNo0(combParam.getLocno(), combMat.getMatnr());
                    int count = manLocDetlMapper.selectCount(new EntityWrapper<ManLocDetl>().eq("loc_no", combParam.getLocno()));
                    if (count == 0) {
                        Node node = nodeService.selectByUuid(combParam.getLocno());
                        node.setUpdateTime(new Date());
                        node.setUpdateBy(userId);
                        node.setBarcode("");
                        nodeService.updateById(node);
                    }
                } else {
                    BigDecimal subtract = BigDecimal.valueOf(locDetl.getAnfme()).subtract(BigDecimal.valueOf(combMat.getAnfme()));
                    i = subtract.byteValue();
                    locDetl.setAnfme(subtract.doubleValue());
                    // 更新库存
                    manLocDetlMapper.updateAnfme(subtract.doubleValue(), combParam.getLocno(), combMat.getMatnr(), combMat.getBatch());
                }
                // 记录日志
                SaasUtils.insertLog(1, combParam.getLocno(), combMat.getMatnr(), combMat.getAnfme(), userId,combMat.getBatch());
            } catch (Exception e) {
                throw new CoolException("更新库存数据出错" + e.getMessage());
            }
        }
        return R.ok();
    }
    @Override
    @Transactional
    public R WarehouseIn(String locNo, String barcode, Long userId) {
        //查询组托数据
        List<WaitPakin> list = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
        if (Cools.isEmpty(list)) {
            return R.error("未找到组托信息");
        }
        Date now = new Date();
        //插入库存数据
        for (WaitPakin waitPakin : list) {
            Mat mat = matService.selectOne(new EntityWrapper<Mat>()
                    .eq("matnr", waitPakin.getMatnr()));
            ManLocDetl locDetl1 = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>().eq("loc_no", locNo).eq("matnr", waitPakin.getMatnr()).
                    eq("batch", waitPakin.getBatch()));
            Node node = nodeService.selectByUuid(locNo);
            if (Cools.isEmpty(node)) {
                throw new CoolException(locNo + ":库位不存在");
            }
            if (!Cools.isEmpty(locDetl1)) {
                locDetl1.setAnfme(waitPakin.getAnfme() + waitPakin.getAnfme());
                locDetl1.setUpdateBy(userId);
                locDetl1.setModiTime(now);
                manLocDetlService.update(locDetl1, new EntityWrapper<ManLocDetl>().eq("loc_no", locNo).eq("matnr", waitPakin.getMatnr()).
                        eq("batch", waitPakin.getBatch()));
            } else {
                ManLocDetl manLocDetl = new ManLocDetl();
                manLocDetl.setLocNo(locNo);
//            manLocDetl.setBarcode(barcode);
                manLocDetl.setZpallet(barcode);
                manLocDetl.setNodeId(node.getId());
                manLocDetl.setMaktx(mat.getMaktx());
                manLocDetl.setMatnr(mat.getMatnr());
                manLocDetl.setSpecs(mat.getSpecs());
                manLocDetl.setBatch(Cools.isEmpty(waitPakin.getBatch()) ? "" : waitPakin.getBatch());
                manLocDetl.setAnfme(waitPakin.getAnfme());
                manLocDetl.setCreateBy(userId);
                manLocDetl.setCreateTime(now);
                manLocDetl.setUpdateBy(userId);
                manLocDetl.setModiTime(now);
                if (!manLocDetlService.insert(manLocDetl)) {
                    throw new CoolException("商品上架失败!");
                }
                // 更新库位条码
                node.setBarcode(barcode);
                node.setUpdateBy(userId);
                node.setUpdateTime(now);
                nodeService.updateById(node);
            }
            // 记录日志
            SaasUtils.insertLog(0, locNo, waitPakin.getMatnr(), waitPakin.getAnfme(), userId,waitPakin.getBatch());
            //是否属于订单数据
//            if (!Cools.isEmpty(waitPakin.getOrderNo())){
//                Order order = orderService.selectByNo(waitPakin.getOrderNo(), hostId);
//                if (Cools.isEmpty(order)){
//                    continue;
//                }
//                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), waitPakin.getMatnr(), waitPakin.getBatch(),hostId);
//                if (Cools.isEmpty(orderDetl)){
//                    continue;
//                }
//                // 修改订单明细完成数量
//                if (!orderDetlService.increase(order.getId(), hostId, waitPakin.getMatnr(), waitPakin.getBatch(), waitPakin.getAnfme())) {
//                    throw new CoolException("修改单据明细数量失败");
//                }
//                // 修改订单状态 作业中 ===>> 已完成
//                orderService.checkComplete(waitPakin.getOrderNo(), hostId);
//
//            }
            // 更新入库工作档
            waitPakin.setLocNo(locNo);
            waitPakin.setIoStatus("Y");
            waitPakin.setModiUser(userId);
            waitPakin.setModiTime(now);
            waitPakinService.update(waitPakin,new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("matnr",waitPakin.getMatnr())
                    .eq("batch",waitPakin.getBatch()));
            // 保存入库通知档历史档
            if (!waitPakinLogService.save(barcode)) {
                throw new CoolException("保存组托数据失败");
            }
            // 删除入库通知档
            if (!waitPakinService.delete(new EntityWrapper<WaitPakin>().eq("zpallet", barcode))) {
                throw new CoolException("删除组托数据失败");
            }
        }
        return R.ok("上架成功");
    }
    @Override
    @Transactional
@@ -252,7 +435,7 @@
            node.setUpdateBy(userId);
            node.setUpdateTime(now);
            nodeService.updateById(node);
            SaasUtils.insertLog(0,manLocDetl.getLocNo(), manLocDetl.getMatnr(),combMat.getAnfme(),userId);
            SaasUtils.insertLog(0,manLocDetl.getLocNo(), manLocDetl.getMatnr(),combMat.getAnfme(),userId,manLocDetl.getBatch());
        }
    }
@@ -268,7 +451,7 @@
        if (anfme < 0) {
            throw new CoolException("商品库存不足!");
        } else if (anfme == 0){
            SaasUtils.insertLog(1,manLocDetl.getLocNo(), manLocDetl.getMatnr(),offSaleParam.getAnfme(),userId);
            SaasUtils.insertLog(1,manLocDetl.getLocNo(), manLocDetl.getMatnr(),offSaleParam.getAnfme(),userId,manLocDetl.getBatch());
            manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr());
            // 清空库位条码
            Node node = nodeService.selectByUuid(offSaleParam.getLocNo());