From d65679fefe52fc2bf2435825c65aec3a329e3b9e Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期二, 22 四月 2025 14:40:21 +0800 Subject: [PATCH] # --- src/main/java/com/zy/asrs/controller/OpenController.java | 281 ++++++++++--------------------------------------------- 1 files changed, 54 insertions(+), 227 deletions(-) diff --git a/src/main/java/com/zy/asrs/controller/OpenController.java b/src/main/java/com/zy/asrs/controller/OpenController.java index 9a16f6c..13cef9e 100644 --- a/src/main/java/com/zy/asrs/controller/OpenController.java +++ b/src/main/java/com/zy/asrs/controller/OpenController.java @@ -3,12 +3,10 @@ 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.*; import com.zy.asrs.service.*; @@ -21,11 +19,8 @@ import org.springframework.web.bind.annotation.*; 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 @@ -61,24 +56,16 @@ 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); + + private void auth(String appkey, Object obj, HttpServletRequest request) { + log.info("{}鎺ュ彛琚闂紱appkey:{}锛涜姹傛暟鎹細{}", request.getServletPath(), appkey, JSON.toJSONString(obj)); + request.setAttribute("cache", obj); + if (Cools.isEmpty(appkey)) { + throw new CoolException("璁よ瘉澶辫触锛岃纭appkey鏃犺锛�"); } - if (Cools.isEmpty(param.getWharfCode())){ - return R.error("鐮佸ご[wharfCode]涓嶈兘涓虹┖"); + if (!APP_KEY_LIST.contains(appkey)) { + throw new CoolException("璁よ瘉澶辫触锛岃纭appkey鏃犺锛�"); } - if (Cools.isEmpty(param.getStatus())){ - return R.error("瀹屾垚鏍囪[status]涓嶈兘涓虹┖"); - } - openService.getAgvTaskOver(param); - return R.ok(); } //鍒涘缓浠诲姟 @@ -105,26 +92,26 @@ return R.error("鏉$爜[barcode]涓嶈兘涓虹┖"); } String locNo=null; - if(param.getIoType()==1){ - locNo=param.getTargetPoint(); - }else{ - locNo=param.getStartPoint(); + if (param.getIoType() == 1) { + locNo = param.getTargetPoint(); + } else { + locNo = param.getStartPoint(); } - try{ + 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); + .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); + } 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())); + 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()); } @@ -132,12 +119,41 @@ locNoList.add(locMast.getLocNo()); paramList.add(param); }else { - return R.error("璇ュ簱浣嶄笉鑳藉悓鏃朵笅鍙戜袱绗斾换鍔�"+locMast.getLocNo()); + return R.error("璇ュ簱浣嶄笉鑳藉悓鏃朵笅鍙戜袱绗斾换鍔�" + locMast.getLocNo()); } } for (TaskCreateParam param : paramList){ openService.taskCreate(param); } + }catch (Exception e){ + log.error("浠诲姟涓嬪彂寮傚父"+e); + return R.error(); + } + return R.ok(); + } + + //鍒涘缓鍏ュ簱浠诲姟 + @PostMapping("/taskCreateIn") + @Transactional + public R taskCreateIn(@RequestHeader String appkey, + @RequestBody TaskCreateInParam param, + HttpServletRequest request) { + auth(appkey, param, request); + try{ + 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]涓嶈兘涓虹┖"); + } + + openService.taskCreateIn(param); }catch (Exception e){ log.error("浠诲姟涓嬪彂寮傚父"+e); return R.error(); @@ -158,44 +174,6 @@ 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") public R queryTaskCommand(@RequestHeader String appkey, @@ -209,111 +187,6 @@ List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskNo); return R.ok().add(commandInfos); - } - - private void auth(String appkey, Object obj, HttpServletRequest request) { - log.info("{}鎺ュ彛琚闂紱appkey:{}锛涜姹傛暟鎹細{}", request.getServletPath(), appkey, JSON.toJSONString(obj)); - request.setAttribute("cache", obj); - if (Cools.isEmpty(appkey)) { - throw new CoolException("璁よ瘉澶辫触锛岃纭appkey鏃犺锛�"); - } - if (!APP_KEY_LIST.contains(appkey)) { - throw new CoolException("璁よ瘉澶辫触锛岃纭appkey鏃犺锛�"); - } - } - - //AGV璇锋眰鍏ュ簱鐮佸ご鎺ュ彛 - @PostMapping("/targetWharfApply") - @AppAuth(memo = "AGV璇锋眰鍏ュ簱鐮佸ご鎺ュ彛") - public R targetWharfApply(@RequestHeader String appkey, - @RequestBody WMSAndAGVInterfaceParam param, - 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.getContainerCode())){ - 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锛変负绌猴紒"); - } - 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())){ - return R.error("璇锋眰绫诲瀷涓虹┖锛�"); - } else if (Cools.isEmpty(param.getWharfCode())){ - 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("绔欑偣鐘舵�佷笉鍙叆"); - } - - - - - } //浠诲姟涓嬪彂鎺ュ彛 @@ -462,52 +335,6 @@ crnStatusParams.add(crnStatusParam); } 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()); - } } } -- Gitblit v1.9.1