添加操作日志服务.

This commit is contained in:
lijiahang
2023-10-11 15:54:06 +08:00
parent 2028d1ee0f
commit 730a20a3e2
12 changed files with 117 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
package ${package.Controller};
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
import com.orion.ops.framework.common.validator.group.Page;
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
@@ -48,6 +49,7 @@ public class ${table.controllerName} {
@Resource
private ${type}Service ${typeLower}Service;
@OperatorLog(${type}OperatorType.CREATE)
@PostMapping("/create")
@Operation(summary = "${apiComment.create}")
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:create')")
@@ -55,6 +57,7 @@ public class ${table.controllerName} {
return ${typeLower}Service.create${type}(request);
}
@OperatorLog(${type}OperatorType.UPDATE)
@PutMapping("/update")
@Operation(summary = "${apiComment.updateById}")
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:update')")
@@ -96,6 +99,7 @@ public class ${table.controllerName} {
return ${typeLower}Service.get${type}Page(request);
}
@OperatorLog(${type}OperatorType.DELETE)
@DeleteMapping("/delete")
@Operation(summary = "${apiComment.deleteById}")
@Parameter(name = "id", description = "id", required = true)
@@ -104,6 +108,7 @@ public class ${table.controllerName} {
return ${typeLower}Service.delete${type}ById(id);
}
@OperatorLog(${type}OperatorType.DELETE)
@DeleteMapping("/batch-delete")
@Operation(summary = "${apiComment.batchDelete}")
@Parameter(name = "idList", description = "idList", required = true)
@@ -112,6 +117,7 @@ public class ${table.controllerName} {
return ${typeLower}Service.batchDelete${type}ByIdList(idList);
}
@OperatorLog(${type}OperatorType.EXPORT)
@PostMapping("/export")
@Operation(summary = "${apiComment.export}")
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:export')")

View File

@@ -0,0 +1,33 @@
package ${currentPackage};
import com.orion.ops.framework.biz.operator.log.core.model.OperatorType;
import static com.orion.ops.framework.biz.operator.log.core.holder.OperatorTypeHolder.set;
/**
* $!{table.comment} 操作日志类型
*
* @author ${author}
* @version ${since}
* @since ${date}
*/
public class ${type}OperatorType {
private static final String MODULE = "${package.ModuleName}:${typeHyphen}";
public static final String CREATE = "${typeHyphen}:create";
public static final String UPDATE = "${typeHyphen}:update";
public static final String DELETE = "${typeHyphen}:delete";
public static final String EXPORT = "${typeHyphen}:export";
public static void init() {
set(new OperatorType(MODULE, CREATE, "创建$!{table.comment}"));
set(new OperatorType(MODULE, UPDATE, "更新$!{table.comment}"));
set(new OperatorType(MODULE, DELETE, "删除$!{table.comment}"));
set(new OperatorType(MODULE, EXPORT, "导出$!{table.comment}"));
}
}

View File

@@ -4,11 +4,12 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.Strings;
import com.orion.lang.utils.collect.Lists;
import com.orion.office.excel.writer.exporting.ExcelExport;
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
#if($cacheMeta.enableCache)
import com.orion.ops.framework.common.constant.Const;
#end
import com.orion.lang.utils.collect.Lists;
import com.orion.office.excel.writer.exporting.ExcelExport;
import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.FileNames;
import com.orion.ops.framework.common.utils.Valid;
@@ -49,6 +50,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
@Override
public Long create${type}(${type}CreateRequest request) {
log.info("${type}Service-create${type} request: {}", JSON.toJSONString(request));
OperatorLogs.add(request);
// 转换
${type}DO record = ${type}Convert.MAPPER.to(request);
// 查询数据是否冲突
@@ -67,6 +69,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
@Override
public Integer update${type}ById(${type}UpdateRequest request) {
log.info("${type}Service-update${type}ById id: {}, request: {}", request.getId(), JSON.toJSONString(request));
OperatorLogs.add(request);
// 查询
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
${type}DO record = ${typeLower}DAO.selectById(id);
@@ -177,6 +180,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
@Override
public Integer delete${type}ById(Long id) {
log.info("${type}Service-delete${type}ById id: {}", id);
OperatorLogs.add(OperatorLogs.ID, id);
// 检查数据是否存在
${type}DO record = ${typeLower}DAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
@@ -193,6 +197,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
@Override
public Integer batchDelete${type}ByIdList(List<Long> idList) {
log.info("${type}Service-batchDelete${type}ByIdList idList: {}", idList);
OperatorLogs.add(OperatorLogs.ID_LIST, idList);
int effect = ${typeLower}DAO.deleteBatchIds(idList);
log.info("${type}Service-batchDelete${type}ByIdList effect: {}", effect);
#if($cacheMeta.enableCache)
@@ -220,6 +225,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
@Override
public void export${type}(${type}QueryRequest request, HttpServletResponse response) throws IOException {
log.info("${type}Service.export${type} request: {}", JSON.toJSONString(request));
OperatorLogs.add(request);
// 条件
LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request);
// 查询