From 199971c2c2f20e22fdfb088b11caeaee1e523c2f Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Tue, 13 Apr 2021 14:26:11 +0800
Subject: [PATCH] 添加角色新增日志

---
 screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleServiceImpl.java |  192 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 192 insertions(+), 0 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 67846e8..2509d63 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,13 +1,33 @@
 package com.moral.api.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.moral.api.entity.ManageAccount;
+import com.moral.api.entity.ManageAccountRole;
+import com.moral.api.entity.ManageLog;
 import com.moral.api.entity.ManageRole;
+import com.moral.api.mapper.ManageAccountRoleMapper;
+import com.moral.api.mapper.ManageLogMapper;
 import com.moral.api.mapper.ManageRoleMapper;
+import com.moral.api.mapper.ManageRoleMenuMapper;
+import com.moral.api.pojo.dto.login.AccountInfoDTO;
 import com.moral.api.service.ManageRoleService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.moral.api.util.LogUtils;
+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;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * <p>
@@ -28,4 +48,176 @@
             return null;
         return null;
     }
+
+    @Autowired(required = false)
+    private ManageRoleMapper manageRoleMapper;
+
+    @Autowired(required = false)
+    private ManageRoleMenuMapper manageRoleMenuMapper;
+
+    @Autowired(required = false)
+    private ManageAccountRoleMapper manageAccountRoleMapper;
+
+    @Autowired
+    LogUtils logUtils;
+
+    @Override
+    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();
+        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
+    @Transactional
+    public Map<String,Object> insertOne(ManageRole manageRole, List list) {
+        Map<String,Object> resultMap = new HashMap<>();
+        if (manageRole.getName()==null){
+            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("code",ResponseCodeEnum.ROLE_IS_EXPIRE.getCode());
+            resultMap.put("msg",ResponseCodeEnum.ROLE_IS_EXPIRE.getMsg());
+            return resultMap;
+        }
+        manageRoleMapper.insertOne(manageRole);
+        ManageRole manageRoleIns = manageRoleMapper.getManageRoleByName(manageRole.getName());
+        int role_id = manageRoleIns.getId();
+        List insertList = new ArrayList();
+        for (Object temp: list) {
+            Map<String,Integer> insertMap = new HashMap<>();
+            insertMap.put("role_id",role_id);
+            insertMap.put("menu_id",Integer.parseInt(temp.toString()));
+            insertList.add(insertMap);
+        }
+        //���������������������������������������������
+        if (insertList.size()>0){
+            manageRoleMenuMapper.insertBatch(insertList);
+        }
+        //������������������
+        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+        String content = "������������:"+manageRole.getName()+";";
+        logUtils.saveOperationForManage(request,content,"1");
+        resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
+        resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
+        return resultMap;
+    }
+
+    @Override
+    @Transactional
+    public Map<String,Object> updateManageRole(Map map) {
+        Map<String,Object> resultMap = new HashMap<>();
+        if (!map.containsKey("id")){
+            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("code",ResponseCodeEnum.ROLE_IS_NULL.getCode());
+            resultMap.put("msg",ResponseCodeEnum.ROLE_IS_NULL.getMsg());
+        }else {
+            manageRoleMapper.updateManageRoleById(map);
+            resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
+            resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
+        }
+        return resultMap;
+    }
+
+    @Override
+    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();
+        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("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("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()));
+            manageRole.setIsDelete(Constants.DELETE);
+            Map deleteMap = new HashMap();
+            deleteMap.put("id",Integer.parseInt(map.get("id").toString()));
+            deleteMap.put("is_delete",1);
+            //manageRoleMapper.updateManageRoleById(deleteMap);
+            ManageAccountRole manageAccountRole = new ManageAccountRole();
+            manageAccountRole.setIsDelete("1");
+            QueryWrapper<ManageAccountRole> wrapper = new QueryWrapper();
+            wrapper.eq("role_id",Integer.parseInt(map.get("id").toString()));
+            //manageAccountRoleMapper.update(manageAccountRole,wrapper);
+            //������������������
+            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+            ManageRole manageRole1 = manageRoleMapper.selectById(Integer.parseInt(map.get("id").toString()));
+            System.out.println(manageRole1);
+            String content = "������������:"+manageRole.getName()+";";
+            //logUtils.saveOperationForManage(request,content,"1");
+            resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
+            resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
+        }
+        return resultMap;
+    }
 }

--
Gitblit v1.8.0