|
|
|
@ -43,13 +43,27 @@ public class AiAspect {
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 定义一个Pointcut,匹配带有StuCreateImgDTO参数的方法
|
|
|
|
|
@Pointcut("execution(* com.sztzjy.marketing.service.impl.QianFanBigModuleServiceImpl.*(..))")
|
|
|
|
|
@Pointcut("execution(* com.sztzjy.marketing.service.impl.QianFanBigModuleServiceImpl.createArticleByMessage(..))")
|
|
|
|
|
public void useInspect() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before("useInspect()")
|
|
|
|
|
public void timesCheck(JoinPoint joinPoint) throws IllegalAccessException {
|
|
|
|
|
/**
|
|
|
|
|
* 切入点
|
|
|
|
|
*
|
|
|
|
|
* @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("开始检查使用次数...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -59,17 +73,17 @@ public class AiAspect {
|
|
|
|
|
|
|
|
|
|
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("超出使用限制,请明日再来!");
|
|
|
|
|
throw new RuntimeException("您的使用已达到今日限额,请明日再试。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StuAiLimit stuAiLimit = stuAiLimits.get(0);
|
|
|
|
|
|
|
|
|
|
stuAiLimit.setNumberOfTimes(stuAiLimit.getNumberOfTimes()+1);
|
|
|
|
|
if (3 == stuAiLimit.getNumberOfTimes())
|
|
|
|
|
if (3 <= stuAiLimit.getNumberOfTimes())
|
|
|
|
|
{
|
|
|
|
|
stuAiLimit.setLimitState((byte)1);
|
|
|
|
|
}
|
|
|
|
@ -83,16 +97,63 @@ public class AiAspect {
|
|
|
|
|
stuAiLimit.setUserId(jwtUser.getUserId());
|
|
|
|
|
stuAiLimit.setLimitState((byte)0);
|
|
|
|
|
stuAiLimit.setCreateTime(new Date());
|
|
|
|
|
stuAiLimit.setNumberOfTimes(1);
|
|
|
|
|
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("未经授权登录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|