From 35bb808ab141e6a3092031ae7ee29028b833e521 Mon Sep 17 00:00:00 2001 From: lizijie <lzjiiie@163.com> Date: Fri, 09 Apr 2021 15:20:24 +0800 Subject: [PATCH] 修改菜单返回类型,父子关系 --- screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleServiceImpl.java | 111 ++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 76 insertions(+), 35 deletions(-) diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleServiceImpl.java index c71e9ca..b0bf07e 100644 --- a/screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleServiceImpl.java +++ b/screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleServiceImpl.java @@ -1,8 +1,8 @@ package com.moral.api.service.impl; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.moral.api.entity.ManageAccountRole; -import com.moral.api.entity.ManageMenu; import com.moral.api.entity.ManageRole; import com.moral.api.mapper.ManageAccountRoleMapper; import com.moral.api.mapper.ManageRoleMapper; @@ -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; @@ -17,10 +18,8 @@ import org.springframework.util.StringUtils; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.text.SimpleDateFormat; +import java.util.*; /** * <p> @@ -52,14 +51,37 @@ private ManageAccountRoleMapper manageAccountRoleMapper; @Override - @Transactional - public List<ManageRole> getAllWithPagingQuery(Map map) { - com.baomidou.mybatisplus.extension.plugins.pagination.Page<ManageRole> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(Integer.parseInt(map.get("current").toString()), Integer.parseInt(map.get("size").toString())); + public Map<String,Object> getAllWithPagingQuery(Map map) { + Map<String,Object> resultMap = new HashMap<>(); + int current = Integer.parseInt(map.get("current").toString()); + int size = Integer.parseInt(map.get("size").toString()); + com.baomidou.mybatisplus.extension.plugins.pagination.Page<ManageRole> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(current, size); QueryWrapper<ManageRole> wrapper = new QueryWrapper(); wrapper.eq("is_delete",0); + wrapper.orderByDesc("create_time"); com.baomidou.mybatisplus.extension.plugins.pagination.Page resultpage = manageRoleMapper.selectPage(page,wrapper); List<ManageRole> manageRoles = resultpage.getRecords(); - return manageRoles; + SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + List<Map<String,Object>> manageRolesList = new ArrayList<>(); + for (ManageRole manageRole:manageRoles) { + Map manageRoleMap = JSON.parseObject(JSON.toJSONString(manageRole),Map.class); + String createTime = SDF.format(manageRole.getCreateTime()); + String updateTime = SDF.format(manageRole.getUpdateTime()); + manageRoleMap.put("createTime",createTime); + manageRoleMap.put("updateTime",updateTime); + manageRoleMap.put("key",manageRole.getId()); + manageRolesList.add(manageRoleMap); + } + resultMap.put("manageRoles",manageRolesList); + int totalNumber = manageRoleMapper.selectCount(wrapper); + resultMap.put("totalNumber",totalNumber); + resultMap.put("current",current); + int totalPageNumber = totalNumber/size; + if(totalNumber%size != 0){ + totalPageNumber += 1; + } + resultMap.put("totalPageNumber",totalPageNumber); + return resultMap; } @Override @@ -67,23 +89,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 +112,6 @@ insertMap.put("menu_id",Integer.parseInt(temp.toString())); insertList.add(insertMap); } - System.out.println(insertList); manageRoleMenuMapper.insertBatch(insertList); } return resultMap; @@ -102,44 +122,65 @@ 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; } @Override - @Transactional - public List<ManageRole> getManageRoleByNameFuzzy(Map map) { - com.baomidou.mybatisplus.extension.plugins.pagination.Page<ManageRole> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(Integer.parseInt(map.get("current").toString()), Integer.parseInt(map.get("size").toString())); + public Map<String,Object> getManageRoleByNameFuzzy(Map map) { + Map<String,Object> resultMap = new HashMap<>(); + int current = Integer.parseInt(map.get("current").toString()); + int size = Integer.parseInt(map.get("size").toString()); + com.baomidou.mybatisplus.extension.plugins.pagination.Page<ManageRole> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(current, size); QueryWrapper<ManageRole> wrapper = new QueryWrapper(); wrapper.eq("is_delete",0); wrapper.like("name",map.get("name")); com.baomidou.mybatisplus.extension.plugins.pagination.Page resultpage = manageRoleMapper.selectPage(page,wrapper); List<ManageRole> manageRoles = resultpage.getRecords(); - return manageRoles; + SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + List<Map<String,Object>> manageRolesList = new ArrayList<>(); + for (ManageRole manageRole:manageRoles) { + Map manageRoleMap = JSON.parseObject(JSON.toJSONString(manageRole),Map.class); + String createTime = SDF.format(manageRole.getCreateTime()); + String updateTime = SDF.format(manageRole.getUpdateTime()); + manageRoleMap.put("createTime",createTime); + manageRoleMap.put("updateTime",updateTime); + manageRolesList.add(manageRoleMap); + } + resultMap.put("manageRoles",manageRolesList); + int totalNumber = manageRoleMapper.selectCount(wrapper); + resultMap.put("totalNumber",totalNumber); + resultMap.put("current",current); + int totalPageNumber = totalNumber/size; + if(totalNumber%size != 0){ + totalPageNumber += 1; + } + resultMap.put("totalPageNumber",totalPageNumber); + return resultMap; } @Override 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 +194,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; } -- Gitblit v1.8.0