作者 钟来

完善上线功能

... ... @@ -4,6 +4,7 @@ import com.ruoyi.common.config.RuoYiConfig;
import com.zhonglai.luhui.config.TokenConfig;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.*;
... ... @@ -27,6 +28,9 @@ public class SwaggerConfig {
@Autowired
protected TokenConfig tokenConfig ;
@Value("${swagger.pathMapping}")
private String pathMapping;
@Bean
public Docket createRestApi() {
// 全局参数列表
... ... @@ -50,7 +54,7 @@ public class SwaggerConfig {
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build().pathMapping("/api");
.build().pathMapping(pathMapping);
}
/**
... ...
... ... @@ -41,16 +41,6 @@ public class AccessTokenVerifyInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler)
throws Exception {
log.info("---------------------开始进入"+httpServletRequest.getRequestURL().toString()+"登录拦截----------------------------");
Map<String,Object> map = new HashMap<>();
map.put("parameterValue",httpServletRequest.getParameterMap());
map.put(LOGIN_TOKEN_KEY,httpServletRequest.getHeader(LOGIN_TOKEN_KEY));
//获取请求body
byte[] bodyBytes = StreamUtils.copyToByteArray(httpServletRequest.getInputStream());
String body = new String(bodyBytes, httpServletRequest.getCharacterEncoding());
map.put("body",body);
log.info("---------------------参数:"+ GsonConstructor.get().toJson(map)+"----------------------------");
HttpSession session = httpServletRequest.getSession();
if(null == session || null == session.getAttribute(LOGIN_TOKEN_KEY))
{
... ...
package com.zhonglai.laikun.fortune.telling.config.adapter;
import com.ruoyi.common.utils.GsonConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StreamUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
public class LogInterceptor extends HandlerInterceptorAdapter {
private final Logger log = LoggerFactory.getLogger(LogInterceptor.class);
// 令牌自定义标识
@Value("${token.header}")
private String LOGIN_TOKEN_KEY;
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse response, Object handler) throws Exception {
log.info("---------------------开始进入"+httpServletRequest.getRequestURL().toString()+"请求拦截----------------------------");
Map<String,Object> map = new HashMap<>();
map.put("parameterValue",httpServletRequest.getParameterMap());
map.put(LOGIN_TOKEN_KEY,httpServletRequest.getHeader(LOGIN_TOKEN_KEY));
//获取请求body
byte[] bodyBytes = StreamUtils.copyToByteArray(httpServletRequest.getInputStream());
String body = new String(bodyBytes, httpServletRequest.getCharacterEncoding());
map.put("body",body);
log.info("---------------------参数:"+ GsonConstructor.get().toJson(map)+"----------------------------");
return super.preHandle(httpServletRequest, response, handler);
}
}
... ...
package com.zhonglai.laikun.fortune.telling.config.adapter;
import com.ruoyi.common.config.RuoYiConfig;
import com.zhonglai.laikun.fortune.telling.config.FilterIgnorePropertiesConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List;
... ... @@ -25,10 +31,15 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
return new AccessTokenVerifyInterceptor();
}
@Bean
public LogInterceptor logInterceptor() {
return new LogInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(logInterceptor()).addPathPatterns("/**").excludePathPatterns();
registry.addInterceptor(tokenVerifyInterceptor()).addPathPatterns("/**").excludePathPatterns(ignorePropertiesConfig.getAntMatchers());
super.addInterceptors(registry);
}
}
\ No newline at end of file
... ...
... ... @@ -14,6 +14,7 @@ import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
... ... @@ -41,6 +42,8 @@ public class CommonController
@Autowired
private ServerConfig serverConfig;
@Value("${swagger.pathMapping}")
private String pathMapping;
private static final String FILE_DELIMETER = ",";
/**
... ...
... ... @@ -61,9 +61,9 @@ public class FortuneTellingController extends BaseController {
"步骤三:判断用户提出的问题中,是否具有多个选择项。当问题里有多个选择项时:根据变爻爻辞的中文内容,严格按照匹配的中文关键词和内容判断规则,必须给每个选择项都占卜一个结果(凶、中、吉、大吉其中之一),例如:(例如:吃火锅,吉,吃烧烤,中);当问题里没有多个选择项时:根据变爻爻辞的中文内容,严格按照匹配的中文关键词和内容判断规则,将这个问题的占卜结果归类为凶、中、吉、大吉其中之一。\n" +
"步骤四:按照以上规则,请严格执行以下输出步骤和内容格式,不要出现其他的内容!\n" +
"当问题中有多个选择项时,输出格式如下:\n" +
"1.标题为“爻辞: ”,输出爻辞,然后换行。\n" +
"2.标题为“结论: ”, 然后换行。\n" +
"3.选择项的名称,选择项的占卜结果(每个选择项都必须分包单独一行输出)\n" +
"1.标题为“爻辞:”,输出爻辞,然后换行。\n" +
"2.标题为“结论:”, 然后换行。\n" +
"3.标题为“分析:”,选择项的名称,选择项的占卜结果(每个选择项都必须分包单独一行输出)\n" +
"示例:\n" +
"吃火锅,吉\n" +
"吃烧烤,中\n" +
... ... @@ -73,9 +73,9 @@ public class FortuneTellingController extends BaseController {
"6.相关于用户问题的其他方面分析:针对财务、生活、爱情、健康、工作、事业、未来等相关领域(最多三个),根据变爻数字和用户问题提供详细分析和建议。 \n" +
"\n" +
"当问题里没有多个选择项时:,输出格式如下:\n" +
"1.标题为“爻辞: ”,输出爻辞,然后换行。\n" +
"2.标题为“结论: ”,输出结论, 然后换行。\n" +
"3.输出用户提问的占卜结果(例如:凶; 中; 吉; 大吉)\n" +
"1.标题为“爻辞:”,输出爻辞,然后换行。\n" +
"2.标题为“结论:”,输出结论, 然后换行。\n" +
"3.标题为“分析:”,输出用户提问的占卜结果(例如:凶; 中; 吉; 大吉)\n" +
"4.根据变爻的文本和占卜结果,提炼出对用户问题的关键占卜结论,并进行详细解释。\n" +
"5.提供变爻内容的深入、全面的专家级解释,分析并回答用户的问题。\n" +
"6.相关于用户问题的其他方面分析:针对财务、生活、爱情、健康、工作、事业、未来等相关领域(最多三个),根据变爻数字和用户问题提供详细分析和建议。 \n" +
... ... @@ -85,6 +85,7 @@ public class FortuneTellingController extends BaseController {
{
clues = (String) list.get(0).get("remark");
}
try {
String str = YiJiFortuneTellingService.calculation(question,yaochi,clues);
FortuneTellingLog fortuneTellingLog = new FortuneTellingLog();
... ... @@ -94,11 +95,27 @@ public class FortuneTellingController extends BaseController {
fortuneTellingLog.setAnswer(str);
fortuneTellingLog.setCreate_time(DateUtils.getTime());
fortuneTellingLog.setUser_id(Integer.parseInt(getLoginToken().getId()));
publicService.insert(fortuneTellingLog);
//加工返回值
return toReturn(str);
}catch (Exception e)
{
String str = YiJiFortuneTellingService.calculation(question,yaochi,clues);
FortuneTellingLog fortuneTellingLog = new FortuneTellingLog();
fortuneTellingLog.setQuestion(question);
fortuneTellingLog.setNums(GsonConstructor.get().toJson(nums));
fortuneTellingLog.setYaochi(yaochi);
fortuneTellingLog.setAnswer(str);
fortuneTellingLog.setCreate_time(DateUtils.getTime());
fortuneTellingLog.setUser_id(Integer.parseInt(getLoginToken().getId()));
publicService.insert(fortuneTellingLog);
//加工返回值
return toReturn(str);
}
}
@ApiOperation("随机三个数")
@Transactional
@RequestMapping(value = "/randomNums3",method = RequestMethod.GET)
... ... @@ -139,14 +156,32 @@ public class FortuneTellingController extends BaseController {
private AjaxResult toReturn(String str)
{
String[] ss = str.split("\\n\\n");
Map<String,String> map = new HashMap<>();
map.put("divination",str.substring(str.indexOf("爻辞: ")+4,findNthOccurrence(str,"\n\n",1)));
map.put("conclusion",str.substring(str.indexOf("结论: ")+4,findNthOccurrence(str,"\n\n",2)));
map.put("analysis",str.substring(findNthOccurrence(str,"\n\n",2)+2));
map.put("divination",str.substring(str.indexOf("爻辞:")+3,str.indexOf("结论:")).replaceAll("\r","").replaceAll("\n",""));
map.put("conclusion",str.substring(str.indexOf("结论:")+3,str.indexOf("分析:")).replaceAll("\r","").replaceAll("\n"," "));
map.put("analysis",str.substring(str.indexOf("分析:")+3));
return AjaxResult.success("成功",map);
}
private int getfxindex(String str)
{
List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT remark FROM `lk-fortune-telling-sys`.`sys_config` WHERE config_key='sys.fortune.telling.retrun.indexstr'");
if(null != list && list.size()==1)
{
String remark = (String) list.get(0).get("remark");
String[] ss = remark.split("\\|");
for (String s:ss)
{
if(str.indexOf(s)>0)
{
return str.indexOf(s);
}
}
}
return -1;
}
private static int findNthOccurrence(String str, String patt, int number) {
if (str == null || patt == null || number < 1) {
... ... @@ -170,10 +205,9 @@ public class FortuneTellingController extends BaseController {
}
public static void main(String[] args) {
String str = "爻辞: 见舆曳,其牛掣,其人天且劓,无初有终。\n\n结论: 中\n\n根据变爻的文本和占卜结果,对您今天的运势进行占卜可以划分为中等级别。这表示您在今天可能会遇到一些困难或挑战,但通过坚定的信念和努力,最终可以克服难关。\n\n深入解释: 这个爻辞描绘了一种困难对抗的场景,但也强调了坚持到底的重要性。牛掣车辐,虽然曳力增大,但只要坚持不懈,最终会有所收获。劓本义是割耳,表示可能会有一些牺牲或损失,但这也是通向成功的必经之路。\n\n其他方面分析:\n财务: 今天可能会有一些额外支出或投资,需要谨慎对待财务安排,以避免不必要的损失。\n生活: 坚持自己的原则和信念,相信自己的选择,即使面临逆境也要勇往直前,生活会逐渐好转。\n工作: 遇到挑战时不要放弃,坚持努力并寻求他人帮助,解决问题的方式会逐渐清晰。";
System.out.println(">>>>>"+str.substring(str.indexOf("爻辞: ")+4,findNthOccurrence(str,"\n\n",1)));
System.out.println(">>>>>"+str.substring(str.indexOf("结论: ")+4,findNthOccurrence(str,"\n\n",2)));
System.out.println(">>>>>"+str.substring(findNthOccurrence(str,"\n\n",2)+2));
String str = "爻辞: 上六:乘马班如,泣血涟如。\n\n结论: 吃火锅,凶\n\n分析:\n吃火锅,凶\n吃烧烤,中\n\n对用户提出的问题,根据变爻爻辞的内容,吃火锅的结果为凶,吃烧烤的结果为中。建议选择吃烧烤会更加合适。\n\n关键占卜结论:此卦指出吃火锅可能会遇到不顺利或困难,建议考虑改变计划,选择其他餐饮方式会更加顺利。详细解释分析请参考专家级解释。\n\n财务方面分析:在财务投资上要注意风险,谨慎行事,避免财务损失。\n\n生活方面分析:在日常生活中要保持乐观态度,积极面对生活中的挑战,合理安排行程。\n\n健康方面分析:关注身体健康,避免过度食用油腻食物,保持适当运动,注意休息。";
System.out.println(">>>>>"+str.substring(str.indexOf("爻辞:")+3,str.indexOf("结论:")).replaceAll("\r","").replaceAll("\n",""));
System.out.println(">>>>>"+str.substring(str.indexOf("结论:")+3,str.indexOf("分析:")).replaceAll("\r","").replaceAll("\n"," "));
System.out.println(">>>>>"+str.substring(str.indexOf("分析:")+3));
}
}
... ...
# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2024 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8086 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # web: # resources: # static-locations: classpath:/static/, classpath:/templates/ # token配置 token: # 令牌自定义标识 header: Authorization # 令牌有效期(默认30分钟) expireTime: 31536000 # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: / sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: - /doc.html - /webjars/** - /swagger-ui.html - /v2/api-docs/** - /swagger/api-docs - /token/code - /swagger-resources/** - /login/** chatgpt: token: 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 # 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 timeout: 5000 apiHost: https://api.openai.com/ proxy: isProxy: true host: 127.0.0.1 port: 7890
\ No newline at end of file
# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2024 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: uploadPath # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8086 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # web: # resources: # static-locations: classpath:/static/, classpath:/templates/ # token配置 token: # 令牌自定义标识 header: Authorization # 令牌有效期(默认30分钟) expireTime: 31536000 # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /api sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: - /doc.html - /webjars/** - /swagger-ui.html - /v2/api-docs/** - /swagger/api-docs - /token/code - /swagger-resources/** - /login/** - /profile/** chatgpt: token: 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 # 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 timeout: 5000 apiHost: https://api.openai.com/ proxy: isProxy: true host: 127.0.0.1 port: 7890
\ No newline at end of file
... ...