|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.controller.CrnController; | 
|---|
|  |  |  | import com.zy.asrs.controller.OpenController; | 
|---|
|  |  |  | import com.zy.asrs.controller.SiteController; | 
|---|
|  |  |  | import com.zy.asrs.domain.dto.NotifyCustomDataDto; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.NotifyMsgType; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.RedisKeyType; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.TaskStatusType; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.WorkNoType; | 
|---|
|  |  |  | import com.zy.asrs.domain.param.CrnOperatorParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.TaskOverToWms; | 
|---|
|  |  |  | import com.zy.asrs.mapper.*; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.utils.CommandUtils; | 
|---|
|  |  |  | import com.zy.asrs.utils.CrnOperaUtils; | 
|---|
|  |  |  | import com.zy.asrs.utils.NotifyUtils; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | import com.zy.common.utils.HttpHandler; | 
|---|
|  |  |  | import com.zy.common.utils.News; | 
|---|
|  |  |  | import com.zy.common.utils.RedisUtil; | 
|---|
|  |  |  | import com.zy.core.CrnThread; | 
|---|
|  |  |  | import com.zy.core.DevpThread; | 
|---|
|  |  |  | import com.zy.core.cache.MessageQueue; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.core.model.CrnSlave; | 
|---|
|  |  |  | import com.zy.core.model.DevpSlave; | 
|---|
|  |  |  | import com.zy.core.model.Task; | 
|---|
|  |  |  | import com.zy.core.model.command.CommandPackage; | 
|---|
|  |  |  | import com.zy.core.model.command.CrnCommand; | 
|---|
|  |  |  | import com.zy.core.model.protocol.CrnProtocol; | 
|---|
|  |  |  | import com.zy.core.model.protocol.StaProtocol; | 
|---|
|  |  |  | import com.zy.core.properties.SlaveProperties; | 
|---|
|  |  |  | import com.zy.core.thread.BarcodeThread; | 
|---|
|  |  |  | import com.zy.core.thread.SiemensDevpThread; | 
|---|
|  |  |  | import com.zy.system.entity.Config; | 
|---|
|  |  |  | import com.zy.system.service.ConfigService; | 
|---|
|  |  |  | 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 org.springframework.transaction.interceptor.TransactionAspectSupport; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service("mainService") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public class MainServiceImpl { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final long COMMAND_TIMEOUT = 5 * 1000; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SlaveProperties slaveProperties; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WrkMastMapper wrkMastMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocMastService locMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskWrkService taskWrkService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ConfigService configService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private StaDescMapper staDescMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CommandInfoService commandInfoService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OpenServiceImpl openServiceImpl; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private StaDescService staDescService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApiLogService apiLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CommonService commonService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CrnOperaUtils crnOperaUtils; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NotifyUtils notifyUtils; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisUtil redisUtil; | 
|---|
|  |  |  | @Value("${wms.count}") | 
|---|
|  |  |  | private Integer maxCount; | 
|---|
|  |  |  | @Value("${wms.url}") | 
|---|
|  |  |  | private String wmsUrl; | 
|---|
|  |  |  | @Value("${wms.inboundTaskApplyPath}") | 
|---|
|  |  |  | private String inboundTaskApplyPath; | 
|---|
|  |  |  | @Value("${wms.movePath}") | 
|---|
|  |  |  | private String movePath; | 
|---|
|  |  |  | @Value("${wms.taskStatusFeedbackPath}") | 
|---|
|  |  |  | private String taskStatusFeedbackPath; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CrnController crnController; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SiteController siteController; | 
|---|
|  |  |  | @Value("${wms.TaskExecCallback}") | 
|---|
|  |  |  | private String taskExecCallback; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void generateStoreWrkFile() throws IOException, InterruptedException { | 
|---|
|  |  |  | public synchronized void generateStoreWrkFile1() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 根据输送线plc遍历 | 
|---|
|  |  |  | for (DevpSlave devp : slaveProperties.getDevp()) { | 
|---|
|  |  |  | // 遍历入库口 | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | staProtocol = staProtocol.clone(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Short workNo = staProtocol.getWorkNo(); | 
|---|
|  |  |  | Short stano = staProtocol.getStaNo(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 尺寸检测异常 | 
|---|
|  |  |  | boolean back = false; | 
|---|
|  |  |  | 
|---|
|  |  |  | errMsg = "扫码失败"; | 
|---|
|  |  |  | back = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 退回 | 
|---|
|  |  |  | if (back) { | 
|---|
|  |  |  | if (stano == inSta.getBackSta().shortValue()){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (workNo == 0 && stano == 0){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!staProtocol.isPakMk()){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                        News.warn("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg); | 
|---|
|  |  |  | staProtocol.setWorkNo(workNo); | 
|---|
|  |  |  | staProtocol.setStaNo(inSta.getBackSta().shortValue()); | 
|---|
|  |  |  | devpThread.setPakMk(staProtocol.getSiteId(), false); | 
|---|
|  |  |  | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol)); | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(workNo)); | 
|---|
|  |  |  | if (taskWrk != null) { | 
|---|
|  |  |  | taskWrk.setMemo(errMsg);//将错误码存入备注字段进行展示 | 
|---|
|  |  |  | taskWrkMapper.updateById(taskWrk); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 判断是否满足入库条件 | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isLoading() | 
|---|
|  |  |  | if (staProtocol.isAutoing() | 
|---|
|  |  |  | && staProtocol.isLoading() | 
|---|
|  |  |  | && staProtocol.isInEnable() | 
|---|
|  |  |  | && !staProtocol.isEmptyMk() && (workNo >= 0) | 
|---|
|  |  |  | && staProtocol.isPakMk()) { | 
|---|
|  |  |  | //                            && !staProtocol.isEmptyMk() | 
|---|
|  |  |  | && staProtocol.isPakMk() | 
|---|
|  |  |  | && (staProtocol.getWorkNo() == 9999 || staProtocol.getWorkNo() == 9998) | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | // 获取条码扫描仪信息 | 
|---|
|  |  |  | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); | 
|---|
|  |  |  | if (barcodeThread == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String barcode = barcodeThread.getBarcode(); | 
|---|
|  |  |  | if(!Cools.isEmpty(barcode) && !barcode.equals("99999999")) { | 
|---|
|  |  |  | // 请求wms接口,获取工作号和目标库位 | 
|---|
|  |  |  | ToWmsDTO toWmsDTO = new ToWmsDTO(barcode,staProtocol.getSiteId(),staProtocol.isHigh() ? 2 : 1); | 
|---|
|  |  |  | TaskWrk taskWrk1=taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode",barcode)); | 
|---|
|  |  |  | if(!Cools.isEmpty(taskWrk1)){ | 
|---|
|  |  |  | log.info("托盘码:"+barcode+"任务档存在"); | 
|---|
|  |  |  | if (Cools.isEmpty(barcode)) { | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), "入库信号满足,托盘码为空"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StaDesc staDesc2 = staDescService.selectOne(new EntityWrapper<StaDesc>().eq("type_no", 1).eq("stn_no", staProtocol.getSiteId())); | 
|---|
|  |  |  | List<TaskWrk> taskWrkOutList = taskWrkService.selectList(new EntityWrapper<TaskWrk>() | 
|---|
|  |  |  | .eq("crn_no", staDesc2.getCrnNo()) | 
|---|
|  |  |  | .eq("wrk_sts", 12) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (!taskWrkOutList.isEmpty()) { | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), "申请入库任务时发现正在执行的出库任务,入库任务被强制退回"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | staProtocol.setWorkNo(9997); | 
|---|
|  |  |  | staProtocol.setStaNo(inSta.getBackSta().shortValue()); | 
|---|
|  |  |  | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode)); | 
|---|
|  |  |  | if (taskWrk1 != null) { | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), "托盘码:" + barcode + "任务档存在"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | HashMap<String, Object> requestParam = new HashMap<>(); | 
|---|
|  |  |  | requestParam.put("barcode", barcode);//托盘码 | 
|---|
|  |  |  | requestParam.put("stationCode", inSta.getStaNo());//入库口 | 
|---|
|  |  |  | if (back) { | 
|---|
|  |  |  | requestParam.put("wcsStatus", 1);//失败 | 
|---|
|  |  |  | requestParam.put("wcsErrorMessage", errMsg);//失败原因 | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), errMsg); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | requestParam.put("wcsStatus", 0);//成功 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String response = "None"; | 
|---|
|  |  |  | Boolean success = false; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Object object = redisUtil.get(RedisKeyType.IN_TASK_LOCK.key + inSta.getStaNo()); | 
|---|
|  |  |  | if(object != null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | HashMap<String, Object> headParam = new HashMap<>(); | 
|---|
|  |  |  | headParam.put("Content-Type","application/json"); | 
|---|
|  |  |  | String response; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | // .setHeaders(headParam) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(inboundTaskApplyPath) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(toWmsDTO)) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(requestParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | apiLogService.save("wms请求入库货位接口" | 
|---|
|  |  |  | ,wmsUrl+inboundTaskApplyPath | 
|---|
|  |  |  | ,null | 
|---|
|  |  |  | ,"127.0.0.1" | 
|---|
|  |  |  | ,JSON.toJSONString(toWmsDTO) | 
|---|
|  |  |  | ,response | 
|---|
|  |  |  | ,true | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | log.info("入库请求参数{}" + JSON.toJSONString(toWmsDTO)); | 
|---|
|  |  |  | if (jsonObject.getInteger("code").equals(200) && !Cools.isEmpty(jsonObject.get("data").toString())) { | 
|---|
|  |  |  | GetWmsDto getWmsDto = JSON.parseObject(jsonObject.get("data").toString(), GetWmsDto.class); | 
|---|
|  |  |  | log.info(response); | 
|---|
|  |  |  | redisUtil.set(RedisKeyType.IN_TASK_LOCK.key + inSta.getStaNo(), "lock", 5); | 
|---|
|  |  |  | if (jsonObject.getInteger("code") == 200) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查看该库位是否为空库位 | 
|---|
|  |  |  | LocMast locMast=locMastService.selectOne(new EntityWrapper<LocMast>() | 
|---|
|  |  |  | .eq("loc_sts","O") | 
|---|
|  |  |  | .eq("loc_no",getWmsDto.getLocNo())); | 
|---|
|  |  |  | if(Cools.isEmpty(locMast)){ | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | HashMap<String, Object> headParam1 = new HashMap<>(); | 
|---|
|  |  |  | headParam1.put("taskNo",getWmsDto.getTaskNo()); | 
|---|
|  |  |  | headParam1.put("status",6); | 
|---|
|  |  |  | headParam1.put("ioType",1); | 
|---|
|  |  |  | headParam1.put("barcode",barcode); | 
|---|
|  |  |  | String response2; | 
|---|
|  |  |  | response2 = new HttpHandler.Builder() | 
|---|
|  |  |  | // .setHeaders(headParam) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(taskStatusFeedbackPath) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(headParam1)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject1 = JSON.parseObject(response2); | 
|---|
|  |  |  | apiLogService.save("wcs派发库位不为空上报wms" | 
|---|
|  |  |  | ,wmsUrl+taskStatusFeedbackPath | 
|---|
|  |  |  | ,null | 
|---|
|  |  |  | ,"127.0.0.1" | 
|---|
|  |  |  | ,JSON.toJSONString(headParam1) | 
|---|
|  |  |  | ,response | 
|---|
|  |  |  | ,true | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("wcs派发库位不为空上报wms", getWmsDto.getWrkNo()); | 
|---|
|  |  |  | throw new CoolException("wcs派发入库任务上报wms失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (jsonObject.getInteger("code") == 500) { | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), "条码:" + barcode + "申请WMS失败,系统回退,response=" + JSON.toJSONString(jsonObject)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 创新一个入库工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkService.selectByTaskNo(getWmsDto.getWrkNo()); | 
|---|
|  |  |  | if(Cools.isEmpty(taskWrk)) { | 
|---|
|  |  |  | taskWrk = createTask(getWmsDto,barcode); | 
|---|
|  |  |  | if (Cools.isEmpty(taskWrk)){ | 
|---|
|  |  |  | log.error("库位异常,库位号:{}", getWmsDto.getTargetLocationCode()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | taskWrkService.insert(taskWrk); | 
|---|
|  |  |  | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() | 
|---|
|  |  |  | .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).eq("stn_no",staProtocol.getSiteId())); | 
|---|
|  |  |  | staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue()); | 
|---|
|  |  |  | staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); | 
|---|
|  |  |  | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | staProtocol.setWorkNo(9997); | 
|---|
|  |  |  | staProtocol.setStaNo(inSta.getBackSta().shortValue()); | 
|---|
|  |  |  | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), "条码:" + barcode + "申请WMS失败,response=" + JSON.toJSONString(jsonObject)); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                        StaDescService staDescService = SpringUtils.getBean(StaDescService.class); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        ToWmsDTO toWmsDTO = new ToWmsDTO(); | 
|---|
|  |  |  | //                        Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | //                        map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2"); | 
|---|
|  |  |  | //                        List<Integer> list = openServiceImpl.getInEnableRoadway(); | 
|---|
|  |  |  | //                        TaskWrk taskWrk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode)); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        if (Cools.isEmpty(taskWrk)){ | 
|---|
|  |  |  | //                            continue; | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | //                        //StaDesc staDesc1 = staDescService.selectOne(new EntityWrapper<StaDesc>().eq("stn_no",inSta.getBackSta())); | 
|---|
|  |  |  | //                        if (taskWrk.getTargetPoint() != null && taskWrk.getStartPoint() != null){ | 
|---|
|  |  |  | //                            if ( taskWrk.getWrkNo() != null && taskWrk.getWrkNo().shortValue() == workNo ){ | 
|---|
|  |  |  | //                                continue; | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | //                            //获取堆垛机站点 | 
|---|
|  |  |  | //                            StaDesc staDesc = new StaDesc(); | 
|---|
|  |  |  | //                            if (devp.getId() <= 1){ | 
|---|
|  |  |  | //                                staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() | 
|---|
|  |  |  | //                                        .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).lt("stn_no", 200)); | 
|---|
|  |  |  | //                            }else { | 
|---|
|  |  |  | //                                staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() | 
|---|
|  |  |  | //                                        .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).lt("stn_no", 400).ge("stn_no", 250)); | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | //                            staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue()); | 
|---|
|  |  |  | //                            staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); | 
|---|
|  |  |  | //                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol)); | 
|---|
|  |  |  | //                            Thread.sleep(500); | 
|---|
|  |  |  | //                        }else { | 
|---|
|  |  |  | //                            //TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo()); | 
|---|
|  |  |  | //                            toWmsDTO.setWarehouseId("1688469798893297665"); | 
|---|
|  |  |  | //                            toWmsDTO.setContainerCode(barcode); | 
|---|
|  |  |  | //                            toWmsDTO.setApplyType("TUNNEL_LOCATION"); | 
|---|
|  |  |  | //                            toWmsDTO.setTaskTunnel(taskWrk.getCrnNo()); | 
|---|
|  |  |  | //                            toWmsDTO.setCanInboundTunnels(list); | 
|---|
|  |  |  | //                            String response = null; | 
|---|
|  |  |  | //                            try { | 
|---|
|  |  |  | //                                response = new HttpHandler.Builder() | 
|---|
|  |  |  | //                                        .setHeaders(map) | 
|---|
|  |  |  | //                                        .setUri(wmsUrl) | 
|---|
|  |  |  | //                                        .setPath(inboundTaskApplyPath) | 
|---|
|  |  |  | //                                        .setJson(JSON.toJSONString(toWmsDTO)) | 
|---|
|  |  |  | //                                        .build() | 
|---|
|  |  |  | //                                        .doPost(); | 
|---|
|  |  |  | //                            }catch (Exception e){ | 
|---|
|  |  |  | //                                log.error("wms通讯失败,"+e.getMessage()); | 
|---|
|  |  |  | //                                continue; | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | //                            apiLogService.save("wms请求入库货位接口" | 
|---|
|  |  |  | //                                    ,wmsUrl+"wcsManager/wcsInterface/inboundTaskApply" | 
|---|
|  |  |  | //                                    ,null | 
|---|
|  |  |  | //                                    ,"127.0.0.1" | 
|---|
|  |  |  | //                                    ,JSON.toJSONString(toWmsDTO) | 
|---|
|  |  |  | //                                    ,response | 
|---|
|  |  |  | //                                    ,true | 
|---|
|  |  |  | //                            ); | 
|---|
|  |  |  | //                            JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | //                            if (jsonObject.getInteger("code").equals(200)) { | 
|---|
|  |  |  | //                                GetWmsDto getWmsDto = JSON.parseObject(jsonObject.get("data").toString(), GetWmsDto.class); | 
|---|
|  |  |  | //                                taskWrk.setOriginTargetPoint(getWmsDto.getTargetLocationCode()); | 
|---|
|  |  |  | //                                taskWrk.setTargetPoint(Utils.getWcsLocNo(getWmsDto.getTargetLocationCode())); | 
|---|
|  |  |  | //                                taskWrk.setStartPoint(String.valueOf(inSta.getBackSta())); | 
|---|
|  |  |  | //                                if (!taskWrkService.updateById(taskWrk)){ | 
|---|
|  |  |  | //                                    log.error("保存wms库位号失败"); | 
|---|
|  |  |  | //                                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                            }else { | 
|---|
|  |  |  | //                                log.error("wms通讯失败,"+jsonObject.get("msg")); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | JSONObject result = jsonObject.getJSONObject("data"); | 
|---|
|  |  |  | Integer resultWrkNo = result.getInteger("wrkNo"); | 
|---|
|  |  |  | Integer resultStaNo = result.getInteger("stnNo"); | 
|---|
|  |  |  | String resultLocNo = result.getString("locNo"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 创新一个入库工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkService.selectByTaskNo(String.valueOf(resultWrkNo)); | 
|---|
|  |  |  | if(taskWrk != null) { | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), "任务:" + resultWrkNo + "已经存在"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LocMast locMast = locMastService.selectByLocNo(resultLocNo); | 
|---|
|  |  |  | if (locMast == null) { | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), resultLocNo + "库位不存在"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!locMast.getLocSts().equals("O")) { | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), resultLocNo + "库位不处于空库位"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | taskWrk = new TaskWrk(); | 
|---|
|  |  |  | taskWrk.setTaskNo(String.valueOf(resultWrkNo));//任务号 | 
|---|
|  |  |  | taskWrk.setWrkNo(commonService.getWorkNo(WorkNoType.PAKIN.type));//获取入库工作号 | 
|---|
|  |  |  | taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 | 
|---|
|  |  |  | taskWrk.setWrkSts(2);//2.设备上走 | 
|---|
|  |  |  | taskWrk.setCreateTime(now); | 
|---|
|  |  |  | taskWrk.setIoType(1);//任务类型 | 
|---|
|  |  |  | taskWrk.setIoPri(13);//优先级 | 
|---|
|  |  |  | taskWrk.setBarcode(barcode);//条码 | 
|---|
|  |  |  | taskWrk.setCrnNo(locMast.getCrnNo()); | 
|---|
|  |  |  | taskWrk.setTargetPoint(resultLocNo); | 
|---|
|  |  |  | taskWrk.setStartPoint(String.valueOf(inSta.getStaNo())); | 
|---|
|  |  |  | if (!Cools.isEmpty(taskWrk.getTargetPoint())) { | 
|---|
|  |  |  | taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!taskWrkService.insert(taskWrk)) { | 
|---|
|  |  |  | News.watchInfo(String.valueOf(staProtocol.getSiteId()), "任务:" + resultWrkNo + "任务创建失败"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | locMast.setLocSts("S"); | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMastService.updateById(locMast); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() | 
|---|
|  |  |  | .eq("crn_no", taskWrk.getCrnNo()).eq("type_no", 1).eq("stn_no", staProtocol.getSiteId())); | 
|---|
|  |  |  | staProtocol.setWorkNo(taskWrk.getWrkNo()); | 
|---|
|  |  |  | staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); | 
|---|
|  |  |  | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //上报 | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); | 
|---|
|  |  |  | HashMap<String, Object> hashMap = new HashMap<>(); | 
|---|
|  |  |  | hashMap.put("taskNo", taskWrk.getTaskNo()); | 
|---|
|  |  |  | hashMap.put("status", TaskStatusType.DISTRIBUTE.id); | 
|---|
|  |  |  | hashMap.put("ioType", 1); | 
|---|
|  |  |  | hashMap.put("barcode", taskWrk.getBarcode()); | 
|---|
|  |  |  | hashMap.put("reportTime", format.format(new Date())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NotifyCustomDataDto customDataDto = new NotifyCustomDataDto(); | 
|---|
|  |  |  | customDataDto.setUri(wmsUrl); | 
|---|
|  |  |  | customDataDto.setPath(taskExecCallback); | 
|---|
|  |  |  | customDataDto.setData(JSON.toJSONString(hashMap)); | 
|---|
|  |  |  | boolean notifyResult = notifyUtils.notify("task", 1, String.valueOf(taskWrk.getWrkNo()), taskWrk.getTaskNo(), NotifyMsgType.TASK_START, JSON.toJSONString(taskWrk), true, customDataDto); | 
|---|
|  |  |  | if(notifyResult) { | 
|---|
|  |  |  | taskWrk.setStatus(TaskStatusType.DISTRIBUTE.id);//任务派发 | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("请求入库调用接口失败"); | 
|---|
|  |  |  | log.error("异常信息打印:" + e); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | BasDevp basDevp = basDevpService.selectById(inSta.getStaNo()); | 
|---|
|  |  |  | if (Cools.isEmpty(basDevp)) { | 
|---|
|  |  |  | log.error("站点号异常" + inSta.getStaNo()); | 
|---|
|  |  |  | } else if (basDevp.getStaErr() != 0) { | 
|---|
|  |  |  | basDevp.setStaErr(2); | 
|---|
|  |  |  | basDevpService.updateById(basDevp); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e1) { | 
|---|
|  |  |  | // 退回 | 
|---|
|  |  |  | log.error("扫码检测程序异常" + inSta.getStaNo() + "异常信息" + e1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | apiLogService.save("wms请求入库货位接口" | 
|---|
|  |  |  | , wmsUrl + inboundTaskApplyPath | 
|---|
|  |  |  | , null | 
|---|
|  |  |  | , "127.0.0.1" | 
|---|
|  |  |  | , JSON.toJSONString(requestParam) | 
|---|
|  |  |  | , response | 
|---|
|  |  |  | , success | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("入库请求参数=" + JSON.toJSONString(barcode)); | 
|---|
|  |  |  | log.info("入库请求返回参数=" + JSON.toJSONString(response)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 堆垛机站出库到出库站 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void crnStnToOutStn() { | 
|---|
|  |  |  | public synchronized void crnStnToOutStn() { | 
|---|
|  |  |  | for (CrnSlave crnSlave : slaveProperties.getCrn()) { | 
|---|
|  |  |  | // 遍历堆垛机出库站 | 
|---|
|  |  |  | for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) { | 
|---|
|  |  |  | List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", crnSlave.getId()).eq("crn_stn", crnStn.getStaNo())); | 
|---|
|  |  |  | for (StaDesc staDesc : staDescs){ | 
|---|
|  |  |  | // 获取堆垛机出库站信息 | 
|---|
|  |  |  | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); | 
|---|
|  |  |  | StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staProtocol == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | staProtocol = staProtocol.clone(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == 0)) { | 
|---|
|  |  |  | // 查询工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectCrnStaWorking(crnSlave.getId(), staDesc.getStnNo().toString()); | 
|---|
|  |  |  | if (taskWrk == null) { | 
|---|
|  |  |  | List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("type_no", 2).eq("crn_no", crnSlave.getId()).eq("crn_stn", crnStn.getStaNo())); | 
|---|
|  |  |  | for (StaDesc staDesc : staDescs) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | // 获取堆垛机出库站信息 | 
|---|
|  |  |  | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); | 
|---|
|  |  |  | StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staProtocol == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | staProtocol = staProtocol.clone(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | siteController.siteDetlUpdate(Integer.valueOf(taskWrk.getTargetPoint()),taskWrk.getWrkNo().shortValue(),(short)0,"Y",false,false); | 
|---|
|  |  |  | taskWrk.setStatus(5); | 
|---|
|  |  |  | taskWrk.setWrkSts(14); | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) { | 
|---|
|  |  |  | // 查询工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectCrnStaWorking(crnSlave.getId(), staDesc.getStnNo().toString()); | 
|---|
|  |  |  | if (taskWrk == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("下发输送线任务:taskWrk:" + JSON.toJSONString(taskWrk)); | 
|---|
|  |  |  | //                            R r = siteController.siteDetlUpdate(Integer.valueOf(taskWrk.getTargetPoint()), taskWrk.getWrkNo().shortValue(), (short) 0, "Y", false, false); | 
|---|
|  |  |  | staProtocol.setWorkNo(taskWrk.getWrkNo()); | 
|---|
|  |  |  | staProtocol.setStaNo(staDesc.getStnNo().shortValue()); | 
|---|
|  |  |  | boolean offer = false; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | offer = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol)); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("下发输送线任务失败:异常:" + e); | 
|---|
|  |  |  | log.error("下发输送线任务失败:异常:offer:" + offer); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                            JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(r)); | 
|---|
|  |  |  | if (offer) { | 
|---|
|  |  |  | log.info("下发输送线任务成功:taskWrk:" + JSON.toJSONString(taskWrk)); | 
|---|
|  |  |  | taskWrk.setStatus(5); | 
|---|
|  |  |  | taskWrk.setWrkSts(14); | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | log.error("下发输送线任务失败:taskWrk:" + JSON.toJSONString(taskWrk)); | 
|---|
|  |  |  | //                                log.error("下发输送线任务失败:异常信息:"+JSON.toJSONString(r)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("出库到出库站异常:异常信息:" + e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | // 获取堆垛机信息 | 
|---|
|  |  |  | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); | 
|---|
|  |  |  | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|---|
|  |  |  | if (crnProtocol == null) { continue; } | 
|---|
|  |  |  | BasCrnp basCrnp = basCrnpService.selectById(crn.getId()); | 
|---|
|  |  |  | if (basCrnp == null) { | 
|---|
|  |  |  | log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId()); | 
|---|
|  |  |  | if (crnProtocol == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasCrnp basCrnp = basCrnpService.selectById(crn.getId()); | 
|---|
|  |  |  | if (basCrnp == null) { | 
|---|
|  |  |  | News.watchInfo(crn.getId() + "号堆垛机", "{}号堆垛机尚未在数据库进行维护!", crn.getId()); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 只有当堆垛机空闲 并且 无任务时才继续执行 | 
|---|
|  |  |  | if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO | 
|---|
|  |  |  | 
|---|
|  |  |  | crnProtocol.setLastIo("O"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 库位移转 | 
|---|
|  |  |  | this.locToLoc(crn, crnProtocol); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 库位移转 | 
|---|
|  |  |  | this.locToLoc(crn, crnProtocol); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 入库  ===>>  堆垛机站到库位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol) throws IOException { | 
|---|
|  |  |  | public synchronized void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol) throws IOException { | 
|---|
|  |  |  | for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) { | 
|---|
|  |  |  | List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", slave.getId()).eq("crn_stn", crnStn.getStaNo())); | 
|---|
|  |  |  | for (StaDesc staDesc : staDescs) { | 
|---|
|  |  |  | 
|---|
|  |  |  | // 查询站点详细信息 | 
|---|
|  |  |  | BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staDetl == null) { | 
|---|
|  |  |  | log.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo()); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable() | 
|---|
|  |  |  | && staDetl.getCanining()!=null && staDetl.getCanining().equals("Y")) { | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!flag) { | 
|---|
|  |  |  | News.watchError(crnStn.getStaNo() + "站点", "入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo()); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable() | 
|---|
|  |  |  | && staDetl.getCanining() != null && staDetl.getCanining().equals("Y")) { | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!flag) { | 
|---|
|  |  |  | //                    News.watchError(crnStn.getStaNo() + "站点", "入库 ===>> 堆垛机站点状态检测失败,站点需要满足:自动、有物、有工作号、站点可入"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取工作状态为2(设备上走)的入库工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectPakIn(slave.getId(), staProtocol.getWorkNo().intValue(), staDesc.getStnNo().toString()); | 
|---|
|  |  |  | if(null == taskWrk) { | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectPakIn(slave.getId(), staProtocol.getWorkNo(), staDesc.getStnNo().toString()); | 
|---|
|  |  |  | if (null == taskWrk) { | 
|---|
|  |  |  | News.watchError(crnStn.getStaNo() + "站点", "入库 ===>> 工作档不存在,检查任务是否生成"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 堆垛机控制过滤 | 
|---|
|  |  |  | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { | 
|---|
|  |  |  | News.watchError(slave.getId() + "号堆垛机", "堆垛机忙碌中"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int workNo = commonService.getWorkNo(WorkNoType.PAKIN.type);//获取入库工作号 | 
|---|
|  |  |  | taskWrk.setWrkNo(workNo);//工作号 | 
|---|
|  |  |  | taskWrk.setStatus(TaskStatusType.DISTRIBUTE.id);//派发状态 | 
|---|
|  |  |  | taskWrk.setAssignTime(new Date());//派发时间 | 
|---|
|  |  |  | taskWrk.setWrkSts(3);//工作状态 3.吊车入库 | 
|---|
|  |  |  | taskWrk.setCrnNo(staDesc.getCrnNo());//堆垛机号 | 
|---|
|  |  |  | taskWrk.setModiTime(new Date()); | 
|---|
|  |  |  | taskWrk.setModiUser(9988L); | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //取出命令 | 
|---|
|  |  |  | //                List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo()); | 
|---|
|  |  |  | //                Integer commandStep = taskWrk.getCommandStep(); | 
|---|
|  |  |  | //                if (commandInfos.isEmpty()) { | 
|---|
|  |  |  | //                    continue;//命令空 | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                CommandInfo commandInfo = commandInfos.get(commandStep); | 
|---|
|  |  |  | //                CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文 | 
|---|
|  |  |  | //                CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) { | 
|---|
|  |  |  | //                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); | 
|---|
|  |  |  | //                } else { | 
|---|
|  |  |  | //                    // 修改工作档状态 2.设备上走 => 3.吊车入库中 | 
|---|
|  |  |  | //                    Date now = new Date(); | 
|---|
|  |  |  | //                    taskWrk.setWrkSts(3); | 
|---|
|  |  |  | //                    taskWrk.setModiTime(now); | 
|---|
|  |  |  | //                    if (taskWrkMapper.updateById(taskWrk) == 0) { | 
|---|
|  |  |  | //                        log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo()); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    //开始运行 | 
|---|
|  |  |  | //                    String response = CrnStartRunning(taskWrk); | 
|---|
|  |  |  | //                    JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | //                    if (jsonObject.getInteger("code").equals(200)) { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                    }else { | 
|---|
|  |  |  | //                        log.error("入库开始运行通讯失败,"+jsonObject.get("msg")); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 命令下发区 -------------------------------------------------------------------------- | 
|---|
|  |  |  | CrnCommand crnCommand = new CrnCommand(); | 
|---|
|  |  |  | 
|---|
|  |  |  | crnCommand.setDestinationPosX(Utils.getRowShort(taskWrk.getTargetPoint()));     // 目标库位列 | 
|---|
|  |  |  | crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint()));     // 目标库位层 | 
|---|
|  |  |  | crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint()));     // 目标库位排 | 
|---|
|  |  |  | crnCommand.setCommand((short)1); | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand),false)) { | 
|---|
|  |  |  | crnCommand.setCommand((short) 1); | 
|---|
|  |  |  | log.info("堆垛机入库任务下发={}",crnCommand); | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand), false)) { | 
|---|
|  |  |  | log.error("堆垛机命令生成失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); | 
|---|
|  |  |  | throw new CoolException("堆垛机命令生成失败"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | HashMap<String, Object> headParam = new HashMap<>(); | 
|---|
|  |  |  | headParam.put("taskNo",taskWrk.getTaskNo()); | 
|---|
|  |  |  | headParam.put("status",taskWrk.getStatus()); | 
|---|
|  |  |  | headParam.put("ioType",taskWrk.getIoType()); | 
|---|
|  |  |  | headParam.put("barcode",taskWrk.getBarcode()); | 
|---|
|  |  |  | String response; | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | // .setHeaders(headParam) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(taskStatusFeedbackPath) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(headParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | apiLogService.save("wcs派发入库任务上报wms" | 
|---|
|  |  |  | ,wmsUrl+taskStatusFeedbackPath | 
|---|
|  |  |  | ,null | 
|---|
|  |  |  | ,"127.0.0.1" | 
|---|
|  |  |  | ,JSON.toJSONString(headParam) | 
|---|
|  |  |  | ,response | 
|---|
|  |  |  | ,true | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("wcs派发入库任务上报wms失败", taskWrk); | 
|---|
|  |  |  | throw new CoolException("wcs派发入库任务上报wms失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 出库  ===>>  库位到堆垛机站 | 
|---|
|  |  |  | * 2022-06-09 TQS修改,查询工作档LIST,遍历下发,防止第一个任务堵塞出库 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol){ | 
|---|
|  |  |  | public synchronized void  locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol) { | 
|---|
|  |  |  | List<TaskWrk> taskWrksInitial = taskWrkMapper.selectPakOut(slave.getId(), null); | 
|---|
|  |  |  | if (taskWrksInitial.size()==0){ | 
|---|
|  |  |  | if (taskWrksInitial.isEmpty()) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) { | 
|---|
|  |  |  | List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", slave.getId()).eq("crn_stn", crnStn.getStaNo())); | 
|---|
|  |  |  | for (StaDesc staDesc : staDescs){ | 
|---|
|  |  |  | for (StaDesc staDesc : staDescs) { | 
|---|
|  |  |  | // 获取工作状态为11(生成出库ID)的出库工作档 | 
|---|
|  |  |  | List<TaskWrk> taskWrks = taskWrkMapper.selectPakOut(slave.getId(),staDesc.getStnNo().toString()); | 
|---|
|  |  |  | for (TaskWrk taskWrk : taskWrks){ | 
|---|
|  |  |  | List<TaskWrk> taskWrks = taskWrkMapper.selectPakOut(slave.getId(), staDesc.getStnNo().toString()); | 
|---|
|  |  |  | for (TaskWrk taskWrk : taskWrks) { | 
|---|
|  |  |  | if (taskWrk == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 工作档状态判断 | 
|---|
|  |  |  | if (taskWrk.getIoType() != 2 || taskWrk.getTargetPoint() == null || taskWrk.getStartPoint() == null) { | 
|---|
|  |  |  | log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", taskWrk.getWrkNo(), taskWrk.getStartPoint(), taskWrk.getIoType()); | 
|---|
|  |  |  | News.watchError(taskWrk.getWrkNo() + "任务", "查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", taskWrk.getWrkNo(), taskWrk.getStartPoint(), taskWrk.getIoType()); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取堆垛机出库站信息 | 
|---|
|  |  |  | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); | 
|---|
|  |  |  | StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 查询站点详细信息 | 
|---|
|  |  |  | BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staDetl == null) { | 
|---|
|  |  |  | log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo()); | 
|---|
|  |  |  | News.watchError(taskWrk.getWrkNo() + "任务", "出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 判断堆垛机出库站状态 | 
|---|
|  |  |  | if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() !=null && staDetl.getCanouting().equals("Y") | 
|---|
|  |  |  | && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) { | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isOutEnable() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y") | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | // 命令下发区 -------------------------------------------------------------------------- | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 堆垛机控制过滤 | 
|---|
|  |  |  | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 已经存在吊车执行任务时,则过滤 | 
|---|
|  |  |  | if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) { | 
|---|
|  |  |  | int storeCount = basDevpService.getStoreCount(); | 
|---|
|  |  |  | if(storeCount >= maxCount){ | 
|---|
|  |  |  | News.watchError(taskWrk.getWrkNo() + "任务", "输送线暂存数达到上限{}", storeCount); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改工作档状态 11.生成出库ID => 12.吊车出库中 | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | taskWrk.setWrkSts(12); | 
|---|
|  |  |  | taskWrk.setStatus(2); | 
|---|
|  |  |  | taskWrk.setModiTime(now); | 
|---|
|  |  |  | if (taskWrkMapper.updateById(taskWrk) == 0) { | 
|---|
|  |  |  | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); | 
|---|
|  |  |  | // 已经存在吊车执行任务时,则过滤 | 
|---|
|  |  |  | if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | CrnCommand command = new CrnCommand(); | 
|---|
|  |  |  | command.setCrnNo(taskWrk.getCrnNo()); // 堆垛机编号 | 
|---|
|  |  |  | 
|---|
|  |  |  | command.setDestinationPosX(crnStn.getRow().shortValue());     // 目标库位排 | 
|---|
|  |  |  | command.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列 | 
|---|
|  |  |  | command.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层 | 
|---|
|  |  |  | command.setCommand((short)1); | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, command),false)) { | 
|---|
|  |  |  | command.setCommand((short) 1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, command), false)) { | 
|---|
|  |  |  | log.error("堆垛机命令生成失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(command)); | 
|---|
|  |  |  | throw new CoolException("堆垛机命令生成失败"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | HashMap<String, Object> headParam = new HashMap<>(); | 
|---|
|  |  |  | headParam.put("taskNo",taskWrk.getTaskNo()); | 
|---|
|  |  |  | headParam.put("status",taskWrk.getStatus()); | 
|---|
|  |  |  | headParam.put("ioType",taskWrk.getIoType()); | 
|---|
|  |  |  | headParam.put("barcode",taskWrk.getBarcode()); | 
|---|
|  |  |  | String response; | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | // .setHeaders(headParam) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(taskStatusFeedbackPath) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(headParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | apiLogService.save("wcs派发入库任务上报wms" | 
|---|
|  |  |  | ,wmsUrl+taskStatusFeedbackPath | 
|---|
|  |  |  | ,null | 
|---|
|  |  |  | ,"127.0.0.1" | 
|---|
|  |  |  | ,JSON.toJSONString(headParam) | 
|---|
|  |  |  | ,response | 
|---|
|  |  |  | ,true | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("wcs派发出库任务上报wms失败", taskWrk); | 
|---|
|  |  |  | throw new CoolException("wcs派发入库任务上报wms失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | // 修改工作档状态 11.生成出库ID => 12.吊车出库中 | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | taskWrk.setWrkSts(12); | 
|---|
|  |  |  | taskWrk.setModiTime(now); | 
|---|
|  |  |  | if (taskWrkMapper.updateById(taskWrk) == 0) { | 
|---|
|  |  |  | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); | 
|---|
|  |  |  | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,异常:" + e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //上报-出库任务开始时,WCS回调WMS | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); | 
|---|
|  |  |  | HashMap<String, Object> hashMap = new HashMap<>(); | 
|---|
|  |  |  | hashMap.put("taskNo", taskWrk.getTaskNo()); | 
|---|
|  |  |  | hashMap.put("status", TaskStatusType.DISTRIBUTE.id); | 
|---|
|  |  |  | hashMap.put("ioType", 2); | 
|---|
|  |  |  | hashMap.put("barcode", taskWrk.getBarcode()); | 
|---|
|  |  |  | hashMap.put("reportTime", format.format(new Date())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NotifyCustomDataDto customDataDto = new NotifyCustomDataDto(); | 
|---|
|  |  |  | customDataDto.setUri(wmsUrl); | 
|---|
|  |  |  | customDataDto.setPath(taskExecCallback); | 
|---|
|  |  |  | customDataDto.setData(JSON.toJSONString(hashMap)); | 
|---|
|  |  |  | boolean notifyResult = notifyUtils.notify("task", 1, String.valueOf(taskWrk.getWrkNo()), taskWrk.getTaskNo(), NotifyMsgType.TASK_START, JSON.toJSONString(taskWrk), true, customDataDto); | 
|---|
|  |  |  | if(notifyResult) { | 
|---|
|  |  |  | taskWrk.setStatus(2); | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                        // 双深库位且浅库位有货,则需先对浅库位进行库位移转 | 
|---|
|  |  |  | //                        if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                            taskWrkMapper.selectPakOutIoType(taskWrk.getCrnNo()); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                            List<TaskWrk> taskWrks1 = taskWrkMapper.selectPakOutIoType(taskWrk.getCrnNo()); | 
|---|
|  |  |  | //                            if (Cools.isEmpty(taskWrks1) && taskWrks1.size()!=0){ | 
|---|
|  |  |  | //                                continue; | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | //                            String shallowLocNo = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint()); | 
|---|
|  |  |  | //                            TaskWrk hallowLocNoTask = taskWrkMapper.selectByStartPoint(shallowLocNo); | 
|---|
|  |  |  | //                            if (!Cools.isEmpty(hallowLocNoTask)){ | 
|---|
|  |  |  | //                                continue; | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        //取出命令 | 
|---|
|  |  |  | //                        List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo()); | 
|---|
|  |  |  | //                        Integer commandStep = taskWrk.getCommandStep(); | 
|---|
|  |  |  | //                        if (commandInfos.isEmpty()) { | 
|---|
|  |  |  | //                            continue;//命令空 | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        //判断末端命令是否执行 | 
|---|
|  |  |  | //                        CommandInfo commandInfo2 = commandInfos.get(commandInfos.size() - 1); | 
|---|
|  |  |  | //                        if (commandInfo2.getCommandStatus() != CommandStatusType.CREATE.id) { | 
|---|
|  |  |  | //                            continue;//指令已执行 | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        CommandInfo commandInfo = commandInfos.get(commandStep); | 
|---|
|  |  |  | //                        CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文 | 
|---|
|  |  |  | //                        CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) { | 
|---|
|  |  |  | //                            log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); | 
|---|
|  |  |  | //                        } else { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                            //开始运行 | 
|---|
|  |  |  | //                            String response = CrnStartRunning(taskWrk); | 
|---|
|  |  |  | //                            JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | //                            if (jsonObject.getInteger("code").equals(200)) { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                            }else { | 
|---|
|  |  |  | //                                log.error("出库开始运行通讯失败,"+jsonObject.get("msg")); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 库位移转 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void locToLoc(CrnSlave slave, CrnProtocol crnProtocol){ | 
|---|
|  |  |  | public synchronized void locToLoc(CrnSlave slave, CrnProtocol crnProtocol) { | 
|---|
|  |  |  | for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) { | 
|---|
|  |  |  | // 获取工作状态为11(生成出库ID)的移库工作档 | 
|---|
|  |  |  | List<TaskWrk> taskWrks = taskWrkMapper.selectList(new EntityWrapper<TaskWrk>() | 
|---|
|  |  |  | .eq("crn_no",slave.getId()) | 
|---|
|  |  |  | .eq("wrk_sts",11) | 
|---|
|  |  |  | .eq("io_type",3)); | 
|---|
|  |  |  | for (TaskWrk taskWrk : taskWrks){ | 
|---|
|  |  |  | .eq("crn_no", slave.getId()) | 
|---|
|  |  |  | .eq("wrk_sts", 11) | 
|---|
|  |  |  | .eq("io_type", 3) | 
|---|
|  |  |  | .orderBy("io_pri", false)); | 
|---|
|  |  |  | for (TaskWrk taskWrk : taskWrks) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 双深库位且浅库位有货,则需先对浅库位进行库位移转 | 
|---|
|  |  |  | //                if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) { | 
|---|
|  |  |  | 
|---|
|  |  |  | // 命令下发区 -------------------------------------------------------------------------- | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 1.堆垛机开始移动 | 
|---|
|  |  |  | CrnCommand crnCommand = new CrnCommand(); | 
|---|
|  |  |  | crnCommand.setCrnNo(slave.getId()); // 堆垛机编号 | 
|---|
|  |  |  | 
|---|
|  |  |  | crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint()));     // 目标库位列 | 
|---|
|  |  |  | crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint()));     // 目标库位层 | 
|---|
|  |  |  | crnCommand.setCommand((short) 1); | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand),false)) { | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand), false)) { | 
|---|
|  |  |  | log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 修改工作档状态 11.生成出库ID => 12.吊车出库中 | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | taskWrk.setWrkSts(12); | 
|---|
|  |  |  | taskWrk.setStatus(2); | 
|---|
|  |  |  | taskWrk.setModiTime(now); | 
|---|
|  |  |  | if (taskWrkMapper.updateById(taskWrk) == 0) { | 
|---|
|  |  |  | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | HashMap<String, Object> headParam = new HashMap<>(); | 
|---|
|  |  |  | headParam.put("taskNo",taskWrk.getTaskNo()); | 
|---|
|  |  |  | headParam.put("status",taskWrk.getStatus()); | 
|---|
|  |  |  | headParam.put("ioType",taskWrk.getIoType()); | 
|---|
|  |  |  | headParam.put("barcode",taskWrk.getBarcode()); | 
|---|
|  |  |  | String response; | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | // .setHeaders(headParam) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(taskStatusFeedbackPath) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(headParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | apiLogService.save("wcs派发移库任务上报wms" | 
|---|
|  |  |  | ,wmsUrl+taskStatusFeedbackPath | 
|---|
|  |  |  | ,null | 
|---|
|  |  |  | ,"127.0.0.1" | 
|---|
|  |  |  | ,JSON.toJSONString(headParam) | 
|---|
|  |  |  | ,response | 
|---|
|  |  |  | ,true | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("wcs派发出库任务上报wms失败", taskWrk); | 
|---|
|  |  |  | throw new CoolException("wcs派发入库任务上报wms失败"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //上报-移库任务开始时,WCS回调WMS | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); | 
|---|
|  |  |  | HashMap<String, Object> hashMap = new HashMap<>(); | 
|---|
|  |  |  | hashMap.put("taskNo", taskWrk.getTaskNo()); | 
|---|
|  |  |  | hashMap.put("status", TaskStatusType.DISTRIBUTE.id); | 
|---|
|  |  |  | hashMap.put("ioType", 3); | 
|---|
|  |  |  | hashMap.put("barcode", taskWrk.getBarcode()); | 
|---|
|  |  |  | hashMap.put("reportTime", format.format(new Date())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NotifyCustomDataDto customDataDto = new NotifyCustomDataDto(); | 
|---|
|  |  |  | customDataDto.setUri(wmsUrl); | 
|---|
|  |  |  | customDataDto.setPath(taskExecCallback); | 
|---|
|  |  |  | customDataDto.setData(JSON.toJSONString(hashMap)); | 
|---|
|  |  |  | boolean notifyResult = notifyUtils.notify("task", 1, String.valueOf(taskWrk.getWrkNo()), taskWrk.getTaskNo(), NotifyMsgType.TASK_START, JSON.toJSONString(taskWrk), true, customDataDto); | 
|---|
|  |  |  | if(notifyResult) { | 
|---|
|  |  |  | taskWrk.setStatus(2); | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 执行对工作档的完成操作 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void storeFinished() throws InterruptedException { | 
|---|
|  |  |  | public synchronized void storeFinished() throws InterruptedException { | 
|---|
|  |  |  | for (CrnSlave crn : slaveProperties.getCrn()) { | 
|---|
|  |  |  | // 获取堆垛机信息 | 
|---|
|  |  |  | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); | 
|---|
|  |  |  | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|---|
|  |  |  | if (crnProtocol == null) { continue; } | 
|---|
|  |  |  | if (crnProtocol == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //  状态:等待确认 并且  任务完成位 = 1 | 
|---|
|  |  |  | if (crnProtocol.getTaskFinish() == 0 && crnProtocol.statusType == CrnStatusType.HANDLING_COMPLETED && crnProtocol.getTaskNo() != 0) { | 
|---|
|  |  |  | //获取入库待确认工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectCrnNoInWorking(crn.getId(),crnProtocol.getTaskNo().intValue()); | 
|---|
|  |  |  | if (Cools.isEmpty(taskWrk)&&crnProtocol.getTaskNo() !=999) { | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectCrnNoInWorking(crn.getId(), crnProtocol.getTaskNo().intValue()); | 
|---|
|  |  |  | if (Cools.isEmpty(taskWrk) && crnProtocol.getTaskNo() != 999) { | 
|---|
|  |  |  | log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo()); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Thread.sleep(300); | 
|---|
|  |  |  | //确认完成信号 | 
|---|
|  |  |  | CrnOperatorParam crnOperatorParam=new CrnOperatorParam(); | 
|---|
|  |  |  | crnOperatorParam.setCrnNo(crn.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | crnController.crnTaskComplete(crnOperatorParam); | 
|---|
|  |  |  | if(!Cools.isEmpty(taskWrk)){ | 
|---|
|  |  |  | if(taskWrk.getIoType()==1&&taskWrk.getWrkSts()==3){ | 
|---|
|  |  |  | boolean result = crnOperaUtils.crnTaskComplete(crn.getId()); | 
|---|
|  |  |  | Thread.sleep(1000); | 
|---|
|  |  |  | if(!result){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(taskWrk)) { | 
|---|
|  |  |  | if (taskWrk.getIoType() == 1 && taskWrk.getWrkSts() == 3) { | 
|---|
|  |  |  | taskWrk.setWrkSts(4);//入库完成 | 
|---|
|  |  |  | taskWrk.setStatus(5);//完结 | 
|---|
|  |  |  | //更新库位状态 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | locMast.setLocSts("F");//F.在库 | 
|---|
|  |  |  | locMast.setBarcode(taskWrk.getBarcode());//托盘码 | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMast.setModiUser(9999L); | 
|---|
|  |  |  | locMastService.updateById(locMast); | 
|---|
|  |  |  | }else if(taskWrk.getIoType()==2&&taskWrk.getWrkSts()==12){ | 
|---|
|  |  |  | } else if (taskWrk.getIoType() == 2 && taskWrk.getWrkSts() == 12) { | 
|---|
|  |  |  | taskWrk.setWrkSts(13);//出库完成 | 
|---|
|  |  |  | taskWrk.setStatus(5);//完结 | 
|---|
|  |  |  | //更新库位状态 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectByLocNo(taskWrk.getStartPoint()); | 
|---|
|  |  |  | locMast.setLocSts("O");//O.空库位 | 
|---|
|  |  |  | locMast.setBarcode("");//托盘码 | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMast.setModiUser(9999L); | 
|---|
|  |  |  | locMastService.updateById(locMast); | 
|---|
|  |  |  | }else if(taskWrk.getIoType()==3&&taskWrk.getWrkSts()==12){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (taskWrk.getIoType() == 3 && taskWrk.getWrkSts() == 12) { | 
|---|
|  |  |  | taskWrk.setWrkSts(4);//入库完成 | 
|---|
|  |  |  | taskWrk.setStatus(5);//完结 | 
|---|
|  |  |  | //更新库位状态 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | locMast.setLocSts("F");//F.在库 | 
|---|
|  |  |  | locMast.setBarcode(taskWrk.getBarcode());//托盘码 | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMast.setModiUser(9999L); | 
|---|
|  |  |  | locMastService.updateById(locMast); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LocMast locMast1 = locMastService.selectByLocNo(taskWrk.getStartPoint()); | 
|---|
|  |  |  | locMast1.setLocSts("O");//O.空库位 | 
|---|
|  |  |  | locMast1.setBarcode("");//托盘码 | 
|---|
|  |  |  | locMast1.setModiTime(new Date()); | 
|---|
|  |  |  | locMast1.setModiUser(9999L); | 
|---|
|  |  |  | locMastService.updateById(locMast1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | HashMap<String, Object> headParam = new HashMap<>(); | 
|---|
|  |  |  | headParam.put("taskNo",taskWrk.getTaskNo()); | 
|---|
|  |  |  | headParam.put("status",taskWrk.getStatus()); | 
|---|
|  |  |  | headParam.put("ioType",taskWrk.getIoType()); | 
|---|
|  |  |  | headParam.put("barcode",taskWrk.getBarcode()); | 
|---|
|  |  |  | String response; | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | // .setHeaders(headParam) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(taskStatusFeedbackPath) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(headParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | apiLogService.save("wcs派发入库任务上报wms" | 
|---|
|  |  |  | ,wmsUrl+taskStatusFeedbackPath | 
|---|
|  |  |  | ,null | 
|---|
|  |  |  | ,"127.0.0.1" | 
|---|
|  |  |  | ,JSON.toJSONString(headParam) | 
|---|
|  |  |  | ,response | 
|---|
|  |  |  | ,true | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("wcs完结任务上报wms失败", taskWrk); | 
|---|
|  |  |  | throw new CoolException("wcs派发入库任务上报wms失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 堆垛机异常信息记录 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void recCrnErr(){ | 
|---|
|  |  |  | public synchronized void recCrnErr() { | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | for (CrnSlave crn : slaveProperties.getCrn()) { | 
|---|
|  |  |  | // 获取堆垛机信息 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 有异常 | 
|---|
|  |  |  | if (latest == null) { | 
|---|
|  |  |  | if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) { | 
|---|
|  |  |  | WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo()); | 
|---|
|  |  |  | if (wrkMast == null) { | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkService.selectByWrkNo(crnProtocol.getTaskNo().intValue()); | 
|---|
|  |  |  | if (taskWrk == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); | 
|---|
|  |  |  | String errName = crnError==null? String.valueOf(crnProtocol.getAlarm()):crnError.getErrName(); | 
|---|
|  |  |  | String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName(); | 
|---|
|  |  |  | BasErrLog basErrLog = new BasErrLog( | 
|---|
|  |  |  | null,    // 编号 | 
|---|
|  |  |  | wrkMast.getWrkNo(),    // 工作号 | 
|---|
|  |  |  | taskWrk.getWrkNo(),    // 工作号 | 
|---|
|  |  |  | now,    // 发生时间 | 
|---|
|  |  |  | null,    // 结束时间 | 
|---|
|  |  |  | wrkMast.getWrkSts(),    // 工作状态 | 
|---|
|  |  |  | wrkMast.getIoType(),    // 入出库类型 | 
|---|
|  |  |  | taskWrk.getWrkSts().longValue(),    // 工作状态 | 
|---|
|  |  |  | taskWrk.getIoType(),    // 入出库类型 | 
|---|
|  |  |  | crn.getId(),    // 堆垛机 | 
|---|
|  |  |  | null,    // plc | 
|---|
|  |  |  | wrkMast.getLocNo(),    // 目标库位 | 
|---|
|  |  |  | wrkMast.getStaNo(),    // 目标站 | 
|---|
|  |  |  | wrkMast.getSourceStaNo(),    // 源站 | 
|---|
|  |  |  | wrkMast.getSourceLocNo(),    // 源库位 | 
|---|
|  |  |  | wrkMast.getBarcode(),    // 条码 | 
|---|
|  |  |  | taskWrk.getTargetPoint(),    // 目标库位 | 
|---|
|  |  |  | null,    // 目标站 | 
|---|
|  |  |  | null,    // 源站 | 
|---|
|  |  |  | taskWrk.getStartPoint(),    // 源库位 | 
|---|
|  |  |  | taskWrk.getBarcode(),    // 条码 | 
|---|
|  |  |  | (int) crnProtocol.getAlarm1(),    // 异常码 | 
|---|
|  |  |  | errName,    // 异常 | 
|---|
|  |  |  | 1,    // 异常情况 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 记录新异常 | 
|---|
|  |  |  | if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm().intValue())) { | 
|---|
|  |  |  | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); | 
|---|
|  |  |  | String errName = crnError==null? String.valueOf(crnProtocol.getAlarm()):crnError.getErrName(); | 
|---|
|  |  |  | String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName(); | 
|---|
|  |  |  | BasErrLog basErrLog = new BasErrLog( | 
|---|
|  |  |  | null,    // 编号 | 
|---|
|  |  |  | null,    // 工作号 | 
|---|
|  |  |  | 
|---|
|  |  |  | null,    // 源站 | 
|---|
|  |  |  | null,    // 源库位 | 
|---|
|  |  |  | null,    // 条码 | 
|---|
|  |  |  | (int)crnProtocol.getAlarm1(),    // 异常码 | 
|---|
|  |  |  | (int) crnProtocol.getAlarm1(),    // 异常码 | 
|---|
|  |  |  | errName,    // 异常 | 
|---|
|  |  |  | 1,    // 异常情况 | 
|---|
|  |  |  | now,    // 添加时间 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //自动派发任务 | 
|---|
|  |  |  | public void autoDistribute() { | 
|---|
|  |  |  | Config config = configService.selectByCode("autoDistribute"); | 
|---|
|  |  |  | if (config == null) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //    //自动派发任务 | 
|---|
|  |  |  | //    public synchronized void autoDistribute() { | 
|---|
|  |  |  | //        Config config = configService.selectByCode("autoDistribute"); | 
|---|
|  |  |  | //        if (config == null) { | 
|---|
|  |  |  | //            return; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        if (config.getValue().equals("false")) {//判断是否开启自动派发任务 | 
|---|
|  |  |  | //            return; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        for (TaskWrk taskWrk : taskWrkService.selectReceive()) { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            try { | 
|---|
|  |  |  | //                taskWrkService.distribute(taskWrk.getTaskNo(), 9527L); | 
|---|
|  |  |  | //            } catch (CoolException e) { | 
|---|
|  |  |  | //                log.info(e.getMessage()); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (config.getValue().equals("false")) {//判断是否开启自动派发任务 | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (TaskWrk taskWrk : taskWrkService.selectReceive()) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | taskWrkService.distribute(taskWrk.getTaskNo(), 9527L); | 
|---|
|  |  |  | } catch (CoolException e) { | 
|---|
|  |  |  | log.info(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //自动完成任务 | 
|---|
|  |  |  | public synchronized void autoCompleteTask() { | 
|---|
|  |  |  | List<TaskWrk> taskWrks = taskWrkMapper.selectWorkingTask(); | 
|---|
|  |  |  | for (TaskWrk taskWrk : taskWrks) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public synchronized String CrnStartRunning(TaskWrk taskWrk){ | 
|---|
|  |  |  | String tasktype = null; | 
|---|
|  |  |  | switch (taskWrk.getIoType()){ | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | tasktype= "RK"; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | tasktype= "CK"; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | tasktype= "YK"; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | tasktype= "未知"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2"); | 
|---|
|  |  |  | TaskOverToWms taskOverToWms = new TaskOverToWms(); | 
|---|
|  |  |  | taskOverToWms.setFeedbackFrom("WCS"); //来源 | 
|---|
|  |  |  | taskOverToWms.setWarehouseId("1688469798893297665"); //仓库标识 | 
|---|
|  |  |  | taskOverToWms.setTaskNo(taskWrk.getTaskNo()); //任务号 | 
|---|
|  |  |  | taskOverToWms.setTaskType(tasktype); // 任务类型 | 
|---|
|  |  |  | taskOverToWms.setContainerCode(taskWrk.getBarcode()); // 容器编码 | 
|---|
|  |  |  | if (taskWrk.getIoType() ==1 || taskWrk.getIoType() == 3){ | 
|---|
|  |  |  | taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码 | 
|---|
|  |  |  | taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位 | 
|---|
|  |  |  | }else if (taskWrk.getIoType() ==2){ | 
|---|
|  |  |  | Map<Integer,String> map1 = new HashMap<>(); | 
|---|
|  |  |  | map1.put(102,"J-1101"); | 
|---|
|  |  |  | map1.put(106,"J-1103"); | 
|---|
|  |  |  | map1.put(110,"J-1105"); | 
|---|
|  |  |  | map1.put(114,"J-1107"); | 
|---|
|  |  |  | map1.put(118,"J-1109"); | 
|---|
|  |  |  | map1.put(122,"J-1111"); | 
|---|
|  |  |  | map1.put(305,"H-1101"); | 
|---|
|  |  |  | map1.put(405,"G-1101"); | 
|---|
|  |  |  | taskOverToWms.setEquipmentCode(map1.get(taskWrk.getTargetPoint())); //设备编码 | 
|---|
|  |  |  | taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | taskOverToWms.setTaskStatus("executing"); //任务状态 | 
|---|
|  |  |  | String response = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setHeaders(map) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath("wcsManager/wcsInterface/taskStatusFeedback") | 
|---|
|  |  |  | .setJson(JSON.toJSONString(taskOverToWms)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("堆垛机任务完成,请求wms任务完成接口失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | apiLogService.save("堆垛机开始运行" | 
|---|
|  |  |  | ,wmsUrl+"wcsManager/wcsInterface/taskStatusFeedback" | 
|---|
|  |  |  | ,null | 
|---|
|  |  |  | ,"127.0.0.1" | 
|---|
|  |  |  | ,JSON.toJSONString(taskOverToWms) | 
|---|
|  |  |  | ,response | 
|---|
|  |  |  | ,true | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | return response; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private TaskWrk createTask(GetWmsDto dto, String barcode){ | 
|---|
|  |  |  | private TaskWrk createTask(GetWmsDto dto, String barcode) { | 
|---|
|  |  |  | String wcsLocNo = dto.getLocNo(); | 
|---|
|  |  |  | if(Cools.isEmpty(wcsLocNo)){ | 
|---|
|  |  |  | if (Cools.isEmpty(wcsLocNo)) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | 
|---|
|  |  |  | taskWrk.setCrnNo(locMast.getCrnNo()); | 
|---|
|  |  |  | taskWrk.setTargetPoint(wcsLocNo); | 
|---|
|  |  |  | taskWrk.setStartPoint(dto.getStaNo().toString()); | 
|---|
|  |  |  | if(taskWrk.getIoType() == 1){ | 
|---|
|  |  |  | if (taskWrk.getIoType() == 1) { | 
|---|
|  |  |  | taskWrk.setWrkSts(2); | 
|---|
|  |  |  | if (!Cools.isEmpty(taskWrk.getTargetPoint())) { | 
|---|
|  |  |  | taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return taskWrk; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|