| | |
| | | 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.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.CarryParam; |
| | | 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.asrs.utils.Utils; |
| | | import com.zy.common.web.BaseController; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | import java.lang.reflect.Field; |
| | | import java.util.*; |
| | | |
| | | import static org.apache.ibatis.ognl.OgnlRuntime.setFieldValue; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private BasCrnErrorService basCrnErrorService; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | |
| | | //任务下发接口 |
| | | @PostMapping("/outboundTaskSend") |
| | | @Transactional |
| | | public R outboundTaskSend(@RequestHeader String appkey, |
| | | @RequestBody List<CarryParam> params, |
| | | HttpServletRequest request) { |
| | | //auth(appkey, params, request); |
| | | public HashMap<String, Object> outboundTaskSend(@RequestBody HashMap<String,Object> hashMap) { |
| | | String jsonString = JSON.toJSONString(hashMap.get("TaskList")); |
| | | List<CarryParam> params= JSONObject.parseArray(jsonString,CarryParam.class); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | List<WMSAndAGVInterfaceParam> params1 =new ArrayList<>(); |
| | | for (CarryParam param:params){ |
| | | |
| | | if (Cools.isEmpty(param)){ |
| | | return R.error("参数为空!"); |
| | | map.put("Code","0"); |
| | | map.put("Msg","参数为空!"); |
| | | return map; |
| | | } else if (Cools.isEmpty(param.getTaskNo())){ |
| | | return R.error("任务号为空!"); |
| | | } else if (Cools.isEmpty(param.getIoType())){ |
| | | return R.error("任务类型为空!"); |
| | | map.put("Code","0"); |
| | | map.put("Msg","任务号为空!"); |
| | | return map; |
| | | } else if (Cools.isEmpty(param.getStereoscopicTaskType())){ |
| | | map.put("Code","0"); |
| | | map.put("Msg","任务类型为空!"); |
| | | return map; |
| | | } |
| | | 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车间 |
| | | // } |
| | | // } |
| | | |
| | | String fusion = Utils.Fusion(param.getOriginalRowNo(), param.getOriginalFloorNo(), param.getOriginalColumnNo()); |
| | | param.setStartPoint(fusion); |
| | | LocMast locMast = locMastService.selectByLocNo(param.getStartPoint()); |
| | | if(Cools.isEmpty(locMast)){ |
| | | return R.error("初始库位无法找到"); |
| | | map.put("Code","0"); |
| | | map.put("Msg","初始库位无法找到!"); |
| | | return map; |
| | | } |
| | | |
| | | R r = null; |
| | | HashMap<String,Object> r = new HashMap<>(); |
| | | |
| | | if(param.getIoType() == 2){ |
| | | if(param.getStereoscopicTaskType() == 2){ |
| | | //出库任务创建 |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("type_no",2) |
| | | .eq("crn_no",locMast.getCrnNo()) |
| | | .eq("stn_no",param.getTargetPoint())); |
| | | .eq("stn_no",param.getTerminalNo())); |
| | | if(Cools.isEmpty(staDesc)){ |
| | | return R.error("出库路劲不存在"); |
| | | map.put("Code","0"); |
| | | map.put("Msg","出库路劲不存在!"); |
| | | return map; |
| | | } |
| | | r = openService.taskCreate(new TaskCreateParam(param,staDesc.getCrnNo())); |
| | | }else if (param.getIoType() == 3){ |
| | | if(r.get("Code").equals("0")){ |
| | | return r; |
| | | } |
| | | }else if (param.getStereoscopicTaskType() == 3){ |
| | | String fusion1 = Utils.Fusion(param.getGoalRowNo(), param.getGoalFloorNo(), param.getGoalColumnNo()); |
| | | param.setTerminalNo(fusion1); |
| | | //移库任务创建 |
| | | r = openService.taskCreate(new TaskCreateParam(param,locMast.getCrnNo())); |
| | | if(r.get("Code").equals("0")){ |
| | | return r; |
| | | } |
| | | } |
| | | |
| | | apiLogService.save("Wms任务下发接口" |
| | | ,request.getRemoteAddr()+request.getRequestURI() |
| | | ,appkey |
| | | ,"" |
| | | ,request.getRemoteAddr() |
| | | ,JSON.toJSONString(param) |
| | | ,r.toString() |
| | | ,true |
| | | ); |
| | | |
| | | } |
| | | |
| | | return R.ok(); |
| | | map.put("Code","1"); |
| | | map.put("Msg","ok"); |
| | | return map; |
| | | } |
| | | |
| | | //任务取消接口 |
| | |
| | | } |
| | | |
| | | //设备状态查询接口 |
| | | @PostMapping("/deviceStatus") |
| | | @GetMapping("/deviceStatus") |
| | | @Transactional |
| | | public R deviceStatus(@RequestHeader String appkey, |
| | | HttpServletRequest request) { |
| | | auth(appkey, "设备状态查询接口", request); |
| | | List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>()); |
| | | List<Object> list = new ArrayList<>(); |
| | | for (BasDevp basDevp:basDevps){ |
| | | list.add(basDevp); |
| | | } |
| | | public R deviceStatus() { |
| | | List<CrnStatusParam> crnStatusParams=new ArrayList<>(); |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | for (BasCrnp basCrnp:basCrnps){ |
| | | list.add(basCrnp); |
| | | CrnStatusParam crnStatusParam=new CrnStatusParam(); |
| | | crnStatusParam.setCrnNo(basCrnp.getCrnNo()); |
| | | crnStatusParam.setCrnSts(basCrnp.getCrnSts()); |
| | | crnStatusParam.setErrorCode(basCrnp.getCrnErr()); |
| | | BasCrnError error=basCrnErrorService.selectOne(new EntityWrapper<BasCrnError>().eq("error_code",basCrnp.getCrnErr())); |
| | | if(Cools.isEmpty(error)){ |
| | | crnStatusParam.setErrorMsg(""); |
| | | }else { |
| | | crnStatusParam.setErrorMsg(error.getErrName()); |
| | | } |
| | | crnStatusParams.add(crnStatusParam); |
| | | } |
| | | return R.ok(list); |
| | | return R.ok(crnStatusParams); |
| | | } |
| | | |
| | | public static <T> List<T> convertListMapToListObject(List<HashMap<String, Object>> listMap, Class<T> clazz) throws Exception { |
| | | List<T> list = new ArrayList<>(); |
| | | |
| | | for (Map<String, Object> map : listMap) { |
| | | T obj = clazz.getDeclaredConstructor().newInstance(); |
| | | |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | String key = entry.getKey(); |
| | | Object value = entry.getValue(); |
| | | |
| | | try { |
| | | Field field = clazz.getDeclaredField(key); |
| | | field.setAccessible(true); |
| | | setFieldValue(obj, field, value); |
| | | } catch (NoSuchFieldException e) { |
| | | System.out.println("No such field: " + key + " in class " + clazz.getName()); |
| | | } |
| | | } |
| | | |
| | | list.add(obj); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | private static void setFieldValue(Object obj, Field field, Object value) throws IllegalAccessException { |
| | | Class<?> fieldType = field.getType(); |
| | | |
| | | if (fieldType.isAssignableFrom(value.getClass())) { |
| | | field.set(obj, value); |
| | | } else if (fieldType == int.class || fieldType == Integer.class) { |
| | | field.set(obj, ((Number) value).intValue()); |
| | | } else if (fieldType == long.class || fieldType == Long.class) { |
| | | field.set(obj, ((Number) value).longValue()); |
| | | } else if (fieldType == double.class || fieldType == Double.class) { |
| | | field.set(obj, ((Number) value).doubleValue()); |
| | | } else if (fieldType == float.class || fieldType == Float.class) { |
| | | field.set(obj, ((Number) value).floatValue()); |
| | | } else if (fieldType == boolean.class || fieldType == Boolean.class) { |
| | | field.set(obj, (Boolean) value); |
| | | } else if (fieldType == String.class) { |
| | | field.set(obj, String.valueOf(value)); |
| | | } else { |
| | | System.out.println("Unsupported field type: " + fieldType.getName()); |
| | | } |
| | | } |
| | | |
| | | } |