kaiyu
2021-03-25 247f19f6c3f17c2ac2f37b55c7d0550731f31ffe
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,23 +68,22 @@
    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);
            List insertList = new ArrayList();
            for (Object temp: list) {
                Map<String,Integer> insertMap = new HashMap<>();
@@ -91,7 +91,6 @@
                insertMap.put("menu_id",Integer.parseInt(temp.toString()));
                insertList.add(insertMap);
            }
            System.out.println(insertList);
            manageRoleMenuMapper.insertBatch(insertList);
        }
        return resultMap;
@@ -102,17 +101,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 +132,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 +152,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;
    }