WXF преди 3 години
родител
ревизия
26379d9e51

+ 2 - 0
api-common/src/main/java/api/common/pojo/param/system/RoleParam.java

@@ -1,7 +1,9 @@
 package api.common.pojo.param.system;
 
 import api.common.pojo.common.PageVO;
+import lombok.Data;
 
+@Data
 public class RoleParam extends PageVO {
 
     //角色名称

+ 22 - 0
api-common/src/main/java/api/common/pojo/param/system/UserParam.java

@@ -0,0 +1,22 @@
+package api.common.pojo.param.system;
+
+import api.common.pojo.common.PageVO;
+import lombok.Data;
+
+@Data
+public class UserParam extends PageVO {
+
+    //账户名
+    private String username;
+    //昵称
+    private String nickname;
+    //所属公司
+    private String company;
+    //角色编码(账户类型)
+    private String roleCode;
+    //是否启用
+    private String visible;
+    //创建人ID
+    private String createUserId;
+
+}

+ 0 - 38
api-common/src/main/java/api/common/pojo/vo/system/UserInfoVO.java

@@ -1,38 +0,0 @@
-package api.common.pojo.vo.system;
-
-import lombok.Data;
-
-import java.util.List;
-
-@Data
-public class UserInfoVO {
-
-    //主键
-    private String id;
-    //账户名
-    private String username;
-    //昵称
-    private String nickname;
-    //电话
-    private String phone;
-    //公司名称
-    private String company;
-    //岗位
-    private String job;
-    //可用CPU数量
-    private String cpuAvailableNumber;
-    //可用GPU数量
-    private String gpuAvailableNumber;
-    //是否是管理员账户
-    private String isAdmin;
-    //是否是子账户
-    private String isSub;
-    //父账号
-    private String parentId;
-    //是否失效(1失效,0有效)
-    private String isDeactivate;
-
-    //菜单
-    //private List<MenuVO> menus;
-
-}

+ 2 - 2
api-common/src/main/java/api/common/pojo/vo/system/UserVO.java

@@ -12,8 +12,8 @@ public class UserVO {
     private String phone;           // 联系电话
     private String photo;           // 头像
     private String company;         // 所属公司
-    private String role_code;       // 账户角色类型
+    private String roleCode;       // 账户角色类型
     private String visible;         // 是否启用
-    private String openid;          // 众工业平台的 openid
+    //private String openid;          // 众工业平台的 openid
 
 }

+ 5 - 1
simulation-oauth-client/src/main/resources/bootstrap.yaml

@@ -2,4 +2,8 @@ spring:
   application:
     name: simulation-oauth-client
   profiles:
-    active: dev
+    active: dev
+
+mybatis:
+  configuration:
+    map-underscore-to-camel-case: true

+ 1 - 0
simulation-oauth-server/src/main/java/com/css/simulation/oauth/server/mapper/UserMapper.java

@@ -18,6 +18,7 @@ public interface UserMapper {
             " from system_user" +
             " where is_deleted = '0'" +
             " and username = #{username}")
+    @ResultType(UserPO.class)
     UserPO selectByUsername(@Param("username") String username);
 
 

+ 4 - 0
simulation-oauth-server/src/main/resources/bootstrap.yaml

@@ -3,3 +3,7 @@ spring:
     name: simulation-oauth-server
   profiles:
     active: dev
+
+mybatis:
+  configuration:
+    map-underscore-to-camel-case: true

+ 1 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/common/oauth/OauthParameter.java

@@ -13,4 +13,5 @@ public class OauthParameter {
     private String checkTokenEndpointUrl;
     private String clientId;
     private String clientSecret;
+    private String simulationDefaultPassword = "123456";
 }

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

@@ -18,4 +18,15 @@ public class AuthUtil {
         String userId = userDetails.getId();
         return userId;
     }
+
+    /**
+     * 获取当前登录人roleCode
+     */
+    public static String getCurrentUserRoleCode(){
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        MyUserDetails userDetails = (MyUserDetails)authentication.getPrincipal();
+        String roleCode = userDetails.getRoleCode();
+        return roleCode;
+    }
+
 }

+ 52 - 5
simulation-resource-server/src/main/java/com/css/simulation/resource/system/ctrl/UserCtrl.java

@@ -1,10 +1,15 @@
 package com.css.simulation.resource.system.ctrl;
 
 import api.common.pojo.common.ResponseBodyVO;
-import api.common.pojo.vo.system.UserInfoVO;
+import api.common.pojo.param.system.UserParam;
+import api.common.pojo.po.system.UserPO;
+import api.common.pojo.vo.system.UserVO;
+import api.common.util.ObjectUtil;
 import com.css.simulation.resource.system.service.UserService;
+import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
@@ -19,11 +24,53 @@ public class UserCtrl {
     /**
      * 获取当前登录人详情
      */
-    @RequestMapping("/getUserInfo")
+    @RequestMapping("/getCurrentUserInfo")
     @ResponseBody
-    public ResponseBodyVO getUserInfo() {
-        ResponseBodyVO<UserInfoVO> response = new ResponseBodyVO<UserInfoVO>(ResponseBodyVO.Response.SUCCESS);
-        response.setInfo(userService.getUserInfo());
+    public ResponseBodyVO getCurrentUserInfo() {
+        ResponseBodyVO<UserVO> response = new ResponseBodyVO<UserVO>(ResponseBodyVO.Response.SUCCESS);
+        response.setInfo(userService.getCurrentUserInfo());
         return response;
     }
+
+    /**
+     * 获取人员列表
+     */
+    @RequestMapping("/getUserPageList")
+    @ResponseBody
+    public ResponseBodyVO<PageInfo<UserVO>> getUserPageList(@RequestBody UserParam pageParam){
+        ResponseBodyVO<PageInfo<UserVO>> response = new ResponseBodyVO<PageInfo<UserVO>>(ResponseBodyVO.Response.SUCCESS);
+        response.setInfo(userService.getUserPageList(pageParam));
+        return response;
+    }
+
+    /**
+     * 新增、修改
+     */
+    @RequestMapping("/saveUser")
+    @ResponseBody
+    public ResponseBodyVO<UserPO> saveUser(@RequestBody UserPO userPO) throws Exception {
+        if(ObjectUtil.isNull(userPO)){
+            return new ResponseBodyVO(false, 400, "参数必传!",null);
+        }
+        ResponseBodyVO<UserPO> response = new ResponseBodyVO<UserPO>(ResponseBodyVO.Response.SUCCESS);
+        userPO = userService.saveUser(userPO);
+        if(ObjectUtil.isNull(userPO)){
+            return new ResponseBodyVO(false, 400, "没有创建账户的权限!",null);
+        }
+        if(ObjectUtil.isNull(userPO.getId())){
+            return new ResponseBodyVO(false, 400, "账户名重复!",null);
+        }
+        response.setInfo(userPO);
+        return response;
+    }
+
+    /**
+     * 人员密码重置
+     */
+    @RequestMapping("/saveDefaultPassword")
+    @ResponseBody
+    public ResponseBodyVO<PageInfo<UserVO>> saveDefaultPassword(@RequestBody UserPO userPO) throws Exception {
+        userService.saveDefaultPassword(userPO);
+        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
+    }
 }

+ 19 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/system/mapper/UserMapper.java

@@ -1,17 +1,33 @@
 package com.css.simulation.resource.system.mapper;
 
-import api.common.pojo.vo.system.UserInfoVO;
+import api.common.pojo.param.system.UserParam;
+import api.common.pojo.po.system.UserPO;
+import api.common.pojo.vo.system.UserVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 @Mapper
 @Repository
 public interface UserMapper {
 
-    UserInfoVO getUserInfo(@Param("userId") String userId);
-
+    UserVO getUserInfo(@Param("userId") String userId);
 
     Integer selectCount();
 
+    List<UserVO> getUserPageLista(UserParam pageParam);
+
+    List<UserVO> getUserPageListb(UserParam pageParam);
+
+    List<UserVO> getUserPageListc(UserParam pageParam);
+
+    List<UserPO> checkUsername(UserPO userPO);
+
+    void insert(UserPO userPO);
+
+    void update(UserPO userPO);
+
+    void saveDefaultPassword(UserPO userPO);
 }

+ 82 - 4
simulation-resource-server/src/main/java/com/css/simulation/resource/system/service/UserService.java

@@ -1,11 +1,24 @@
 package com.css.simulation.resource.system.service;
 
-import api.common.pojo.vo.system.UserInfoVO;
+import api.common.pojo.constants.DictConstants;
+import api.common.pojo.param.system.UserParam;
+import api.common.pojo.po.system.UserPO;
+import api.common.pojo.vo.system.UserVO;
+import api.common.util.EncryptUtil;
+import api.common.util.ObjectUtil;
+import api.common.util.StringUtil;
+import com.css.simulation.resource.common.oauth.OauthParameter;
 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.system.mapper.UserMapper;
+import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.security.NoSuchAlgorithmException;
+import java.util.List;
+
 
 @Service
 public class UserService {
@@ -13,10 +26,75 @@ public class UserService {
     @Autowired
     UserMapper userMapper;
 
+    @Autowired
+    OauthParameter oauthParameter;
+
 
-    public UserInfoVO getUserInfo() {
+    public UserVO getCurrentUserInfo() {
         String userId = AuthUtil.getCurrentUserId();
-        UserInfoVO userInfoVO = userMapper.getUserInfo(userId);
-        return userInfoVO;
+        UserVO userVO = userMapper.getUserInfo(userId);
+        return userVO;
+    }
+
+    public PageInfo<UserVO> getUserPageList(UserParam pageParam) {
+        PageUtil.setPageInfo(pageParam);
+        List<UserVO> list = null;
+        String currentUserRoleCode = AuthUtil.getCurrentUserRoleCode();
+        if(DictConstants.ROLE_CODE_SYSADMIN.equals(currentUserRoleCode)){//超级管理员
+            list = userMapper.getUserPageLista(pageParam);
+        }else if(DictConstants.ROLE_CODE_ADMIN.equals(currentUserRoleCode)){//子管理员
+            list = userMapper.getUserPageListb(pageParam);
+        }else if(DictConstants.ROLE_CODE_UESR.equals(currentUserRoleCode)){//普通用户
+            //只查询自己创建的子账户
+            pageParam.setCreateUserId(AuthUtil.getCurrentUserId());
+            list = userMapper.getUserPageListc(pageParam);
+        }else{
+            return null;
+        }
+        return new PageInfo<>(list);
+    }
+
+    public UserPO saveUser(UserPO userPO) throws NoSuchAlgorithmException {
+        //权限校验
+        String currentUserRoleCode = AuthUtil.getCurrentUserRoleCode();
+        if(DictConstants.ROLE_CODE_SYSADMIN.equals(currentUserRoleCode)){//超级管理员
+            if(DictConstants.ROLE_CODE_ADMIN.equals(userPO.getRoleCode())){
+                userPO.setRoleCode(DictConstants.ROLE_CODE_ADMIN);
+            }else{
+                userPO.setRoleCode(DictConstants.ROLE_CODE_UESR);
+            }
+        }else if(DictConstants.ROLE_CODE_ADMIN.equals(currentUserRoleCode)){//子管理员
+            userPO.setRoleCode(DictConstants.ROLE_CODE_UESR);
+        }else if(DictConstants.ROLE_CODE_UESR.equals(currentUserRoleCode)){//普通用户
+            userPO.setRoleCode(DictConstants.ROLE_CODE_SUBUESR);
+        }else{
+            return null;
+        }
+        //重名校验
+        List<UserPO> list = userMapper.checkUsername(userPO);
+        if(ObjectUtil.isNotNull(list)){
+            userPO.setId(null);
+            return userPO;
+        }
+        PoUtil.initAddPo(userPO);
+        String id = userPO.getId();
+        if(ObjectUtil.isNull(id)){//新增
+            userPO.setId(StringUtil.getRandomUUID());
+            //初始密码
+            userPO.setPassword(EncryptUtil.getLowerMD5(oauthParameter.getSimulationDefaultPassword()));
+            userPO.setVisible("1");
+            userMapper.insert(userPO);
+        }else{
+            userMapper.update(userPO);
+        }
+        //密码清空
+        userPO.setPassword(null);
+        return userPO;
+    }
+
+    public void saveDefaultPassword(UserPO userPO) throws NoSuchAlgorithmException {
+        userPO.setPassword(EncryptUtil.getLowerMD5(oauthParameter.getSimulationDefaultPassword()));
+        PoUtil.initUpdatePo(userPO);
+        userMapper.saveDefaultPassword(userPO);
     }
 }

+ 3 - 3
simulation-resource-server/src/main/resources/mapper/system/RoleMapper.xml

@@ -13,13 +13,13 @@
         FROM system_role
         WHERE is_deleted = '0'
         <if test="roleName != null and roleName != ''">
-            and c.role_name like CONCAT('%',#{roleName,jdbcType=VARCHAR},'%')
+            and role_name like CONCAT('%',#{roleName,jdbcType=VARCHAR},'%')
         </if>
         <if test="roleCode != null and roleCode != ''">
-            and c.role_code like CONCAT('%',#{roleCode,jdbcType=VARCHAR},'%')
+            and role_code like CONCAT('%',#{roleCode,jdbcType=VARCHAR},'%')
         </if>
         <if test="visible != null and visible != ''">
-            and c.visible = #{roleName,jdbcType=VARCHAR}
+            and visible = #{visible,jdbcType=VARCHAR}
         </if>
         ORDER BY sort
     </select>

+ 134 - 9
simulation-resource-server/src/main/resources/mapper/system/UserMapper.xml

@@ -3,22 +3,147 @@
 <mapper namespace="com.css.simulation.resource.system.mapper.UserMapper" >
 
 
-    <select id="getUserInfo" parameterType="java.lang.String" resultType="api.common.pojo.vo.system.UserInfoVO">
+    <select id="getUserInfo" parameterType="java.lang.String" resultType="api.common.pojo.vo.system.UserVO">
         SELECT
-            id,username,nickname,
+            id,
+            username,
+            nickname,
+            photo,
             phone,
             company,
-            job,
-            cpu_available_number,
-            gpu_available_number,
-            is_admin,
-            is_sub,
-            parent_id,
-            is_deactivate
+            role_code
         FROM system_user WHERE id = #{userId,jdbcType=VARCHAR}
     </select>
+
+    <!-- 列表查询共用字段-->
+    <sql id="pageColumn">
+        id,
+        username,
+        nickname,
+        photo,
+        phone,
+        company,
+        role_code,
+        visible
+    </sql>
+    <!-- 列表查询共用查询条件-->
+    <sql id="pageWhere">
+        <if test="username != null and username != ''">
+            and username like CONCAT('%',#{username,jdbcType=VARCHAR},'%')
+        </if>
+        <if test="nickname != null and nickname != ''">
+            and nickname like CONCAT('%',#{nickname,jdbcType=VARCHAR},'%')
+        </if>
+        <if test="company != null and company != ''">
+            and company like CONCAT('%',#{company,jdbcType=VARCHAR},'%')
+        </if>
+        <if test="roleCode != null and roleCode != ''">
+            and role_code = #{roleCode,jdbcType=VARCHAR}
+        </if>
+        <if test="visible != null and visible != ''">
+            and visible = #{visible,jdbcType=VARCHAR}
+        </if>
+    </sql>
+
+    <select id="getUserPageLista" parameterType="api.common.pojo.param.system.UserParam" resultType="api.common.pojo.vo.system.UserVO">
+        SELECT
+           <include refid="pageColumn"></include>
+        FROM system_user
+        WHERE is_deleted = '0' AND role_code &lt;&gt; '0'
+          <include refid="pageWhere"></include>
+        ORDER BY modify_time DESC
+    </select>
+
+    <select id="getUserPageListb" parameterType="api.common.pojo.param.system.UserParam" resultType="api.common.pojo.vo.system.UserVO">
+        SELECT
+        <include refid="pageColumn"></include>
+        FROM system_user
+        WHERE is_deleted = '0' AND role_code &lt;&gt; '0' and role_code &lt;&gt; '1'
+        <include refid="pageWhere"></include>
+        ORDER BY modify_time DESC
+    </select>
+
+    <select id="getUserPageListc" parameterType="api.common.pojo.param.system.UserParam" resultType="api.common.pojo.vo.system.UserVO">
+        SELECT
+        <include refid="pageColumn"></include>
+        FROM system_user
+        WHERE is_deleted = '0' AND role_code = '3'
+        <include refid="pageWhere"></include>
+        and create_user_id = #{createUserId,jdbcType=VARCHAR}
+        ORDER BY modify_time DESC
+    </select>
+
     <select id="selectCount" resultType="java.lang.Integer">
         select count(*)
         from system_user
     </select>
+
+    <select id="checkUsername" parameterType="api.common.pojo.po.system.UserPO" resultType="api.common.pojo.po.system.UserPO">
+        select
+          id
+        from system_user
+        where is_deleted = '0'
+        and username = #{username,jdbcType=VARCHAR}
+        <if test="id != null and id != ''">
+            and id &lt;&gt; #{id,jdbcType=VARCHAR}
+        </if>
+    </select>
+
+    <insert id="insert" parameterType="api.common.pojo.po.system.UserPO">
+        INSERT INTO system_user(
+            id,
+            username,
+            password,
+            nickname,
+            photo,
+            phone,
+            company,
+            role_code,
+            visible,
+            create_time,
+            modify_time,
+            create_user_id,
+            modify_user_id,
+            is_deleted
+        )
+        VALUES(
+            #{id,jdbcType=VARCHAR},
+            #{username,jdbcType=VARCHAR},
+            #{password,jdbcType=VARCHAR},
+            #{nickname,jdbcType=VARCHAR},
+            #{photo,jdbcType=VARCHAR},
+            #{phone,jdbcType=VARCHAR},
+            #{company,jdbcType=VARCHAR},
+            #{roleCode,jdbcType=VARCHAR},
+            #{visible,jdbcType=VARCHAR},
+            #{createTime,jdbcType=TIMESTAMP},
+            #{modifyTime,jdbcType=TIMESTAMP},
+            #{createUserId,jdbcType=VARCHAR},
+            #{modifyUserId,jdbcType=VARCHAR},
+            #{isDeleted,jdbcType=VARCHAR}
+        )
+    </insert>
+
+    <update id="update" parameterType="api.common.pojo.po.system.UserPO">
+        update system_user set
+            username = #{username,jdbcType=VARCHAR},
+            nickname = #{nickname,jdbcType=VARCHAR},
+            photo = #{photo,jdbcType=VARCHAR},
+            phone = #{phone,jdbcType=VARCHAR},
+            company = #{company,jdbcType=VARCHAR},
+            visible = #{visible,jdbcType=VARCHAR},
+
+            modify_time = #{modifyTime,jdbcType=TIMESTAMP},
+            modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
+        where id = #{id,jdbcType=VARCHAR}
+    </update>
+
+    <update id="saveDefaultPassword" parameterType="api.common.pojo.po.system.UserPO">
+        update system_user set
+            password = #{password,jdbcType=VARCHAR},
+            modify_time = #{modifyTime,jdbcType=TIMESTAMP},
+            modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
+        where id = #{id,jdbcType=VARCHAR}
+    </update>
+
 </mapper>