lizijie
2021-03-22 ebdacd7123e42c76cd7cb43938574cfeb0706250
角色菜单配置
6 files modified
142 ■■■■ changed files
screen-common/src/main/java/com/moral/constant/ResponseCodeEnum.java 6 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/controller/ManageRoleController.java 21 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/ManageRoleMenuService.java 8 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/ManageMenuServiceImpl.java 37 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleMenuServiceImpl.java 29 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleServiceImpl.java 41 ●●●● patch | view | raw | blame | history
screen-common/src/main/java/com/moral/constant/ResponseCodeEnum.java
@@ -23,7 +23,11 @@
    ACCOUNT_INVALID(-11, "用户名无效"),
    PASSWORD_INVALID(-12, "密码无效"),
    ACCOUNT_IS_EXPIRE(-13, "用户已过期"),
    GROUP_EXIST(-14, "组已存在")
    GROUP_EXIST(-14, "组已存在"),
    ROLE_IS_EXPIRE(-15, "用户名无效"),
    ROLE_IS_NULL(-16, "密码无效"),
    MENU_IS_EXPIRE(-17, "用户已过期"),
    MENU_IS_NULL(-18, "组已存在")
    ;
    private final Integer code;
screen-manage/src/main/java/com/moral/api/controller/ManageRoleController.java
@@ -4,6 +4,7 @@
import com.moral.api.entity.ManageMenu;
import com.moral.api.entity.ManageRole;
import com.moral.api.service.ManageMenuService;
import com.moral.api.service.ManageRoleMenuService;
import com.moral.api.service.ManageRoleService;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
@@ -33,6 +34,9 @@
    @Autowired
    private ManageRoleService manageRoleService;
    @Autowired
    private ManageRoleMenuService manageRoleMenuService;
    @ApiOperation(value = "获取所有角色", notes = "获取所有角色")
    @ApiImplicitParams({
@@ -115,4 +119,21 @@
        List<ManageRole> re = manageRoleService.getManageRoleByNameFuzzy(parameters);
        return ResultMessage.ok(re);
    }
    @ApiOperation(value = "更新角色菜单", notes = "更新角色菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query", dataType = "int")
    })
    @RequestMapping(value = "updateRoleMenu", method = RequestMethod.GET)
    public ResultMessage updateRoleMenu(HttpServletRequest request) {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        int id = Integer.parseInt(parameters.get("id").toString());
        List list = new ArrayList();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        Map<String,Object> re = manageRoleMenuService.updateRoleMenu(list,id);
        return ResultMessage.ok(re);
    }
}
screen-manage/src/main/java/com/moral/api/service/ManageRoleMenuService.java
@@ -2,6 +2,10 @@
import com.moral.api.entity.ManageRoleMenu;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
/**
 * <p>
@@ -11,6 +15,10 @@
 * @author moral
 * @since 2021-03-09
 */
@Transactional
public interface ManageRoleMenuService extends IService<ManageRoleMenu> {
    @Transactional
    Map<String,Object> updateRoleMenu(List list,int id);
}
screen-manage/src/main/java/com/moral/api/service/impl/ManageMenuServiceImpl.java
@@ -5,6 +5,7 @@
import com.moral.api.mapper.ManageRoleMenuMapper;
import com.moral.api.service.ManageMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.ResponseCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -35,17 +36,17 @@
    public Map<String,Object> insertManageMenu(ManageMenu manageMenu) {
        Map<String,Object> resultMap = new HashMap<>();
        if (manageMenu.getName()==null){
            resultMap.put("flag",false);
            resultMap.put("msg","名称为空!");
            resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode());
            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            return resultMap;
        }
        if (manageMenuMapper.getManageMenuByName(manageMenu.getName()) != null){
            resultMap.put("flag",false);
            resultMap.put("msg","该菜单已存在!");
            resultMap.put("code",ResponseCodeEnum.MENU_IS_EXPIRE.getCode());
            resultMap.put("msg",ResponseCodeEnum.MENU_IS_EXPIRE.getMsg());
        }else {
            manageMenuMapper.insertOne(manageMenu);
            resultMap.put("flag",true);
            resultMap.put("msg","添加成功!");
            resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
            resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
        }
        return resultMap;
    }
@@ -55,17 +56,17 @@
    public Map<String,Object> updateManageMenu(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        if (!map.containsKey("id")){
            resultMap.put("flag",false);
            resultMap.put("msg","未选择更新目标!");
            resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode());
            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            return resultMap;
        }
        if (manageMenuMapper.getManageMenuById(Integer.parseInt(map.get("id").toString())) == null){
            resultMap.put("flag",false);
            resultMap.put("msg","该菜单不存在!");
            resultMap.put("code",ResponseCodeEnum.MENU_IS_NULL.getCode());
            resultMap.put("msg",ResponseCodeEnum.MENU_IS_NULL.getMsg());
        }else {
            manageMenuMapper.updateManageMenuById(map);
            resultMap.put("flag",true);
            resultMap.put("msg","更新成功!");
            resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
            resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
        }
        return resultMap;
    }
@@ -75,13 +76,13 @@
    public Map<String, Object> deleteManageMenu(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        if (!map.containsKey("id")){
            resultMap.put("flag",false);
            resultMap.put("msg","未选择删除目标!");
            resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode());
            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            return resultMap;
        }
        if (manageMenuMapper.getManageMenuById(Integer.parseInt(map.get("id").toString())) == null){
            resultMap.put("flag",false);
            resultMap.put("msg","该角色不存在或已被删除!");
            resultMap.put("code",ResponseCodeEnum.MENU_IS_NULL.getCode());
            resultMap.put("msg",ResponseCodeEnum.MENU_IS_NULL.getMsg());
        }else {
            Map deleteMap = new HashMap();
            int id = Integer.parseInt(map.get("id").toString());
@@ -91,8 +92,8 @@
            Map role_menuDeleteMap = new HashMap();
            role_menuDeleteMap.put("menu_id",id);
            manageRoleMenuMapper.updateDeleteStateByMenu_id(role_menuDeleteMap);
            resultMap.put("flag",true);
            resultMap.put("msg","删除成功!");
            resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
            resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
        }
        return resultMap;
    }
screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleMenuServiceImpl.java
@@ -1,10 +1,19 @@
package com.moral.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.ManageRoleMenu;
import com.moral.api.mapper.ManageRoleMenuMapper;
import com.moral.api.service.ManageRoleMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.ResponseCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * <p>
@@ -17,4 +26,24 @@
@Service
public class ManageRoleMenuServiceImpl extends ServiceImpl<ManageRoleMenuMapper, ManageRoleMenu> implements ManageRoleMenuService {
    @Autowired(required = false)
    private ManageRoleMenuMapper manageRoleMenuMapper;
    @Override
    @Transactional
    public Map<String, Object> updateRoleMenu(List list, int id) {
        Map<String,Object> resultMap = new HashMap<>();
        if (list.size()==0){
            resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode());
            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            return resultMap;
        }
        QueryWrapper<ManageRoleMenu> wrapper = new QueryWrapper();
        wrapper.eq("role_id",id);
        System.out.println(manageRoleMenuMapper.selectCount(wrapper));
        if (manageRoleMenuMapper.selectCount(wrapper)==0){
        }
        return null;
    }
}
screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleServiceImpl.java
@@ -10,6 +10,7 @@
import com.moral.api.service.ManageRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@@ -67,20 +68,20 @@
    public Map<String,Object> insertOne(ManageRole manageRole,List list) {
        Map<String,Object> resultMap = new HashMap<>();
        if (manageRole.getName()==null){
            resultMap.put("flag",false);
            resultMap.put("msg","名称为空!");
            resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode());
            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            return resultMap;
        }
        if (manageRoleMapper.getManageRoleByName(manageRole.getName()) != null){
            resultMap.put("flag",false);
            resultMap.put("msg","该角色已存在!");
            resultMap.put("code",ResponseCodeEnum.ROLE_IS_EXPIRE.getCode());
            resultMap.put("msg",ResponseCodeEnum.ROLE_IS_EXPIRE.getMsg());
        }else {
            manageRoleMapper.insertOne(manageRole);
            resultMap.put("flag",true);
            resultMap.put("msg","添加成功!");
            resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
            resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
        }
        boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString());
        if (flag){
        Integer code = Integer.parseInt(resultMap.get("code").toString());
        if (code.equals(ResponseCodeEnum.SUCCESS.getCode())){
            ManageRole manageRoleIns = manageRoleMapper.getManageRoleByName(manageRole.getName());
            int role_id = manageRoleIns.getId();
            System.out.println(role_id);
@@ -102,17 +103,17 @@
    public Map<String,Object> updateManageRole(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        if (!map.containsKey("id")){
            resultMap.put("flag",false);
            resultMap.put("msg","未选择更新目标!");
            resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode());
            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            return resultMap;
        }
        if (manageRoleMapper.getManageRoleById(Integer.parseInt(map.get("id").toString())) == null){
            resultMap.put("flag",false);
            resultMap.put("msg","该角色不存在!");
            resultMap.put("code",ResponseCodeEnum.ROLE_IS_NULL.getCode());
            resultMap.put("msg",ResponseCodeEnum.ROLE_IS_NULL.getMsg());
        }else {
            manageRoleMapper.updateManageRoleById(map);
            resultMap.put("flag",true);
            resultMap.put("msg","更新成功!");
            resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
            resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
        }
        return resultMap;
    }
@@ -133,13 +134,13 @@
    public Map<String, Object> deleteManageRole(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        if (!map.containsKey("id")){
            resultMap.put("flag",false);
            resultMap.put("msg","未选择删除目标!");
            resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode());
            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            return resultMap;
        }
        if (manageRoleMapper.getManageRoleById(Integer.parseInt(map.get("id").toString())) == null){
            resultMap.put("flag",false);
            resultMap.put("msg","该角色不存在或已被删除!");
            resultMap.put("code",ResponseCodeEnum.ROLE_IS_NULL.getCode());
            resultMap.put("msg",ResponseCodeEnum.ROLE_IS_NULL.getMsg());
        }else {
            ManageRole manageRole = new ManageRole();
            manageRole.setId(Integer.parseInt(map.get("id").toString()));
@@ -153,8 +154,8 @@
            QueryWrapper<ManageAccountRole> wrapper = new QueryWrapper();
            wrapper.eq("role_id",Integer.parseInt(map.get("id").toString()));
            manageAccountRoleMapper.update(manageAccountRole,wrapper);
            resultMap.put("flag",true);
            resultMap.put("msg","删除成功!");
            resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
            resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
        }
        return resultMap;
    }