SysLogService.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package cc.uncarbon.module.sys.service;
  2. import cc.uncarbon.framework.core.page.PageParam;
  3. import cc.uncarbon.framework.core.page.PageResult;
  4. import cc.uncarbon.framework.crud.service.impl.HelioBaseServiceImpl;
  5. import cc.uncarbon.module.sys.entity.SysLogEntity;
  6. import cc.uncarbon.module.sys.enums.SysErrorEnum;
  7. import cc.uncarbon.module.sys.mapper.SysLogMapper;
  8. import cc.uncarbon.module.sys.model.request.AdminListSysLogDTO;
  9. import cc.uncarbon.module.sys.model.response.SysLogBO;
  10. import cn.hutool.core.bean.BeanUtil;
  11. import cn.hutool.core.util.ObjectUtil;
  12. import cn.hutool.core.util.StrUtil;
  13. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  14. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.stereotype.Service;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. /**
  20. * 后台操作日志
  21. * @author Uncarbon
  22. */
  23. @Slf4j
  24. @Service
  25. public class SysLogService extends HelioBaseServiceImpl<SysLogMapper, SysLogEntity> {
  26. /**
  27. * 后台管理-分页列表
  28. */
  29. public PageResult<SysLogBO> adminList(PageParam pageParam, AdminListSysLogDTO dto) {
  30. Page<SysLogEntity> entityPage = this.page(
  31. new Page<>(pageParam.getPageNum(), pageParam.getPageSize()),
  32. new QueryWrapper<SysLogEntity>()
  33. .lambda()
  34. // 用户账号
  35. .like(StrUtil.isNotBlank(dto.getUsername()), SysLogEntity::getUsername, StrUtil.cleanBlank(dto.getUsername()))
  36. // 操作内容
  37. .like(StrUtil.isNotBlank(dto.getOperation()), SysLogEntity::getOperation, StrUtil.cleanBlank(dto.getOperation()))
  38. // 状态
  39. .eq(ObjectUtil.isNotNull(dto.getStatus()), SysLogEntity::getStatus, dto.getStatus())
  40. // 时间区间
  41. .between(ObjectUtil.isNotNull(dto.getBeginAt()) && ObjectUtil.isNotNull(dto.getEndAt()), SysLogEntity::getCreatedAt, dto.getBeginAt(), dto.getEndAt())
  42. // 排序
  43. .orderByDesc(SysLogEntity::getCreatedAt)
  44. );
  45. return this.entityPage2BOPage(entityPage);
  46. }
  47. /**
  48. * 通用-详情
  49. */
  50. public SysLogBO getOneById(Long entityId) {
  51. SysLogEntity entity = this.getById(entityId);
  52. SysErrorEnum.INVALID_ID.assertNotNull(entity);
  53. return this.entity2BO(entity);
  54. }
  55. /*
  56. 私有方法
  57. ------------------------------------------------------------------------------------------------
  58. */
  59. private SysLogBO entity2BO(SysLogEntity entity) {
  60. if (entity == null) {
  61. return null;
  62. }
  63. SysLogBO bo = new SysLogBO();
  64. BeanUtil.copyProperties(entity, bo);
  65. // 可以在此处为BO填充字段
  66. return bo;
  67. }
  68. private List<SysLogBO> entityList2BOs(List<SysLogEntity> entityList) {
  69. // 深拷贝
  70. List<SysLogBO> ret = new ArrayList<>(entityList.size());
  71. entityList.forEach(
  72. entity -> ret.add(this.entity2BO(entity))
  73. );
  74. return ret;
  75. }
  76. private PageResult<SysLogBO> entityPage2BOPage(Page<SysLogEntity> entityPage) {
  77. PageResult<SysLogBO> ret = new PageResult<>();
  78. BeanUtil.copyProperties(entityPage, ret);
  79. ret.setRecords(this.entityList2BOs(entityPage.getRecords()));
  80. return ret;
  81. }
  82. }