add:redisson:缓存线载具同步功能

This commit is contained in:
zhangzhiqiang
2023-03-27 11:00:13 +08:00
parent 1948c76aa1
commit 6e096fbd19
12 changed files with 116 additions and 41 deletions

View File

@@ -43,7 +43,12 @@
<artifactId>jansi</artifactId>
<version>1.9</version>
</dependency>
<!--redisson-->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.16.4</version>
</dependency>
<!--登录相关-->
<dependency>
<groupId>cn.dev33</groupId>

View File

@@ -20,12 +20,12 @@ public enum StatusEnum {
//锁状态
LOCK_OFF("0","",""),
LOCK_ON("1","",""),
//缓存线载具状态00-空位、01-绿色空箱、02-黄色满箱、03-红色异常、04不显示
CACHE_VEL_NULL("00","空位",""),
CACHE_VEL_EMT("01","绿色空箱",""),
CACHE_VEL_FULL("02","黄色满箱",""),
CACHE_VEL_ERR("03","红色异常",""),
CACHE_VEL_DIS("04","04不显示",""),
//缓存线载具状态 1-空位、2-绿色空箱、3-黄色满箱、4-红色异常、5不显示
CACHE_VEL_NULL("1","空位",""),
CACHE_VEL_EMT("2","绿色空箱",""),
CACHE_VEL_FULL("3","黄色满箱",""),
CACHE_VEL_ERR("4","红色异常",""),
CACHE_VEL_DIS("5","不显示",""),
//任务状态
TASK_CREATE("1","生成",""),
TASK_START_P("2","起点确认",""),

View File

@@ -6,12 +6,13 @@ package org.nl.common.enums;
* @Date: 2023/3/16
*/
public enum WorkerOrderEnum {
// 1-创建、2-下发、3-生产中、4-暂停、5-完成
// 1-创建、2-下发、3-生产中、4-暂停、5-完成 6-强制完成
CREATE("创建", "1"),
SEND("下发", "2"),
PRODUCTING("生产中", "3"),
STOP("暂停", "4"),
COMPLETE("完成", "5"),
FORCE_COMPLETE("强制完成", "6"),
// 1-PC创建、2-Excel导入
PCINTO("PC创建", "1"),
EXCELINTO("EXCEL导入", "2"),

View File

@@ -0,0 +1,7 @@
package org.nl.common.handler;
@FunctionalInterface
public
interface LockProcess {
void process();
}

View File

@@ -0,0 +1,42 @@
package org.nl.common.utils;
import lombok.SneakyThrows;
import org.nl.common.handler.LockProcess;
import org.nl.modules.wql.util.SpringContextHolder;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import java.util.concurrent.TimeUnit;
/*
* @author ZZQ
* @Date 2023/3/27 10:30
*/
public class RedissonUtils {
/**
*
* @param process 业务代码
* @param key
* @param seconds 尝试获取锁的等待时间,允许为空
*/
@SneakyThrows
public static void lock(LockProcess process, String key, Integer seconds){
RedissonClient redissonClient = SpringContextHolder.getBean(RedissonClient.class);
RLock lock = redissonClient.getLock(key);
boolean isLock;
if (seconds == null){
isLock = lock.tryLock();
}else {
isLock = lock.tryLock(seconds, TimeUnit.SECONDS);
}
try {
if (isLock){
process.process();
}
}finally {
if (isLock){
lock.unlock();
}
}
}
}

View File

@@ -15,7 +15,7 @@ import javax.sql.DataSource;
import java.sql.DriverManager;
import java.sql.SQLException;
@Configuration
//@Configuration
@Slf4j
public class DataBaseConfig {
@Value("${erp.oracle.enabled}")

View File

@@ -20,7 +20,7 @@ import org.nl.wms.pda.service.CacheLineHandService;
import org.nl.wms.sch.manage.TaskStatusEnum;
import org.nl.wms.sch.service.TaskService;
import org.nl.wms.sch.service.dto.TaskDto;
import org.nl.wms.ext.acs.service.AcsToWmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@@ -274,7 +274,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
positionTab.update(MapOf.of("position_code",s[0],"Vehicle_code",s[1]),"cacheline_code = '"+cachelineCode+"'");
}
//更新缓存线及缓存线载具表对应关系
cacheLineHandService.cacheLineMaterSync();
cacheLineHandService.cacheLineMaterSync(param.getString("cacheline_code"));
}
@Override

View File

@@ -14,7 +14,7 @@ public class CachelineVehileMaterialDto implements Serializable{
/**
* 载具库存标识
*/
private String vehmaterial_uuid;
private String vehmaterial_id;
/**
* 缓存线位置编码
*/

View File

@@ -112,7 +112,7 @@ public interface CacheLineHandService{
* @author gbx
* @date 2023/3/24
*/
JSONArray cacheLineMaterSync(JSONObject );
void cacheLineMaterSync(String cachelineCode);
/**
* 缓存线料箱条码查询料箱信息

View File

@@ -2,20 +2,18 @@ package org.nl.wms.pda.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.nl.common.enums.StatusEnum;
import org.nl.common.utils.AcsUtil;
import org.nl.common.utils.LocalCache;
import org.nl.common.utils.MapOf;
import org.nl.common.utils.SecurityUtils;
import org.nl.common.handler.LockProcess;
import org.nl.common.utils.*;
import org.nl.config.thread.ThreadPoolExecutorUtil;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.RedisUtils;
@@ -28,6 +26,7 @@ import org.nl.wms.sch.service.impl.TaskServiceImpl;
import org.nl.wms.sch.tasks.SpeMachineryTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -171,26 +170,37 @@ public class CacheLineHandServiceImpl implements CacheLineHandService{
}
@Override
public JSONArray cacheLineMaterSync() {
WQLObject positionTab = WQLObject.getWQLObject("sch_cacheline_position");
JSONArray positionArr = positionTab.query("is_delete = '0'").getResultJSONArray(0);
// 缓存线位置表
List<CachelineVehileMaterialDto> positionList = positionArr.toJavaList(CachelineVehileMaterialDto.class);
WQLObject ivtTab = WQLObject.getWQLObject("sch_cacheline_vehilematerial");
JSONArray ivtArr = ivtTab.query("is_delete = '0'").getResultJSONArray(0);
// 缓存线载具物料表
List<CachelineVehileMaterialDto> ivtList = ivtArr.toJavaList(CachelineVehileMaterialDto.class);
//取缓存线位置表多出来的物料
List<CachelineVehileMaterialDto> resultList = positionList.stream().filter(p -> !ivtList.stream().map(e -> e.getPosition_code() + "&" + e.getVehicle_code()).collect(Collectors.toList()).contains(p.getPosition_code() + "&" + p.getVehicle_code())).collect(Collectors.toList());
//取载具物料表多出来的物料
List<CachelineVehileMaterialDto> resultLists = ivtList.stream().filter(i -> !positionList.stream().map(e -> e.getPosition_code() + "&" + e.getVehicle_code()).collect(Collectors.toList()).contains(i.getPosition_code() + "&" + i.getVehicle_code())).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(resultList)) {
//TODO 缓存线位置表多出来的物料处理
@Async
public void cacheLineMaterSync(String cachelineCode) {
if (StringUtils.isEmpty(cachelineCode)){
return;
}
if(CollectionUtil.isNotEmpty(resultLists)) {
//TODO 载具物料表多出来的物料处理
}
return null;
RedissonUtils.lock(() -> {
WQLObject positionTab = WQLObject.getWQLObject("sch_cacheline_position");
WQLObject ivtTab = WQLObject.getWQLObject("sch_cacheline_vehilematerial");
JSONArray positionArr = positionTab.query("cacheline_code = '"+cachelineCode+"'").getResultJSONArray(0);
if (positionArr.size() == 0){
log.warn("CacheLineHandServiceImpl#cacheLineMaterSync");
return;
}
// 缓存线位置表
Set<String> cacheLineVehiles = positionArr.stream().map(a -> ((JSONObject) a).getString("vehicle_code")).collect(Collectors.toSet());
JSONArray ivtArr = ivtTab.query("cacheline_code = '"+cachelineCode+"'").getResultJSONArray(0);
Set<String> relationVehiles = ivtArr.stream().map(a -> ((JSONObject) a).getString("vehicle_code")).collect(Collectors.toSet());
Collection<String> cacheLineVehilesSub = CollectionUtils.subtract(cacheLineVehiles, relationVehiles);
Collection<String> relationVehilesSub = CollectionUtils.subtract(relationVehiles, cacheLineVehiles);
if (!CollectionUtils.isEmpty(relationVehilesSub)){
String sql = relationVehilesSub.stream().collect(Collectors.joining("','"));
ivtTab.delete("cacheline_code = '"+cachelineCode+"' and vehicle_code in ('"+sql+"')");
}
if (!CollectionUtils.isEmpty(cacheLineVehilesSub)){
for (String vehileCode : cacheLineVehilesSub) {
ivtTab.insert(MapOf.of("vehmaterial_id", IdUtil.getStringId(),"vehicle_code",vehileCode,"vehicle_status", StatusEnum.CACHE_VEL_ERR.getCode()
,"cacheline_code",cachelineCode,"err_type",StatusEnum.STATUS_TRUE.getCode()));
}
}
},cachelineCode,3);
}
/**
@@ -303,7 +313,7 @@ public class CacheLineHandServiceImpl implements CacheLineHandService{
ivtTab.delete("vehicle_code = '" + vehicle_code + "'");
// 物料信息
HashMap<String,String> json = new HashMap<>();
json.put("vehmaterial_uuid", IdUtil.getSnowflake(1, 1).nextIdStr());
json.put("vehmaterial_id", IdUtil.getStringId());
json.put("vehicle_code", vehicle_code);
json.put("cacheLine_code", wcsdevice_code);
json.put("material_uuid", meObj.getString("material_id"));
@@ -346,7 +356,7 @@ public class CacheLineHandServiceImpl implements CacheLineHandService{
//2.先删除料箱的所有关联信息,包括物料,工序,生产区域
ivtTab.delete("vehicle_code = '" + vehicle_code + "'");
JSONObject json = new JSONObject();
json.put("vehmaterial_uuid", IdUtil.getSnowflake(1, 1).nextIdStr());
json.put("vehmaterial_id", IdUtil.getStringId());
json.put("vehicle_code", vehicle_code);
json.put("cacheLine_code", wcsdevice_code);
json.put("vehicle_status", "01");
@@ -406,7 +416,7 @@ public class CacheLineHandServiceImpl implements CacheLineHandService{
}
// 3.入空箱子
JSONObject afterIvt = new JSONObject();
afterIvt.put("vehmaterial_uuid", IdUtil.getSnowflake(1, 1).nextIdStr());
afterIvt.put("vehmaterial_id", IdUtil.getStringId());
afterIvt.put("vehicle_code", vehicle_code);
afterIvt.put("cacheLine_code", cacheLine_code);
afterIvt.put("vehicle_status", "01");
@@ -578,7 +588,7 @@ public class CacheLineHandServiceImpl implements CacheLineHandService{
HashMap<String,String> json = new HashMap<>();
json.put("vehicle_code", vehicle_code);
json.put("cacheLine_code", position_code);
json.put("vehmaterial_uuid", IdUtil.getSnowflake(1, 1).nextIdStr());
json.put("vehmaterial_id", IdUtil.getStringId());
json.put("create_time", DateUtil.now());
// 入满箱扫码异常
if("1".equals(inOut_type)) {

View File

@@ -73,6 +73,16 @@ spring:
password: ${REDIS_PWD:}
#连接超时时间
timeout: 5000
redisson:
config: |
threads: 4
nettyThreads: 4
singleServerConfig:
connectionMinimumIdleSize: 8
connectionPoolSize: 8
address: redis://127.0.0.1:6379
idleConnectionTimeout: 10000
timeout: 3000
# 登录相关配置
login:
# 登录缓存