mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-01 02:38:43 +08:00 
			
		
		
		
	📖 code review 操作日志的实现
This commit is contained in:
		| @@ -60,7 +60,7 @@ public class CrmCustomerController { | ||||
|  | ||||
|     @PostMapping("/create") | ||||
|     @Operation(summary = "创建客户") | ||||
|     @OperateLog(enable = false) // TODO 关闭原有日志记录 | ||||
|     @OperateLog(enable = false) // TODO 关闭原有日志记录;@puhui999:注解都先删除。先记录,没关系。我们下个迭代,就都删除掉操作日志了; | ||||
|     @PreAuthorize("@ss.hasPermission('crm:customer:create')") | ||||
|     public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerCreateReqVO createReqVO) { | ||||
|         return success(customerService.createCustomer(createReqVO, getLoginUserId())); | ||||
| @@ -102,6 +102,7 @@ public class CrmCustomerController { | ||||
|         return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap)); | ||||
|     } | ||||
|  | ||||
|     // TODO @puhui999:这个查询会查出多个;微信发你图了 | ||||
|     @GetMapping("/page") | ||||
|     @Operation(summary = "获得客户分页") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:customer:query')") | ||||
| @@ -141,6 +142,7 @@ public class CrmCustomerController { | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     // TODO @puhui999:是不是接口只要传递 bizId,由 Controller 自己组装出 OperateLogV2PageReqDTO | ||||
|     @GetMapping("/operate-log-page") | ||||
|     @Operation(summary = "获得客户操作日志") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:customer:query')") | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| 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; | ||||
| @@ -10,7 +9,7 @@ import org.springframework.stereotype.Component; | ||||
| import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY; | ||||
|  | ||||
| /** | ||||
|  * 自定义函数-通过行业编号获取行业信息 | ||||
|  * 行业的 {@link IParseFunction} 实现类 | ||||
|  * | ||||
|  * @author HUIHUI | ||||
|  */ | ||||
| @@ -30,14 +29,9 @@ public class CrmIndustryParseFunction implements IParseFunction { | ||||
|  | ||||
|     @Override | ||||
|     public String apply(Object value) { | ||||
|         if (ObjUtil.isEmpty(value)) { | ||||
|         if (StrUtil.isEmptyIfStr(value)) { | ||||
|             return ""; | ||||
|         } | ||||
|         if (StrUtil.isEmpty(value.toString())) { | ||||
|             return ""; | ||||
|         } | ||||
|  | ||||
|         // 获取行业信息 | ||||
|         return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, value.toString()); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| 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; | ||||
| @@ -10,7 +9,7 @@ import org.springframework.stereotype.Component; | ||||
| import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL; | ||||
|  | ||||
| /** | ||||
|  * 自定义函数-通过客户等级编号获取客户等级信息 | ||||
|  * 客户等级的 {@link IParseFunction} 实现类 | ||||
|  * | ||||
|  * @author HUIHUI | ||||
|  */ | ||||
| @@ -30,14 +29,9 @@ public class CrmLevelParseFunction implements IParseFunction { | ||||
|  | ||||
|     @Override | ||||
|     public String apply(Object value) { | ||||
|         if (ObjUtil.isEmpty(value)) { | ||||
|         if (StrUtil.isEmptyIfStr(value)) { | ||||
|             return ""; | ||||
|         } | ||||
|         if (StrUtil.isEmpty(value.toString())) { | ||||
|             return ""; | ||||
|         } | ||||
|  | ||||
|         // 获取客户等级信息 | ||||
|         return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_LEVEL, value.toString()); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| 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; | ||||
| @@ -10,7 +9,7 @@ import org.springframework.stereotype.Component; | ||||
| import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE; | ||||
|  | ||||
| /** | ||||
|  * 自定义函数-通过客户来源编号获取客户来源信息 | ||||
|  * 客户来源的 {@link IParseFunction} 实现类 | ||||
|  * | ||||
|  * @author HUIHUI | ||||
|  */ | ||||
| @@ -30,14 +29,9 @@ public class CrmSourceParseFunction implements IParseFunction { | ||||
|  | ||||
|     @Override | ||||
|     public String apply(Object value) { | ||||
|         if (ObjUtil.isEmpty(value)) { | ||||
|         if (StrUtil.isEmptyIfStr(value)) { | ||||
|             return ""; | ||||
|         } | ||||
|         if (StrUtil.isEmpty(value.toString())) { | ||||
|             return ""; | ||||
|         } | ||||
|  | ||||
|         // 获取客户来源信息 | ||||
|         return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_SOURCE, value.toString()); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -13,7 +13,6 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti | ||||
|  */ | ||||
| public class CrmPermissionUtils { | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * 校验用户是否是 CRM 管理员 | ||||
|      * | ||||
|   | ||||
| @@ -62,7 +62,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | ||||
|         crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()) | ||||
|                 .setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人 | ||||
|  | ||||
|         // 添加日志上下文所需 | ||||
|         // 记录操作日志 | ||||
|         LogRecordContext.putVariable("customerId", customer.getId()); | ||||
|         return customer.getId(); | ||||
|     } | ||||
| @@ -73,15 +73,15 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | ||||
|     @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) | ||||
|     public void updateCustomer(CrmCustomerUpdateReqVO updateReqVO) { | ||||
|         // 校验存在 | ||||
|         CrmCustomerDO oldCustomerDO = validateCustomerExists(updateReqVO.getId()); | ||||
|         CrmCustomerDO oldCustomer = validateCustomerExists(updateReqVO.getId()); | ||||
|  | ||||
|         // 更新 | ||||
|         CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(updateReqVO); | ||||
|         customerMapper.updateById(updateObj); | ||||
|  | ||||
|         // __DIFF 函数传递了一个参数,传递的参数是修改之后的对象,这种方式需要在方法内部向 LogRecordContext 中 put 一个变量,代表是之前的对象,这个对象可以是null | ||||
|         LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomerDO, CrmCustomerUpdateReqVO.class)); | ||||
|         // TODO 扩展信息测试 | ||||
|         // 记录操作日志 | ||||
|         LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerUpdateReqVO.class)); | ||||
|         // TODO 扩展信息测试 @puhui999:看着没啥问题,可以删除啦; | ||||
|         HashMap<String, Object> extra = new HashMap<>(); | ||||
|         extra.put("tips", "随便记录一点啦"); | ||||
|         LogRecordContext.putVariable("extra", extra); | ||||
|   | ||||
| @@ -90,7 +90,8 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | ||||
|         CrmPermissionDO oldPermission = crmPermissionMapper.selectByBizTypeAndBizIdByUserId( | ||||
|                 transferReqBO.getBizType(), transferReqBO.getBizId(), transferReqBO.getUserId()); | ||||
|         String bizTypeName = CrmBizTypeEnum.getNameByType(transferReqBO.getBizType()); | ||||
|         if (oldPermission == null || (!isOwner(oldPermission.getLevel()) && !CrmPermissionUtils.isCrmAdmin())) {  // 不是拥有者,并且不是超管 | ||||
|         if (oldPermission == null // 不是拥有者,并且不是超管 | ||||
|                 || (!isOwner(oldPermission.getLevel()) && !CrmPermissionUtils.isCrmAdmin())) { | ||||
|             throw exception(CRM_PERMISSION_DENIED, bizTypeName); | ||||
|         } | ||||
|         // 1.1 校验转移对象是否已经是该负责人 | ||||
|   | ||||
| @@ -40,7 +40,7 @@ public class CrmQueryWrapperUtils { | ||||
|                                                                                     Long userId, Integer sceneType, Boolean pool) { | ||||
|         final String ownerUserIdField = SingletonManager.getMybatisPlusJoinProperties().getTableAlias() + ".owner_user_id"; | ||||
|         // 1. 构建数据权限连表条件 | ||||
|         if (ObjUtil.notEqual(CrmPermissionUtils.isCrmAdmin(), Boolean.TRUE) && ObjUtil.notEqual(pool, Boolean.TRUE)) { // 管理员,公海不需要数据权限 | ||||
|         if (!CrmPermissionUtils.isCrmAdmin() && ObjUtil.notEqual(pool, Boolean.TRUE)) { // 管理员,公海不需要数据权限 | ||||
|             query.innerJoin(CrmPermissionDO.class, on -> on.eq(CrmPermissionDO::getBizType, bizType) | ||||
|                     .eq(CrmPermissionDO::getBizId, bizId) // 只能使用 SFunction 如果传 id 解析出来的 sql 不对 | ||||
|                     .eq(CrmPermissionDO::getUserId, userId)); | ||||
| @@ -81,7 +81,7 @@ public class CrmQueryWrapperUtils { | ||||
|      * @param userId  用户编号 | ||||
|      */ | ||||
|     public static <T extends MPJLambdaWrapper<?>> void appendPermissionCondition(T query, Integer bizType, Collection<Long> bizIds, Long userId) { | ||||
|         if (ObjUtil.equal(CrmPermissionUtils.isCrmAdmin(), Boolean.TRUE)) {// 管理员不需要数据权限 | ||||
|         if (CrmPermissionUtils.isCrmAdmin()) {// 管理员不需要数据权限 | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV