fix:代码整理

上级 6dd660c9
package com.kwan.springbootkwan.controller;
import com.kwan.springbootkwan.utils.ThreadPoolUntil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
/**
* 方法上跨域配置
......@@ -11,10 +17,26 @@ import org.springframework.web.bind.annotation.*;
* @version : 2.2.0
* @date : 2022/12/19 16:10
*/
@Api(description = "书籍信息", tags = "BookController")
@Api(tags = "BookController")
@RestController
public class BookController {
@ApiOperation(value = "异步添加书籍", notes = "异步添加书籍")
@CrossOrigin(maxAge = 1800, allowedHeaders = "*")
@PostMapping("addBookAsyn")
public DeferredResult<String> addBookAsyn(String name) {
DeferredResult<String> deferredResult = new DeferredResult<>(10000L);
// 设置超时处理
deferredResult.onTimeout(() -> deferredResult.setErrorResult("请求超时"));
// 设置错误处理
deferredResult.onError((Throwable t) -> deferredResult.setErrorResult("系统错误"));
// 创建任务
Runnable task = () -> deferredResult.setResult("receive:" + name);
ThreadPoolUntil.executeTask(task);
return deferredResult;
}
@ApiOperation(value = "添加书籍", notes = "添加书籍")
@CrossOrigin(value = "http://localhost:8081", maxAge = 1800, allowedHeaders = "*")
@PostMapping("addBook")
......
......@@ -7,7 +7,6 @@ import com.kwan.springbootkwan.entity.User;
import com.kwan.springbootkwan.mapper.UserMapper;
import com.kwan.springbootkwan.service.IPersonService;
import com.kwan.springbootkwan.service.IUserService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -43,7 +42,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
}
@DS(value = "kwan-ds")
@GlobalTransactional
// @GlobalTransactional
@Override
public User saveUser(User user) {
userMapper.insert(user);
......
......@@ -17,7 +17,6 @@ import java.util.List;
* @version : 2.2.0
* @date : 2023/7/21 23:29
*/
@Slf4j
public class DateUtils {
......
......@@ -6,13 +6,13 @@ import redis.clients.jedis.Tuple;
import java.util.Set;
/**
* 商品排序
* redis商品排序工具类
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/22 10:01
*/
public class GoodsRankService {
public class GoodsRankUtil {
private static Jedis jedis;
......@@ -25,37 +25,39 @@ public class GoodsRankService {
*/
private static String KEY = "goods";
public static void removeOne() {
/**
* zrem——移除某个商品
* 命令格式:***zrem 排行榜名称 商品标识*** 时间复杂度:O(log(N))
*/
public static void removeOne() {
Long aLong = jedis.zrem(KEY, "god-10");
}
public static void addScore() {
/**
* zincrby——增减商品分数
* 命令格式:***zincrby 排行榜名称 分数增量 商品标识*** 时间复杂度:O(log(N))
* 有的排行榜是在变更时重新设置商品的分数,而还有的排行榜则是以增量方式修改商品分数,增量可正可负。如果执行zincrby时商品尚不在排行榜中,则认为其原始分数为0,相当于执行zdd。
*/
public static void addScore() {
Double zincrby = jedis.zincrby(KEY, 1, "god-10");
System.out.println(zincrby);
}
public static void getNum() {
/**
* zrevrank——查看商品的排名
* 命令格式:***zrevrank 排行榜名称 商品标识*** 时间复杂度:O(log(N))
* 与zrevrange类似,zrevrank是以分数由高到低的排序返回商品排名(实际返回的是以0开始的索引),对应的zrank则是以分数由低到高的排序返回排名。
*/
public static void getNum() {
Long aLong = jedis.zrevrank(KEY, "god-10");
System.out.println(aLong);
Long aLong2 = jedis.zrevrank(KEY, "god-1000");
System.out.println(aLong2);
}
public static void getRange() {
/**
* zrevrange——按名次查看排行榜
* 命令格式:***zrevrange 排行榜名称 起始位置 结束位置 [withscores]*** 时间复杂度:O(log(N)+M)
......@@ -63,27 +65,31 @@ public class GoodsRankService {
* 起始位置和结束位置都是以0开始的索引,且都包含在内。如果结束位置为-1则查看范围为整个排行榜。
* 带上withscores则会返回商品分数。
*/
public static void getRange() {
Set<String> zrevrange = jedis.zrevrange(KEY, 2, 5);
zrevrange.forEach(System.out::println);
Set<Tuple> set = jedis.zrangeWithScores(KEY, 2, 5);
set.forEach(System.out::println);
}
public static void getData() {
/**
* zscore——查看商品分数
* 命令格式:***zscore 排行榜名称 商品标识*** 时间复杂度:O(1)
*/
public static void getData() {
Double zscore = jedis.zscore(KEY, "go-20");
System.out.println(zscore);
}
public static void setData() {
for (int i = 0; i < 100; i++) {
/**
* zadd——设置商品分数
* 命令格式:***zadd 排行榜名称 分数 商品名字 时间复杂度:O(log(N))
*/
public static void setData() {
for (int i = 0; i < 100; i++) {
jedis.zadd(KEY, i, "go-" + i);
}
}
......
......@@ -14,7 +14,7 @@ import java.util.List;
import java.util.Map;
/**
* 人工智能chatgpt-api
* chatgpt-api
*
* @author : qinyingjie
* @version : 2.2.0
......@@ -34,7 +34,6 @@ public class OpenAIChatGptUtil {
*/
final static private String Authorization = "Bearer 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";
public static void main(String[] args) {
String question = "默写静夜思";
//这里是我根据模型请求封装的模型实体
......@@ -61,39 +60,4 @@ public class OpenAIChatGptUtil {
}
System.out.println("成功");
}
// public static CompletionChatResponse chatCompletion(String prompt) {//prompt即要将要发送至gtp的内容
// //这里我把用户发送和机器人返回的20条内容内容存在了redis中,用于关联对话上下文场景,如果不需要,注释掉即可,直接new一个ArrayList
// List<Object> messages = getUserCacheMessages();
// int size = messages.size();
//
// if (size > 19) {
// messages.remove(0);
// }
//
// messages.add(message);
// setUserCacheMessages(messages);//把新的放到redis
// completionChatRequest.setMessages(messages);
// post.body(JSON.toJSONString(completionChatRequest));
// String body = post.execute().body();
// CompletionChatResponse completionChatResponse = JSON.parseObject(body, CompletionChatResponse.class);
// return completionChatResponse;
// }
//
// public static List<Object> getUserCacheMessages(){
// RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
// List<Object> cacheMessages = redisCache.getCacheObject(JwtTokenUtil.getUserId + ":messages");
// if (StringUtils.isEmpty(cacheMessages)){
// cacheMessages= new ArrayList<>();
// }
// return cacheMessages;
// }
//
// public static void setUserCacheMessages(List<Object> messages){
// while(messages.size()>20){
// messages.remove(0);
// }
// RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
// redisCache.setCacheObject(JwtTokenUtil.getUserId + ":messages", messages, 30, TimeUnit.MINUTES);
// }
}
......@@ -6,6 +6,14 @@ import org.springframework.stereotype.Component;
import java.util.List;
/**
* 敏感词过滤工具类
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/8/17 09:41
*/
@Component
public class SensitiveWordUtil {
......
package com.kwan.springbootkwan.utils;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 线程池工具类
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/8/17 09:38
*/
public class ThreadPoolUntil {
private static final int THREAD_POOL_SIZE = 10;
private static ExecutorService executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
public static void executeTask(Runnable task) {
executorService.submit(task);
}
public static void shutdown() {
executorService.shutdown();
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册