|
|
|
@ -1,164 +1,164 @@
|
|
|
|
|
//package com.sztzjy.marketing.annotation.aspect;
|
|
|
|
|
//
|
|
|
|
|
//import com.sztzjy.marketing.config.exception.UnAuthorizedException;
|
|
|
|
|
//import com.sztzjy.marketing.config.security.JwtUser;
|
|
|
|
|
//import com.sztzjy.marketing.entity.StuAiLimit;
|
|
|
|
|
//import com.sztzjy.marketing.entity.StuAiLimitExample;
|
|
|
|
|
//import com.sztzjy.marketing.mapper.StuAiLimitMapper;
|
|
|
|
|
//import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
//import org.aspectj.lang.JoinPoint;
|
|
|
|
|
//import org.aspectj.lang.annotation.Aspect;
|
|
|
|
|
//import org.aspectj.lang.annotation.Before;
|
|
|
|
|
//import org.aspectj.lang.annotation.Pointcut;
|
|
|
|
|
//import org.aspectj.lang.reflect.MethodSignature;
|
|
|
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
//import org.springframework.http.HttpStatus;
|
|
|
|
|
//import org.springframework.http.ResponseEntity;
|
|
|
|
|
//import org.springframework.security.core.Authentication;
|
|
|
|
|
//import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
|
//import org.springframework.stereotype.Component;
|
|
|
|
|
//
|
|
|
|
|
//import java.lang.reflect.Field;
|
|
|
|
|
//import java.util.Date;
|
|
|
|
|
//import java.util.List;
|
|
|
|
|
//
|
|
|
|
|
///**
|
|
|
|
|
// * @author 17803
|
|
|
|
|
// * @date 2024-06-21 8:59
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
//@Component
|
|
|
|
|
//@Aspect
|
|
|
|
|
//@Slf4j
|
|
|
|
|
//public class AiAspect {
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private StuAiLimitMapper stuAiLimitMapper;
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 切入点
|
|
|
|
|
// *
|
|
|
|
|
// * @param
|
|
|
|
|
// * @return
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// // 定义一个Pointcut,匹配带有StuCreateImgDTO参数的方法
|
|
|
|
|
// @Pointcut("execution(* com.sztzjy.marketing.service.impl.QianFanBigModuleServiceImpl.createArticleByMessage(..))")
|
|
|
|
|
// public void useInspect() {
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 切入点
|
|
|
|
|
// *
|
|
|
|
|
// * @param
|
|
|
|
|
// * @return
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// // 定义一个Pointcut,匹配带有StuCreateImgDTO参数的方法
|
|
|
|
|
// @Pointcut("execution(* com.sztzjy.marketing.service.impl.QianFanBigModuleServiceImpl.createImgByAi(..))")
|
|
|
|
|
// public void limitImg() {
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// @Before("limitImg()")
|
|
|
|
|
// public void imgTimesCheck(JoinPoint joinPoint) throws IllegalAccessException {
|
|
|
|
|
// log.info("开始检查使用次数...");
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
// if (authentication != null && authentication.isAuthenticated()) {
|
|
|
|
|
// JwtUser jwtUser = (JwtUser) authentication.getPrincipal();
|
|
|
|
|
//
|
|
|
|
|
// StuAiLimitExample limitExample = new StuAiLimitExample();
|
|
|
|
|
// limitExample.createCriteria().andUserIdEqualTo(jwtUser.getUserId());
|
|
|
|
|
// List<StuAiLimit> stuAiLimits = stuAiLimitMapper.selectByExample(limitExample);
|
|
|
|
|
// if (!stuAiLimits.isEmpty())
|
|
|
|
|
// {
|
|
|
|
|
// if (stuAiLimits.get(0).getLimitState()== (byte) 1 || 3 < stuAiLimits.get(0).getNumberOfTimes()){
|
|
|
|
|
// throw new RuntimeException("您的使用已达到今日限额,请明日再试。");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// StuAiLimit stuAiLimit = stuAiLimits.get(0);
|
|
|
|
|
//
|
|
|
|
|
// stuAiLimit.setNumberOfTimes(stuAiLimit.getNumberOfTimes()+1);
|
|
|
|
|
// if (3 <= stuAiLimit.getNumberOfTimes())
|
|
|
|
|
// {
|
|
|
|
|
// stuAiLimit.setLimitState((byte)1);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// stuAiLimitMapper.updateByPrimaryKeySelective(stuAiLimit);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// }else {
|
|
|
|
|
//
|
|
|
|
|
// StuAiLimit stuAiLimit = new StuAiLimit();
|
|
|
|
|
// stuAiLimit.setUserId(jwtUser.getUserId());
|
|
|
|
|
// stuAiLimit.setLimitState((byte)0);
|
|
|
|
|
// stuAiLimit.setCreateTime(new Date());
|
|
|
|
|
// stuAiLimit.setNumberOfTimes(0);
|
|
|
|
|
// stuAiLimit.setWordNumber(0);
|
|
|
|
|
// stuAiLimitMapper.insertSelective(stuAiLimit);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// } else {
|
|
|
|
|
// throw new UnAuthorizedException("未经授权登录");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// @Before("useInspect()")
|
|
|
|
|
// public void timesCheck(JoinPoint joinPoint) throws IllegalAccessException {
|
|
|
|
|
// log.info("开始检查使用次数...");
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
// if (authentication != null && authentication.isAuthenticated()) {
|
|
|
|
|
// JwtUser jwtUser = (JwtUser) authentication.getPrincipal();
|
|
|
|
|
//
|
|
|
|
|
// StuAiLimitExample limitExample = new StuAiLimitExample();
|
|
|
|
|
// limitExample.createCriteria().andUserIdEqualTo(jwtUser.getUserId());
|
|
|
|
|
// List<StuAiLimit> stuAiLimits = stuAiLimitMapper.selectByExample(limitExample);
|
|
|
|
|
// if (!stuAiLimits.isEmpty())
|
|
|
|
|
// {
|
|
|
|
|
// if (stuAiLimits.get(0).getLimitState()== (byte) 1 || 30 < stuAiLimits.get(0).getWordNumber()){
|
|
|
|
|
// throw new RuntimeException("您的使用已达到今日限额,请明日再试。");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// StuAiLimit stuAiLimit = stuAiLimits.get(0);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// if (30 <= stuAiLimit.getWordNumber())
|
|
|
|
|
// {
|
|
|
|
|
// stuAiLimit.setLimitState((byte)1);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// stuAiLimitMapper.updateByPrimaryKeySelective(stuAiLimit);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// }else {
|
|
|
|
|
//
|
|
|
|
|
// StuAiLimit stuAiLimit = new StuAiLimit();
|
|
|
|
|
// stuAiLimit.setUserId(jwtUser.getUserId());
|
|
|
|
|
// stuAiLimit.setLimitState((byte)0);
|
|
|
|
|
// stuAiLimit.setCreateTime(new Date());
|
|
|
|
|
// stuAiLimit.setNumberOfTimes(1);
|
|
|
|
|
// stuAiLimit.setWordNumber(0);
|
|
|
|
|
// stuAiLimitMapper.insertSelective(stuAiLimit);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// } else {
|
|
|
|
|
// throw new UnAuthorizedException("未经授权登录");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//}
|
|
|
|
|
package com.sztzjy.marketing.annotation.aspect;
|
|
|
|
|
|
|
|
|
|
import com.sztzjy.marketing.config.exception.UnAuthorizedException;
|
|
|
|
|
import com.sztzjy.marketing.config.security.JwtUser;
|
|
|
|
|
import com.sztzjy.marketing.entity.StuAiLimit;
|
|
|
|
|
import com.sztzjy.marketing.entity.StuAiLimitExample;
|
|
|
|
|
import com.sztzjy.marketing.mapper.StuAiLimitMapper;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
|
|
import org.aspectj.lang.annotation.Before;
|
|
|
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
|
|
|
import org.aspectj.lang.reflect.MethodSignature;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author 17803
|
|
|
|
|
* @date 2024-06-21 8:59
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
@Aspect
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class AiAspect {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private StuAiLimitMapper stuAiLimitMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 切入点
|
|
|
|
|
*
|
|
|
|
|
* @param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 定义一个Pointcut,匹配带有StuCreateImgDTO参数的方法
|
|
|
|
|
@Pointcut("execution(* com.sztzjy.marketing.service.impl.QianFanBigModuleServiceImpl.createArticleByMessage(..))")
|
|
|
|
|
public void useInspect() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 切入点
|
|
|
|
|
*
|
|
|
|
|
* @param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 定义一个Pointcut,匹配带有StuCreateImgDTO参数的方法
|
|
|
|
|
@Pointcut("execution(* com.sztzjy.marketing.service.impl.QianFanBigModuleServiceImpl.createImgByAi(..))")
|
|
|
|
|
public void limitImg() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before("limitImg()")
|
|
|
|
|
public void imgTimesCheck(JoinPoint joinPoint) throws IllegalAccessException {
|
|
|
|
|
log.info("开始检查使用次数...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
if (authentication != null && authentication.isAuthenticated()) {
|
|
|
|
|
JwtUser jwtUser = (JwtUser) authentication.getPrincipal();
|
|
|
|
|
|
|
|
|
|
StuAiLimitExample limitExample = new StuAiLimitExample();
|
|
|
|
|
limitExample.createCriteria().andUserIdEqualTo(jwtUser.getUserId());
|
|
|
|
|
List<StuAiLimit> stuAiLimits = stuAiLimitMapper.selectByExample(limitExample);
|
|
|
|
|
if (!stuAiLimits.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (stuAiLimits.get(0).getLimitState()== (byte) 1 || 3 < stuAiLimits.get(0).getNumberOfTimes()){
|
|
|
|
|
throw new RuntimeException("您的使用已达到今日限额,请明日再试。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StuAiLimit stuAiLimit = stuAiLimits.get(0);
|
|
|
|
|
|
|
|
|
|
stuAiLimit.setNumberOfTimes(stuAiLimit.getNumberOfTimes()+1);
|
|
|
|
|
if (3 <= stuAiLimit.getNumberOfTimes())
|
|
|
|
|
{
|
|
|
|
|
stuAiLimit.setLimitState((byte)1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stuAiLimitMapper.updateByPrimaryKeySelective(stuAiLimit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
|
|
StuAiLimit stuAiLimit = new StuAiLimit();
|
|
|
|
|
stuAiLimit.setUserId(jwtUser.getUserId());
|
|
|
|
|
stuAiLimit.setLimitState((byte)0);
|
|
|
|
|
stuAiLimit.setCreateTime(new Date());
|
|
|
|
|
stuAiLimit.setNumberOfTimes(0);
|
|
|
|
|
stuAiLimit.setWordNumber(0);
|
|
|
|
|
stuAiLimitMapper.insertSelective(stuAiLimit);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new UnAuthorizedException("未经授权登录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before("useInspect()")
|
|
|
|
|
public void timesCheck(JoinPoint joinPoint) throws IllegalAccessException {
|
|
|
|
|
log.info("开始检查使用次数...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
if (authentication != null && authentication.isAuthenticated()) {
|
|
|
|
|
JwtUser jwtUser = (JwtUser) authentication.getPrincipal();
|
|
|
|
|
|
|
|
|
|
StuAiLimitExample limitExample = new StuAiLimitExample();
|
|
|
|
|
limitExample.createCriteria().andUserIdEqualTo(jwtUser.getUserId());
|
|
|
|
|
List<StuAiLimit> stuAiLimits = stuAiLimitMapper.selectByExample(limitExample);
|
|
|
|
|
if (!stuAiLimits.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (stuAiLimits.get(0).getLimitState()== (byte) 1 || 30 < stuAiLimits.get(0).getWordNumber()){
|
|
|
|
|
throw new RuntimeException("您的使用已达到今日限额,请明日再试。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StuAiLimit stuAiLimit = stuAiLimits.get(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (30 <= stuAiLimit.getWordNumber())
|
|
|
|
|
{
|
|
|
|
|
stuAiLimit.setLimitState((byte)1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stuAiLimitMapper.updateByPrimaryKeySelective(stuAiLimit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
|
|
StuAiLimit stuAiLimit = new StuAiLimit();
|
|
|
|
|
stuAiLimit.setUserId(jwtUser.getUserId());
|
|
|
|
|
stuAiLimit.setLimitState((byte)0);
|
|
|
|
|
stuAiLimit.setCreateTime(new Date());
|
|
|
|
|
stuAiLimit.setNumberOfTimes(1);
|
|
|
|
|
stuAiLimit.setWordNumber(0);
|
|
|
|
|
stuAiLimitMapper.insertSelective(stuAiLimit);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new UnAuthorizedException("未经授权登录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|