#
lsh
2024-09-12 05b6ccedbd294ad536fe86b49e10d6825284fb65
zy-asrs-common/src/main/java/com/zy/asrs/common/wms/service/impl/MobileServiceImpl.java
@@ -19,6 +19,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
@@ -98,6 +99,8 @@
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
                waitPakin.setModiTime(now);
                waitPakin.setFullPlt(param.getFullPlt());
                waitPakin.setOwner(param.getOwner());
                if (!waitPakinService.save(waitPakin)) {
                    throw new CoolException("保存入库通知档失败");
                }
@@ -123,6 +126,9 @@
                }
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
                detlDto.setWarehouse(orderDetl.getThreeCode());//来源仓库
                detlDto.setOrigin(orderDetl.getSupp());//来源单号
                detlDto.setOriginNo(orderDetl.getSuppCode());//来源序号
                if (DetlDto.has(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch());
                    assert one != null;
@@ -143,11 +149,15 @@
                waitPakin.setZpallet(param.getBarcode());   // 托盘码
                waitPakin.setIoStatus("N");     // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme());  // 数量
                waitPakin.setThreeCode(detlDto.getWarehouse());  // 仓库
                waitPakin.setSupp(detlDto.getOrigin());  // 来源单号
                waitPakin.setSuppCode(detlDto.getOriginNo());  // 来源序号
                waitPakin.setStatus("Y");    // 状态
                waitPakin.setAppeUser(userId);
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
                waitPakin.setModiTime(now);
                waitPakin.setOwner(param.getOwner());
                if (!waitPakinService.save(waitPakin)) {
                    throw new CoolException("保存入库通知档失败");
                }
@@ -238,7 +248,7 @@
    @Transactional
    public R WarehouseIn(String locNo, String barcode,Long hostId) {
        //判断库位状态
        LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, locNo).eq(LocMast::getHostId,hostId));
        LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, locNo).eq(LocMast::getHostId,hostId).eq(LocMast::getWhsType,1L));
        if (Cools.isEmpty(locMast)){
            return R.error("该库位不存在");
        }
@@ -280,6 +290,9 @@
                if (!orderDetlService.increase(order.getId(), hostId, waitPakin.getMatnr(), waitPakin.getBatch(), waitPakin.getAnfme())) {
                    throw new CoolException("修改单据明细数量失败");
                }
                // 修改订单状态 作业中 ===>> 已完成
                orderService.checkComplete(waitPakin.getOrderNo(), hostId);
            }
        }
        //修改库位状态
@@ -301,9 +314,10 @@
    }
    @Override
    @Transactional
    public R WarehouseOut(CombParam combParam, Long hostId) {
        //判断库位状态
        LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, combParam.getLocno()).eq(LocMast::getHostId,hostId));
        LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, combParam.getLocno()).eq(LocMast::getHostId,hostId).eq(LocMast::getWhsType,1L));
        if (Cools.isEmpty(locMast)){
            return R.error("该库位不存在");
        }
@@ -311,14 +325,150 @@
            return R.error("该库位状态为:"+locMast.getLocSts()+",禁止出库");
        }
        //查询库存数据
        List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getZpallet, combParam.getBarcode()).eq(LocDetl::getLocNo, combParam.getLocno()).eq(LocDetl::getHostId, hostId));
        if (Cools.isEmpty(locDetls)){
            return R.error("未查询到库存数据");
        }
        for (LocDetl locDetl: locDetls){
        for (CombParam.CombMat combMat :combParam.getCombMats()){
            LocDetl locDetl = locDetlService.getOne(new LambdaQueryWrapper<LocDetl>()
                    .eq(LocDetl::getLocNo, combParam.getLocno())
                    .eq(LocDetl::getHostId, hostId)
                    .eq(LocDetl::getZpallet, combMat.getZpallet())
                    .eq(LocDetl::getMatnr, 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(), hostId);
                if (Cools.isEmpty(order)){
                    continue;
                }
                if (order.getSettle() == 1){
                    orderService.updateSettle(order.getId(), 2L, 9527L, hostId);
                }
                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), combMat.getMatnr(), combMat.getBatch(),hostId);
                if (Cools.isEmpty(orderDetl)){
                    continue;
                }
                if (orderDetl.getAnfme() < orderDetl.getWorkQty()+combMat.getAnfme()){
                    throw new CoolException("下架数量出错");
                }
                // 修改订单明细作业数量
                if (!orderDetlService.increaseWorkQtyByOrderNo(combParam.getOrderNo(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), hostId)) {
                    throw new CoolException("修改单据明细工作数量失败");
                }
                // 修改订单明细完成数量
                if (!orderDetlService.increase(order.getId(), hostId, combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme())) {
                    throw new CoolException("修改单据明细完成数量失败");
                }
                // 修改订单状态 作业中 ===>> 已完成
                orderService.checkComplete(combParam.getOrderNo(), hostId);
            }
            try {
                //处理库存信息
                if (combMat.getAnfme().equals(locDetl.getAnfme())){
                    //库存相等删除数据
                    locDetlService.removeById(locDetl);
                    int count = locDetlService.count(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo,combParam.getLocno()).eq(LocDetl::getHostId, hostId));
                    if (count == 0){
                        LocMast locMast1 = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, combParam.getLocno()).eq(LocMast::getHostId, hostId));
                        locMast1.setLocSts("O");
                        locMastService.updateById(locMast1);
                    }
                }else {
                    BigDecimal subtract = BigDecimal.valueOf(locDetl.getAnfme()).subtract(BigDecimal.valueOf(combMat.getAnfme()));
                    locDetl.setAnfme(subtract.doubleValue());
                    locDetlService.updateById(locDetl);
                }
            }catch (Exception e){
                throw new CoolException("更新库存数据出错"+e.getMessage());
            }
        }
        return R.ok();
    }
    @Override
    @Transactional
    public R WarehouseOutV1(CombParam combParam, Long hostId) {
        //判断库位状态
        LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, combParam.getLocno()).eq(LocMast::getHostId,hostId).eq(LocMast::getWhsType,0L));
        if (Cools.isEmpty(locMast)){
            return R.error("该库位不存在");
        }
        if (!locMast.getLocSts().equals("P")){
            return R.error("该库位状态为:"+locMast.getLocSts()+",不满足并板途中拣选条件!!!");
        }
        //查询库存数据
        for (CombParam.CombMat combMat :combParam.getCombMats()){
            List<LocDetl> locDetlList = locDetlService.list(new LambdaQueryWrapper<LocDetl>()
                    .eq(LocDetl::getLocNo, combParam.getLocno())
                    .eq(LocDetl::getHostId, hostId)
//                    .eq(LocDetl::getZpallet, combMat.getZpallet())
                    .eq(LocDetl::getMatnr, combMat.getMatnr())
//                    .eq(LocDetl::getBatch, combMat.getBatch())
            );
            if (locDetlList.isEmpty()){
                return R.error("未查询到库存数据");
            }
            if (locDetlList.size()>1){
                return R.error("库存数据大于1条,为保证数据准确性,请用正常流程出库!!!");
            }
            LocDetl locDetl = locDetlList.get(0);
            if (combMat.getAnfme() > locDetl.getAnfme()){
                return R.error("拣选数量错误,超出库存数量");
            }
            if (!Cools.isEmpty(combParam.getOrderNo())){
                Order order = orderService.selectByNo(combParam.getOrderNo(), hostId);
                if (Cools.isEmpty(order)){
                    continue;
                }
                if (order.getSettle() == 1){
                    orderService.updateSettle(order.getId(), 2L, 9527L, hostId);
                }
                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), combMat.getMatnr(), combMat.getBatch(),hostId);
                if (Cools.isEmpty(orderDetl)){
                    continue;
                }
                if (orderDetl.getAnfme() < (orderDetl.getWorkQty()+combMat.getAnfme())){
                    throw new CoolException("拣选数量出错,订单剩余出库数量小于已出库数量与将拣选数量之和!!!");
                }
                // 修改订单明细作业数量
                if (!orderDetlService.increaseWorkQtyByOrderNo(combParam.getOrderNo(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), hostId)) {
                    throw new CoolException("修改单据明细工作数量失败");
                }
                // 修改订单明细完成数量
                if (!orderDetlService.increase(order.getId(), hostId, combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme())) {
                    throw new CoolException("修改单据明细完成数量失败");
                }
                // 修改订单状态 作业中 ===>> 已完成
                orderService.checkComplete(combParam.getOrderNo(), hostId);
            }
            try {
                //处理库存信息
                if (combMat.getAnfme().equals(locDetl.getAnfme())){
                    //库存相等删除数据
                    locDetlService.removeById(locDetl);
                    int count = locDetlService.count(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo,combParam.getLocno()).eq(LocDetl::getHostId, hostId));
                    if (count == 0){
                        LocMast locMast1 = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, combParam.getLocno()).eq(LocMast::getHostId, hostId));
                        locMast1.setLocSts("O");
                        locMastService.updateById(locMast1);
                    }
                } else {
                    BigDecimal subtract = BigDecimal.valueOf(locDetl.getAnfme()).subtract(BigDecimal.valueOf(combMat.getAnfme()));
                    locDetl.setAnfme(subtract.doubleValue());
                    locDetlService.updateById(locDetl);
                }
            }catch (Exception e){
                throw new CoolException("更新库存数据出错"+e.getMessage());
            }
        }
        return R.ok();
    }
}