增加了数据字典刷新
authorTang Cheng <cheng.tang@supwisdom.com>
Tue, 9 Jul 2019 03:41:43 +0000 (11:41 +0800)
committerTang Cheng <cheng.tang@supwisdom.com>
Wed, 10 Jul 2019 02:23:23 +0000 (10:23 +0800)
payapi/src/main/java/com/supwisdom/dlpay/framework/dao/DictionaryDao.java
payapi/src/main/java/com/supwisdom/dlpay/system/controller/DictPoolAction.java
payapi/src/main/java/com/supwisdom/dlpay/system/service/DictionaryDataService.java
payapi/src/main/java/com/supwisdom/dlpay/system/service/DictionaryProxy.java
payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/DictionaryDataServiceImpl.java

index efdd384..6ffdc21 100644 (file)
@@ -12,4 +12,5 @@ import java.util.List;
 @Repository
 public interface DictionaryDao extends JpaRepository<TDictionary, TDictionaryPK> {
   List<TDictionary> findAllByDicttype(String dicttype);
+  void deleteByDicttype(String dicttype);
 }
index af00076..9c78b00 100644 (file)
@@ -13,8 +13,11 @@ import java.util.Map;
 
 @RestController
 public class DictPoolAction {
-  @Autowired
-  private DictionaryProxy dictionaryProxy;
+  private final DictionaryProxy dictionaryProxy;
+
+  public DictPoolAction(DictionaryProxy dictionaryProxy) {
+    this.dictionaryProxy = dictionaryProxy;
+  }
 
   @GetMapping("/dictpool")
   public Map getDictDataByDicttype(@FormParam("dicttype") String dictType, HttpServletRequest request) {
@@ -24,6 +27,7 @@ public class DictPoolAction {
 
   @GetMapping("/dictrefresh")
   public JsonResult refreshDict() {
+    dictionaryProxy.refreshDictionary();
     return JsonResult.ok();
   }
 
index 48cc4df..d7d1027 100644 (file)
@@ -8,6 +8,12 @@ import java.util.List;
 public interface DictionaryDataService {
   List<TDictionary> getDictionaryByDictType(String dicttype);
 
+  void updateDictionaryByDictType(String dicttype, List<TDictionary> list);
+
+  void refreshCache(String dicttype);
+
+  void refreshCache();
+
   List<TTranscode> getTransCode();
 
 }
index 7f8d814..c78b89c 100644 (file)
@@ -53,4 +53,12 @@ public class DictionaryProxy {
       return (List<T>) dictionaryDataService.getDictionaryByDictType(dictType);
     }
   }
+
+  public void refreshDictionary() {
+    dictionaryDataService.refreshCache();
+  }
+
+  public void refreshDictionary(String dicttype) {
+    dictionaryDataService.refreshCache(dicttype);
+  }
 }
index 523bded..1b9a14e 100644 (file)
@@ -5,6 +5,7 @@ import com.supwisdom.dlpay.framework.dao.TranscodeDao;
 import com.supwisdom.dlpay.framework.domain.TDictionary;
 import com.supwisdom.dlpay.framework.domain.TTranscode;
 import com.supwisdom.dlpay.system.service.DictionaryDataService;
+import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
@@ -23,7 +24,7 @@ public class DictionaryDataServiceImpl implements DictionaryDataService {
   }
 
   @Override
-  @Cacheable(cacheNames = "dicationary_cache", key = "#p0")
+  @Cacheable(cacheNames = "dictionary_cache", key = "#p0")
   public List<TDictionary> getDictionaryByDictType(String dicttype) {
     List<TDictionary> list = dictionaryDao.findAllByDicttype(dicttype);
     if (!list.isEmpty()) {
@@ -33,6 +34,31 @@ public class DictionaryDataServiceImpl implements DictionaryDataService {
   }
 
 
+  @Override
+  @CacheEvict(cacheNames = "dictionary_cache", key = "#p0")
+  public void updateDictionaryByDictType(String dicttype, List<TDictionary> list) {
+    for (TDictionary item : list) {
+      if (!dicttype.equals(item.getDicttype())) {
+        throw new IllegalArgumentException("TDictionary dicttype mismatch");
+      }
+    }
+    dictionaryDao.deleteByDicttype(dicttype);
+    for (TDictionary item : list) {
+      dictionaryDao.save(item);
+    }
+  }
+
+  @Override
+  @CacheEvict(cacheNames = "dictionary_cache", key = "#p0")
+  public void refreshCache(String dicttype) {
+  }
+
+  @Override
+  @CacheEvict(cacheNames = "dictionary_cache", allEntries = true)
+  public void refreshCache() {
+
+  }
+
   @Override
   @Cacheable(cacheNames = "trans_code_cache")
   public List<TTranscode> getTransCode() {