From 9fe1ec3afe8696c628d076d1f76686c4efc3012e Mon Sep 17 00:00:00 2001
From: zc <zyzc>
Date: 星期二, 21 十月 2025 10:49:55 +0800
Subject: [PATCH] 容器初始化功能优化
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java | 579 +++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 515 insertions(+), 64 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java
index 076e72d..eb5e75e 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java
@@ -1,26 +1,61 @@
package com.vincent.rsf.server.manager.schedules;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.cfg.CoercionAction;
+import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
+import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
-import com.vincent.rsf.server.manager.enums.TaskStsType;
+import com.vincent.rsf.server.api.config.RemotesInfoProperties;
+import com.vincent.rsf.server.api.entity.CommonResponse;
+import com.vincent.rsf.server.api.entity.constant.RcsConstant;
+import com.vincent.rsf.server.api.entity.params.TaskItemParam;
+import com.vincent.rsf.server.api.entity.params.WcsTaskParams;
+import com.vincent.rsf.server.api.utils.LocUtils;
+import com.vincent.rsf.server.common.constant.Constants;
+import com.vincent.rsf.server.manager.controller.params.LocToTaskParams;
+import com.vincent.rsf.server.manager.enums.*;
import com.vincent.rsf.server.manager.entity.*;
import com.vincent.rsf.server.manager.service.*;
+import com.vincent.rsf.server.manager.service.impl.LocServiceImpl;
+import com.vincent.rsf.server.system.constant.GlobalConfigCode;
+import com.vincent.rsf.server.system.constant.SerialRuleCode;
+import com.vincent.rsf.server.system.entity.Config;
+import com.vincent.rsf.server.system.service.ConfigService;
+import com.vincent.rsf.server.system.utils.SerialRuleUtils;
+import com.vincent.rsf.server.system.utils.SystemAuthUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
import java.util.stream.Collectors;
/**
* @Author Ryan
* 浠诲姟宸ヤ綔妗�
*/
+@Slf4j
@Component
public class TaskSchedules {
+
+ public static Logger logger = LoggerFactory.getLogger(TaskSchedules.class);
@Autowired
private TaskService taskService;
@@ -31,91 +66,507 @@
@Autowired
private TaskItemLogService taskItemLogService;
@Autowired
- private StockItemService stockItemService;
+ private ConfigService configService;
@Autowired
- private PurchaseService purchaseService;
+ private LocServiceImpl locService;
+ @Value("${wcs-slave.doubleLocs}")
+ private List<Integer> rows;
@Autowired
- private AsnOrderService asnOrderService;
+ private LocItemService locItemService;
+ @Autowired
+ private OutStockService outStockService;
+ @Autowired
+ private OutStockItemService outStockItemService;
@Autowired
private AsnOrderItemService asnOrderItemService;
@Autowired
- private StockService stockService;
+ private AsnOrderService asnOrderService;
@Autowired
- private LocService locService;
+ private TransferOrderService transferOrderService;
+ @Autowired
+ private TransferService transferService;
+ @Autowired
+ private RestTemplate restTemplate;
+ @Autowired
+ private RemotesInfoProperties.RcsApi rcsApi;
+ @Autowired
+ private BasStationService basStationService;
+
/**
- * @author Ryan
- * @description 瀹屾垚鍏ュ簱锛屾洿鏂板簱瀛�
- * @param
- * @return
- * @time 2025/4/2 12:37
- */
-// @Scheduled(cron = "0 0/05 * * * ? ")
- @Scheduled(cron = "0/15 * * * * ?")
- @Transactional(rollbackFor = Exception.class)
+ * @param
+ * @return
+ * @author Ryan
+ * @description 瀹屾垚鍏ュ簱锛屾洿鏂板簱瀛�
+ * @time 2025/4/2 12:37
+ */
+ @Scheduled(cron = "0/3 * * * * ?")
public void completeInStock() throws Exception {
- List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskStatus, TaskStsType.COMPLETE_IN.id));
+ List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskStatus, TaskStsType.COMPLETE_IN.id).select(Task::getId));
if (tasks.isEmpty()) {
return;
}
- taskService.completeTask(tasks);
+ List<Long> longSet = tasks.stream().map(Task::getId).collect(Collectors.toList());
+ List<Task> vaildTasks = taskService.list(new LambdaQueryWrapper<Task>().in(Task::getId, longSet));
+ taskService.complateInTask(vaildTasks);
+ }
+
+ /**
+ * @author Ryan
+ * @date 2025/5/20
+ * @description: 瀹屾垚鍑哄簱浠诲姟锛屾洿鏂板簱瀛�
+ * @version 1.0
+ */
+ @Scheduled(cron = "0/5 * * * * ? ")
+ @Transactional(rollbackFor = Exception.class)
+ public void complateOutStock() throws Exception {
+ List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
+ .eq(Task::getTaskStatus, TaskStsType.COMPLETE_OUT.id)
+ .select(Task::getId));
+ if (tasks.isEmpty()) {
+ return;
+ }
+ List<Long> longSet = tasks.stream().map(Task::getId).collect(Collectors.toList());
+ List<Task> vaildTasks = taskService.list(new LambdaQueryWrapper<Task>().in(Task::getId, longSet));
+ taskService.completeTask(vaildTasks);
+
+// List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>()
+// .eq(TaskItem::getWkType, OrderWorkType.ORDER_WORK_TYPE_STOCK_TERANSFER.type)
+// .in(TaskItem::getTaskId, longSet));
+// if (!taskItems.isEmpty()) {
+// genInStock(taskItems);
+// }
+ }
+
+ /**
+ * @author Ryan
+ * @date 2025/7/29
+ * @description: 鐢熸垚鍏ュ簱鍗�
+ * @version 1.0
+ */
+ @Transactional(rollbackFor = Exception.class)
+ public void genInStock(List<TaskItem> taskItems) throws Exception {
+ Set<Long> orderIds = taskItems.stream().map(TaskItem::getSourceId).collect(Collectors.toSet());
+ List<WkOrder> wkOrders = outStockService.list(new LambdaQueryWrapper<WkOrder>().in(WkOrder::getId, orderIds));
+ wkOrders.forEach(wkOrder -> {
+ List<WkOrderItem> orderItems = outStockItemService.list(new LambdaQueryWrapper<WkOrderItem>()
+ .eq(WkOrderItem::getOrderId, wkOrder.getId()));
+ if (!orderItems.isEmpty()) {
+ WkOrder order = new WkOrder();
+ BeanUtils.copyProperties(wkOrder, order);
+ String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_ASN_ORDER, order);
+ if (StringUtils.isBlank(ruleCode)) {
+ throw new CoolException("鍏ュ簱鍗曞彿鐢熸垚澶辫触锛侊紒");
+ }
+ order.setWkType(OrderWorkType.ORDER_WORK_TYPE_OTHER_TERANSFER.type)
+ .setId(null)
+ .setCode(ruleCode)
+ .setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val)
+ .setType(OrderType.ORDER_IN.type);
+// Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.DIRECT_WAIT_PAKIN));
+// if (!Boolean.parseBoolean(config.getVal())) {
+// order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val);
+// } else {
+// order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val);
+// }
+ if (!asnOrderService.save(order)) {
+ throw new CoolException("鍏ュ簱鍗曠敓鎴愬け璐ワ紒锛�");
+ }
+
+ orderItems.forEach(orderItem -> {
+ orderItem.setOrderId(order.getId()).setOrderCode(order.getCode()).setId(null);
+ if (!asnOrderItemService.save(orderItem)) {
+ throw new CoolException("鍏ュ簱鍗曟槑缁嗕繚瀛樺け璐ワ紒锛�");
+ }
+ });
+
+ Transfer transfer = transferService.getById(order.getPoId());
+
+ TransferOrder transferOrder = new TransferOrder();
+ transferOrder.setOrderId(order.getId())
+ .setType(OrderType.ORDER_IN.type)
+ .setTransferId(transfer.getId());
+ if (!transferOrderService.save(transferOrder)) {
+ throw new CoolException("鍏宠仈鍗曚繚瀛樺け璐ワ紒锛�");
+ }
+ }
+ });
+
+// Set<Long> taskIds = taskItems.stream().map(TaskItem::getTaskId).collect(Collectors.toSet());
+// List<Task> tasks = taskService.listByIds(taskIds);
+// if (!tasks.isEmpty()) {
+// tasks.forEach(task -> {
+// TaskItem one = taskItemService.getOne(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()), false);
+// if (Objects.isNull(one)) {
+// throw new CoolException("鏁版嵁閿欒锛氫换鍔℃槑缁嗕涪澶憋紒锛�");
+// }
+// TransferOrder order = transferOrderService.getOne(new LambdaQueryWrapper<TransferOrder>().eq(TransferOrder::getOrderId, one.getOrderId()));
+// if (Objects.isNull(order)) {
+// throw new CoolException("鏁版嵁閿欒锛侊紒");
+// }
+// Transfer transfer = transferService.getById(order.getTransferId());
+// Task task1 = new Task();
+// BeanUtils.copyProperties(task, task1);
+// String targetLoc = LocManageUtil.getTargetLoc(transfer.getTarAreaId());
+// if (Objects.isNull(targetLoc)) {
+// throw new CoolException("鏈兘鎵惧埌鏈夋晥搴撲綅");
+// }
+// task.setTaskType(TaskType.TASK_TYPE_IN.type)
+// .setTargLoc(targetLoc)
+// .setTargSite(null)
+// .setId(null)
+// .setTaskStatus(TaskStsType.GENERATE_IN.id);
+// if (!taskService.save(task1)) {
+// throw new CoolException("浠诲姟鐢熸垚澶辫触锛侊紒");
+// }
+// List<TaskItem> items = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
+// if (items.isEmpty()) {
+// throw new CoolException("鏁版嵁閿欒锛侊紒");
+// }
+// items.forEach(taskItem -> {
+// TaskItem item = new TaskItem();
+// BeanUtils.copyProperties(taskItem, item);
+// item.setTaskId(task1.getId()).setId(null);
+// if (!taskItemService.save(item)) {
+// throw new CoolException("鍏ュ簱浠诲姟鏄庣粏淇濆瓨澶辫触锛侊紒");
+// }
+// });
+// });
+// }
+ }
+
+ /**
+ * 闈炲厜鐢电珯鐐逛换鍔′笅鍙�
+ */
+ @Scheduled(cron = "0/5 * * * * ? ")
+ @Transactional(rollbackFor = Exception.class)
+ public void pubTaskToWcs() {
+ Long loginUserId = SystemAuthUtils.getLoginUserId();
+ List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_LOC_MOVE.type, TaskType.TASK_TYPE_EMPITY_IN.type
+ , TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPITY_OUT.type, TaskType.TASK_TYPE_PICK_IN.type,
+ TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
+ List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
+ List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
+ .in(Task::getTaskType, list)
+ .in(Task::getTaskStatus, integers).last("limit 1")
+ .orderByDesc(Task::getSort));
+ for (Task task : tasks) {
+ /**绉诲簱涓嶅仛绔欑偣鎿嶄綔*/
+ if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
+ .eq(BasStation::getStationName,
+ task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite()));
+ if (station.getType().equals(StationTypeEnum.STATION_TYPE_MUTI.type)) {
+ continue;
+ }
+ }
+ /**涓嬪彂鏅�氱珯鐐逛换鍔★紝鎶ラ敊鍥炴粴锛屼笉鍐嶅線涓嬫墽琛�*/
+ pubTaskToWcs(task);
+ }
+ }
+
+ /**
+ * @author Ryan
+ * @date 2025/9/4
+ * @description: 鍏夌數绔欑偣浠诲姟涓嬪彂
+ * @version 1.0
+ */
+// @Scheduled(cron = "0/5 * * * * ? ")
+ @Transactional(rollbackFor = Exception.class)
+ public void taskToWCS() throws Exception {
+ Long loginUserId = SystemAuthUtils.getLoginUserId();
+ List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_LOC_MOVE.type, TaskType.TASK_TYPE_EMPITY_IN.type
+ , TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPITY_OUT.type,
+ TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
+ List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
+ List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
+ .in(Task::getTaskType, list)
+ .in(Task::getTaskStatus, integers)
+ .orderByDesc(Task::getSort));
+ for (Task task : tasks) {
+ /**绉诲簱涓嶅仛绔欑偣鎿嶄綔*/
+ if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName,
+ task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite()));
+ /**杩囨护鎺夋櫘閫氱珯鐐逛换鍔�*/
+ if (station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ continue;
+ }
+ Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, task.getBarcode()));
+ if (Objects.isNull(loc)) {
+ continue;
+ }
+ //鍒ゆ柇鏄惁娣卞簱浣�
+ if (!LocUtils.isShallowLoc(loc.getCode())) {
+ //鑾峰彇娣卞簱浣嶅搴旂殑娴呭簱浣�
+ String shallowLoc = LocUtils.getShallowLoc(loc.getCode());
+ if (StringUtils.isBlank(shallowLoc)) {
+ continue;
+ }
+ Loc shalloc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
+ if (Objects.isNull(shalloc) || !shalloc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
+ //濡傛灉娴呭簱浣嶄笉鍦ㄥ簱璺冲嚭寰幆
+ continue;
+ }
+ LocToTaskParams params = new LocToTaskParams();
+ params.setOrgLoc(shallowLoc).setType(TaskType.TASK_TYPE_LOC_MOVE.type + "");
+ //鐢熸垚绉诲簱浠诲姟
+ Task moveTask = locItemService.genMoveTask(params, loginUserId);
+ moveTask.setSort(!Objects.isNull(task.getSort()) ? task.getSort() + 1 : Constants.TASK_SORT_DEFAULT_VALUE + 1);
+ if (!taskService.updateById(moveTask)) {
+ throw new Exception("浠诲姟浼樺厛绾ф洿鏂板け璐ワ紒锛�");
+ }
+ }
+ }
+ /**涓嬪彂浠诲姟*/
+ try {
+ pubTaskToWcs(task);
+ } catch (Exception e) {
+ log.error("浠诲姟涓嬪彂澶辫触锛侊紒", e);
+ }
+ }
+ }
+
+ /**
+ * 姣忎簲绉掓牎楠屾繁搴撲綅鏄惁涓虹┖锛屽鏋滄祬搴撲綅鏈夎揣锛屽皢娴呭簱浣嶇Щ鑷虫繁搴撲綅
+ *///TODO 鐢熸垚绉诲簱浠诲姟鍓嶏紝闇�瑕佹鏌ユ槸鍚︽湁浠诲姟鍓嶅線褰撳墠鎵樼洏
+// @Scheduled(cron = "0/35 * * * * ? ")
+// @Transactional(rollbackFor = Exception.class)
+// public void shallocToDeep() throws Exception {
+// List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>()
+// .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+// .in(Loc::getRow, rows));
+// if (locs.isEmpty()) {
+// return;
+// }
+// for (Loc loc : locs) {
+// String shallowLoc = LocUtils.getShallowLoc(loc.getCode());
+// Loc one = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
+// if (Objects.isNull(one) || !one.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
+// continue;
+// }
+// taskService.moveToDeep(SystemAuthUtils.getLoginUserId(), shallowLoc);
+// }
+// }
+
+
+ /**
+ * 涓嬪彂浠诲姟鑷砏CS
+ *
+ * @param task
+ */
+ @Transactional(rollbackFor = Exception.class)
+ public void pubTaskToWcs(Task task) {
+ WcsTaskParams taskParams = new WcsTaskParams();
+ TaskItemParam itemParam = new TaskItemParam();
+ //浠诲姟绫诲瀷锛屼换鍔$紪鐮�
+ itemParam.setTaskType(RcsTaskType.getTypeDesc(task.getTaskType()))
+ .setSeqNum(task.getTaskCode());
+ //涓诲弬鏁�
+ taskParams.setBatch(task.getBarcode());
+
+
+ BasStation station = null;
+ if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
+ if (Objects.isNull(station)) {
+ throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+ }
+ }
+
+
+ /**鍒ゆ柇鏄惁鍏夌數绔欑偣锛岄潪鍏夊簵绔欑偣闇�绠℃帶绔欑偣鐘舵��*/
+ if (!Objects.isNull(station) && station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ if (task.getTaskType() <= TaskType.TASK_TYPE_CHECK_IN.type && !task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+// if (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
+// throw new CoolException( "褰撳墠绔欑偣涓嶆槸F.鍦ㄥ簱鐘舵�佺姸鎬侊紒锛�");
+// }
+ station.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
+ if (!basStationService.updateById(station)) {
+ throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+ }
+ } else if (task.getTaskType() >= TaskType.TASK_TYPE_OUT.type) {
+ if (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
+ throw new CoolException("鐩爣绔欑偣涓嶅O.绌洪棽鐘舵�侊紝鏃犳硶棰勭害鍑哄簱銆�");
+ }
+ station.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
+ if (!basStationService.updateById(station)) {
+ throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+ }
+ }
+ }
+
+ /**绉诲簱鍙傛暟*/
+ if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ itemParam.setOriLoc(task.getOrgLoc()).setDestLoc(task.getTargLoc());
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) {
+ /**鍏ㄦ澘鍏ュ簱鍙傛暟*/
+ itemParam.setDestLoc(task.getTargLoc())
+ .setOriSta(task.getOrgSite());
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)) {
+ /**鎷f枡/鐩樼偣鍏ュ簱鍙傛暟*/
+ itemParam.setDestLoc(task.getTargLoc())
+ .setOriSta(task.getTargSite());
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)) {
+ /**鍑哄簱鍙傛暟*/
+ itemParam.setOriLoc(task.getOrgLoc())
+ .setDestSta(task.getTargSite());
+ } else {
+ /**绔欑偣闂寸Щ搴撳弬鏁�*/
+ itemParam.setOriSta(task.getOrgSite()).setDestSta(task.getTargSite());
+
+ BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite()));
+ if (Objects.isNull(curSta)) {
+ throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+ }
+ if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ if (!curSta.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
+ throw new CoolException("褰撳墠绔欑偣涓嶆槸F.鍦ㄥ簱鐘舵�侊紒锛�");
+ }
+ }
+ if (station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ if (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
+ throw new CoolException("鐩爣绔欑偣涓嶆槸O.绌洪棽鐘舵�侊紒锛�");
+ }
+ }
+ }
+
+ List<TaskItemParam> items = Arrays.asList(itemParam);
+
+ taskParams.setTaskList(items);
+
+ /**浠诲姟涓嬪彂鎺ュ彛*/
+ String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
+
+ /**RCS鍩虹閰嶇疆閾炬帴*/
+ log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", pubTakUrl, JSONObject.toJSONString(taskParams));
+ HttpHeaders headers = new HttpHeaders();
+ headers.add("Content-Type", "application/json");
+ headers.add("api-version", "v2.0");
+ HttpEntity httpEntity = new HttpEntity(taskParams, headers);
+ ResponseEntity<String> exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class);
+ log.info("浠诲姟涓嬪彂鍚庯紝鍝嶅簲缁撴灉锛� {}", exchange);
+ if (Objects.isNull(exchange.getBody())) {
+ throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
+ } else {
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.coercionConfigDefaults()
+ .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+ CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+ if (result.getCode() == 200) {
+ if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
+ .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_IN.id))) {
+ throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+ }
+ /**鎺掗櫎绉诲簱鍔熻兘*/
+ if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+ /**濡傛灉鏄櫘閫氱珯鐐癸紝淇敼绔欑偣鐘舵�佷负鍑哄簱棰勭害*/
+ if (station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ station.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
+ if (!basStationService.updateById(station)) {
+ throw new CoolException("绔欑偣棰勭害澶辫触锛侊紒");
+ }
+ }
+ }
+ } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
+ || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)) {
+ if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
+ .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_OUT.id))) {
+ throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+ }
+ /**濡傛灉鏄櫘閫氱珯鐐癸紝淇敼绔欑偣鐘舵�佷负鍏ュ簱棰勭害*/
+ if (station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
+ station.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
+ if (!basStationService.updateById(station)) {
+ throw new CoolException("绔欑偣棰勭害澶辫触锛侊紒");
+ }
+ }
+ }
+ } else {
+ throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
+ }
+ } catch (JsonProcessingException e) {
+ throw new CoolException(e.getMessage());
+ }
+ }
+
}
/**
- * @author Ryan
- * @description 宸插畬鎴愪换鍔″姞鍏ュ巻鍙叉。
- * @param
- * @return
- * @time 2025/4/3 12:54
- */
- @Scheduled(cron = "0 0/05 * * * ? ")
+ * @param
+ * @return
+ * @author Ryan
+ * @description 宸插畬鎴愪换鍔″姞鍏ュ巻鍙叉。
+ * @time 2025/4/3 12:54
+ */
+ @Scheduled(cron = "0 0/01 * * * ? ")
@Transactional(rollbackFor = Exception.class)
public void taskLogUpdate() {
- List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskStatus, TaskStsType.UPDATED_IN.id));
+ LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<Task>();
+ Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.ORDER_INOF_REPORT_PLAT));//鏄惁涓婃姤骞冲彴
+ if (!Objects.isNull(config)) {
+ if (Boolean.parseBoolean(config.getVal())) {
+ queryWrapper.in(Task::getTaskStatus, TaskStsType.REPORT_IN.id);
+ } else {
+ queryWrapper.in(Task::getTaskStatus, TaskStsType.UPDATED_IN.id, TaskStsType.UPDATED_OUT.id);
+ }
+ } else {
+ queryWrapper.in(Task::getTaskStatus, TaskStsType.UPDATED_IN.id, TaskStsType.UPDATED_OUT.id);
+ }
+ List<Task> tasks = taskService.list(queryWrapper);
if (tasks.isEmpty()) {
return;
}
- List<Long> list = tasks.stream().map(Task::getId).collect(Collectors.toList());
- List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().in(TaskItem::getTaskId, list));
- if (taskItems.isEmpty()) {
- return;
- }
- List<TaskLog> taskLogs = new ArrayList<>();
tasks.forEach(task -> {
TaskLog taskLog = new TaskLog();
BeanUtils.copyProperties(task, taskLog);
- taskLog.setTaskId(task.getId()).setId(null);
- taskLogs.add(taskLog);
+ taskLog.setTaskId(task.getId())
+ .setId(null);
+ if (!taskLogService.save(taskLog)) {
+ throw new CoolException("浠诲姟鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
+ }
+ List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
+ List<TaskItemLog> itemLogs = new ArrayList<>();
+ for (TaskItem item : taskItems) {
+ TaskItemLog itemLog = new TaskItemLog();
+ BeanUtils.copyProperties(item, itemLog);
+ itemLog.setId(null)
+ .setTaskId(task.getId())
+ .setLogId(taskLog.getId())
+ .setTaskItemId(item.getId());
+ itemLogs.add(itemLog);
+ }
+
+ if (!taskService.removeById(task.getId())) {
+ throw new CoolException("鍘熷浠诲姟鍒犻櫎澶辫触锛侊紒");
+ }
+
+ if (!taskItems.isEmpty()) {
+ if (!taskItemLogService.saveBatch(itemLogs)) {
+ throw new CoolException("浠诲姟鏄庣粏鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
+ }
+
+ if (!taskItemService.remove(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()))) {
+ throw new CoolException("鍘熷浠诲姟鏄庣粏鍒犻櫎澶辫触锛侊紒");
+ }
+ }
});
- if (!taskLogService.saveBatch(taskLogs)) {
- throw new CoolException("浠诲姟鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
- }
- List<TaskItemLog >itemLogs = new ArrayList<>();
-
- taskItems.forEach(item -> {
- TaskItemLog itemLog = new TaskItemLog();
- BeanUtils.copyProperties(item, itemLog);
- itemLog.setId(null).setTaskItemId(item.getId());
- itemLogs.add(itemLog);
- });
-
- if (!taskItemLogService.saveBatch(itemLogs)) {
- throw new CoolException("浠诲姟鏄庣粏鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
- }
-
- if (!taskService.removeByIds(list)) {
- throw new CoolException("鍘熷浠诲姟鍒犻櫎澶辫触锛侊紒");
- }
- List<Long> itemIds = taskItems.stream().map(TaskItem::getId).collect(Collectors.toList());
-
- if (!taskItemService.removeByIds(itemIds)) {
- throw new CoolException("鍘熷浠诲姟鏄庣粏鍒犻櫎澶辫触锛侊紒");
- }
-
}
-
-
-
-
}
--
Gitblit v1.9.1