| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasAgv; |
| | | 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; |
| | | import com.zy.asrs.service.WaitPakinService; |
| | | 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; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.IOException; |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 移动端服务核心类 |
| | | * Created by vincent on 2020/6/28 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class MobileServiceImpl implements MobileService { |
| | | |
| | | @Value("${agv.url}") |
| | | private String agvUrl; |
| | | @Autowired |
| | | private MatCodeService matCodeService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private BasAgvService basAgvService; |
| | | @Autowired |
| | | private ErpSqlServer erpSqlServer; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | waitPakin.setModiUser(userId); |
| | | waitPakin.setModiTime(new Date()); |
| | | VersionUtils.setWaitPakIn(waitPakin, matCode); |
| | | // waitPakin.setMatnr(matCode.getMatNo()+"|"+combMat.getMnemonic()); //产品编码|生产单号 |
| | | // waitPakin.setBname(matCode.getMatNo()); |
| | | // 如果生成单号不为空插入生产单号 |
| | | if (!Cools.isEmpty(combMat.getMnemonic())) { |
| | | waitPakin.setMnemonic(combMat.getMnemonic()); |
| | | } |
| | | |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存数据失败"); |
| | | } |
| | | } |
| | | // 小车入库搬运命令 ---------------------------------------------------- |
| | | if (!Cools.isEmpty(param.getAgvSite())) { |
| | | // 判断是否有空闲小车 |
| | | 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("没有空闲小车"); |
| | | } |
| | | |
| | | } |
| | | // 判断无通知单号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,Fflag_rw) 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, 1)"; |
| | | ErpSql = MessageFormat.format(ErpSql, maxKey - 1, es.getCount(), es.getCount(), es.getCount(), es.getMatNo(), es.getCount(), es.getMnemonic()); |
| | | erpSqlServer.update(ErpSql); |
| | | } |
| | | } |
| | | |
| | | } else { |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | |
| | | |
| | | 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, Fflag_rw) 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, 1)"; |
| | | ErpSql = MessageFormat.format(ErpSql, maxKey - 1, es.getCount(), es.getCount(), es.getCount(), es.getMatNo(), es.getCount(), es.getMnemonic()); |
| | | erpSqlServer.update(ErpSql); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | |
| | | |
| | | } |
| | | |
| | | // 小车入库搬运命令 ---------------------------------------------------- |
| | | if (!Cools.isEmpty(param.getCombMats()) && !Cools.isEmpty(param.getAgvSite())) { |
| | | // 判断是否有空闲小车 |
| | | 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("没有空闲小车"); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | } |
| | | // 小车入库搬运命令 ---------------------------------------------------- |
| | | if (!Cools.isEmpty(param.getCombMats()) && !Cools.isEmpty(param.getAgvSite())) { |
| | | // 判断是否有空闲小车 |
| | | 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("没有空闲小车"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |