From a2e44acd72122204791e0da7ff6dd7b4fccf18c2 Mon Sep 17 00:00:00 2001 From: xd <844539747@qq.com> Date: Wed, 20 Mar 2024 11:24:35 +0800 Subject: [PATCH] '123' --- .../controller/monitor/CacheController.java | 1 + .../storageLocationController.java | 10 +-- .../ruoyi/common/constant/CacheConstants.java | 5 ++ .../java/com/ruoyi/quartz/task/RbTask.java | 64 ++++++++++++++----- 4 files changed, 60 insertions(+), 20 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java index 35ed432..19dbb58 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java @@ -43,6 +43,7 @@ public class CacheController caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理")); caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数")); caches.add(new SysCache(CacheConstants.STORAGE_LOCATION, "车间库位")); + caches.add(new SysCache(CacheConstants.SYS_JOB_KEY, "定时任务")); } @PreAuthorize("@ss.hasPermi('monitor:cache:list')") diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/storageLocation/storageLocationController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/storageLocation/storageLocationController.java index 200e71c..ff5f3d6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/storageLocation/storageLocationController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/storageLocation/storageLocationController.java @@ -11,7 +11,6 @@ import com.ruoyi.common.core.redis.RedisLock; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.DataSourceType; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.storageLocation.domain.Operlog; import com.ruoyi.storageLocation.domain.StorageLocation; import com.ruoyi.storageLocation.domain.StorageSelected; @@ -19,10 +18,8 @@ import com.ruoyi.storageLocation.service.StorageLocationService; import com.ruoyi.system.service.ISysConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; - import java.text.SimpleDateFormat; import java.util.*; -import java.util.concurrent.TimeUnit; /** * 库位管理Controller @@ -207,7 +204,10 @@ public class storageLocationController extends BaseController if(StringUtils.isNotNull(kw_user_name)&&!user_name.equals(kw_user_name)){ return error("当前库位有人正在操作,请勿操作!"); }else{ - redisLock.getLock(getLocationZyCacheKey(materialBh), Integer.valueOf(storageExpire), user_name); + Boolean lock= redisLock.getLock(getLocationZyCacheKey(materialBh), Integer.valueOf(storageExpire), user_name); + if(!lock){ + return error("当前库位有人正在操作,请勿操作!"); + } //redisCache.setCacheObject(getLocationZyCacheKey(materialBh),user_name,Integer.valueOf(storageExpire), TimeUnit.SECONDS); return success(); } @@ -327,6 +327,8 @@ public class storageLocationController extends BaseController Boolean lock = redisLock.getLock(getLocationLyCacheKey(materialBh), -1, user_name); if(lock){ storageLocationService.saveStorageLocation(user_name,materialBh); + }else{ + return error("该库位当前有人正在领用操作,请勿操作!"); } } return success(); diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java index 34e5e2a..5cf5030 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java @@ -46,4 +46,9 @@ public class CacheConstants * 一车间库位号占用状态 redis key */ public static final String STORAGE_LOCATION = "storage_location:"; + + /** + * 定时任务 redis key + */ + public static final String SYS_JOB_KEY = "sys_job:"; } diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RbTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RbTask.java index 6d7a97f..4ded357 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RbTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RbTask.java @@ -1,12 +1,17 @@ package com.ruoyi.quartz.task; import com.ruoyi.common.annotation.DataSource; +import com.ruoyi.common.constant.CacheConstants; +import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.core.redis.RedisLock; import com.ruoyi.common.enums.DataSourceType; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.quartz.domain.c_rb_product_price; import com.ruoyi.quartz.domain.c_rb_productbase_price; import com.ruoyi.quartz.service.SapTjService; import com.ruoyi.quartz.util.JDBCBatchInsert; +import org.quartz.Scheduler; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -24,6 +29,15 @@ import java.util.List; @Component("rbTask") public class RbTask { + @Autowired + private RedisCache redisCache; + + @Autowired + private RedisLock redisLock; + + @Autowired + private Scheduler scheduler; + @Resource private SapTjService sapTjService; @@ -38,28 +52,46 @@ public class RbTask * 同步红本数据库 */ public void tongb() throws Exception { - //判断是否已执行调价 (6.3 redbook rb_productVersion 是否有新增uid and sta='1'、sdmdm1 调价日期今日的数据是否存在) + + String jobId = scheduler.getSchedulerInstanceId(); String rbVersionUid = testUtils.sapTjService.selRbVersionUid();//红本调价记录uid - String locVersionUid = testUtils.sapTjService.selLocVersionUid();//本地红本调价记录uid + Boolean lock= redisLock.getLock(getJobKey(jobId), -1, rbVersionUid); + if(lock){ + //判断是否已执行调价 (6.3 redbook rb_productVersion 是否有新增uid and sta='1'、sdmdm1 调价日期今日的数据是否存在) + String locVersionUid = testUtils.sapTjService.selLocVersionUid();//本地红本调价记录uid - String RbProductPriceCount = testUtils.sapTjService.selRbProductPriceVersionUid(rbVersionUid);//RbProductPrice表是否有更新 - String RbProductBasePriceCount = testUtils.sapTjService.selRbProductBasePriceVersionUid(rbVersionUid);//RbProductBasePrice表是否有更新 + String RbProductPriceCount = testUtils.sapTjService.selRbProductPriceVersionUid(rbVersionUid);//RbProductPrice表是否有更新 + String RbProductBasePriceCount = testUtils.sapTjService.selRbProductBasePriceVersionUid(rbVersionUid);//RbProductBasePrice表是否有更新 - try{ - if(!rbVersionUid.equals(locVersionUid) && Integer.valueOf(RbProductPriceCount)>0 && Integer.valueOf(RbProductBasePriceCount)>0) {//有新增调价版本并且有调价记录 - System.out.println("=======================开始同步!======================"); - testUtils.sapTjService.deleteLocProductPrice();//删除本地c_rb_product_price表数据 - List productPriceList = testUtils.sapTjService.getProductPriceList(rbVersionUid); - JDBCBatchInsert.insertRbProductPrice(productPriceList);//批量插入 + try{ + if(!rbVersionUid.equals(locVersionUid) && Integer.valueOf(RbProductPriceCount)>0 && Integer.valueOf(RbProductBasePriceCount)>0) {//有新增调价版本并且有调价记录 + System.out.println("=======================开始同步!======================"); + testUtils.sapTjService.deleteLocProductPrice();//删除本地c_rb_product_price表数据 + List productPriceList = testUtils.sapTjService.getProductPriceList(rbVersionUid); + JDBCBatchInsert.insertRbProductPrice(productPriceList);//批量插入 - testUtils.sapTjService.deleteLocProductBasePrice();//删除本地c_rb_productbase_price表数据 - List productBasePriceList = testUtils.sapTjService.getProductBasePriceList(rbVersionUid); - JDBCBatchInsert.insertRbProductBasePrice(productBasePriceList);//批量插入 + testUtils.sapTjService.deleteLocProductBasePrice();//删除本地c_rb_productbase_price表数据 + List productBasePriceList = testUtils.sapTjService.getProductBasePriceList(rbVersionUid); + JDBCBatchInsert.insertRbProductBasePrice(productBasePriceList);//批量插入 - testUtils.sapTjService.updateLocRbVersion(rbVersionUid);//更新本地c_rb_version表 + testUtils.sapTjService.updateLocRbVersion(rbVersionUid);//更新本地c_rb_version表 + + redisCache.deleteObject(getJobKey(jobId)); + } + }catch (Exception e) { + throw new Exception(e.getMessage(), e); } - }catch (Exception e) { - throw new Exception(e.getMessage(), e); } } + + /** + * 定时任务缓存键名 + * + * @param jobId 任务编号 + * @return 缓存键key + */ + private String getJobKey(String jobId) + { + return CacheConstants.SYS_JOB_KEY + jobId; + } }