Browse Source

小优化

xiaochan 1 year ago
parent
commit
cf22c3fa27

+ 5 - 0
src/main/java/thyyxxk/webserver/dao/his/settings/MenuSettingsDao.java

@@ -13,4 +13,9 @@ public interface MenuSettingsDao extends BaseMapper<IntergrationMenu> {
     @Select("select * from t_intergration_menu order by type , sort  ")
     List<IntergrationMenu> getAll();
 
+
+
+    @Select("select * from yz_act_order where inpatient_no = '023594' and admiss_times = 6 and enter_oper = '02896'")
+    List<Object> test();
+
 }

+ 14 - 6
src/main/java/thyyxxk/webserver/service/settings/MenuSettingsService.java

@@ -3,6 +3,7 @@ package thyyxxk.webserver.service.settings;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.dao.his.settings.MenuSettingsDao;
@@ -12,31 +13,38 @@ import thyyxxk.webserver.entity.settings.IntergrationMenu;
 import thyyxxk.webserver.entity.settings.IntergrationPlatformRoleMenu;
 import thyyxxk.webserver.service.RedisServer;
 import thyyxxk.webserver.service.redislike.RedisLikeService;
+import thyyxxk.webserver.utils.DynamicDataUtils;
 import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.TokenUtil;
 import thyyxxk.webserver.utils.TreeUtil;
 
-import javax.annotation.PostConstruct;
 import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
 @Slf4j
 public class MenuSettingsService {
-
     private final MenuSettingsDao dao;
     private final RedisServer redisServer;
     private final RedisLikeService redisLikeService;
 
+    @Value("${spring.redis.host}")
+    private String redisUrl = "";
+
+    @Value("${spring.datasource.dynamic.primary}")
+    private String currentDbName = "";
+
     public MenuSettingsService(MenuSettingsDao dao, RedisServer redisServer, RedisLikeService redisLikeService) {
         this.dao = dao;
         this.redisServer = redisServer;
         this.redisLikeService = redisLikeService;
     }
 
-    @DS("his")
     public void menuPushRedis() {
-        redisServer.setData("IntergrationPlatformMenu", dao.getAll());
+        String redisProdUrl = "172.16.32.167";
+        String dbName = redisProdUrl.equals(redisUrl) ? "his" : currentDbName;
+        List<IntergrationMenu> list = DynamicDataUtils.changeByName(dbName, dao::getAll);
+        redisServer.setData("IntergrationPlatformMenu", list);
     }
 
     public List<IntergrationMenu> getMenuSettings() {
@@ -52,7 +60,7 @@ public class MenuSettingsService {
     }
 
     private List<IntergrationMenu> menuListByTree(List<IntergrationMenu> list) {
-        List<IntergrationMenu> res = TreeUtil.ObjectTree(list, (parent, child) -> {
+        List<IntergrationMenu> res = TreeUtil.objectTree(list, (parent, child) -> {
             if (parent == null) {
                 child.setCompletePath(child.getPath());
             } else {
@@ -61,7 +69,7 @@ public class MenuSettingsService {
                 child.setCompletePath(parent.getCompletePath() + "/" + child.getPath());
             }
         });
-        return TreeUtil.ObjectSort(res, "sort");
+        return TreeUtil.objectSort(res, "sort");
     }
 
     private List<IntergrationMenu> findParentMenus(List<IntergrationMenu> list, IntergrationMenu item) {

+ 20 - 0
src/main/java/thyyxxk/webserver/utils/DynamicDataUtils.java

@@ -0,0 +1,20 @@
+package thyyxxk.webserver.utils;
+
+
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
+
+import java.util.function.Supplier;
+
+
+public class DynamicDataUtils {
+
+    public static <T> T changeByName(String name, Supplier<T> supplier) {
+        DynamicDataSourceContextHolder.push(name);
+        try {
+            return supplier.get();
+        } finally {
+            DynamicDataSourceContextHolder.poll();
+        }
+    }
+
+}

+ 7 - 7
src/main/java/thyyxxk/webserver/utils/TreeUtil.java

@@ -18,11 +18,11 @@ public class TreeUtil {
         void apply(T t, T1 t1);
     }
 
-    public static <T> List<T> ObjectTree(List<T> tempList, TowFunction<T, T> addCallback) {
-        return ObjectTree(tempList, "id", "parentId", addCallback);
+    public static <T> List<T> objectTree(List<T> tempList, TowFunction<T, T> addCallback) {
+        return objectTree(tempList, "id", "parentId", addCallback);
     }
 
-    public static <T> List<T> ObjectSort(List<T> tempList, String sortName) {
+    public static <T> List<T> objectSort(List<T> tempList, String sortName) {
         String getSortName = StringUtil.getMethodName(sortName);
         String getChildrenName = StringUtil.getMethodName("children");
         String setChildrenName = StringUtil.setMethodName("children");
@@ -31,7 +31,7 @@ public class TreeUtil {
                 .sorted((Comparator.comparing(a -> {
                             List<T> child = ReflectUtil.invoke(a, getChildrenName);
                             if (child != null && !child.isEmpty()) {
-                                ReflectUtil.invoke(a, setChildrenName, ObjectSort(child, sortName));
+                                ReflectUtil.invoke(a, setChildrenName, objectSort(child, sortName));
                             }
                             Integer sort = ReflectUtil.invoke(a, getSortName);
                             return sort == null ? 0 : sort;
@@ -41,11 +41,11 @@ public class TreeUtil {
         return sorted.collect(Collectors.toList());
     }
 
-    public static <T> List<T> ObjectTree(List<T> tempList) {
-        return ObjectTree(tempList, "id", "parentId", null);
+    public static <T> List<T> objectTree(List<T> tempList) {
+        return objectTree(tempList, "id", "parentId", null);
     }
 
-    public static <T> List<T> ObjectTree(List<T> tempList, String id, String parentId, TowFunction<T, T> addCallback) {
+    public static <T> List<T> objectTree(List<T> tempList, String id, String parentId, TowFunction<T, T> addCallback) {
         id = StringUtil.getMethodName(id);
         parentId = StringUtil.getMethodName(parentId);
 

+ 1 - 1
src/main/resources/application-cytest.yml

@@ -15,7 +15,7 @@ spring:
     cache: false
   datasource:
     dynamic:
-      primary: dev
+      primary: his
       strict: false
       datasource:
         his: