From c007f0ca1785db093d48f4846cda82fe8e955765 Mon Sep 17 00:00:00 2001
From: kimi <kimi42345@gmail.com>
Date: 星期三, 27 五月 2020 09:59:29 +0800
Subject: [PATCH] merage

---
 src/main/java/com/highdatas/mdm/util/DbUtils.java |  147 ++++++++++++++++++++++++++++---------------------
 1 files changed, 84 insertions(+), 63 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/util/DbUtils.java b/src/main/java/com/highdatas/mdm/util/DbUtils.java
index 26a1c9c..529d82b 100644
--- a/src/main/java/com/highdatas/mdm/util/DbUtils.java
+++ b/src/main/java/com/highdatas/mdm/util/DbUtils.java
@@ -1,7 +1,7 @@
 package com.highdatas.mdm.util;
 
 
-import com.baomidou.mybatisplus.annotations.TableName;
+import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Maps;
 import com.highdatas.mdm.entity.Character;
 import com.highdatas.mdm.entity.*;
@@ -27,8 +27,6 @@
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletRequest;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.security.MessageDigest;
 import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
@@ -62,6 +60,15 @@
 
     public static ISysDispenseLogsService dispenseLogsService;
     public static DispenseService dispenseService;
+
+    public static AntianaphylaxisClient antianaphylaxisClient;
+
+
+    @Autowired
+    public void setAntianaphylaxisClient(AntianaphylaxisClient antianaphylaxisClient){
+        DbUtils.antianaphylaxisClient = antianaphylaxisClient;
+    }
+
 
 
     @Autowired
@@ -187,29 +194,14 @@
         return map;
     }
 
+    public static HashMap<String, Object> JsonObjectToHashMap(JSONObject jsonObj){
+        HashMap<String, Object> data = new HashMap<String, Object>();
 
-    public static Integer getSubVersion(String baseVersion) {
-        if (StringUtils.isEmpty(baseVersion)) {
-            return null;
+        Set<String> keySet = jsonObj.keySet();
+        for (String key : keySet) {
+            data.put(key, jsonObj.get(key));
         }
-
-        String[] split = baseVersion.split(Constant.Dot);
-        if (split.length == 1) {
-            return null;
-        }
-        return  Integer.valueOf(split[1]);
-    }
-    public static Integer getBigVersion(String baseVersion) {
-        if (StringUtils.isEmpty(baseVersion)) {
-            return null;
-        }
-
-        String[] split = baseVersion.split(Constant.Dot);
-        if (split.length == 0 || split[0].length() < 2) {
-            return null;
-        }
-
-        return  Integer.valueOf(split[0].substring(1));
+        return data;
     }
 
 
@@ -227,29 +219,6 @@
         return segment.toString();
     }
 
-    public static String getTableNameFromEntity(Object object) {
-        Field[] fields = object.getClass().getDeclaredFields();
-        for (Field field : fields) {
-            field.setAccessible(true);
-            // 鑾峰彇琛ㄥ悕
-            TableName table = object.getClass().getAnnotation(TableName.class);
-            if (table != null) {
-                String tableName = table.value();
-                return tableName;
-            }
-        }
-        return null;
-    }
-
-    public static Object toSqlToJava(String value, TableSchemaResult tableSchema) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException {
-        String dbType = tableSchema.getDbType();
-        String javaType = toSqlToJava(dbType);
-        Class<?> baseWapperClaz = Class.forName("java.lang." + javaType);
-        Object baseWapper = baseWapperClaz.newInstance();
-        Method valueOfMethod = baseWapperClaz.getDeclaredMethod("valueOf");
-        return null;
-//        valueOfMethod.invoke(baseWapper, )
-    }
 
     public static String toSqlToJava(String sqlType) {
         if( sqlType == null || sqlType.trim().length() == 0 ) return sqlType;
@@ -289,12 +258,6 @@
         return sqlType;
     }
 
-    public static void sqlValueToJava(Object value, String dbType) throws Exception {
-        String javaType = toSqlToJava(dbType);
-        Class<?> baseWapperClaz = Class.forName("java.lang." + javaType);
-        Object baseWapper = baseWapperClaz.newInstance();
-        Method valueOfMethod = baseWapperClaz.getDeclaredMethod("valueOf");
-    }
 
     public static String quotedStr(Object o) {
        return quotedStr(String.valueOf(o));
@@ -365,15 +328,6 @@
         return orderNo + 1;
     }
 
-    public static Date getDateByStart() {
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime(new Date());
-        calendar.set(Calendar.HOUR_OF_DAY, 0);
-        calendar.set(Calendar.MINUTE, 0);
-        calendar.set(Calendar.SECOND, 0);
-        Date zero = calendar.getTime();
-        return zero;
-    }
     public static Date getDateByEnd() {
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(new Date());
@@ -493,6 +447,15 @@
         }
         String[] split = redisVal.split(Constant.SEMICOLON);
         List<String> strings = Arrays.asList(split);
+        return  new ArrayList<String>(strings);
+    }
+
+    public static List<String> split(String redisVal, String spilt) {
+        if (StringUtils.isEmpty(redisVal)) {
+            return new ArrayList<>();
+        }
+        String[] split = redisVal.split(spilt);
+        List<String> strings = Arrays.asList(split);
         return strings;
     }
 
@@ -552,6 +515,7 @@
     }
     public static TUser getUserById(String userId) {
         TUser tUserById = userRoleClient.getTUserById(userId);
+
         return tUserById;
     }
 
@@ -575,13 +539,18 @@
 
     public static Set<TUser> getAllUser() {
         List<TUser> tRoleListByUserId = userRoleClient.listUserRoleGroup();
+        if (tRoleListByUserId == null) {
+            return new HashSet<>();
+        }
         return new HashSet<TUser>(tRoleListByUserId);
     }
 
 
     public static Set<String> getUserByRole(String roleId) {
         List<String> userListByRole = userRoleClient.getUserListByRole(roleId);
-
+        if (userListByRole == null) {
+            return new HashSet<>();
+        }
         HashSet<String> result = new HashSet<>(userListByRole);
         return result;
     }
@@ -658,4 +627,56 @@
         String time = format.format(new Date());
         return time;
     }
+
+    public static Set<String> getRoleByUser(String userId, String uuid) {
+
+        Date start = new Date();
+        List<TRole> tRoleListByUserId = userRoleClient.getTRoleListByUserId(userId);
+        Date end = new Date();
+        log.info(MessageFormat.format("master tag:{0} form userId select role :{1} ms",uuid, (end.getTime() - start.getTime())));
+
+
+        if (tRoleListByUserId == null || tRoleListByUserId.isEmpty()){
+            return new HashSet<>();
+        }
+        Set<String> collect = tRoleListByUserId.stream()
+                .filter(tRole -> tRole != null).map(tRole -> tRole.getRoleId()).collect(Collectors.toSet());
+
+
+        return collect;
+        
+    }
+
+    public static Set<String> getGroupByUser(String userId, String uuid) {
+
+        Date start = new Date();
+        List<TUserGroup> tRoleListByUserId = userRoleClient.getUserGroupByUserId(userId);
+        Date end = new Date();
+        log.info(MessageFormat.format("master tag:{0} form userId select group :{1} ms",uuid, (end.getTime() - start.getTime())));
+
+        if (tRoleListByUserId == null || tRoleListByUserId.isEmpty()){
+            return new HashSet<>();
+        }
+        Set<String> collect = tRoleListByUserId.stream().map(tRole -> tRole.getGroupId()).collect(Collectors.toSet());
+
+
+        return collect;
+    }
+
+    public static Set<String> getRoleByGroup(String groupId, String uuid) {
+
+        Date start = new Date();
+        List<TRole> tRoleListByUserId = userRoleClient.getRoleListByGroupId(groupId);
+        Date end = new Date();
+        log.info(MessageFormat.format("master tag:{0} form groupId select role :{1} ms",uuid, (end.getTime() - start.getTime())));
+
+        if (tRoleListByUserId == null || tRoleListByUserId.isEmpty()){
+            return new HashSet<>();
+        }
+        Set<String> collect = tRoleListByUserId.stream().map(tRole -> tRole.getRoleId()).collect(Collectors.toSet());
+
+
+        return collect;
+    }
+
 }

--
Gitblit v1.8.0