自动化立体仓库 - WMS系统
1
ZY
2024-09-26 4df80cad47f22a930435835e7f7135bd60672cd8
src/main/java/com/zy/asrs/service/impl/PlaServiceImpl.java
@@ -2,8 +2,10 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.OrderDetl;
import com.zy.asrs.entity.Pla;
@@ -27,8 +29,8 @@
    @Autowired
    private PlaQtyService plaQtyService;
    public Pla selectByBatchAndPackageNo(String batch, String packageNo) {
        return this.selectOne(new EntityWrapper<Pla>().eq("batch",batch).eq("package_no",packageNo));
    public Pla selectByBatchAndPackageNo(String batch, Integer packageNo, String brand) {
        return this.selectOne(new EntityWrapper<Pla>().eq("batch",batch).eq("package_no",packageNo).eq("brand",brand).eq(false,"status","全部出库"));
    }
    @Override
@@ -65,7 +67,7 @@
            }
            //需要减去此次出库预览其他订单需出库的数量
            for (PlaQty plaQty : plaQties){
                if(Cools.eq(plaQty.getBatch(),pla.getBatch()) && Cools.eq(plaQty.getPackageNo(),pla.getPackageNo())){
                if(Cools.eq(plaQty.getBatch(),pla.getBatch()) && plaQty.getPackageNo() == pla.getPackageNo()){
                    weightAnfme -= plaQty.getQtyAnfme();
                }
            }
@@ -84,20 +86,22 @@
        }
        if(anfme > 0){
            PlaQty plaQty = new PlaQty(orderDetl.getBatch(),orderDetl.getBrand(),orderDetl.getId(),orderDetl.getOrderId(),orderDetl.getOrderNo(),anfme,null,new Date());
            PlaQty plaQty = new PlaQty(orderDetl.getBatch(),Integer.parseInt(orderDetl.getBrand()),orderDetl.getId(),orderDetl.getOrderId(),orderDetl.getOrderNo(),anfme,null,new Date());
            plaQties.add(plaQty);
        }
    }
    //退回
    @Transactional
    public void returned(List<PlaQty> plaQties, User user) {
        plaQties.forEach(plaQty -> {
            PlaQty plaQtyOut = plaQtyService.selectById(plaQty.getId());
            if(Cools.isEmpty(plaQtyOut.getReturned())){
            if(Cools.isEmpty(plaQtyOut.getReturned()) || plaQtyOut.getReturned() == 0){
                plaQtyOut.setReturned(plaQty.getOrderWeight());
            }else {
                plaQtyOut.setReturned(plaQty.getOrderWeight()+plaQtyOut.getReturned());
                throw new CoolException("该包物料已退回");
                //plaQtyOut.setReturned(plaQty.getOrderWeight()+plaQtyOut.getReturned());
            }
            plaQtyService.updateById(plaQtyOut);
@@ -108,6 +112,7 @@
            plaQtyReturned.setLocNo(plaQtyOut.getLocNo());
            plaQtyReturned.setOrderNo(plaQtyOut.getOrderNo());
            plaQtyReturned.setPakoutTime(Utils.getDateStr(new Date()));
            plaQtyReturned.setBrand(plaQty.getBrand());
            plaQtyReturned.setOrderWeight(plaQty.getOrderWeight());
            plaQtyReturned.setTransfer("退回入库");
            plaQtyReturned.setHandlerBy(user.getUsername());
@@ -116,7 +121,7 @@
            plaQtyService.insert(plaQtyReturned);
            //直接更新pla的库存
            Pla pla = this.selectByBatchAndPackageNo(plaQty.getBatch(), plaQty.getPackageNo());
            Pla pla = this.selectByBatchAndPackageNo(plaQty.getBatch(), plaQty.getPackageNo(),plaQty.getBrand());
            //pla.setStatus(GlobleParameter.PLA_STATUS_0);
            pla.setModifyTime(new Date());
@@ -124,7 +129,8 @@
            pla.setStatus(GlobleParameter.PLA_STATUS_1);
            this.updateById(pla);
            SaasUtils.insertLog(0,pla.getLocNo(),pla.getBatch()+","+pla.getPackageNo(),plaQty.getOrderWeight(),user.getUsername());
            SaasUtils.insertLog(0,pla.getLocNo(),pla.getBrand(),plaQty.getOrderWeight(),user.getUsername(),
                    null,pla.getBatch(),pla.getPackageNo(),pla.getOwner(),pla.getWorkshop(),null);
        });
    }
@@ -147,4 +153,35 @@
    public List<Pla> selectToHistory() {
        return this.selectList(new EntityWrapper<Pla>().eq("status",GlobleParameter.PLA_STATUS_4));
    }
    @Override
    public Page<Pla> getStockStatisAll(Page<Pla> page) {
        List<Pla> plaList;
        Date stime = null;
        Date etime = null;
        Object create_time = page.getCondition().get("create_time");
        Object brand = page.getCondition().get("brand");
        Object status = page.getCondition().get("status");
        String createTime = create_time == null ? null : create_time.toString();
        if(!Cools.isEmpty(createTime)){
            String[] dates = createTime.split(" - ");
            stime = DateUtils.convert(dates[0]);
            etime = DateUtils.convert(dates[1]);
        }
        plaList=baseMapper.getStockStatisAll(brand == null ? null:brand.toString(), status == null ? null:status.toString(),  stime,etime);
        double weightSum = plaList.stream().mapToDouble(Pla::getWeight).sum();
        // 最后一条记录仅供合计重量信息展示
        Pla pla = new Pla();
        pla.setBrand("合计");
        pla.setMatnr("");
        pla.setWeight(weightSum);
        plaList.add(pla);
        page.setRecords(plaList);
        page.setTotal(0);
        return page;
    }
}