| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.domain.enums.TaskStatusType; |
| | | import com.zy.asrs.domain.enums.WorkNoType; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.entity.TaskWrk; |
| | | import com.zy.asrs.entity.TaskWrkReport; |
| | | import com.zy.asrs.entity.wms.StorageEscalationParam; |
| | | import com.zy.asrs.entity.wms.WmsResult; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.utils.Synchro; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | 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 java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | |
| | | @Service |
| | | @Slf4j |
| | | @Service("toWmsService") |
| | | public class ToWmsServiceImpl implements ToWmsService { |
| | | |
| | | |
| | | @Autowired |
| | | private TaskWrkService taskWrkService; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | |
| | | |
| | | @Autowired |
| | | private TaskWrkReportService taskWrkReportService; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | |
| | | @Autowired |
| | | private CommonService commonService; |
| | | |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | |
| | | |
| | | @Autowired |
| | |
| | | |
| | | @Value("${wms.data}") |
| | | private String data; |
| | | @Override |
| | | public void addReportLog(TaskWrk taskWrk) { |
| | | |
| | | @Override |
| | | public void addReportLog(TaskWrk taskWrk) { |
| | | TaskWrkReport taskWrkReport = new TaskWrkReport(); |
| | | Synchro.Copy(taskWrk, taskWrkReport); |
| | | taskWrkReport.setCreateTime(new Date()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public WmsResult getLocNoFromWms(StorageEscalationParam wmsParam) { |
| | | public TaskWrk getLocNoFromWms(StorageEscalationParam wmsParam) { |
| | | String response = ""; |
| | | Boolean success = false; |
| | | try { |
| | |
| | | .setJson(JSON.toJSONString(wmsParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (!Cools.isEmpty(response) && !Cools.isEmpty(jsonObject.get(code)) && jsonObject.get(code).equals(successCode)) { |
| | | WmsResult result = JSON.parseObject(jsonObject.get(data).toString(), WmsResult.class); |
| | | return result; |
| | | if (!Cools.isEmpty(response)) { |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (!Cools.isEmpty(jsonObject.get(code)) && jsonObject.get(code).equals(successCode)) { |
| | | //有些三方wms系统不能及时返回库位号,这时候就需要 |
| | | //ZWmsResult result = JSON.parseObject(jsonObject.get(data).toString(), WmsResult.class); |
| | | TaskWrk taskWrk = null; |
| | | int i = 1; |
| | | while (i < 10) { |
| | | taskWrk = taskWrkService.selectByBarcode(wmsParam.getBarcode()); |
| | | if (taskWrk != null) { |
| | | break; |
| | | } |
| | | try { |
| | | i++; |
| | | Thread.sleep(500L); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | return taskWrk; |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | |
| | | e.printStackTrace(); |
| | | log.info("请求wms报错,{}", e.getMessage()); |
| | | } finally { |
| | | addApiLog("入库任务请求获取库位", wmsUrl + inboundTaskApplyPath, JSON.toJSONString(wmsParam), response, success); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public boolean checkLocNo(String locNo) { |
| | | try { |
| | | BasDevp basDevp = basDevpService.selectById(inSta.getStaNo()); |
| | | if (Cools.isEmpty(basDevp)) { |
| | | log.error("站点号异常1" + inSta.getStaNo()); |
| | | throw new CoolException("站点号异常1,未查询到站点信息" + inSta.getStaNo()); |
| | | } |
| | | Integer staNoCrnNo = Utils.StaNoCrnNo(inSta.getStaNo()); |
| | | if (staNoCrnNo == 0) { |
| | | basDevp.setStaErr(1); |
| | | basDevpService.updateById(basDevp); |
| | | log.error("站点号异常2" + inSta.getStaNo()); |
| | | throw new CoolException("站点号异常2,站点号不存在" + inSta.getStaNo()); |
| | | } else { |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("crn_no", staNoCrnNo.longValue()) |
| | | .eq("loc_no", result.getLocNo())); |
| | | if (Cools.isEmpty(locMast)) { |
| | | basDevp.setStaErr(1); |
| | | basDevpService.updateById(basDevp); |
| | | log.error("站点号异常3" + inSta.getStaNo()); |
| | | throw new CoolException("站点号异常3:此巷道不存在目标库位" + inSta.getStaNo()); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | // log.error("扫码检测程序异常"+inSta.getStaNo()+"异常信息"+e); |
| | | // 退回 |
| | | log.error("扫码检测程序异常" + inSta.getStaNo() + errMsg); |
| | | log.error("扫码检测程序异常,异常信息" + e); |
| | | |
| | | staProtocol.setWorkNo((short) 9999); |
| | | staProtocol.setStaNo(inSta.getStaNo().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(workNo)); |
| | | if (taskWrk != null) { |
| | | taskWrk.setMemo(errMsg);//将错误码存入备注字段进行展示 |
| | | taskWrkMapper.updateById(taskWrk); |
| | | } |
| | | continue; |
| | | } |
| | | //查看该库位是否为空库位 |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts", "O") |
| | | .eq("loc_no", result.getLocNo())); |
| | | if (Cools.isEmpty(locMast)) { |
| | | try { |
| | | HashMap<String, Object> headParam1 = new HashMap<>(); |
| | | headParam1.put("taskNo", result.getTaskNo()); |
| | | headParam1.put("status", 6); |
| | | headParam1.put("ioType", 1); |
| | | headParam1.put("barcode", BoxNo); |
| | | 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", result.getTaskNo()); |
| | | throw new CoolException("wcs派发入库任务上报wms失败,派发库位==》不为空《==,异常信息:" + e); |
| | | private TaskWrk createInTask(WmsResult result, String barcode, Integer startPoint) { |
| | | //String locNo = Utils.Fusion(result.getRow(), result.getFloor(), result.getColumn()); |
| | | String locNo = result.getLocNo(); |
| | | Date now = new Date(); |
| | | TaskWrk taskWrk = new TaskWrk(); |
| | | int workNo1 = commonService.getWorkNo(WorkNoType.PAKIN.type);//获取入库工作号 |
| | | taskWrk.setTaskNo(result.getTaskNo());//任务号 |
| | | taskWrk.setWrkNo(workNo1); |
| | | taskWrk.setStatus(TaskStatusType.DISTRIBUTE.id);//任务状态:派发 |
| | | taskWrk.setCreateTime(now); |
| | | taskWrk.setIoType(1);//任务类型 |
| | | taskWrk.setIoPri(13);//优先级 |
| | | taskWrk.setBarcode(barcode);//条码 |
| | | LocMast locMast = locMastService.selectByLocNo(locNo); |
| | | taskWrk.setCrnNo(locMast.getCrnNo()); |
| | | taskWrk.setTargetPoint(locNo); |
| | | taskWrk.setStartPoint(startPoint + ""); |
| | | taskWrk.setCrnNo(result.getCrnNo()); |
| | | if (taskWrk.getIoType() == 1) { |
| | | taskWrk.setWrkSts(2); |
| | | if (!Cools.isEmpty(taskWrk.getTargetPoint())) { |
| | | taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); |
| | | } |
| | | } |
| | | return taskWrk; |
| | | } |
| | | |
| | | |
| | | private void addApiLog(String nameSpace, String url, String param, String response, Boolean success) { |
| | | apiLogService.save(nameSpace, url, null, "127.0.0.1", param, response, success); |