恢复因测试暂停的AI次数限制和匿名登录注解

master
whb 7 months ago
parent 8e91310ec2
commit 397139314e

@ -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("未经授权登录");
}
}
}

@ -114,23 +114,24 @@ public class QianFanBigModuleServiceImpl implements QianFanBigModuleService {
@Override
public Flux<String> createArticleByMessage(List<Message> messageList) {
// int count = 0;
// for (Message message : messageList) {
// int length = message.getContent().length();
// count += length;
// }
// System.out.println(count);
//
// StuAiLimitExample limitExample = new StuAiLimitExample();
// limitExample.createCriteria().andUserIdEqualTo(messageList.get(0).getUserId());
// List<StuAiLimit> stuAiLimits = stuAiLimitMapper.selectByExample(limitExample);
//
//
// if (stuAiLimits.get(0).getLimitState()== (byte) 1 || 30 < stuAiLimits.get(0).getWordNumber()) {
// throw new RuntimeException("您的使用已达到今日限额,请明日再试。");
// }
// stuAiLimits.get(0).setWordNumber(stuAiLimits.get(0).getWordNumber() + count);
// stuAiLimitMapper.updateByPrimaryKeySelective(stuAiLimits.get(0));
int count = 0;
for (Message message : messageList) {
int length = message.getContent().length();
count += length;
}
System.out.println(count);
StuAiLimitExample limitExample = new StuAiLimitExample();
limitExample.createCriteria().andUserIdEqualTo(messageList.get(0).getUserId());
List<StuAiLimit> stuAiLimits = stuAiLimitMapper.selectByExample(limitExample);
if (stuAiLimits.get(0).getLimitState()== (byte) 1 || 30 < stuAiLimits.get(0).getWordNumber()) {
throw new RuntimeException("您的使用已达到今日限额,请明日再试。");
}
stuAiLimits.get(0).setWordNumber(stuAiLimits.get(0).getWordNumber() + count);
stuAiLimitMapper.updateByPrimaryKeySelective(stuAiLimits.get(0));
String accesstoken = null;

@ -80,10 +80,12 @@ public class StuUserServiceImpl implements StuUserService {
}
}
System.out.println("==========11111开始同步智云主平台用户数据11111==============="+System.currentTimeMillis());
for (StuUser userinfo : users) {
userMapper.insertSelective(userinfo);
}
System.out.println("==========22222同步智云主平台用户数据成功22222==============="+System.currentTimeMillis());
//根据学校id 查询成绩总览权重表中是否有数据 有则不进行操作 没有则新增权重
//根据学校id 查询成绩总览权重表中是否有数据 有则不进行操作 没有则新增权重
@ -147,11 +149,12 @@ public class StuUserServiceImpl implements StuUserService {
}
System.out.println("==========11111开始同步智云主平台用户数据11111==============="+System.currentTimeMillis());
for (StuUser user : users) {
userMapper.insertSelective(user);
}
System.out.println("==========22222同步智云主平台用户数据成功22222==============="+System.currentTimeMillis());
//根据学校id 查询成绩总览权重表中是否有数据 有则不进行操作 没有则新增权重
TchModuleWeithExample resultsExample = new TchModuleWeithExample();

@ -11,7 +11,7 @@ spring:
# 文件存储
file:
type: local
path: D:\home\marketing
path: /usr/local/tianzeProject/digitalMarketing/uploadFile
# path: D:\home
# path: /usr/local/tianzeProject/blockFinance/uploadFile

Loading…
Cancel
Save