Browse Source

Merge branch 'feature-refactor' of ssh://10.10.100.21/source/platform-bi-server into feature-refactor

zhuth 6 years ago
parent
commit
6148383030

+ 3 - 3
bi-core/src/main/java/com/usoftchina/bi/core/base/BaseContextHolder.java

@@ -35,7 +35,7 @@ public class BaseContextHolder {
         return Integer.valueOf(String.valueOf(value));
     }
 
-    public static void setUserId(int userId) {
+    public static synchronized void setUserId(int userId) {
         set("userId", userId);
     }
 
@@ -44,7 +44,7 @@ public class BaseContextHolder {
         return String.valueOf(value);
     }
 
-    public static void setUserName(String userName) {
+    public static synchronized void setUserName(String userName) {
         set("userName", userName);
     }
 
@@ -53,7 +53,7 @@ public class BaseContextHolder {
         return String.valueOf(value);
     }
 
-    public static void setRole(String role){
+    public static synchronized void setRole(String role){
         set("role", role);
     }
 }

+ 2 - 1
bi-core/src/main/java/com/usoftchina/bi/core/base/RepCode.java

@@ -25,7 +25,8 @@ public enum  RepCode {
     DATACONNECTOR_USED_DATASOURCE(-511, "已有数据源使用了此连接,无法删除!"),
     CHARTS_USED_DATACONNECTOR(-512, "该数据源存在关联的图表,不允许删除!"),
     DASHBOARD_USED_CHARTS(-513, "该图表存在关联的报表,不允许删除!"),
-    MENU_USED_DASHBOARD(-514, "此目录下存在看板,无法删除!");
+    MENU_USED_DASHBOARD(-514, "此目录下存在报表,无法删除!"),
+    USER_GROUP_EXISTS(-515, "用户组名称已存在!");
 
     private int code;
     private String msg;

+ 3 - 5
bi-server/src/main/java/com/usoftchina/bi/server/dao/chart/ChartsConfigMapper.java

@@ -48,8 +48,9 @@ public interface ChartsConfigMapper {
     /*
     查看图表列表
      */
-    @Select("select id as chartId, chart_name as chartName, chart_type as chartType, create_by as createBy, create_date as createDate" +
-            ",bc_filters as filters, CHART_DESCRIBES as describes, bc_charts_group as chartsGroup, bc_charts_option as chartOption, demo from bi_charts")
+    @Select("select '1' as authority,case when bc.BD_DATA_ID not in(select id from bi_data_connectors) then '1' else '0' end dbStatus, bc.id as chartId, bc.chart_name as chartName, bc.chart_type as chartType, bc.create_by as createBy, bc.create_date as createDate"
+            + ",bc.bc_filters as filters, bc.CHART_DESCRIBES as describes, bc.bc_charts_group as chartsGroup, bc.bc_charts_option as chartOption ,bc.bd_data_id as dataId,bd.data_name as dataName, bc.create_id as createId, bc.demo, bds.BASES_NAME as dataConnectionName, bds.id as dataConnectionId "
+            + "from bi_charts bc left join bi_data_connectors bd on bc.bd_data_id=bd.id left join BI_DATABASES bds on bds.id = BD.DB_CONFIG")
     List<ChartConfigList> getListCharts();
 
     /*
@@ -107,9 +108,6 @@ public interface ChartsConfigMapper {
             "    ))")
     List<ChartConfigList> getListByUser(@Param("id") int id, TestPage testPage);
 
-    @Select("")
-    List<ChartConfigList> getListWithoutLimit(@Param("id") int id, TestPage testPage);
-
     /*
     通过Id查找表名
     */

+ 18 - 2
bi-server/src/main/java/com/usoftchina/bi/server/dao/user/UserMapper.java

@@ -129,7 +129,7 @@ public interface UserMapper {
      */
     @Select("SELECT BU_ID as id, BU_NAME as name, BU_DEPARTMENT as department, BU_POST as post, BU_ROLE as role," +
             " USER_NAME as userName, PASS_WORD as passWord, BU_PHONE as phone, BU_CLASS as state " +
-            "FROM BI_USERS WHERE USER_NAME = #{userName}")
+            "FROM BI_USERS WHERE USER_NAME = #{userName} AND BU_CLASS <> '离职'")
     User getBIUserByName(@Param("userName") String userName);
 
     /**
@@ -139,7 +139,7 @@ public interface UserMapper {
      */
     @Select("SELECT BU_ID as id, BU_NAME as name, BU_DEPARTMENT as department, BU_POST as post, BU_ROLE as role," +
             " USER_NAME as userName, PASS_WORD as passWord, BU_PHONE as phone, BU_CLASS as state " +
-            "FROM BI_USERS WHERE BU_PHONE = #{mobile}")
+            "FROM BI_USERS WHERE BU_PHONE = #{mobile} AND BU_CLASS <> '离职'")
     User getBIUserByMobile(@Param("mobile") String mobile);
 
     /*
@@ -180,6 +180,14 @@ public interface UserMapper {
     @Update("update bi_users set user_token = #{token} where bu_id = #{id}")
     void updateToken(@Param("token") String token, @Param("id") int id);
 
+    /**
+     * 查询名称是否重复
+     * @param name
+     * @return
+     */
+    @Select("SELECT COUNT(*) FROM BI_USER_GROUPS WHERE BG_NAME = #{name,jdbcType=VARCHAR}")
+    int getGroupCountByGroupName(@Param("name")String name);
+
     /*
     创建用户组
      */
@@ -241,6 +249,14 @@ public interface UserMapper {
     @Select("select count(*) from bi_user_rel_groups where br_user_id = #{userId} and br_user_group = #{userGroupId} ")
     int getUserCountInGroup(@Param("userId") int userId, @Param("userGroupId") int userGroupId);
 
+    /**
+     * 获取用户名
+     * @param ids
+     * @return
+     */
+    @Select("SELECT WM_CONCAT(BU_NAME) FROM BI_USERS WHERE BU_ID IN (${ids})")
+    String getUserByIds(String ids);
+
     /*
     查询用户组下的用户信息
      */

+ 7 - 1
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ChartsConfigService.java

@@ -205,7 +205,13 @@ public class ChartsConfigService {
      */
     public RepEntity getListCharts(String token, TestPage testPage){
         int id = BaseContextHolder.getUserId();
-        List<ChartConfigList> chartsList = chartsConfigMapper.getListByUser(id,testPage.enablePaging());
+        String role = BaseContextHolder.getRole();
+        List<ChartConfigList> chartsList = new ArrayList<>();
+        if (RoleConstant.SUPER_ADMIN.getRole().equals(role)) {
+            chartsList = chartsConfigMapper.getListCharts();
+        }else {
+            chartsList = chartsConfigMapper.getListByUser(id, testPage.enablePaging());
+        }
         PageInfo<ChartConfigList> pageInfo = new PageInfo<>(chartsList);
         return new RepEntity(RepCode.success, pageInfo);
     }

+ 20 - 4
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowHistogramService.java

@@ -138,10 +138,26 @@ public class ShowHistogramService {
             }
 
             //无分组时Y值
-            if ("time".equals(xColumnType)){        //如果是时间类型
-                value = timeConverterUtil.getHistogramTimeValue(yColumn, xColumn, tableName, yAxisType, xAxisType, xAxisData, screenToColumnS);
-            }else {
-                value = showChartsMapper.getValues(yColumn, xColumn, tableName, yAxisType, screenToColumnS, screen, histogramConfigInfo.getMaxCount());
+            Iterator itX = xAxisData.iterator();
+            while (itX.hasNext()){
+                String xdata = (String)itX.next();
+                double valueOne = 0;
+                String valueOnes = null;
+                if ("time".equals(xColumnType)){
+                    valueOnes = timeConverterUtil.getTimeValueConverter(yColumn, xColumn, tableName, yAxisType, xAxisType, xdata, screenToColumnS);
+                }else {
+                    if (xdata == null || "".equals(xdata)){
+                        valueOnes = showChartsMapper.getValuesIsNull(yColumn, xColumn, tableName, yAxisType, screenToColumnS);
+                    }else {
+                        valueOnes = showChartsMapper.getXValue(yColumn, xColumn, tableName, yAxisType, xdata, screenToColumnS);
+                    }
+                }
+                if (valueOnes == null || "".equals(valueOnes)){
+                    valueOne = 0;
+                }else {
+                    valueOne = Double.parseDouble(valueOnes);
+                }
+                value.add(valueOne);
             }
 
             series.setName(xColumn);

+ 3 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/dataSource/DataConnectorService.java

@@ -139,6 +139,9 @@ public class DataConnectorService {
         while (isList.hasNext()) {
             DataConnectorList dataConnectorList = (DataConnectorList) isList.next();
             BaseConfig baseConfig = dataConnectorList.getDbConfig();
+            if (ObjectUtils.isEmpty(baseConfig)) {
+                continue;
+            }
             baseConfig.setPassWord("");
             dataConnectorList.setDbConfig(baseConfig);
             listConnectors.add(dataConnectorList);

+ 63 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/user/UserService.java

@@ -9,6 +9,7 @@ import com.usoftchina.bi.core.utils.EncryUtil;
 import com.usoftchina.bi.server.aspect.JwtTokenAspect;
 import com.usoftchina.bi.server.dao.user.UserMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.usoftchina.bi.server.model.po.MessageLog;
 import com.usoftchina.bi.server.model.po.TokenData;
 import com.usoftchina.bi.server.model.po.User;
 import com.usoftchina.bi.server.model.po.UserGroup;
@@ -24,6 +25,7 @@ import org.springframework.util.StringUtils;
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
 public class UserService {
@@ -68,6 +70,11 @@ public class UserService {
             password = user.getPassWord();
 
             user = findUserFromUAS(userName, pws);
+            if ("离职".equals(user.getState())) {
+                //更新离职状态
+                userMapper.updateUser(user);
+                throw new MyException(RepCode.NoUser);
+            }
             user.setRole(role);
             int userId = userMapper.getUserId(user.getUserName());
             user.setId(userId);
@@ -158,6 +165,10 @@ public class UserService {
     创建用户组
      */
     public RepEntity createUserGroup(UserGroupInfo userGroupInfo){
+        int count = userMapper.getGroupCountByGroupName(userGroupInfo.getUserGroupName());
+        if (count > 0) {
+            throw new MyException(RepCode.USER_GROUP_EXISTS);
+        }
         UserGroup userGroup = new UserGroup();
         BeanUtils.copyProperties(userGroupInfo,userGroup);
         if (userGroup.getUserGroupNote() == null){
@@ -201,7 +212,9 @@ public class UserService {
     添加用户到用户组
      */
     public RepEntity setUserInto(UserGroupSetInfo userGroupSetInfo){
+        String username = BaseContextHolder.getUserName();
         int userGroupId = userGroupSetInfo.getUserGroupId();
+        String groupName = userMapper.getUserGroup(userGroupId).getUserGroupName();
         List<Integer> userList = userGroupSetInfo.getUserList();
         Iterator isList = userList.iterator();
         while (isList.hasNext()){
@@ -213,6 +226,8 @@ public class UserService {
                 userMapper.setUserInto(userId, userGroupId);
             }
         }
+        //记录LOG
+        userGroupLog(userList, username, groupName, "add");
         return new RepEntity(RepCode.success);
     }
 
@@ -230,11 +245,59 @@ public class UserService {
     public RepEntity delUserInGroup(UserGroupSetInfo userGroupSetInfo){
         List<Integer> list = userGroupSetInfo.getUserList();
         int userGroupId = userGroupSetInfo.getUserGroupId();
+        String username = BaseContextHolder.getUserName();
+        String groupName = userMapper.getUserGroup(userGroupId).getUserGroupName();
         Iterator isList = list.iterator();
         while (isList.hasNext()){
             int userId = (int) isList.next();
             userMapper.delUserInGroup(userId, userGroupId);
         }
+        //记录LOG
+        userGroupLog(list, username, groupName, "delete");
         return new RepEntity(RepCode.success);
     }
+
+    private void userGroupLog(List<Integer> userList, String username, String groupName, String type){
+        //记录LOG
+        List<String> userIdsList = userList.stream().map(x -> x + "").collect(Collectors.toList());
+        String userIds = String.join(",", userIdsList);
+        String userNames = userMapper.getUserByIds(userIds);
+        String[] userNameArray = userNames.split(",");
+        StringBuilder sb = new StringBuilder();
+        MessageLog messageLog = new MessageLog();
+        String content = "", result = "";
+        if (userNameArray.length > 10) {
+            for (int i = 0, len = userNameArray.length; i < len; i = i+10) {
+                for (int j = 0; j < 10; j++) {
+                    sb.append(userNameArray[i+j] + ",");
+                }
+                String names = sb.substring(0, sb.length() - 1);
+                if ("add".equals(type)) {
+                    content = "添加用户:" + names + " 到用户组" + groupName + "中";
+                    result = "添加成功";
+                }else if ("delete".equals(type)){
+                    content = "从用户组" + groupName + "删除用户:" + names;
+                    result = "删除成功";
+                }
+                messageLog = new MessageLog(username, content,result, null, "用户管理", null);
+                messageLogService.customizeLog(messageLog);
+                sb.delete(0, sb.length());
+            }
+
+        }else {
+            for (int i = 0, len = userNameArray.length; i < len; i++) {
+                sb.append(userNameArray[i] + ",");
+            }
+            String names = sb.substring(0, sb.length() - 1);
+            if ("add".equals(type)) {
+                content = "添加用户:" + names + " 到用户组" + groupName + "中";
+                result = "添加成功";
+            }else if ("delete".equals(type)){
+                content = "从用户组" + groupName + "删除用户:" + names;
+                result = "删除成功";
+            }
+            messageLog = new MessageLog(username, content,result, null, "用户管理", null);
+            messageLogService.customizeLog(messageLog);
+        }
+    }
 }