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 | 208 ++++++++++++++++++++++++++-------------------------- 1 files changed, 104 insertions(+), 104 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 f4c88e5..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 @@ -5,8 +5,7 @@ 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.Constant; -import com.zy.asrs.wms.apis.wcs.entity.request.ConveyorStarParam; +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; @@ -22,19 +21,14 @@ 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.TransactionDefinition; -import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @Slf4j @@ -54,45 +48,45 @@ /*** * 鍏ュ簱浠诲姟---閫氱煡ESS杈撻�佺嚎娴佸姩 */ - // @Scheduled(cron = "0/3 * * * * ? ") + @Scheduled(cron = "0/3 * * * * ? ") @Transactional(rollbackFor = Exception.class) public void conveyorStart() { List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() - .eq(Task::getTaskSts, TaskStsType.WCS_CONTAINER_RECEIVE.id).eq(Task::getStatus, 0)); + .eq(Task::getTaskSts, TaskStsType.WCS_CONTAINER_RECEIVE.id).eq(Task::getStatus, 1)); tasks.forEach(task -> { try { - ConveyorStarParam conveyorStarParam = new ConveyorStarParam(); - conveyorStarParam.setSlotCode(task.getOriginLoc()) - .setContainerCode(task.getBarcode()); - //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴 - MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); - // 璁剧疆璇锋眰鍙傛暟 - params.add("params", JSONObject.toJSONString(conveyorStarParam)); - log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.CONVEYOR_START, JSONObject.toJSONString(conveyorStarParam)); - HttpHeaders headers = new HttpHeaders(); - headers.add("Content-Type", "application/json"); - HttpEntity httpEntity = new HttpEntity<>(params, headers); - // 璇锋眰 - ResponseEntity<String> exchange = restTemplate.exchange(Constant.CONVEYOR_START, HttpMethod.POST, httpEntity, String.class); - log.info("涓嬪彂娴佸姩閫氱煡 杩斿洖缁撴灉锛歿}", exchange); - if (exchange.getBody() == null) { - throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒"); - } else { - CommonReponse commonReponse = JSON.toJavaObject(JSON.parseObject(exchange.getBody()), CommonReponse.class); - if (commonReponse.getCode() == 0) { +// ConveyorStarParam conveyorStarParam = new ConveyorStarParam(); +// conveyorStarParam.setSlotCode(task.getOriginLoc()) +// .setContainerCode(task.getBarcode()); +// //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴 +// MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); +// // 璁剧疆璇锋眰鍙傛暟 +// params.add("params", JSONObject.toJSONString(conveyorStarParam)); +// log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.CONVEYOR_START, JSONObject.toJSONString(conveyorStarParam)); +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Content-Type", "application/json"); +// HttpEntity httpEntity = new HttpEntity<>(params, headers); +// // 璇锋眰 +// ResponseEntity<String> exchange = restTemplate.exchange(Constant.CONVEYOR_START, HttpMethod.POST, httpEntity, String.class); +// log.info("涓嬪彂娴佸姩閫氱煡 杩斿洖缁撴灉锛歿}", exchange); +// if (exchange.getBody() == null) { +// throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒"); +// } else { +// 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::getTaskType, TaskStsType.WCS_CONVEYOR_START.id)); - log.info(task.getTaskNo() + "涓嬪彂娴佸姩閫氱煡" + commonReponse.getMsg()); - } else { - throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒"); - } - } + .set(Task::getTaskSts, TaskStsType.WCS_CONVEYOR_START.id)); +// log.info(task.getTaskNo() + "涓嬪彂娴佸姩閫氱煡" + commonReponse.getMsg()); +// } else { +// throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒"); +// } +// } } catch (Exception ex) { log.error(ex.getMessage()); } finally { //濡傛灉寮傚父淇敼绂佺敤鐘舵�� - taskService.update(new LambdaUpdateWrapper<Task>().set(Task::getStatus, 1).eq(Task::getId, task.getId())); +// taskService.update(new LambdaUpdateWrapper<Task>().set(Task::getStatus, 0).eq(Task::getId, task.getId())); } }); @@ -100,18 +94,22 @@ /*** - * 鍏ュ簱浠诲姟---姣忛殧3绉掞紝鍒锋柊褰撳墠閫氱煡妗e垪琛紝涓嬪彂寰呭叆搴撹鍗曡嚦ESS + * 鍏ュ簱浠诲姟---涓嬪彂鍏ュ簱浠诲姟 + * 姣忛殧3绉掞紝鍒锋柊褰撳墠閫氱煡妗e垪琛紝涓嬪彂寰呭叆搴撹鍗曡嚦ESS * 鏌ヨ褰撳墠浠诲姟鍒楄〃锛� */ -// @Scheduled(cron = "0/3 * * * * ? ") + @Scheduled(cron = "0/3 * * * * ? ") @Transactional(rollbackFor = Exception.class) public void waitPakinSchedule() { //鑾峰彇褰撳墠浠诲姟妗d腑锛屾墍鏈変负寰呭叆搴撶姸鎬佺殑浠诲姟妗o紝鎸夋椂闂村崌搴忔帓鍒� List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() - .eq(Task::getTaskType, 1) - .eq(Task::getTaskSts, TaskStsType.GENERATE_IN)) +// .eq(Task::getTaskType, 1) + .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(); @@ -139,19 +137,19 @@ MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); // 璁剧疆璇锋眰鍙傛暟 params.add("params", JSONObject.toJSONString(tasksParam)); - log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.ISSUE_TASK_OF_EVENT, 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(Constant.ISSUE_TASK_OF_EVENT, HttpMethod.POST, httpEntity, String.class); + 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) @@ -166,63 +164,61 @@ /** - * 鍑哄簱浠诲姟--- 姣忛殧3绉掞紝鑾峰彇褰撳墠鍑哄簱浠诲姟鍒楄〃鐘舵�佷负WCS_EXECUTE_OUT_ARRIVED鐨勪换鍔★紝骞堕�氱煡ESS娴佸姩杈撻�佺嚎 - * */ -// @Scheduled(cron = "0/3 * * * * ? ") + * //fixme 寮冪敤 + * 鍑哄簱浠诲姟---閫氱煡瀹瑰櫒娴佸姩 + * 姣忛殧3绉掞紝鑾峰彇褰撳墠鍑哄簱浠诲姟鍒楄〃鐘舵�佷负COMPLETE_OUT鐨勪换鍔★紝骞堕�氱煡ESS娴佸姩杈撻�佺嚎 + */ +// @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, 0)); - tasks.forEach(task -> { - try { - ConveyorStarParam conveyorStarParam = new ConveyorStarParam(); - conveyorStarParam.setSlotCode(task.getOriginLoc()) - .setContainerCode(task.getBarcode()); - if (task.getTaskType() == 101) { //浠诲姟绫诲瀷涓�101鍏ㄧ洏鍑哄簱锛岀洿鎺ュ彇涓嬪鍣紝浼�200 - conveyorStarParam.setDirection("200"); - } else if (task.getTaskType() == 103) { //濡傛灉涓轰换鍔$被鍨嬩负103锛岄渶璧板洖搴撴搷浣滐紝浼�100 - conveyorStarParam.setDirection("100"); - } - //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴 - MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); - // 璁剧疆璇锋眰鍙傛暟 - params.add("params", JSONObject.toJSONString(conveyorStarParam)); - log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.CONVEYOR_START, JSONObject.toJSONString(conveyorStarParam)); - HttpHeaders headers = new HttpHeaders(); - headers.add("Content-Type", "application/json"); - HttpEntity httpEntity = new HttpEntity<>(params, headers); - // 璇锋眰 - ResponseEntity<String> exchange = restTemplate.exchange(Constant.CONVEYOR_START, HttpMethod.POST, httpEntity, String.class); - log.info("涓嬪彂娴佸姩閫氱煡 杩斿洖缁撴灉锛歿}", exchange); - if (exchange.getBody() == null) { - throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒"); - } else { - CommonReponse commonReponse = JSON.toJavaObject(JSON.parseObject(exchange.getBody()), CommonReponse.class); - if (commonReponse.getCode() == 0) { - //娴佸姩閫氱煡涓嬪彂瀹屾垚鍚庯紝淇敼浠诲姟鐘舵�佷负杈撻�佺嚎娴佸姩涓�傘�� - if (task.getTaskType() == 101) { - taskService.update(new LambdaUpdateWrapper<Task>() - .eq(Task::getId, task.getId()) - .set(Task::getTaskType, TaskStsType.COMPLETE_OUT.id)); - } else { - taskService.update(new LambdaUpdateWrapper<Task>() - .eq(Task::getId, task.getId()) - .set(Task::getTaskType, TaskStsType.WCS_EXECUTE_OUT_CONVEYOR.id)); - } + .eq(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT_CONVEYOR.id).eq(Task::getStatus, 1)); - log.info(task.getTaskNo() + "涓嬪彂娴佸姩閫氱煡" + commonReponse.getMsg()); - } else { - throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒"); - } - } - } catch (Exception ex) { - log.error(ex.getMessage()); - } finally { - //濡傛灉寮傚父淇敼绂佺敤鐘舵�� - taskService.update(new LambdaUpdateWrapper<Task>().set(Task::getStatus, 1) - .set(Task::getUpdateTime, new Date()) - .eq(Task::getId, task.getId())); - } + // 杩橀渶瑕佸啀淇敼 + tasks.forEach(task -> { +// try { +// ConveyorStarParam conveyorStarParam = new ConveyorStarParam(); +// conveyorStarParam.setSlotCode(task.getOriginLoc()) +// .setContainerCode(task.getBarcode()); +// if (task.getTaskType() == 101) { //浠诲姟绫诲瀷涓�101鍏ㄧ洏鍑哄簱锛岀洿鎺ュ彇涓嬪鍣紝浼�200 +// conveyorStarParam.setDirection("200"); +// } else if (task.getTaskType() == 103) { //濡傛灉涓轰换鍔$被鍨嬩负103锛岄渶璧板洖搴撴搷浣滐紝浼�100 +// conveyorStarParam.setDirection("100"); +// } +// //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴 +// MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); +// // 璁剧疆璇锋眰鍙傛暟 +// params.add("params", JSONObject.toJSONString(conveyorStarParam)); +// log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.CONVEYOR_START, JSONObject.toJSONString(conveyorStarParam)); +// HttpHeaders headers = new HttpHeaders(); +// headers.add("Content-Type", "application/json"); +// HttpEntity httpEntity = new HttpEntity<>(params, headers); +// // 璇锋眰 +// ResponseEntity<String> exchange = restTemplate.exchange(Constant.CONVEYOR_START, HttpMethod.POST, httpEntity, String.class); +// log.info("涓嬪彂娴佸姩閫氱煡 杩斿洖缁撴灉锛歿}", exchange); +// if (exchange.getBody() == null) { +// throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒"); +// } else { +// 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_OUT.id)); + +// log.info(task.getTaskNo() + "涓嬪彂娴佸姩閫氱煡" + commonReponse.getMsg()); +// } else { +// throw new CoolException("涓嬪彂娴佸姩閫氱煡澶辫触锛侊紒"); +// } +// } +// } catch (Exception ex) { +// log.error(ex.getMessage()); +// } finally { +// //濡傛灉寮傚父淇敼绂佺敤鐘舵�� +// taskService.update(new LambdaUpdateWrapper<Task>().set(Task::getStatus, 0) +// .set(Task::getUpdateTime, new Date()) +// .eq(Task::getId, task.getId())); +// } }); } @@ -233,14 +229,17 @@ * //TODO 1. 姝e父鍑哄簱鍚庯紝娓呴櫎浠诲姟锛� * //TODO 2. 鍑哄簱鍚庤繕鏈夊簱瀛橈紝闇�瑕佹坊鍔犲鍣ㄥ洖搴撴搷浣� */ - //@Scheduled(cron = "0/3 * * * * ? ") + @Scheduled(cron = "0/3 * * * * ? ") @Transactional(rollbackFor = Exception.class) public void waveToTask() { //鑾峰彇褰撳墠浠诲姟妗d腑锛屾墍鏈変负寰呭嚭搴撶姸鎬佺殑浠诲姟妗o紝鎸夋椂闂村崌搴忔帓鍒� List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() - .eq(Task::getTaskType, 101) //TODO 濡備綍纭鏄�101锛岃繕鏄�103 - .eq(Task::getTaskSts, TaskStsType.GENERATE_OUT)) - .stream().sorted(Comparator.comparing(Task::getTaskSts)) + .ge(Task::getTaskType, 101) //TODO 濡備綍纭鏄�101锛岃繕鏄�103 + .eq(Task::getTaskSts, TaskStsType.GENERATE_OUT.id)); + if (tasks.isEmpty()) { + return; + } + tasks.stream().sorted(Comparator.comparing(Task::getTaskSts)) .collect(Collectors.toList()); // 鏁版嵁缁勮 @@ -267,14 +266,15 @@ // TODO 澶氫换鍔″璁㈠崟锛岀粺涓�璋冨害锛屾槸鍚︿細鍑虹幇閮ㄥ垎鎴愬姛锛岄儴鍒嗗け璐ョ殑鎯呭喌 //璋冪敤涓夋柟鎺ュ彛锛屽皢浠诲姟鎺ㄩ�佽嚦ESS骞冲彴 MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); + SystemProperties properties = new SystemProperties(); // 璁剧疆璇锋眰鍙傛暟 params.add("params", JSONObject.toJSONString(tasksParam)); - log.info("璇锋眰鍦板潃锛歿}锛岃姹傚弬鏁帮細{}", Constant.ISSUE_TASK_OF_EVENT, 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(Constant.ISSUE_TASK_OF_EVENT, HttpMethod.POST, httpEntity, String.class); + ResponseEntity<String> exchange = restTemplate.exchange(properties.getBaseHost() + properties.getIssueTaskOfEvent(), HttpMethod.POST, httpEntity, String.class); log.info("涓嬪彂浠诲姟 杩斿洖缁撴灉锛歿}", exchange); if (exchange.getBody() == null) { throw new CoolException("涓嬪彂浠诲姟澶辫触锛侊紒"); @@ -285,7 +285,7 @@ tasks.forEach(task -> { taskService.update(new LambdaUpdateWrapper<Task>() .set(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT.id) - .eq(Task::getBarcode, task.getBarcode())); + .eq(Task::getId, task.getId())); }); } else { // TODO 璇锋眰澶辫触闇�纭鏄惁瀛樺湪閮ㄥ垎鎴愬姛鐨勬儏鍐碉紝閮ㄥ垎鎴愬姛闇�瑕佸崟鐙埛鏂版垚鍔熺殑浠诲姟妗g姸鎬� -- Gitblit v1.9.1