Эх сурвалжийг харах

Merge branch 'huangzqa-use-spring-cahce-20210531' into 'develop'

Huangzqa use spring cahce 20210531

See merge request dcuc-bujz/app-service!6
黄资权 4 жил өмнө
parent
commit
b338c52569

+ 9 - 10
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ApplyInfoServiceImpl.java

@@ -32,7 +32,6 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheConfig;
 import org.springframework.cache.annotation.CacheEvict;
-import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Sort;
@@ -48,7 +47,7 @@ import java.util.stream.Collectors;
  * @author huangzqa
  * @date 2020/10/27
  */
-@CacheConfig(cacheNames = "DCUC-APP:app")
+@CacheConfig(cacheNames = "DCUC-APP-APP")
 @Service
 public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String> implements IApplyInfoService {
 
@@ -90,7 +89,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.pagingBySearchable(searchable);
     }
 
-    @CachePut(key = "targetClass + #p0.id")
+    @CacheEvict(allEntries = true)
     @Transactional(rollbackFor = Exception.class)
     @Override
     public ApplyInfo saveAppIy(ApplyInfoDTO applyInfoDTO) {
@@ -126,7 +125,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfo;
     }
 
-    @CachePut(key = "targetClass + #p0.id")
+    @CacheEvict(allEntries = true)
     @Transactional(rollbackFor = Exception.class)
     @Override
     public ApplyInfo updateApply(ApplyInfoDTO applyInfoDTO) {
@@ -174,7 +173,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfo;
     }
 
-    @CacheEvict(value = "DCUC-APP:app", allEntries = true)
+    @CacheEvict(allEntries = true)
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void del(String id) {
@@ -194,7 +193,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.getNewSort();
     }
 
-    @CacheEvict(value = "DCUC-APP:app", allEntries = true)
+    @CacheEvict(allEntries = true)
     @Transactional(rollbackFor = Exception.class)
     @Override
     public String startOrStop(String id) {
@@ -218,7 +217,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return message;
     }
 
-    @CacheEvict(value = "DCUC-APP:app", allEntries = true)
+    @CacheEvict(allEntries = true)
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void sortApp(String id, String target) {
@@ -276,7 +275,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return LangUtil.array2String(stringList, StrUtil.COMMA);
     }
 
-    @Cacheable(key = "targetClass +#p0")
+    @Cacheable(key = "targetClass +methodName+#p0")
     @Override
     public ApplyInfo getAppByCode(String appCode) {
         LambdaQueryWrapper<ApplyInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -360,7 +359,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return ResponseStatus.success();
     }
 
-    @CacheEvict(value = "DCUC-APP:app", allEntries = true)
+    @CacheEvict(allEntries = true)
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void updateOrgInfos(String orgId, String orgName) {
@@ -394,7 +393,7 @@ public class ApplyInfoServiceImpl extends BaseMybatisService<ApplyInfo, String>
         return applyInfoMapper.selectList(queryWrapper);
     }
 
-    @CacheEvict(value = "DCUC-APP:app", allEntries = true)
+    @CacheEvict(allEntries = true)
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void saveDutyMan(String dutyProject, String userId, String mobileWork) {

+ 19 - 2
dcuc-app-service/src/main/java/com/dragoninfo/dcuc/app/service/impl/ManufacturerInfoServiceImpl.java

@@ -16,6 +16,9 @@ import com.dragonsoft.duceap.core.search.Searchable;
 import com.dragonsoft.duceap.core.search.enums.SearchOperator;
 import com.dragonsoft.duceap.mybaitsplus.core.services.BaseMybatisService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -28,7 +31,7 @@ import java.util.stream.Collectors;
  * @author huangzqa
  * @date 2020/10/26
  */
-@Transactional(rollbackFor = Exception.class)
+@CacheConfig(cacheNames = "DCUC-APP-MANU")
 @Service
 public class ManufacturerInfoServiceImpl extends BaseMybatisService<ManufacturerInfo, String> implements IManufacturerInfoService {
 
@@ -42,6 +45,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         this.manufacturerInfoMapper = manufacturerInfoMapper;
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0")
     @Override
     public Page<ManufacturerInfo> manufacturerInfoPage(SearchDTO searchDTO) {
         Searchable searchable = Searchable.toSearchable(searchDTO);
@@ -49,11 +53,14 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return manufacturerInfoMapper.pagingBySearchable(searchable);
     }
 
+    @Cacheable(key = "targetClass +#p0")
     @Override
     public ManufacturerInfo manufacturerInfoDetail(String id) {
         return manufacturerInfoMapper.selectById(id);
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public ManufacturerInfo saveManufacturer(ManufacturerInfo info) {
         info.setDeleted(BooleanEnum.FALSE.getValue());
@@ -63,6 +70,8 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return info;
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public ManufacturerInfo updateManufacturer(ManufacturerInfo info) {
         manufacturerInfoMapper.updateById(info);
@@ -70,6 +79,8 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return info;
     }
 
+    @CacheEvict(allEntries = true)
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public void del(String id) {
         ManufacturerInfo manufacturerInfo = manufacturerInfoMapper.selectById(id);
@@ -80,6 +91,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         sendMessage("厂商表信息删除", manufacturerInfo, ManufacturerMsgTypeEnum.DELETED);
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0")
     @Override
     public ManufacturerInfo detailByCode(String code) {
         LambdaQueryWrapper<ManufacturerInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -89,6 +101,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return manufacturerInfoMapper.selectOne(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0")
     @Override
     public ManufacturerInfo getOneByName(String manufacturerName) {
 
@@ -99,6 +112,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return manufacturerInfoMapper.selectOne(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0+p1")
     @Override
     public ManufacturerInfo getOneByCodeName(String code, String manufacturerName) {
         LambdaQueryWrapper<ManufacturerInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -107,6 +121,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
         return manufacturerInfoMapper.selectOne(queryWrapper);
     }
 
+    @Cacheable(key = "targetClass +methodName")
     @Override
     public List<CodeRecord> getAllCodeRecord() {
 
@@ -128,6 +143,7 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
                 .collect(Collectors.toList());
     }
 
+    @Cacheable(key = "targetClass +methodName")
     @Override
     public Map<String, String> getAllIdNameMap() {
         LambdaQueryWrapper<ManufacturerInfo> queryWrapper = Wrappers.lambdaQuery();
@@ -139,11 +155,12 @@ public class ManufacturerInfoServiceImpl extends BaseMybatisService<Manufacturer
                 .collect(Collectors.toMap(ManufacturerInfo::getId, ManufacturerInfo::getManufacturerName));
     }
 
+    @Cacheable(key = "targetClass +methodName +#p0")
     @Override
     public List<ManufacturerInfo> getByCodes(List<String> list) {
         LambdaQueryWrapper<ManufacturerInfo> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.select()
-                    .in(ManufacturerInfo::getCode);
+                .in(ManufacturerInfo::getCode);
         return manufacturerInfoMapper.selectList(queryWrapper);
     }
 

+ 11 - 10
dcuc-app-service/src/main/resources/application-base.yml

@@ -30,6 +30,17 @@ spring:
     jedis:
       pool:
         max-active: 500
+  cache:
+    # 缓存类型,默认根据环境自动检测,ehcache、redis、simple、caffeine、jcache、infinispan、Hazeleast、none
+    type: redis
+    # 如果底层缓存管理器支持缓存名的话,可以在这里指定要创建的缓存名列表,用逗号分 隔。通常这会禁用运行时创建其他额外缓存的能力。
+    cache-names: DCUC-APP-APP,DCUC-APP-MANU
+    # 缓存连接超时时间
+    #多cacheManager支持 CacheManager(ex:ehCacheCacheManager,simpleCacheManager,redisCacheManager,caffeineCacheManager)
+    init-cache-managers: redisCacheManager
+    redis-time-live:
+      DCUC-APP-APP: 1800000
+      DCUC-APP-MANU: 1800000
   kafka:
     producer:
       bootstrap-servers: 192.168.10.20:9093
@@ -79,16 +90,6 @@ duceap:
     sqlaudit:
       output: kafka
       exclude-tables: T_LOG_*
-  cache:
-    # 缓存类型,默认根据环境自动检测,ehcache、redis、simple、caffeine、jcache、infinispan、Hazeleast、none
-    type: redis
-    # 如果底层缓存管理器支持缓存名的话,可以在这里指定要创建的缓存名列表,用逗号分 隔。通常这会禁用运行时创建其他额外缓存的能力。
-    cache-names: DCUC-APP:app
-    # 缓存连接超时时间
-    redis:
-      time-to-live: 5000
-    #多cacheManager支持 CacheManager(ex:ehCacheCacheManager,simpleCacheManager,redisCacheManager,caffeineCacheManager)
-    init-cache-managers: redisCacheManager
   license:
     enabled: false
     #配置用来指定license对接的后端项目地址(格式:ip:port/context,如http://10.10.10.10:8080/ctx),