| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.core.common.DateUtils; |
| | | import com.zy.asrs.domain.enums.TaskStatusType; |
| | | import com.zy.asrs.entity.CommandInfo; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.entity.TaskWrk; |
| | | import com.zy.asrs.entity.param.TaskOverToWms; |
| | | import com.zy.asrs.service.CommandInfoService; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.TaskWrkService; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.utils.SaasUtils; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | | import java.util.*; |
| | | |
| | | import static com.zy.asrs.entity.param.TaskStatusFeedbackParam.getTaskType; |
| | | |
| | | @RestController |
| | | @Slf4j |
| | | public class TaskWrkController extends BaseController { |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | |
| | | @Autowired |
| | | private TaskWrkService taskWrkService; |
| | | |
| | | @Autowired |
| | | private CommandInfoService commandInfoService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | |
| | | @RequestMapping(value = "/taskWrk/{wrkNo}/auth") |
| | | @ManagerAuth |
| | |
| | | @RequestMapping(value = "/taskWrk/update/auth") |
| | | @ManagerAuth |
| | | public R update(TaskWrk taskWrk){ |
| | | if (Cools.isEmpty(taskWrk) || null==taskWrk.getTaskNo()){ |
| | | if (Cools.isEmpty(taskWrk) || null == taskWrk.getTaskNo()) { |
| | | return R.error(); |
| | | } |
| | | taskWrkService.updateById(taskWrk); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/taskWrk/updatePoint/auth") |
| | | @ManagerAuth |
| | | public R updatePoint(TaskWrk taskWrk) throws UnknownHostException { |
| | | if (Cools.isEmpty(taskWrk) || null == taskWrk.getTaskNo()) { |
| | | return R.error(); |
| | | } |
| | | TaskWrk taskWrk1 = taskWrkService.selectByTaskNo(taskWrk.getTaskNo()); |
| | | if (taskWrk1 == null) { |
| | | return R.error(); |
| | | } |
| | | InetAddress localHost = InetAddress.getLocalHost(); |
| | | String ipAddress = localHost.getHostAddress(); |
| | | |
| | | SaasUtils.insertLog(1,taskWrk1.getStartPoint()+"-"+taskWrk1.getTargetPoint(),taskWrk.getStartPoint()+"-"+taskWrk.getTargetPoint(), ipAddress,getUser().getUsername()); |
| | | |
| | | |
| | | taskWrk1.setStartPoint(taskWrk.getStartPoint()); |
| | | taskWrk1.setTargetPoint(taskWrk.getTargetPoint()); |
| | | if (taskWrk1.getIoType() == 1){ |
| | | taskWrk1.setOriginTargetPoint(Utils.getWmsLocNo(taskWrk.getTargetPoint())); |
| | | } else if (taskWrk1.getIoType() == 2) { |
| | | taskWrk1.setOriginStartPoint(Utils.getWmsLocNo(taskWrk.getStartPoint())); |
| | | } else if (taskWrk1.getIoType() == 3) { |
| | | taskWrk1.setOriginTargetPoint(Utils.getWmsLocNo(taskWrk.getTargetPoint())); |
| | | taskWrk1.setOriginStartPoint(Utils.getWmsLocNo(taskWrk.getStartPoint())); |
| | | } |
| | | taskWrk1.setModiTime(new Date()); |
| | | taskWrk1.setModiUser(getUserId()); |
| | | |
| | | taskWrkService.updateById(taskWrk1); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | @ManagerAuth(memo = "手动完成任务") |
| | | public R complete(@RequestParam String taskNo) { |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo); |
| | | if (taskWrk == null) { |
| | | return R.error(); |
| | | |
| | | |
| | | 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(getTaskType(taskWrk.getIoType())); // 任务类型 |
| | | taskOverToWms.setContainerCode(taskWrk.getBarcode()); // 容器编码 |
| | | if (taskWrk.getIoType() ==1 ){ |
| | | 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"); |
| | | taskOverToWms.setEquipmentCode(map1.get(taskWrk.getTargetPoint())); //设备编码 |
| | | taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位 |
| | | } |
| | | if (taskWrk.getStatus().equals(TaskStatusType.COMPLETE.id)) { |
| | | return R.error(taskWrk.getTaskNo() + "已完结"); |
| | | } |
| | | Date now = new Date(); |
| | | taskWrk.setStatus(TaskStatusType.COMPLETE.id); |
| | | taskWrk.setModiTime(now);//操作时间 |
| | | try{ |
| | | taskWrk.setModiUser(getUserId());//操作员 |
| | | |
| | | taskOverToWms.setTaskStatus("handle"); //任务状态 |
| | | 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){ |
| | | taskWrk.setModiUser(9999L);//操作员 |
| | | log.error("wms连接失败"); |
| | | } |
| | | taskWrk.setCompleteTime(now);//完结时间 |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)){ |
| | | if (taskWrk == null) { |
| | | return R.error(); |
| | | } |
| | | if (taskWrk.getStatus().equals(TaskStatusType.OVER.id)) { |
| | | return R.error(taskWrk.getTaskNo() + "已完结"); |
| | | } |
| | | Date now = new Date(); |
| | | taskWrk.setStatus(TaskStatusType.OVER.id); |
| | | taskWrk.setModiTime(now);//操作时间 |
| | | try{ |
| | | taskWrk.setModiUser(getUserId());//操作员 |
| | | }catch (Exception e){ |
| | | taskWrk.setModiUser(9999L);//操作员 |
| | | } |
| | | taskWrk.setCompleteTime(now);//完结时间 |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | | |
| | | if (taskWrk.getIoType() == 1) { |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); |
| | | locMast.setLocSts("Z");//F.在库 |
| | | locMast.setBarcode(taskWrk.getBarcode());//托盘码 |
| | | locMast.setModiTime(now); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | } else if (taskWrk.getIoType() == 2) { |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getStartPoint()); |
| | | locMast.setLocSts("K");//O.空库位 |
| | | locMast.setBarcode("");//托盘码 |
| | | locMast.setModiTime(now); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | } |
| | | |
| | | |
| | | if (taskWrkService.saveToHistory(taskWrk.getTaskNo()) > 0) { |
| | | //任务已经转日志,将该任务下面的指令转日志 |
| | | commandInfoService.saveToHistory(taskWrk.getTaskNo()); |
| | | |
| | | //删除任务 |
| | | taskWrkService.delete(new EntityWrapper<TaskWrk>().eq("task_no", taskWrk.getTaskNo())); |
| | | //删除指令 |
| | | commandInfoService.delete(new EntityWrapper<CommandInfo>().eq("task_no", taskWrk.getTaskNo())); |
| | | } |
| | | }else { |
| | | return R.error("wms通讯失败"); |
| | | } |
| | | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | if (taskWrk == null) { |
| | | return R.error(); |
| | | } |
| | | if (taskWrk.getStatus().equals(TaskStatusType.CANCEL.id)) { |
| | | return R.error(taskWrk.getTaskNo() + "已被取消"); |
| | | String wmsCancelledtask = toWmsCancelledtask(taskWrk); |
| | | JSONObject jsonObject = JSON.parseObject(wmsCancelledtask); |
| | | if (Cools.isEmpty(jsonObject)){ |
| | | return R.error("超时或未知错误"); |
| | | } |
| | | Date now = new Date(); |
| | | taskWrk.setStatus(TaskStatusType.CANCEL.id); |
| | | taskWrk.setModiTime(now);//操作时间 |
| | | try{ |
| | | taskWrk.setModiUser(getUserId());//操作员 |
| | | }catch (Exception e){ |
| | | taskWrk.setModiUser(9999L);//操作员 |
| | | if (jsonObject.getInteger("code").equals(200)){ |
| | | if (!taskWrkService.delete(new EntityWrapper<TaskWrk>().eq("task_no",taskNo))){ |
| | | return R.error("删除任务失败"); |
| | | } |
| | | }else if (jsonObject.getInteger("code").equals(500)){ |
| | | return R.error(jsonObject.get("msg").toString()); |
| | | }else { |
| | | return R.error("超时或未知错误"); |
| | | } |
| | | taskWrk.setCompleteTime(now);//完结时间 |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | public String toWmsCancelledtask(TaskWrk taskWrk){ |
| | | 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(getTaskType(taskWrk.getIoType())); // 任务类型 |
| | | taskOverToWms.setContainerCode(taskWrk.getBarcode()); // 容器编码 |
| | | if (taskWrk.getIoType() ==1 ){ |
| | | 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"); |
| | | taskOverToWms.setEquipmentCode(map1.get(taskWrk.getTargetPoint())); //设备编码 |
| | | taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位 |
| | | } |
| | | |
| | | taskOverToWms.setTaskStatus("cancelled"); //任务状态 |
| | | 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连接失败"); |
| | | } |
| | | return response; |
| | | } |
| | | |
| | | |
| | | @PostMapping(value = "/taskWrk/updateCommandStep") |
| | | @ManagerAuth(memo = "更新步序") |
| | |
| | | taskWrkService.updateById(taskWrk); |
| | | return R.ok(); |
| | | } |
| | | @PostMapping(value = "/taskWrk/upIoPri") |
| | | public R upIoPri(@RequestParam String taskNo){ |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo); |
| | | if (taskWrk.getIoPri() > 300){ |
| | | return R.error("优先级已最高"); |
| | | } |
| | | Map<Integer,Integer> map = new HashMap<>(); |
| | | map.put(100,200);map.put(200,300);map.put(300,400); |
| | | Integer pri = map.get(taskWrk.getIoPri()); |
| | | taskWrk.setIoPri(pri); |
| | | if (!taskWrkService.updateById(taskWrk)){ |
| | | return R.error("增加优先级失败"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @PostMapping(value = "/taskWrk/downIoPri") |
| | | public R downIoPri(@RequestParam String taskNo){ |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo); |
| | | if (taskWrk.getIoPri() <200){ |
| | | return R.error("优先级已最低"); |
| | | } |
| | | Map<Integer,Integer> map = new HashMap<>(); |
| | | map.put(200,100);map.put(300,200);map.put(400,300); |
| | | Integer pri = map.get(taskWrk.getIoPri()); |
| | | taskWrk.setIoPri(pri); |
| | | if (!taskWrkService.updateById(taskWrk)){ |
| | | return R.error("降低优先级失败"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | public static String getTaskType(Integer paramIoType){ |
| | | switch (paramIoType){ |
| | | case 1: |
| | | return "RK"; |
| | | case 2: |
| | | return "CK"; |
| | | case 3: |
| | | return "YK"; |
| | | default: |
| | | return "未知"; |
| | | } |
| | | } |
| | | |
| | | } |