#
18516761980
2022-08-02 33cc8de8a39b88d619cce6e80f13564a85e5dce0
src/main/java/com/zy/asrs/service/impl/OutStockServiceImpl.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.core.common.Cools;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.StockOutParam;
@@ -49,6 +50,8 @@
    private LocNormalService locNormalService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private OutStockService outStockService;
    @Override
    public Page<OutStockBillEntry> queryOutStock(Page<OutStockBillEntry> page) {
@@ -70,13 +73,13 @@
            if (tempLocList.size() > 0) {
                for (Integer j = 0; j < tempLocList.size(); j ++) {
                    locNum = locNum.add(new BigDecimal(tempLocList.get(j).getAnfme()));
                    /* 计算需要的数量,符合数量后结束循环 */
                    if (needNum.compareTo(locNum) == 1) {
//                    /* 计算需要的数量,符合数量后结束循环 */
//                    if (needNum.compareTo(locNum) == 1) {
                        locList.add(tempLocList.get(j));
                    } else {
                        locList.add(tempLocList.get(j));
                        break;
                    }
//                    } else {
//                        locList.add(tempLocList.get(j));
//                        break;
//                    }
                }
            }
        }
@@ -94,11 +97,9 @@
        String sql = "update OutStockbillEntry set FAuxCommitQty = (FAuxCommitQty + {0,number,#}) where 1=1 and Fnumber = ''{1}'' and FInterID = {2,number,#}";
        sql = MessageFormat.format(sql, increment, Fnumber, FInterID);
        if (jdbcTemplate.update(sql) > 0) {
            log.info("step 1 ======>> {}", sql);
            sql = "select * from OutStockbillEntry where 1=1 and Fnumber = ''{0}'' and FInterID = {1,number,#}";
            sql = MessageFormat.format(sql, Fnumber, FInterID);
            List<OutStockBillEntry> select = jdbcTemplate.queryForList(sql, OutStockBillEntry.class);
            log.info("step 2 ======>> {}", sql);
            List<OutStockBillEntry> select = this.selectList(new EntityWrapper<OutStockBillEntry>().eq("Fnumber", Fnumber).eq("FInterID", FInterID));
            OutStockBillEntry outStockBillEntry = select.get(0);
            boolean complete = false;
            if (outStockBillEntry.getFQty().compareTo(BigDecimal.ZERO) == 1) {
@@ -111,9 +112,12 @@
                }
            }
            if (complete) {
                if (!completeCPakOut(FBillNo)) {
                    log.error("{}出库单标记完成失败", FBillNo);
                }
                List<OutStockBillEntry> select1 = this.selectList(new EntityWrapper<OutStockBillEntry>().eq("FInterID", FInterID));
               if(select1.size()<=1){
                    if (!completeCPakOut(FBillNo) )  {
                        log.error("{}出库单标记完成失败", FBillNo);
                    }
               }
            }
            return true;
        } else {
@@ -125,19 +129,45 @@
    private boolean completeCPakOut(String FBillNo){
        String sql = "update OutStockbill set Fflag_finish = 1 where FBillNo = ''{0}''";
        sql = MessageFormat.format(sql, FBillNo);
        log.info("step 3 ======>> {}", sql);
        return jdbcTemplate.update(sql) > 0;
    }
    @Override
    @Transactional
    public void startupFullTakeStore(StockOutParam param, Long userId) {
        //判断出库熟练是否大于库存数量
        for (StockOutParam.LocDetl detl : param.getLocDetls()) {
//            LocDetl locDetl = locDetlService.selectById(detl.getLocNo());
            LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no",detl.getLocNo()));
            if(locDetl != null){
                if(detl.getCount() > locDetl.getAnfme()){
                    throw new CoolException("出库数量超过了库存数量[locNo=" + detl.getLocNo() + "]");
                }
            }
        }
        //判断出库数量是否大于通知档数量
        Integer FInterI = outStockService.queryOutStockFInterID(param.getFbillNo()); // 获取出库单主表主键
        List<OutStockBillEntry>  entryList = outStockService.selectList(new EntityWrapper<OutStockBillEntry>().eq("FInterID",FInterI));
        for(OutStockBillEntry one : entryList){
            String Fnumber = one.getFnumber();
            BigDecimal qty = new BigDecimal(0);
            for (StockOutParam.LocDetl detl : param.getLocDetls()) {
                if(detl.getMatnr().equals(Fnumber)){
                    qty = qty.add(BigDecimal.valueOf(detl.getCount()));
                }
            }
            if(qty.compareTo(one.getFQty()) == 1){
                throw new CoolException("出库数量大于通知档数量[FInterID=" + FInterI + ",Fnumber=" + Fnumber + "]");
            }
        }
        // 目标站点状态检测
        BasDevp staNo = basDevpService.checkSiteStatus(param.getOutSite());
        // 获取库位明细
        List<LocDetlDto> locDetlDtos = new ArrayList<>();
        for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount())) {
            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount())
                && paramLocDetl.getCount() > 0) {
                LocDetl sqlParam = new LocDetl();
                sqlParam.setLocNo(paramLocDetl.getLocNo());
                sqlParam.setMatnr(paramLocDetl.getMatnr());
@@ -175,11 +205,15 @@
        // 生成工作档
        for (OutLocDto dto : dtos) {
            // 判断入出库类型:101.全板出库 or 103.拣料出库
            if (ioType == null) {
//            if (ioType == null) {
                ioType = dto.isAll() ? 101 : 103;
            }
//            }
            // 获取库位
            LocMast locMast = locMastService.selectById(dto.getLocNo());
            //如果托盘条码为空,就不能进行拣料,无法再入库
            if(ioType==103 && null!=locMast && Cools.isEmpty(locMast.getBarcode())){
                throw new CoolException("库位没有托盘码,无法拣料作业===>>" + locMast.getLocNo());
            }
            // 获取路径
            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                    .eq("type_no", ioType)
@@ -241,6 +275,16 @@
                if (!wrkDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作档明细失败");
                }
                //更新出库通知档Famount字段,防止重复下发任务 2021-09-28 TQS ADD
                Integer FInterI = outStockService.queryOutStockFInterID(fbillNo); // 获取出库单主表主键
                Wrapper wrapper1 = new EntityWrapper<OutStockBillEntry>().eq("FInterID",FInterI).eq("Fnumber",detlDto.getLocDetl().getMatnr());
                OutStockBillEntry outStockBillEntry = outStockService.selectOne(wrapper1);
                outStockBillEntry.setFAmount(outStockBillEntry.getFAmount().add(BigDecimal.valueOf(anfme)));  //借用famount字段,控制下发出库任务数量
                outStockBillEntry.setFAuxQty(outStockBillEntry.getFAuxQty().subtract(BigDecimal.valueOf(anfme)));
                if(!outStockService.update(outStockBillEntry,wrapper1)){
                    throw new CoolException("更新出库通知档明细FAmount失败[FInterID="+FInterI+",Fnumber="+detlDto.getLocDetl().getMatnr()+"]");
                }
            }
            // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
            locMast = locMastService.selectById(dto.getLocNo());