screen-manage
修改日志插入工具类
规范日志插入格式
2 files deleted
2 files added
17 files modified
| | |
| | | public static final String VERIFICATION_TYPE = "front_verificationCode"; |
| | | |
| | | /* |
| | | * 添加操作类型 |
| | | * 登陆操作字典Key |
| | | * */ |
| | | public static final String INSERT_OPERATE_TYPE = "添加"; |
| | | public static final String LOGIN_OPERTATE_TYPE = "0"; |
| | | |
| | | /* |
| | | * 删除操作类型 |
| | | * 添加操作类型 |
| | | * */ |
| | | public static final String DELETE_OPERATE_TYPE = "删除"; |
| | | public static final String INSERT_OPERATE_TYPE = "1"; |
| | | |
| | | /* |
| | | * 更新操作类型 |
| | | * */ |
| | | public static final String UPDATE_OPERATE_TYPE = "更新"; |
| | | public static final String UPDATE_OPERATE_TYPE = "2"; |
| | | |
| | | /* |
| | | * 查询操作类型 |
| | | * 删除操作类型 |
| | | * */ |
| | | public static final String QUERY_OPERATE_TYPE = "查询"; |
| | | public static final String DELETE_OPERATE_TYPE = "3"; |
| | | |
| | | /* |
| | | * Organization模块名称 |
| | | * */ |
| | | public static final String ORGANIZATION_MODULE_NAME = "组织"; |
| | | |
| | | |
| | | } |
| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.moral.api.entity.SysArea; |
| | | import com.moral.api.pojo.dto.account.*; |
| | | import com.moral.api.pojo.dto.organization.OrganizationDTO; |
| | | import com.moral.api.pojo.form.account.AccountDeleteForm; |
| | |
| | | import com.moral.api.pojo.vo.account.AccountQueryVO; |
| | | import com.moral.api.pojo.vo.account.AccountUpdateVO; |
| | | import com.moral.api.service.ManageAccountService; |
| | | import com.moral.api.service.SysAreaService; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import io.swagger.annotations.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Api(tags = {"后台账户管理"}) |
| | |
| | | |
| | | return new ResultMessage(accountQueryDTO.getCode(), accountQueryDTO.getMsg(), accountQueryVO); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.moral.api.aop.log.OperationLogAnno; |
| | | import com.moral.api.pojo.dto.organization.OrganizationDTO; |
| | | import com.moral.api.pojo.dto.organization.OrganizationQueryDTO; |
| | | import com.moral.api.pojo.form.organization.OrganizationDeleteForm; |
| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.moral.api.entity.SysArea; |
| | | import com.moral.api.pojo.dto.login.AccountInfoDTO; |
| | | import com.moral.api.pojo.dto.system.ManageLogQueryDTO; |
| | | import com.moral.api.pojo.form.system.ManageLogQueryForm; |
| | | import com.moral.api.service.ManageLogService; |
| | | import com.moral.api.service.SysAreaService; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import io.swagger.annotations.Api; |
| | | import com.moral.util.TokenUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | |
| | | * @Version TODO |
| | | **/ |
| | | @Slf4j |
| | | @Api(tags = {"用户组织控制器"}) |
| | | @CrossOrigin(origins = "*", maxAge = 3600) |
| | | @RestController |
| | | @CrossOrigin(origins = "*", maxAge = 3600) |
| | | @RequestMapping("/system") |
| | | public class SystemController { |
| | | |
| | | @Autowired |
| | | SysAreaService sysAreaService; |
| | | |
| | | @Autowired |
| | | ManageLogService manageLogService; |
| | | |
| | | @GetMapping("area/query") |
| | | public ResultMessage query(){ |
| | | public ResultMessage queryArea() { |
| | | List<SysArea> sysAreas = sysAreaService.querySysArea(); |
| | | return ResultMessage.ok(sysAreas); |
| | | } |
| | | |
| | | @GetMapping("log/query") |
| | | public ResultMessage queryLog(ManageLogQueryForm form) { |
| | | |
| | | //判断是否缺少参数 |
| | | if (!form.valid()) |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | |
| | | //处理查询业务 |
| | | ManageLogQueryDTO dto = manageLogService.queryManageLog(form); |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import java.time.LocalDateTime; |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | |
| | |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-04-02 |
| | | * @since 2021-04-12 |
| | | */ |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | |
| | | */ |
| | | private Integer accountId; |
| | | |
| | | /* |
| | | * 操作人员账号 |
| | | * */ |
| | | private String account; |
| | | |
| | | /** |
| | | * 操作人员 |
| | | */ |
| | | private String userName; |
| | | |
| | | /** |
| | | * 操作类型 |
| | | */ |
| | | private String type; |
| | | |
| | | |
| | | /** |
| | | * 操作描述 |
| | |
| | | /** |
| | | * 操作时间 |
| | | */ |
| | | private LocalDateTime createTime; |
| | | private Date createTime; |
| | | |
| | | |
| | | @Override |
| | |
| | | */ |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | | @JsonInclude(JsonInclude.Include.NON_EMPTY) |
| | | public class ManageRole extends Model<ManageRole> { |
| | | |
| | | |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-04-02 |
| | | * @since 2021-04-12 |
| | | */ |
| | | public interface ManageLogMapper extends BaseMapper<ManageLog> { |
| | | |
New file |
| | |
| | | package com.moral.api.pojo.dto.system; |
| | | |
| | | import com.moral.api.entity.ManageLog; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @ClassName ManageLogQueryDTO |
| | | * @Description TODO |
| | | * @Author 陈凯裕 |
| | | * @Date 2021/4/12 13:23 |
| | | * @Version TODO |
| | | **/ |
| | | @Data |
| | | public class ManageLogQueryDTO { |
| | | |
| | | private Integer code; |
| | | |
| | | private String msg; |
| | | |
| | | private long page; |
| | | |
| | | private long total; |
| | | |
| | | private long current; |
| | | |
| | | private long size; |
| | | |
| | | private List<ManageLog> manageLogs; |
| | | } |
| | |
| | | package com.moral.api.pojo.form.organization; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.pojo.dto.organization.OrganizationDTO; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.DateUtils; |
| | | import com.moral.util.RegexUtils; |
| | | import lombok.Data; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.io.Serializable; |
| | |
| | | |
| | | private String wechat; |
| | | |
| | | private String expireTime; |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") |
| | | private Date expireTime; |
| | | |
| | | public boolean valid() { |
| | | if ( |
| | |
| | | organization.setPhone(phone); |
| | | organization.setEmail(email); |
| | | organization.setWechat(wechat); |
| | | Date expireTimeDate = DateUtils.getDate(expireTime + " 00:00:00", "yyyy-MM-dd HH:mm:ss"); |
| | | organization.setExpireTime(expireTimeDate); |
| | | organization.setExpireTime(expireTime); |
| | | return organization; |
| | | } |
| | | |
| | |
| | | return dto; |
| | | } |
| | | } |
| | | //判断过期时间格式 |
| | | if (!RegexUtils.checkDate(expireTime)) { |
| | | dto.setCode(ResponseCodeEnum.TIME_FORMAT_INVALID.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.TIME_FORMAT_INVALID.getMsg()); |
| | | return dto; |
| | | } |
| | | //判断过期时间是否小于当前时间 |
| | | Date expireDate = DateUtils.getDate(expireTime, "yyyy-MM-dd"); |
| | | Date currentDate = new Date(); |
| | | if (DateUtils.compareDateStr(expireDate, currentDate) >= 0) { |
| | | if (DateUtils.compareDateStr(expireTime, currentDate) >= 0) { |
| | | dto.setCode(ResponseCodeEnum.TIME_INVALID.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.TIME_INVALID.getMsg()); |
| | | return dto; |
| | |
| | | package com.moral.api.pojo.form.organization; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.pojo.dto.organization.OrganizationDTO; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.DateUtils; |
| | | import com.moral.util.RegexUtils; |
| | | import lombok.Data; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.Date; |
| | |
| | | |
| | | private String wechat; |
| | | |
| | | private String expireTime; |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") |
| | | private Date expireTime; |
| | | |
| | | public boolean valid() { |
| | | if (ObjectUtils.isEmpty(organizationId)) |
| | |
| | | organization.setPhone(phone); |
| | | organization.setEmail(email); |
| | | organization.setWechat(wechat); |
| | | if (!ObjectUtils.isEmpty(expireTime)) { |
| | | Date expireTimeDate = DateUtils.getDate(expireTime + " 00:00:00", "yyyy-MM-dd HH:mm:ss"); |
| | | organization.setExpireTime(expireTimeDate); |
| | | } |
| | | organization.setExpireTime(expireTime); |
| | | |
| | | return organization; |
| | | } |
| | | |
| | |
| | | return dto; |
| | | } |
| | | } |
| | | //判断过期时间格式 |
| | | if (!ObjectUtils.isEmpty(expireTime)) { |
| | | if (!RegexUtils.checkDate(expireTime)) { |
| | | dto.setCode(ResponseCodeEnum.TIME_FORMAT_INVALID.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.TIME_FORMAT_INVALID.getMsg()); |
| | | return dto; |
| | | } |
| | | //判断过期时间是否小于当前时间 |
| | | Date expireDate = DateUtils.getDate(expireTime, "yyyy-MM-dd"); |
| | | if (!ObjectUtils.isEmpty(expireTime)) { |
| | | Date currentDate = new Date(); |
| | | if (DateUtils.compareDateStr(expireDate, currentDate) >= 0) { |
| | | if (DateUtils.compareDateStr(expireTime, currentDate) >= 0) { |
| | | dto.setCode(ResponseCodeEnum.TIME_INVALID.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.TIME_INVALID.getMsg()); |
| | | return dto; |
New file |
| | |
| | | package com.moral.api.pojo.form.system; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @ClassName ManageLogQueryForm |
| | | * @Description TODO |
| | | * @Author 陈凯裕 |
| | | * @Date 2021/4/12 9:33 |
| | | * @Version TODO |
| | | **/ |
| | | public class ManageLogQueryForm { |
| | | |
| | | private Integer page; |
| | | |
| | | private Integer size; |
| | | |
| | | private String id; |
| | | |
| | | private String type; |
| | | |
| | | private String ip; |
| | | |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") |
| | | private Date startTime; |
| | | |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") |
| | | private Date endTime; |
| | | |
| | | public boolean valid() { |
| | | if ( |
| | | ObjectUtils.isEmpty(page) || |
| | | ObjectUtils.isEmpty(size) |
| | | ) |
| | | return false; |
| | | return true; |
| | | } |
| | | } |
| | |
| | | AccountInsertVO vo = new AccountInsertVO(); |
| | | ManageAccount account = dto.getAccount(); |
| | | List<ManageRole> roles = dto.getRoles(); |
| | | List<String> roleNames = new ArrayList<>(); |
| | | if (!ObjectUtils.isEmpty(roles)) { |
| | | roles.forEach(role -> roleNames.add(role.getName())); |
| | | roles.forEach(value-> { |
| | | value.setIsDelete(null); |
| | | value.setCreateTime(null); |
| | | value.setUpdateTime(null); |
| | | value.setDesc(null); |
| | | }); |
| | | } |
| | | vo.setId(account.getId()); |
| | | vo.setUserName(account.getUserName()); |
| | | vo.setEmail(account.getEmail()); |
| | | vo.setMobile(account.getMobile()); |
| | | vo.setWechat(account.getWechat()); |
| | | vo.setRoleNames(roleNames); |
| | | vo.setRoles(roles); |
| | | //Date转换String |
| | | Date createTime = account.getCreateTime(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | |
| | | |
| | | private String wechat; |
| | | |
| | | private List<ManageRole> roles; |
| | | |
| | | private List<String> roleNames; |
| | | |
| | | private String createTime; |
| | | |
| | | private String updateTime; |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | import com.moral.api.entity.ManageLog; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.moral.api.pojo.dto.system.ManageLogQueryDTO; |
| | | import com.moral.api.pojo.form.system.ManageLogQueryForm; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-04-02 |
| | | * @since 2021-04-12 |
| | | */ |
| | | public interface ManageLogService extends IService<ManageLog> { |
| | | |
| | | ManageLogQueryDTO queryManageLog(ManageLogQueryForm form); |
| | | } |
| | |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append(manageAccount.getUserName()).append("登陆了后台系统;"); |
| | | logUtils.saveLoginForManage(request, content.toString(), manageAccount.getId(), manageAccount.getUserName()); |
| | | logUtils.saveLoginForManage(request, content.toString(), manageAccount, manageAccount.getUserName()); |
| | | |
| | | return loginDTO; |
| | | } |
| | |
| | | //操作插入日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("添加了账号:").append(manageAccount.getUserName() + ";") |
| | | .append("id:" + manageAccount.getId() + ";"); |
| | | logUtils.saveOperationForManage(request, content.toString()); |
| | | content.append("添加了用户:").append(manageAccount.getUserName() + ";") |
| | | .append("account:" + manageAccount.getAccount() + ";"); |
| | | logUtils.saveOperationForManage(request, content.toString(),Constants.INSERT_OPERATE_TYPE); |
| | | |
| | | return accountDTO; |
| | | } |
| | |
| | | //操作插入日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("删除了账号:").append(existManageAccount.getUserName() + ";") |
| | | .append("id:" + existManageAccount.getId() + ";"); |
| | | logUtils.saveOperationForManage(request, content.toString()); |
| | | content.append("删除了用户:").append(existManageAccount.getUserName() + ";") |
| | | .append("账号:" + existManageAccount.getAccount() + ";"); |
| | | logUtils.saveOperationForManage(request, content.toString(),Constants.DELETE_OPERATE_TYPE); |
| | | |
| | | return accountDTO; |
| | | } |
| | |
| | | //操作插入日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("修改了账号:").append(oldAccount.getUserName() + ";") |
| | | .append("id:" + oldAccount.getId() + ";"); |
| | | content.append("修改了用户:").append(oldAccount.getUserName() + ";") |
| | | .append("账号:" + oldAccount.getAccount() + ";"); |
| | | //对象转为Map,获取对象更新前后的属性 |
| | | Map<String, Object> newParameters = JSONObject.parseObject(JSON.toJSONString(updateForm), Map.class); |
| | | Map<String, Object> oldParameters = JSONObject.parseObject(JSON.toJSONString(oldAccount), Map.class); |
| | |
| | | } |
| | | } |
| | | } |
| | | logUtils.saveOperationForManage(request, content.toString()); |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | import com.moral.api.entity.ManageLog; |
| | | import com.moral.api.mapper.ManageLogMapper; |
| | | import com.moral.api.pojo.dto.system.ManageLogQueryDTO; |
| | | import com.moral.api.pojo.form.system.ManageLogQueryForm; |
| | | import com.moral.api.service.ManageLogService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-04-02 |
| | | * @since 2021-04-12 |
| | | */ |
| | | @Service |
| | | public class ManageLogServiceImpl extends ServiceImpl<ManageLogMapper, ManageLog> implements ManageLogService { |
| | | |
| | | @Override |
| | | public ManageLogQueryDTO queryManageLog(ManageLogQueryForm form) { |
| | | return null; |
| | | } |
| | | } |
| | |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("添加了组织:").append(organization.getName()+";"); |
| | | logUtils.saveOperationForManage(request, content.toString()); |
| | | logUtils.saveOperationForManage(request, content.toString(),Constants.INSERT_OPERATE_TYPE); |
| | | return organizationDTO; |
| | | } |
| | | |
| | |
| | | content.append("删除了组织:").append(existOrganization.getName()+";"); |
| | | if(form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)) |
| | | content.append("以及所有子组织;"); |
| | | logUtils.saveOperationForManage(request, content.toString()); |
| | | logUtils.saveOperationForManage(request, content.toString(),Constants.DELETE_OPERATE_TYPE); |
| | | |
| | | return dto; |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | logUtils.saveOperationForManage(request, content.toString()); |
| | | logUtils.saveOperationForManage(request, content.toString(),Constants.UPDATE_OPERATE_TYPE); |
| | | } |
| | | |
| | | |
| | |
| | | import com.moral.api.entity.ManageLog; |
| | | import com.moral.api.mapper.ManageLogMapper; |
| | | import com.moral.api.pojo.dto.login.AccountInfoDTO; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.TokenUtils; |
| | | import com.moral.util.WebUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | * @Date: 2021/4/8 |
| | | */ |
| | | @Transactional |
| | | public void saveOperationForManage(HttpServletRequest request, String content) { |
| | | public void saveOperationForManage(HttpServletRequest request, String content,String type) { |
| | | String token = request.getHeader("token"); |
| | | AccountInfoDTO accountInfoDTO = (AccountInfoDTO) TokenUtils.getUserInfoByToken(token); |
| | | ManageAccount account = accountInfoDTO.getAccount(); |
| | | Integer id = account.getId(); |
| | | String userName = account.getUserName(); |
| | | ManageAccount manageAccount = accountInfoDTO.getAccount(); |
| | | Integer id = manageAccount.getId(); |
| | | String userName = manageAccount.getUserName(); |
| | | String account = manageAccount.getAccount(); |
| | | String ip = WebUtils.getIpAddr(request); |
| | | |
| | | ManageLog log = new ManageLog(); |
| | | log.setType(type); |
| | | log.setUserName(userName); |
| | | log.setAccountId(id); |
| | | log.setIp(ip); |
| | | log.setAccount(account); |
| | | log.setContent(content); |
| | | manageLogMapper.insert(log); |
| | | } |
| | |
| | | * @Date: 2021/4/8 |
| | | */ |
| | | @Transactional |
| | | public void saveLoginForManage(HttpServletRequest request,String content,Integer id,String userName){ |
| | | public void saveLoginForManage(HttpServletRequest request,String content,ManageAccount account,String userName){ |
| | | ManageLog log = new ManageLog(); |
| | | String ip = WebUtils.getIpAddr(request); |
| | | |
| | | log.setAccountId(id); |
| | | log.setAccountId(account.getId()); |
| | | log.setAccount(account.getAccount()); |
| | | log.setUserName(userName); |
| | | log.setIp(ip); |
| | | log.setContent(content); |
| | | log.setType(Constants.LOGIN_OPERTATE_TYPE); |
| | | manageLogMapper.insert(log); |
| | | } |
| | | } |
| | |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.ManageLog"> |
| | | <id column="id" property="id" /> |
| | | <result column="account_id" property="accountId" /> |
| | | <result column="type" property="type" /> |
| | | <result column="user_name" property="userName" /> |
| | | <result column="content" property="content" /> |
| | | <result column="ip" property="ip" /> |