| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.annotations.AppAuth; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.CommandInfo; |
| | | import com.zy.asrs.entity.TaskWrk; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.domain.vo.CrnStateTableVo; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.TaskOverParam; |
| | | import com.zy.asrs.entity.param.WMSAndAGVInterfaceParam; |
| | | import com.zy.asrs.entity.param.taskCreateParam; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.web.BaseController; |
| | | import com.zy.core.CrnThread; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | |
| | | private TaskWrkController taskWrkController; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | |
| | | private static final boolean auth = true; |
| | | |
| | | public static final ArrayList<String> APP_KEY_LIST = new ArrayList<String>() {{ |
| | | add("ea1f0459efc02a79f046f982767939ae"); |
| | | }}; |
| | | //agv任务完成 |
| | | @PostMapping("/toAgvTaskOver") |
| | | @AppAuth(memo = "agv任务完成接口") |
| | | public R getAgvTaskOver(@RequestHeader String appkey, |
| | | @RequestBody TaskOverParam param, |
| | | HttpServletRequest request){ |
| | | auth(appkey, param, request); |
| | | if (Cools.isEmpty(param)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | if (Cools.isEmpty(param.getWharfCode())){ |
| | | return R.error("码头[wharfCode]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getStatus())){ |
| | | return R.error("完成标记[status]不能为空"); |
| | | } |
| | | R agvTaskOver = openService.getAgvTaskOver(param); |
| | | apiLogService.save("AGV请求任务完成" |
| | | ,request.getRemoteAddr()+request.getRequestURI() |
| | | ,appkey |
| | | ,request.getRemoteAddr() |
| | | ,JSON.toJSONString(param) |
| | | ,agvTaskOver.toString() |
| | | ,true |
| | | ); |
| | | return agvTaskOver; |
| | | } |
| | | |
| | | //创建任务 |
| | | @PostMapping("/taskCreate") |
| | |
| | | |
| | | //AGV请求入库码头接口 |
| | | @PostMapping("/targetWharfApply") |
| | | @AppAuth(memo = "AGV请求入库码头接口") |
| | | public R targetWharfApply(@RequestHeader String appkey, |
| | | @RequestBody WMSAndAGVInterfaceParam param, |
| | | HttpServletRequest request) { |
| | | HttpServletRequest request) throws IOException { |
| | | auth(appkey,param,request); |
| | | |
| | | if (Cools.isEmpty(param)){ |
| | | return R.error("参数为空!"); |
| | | } else if (Cools.isEmpty(param.getTaskNo())){ |
| | |
| | | return R.error("托盘编码为空!"); |
| | | } else if (Cools.isEmpty(param.getWharfSource())){ |
| | | return R.error("源码头为空!"); |
| | | } else if (Cools.isEmpty(param.getFreeWharfs()) || param.getFreeWharfs().size()==0){ |
| | | return R.error("空闲的入库码头(AGV)为空!"); |
| | | } |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo()); |
| | | |
| | | return R.ok(taskWrk.getStartPoint()); |
| | | // else if (Cools.isEmpty(param.getFreeWharfs()) || param.getFreeWharfs().size()==0){ |
| | | // return R.error("空闲的入库码头(AGV)为空!"); |
| | | // } |
| | | R r = openService.AgvToWCSToWms(param); |
| | | apiLogService.save("AGV请求入库码头接口" |
| | | ,request.getRemoteAddr()+request.getRequestURI() |
| | | ,appkey |
| | | ,request.getRemoteAddr() |
| | | ,JSON.toJSONString(param) |
| | | ,r.toString() |
| | | ,true |
| | | ); |
| | | return r; |
| | | } |
| | | |
| | | //AGV请求动作接口 |
| | | @PostMapping("/agvTaskRequest") |
| | | @AppAuth(memo = "AGV请求动作接口") |
| | | public R agvTaskRequest(@RequestHeader String appkey, |
| | | @RequestBody WMSAndAGVInterfaceParam param, |
| | | HttpServletRequest request) { |
| | | auth(appkey, param, request); |
| | | if (Cools.isEmpty(param)){ |
| | | return R.error("参数为空!"); |
| | | } else if (Cools.isEmpty(param.getRequestType())){ |
| | |
| | | } else if (Cools.isEmpty(param.getWharfCode())){ |
| | | return R.error("码头编号为空!"); |
| | | } |
| | | BasDevp basDevp = basDevpService.selectById(param.getWharfCode()); |
| | | if (basDevp.getAutoing().equals("Y") && basDevp.getLoading().equals("N")){ |
| | | return R.ok(); |
| | | }else { |
| | | return R.error(); |
| | | |
| | | Map<String,Integer> map = new HashMap<>(); |
| | | map.put("J-1102",102);map.put("J-1101",101); |
| | | map.put("J-1103",105);map.put("J-1104",106); |
| | | map.put("J-1105",109);map.put("J-1106",110); |
| | | map.put("J-1107",113);map.put("J-1108",114); |
| | | map.put("J-1109",117);map.put("J-1110",118); |
| | | map.put("J-1111",121);map.put("J-1112",122); |
| | | map.put("H-1102",300);map.put("H-1101",305); |
| | | map.put("G-1102",400);map.put("G-1101",405); |
| | | // StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | // .eq("stn_desc", param.getWharfCode())); |
| | | // |
| | | // if (Cools.isEmpty(staDesc)){ |
| | | // return R.error("程序报错,未查询到站点"); |
| | | // } |
| | | if (Cools.isEmpty(map.get(param.getWharfCode()))){ |
| | | return R.error("未查询到站点"); |
| | | } |
| | | BasDevp basDevp = basDevpService.selectById(map.get(param.getWharfCode())); |
| | | // BasDevp basDevp = basDevpService.selectById(staDesc.getStnNo()); |
| | | if (basDevp.getAutoing().equals("Y") && (basDevp.getInEnable().equals("Y") || basDevp.getOutEnable().equals("Y"))){ |
| | | apiLogService.save("AGV请求入库码头接口" |
| | | ,request.getRemoteAddr()+request.getRequestURI() |
| | | ,appkey |
| | | ,request.getRemoteAddr() |
| | | ,JSON.toJSONString(param) |
| | | ,R.ok().toString() |
| | | ,true |
| | | ); |
| | | return R.ok("可入"); |
| | | }else { |
| | | apiLogService.save("AGV请求入库码头接口" |
| | | ,request.getRemoteAddr()+request.getRequestURI() |
| | | ,appkey |
| | | ,request.getRemoteAddr() |
| | | ,JSON.toJSONString(param) |
| | | ,R.error("站点状态不可入").toString() |
| | | ,true |
| | | ); |
| | | return R.error("站点状态不可入"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | //任务下发接口 |
| | | @PostMapping("/outboundTaskSend") |
| | | @Transactional |
| | | public R outboundTaskSend(@RequestHeader String appkey, |
| | | @RequestBody WMSAndAGVInterfaceParam param, |
| | | @RequestBody List<WMSAndAGVInterfaceParam> params, |
| | | HttpServletRequest request) { |
| | | try { |
| | | if (Cools.isEmpty(param)){ |
| | | return R.error("参数为空!"); |
| | | } else if (Cools.isEmpty(param.getTaskNo())){ |
| | | return R.error("任务号为空!"); |
| | | } else if (Cools.isEmpty(param.getTaskType())){ |
| | | return R.error("任务类型为空!"); |
| | | } else if (Cools.isEmpty(param.getWarehouseId())){ |
| | | return R.error("仓库标识为空!"); |
| | | } |
| | | if (Cools.isEmpty(param.getTaskPriority())){ |
| | | param.setTaskPriority(1); |
| | | } |
| | | if (Cools.isEmpty(param.getContainerCode())){ |
| | | return R.error("容器编码(托盘码)为空!"); |
| | | } |
| | | if (Cools.isEmpty(param.getEmptyContainer())){ |
| | | return R.error("是否空托盘信号为空!"); |
| | | } |
| | | // if (Cools.isEmpty(param.getTaskTunnel())){ |
| | | // return R.error("任务巷道为空!"); |
| | | // } |
| | | // if (Cools.isEmpty(param.getGroupNo())){ |
| | | // return R.error("任务组为空!"); |
| | | // } |
| | | // if (Cools.isEmpty(param.getTaskSerialNo())){ |
| | | // return R.error("任务执行顺序为空!"); |
| | | // } |
| | | if (Cools.isEmpty(param.getTargetWharf())){ |
| | | return R.error("目标码头区域为空!");//G开头=7车间,H开头=8层,J开头=9车间 |
| | | } |
| | | auth(appkey, params, request); |
| | | List<WMSAndAGVInterfaceParam> params1 =new ArrayList<>(); |
| | | for (WMSAndAGVInterfaceParam param:params){ |
| | | |
| | | openService.taskCreate(new taskCreateParam(param)); |
| | | if (Cools.isEmpty(param)){ |
| | | return R.error("参数为空!"); |
| | | } else if (Cools.isEmpty(param.getTaskNo())){ |
| | | return R.error("任务号为空!"); |
| | | } else if (Cools.isEmpty(param.getTaskType())){ |
| | | return R.error("任务类型为空!"); |
| | | } else if (Cools.isEmpty(param.getWarehouseId())){ |
| | | return R.error("仓库标识为空!"); |
| | | } |
| | | if (Cools.isEmpty(param.getTaskPriority())){ |
| | | param.setTaskPriority(1); |
| | | } |
| | | if (Cools.isEmpty(param.getContainerCode())){ |
| | | return R.error("容器编码(托盘码)为空!"); |
| | | } |
| | | if (Cools.isEmpty(param.getEmptyContainer())){ |
| | | return R.error("是否空托盘信号为空!"); |
| | | } |
| | | if (!param.getTaskType().equals("YK")){ |
| | | if (Cools.isEmpty(param.getTargetWharf())){ |
| | | return R.error("目标码头区域为空!");//G开头=7车间,H开头=8层,J开头=9车间 |
| | | } |
| | | } |
| | | |
| | | return R.ok(param); |
| | | }catch (Exception e){ |
| | | String errorMsg = Cools.isEmpty(e.getLocalizedMessage()) ? "" : e.getLocalizedMessage(); |
| | | return R.ok("生成任务失败,请联系管理员!"+ errorMsg); |
| | | StaDesc staDesc = new StaDesc(); |
| | | if (param.getTaskType().equals("CK") && param.getTargetWharf().contains("J")){ |
| | | staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no",param.getTaskTunnel()) |
| | | .eq("type_no",2) |
| | | .lt("stn_no",200)); |
| | | }else if (param.getTaskType().equals("CK") && param.getTargetWharf().contains("H")){ |
| | | staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no",param.getTaskTunnel()) |
| | | .eq("type_no",2) |
| | | .lt("stn_no",400) |
| | | .gt("stn_no",200)); |
| | | }else { |
| | | staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no",param.getTaskTunnel()) |
| | | .eq("type_no",2) |
| | | .lt("stn_no",500) |
| | | .ge("stn_no",400)); |
| | | } |
| | | param.setTargetLocationCode(staDesc.getStnNo().toString()); |
| | | |
| | | |
| | | R r = openService.taskCreate(new taskCreateParam(param)); |
| | | |
| | | apiLogService.save("Wms任务下发接口" |
| | | ,request.getRemoteAddr()+request.getRequestURI() |
| | | ,appkey |
| | | ,request.getRemoteAddr() |
| | | ,JSON.toJSONString(param) |
| | | ,r.toString() |
| | | ,true |
| | | ); |
| | | |
| | | |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | //任务取消接口 |
| | |
| | | } |
| | | boolean sign =false; |
| | | switch (param.getTaskStatus()){ |
| | | case "1"://正常取消 |
| | | case 1://正常取消 |
| | | if (taskWrk.getWrkSts()>1){ |
| | | return R.error("任务已开始执行"); |
| | | } |
| | | case "2"://强制取消 |
| | | case 2://强制取消 |
| | | if (taskWrk.getWrkSts()>3){ |
| | | return R.error("任务已执行完成"); |
| | | } |
| | | break; |
| | | case "3"://正常完成 |
| | | case 3://正常完成 |
| | | if (taskWrk.getWrkSts()>11){ |
| | | return R.error("任务已开始执行"); |
| | | } |
| | | case "4"://强制完成 |
| | | case 4://强制完成 |
| | | if (taskWrk.getWrkSts()>14){ |
| | | return R.error("任务已执行完成"); |
| | | } |
| | |
| | | return R.error(); |
| | | } |
| | | } |
| | | @PostMapping("/getCrnStatus") |
| | | public R getCrnStatus(HttpServletRequest request){ |
| | | List<Integer> crnStatusDtos = new ArrayList<>(); |
| | | List<BasCrnp> crnps = basCrnpService.selectList(new EntityWrapper<BasCrnp>().orderBy("crn_no")); |
| | | for (BasCrnp basCrnp : crnps) { |
| | | // 表格行 |
| | | CrnStateTableVo vo = new CrnStateTableVo(); |
| | | vo.setCrnNo(basCrnp.getCrnNo()); // 堆垛机号 |
| | | // 获取堆垛机信息 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo()); |
| | | if (crnThread == null) { |
| | | continue; |
| | | } |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (basCrnp.getOutEnable().equals("N")){ |
| | | continue; |
| | | } |
| | | if (crnProtocol.getAlarm() != 0){ |
| | | continue; |
| | | } |
| | | if (crnProtocol.getMode() != 3){ |
| | | continue; |
| | | } |
| | | |
| | | crnStatusDtos.add(basCrnp.getCrnNo()); |
| | | |
| | | } |
| | | return R.ok(crnStatusDtos); |
| | | } |
| | | |
| | | // @PostMapping("/getCrnStatus") |
| | | // public R getCrnStatus(HttpServletRequest request) { |
| | | // List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<BasCrnp>()); |
| | | // if (Cools.isEmpty(basCrnps)){ |
| | | // return R.error("数据库异常,堆垛机列表为空"); |
| | | // } |
| | | // List<CrnStatusDto> crnStatusDtos = new ArrayList<>(); |
| | | // for (BasCrnp basCrnp : basCrnps){ |
| | | // CrnStatusDto crnStatusDto = new CrnStatusDto(); |
| | | // crnStatusDto.setCrnNo(basCrnp.getCrnNo()); |
| | | // if (basCrnp.getOutEnable().equals("N")){ |
| | | // crnStatusDto.setCrnStatus(500); |
| | | // crnStatusDto.setCrnErrMsg("堆垛机出库被禁用"); |
| | | // crnStatusDtos.add(crnStatusDto); |
| | | // continue; |
| | | // } |
| | | // if (basCrnp.getCrnErr() != 0){ |
| | | // crnStatusDto.setCrnStatus(500); |
| | | // crnStatusDto.setCrnErrMsg("堆垛机处于报警状态"); |
| | | // crnStatusDtos.add(crnStatusDto); |
| | | // continue; |
| | | // } |
| | | // if (basCrnp.getCrnSts() != 3){ |
| | | // crnStatusDto.setCrnStatus(500); |
| | | // crnStatusDto.setCrnErrMsg("堆垛机处于非自动状态"); |
| | | // crnStatusDtos.add(crnStatusDto); |
| | | // continue; |
| | | // } |
| | | // |
| | | // crnStatusDto.setCrnStatus(200); |
| | | // crnStatusDto.setCrnErrMsg(""); |
| | | // crnStatusDtos.add(crnStatusDto); |
| | | // |
| | | // |
| | | // } |
| | | // |
| | | // return R.ok(crnStatusDtos); |
| | | // } |
| | | |
| | | |
| | | } |