CRM客户关系管理系统难点实现

一、通过redis缓存技术解决了活动code加载慢的问题

空间换时间:通过在启动类上实现CommandLineRunner,重写run方法,加载所有的活动code到缓存,下次查询直接从redis缓存中查询,提高了查询效率

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class})
@EnableScheduling
public class HuiKeApplication implements CommandLineRunner{// implements CommandLineRunner
    //注入活动的service
    @Autowired
    private ITbActivityService activityService;

    public static void main(String[] args){
        SpringApplication.run(HuiKeApplication.class, args);
    }

    @Override
    public void run(String... args)  {
        try{
            //加载所有活动code到缓存
            activityService.loadAllActivityCode();
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}

二、通过springsecutiry的@PreAuthorize注解实现接口资源鉴权功能

在该系统中,所有接口都有一个ss权限标识符,对应在系统目录表中。登录时,用户权限标识符被封装到该用户对象中,并缓存到Redis中,Key为UUID。该UUID会被封装到JWT载荷中返回给前端。前端通过将JWT存在Header中发送请求。后端解析JWT获取UUID,查询Redis中的用户对象,验证权限标识符集合是否包含接口写死的权限标识符,如果权限验证通过,则运行访问接口,否则拒绝请求。

	/**
	 * 查询线索管理列表
	 */
	@PreAuthorize("@ss.hasPermi('clues:clue:list')")
	@GetMapping("/list")
	public TableDataInfo list(TbClue tbClue) {
		List<TbClue> list = tbClueService.selectTbClueList(tbClue);
		return getDataTablePage(list);
	}

三、实现AOP+自定义注解@Log的方式记录操作日志


        通过在Controller接口的方法上添加@Log注解,结合AOP技术实现对该方法执行前后状态信息的记录。@Log注解中设置了操作类型、模块名称等参数,这些参数会被用于构建操作日志实体类。拦截器可以获取请求参数、返回值和异常信息,并将其封装到操作日志实体类中。最终实现对系统操作日志的记录。

自定义操作日志注解

/**
 * 自定义操作日志记录注解
 * 
 * 
 *
 */
@Target({ ElementType.PARAMETER, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Log
{
    /**
     * 模块 
     */
    public String title() default "";

    /**
     * 功能
     */
    public BusinessType businessType() default BusinessType.OTHER;

    /**
     * 操作人类别
     */
    public OperatorType operatorType() default OperatorType.MANAGE;

    /**
     * 是否保存请求的参数
     */
    public boolean isSaveRequestData() default true;
}
	/**
	 * 新增线索管理
	 */
	@PreAuthorize("@ss.hasPermi('clues:clue:add')")
	@Log(title = "线索管理", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody TbClue tbClue) {
		if(!tbClueService.checkCluePhoneExis(tbClue.getPhone())) return error("手机号已存在");
		return toAjax(tbClueService.insertTbClue(tbClue));
	}

猜你喜欢

转载自blog.csdn.net/weixin_71921932/article/details/129747297