From 83b51a5a0774ea8ecb9a06304af3b956a21307c8 Mon Sep 17 00:00:00 2001 From: pjb <123456> Date: 星期六, 08 三月 2025 09:06:55 +0800 Subject: [PATCH] CUT库条码T开头,截取后10位 --- zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java | 211 +++++++++++++++++++++++++++++----------------------- 1 files changed, 116 insertions(+), 95 deletions(-) diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java index 566609c..7ea4d15 100644 --- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java +++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/schedule/ScheduleJobs.java @@ -1,21 +1,34 @@ package com.zy.asrs.wms.apis.wcs.schedule; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.zy.asrs.framework.exception.CoolException; +import com.zy.asrs.wms.apis.wcs.entity.domain.SystemProperties; +import com.zy.asrs.wms.apis.wcs.entity.request.PublishTasksParam; +import com.zy.asrs.wms.apis.wcs.entity.request.TaskDescribe; +import com.zy.asrs.wms.apis.wcs.entity.request.TaskParam; +import com.zy.asrs.wms.apis.wcs.entity.response.CommonReponse; import com.zy.asrs.wms.asrs.entity.Task; import com.zy.asrs.wms.asrs.entity.enums.TaskStsType; import com.zy.asrs.wms.asrs.service.TaskService; import com.zy.asrs.wms.asrs.service.WorkService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @Slf4j @@ -94,68 +107,72 @@ .eq(Task::getTaskSts, TaskStsType.GENERATE_IN.id)) .stream().sorted(Comparator.comparing(Task::getTaskSts)) .collect(Collectors.toList()); + if (tasks.size() == 0) { + return; + } // 鏁版嵁缁勮 -// PublishTasksParam tasksParam = new PublishTasksParam(); -// //TODO 纭鏄惁闇�瑕佸崟浠诲姟澶氬鍣ㄧ爜鐨勯渶姹傦紝鐩墠绯荤粺閮芥槸鍗曞鍣ㄧ爜鐢熸垚鍗曚换鍔★紝澶氫换鍔℃槑缁嗭紙鐗╂枡娣疯锛� -// tasks.forEach(task -> { -// List<TaskParam> params = new ArrayList<>(); -// TaskParam param = new TaskParam(); -// //璁剧疆瀹瑰櫒缂栫爜 -// param.setTaskCode(task.getTaskNo()); -// List<TaskDescribe> taskDescribes = new ArrayList<>(); -// TaskDescribe describe = new TaskDescribe(); -// //璁剧疆鐩爣搴撲綅锛岀珯鐐� -// describe.setContainerCode(task.getBarcode()) -// .setToLocationCode(task.getTargetLoc()) -// .setToStationCode(task.getTargetSite()); -// taskDescribes.add(describe); -// param.setTaskDescribe(taskDescribes); -// params.add(param); -// tasksParam.setTasks(params); -// }); -// -// tasksParam.setTaskType("putaway"); -// // TODO 澶氫换鍔″璁㈠崟锛岀粺涓�璋冨害锛屾槸鍚︿細鍑虹幇閮ㄥ垎鎴愬姛锛岄儴鍒嗗け璐ョ殑鎯呭喌 -// //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴 -// MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); -// // 璁剧疆璇锋眰鍙傛暟 -// params.add("params", JSONObject.toJSONString(tasksParam)); -// log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.ISSUE_TASK_OF_EVENT, JSONObject.toJSONString(tasksParam)); -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Content-Type", "application/json"); -// HttpEntity httpEntity = new HttpEntity<>(params, headers); -// // 璇锋眰 -// ResponseEntity<String> exchange = restTemplate.exchange(Constant.ISSUE_TASK_OF_EVENT, HttpMethod.POST, httpEntity, String.class); -// log.info("涓嬪彂浠诲姟 杩斿洖缁撴灉锛歿}", exchange); -// if (exchange.getBody() == null) { -// throw new CoolException("涓嬪彂浠诲姟澶辫触锛侊紒"); -// } else { -// CommonReponse reponse = (CommonReponse) JSON.parse(exchange.getBody()); -// if (reponse.getCode() == 0) { - //璇锋眰鎴愬姛鍚庯紝缁熶竴淇敼鎵�鏈変换鍔℃。鐘舵�佷负鍏ュ簱鎵ц涓�� + PublishTasksParam tasksParam = new PublishTasksParam(); + //TODO 纭鏄惁闇�瑕佸崟浠诲姟澶氬鍣ㄧ爜鐨勯渶姹傦紝鐩墠绯荤粺閮芥槸鍗曞鍣ㄧ爜鐢熸垚鍗曚换鍔★紝澶氫换鍔℃槑缁嗭紙鐗╂枡娣疯锛� + tasks.forEach(task -> { + List<TaskParam> params = new ArrayList<>(); + TaskParam param = new TaskParam(); + //璁剧疆瀹瑰櫒缂栫爜 + param.setTaskCode(task.getTaskNo()); + List<TaskDescribe> taskDescribes = new ArrayList<>(); + TaskDescribe describe = new TaskDescribe(); + //璁剧疆鐩爣搴撲綅锛岀珯鐐� + describe.setContainerCode(task.getBarcode()) + .setToLocationCode(task.getTargetLoc()) + .setToStationCode(task.getTargetSite()); + taskDescribes.add(describe); + param.setTaskDescribe(taskDescribes); + params.add(param); + tasksParam.setTasks(params); + }); + + tasksParam.setTaskType("putaway"); + // TODO 澶氫换鍔″璁㈠崟锛岀粺涓�璋冨害锛屾槸鍚︿細鍑虹幇閮ㄥ垎鎴愬姛锛岄儴鍒嗗け璐ョ殑鎯呭喌 + //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴 + MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); + // 璁剧疆璇锋眰鍙傛暟 + params.add("params", JSONObject.toJSONString(tasksParam)); + log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", "http://192.168.2.200:9046/task/create", JSONObject.toJSONString(tasksParam)); + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", "application/json"); + HttpEntity httpEntity = new HttpEntity<>(params, headers); + // 璇锋眰 + ResponseEntity<String> exchange = restTemplate.exchange("http://192.168.2.200:9046/task/create", HttpMethod.POST, httpEntity, String.class); + log.info("涓嬪彂浠诲姟 杩斿洖缁撴灉锛歿}", exchange); + if (exchange.getBody() == null) { + throw new CoolException("涓嬪彂浠诲姟澶辫触锛侊紒"); + } else { + CommonReponse reponse = (CommonReponse) JSON.parse(exchange.getBody()); + if (reponse.getCode() == 0) { + // 璇锋眰鎴愬姛鍚庯紝缁熶竴淇敼鎵�鏈変换鍔℃。鐘舵�佷负鍏ュ簱鎵ц涓�� tasks.forEach(task -> { taskService.update(new LambdaUpdateWrapper<Task>() .set(Task::getTaskSts, TaskStsType.WCS_EXECUTE_IN.id) .eq(Task::getBarcode, task.getBarcode())); }); -// } else { -// // TODO 璇锋眰澶辫触闇�纭鏄惁瀛樺湪閮ㄥ垎鎴愬姛鐨勬儏鍐碉紝閮ㄥ垎鎴愬姛闇�瑕佸崟鐙埛鏂版垚鍔熺殑浠诲姟妗g姸鎬� -// throw new CoolException(reponse.getMsg()); -// } -// } + } else { + // TODO 璇锋眰澶辫触闇�纭鏄惁瀛樺湪閮ㄥ垎鎴愬姛鐨勬儏鍐碉紝閮ㄥ垎鎴愬姛闇�瑕佸崟鐙埛鏂版垚鍔熺殑浠诲姟妗g姸鎬� + throw new CoolException(reponse.getMsg()); + } + } } /** + * //fixme 寮冪敤 * 鍑哄簱浠诲姟---閫氱煡瀹瑰櫒娴佸姩 - * 姣忛殧3绉掞紝鑾峰彇褰撳墠鍑哄簱浠诲姟鍒楄〃鐘舵�佷负WCS_EXECUTE_OUT_ARRIVED鐨勪换鍔★紝骞堕�氱煡ESS娴佸姩杈撻�佺嚎 + * 姣忛殧3绉掞紝鑾峰彇褰撳墠鍑哄簱浠诲姟鍒楄〃鐘舵�佷负COMPLETE_OUT鐨勪换鍔★紝骞堕�氱煡ESS娴佸姩杈撻�佺嚎 */ - @Scheduled(cron = "0/5 * * * * ? ") +// @Scheduled(cron = "0/5 * * * * ? ") @Transactional(rollbackFor = Exception.class) public void conveyorToNotify() { List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() - .eq(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT_ARRIVED.id).eq(Task::getStatus, 1)); + .eq(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT_CONVEYOR.id).eq(Task::getStatus, 1)); // 杩橀渶瑕佸啀淇敼 tasks.forEach(task -> { @@ -185,9 +202,9 @@ // CommonReponse commonReponse = JSON.toJavaObject(JSON.parseObject(exchange.getBody()), CommonReponse.class); // if (commonReponse.getCode() == 0) { //娴佸姩閫氱煡涓嬪彂瀹屾垚鍚庯紝淇敼浠诲姟鐘舵�佷负杈撻�佺嚎娴佸姩涓�傘�� - taskService.update(new LambdaUpdateWrapper<Task>() - .eq(Task::getId, task.getId()) - .set(Task::getTaskSts, TaskStsType.COMPLETE_IN.id)); +// taskService.update(new LambdaUpdateWrapper<Task>() +// .eq(Task::getId, task.getId()) +// .set(Task::getTaskSts, TaskStsType.COMPLETE_OUT.id)); // log.info(task.getTaskNo() + "涓嬪彂娴佸姩閫氱煡" + commonReponse.getMsg()); // } else { @@ -218,58 +235,62 @@ //鑾峰彇褰撳墠浠诲姟妗d腑锛屾墍鏈変负寰呭嚭搴撶姸鎬佺殑浠诲姟妗o紝鎸夋椂闂村崌搴忔帓鍒� List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() .ge(Task::getTaskType, 101) //TODO 濡備綍纭鏄�101锛岃繕鏄�103 - .eq(Task::getTaskSts, TaskStsType.GENERATE_OUT.id)) - .stream().sorted(Comparator.comparing(Task::getTaskSts)) + .eq(Task::getTaskSts, TaskStsType.GENERATE_OUT.id)); + if (tasks.isEmpty()) { + return; + } + tasks.stream().sorted(Comparator.comparing(Task::getTaskSts)) .collect(Collectors.toList()); // 鏁版嵁缁勮 -// PublishTasksParam tasksParam = new PublishTasksParam(); -// //TODO 纭鏄惁闇�瑕佸崟浠诲姟澶氬鍣ㄧ爜鐨勯渶姹傦紝鐩墠绯荤粺閮芥槸鍗曞鍣ㄧ爜鐢熸垚鍗曚换鍔★紝澶氫换鍔℃槑缁嗭紙鐗╂枡娣疯锛� -// tasks.forEach(task -> { -// List<TaskParam> params = new ArrayList<>(); -// TaskParam param = new TaskParam(); -// //璁剧疆瀹瑰櫒缂栫爜 -// param.setTaskCode(task.getTaskNo()); -// List<TaskDescribe> taskDescribes = new ArrayList<>(); -// TaskDescribe describe = new TaskDescribe(); -// //璁剧疆鐩爣搴撲綅锛岀珯鐐� -// describe.setContainerCode(task.getBarcode()) -// .setToLocationCode(task.getTargetLoc()) -// .setToStationCode(task.getTargetSite()); -// taskDescribes.add(describe); -// param.setTaskDescribe(taskDescribes); -// params.add(param); -// tasksParam.setTasks(params); -// }); -// -// tasksParam.setTaskType("carry"); -// // TODO 澶氫换鍔″璁㈠崟锛岀粺涓�璋冨害锛屾槸鍚︿細鍑虹幇閮ㄥ垎鎴愬姛锛岄儴鍒嗗け璐ョ殑鎯呭喌 -// //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴 -// MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); -// // 璁剧疆璇锋眰鍙傛暟 -// params.add("params", JSONObject.toJSONString(tasksParam)); -// log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.ISSUE_TASK_OF_EVENT, JSONObject.toJSONString(tasksParam)); -// HttpHeaders headers = new HttpHeaders(); -// headers.add("Content-Type", "application/json"); -// HttpEntity httpEntity = new HttpEntity<>(params, headers); -// // 璇锋眰 -// ResponseEntity<String> exchange = restTemplate.exchange(Constant.ISSUE_TASK_OF_EVENT, HttpMethod.POST, httpEntity, String.class); -// log.info("涓嬪彂浠诲姟 杩斿洖缁撴灉锛歿}", exchange); -// if (exchange.getBody() == null) { -// throw new CoolException("涓嬪彂浠诲姟澶辫触锛侊紒"); -// } else { -// CommonReponse reponse = (CommonReponse) JSON.parse(exchange.getBody()); -// if (reponse.getCode() == 0) { + PublishTasksParam tasksParam = new PublishTasksParam(); + //TODO 纭鏄惁闇�瑕佸崟浠诲姟澶氬鍣ㄧ爜鐨勯渶姹傦紝鐩墠绯荤粺閮芥槸鍗曞鍣ㄧ爜鐢熸垚鍗曚换鍔★紝澶氫换鍔℃槑缁嗭紙鐗╂枡娣疯锛� + tasks.forEach(task -> { + List<TaskParam> params = new ArrayList<>(); + TaskParam param = new TaskParam(); + //璁剧疆瀹瑰櫒缂栫爜 + param.setTaskCode(task.getTaskNo()); + List<TaskDescribe> taskDescribes = new ArrayList<>(); + TaskDescribe describe = new TaskDescribe(); + //璁剧疆鐩爣搴撲綅锛岀珯鐐� + describe.setContainerCode(task.getBarcode()) + .setToLocationCode(task.getTargetLoc()) + .setToStationCode(task.getTargetSite()); + taskDescribes.add(describe); + param.setTaskDescribe(taskDescribes); + params.add(param); + tasksParam.setTasks(params); + }); + + tasksParam.setTaskType("carry"); + // TODO 澶氫换鍔″璁㈠崟锛岀粺涓�璋冨害锛屾槸鍚︿細鍑虹幇閮ㄥ垎鎴愬姛锛岄儴鍒嗗け璐ョ殑鎯呭喌 + //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴 + MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); + SystemProperties properties = new SystemProperties(); + // 璁剧疆璇锋眰鍙傛暟 + params.add("params", JSONObject.toJSONString(tasksParam)); + log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", properties.getBaseHost() + properties.getIssueTaskOfEvent(), JSONObject.toJSONString(tasksParam)); + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", "application/json"); + HttpEntity httpEntity = new HttpEntity<>(params, headers); + // 璇锋眰 + ResponseEntity<String> exchange = restTemplate.exchange(properties.getBaseHost() + properties.getIssueTaskOfEvent(), HttpMethod.POST, httpEntity, String.class); + log.info("涓嬪彂浠诲姟 杩斿洖缁撴灉锛歿}", exchange); + if (exchange.getBody() == null) { + throw new CoolException("涓嬪彂浠诲姟澶辫触锛侊紒"); + } else { + CommonReponse reponse = (CommonReponse) JSON.parse(exchange.getBody()); + if (reponse.getCode() == 0) { //璇锋眰鎴愬姛鍚庯紝缁熶竴淇敼鎵�鏈変换鍔℃。鐘舵�佷负鍏ュ簱鎵ц涓�� tasks.forEach(task -> { taskService.update(new LambdaUpdateWrapper<Task>() .set(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT.id) .eq(Task::getId, task.getId())); }); -// } else { -// // TODO 璇锋眰澶辫触闇�纭鏄惁瀛樺湪閮ㄥ垎鎴愬姛鐨勬儏鍐碉紝閮ㄥ垎鎴愬姛闇�瑕佸崟鐙埛鏂版垚鍔熺殑浠诲姟妗g姸鎬� -// throw new CoolException(reponse.getMsg()); -// } -// } + } else { + // TODO 璇锋眰澶辫触闇�纭鏄惁瀛樺湪閮ㄥ垎鎴愬姛鐨勬儏鍐碉紝閮ㄥ垎鎴愬姛闇�瑕佸崟鐙埛鏂版垚鍔熺殑浠诲姟妗g姸鎬� + throw new CoolException(reponse.getMsg()); + } + } } } -- Gitblit v1.9.1