From 537c421019cc5f626f000da8cff3d0bb0f47a3d9 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 11 十二月 2024 16:11:24 +0800 Subject: [PATCH] 1 --- se-modules/se-system/src/main/java/com/se/system/service/impl/SysSoftServiceImpl.java | 64 ++++++++++++++------- se-modules/se-system/src/main/java/com/se/system/SeSystemApplication.java | 8 +- se-modules/se-system/src/main/java/com/se/system/utils/CaffeineUtils.java | 15 ++++- se-modules/se-system/src/main/java/com/se/system/service/impl/SysStatusCtrlServiceImpl.java | 60 +++++++++++++------ docker-compose/mysql/initdb/se_cloud_20240629.sql | 4 docker-compose/mysql/initdb/se_cloud_20241204.sql | 3 se-modules/se-system/src/main/java/com/se/system/utils/RyTask.java | 20 ++++++ 7 files changed, 120 insertions(+), 54 deletions(-) diff --git a/docker-compose/mysql/initdb/se_cloud_20240629.sql b/docker-compose/mysql/initdb/se_cloud_20240629.sql index c0f08c9..f2510cd 100644 --- a/docker-compose/mysql/initdb/se_cloud_20240629.sql +++ b/docker-compose/mysql/initdb/se_cloud_20240629.sql @@ -634,8 +634,8 @@ primary key (job_id, job_name, job_group) ) engine=innodb auto_increment=4 comment = '瀹氭椂浠诲姟璋冨害琛�'; -insert into sys_job values(1, '杞欢妫�娴嬪畾鏃朵换鍔�', 'DEFAULT', 'ryTask.runSoftTest', '0/10 * * * * ?', '3', '1', '1', 'admin', sysdate(), '', null, ''); -insert into sys_job values(2, '鍒嗙郴缁熸娴嬪畾鏃朵换鍔�', 'DEFAULT', 'ryTask.runSubSysTest', '0/10 * * * * ?', '3', '1', '1', 'admin', sysdate(), '', null, ''); +insert into sys_job values(1, '杞欢鐘舵�佹娴嬪畾鏃朵换鍔�', 'DEFAULT', 'ryTask.runSoftTest', '0/10 * * * * ?', '3', '1', '1', 'admin', sysdate(), '', null, ''); +insert into sys_job values(2, '绯荤粺鐘舵�佹娴嬪畾鏃朵换鍔�', 'DEFAULT', 'ryTask.runSubSysTest', '0/10 * * * * ?', '3', '1', '1', 'admin', sysdate(), '', null, ''); -- insert into sys_job values(3, '绯荤粺榛樿锛堝鍙傦級', 'DEFAULT', 'ryTask.ryMultipleParams(\'ry\', true, 2000L, 316.50D, 100)', '0/20 * * * * ?', '3', '1', '1', 'admin', sysdate(), '', null, ''); -- select * from sys_job order by job_id; diff --git a/docker-compose/mysql/initdb/se_cloud_20241204.sql b/docker-compose/mysql/initdb/se_cloud_20241204.sql index 94ba3f6..b34a00a 100644 --- a/docker-compose/mysql/initdb/se_cloud_20241204.sql +++ b/docker-compose/mysql/initdb/se_cloud_20241204.sql @@ -105,6 +105,7 @@ update sys_menu set mark = 'sys' where menu_id >= @parentId; -insert into sys_status_ctrl (sys_name,ip,url,method,order_num) values ('鐢ㄦ埛鍙婃潈闄愮鐞�','127.0.0.1','http://localhost:8080/system/health','GET',1); +insert into sys_status_ctrl (sys_name,ip,url,method,order_num) values ('鐢ㄦ埛鍙婃潈闄愮鐞�','127.0.0.1','http://localhost:8080/system/health', 'GET',1); +insert into sys_status_ctrl (sys_name,ip,url,method,order_num) values ('鏁版嵁绠$悊鍒嗙郴缁�','127.0.0.1','http://localhost:8080/gateway/health','GET',2); -- ---------------------------- diff --git a/se-modules/se-system/src/main/java/com/se/system/SeSystemApplication.java b/se-modules/se-system/src/main/java/com/se/system/SeSystemApplication.java index 747f85d..1d71d00 100644 --- a/se-modules/se-system/src/main/java/com/se/system/SeSystemApplication.java +++ b/se-modules/se-system/src/main/java/com/se/system/SeSystemApplication.java @@ -1,5 +1,6 @@ package com.se.system; +import com.se.system.utils.CaffeineUtils; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import com.se.common.security.annotation.EnableCustomConfig; @@ -15,11 +16,10 @@ @EnableCustomSwagger2 @EnableRyFeignClients @SpringBootApplication -public class SeSystemApplication -{ - public static void main(String[] args) - { +public class SeSystemApplication { + public static void main(String[] args) { SpringApplication.run(SeSystemApplication.class, args); + CaffeineUtils.init(); System.out.println(" 绯荤粺妯″潡鍚姩鎴愬姛 "); } } diff --git a/se-modules/se-system/src/main/java/com/se/system/service/impl/SysSoftServiceImpl.java b/se-modules/se-system/src/main/java/com/se/system/service/impl/SysSoftServiceImpl.java index 4973006..d4c0b65 100644 --- a/se-modules/se-system/src/main/java/com/se/system/service/impl/SysSoftServiceImpl.java +++ b/se-modules/se-system/src/main/java/com/se/system/service/impl/SysSoftServiceImpl.java @@ -2,11 +2,14 @@ import java.util.List; import com.se.common.core.utils.DateUtils; -import org.springframework.beans.factory.annotation.Autowired; +import com.se.system.utils.CaffeineUtils; import org.springframework.stereotype.Service; import com.se.system.mapper.SysSoftMapper; import com.se.system.domain.SysSoft; import com.se.system.service.inte.ISysSoftService; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; /** * 杞欢Service涓氬姟灞傚鐞� @@ -15,82 +18,99 @@ * @date 2024-11-22 */ @Service -public class SysSoftServiceImpl implements ISysSoftService -{ - @Autowired +@SuppressWarnings("ALL") +public class SysSoftServiceImpl implements ISysSoftService { + @Resource private SysSoftMapper sysSoftMapper; + + private final static String CACHE_KEY = "list:syssoft"; /** * 鏌ヨ杞欢 - * + * * @param softId 杞欢涓婚敭 * @return 杞欢 */ @Override - public SysSoft selectSysSoftBySoftId(Long softId) - { + public SysSoft selectSysSoftBySoftId(Long softId) { return sysSoftMapper.selectSysSoftBySoftId(softId); } /** * 鏌ヨ杞欢鍒楄〃 - * + * * @param sysSoft 杞欢 * @return 杞欢 */ @Override - public List<SysSoft> selectSysSoftList(SysSoft sysSoft) - { + public List<SysSoft> selectSysSoftList(SysSoft sysSoft) { return sysSoftMapper.selectSysSoftList(sysSoft); } /** * 鏂板杞欢 - * + * * @param sysSoft 杞欢 * @return 缁撴灉 */ @Override - public int insertSysSoft(SysSoft sysSoft) - { + public int insertSysSoft(SysSoft sysSoft) { + CaffeineUtils.remove(CACHE_KEY); sysSoft.setCreateTime(DateUtils.getNowDate()); return sysSoftMapper.insertSysSoft(sysSoft); } /** * 淇敼杞欢 - * + * * @param sysSoft 杞欢 * @return 缁撴灉 */ @Override - public int updateSysSoft(SysSoft sysSoft) - { + public int updateSysSoft(SysSoft sysSoft) { + CaffeineUtils.remove(CACHE_KEY); sysSoft.setUpdateTime(DateUtils.getNowDate()); return sysSoftMapper.updateSysSoft(sysSoft); } /** * 鎵归噺鍒犻櫎杞欢 - * + * * @param softIds 闇�瑕佸垹闄ょ殑杞欢涓婚敭 * @return 缁撴灉 */ @Override - public int deleteSysSoftBySoftIds(Long[] softIds) - { + public int deleteSysSoftBySoftIds(Long[] softIds) { + CaffeineUtils.remove(CACHE_KEY); return sysSoftMapper.deleteSysSoftBySoftIds(softIds); } /** * 鍒犻櫎杞欢淇℃伅 - * + * * @param softId 杞欢涓婚敭 * @return 缁撴灉 */ @Override - public int deleteSysSoftBySoftId(Long softId) - { + public int deleteSysSoftBySoftId(Long softId) { + CaffeineUtils.remove(CACHE_KEY); return sysSoftMapper.deleteSysSoftBySoftId(softId); } + + private List<SysSoft> getList() { + List<SysSoft> list = CaffeineUtils.getListByKey(CACHE_KEY); + if (null == list) { + list = selectSysSoftList(new SysSoft()); + CaffeineUtils.putListByKey(CACHE_KEY, list); + } + + return list; + } + + public void runSoftTest() throws Exception { + List<SysSoft> list = getList(); + if (CollectionUtils.isEmpty(list)) return; + + // + } } diff --git a/se-modules/se-system/src/main/java/com/se/system/service/impl/SysStatusCtrlServiceImpl.java b/se-modules/se-system/src/main/java/com/se/system/service/impl/SysStatusCtrlServiceImpl.java index b48b211..abdfda4 100644 --- a/se-modules/se-system/src/main/java/com/se/system/service/impl/SysStatusCtrlServiceImpl.java +++ b/se-modules/se-system/src/main/java/com/se/system/service/impl/SysStatusCtrlServiceImpl.java @@ -2,10 +2,13 @@ import java.util.List; import com.se.common.core.utils.DateUtils; +import com.se.system.domain.SysSoft; +import com.se.system.utils.CaffeineUtils; import org.springframework.stereotype.Service; import com.se.system.mapper.SysStatusCtrlMapper; import com.se.system.domain.SysStatusCtrl; import com.se.system.service.inte.ISysStatusCtrlService; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; @@ -16,82 +19,99 @@ * @date 2024-12-07 */ @Service -public class SysStatusCtrlServiceImpl implements ISysStatusCtrlService -{ +@SuppressWarnings("ALL") +public class SysStatusCtrlServiceImpl implements ISysStatusCtrlService { @Resource private SysStatusCtrlMapper sysStatusCtrlMapper; + private final static String CACHE_KEY = "list:statusctrl"; + /** * 鏌ヨ绯荤粺鐘舵�佺洃鎺� - * + * * @param statusId 绯荤粺鐘舵�佺洃鎺т富閿� * @return 绯荤粺鐘舵�佺洃鎺� */ @Override - public SysStatusCtrl selectSysStatusCtrlByStatusId(Long statusId) - { + public SysStatusCtrl selectSysStatusCtrlByStatusId(Long statusId) { return sysStatusCtrlMapper.selectSysStatusCtrlByStatusId(statusId); } /** * 鏌ヨ绯荤粺鐘舵�佺洃鎺у垪琛� - * + * * @param sysStatusCtrl 绯荤粺鐘舵�佺洃鎺� * @return 绯荤粺鐘舵�佺洃鎺� */ @Override - public List<SysStatusCtrl> selectSysStatusCtrlList(SysStatusCtrl sysStatusCtrl) - { + public List<SysStatusCtrl> selectSysStatusCtrlList(SysStatusCtrl sysStatusCtrl) { return sysStatusCtrlMapper.selectSysStatusCtrlList(sysStatusCtrl); } /** * 鏂板绯荤粺鐘舵�佺洃鎺� - * + * * @param sysStatusCtrl 绯荤粺鐘舵�佺洃鎺� * @return 缁撴灉 */ @Override - public int insertSysStatusCtrl(SysStatusCtrl sysStatusCtrl) - { + public int insertSysStatusCtrl(SysStatusCtrl sysStatusCtrl) { + CaffeineUtils.remove(CACHE_KEY); sysStatusCtrl.setCreateTime(DateUtils.getNowDate()); return sysStatusCtrlMapper.insertSysStatusCtrl(sysStatusCtrl); } /** * 淇敼绯荤粺鐘舵�佺洃鎺� - * + * * @param sysStatusCtrl 绯荤粺鐘舵�佺洃鎺� * @return 缁撴灉 */ @Override - public int updateSysStatusCtrl(SysStatusCtrl sysStatusCtrl) - { + public int updateSysStatusCtrl(SysStatusCtrl sysStatusCtrl) { + CaffeineUtils.remove(CACHE_KEY); sysStatusCtrl.setUpdateTime(DateUtils.getNowDate()); return sysStatusCtrlMapper.updateSysStatusCtrl(sysStatusCtrl); } /** * 鎵归噺鍒犻櫎绯荤粺鐘舵�佺洃鎺� - * + * * @param statusIds 闇�瑕佸垹闄ょ殑绯荤粺鐘舵�佺洃鎺т富閿� * @return 缁撴灉 */ @Override - public int deleteSysStatusCtrlByStatusIds(Long[] statusIds) - { + public int deleteSysStatusCtrlByStatusIds(Long[] statusIds) { + CaffeineUtils.remove(CACHE_KEY); return sysStatusCtrlMapper.deleteSysStatusCtrlByStatusIds(statusIds); } /** * 鍒犻櫎绯荤粺鐘舵�佺洃鎺т俊鎭� - * + * * @param statusId 绯荤粺鐘舵�佺洃鎺т富閿� * @return 缁撴灉 */ @Override - public int deleteSysStatusCtrlByStatusId(Long statusId) - { + public int deleteSysStatusCtrlByStatusId(Long statusId) { + CaffeineUtils.remove(CACHE_KEY); return sysStatusCtrlMapper.deleteSysStatusCtrlByStatusId(statusId); } + + private List<SysStatusCtrl> getList() { + List<SysStatusCtrl> list = CaffeineUtils.getListByKey(CACHE_KEY); + if (null == list) { + list = selectSysStatusCtrlList(new SysStatusCtrl()); + CaffeineUtils.putListByKey(CACHE_KEY, list); + } + + return list; + } + + public void runSubSysTest() throws Exception { + List<SysStatusCtrl> list = getList(); + if (CollectionUtils.isEmpty(list)) return; + + // + } } diff --git a/se-modules/se-system/src/main/java/com/se/system/utils/CaffeineUtils.java b/se-modules/se-system/src/main/java/com/se/system/utils/CaffeineUtils.java index 921640e..91d7945 100644 --- a/se-modules/se-system/src/main/java/com/se/system/utils/CaffeineUtils.java +++ b/se-modules/se-system/src/main/java/com/se/system/utils/CaffeineUtils.java @@ -2,8 +2,10 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; +import com.se.system.SeSystemApplication; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import java.math.BigInteger; import java.security.MessageDigest; @@ -12,15 +14,22 @@ @SuppressWarnings("ALL") public class CaffeineUtils { + static Integer cacheTime; + + @Value("${sys.cacheTime}") + public void setCacheTime(Integer cacheTime) { + CaffeineUtils.cacheTime = cacheTime; + } + private static Cache<String, Object> cache; private static final Logger log = LoggerFactory.getLogger(CaffeineUtils.class); - public static void init(Integer cacheTime) { + public static void init() { cache = Caffeine.newBuilder() .initialCapacity(16) .maximumSize(4096) - .expireAfterWrite(cacheTime, TimeUnit.MINUTES) + .expireAfterWrite(60 * 60 * 8, TimeUnit.SECONDS) .build(); } @@ -50,7 +59,7 @@ } public static <T> void putListByKey(String key, List<T> list) { - if (null != list && list.size() > 0) { + if (null != list) { put(key, list); } } diff --git a/se-modules/se-system/src/main/java/com/se/system/utils/RyTask.java b/se-modules/se-system/src/main/java/com/se/system/utils/RyTask.java index b779970..f4b2ec3 100644 --- a/se-modules/se-system/src/main/java/com/se/system/utils/RyTask.java +++ b/se-modules/se-system/src/main/java/com/se/system/utils/RyTask.java @@ -1,7 +1,13 @@ package com.se.system.utils; import com.se.common.core.utils.StringUtils; +import com.se.system.service.impl.SysSoftServiceImpl; +import com.se.system.service.impl.SysStatusCtrlServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; + +import javax.annotation.Resource; /** * 瀹氭椂浠诲姟璋冨害 @@ -10,6 +16,14 @@ */ @Component("ryTask") public class RyTask { + @Resource + SysSoftServiceImpl sysSoftService; + + @Resource + SysStatusCtrlServiceImpl sysStatusCtrlService; + + private static final Logger log = LoggerFactory.getLogger(RyTask.class); + public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { System.out.println(StringUtils.format("鎵ц澶氬弬鏂规硶锛� 瀛楃涓茬被鍨媨}锛屽竷灏旂被鍨媨}锛岄暱鏁村瀷{}锛屾诞鐐瑰瀷{}锛屾暣褰}", s, b, l, d, i)); } @@ -22,11 +36,13 @@ System.out.println("鎵ц鏃犲弬鏂规硶"); } - public void runSoftTest() { + public void runSoftTest() throws Exception { System.out.println("ryTask.runSoftTest()"); + sysSoftService.runSoftTest(); } - public void runSubSysTest() { + public void runSubSysTest() throws Exception { System.out.println("ryTask.runSubSysTest()"); + sysStatusCtrlService.runSubSysTest(); } } -- Gitblit v1.9.3