From 397139314e8e75cd4c728a2987a504a1ceed924c Mon Sep 17 00:00:00 2001 From: whb <17803890193@163.com> Date: Fri, 16 Aug 2024 16:55:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=9B=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=9A=82=E5=81=9C=E7=9A=84AI=E6=AC=A1=E6=95=B0=E9=99=90?= =?UTF-8?q?=E5=88=B6=E5=92=8C=E5=8C=BF=E5=90=8D=E7=99=BB=E5=BD=95=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../marketing/annotation/aspect/AiAspect.java | 328 +++++++++--------- .../impl/QianFanBigModuleServiceImpl.java | 35 +- .../service/impl/StuUserServiceImpl.java | 7 +- src/main/resources/application-dev.yml | 2 +- 4 files changed, 188 insertions(+), 184 deletions(-) diff --git a/src/main/java/com/sztzjy/marketing/annotation/aspect/AiAspect.java b/src/main/java/com/sztzjy/marketing/annotation/aspect/AiAspect.java index 692ee3a..a65e444 100644 --- a/src/main/java/com/sztzjy/marketing/annotation/aspect/AiAspect.java +++ b/src/main/java/com/sztzjy/marketing/annotation/aspect/AiAspect.java @@ -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("未经授权登录"); + } + + } + + + + + +} diff --git a/src/main/java/com/sztzjy/marketing/service/impl/QianFanBigModuleServiceImpl.java b/src/main/java/com/sztzjy/marketing/service/impl/QianFanBigModuleServiceImpl.java index 2831da1..6e57ea2 100644 --- a/src/main/java/com/sztzjy/marketing/service/impl/QianFanBigModuleServiceImpl.java +++ b/src/main/java/com/sztzjy/marketing/service/impl/QianFanBigModuleServiceImpl.java @@ -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; diff --git a/src/main/java/com/sztzjy/marketing/service/impl/StuUserServiceImpl.java b/src/main/java/com/sztzjy/marketing/service/impl/StuUserServiceImpl.java index bc644cc..0e64d32 100644 --- a/src/main/java/com/sztzjy/marketing/service/impl/StuUserServiceImpl.java +++ b/src/main/java/com/sztzjy/marketing/service/impl/StuUserServiceImpl.java @@ -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(); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index ab85338..389869d 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -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