ソースを参照

集群管理、参数管理加日志;新增增加user_id查询仿真软件license数量接口

zhaoyan 3 年 前
コミット
d669874301

+ 3 - 0
api-common/src/main/java/api/common/pojo/constants/DictConstants.java

@@ -100,5 +100,8 @@ public class DictConstants {
     public static final String TASK_ERROR_REASON_4 = "未知状态!";
     public static final String TASK_ERROR_REASON_5 = "打分出错!";
 
+    public static final String USE_TYPE_EXCLUSIVE = "1";//独占使用
+    public static final String USE_TYPE_PUBLIC = "2";//公共使用
+
 
 }

+ 4 - 0
api-common/src/main/java/api/common/pojo/constants/LogConstants.java

@@ -28,7 +28,11 @@ public class LogConstants {
     public static final String SYS_LOG_USER_START = "0104";//用户管理-启用
     public static final String SYS_LOG_USER_STOP = "0105";//用户管理-停用
     public static final String SYS_LOG_PARAM = "02";//参数管理
+    public static final String SYS_LOG_PARAM_INSERT = "0201";//参数管理-编辑即新增
+    public static final String SYS_LOG_PARAM_DELETE = "0202";//集群管理-删除
     public static final String SYS_LOG_CLUSTER = "03";//集群管理
+    public static final String SYS_LOG_CLUSTER_INSERT = "0301";//集群管理-编辑即新增
+    public static final String SYS_LOG_CLUSTER_DELETE = "0302";//集群管理-删除
     public static final String SYS_LOG_VEHICLE = "04";//车辆模板管理
     public static final String SYS_LOG_VEHICLE_INSERT = "0401";//车辆模板管理-新增
     public static final String SYS_LOG_VEHICLE_UPDATE = "0402";//车辆模板管理-修改

+ 1 - 0
api-common/src/main/java/api/common/pojo/po/system/ClusterPO.java

@@ -10,6 +10,7 @@ public class ClusterPO extends CommonPO {
 
     private String id;              // 用户主键(唯一)
     private String userId;        // 账户id
+    private String userName;      //账户名称
     private int numSimulationLicense;        // 仿真软件license数量
     private Date dateSimulationLicense;       // 仿真软件license到期时间
     private int numDynamicLicense;        // 动力学软件license数量

+ 1 - 0
api-common/src/main/java/api/common/pojo/po/system/ParameterPO.java

@@ -8,6 +8,7 @@ public class ParameterPO extends CommonPO {
 
     private String id;              // 用户主键(唯一)
     private String userId;        // 账户id
+    private String userName;      //账户名称
     private int numCreateUser;        // 可创建子账户数量
     private int numCreateScenePackage;           // 最多可创建场景测试包数量
     private int numScenePerPackage;           // 场景测试包最大场景数量

+ 1 - 1
api-common/src/main/java/api/common/pojo/vo/system/ClusterVO.java

@@ -9,7 +9,7 @@ public class ClusterVO {
 
     private String id;              // 用户主键(唯一)
     private String userName;        // 账户名称
-    private String userType;        // 占用类型
+    private String useType;        // 占用类型
     private String userId;        // 账户id
     private int numSimulationLicense;        // 仿真软件license数量
     private Date dateSimulationLicense;       // 仿真软件license到期时间

+ 10 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/common/utils/AuthUtil.java

@@ -49,4 +49,14 @@ public class AuthUtil {
         return username;
     }
 
+    /**
+     * 获取当前登录人createUserId
+     */
+    public static String getCreateUserId(){
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        MyUserDetails userDetails = (MyUserDetails)authentication.getPrincipal();
+        String createUserId = userDetails.getCreateUserId();
+        return createUserId;
+    }
+
 }

+ 37 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/log/service/LogService.java

@@ -6,6 +6,8 @@ import api.common.pojo.po.log.LogLoginPO;
 import api.common.pojo.po.log.LogOperationPO;
 import api.common.pojo.po.log.LogSystemPO;
 import api.common.pojo.po.model.VehicleTempPO;
+import api.common.pojo.po.system.ClusterPO;
+import api.common.pojo.po.system.ParameterPO;
 import api.common.pojo.po.system.UserPO;
 import api.common.util.ObjectUtil;
 import api.common.util.StringUtil;
@@ -116,6 +118,41 @@ public class LogService {
         }
     }
 
+    /**
+     * 记录参数管理模块日志
+     */
+    public void logParameter(String operationType, ParameterPO parameterPO) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_PARAM, operationType);
+            String paramId = parameterPO.getId();
+            String userId = parameterPO.getUserId();
+            String userName = parameterPO.getUserName();
+            String content = "账户:" + userName +  " ( ID: " + userId + " ); 参数配置" +  " ( ID: " + paramId + " )";
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 记录集群管理模块日志
+     */
+    public void logCluster(String operationType, ClusterPO clusterPO) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_CLUSTER, operationType);
+            String clusterId = clusterPO.getId();
+            String userId = clusterPO.getUserId();
+            String userName = clusterPO.getUserName();
+            String content = "账户:" + userName +  " ( ID: " + userId + " ); 节点配置" +  " ( ID: " + clusterId + " )";
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+
 
 
 

+ 15 - 54
simulation-resource-server/src/main/java/com/css/simulation/resource/system/ctrl/ClusterCtrl.java

@@ -1,12 +1,10 @@
 package com.css.simulation.resource.system.ctrl;
 
 import api.common.pojo.common.ResponseBodyVO;
-import api.common.pojo.constants.DictConstants;
 import api.common.pojo.param.system.ClusterParam;
 import api.common.pojo.po.system.ClusterPO;
 import api.common.pojo.vo.system.ClusterVO;
 import api.common.util.ObjectUtil;
-import com.css.simulation.resource.common.utils.AuthUtil;
 import com.css.simulation.resource.system.service.ClusterService;
 import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,30 +30,6 @@ public class ClusterCtrl {
     @RequestMapping("/getClusterList")
     @ResponseBody
     public ResponseBodyVO<PageInfo<ClusterVO>> getClusterList(@RequestBody ClusterParam clusterParam){
-
-        String roleCode = AuthUtil.getCurrentUserRoleCode();
-        if(roleCode == null){
-            return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE);
-        }
-        //当前账户为普通账户子账户,列表显示空
-        if(DictConstants.ROLE_CODE_SUBUESR.equals(roleCode)){
-            clusterParam.setRoleCode("-1");//查不到
-        }
-        //当前账户为管理员账户,需要查询普通账户,设置roleCode为2
-        if(DictConstants.ROLE_CODE_ADMIN.equals(roleCode) || DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)){
-            clusterParam.setRoleCode(DictConstants.ROLE_CODE_UESR);
-        }
-        // 当前账户为普通账户,需要查询该账户创建的普通账户子账户,设置roleCode为3及当前创建用户id
-        if(DictConstants.ROLE_CODE_UESR.equals(roleCode)){
-            String useType = AuthUtil.getCurrentUseType();
-            if("1".equals(useType)){//独占
-                clusterParam.setRoleCode(DictConstants.ROLE_CODE_SUBUESR);
-                clusterParam.setCreateUserId(AuthUtil.getCurrentUserId());
-            }else {
-                clusterParam.setRoleCode("-1"); //查不到
-            }
-
-        }
         ResponseBodyVO<PageInfo<ClusterVO>> response = new ResponseBodyVO<PageInfo<ClusterVO>>(ResponseBodyVO.Response.SUCCESS);
         response.setInfo(clusterService.getClusterList(clusterParam));
         return response;
@@ -66,7 +40,7 @@ public class ClusterCtrl {
      */
     @RequestMapping("/saveCluster")
     @ResponseBody
-    public ResponseBodyVO<ClusterPO> saveCluster(@RequestBody ClusterPO clusterPO) throws Exception {
+    public ResponseBodyVO<ClusterPO> saveCluster(@RequestBody ClusterPO clusterPO) {
         if(ObjectUtil.isNull(clusterPO)){
             return new ResponseBodyVO(false, 400, "参数必传!",null);
         }
@@ -82,7 +56,6 @@ public class ClusterCtrl {
     @RequestMapping("/getClusterHistory")
     @ResponseBody
     public ResponseBodyVO<PageInfo<ClusterVO>> getClusterHistory(@RequestBody ClusterParam clusterParam){
-
         ResponseBodyVO<PageInfo<ClusterVO>> response = new ResponseBodyVO<PageInfo<ClusterVO>>(ResponseBodyVO.Response.SUCCESS);
         response.setInfo(clusterService.getClusterHistory(clusterParam));
         return response;
@@ -93,35 +66,23 @@ public class ClusterCtrl {
      */
     @RequestMapping("/getClusterNum")
     @ResponseBody
-    public ResponseBodyVO<HashMap<String, Integer>> getClusterNum() throws Exception {
-
-        ClusterParam clusterParam = new ClusterParam();
+    public ResponseBodyVO<HashMap<String, Integer>> getClusterNum() {
         ResponseBodyVO<HashMap<String, Integer>> response = new ResponseBodyVO<HashMap<String, Integer>>(ResponseBodyVO.Response.SUCCESS);
-        String roleCode = AuthUtil.getCurrentUserRoleCode();
-        if(roleCode == null){
-            return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE);
-        }
-        if(DictConstants.ROLE_CODE_SUBUESR.equals(roleCode)){
-            response.setInfo(null);
-        }
-        //当前账户为管理员账户,需要查询普通账户,设置roleCode为2
-        if(DictConstants.ROLE_CODE_ADMIN.equals(roleCode) || DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)){
-            clusterParam.setRoleCode(DictConstants.ROLE_CODE_UESR);
-        }
-        // 当前账户为普通账户,需要查询该账户创建的普通账户子账户,设置roleCode为3及当前创建用户id
-        if(DictConstants.ROLE_CODE_UESR.equals(roleCode)){
-            String useType = AuthUtil.getCurrentUseType();
-            if("1".equals(useType)){//独占
-                clusterParam.setRoleCode(DictConstants.ROLE_CODE_SUBUESR);
-                clusterParam.setCreateUserId(AuthUtil.getCurrentUserId());
-            }else {
-                response.setInfo(null);
-            }
-
-        }
-        HashMap<String, Integer> resMap = clusterService.getClusterNum(clusterParam);
+        HashMap<String, Integer> resMap = clusterService.getClusterNum();
         response.setInfo(resMap);
         return response;
     }
 
+    /**
+     * 查询已分配未到期节点数量
+     */
+    @RequestMapping("/getLicenseNum")
+    @ResponseBody
+    public ResponseBodyVO<Integer> getLicenseNum() {
+        ResponseBodyVO<Integer> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
+        Integer simulationLicenseNum = clusterService.getLicenseNum();
+        response.setInfo(simulationLicenseNum);
+        return response;
+    }
+
 }

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/system/ctrl/ParameterCtrl.java

@@ -38,7 +38,7 @@ public class ParameterCtrl {
      */
     @RequestMapping("/saveParameter")
     @ResponseBody
-    public ResponseBodyVO<ParameterPO> saveParameter(@RequestBody ParameterPO parameterPO) throws Exception {
+    public ResponseBodyVO<ParameterPO> saveParameter(@RequestBody ParameterPO parameterPO) {
         if(ObjectUtil.isNull(parameterPO)){
             return new ResponseBodyVO(false, 400, "参数必传!",null);
         }

+ 1 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/system/mapper/ClusterMapper.java

@@ -24,4 +24,5 @@ public interface ClusterMapper {
 
     HashMap<String, Integer> getClusterNum(ClusterParam clusterParam);
 
+    Integer getLicenseNum(String userId);
 }

+ 58 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/system/service/ClusterService.java

@@ -1,19 +1,25 @@
 package com.css.simulation.resource.system.service;
 
+import api.common.pojo.constants.DictConstants;
+import api.common.pojo.constants.LogConstants;
 import api.common.pojo.param.system.ClusterParam;
 import api.common.pojo.po.system.ClusterPO;
 import api.common.pojo.vo.system.ClusterVO;
 import api.common.util.ObjectUtil;
 import api.common.util.StringUtil;
+import com.css.simulation.resource.common.utils.AuthUtil;
 import com.css.simulation.resource.common.utils.PageUtil;
 import com.css.simulation.resource.common.utils.PoUtil;
+import com.css.simulation.resource.log.service.LogService;
 import com.css.simulation.resource.system.mapper.ClusterMapper;
 import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 
 @Service
@@ -22,10 +28,31 @@ public class ClusterService {
     @Autowired
     ClusterMapper clusterMapper;
 
+    @Autowired
+    LogService logService;
+
+    @Autowired
+    DictService dictService;
+
 
     public PageInfo<ClusterVO> getClusterList(ClusterParam clusterParam) {
         PageUtil.setPageInfo(clusterParam);
+        String roleCode = AuthUtil.getCurrentUserRoleCode();
+        String useType = AuthUtil.getCurrentUseType();
+        //当前账户为管理员账户,需要查询普通账户,设置roleCode为2
+        if(DictConstants.ROLE_CODE_ADMIN.equals(roleCode) || DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)){
+            clusterParam.setRoleCode(DictConstants.ROLE_CODE_UESR);
+        }else if(DictConstants.ROLE_CODE_UESR.equals(roleCode) && DictConstants.USE_TYPE_EXCLUSIVE.equals(useType)){
+            // 当前账户为独占使用的普通账户,需要查询该账户创建的普通账户子账户,设置roleCode为3及当前创建用户id
+            clusterParam.setRoleCode(DictConstants.ROLE_CODE_SUBUESR);
+        }else{
+            return new PageInfo<>(new ArrayList<>());
+        }
         List<ClusterVO> list = clusterMapper.getClusterList(clusterParam);
+        for (ClusterVO vo:list){
+            Map<String, String> dictMapByType = dictService.getDictMapByType(DictConstants.USE_TYPE);
+            vo.setUseType(dictMapByType.get(vo.getUseType()));
+        }
         return new PageInfo<>(list);
     }
 
@@ -42,6 +69,7 @@ public class ClusterService {
         clusterPO.setId(StringUtil.getRandomUUID());
         PoUtil.initAddPo(clusterPO);
         clusterMapper.insert(clusterPO);
+        logService.logCluster(LogConstants.SYS_LOG_CLUSTER_INSERT, clusterPO);
         return clusterPO;
     }
 
@@ -53,9 +81,38 @@ public class ClusterService {
     }
 
 
-    public HashMap<String, Integer> getClusterNum(ClusterParam clusterParam) {
+    public HashMap<String, Integer> getClusterNum() {
+
+        ClusterParam clusterParam = new ClusterParam();
+        String roleCode = AuthUtil.getCurrentUserRoleCode();
+        String useType = AuthUtil.getCurrentUseType();
+        //当前账户为管理员账户,需要查询普通账户,设置roleCode为2
+        if(DictConstants.ROLE_CODE_ADMIN.equals(roleCode) || DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)){
+            clusterParam.setRoleCode(DictConstants.ROLE_CODE_UESR);
+        }else if(DictConstants.ROLE_CODE_UESR.equals(roleCode) && DictConstants.USE_TYPE_EXCLUSIVE.equals(useType)){
+            // 当前账户为独占使用的普通账户,需要查询该账户创建的普通账户子账户,设置roleCode为3及当前创建用户id
+            clusterParam.setRoleCode(DictConstants.ROLE_CODE_SUBUESR);
+        }else{
+            return null;
+        }
 
         HashMap<String, Integer> resMap = clusterMapper.getClusterNum(clusterParam);
         return resMap;
     }
+
+
+    public Integer getLicenseNum(){
+        String roleCode = AuthUtil.getCurrentUserRoleCode();
+        String useType = AuthUtil.getCurrentUseType();
+        String userId = AuthUtil.getCurrentUserId();
+        if(DictConstants.ROLE_CODE_ADMIN.equals(roleCode) || DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)){ //管理员账户
+            return -1;
+        }else if(DictConstants.ROLE_CODE_SUBUESR.equals(roleCode) && DictConstants.USE_TYPE_PUBLIC.equals(useType)){
+            //查询父账户
+            userId = AuthUtil.getCreateUserId();
+        }
+        Integer simulationLicenseNum = clusterMapper.getLicenseNum(userId);
+
+        return simulationLicenseNum;
+    }
 }

+ 6 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/system/service/ParameterService.java

@@ -1,5 +1,6 @@
 package com.css.simulation.resource.system.service;
 
+import api.common.pojo.constants.LogConstants;
 import api.common.pojo.param.system.ParameterParam;
 import api.common.pojo.po.system.ParameterPO;
 import api.common.pojo.vo.system.ParameterVO;
@@ -7,6 +8,7 @@ import api.common.util.ObjectUtil;
 import api.common.util.StringUtil;
 import com.css.simulation.resource.common.utils.PageUtil;
 import com.css.simulation.resource.common.utils.PoUtil;
+import com.css.simulation.resource.log.service.LogService;
 import com.css.simulation.resource.system.mapper.ParameterMapper;
 import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,6 +23,9 @@ public class ParameterService {
     @Autowired
     ParameterMapper parameterMapper;
 
+    @Autowired
+    LogService logService;
+
 
     public PageInfo<ParameterVO> getParameterList(ParameterParam pageParam) {
         PageUtil.setPageInfo(pageParam);
@@ -28,7 +33,6 @@ public class ParameterService {
         return new PageInfo<>(list);
     }
 
-
     public ParameterPO saveParameter(ParameterPO paramPO) {
         String id = paramPO.getId();
         if(ObjectUtil.isNotNull(id)){
@@ -42,6 +46,7 @@ public class ParameterService {
         paramPO.setId(StringUtil.getRandomUUID());
         PoUtil.initAddPo(paramPO);
         parameterMapper.insert(paramPO);
+        logService.logParameter(LogConstants.SYS_LOG_PARAM_INSERT, paramPO);
         return paramPO;
     }
 

+ 30 - 26
simulation-resource-server/src/main/resources/mapper/system/ClusterMapper.xml

@@ -17,29 +17,28 @@
         p.modify_time
         from system_user u
         left join system_cluster p on u.id = p.user_id
-        <where>
-            u.is_deleted = '0' and u.visible = '1' and p.is_deleted = '0'
+        where
+            u.is_deleted = '0' and u.visible = '1' and IFNULL(p.is_deleted,'0') = '0'
             and u.role_code = #{roleCode,jdbcType=VARCHAR}
-        </where>
-        <if test="createUserId != null and createUserId != ''">
-            and u.create_user_id = #{createUserId,jdbcType=VARCHAR}
-        </if>
-        <if test="userName != null and userName != ''">
-            and u.username like CONCAT('%',#{userName,jdbcType=VARCHAR},'%')
-        </if>
-        <if test="modifyTimeStart != null and modifyTimeStart != ''">
-            and p.modify_time &gt;= #{modifyTimeStart}
-        </if>
-        <if test="modifyTimeEnd != null and modifyTimeEnd != ''">
-            and p.modify_time &lt;= #{modifyTimeEnd}
-        </if>
-        <if test="dueTimeStart != null and dueTimeStart != ''">
-            and (p.date_simulation_license &gt;= #{dueTimeStart} or p.date_dynamic_license &gt;= #{dueTimeStart})
-        </if>
-        <if test="dueTimeEnd != null and dueTimeEnd != ''">
-            and (p.date_simulation_license &lt;= #{dueTimeEnd} or p.date_dynamic_license &lt;= #{dueTimeEnd})
-        </if>
-        order by modify_time desc
+            <if test="createUserId != null and createUserId != ''">
+                and u.create_user_id = #{createUserId,jdbcType=VARCHAR}
+            </if>
+            <if test="userName != null and userName != ''">
+                and u.username like CONCAT('%',#{userName,jdbcType=VARCHAR},'%')
+            </if>
+            <if test="modifyTimeStart != null and modifyTimeStart != ''">
+                and p.modify_time &gt;= #{modifyTimeStart}
+            </if>
+            <if test="modifyTimeEnd != null and modifyTimeEnd != ''">
+                and p.modify_time &lt;= #{modifyTimeEnd}
+            </if>
+            <if test="dueTimeStart != null and dueTimeStart != ''">
+                and (p.date_simulation_license &gt;= #{dueTimeStart} or p.date_dynamic_license &gt;= #{dueTimeStart})
+            </if>
+            <if test="dueTimeEnd != null and dueTimeEnd != ''">
+                and (p.date_simulation_license &lt;= #{dueTimeEnd} or p.date_dynamic_license &lt;= #{dueTimeEnd})
+            </if>
+        order by p.modify_time desc
     </select>
 
 
@@ -110,8 +109,8 @@
         from system_user u
         left join system_cluster p on u.id = p.user_id
         <where>
-            u.is_deleted = '0' and u.visible = '1'
-            and p.date_simulation_license >= NOW()
+            u.is_deleted = '0' and u.visible = '1' and p.is_deleted = '0'
+            and DATE(p.date_simulation_license) >= DATE(NOW())
             and u.role_code = #{roleCode,jdbcType=VARCHAR}
         </where>
         <if test="createUserId != null and createUserId != ''">
@@ -123,8 +122,8 @@
         from system_user u
         left join system_cluster p on u.id = p.user_id
         <where>
-            u.is_deleted = '0' and u.visible = '1'
-            and p.date_dynamic_license >= NOW()
+            u.is_deleted = '0' and u.visible = '1'  and p.is_deleted = '0'
+            and DATE(p.date_dynamic_license) >= DATE(NOW())
             and u.role_code = #{roleCode,jdbcType=VARCHAR}
         </where>
         <if test="createUserId != null and createUserId != ''">
@@ -132,4 +131,9 @@
         </if>
         ) as totalDynamic
     </select>
+
+    <select id="getLicenseNum" parameterType="java.lang.String" resultType="java.lang.Integer">
+        select num_simulation_license from system_cluster
+        where is_deleted = '0' and DATE(date_simulation_license) >= DATE(NOW()) and create_user_id = #{createUserId,jdbcType=VARCHAR}
+    </select>
 </mapper>

+ 6 - 7
simulation-resource-server/src/main/resources/mapper/system/ParameterMapper.xml

@@ -15,14 +15,13 @@
         p.modify_time
         from system_user u
         left join system_parameter p on u.id = p.user_id
-        <where>
+        where
             u.is_deleted = '0' and u.visible = '1' and u.role_code = '2'
-            and p.is_deleted = '0'
-        </where>
-        <if test="userName != null and userName != ''">
-            and u.username like CONCAT('%',#{userName,jdbcType=VARCHAR},'%')
-        </if>
-        order by modify_time desc
+            and IFNULL(p.is_deleted,'0') = '0'
+            <if test="userName != null and userName != ''">
+                and u.username like CONCAT('%',#{userName,jdbcType=VARCHAR},'%')
+            </if>
+        order by p.modify_time desc
     </select>