From f73dad756121e3e12df88adeed0132342ddf115e Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期五, 29 八月 2025 15:45:00 +0800
Subject: [PATCH] 跑酷
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java | 6
rsf-server/src/main/java/com/vincent/rsf/server/manager/constant/StaGroupConstant.java | 54 ++++++
rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/AutoRunSchedules.java | 293 ++++++++++++++++++++++++++++++++++++
rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/params/LocToTaskParams.java | 2
rsf-server/src/main/java/com/vincent/rsf/server/manager/constant/LocGroupConstant.java | 81 ++++++++++
5 files changed, 434 insertions(+), 2 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/constant/LocGroupConstant.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/constant/LocGroupConstant.java
new file mode 100644
index 0000000..2f8d4e4
--- /dev/null
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/constant/LocGroupConstant.java
@@ -0,0 +1,81 @@
+package com.vincent.rsf.server.manager.constant;
+
+import java.util.ArrayList;
+
+public class LocGroupConstant {
+
+ public static final ArrayList<Integer> FAR_LEFT_LOC_ROW_LIST = new ArrayList<Integer>(){{
+ add(49);
+ add(50);
+ add(51);
+ add(52);
+ add(53);
+ add(54);
+ add(55);
+ add(56);
+ add(57);
+ add(58);
+ add(59);
+ }};
+
+ public static final ArrayList<Integer> LEFT_LOC_ROW_LIST = new ArrayList<Integer>(){{
+ add(37);
+ add(38);
+ add(39);
+ add(40);
+ add(41);
+ add(42);
+ add(43);
+ add(44);
+ add(45);
+ add(46);
+ add(47);
+ add(48);
+ }};
+
+ public static final ArrayList<Integer> MIDDLE_LOC_ROW_LIST = new ArrayList<Integer>(){{
+ add(25);
+ add(26);
+ add(27);
+ add(28);
+ add(29);
+ add(30);
+ add(31);
+ add(32);
+ add(33);
+ add(34);
+ add(35);
+ add(36);
+ }};
+
+ public static final ArrayList<Integer> RIGHT_LOC_ROW_LIST = new ArrayList<Integer>(){{
+ add(13);
+ add(14);
+ add(15);
+ add(16);
+ add(17);
+ add(18);
+ add(19);
+ add(20);
+ add(21);
+ add(22);
+ add(23);
+ add(24);
+ }};
+
+ public static final ArrayList<Integer> FAR_RIGHT_LOC_ROW_LIST = new ArrayList<Integer>(){{
+ add(1);
+ add(2);
+ add(3);
+ add(4);
+ add(5);
+ add(6);
+ add(7);
+ add(8);
+ add(9);
+ add(10);
+ add(11);
+ add(12);
+ }};
+
+}
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/constant/StaGroupConstant.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/constant/StaGroupConstant.java
new file mode 100644
index 0000000..a3bb269
--- /dev/null
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/constant/StaGroupConstant.java
@@ -0,0 +1,54 @@
+package com.vincent.rsf.server.manager.constant;
+
+import java.util.ArrayList;
+
+public class StaGroupConstant {
+
+ public static final ArrayList<String> FAR_LEFT_STA_ROW_LIST = new ArrayList<String>(){{
+ add("9-1");
+ add("9-2");
+ add("9-3");
+ add("10-1");
+ add("10-2");
+ add("10-3");
+ add("1001");
+ add("1007");
+ }};
+
+ public static final ArrayList<String> LEFT_STA_ROW_LIST = new ArrayList<String>(){{
+ add("7-1");
+ add("7-2");
+ add("7-3");
+ add("8-1");
+ add("8-2");
+ add("8-3");
+ }};
+
+ public static final ArrayList<String> MIDDLE_STA_ROW_LIST = new ArrayList<String>(){{
+ add("5-1");
+ add("5-2");
+ add("5-3");
+ add("6-1");
+ add("6-2");
+ add("6-3");
+ }};
+
+ public static final ArrayList<String> RIGHT_STA_ROW_LIST = new ArrayList<String>(){{
+ add("3-1");
+ add("3-2");
+ add("3-3");
+ add("4-1");
+ add("4-2");
+ add("4-3");
+ }};
+
+ public static final ArrayList<String> FAR_RIGHT_STA_ROW_LIST = new ArrayList<String>(){{
+ add("1-1");
+ add("1-2");
+ add("1-3");
+ add("2-1");
+ add("2-2");
+ add("2-3");
+ }};
+
+}
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/params/LocToTaskParams.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/params/LocToTaskParams.java
index 8323840..6f4700d 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/params/LocToTaskParams.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/params/LocToTaskParams.java
@@ -32,4 +32,6 @@
@ApiModelProperty("鐩爣搴撲綅")
private String tarLoc;
+ @ApiModelProperty("澶囨敞")
+ private String memo;
}
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/AutoRunSchedules.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/AutoRunSchedules.java
new file mode 100644
index 0000000..2728d00
--- /dev/null
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/AutoRunSchedules.java
@@ -0,0 +1,293 @@
+package com.vincent.rsf.server.manager.schedules;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.vincent.rsf.framework.common.Cools;
+import com.vincent.rsf.framework.exception.CoolException;
+import com.vincent.rsf.server.common.constant.Constants;
+import com.vincent.rsf.server.manager.constant.LocGroupConstant;
+import com.vincent.rsf.server.manager.constant.StaGroupConstant;
+import com.vincent.rsf.server.manager.controller.params.LocToTaskParams;
+import com.vincent.rsf.server.manager.entity.*;
+import com.vincent.rsf.server.manager.enums.*;
+import com.vincent.rsf.server.manager.service.*;
+import com.vincent.rsf.server.system.constant.SerialRuleCode;
+import com.vincent.rsf.server.system.service.ConfigService;
+import com.vincent.rsf.server.system.utils.SerialRuleUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.*;
+
+import static com.vincent.rsf.server.system.utils.SystemAuthUtils.getLoginUserId;
+
+/**
+ * 鑷姩璺戝簱绋嬪簭
+ */
+@Slf4j
+@Component
+public class AutoRunSchedules {
+
+ @Autowired
+ private LocService locService;
+
+ @Autowired
+ private ConfigService configService;
+
+ @Autowired
+ private BasStationService stationService;
+
+ @Autowired
+ private TaskService taskService;
+
+
+ @Autowired
+ private TaskItemService taskItemService;
+
+ @Autowired
+ private MatnrService matnrService;
+
+ @Autowired
+ private LocItemService locItemService;
+
+ public void genRun() {
+ String autoRunArea = configService.getVal("AUTO_RUN_AREA", String.class);
+ if (Cools.isEmpty(autoRunArea)) {
+ return;
+ }
+ for (char c : autoRunArea.toCharArray()) {
+ switch (c) {
+ case '1':
+ this.autoRun(LocGroupConstant.FAR_RIGHT_LOC_ROW_LIST, StaGroupConstant.FAR_RIGHT_STA_ROW_LIST);
+ break;
+ case '2':
+ this.autoRun(LocGroupConstant.RIGHT_LOC_ROW_LIST, StaGroupConstant.RIGHT_STA_ROW_LIST);
+ break;
+ case '3':
+ this.autoRun(LocGroupConstant.MIDDLE_LOC_ROW_LIST, StaGroupConstant.MIDDLE_STA_ROW_LIST);
+ break;
+ case '4':
+ this.autoRun(LocGroupConstant.LEFT_LOC_ROW_LIST, StaGroupConstant.LEFT_STA_ROW_LIST);
+ break;
+ case '5':
+ this.autoRun(LocGroupConstant.FAR_LEFT_LOC_ROW_LIST, StaGroupConstant.FAR_LEFT_STA_ROW_LIST);
+ break;
+ default:
+ break;
+ }
+ }
+
+ }
+
+
+ private void autoRun(List<Integer> locGroupList, List<String> staGroupList) {
+
+ List<String> staPreNos = getStaPrefixes(staGroupList);
+ String staTaskMemo = "DEMO_STA_" + String.join("-", staPreNos);
+
+ List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getMemo, staTaskMemo));
+ if (!Cools.isEmpty(list) && list.size() > 30) {
+ return;
+ }
+ // 鍏ュ簱 搴旇鏍规嵁宸ヤ綔妗e洖鍘�
+ this.runStaToLoc(locGroupList, staGroupList, staTaskMemo);
+ // 鍑哄簱,闇�瑕佹牎楠屽伐浣滄。鏄惁瀛樺湪锛屽瓨鍦ㄥ氨璇存槑绔欑偣澶勪簬蹇欑鐘舵��
+ this.runLocToSta(locGroupList, staGroupList, staTaskMemo);
+
+ // 绉诲簱
+ this.runLocToLoc(locGroupList, staTaskMemo);
+ }
+
+
+ // 鍏ュ簱
+ private void runStaToLoc(List<Integer> locGroupList, List<String> staGroupList, String memo) {
+ Integer startRow = Collections.min(locGroupList);
+ Integer endRow = Collections.max(locGroupList);
+
+
+ // STA IDLE
+ LambdaQueryWrapper<BasStation> idleWrapper = new LambdaQueryWrapper<BasStation>().eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).in(BasStation::getStationName, staGroupList);
+ List<BasStation> idleList = stationService.list(idleWrapper);
+ if (Cools.isEmpty(idleList)) {
+ return;
+ }
+ Collections.shuffle(idleList);
+
+ // LOC STOCK
+ LambdaQueryWrapper<Loc> stockWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type);
+ if (null != startRow) {
+ stockWrapper.ge(Loc::getRow, startRow);
+ }
+ if (null != endRow) {
+ stockWrapper.le(Loc::getRow, endRow);
+ }
+ List<Loc> stockList = locService.list(stockWrapper);
+ if (Cools.isEmpty(stockList)) {
+ return;
+ }
+ Collections.shuffle(stockList);
+
+ //鐢熸垚鍏ュ簱宸ヤ綔妗�
+ generateTask(idleList.get(0).getStationName(), stockList.get(0).getCode(), idleList.get(0).getBarcode());
+ }
+
+
+ // 鍑哄簱
+ private void runLocToSta(List<Integer> locGroupList, List<String> staGroupList, String memo) {
+ Integer startRow = Collections.min(locGroupList);
+ Integer endRow = Collections.max(locGroupList);
+
+
+ // STA IDLE
+ LambdaQueryWrapper<BasStation> idleWrapper = new LambdaQueryWrapper<BasStation>().eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_O.type).in(BasStation::getStationName, staGroupList);
+ List<BasStation> idleList = stationService.list(idleWrapper);
+ if (Cools.isEmpty(idleList)) {
+ return;
+ }
+ Collections.shuffle(idleList);
+
+ // LOC STOCK
+ LambdaQueryWrapper<Loc> stockWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type);
+ if (null != startRow) {
+ stockWrapper.ge(Loc::getRow, startRow);
+ }
+ if (null != endRow) {
+ stockWrapper.le(Loc::getRow, endRow);
+ }
+ List<Loc> stockList = locService.list(stockWrapper);
+ if (Cools.isEmpty(stockList)) {
+ return;
+ }
+ Collections.shuffle(stockList);
+
+
+ Loc loc = stockList.get(0);
+ List<LocItem> list = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()));
+ LocToTaskParams param = new LocToTaskParams();
+ param.setType(Constants.TASK_TYPE_OUT_STOCK);
+ param.setTarLoc(loc.getCode());
+ param.setItems(list);
+ param.setSiteNo(idleList.get(0).getStationName());
+ param.setMemo(memo);
+ //鐢熸垚鍑哄簱宸ヤ綔妗�
+ try {
+ locItemService.generateTask(TaskResouceType.TASK_RESOUCE_STOCK_TYPE.val, param, getLoginUserId());
+ } catch (Exception e) {
+ log.info("鐢熸垚鍑哄簱浠诲姟澶辫触", e);
+ }
+
+ }
+
+
+ // 绉诲簱
+ private void runLocToLoc(List<Integer> locGroupList, String staTaskMemo) {
+ Integer startRow = Collections.min(locGroupList);
+ Integer endRow = Collections.max(locGroupList);
+
+ String memo = "DEMO_LOC_" + startRow + "-" + endRow;
+
+
+ // STOCK
+ LambdaQueryWrapper<Loc> stockWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type);
+ if (null != startRow) {
+ stockWrapper.ge(Loc::getRow, startRow);
+ }
+ if (null != endRow) {
+ stockWrapper.le(Loc::getRow, endRow);
+ }
+ List<Loc> stockList = locService.list(stockWrapper);
+ if (Cools.isEmpty(stockList)) {
+ return;
+ }
+ Collections.shuffle(stockList);
+
+ // IDLE
+ LambdaQueryWrapper<Loc> idleWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type);
+ if (null != startRow) {
+ idleWrapper.ge(Loc::getRow, startRow);
+ }
+ if (null != endRow) {
+ idleWrapper.le(Loc::getRow, endRow);
+ }
+ List<Loc> idleList = locService.list(idleWrapper);
+ if (Cools.isEmpty(idleList)) {
+ return;
+ }
+ Collections.shuffle(idleList);
+ //鐢熸垚绉诲簱浠诲姟
+ Loc loc = stockList.get(0);
+ List<LocItem> list = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()));
+ LocToTaskParams param = new LocToTaskParams();
+ param.setType(Constants.TASK_TYPE_OUT_CHECK);
+ param.setTarLoc(idleList.get(0).getCode());
+ param.setItems(list);
+ param.setOrgLoc(stockList.get(0).getCode());
+ param.setMemo(memo);
+ //鐢熸垚绉诲簱宸ヤ綔妗�
+ try {
+ locItemService.genMoveTask(param, 6666L);
+ } catch (Exception e) {
+ log.info("鐢熸垚鍑哄簱浠诲姟澶辫触", e);
+ }
+
+ }
+
+ private void generateTask(String sourceStaNo, String locNo, String barcode) {
+ String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null);
+ if (StringUtils.isBlank(ruleCode)) {
+ throw new CoolException("缂栫爜閿欒锛氳纭缂栫爜銆孲YS_TASK_CODE銆嶆槸鍚﹀凡鐢熸垚!!");
+ }
+ Task task = new Task();
+ task.setTaskCode(ruleCode)
+ .setTaskStatus(TaskStsType.GENERATE_IN.id)
+ .setTaskType(TaskType.TASK_TYPE_IN.type)
+ .setResource(TaskResouceType.TASK_RESOUCE_PAKIN_TYPE.val)
+ .setTargLoc(locNo)
+ .setBarcode(barcode)
+ .setOrgSite(sourceStaNo)
+ .setCreateBy(6666L)
+ .setUpdateBy(6666L);
+
+ if (!taskService.save(task)) {
+ throw new CoolException("浠诲姟淇濆瓨澶辫触锛侊紒");
+ }
+ LambdaQueryWrapper<Matnr> wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(Matnr::getStatus, 1);
+ wrapper.orderByAsc(Matnr::getUpdateTime);
+ List<Matnr> list = matnrService.page(new Page<>(1, 100), wrapper).getRecords();
+ Collections.shuffle(list);
+ List<TaskItem> taskItems = new ArrayList<>();
+ int i = 0;
+ for (Matnr item : list) {
+ if (i > 5) {
+ break;
+ }
+ TaskItem taskItem = new TaskItem();
+ BeanUtils.copyProperties(item, taskItem);
+ taskItem.setTaskId(task.getId())
+ .setOrderType(OrderType.ORDER_IN.type)
+ .setCreateBy(6666L)
+ .setUpdateBy(6666L)
+ .setExtendFields(item.getExtendFields());
+ taskItems.add(taskItem);
+ item.setUpdateTime(new Date());
+ matnrService.updateById(item);
+ i++;
+ }
+ taskItemService.saveBatch(taskItems);
+ }
+
+
+ public static List<String> getStaPrefixes(List<String> staGroupList) {
+ Set<String> rowSet = new HashSet<>();
+ for (String s : staGroupList) {
+ rowSet.add(s.split("-")[0]);
+ }
+ List<String> result = new ArrayList<>(rowSet);
+ result.sort(Comparator.comparingInt(Integer::parseInt));
+ return result;
+ }
+}
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java
index 36e4db5..e5294ef 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java
@@ -117,7 +117,8 @@
.setCreateTime(new Date())
.setUpdateTime(new Date())
.setTaskStatus(TaskStsType.GENERATE_OUT.id)
- .setBarcode(loc.getBarcode());
+ .setBarcode(loc.getBarcode())
+ .setMemo(map.getMemo());
List<LocItem> locItems = this.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, key));
if (locItems.isEmpty()) {
@@ -334,7 +335,8 @@
.setSort(Constants.TASK_SORT_DEFAULT_VALUE)
.setUpdateTime(new Date())
.setTaskStatus(TaskStsType.GENERATE_IN.id)
- .setBarcode(orgLoc.getBarcode());
+ .setBarcode(orgLoc.getBarcode())
+ .setMemo(map.getMemo());
if (!taskService.save(task)) {
throw new CoolException("鏂板缓绉诲簱浠诲姟澶辫触锛侊紒");
--
Gitblit v1.9.1