#
18516761980
2021-09-29 15c8f00ab3a1e3d2d96b56bae0ec11efedd60231
src/main/java/com/zy/asrs/controller/OutStockController.java
@@ -1,25 +1,66 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.LocNormal;
import com.zy.asrs.entity.LocNormalLog;
import com.zy.asrs.entity.param.LocNormalStockOutParam;
import com.zy.asrs.entity.param.StockOutParam;
import com.zy.asrs.service.LocNormalLogService;
import com.zy.asrs.service.LocNormalService;
import com.zy.asrs.service.OutStockService;
import com.zy.asrs.service.WorkService;
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.service.erp.ErpService;
import com.zy.common.service.erp.entity.OutStockBill;
import com.zy.common.service.erp.entity.OutStockBillEntry;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.implementation.bytecode.Throw;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
public class OutStockController extends BaseController {
    @Autowired
    private OutStockService outStockService;
    @Autowired
    private WorkService workService;
    @Autowired
    private LocNormalService locNormalService;
    @Autowired
    private ErpService erpService;
    @Autowired
    private LocNormalLogService locNormalLogService;
    /**
     *
     * @param curr
     * @param limit
     * @param param
     * @return
     */
    @RequestMapping(value = "/outStock/query/list")
    @ManagerAuth
    public R outStockQueryList(@RequestParam(defaultValue = "1")Integer curr,
@@ -27,4 +68,123 @@
                          @RequestParam Map<String, Object> param){
        return R.ok(outStockService.queryOutStock(toPage(curr, limit, param, OutStockBillEntry.class)));
    }
    /**
     * 检索符合通知单的立库库存物料
     * @param fbillNo
     * @return
     */
    @RequestMapping(value = "/outStock/query/locList")
    @ManagerAuth
    public R queryMatWithLoc(String fbillNo) {
        List<LocDetl> list = outStockService.queryMatWithLoc(fbillNo);
        return R.ok(list);
    }
    @RequestMapping(value = "/plate/outStock/start")
    @ManagerAuth(memo = "出库作业")
    public R fullStoreTakeStart(@RequestBody StockOutParam param) {
        outStockService.startupFullTakeStore(param, getUserId());
        return R.ok("出库启动成功");
    }
    /**
     * 检索符合通知单的平仓库存物料
     * @param fbillNo
     * @return
     */
    @RequestMapping(value = "/outStock/query/locNormalList")
    @ManagerAuth
    public R queryMatWithLocNormal(String fbillNo, String mnemonic) {
        List<LocNormal> list = locNormalService.queryLocNorlMatnr(fbillNo, mnemonic);
        return R.ok(list);
    }
    /**
     * 平仓对接erp出库
     * @param
     * @return
     */
    @RequestMapping(value = "/outStock/locNormal")
    @ManagerAuth
    @Transactional
    public R outStockLocNormal(@RequestBody LocNormalStockOutParam param) {
        Long modiUser = getUserId();
        Date modiTime = new Date();
        Integer FInterI = outStockService.queryOutStockFInterID(param.getSupplier()); // 获取出库单主表主键
        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 (LocNormal locNormals:param.getList()) {
                if(locNormals.getMatnr().equals(Fnumber)){
                    qty = qty.add(locNormals.getAnfme());
                }
            }
            if(qty.compareTo(one.getFQty()) == 1){
                return R.error("出库数量大于通知档数量[FInterID=" + FInterI + ",Fnumber=" + Fnumber + "]");
            }
        }
        for (LocNormal locNormals:param.getList()) {
            LocNormal locNormal = locNormalService.selectOne(new EntityWrapper<LocNormal>().eq("id", locNormals.getId()));
            if (!Cools.isEmpty(locNormal)) {
                if (locNormal.getAnfme().compareTo(locNormals.getAnfme()) == 1) {
                    LocNormal logLocNormal = new LocNormal();
                    logLocNormal.setAnfme(locNormals.getAnfme());
                    logLocNormal.setMatnr(locNormal.getMatnr());
                    logLocNormal.setMaktx(locNormal.getMaktx());
                    logLocNormal.setLgnum(locNormal.getLgnum());
                    logLocNormal.setType(locNormal.getType());
                    logLocNormal.setMnemonic(locNormal.getMnemonic());
                    logLocNormal.setSupplier(locNormal.getSupplier());
                    logLocNormal.setWarehouse(locNormal.getWarehouse());
                    logLocNormal.setWarehouseName(locNormal.getWarehouseName());
                    logLocNormal.setBrand(locNormal.getBrand());
                    logLocNormal.setAltme(locNormal.getAltme());
                    logLocNormal.setBname(locNormal.getBname());
                    logLocNormal.setMemo(locNormal.getMemo());
                    logLocNormal.setState("2");
                    // 生成出库记录
//                    locNormalService.insert(logLocNormal);
                    // 更新原先平仓记录
                    locNormalService.updateLocNormal(locNormal.getMatnr(), locNormal.getAnfme().subtract(locNormals.getAnfme()), modiUser, modiTime, locNormal.getId());
                    // 生成平仓出入库记录
                    LocNormalLog locLog = new LocNormalLog();
                    VersionUtils.setLocNormalLog(locLog, locNormals);
                    locLog.setAnfme(locNormals.getAnfme().doubleValue());
                    locLog.setIoType(2);
                    locLog.setCreateTime(new Date());
                    locLog.setCreateUser(modiUser);
                    if (!locNormalLogService.insert(locLog)) {
                        String logStr = JSON.toJSONString(locLog);
                        log.info("平仓出库记录插入失败,数据:" + logStr);
                    }
                } else {
                    // 把对应物料平仓库存出库
                    locNormalService.outLocNormal(locNormals.getMatnr(), modiUser, modiTime, locNormals.getId());
                }
            }
//            Integer FInterI = outStockService.queryOutStockFInterID(param.getSupplier()); // 获取出库单主表主键
            //更新ASRS出库通知档明细出库数量
            Wrapper wrapper = new EntityWrapper<OutStockBillEntry>().eq("FInterID",FInterI).eq("Fnumber",locNormals.getMatnr());
            OutStockBillEntry outStockBillEntry = outStockService.selectOne(wrapper);
            outStockBillEntry.setFAuxCommitQty(outStockBillEntry.getFAuxCommitQty().add(locNormals.getAnfme()));
            outStockBillEntry.setFAmount(outStockBillEntry.getFAmount().add(locNormals.getAnfme()));  //借用amount字段,控制下发出库任务数量
            if(!outStockService.update(outStockBillEntry,wrapper)){
                throw new CoolException("更新出库通知档明细失败[FInterID="+FInterI+",Fnumber="+locNormals.getMatnr()+"]");
            }
            // erp中间表更新数据
            if (!erpService.incrementCPakOut(FInterI, locNormals.getMatnr(), locNormals.getAnfme().doubleValue(), param.getSupplier())) {
                log.error("更新ERP成品出库数据[matnr={},FBillNo={}]失败", locNormals.getMatnr(), param.getSupplier());
            }
        }
        return R.ok("平仓出库成功");
    }
}