| | |
| | | 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.R; |
| | | import com.core.exception.CoolException; |
| | | 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.entity.param.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.asrs.service.impl.BasCrnErrorServiceImpl; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.web.BaseController; |
| | | import com.zy.core.CrnThread; |
| | | import com.zy.core.cache.RgvStatusCache; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.CrnSlave; |
| | | import com.zy.core.model.RgvSlave; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.model.protocol.RgvProtocol; |
| | | 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 javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | import java.sql.ResultSetMetaData; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | |
| | | @RequestMapping("/open") |
| | | public class OpenController extends BaseController { |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private OpenService openService; |
| | | @Autowired |
| | |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private BasRgvErrService basRgvErrService; |
| | | @Autowired |
| | | private BasCrnErrorServiceImpl basCrnErrorService; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | |
| | | public static final ArrayList<String> APP_KEY_LIST = new ArrayList<String>() {{ |
| | | add("ea1f0459efc02a79f046f982767939ae"); |
| | | }}; |
| | | |
| | | //agv任务完成 |
| | | @PostMapping("/toAgvTaskOver") |
| | | @AppAuth(memo = "agv任务完成接口") |
| | |
| | | |
| | | //创建任务 |
| | | @PostMapping("/taskCreate") |
| | | @Transactional |
| | | public R taskCreate(@RequestHeader String appkey, |
| | | @RequestBody taskCreateParam param, |
| | | @RequestBody List<TaskCreateParam> param1, |
| | | HttpServletRequest request) { |
| | | auth(appkey, param, request); |
| | | if (Cools.isEmpty(param)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | auth(appkey, param1, request); |
| | | try{ |
| | | List<TaskCreateParam> paramList = new ArrayList<>(); |
| | | List<String> locNoList = new ArrayList<>(); |
| | | for (TaskCreateParam param : param1) { |
| | | if (Cools.isEmpty(param)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | if (Cools.isEmpty(param.getTaskNo())) { |
| | | return R.error("任务号[taskNo]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getIoType())) { |
| | | return R.error("任务类型[ioType]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getBarcode())) { |
| | | return R.error("条码[barcode]不能为空"); |
| | | } |
| | | String locNo=null; |
| | | if(param.getIoType()==1){ |
| | | locNo=param.getTargetPoint(); |
| | | }else{ |
| | | locNo=param.getStartPoint(); |
| | | } |
| | | try{ |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no", locNo).ne("loc_sts","X")); |
| | | if (Cools.isEmpty(locMast)){ |
| | | log.error("库位号不存在"+locNo); |
| | | return R.error("库位号不存在"+locNo).add("库位号不存在"+locNo); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("库位号检测程序异常==》异常信息"+e); |
| | | return R.error("库位号检测程序异常").add("库位号检测程序异常==》异常信息"+e); |
| | | } |
| | | LocMast locMast=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts","F") |
| | | .eq("loc_no",locNo) |
| | | .eq("barcode",param.getBarcode())); |
| | | if(Cools.isEmpty(locMast)){ |
| | | return R.error("该库位不满足出库条件"+param.getTargetPoint()); |
| | | } |
| | | if (!locNoList.contains(locMast.getLocNo())){ |
| | | locNoList.add(locMast.getLocNo()); |
| | | paramList.add(param); |
| | | }else { |
| | | return R.error("该库位不能同时下发两笔任务"+locMast.getLocNo()); |
| | | } |
| | | } |
| | | for (TaskCreateParam param : paramList){ |
| | | openService.taskCreate(param); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("任务下发异常"+e); |
| | | return R.error(); |
| | | } |
| | | if (Cools.isEmpty(param.getTaskNo())) { |
| | | return R.error("任务号[taskNo]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getIoType())) { |
| | | return R.error("任务类型[ioType]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getBarcode())) { |
| | | return R.error("条码[barcode]不能为空"); |
| | | } |
| | | openService.taskCreate(param); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | } |
| | | return R.ok().add(taskWrk); |
| | | } |
| | | |
| | | // //取放货申请 |
| | | // @PostMapping("/pick/and/place/v1") |
| | | // @AppAuth(memo = "agv取放货申请") |
| | | // public R getAgvPickAndPlaceV1(@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.getStaNo())){ |
| | | // return R.error("码头[staNo]不能为空"); |
| | | // } |
| | | // if (Cools.isEmpty(param.getType())){ |
| | | // return R.error("类型[type]不能为空"); |
| | | // } |
| | | // return openService.getAgvPickAndPlaceV1(param); |
| | | // } |
| | | |
| | | // //取放货完成反馈 |
| | | // @PostMapping("/pick/and/place/v2") |
| | | // @AppAuth(memo = "agv取放货完成反馈") |
| | | // public R getAgvPickAndPlaceV2(@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.getStaNo())){ |
| | | // return R.error("码头[staNo]不能为空"); |
| | | // } |
| | | // if (Cools.isEmpty(param.getType())){ |
| | | // return R.error("类型[type]不能为空"); |
| | | // } |
| | | // return openService.getAgvPickAndPlaceV2(param); |
| | | // } |
| | | |
| | | //查询任务指令集合 |
| | | @GetMapping("/queryTaskCommand") |
| | |
| | | |
| | | //任务下发接口 |
| | | @PostMapping("/outboundTaskSend") |
| | | // @PostMapping("/taskCreate") |
| | | // @AppAuth(memo = "任务下发接口") |
| | | @Transactional |
| | | public R outboundTaskSend(@RequestHeader String appkey, |
| | | @RequestBody List<WMSAndAGVInterfaceParam> params, |
| | | @RequestBody List<CarryParam> params,//中航下发 1:出库,2:移库 3:入库 |
| | | HttpServletRequest request) { |
| | | auth(appkey, params, request); |
| | | List<WMSAndAGVInterfaceParam> params1 =new ArrayList<>(); |
| | | for (WMSAndAGVInterfaceParam param:params){ |
| | | // List<WMSAndAGVInterfaceParam> params1 =new ArrayList<>(); |
| | | for (CarryParam param:params){ |
| | | param.updateIoTyoe(param.getIoType());//中航下发 1:出库,2:移库 3:入库 ====转换为====> 1:入库,2:出库,3:移库 |
| | | |
| | | 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车间 |
| | | } |
| | | } |
| | | if (Cools.isEmpty(param)){ |
| | | return R.error("参数为空!"); |
| | | } else if (Cools.isEmpty(param.getTaskNo())){ |
| | | return R.error("任务号为空!"); |
| | | } else if (Cools.isEmpty(param.getIoType())){ |
| | | return R.error("任务类型为空!"); |
| | | } |
| | | if (Cools.isEmpty(param.getStartPoint()) || Cools.isEmpty(param.getTargetPoint())){ |
| | | return R.error("初始目标或者目标位为空"); |
| | | } |
| | | // 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车间 |
| | | // } |
| | | // } |
| | | |
| | | 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)); |
| | | LocMast locMast = locMastService.selectByLocNo(param.getStartPoint()); |
| | | if(Cools.isEmpty(locMast)){ |
| | | return R.error("初始库位无法找到"); |
| | | } |
| | | |
| | | R r = null; |
| | | |
| | | if(param.getIoType() == 1){ |
| | | //入库任务创建 |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("type_no",1) |
| | | .eq("crn_no",locMast.getCrnNo()) |
| | | .eq("stn_no",param.getStartPoint())); |
| | | if(Cools.isEmpty(staDesc)){ |
| | | return R.error("入库路劲不存在"); |
| | | } |
| | | param.setTargetLocationCode(staDesc.getStnNo().toString()); |
| | | r = openService.taskCreate(new TaskCreateParam(param,staDesc.getCrnNo())); |
| | | |
| | | }else if(param.getIoType() == 2){ |
| | | //出库任务创建 |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("type_no",2) |
| | | .eq("crn_no",locMast.getCrnNo()) |
| | | .eq("stn_no",param.getTargetPoint())); |
| | | if(Cools.isEmpty(staDesc)){ |
| | | return R.error("出库路劲不存在"); |
| | | } |
| | | r = openService.taskCreate(new TaskCreateParam(param,staDesc.getCrnNo())); |
| | | }else if (param.getIoType() == 3){ |
| | | LocMast locMast2 = locMastService.selectByLocNo(param.getTargetPoint()); |
| | | if(Cools.isEmpty(locMast2)){ |
| | | return R.error("目标库位无法找到"); |
| | | } |
| | | if (!locMast2.getCrnNo().equals(locMast.getCrnNo())){ |
| | | return R.error("起始库位与目标库位不再同一巷道"); |
| | | } |
| | | //移库任务创建 |
| | | r = openService.taskCreate(new TaskCreateParam(param,locMast.getCrnNo())); |
| | | } |
| | | |
| | | R r = openService.taskCreate(new taskCreateParam(param)); |
| | | |
| | | apiLogService.save("Wms任务下发接口" |
| | | ,request.getRemoteAddr()+request.getRequestURI() |
| | | ,appkey |
| | | ,request.getRemoteAddr() |
| | | ,JSON.toJSONString(param) |
| | | ,r.toString() |
| | | ,true |
| | | ); |
| | | |
| | | apiLogService.save("Wms任务下发接口" |
| | | ,request.getRemoteAddr()+request.getRequestURI() |
| | | ,appkey |
| | | ,request.getRemoteAddr() |
| | | ,JSON.toJSONString(param) |
| | | ,r.toString() |
| | | ,true |
| | | ); |
| | | |
| | | } |
| | | |
| | |
| | | //任务取消接口 |
| | | @PostMapping("/taskCancel") |
| | | public R taskCancel(@RequestHeader String appkey, |
| | | @RequestBody WMSAndAGVInterfaceParam param, |
| | | @RequestBody WMSAndAGVInterfaceParam param,//中航下发 1:出库,2:移库 3:入库 1:取消 2 完成 |
| | | HttpServletRequest request) { |
| | | auth(appkey, param, request); |
| | | // param.updateTaskStatus(param.getTaskStatus()); |
| | | if (Cools.isEmpty(param)){ |
| | | return R.error("参数为空!"); |
| | | } else if (Cools.isEmpty(param.getTaskNo())){ |
| | | return R.error("工作号为空!"); |
| | | } else if (Cools.isEmpty(param.getTaskStatus())){ |
| | | } else if (Cools.isEmpty(param.getIoType())){ |
| | | return R.error("操作类型为空!"); |
| | | } else if (Cools.isEmpty(param.getBarcode())){ |
| | | return R.error("托盘码不能为空!"); |
| | | } |
| | | // else if (Cools.isEmpty(param.getWarehouseId())){ |
| | | // return R.error("仓库标识为空!"); |
| | | // } |
| | | |
| | | TaskWrk taskWrk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("task_no", param.getTaskNo())); |
| | | TaskWrk taskWrk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>() |
| | | .eq("task_no", param.getTaskNo()) |
| | | .eq("io_type",param.getIoType()) |
| | | .eq("barcode",param.getBarcode())); |
| | | if (Cools.isEmpty(taskWrk)){ |
| | | return R.error("未查到当前任务"); |
| | | return R.error("未查到当前任务---"+param); |
| | | } |
| | | boolean sign =false; |
| | | switch (param.getTaskStatus()){ |
| | | case 1://正常取消 |
| | | if (taskWrk.getWrkSts()>1){ |
| | | if (taskWrk.getStatus()>1){ |
| | | return R.error("任务已开始执行"); |
| | | } |
| | | case 2://强制取消 |
| | | if (taskWrk.getWrkSts()>3){ |
| | | return R.error("任务已执行完成"); |
| | | } |
| | | break; |
| | | case 3://正常完成 |
| | | if (taskWrk.getWrkSts()>11){ |
| | | case 2://正常完成 |
| | | if (taskWrk.getStatus()>1){ |
| | | return R.error("任务已开始执行"); |
| | | } |
| | | case 4://强制完成 |
| | | if (taskWrk.getWrkSts()>14){ |
| | | return R.error("任务已执行完成"); |
| | | } |
| | | sign=true; |
| | | break; |
| | |
| | | HttpServletRequest request) { |
| | | auth(appkey, "设备状态查询接口", request); |
| | | List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>()); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | List<Object> list = new ArrayList<>(); |
| | | for (BasDevp basDevp:basDevps){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("devNo", basDevp.getDevNo()); |
| | | map.put("devType", "输送线"); |
| | | map.put("devStatus", basDevp.getAutoing().equals("Y")? 1:0); |
| | | map.put("errorCode", 0); |
| | | map.put("errorMsg", ""); |
| | | map.put("newDate",new Date()); |
| | | list.add(map); |
| | | BasDevpWmsParam basDevpWmsParam = new BasDevpWmsParam(); |
| | | basDevpWmsParam.setDevNo(basDevp.getDevNo()); |
| | | basDevpWmsParam.setWrkNo(basDevp.getWrkNo().longValue()); |
| | | basDevpWmsParam.setAutoing(basDevp.getAutoing()); |
| | | basDevpWmsParam.setLoading(basDevp.getLoading()); |
| | | basDevpWmsParam.setInEnable(basDevp.getInEnable()); |
| | | basDevpWmsParam.setOutEnable(basDevp.getOutEnable()); |
| | | basDevpWmsParam.setDevErr(basDevp.getStaErr().longValue()); |
| | | basDevpWmsParam.setDevErrM(basDevpWmsParam.getDevErr$()); |
| | | list.add(basDevpWmsParam); |
| | | } |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | for (BasCrnp basCrnp:basCrnps){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("devNo", basCrnp.getCrnNo()); |
| | | map.put("devType", "堆垛机"); |
| | | map.put("devStatus", basCrnp.getCrnSts()); |
| | | map.put("errorCode", 0); |
| | | map.put("errorMsg", ""); |
| | | map.put("newDate",new Date()); |
| | | list.add(map); |
| | | List<BasCrnpWmsParam> basCrnpWmsParamList = new ArrayList<>(); |
| | | for (CrnSlave crn : slaveProperties.getCrn()) { |
| | | // 获取堆垛机信息 |
| | | 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()); |
| | | continue; |
| | | } |
| | | BasCrnpWmsParam basCrnpWmsParam = new BasCrnpWmsParam(); |
| | | basCrnpWmsParam.sync(basCrnp); |
| | | |
| | | basCrnpWmsParam.setCrnNoH(crnProtocol.getLaneNo()); |
| | | basCrnpWmsParamList.add(basCrnpWmsParam); |
| | | |
| | | try{ |
| | | BasCrnError basCrnError = basCrnErrorService.selectById(basCrnp.getCrnErr()); |
| | | basCrnpWmsParam.setCrnErrM(basCrnError.getErrName()); |
| | | } catch (Exception e){ |
| | | basCrnpWmsParam.setCrnErrM("未知异常"); |
| | | } |
| | | |
| | | list.add(basCrnpWmsParam); |
| | | } |
| | | for (RgvSlave rgvSlave : slaveProperties.getRgv()) { |
| | | RgvProtocol rgvStatus = RgvStatusCache.getRgvStatus(rgvSlave.getId()); |
| | | if (Cools.isEmpty(rgvStatus)){ |
| | | continue; |
| | | } |
| | | BasRgvWmsParam basRgvWmsParam = new BasRgvWmsParam(); |
| | | basRgvWmsParam.setWrkNo(rgvStatus.getTaskNo()); |
| | | basRgvWmsParam.setCrnSts(rgvStatus.getStatus().intValue()); |
| | | basRgvWmsParam.setStatusType(rgvStatus.getStatusType().desc); |
| | | basRgvWmsParam.setSteNo(rgvSlave.getId()); |
| | | basRgvWmsParam.setSteErr(rgvStatus.getAlarm().longValue()); |
| | | try{ |
| | | BasRgvErr basRgvErr = basRgvErrService.selectById(rgvStatus.getAlarm().longValue()); |
| | | |
| | | basRgvWmsParam.setSteErrM(basRgvErr.getErrName()); |
| | | } catch (Exception e){ |
| | | basRgvWmsParam.setSteErrM("未知异常"); |
| | | } |
| | | list.add(basRgvWmsParam); |
| | | } |
| | | // List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | // for (BasCrnp basCrnp:basCrnps){ |
| | | // list.add(basCrnp); |
| | | // } |
| | | return R.ok(list); |
| | | } |
| | | |