#
18516761980
2021-11-05 acdc4b3427cbd2a6dc811aed202fbd3e9c309d69
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;
@@ -16,13 +17,17 @@
import com.zy.common.service.CommonService;
import com.zy.common.service.erp.entity.OutStockBillEntry;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.*;
@Slf4j
@Service("outStockService")
public class OutStockServiceImpl extends ServiceImpl<OutStockMapper, OutStockBillEntry> implements OutStockService{
    // 工作号生成规则默认类型
@@ -43,6 +48,10 @@
    private WrkDetlService wrkDetlService;
    @Autowired
    private LocNormalService locNormalService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private OutStockService outStockService;
    @Override
    public Page<OutStockBillEntry> queryOutStock(Page<OutStockBillEntry> page) {
@@ -82,9 +91,73 @@
       return baseMapper.queryOutStockFInterID(supplier);
    }
    /* 成品增量出库 */
    @Override
    public boolean incrementCPakOut(Integer FInterID, String Fnumber, Double increment, String FBillNo) {
        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) {
            sql = "select * from OutStockbillEntry where 1=1 and Fnumber = ''{0}'' and FInterID = {1,number,#}";
            sql = MessageFormat.format(sql, Fnumber, FInterID);
            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) {
                if (outStockBillEntry.getFAuxCommitQty().compareTo(outStockBillEntry.getFQty()) > -1) {
                    complete = true;
                }
            } else {
                if (outStockBillEntry.getFAuxCommitQty().compareTo(outStockBillEntry.getFAuxQty()) > -1) {
                    complete = true;
                }
            }
            if (complete) {
                if (!completeCPakOut(FBillNo)) {
                    log.error("{}出库单标记完成失败", FBillNo);
                }
            }
            return true;
        } else {
            return false;
        }
    }
    /* 成品出库单标记完成 */
    private boolean completeCPakOut(String FBillNo){
        String sql = "update OutStockbill set Fflag_finish = 1 where FBillNo = ''{0}''";
        sql = MessageFormat.format(sql, FBillNo);
        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());
        // 获取库位明细
@@ -194,6 +267,15 @@
                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)));  //借用amount字段,控制下发出库任务数量
                if(!outStockService.update(outStockBillEntry,wrapper1)){
                    throw new CoolException("更新出库通知档明细FAmount失败[FInterID="+FInterI+",Fnumber="+detlDto.getLocDetl().getMatnr()+"]");
                }
            }
            // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
            locMast = locMastService.selectById(dto.getLocNo());