操作日志:完善 code review 提到的问题

This commit is contained in:
puhui999
2023-12-26 00:04:20 +08:00
parent 5de6a8bd23
commit 6950368991
27 changed files with 183 additions and 649 deletions

View File

@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.framework.operatelogv2.core.vo.OperateLogV2PageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
@ -61,6 +60,7 @@ public class CrmCustomerController {
@PostMapping("/create")
@Operation(summary = "创建客户")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@PreAuthorize("@ss.hasPermission('crm:customer:create')")
public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerCreateReqVO createReqVO) {
return success(customerService.createCustomer(createReqVO, getLoginUserId()));
@ -68,6 +68,7 @@ public class CrmCustomerController {
@PutMapping("/update")
@Operation(summary = "更新客户")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> updateCustomer(@Valid @RequestBody CrmCustomerUpdateReqVO updateReqVO) {
customerService.updateCustomer(updateReqVO);
@ -76,6 +77,7 @@ public class CrmCustomerController {
@DeleteMapping("/delete")
@Operation(summary = "删除客户")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('crm:customer:delete')")
public CommonResult<Boolean> deleteCustomer(@RequestParam("id") Long id) {
@ -132,6 +134,7 @@ public class CrmCustomerController {
@PutMapping("/transfer")
@Operation(summary = "客户转移")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> transfer(@Valid @RequestBody CrmCustomerTransferReqVO reqVO) {
customerService.transferCustomer(reqVO, getLoginUserId());
@ -140,9 +143,8 @@ public class CrmCustomerController {
@GetMapping("/operate-log-page")
@Operation(summary = "获得客户操作日志")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
public CommonResult<PageResult<OperateLogV2RespDTO>> getCustomerOperateLog(OperateLogV2PageReqVO reqVO) {
public CommonResult<PageResult<OperateLogV2RespDTO>> getCustomerOperateLog(CrmCustomerOperateLogPageReqVO reqVO) {
reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
reqVO.setBizType(CRM_CUSTOMER);
return success(operateLogApi.getOperateLogPage(BeanUtils.toBean(reqVO, OperateLogV2PageReqDTO.class)));
@ -151,6 +153,7 @@ public class CrmCustomerController {
// TODO @Joey单独建一个属于自己业务的 ReqVO因为前端如果模拟请求是不是可以更新其它字段了
@PutMapping("/lock")
@Operation(summary = "锁定/解锁客户")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> lockCustomer(@Valid @RequestBody CrmCustomerUpdateReqVO updateReqVO) {
customerService.lockCustomer(updateReqVO);
@ -161,6 +164,7 @@ public class CrmCustomerController {
@PutMapping("/put-pool")
@Operation(summary = "数据放入公海")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@Parameter(name = "id", description = "客户编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> putCustomerPool(@RequestParam("id") Long id) {

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - crm 客户操作日志分页 Request VO")
@Data
public class CrmCustomerOperateLogPageReqVO extends PageParam {
@Schema(description = "模块数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long bizId;
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long userId;
@Schema(description = "模块类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private String bizType;
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.crm.framework.operatelog.parse;
package cn.iocoder.yudao.module.crm.framework.operatelog.core;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import com.mzt.logapi.service.IParseFunction;
@ -8,7 +9,6 @@ import org.springframework.stereotype.Component;
import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY;
// TODO @puhui999还是放在 core 包下哈
/**
* 自定义函数-通过行业编号获取行业信息
*
@ -30,8 +30,7 @@ public class CrmIndustryParseFunction implements IParseFunction {
@Override
public String apply(Object value) {
// if (ObjUtil.isEmpty(value)) TODO @puhui999 可以直接替代哈
if (value == null) {
if (ObjUtil.isEmpty(value)) {
return "";
}
if (StrUtil.isEmpty(value.toString())) {
@ -39,12 +38,7 @@ public class CrmIndustryParseFunction implements IParseFunction {
}
// 获取行业信息
// TODO @puhui999这里可以不用 try catch
try {
return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, value.toString());
} catch (Exception ignored) {
}
return "";
return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, value.toString());
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.crm.framework.operatelog.parse;
package cn.iocoder.yudao.module.crm.framework.operatelog.core;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import com.mzt.logapi.service.IParseFunction;
@ -29,7 +30,7 @@ public class CrmLevelParseFunction implements IParseFunction {
@Override
public String apply(Object value) {
if (value == null) {
if (ObjUtil.isEmpty(value)) {
return "";
}
if (StrUtil.isEmpty(value.toString())) {
@ -37,10 +38,7 @@ public class CrmLevelParseFunction implements IParseFunction {
}
// 获取客户等级信息
try {
return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_LEVEL, value.toString());
} catch (Exception ignored) {
}
return "";
return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_LEVEL, value.toString());
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.crm.framework.operatelog.parse;
package cn.iocoder.yudao.module.crm.framework.operatelog.core;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import com.mzt.logapi.service.IParseFunction;
@ -29,7 +30,7 @@ public class CrmSourceParseFunction implements IParseFunction {
@Override
public String apply(Object value) {
if (value == null) {
if (ObjUtil.isEmpty(value)) {
return "";
}
if (StrUtil.isEmpty(value.toString())) {
@ -37,10 +38,7 @@ public class CrmSourceParseFunction implements IParseFunction {
}
// 获取客户来源信息
try {
return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_SOURCE, value.toString());
} catch (Exception ignored) {
}
return "";
return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_SOURCE, value.toString());
}
}

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.crm.service.customer;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.operatelogv2.core.enums.OperateLogV2Constants;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
@ -53,7 +52,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, bizNo = "{{#customerId}}", success = "创建了客户")
@LogRecord(type = CRM_CUSTOMER, subType = "创建客户", bizNo = "{{#customerId}}", success = "创建了客户")
public Long createCustomer(CrmCustomerCreateReqVO createReqVO, Long userId) {
// 插入
CrmCustomerDO customer = CrmCustomerConvert.INSTANCE.convert(createReqVO);
@ -71,7 +70,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
// TODO @puhui999测试下能不能打出用户数据的变更。啊哈可以打完微信发我下
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, bizNo = "{{#updateReqVO.id}}", success = "更新了客户{_DIFF{#updateReqVO}}")
@LogRecord(type = CRM_CUSTOMER, subType = "更新客户", bizNo = "{{#updateReqVO.id}}", success = "更新了客户{_DIFF{#updateReqVO}}", extra = "{{#extra}}")
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
public void updateCustomer(CrmCustomerUpdateReqVO updateReqVO) {
// 校验存在
@ -83,14 +82,15 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
// __DIFF 函数传递了一个参数,传递的参数是修改之后的对象,这种方式需要在方法内部向 LogRecordContext 中 put 一个变量代表是之前的对象这个对象可以是null
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomerDO, CrmCustomerUpdateReqVO.class));
// TODO 扩展信息测试
HashMap<String, Object> extra = new HashMap<>();
extra.put("tips", "随便记录一点啦");
LogRecordContext.putVariable(OperateLogV2Constants.EXTRA_KEY, extra);
LogRecordContext.putVariable("extra", extra);
}
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, bizNo = "{{#id}}", success = "删除了客户")
@LogRecord(type = CRM_CUSTOMER, subType = "删除客户", bizNo = "{{#id}}", success = "删除了客户")
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void deleteCustomer(Long id) {
// 校验存在
@ -141,7 +141,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, bizNo = "{{#reqVO.id}}", success = TRANSFER_CUSTOMER_LOG_SUCCESS)
@LogRecord(type = CRM_CUSTOMER, subType = "客户转移", bizNo = "{{#reqVO.id}}", success = TRANSFER_CUSTOMER_LOG_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
// 1. 校验客户是否存在
@ -158,7 +158,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
}
@Override
@LogRecord(type = CRM_CUSTOMER, bizNo = "{{#updateReqVO.id}}", success = "锁定了客户")
@LogRecord(type = CRM_CUSTOMER, subType = "锁定/解锁客户", bizNo = "{{#updateReqVO.id}}", success = "锁定了客户")
public void lockCustomer(CrmCustomerUpdateReqVO updateReqVO) {
// 校验存在
validateCustomerExists(updateReqVO.getId());
@ -172,7 +172,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, bizNo = "{{#id}}", success = "将客户放入了公海")
@LogRecord(type = CRM_CUSTOMER, subType = "客户放入公海", bizNo = "{{#id}}", success = "将客户放入了公海")
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void putCustomerPool(Long id) {
// 1. 校验存在