feat(bizLog): 新增业务日志模块

- 添加业务日志相关实体、DTO、控制器、服务、仓库和映射器- 实现业务日志的创建、更新、删除、查询等功能- 添加业务日志字典脚本
This commit is contained in:
2025-05-09 20:25:50 +08:00
parent 69035a7f59
commit b49cba82e4
9 changed files with 388 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
package cn.lihongjie.coal.bizLog.controller;
import cn.lihongjie.coal.annotation.OrgScope;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.bizLog.dto.BizLogDto;
import cn.lihongjie.coal.bizLog.dto.CreateBizLogDto;
import cn.lihongjie.coal.bizLog.dto.UpdateBizLogDto;
import cn.lihongjie.coal.bizLog.service.BizLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/bizLog")
@SysLog(module = "业务日志")
@Slf4j
@OrgScope
public class BizLogController {
@Autowired private BizLogService service;
@PostMapping("/create")
public BizLogDto create(@RequestBody CreateBizLogDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public BizLogDto update(@RequestBody UpdateBizLogDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public BizLogDto getById(@RequestBody IdRequest request) {
return this.service.getById(request.getId());
}
@PostMapping("/list")
public Page<BizLogDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

@@ -0,0 +1,61 @@
package cn.lihongjie.coal.bizLog.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDateTime;
@Data
public class BizLogDto extends OrgCommonDto {
@Comment("一级菜单")
private String level1;
@Comment("二级菜单")
private String level2;
@Comment("三级菜单")
private String level3;
@Comment("四级菜单")
private String level4;
@Comment("五级菜单")
private String level5;
@Comment("功能点")
private String functionPoint;
@Comment("操作类型 查看/新增/修改/删除")
private String operationType;
@Comment("操作明细")
private String operationDetail;
@Comment("操作时间")
private LocalDateTime operationTime;
@Comment("之前版本")
private String beforeVersion;
@Comment("当前版本")
private String currentVersion;
@Comment("备用字段1")
private String reverse1;
@Comment("备用字段2")
private String reverse2;
@Comment("备用字段3")
private String reverse3;
@Comment("备用字段4")
private String reverse4;
@Comment("备用字段5")
private String reverse5;
}

View File

@@ -0,0 +1,62 @@
package cn.lihongjie.coal.bizLog.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDateTime;
@Data
public class CreateBizLogDto extends OrgCommonDto {
@Comment("一级菜单")
private String level1;
@Comment("二级菜单")
private String level2;
@Comment("三级菜单")
private String level3;
@Comment("四级菜单")
private String level4;
@Comment("五级菜单")
private String level5;
@Comment("功能点")
private String functionPoint;
@Comment("操作类型 查看/新增/修改/删除")
private String operationType;
@Comment("操作明细")
private String operationDetail;
@Comment("操作时间")
private LocalDateTime operationTime;
@Comment("之前版本")
private String beforeVersion;
@Comment("当前版本")
private String currentVersion;
@Comment("备用字段1")
private String reverse1;
@Comment("备用字段2")
private String reverse2;
@Comment("备用字段3")
private String reverse3;
@Comment("备用字段4")
private String reverse4;
@Comment("备用字段5")
private String reverse5;
}

View File

@@ -0,0 +1,8 @@
package cn.lihongjie.coal.bizLog.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
@Data
public class UpdateBizLogDto extends OrgCommonDto {}

View File

@@ -0,0 +1,70 @@
package cn.lihongjie.coal.bizLog.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDateTime;
@Data
@Entity
@Table(
indexes =
@jakarta.persistence.Index(
name = "idx_bizLog_org_id",
columnList = "organization_id"))
public class BizLogEntity extends OrgCommonEntity {
@Comment("一级菜单")
private String level1;
@Comment("二级菜单")
private String level2;
@Comment("三级菜单")
private String level3;
@Comment("四级菜单")
private String level4;
@Comment("五级菜单")
private String level5;
@Comment("功能点")
private String functionPoint;
@Comment("操作类型 查看/新增/修改/删除")
private String operationType;
@Comment("操作明细")
private String operationDetail;
@Comment("操作时间")
private LocalDateTime operationTime;
@Comment("之前版本")
private String beforeVersion;
@Comment("当前版本")
private String currentVersion;
@Comment("备用字段1")
private String reverse1;
@Comment("备用字段2")
private String reverse2;
@Comment("备用字段3")
private String reverse3;
@Comment("备用字段4")
private String reverse4;
@Comment("备用字段5")
private String reverse5;
}

View File

@@ -0,0 +1,19 @@
package cn.lihongjie.coal.bizLog.mapper;
import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.bizLog.dto.BizLogDto;
import cn.lihongjie.coal.bizLog.dto.CreateBizLogDto;
import cn.lihongjie.coal.bizLog.dto.UpdateBizLogDto;
import cn.lihongjie.coal.bizLog.entity.BizLogEntity;
import org.mapstruct.Mapper;
import org.mapstruct.control.DeepClone;
@Mapper(
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class, CommonEntityMapper.class},
mappingControl = DeepClone.class)
public interface BizLogMapper
extends BaseMapper<BizLogEntity, BizLogDto, CreateBizLogDto, UpdateBizLogDto> {}

View File

@@ -0,0 +1,15 @@
package cn.lihongjie.coal.bizLog.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.bizLog.entity.BizLogEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface BizLogRepository extends BaseRepository<BizLogEntity> {
@Query("select false")
boolean isLinked(List<String> ids);
}

View File

@@ -0,0 +1,80 @@
package cn.lihongjie.coal.bizLog.service;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.bizLog.dto.BizLogDto;
import cn.lihongjie.coal.bizLog.dto.CreateBizLogDto;
import cn.lihongjie.coal.bizLog.dto.UpdateBizLogDto;
import cn.lihongjie.coal.bizLog.entity.BizLogEntity;
import cn.lihongjie.coal.bizLog.mapper.BizLogMapper;
import cn.lihongjie.coal.bizLog.repository.BizLogRepository;
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
import cn.lihongjie.coal.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Slf4j
@Transactional
public class BizLogService extends BaseService<BizLogEntity, BizLogRepository> {
@Autowired private BizLogRepository repository;
@Autowired private BizLogMapper mapper;
@Autowired private ConversionService conversionService;
@Autowired private DbFunctionService dbFunctionService;
public BizLogDto create(CreateBizLogDto request) {
BizLogEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public BizLogDto update(UpdateBizLogDto request) {
BizLogEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
this.repository.save(entity);
return getById(entity.getId());
}
public void delete(IdRequest request) {
boolean linked = this.repository.isLinked(request.getIds());
if (linked) {
throw new BizException("数据已被关联,无法删除");
}
this.repository.deleteAllById(request.getIds());
}
public BizLogDto getById(String id) {
BizLogEntity entity = repository.get(id);
return mapper.toDto(entity);
}
public Page<BizLogDto> list(CommonQuery query) {
Page<BizLogEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
}

View File

@@ -0,0 +1,19 @@
package scripts.dict
import cn.lihongjie.coal.base.dto.CommonQuery
import cn.lihongjie.coal.bizLog.controller.BizLogController
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.context.ApplicationContext
ApplicationContext ioc = ioc
def controller = ioc.getBean(BizLogController.class)
def objectMapper = ioc.getBean(ObjectMapper.class) as ObjectMapper
return controller.list(params!=null ? objectMapper.convertValue(params, CommonQuery.class ) : new CommonQuery())