#
luxiaotao1123
2021-08-03 67da83c698e77ccf178669a31e4bd3a4e8fc1ca7
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -10,6 +10,8 @@
import com.zy.asrs.entity.MatCode;
import com.zy.asrs.entity.WaitPakin;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.entity.param.ERPselectParam;
import com.zy.asrs.entity.param.FullStoreParam;
import com.zy.asrs.service.BasAgvService;
import com.zy.asrs.service.MatCodeService;
import com.zy.asrs.service.MobileService;
@@ -17,6 +19,7 @@
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.model.agv.AgvCommand;
import com.zy.common.model.agv.AgvResult;
import com.zy.common.service.erp.ErpSqlServer;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,7 +28,9 @@
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Date;
import java.util.List;
/**
 * 移动端服务核心类
@@ -43,6 +48,8 @@
    private WaitPakinService waitPakinService;
    @Autowired
    private BasAgvService basAgvService;
    @Autowired
    private ErpSqlServer erpSqlServer;
    @Override
    @Transactional
@@ -86,29 +93,46 @@
                }
                // 小车入库搬运命令 ----------------------------------------------------
                if (!Cools.isEmpty(param.getAgvSite())) {
                    BasAgv idleAgv = basAgvService.selectIdleAgv();
                    AgvCommand command = new AgvCommand();
                    command.setAgvId(idleAgv.getAgvId());
                    command.setInterCode(basAgvService.getAgvWorkNo());
                    command.setBeginLoc(String.valueOf(param.getAgvSite()));
                    command.setEndLoc("1088");
                    log.info(JSON.toJSONString(command));
                    String result;
                    try {
                        result = new HttpHandler.Builder()
                                .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                                .setJson(JSON.toJSONString(command))
                                .build()
                                .doPost();
                    } catch (IOException e) {
                        e.printStackTrace();
                        throw new CoolException("访问AGV接口失败");
                    // 判断是否有空闲小车
                    if (basAgvService.haveIdleAgv()) {
                        AgvCommand command = new AgvCommand();
                        command.setAgvId(0);
                        command.setInterCode(basAgvService.getAgvWorkNo());
                        command.setBeginLoc(String.valueOf(param.getAgvSite()));
                        command.setEndLoc("1088");
                        log.info(JSON.toJSONString(command));
                        String result;
                        try {
                            result = new HttpHandler.Builder()
                                    .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                                    .setJson(JSON.toJSONString(command))
                                    .build()
                                    .doPost();
                        } catch (IOException e) {
                            e.printStackTrace();
                            throw new CoolException("访问AGV接口失败");
                        }
                        AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                        log.info(JSON.toJSONString(agvResult));
                        if (!agvResult.getResult()) {
                            log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                            throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                        }
                    } else {
                        throw new CoolException("没有空闲小车");
                    }
                    AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                    log.info(JSON.toJSONString(agvResult));
                    if (!agvResult.getResult()) {
                        log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                        throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                }
                // 判断无通知单号supplier的入库数据,CPICMO插入数据
                List<CombParam.CombMat> erpMatList = param.getCombMats();
                for (CombParam.CombMat es : erpMatList) {
                    if (Cools.isEmpty(es.getSupplier())) {
                        String maxKeySql = "select min(FInterID) as num from CPICMO";
                        List<ERPselectParam> maxKeyList = erpSqlServer.select(maxKeySql, ERPselectParam.class);
                        Integer maxKey = maxKeyList.get(0).getNum();
                        String ErpSql = "insert into CPICMO(FBrNo, FSourceBillNo, FBillNo, FTranType, FStatus, FMRP, FItemID, FQty, FCommitQty, FSourceEntryID, FClosed, FUnitID, FAuxCommitQty, FCancellation, FQtyFinish, FQtyScrap, FQtyLost, FAuxQtyFinish, FAuxQtyScrap, FAuxQtyLost, FMrpClosed, FBomInterID, FQtyPass, FAuxQtyPass, FQtyBack, FAuxQtyBack, FFinishTime, FReadyTIme, FPowerCutTime, FFixTime, FWaitItemTime, FWaitToolTime, FTaskID, FWorkTypeID, FCostObjID, FStockQty, FAuxStockQty, FSuspend, FReleasedQty, FReleasedAuxQty, FUnScheduledQty, FUnScheduledAuxQty, FSubEntryID, FScheduleID, FPlanOrderInterID, FProcessPrice, FProcessFee, FGMPBatchNo, FGMPCollectRate, FGMPItemBalance, FGMPBulkQty, FCustID, FMRPLockFlag, FHandworkClose, FInHighLimit, FInHighLimitQty, FInLowLimit, FInLowLimitQty, FChangeTimes, FCheckCommitQty, FAuxCheckCommitQty, FPlanConfirmed, FPlanMode, FMTONo, FPrintCount, FFinClosed, FStockFlag, FStartFlag, FVchBillNo, FVchInterID, FCardClosed, FHRReadyTime, FSourceTranType, FSourceInterId, FInterID, FAuxQty, FAuxInHighLimitQty, FAuxInLowLimitQty, Fnumber, FWorkShop) values (0, ''{6}'', '0', 85, 0, 1052, 0, 0, 0, 0, 0, 250, {5,number,#}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14036, '0', 0, 0, 14215, 0, '0', 0, 1059, 0, 0, 0, 0, {0,number,#}, {1,number,#}, {2,number,#}, {3,number,#}, ''{4}'', 11378)";
                        ErpSql = MessageFormat.format(ErpSql, maxKey - 1, es.getCount(), es.getCount(), es.getCount(), es.getMatNo(), es.getCount(), es.getMnemonic());
                        erpSqlServer.update(ErpSql);
                    }
                }
@@ -135,6 +159,18 @@
                if (!waitPakinService.insert(waitPakin)) {
                    throw new CoolException("保存数据失败");
                }
                // 判断无通知单号supplier的入库数据,CPICMO插入数据
                List<CombParam.CombMat> erpMatList = param.getCombMats();
                for (CombParam.CombMat es : erpMatList) {
                    if (Cools.isEmpty(es.getSupplier())) {
                        String maxKeySql = "select min(FInterID) as num from CPICMO";
                        List<ERPselectParam> maxKeyList = erpSqlServer.select(maxKeySql, ERPselectParam.class);
                        Integer maxKey = maxKeyList.get(0).getNum();
                        String ErpSql = "insert into CPICMO(FBrNo, FSourceBillNo, FBillNo, FTranType, FStatus, FMRP, FItemID, FQty, FCommitQty, FSourceEntryID, FClosed, FUnitID, FAuxCommitQty, FCancellation, FQtyFinish, FQtyScrap, FQtyLost, FAuxQtyFinish, FAuxQtyScrap, FAuxQtyLost, FMrpClosed, FBomInterID, FQtyPass, FAuxQtyPass, FQtyBack, FAuxQtyBack, FFinishTime, FReadyTIme, FPowerCutTime, FFixTime, FWaitItemTime, FWaitToolTime, FTaskID, FWorkTypeID, FCostObjID, FStockQty, FAuxStockQty, FSuspend, FReleasedQty, FReleasedAuxQty, FUnScheduledQty, FUnScheduledAuxQty, FSubEntryID, FScheduleID, FPlanOrderInterID, FProcessPrice, FProcessFee, FGMPBatchNo, FGMPCollectRate, FGMPItemBalance, FGMPBulkQty, FCustID, FMRPLockFlag, FHandworkClose, FInHighLimit, FInHighLimitQty, FInLowLimit, FInLowLimitQty, FChangeTimes, FCheckCommitQty, FAuxCheckCommitQty, FPlanConfirmed, FPlanMode, FMTONo, FPrintCount, FFinClosed, FStockFlag, FStartFlag, FVchBillNo, FVchInterID, FCardClosed, FHRReadyTime, FSourceTranType, FSourceInterId, FInterID, FAuxQty, FAuxInHighLimitQty, FAuxInLowLimitQty, Fnumber, FWorkShop) values (0, ''{6}'', '0', 85, 0, 1052, 0, 0, 0, 0, 0, 250, {5,number,#}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14036, '0', 0, 0, 14215, 0, '0', 0, 1059, 0, 0, 0, 0, {0,number,#}, {1,number,#}, {2,number,#}, {3,number,#}, ''{4}'', 11378)";
                        ErpSql = MessageFormat.format(ErpSql, maxKey - 1, es.getCount(), es.getCount(), es.getCount(), es.getMatNo(), es.getCount(), es.getMnemonic());
                        erpSqlServer.update(ErpSql);
                    }
                }
            }
        } else {
@@ -196,30 +232,35 @@
            // 小车入库搬运命令 ----------------------------------------------------
            if (!Cools.isEmpty(param.getCombMats()) && !Cools.isEmpty(param.getAgvSite())) {
                BasAgv idleAgv = basAgvService.selectIdleAgv();
                AgvCommand command = new AgvCommand();
                command.setAgvId(idleAgv.getAgvId());
                command.setInterCode(basAgvService.getAgvWorkNo());
                command.setBeginLoc(String.valueOf(param.getAgvSite()));
                command.setEndLoc("1088");
                log.info(JSON.toJSONString(command));
                String result;
                try {
                    result = new HttpHandler.Builder()
                            .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                            .setJson(JSON.toJSONString(command))
                            .build()
                            .doPost();
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new CoolException("访问AGV接口失败");
                // 判断是否有空闲小车
                if (basAgvService.haveIdleAgv()) {
                    AgvCommand command = new AgvCommand();
                    command.setAgvId(0);
                    command.setInterCode(basAgvService.getAgvWorkNo());
                    command.setBeginLoc(String.valueOf(param.getAgvSite()));
                    command.setEndLoc("1088");
                    log.info(JSON.toJSONString(command));
                    String result;
                    try {
                        result = new HttpHandler.Builder()
                                .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                                .setJson(JSON.toJSONString(command))
                                .build()
                                .doPost();
                    } catch (IOException e) {
                        e.printStackTrace();
                        throw new CoolException("访问AGV接口失败");
                    }
                    AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                    log.info(JSON.toJSONString(agvResult));
                    if (!agvResult.getResult()) {
                        log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                        throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                    }
                } else {
                    throw new CoolException("没有空闲小车");
                }
                AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                log.info(JSON.toJSONString(agvResult));
                if (!agvResult.getResult()) {
                    log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                    throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                }
            }
        }
@@ -301,30 +342,35 @@
        }
        // 小车入库搬运命令 ----------------------------------------------------
        if (!Cools.isEmpty(param.getCombMats()) && !Cools.isEmpty(param.getAgvSite())) {
            BasAgv idleAgv = basAgvService.selectIdleAgv();
            AgvCommand command = new AgvCommand();
            command.setAgvId(idleAgv.getAgvId());
            command.setInterCode(basAgvService.getAgvWorkNo());
            command.setBeginLoc(String.valueOf(param.getAgvSite()));
            command.setEndLoc("1088");
            log.info(JSON.toJSONString(command));
            String result;
            try {
                result = new HttpHandler.Builder()
                        .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                        .setJson(JSON.toJSONString(command))
                        .build()
                        .doPost();
            } catch (IOException e) {
                e.printStackTrace();
                throw new CoolException("访问AGV接口失败");
            // 判断是否有空闲小车
            if (basAgvService.haveIdleAgv()) {
                AgvCommand command = new AgvCommand();
                command.setAgvId(0);
                command.setInterCode(basAgvService.getAgvWorkNo());
                command.setBeginLoc(String.valueOf(param.getAgvSite()));
                command.setEndLoc("1088");
                log.info(JSON.toJSONString(command));
                String result;
                try {
                    result = new HttpHandler.Builder()
                            .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                            .setJson(JSON.toJSONString(command))
                            .build()
                            .doPost();
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new CoolException("访问AGV接口失败");
                }
                AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                log.info(JSON.toJSONString(agvResult));
                if (!agvResult.getResult()) {
                    log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                    throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                }
            } else {
                throw new CoolException("没有空闲小车");
            }
            AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
            log.info(JSON.toJSONString(agvResult));
            if (!agvResult.getResult()) {
                log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
            }
        }