kaiyu
2021-04-09 54d7eb96e071c62fa96f95b56ff8be66f7c3718e
screen-manage
修改日志插入工具类
规范日志插入格式
10 files modified
423 ■■■■ changed files
screen-manage/src/main/java/com/moral/api/controller/OrganizationController.java 1 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/entity/ManageMenu.java 2 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/exception/GlobalExceptionHandler.java 3 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/pojo/form/account/AccountUpdateForm.java 2 ●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/OrganizationService.java 1 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java 265 ●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/ManageMenuServiceImpl.java 3 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java 112 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/util/LogUtils.java 27 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/resources/application-moduleFormColumn.yml 7 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/controller/OrganizationController.java
@@ -117,4 +117,5 @@
        return new ResultMessage(dto.getCode(), dto.getMsg(), vo);
    }
}
screen-manage/src/main/java/com/moral/api/entity/ManageMenu.java
@@ -1,6 +1,7 @@
package com.moral.api.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
@@ -76,6 +77,7 @@
    /*
    * 二级菜单
    * */
    @TableField(exist = false)
    private List<ManageMenu> children;
    @Override
screen-manage/src/main/java/com/moral/api/exception/GlobalExceptionHandler.java
@@ -23,8 +23,9 @@
    @ResponseBody
    @ResponseStatus(HttpStatus.OK)
    public ResultMessage handleException(Exception ex) {
        log.error(ex.getMessage());
       // log.error(ex.getMessage());
        ex.printStackTrace();
        return  ResultMessage.fail(ResponseCodeEnum.FAIL.getCode(), ResponseCodeEnum.FAIL.getMsg());
    }
screen-manage/src/main/java/com/moral/api/pojo/form/account/AccountUpdateForm.java
@@ -45,7 +45,7 @@
                        ObjectUtils.isEmpty(email) &&
                        ObjectUtils.isEmpty(mobile) &&
                        ObjectUtils.isEmpty(wechat) &&
                        ObjectUtils.isEmpty(roleIds)
                        null == roleIds
                )
            return false;
        return true;
screen-manage/src/main/java/com/moral/api/service/OrganizationService.java
@@ -54,4 +54,5 @@
     */
    OrganizationQueryDTO queryOrganization(OrganizationQueryForm organizationQueryForm);
}
screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java
@@ -1,5 +1,7 @@
package com.moral.api.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -24,14 +26,19 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.config.mybatis.wrapper.NullFilterWrapper;
import com.moral.api.service.ManageMenuService;
import com.moral.api.util.LogUtils;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
@@ -43,6 +50,7 @@
 * @since 2021-03-09
 */
@Service
@ConfigurationProperties(prefix = "log-aspect")
public class ManageAccountServiceImpl extends ServiceImpl<ManageAccountMapper, ManageAccount> implements ManageAccountService {
@@ -54,15 +62,22 @@
    ManageMenuService manageMenuService;
    @Autowired
    ManageAccountRoleMapper manageAccountRoleMapper;
    @Autowired
    LogUtils logUtils;
    Map<String, String> manageAccountFormMap;
    public void setManageAccountFormMap(Map<String, String> manageAccountFormMap) {
        this.manageAccountFormMap = manageAccountFormMap;
    }
    /**
    * @Description: 登陆接口
            * @Param: [loginForm]
            * @return: com.moral.api.pojo.dto.login.LoginDTO
            * @Author: 陈凯裕
            * @Date: 2021/3/30
            */
     * @Description: 登陆接口
     * @Param: [loginForm]
     * @return: com.moral.api.pojo.dto.login.LoginDTO
     * @Author: 陈凯裕
     * @Date: 2021/3/30
     */
    @Override
    public LoginDTO login(LoginForm loginForm) {
        LoginDTO loginDTO = new LoginDTO();
@@ -122,6 +137,12 @@
        loginDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        loginDTO.setAccountInfoDTO(accountInfoDTO);
        loginDTO.setToken(token);
        //登陆插入日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        StringBuilder content = new StringBuilder();
        content.append(manageAccount.getUserName()).append("登陆了后台系统;");
        logUtils.saveLoginForManage(request, content.toString(), manageAccount.getId(), manageAccount.getUserName());
        return loginDTO;
    }
@@ -196,6 +217,14 @@
        accountDTO.setRoles(roles);
        accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
        accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        //操作插入日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        StringBuilder content = new StringBuilder();
        content.append("添加了账号:").append(manageAccount.getUserName() + ";")
                .append("id:" + manageAccount.getId() + ";");
        logUtils.saveOperationForManage(request, content.toString());
        return accountDTO;
    }
@@ -274,70 +303,6 @@
    }
    /**
     * @Description: 更新后台账号
     * @Param: [accountUpdateRequest]
     * @return: com.moral.api.pojo.dto.account.AccountUpdateDTO
     * @Author: 陈凯裕
     * @Date: 2021/3/16
     */
    @Override
    @Transactional
    public AccountDTO updateAccount(AccountUpdateForm accountUpdateForm) {
        AccountDTO accountDTO = new AccountDTO();
        //取参
        ManageAccount manageAccount = accountUpdateForm.formConvertEntity();
        List<Integer> roleIds = accountUpdateForm.getRoleIds();
        //判断要更新的用户是否存在
        QueryWrapper<ManageAccount> exitWrapper = new QueryWrapper<>();
        ManageAccount exitManageAccount = new ManageAccount();
        exitManageAccount.setId(manageAccount.getId());
        exitManageAccount.setIsDelete(Constants.NOT_DELETE);
        exitWrapper.setEntity(exitManageAccount);
        List<ManageAccount> manageAccounts = manageAccountMapper.selectList(exitWrapper);
        if (ObjectUtils.isEmpty(manageAccounts)) {
            accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode());
            accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg());
            return accountDTO;
        }
        //更新ManageAccount表
        manageAccountMapper.updateById(manageAccount);
        //如果角色有变动,则更新ManageAccountRole表
        /*
         * 如果roleIds为null,则是该账号角色没有发生改变
         * 如果roleIds为空,则是该账号所有的角色都被移除
         * 如果roleIds有元素,则是该账号的角色有更新
         * */
        List<ManageRole> roles = null;
        if (roleIds != null) {
            UpdateWrapper<ManageAccountRole> deleteWrapper = new UpdateWrapper<>();
            deleteWrapper.eq("account_id", manageAccount.getId()).set("is_delete", Constants.DELETE);
            manageAccountRoleMapper.update(null, deleteWrapper);
            /*重新添加角色*/
            for (Integer roleId : roleIds) {
                ManageAccountRole manageAccountRole = new ManageAccountRole();
                manageAccountRole.setAccountId(manageAccount.getId());
                manageAccountRole.setRoleId(roleId);
                manageAccountRoleMapper.insert(manageAccountRole);
            }
            //获取用户所有角色
            if (roleIds.size() != 0)
                roles = manageRoleMapper.selectBatchIds(roleIds);
        } else {
            roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId());
        }
        accountDTO.setRoles(roles);
        //封装返回结果
        accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
        accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        accountDTO.setAccount(manageAccountMapper.selectById(manageAccount.getId()));
        return accountDTO;
    }
    /**
     * @Description: 删除后台账号
     * @Param: [accountDeleteRequest]
     * @return: com.moral.api.pojo.dto.account.AccountDeleteDTO
@@ -375,8 +340,168 @@
        accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
        accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        accountDTO.setAccount(existManageAccount);
        //操作插入日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        StringBuilder content = new StringBuilder();
        content.append("删除了账号:").append(existManageAccount.getUserName() + ";")
                .append("id:" + existManageAccount.getId() + ";");
        logUtils.saveOperationForManage(request, content.toString());
        return accountDTO;
    }
    /**
     * @Description: 更新后台账号
     * @Param: [accountUpdateRequest]
     * @return: com.moral.api.pojo.dto.account.AccountUpdateDTO
     * @Author: 陈凯裕
     * @Date: 2021/3/16
     */
    @Override
    @Transactional
    public AccountDTO updateAccount(AccountUpdateForm accountUpdateForm) {
        AccountDTO accountDTO = new AccountDTO();
        //取参
        ManageAccount manageAccount = accountUpdateForm.formConvertEntity();
        List<Integer> roleIds = accountUpdateForm.getRoleIds();
        //判断要更新的用户是否存在
        QueryWrapper<ManageAccount> exitWrapper = new QueryWrapper<>();
        ManageAccount exitManageAccount = new ManageAccount();
        exitManageAccount.setId(manageAccount.getId());
        exitManageAccount.setIsDelete(Constants.NOT_DELETE);
        exitWrapper.setEntity(exitManageAccount);
        exitManageAccount = manageAccountMapper.selectOne(exitWrapper);
        if (ObjectUtils.isEmpty(exitManageAccount)) {
            accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode());
            accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg());
            return accountDTO;
        }
        //更新ManageAccount表
        Map manageAccountMap = JSONObject.parseObject(JSON.toJSONString(manageAccount),Map.class);//转换为Map判断属性是否有更新
        if (manageAccountMap.size()>2) {//判断如果account表中没有相应字段更新则不更新
            manageAccountMapper.updateById(manageAccount);
        }
        //获取更新后的对象
        manageAccount = manageAccountMapper.selectById(manageAccount.getId());
        //获取账号更新前的角色
        List<ManageRole> oldRoles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId());
        //如果角色有变动,则更新ManageAccountRole表
        /*
         * 如果roleIds为null,则是该账号角色没有发生改变
         * 如果roleIds为空,则是该账号所有的角色都被移除
         * 如果roleIds有元素,则是该账号的角色有更新
         * */
        List<ManageRole> roles = null;
        if (roleIds != null) {
            UpdateWrapper<ManageAccountRole> deleteWrapper = new UpdateWrapper<>();
            deleteWrapper.eq("account_id", manageAccount.getId()).set("is_delete", Constants.DELETE);
            manageAccountRoleMapper.update(null, deleteWrapper);
            /*重新添加角色*/
            for (Integer roleId : roleIds) {
                ManageAccountRole manageAccountRole = new ManageAccountRole();
                manageAccountRole.setAccountId(manageAccount.getId());
                manageAccountRole.setRoleId(roleId);
                manageAccountRoleMapper.insert(manageAccountRole);
            }
            //获取用户所有角色
            if (roleIds.size() != 0)
                roles = manageRoleMapper.selectBatchIds(roleIds);
        } else {
            roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId());
        }
        accountDTO.setRoles(roles);
        //封装返回结果
        accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
        accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        accountDTO.setAccount(manageAccount);
        //操作插入日志
        insertUpdateLog(accountUpdateForm, exitManageAccount, oldRoles);
        return accountDTO;
    }
    /**
     * @Description: 将更新操作插入日志
     * @Param: [form, newAccount, oldAccount]
     * @return: void
     * @Author: 陈凯裕
     * @Date: 2021/4/8
     */
    private void insertUpdateLog(AccountUpdateForm updateForm, ManageAccount oldAccount, List<ManageRole> oldRoles) {
        //操作插入日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        StringBuilder content = new StringBuilder();
        content.append("修改了账号:").append(oldAccount.getUserName() + ";")
                .append("id:" + oldAccount.getId() + ";");
        //对象转为Map,获取对象更新前后的属性
        Map<String, Object> newParameters = JSONObject.parseObject(JSON.toJSONString(updateForm), Map.class);
        Map<String, Object> oldParameters = JSONObject.parseObject(JSON.toJSONString(oldAccount), Map.class);
        //遍历配置文件中的Map,将属性转化为汉字
        Set<String> keys = manageAccountFormMap.keySet();
        for (String key : keys) {
            String value = manageAccountFormMap.get(key);//属性对应的汉字
            if ("password".equals(key)) {//密码特殊处理,不显示在日志上
                if (!ObjectUtils.isEmpty(updateForm.getPassword())) {//判断密码是否进行了更新
                    content.append("修改了密码;");
                }
            } else if ("roleIds".equals(key)) {//角色特殊处理,将Id转化为角色名称
                List<Integer> newRoleIds = updateForm.getRoleIds();
                if (newRoleIds != null && 0 == newRoleIds.size()) {//如果新的角色集合为空,则是删除了所有的角色
                    content.append("删除了所有角色;");
                }
                if ((newRoleIds != null) && (newRoleIds.size() != 0)) {//如果新的角色集合不为空,且不为null,则角色进行了更新
                    StringBuilder oldRolesName = new StringBuilder("空");
                    StringBuilder newRolesName = new StringBuilder("空");
                    List<ManageRole> newRoles = null;
                    if (!ObjectUtils.isEmpty(updateForm.getRoleIds())) {
                        newRoles = manageRoleMapper.selectBatchIds(updateForm.getRoleIds());
                    }
                    if (!ObjectUtils.isEmpty(oldRoles)) {
                        oldRolesName.deleteCharAt(oldRolesName.length()-1);//删除 "空"
                        oldRolesName.append("[");
                        for (ManageRole role : oldRoles) {
                            oldRolesName.append(role.getName() + ",");
                        }
                        oldRolesName.deleteCharAt(oldRolesName.length() - 1);//移除最后一个逗号
                        oldRolesName.append("]");
                    }
                    if (!ObjectUtils.isEmpty(newRoles)) {
                        newRolesName.deleteCharAt(newRolesName.length()-1);//删除 "空"
                        newRolesName.append("[");
                        for (ManageRole role : newRoles) {
                            newRolesName.append(role.getName() + ",");
                        }
                        newRolesName.deleteCharAt(newRolesName.length() - 1);//移除最后一个逗号
                        newRolesName.append("]");
                    }
                    //拼接完整content
                    content.append(value+":"+oldRolesName + "->" + newRolesName + ";");
                }
            } else {//其他属性处理
                if (newParameters.get(key) != null) {
                    String newValue = "空";
                    String oldValue = "空";
                    if (newParameters.get(key) != null && !newParameters.get(key).equals(" ")) {
                        newValue = String.valueOf(newParameters.get(key));
                    }
                    if (oldParameters.get(key) != null && !oldParameters.get(key).equals(" ")) {
                        oldValue = String.valueOf(oldParameters.get(key));
                    }
                    content.append(value + ":" + oldValue + "->" + newValue + ";");
                }
            }
        }
        logUtils.saveOperationForManage(request, content.toString());
    }
}
screen-manage/src/main/java/com/moral/api/service/impl/ManageMenuServiceImpl.java
@@ -127,6 +127,8 @@
    @Override
    public List<ManageMenu> getParentChildrenMenusByRoles(List<ManageRole> roles) {
        List<ManageMenu> allMenus = manageMenuMapper.getAllMenusByRoles(roles);
        if(ObjectUtils.isEmpty(allMenus))
            return null;
        Map<Integer, ManageMenu> menusMap = new HashMap<>();
        for (ManageMenu menu : allMenus) {
            menu.setChildren(new ArrayList<>());//初始化
@@ -135,6 +137,7 @@
        for (ManageMenu menu : allMenus) {
            combinationParentChildrenMenus(menusMap, menu);
        }
        //已经封装好父子菜单,去除parentId不是0的菜单,去除重复
        allMenus.removeIf(new Predicate<ManageMenu>() {
            @Override
screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
@@ -108,7 +108,7 @@
        //操作插入日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        StringBuilder content = new StringBuilder();
        content.append("添加了组织:").append(organization.getName());
        content.append("添加了组织:").append(organization.getName()+";");
        logUtils.saveOperationForManage(request, content.toString());
        return organizationDTO;
    }
@@ -169,50 +169,7 @@
        organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        //操作插入日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        StringBuilder content = new StringBuilder();
        content.append("更新了组织:").append(organization.getName()).append(";");
        //更新对象转为Map
        Map<String, Object> newParameters = JSONObject.parseObject(JSON.toJSONString(organizationUpdateForm), Map.class);
        Map<String, Object> oldParameters = JSONObject.parseObject(JSON.toJSONString(existOrganization), Map.class);
        Set<String> keys = organizationFormMap.keySet();
        for (String key : keys) {
            String value = organizationFormMap.get(key);
            if ("parentName".equals(key)) {//更新父组织特殊处理
                if (organizationUpdateForm.getParentId() != null) {//判断父组织是否进行了更新
                    String oldParentName = "空";
                    String newParentName = "空";
                    if (!existOrganization.getParentId().equals(0)) {
                        oldParentName = organizationMapper.selectById(existOrganization.getParentId()).getName();
                    }
                    if (!organization.getParentId().equals(0)) {
                        newParentName = organizationMapper.selectById(organization.getParentId()).getName();
                    }
                    content.append(value + ":" + oldParentName + "->" + newParentName + ";");
                }
            } else if ("expireTime".equals(key)) {//expireTime时间格式特殊处理
                if (organizationUpdateForm.getExpireTime() != null) {
                    Date oldExpireTime = existOrganization.getExpireTime();
                    Date newExpireTime = organization.getExpireTime();
                    String oldExpireTimeStr = DateUtils.dateToDateString(oldExpireTime, "yyyy-MM-dd");
                    String newExpireTimeStr = DateUtils.dateToDateString(newExpireTime, "yyyy-MM-dd");
                    content.append(value + ":" + oldExpireTimeStr + "->" + newExpireTimeStr + ";");
                }
            } else {//处理其他属性
                if (newParameters.get(key) != null) {
                    String newValue = "空";
                    String oldValue = "空";
                    if (newParameters.get(key) != null && !newParameters.get(key).equals(" ")) {
                        newValue = String.valueOf(newParameters.get(key));
                    }
                    if (oldParameters.get(key) != null && !oldParameters.get(key).equals(" ")) {
                        oldValue = String.valueOf(oldParameters.get(key));
                    }
                    content.append(value + ":" + oldValue + "->" + newValue + ";");
                }
            }
        }
        logUtils.saveOperationForManage(request, content.toString());
        insertUpdateLog(organizationUpdateForm,organization,existOrganization);
        return organizationDTO;
    }
@@ -267,9 +224,9 @@
        //操作插入日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        StringBuilder content = new StringBuilder();
        content.append("删除了组织:").append(existOrganization.getName());
        content.append("删除了组织:").append(existOrganization.getName()+";");
        if(form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG))
            content.append("以及所有子组织");
            content.append("以及所有子组织;");
        logUtils.saveOperationForManage(request, content.toString());
        return dto;
@@ -360,6 +317,7 @@
        return dto;
    }
    /**
     * @Description: 将organization的address字段与provinceName cityName areaName进行拼接
     * @Param: [organization]
@@ -367,7 +325,7 @@
     * @Author: 陈凯裕
     * @Date: 2021/4/2
     */
    public void changeAddressByOrganization(Organization organization) {
    private void changeAddressByOrganization(Organization organization) {
        String provinceName = organization.getProvinceName();
        String cityName = organization.getCityName();
        String areaName = organization.getAreaName();
@@ -385,4 +343,62 @@
        organization.setAddress(newAddress.toString());
    }
    /**
    * @Description: 将更新操作插入日志
            * @Param: [updateForm, newOrganization, oldOrganization]
            * @return: void
            * @Author: 陈凯裕
            * @Date: 2021/4/8
            */
    private void insertUpdateLog(OrganizationUpdateForm updateForm,Organization newOrganization,Organization oldOrganization){
        //操作插入日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        StringBuilder content = new StringBuilder();
        content.append("修改了组织:").append(oldOrganization.getName()).append(";");
        //对象转为Map,获取对象更新前后的属性
        Map<String, Object> newParameters = JSONObject.parseObject(JSON.toJSONString(updateForm), Map.class);
        Map<String, Object> oldParameters = JSONObject.parseObject(JSON.toJSONString(oldOrganization), Map.class);
        //遍历配置文件中的Map,将属性转化为汉字
        Set<String> keys = organizationFormMap.keySet();
        for (String key : keys) {
            String value = organizationFormMap.get(key);//属性对应的汉字
            if ("parentName".equals(key)) {//更新父组织特殊处理
                if (updateForm.getParentId() != null) {//判断父组织是否进行了更新
                    String oldParentName = "空";
                    String newParentName = "空";
                    if (!oldOrganization.getParentId().equals(0)) {
                        oldParentName = organizationMapper.selectById(oldOrganization.getParentId()).getName();
                    }
                    if (!newOrganization.getParentId().equals(0)) {
                        newParentName = organizationMapper.selectById(newOrganization.getParentId()).getName();
                    }
                    content.append(value + ":" + oldParentName + "->" + newParentName + ";");
                }
            } else if ("expireTime".equals(key)) {//expireTime时间格式特殊处理
                if (updateForm.getExpireTime() != null) {
                    Date oldExpireTime = oldOrganization.getExpireTime();
                    Date newExpireTime = newOrganization.getExpireTime();
                    String oldExpireTimeStr = DateUtils.dateToDateString(oldExpireTime, "yyyy-MM-dd");
                    String newExpireTimeStr = DateUtils.dateToDateString(newExpireTime, "yyyy-MM-dd");
                    content.append(value + ":" + oldExpireTimeStr + "->" + newExpireTimeStr + ";");
                }
            } else {//处理其他属性
                if (newParameters.get(key) != null) {
                    String newValue = "空";
                    String oldValue = "空";
                    if (newParameters.get(key) != null && !newParameters.get(key).equals(" ")) {
                        newValue = String.valueOf(newParameters.get(key));
                    }
                    if (oldParameters.get(key) != null && !oldParameters.get(key).equals(" ")) {
                        oldValue = String.valueOf(oldParameters.get(key));
                    }
                    content.append(value + ":" + oldValue + "->" + newValue + ";");
                }
            }
        }
        logUtils.saveOperationForManage(request, content.toString());
    }
}
screen-manage/src/main/java/com/moral/api/util/LogUtils.java
@@ -7,6 +7,7 @@
import com.moral.util.TokenUtils;
import com.moral.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -25,6 +26,13 @@
    @Autowired
    public ManageLogMapper manageLogMapper;
    /**
    * @Description: 通用插入日志
            * @Param: [request, content]
            * @return: void
            * @Author: 陈凯裕
            * @Date: 2021/4/8
            */
    @Transactional
    public void saveOperationForManage(HttpServletRequest request, String content) {
        String token = request.getHeader("token");
@@ -35,10 +43,29 @@
        String ip = WebUtils.getIpAddr(request);
        ManageLog log = new ManageLog();
        log.setUserName(userName);
        log.setAccountId(id);
        log.setIp(ip);
        log.setContent(content);
        manageLogMapper.insert(log);
    }
    /**
    * @Description: 插入登陆操作日志
            * @Param: [request, content, id, userName]
            * @return: void
            * @Author: 陈凯裕
            * @Date: 2021/4/8
            */
    @Transactional
    public void saveLoginForManage(HttpServletRequest request,String content,Integer id,String userName){
        ManageLog log = new ManageLog();
        String ip = WebUtils.getIpAddr(request);
        log.setAccountId(id);
        log.setUserName(userName);
        log.setIp(ip);
        log.setContent(content);
        manageLogMapper.insert(log);
    }
}
screen-manage/src/main/resources/application-moduleFormColumn.yml
@@ -12,6 +12,13 @@
    email: 邮箱
    wechat: 微信
    expireTime: 过期时间
  manage-account-form-map:
    userName: 名称
    password: 密码
    email: 邮箱
    mobile: 手机号
    wechat: 微信
    roleIds: 角色