ソースを参照

账户2.0——导入账户初版

zhaoxian 3 年 前
コミット
ff15fcc285
16 ファイル変更460 行追加270 行削除
  1. 15 4
      ruixuan-live/src/main/java/com/ruixuan/live/controller/KuaishouLiveUserAccountController.java
  2. 7 8
      ruixuan-live/src/main/java/com/ruixuan/live/entity/KuaishouLiveUserAccount.java
  3. 8 0
      ruixuan-live/src/main/java/com/ruixuan/live/mapper/KuaishouLiveUserAccountMapper.java
  4. 4 1
      ruixuan-live/src/main/java/com/ruixuan/live/service/IKuaishouLiveUserAccountService.java
  5. 43 8
      ruixuan-live/src/main/java/com/ruixuan/live/service/impl/KuaishouLiveUserAccountServiceImpl.java
  6. 119 2
      ruixuan-live/src/main/resources/mapper/live/KuaishouLiveUserAccountMapper.xml
  7. 2 0
      ruixuan-live/src/main/resources/mapper/live/KuaishouLiveUserAccountPartMapper.xml
  8. 2 0
      ruixuan-system/src/main/java/com/ruixuan/system/mapper/SysRoleMapper.java
  9. 7 0
      ruixuan-system/src/main/java/com/ruixuan/system/mapper/SysUserMapper.java
  10. 2 0
      ruixuan-system/src/main/java/com/ruixuan/system/mapper/SysUserRoleMapper.java
  11. 2 0
      ruixuan-system/src/main/java/com/ruixuan/system/service/ISysRoleService.java
  12. 7 0
      ruixuan-system/src/main/java/com/ruixuan/system/service/ISysUserService.java
  13. 70 104
      ruixuan-system/src/main/java/com/ruixuan/system/service/impl/SysRoleServiceImpl.java
  14. 5 0
      ruixuan-system/src/main/java/com/ruixuan/system/service/impl/SysUserServiceImpl.java
  15. 162 143
      ruixuan-system/src/main/resources/mapper/system/SysRoleMapper.xml
  16. 5 0
      ruixuan-system/src/main/resources/mapper/system/SysUserMapper.xml

+ 15 - 4
ruixuan-live/src/main/java/com/ruixuan/live/controller/KuaishouLiveUserAccountController.java

@@ -44,13 +44,22 @@ public class KuaishouLiveUserAccountController extends BaseController {
      * 查询快手直播账户列表
      */
     @GetMapping("/list")
-    @ApiOperation(value = "查询快手直播账户列表")
+    @ApiOperation(value = "操盘手——查询快手直播账户列表")
     public TableDataInfo list(KuaishouLiveUserAccount kuaishouLiveUserAccount) {
-        startPage();
         List<KuaishouLiveUserAccount> list = kuaishouLiveUserAccountService.selectKuaishouLiveUserAccountList(kuaishouLiveUserAccount);
         return getDataTable(list);
     }
 
+     /**
+     * 查询快手直播账户列表
+     */
+    @GetMapping("/queryAllList")
+    @ApiOperation(value = "账户管理——查询快手直播账户列表")
+    public TableDataInfo queryAllList(KuaishouLiveUserAccount kuaishouLiveUserAccount) {
+        List<KuaishouLiveUserAccount> list = kuaishouLiveUserAccountService.queryAllList(kuaishouLiveUserAccount);
+        return getDataTable(list);
+    }
+
     /**
      * 查询快手昵称
      */
@@ -96,8 +105,10 @@ public class KuaishouLiveUserAccountController extends BaseController {
      */
     @PostMapping(value = "/insertByExcel")
     @ApiOperation(value = "通过excel导入账户")
-    public ResultResponse insertByExcel(@ApiParam("excel文档") @RequestParam(value = "file", required = false) MultipartFile file) {
-        return kuaishouLiveUserAccountService.insertByExcel(file);
+    public ResultResponse insertByExcel(@ApiParam("excel文档") @RequestParam(value = "file", required = false) MultipartFile file,
+                                        @ApiParam("创建人ID") @RequestParam(value = "createrId", required = false) Long createrId
+                                        ) {
+        return kuaishouLiveUserAccountService.insertByExcel(file,createrId);
     }
 
     /**

+ 7 - 8
ruixuan-live/src/main/java/com/ruixuan/live/entity/KuaishouLiveUserAccount.java

@@ -65,7 +65,7 @@ public class KuaishouLiveUserAccount implements Serializable {
     /**
      * 销售负责人Id
      */
-    private String saleLeaderId;
+    private Long saleLeaderId;
 
     /**
      * 销售负责人
@@ -75,7 +75,7 @@ public class KuaishouLiveUserAccount implements Serializable {
     /**
      * 运营(优化)负责人Id
      */
-    private String operatorLeaderId;
+    private Long operatorLeaderId;
 
     /**
      * 运营(优化)负责人
@@ -85,7 +85,7 @@ public class KuaishouLiveUserAccount implements Serializable {
     /**
      * 设计负责人Id
      */
-    private String designerLeaderId;
+    private Long designerLeaderId;
 
     /**
      * 设计负责人
@@ -125,7 +125,8 @@ public class KuaishouLiveUserAccount implements Serializable {
     /**
      * 创建人ID
      */
-    private String createrId;
+    private Long createrId;
+    private Long userId;
     private String projectName;
 
     /**
@@ -150,15 +151,13 @@ public class KuaishouLiveUserAccount implements Serializable {
 
     }
 
-    public KuaishouLiveUserAccount(JSONObject obj) {
+    public KuaishouLiveUserAccount(JSONObject obj, Long createrId) {
         this.setId(UUID.randomUUID().toString().replace("-", ""));
         this.setAccountName(obj.getString("0"));//账户名称
         this.setAccountId(obj.getLong("1"));//广告主 ID
         this.setQualificationStatus(obj.getString("2"));//资质状态
         //快手昵称与快手 ID
         String ksIdAndName = obj.getString("3").replace("(", "(").replace(")", ")").trim();
-
-        String collaborators = "小齐菩提(潘家园带货)(352615857)".replace("(", "(").replace(")", ")").trim();
         String[] split = ksIdAndName.split("(");
         this.setKsName(ksIdAndName.substring(0, ksIdAndName.lastIndexOf("(")));
         this.setKsId(Long.valueOf(ksIdAndName.substring(ksIdAndName.lastIndexOf("(") + 1).replace(")", "")));
@@ -173,6 +172,7 @@ public class KuaishouLiveUserAccount implements Serializable {
         this.setSaleLeader(getUserName(obj.getString("25")));//销售责任人
         this.setCollaboratorList(obj.getString("26"));//协作人列表
         this.setPortName(obj.getString("29"));//端口名称
+        this.setCreaterId(createrId);
     }
 
     private String getUserName(String name) {
@@ -183,7 +183,6 @@ public class KuaishouLiveUserAccount implements Serializable {
         return name.split("(")[0];
     }
 
-
     private enum AccountTypeEnum {
         CLJN("cljn", "磁力金牛"),
         CLJN_YD("cljnydd", "磁力金牛移动端"),

+ 8 - 0
ruixuan-live/src/main/java/com/ruixuan/live/mapper/KuaishouLiveUserAccountMapper.java

@@ -68,4 +68,12 @@ public interface KuaishouLiveUserAccountMapper {
     KuaishouLiveUserAccount getOne(@Param("ksId") Long ksId, @Param("accountName") String accountName);
 
     void replaceBatch(@Param(value = "accountList")  List<KuaishouLiveUserAccount> accountList);
+
+    List<KuaishouLiveUserAccount> queryAllList(KuaishouLiveUserAccount kuaishouLiveUserAccount);
+
+    List<String> queryAccountNamesByUserId(@Param("userId") Long userId);
+
+    List<KuaishouLiveUserAccount> queryAllListByAccountNames(@Param("accountNames") List<String> accountNames,@Param("accountName") String accountName,@Param("ksName") String ksName);
+
+    List<KuaishouLiveUserAccount> selectAllListByAccountNames(@Param("accountNames") List<String> accountNames,KuaishouLiveUserAccount kuaishouLiveUserAccount);
 }

+ 4 - 1
ruixuan-live/src/main/java/com/ruixuan/live/service/IKuaishouLiveUserAccountService.java

@@ -31,6 +31,8 @@ public interface IKuaishouLiveUserAccountService {
      */
     public List<KuaishouLiveUserAccount> selectKuaishouLiveUserAccountList(KuaishouLiveUserAccount kuaishouLiveUserAccount);
 
+
+    List<KuaishouLiveUserAccount> queryAllList(KuaishouLiveUserAccount kuaishouLiveUserAccount);
     /**
      * 新增快手直播账户
      *
@@ -39,7 +41,7 @@ public interface IKuaishouLiveUserAccountService {
      */
     public ResultResponse insertKuaishouLiveUserAccount(KuaishouLiveUserAccount kuaishouLiveUserAccount);
 
-    ResultResponse insertByExcel(MultipartFile file);
+    ResultResponse insertByExcel(MultipartFile file,Long createrId);
     /**
      * 修改快手直播账户
      *
@@ -70,4 +72,5 @@ public interface IKuaishouLiveUserAccountService {
 
     ResultResponse queryRoles(String type);
 
+
 }

+ 43 - 8
ruixuan-live/src/main/java/com/ruixuan/live/service/impl/KuaishouLiveUserAccountServiceImpl.java

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.ruixuan.common.core.domain.ResultResponse;
 import com.ruixuan.common.core.domain.entity.SysUser;
 import com.ruixuan.common.utils.Check;
+import com.ruixuan.common.utils.PageUtils;
 import com.ruixuan.data.utils.LiveDataExcelUtils;
 import com.ruixuan.live.entity.KuaishouLiveProject;
 import com.ruixuan.live.entity.KuaishouLiveUserAccount;
@@ -13,6 +14,7 @@ import com.ruixuan.live.mapper.KuaishouLiveProjectMapper;
 import com.ruixuan.live.mapper.KuaishouLiveUserAccountMapper;
 import com.ruixuan.live.mapper.KuaishouLiveUserAccountPartMapper;
 import com.ruixuan.live.service.IKuaishouLiveUserAccountService;
+import com.ruixuan.system.service.ISysRoleService;
 import com.ruixuan.system.service.ISysUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -44,6 +46,9 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
     @Autowired
     private ISysUserService sysUserService;
 
+    @Autowired
+    private ISysRoleService roleService;
+
     /**
      * 查询快手直播账户
      *
@@ -69,15 +74,43 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
      */
     @Override
     public List<KuaishouLiveUserAccount> selectKuaishouLiveUserAccountList(KuaishouLiveUserAccount kuaishouLiveUserAccount) {
+        List<KuaishouLiveUserAccount> list = new ArrayList<>();
         if (Check.isNull(kuaishouLiveUserAccount.getAccountType())) {
             kuaishouLiveUserAccount.setAccountType("cljn");
         }
-        return kuaishouLiveUserAccountMapper.selectKuaishouLiveUserAccountList(kuaishouLiveUserAccount);
+        String roleCode = roleService.selectRoleByUserId(kuaishouLiveUserAccount.getUserId());
+        if ("admin".equals(roleCode)) {
+            PageUtils.startPage();
+            list = kuaishouLiveUserAccountMapper.selectKuaishouLiveUserAccountList(kuaishouLiveUserAccount);
+        } else {
+            List<String> accountNames = kuaishouLiveUserAccountMapper.queryAccountNamesByUserId(kuaishouLiveUserAccount.getUserId());
+            if (Check.isNotNull(accountNames) && accountNames.size() > 0) {
+                PageUtils.startPage();
+                list = kuaishouLiveUserAccountMapper.selectAllListByAccountNames(accountNames, kuaishouLiveUserAccount);
+            }
+        }
+        return list;
+    }
+
+    @Override
+    public List<KuaishouLiveUserAccount> queryAllList(KuaishouLiveUserAccount userAccount) {
+        List<KuaishouLiveUserAccount> list = new ArrayList<>();
+        String roleCode = roleService.selectRoleByUserId(userAccount.getUserId());
+        if ("admin".equals(roleCode)) {
+            PageUtils.startPage();
+            list = kuaishouLiveUserAccountMapper.queryAllList(userAccount);
+        } else {
+            List<String> accountNames = kuaishouLiveUserAccountMapper.queryAccountNamesByUserId(userAccount.getUserId());
+            if (Check.isNotNull(accountNames) && accountNames.size() > 0) {
+                PageUtils.startPage();
+                list = kuaishouLiveUserAccountMapper.queryAllListByAccountNames(accountNames, userAccount.getAccountName(), userAccount.getKsName());
+            }
+        }
+        return list;
     }
 
+
     /**
-     * 新增快手直播账户
-     *
      * @param kuaishouLiveUserAccount 快手直播账户
      * @return 结果
      */
@@ -103,6 +136,7 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
         }
         account.setId(UUID.randomUUID().toString().replace("-", ""));
         account.setProjectId(getAndInsertProject(account.getKsId(), account.getKsName()));
+        account.setAccountStatus("正常");
         int num = kuaishouLiveUserAccountMapper.insertKuaishouLiveUserAccount(account);
         if (num > 0) {
             return ResultResponse.success();
@@ -122,13 +156,13 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
     }
 
     @Override
-    public ResultResponse insertByExcel(MultipartFile file) {
+    public ResultResponse insertByExcel(MultipartFile file,Long createrId) {
         List<KuaishouLiveUserAccount> accountList = new ArrayList<>();
         try {
             String fileName = file.getOriginalFilename();
             List<JSONObject> list = LiveDataExcelUtils.analysisFile(file, fileName);
             for (JSONObject object : list) {
-                KuaishouLiveUserAccount account = new KuaishouLiveUserAccount(object);
+                KuaishouLiveUserAccount account = new KuaishouLiveUserAccount(object,createrId);
                 account.setOperatorLeaderId(getUserIdByName(account.getOperatorLeader()));
                 account.setSaleLeaderId(getUserIdByName(account.getSaleLeader()));
                 account.setProjectId(getAndInsertProject(account.getKsId(), account.getProjectName()));
@@ -171,13 +205,13 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
     }
 
     // 通过人员名字查询人员ID
-    private String getUserIdByName(String name) {
+    private Long getUserIdByName(String name) {
         if (Check.isNull(name)) {
             return null;
         }
-        SysUser user = sysUserService.selectUserByUserName(name);
+        SysUser user = sysUserService.selectUserByNickName(name);
         if (Check.isNotNull(user)) {
-            return user.getUserId().toString();
+            return user.getUserId();
         }
         return null;
     }
@@ -237,6 +271,7 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
 
     @Override
     public List<JSONObject> queryNicknameList() {
+
         return kuaishouLiveUserAccountMapper.queryNicknameList();
     }
 

+ 119 - 2
ruixuan-live/src/main/resources/mapper/live/KuaishouLiveUserAccountMapper.xml

@@ -64,8 +64,12 @@
         IFNULL(t2.count,0) as 'count'
         from kuaishou_live_user_account t1
         left join (
-        SELECT ks_id as ksId,account_name as accountName, sum(1) as 'count' FROM kuaishou_live_user_account_part
-        GROUP BY ks_id,account_name
+        select ksId,accountName, IFNULL(SUM(1),0) as 'count'
+        from (
+        SELECT ks_id as 'ksId',account_name as 'accountName', collaborator FROM kuaishou_live_user_account_part
+        WHERE collaborator_id is not null
+        GROUP BY ks_id,account_name, collaborator) tt
+        GROUP BY ksId ,accountName
         ) t2 ON t2.accountName = t1.account_name AND t2.ksId = t1.ks_id
         <where>
             <if test="ksId != null ">and ks_id = #{ksId}</if>
@@ -90,6 +94,103 @@
         ORDER BY create_time desc
     </select>
 
+
+    <select id="selectAllListByAccountNames" resultMap="KuaishouLiveUserAccountResult">
+        select id,
+        ks_id,
+        ks_name,
+        account_id,
+        account_name,
+        account_type,
+        sale_leader_id,
+        sale_leader,
+        operator_leader_id,
+        operator_leader,
+        designer_leader_id,
+        designer_leader,
+        IFNULL(t2.count,0) as 'count'
+        from kuaishou_live_user_account t1
+        left join (
+        select ksId,accountName, IFNULL(SUM(1),0) as 'count'
+        from (
+        SELECT ks_id as 'ksId',account_name as 'accountName', collaborator FROM kuaishou_live_user_account_part
+        GROUP BY ks_id,account_name, collaborator) tt
+        GROUP BY ksId ,accountName
+        ) t2 ON t2.accountName = t1.account_name AND t2.ksId = t1.ks_id
+        <where>
+            <if test="accountNames != null and accountNames.size() > 0">
+                and account_name in
+                <foreach item="name" index="index" collection="accountNames"
+                         open="(" separator="," close=")">
+                    #{name}
+                </foreach>
+            </if>
+            <if test="ksId != null ">and ks_id = #{ksId}</if>
+            <if test="ksName != null  and ksName != ''">and ks_name like concat('%', #{ksName}, '%')</if>
+            <if test="accountId != null ">and account_id = #{accountId}</if>
+            <if test="accountName != null  and accountName != ''">and account_name like concat('%', #{accountName}, '%')
+            </if>
+            <if test="accountType != null  and accountType != ''">and account_type like concat('%', #{accountType}, '%')
+            </if>
+            <if test="saleLeaderId != null  and saleLeaderId != ''">and sale_leader_id = #{saleLeaderId}</if>
+            <if test="saleLeader != null  and saleLeader != ''">and sale_leader = #{saleLeader}</if>
+            <if test="operatorLeaderId != null  and operatorLeaderId != ''">and operator_leader_id =
+                #{operatorLeaderId}
+            </if>
+            <if test="operatorLeader != null  and operatorLeader != ''">and operator_leader = #{operatorLeader}</if>
+            <if test="designerLeaderId != null  and designerLeaderId != ''">and designer_leader_id =
+                #{designerLeaderId}
+            </if>
+            <if test="designerLeader != null  and designerLeader != ''">and designer_leader = #{designerLeader}</if>
+            <if test="createrId != null  and createrId != ''">and creater_id = #{createrId}</if>
+        </where>
+        ORDER BY create_time desc
+    </select>
+
+
+    <select id="queryAllList" parameterType="String" resultMap="KuaishouLiveUserAccountResult">
+        <include refid="selectKuaishouLiveUserAccountVo"/>
+        <where>
+            <if test="ksId != null ">and ks_id = #{ksId}</if>
+            <if test="ksName != null  and ksName != ''">and ks_name like concat('%', #{ksName}, '%')</if>
+            <if test="accountId != null ">and account_id = #{accountId}</if>
+            <if test="accountName != null  and accountName != ''">and account_name like concat('%', #{accountName}, '%')
+            </if>
+            <if test="accountType != null  and accountType != ''">and account_type like concat('%', #{accountType}, '%')
+            </if>
+            <if test="saleLeaderId != null  and saleLeaderId != ''">and sale_leader_id = #{saleLeaderId}</if>
+            <if test="saleLeader != null  and saleLeader != ''">and sale_leader = #{saleLeader}</if>
+            <if test="operatorLeaderId != null  and operatorLeaderId != ''">and operator_leader_id =
+                #{operatorLeaderId}
+            </if>
+            <if test="operatorLeader != null  and operatorLeader != ''">and operator_leader = #{operatorLeader}</if>
+            <if test="designerLeaderId != null  and designerLeaderId != ''">and designer_leader_id =
+                #{designerLeaderId}
+            </if>
+            <if test="designerLeader != null  and designerLeader != ''">and designer_leader = #{designerLeader}</if>
+            <if test="createrId != null  and createrId != ''">and creater_id = #{createrId}</if>
+        </where>
+        ORDER BY create_time desc
+    </select>
+
+    <select id="queryAllListByAccountNames" parameterType="String" resultMap="KuaishouLiveUserAccountResult">
+        <include refid="selectKuaishouLiveUserAccountVo"/>
+        <where>
+            <if test="accountNames != null and accountNames.size() > 0">
+                and account_name in
+                <foreach item="name" index="index" collection="accountNames"
+                         open="(" separator="," close=")">
+                    #{name}
+                </foreach>
+            </if>
+            <if test="accountName != null  and accountName != ''">and account_name like concat('%', #{accountName}, '%')
+            </if>
+            <if test="ksName != null  and ksName != ''">and ks_name like concat('%', #{ksName}, '%')</if>
+        </where>
+        ORDER BY create_time desc
+    </select>
+
+
     <select id="getOne" parameterType="String" resultType="com.ruixuan.live.entity.KuaishouLiveUserAccount">
         <include refid="selectKuaishouLiveUserAccountVo"/>
         <where>
@@ -99,6 +200,22 @@
         LIMIT 1
     </select>
 
+    <select id="queryAccountNamesByUserId" parameterType="Long" resultType="String">
+        SELECT account_name
+        FROM (
+                 SELECT account_name
+                 FROM `kuaishou_live_user_account`
+                 WHERE sale_leader_id = #{userId}
+                    OR operator_leader_id = #{userId}
+                    OR designer_leader_id = #{userId}
+                 UNION ALL
+                 SELECT account_name
+                 FROM `kuaishou_live_user_account_part`
+                 WHERE collaborator_id = #{userId}
+             ) t
+        GROUP BY account_name
+    </select>
+
     <select id="selectKuaishouLiveUserAccountById" parameterType="String" resultMap="KuaishouLiveUserAccountResult">
         <include refid="selectKuaishouLiveUserAccountVo"/>
         where id = #{id}

+ 2 - 0
ruixuan-live/src/main/resources/mapper/live/KuaishouLiveUserAccountPartMapper.xml

@@ -34,6 +34,8 @@
         select collaborator_id as 'userId', collaborator as 'name'
         from kuaishou_live_user_account_part
         where ks_id = #{ksId}
+        and collaborator_id is not null
+        group by collaborator_id
     </select>
 
     <select id="selectKuaishouLiveUserAccountPartById" parameterType="Long"

+ 2 - 0
ruixuan-system/src/main/java/com/ruixuan/system/mapper/SysRoleMapper.java

@@ -104,4 +104,6 @@ public interface SysRoleMapper
      * @return 结果
      */
     public int deleteRoleByIds(Long[] roleIds);
+
+    String selectRoleByUserId(Long userId);
 }

+ 7 - 0
ruixuan-system/src/main/java/com/ruixuan/system/mapper/SysUserMapper.java

@@ -46,6 +46,13 @@ public interface SysUserMapper
     public SysUser selectUserByUserName(String userName);
 
     /**
+     * 通过用户昵称查询用户
+     *
+     * @param nickName 用户昵称
+     * @return 用户对象信息
+     */
+    SysUser selectUserByNickName(String nickName);
+    /**
      * 通过用户ID查询用户
      * 
      * @param userId 用户ID

+ 2 - 0
ruixuan-system/src/main/java/com/ruixuan/system/mapper/SysUserRoleMapper.java

@@ -59,4 +59,6 @@ public interface SysUserRoleMapper
      * @return 结果
      */
     public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
+
+    String selectRoleByUserId(@Param("userId")  String userId);
 }

+ 2 - 0
ruixuan-system/src/main/java/com/ruixuan/system/service/ISysRoleService.java

@@ -170,4 +170,6 @@ public interface ISysRoleService
      * @return 结果
      */
     public int insertAuthUsers(Long roleId, Long[] userIds);
+
+    String selectRoleByUserId(Long userId);
 }

+ 7 - 0
ruixuan-system/src/main/java/com/ruixuan/system/service/ISysUserService.java

@@ -42,6 +42,13 @@ public interface ISysUserService {
      * @return 用户对象信息
      */
     public SysUser selectUserByUserName(String userName);
+    /**
+     * 通过用户昵称查询用户
+     *
+     * @param nickName 用户昵称
+     * @return 用户对象信息
+     */
+    public SysUser selectUserByNickName(String nickName);
 
     /**
      * 通过用户ID查询用户

+ 70 - 104
ruixuan-system/src/main/java/com/ruixuan/system/service/impl/SysRoleServiceImpl.java

@@ -5,6 +5,7 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -27,12 +28,11 @@ import com.ruixuan.system.service.ISysRoleService;
 
 /**
  * 角色 业务层处理
- * 
+ *
  * @author ruixuan
  */
 @Service
-public class SysRoleServiceImpl implements ISysRoleService
-{
+public class SysRoleServiceImpl implements ISysRoleService {
     @Autowired
     private SysRoleMapper roleMapper;
 
@@ -47,34 +47,29 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 根据条件分页查询角色数据
-     * 
+     *
      * @param role 角色信息
      * @return 角色数据集合信息
      */
     @Override
     @DataScope(deptAlias = "d")
-    public List<SysRole> selectRoleList(SysRole role)
-    {
+    public List<SysRole> selectRoleList(SysRole role) {
         return roleMapper.selectRoleList(role);
     }
 
     /**
      * 根据用户ID查询角色
-     * 
+     *
      * @param userId 用户ID
      * @return 角色列表
      */
     @Override
-    public List<SysRole> selectRolesByUserId(Long userId)
-    {
+    public List<SysRole> selectRolesByUserId(Long userId) {
         List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
         List<SysRole> roles = selectRoleAll();
-        for (SysRole role : roles)
-        {
-            for (SysRole userRole : userRoles)
-            {
-                if (role.getRoleId().longValue() == userRole.getRoleId().longValue())
-                {
+        for (SysRole role : roles) {
+            for (SysRole userRole : userRoles) {
+                if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
                     role.setFlag(true);
                     break;
                 }
@@ -85,19 +80,16 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 根据用户ID查询权限
-     * 
+     *
      * @param userId 用户ID
      * @return 权限列表
      */
     @Override
-    public Set<String> selectRolePermissionByUserId(Long userId)
-    {
+    public Set<String> selectRolePermissionByUserId(Long userId) {
         List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
         Set<String> permsSet = new HashSet<>();
-        for (SysRole perm : perms)
-        {
-            if (StringUtils.isNotNull(perm))
-            {
+        for (SysRole perm : perms) {
+            if (StringUtils.isNotNull(perm)) {
                 permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
             }
         }
@@ -106,52 +98,47 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 查询所有角色
-     * 
+     *
      * @return 角色列表
      */
     @Override
-    public List<SysRole> selectRoleAll()
-    {
+    public List<SysRole> selectRoleAll() {
         return SpringUtils.getAopProxy(this).selectRoleList(new SysRole());
     }
 
     /**
      * 根据用户ID获取角色选择框列表
-     * 
+     *
      * @param userId 用户ID
      * @return 选中角色ID列表
      */
     @Override
-    public List<Long> selectRoleListByUserId(Long userId)
-    {
+    public List<Long> selectRoleListByUserId(Long userId) {
         return roleMapper.selectRoleListByUserId(userId);
     }
 
     /**
      * 通过角色ID查询角色
-     * 
+     *
      * @param roleId 角色ID
      * @return 角色对象信息
      */
     @Override
-    public SysRole selectRoleById(Long roleId)
-    {
+    public SysRole selectRoleById(Long roleId) {
         return roleMapper.selectRoleById(roleId);
     }
 
     /**
      * 校验角色名称是否唯一
-     * 
+     *
      * @param role 角色信息
      * @return 结果
      */
     @Override
-    public String checkRoleNameUnique(SysRole role)
-    {
+    public String checkRoleNameUnique(SysRole role) {
         Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
         SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
-        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue())
-        {
+        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
@@ -159,17 +146,15 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 校验角色权限是否唯一
-     * 
+     *
      * @param role 角色信息
      * @return 结果
      */
     @Override
-    public String checkRoleKeyUnique(SysRole role)
-    {
+    public String checkRoleKeyUnique(SysRole role) {
         Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
         SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey());
-        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue())
-        {
+        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
@@ -177,33 +162,28 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 校验角色是否允许操作
-     * 
+     *
      * @param role 角色信息
      */
     @Override
-    public void checkRoleAllowed(SysRole role)
-    {
-        if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin())
-        {
+    public void checkRoleAllowed(SysRole role) {
+        if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) {
             throw new ServiceException("不允许操作超级管理员角色");
         }
     }
 
     /**
      * 校验角色是否有数据权限
-     * 
+     *
      * @param roleId 角色id
      */
     @Override
-    public void checkRoleDataScope(Long roleId)
-    {
-        if (!SysUser.isAdmin(SecurityUtils.getUserId()))
-        {
+    public void checkRoleDataScope(Long roleId) {
+        if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
             SysRole role = new SysRole();
             role.setRoleId(roleId);
             List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
-            if (StringUtils.isEmpty(roles))
-            {
+            if (StringUtils.isEmpty(roles)) {
                 throw new ServiceException("没有权限访问角色数据!");
             }
         }
@@ -211,26 +191,24 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 通过角色ID查询角色使用数量
-     * 
+     *
      * @param roleId 角色ID
      * @return 结果
      */
     @Override
-    public int countUserRoleByRoleId(Long roleId)
-    {
+    public int countUserRoleByRoleId(Long roleId) {
         return userRoleMapper.countUserRoleByRoleId(roleId);
     }
 
     /**
      * 新增保存角色信息
-     * 
+     *
      * @param role 角色信息
      * @return 结果
      */
     @Override
     @Transactional
-    public int insertRole(SysRole role)
-    {
+    public int insertRole(SysRole role) {
         // 新增角色信息
         roleMapper.insertRole(role);
         return insertRoleMenu(role);
@@ -238,14 +216,13 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 修改保存角色信息
-     * 
+     *
      * @param role 角色信息
      * @return 结果
      */
     @Override
     @Transactional
-    public int updateRole(SysRole role)
-    {
+    public int updateRole(SysRole role) {
         // 修改角色信息
         roleMapper.updateRole(role);
         // 删除角色与菜单关联
@@ -255,26 +232,24 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 修改角色状态
-     * 
+     *
      * @param role 角色信息
      * @return 结果
      */
     @Override
-    public int updateRoleStatus(SysRole role)
-    {
+    public int updateRoleStatus(SysRole role) {
         return roleMapper.updateRole(role);
     }
 
     /**
      * 修改数据权限信息
-     * 
+     *
      * @param role 角色信息
      * @return 结果
      */
     @Override
     @Transactional
-    public int authDataScope(SysRole role)
-    {
+    public int authDataScope(SysRole role) {
         // 修改角色信息
         roleMapper.updateRole(role);
         // 删除角色与部门关联
@@ -285,23 +260,20 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 新增角色菜单信息
-     * 
+     *
      * @param role 角色对象
      */
-    public int insertRoleMenu(SysRole role)
-    {
+    public int insertRoleMenu(SysRole role) {
         int rows = 1;
         // 新增用户与角色管理
         List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
-        for (Long menuId : role.getMenuIds())
-        {
+        for (Long menuId : role.getMenuIds()) {
             SysRoleMenu rm = new SysRoleMenu();
             rm.setRoleId(role.getRoleId());
             rm.setMenuId(menuId);
             list.add(rm);
         }
-        if (list.size() > 0)
-        {
+        if (list.size() > 0) {
             rows = roleMenuMapper.batchRoleMenu(list);
         }
         return rows;
@@ -312,20 +284,17 @@ public class SysRoleServiceImpl implements ISysRoleService
      *
      * @param role 角色对象
      */
-    public int insertRoleDept(SysRole role)
-    {
+    public int insertRoleDept(SysRole role) {
         int rows = 1;
         // 新增角色与部门(数据权限)管理
         List<SysRoleDept> list = new ArrayList<SysRoleDept>();
-        for (Long deptId : role.getDeptIds())
-        {
+        for (Long deptId : role.getDeptIds()) {
             SysRoleDept rd = new SysRoleDept();
             rd.setRoleId(role.getRoleId());
             rd.setDeptId(deptId);
             list.add(rd);
         }
-        if (list.size() > 0)
-        {
+        if (list.size() > 0) {
             rows = roleDeptMapper.batchRoleDept(list);
         }
         return rows;
@@ -333,14 +302,13 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 通过角色ID删除角色
-     * 
+     *
      * @param roleId 角色ID
      * @return 结果
      */
     @Override
     @Transactional
-    public int deleteRoleById(Long roleId)
-    {
+    public int deleteRoleById(Long roleId) {
         // 删除角色与菜单关联
         roleMenuMapper.deleteRoleMenuByRoleId(roleId);
         // 删除角色与部门关联
@@ -350,21 +318,18 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 批量删除角色信息
-     * 
+     *
      * @param roleIds 需要删除的角色ID
      * @return 结果
      */
     @Override
     @Transactional
-    public int deleteRoleByIds(Long[] roleIds)
-    {
-        for (Long roleId : roleIds)
-        {
+    public int deleteRoleByIds(Long[] roleIds) {
+        for (Long roleId : roleIds) {
             checkRoleAllowed(new SysRole(roleId));
             checkRoleDataScope(roleId);
             SysRole role = selectRoleById(roleId);
-            if (countUserRoleByRoleId(roleId) > 0)
-            {
+            if (countUserRoleByRoleId(roleId) > 0) {
                 throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName()));
             }
         }
@@ -377,43 +342,39 @@ public class SysRoleServiceImpl implements ISysRoleService
 
     /**
      * 取消授权用户角色
-     * 
+     *
      * @param userRole 用户和角色关联信息
      * @return 结果
      */
     @Override
-    public int deleteAuthUser(SysUserRole userRole)
-    {
+    public int deleteAuthUser(SysUserRole userRole) {
         return userRoleMapper.deleteUserRoleInfo(userRole);
     }
 
     /**
      * 批量取消授权用户角色
-     * 
-     * @param roleId 角色ID
+     *
+     * @param roleId  角色ID
      * @param userIds 需要取消授权的用户数据ID
      * @return 结果
      */
     @Override
-    public int deleteAuthUsers(Long roleId, Long[] userIds)
-    {
+    public int deleteAuthUsers(Long roleId, Long[] userIds) {
         return userRoleMapper.deleteUserRoleInfos(roleId, userIds);
     }
 
     /**
      * 批量选择授权用户角色
-     * 
-     * @param roleId 角色ID
+     *
+     * @param roleId  角色ID
      * @param userIds 需要授权的用户数据ID
      * @return 结果
      */
     @Override
-    public int insertAuthUsers(Long roleId, Long[] userIds)
-    {
+    public int insertAuthUsers(Long roleId, Long[] userIds) {
         // 新增用户与角色管理
         List<SysUserRole> list = new ArrayList<SysUserRole>();
-        for (Long userId : userIds)
-        {
+        for (Long userId : userIds) {
             SysUserRole ur = new SysUserRole();
             ur.setUserId(userId);
             ur.setRoleId(roleId);
@@ -421,4 +382,9 @@ public class SysRoleServiceImpl implements ISysRoleService
         }
         return userRoleMapper.batchUserRole(list);
     }
+
+    @Override
+    public String selectRoleByUserId(Long userId) {
+        return roleMapper.selectRoleByUserId(userId);
+    }
 }

+ 5 - 0
ruixuan-system/src/main/java/com/ruixuan/system/service/impl/SysUserServiceImpl.java

@@ -109,6 +109,11 @@ public class SysUserServiceImpl implements ISysUserService {
         return userMapper.selectUserByUserName(userName);
     }
 
+    @Override
+    public SysUser selectUserByNickName(String nickName) {
+        return userMapper.selectUserByNickName(nickName);
+    }
+
     /**
      * 通过用户ID查询用户
      *

+ 162 - 143
ruixuan-system/src/main/resources/mapper/system/SysRoleMapper.xml

@@ -1,152 +1,171 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruixuan.system.mapper.SysRoleMapper">
 
-	<resultMap type="SysRole" id="SysRoleResult">
-		<id     property="roleId"             column="role_id"               />
-		<result property="roleName"           column="role_name"             />
-		<result property="roleKey"            column="role_key"              />
-		<result property="roleSort"           column="role_sort"             />
-		<result property="dataScope"          column="data_scope"            />
-		<result property="menuCheckStrictly"  column="menu_check_strictly"   />
-		<result property="deptCheckStrictly"  column="dept_check_strictly"   />
-		<result property="status"             column="status"                />
-		<result property="delFlag"            column="del_flag"              />
-		<result property="createBy"           column="create_by"             />
-		<result property="createTime"         column="create_time"           />
-		<result property="updateBy"           column="update_by"             />
-		<result property="updateTime"         column="update_time"           />
-		<result property="remark"             column="remark"                />
-	</resultMap>
-	
-	<sql id="selectRoleVo">
-	    select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
-            r.status, r.del_flag, r.create_time, r.remark 
+    <resultMap type="SysRole" id="SysRoleResult">
+        <id property="roleId" column="role_id"/>
+        <result property="roleName" column="role_name"/>
+        <result property="roleKey" column="role_key"/>
+        <result property="roleSort" column="role_sort"/>
+        <result property="dataScope" column="data_scope"/>
+        <result property="menuCheckStrictly" column="menu_check_strictly"/>
+        <result property="deptCheckStrictly" column="dept_check_strictly"/>
+        <result property="status" column="status"/>
+        <result property="delFlag" column="del_flag"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="remark" column="remark"/>
+    </resultMap>
+
+    <sql id="selectRoleVo">
+        select distinct r.role_id,
+                        r.role_name,
+                        r.role_key,
+                        r.role_sort,
+                        r.data_scope,
+                        r.menu_check_strictly,
+                        r.dept_check_strictly,
+                        r.status,
+                        r.del_flag,
+                        r.create_time,
+                        r.remark
         from sys_role r
-	        left join sys_user_role ur on ur.role_id = r.role_id
-	        left join sys_user u on u.user_id = ur.user_id
-	        left join sys_dept d on u.dept_id = d.dept_id
+                 left join sys_user_role ur on ur.role_id = r.role_id
+                 left join sys_user u on u.user_id = ur.user_id
+                 left join sys_dept d on u.dept_id = d.dept_id
     </sql>
-    
+
     <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult">
-		<include refid="selectRoleVo"/>
-		where r.del_flag = '0'
-		<if test="roleId != null and roleId != 0">
-			AND r.role_id = #{roleId}
-		</if>
-		<if test="roleName != null and roleName != ''">
-			AND r.role_name like concat('%', #{roleName}, '%')
-		</if>
-		<if test="status != null and status != ''">
-			AND r.status = #{status}
-		</if>
-		<if test="roleKey != null and roleKey != ''">
-			AND r.role_key like concat('%', #{roleKey}, '%')
-		</if>
-		<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
-			and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
-		</if>
-		<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
-			and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
-		</if>
-		<!-- 数据范围过滤 -->
-		${params.dataScope}
-		order by r.role_sort
-	</select>
-    
-	<select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
-		<include refid="selectRoleVo"/>
-		WHERE r.del_flag = '0' and ur.user_id = #{userId}
-	</select>
-	
-	<select id="selectRoleAll" resultMap="SysRoleResult">
-		<include refid="selectRoleVo"/>
-	</select>
-	
-	<select id="selectRoleListByUserId" parameterType="Long" resultType="Long">
-		select r.role_id
+        <include refid="selectRoleVo"/>
+        where r.del_flag = '0'
+        <if test="roleId != null and roleId != 0">
+            AND r.role_id = #{roleId}
+        </if>
+        <if test="roleName != null and roleName != ''">
+            AND r.role_name like concat('%', #{roleName}, '%')
+        </if>
+        <if test="status != null and status != ''">
+            AND r.status = #{status}
+        </if>
+        <if test="roleKey != null and roleKey != ''">
+            AND r.role_key like concat('%', #{roleKey}, '%')
+        </if>
+        <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
+            and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
+        </if>
+        <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
+            and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
+        </if>
+        <!-- 数据范围过滤 -->
+        ${params.dataScope}
+        order by r.role_sort
+    </select>
+
+    <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
+        <include refid="selectRoleVo"/>
+        WHERE r.del_flag = '0' and ur.user_id = #{userId}
+    </select>
+
+    <select id="selectRoleByUserId" parameterType="Long" resultType="String">
+        select r.role_key
         from sys_role r
-	        left join sys_user_role ur on ur.role_id = r.role_id
-	        left join sys_user u on u.user_id = ur.user_id
-	    where u.user_id = #{userId}
-	</select>
-	
-	<select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
-		<include refid="selectRoleVo"/>
-		where r.role_id = #{roleId}
-	</select>
-	
-	<select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
-		<include refid="selectRoleVo"/>
-		WHERE r.del_flag = '0' and u.user_name = #{userName}
-	</select>
-	
-	<select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
-		<include refid="selectRoleVo"/>
-		 where r.role_name=#{roleName} limit 1
-	</select>
-	
-	<select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
-		<include refid="selectRoleVo"/>
-		 where r.role_key=#{roleKey} limit 1
-	</select>
-	
- 	<insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
- 		insert into sys_role(
- 			<if test="roleId != null and roleId != 0">role_id,</if>
- 			<if test="roleName != null and roleName != ''">role_name,</if>
- 			<if test="roleKey != null and roleKey != ''">role_key,</if>
- 			<if test="roleSort != null and roleSort != ''">role_sort,</if>
- 			<if test="dataScope != null and dataScope != ''">data_scope,</if>
- 			<if test="menuCheckStrictly != null">menu_check_strictly,</if>
- 			<if test="deptCheckStrictly != null">dept_check_strictly,</if>
- 			<if test="status != null and status != ''">status,</if>
- 			<if test="remark != null and remark != ''">remark,</if>
- 			<if test="createBy != null and createBy != ''">create_by,</if>
- 			create_time
- 		)values(
- 			<if test="roleId != null and roleId != 0">#{roleId},</if>
- 			<if test="roleName != null and roleName != ''">#{roleName},</if>
- 			<if test="roleKey != null and roleKey != ''">#{roleKey},</if>
- 			<if test="roleSort != null and roleSort != ''">#{roleSort},</if>
- 			<if test="dataScope != null and dataScope != ''">#{dataScope},</if>
- 			<if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
- 			<if test="deptCheckStrictly != null">#{deptCheckStrictly},</if>
- 			<if test="status != null and status != ''">#{status},</if>
- 			<if test="remark != null and remark != ''">#{remark},</if>
- 			<if test="createBy != null and createBy != ''">#{createBy},</if>
- 			sysdate()
- 		)
-	</insert>
-	
-	<update id="updateRole" parameterType="SysRole">
- 		update sys_role
- 		<set>
- 			<if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
- 			<if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
- 			<if test="roleSort != null and roleSort != ''">role_sort = #{roleSort},</if>
- 			<if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
- 			<if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
- 			<if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
- 			<if test="status != null and status != ''">status = #{status},</if>
- 			<if test="remark != null">remark = #{remark},</if>
- 			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
- 			update_time = sysdate()
- 		</set>
- 		where role_id = #{roleId}
-	</update>
-	
-	<delete id="deleteRoleById" parameterType="Long">
-		update sys_role set del_flag = '2' where role_id = #{roleId}
- 	</delete>
- 	
- 	<delete id="deleteRoleByIds" parameterType="Long">
- 	    update sys_role set del_flag = '2' where role_id in
- 		<foreach collection="array" item="roleId" open="(" separator="," close=")">
- 			#{roleId}
-        </foreach> 
- 	</delete>
- 	
+                 left join sys_user_role ur on ur.role_id = r.role_id
+                 left join sys_user u on u.user_id = ur.user_id
+        where u.user_id = #{userId}
+    </select>
+
+    <select id="selectRoleAll" resultMap="SysRoleResult">
+        <include refid="selectRoleVo"/>
+    </select>
+
+    <select id="selectRoleListByUserId" parameterType="Long" resultType="Long">
+        select r.role_id
+        from sys_role r
+                 left join sys_user_role ur on ur.role_id = r.role_id
+                 left join sys_user u on u.user_id = ur.user_id
+        where u.user_id = #{userId}
+    </select>
+
+    <select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
+        <include refid="selectRoleVo"/>
+        where r.role_id = #{roleId}
+    </select>
+
+    <select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
+        <include refid="selectRoleVo"/>
+        WHERE r.del_flag = '0' and u.user_name = #{userName}
+    </select>
+
+    <select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
+        <include refid="selectRoleVo"/>
+        where r.role_name=#{roleName} limit 1
+    </select>
+
+    <select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
+        <include refid="selectRoleVo"/>
+        where r.role_key=#{roleKey} limit 1
+    </select>
+
+    <insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
+        insert into sys_role(
+        <if test="roleId != null and roleId != 0">role_id,</if>
+        <if test="roleName != null and roleName != ''">role_name,</if>
+        <if test="roleKey != null and roleKey != ''">role_key,</if>
+        <if test="roleSort != null and roleSort != ''">role_sort,</if>
+        <if test="dataScope != null and dataScope != ''">data_scope,</if>
+        <if test="menuCheckStrictly != null">menu_check_strictly,</if>
+        <if test="deptCheckStrictly != null">dept_check_strictly,</if>
+        <if test="status != null and status != ''">status,</if>
+        <if test="remark != null and remark != ''">remark,</if>
+        <if test="createBy != null and createBy != ''">create_by,</if>
+        create_time
+        )values(
+        <if test="roleId != null and roleId != 0">#{roleId},</if>
+        <if test="roleName != null and roleName != ''">#{roleName},</if>
+        <if test="roleKey != null and roleKey != ''">#{roleKey},</if>
+        <if test="roleSort != null and roleSort != ''">#{roleSort},</if>
+        <if test="dataScope != null and dataScope != ''">#{dataScope},</if>
+        <if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
+        <if test="deptCheckStrictly != null">#{deptCheckStrictly},</if>
+        <if test="status != null and status != ''">#{status},</if>
+        <if test="remark != null and remark != ''">#{remark},</if>
+        <if test="createBy != null and createBy != ''">#{createBy},</if>
+        sysdate()
+        )
+    </insert>
+
+    <update id="updateRole" parameterType="SysRole">
+        update sys_role
+        <set>
+            <if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
+            <if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
+            <if test="roleSort != null and roleSort != ''">role_sort = #{roleSort},</if>
+            <if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
+            <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
+            <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
+            <if test="status != null and status != ''">status = #{status},</if>
+            <if test="remark != null">remark = #{remark},</if>
+            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
+            update_time = sysdate()
+        </set>
+        where role_id = #{roleId}
+    </update>
+
+    <delete id="deleteRoleById" parameterType="Long">
+        update sys_role
+        set del_flag = '2'
+        where role_id = #{roleId}
+    </delete>
+
+    <delete id="deleteRoleByIds" parameterType="Long">
+        update sys_role set del_flag = '2' where role_id in
+        <foreach collection="array" item="roleId" open="(" separator="," close=")">
+            #{roleId}
+        </foreach>
+    </delete>
+
 </mapper> 

+ 5 - 0
ruixuan-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -155,6 +155,11 @@
         where u.user_name = #{userName}
     </select>
 
+     <select id="selectUserByNickName" parameterType="String" resultMap="SysUserResult">
+        <include refid="selectUserVo"/>
+        where u.nick_name = #{nickName}
+    </select>
+
     <select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
         <include refid="selectUserVo"/>
         where u.user_id = #{userId}