| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.zy.asrs.entity.param.WmsWrkCreateParam; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.domain.enums.TaskStatusType; |
| | | import com.zy.asrs.entity.TaskWrk; |
| | | import com.zy.asrs.entity.ToWmsDTO; |
| | | import com.zy.asrs.entity.param.WMSAndAGVInterfaceParam; |
| | | import com.zy.asrs.entity.param.taskCreateParam; |
| | | import com.zy.asrs.service.OpenService; |
| | | import com.zy.asrs.service.TaskWrkService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | 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.*; |
| | | |
| | | @Service |
| | | public class OpenServiceImpl implements OpenService { |
| | | |
| | | @Autowired |
| | | private TaskWrkService taskWrkService; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | |
| | | @Override |
| | | public void wmsWrkCreate(WmsWrkCreateParam param) { |
| | | // WmsWrk wmsWrk = wmsWrkService.selectByWmsWrkNo(param.getWmsWrkNo()); |
| | | // if (wmsWrk != null) { |
| | | // throw new CoolException(param.getWmsWrkNo() + "任务已存在,请勿重复提交"); |
| | | // } |
| | | // |
| | | // Date now = new Date(); |
| | | // wmsWrk = new WmsWrk(); |
| | | // wmsWrk.setWmsWrkNo(param.getWmsWrkNo());//WMS任务号 |
| | | // wmsWrk.setWmsStatus(WmsWrkStatusType.RECEIVE.id);//WMS状态:接收 |
| | | // wmsWrk.setCreateTime(now); |
| | | // wmsWrk.setAppeTime(now); |
| | | // wmsWrk.setAppeUser(9527L); |
| | | // wmsWrk.setIoType(param.getIoType());//任务类型 |
| | | // wmsWrk.setIoPri(13D);//优先级 |
| | | // wmsWrk.setBarcode(param.getBarcode());//条码 |
| | | // if (!Cools.isEmpty(param.getLocNo())) { |
| | | // wmsWrk.setLocNo(param.getLocNo());//目标库位 |
| | | // } |
| | | // if (!Cools.isEmpty(param.getSourceLocNo())) { |
| | | // wmsWrk.setSourceLocNo(param.getSourceLocNo());//源库位 |
| | | // } |
| | | // if (!Cools.isEmpty(param.getStaNo())) { |
| | | // wmsWrk.setStaNo(param.getStaNo());//目标站 |
| | | // } |
| | | // if (!Cools.isEmpty(param.getSourceStaNo())) { |
| | | // wmsWrk.setSourceStaNo(param.getSourceStaNo());//源站 |
| | | // } |
| | | // if (!Cools.isEmpty(param.getMemo())) { |
| | | // wmsWrk.setMemo(param.getMemo());//备注 |
| | | // } |
| | | // |
| | | // if (!wmsWrkService.insert(wmsWrk)) { |
| | | // throw new CoolException("生成任务失败,请联系管理员"); |
| | | // } |
| | | public void taskCreate(taskCreateParam param) { |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo()); |
| | | if (taskWrk != null) { |
| | | throw new CoolException(param.getTaskNo() + "任务已存在,请勿重复提交"); |
| | | } |
| | | if (param.getIoType().equals(0)){ |
| | | throw new CoolException("生成任务失败,任务类型不存在!"); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | taskWrk = new TaskWrk(); |
| | | taskWrk.setTaskNo(param.getTaskNo());//任务号 |
| | | taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 |
| | | taskWrk.setCreateTime(now); |
| | | taskWrk.setIoType(param.getIoType());//任务类型 |
| | | taskWrk.setIoPri(param.getTaskPriority());//优先级 |
| | | taskWrk.setBarcode(param.getBarcode());//条码 |
| | | taskWrk.setCrnNo(param.getCrn()); |
| | | if(param.getIoType() == 1){ |
| | | taskWrk.setWrkSts(1); |
| | | } else if (param.getIoType() == 2) { |
| | | taskWrk.setWrkSts(11); |
| | | } |
| | | |
| | | if (!Cools.isEmpty(param.getStartPoint())) { |
| | | taskWrk.setStartPoint(param.getStartPoint());//起点 |
| | | } |
| | | if (!Cools.isEmpty(param.getTargetPoint())) { |
| | | taskWrk.setTargetPoint(param.getTargetPoint());//终点 |
| | | } |
| | | if (!Cools.isEmpty(param.getMemo())) { |
| | | taskWrk.setMemo(param.getMemo());//备注 |
| | | } |
| | | |
| | | if (!taskWrkService.insert(taskWrk)) { |
| | | throw new CoolException("生成任务失败,请联系管理员"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public R AgvToWCSToWms(WMSAndAGVInterfaceParam param) throws IOException { |
| | | ToWmsDTO toWmsDTO = new ToWmsDTO(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2"); |
| | | List<Integer> list = new ArrayList<>(); |
| | | list.add(1); |
| | | list.add(4); |
| | | //TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo()); |
| | | toWmsDTO.setWarehouseId("1688469798893297665"); |
| | | toWmsDTO.setContainerCode(param.getContainerCode()); |
| | | toWmsDTO.setApplyType("TUNNEL"); |
| | | toWmsDTO.setWharfSource(null); |
| | | toWmsDTO.setCanInboundTunnels(list); |
| | | String response = new HttpHandler.Builder() |
| | | .setHeaders(map) |
| | | .setUri(wmsUrl) |
| | | .setPath("wcsManager/wcsInterface/inboundTaskApply") |
| | | .setJson(JSON.toJSONString(toWmsDTO)) |
| | | .build() |
| | | .doPost(); |
| | | |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | //解析 |
| | | List<WMSAndAGVInterfaceParam> params = new ArrayList<>(); |
| | | params.add(param); |
| | | WMSAndAGVInterfaceParam data = JSONObject.parseObject(jsonObject.get("data").toString(), WMSAndAGVInterfaceParam.class); |
| | | |
| | | taskCreate(new taskCreateParam(data)); |
| | | return R.ok(jsonObject.get("data")); |
| | | }else { |
| | | return R.error((String) jsonObject.get("msg")); |
| | | } |
| | | |
| | | } |
| | | } |