Compare commits
55 Commits
539656b91a
...
feat/code_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e22bc012c9 | ||
|
|
b598d67281 | ||
|
|
d4c3cf4870 | ||
|
|
bc4b0c9753 | ||
|
|
26474073e5 | ||
|
|
3d50ec5985 | ||
|
|
1ab0e94cfa | ||
|
|
2f087553eb | ||
|
|
59b3dd6320 | ||
|
|
217dc6879d | ||
|
|
12728d5c84 | ||
|
|
8928c076c5 | ||
|
|
ec6723070f | ||
|
|
5b9ac21ecf | ||
|
|
f3637a80f2 | ||
|
|
4bc549eebe | ||
|
|
237fcc7139 | ||
|
|
4277106d00 | ||
|
|
7932222f8e | ||
|
|
6d19b1a021 | ||
|
|
57a28b4049 | ||
|
|
a3c9e2eb51 | ||
|
|
93969624c1 | ||
|
|
4904be16da | ||
|
|
c4915b17c8 | ||
|
|
7fce8c91f2 | ||
|
|
d942b31c8b | ||
|
|
d7b49281c1 | ||
|
|
c6817b23fc | ||
|
|
69257b5c80 | ||
|
|
1cd24c78e7 | ||
|
|
12c4ccdd5d | ||
|
|
d5c096e7a5 | ||
|
|
b7ecbdfa7a | ||
|
|
454d93b5cc | ||
|
|
fd30c72a73 | ||
|
|
48590d5d26 | ||
|
|
56df38d7c5 | ||
|
|
8fbc83bf06 | ||
|
|
d3920fe6c2 | ||
|
|
1b6b48e8df | ||
|
|
2e2e69f139 | ||
|
|
174b7a269c | ||
|
|
dd99d2609b | ||
|
|
b2b1921c32 | ||
|
|
54afcf47fc | ||
|
|
2b68a860c2 | ||
|
|
70224d4c3e | ||
|
|
422ae693b2 | ||
|
|
7c2b8f4731 | ||
|
|
bccf5ad774 | ||
|
|
1e54ee39d4 | ||
|
|
388287fc65 | ||
|
|
e65cc97ef9 | ||
|
|
97b4b6a1a8 |
139
pom.xml
139
pom.xml
@@ -27,35 +27,124 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.github.jsqlparser/jsqlparser -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.xiang</groupId>
|
<groupId>com.github.jsqlparser</groupId>
|
||||||
<artifactId>xservice-common</artifactId>
|
<artifactId>jsqlparser</artifactId>
|
||||||
<version>2.0</version>
|
<version>5.3</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- JUnit 5 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Mockito for JUnit 5 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Boot Test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 添加 Undertow依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- FastJson2中FastJsonHttpMessageConverter找不到类问题 by https://zhengkai.blog.csdn.net/-->
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.60</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2-extension</artifactId>
|
||||||
|
<version>2.0.60</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2-extension-spring6 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2-extension-spring6</artifactId>
|
||||||
|
<version>2.0.59</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 支持 @ConfigurationProperties 注解 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- freemarker -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
<version>4.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-mysql-starter</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-cache-starter</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-common</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-message-starter</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-http-starter</artifactId>
|
||||||
|
<version>2.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.starter</groupId>
|
||||||
|
<artifactId>xmc-logger-starter</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.xiang</groupId>
|
<groupId>com.xiang</groupId>
|
||||||
<artifactId>xservice-message-starter</artifactId>
|
<artifactId>xmc-schedule-starter</artifactId>
|
||||||
<version>2.0</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.xiang</groupId>
|
|
||||||
<artifactId>xservice-schedule-starter</artifactId>
|
|
||||||
<version>2.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.xiang</groupId>
|
|
||||||
<artifactId>xservice-cache-starter</artifactId>
|
|
||||||
<version>2.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.xiang</groupId>
|
|
||||||
<artifactId>xservice-http-starter</artifactId>
|
|
||||||
<version>2.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.xiang</groupId>
|
|
||||||
<artifactId>xservice-mysql-starter</artifactId>
|
|
||||||
<version>2.0</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
"com.xiang.xservice.application.script.fwd.mapper",
|
"com.xiang.xservice.application.script.fwd.mapper",
|
||||||
"com.xiang.xservice.application.script.glados.repository",
|
"com.xiang.xservice.application.script.glados.repository",
|
||||||
"com.xiang.xservice.application.script.xb.repository",
|
"com.xiang.xservice.application.script.xb.repository",
|
||||||
"com.xiang.xservice.application.script.stock.gnshyx.mapper",
|
"com.xiang.xservice.common.mapper",
|
||||||
"com.xiang.xservice.application.script.stock.data.mapper",
|
|
||||||
})
|
})
|
||||||
@ConfigurationPropertiesScan(basePackages = {
|
@ConfigurationPropertiesScan(basePackages = {
|
||||||
"com.xiang.xservice.config"
|
"com.xiang.xservice.config"
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.xiang.xservice.application.generator.controller;
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ParamInfo;
|
||||||
|
import com.xiang.xservice.application.generator.service.CodeGenService;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成控制器
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/generator/code")
|
||||||
|
public class CodeGenController {
|
||||||
|
|
||||||
|
private final CodeGenService codeGenService;
|
||||||
|
|
||||||
|
@PostMapping("/generate")
|
||||||
|
public Result<Map<String, String>> generateCode(@RequestBody ParamInfo paramInfo) throws Exception {
|
||||||
|
return codeGenService.generateCode(paramInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.xiang.xservice.application.generator.controller;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面控制器
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/generator")
|
||||||
|
public class PageController {
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public ModelAndView defaultPage() {
|
||||||
|
return new ModelAndView("newui2");
|
||||||
|
}
|
||||||
|
@GetMapping("/index")
|
||||||
|
public ModelAndView indexPage() {
|
||||||
|
return new ModelAndView("newui2");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.xiang.xservice.application.generator.controller;
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.TemplateList;
|
||||||
|
import com.xiang.xservice.application.generator.service.TemplateService;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板管理控制器
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("system/generator/template")
|
||||||
|
public class TemplateController {
|
||||||
|
|
||||||
|
private final TemplateService templateService;
|
||||||
|
|
||||||
|
@PostMapping("/all")
|
||||||
|
public Result<TemplateList> getAllTemplates() throws Exception {
|
||||||
|
return Result.success(templateService.getAllTemplates());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
package com.xiang.xservice.application.generator.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String 包装类
|
||||||
|
* <p>
|
||||||
|
* 忽略大小写
|
||||||
|
**考虑增加这个类是, 如果在 StringUtils 中加工具方法, 使用起来代码非常冗长且不方便
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class NonCaseString implements CharSequence {
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public static NonCaseString of(String str) {
|
||||||
|
assert str != null;
|
||||||
|
return new NonCaseString(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link String#indexOf(String)} 增强, 忽略大小写
|
||||||
|
*/
|
||||||
|
public int indexOf(String m) {
|
||||||
|
String text = this.value;
|
||||||
|
if (text == null || m == null || text.length() < m.length()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return text.toLowerCase().indexOf(m.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link String#lastIndexOf(String)} 增强, 忽略大小写
|
||||||
|
*/
|
||||||
|
public int lastIndexOf(String m) {
|
||||||
|
String text = this.value;
|
||||||
|
if (text == null || m == null || text.length() < m.length()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return text.toLowerCase().lastIndexOf(m.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否包含, 大小写不敏感
|
||||||
|
* <pre
|
||||||
|
* "abcxyz" 包含 "abc" => true
|
||||||
|
* "abcxyz" 包含 "ABC" => true
|
||||||
|
* "abcxyz" 包含 "aBC" => true
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param m 被包含字符串
|
||||||
|
*/
|
||||||
|
public boolean contains(String m) {
|
||||||
|
String text = this.value;
|
||||||
|
if (text.length() < m.length()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return text.toLowerCase().contains(m.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任意一个包含返回true
|
||||||
|
* <pre>
|
||||||
|
* containsAny("abcdef", "a", "b)
|
||||||
|
* 等价
|
||||||
|
* "abcdef".contains("a") || "abcdef".contains("b")
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param matchers 多个要判断的被包含项
|
||||||
|
*/
|
||||||
|
public boolean containsAny(String... matchers) {
|
||||||
|
for (String matcher : matchers) {
|
||||||
|
if (contains(matcher)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有都包含才返回true
|
||||||
|
*
|
||||||
|
* @param matchers 多个要判断的被包含项
|
||||||
|
*/
|
||||||
|
public boolean containsAllIgnoreCase(String... matchers) {
|
||||||
|
for (String matcher : matchers) {
|
||||||
|
if (contains(matcher) == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NonCaseString trim() {
|
||||||
|
return NonCaseString.of(this.value.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public NonCaseString replace(char oldChar, char newChar) {
|
||||||
|
return NonCaseString.of(this.value.replace(oldChar, newChar));
|
||||||
|
}
|
||||||
|
|
||||||
|
public NonCaseString replaceAll(String regex, String replacement) {
|
||||||
|
return NonCaseString.of(this.value.replaceAll(regex, replacement));
|
||||||
|
}
|
||||||
|
|
||||||
|
public NonCaseString substring(int beginIndex) {
|
||||||
|
return NonCaseString.of(this.value.substring(beginIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
public NonCaseString substring(int beginIndex, int endIndex) {
|
||||||
|
return NonCaseString.of(this.value.substring(beginIndex, endIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNotEmpty() {
|
||||||
|
return !this.value.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int length() {
|
||||||
|
return this.value.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char charAt(int index) {
|
||||||
|
return this.value.charAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence subSequence(int start, int end) {
|
||||||
|
return this.value.subSequence(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] split(String regex) {
|
||||||
|
return this.value.split(regex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 原始字符串
|
||||||
|
*/
|
||||||
|
public String get() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.xiang.xservice.application.generator.entity.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类信息
|
||||||
|
*
|
||||||
|
* @author xiang
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ClassInfo {
|
||||||
|
|
||||||
|
private String tableName;
|
||||||
|
private String originTableName;
|
||||||
|
private String className;
|
||||||
|
private String classComment;
|
||||||
|
private List<FieldInfo> fieldList;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.xiang.xservice.application.generator.entity.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段信息
|
||||||
|
*
|
||||||
|
* @author xiang
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class FieldInfo {
|
||||||
|
|
||||||
|
private String columnName;
|
||||||
|
private String fieldName;
|
||||||
|
private String fieldClass;
|
||||||
|
private String swaggerClass;
|
||||||
|
private String fieldComment;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.xiang.xservice.application.generator.entity.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求参数信息
|
||||||
|
*
|
||||||
|
* @author xiang
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ParamInfo {
|
||||||
|
|
||||||
|
private String tableSql;
|
||||||
|
private Map<String, Object> options;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class NameCaseType {
|
||||||
|
public static final String CAMEL_CASE = "CamelCase";
|
||||||
|
public static final String UNDER_SCORE_CASE = "UnderScoreCase";
|
||||||
|
public static final String UPPER_UNDER_SCORE_CASE = "UpperUnderScoreCase";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.xiang.xservice.application.generator.entity.domain;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Template {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.xiang.xservice.application.generator.entity.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TemplateList {
|
||||||
|
private String group;
|
||||||
|
private List<Template> templates;
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.xiang.xservice.application.generator.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析类型枚举
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum ParserTypeEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL解析类型
|
||||||
|
*/
|
||||||
|
SQL("sql", "默认SQL解析"),
|
||||||
|
JSON("json", "JSON解析"),
|
||||||
|
INSERT_SQL("insert-sql", "INSERT SQL解析"),
|
||||||
|
SQL_REGEX("sql-regex", "正则表达式SQL解析"),
|
||||||
|
SELECT_SQL("select-sql", "SELECT SQL解析"),
|
||||||
|
CREATE_SQL("create-sql", "CREATE SQL解析");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
ParserTypeEnum(String value, String description) {
|
||||||
|
this.value = value;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ParserTypeEnum fromValue(String value) {
|
||||||
|
if (value == null || value.trim().isEmpty()) {
|
||||||
|
return SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
String trimmedValue = value.trim();
|
||||||
|
|
||||||
|
// 首先尝试精确匹配枚举值
|
||||||
|
for (ParserTypeEnum type : ParserTypeEnum.values()) {
|
||||||
|
if (type.getValue().equals(trimmedValue)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果精确匹配失败,尝试忽略大小写匹配
|
||||||
|
for (ParserTypeEnum type : ParserTypeEnum.values()) {
|
||||||
|
if (type.getValue().equalsIgnoreCase(trimmedValue)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试匹配枚举名称
|
||||||
|
for (ParserTypeEnum type : ParserTypeEnum.values()) {
|
||||||
|
if (type.name().equalsIgnoreCase(trimmedValue)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认返回SQL类型
|
||||||
|
return SQL;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.xiang.xservice.application.generator.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ParamInfo;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成服务接口
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
public interface CodeGenService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成代码
|
||||||
|
*
|
||||||
|
* @param paramInfo 参数信息
|
||||||
|
* @return 生成的代码映射
|
||||||
|
* @throws Exception 生成过程中的异常
|
||||||
|
*/
|
||||||
|
Result<Map<String, String>> generateCode(ParamInfo paramInfo) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数获取结果
|
||||||
|
*
|
||||||
|
* @param params 参数映射
|
||||||
|
* @return 结果映射
|
||||||
|
* @throws Exception 处理过程中的异常
|
||||||
|
*/
|
||||||
|
Map<String, String> getResultByParams(Map<String, Object> params) throws Exception;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.xiang.xservice.application.generator.service;
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.TemplateList;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板服务接口
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
public interface TemplateService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有模板配置
|
||||||
|
*
|
||||||
|
* @return 模板配置字符串
|
||||||
|
* @throws IOException IO异常
|
||||||
|
*/
|
||||||
|
List<TemplateList> getAllTemplates() throws IOException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package com.xiang.xservice.application.generator.service.impl;
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ClassInfo;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ParamInfo;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.TemplateList;
|
||||||
|
import com.xiang.xservice.application.generator.enums.ParserTypeEnum;
|
||||||
|
import com.xiang.xservice.application.generator.service.CodeGenService;
|
||||||
|
import com.xiang.xservice.application.generator.service.TemplateService;
|
||||||
|
import com.xiang.xservice.application.generator.service.parser.JsonParserService;
|
||||||
|
import com.xiang.xservice.application.generator.service.parser.SqlParserService;
|
||||||
|
import com.xiang.xservice.application.generator.util.FreemarkerUtil;
|
||||||
|
import com.xiang.xservice.application.generator.util.MapUtil;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成服务实现类
|
||||||
|
*
|
||||||
|
* @author xiang
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class CodeGenServiceImpl implements CodeGenService {
|
||||||
|
|
||||||
|
private final TemplateService templateService;
|
||||||
|
private final SqlParserService sqlParserService;
|
||||||
|
private final JsonParserService jsonParserService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Map<String, String>> generateCode(ParamInfo paramInfo) throws Exception {
|
||||||
|
if (paramInfo.getTableSql() == null || paramInfo.getTableSql().isEmpty()) {
|
||||||
|
return Result.error("表结构信息为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 1. Parse Table Structure 表结构解析
|
||||||
|
ClassInfo classInfo = parseTableStructure(paramInfo);
|
||||||
|
|
||||||
|
// 2. Set the params 设置表格参数
|
||||||
|
paramInfo.getOptions().put("classInfo", classInfo);
|
||||||
|
paramInfo.getOptions().put("tableName", classInfo == null ? System.currentTimeMillis() + "" : classInfo.getTableName());
|
||||||
|
|
||||||
|
// 3. generate the code by freemarker templates with parameters .
|
||||||
|
// Freemarker根据参数和模板生成代码
|
||||||
|
Map<String, String> result = getResultByParams(paramInfo.getOptions());
|
||||||
|
return Result.success(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("代码生成失败", e);
|
||||||
|
return Result.error("代码生成失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getResultByParams(Map<String, Object> params) throws Exception {
|
||||||
|
Map<String, String> result = new HashMap<>(32);
|
||||||
|
result.put("tableName", MapUtil.getString(params, "tableName"));
|
||||||
|
|
||||||
|
// 处理模板生成逻辑
|
||||||
|
// 解析模板配置并生成代码
|
||||||
|
List<TemplateList> parentTemplates = templateService.getAllTemplates();
|
||||||
|
for (TemplateList parentTemplateObj : parentTemplates) {
|
||||||
|
List<com.xiang.xservice.application.generator.entity.domain.Template> childTemplates = parentTemplateObj.getTemplates();
|
||||||
|
if (childTemplates != null) {
|
||||||
|
for (int x = 0; x < childTemplates.size(); x++) {
|
||||||
|
com.xiang.xservice.application.generator.entity.domain.Template childTemplate = childTemplates.get(x);
|
||||||
|
String templatePath = parentTemplateObj.getGroup() + "/" + childTemplate.getName() + ".ftl";
|
||||||
|
String generatedCode = FreemarkerUtil.processString(templatePath, params);
|
||||||
|
result.put(childTemplate.getName(), generatedCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据不同的解析类型解析表结构
|
||||||
|
*
|
||||||
|
* @param paramInfo 参数信息
|
||||||
|
* @return 类信息
|
||||||
|
* @throws Exception 解析异常
|
||||||
|
*/
|
||||||
|
private ClassInfo parseTableStructure(ParamInfo paramInfo) throws Exception {
|
||||||
|
String dataType = MapUtil.getString(paramInfo.getOptions(), "dataType");
|
||||||
|
ParserTypeEnum parserType = ParserTypeEnum.fromValue(dataType);
|
||||||
|
|
||||||
|
// 添加调试信息
|
||||||
|
log.debug("解析数据类型: {}, 解析结果: {}", dataType, parserType);
|
||||||
|
|
||||||
|
switch (parserType) {
|
||||||
|
case SQL:
|
||||||
|
// 默认模式:parse DDL table structure from sql
|
||||||
|
return sqlParserService.processTableIntoClassInfo(paramInfo);
|
||||||
|
case JSON:
|
||||||
|
// JSON模式:parse field from json string
|
||||||
|
return jsonParserService.processJsonToClassInfo(paramInfo);
|
||||||
|
case INSERT_SQL:
|
||||||
|
// INSERT SQL模式:parse field from insert sql
|
||||||
|
return sqlParserService.processInsertSqlToClassInfo(paramInfo);
|
||||||
|
case SQL_REGEX:
|
||||||
|
// 正则表达式模式(非完善版本):parse sql by regex
|
||||||
|
return sqlParserService.processTableToClassInfoByRegex(paramInfo);
|
||||||
|
case SELECT_SQL:
|
||||||
|
// SelectSqlBySQLPraser模式:parse select sql by JSqlParser
|
||||||
|
return sqlParserService.generateSelectSqlBySQLPraser(paramInfo);
|
||||||
|
case CREATE_SQL:
|
||||||
|
// CreateSqlBySQLPraser模式:parse create sql by JSqlParser
|
||||||
|
return sqlParserService.generateCreateSqlBySQLPraser(paramInfo);
|
||||||
|
default:
|
||||||
|
// 默认模式:parse DDL table structure from sql
|
||||||
|
return sqlParserService.processTableIntoClassInfo(paramInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.xiang.xservice.application.generator.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.TemplateList;
|
||||||
|
import com.xiang.xservice.application.generator.service.TemplateService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.StreamUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板服务实现类
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class TemplateServiceImpl implements TemplateService {
|
||||||
|
|
||||||
|
private String templateConfig = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TemplateList> getAllTemplates() throws IOException {
|
||||||
|
if (templateConfig == null) {
|
||||||
|
ClassPathResource resource = new ClassPathResource("template.json");
|
||||||
|
try (InputStream inputStream = resource.getInputStream()) {
|
||||||
|
templateConfig = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return JSONArray.parseArray(templateConfig, TemplateList.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package com.xiang.xservice.application.generator.service.impl.parser;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ClassInfo;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.FieldInfo;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ParamInfo;
|
||||||
|
import com.xiang.xservice.application.generator.service.parser.JsonParserService;
|
||||||
|
import com.xiang.xservice.basic.exception.BusinessException;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON解析服务实现类
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class JsonParserServiceImpl implements JsonParserService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClassInfo processJsonToClassInfo(ParamInfo paramInfo) {
|
||||||
|
ClassInfo codeJavaInfo = new ClassInfo();
|
||||||
|
codeJavaInfo.setTableName("JsonDto");
|
||||||
|
codeJavaInfo.setClassName("JsonDto");
|
||||||
|
codeJavaInfo.setClassComment("JsonDto");
|
||||||
|
|
||||||
|
//support children json if forget to add '{' in front of json
|
||||||
|
if (paramInfo.getTableSql().trim().startsWith("\"")) {
|
||||||
|
paramInfo.setTableSql("{" + paramInfo.getTableSql());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (paramInfo.getTableSql().trim().startsWith("{")) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(paramInfo.getTableSql().trim());
|
||||||
|
//parse FieldList by JSONObject
|
||||||
|
codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonObject));
|
||||||
|
} else if (paramInfo.getTableSql().trim().startsWith("[")) {
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(paramInfo.getTableSql().trim());
|
||||||
|
//parse FieldList by JSONObject
|
||||||
|
codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonArray.getJSONObject(0)));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// JSON解析失败,抛出自定义异常
|
||||||
|
throw new BusinessException("JSON格式不正确: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return codeJavaInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FieldInfo> processJsonObjectToFieldList(JSONObject jsonObject) {
|
||||||
|
// field List
|
||||||
|
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||||
|
for (String jsonField : jsonObject.keySet()) {
|
||||||
|
FieldInfo fieldInfo = new FieldInfo();
|
||||||
|
fieldInfo.setFieldName(jsonField);
|
||||||
|
fieldInfo.setColumnName(jsonField);
|
||||||
|
fieldInfo.setFieldClass(String.class.getSimpleName());
|
||||||
|
fieldInfo.setFieldComment("father:" + jsonField);
|
||||||
|
fieldList.add(fieldInfo);
|
||||||
|
if (jsonObject.get(jsonField) instanceof JSONArray) {
|
||||||
|
JSONArray jsonArray = jsonObject.getJSONArray(jsonField);
|
||||||
|
for (Object arrayObject : jsonArray) {
|
||||||
|
FieldInfo fieldInfo2 = new FieldInfo();
|
||||||
|
fieldInfo2.setFieldName(arrayObject.toString());
|
||||||
|
fieldInfo2.setColumnName(arrayObject.toString());
|
||||||
|
fieldInfo2.setFieldClass(String.class.getSimpleName());
|
||||||
|
fieldInfo2.setFieldComment("children:" + arrayObject.toString());
|
||||||
|
fieldList.add(fieldInfo2);
|
||||||
|
}
|
||||||
|
} else if (jsonObject.get(jsonField) instanceof JSONObject) {
|
||||||
|
JSONObject subJsonObject = jsonObject.getJSONObject(jsonField);
|
||||||
|
for (String arrayObject : subJsonObject.keySet()) {
|
||||||
|
FieldInfo fieldInfo2 = new FieldInfo();
|
||||||
|
fieldInfo2.setFieldName(arrayObject.toString());
|
||||||
|
fieldInfo2.setColumnName(arrayObject.toString());
|
||||||
|
fieldInfo2.setFieldClass(String.class.getSimpleName());
|
||||||
|
fieldInfo2.setFieldComment("children:" + arrayObject.toString());
|
||||||
|
fieldList.add(fieldInfo2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fieldList.size() < 1) {
|
||||||
|
throw new BusinessException("JSON解析失败");
|
||||||
|
}
|
||||||
|
return fieldList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,545 @@
|
|||||||
|
package com.xiang.xservice.application.generator.service.impl.parser;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ClassInfo;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.FieldInfo;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ParamInfo;
|
||||||
|
import com.xiang.xservice.application.generator.service.parser.SqlParserService;
|
||||||
|
import com.xiang.xservice.application.generator.util.MapUtil;
|
||||||
|
import com.xiang.xservice.application.generator.util.StringUtilsPlus;
|
||||||
|
import com.xiang.xservice.application.generator.util.Mysql2JavaTypeUtil;
|
||||||
|
import com.xiang.xservice.basic.exception.BusinessException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.sf.jsqlparser.parser.CCJSqlParserManager;
|
||||||
|
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||||
|
import net.sf.jsqlparser.schema.Column;
|
||||||
|
import net.sf.jsqlparser.statement.Statement;
|
||||||
|
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
|
||||||
|
import net.sf.jsqlparser.statement.create.table.CreateTable;
|
||||||
|
import net.sf.jsqlparser.statement.select.PlainSelect;
|
||||||
|
import net.sf.jsqlparser.statement.select.Select;
|
||||||
|
import net.sf.jsqlparser.statement.select.SelectItem;
|
||||||
|
import net.sf.jsqlparser.util.TablesNamesFinder;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL解析服务实现类
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class SqlParserServiceImpl implements SqlParserService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Exception {
|
||||||
|
ClassInfo classInfo = new ClassInfo();
|
||||||
|
String processedSql = paramInfo.getTableSql().trim()
|
||||||
|
.replaceAll("'", "`") // 将单引号替换为反引号
|
||||||
|
.replaceAll("\"", "`") // 将双引号替换为反引号
|
||||||
|
.replaceAll(",", ","); // 将中文逗号替换为英文逗号
|
||||||
|
|
||||||
|
Statement statement = null;
|
||||||
|
CCJSqlParserManager parserManager = new CCJSqlParserManager();
|
||||||
|
statement = parserManager.parse(new StringReader(processedSql));
|
||||||
|
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); // 创建表名发现者对象
|
||||||
|
List<String> tableNameList = tablesNamesFinder.getTableList(statement); // 获取到表名列表
|
||||||
|
//一般这里应该只解析到一个表名,除非多个表名,取第一个
|
||||||
|
if (!CollectionUtils.isEmpty(tableNameList)) {
|
||||||
|
String tableName = tableNameList.get(0).trim();
|
||||||
|
classInfo.setTableName(tableName);
|
||||||
|
classInfo.setOriginTableName(tableName);
|
||||||
|
String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)).replaceAll("`", "");
|
||||||
|
if (className.contains("_")) {
|
||||||
|
className = className.replaceAll("_", "");
|
||||||
|
}
|
||||||
|
classInfo.setClassName(className);
|
||||||
|
classInfo.setClassComment(paramInfo.getTableSql());
|
||||||
|
}
|
||||||
|
//解析查询元素
|
||||||
|
Select select = null;
|
||||||
|
select = (Select) CCJSqlParserUtil.parse(paramInfo.getTableSql());
|
||||||
|
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
|
||||||
|
List<SelectItem<?>> selectItems = plainSelect.getSelectItems();
|
||||||
|
|
||||||
|
// field List
|
||||||
|
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||||
|
selectItems.forEach(t->{
|
||||||
|
FieldInfo fieldInfo = new FieldInfo();
|
||||||
|
String fieldName = ((Column)t.getExpression()).getColumnName().replaceAll("`", "");
|
||||||
|
String aliasName = t.getAlias() != null ? t.getAlias().getName() : ((Column)t.getExpression()).getColumnName();
|
||||||
|
//存储原始字段名
|
||||||
|
fieldInfo.setFieldComment(aliasName);fieldInfo.setColumnName(aliasName);
|
||||||
|
//处理字段名是t.xxx的情况
|
||||||
|
fieldName=fieldName.contains(".")?fieldName.substring(fieldName.indexOf(".")+1):fieldName;
|
||||||
|
//转换前
|
||||||
|
fieldInfo.setColumnName(fieldName);
|
||||||
|
fieldName = switch ((String) paramInfo.getOptions().get("nameCaseType")) {
|
||||||
|
case ParamInfo.NameCaseType.CAMEL_CASE ->
|
||||||
|
// 2024-1-27 L&J 适配任意(maybe)原始风格转小写驼峰
|
||||||
|
StringUtilsPlus.toLowerCamel(aliasName);
|
||||||
|
case ParamInfo.NameCaseType.UNDER_SCORE_CASE -> StringUtilsPlus.toUnderline(aliasName, false);
|
||||||
|
case ParamInfo.NameCaseType.UPPER_UNDER_SCORE_CASE ->
|
||||||
|
StringUtilsPlus.toUnderline(aliasName.toUpperCase(), true);
|
||||||
|
default -> aliasName;
|
||||||
|
};
|
||||||
|
//转换后
|
||||||
|
fieldInfo.setFieldName(fieldName);
|
||||||
|
|
||||||
|
//无法推测类型,所有都set为String
|
||||||
|
fieldInfo.setFieldClass("String");
|
||||||
|
fieldList.add(fieldInfo);
|
||||||
|
});
|
||||||
|
classInfo.setFieldList(fieldList);
|
||||||
|
log.info("classInfo:{}", JSON.toJSONString(classInfo));
|
||||||
|
return classInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception {
|
||||||
|
ClassInfo classInfo = new ClassInfo();
|
||||||
|
Statement statement = null;
|
||||||
|
// 对SQL进行预处理,以提高解析成功率
|
||||||
|
String processedSql = paramInfo.getTableSql().trim()
|
||||||
|
.replaceAll("'", "`") // 将单引号替换为反引号
|
||||||
|
.replaceAll("\"", "`") // 将双引号替换为反引号
|
||||||
|
.replaceAll(",", ","); // 将中文逗号替换为英文逗号
|
||||||
|
|
||||||
|
try {
|
||||||
|
statement = CCJSqlParserUtil.parse(processedSql);
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new BusinessException("SQL语法错误:"+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保是CREATE TABLE语句
|
||||||
|
if (!(statement instanceof CreateTable createTable)) {
|
||||||
|
throw new BusinessException("检测到SQL语句不是DLL CREATE TABLE语句");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取表名
|
||||||
|
String tableName = createTable.getTable().getName().replaceAll("`", "");
|
||||||
|
classInfo.setTableName(tableName);
|
||||||
|
String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName));
|
||||||
|
if (className.contains("_")) {
|
||||||
|
className = className.replaceAll("_", "");
|
||||||
|
}
|
||||||
|
classInfo.setClassName(className);
|
||||||
|
classInfo.setOriginTableName(tableName);
|
||||||
|
classInfo.setClassComment(paramInfo.getTableSql());
|
||||||
|
|
||||||
|
// 提取字段信息
|
||||||
|
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||||
|
List<ColumnDefinition> columnDefinitions = createTable.getColumnDefinitions();
|
||||||
|
|
||||||
|
if (columnDefinitions != null) {
|
||||||
|
for (ColumnDefinition columnDefinition : columnDefinitions) {
|
||||||
|
FieldInfo fieldInfo = new FieldInfo();
|
||||||
|
String columnName = columnDefinition.getColumnName().replaceAll("`", "");
|
||||||
|
fieldInfo.setColumnName(columnName);
|
||||||
|
fieldInfo.setFieldComment(columnDefinition.toString());
|
||||||
|
|
||||||
|
// 根据命名规则转换字段名
|
||||||
|
String fieldName = switch ((String) paramInfo.getOptions().get("nameCaseType")) {
|
||||||
|
case ParamInfo.NameCaseType.CAMEL_CASE -> StringUtilsPlus.toLowerCamel(columnName);
|
||||||
|
case ParamInfo.NameCaseType.UNDER_SCORE_CASE -> StringUtilsPlus.toUnderline(columnName, false);
|
||||||
|
case ParamInfo.NameCaseType.UPPER_UNDER_SCORE_CASE ->
|
||||||
|
StringUtilsPlus.toUnderline(columnName.toUpperCase(), true);
|
||||||
|
default -> columnName;
|
||||||
|
};
|
||||||
|
fieldInfo.setFieldName(fieldName);
|
||||||
|
|
||||||
|
// 设置字段类型为String(因为无法准确推测类型)
|
||||||
|
fieldInfo.setFieldClass("String");
|
||||||
|
fieldList.add(fieldInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
classInfo.setFieldList(fieldList);
|
||||||
|
log.info("classInfo:{}", JSON.toJSONString(classInfo));
|
||||||
|
return classInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception {
|
||||||
|
//process the param
|
||||||
|
String tableSql = paramInfo.getTableSql();
|
||||||
|
String nameCaseType = MapUtil.getString(paramInfo.getOptions(),"nameCaseType");
|
||||||
|
String isPackageType = MapUtil.getString(paramInfo.getOptions(),"isPackageType");
|
||||||
|
|
||||||
|
//更新空值处理
|
||||||
|
if (StringUtils.isBlank(tableSql)) {
|
||||||
|
throw new Exception("Table structure can not be empty. 表结构不能为空。");
|
||||||
|
}
|
||||||
|
//deal with special character
|
||||||
|
tableSql = tableSql.trim()
|
||||||
|
.replaceAll("'", "`")
|
||||||
|
.replaceAll("\"", "`")
|
||||||
|
.replaceAll(",", ",")
|
||||||
|
// 这里全部转小写, 会让驼峰风格的字段名丢失驼峰信息(真有驼峰sql字段名的呢(* ̄︶ ̄)); 下文使用工具方法处理包含等
|
||||||
|
// .toLowerCase()
|
||||||
|
;
|
||||||
|
//deal with java string copy \n"
|
||||||
|
tableSql = tableSql.trim().replaceAll("\\\\n`", "").replaceAll("\\+", "").replaceAll("``", "`").replaceAll("\\\\", "");
|
||||||
|
// table Name
|
||||||
|
String tableName = null;
|
||||||
|
int tableKwIx = tableSql.indexOf("TABLE"); // 包含判断和位置一次搞定
|
||||||
|
if (tableKwIx > -1 && tableSql.contains("(")) {
|
||||||
|
tableName = tableSql.substring(tableKwIx + 5, tableSql.indexOf("("));
|
||||||
|
} else {
|
||||||
|
throw new Exception("Table structure incorrect.表结构不正确。");
|
||||||
|
}
|
||||||
|
|
||||||
|
//新增处理create table if not exists members情况
|
||||||
|
if (tableName.contains("if not exists")) {
|
||||||
|
tableName = tableName.replaceAll("if not exists", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tableName.contains("`")) {
|
||||||
|
tableName = tableName.substring(tableName.indexOf("`") + 1, tableName.lastIndexOf("`"));
|
||||||
|
} else {
|
||||||
|
//空格开头的,需要替换掉\n\t空格
|
||||||
|
tableName = tableName.replaceAll(" ", "").replaceAll("\n", "").replaceAll("\t", "");
|
||||||
|
}
|
||||||
|
//优化对byeas`.`ct_bd_customerdiscount这种命名的支持
|
||||||
|
if (tableName.contains("`.`")) {
|
||||||
|
tableName = tableName.substring(tableName.indexOf("`.`") + 3);
|
||||||
|
} else if (tableName.contains(".")) {
|
||||||
|
//优化对likeu.members这种命名的支持
|
||||||
|
tableName = tableName.substring(tableName.indexOf(".") + 1);
|
||||||
|
}
|
||||||
|
String originTableName = tableName;
|
||||||
|
//ignore prefix
|
||||||
|
if(tableName!=null && StringUtils.isNotBlank(MapUtil.getString(paramInfo.getOptions(),"ignorePrefix"))){
|
||||||
|
tableName = tableName.replaceAll(MapUtil.getString(paramInfo.getOptions(),"ignorePrefix"),"");
|
||||||
|
}
|
||||||
|
// class Name
|
||||||
|
String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName));
|
||||||
|
if (className.contains("_")) {
|
||||||
|
className = className.replaceAll("_", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// class Comment
|
||||||
|
String classComment = null;
|
||||||
|
//mysql是comment=,pgsql/oracle是comment on table,
|
||||||
|
//2020-05-25 优化表备注的获取逻辑
|
||||||
|
if (tableSql.toLowerCase().contains("comment=") || tableSql.toLowerCase().contains("comment on table")) {
|
||||||
|
int ix = tableSql.toLowerCase().lastIndexOf("comment=");
|
||||||
|
String classCommentTmp = (ix > -1) ?
|
||||||
|
tableSql.substring(ix + 8).trim() :
|
||||||
|
tableSql.substring(tableSql.toLowerCase().lastIndexOf("comment on table") + 17).trim();
|
||||||
|
if (classCommentTmp.contains("`")) {
|
||||||
|
classCommentTmp = classCommentTmp.substring(classCommentTmp.indexOf("`") + 1);
|
||||||
|
classCommentTmp = classCommentTmp.substring(0, classCommentTmp.indexOf("`"));
|
||||||
|
classComment = classCommentTmp;
|
||||||
|
} else {
|
||||||
|
//非常规的没法分析
|
||||||
|
classComment = className;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//修复表备注为空问题
|
||||||
|
classComment = tableName;
|
||||||
|
}
|
||||||
|
//如果备注跟;混在一起,需要替换掉
|
||||||
|
classComment = classComment.replaceAll(";", "");
|
||||||
|
// field List
|
||||||
|
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||||
|
|
||||||
|
// 正常( ) 内的一定是字段相关的定义。
|
||||||
|
String fieldListTmp = tableSql.substring(tableSql.indexOf("(") + 1, tableSql.lastIndexOf(")")).trim();
|
||||||
|
|
||||||
|
// 匹配 comment,替换备注里的小逗号, 防止不小心被当成切割符号切割
|
||||||
|
String commentPattenStr1 = "comment `(.*?)\\`";
|
||||||
|
Matcher matcher1 = Pattern.compile(commentPattenStr1).matcher(fieldListTmp.toLowerCase());
|
||||||
|
while (matcher1.find()) {
|
||||||
|
|
||||||
|
String commentTmp = matcher1.group();
|
||||||
|
//2018-9-27 zhengk 不替换,只处理,支持COMMENT评论里面多种注释
|
||||||
|
//commentTmp = commentTmp.replaceAll("\\ comment `|\\`", " "); // "\\{|\\}"
|
||||||
|
|
||||||
|
if (commentTmp.contains(",")) {
|
||||||
|
String commentTmpFinal = commentTmp.replaceAll(",", ",");
|
||||||
|
fieldListTmp = fieldListTmp.replace(matcher1.group(), commentTmpFinal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//2018-10-18 zhengkai 新增支持double(10, 2)等类型中有英文逗号的特殊情况
|
||||||
|
String commentPattenStr2 = "\\`(.*?)\\`";
|
||||||
|
Matcher matcher2 = Pattern.compile(commentPattenStr2).matcher(fieldListTmp);
|
||||||
|
while (matcher2.find()) {
|
||||||
|
String commentTmp2 = matcher2.group();
|
||||||
|
if (commentTmp2.contains(",")) {
|
||||||
|
String commentTmpFinal = commentTmp2.replaceAll(",", ",").replaceAll("\\(", "(").replaceAll("\\)", ")");
|
||||||
|
fieldListTmp = fieldListTmp.replace(matcher2.group(), commentTmpFinal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//2018-10-18 zhengkai 新增支持double(10, 2)等类型中有英文逗号的特殊情况
|
||||||
|
String commentPattenStr3 = "\\((.*?)\\)";
|
||||||
|
Matcher matcher3 = Pattern.compile(commentPattenStr3).matcher(fieldListTmp);
|
||||||
|
while (matcher3.find()) {
|
||||||
|
String commentTmp3 = matcher3.group();
|
||||||
|
if (commentTmp3.contains(",")) {
|
||||||
|
String commentTmpFinal = commentTmp3.replaceAll(",", ",");
|
||||||
|
fieldListTmp = fieldListTmp.replace(matcher3.group(), commentTmpFinal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String[] fieldLineList = fieldListTmp.split(",");
|
||||||
|
if (fieldLineList.length > 0) {
|
||||||
|
int i = 0;
|
||||||
|
//i为了解决primary key关键字出现的地方,出现在前3行,一般和id有关
|
||||||
|
for (String columnLine0 : fieldLineList) {
|
||||||
|
i++;
|
||||||
|
String columnLine = columnLine0.replaceAll("\n", "").replaceAll("\t", "").trim();
|
||||||
|
// `userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
|
||||||
|
// 2018-9-18 zhengk 修改为contains,提升匹配率和匹配不按照规矩出牌的语句
|
||||||
|
// 2018-11-8 zhengkai 修复tornadoorz反馈的KEY FK_permission_id (permission_id),KEY FK_role_id (role_id)情况
|
||||||
|
// 2019-2-22 zhengkai 要在条件中使用复杂的表达式
|
||||||
|
// 2019-4-29 zhengkai 优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 )
|
||||||
|
// 2020-10-20 zhengkai 优化对fulltext/index关键字的处理(感谢@WEGFan的反馈)
|
||||||
|
// 2025-12-07 zhengkai 修复对primary key的处理
|
||||||
|
boolean notSpecialFlag = (
|
||||||
|
!columnLine.contains("key ")
|
||||||
|
&& !columnLine.toLowerCase().contains("constraint")
|
||||||
|
&& !columnLine.toLowerCase().contains(" using ")
|
||||||
|
&& !columnLine.toLowerCase().contains("unique ")
|
||||||
|
&& !columnLine.toLowerCase().contains("fulltext ")
|
||||||
|
&& !columnLine.toLowerCase().contains("index ")
|
||||||
|
&& !columnLine.toLowerCase().contains("pctincrease")
|
||||||
|
&& !columnLine.toLowerCase().contains("buffer_pool")
|
||||||
|
&& !columnLine.toLowerCase().contains("tablespace")
|
||||||
|
&& !(columnLine.toLowerCase().contains("primary ") && columnLine.indexOf("storage") + 3 > columnLine.indexOf("("))
|
||||||
|
&& !(columnLine.toLowerCase().contains("primary ") && i > 3)
|
||||||
|
&& !columnLine.toLowerCase().contains("primary key")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (notSpecialFlag) {
|
||||||
|
//如果是oracle的number(x,x),可能出现最后分割残留的,x),这里做排除处理
|
||||||
|
if (columnLine.length() < 5) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//2018-9-16 zhengkai 支持'符号以及空格的oracle语句// userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
|
||||||
|
String columnName = "";
|
||||||
|
columnLine = columnLine.replaceAll("`", " ").replaceAll("\"", " ").replaceAll("'", "").replaceAll(" ", " ").trim();
|
||||||
|
//如果遇到username varchar(65) default '' not null,这种情况,判断第一个空格是否比第一个引号前
|
||||||
|
try {
|
||||||
|
columnName = columnLine.substring(0, columnLine.indexOf(" "));
|
||||||
|
} catch (StringIndexOutOfBoundsException e) {
|
||||||
|
System.out.println("err happened: " + columnLine);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// field Name
|
||||||
|
// 2019-09-08 yj 添加是否下划线转换为驼峰的判断
|
||||||
|
// 2023-8-27 L&J 支持原始列名任意命名风格, 不依赖用户是否输入下划线
|
||||||
|
String fieldName = null;
|
||||||
|
if (ParamInfo.NameCaseType.CAMEL_CASE.equals(nameCaseType)) {
|
||||||
|
// 2024-1-27 L&J 适配任意(maybe)原始风格转小写驼峰
|
||||||
|
fieldName = StringUtilsPlus.toLowerCamel(columnName);
|
||||||
|
} else if (ParamInfo.NameCaseType.UNDER_SCORE_CASE.equals(nameCaseType)) {
|
||||||
|
fieldName = StringUtilsPlus.toUnderline(columnName, false);
|
||||||
|
} else if (ParamInfo.NameCaseType.UPPER_UNDER_SCORE_CASE.equals(nameCaseType)) {
|
||||||
|
fieldName = StringUtilsPlus.toUnderline(columnName.toUpperCase(), true);
|
||||||
|
} else {
|
||||||
|
fieldName = columnName;
|
||||||
|
}
|
||||||
|
// 修复Oracle字段名不带引号的情况
|
||||||
|
if (columnLine.contains("`")) {
|
||||||
|
columnLine = columnLine.substring(columnLine.indexOf("`") + 1).trim();
|
||||||
|
}
|
||||||
|
//2025-03-16 修复由于类型大写导致无法转换的问题
|
||||||
|
String mysqlType = columnLine.split("\\s+")[1].toLowerCase();
|
||||||
|
if(mysqlType.contains("(")){
|
||||||
|
mysqlType = mysqlType.substring(0, mysqlType.indexOf("("));
|
||||||
|
}
|
||||||
|
//swagger class
|
||||||
|
String swaggerClass = "string" ;
|
||||||
|
if(Mysql2JavaTypeUtil.getMysqlSwaggerTypeMap().containsKey(mysqlType)){
|
||||||
|
swaggerClass = Mysql2JavaTypeUtil.getMysqlSwaggerTypeMap().get(mysqlType);
|
||||||
|
}
|
||||||
|
// field class
|
||||||
|
// int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
|
||||||
|
String fieldClass = "String";
|
||||||
|
//2018-9-16 zhengk 补充char/clob/blob/json等类型,如果类型未知,默认为String
|
||||||
|
//2018-11-22 lshz0088 处理字段类型的时候,不严谨columnLine.contains(" int") 类似这种的,可在前后适当加一些空格之类的加以区分,否则当我的字段包含这些字符的时候,产生类型判断问题。
|
||||||
|
//2020-05-03 MOSHOW.K.ZHENG 优化对所有类型的处理
|
||||||
|
//2020-10-20 zhengkai 新增包装类型的转换选择
|
||||||
|
if(Mysql2JavaTypeUtil.getMysqlJavaTypeMap().containsKey(mysqlType)){
|
||||||
|
fieldClass = Mysql2JavaTypeUtil.getMysqlJavaTypeMap().get(mysqlType);
|
||||||
|
}
|
||||||
|
// field comment,MySQL的一般位于field行,而pgsql和oralce多位于后面。
|
||||||
|
String fieldComment = null;
|
||||||
|
if (tableSql.toLowerCase().contains("comment on column") && (tableSql.toLowerCase().contains("." + columnName + " is ") || tableSql.toLowerCase().contains(".`" + columnName + "` is"))) {
|
||||||
|
//新增对pgsql/oracle的字段备注支持
|
||||||
|
//COMMENT ON COLUMN public.check_info.check_name IS '检查者名称';
|
||||||
|
//2018-11-22 lshz0088 正则表达式的点号前面应该加上两个反斜杠,否则会认为是任意字符
|
||||||
|
//2019-4-29 zhengkai 优化对oracle注释comment on column的支持(@liukex)
|
||||||
|
tableSql = tableSql.toLowerCase().replaceAll(".`" + columnName + "` is", "." + columnName + " is");
|
||||||
|
Matcher columnCommentMatcher = Pattern.compile("\\." + columnName + " is `").matcher(tableSql.toLowerCase());
|
||||||
|
fieldComment = columnName;
|
||||||
|
while (columnCommentMatcher.find()) {
|
||||||
|
String columnCommentTmp = columnCommentMatcher.group();
|
||||||
|
//System.out.println(columnCommentTmp);
|
||||||
|
fieldComment = tableSql.substring(tableSql.indexOf(columnCommentTmp) + columnCommentTmp.length()).trim();
|
||||||
|
fieldComment = fieldComment.substring(0, fieldComment.indexOf("`")).trim();
|
||||||
|
}
|
||||||
|
} else if (columnLine.toLowerCase().contains(" comment")) {
|
||||||
|
//20200518 zhengkai 修复包含comment关键字的问题
|
||||||
|
String commentTmp = columnLine.toLowerCase().substring(columnLine.toLowerCase().lastIndexOf("comment") + 7).trim();
|
||||||
|
// '用户ID',
|
||||||
|
if (commentTmp.contains("`") || commentTmp.indexOf("`") != commentTmp.lastIndexOf("`")) {
|
||||||
|
commentTmp = commentTmp.substring(commentTmp.indexOf("`") + 1, commentTmp.lastIndexOf("`"));
|
||||||
|
}
|
||||||
|
//解决最后一句是评论,无主键且连着)的问题:album_id int(3) default '1' null comment '相册id:0 代表头像 1代表照片墙')
|
||||||
|
if (commentTmp.contains(")")) {
|
||||||
|
commentTmp = commentTmp.substring(0, commentTmp.lastIndexOf(")") + 1);
|
||||||
|
}
|
||||||
|
fieldComment = commentTmp;
|
||||||
|
} else if (columnLine.contains("--")) {
|
||||||
|
// 支持Oracle风格的注释(--)
|
||||||
|
fieldComment = columnLine.substring(columnLine.indexOf("--") + 2).trim();
|
||||||
|
} else {
|
||||||
|
//修复comment不存在导致报错的问题
|
||||||
|
fieldComment = columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldInfo fieldInfo = new FieldInfo();
|
||||||
|
//
|
||||||
|
fieldInfo.setColumnName(columnName);
|
||||||
|
fieldInfo.setFieldName(fieldName);
|
||||||
|
fieldInfo.setFieldClass(fieldClass);
|
||||||
|
fieldInfo.setSwaggerClass(swaggerClass);
|
||||||
|
fieldInfo.setFieldComment(fieldComment);
|
||||||
|
|
||||||
|
fieldList.add(fieldInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldList.isEmpty()) {
|
||||||
|
throw new Exception("表结构分析失败,请检查语句或者提交issue给我");
|
||||||
|
}
|
||||||
|
//build Class Info
|
||||||
|
ClassInfo codeJavaInfo = new ClassInfo();
|
||||||
|
codeJavaInfo.setTableName(tableName);
|
||||||
|
codeJavaInfo.setClassName(className);
|
||||||
|
codeJavaInfo.setClassComment(classComment);
|
||||||
|
codeJavaInfo.setFieldList(fieldList);
|
||||||
|
codeJavaInfo.setOriginTableName(originTableName);
|
||||||
|
|
||||||
|
return codeJavaInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo) {
|
||||||
|
// field List
|
||||||
|
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||||
|
//return classInfo
|
||||||
|
ClassInfo codeJavaInfo = new ClassInfo();
|
||||||
|
|
||||||
|
//匹配整个ddl,将ddl分为表名,列sql部分,表注释
|
||||||
|
String DDL_PATTEN_STR = "\\s*create\\s+table\\s+(?<tableName>\\S+)[^\\(]*\\((?<columnsSQL>[\\s\\S]+)\\)[^\\)]+?(comment\\s*(=|on\\s+table)\\s*'(?<tableComment>.*?)'\\s*;?)?$";
|
||||||
|
|
||||||
|
Pattern DDL_PATTERN = Pattern.compile(DDL_PATTEN_STR, Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
|
//匹配列sql部分,分别解析每一列的列名 类型 和列注释
|
||||||
|
String COL_PATTERN_STR = "\\s*(?<fieldName>\\S+)\\s+(?<fieldType>\\w+)\\s*(?:\\([\\s\\d,]+\\))?((?!comment).)*(comment\\s*'(?<fieldComment>.*?)')?\\s*(,|$)";
|
||||||
|
|
||||||
|
Pattern COL_PATTERN = Pattern.compile(COL_PATTERN_STR, Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
|
Matcher matcher = Pattern.compile(DDL_PATTEN_STR).matcher(paramInfo.getTableSql().trim());
|
||||||
|
if (matcher.find()) {
|
||||||
|
String tableName = matcher.group("tableName");
|
||||||
|
String tableComment = matcher.group("tableComment");
|
||||||
|
codeJavaInfo.setTableName(tableName.replaceAll("'", ""));
|
||||||
|
codeJavaInfo.setClassName(tableName.replaceAll("'", ""));
|
||||||
|
codeJavaInfo.setClassComment(tableComment.replaceAll("'", ""));
|
||||||
|
String columnsSQL = matcher.group("columnsSQL");
|
||||||
|
if (columnsSQL != null && columnsSQL.length() > 0) {
|
||||||
|
Matcher colMatcher = COL_PATTERN.matcher(columnsSQL);
|
||||||
|
while (colMatcher.find()) {
|
||||||
|
String fieldName = colMatcher.group("fieldName");
|
||||||
|
String fieldType = colMatcher.group("fieldType");
|
||||||
|
String fieldComment = colMatcher.group("fieldComment");
|
||||||
|
if (!"key".equalsIgnoreCase(fieldType)) {
|
||||||
|
FieldInfo fieldInfo = new FieldInfo();
|
||||||
|
fieldInfo.setFieldName(fieldName.replaceAll("'", ""));
|
||||||
|
fieldInfo.setColumnName(fieldName.replaceAll("'", ""));
|
||||||
|
fieldInfo.setFieldClass(fieldType.replaceAll("'", ""));
|
||||||
|
fieldInfo.setFieldComment(fieldComment.replaceAll("'", ""));
|
||||||
|
fieldList.add(fieldInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
codeJavaInfo.setFieldList(fieldList);
|
||||||
|
}
|
||||||
|
return codeJavaInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClassInfo processInsertSqlToClassInfo(ParamInfo paramInfo) {
|
||||||
|
// field List
|
||||||
|
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||||
|
//return classInfo
|
||||||
|
ClassInfo codeJavaInfo = new ClassInfo();
|
||||||
|
|
||||||
|
//get origin sql
|
||||||
|
String fieldSqlStr = paramInfo.getTableSql().toLowerCase().trim();
|
||||||
|
fieldSqlStr = fieldSqlStr.replaceAll(" ", " ").replaceAll("\\\\n`", "")
|
||||||
|
.replaceAll("\\+", "").replaceAll("``", "`").replaceAll("\\\\", "");
|
||||||
|
String valueStr = fieldSqlStr.substring(fieldSqlStr.lastIndexOf("values") + 6).replaceAll(" ", "").replaceAll("\\(", "").replaceAll("\\)", "");
|
||||||
|
//get the string between insert into and values
|
||||||
|
fieldSqlStr = fieldSqlStr.substring(0, fieldSqlStr.lastIndexOf("values"));
|
||||||
|
|
||||||
|
System.out.println(fieldSqlStr);
|
||||||
|
|
||||||
|
String insertSqlPattenStr = "insert into (?<tableName>.*) \\((?<columnsSQL>.*)\\)";
|
||||||
|
//String DDL_PATTEN_STR="\\s*create\\s+table\\s+(?<tableName>\\S+)[^\\(]*\\((?<columnsSQL>[\\s\\S]+)\\)[^\\)]+?(comment\\s*(=|on\\s+table)\\s*'(?<tableComment>.*?)'\\s*;?)?$";
|
||||||
|
|
||||||
|
Matcher matcher1 = Pattern.compile(insertSqlPattenStr).matcher(fieldSqlStr);
|
||||||
|
while (matcher1.find()) {
|
||||||
|
|
||||||
|
String tableName = matcher1.group("tableName");
|
||||||
|
//System.out.println("tableName:"+tableName);
|
||||||
|
codeJavaInfo.setClassName(tableName);
|
||||||
|
codeJavaInfo.setTableName(tableName);
|
||||||
|
|
||||||
|
String columnsSQL = matcher1.group("columnsSQL");
|
||||||
|
//System.out.println("columnsSQL:"+columnsSQL);
|
||||||
|
|
||||||
|
List<String> valueList = new ArrayList<>();
|
||||||
|
//add values as comment
|
||||||
|
String[] values = valueStr.split(",");
|
||||||
|
for (String column : values) {
|
||||||
|
valueList.add(column);
|
||||||
|
}
|
||||||
|
AtomicInteger n = new AtomicInteger(0);
|
||||||
|
//add column to fleldList
|
||||||
|
String[] columns = columnsSQL.replaceAll(" ", "").split(",");
|
||||||
|
for (String column : columns) {
|
||||||
|
FieldInfo fieldInfo2 = new FieldInfo();
|
||||||
|
fieldInfo2.setFieldName(column);
|
||||||
|
fieldInfo2.setColumnName(column);
|
||||||
|
fieldInfo2.setFieldClass(String.class.getSimpleName());
|
||||||
|
if (n.get() < valueList.size()) {
|
||||||
|
fieldInfo2.setFieldComment(column + " , eg." + valueList.get(n.get()));
|
||||||
|
}
|
||||||
|
fieldList.add(fieldInfo2);
|
||||||
|
n.getAndIncrement();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (fieldList.size() < 1) {
|
||||||
|
throw new RuntimeException("INSERT SQL解析失败");
|
||||||
|
}
|
||||||
|
codeJavaInfo.setFieldList(fieldList);
|
||||||
|
return codeJavaInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.xiang.xservice.application.generator.service.parser;
|
||||||
|
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ClassInfo;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ParamInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON解析服务接口
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
public interface JsonParserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析JSON生成类信息
|
||||||
|
*
|
||||||
|
* @param paramInfo 参数信息
|
||||||
|
* @return 类信息
|
||||||
|
*/
|
||||||
|
ClassInfo processJsonToClassInfo(ParamInfo paramInfo);
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.xiang.xservice.application.generator.service.parser;
|
||||||
|
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ClassInfo;
|
||||||
|
import com.xiang.xservice.application.generator.entity.domain.ParamInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL解析服务接口
|
||||||
|
*
|
||||||
|
* @author zhengkai.blog.csdn.net
|
||||||
|
*/
|
||||||
|
public interface SqlParserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析Select-SQL生成类信息(JSQLPraser版本)
|
||||||
|
*
|
||||||
|
* @param paramInfo 参数信息
|
||||||
|
* @return 类信息
|
||||||
|
* @throws Exception 解析异常
|
||||||
|
*/
|
||||||
|
ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析Create-SQL生成类信息(JSQLPraser版本)
|
||||||
|
*
|
||||||
|
* @param paramInfo 参数信息
|
||||||
|
* @return 类信息
|
||||||
|
* @throws Exception 解析异常
|
||||||
|
*/
|
||||||
|
ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析DDL-SQL生成类信息
|
||||||
|
*
|
||||||
|
* @param paramInfo 参数信息
|
||||||
|
* @return 类信息
|
||||||
|
* @throws Exception 解析异常
|
||||||
|
*/
|
||||||
|
ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析DDL SQL生成类信息-正则表达式版本
|
||||||
|
*
|
||||||
|
* @param paramInfo 参数信息
|
||||||
|
* @return 类信息
|
||||||
|
*/
|
||||||
|
ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析INSERT-SQL生成类信息-正则表达式版本
|
||||||
|
*
|
||||||
|
* @param paramInfo 参数信息
|
||||||
|
* @return 类信息
|
||||||
|
*/
|
||||||
|
ClassInfo processInsertSqlToClassInfo(ParamInfo paramInfo);
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package com.xiang.xservice.application.generator.util;
|
||||||
|
|
||||||
|
import freemarker.cache.ClassTemplateLoader;
|
||||||
|
import freemarker.template.Configuration;
|
||||||
|
import freemarker.template.Template;
|
||||||
|
import freemarker.template.TemplateException;
|
||||||
|
import freemarker.template.TemplateExceptionHandler;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* freemarker tool
|
||||||
|
*
|
||||||
|
* @author xiang
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class FreemarkerUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入需要转义的字符串进行转义
|
||||||
|
*/
|
||||||
|
public static String escapeString(String originStr) {
|
||||||
|
return originStr.replaceAll("井", "\\#").replaceAll("¥", "\\$");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* freemarker config
|
||||||
|
*/
|
||||||
|
private static final Configuration freemarkerConfig = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
freemarkerConfig.setClassForTemplateLoading(FreemarkerUtil.class, "/templates/code-generator");
|
||||||
|
freemarkerConfig.setTemplateLoader(new ClassTemplateLoader(FreemarkerUtil.class, "/templates/code-generator"));
|
||||||
|
freemarkerConfig.setNumberFormat("#");
|
||||||
|
freemarkerConfig.setClassicCompatible(true);
|
||||||
|
freemarkerConfig.setDefaultEncoding("UTF-8");
|
||||||
|
freemarkerConfig.setLocale(Locale.CHINA);
|
||||||
|
freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* process Template Into String
|
||||||
|
*
|
||||||
|
* @param template
|
||||||
|
* @param model
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
* @throws TemplateException
|
||||||
|
*/
|
||||||
|
public static String processTemplateIntoString(Template template, Object model)
|
||||||
|
throws IOException, TemplateException {
|
||||||
|
|
||||||
|
StringWriter result = new StringWriter();
|
||||||
|
template.process(model, result);
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* process String
|
||||||
|
*
|
||||||
|
* @param templateName
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
* @throws TemplateException
|
||||||
|
*/
|
||||||
|
public static String processString(String templateName, Map<String, Object> params)
|
||||||
|
throws IOException, TemplateException {
|
||||||
|
|
||||||
|
Template template = freemarkerConfig.getTemplate(templateName);
|
||||||
|
return escapeString(processTemplateIntoString(template, params));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
package com.xiang.xservice.application.generator.util;
|
||||||
|
|
||||||
|
import joptsimple.internal.Strings;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MapUtil {
|
||||||
|
public static String getString(Map<String, Object> map, String key) {
|
||||||
|
if (map != null && map.containsKey(key)) {
|
||||||
|
try {
|
||||||
|
return map.get(key).toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Strings.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Strings.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.xiang.xservice.application.generator.util;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public final class Mysql2JavaTypeUtil {
|
||||||
|
public static final HashMap<String, String> mysqlJavaTypeMap = new HashMap<String, String>();
|
||||||
|
public static final HashMap<String, String> mysqlSwaggerTypeMap = new HashMap<String, String>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
mysqlJavaTypeMap.put("bigint", "Long");
|
||||||
|
mysqlJavaTypeMap.put("int", "Integer");
|
||||||
|
mysqlJavaTypeMap.put("tinyint", "Integer");
|
||||||
|
mysqlJavaTypeMap.put("smallint", "Integer");
|
||||||
|
mysqlJavaTypeMap.put("mediumint", "Integer");
|
||||||
|
mysqlJavaTypeMap.put("integer", "Integer");
|
||||||
|
//小数
|
||||||
|
mysqlJavaTypeMap.put("float", "Float");
|
||||||
|
mysqlJavaTypeMap.put("double", "Double");
|
||||||
|
mysqlJavaTypeMap.put("decimal", "Double");
|
||||||
|
//bool
|
||||||
|
mysqlJavaTypeMap.put("bit", "Boolean");
|
||||||
|
//字符串
|
||||||
|
mysqlJavaTypeMap.put("char", "String");
|
||||||
|
mysqlJavaTypeMap.put("varchar", "String");
|
||||||
|
mysqlJavaTypeMap.put("varchar2", "String"); // Oracle类型
|
||||||
|
mysqlJavaTypeMap.put("tinytext", "String");
|
||||||
|
mysqlJavaTypeMap.put("text", "String");
|
||||||
|
mysqlJavaTypeMap.put("mediumtext", "String");
|
||||||
|
mysqlJavaTypeMap.put("longtext", "String");
|
||||||
|
//日期
|
||||||
|
mysqlJavaTypeMap.put("date", "Date");
|
||||||
|
mysqlJavaTypeMap.put("datetime", "Date");
|
||||||
|
mysqlJavaTypeMap.put("timestamp", "Date");
|
||||||
|
// 数字类型 - Oracle增强
|
||||||
|
mysqlJavaTypeMap.put("number", "BigDecimal"); // Oracle的NUMBER类型默认映射为BigDecimal,支持精度
|
||||||
|
|
||||||
|
|
||||||
|
mysqlSwaggerTypeMap.put("bigint", "integer");
|
||||||
|
mysqlSwaggerTypeMap.put("int", "integer");
|
||||||
|
mysqlSwaggerTypeMap.put("tinyint", "integer");
|
||||||
|
mysqlSwaggerTypeMap.put("smallint", "integer");
|
||||||
|
mysqlSwaggerTypeMap.put("mediumint", "integer");
|
||||||
|
mysqlSwaggerTypeMap.put("integer", "integer");
|
||||||
|
mysqlSwaggerTypeMap.put("boolean", "boolean");
|
||||||
|
mysqlSwaggerTypeMap.put("float", "number");
|
||||||
|
mysqlSwaggerTypeMap.put("double", "number");
|
||||||
|
mysqlSwaggerTypeMap.put("decimal", "number");
|
||||||
|
// Oracle类型
|
||||||
|
mysqlSwaggerTypeMap.put("varchar2", "string");
|
||||||
|
mysqlSwaggerTypeMap.put("number", "number");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, String> getMysqlJavaTypeMap() {
|
||||||
|
return mysqlJavaTypeMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, String> getMysqlSwaggerTypeMap() {
|
||||||
|
return mysqlSwaggerTypeMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
package com.xiang.xservice.application.generator.util;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class StringUtilsPlus {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首字母大写
|
||||||
|
*
|
||||||
|
* @param str 字符串
|
||||||
|
*
|
||||||
|
* @return 首字母大写
|
||||||
|
*/
|
||||||
|
public static String upperCaseFirst(String str) {
|
||||||
|
if (str == null || str.trim().isEmpty()) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首字母小写
|
||||||
|
*
|
||||||
|
* @param str 字符串
|
||||||
|
*
|
||||||
|
* @return 首字母小写
|
||||||
|
*/
|
||||||
|
public static String lowerCaseFirst(String str) {
|
||||||
|
return (str != null && str.length() > 1) ? str.substring(0, 1).toLowerCase() + str.substring(1) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下划线,转换为驼峰式
|
||||||
|
*
|
||||||
|
* @param underscoreName 下划线字符串
|
||||||
|
*
|
||||||
|
* @return 驼峰式
|
||||||
|
*/
|
||||||
|
public static String underlineToCamelCase(String underscoreName) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
if (StringUtils.isNotBlank(underscoreName)) {
|
||||||
|
boolean flag = false;
|
||||||
|
for (int i = 0; i < underscoreName.length(); i++) {
|
||||||
|
char ch = underscoreName.charAt(i);
|
||||||
|
if ('_' == ch) {
|
||||||
|
flag = true;
|
||||||
|
} else {
|
||||||
|
if (flag) {
|
||||||
|
result.append(Character.toUpperCase(ch));
|
||||||
|
flag = false;
|
||||||
|
} else {
|
||||||
|
result.append(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转 user_name 风格
|
||||||
|
*/
|
||||||
|
public static String toUnderline(String str, boolean upperCase) {
|
||||||
|
if (str == null || str.trim().isEmpty()) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
boolean preIsUnderscore = false;
|
||||||
|
for (int i = 0; i < str.length(); i++) {
|
||||||
|
char ch = str.charAt(i);
|
||||||
|
if (ch == '_') {
|
||||||
|
preIsUnderscore = true;
|
||||||
|
} else if (ch == '-') {
|
||||||
|
ch = '_';
|
||||||
|
preIsUnderscore = true; // -A -> _a
|
||||||
|
} else if (ch >= 'A' && ch <= 'Z') {
|
||||||
|
// A -> _a
|
||||||
|
if (!preIsUnderscore && i > 0) { // _A -> _a
|
||||||
|
result.append("_");
|
||||||
|
}
|
||||||
|
preIsUnderscore = false;
|
||||||
|
} else {
|
||||||
|
preIsUnderscore = false;
|
||||||
|
}
|
||||||
|
result.append(upperCase ? Character.toUpperCase(ch) : Character.toLowerCase(ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任何字符串 转驼峰
|
||||||
|
* @param str 任何字符串
|
||||||
|
*/
|
||||||
|
public static String toLowerCamel(String str) {
|
||||||
|
if (str == null || str.trim().isEmpty()) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
char pre = '\0';
|
||||||
|
for (int i = 0; i < str.length(); i++) {
|
||||||
|
char ch = str.charAt(i);
|
||||||
|
if (ch == '-' || ch == '—' || ch == '_') {
|
||||||
|
ch = '_';
|
||||||
|
pre = ch;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char ch2 = ch;
|
||||||
|
if (pre == '_') {
|
||||||
|
ch2 = Character.toUpperCase(ch);
|
||||||
|
pre = ch2;
|
||||||
|
} else if (pre >= 'A' && pre <= 'Z') {
|
||||||
|
pre = ch;
|
||||||
|
ch2 = Character.toLowerCase(ch);
|
||||||
|
} else {
|
||||||
|
pre = ch;
|
||||||
|
}
|
||||||
|
result.append(ch2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lowerCaseFirst(result.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ public class DynamicDomainSchedule {
|
|||||||
|
|
||||||
private final IDomainService IDomainService;
|
private final IDomainService IDomainService;
|
||||||
|
|
||||||
@Scheduled(cron = "0 0/5 * * * ? ")
|
@Scheduled(cron = "0 0/30 * * * ? ")
|
||||||
public void dynamicDomainSchedule() {
|
public void dynamicDomainSchedule() {
|
||||||
String publicIp = "";
|
String publicIp = "";
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.domain.service;
|
|
||||||
|
|
||||||
import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService;
|
|
||||||
import com.xiang.xservice.config.DingTalkRobotScriptConfig;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-08-07 10:30
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class DingTalkScriptDomainService {
|
|
||||||
|
|
||||||
private final DingTalkService dingTalkService;
|
|
||||||
private final DingTalkRobotScriptConfig dingTalkRobotScriptConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送脚本消息
|
|
||||||
* @param msg 消息
|
|
||||||
*/
|
|
||||||
public void sendScriptMsg(String msg) {
|
|
||||||
try {
|
|
||||||
dingTalkService.sendRobotMessage(dingTalkRobotScriptConfig.getSecret(), dingTalkRobotScriptConfig.getToken(),
|
|
||||||
dingTalkRobotScriptConfig.getUsers(), msg);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("信息发送异常, 信息:{}", msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,6 +9,7 @@ import com.aliyun.alidns20150109.models.DescribeSubDomainRecordsResponseBody;
|
|||||||
import com.aliyun.alidns20150109.models.UpdateDomainRecordRequest;
|
import com.aliyun.alidns20150109.models.UpdateDomainRecordRequest;
|
||||||
import com.aliyun.teaopenapi.models.Config;
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
import com.xiang.xservice.application.script.domain.config.AliyunDnsPropertyConfig;
|
import com.xiang.xservice.application.script.domain.config.AliyunDnsPropertyConfig;
|
||||||
|
import com.xiang.xservice.common.service.dingTalk.ScriptDingTalkFactory;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -36,7 +37,7 @@ public class IDomainServiceImpl implements IDomainService {
|
|||||||
private final AliyunDnsPropertyConfig aliyunDnsPropertyConfig;
|
private final AliyunDnsPropertyConfig aliyunDnsPropertyConfig;
|
||||||
private static final String TYPE = "A";
|
private static final String TYPE = "A";
|
||||||
|
|
||||||
private final DingTalkScriptDomainService dingTalkService;
|
private final ScriptDingTalkFactory dingTalkService;
|
||||||
@Override
|
@Override
|
||||||
public void dynamicDomainAnalysis(String publicIp) throws Exception {
|
public void dynamicDomainAnalysis(String publicIp) throws Exception {
|
||||||
Client client = createClient();
|
Client client = createClient();
|
||||||
@@ -53,14 +54,14 @@ public class IDomainServiceImpl implements IDomainService {
|
|||||||
if (records.isEmpty()) {
|
if (records.isEmpty()) {
|
||||||
log.info("未找到记录,添加记录..., ip:{}", publicIp);
|
log.info("未找到记录,添加记录..., ip:{}", publicIp);
|
||||||
addDnsRecord(client, publicIp, rr);
|
addDnsRecord(client, publicIp, rr);
|
||||||
dingTalkService.sendScriptMsg("动态解析公网ip成功,域名:" + rr + "." + DOMAIN_NAME + ", 新ip:" + publicIp);
|
dingTalkService.sendMsg("动态解析公网ip成功,域名:" + rr + "." + DOMAIN_NAME + ", 新ip:" + publicIp);
|
||||||
} else {
|
} else {
|
||||||
String recordId = records.get(0).getRecordId();
|
String recordId = records.get(0).getRecordId();
|
||||||
String currentValue = records.get(0).getValue();
|
String currentValue = records.get(0).getValue();
|
||||||
if (!publicIp.equals(currentValue)) {
|
if (!publicIp.equals(currentValue)) {
|
||||||
log.info("IP变更,更新记录...,ip:{}", publicIp);
|
log.info("IP变更,更新记录...,ip:{}", publicIp);
|
||||||
updateDnsRecord(client, recordId, publicIp, rr);
|
updateDnsRecord(client, recordId, publicIp, rr);
|
||||||
dingTalkService.sendScriptMsg("动态解析公网ip成功,域名:" + rr + "." + DOMAIN_NAME + ", 新ip:" + publicIp);
|
dingTalkService.sendMsg("动态解析公网ip成功,域名:" + rr + "." + DOMAIN_NAME + ", 新ip:" + publicIp);
|
||||||
} else {
|
} else {
|
||||||
log.info("ip未变更,无需修改,ip:{}", publicIp);
|
log.info("ip未变更,无需修改,ip:{}", publicIp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.xiang.xservice.application.script.fwd.constants;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum PriceRange {
|
||||||
|
RANGE_600_900(0, BigDecimal.valueOf(600), BigDecimal.valueOf(900)),
|
||||||
|
RANGE_900_1300(1, BigDecimal.valueOf(900), BigDecimal.valueOf(1300)),
|
||||||
|
RANGE_1300_1600(2, BigDecimal.valueOf(1300), BigDecimal.valueOf(1600)),
|
||||||
|
RANGE_OVER_1600(3, BigDecimal.valueOf(1600), null),
|
||||||
|
RANGE_UNDER_600(4, null, BigDecimal.valueOf(600));
|
||||||
|
|
||||||
|
private final int index;
|
||||||
|
private final BigDecimal min;
|
||||||
|
private final BigDecimal max;
|
||||||
|
|
||||||
|
public boolean contains(BigDecimal price) {
|
||||||
|
boolean minCondition = min == null || price.compareTo(min) > 0;
|
||||||
|
boolean maxCondition = max == null || price.compareTo(max) <= 0;
|
||||||
|
return minCondition && maxCondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static PriceRange fromPrice(BigDecimal price) {
|
||||||
|
return Arrays.stream(values())
|
||||||
|
.filter(range -> range.contains(price))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Invalid price: " + price));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,6 @@ package com.xiang.xservice.application.script.fwd.constants;
|
|||||||
|
|
||||||
public class UrlConstants {
|
public class UrlConstants {
|
||||||
|
|
||||||
public static final String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJjdCI6MTc1MjYzODAwNTUxNywic3ViIjoiTDIxMTQzMjU2NDEiLCJhdWQiOiJMSVZFTEFCIiwiaXNzIjoiVElDS0VUIiwibWlkIjoxNzU4ODA4NTcxMzgzNjcxNTUzLCJ0eXBlIjoiYXBwbGV0IiwiaWF0IjoxNzUyNjM4MDA1LCJkaWQiOiI2RTRDMDQ5RS00RkFBLTQ0NDMtQjI3NC1DNjRBMjZEMUFGNTkiLCJrZXkiOiJMSVZFTEFCIn0.iw1u3LyCYlxYCI1gMwTeuJlPdv-rQKCVlO2ySF_UrJ-lrEH6fm5lGo4wGalLn1qGkyqZaxuTx1K6X7Oy7sHgBA";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 芬玩岛的基础URL
|
* 芬玩岛的基础URL
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -25,4 +25,6 @@ public class ProjectOrderCreateReq {
|
|||||||
private String blackBox;
|
private String blackBox;
|
||||||
private String combineTicketVos;
|
private String combineTicketVos;
|
||||||
private String ordinaryTicketVos;
|
private String ordinaryTicketVos;
|
||||||
|
private Integer activityType;
|
||||||
|
private String activityId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,17 @@ package com.xiang.xservice.application.script.fwd.schedule;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
import com.xiang.xmc.service.schedule.core.DynamicTaskScheduler;
|
||||||
import com.xiang.xservice.basic.utils.PrimaryKeyUtils;
|
import com.xiang.xmc.service.schedule.entity.ScheduledTaskEntity;
|
||||||
|
import com.xiang.xmc.service.schedule.entity.TaskConfig;
|
||||||
|
import com.xiang.xmc.service.schedule.enums.TaskGroupEnum;
|
||||||
|
import com.xiang.xmc.service.schedule.enums.TaskStatusEnum;
|
||||||
|
import com.xiang.xmc.service.schedule.service.IDynamicTaskSchedulerService;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.param.FwdOrderTaskParam;
|
import com.xiang.xservice.application.script.fwd.entity.param.FwdOrderTaskParam;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo;
|
||||||
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FUserConfig;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.Perform;
|
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.Perform;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.PerformDetail;
|
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.PerformDetail;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.PerformInfo;
|
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.PerformInfo;
|
||||||
@@ -18,20 +23,19 @@ import com.xiang.xservice.application.script.fwd.mapper.FwdAudienceConfigMapper;
|
|||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformConfigMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformConfigMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformProjectInfoMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformProjectInfoMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.service.DingTalkScriptFWDService;
|
|
||||||
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
||||||
import com.xiang.xservice.application.script.fwd.service.IPerformServiceHttp;
|
import com.xiang.xservice.application.script.fwd.service.IPerformServiceHttp;
|
||||||
import com.xiang.xservice.application.script.fwd.utils.TimeSyncUtils;
|
import com.xiang.xservice.application.script.fwd.utils.TimeSyncUtils;
|
||||||
import com.xiang.xservice.schedule.core.DynamicTaskScheduler;
|
import com.xiang.xservice.basic.utils.DateUtils;
|
||||||
import com.xiang.xservice.schedule.entity.ScheduledTaskEntity;
|
import com.xiang.xservice.basic.utils.PrimaryKeyUtils;
|
||||||
import com.xiang.xservice.schedule.entity.TaskConfig;
|
import com.xiang.xservice.common.entity.SysConfigDO;
|
||||||
import com.xiang.xservice.schedule.enums.TaskGroupEnum;
|
import com.xiang.xservice.common.mapper.SysConfigMapper;
|
||||||
import com.xiang.xservice.schedule.enums.TaskStatusEnum;
|
import com.xiang.xservice.common.service.dingTalk.ScriptDingTalkFactory;
|
||||||
import com.xiang.xservice.schedule.service.IDynamicTaskSchedulerService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -62,12 +66,13 @@ public class FwdImportantMsgJob {
|
|||||||
private final FwdPerformProjectInfoMapper performProjectInfoMapper;
|
private final FwdPerformProjectInfoMapper performProjectInfoMapper;
|
||||||
private final FwdPerformConfigMapper performConfigMapper;
|
private final FwdPerformConfigMapper performConfigMapper;
|
||||||
private final DynamicTaskScheduler dynamicTaskScheduler;
|
private final DynamicTaskScheduler dynamicTaskScheduler;
|
||||||
private final DingTalkScriptFWDService dingTalkScriptFWDService;
|
private final ScriptDingTalkFactory dingTalkScriptFWDService;
|
||||||
private final FwdUserConfigMapper fwdUserConfigMapper;
|
private final FwdUserConfigMapper fwdUserConfigMapper;
|
||||||
private final FwdAudienceConfigMapper fwdAudienceConfigMapper;
|
private final FwdAudienceConfigMapper fwdAudienceConfigMapper;
|
||||||
private final IPerformService iPerformService;
|
private final IPerformService iPerformService;
|
||||||
private final IDynamicTaskSchedulerService dynamicTaskSchedulerService;
|
private final IDynamicTaskSchedulerService dynamicTaskSchedulerService;
|
||||||
private final IPerformServiceHttp iPerformServiceHttp;
|
private final IPerformServiceHttp iPerformServiceHttp;
|
||||||
|
private final SysConfigMapper sysConfigMapper;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
@@ -78,7 +83,7 @@ public class FwdImportantMsgJob {
|
|||||||
List<ScheduledTaskEntity> taskList = dynamicTaskSchedulerService.getTaskList(scheduledTaskEntity);
|
List<ScheduledTaskEntity> taskList = dynamicTaskSchedulerService.getTaskList(scheduledTaskEntity);
|
||||||
for (ScheduledTaskEntity taskEntity : taskList) {
|
for (ScheduledTaskEntity taskEntity : taskList) {
|
||||||
HashMap params = com.alibaba.fastjson2.JSON.parseObject(taskEntity.getParameters(), HashMap.class);
|
HashMap params = com.alibaba.fastjson2.JSON.parseObject(taskEntity.getParameters(), HashMap.class);
|
||||||
FwdOrderTaskParam param = MapUtils.isEmpty(params) ? new FwdOrderTaskParam(null, taskEntity.getId()) : new FwdOrderTaskParam((Long) params.get("projectId"), taskEntity.getId());
|
FwdOrderTaskParam param = MapUtils.isEmpty(params) ? new FwdOrderTaskParam(null, taskEntity.getId()) : new FwdOrderTaskParam(Long.parseLong(params.get("projectId").toString()), taskEntity.getId());
|
||||||
LocalDateTime runTime = taskEntity.getRunTime().isBefore(TimeSyncUtils.now()) ? TimeSyncUtils.now() : taskEntity.getRunTime();
|
LocalDateTime runTime = taskEntity.getRunTime().isBefore(TimeSyncUtils.now()) ? TimeSyncUtils.now() : taskEntity.getRunTime();
|
||||||
dynamicTaskScheduler.schedule(
|
dynamicTaskScheduler.schedule(
|
||||||
new TaskConfig(taskEntity.getId(), taskEntity.getTaskName(), taskEntity.getTaskGroup(), runTime, params),
|
new TaskConfig(taskEntity.getId(), taskEntity.getTaskName(), taskEntity.getTaskGroup(), runTime, params),
|
||||||
@@ -115,6 +120,17 @@ public class FwdImportantMsgJob {
|
|||||||
performConfigMapper.insertPerforms(addList);
|
performConfigMapper.insertPerforms(addList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否下单开关
|
||||||
|
boolean flag = false;
|
||||||
|
SysConfigDO config = sysConfigMapper.getByName("fwd.order.create.switch");
|
||||||
|
if (Objects.nonNull(config)) {
|
||||||
|
if (StringUtils.isNotBlank(config.getValue())) {
|
||||||
|
if (StringUtils.equals(config.getValue(), "true")) {
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder msg = new StringBuilder("今日" + now + "演唱会门票预售信息:\n");
|
StringBuilder msg = new StringBuilder("今日" + now + "演唱会门票预售信息:\n");
|
||||||
for (FPerformProjectInfo data : saleTodayData) {
|
for (FPerformProjectInfo data : saleTodayData) {
|
||||||
msg.append("演唱会名称:").append(data.getProjectName()).append("预售时间:").append(DateUtils.getDateTimeFromDateTime(data.getPreSaleTime())).append("\n");
|
msg.append("演唱会名称:").append(data.getProjectName()).append("预售时间:").append(DateUtils.getDateTimeFromDateTime(data.getPreSaleTime())).append("\n");
|
||||||
@@ -122,16 +138,18 @@ public class FwdImportantMsgJob {
|
|||||||
Map<String, Object> params = Maps.newHashMap();
|
Map<String, Object> params = Maps.newHashMap();
|
||||||
params.put("projectId", data.getProjectId());
|
params.put("projectId", data.getProjectId());
|
||||||
LocalDateTime runTime = data.getPreSaleTime().isBefore(LocalDateTime.now()) ? LocalDateTime.now().plusMinutes(1) : data.getPreSaleTime();
|
LocalDateTime runTime = data.getPreSaleTime().isBefore(LocalDateTime.now()) ? LocalDateTime.now().plusMinutes(1) : data.getPreSaleTime();
|
||||||
dynamicTaskScheduler.schedule(
|
if (flag) {
|
||||||
new TaskConfig(taskId, "芬玩岛演唱会抢票-【" + data.getProjectName() + "】", TaskGroupEnum.SERVICE_FWD_SCHEDULE.getCode(),
|
dynamicTaskScheduler.schedule(
|
||||||
runTime, params),
|
new TaskConfig(taskId, "芬玩岛演唱会抢票-【" + data.getProjectName() + "】", TaskGroupEnum.SERVICE_FWD_SCHEDULE.getCode(),
|
||||||
new TicketGrabTask(fwdUserConfigMapper, fwdAudienceConfigMapper, iPerformService,
|
runTime, params),
|
||||||
new FwdOrderTaskParam(data.getProjectId(), taskId), dynamicTaskSchedulerService),
|
new TicketGrabTask(fwdUserConfigMapper, fwdAudienceConfigMapper, iPerformService,
|
||||||
TimeSyncUtils.now());
|
new FwdOrderTaskParam(data.getProjectId(), taskId), dynamicTaskSchedulerService),
|
||||||
savaTask(data, taskId, params);
|
TimeSyncUtils.now());
|
||||||
|
savaTask(data, taskId, params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
msg.append("请注意进行数据库配置的更改!");
|
msg.append("请注意进行数据库配置的更改!");
|
||||||
dingTalkScriptFWDService.sendScriptMsg(msg.toString());
|
dingTalkScriptFWDService.sendMsg(msg.toString());
|
||||||
log.info("【芬玩岛】演唱会预售定时任务结束!time:{}", System.currentTimeMillis());
|
log.info("【芬玩岛】演唱会预售定时任务结束!time:{}", System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +157,9 @@ public class FwdImportantMsgJob {
|
|||||||
@PostMapping("/presaleSeatReminderJob")
|
@PostMapping("/presaleSeatReminderJob")
|
||||||
public void presaleSeatReminderJob() {
|
public void presaleSeatReminderJob() {
|
||||||
|
|
||||||
|
List<FUserConfig> availableUser = fwdUserConfigMapper.getAvailableUser();
|
||||||
|
String token = availableUser.get(0).getToken();
|
||||||
|
|
||||||
ScheduledTaskEntity entity = new ScheduledTaskEntity();
|
ScheduledTaskEntity entity = new ScheduledTaskEntity();
|
||||||
entity.setStatus(TaskStatusEnum.UN_START.getCode());
|
entity.setStatus(TaskStatusEnum.UN_START.getCode());
|
||||||
List<ScheduledTaskEntity> taskList = dynamicTaskSchedulerService.getTaskList(entity);
|
List<ScheduledTaskEntity> taskList = dynamicTaskSchedulerService.getTaskList(entity);
|
||||||
@@ -162,7 +183,7 @@ public class FwdImportantMsgJob {
|
|||||||
log.error("异常错误信息:{}", JSON.toJSONString(taskEntity), e);
|
log.error("异常错误信息:{}", JSON.toJSONString(taskEntity), e);
|
||||||
}
|
}
|
||||||
if (Objects.nonNull(projectId)) {
|
if (Objects.nonNull(projectId)) {
|
||||||
Perform performsByProjectIdFromHttp = iPerformServiceHttp.getPerformsByProjectIdFromHttp(projectId);
|
Perform performsByProjectIdFromHttp = iPerformServiceHttp.getPerformsByProjectIdFromHttp(projectId, token);
|
||||||
if (Objects.nonNull(performsByProjectIdFromHttp)) {
|
if (Objects.nonNull(performsByProjectIdFromHttp)) {
|
||||||
for (PerformInfo performInfo : performsByProjectIdFromHttp.getPerformInfos()) {
|
for (PerformInfo performInfo : performsByProjectIdFromHttp.getPerformInfos()) {
|
||||||
for (PerformDetail performDetail : performInfo.getPerformInfo()) {
|
for (PerformDetail performDetail : performInfo.getPerformInfo()) {
|
||||||
@@ -171,7 +192,7 @@ public class FwdImportantMsgJob {
|
|||||||
List<SeatPlan> seatPlans = performDetail.getSeatPlans();
|
List<SeatPlan> seatPlans = performDetail.getSeatPlans();
|
||||||
Map<Long, SeatPlan> seatPlanMap = seatPlans.stream().collect(Collectors.toMap(SeatPlan::getSeatPlanId, Function.identity(), (a, b) -> a));
|
Map<Long, SeatPlan> seatPlanMap = seatPlans.stream().collect(Collectors.toMap(SeatPlan::getSeatPlanId, Function.identity(), (a, b) -> a));
|
||||||
List<Long> seatPlanIds = seatPlans.stream().map(SeatPlan::getSeatPlanId).collect(Collectors.toList());
|
List<Long> seatPlanIds = seatPlans.stream().map(SeatPlan::getSeatPlanId).collect(Collectors.toList());
|
||||||
List<SeatPlanStatus> seatPlanStatusFromHttp = iPerformServiceHttp.getSeatPlanStatusFromHttp(seatPlanIds);
|
List<SeatPlanStatus> seatPlanStatusFromHttp = iPerformServiceHttp.getSeatPlanStatusFromHttp(seatPlanIds, token);
|
||||||
for (SeatPlanStatus seatPlanStatus : seatPlanStatusFromHttp) {
|
for (SeatPlanStatus seatPlanStatus : seatPlanStatusFromHttp) {
|
||||||
if (!seatPlanStatus.getSoldOutFlag()) {
|
if (!seatPlanStatus.getSoldOutFlag()) {
|
||||||
FPerformSeatInfo seatInfoBySeatId = iPerformService.getSeatInfoBySeatId(seatPlanStatus.getSeatPlanId());
|
FPerformSeatInfo seatInfoBySeatId = iPerformService.getSeatInfoBySeatId(seatPlanStatus.getSeatPlanId());
|
||||||
@@ -228,7 +249,7 @@ public class FwdImportantMsgJob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dingTalkScriptFWDService.sendScriptMsg(msg.toString());
|
dingTalkScriptFWDService.sendMsg(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void savaTask(FPerformProjectInfo data, long taskId, Map<String, Object> params) {
|
private void savaTask(FPerformProjectInfo data, long taskId, Map<String, Object> params) {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package com.xiang.xservice.application.script.fwd.schedule;
|
package com.xiang.xservice.application.script.fwd.schedule;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.xiang.xservice.basic.common.req.BaseRequest;
|
import com.xiang.xmc.service.http.helper.HttpRequestHelper;
|
||||||
import com.xiang.xservice.basic.config.MyThreadFactory;
|
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FAudienceConfig;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FAudienceConfig;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo;
|
||||||
@@ -23,7 +21,10 @@ import com.xiang.xservice.application.script.fwd.mapper.FwdPerformProjectInfoMap
|
|||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformSeatInfoMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformSeatInfoMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.service.IPerformServiceHttp;
|
import com.xiang.xservice.application.script.fwd.service.IPerformServiceHttp;
|
||||||
import com.xiang.xservice.http.helper.HttpRequestHelper;
|
import com.xiang.xservice.basic.common.req.BaseRequest;
|
||||||
|
import com.xiang.xservice.basic.config.MyThreadFactory;
|
||||||
|
import com.xiang.xservice.basic.utils.DateUtils;
|
||||||
|
import com.xiang.xservice.basic.utils.RandomCodeUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
@@ -36,7 +37,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
@@ -139,6 +139,8 @@ public class PullDataFromFWDJob {
|
|||||||
@Scheduled(cron = "0 0 1 1/1 * ?")
|
@Scheduled(cron = "0 0 1 1/1 * ?")
|
||||||
public void pullPerformDataJobV2() {
|
public void pullPerformDataJobV2() {
|
||||||
int pageNum = 0;
|
int pageNum = 0;
|
||||||
|
List<FUserConfig> availableUser = userConfigMapper.getAvailableUser();
|
||||||
|
String token = availableUser.get(0).getToken();
|
||||||
while (true) {
|
while (true) {
|
||||||
pageNum++;
|
pageNum++;
|
||||||
BaseRequest baseRequest = new BaseRequest();
|
BaseRequest baseRequest = new BaseRequest();
|
||||||
@@ -149,12 +151,12 @@ public class PullDataFromFWDJob {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
List<ProjectList> projects = projectsResp.getList();
|
List<ProjectList> projects = projectsResp.getList();
|
||||||
List<CompletableFuture<FPerformProjectInfo>> futures = Lists.newArrayList();
|
List<FPerformProjectInfo> results = Lists.newArrayList();
|
||||||
for (ProjectList project : projects) {
|
for (ProjectList project : projects) {
|
||||||
CompletableFuture<FPerformProjectInfo> future = CompletableFuture.supplyAsync(() -> handleProjectData(project), es);
|
FPerformProjectInfo performProjectInfo = handleProjectData(project, token);
|
||||||
futures.add(future);
|
results.add(performProjectInfo);
|
||||||
}
|
}
|
||||||
List<FPerformProjectInfo> results = futures.stream().map(CompletableFuture::join).toList();
|
results = results.stream().filter(Objects::nonNull).toList();
|
||||||
// 查询演出座位档次信息
|
// 查询演出座位档次信息
|
||||||
List<FPerformSeatInfo> insertList = Lists.newCopyOnWriteArrayList();
|
List<FPerformSeatInfo> insertList = Lists.newCopyOnWriteArrayList();
|
||||||
List<FPerformSeatInfo> updateList = Lists.newCopyOnWriteArrayList();
|
List<FPerformSeatInfo> updateList = Lists.newCopyOnWriteArrayList();
|
||||||
@@ -164,7 +166,7 @@ public class PullDataFromFWDJob {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<Long> seatPlanIds = seatPlans.stream().map(SeatPlan::getSeatPlanId).toList();
|
List<Long> seatPlanIds = seatPlans.stream().map(SeatPlan::getSeatPlanId).toList();
|
||||||
List<SeatPlanStatus> seatPlanStatusList = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getSeatPlanStatusFromHttp(seatPlanIds), "fetch-seat-plan-status");
|
List<SeatPlanStatus> seatPlanStatusList = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getSeatPlanStatusFromHttp(seatPlanIds, token), "fetch-seat-plan-status");
|
||||||
if (CollectionUtils.isEmpty(seatPlanStatusList)) {
|
if (CollectionUtils.isEmpty(seatPlanStatusList)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -186,6 +188,7 @@ public class PullDataFromFWDJob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stopThread();
|
||||||
}
|
}
|
||||||
if (!CollectionUtils.isEmpty(insertList)) {
|
if (!CollectionUtils.isEmpty(insertList)) {
|
||||||
performSeatInfoMapper.batchSave(insertList);
|
performSeatInfoMapper.batchSave(insertList);
|
||||||
@@ -198,14 +201,14 @@ public class PullDataFromFWDJob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private FPerformProjectInfo handleProjectData(ProjectList project) {
|
private FPerformProjectInfo handleProjectData(ProjectList project, String token) {
|
||||||
// 查询演出的详情
|
// 查询演出的详情
|
||||||
ProjectInfoResp projectInfoFromHttp = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getProjectInfoFromHttp(project.getProjectId()), "fetch-project-info");
|
ProjectInfoResp projectInfoFromHttp = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getProjectInfoFromHttp(project.getProjectId(), token), "fetch-project-info");
|
||||||
if (Objects.isNull(projectInfoFromHttp)) {
|
if (Objects.isNull(projectInfoFromHttp)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 查询演出信息
|
// 查询演出信息
|
||||||
Perform performsByProjectIdFromHttp = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getPerformsByProjectIdFromHttp(project.getProjectId()), "fetch-perform-by-project-id");
|
Perform performsByProjectIdFromHttp = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getPerformsByProjectIdFromHttp(project.getProjectId(), token), "fetch-perform-by-project-id");
|
||||||
if (Objects.isNull(performsByProjectIdFromHttp)) {
|
if (Objects.isNull(performsByProjectIdFromHttp)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -235,100 +238,17 @@ public class PullDataFromFWDJob {
|
|||||||
|
|
||||||
}
|
}
|
||||||
projectInfo.setSeatPlans(seats);
|
projectInfo.setSeatPlans(seats);
|
||||||
|
stopThread();
|
||||||
return projectInfo;
|
return projectInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void stopThread() {
|
||||||
public void pullPerformDataJob() {
|
try {
|
||||||
int pageNum = 0;
|
String random = RandomCodeUtils.getNumberRandomCode(1);
|
||||||
while (true) {
|
log.info("线程暂停:{}s", random);
|
||||||
pageNum++;
|
Thread.sleep(Long.parseLong(random) * 1000);
|
||||||
BaseRequest baseRequest = new BaseRequest();
|
} catch (InterruptedException e) {
|
||||||
baseRequest.setCurrent(pageNum);
|
log.error("线程暂停1s失败");
|
||||||
baseRequest.setPageSize(50);
|
|
||||||
// 查询所有的演出
|
|
||||||
ProjectsResp projectsResp = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getShowProjectsFromHttp(baseRequest), "fetch-projects");
|
|
||||||
if (Objects.isNull(projectsResp)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
List<ProjectList> projectLists = projectsResp.getList();
|
|
||||||
if (CollectionUtils.isEmpty(projectLists)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (ProjectList projectList : projectLists) {
|
|
||||||
// 查询演出的详情
|
|
||||||
ProjectInfoResp projectInfoFromHttp = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getProjectInfoFromHttp(projectList.getProjectId()), "fetch-project-info");
|
|
||||||
if (Objects.isNull(projectInfoFromHttp)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 查询演出信息
|
|
||||||
Perform performsByProjectIdFromHttp = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getPerformsByProjectIdFromHttp(projectList.getProjectId()), "fetch-perform-by-project-id");
|
|
||||||
if (Objects.isNull(performsByProjectIdFromHttp)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询数据库
|
|
||||||
FPerformProjectInfo projectInfo = performProjectInfoMapper.getProjectByProjectId(performsByProjectIdFromHttp.getProjectId());
|
|
||||||
if (Objects.isNull(projectInfo)) {
|
|
||||||
// 不存在则新增
|
|
||||||
saveProjectInfo(projectList, projectInfoFromHttp);
|
|
||||||
} else {
|
|
||||||
// 存在则更新
|
|
||||||
buildUpdateProjectInfo(projectList, projectInfo, projectInfoFromHttp);
|
|
||||||
performProjectInfoMapper.update(projectInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询演出信息
|
|
||||||
List<PerformInfo> performInfos = performsByProjectIdFromHttp.getPerformInfos();
|
|
||||||
if (CollectionUtils.isEmpty(performInfos)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 查询演出座位档次信息
|
|
||||||
List<FPerformSeatInfo> insertList = Lists.newCopyOnWriteArrayList();
|
|
||||||
List<FPerformSeatInfo> updateList = Lists.newCopyOnWriteArrayList();
|
|
||||||
for (PerformInfo performInfo : performInfos) {
|
|
||||||
List<PerformDetail> performs = performInfo.getPerformInfo();
|
|
||||||
if (CollectionUtils.isEmpty(performs)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (PerformDetail perform : performs) {
|
|
||||||
if (CollectionUtils.isEmpty(perform.getSeatPlans())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
List<Long> seatPlanIds = perform.getSeatPlans().stream().map(SeatPlan::getSeatPlanId).collect(Collectors.toList());
|
|
||||||
List<SeatPlanStatus> seatPlanStatusList = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.getSeatPlanStatusFromHttp(seatPlanIds), "fetch-seat-plan-status");
|
|
||||||
if (CollectionUtils.isEmpty(seatPlanStatusList)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Map<Long, SeatPlanStatus> map = seatPlanStatusList.stream().collect(Collectors.toMap(SeatPlanStatus::getSeatPlanId, Function.identity(), (a, b) -> a));
|
|
||||||
Map<Long, FPerformSeatInfo> existSeatMap = performSeatInfoMapper.getPerformSeatInfoBySeatIds(seatPlanIds)
|
|
||||||
.stream()
|
|
||||||
.collect(Collectors.toMap(FPerformSeatInfo::getSeatPlanId, Function.identity(), (a, b) -> a));
|
|
||||||
for (SeatPlan seatPlan : perform.getSeatPlans()) {
|
|
||||||
if (map.containsKey(seatPlan.getSeatPlanId())) {
|
|
||||||
SeatPlanStatus value = map.get(seatPlan.getSeatPlanId());
|
|
||||||
if (existSeatMap.containsKey(seatPlan.getSeatPlanId())) {
|
|
||||||
// 更新
|
|
||||||
FPerformSeatInfo performSeatInfo = existSeatMap.get(seatPlan.getSeatPlanId());
|
|
||||||
performSeatInfo.setSoldStock(value.getSoldOutFlag() ? 1 : 0);
|
|
||||||
updateList.add(performSeatInfo);
|
|
||||||
} else {
|
|
||||||
// 新增
|
|
||||||
saveSeatInfo(projectList.getProjectId(), seatPlan.getSeatPlanId(), value, seatPlan, insertList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!CollectionUtils.isEmpty(insertList)) {
|
|
||||||
performSeatInfoMapper.batchSave(insertList);
|
|
||||||
}
|
|
||||||
if (!CollectionUtils.isEmpty(updateList)) {
|
|
||||||
for (FPerformSeatInfo seatInfo : updateList) {
|
|
||||||
performSeatInfoMapper.update(seatInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package com.xiang.xservice.application.script.fwd.schedule;
|
package com.xiang.xservice.application.script.fwd.schedule;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.xiang.xmc.service.schedule.service.IDynamicTaskSchedulerService;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.param.FwdOrderTaskParam;
|
import com.xiang.xservice.application.script.fwd.entity.param.FwdOrderTaskParam;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FAudienceConfig;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FAudienceConfig;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FUserConfig;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FUserConfig;
|
||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdAudienceConfigMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdAudienceConfigMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
||||||
import com.xiang.xservice.schedule.service.IDynamicTaskSchedulerService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public class TicketGrabTask implements Runnable {
|
|||||||
for (FUserConfig userConfig : availableUser) {
|
for (FUserConfig userConfig : availableUser) {
|
||||||
List<FAudienceConfig> audiences = audienceConfigMapper.getAudienceByUserId(userConfig.getId());
|
List<FAudienceConfig> audiences = audienceConfigMapper.getAudienceByUserId(userConfig.getId());
|
||||||
try {
|
try {
|
||||||
performService.createProjectOrder(param.getProjectId(), audiences.stream().map(FAudienceConfig::getFrequentId).collect(Collectors.toList()));
|
performService.createProjectOrder(param.getProjectId(), audiences.stream().map(FAudienceConfig::getFrequentId).collect(Collectors.toList()), userConfig.getToken());
|
||||||
dynamicTaskSchedulerService.finishTask(param.getTaskId());
|
dynamicTaskSchedulerService.finishTask(param.getTaskId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("创建订单失败", e);
|
log.error("创建订单失败", e);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiang.xservice.application.script.fwd.server;
|
package com.xiang.xservice.application.script.fwd.server;
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
import com.xiang.xservice.basic.utils.DateUtils;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig;
|
||||||
@@ -27,13 +28,15 @@ public class FwdDataController {
|
|||||||
|
|
||||||
private final IPerformService performService;
|
private final IPerformService performService;
|
||||||
private final IPerformServiceHttp performServiceHttp;
|
private final IPerformServiceHttp performServiceHttp;
|
||||||
|
private final FwdUserConfigMapper userConfigMapper;
|
||||||
|
|
||||||
@PostMapping("/refreshData")
|
@PostMapping("/refreshData")
|
||||||
public Result<String> refreshData() {
|
public Result<String> refreshData() {
|
||||||
|
String token = userConfigMapper.getAvailableUser().get(0).getToken();
|
||||||
List<FPerformConfig> availablePerforms = performService.getAvailablePerform();
|
List<FPerformConfig> availablePerforms = performService.getAvailablePerform();
|
||||||
for (FPerformConfig availablePerform : availablePerforms) {
|
for (FPerformConfig availablePerform : availablePerforms) {
|
||||||
ProjectInfoResp info = performServiceHttp.getProjectInfoFromHttp(availablePerform.getProjectId());
|
ProjectInfoResp info = performServiceHttp.getProjectInfoFromHttp(availablePerform.getProjectId(), token);
|
||||||
Perform performsByProjectIdFromHttp = performServiceHttp.getPerformsByProjectIdFromHttp(availablePerform.getProjectId());
|
Perform performsByProjectIdFromHttp = performServiceHttp.getPerformsByProjectIdFromHttp(availablePerform.getProjectId(), token);
|
||||||
FPerformProjectInfo performByProjectId = performService.getPerformByProjectId(availablePerform.getProjectId());
|
FPerformProjectInfo performByProjectId = performService.getPerformByProjectId(availablePerform.getProjectId());
|
||||||
performByProjectId.setStatus(info.getStatus());
|
performByProjectId.setStatus(info.getStatus());
|
||||||
performByProjectId.setPreSaleTime(DateUtils.getDateTimeFromStr(info.getPreSaleTime()));
|
performByProjectId.setPreSaleTime(DateUtils.getDateTimeFromStr(info.getPreSaleTime()));
|
||||||
@@ -53,7 +56,7 @@ public class FwdDataController {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<Long> seatIds = seatPlans.stream().map(SeatPlan::getSeatPlanId).collect(Collectors.toList());
|
List<Long> seatIds = seatPlans.stream().map(SeatPlan::getSeatPlanId).collect(Collectors.toList());
|
||||||
List<SeatPlanStatus> seatPlanStatusFromHttp = performServiceHttp.getSeatPlanStatusFromHttp(seatIds);
|
List<SeatPlanStatus> seatPlanStatusFromHttp = performServiceHttp.getSeatPlanStatusFromHttp(seatIds, token);
|
||||||
if (CollectionUtils.isEmpty(seatPlanStatusFromHttp)) {
|
if (CollectionUtils.isEmpty(seatPlanStatusFromHttp)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiang.xservice.application.script.fwd.server;
|
package com.xiang.xservice.application.script.fwd.server;
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
||||||
import com.xiang.xservice.basic.common.req.BaseRequest;
|
import com.xiang.xservice.basic.common.req.BaseRequest;
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.Perform;
|
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.Perform;
|
||||||
@@ -28,6 +29,7 @@ public class FwdOuterController {
|
|||||||
|
|
||||||
private final IPerformServiceHttp performServiceHttp;
|
private final IPerformServiceHttp performServiceHttp;
|
||||||
private final IPerformService performService;
|
private final IPerformService performService;
|
||||||
|
private final FwdUserConfigMapper fwdUserConfigMapper;
|
||||||
private static final List<Long> FREQUENT_IDS = List.of(50438548L, 35320661L, 50436621L, 50442739L);
|
private static final List<Long> FREQUENT_IDS = List.of(50438548L, 35320661L, 50436621L, 50442739L);
|
||||||
|
|
||||||
|
|
||||||
@@ -39,19 +41,22 @@ public class FwdOuterController {
|
|||||||
|
|
||||||
@GetMapping("/getProjectInfo/{id}")
|
@GetMapping("/getProjectInfo/{id}")
|
||||||
public Result<Perform> getProjectInfo(@PathVariable("id") Long id) {
|
public Result<Perform> getProjectInfo(@PathVariable("id") Long id) {
|
||||||
Perform performsByProjectIdFromHttp = performServiceHttp.getPerformsByProjectIdFromHttp(id);
|
String token = fwdUserConfigMapper.getAvailableUser().get(0).getToken();
|
||||||
|
Perform performsByProjectIdFromHttp = performServiceHttp.getPerformsByProjectIdFromHttp(id, token);
|
||||||
return Result.success("查询成功!", performsByProjectIdFromHttp);
|
return Result.success("查询成功!", performsByProjectIdFromHttp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getPerformsByProjectIdFromHttp/{id}")
|
@GetMapping("/getPerformsByProjectIdFromHttp/{id}")
|
||||||
public Result<Perform> getPerformsByProjectIdFromHttp(@PathVariable("id") Long id) {
|
public Result<Perform> getPerformsByProjectIdFromHttp(@PathVariable("id") Long id) {
|
||||||
Perform performsByProjectIdFromHttp = performServiceHttp.getPerformsByProjectIdFromHttp(id);
|
String token = fwdUserConfigMapper.getAvailableUser().get(0).getToken();
|
||||||
|
Perform performsByProjectIdFromHttp = performServiceHttp.getPerformsByProjectIdFromHttp(id, token);
|
||||||
return Result.success("查询成功!", performsByProjectIdFromHttp);
|
return Result.success("查询成功!", performsByProjectIdFromHttp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/createOrder")
|
@PostMapping("/createOrder")
|
||||||
public Result<String> createOrder(Long projectId) throws Exception {
|
public Result<String> createOrder(Long projectId) throws Exception {
|
||||||
if (performService.createProjectOrder(projectId, FREQUENT_IDS)) {
|
String token = fwdUserConfigMapper.getAvailableUser().get(0).getToken();
|
||||||
|
if (performService.createProjectOrder(projectId, FREQUENT_IDS, token)) {
|
||||||
return Result.success("下单成功!");
|
return Result.success("下单成功!");
|
||||||
}
|
}
|
||||||
return Result.error("下单失败!");
|
return Result.error("下单失败!");
|
||||||
@@ -59,7 +64,8 @@ public class FwdOuterController {
|
|||||||
|
|
||||||
@GetMapping("/getSeatPlanStatus")
|
@GetMapping("/getSeatPlanStatus")
|
||||||
public Result<SeatPlanStatus> getSeatPlanStatu (@RequestParam List<Long> ids) {
|
public Result<SeatPlanStatus> getSeatPlanStatu (@RequestParam List<Long> ids) {
|
||||||
List<SeatPlanStatus> seatPlanStatusFromHttp = performServiceHttp.getSeatPlanStatusFromHttp(ids);
|
String token = fwdUserConfigMapper.getAvailableUser().get(0).getToken();
|
||||||
|
List<SeatPlanStatus> seatPlanStatusFromHttp = performServiceHttp.getSeatPlanStatusFromHttp(ids, token);
|
||||||
return Result.success("查询成功!", seatPlanStatusFromHttp);
|
return Result.success("查询成功!", seatPlanStatusFromHttp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.xiang.xservice.application.script.fwd.server;
|
package com.xiang.xservice.application.script.fwd.server;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
|
||||||
import com.xiang.xservice.application.script.fwd.service.DingTalkScriptFWDService;
|
|
||||||
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
|
import com.xiang.xservice.common.service.dingTalk.ScriptDingTalkFactory;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -24,7 +24,7 @@ import java.util.Map;
|
|||||||
public class FwdUserController {
|
public class FwdUserController {
|
||||||
|
|
||||||
private final IPerformService performService;
|
private final IPerformService performService;
|
||||||
private final DingTalkScriptFWDService dingTalkService;
|
private final ScriptDingTalkFactory dingTalkService;
|
||||||
|
|
||||||
@GetMapping("/token")
|
@GetMapping("/token")
|
||||||
public Result<Void> updateUserTokenFromHttpProxy(@RequestParam Map<String, String> params) {
|
public Result<Void> updateUserTokenFromHttpProxy(@RequestParam Map<String, String> params) {
|
||||||
@@ -35,7 +35,7 @@ public class FwdUserController {
|
|||||||
if (b) {
|
if (b) {
|
||||||
String msg = "用户:" + name + "的token更新成功!";
|
String msg = "用户:" + name + "的token更新成功!";
|
||||||
try {
|
try {
|
||||||
dingTalkService.sendScriptMsg(msg);
|
dingTalkService.sendMsg(msg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("消息发送失败", e);
|
log.error("消息发送失败", e);
|
||||||
return Result.error("消息发送失败");
|
return Result.error("消息发送失败");
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.fwd.service;
|
|
||||||
|
|
||||||
import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService;
|
|
||||||
import com.xiang.xservice.config.DingTalkRobotScriptConfig;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-08-07 10:30
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class DingTalkScriptFWDService {
|
|
||||||
|
|
||||||
private final DingTalkService dingTalkService;
|
|
||||||
private final DingTalkRobotScriptConfig dingTalkRobotConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送脚本消息
|
|
||||||
* @param msg 消息
|
|
||||||
*/
|
|
||||||
public void sendScriptMsg(String msg) {
|
|
||||||
try {
|
|
||||||
dingTalkService.sendRobotMessage(dingTalkRobotConfig.getSecret(), dingTalkRobotConfig.getToken(), dingTalkRobotConfig.getUsers(), msg);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("信息发送异常, 信息:{}", msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,7 +16,7 @@ public interface IPerformService {
|
|||||||
|
|
||||||
List<FPerformSeatInfo> getPerformSeatInfoByProjectId(Long projectId);
|
List<FPerformSeatInfo> getPerformSeatInfoByProjectId(Long projectId);
|
||||||
|
|
||||||
Boolean createProjectOrder(Long projectId, List<Long> frequentIds) throws Exception;
|
Boolean createProjectOrder(Long projectId, List<Long> frequentIds, String token) throws Exception;
|
||||||
|
|
||||||
List<FPerformConfig> getAvailablePerform();
|
List<FPerformConfig> getAvailablePerform();
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public interface IPerformServiceHttp {
|
|||||||
* @param projectId projectId
|
* @param projectId projectId
|
||||||
* @return ProjectInfoResp
|
* @return ProjectInfoResp
|
||||||
*/
|
*/
|
||||||
ProjectInfoResp getProjectInfoFromHttp(Long projectId);
|
ProjectInfoResp getProjectInfoFromHttp(Long projectId, String token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http请求创建演出订单
|
* http请求创建演出订单
|
||||||
@@ -38,14 +38,14 @@ public interface IPerformServiceHttp {
|
|||||||
* @param projectId
|
* @param projectId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Perform getPerformsByProjectIdFromHttp(Long projectId);
|
Perform getPerformsByProjectIdFromHttp(Long projectId, String token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http请求获取座位状态信息
|
* http请求获取座位状态信息
|
||||||
* @param seatPlanIds
|
* @param seatPlanIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<SeatPlanStatus> getSeatPlanStatusFromHttp(List<Long> seatPlanIds);
|
List<SeatPlanStatus> getSeatPlanStatusFromHttp(List<Long> seatPlanIds, String token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http请求查询观影人信息
|
* http请求查询观影人信息
|
||||||
|
|||||||
@@ -66,11 +66,11 @@ public class PerformServiceHttpServiceImpl implements IPerformServiceHttp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProjectInfoResp getProjectInfoFromHttp(Long projectId) {
|
public ProjectInfoResp getProjectInfoFromHttp(Long projectId, String token) {
|
||||||
Map<String, String> params = Maps.newHashMap();
|
Map<String, String> params = Maps.newHashMap();
|
||||||
params.put("project_id", String.valueOf(projectId));
|
params.put("project_id", String.valueOf(projectId));
|
||||||
params.put("v", String.valueOf(Instant.now().getEpochSecond()));
|
params.put("v", String.valueOf(Instant.now().getEpochSecond()));
|
||||||
String respStr = HttpUtils.doGet(UrlConstants.PROJECTS_INFO_URL, buildFWDHeaders(UrlConstants.token), params);
|
String respStr = HttpUtils.doGet(UrlConstants.PROJECTS_INFO_URL, buildFWDHeaders(token), params);
|
||||||
if (StringUtils.isBlank(respStr)) {
|
if (StringUtils.isBlank(respStr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ public class PerformServiceHttpServiceImpl implements IPerformServiceHttp {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProjectOrderCreateResp createProjectOrder(ProjectOrderCreateReq req, String token) {
|
public ProjectOrderCreateResp createProjectOrder(ProjectOrderCreateReq req, String token) {
|
||||||
String respStr = HttpUtils.doPost(UrlConstants.PROJECT_ORDER_CREATE_URL, buildFWDHeaders(token), JsonUtils.toJsonString(req));
|
String respStr = HttpUtils.doPost(UrlConstants.PROJECT_ORDER_CREATE_URL, buildFWDOrderHeaders(token), JsonUtils.toJsonString(req));
|
||||||
if (StringUtils.isBlank(respStr)) {
|
if (StringUtils.isBlank(respStr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -104,19 +104,26 @@ public class PerformServiceHttpServiceImpl implements IPerformServiceHttp {
|
|||||||
return projectOrderCreateResp;
|
return projectOrderCreateResp;
|
||||||
}
|
}
|
||||||
if (Objects.nonNull(code) && Objects.equals(code, CodeConstants.LIMIT)) {
|
if (Objects.nonNull(code) && Objects.equals(code, CodeConstants.LIMIT)) {
|
||||||
Integer waitTime = new Random().nextInt(10);
|
int waitTime = new Random().nextInt(3);
|
||||||
log.info("触发FWD限流机制,等待:{}秒后重新发送。", waitTime);
|
if (Objects.equals(waitTime, 0)) {
|
||||||
|
waitTime = 3;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
log.info("触发FWD限流机制,等待:{}秒后重新发送。", waitTime);
|
||||||
|
Thread.sleep((long) waitTime * 1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("线程暂停失败!");
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Perform getPerformsByProjectIdFromHttp(Long projectId) {
|
public Perform getPerformsByProjectIdFromHttp(Long projectId, String token) {
|
||||||
Map<String, String> params = Maps.newHashMap();
|
Map<String, String> params = Maps.newHashMap();
|
||||||
params.put("project_id", String.valueOf(projectId));
|
params.put("project_id", String.valueOf(projectId));
|
||||||
params.put("v", String.valueOf(Instant.now().getEpochSecond()));
|
params.put("v", String.valueOf(Instant.now().getEpochSecond()));
|
||||||
String respStr = HttpUtils.doGet(UrlConstants.PERFORMS_URL, buildFWDHeaders(UrlConstants.token), params);
|
String respStr = HttpUtils.doGet(UrlConstants.PERFORMS_URL, buildFWDHeaders(token), params);
|
||||||
if (StringUtils.isBlank(respStr)) {
|
if (StringUtils.isBlank(respStr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -134,7 +141,7 @@ public class PerformServiceHttpServiceImpl implements IPerformServiceHttp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SeatPlanStatus> getSeatPlanStatusFromHttp(List<Long> seatPlanIds) {
|
public List<SeatPlanStatus> getSeatPlanStatusFromHttp(List<Long> seatPlanIds, String token) {
|
||||||
StringBuilder seatIds = new StringBuilder();
|
StringBuilder seatIds = new StringBuilder();
|
||||||
for (Long seatPlanId : seatPlanIds) {
|
for (Long seatPlanId : seatPlanIds) {
|
||||||
seatIds.append(seatPlanId).append(",");
|
seatIds.append(seatPlanId).append(",");
|
||||||
@@ -142,7 +149,7 @@ public class PerformServiceHttpServiceImpl implements IPerformServiceHttp {
|
|||||||
Map<String, String> params = Maps.newHashMap();
|
Map<String, String> params = Maps.newHashMap();
|
||||||
params.put("seatPlanIds", seatIds.substring(0, seatIds.length() - 2));
|
params.put("seatPlanIds", seatIds.substring(0, seatIds.length() - 2));
|
||||||
params.put("type", "3");
|
params.put("type", "3");
|
||||||
String respStr = HttpUtils.doGet(UrlConstants.PROJECT_SEAT_STATUS_URL, buildFWDHeaders(UrlConstants.token), params);
|
String respStr = HttpUtils.doGet(UrlConstants.PROJECT_SEAT_STATUS_URL, buildFWDHeaders(token), params);
|
||||||
if (StringUtils.isBlank(respStr)) {
|
if (StringUtils.isBlank(respStr)) {
|
||||||
return Lists.newArrayList();
|
return Lists.newArrayList();
|
||||||
}
|
}
|
||||||
@@ -219,6 +226,20 @@ public class PerformServiceHttpServiceImpl implements IPerformServiceHttp {
|
|||||||
|
|
||||||
private Map<String, String> buildFWDOrderHeaders(String token) {
|
private Map<String, String> buildFWDOrderHeaders(String token) {
|
||||||
Map<String, String> headers = Maps.newHashMap();
|
Map<String, String> headers = Maps.newHashMap();
|
||||||
|
headers.put("Host", "api.livelab.com.cn");
|
||||||
|
headers.put("x-fwd-anonymousId", "ocXac5C25MY5O3UM_EfL0oTgm7Jw");
|
||||||
|
headers.put("platform-type", "%E7%BA%B7%E7%8E%A9%E5%B2%9B%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F");
|
||||||
|
headers.put("Authorization", token);
|
||||||
|
headers.put("platform-version", "3.17.1");
|
||||||
|
headers.put("xweb_xhr", "1");
|
||||||
|
headers.put("Content-Type", "application/json");
|
||||||
|
headers.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Mac MacWechat/WMPF MacWechat/3.8.7(0x13080712) UnifiedPCMacWechat(0xf2641110) XWEB/16730");
|
||||||
|
headers.put("Accept", "*/*");
|
||||||
|
headers.put("Sec-Fetch-Site", "cross-site");
|
||||||
|
headers.put("Sec-Fetch-Mode", "cors");
|
||||||
|
headers.put("Sec-Fetch-Dest", "empty");
|
||||||
|
headers.put("Referer", "https://servicewechat.com/wx5a8f481d967649eb/123/page-frame.html");
|
||||||
|
headers.put("Accept-Language", "zh-CN,zh;q=0.9");
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.xiang.xservice.application.script.fwd.service.impl;
|
package com.xiang.xservice.application.script.fwd.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.xiang.xservice.basic.config.MyThreadFactory;
|
import com.xiang.xmc.service.http.helper.HttpRequestHelper;
|
||||||
|
import com.xiang.xservice.application.script.fwd.constants.PriceRange;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo;
|
||||||
@@ -12,25 +13,30 @@ import com.xiang.xservice.application.script.fwd.mapper.FwdPerformConfigMapper;
|
|||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformProjectInfoMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformProjectInfoMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformSeatInfoMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdPerformSeatInfoMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
||||||
import com.xiang.xservice.application.script.fwd.service.DingTalkScriptFWDService;
|
|
||||||
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
||||||
import com.xiang.xservice.application.script.fwd.service.IPerformServiceHttp;
|
import com.xiang.xservice.application.script.fwd.service.IPerformServiceHttp;
|
||||||
import com.xiang.xservice.http.helper.HttpRequestHelper;
|
import com.xiang.xservice.basic.config.MyThreadFactory;
|
||||||
|
import com.xiang.xservice.common.service.dingTalk.ScriptDingTalkFactory;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: xiang
|
* @Author: xiang
|
||||||
@@ -45,7 +51,7 @@ public class PerformServiceImpl implements IPerformService {
|
|||||||
private final FwdPerformProjectInfoMapper fwdPerformProjectInfoMapper;
|
private final FwdPerformProjectInfoMapper fwdPerformProjectInfoMapper;
|
||||||
private final FwdPerformConfigMapper fwdPerformConfigMapper;
|
private final FwdPerformConfigMapper fwdPerformConfigMapper;
|
||||||
private final IPerformServiceHttp performServiceHttp;
|
private final IPerformServiceHttp performServiceHttp;
|
||||||
private final DingTalkScriptFWDService dingTalkService;
|
private final ScriptDingTalkFactory dingTalkService;
|
||||||
private final FwdUserConfigMapper fwdUserConfigMapper;
|
private final FwdUserConfigMapper fwdUserConfigMapper;
|
||||||
private final HttpRequestHelper httpRequestHelper;
|
private final HttpRequestHelper httpRequestHelper;
|
||||||
private final ExecutorService es =
|
private final ExecutorService es =
|
||||||
@@ -69,11 +75,7 @@ public class PerformServiceImpl implements IPerformService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean createProjectOrder(Long projectId, List<Long> frequentIds) throws Exception {
|
public Boolean createProjectOrder(Long projectId, List<Long> frequentIds, String token) throws Exception {
|
||||||
List<FUserConfig> availableUser = fwdUserConfigMapper.getAvailableUser();
|
|
||||||
if (CollectionUtils.isEmpty(availableUser)) {
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
FPerformProjectInfo performByProjectId = getPerformByProjectId(projectId);
|
FPerformProjectInfo performByProjectId = getPerformByProjectId(projectId);
|
||||||
if (Objects.isNull(performByProjectId)) {
|
if (Objects.isNull(performByProjectId)) {
|
||||||
log.info("该projectId:{}暂无演出信息", projectId);
|
log.info("该projectId:{}暂无演出信息", projectId);
|
||||||
@@ -84,42 +86,69 @@ public class PerformServiceImpl implements IPerformService {
|
|||||||
log.info("该projectId:{}暂无座位信息", projectId);
|
log.info("该projectId:{}暂无座位信息", projectId);
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
for (FPerformSeatInfo fPerformSeatInfo : seatInfoByProjectId) {
|
Map<Long, List<FPerformSeatInfo>> performMap = seatInfoByProjectId.stream().filter(item -> 0 == item.getSoldOut()).collect(Collectors.groupingBy(FPerformSeatInfo::getPerformId));
|
||||||
if (1 == fPerformSeatInfo.getSoldOut()) {
|
// todo 场次座位排序 优先 场次先后顺序 周六>周日>周五>工作日 根据场次分组进行
|
||||||
continue;
|
// todo 座位价格排序 优先 600-900 > 900-1300 > 1300-1600 > 1600~* > 0-600
|
||||||
}
|
for (Long performId : performMap.keySet()) {
|
||||||
ProjectOrderCreateReq projectOrderCreateReq = buildReq(projectId, frequentIds, fPerformSeatInfo);
|
List<FPerformSeatInfo> fPerformSeatInfos = performMap.get(performId);
|
||||||
for (int i = 1; i <= 10; i++) {
|
AtomicReference<BigDecimal> atomicPrice = new AtomicReference<>();
|
||||||
ProjectOrderCreateResp projectOrder = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.createProjectOrder(projectOrderCreateReq, availableUser.get(0).getToken()), "create-project-order");
|
fPerformSeatInfos.stream().map(FPerformSeatInfo::getPrice).max(BigDecimal::compareTo).ifPresent(atomicPrice::set);
|
||||||
|
BigDecimal price = atomicPrice.get();
|
||||||
|
// 排序座位
|
||||||
|
/*
|
||||||
|
0: 600-900
|
||||||
|
1: 900-1300
|
||||||
|
2: 1300-1600
|
||||||
|
3: >1600
|
||||||
|
4: <=600
|
||||||
|
*/
|
||||||
|
List<Long> seatIds = fPerformSeatInfos.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
seat -> PriceRange.fromPrice(seat.getPrice()),
|
||||||
|
Collectors.collectingAndThen(Collectors.toList(), list -> {
|
||||||
|
Collections.shuffle(list);
|
||||||
|
return list;
|
||||||
|
})
|
||||||
|
))
|
||||||
|
.entrySet().stream()
|
||||||
|
.sorted(Comparator.comparing(entry -> entry.getKey().getIndex()))
|
||||||
|
.flatMap(entry -> entry.getValue().stream())
|
||||||
|
.map(FPerformSeatInfo::getSeatPlanId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
ProjectOrderCreateReq projectOrderCreateReq = buildReqV2(projectId, frequentIds, seatIds, performId, price);
|
||||||
|
for (int i = 1; i <= 100; i++) {
|
||||||
|
ProjectOrderCreateResp projectOrder = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.createProjectOrder(projectOrderCreateReq, token), "create-project-order");
|
||||||
if (Objects.nonNull(projectOrder)) {
|
if (Objects.nonNull(projectOrder)) {
|
||||||
log.info("下单成功,订单信息:{}", JSONObject.toJSONString(projectOrder));
|
log.info("下单成功,订单信息:{}", JSONObject.toJSONString(projectOrder));
|
||||||
String msg = "【芬玩岛】下单成功✅✅✅,演出名称:" + performByProjectId.getProjectName() + ",请在2分钟内完成付款!";
|
String msg = "【芬玩岛】下单成功✅✅✅,演出名称:" + performByProjectId.getProjectName() + ",请在5分钟内完成付款!订单号:" + projectOrder.getOrderNo();
|
||||||
dingTalkService.sendScriptMsg(msg);
|
dingTalkService.sendMsg(msg);
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dingTalkService.sendScriptMsg("【芬玩岛】下单失败❌❌❌,演出名称:" + performByProjectId.getProjectName());
|
dingTalkService.sendMsg("【芬玩岛】下单失败❌❌❌,演出名称:" + performByProjectId.getProjectName());
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static ProjectOrderCreateReq buildReq(Long projectId, List<Long> frequentIds, FPerformSeatInfo fPerformSeatInfo) {
|
private static ProjectOrderCreateReq buildReqV2(Long projectId, List<Long> frequentIds, List<Long> seatPlanIds, Long perfomrId, BigDecimal price) {
|
||||||
ProjectOrderCreateReq projectOrderCreateReq = new ProjectOrderCreateReq();
|
ProjectOrderCreateReq projectOrderCreateReq = new ProjectOrderCreateReq();
|
||||||
projectOrderCreateReq.setDeliveryType(1);
|
projectOrderCreateReq.setDeliveryType(1);
|
||||||
projectOrderCreateReq.setContactName("朱吉祥");
|
projectOrderCreateReq.setContactName("朱吉祥");
|
||||||
projectOrderCreateReq.setContactPhone("15858717571");
|
projectOrderCreateReq.setContactPhone("15858717571");
|
||||||
projectOrderCreateReq.setPayment(fPerformSeatInfo.getPrice().multiply(BigDecimal.valueOf(frequentIds.size())).setScale(2));
|
projectOrderCreateReq.setPayment(price.multiply(BigDecimal.valueOf(frequentIds.size())).setScale(2));
|
||||||
projectOrderCreateReq.setTotalPrice(fPerformSeatInfo.getPrice().multiply(BigDecimal.valueOf(frequentIds.size())).setScale(2, BigDecimal.ROUND_HALF_UP));
|
projectOrderCreateReq.setTotalPrice(price.multiply(BigDecimal.valueOf(frequentIds.size())).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||||
projectOrderCreateReq.setPerformId(fPerformSeatInfo.getPerformId());
|
projectOrderCreateReq.setPerformId(perfomrId);
|
||||||
projectOrderCreateReq.setProjectId(projectId.toString());
|
projectOrderCreateReq.setProjectId(projectId.toString());
|
||||||
projectOrderCreateReq.setPrivilegeCodeList(new ArrayList<>());
|
projectOrderCreateReq.setPrivilegeCodeList(new ArrayList<>());
|
||||||
projectOrderCreateReq.setAudienceCount(frequentIds.size());
|
projectOrderCreateReq.setAudienceCount(frequentIds.size());
|
||||||
projectOrderCreateReq.setFrequentIds(frequentIds);
|
projectOrderCreateReq.setFrequentIds(frequentIds);
|
||||||
projectOrderCreateReq.setSeatPlanIds(Collections.singletonList(fPerformSeatInfo.getSeatPlanId()));
|
projectOrderCreateReq.setSeatPlanIds(seatPlanIds);
|
||||||
projectOrderCreateReq.setBlackBox(":0");
|
projectOrderCreateReq.setBlackBox(":0");
|
||||||
projectOrderCreateReq.setCombineTicketVos(null);
|
projectOrderCreateReq.setCombineTicketVos(null);
|
||||||
projectOrderCreateReq.setOrdinaryTicketVos(null);
|
projectOrderCreateReq.setOrdinaryTicketVos(null);
|
||||||
|
projectOrderCreateReq.setActivityId(Strings.EMPTY);
|
||||||
|
projectOrderCreateReq.setActivityType(0);
|
||||||
return projectOrderCreateReq;
|
return projectOrderCreateReq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ public class GladosConstants {
|
|||||||
|
|
||||||
public static final String GLADOS_COOKIE = "SL_G_WPT_TO=en; SL_GWPT_Show_Hide_tmp=1; SL_wptGlobTipTmp=1; koa:sess=eyJ1c2VySWQiOjU1OTg1MywiX2V4cGlyZSI6MTc3MjYwNDkyNjI4OCwiX21heEFnZSI6MjU5MjAwMDAwMDB9; koa:sess.sig=OdaqjpLkIp19lXn0lFuOsHX7vEM";
|
public static final String GLADOS_COOKIE = "SL_G_WPT_TO=en; SL_GWPT_Show_Hide_tmp=1; SL_wptGlobTipTmp=1; koa:sess=eyJ1c2VySWQiOjU1OTg1MywiX2V4cGlyZSI6MTc3MjYwNDkyNjI4OCwiX21heEFnZSI6MjU5MjAwMDAwMDB9; koa:sess.sig=OdaqjpLkIp19lXn0lFuOsHX7vEM";
|
||||||
|
|
||||||
public static final String GLADOS_CHECK_IN_BODY = "{\"token\":\"glados.one\"}";
|
public static final String GLADOS_CHECK_IN_BODY = "{\"token\":\"glados.cloud\"}";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ public class URLConstants {
|
|||||||
/**
|
/**
|
||||||
* glados 主域名
|
* glados 主域名
|
||||||
*/
|
*/
|
||||||
public static final String GLADOS_URL_PREFIX = "https://www.glados.one";
|
public static final String GLADOS_URL_PREFIX = "https://glados.cloud";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 签到
|
* 签到
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package com.xiang.xservice.application.script.glados.controller;
|
package com.xiang.xservice.application.script.glados.controller;
|
||||||
|
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
|
||||||
import com.xiang.xservice.application.script.glados.entity.req.GladosCheckInReq;
|
|
||||||
import com.xiang.xservice.application.script.glados.service.GLaDOSService;
|
import com.xiang.xservice.application.script.glados.service.GLaDOSService;
|
||||||
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -21,9 +19,10 @@ public class GLaDOSController {
|
|||||||
|
|
||||||
private final GLaDOSService glaDOSService;
|
private final GLaDOSService glaDOSService;
|
||||||
|
|
||||||
@PostMapping("/checkIn")
|
@GetMapping("/checkIn")
|
||||||
public Result<String> checkIn(@RequestBody GladosCheckInReq request) {
|
public Result<Void> checkIn() {
|
||||||
return Result.success(glaDOSService.checkIn());
|
glaDOSService.checkInV2();
|
||||||
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.xiang.xservice.application.script.glados.entity.resp;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-01-23 09:21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CheckInResp {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private Long userId;
|
||||||
|
private Long time;
|
||||||
|
private String asset;
|
||||||
|
private String business;
|
||||||
|
private String change;
|
||||||
|
private String balance;
|
||||||
|
private String detail;
|
||||||
|
}
|
||||||
@@ -19,9 +19,9 @@ public class GladosCheckInJob {
|
|||||||
|
|
||||||
private final GLaDOSService glaDOSService;
|
private final GLaDOSService glaDOSService;
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 8,16 1/1 * ?")
|
@Scheduled(cron = "0 0 7 1/1 * ?")
|
||||||
public void checkInJon() {
|
public void checkInJon() {
|
||||||
log.info("[job] Glados Check In Job start, time:{}", LocalDateTime.now());
|
log.info("[job] Glados Check In Job start, time:{}", LocalDateTime.now());
|
||||||
glaDOSService.checkIn();
|
glaDOSService.checkInV2();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.glados.service;
|
|
||||||
|
|
||||||
import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService;
|
|
||||||
import com.xiang.xservice.config.DingTalkRobotScriptConfig;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-08-07 10:30
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class DingTalkScriptGladosService {
|
|
||||||
|
|
||||||
private final DingTalkService dingTalkService;
|
|
||||||
private final DingTalkRobotScriptConfig dingTalkRobotScriptConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送脚本消息
|
|
||||||
* @param msg 消息
|
|
||||||
*/
|
|
||||||
public void sendScriptMsg(String msg) {
|
|
||||||
try {
|
|
||||||
dingTalkService.sendRobotMessage(dingTalkRobotScriptConfig.getSecret(), dingTalkRobotScriptConfig.getToken(),
|
|
||||||
dingTalkRobotScriptConfig.getUsers(), msg);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("信息发送异常, 信息:{}", msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,4 +10,9 @@ public interface GLaDOSService {
|
|||||||
* 签到
|
* 签到
|
||||||
*/
|
*/
|
||||||
String checkIn();
|
String checkIn();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 签到
|
||||||
|
*/
|
||||||
|
void checkInV2();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
package com.xiang.xservice.application.script.glados.service;
|
package com.xiang.xservice.application.script.glados.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.alibaba.fastjson2.TypeReference;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.xiang.xservice.basic.utils.HttpUtils;
|
import com.xiang.xmc.service.http.helper.BaseHttpHelp;
|
||||||
|
import com.xiang.xmc.service.http.helper.HttpHelperFactory;
|
||||||
import com.xiang.xservice.application.script.glados.common.GladosConstants;
|
import com.xiang.xservice.application.script.glados.common.GladosConstants;
|
||||||
import com.xiang.xservice.application.script.glados.common.URLConstants;
|
import com.xiang.xservice.application.script.glados.common.URLConstants;
|
||||||
import com.xiang.xservice.application.script.glados.entity.GladosRunLog;
|
import com.xiang.xservice.application.script.glados.entity.GladosRunLog;
|
||||||
|
import com.xiang.xservice.application.script.glados.entity.resp.CheckInResp;
|
||||||
import com.xiang.xservice.application.script.glados.entity.resp.GLaDOSResponse;
|
import com.xiang.xservice.application.script.glados.entity.resp.GLaDOSResponse;
|
||||||
import com.xiang.xservice.application.script.glados.repository.GladosMapper;
|
import com.xiang.xservice.application.script.glados.repository.GladosMapper;
|
||||||
import com.xiang.xservice.application.script.xb.entity.pojo.User;
|
import com.xiang.xservice.application.script.xb.entity.pojo.User;
|
||||||
|
import com.xiang.xservice.basic.utils.HttpUtils;
|
||||||
|
import com.xiang.xservice.common.service.dingTalk.ScriptDingTalkFactory;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -31,7 +36,9 @@ public class GLaDOSServiceImpl implements GLaDOSService{
|
|||||||
|
|
||||||
private final GladosMapper gladosMapper;
|
private final GladosMapper gladosMapper;
|
||||||
|
|
||||||
private final DingTalkScriptGladosService dingTalkService;
|
private final ScriptDingTalkFactory dingTalkService;
|
||||||
|
|
||||||
|
private final BaseHttpHelp httpHelp = HttpHelperFactory.createSimpleHttp();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 签到
|
* 签到
|
||||||
@@ -46,7 +53,16 @@ public class GLaDOSServiceImpl implements GLaDOSService{
|
|||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
users.parallelStream().forEach(user -> {
|
users.parallelStream().forEach(user -> {
|
||||||
try {
|
try {
|
||||||
checkIn(user, sb);
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (checkIn(user, sb)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(10000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("线程暂停10s失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("签到失败,", e);
|
log.error("签到失败,", e);
|
||||||
}
|
}
|
||||||
@@ -54,7 +70,92 @@ public class GLaDOSServiceImpl implements GLaDOSService{
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkIn(User user, StringBuffer sb) {
|
@Override
|
||||||
|
public void checkInV2() {
|
||||||
|
List<User> users = gladosMapper.listAllUser();
|
||||||
|
if (CollectionUtils.isEmpty(users)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (User user : users) {
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (checkInV2(user)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(10000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("线程暂停10s失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("签到失败,", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkInV2(User user) {
|
||||||
|
Map<String, String> header = Maps.newHashMap();
|
||||||
|
header.put("Cookie", user.getCookie());
|
||||||
|
|
||||||
|
String response = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
response = httpHelp.doPost(URLConstants.GLADOS_CHECK_IN_URL, header, GladosConstants.GLADOS_CHECK_IN_BODY);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("http请求异常:{}", user.getEmail());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (org.apache.commons.lang3.StringUtils.isBlank(response)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLaDOSResponse<CheckInResp> gLaDOSResponse = JSONObject.parseObject(response, new TypeReference<GLaDOSResponse<CheckInResp>>() {
|
||||||
|
});
|
||||||
|
if (Objects.isNull(gLaDOSResponse)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == gLaDOSResponse.getCode()) {
|
||||||
|
// 成功请求
|
||||||
|
if (Objects.nonNull(gLaDOSResponse.getPoints()) && 0 != gLaDOSResponse.getPoints()) {
|
||||||
|
// 签到成功
|
||||||
|
dingTalkService.sendMsg("[时间:" + LocalDateTime.now() + "] 用户: " +
|
||||||
|
user.getEmail() + "签到成功,获得积分:" + gLaDOSResponse.getPoints());
|
||||||
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(1).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gLaDOSResponse.getMessage().contains("Repeats")) {
|
||||||
|
if (!CollectionUtils.isEmpty(gLaDOSResponse.getList())) {
|
||||||
|
dingTalkService.sendMsg("用户:" + user.getEmail() + "当前已签到。结果:" + gLaDOSResponse.getList().get(0));
|
||||||
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(1).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-2 == gLaDOSResponse.getCode()) {
|
||||||
|
log.warn("签到失败,用户:{}, cookie过期:{}", user.getEmail(), gLaDOSResponse.getMessage());
|
||||||
|
String message = "[时间:" + LocalDateTime.now() + "] 用户: " + user.getEmail() + ",签到消息: " + gLaDOSResponse.getMessage() + "手动请求:http://general.xiangtech.xyz:30026/system/glados/checkIn";
|
||||||
|
try {
|
||||||
|
dingTalkService.sendMsg(message);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送钉钉消息失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 请求异常
|
||||||
|
dingTalkService.sendMsg("用户:" + user.getEmail() + "请求异常,响应结果:" + gLaDOSResponse.getMessage());
|
||||||
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(0).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIn(User user, StringBuffer sb) {
|
||||||
|
|
||||||
Map<String, String> header = Maps.newHashMap();
|
Map<String, String> header = Maps.newHashMap();
|
||||||
header.put("Cookie", user.getCookie());
|
header.put("Cookie", user.getCookie());
|
||||||
@@ -72,38 +173,74 @@ public class GLaDOSServiceImpl implements GLaDOSService{
|
|||||||
GLaDOSResponse gLaDOSResponse =JSONObject.parseObject(response, GLaDOSResponse.class);
|
GLaDOSResponse gLaDOSResponse =JSONObject.parseObject(response, GLaDOSResponse.class);
|
||||||
if (Objects.nonNull(gLaDOSResponse)) {
|
if (Objects.nonNull(gLaDOSResponse)) {
|
||||||
log.info("http do post success, response:{}", response);
|
log.info("http do post success, response:{}", response);
|
||||||
if (0 == gLaDOSResponse.getCode() && Objects.nonNull(gLaDOSResponse.getPoints())) {
|
|
||||||
log.info("签到成功, 签到积分:{}, 签到消息:{}", gLaDOSResponse.getPoints(), gLaDOSResponse.getMessage());
|
// 成功签到记录
|
||||||
sb.append(user.getEmail()).append("签到成功,获得积分:").append(gLaDOSResponse.getPoints()).append("\n");
|
if (0 == gLaDOSResponse.getCode()) {
|
||||||
try {
|
if (Objects.nonNull(gLaDOSResponse.getPoints())) {
|
||||||
dingTalkService.sendScriptMsg("[时间:" + LocalDateTime.now() + "] 用户: " +
|
log.info("签到成功, 签到积分:{}, 签到消息:{}", gLaDOSResponse.getPoints(), gLaDOSResponse.getMessage());
|
||||||
user.getEmail() + "签到成功,获得积分:" + gLaDOSResponse.getPoints());
|
sb.append(user.getEmail()).append("签到成功,获得积分:").append(gLaDOSResponse.getPoints()).append("\n");
|
||||||
} catch (Exception e) {
|
try {
|
||||||
log.error("发送钉钉消息失败", e);
|
dingTalkService.sendMsg("[时间:" + LocalDateTime.now() + "] 用户: " +
|
||||||
|
user.getEmail() + "签到成功,获得积分:" + gLaDOSResponse.getPoints());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送钉钉消息失败", e);
|
||||||
|
}
|
||||||
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(1).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return Boolean.TRUE;
|
||||||
|
} else {
|
||||||
|
log.info("签到异常, 签到消息:{}", gLaDOSResponse.getMessage());
|
||||||
|
sb.append(user.getEmail()).append("签到异常,消息:").append(gLaDOSResponse.getMessage());
|
||||||
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(0).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重复签到,表示当日签到成功
|
||||||
if (1 == gLaDOSResponse.getCode()) {
|
if (1 == gLaDOSResponse.getCode()) {
|
||||||
log.warn("签到失败,重复签到,用户:{}, 签到消息:{}", user.getEmail(), gLaDOSResponse.getMessage());
|
log.warn("签到失败,重复签到,用户:{}, 签到消息:{}", user.getEmail(), gLaDOSResponse.getMessage());
|
||||||
sb.append(user).append("签到失败,重复签到,用户:").append(user).append(",签到消息:").append(gLaDOSResponse.getMessage());
|
sb.append(user).append("签到失败,重复签到,用户:").append(user).append(",签到消息:").append(gLaDOSResponse.getMessage());
|
||||||
|
try {
|
||||||
|
dingTalkService.sendMsg("[时间:" + LocalDateTime.now() + "] 用户: " +
|
||||||
|
user.getEmail() + "当天已经签到成功!获得积分" + gLaDOSResponse.getList().get(0));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送钉钉消息失败", e);
|
||||||
|
}
|
||||||
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(1).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cookie过期
|
||||||
if (-2 == gLaDOSResponse.getCode()) {
|
if (-2 == gLaDOSResponse.getCode()) {
|
||||||
log.warn("签到失败,用户:{}, cookie过期:{}", user.getEmail(), gLaDOSResponse.getMessage());
|
log.warn("签到失败,用户:{}, cookie过期:{}", user.getEmail(), gLaDOSResponse.getMessage());
|
||||||
String message = "[时间:" + LocalDateTime.now() + "] 用户: " + user.getEmail() + ",签到消息: " + gLaDOSResponse.getMessage();
|
String message = "[时间:" + LocalDateTime.now() + "] 用户: " + user.getEmail() + ",签到消息: " + gLaDOSResponse.getMessage();
|
||||||
try {
|
try {
|
||||||
dingTalkService.sendScriptMsg(message);
|
dingTalkService.sendMsg(message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("发送钉钉消息失败", e);
|
log.error("发送钉钉消息失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 其余的异常情况
|
||||||
if (gLaDOSResponse.getCode() != 1) {
|
if (gLaDOSResponse.getCode() != 1) {
|
||||||
log.warn("签到异常,返回的消息:{}", gLaDOSResponse.getMessage());
|
log.warn("签到异常,返回的消息:{}", gLaDOSResponse.getMessage());
|
||||||
sb.append(user.getEmail()).append("签到异常,返回的消息:").append(gLaDOSResponse.getMessage()).append("\n");
|
sb.append(user.getEmail()).append("签到异常,返回的消息:").append(gLaDOSResponse.getMessage()).append("\n");
|
||||||
}
|
}
|
||||||
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(1).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(0).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
gladosMapper.insertScriptRunLog(build);
|
gladosMapper.insertScriptRunLog(build);
|
||||||
return;
|
return Boolean.FALSE;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
String mes = "[时间:" + LocalDateTime.now() + "] 用户: " + user.getEmail() + ",签到异常,请求结果为空。";
|
||||||
|
dingTalkService.sendMsg(mes);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送钉钉消息失败", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(0).response(response).user(user.getEmail()).userId(user.getId()).build();
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(0).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
gladosMapper.insertScriptRunLog(build);
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.jntyzx.entity.resp;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-05-14 14:38
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class JntyzxResponse<T> {
|
|
||||||
private Boolean success;
|
|
||||||
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
private Integer code;
|
|
||||||
|
|
||||||
private T result;
|
|
||||||
|
|
||||||
private Long timestamp;
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.jntyzx.entity.resp.query;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-05-14 14:37
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class QueryVenueResponse {
|
|
||||||
private List<TimeList> timeList;
|
|
||||||
|
|
||||||
private List<VenueList> venue;
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.jntyzx.entity.resp.query;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-05-14 14:45
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class SitePositionList {
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String ballCourtId;
|
|
||||||
|
|
||||||
private String sjName;
|
|
||||||
|
|
||||||
private String scheduleId;
|
|
||||||
|
|
||||||
private String placeName;
|
|
||||||
|
|
||||||
private Integer placeId;
|
|
||||||
|
|
||||||
private Integer type;
|
|
||||||
|
|
||||||
private String className;
|
|
||||||
|
|
||||||
private String classCode;
|
|
||||||
|
|
||||||
private BigDecimal money;
|
|
||||||
|
|
||||||
private String contacts;
|
|
||||||
|
|
||||||
private String contactNumber;
|
|
||||||
|
|
||||||
private String memberNumber;
|
|
||||||
|
|
||||||
private String appointments;
|
|
||||||
|
|
||||||
private String operator;
|
|
||||||
|
|
||||||
private String endTime;
|
|
||||||
|
|
||||||
private String beginTime;
|
|
||||||
|
|
||||||
private Integer specOneTimes;
|
|
||||||
|
|
||||||
private String ctypeCode;
|
|
||||||
|
|
||||||
private String isWhole;
|
|
||||||
|
|
||||||
private Long orderId;
|
|
||||||
|
|
||||||
private Integer votesnum;
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.jntyzx.entity.resp.query;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-05-14 14:39
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class TimeList {
|
|
||||||
private Long id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String beginTime;
|
|
||||||
|
|
||||||
private String endTime;
|
|
||||||
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
private String isenable;
|
|
||||||
|
|
||||||
private String operator;
|
|
||||||
|
|
||||||
private String createtime;
|
|
||||||
|
|
||||||
private String remarks;
|
|
||||||
|
|
||||||
private String default01;
|
|
||||||
private String default02;
|
|
||||||
private String default03;
|
|
||||||
private String votesnum;
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.jntyzx.entity.resp.query;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-05-14 14:39
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class VenueList {
|
|
||||||
|
|
||||||
private Integer placeId;
|
|
||||||
|
|
||||||
private String placeName;
|
|
||||||
|
|
||||||
private List<SitePositionList> sitePosition;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.jntyzx.service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-05-14 14:06
|
|
||||||
*/
|
|
||||||
public interface JntyzxService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询可用场地
|
|
||||||
*/
|
|
||||||
void queryAvailable() throws Exception;
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.jntyzx.service;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.xiang.xservice.basic.utils.HttpUtils;
|
|
||||||
import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService;
|
|
||||||
import com.xiang.xservice.application.script.xb.common.URLConstants;
|
|
||||||
import com.xiang.xservice.application.script.jntyzx.entity.resp.JntyzxResponse;
|
|
||||||
import com.xiang.xservice.application.script.jntyzx.entity.resp.query.QueryVenueResponse;
|
|
||||||
import com.xiang.xservice.application.script.jntyzx.entity.resp.query.SitePositionList;
|
|
||||||
import com.xiang.xservice.application.script.jntyzx.entity.resp.query.VenueList;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-05-14 14:07
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Slf4j
|
|
||||||
public class JntyzxServiceImpl implements JntyzxService{
|
|
||||||
|
|
||||||
|
|
||||||
private final DingTalkService dingTalkService;
|
|
||||||
|
|
||||||
@Value("${dingtalk.chatId}")
|
|
||||||
private String chatId;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void queryAvailable() throws Exception {
|
|
||||||
String url = URLConstants.JNTYZX_QUERY_TODAY_VENUE;
|
|
||||||
Map<String, String> header = Maps.newHashMap();
|
|
||||||
header.put("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NDcyMTAwNzQsInVzZXJuYW1lIjoid3hfb3Blbl9pZF9vMjFNWDR5N3doWENHanZVVEdQNkNUejJIYkQ4In0.0h_cAH_e5cCXDQlQN40jZDBgtfrzQWAmgl3YPQf0d-M");
|
|
||||||
String resp = null;
|
|
||||||
try {
|
|
||||||
resp = HttpUtils.doGet(url, header, null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("[doGet] 江南体育中心查询当天场地 请求失败, url:{}", url);
|
|
||||||
}
|
|
||||||
if (StringUtils.isEmpty(resp)) {
|
|
||||||
log.warn("[查询场地] 江南体育中心查询当天场地 请求结果为空, url:{}, resp:{}", url, resp);
|
|
||||||
}
|
|
||||||
JntyzxResponse response = JSONObject.parseObject(resp, JntyzxResponse.class);
|
|
||||||
String message = "";
|
|
||||||
if (Objects.nonNull(response)) {
|
|
||||||
if (response.getSuccess()) {
|
|
||||||
log.info("[查询场地] 江南体育中心查询当天场地 请求地址:{}, 请求结果:{}", url, resp);
|
|
||||||
JSONObject object = (JSONObject) response.getResult();
|
|
||||||
if (Objects.nonNull(object)) {
|
|
||||||
QueryVenueResponse result = object.toJavaObject(QueryVenueResponse.class);
|
|
||||||
if (Objects.nonNull(result)) {
|
|
||||||
List<VenueList> venueLists = result.getVenue();
|
|
||||||
if (!CollectionUtils.isEmpty(venueLists)) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (VenueList venue : venueLists) {
|
|
||||||
List<SitePositionList> positionList = venue.getSitePosition();
|
|
||||||
positionList = positionList.stream().filter(this::filterTime).collect(Collectors.toList());
|
|
||||||
for (SitePositionList sitePositionList : positionList) {
|
|
||||||
sb.append(venue.getPlaceName()).append(":").append(sitePositionList.getSjName()).append(":预定人:").append(sitePositionList.getContacts()).append(",电话:").append(sitePositionList.getContactNumber()).append("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
message = sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(message)) {
|
|
||||||
dingTalkService.sendChatMessage(chatId, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private Boolean filterTime(SitePositionList sitePositionList) {
|
|
||||||
if (StringUtils.equals("18:00-19:00", sitePositionList.getSjName())) {
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
if (StringUtils.equals("19:00-20:00", sitePositionList.getSjName())) {
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
if (StringUtils.equals("20:00-21:00", sitePositionList.getSjName())) {
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
if (StringUtils.equals("21:00-22:00", sitePositionList.getSjName())) {
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.data.common.constants;
|
|
||||||
|
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
public class RedisConstants {
|
|
||||||
|
|
||||||
public static final String MSG_SEND_REDIS_KEY = "stock:msg:send:";
|
|
||||||
|
|
||||||
|
|
||||||
public static String getDate4Key() {
|
|
||||||
return DateUtils.getDateFromDate(LocalDate.now(), "yyyyMMdd");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.data.common.constants;
|
|
||||||
|
|
||||||
public class UrlConstants {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新浪财经 股票数据拉取
|
|
||||||
*/
|
|
||||||
public static final String SINA_STOCK_DATA_PULL_URL = "https://hq.sinajs.cn/list=";
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.data.entity;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class StockSinaDataRecordDO {
|
|
||||||
/**
|
|
||||||
* 主键id
|
|
||||||
*/
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 股票名称
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 今开价格
|
|
||||||
*/
|
|
||||||
private BigDecimal jkPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 昨收价格
|
|
||||||
*/
|
|
||||||
private BigDecimal zsPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 现在价格
|
|
||||||
*/
|
|
||||||
private BigDecimal xjPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 最高价格
|
|
||||||
*/
|
|
||||||
private BigDecimal zgPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 最低价格
|
|
||||||
*/
|
|
||||||
private BigDecimal zdPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 总手数量
|
|
||||||
*/
|
|
||||||
private String zsNum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 总交易金额
|
|
||||||
*/
|
|
||||||
private BigDecimal price;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.data.mapper;
|
|
||||||
|
|
||||||
import com.xiang.xservice.application.script.stock.data.entity.StockSinaDataRecordDO;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
@Mapper
|
|
||||||
public interface StockSinaDataRecordPullMapper {
|
|
||||||
|
|
||||||
int batchInsert(@Param("list") List<StockSinaDataRecordDO> list);
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.data.schedule;
|
|
||||||
|
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
|
||||||
import com.xiang.xservice.cache.service.IRedisService;
|
|
||||||
import com.xiang.xservice.application.script.stock.data.common.constants.RedisConstants;
|
|
||||||
import com.xiang.xservice.application.script.stock.data.entity.StockSinaDataRecordDO;
|
|
||||||
import com.xiang.xservice.application.script.stock.data.service.DingTalkScriptStockService;
|
|
||||||
import com.xiang.xservice.application.script.stock.data.service.IStockDataService;
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.entity.StockGnshyxRecordDataDO;
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.service.ICloudRecordDataService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.DayOfWeek;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class DataMsgSendJob {
|
|
||||||
|
|
||||||
private final ICloudRecordDataService cloudRecordDataService;
|
|
||||||
private final IStockDataService stockDataService;
|
|
||||||
private final DingTalkScriptStockService dingTalkScriptStockService;
|
|
||||||
private final IRedisService redisService;
|
|
||||||
|
|
||||||
@Scheduled(cron = "0/10 * * * * ?")
|
|
||||||
public void stockGetTargetMsgSend() {
|
|
||||||
if (DateUtils.validWeekTime()) return;
|
|
||||||
|
|
||||||
StringBuilder msg = new StringBuilder();
|
|
||||||
List<StockGnshyxRecordDataDO> list = cloudRecordDataService.getList();
|
|
||||||
for (StockGnshyxRecordDataDO stockGnshyxRecordDataDO : list) {
|
|
||||||
String stockCode = stockGnshyxRecordDataDO.getStockCode();
|
|
||||||
String[] values = stockCode.split("\\.");
|
|
||||||
String c1 = values[1].toLowerCase();
|
|
||||||
String c2 = values[0];
|
|
||||||
String code = c1 + c2;
|
|
||||||
String resp = stockDataService.getStockDataFromHttp(code);
|
|
||||||
StockSinaDataRecordDO recordDO = stockDataService.buildRecordDO(resp);
|
|
||||||
if (Objects.nonNull(recordDO)) {
|
|
||||||
Object o = redisService.hGet(RedisConstants.MSG_SEND_REDIS_KEY + RedisConstants.getDate4Key(), stockGnshyxRecordDataDO.getStockCode());
|
|
||||||
if (Objects.isNull(o)) {
|
|
||||||
if (recordDO.getXjPrice().compareTo(stockGnshyxRecordDataDO.getAttentionPrice()) > 0) {
|
|
||||||
msg.append("股票代码:")
|
|
||||||
.append(stockGnshyxRecordDataDO.getStockCode())
|
|
||||||
.append(",名称:")
|
|
||||||
.append(stockGnshyxRecordDataDO.getStockName())
|
|
||||||
.append(",达到预期的价格:")
|
|
||||||
.append(stockGnshyxRecordDataDO.getAttentionPrice())
|
|
||||||
.append(",现在价格:").append(recordDO.getXjPrice())
|
|
||||||
.append("\n");
|
|
||||||
}
|
|
||||||
if (recordDO.getXjPrice().compareTo(stockGnshyxRecordDataDO.getStopPrice()) < 0) {
|
|
||||||
msg.append("股票代码:")
|
|
||||||
.append(stockGnshyxRecordDataDO.getStockCode())
|
|
||||||
.append(",名称:")
|
|
||||||
.append(stockGnshyxRecordDataDO.getStockName())
|
|
||||||
.append("达到止损的价格:")
|
|
||||||
.append(stockGnshyxRecordDataDO.getStopPrice())
|
|
||||||
.append(",现在价格:").append(recordDO.getXjPrice())
|
|
||||||
.append("\n");
|
|
||||||
}
|
|
||||||
redisService.hSet(RedisConstants.MSG_SEND_REDIS_KEY + RedisConstants.getDate4Key(), stockGnshyxRecordDataDO.getStockCode(), "true");
|
|
||||||
redisService.expire("xservice-script-center", RedisConstants.MSG_SEND_REDIS_KEY + RedisConstants.getDate4Key(), 10, TimeUnit.DAYS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(msg)) {
|
|
||||||
log.info("发送钉钉消息:{}", msg);
|
|
||||||
dingTalkScriptStockService.sendScriptMsg(msg.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean validTime() {
|
|
||||||
if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) ||
|
|
||||||
Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) {
|
|
||||||
log.info("当前时间为:{}", LocalDateTime.now());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LocalTime now = LocalTime.now();
|
|
||||||
|
|
||||||
boolean inMorning = now.isAfter(LocalTime.of(9, 29)) && now.isBefore(LocalTime.of(11, 31));
|
|
||||||
boolean inAfternoon = now.isAfter(LocalTime.of(12, 59)) && now.isBefore(LocalTime.of(15, 1));
|
|
||||||
if (!inAfternoon && !inMorning) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.data.schedule;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
|
||||||
import com.xiang.xservice.cache.service.IRedisService;
|
|
||||||
import com.xiang.xservice.common.entity.DayResult;
|
|
||||||
import com.xiang.xservice.common.enums.RedisConstant;
|
|
||||||
import com.xiang.xservice.application.script.stock.data.entity.StockSinaDataRecordDO;
|
|
||||||
import com.xiang.xservice.application.script.stock.data.service.IStockDataService;
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.entity.StockGnshyxRecordDataDO;
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.service.ICloudRecordDataService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class StockDataPullJob {
|
|
||||||
|
|
||||||
private final ICloudRecordDataService cloudRecordDataService;
|
|
||||||
private final IStockDataService stockDataService;
|
|
||||||
private final IRedisService redisService;
|
|
||||||
private static final Integer BATCH_SIZE = 500;
|
|
||||||
|
|
||||||
@Scheduled(cron = "*/1 * * * * ?")
|
|
||||||
public void sinaDataPullJob() {
|
|
||||||
if (DateUtils.validWeekTime()) return;
|
|
||||||
LocalDate now = LocalDate.now();
|
|
||||||
String dayResult = (String) redisService.hGet(RedisConstant.DAY_INFO_PREFIX_KEY, DateUtils.getDateFromDate(now));
|
|
||||||
if (com.xiang.xservice.common.utils.DateUtils.validHoliday(JSON.parseObject(dayResult, DayResult.class))) return;
|
|
||||||
log.info(">>>>>>>>>>>>>>>>>新浪财经数据拉取开始>>>>>>>>>>>>>>>>>");
|
|
||||||
List<StockGnshyxRecordDataDO> dataList = cloudRecordDataService.getList();
|
|
||||||
List<StockSinaDataRecordDO> result = Lists.newArrayList();
|
|
||||||
for (StockGnshyxRecordDataDO stockGnshyxRecordDataDO : dataList) {
|
|
||||||
String stockCode = stockGnshyxRecordDataDO.getStockCode();
|
|
||||||
String[] values = stockCode.split("\\.");
|
|
||||||
String c1 = values[1].toLowerCase();
|
|
||||||
String c2 = values[0];
|
|
||||||
String code = c1 + c2;
|
|
||||||
String resp = stockDataService.getStockDataFromHttp(code);
|
|
||||||
StockSinaDataRecordDO stockSinaDataRecordDO = stockDataService.buildRecordDO(resp);
|
|
||||||
if (Objects.nonNull(stockSinaDataRecordDO)) {
|
|
||||||
result.add(stockSinaDataRecordDO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(result)) {
|
|
||||||
if (BATCH_SIZE > result.size()) {
|
|
||||||
Lists.partition(result, BATCH_SIZE).forEach(stockDataService::insertData2DB);
|
|
||||||
} else {
|
|
||||||
stockDataService.insertData2DB(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.info(">>>>>>>>>>>>>>>>>新浪财经数据拉取结束>>>>>>>>>>>>>>>>>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.data.service;
|
|
||||||
|
|
||||||
import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService;
|
|
||||||
import com.xiang.xservice.config.DingTalkRobotXbConfig;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-08-07 10:30
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class DingTalkScriptStockService {
|
|
||||||
|
|
||||||
private final DingTalkService dingTalkService;
|
|
||||||
private final DingTalkRobotXbConfig dingTalkRobotXbConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送脚本消息
|
|
||||||
* @param msg 消息
|
|
||||||
*/
|
|
||||||
public void sendScriptMsg(String msg) {
|
|
||||||
try {
|
|
||||||
dingTalkService.sendRobotMessage(dingTalkRobotXbConfig.getSecret(), dingTalkRobotXbConfig.getToken(), dingTalkRobotXbConfig.getUsers(), msg);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("信息发送异常, 信息:{}", msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.data.service;
|
|
||||||
|
|
||||||
import com.xiang.xservice.application.script.stock.data.entity.StockSinaDataRecordDO;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface IStockDataService {
|
|
||||||
|
|
||||||
String getStockDataFromHttp(String stockCode);
|
|
||||||
|
|
||||||
boolean insertData2DB(List<StockSinaDataRecordDO> stockSinaDataRecordDOs);
|
|
||||||
|
|
||||||
StockSinaDataRecordDO buildRecordDO(String resp);
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.data.service;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.xiang.xservice.basic.exception.BusinessException;
|
|
||||||
import com.xiang.xservice.basic.utils.HttpUtils;
|
|
||||||
import com.xiang.xservice.application.script.stock.data.common.constants.UrlConstants;
|
|
||||||
import com.xiang.xservice.application.script.stock.data.entity.StockSinaDataRecordDO;
|
|
||||||
import com.xiang.xservice.application.script.stock.data.mapper.StockSinaDataRecordPullMapper;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class StockDataServiceImpl implements IStockDataService{
|
|
||||||
|
|
||||||
private final StockSinaDataRecordPullMapper stockSinaDataRecordPullMapper;
|
|
||||||
|
|
||||||
//文灿股份,22.210,22.240,22.070,22.310,21.960,22.070,22.080,5173623, 114323642.000, 2900, 22.070,7600, 22.060,4600, 22.050,2700, 22.040,4700, 22.030,600, 22.080,29800,22.090,3800, 22.100,3000, 22.120,800, 22.130,2025-09-19,15:00:02,00
|
|
||||||
//浦发银行,12.690,12.750,12.810,12.900,12.560,12.800,12.810,79638295,1015780801.000,78500, 12.800,88400, 12.790,151900,12.780,42900,12.770,71700,12.760,841170, 12.810,1100, 12.830,48100,12.860,128600,12.870,116600,12.880,2025-09-19,15:00:03,00,
|
|
||||||
//平安银行,11.410,11.410,11.450,11.510,11.370,11.450,11.460,83465123,955004096.910, 103813,11.450,321000,11.440,198700,11.430,216100,11.420,553000,11.410,15300,11.460,27500,11.470,28400,11.480,175335,11.490,893111,11.500,2025-09-19,15:00:00,00
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStockDataFromHttp(String stockCode) {
|
|
||||||
String url = UrlConstants.SINA_STOCK_DATA_PULL_URL + stockCode;
|
|
||||||
|
|
||||||
Map<String, String> headers = Maps.newHashMap();
|
|
||||||
headers.put("Referer", "https://finance.sina.com.cn");
|
|
||||||
headers.put("User-Agent", "Mozilla/5.0");
|
|
||||||
String resp = HttpUtils.doGet(url, headers, null);
|
|
||||||
if (StringUtils.isBlank(resp)) {
|
|
||||||
log.error("http请求拉取新浪财经股票数据失败, 股票代码:{}, 响应结果:{}", stockCode, resp);
|
|
||||||
throw new BusinessException("拉取数据失败");
|
|
||||||
}
|
|
||||||
return resp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean insertData2DB(List<StockSinaDataRecordDO> stockSinaDataRecordDOs) {
|
|
||||||
return stockSinaDataRecordPullMapper.batchInsert(stockSinaDataRecordDOs) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StockSinaDataRecordDO buildRecordDO(String resp) {
|
|
||||||
if (resp.contains("=")) {
|
|
||||||
resp = resp.split("=")[1].replace("\"", "").replace(";", "");
|
|
||||||
if (StringUtils.equals(resp, "FAILED")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String[] values = resp.split(",");
|
|
||||||
|
|
||||||
// 股票名称
|
|
||||||
String mc = values[0];
|
|
||||||
// 今开价格
|
|
||||||
String jk = values[1];
|
|
||||||
// 昨收价格
|
|
||||||
String zs = values[2];
|
|
||||||
// 现在价格
|
|
||||||
String xj = values[3];
|
|
||||||
// 最高价格
|
|
||||||
String zg = values[4];
|
|
||||||
// 最低价格
|
|
||||||
String zd = values[5];
|
|
||||||
// 总手
|
|
||||||
String zongshou = values[8];
|
|
||||||
// 金额
|
|
||||||
String je = values[9];
|
|
||||||
// 时间
|
|
||||||
String sj = values[values.length - 3];
|
|
||||||
// 日期
|
|
||||||
String rq = values[values.length - 4];
|
|
||||||
|
|
||||||
BigDecimal change = (new BigDecimal(xj).subtract(new BigDecimal(zs))).divide(new BigDecimal(zs), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
|
|
||||||
log.info("股票名称:{}, 当前价格:{}, 昨收价格:{}, 涨跌幅:{}%", mc, xj, zs, change);
|
|
||||||
|
|
||||||
StockSinaDataRecordDO stockSinaDataRecordDO = new StockSinaDataRecordDO();
|
|
||||||
stockSinaDataRecordDO.setName(mc);
|
|
||||||
stockSinaDataRecordDO.setJkPrice(new BigDecimal(jk));
|
|
||||||
stockSinaDataRecordDO.setZsPrice(new BigDecimal(zs));
|
|
||||||
stockSinaDataRecordDO.setXjPrice(new BigDecimal(xj));
|
|
||||||
stockSinaDataRecordDO.setZgPrice(new BigDecimal(zg));
|
|
||||||
stockSinaDataRecordDO.setZdPrice(new BigDecimal(zd));
|
|
||||||
stockSinaDataRecordDO.setZsNum(zs);
|
|
||||||
stockSinaDataRecordDO.setPrice(new BigDecimal(je));
|
|
||||||
stockSinaDataRecordDO.setUpdateTime(LocalDateTime.now());
|
|
||||||
return stockSinaDataRecordDO;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.gnshyx.common.constants;
|
|
||||||
|
|
||||||
public class UrlConstant {
|
|
||||||
|
|
||||||
public final static String BASE_URL = "https://gnshyx.cloudgn.com";
|
|
||||||
|
|
||||||
public final static String URL_PREFIX = "/prod-api";
|
|
||||||
|
|
||||||
public final static String LAST_PRICE = BASE_URL + "/price/lastprice";
|
|
||||||
|
|
||||||
public final static String LAST_LIST = BASE_URL + URL_PREFIX + "/public/stockDailySelection/listLast";
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.gnshyx.entity;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class StockGnshyxRecordDataDO {
|
|
||||||
/**
|
|
||||||
* id
|
|
||||||
*/
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 名称
|
|
||||||
*/
|
|
||||||
private String symbolName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 股票名称
|
|
||||||
*/
|
|
||||||
private String stockName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 目标价格
|
|
||||||
*/
|
|
||||||
private BigDecimal attentionPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关注价格低位
|
|
||||||
*/
|
|
||||||
private BigDecimal targetPriceLow;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关注价格高位
|
|
||||||
*/
|
|
||||||
private BigDecimal targetPriceHigh;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 止损价位
|
|
||||||
*/
|
|
||||||
private BigDecimal stopPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统每日选择id
|
|
||||||
*/
|
|
||||||
private Long stockDailySelectionId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 股票代码
|
|
||||||
*/
|
|
||||||
private String stockCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime selectionTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* maximum_increase
|
|
||||||
*/
|
|
||||||
private String maximumIncrease;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* maximum_increase_seven
|
|
||||||
*/
|
|
||||||
private String maximumIncreaseSeven;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.gnshyx.entity.resp;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class GnshyxBaseResp {
|
|
||||||
|
|
||||||
private Integer code;
|
|
||||||
|
|
||||||
private String msg;
|
|
||||||
|
|
||||||
@JSONField(name = "server_time")
|
|
||||||
private Long serverTime;
|
|
||||||
|
|
||||||
private String data;
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.gnshyx.entity.resp;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class ListLastDataResp {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 选择id
|
|
||||||
*/
|
|
||||||
private Long stockDailySelectionId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 股票代码
|
|
||||||
*/
|
|
||||||
private String stockCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 股票名称
|
|
||||||
*/
|
|
||||||
private String stockName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 标识名称
|
|
||||||
*/
|
|
||||||
private String symbolName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 目标价格
|
|
||||||
*/
|
|
||||||
private BigDecimal attentionPrice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关注价格低位
|
|
||||||
*/
|
|
||||||
private BigDecimal targetPriceLow;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关注价格高位
|
|
||||||
*/
|
|
||||||
private BigDecimal targetPriceHigh;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 止损价格
|
|
||||||
*/
|
|
||||||
private BigDecimal stopPrice;
|
|
||||||
|
|
||||||
|
|
||||||
private String maximumIncrease;
|
|
||||||
|
|
||||||
private String maximumIncreaseSeven;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成时间
|
|
||||||
*/
|
|
||||||
private String selectionTime;
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.gnshyx.enums;
|
|
||||||
|
|
||||||
public enum GnshyxUrlEnum {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.gnshyx.mapper;
|
|
||||||
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.entity.StockGnshyxRecordDataDO;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
@Mapper
|
|
||||||
public interface StockGnshyxRecordDataMapper {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量新增
|
|
||||||
* @param entities
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int batchInsertRecord(@Param("list") List<StockGnshyxRecordDataDO> entities);
|
|
||||||
|
|
||||||
List<StockGnshyxRecordDataDO> getList();
|
|
||||||
|
|
||||||
|
|
||||||
int insert(StockGnshyxRecordDataDO entity);
|
|
||||||
|
|
||||||
StockGnshyxRecordDataDO getByStockCode(@Param("stockCode") String stockCode);
|
|
||||||
|
|
||||||
int update(StockGnshyxRecordDataDO entity);
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.gnshyx.schedule;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
|
||||||
import com.xiang.xservice.basic.utils.HttpUtils;
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.common.constants.UrlConstant;
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.entity.StockGnshyxRecordDataDO;
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.entity.resp.ListLastDataResp;
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.service.ICloudRecordDataService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Component
|
|
||||||
public class CloudRecordDataJob {
|
|
||||||
|
|
||||||
private final ICloudRecordDataService cloudRecordDataService;
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 30 9,14 * * ?")
|
|
||||||
public void gnshyxRecordDataPullJob() {
|
|
||||||
log.info("<<<<<gnshyx数据拉取定时任务开始>>>>>, 时间戳:{}", System.currentTimeMillis());
|
|
||||||
|
|
||||||
String resp = HttpUtils.doGet(UrlConstant.LAST_LIST, null, null);
|
|
||||||
if (StringUtils.isBlank(resp)) {
|
|
||||||
log.error("{}请求失败,响应结果为空, time:{}", UrlConstant.LAST_LIST, System.currentTimeMillis());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(resp);
|
|
||||||
Integer code = (Integer) jsonObject.get("code");
|
|
||||||
if (200 == code) {
|
|
||||||
String data = JSON.toJSONString(jsonObject.get("data"));
|
|
||||||
log.info("查询到的数据结果:{}", data);
|
|
||||||
List<ListLastDataResp> dataRespList = JSON.parseArray(data, ListLastDataResp.class);
|
|
||||||
if (CollectionUtils.isNotEmpty(dataRespList)) {
|
|
||||||
for (ListLastDataResp listLastDataResp : dataRespList) {
|
|
||||||
StockGnshyxRecordDataDO stock = cloudRecordDataService.getByStockCode(listLastDataResp.getStockCode());
|
|
||||||
if (Objects.nonNull(stock)) {
|
|
||||||
stock.setSymbolName(listLastDataResp.getSymbolName());
|
|
||||||
stock.setStockName(listLastDataResp.getStockName());
|
|
||||||
stock.setAttentionPrice(listLastDataResp.getAttentionPrice());
|
|
||||||
stock.setTargetPriceLow(listLastDataResp.getTargetPriceLow());
|
|
||||||
stock.setTargetPriceHigh(listLastDataResp.getTargetPriceHigh());
|
|
||||||
stock.setStopPrice(listLastDataResp.getStopPrice());
|
|
||||||
stock.setStockDailySelectionId(listLastDataResp.getStockDailySelectionId());
|
|
||||||
stock.setStockCode(listLastDataResp.getStockCode());
|
|
||||||
stock.setSelectionTime(DateUtils.getDateTimeFromStr(listLastDataResp.getSelectionTime()));
|
|
||||||
stock.setMaximumIncrease(listLastDataResp.getMaximumIncrease());
|
|
||||||
stock.setMaximumIncreaseSeven(listLastDataResp.getMaximumIncreaseSeven());
|
|
||||||
stock.setCreateTime(LocalDateTime.now());
|
|
||||||
cloudRecordDataService.updateRecord(stock);
|
|
||||||
} else {
|
|
||||||
StockGnshyxRecordDataDO stockGnshyxRecordDataDO = new StockGnshyxRecordDataDO();
|
|
||||||
stockGnshyxRecordDataDO.setSymbolName(listLastDataResp.getSymbolName());
|
|
||||||
stockGnshyxRecordDataDO.setStockName(listLastDataResp.getStockName());
|
|
||||||
stockGnshyxRecordDataDO.setAttentionPrice(listLastDataResp.getAttentionPrice());
|
|
||||||
stockGnshyxRecordDataDO.setTargetPriceLow(listLastDataResp.getTargetPriceLow());
|
|
||||||
stockGnshyxRecordDataDO.setTargetPriceHigh(listLastDataResp.getTargetPriceHigh());
|
|
||||||
stockGnshyxRecordDataDO.setStopPrice(listLastDataResp.getStopPrice());
|
|
||||||
stockGnshyxRecordDataDO.setStockDailySelectionId(listLastDataResp.getStockDailySelectionId());
|
|
||||||
stockGnshyxRecordDataDO.setStockCode(listLastDataResp.getStockCode());
|
|
||||||
stockGnshyxRecordDataDO.setSelectionTime(DateUtils.getDateTimeFromStr(listLastDataResp.getSelectionTime()));
|
|
||||||
stockGnshyxRecordDataDO.setMaximumIncrease(listLastDataResp.getMaximumIncrease());
|
|
||||||
stockGnshyxRecordDataDO.setMaximumIncreaseSeven(listLastDataResp.getMaximumIncreaseSeven());
|
|
||||||
stockGnshyxRecordDataDO.setCreateTime(LocalDateTime.now());
|
|
||||||
cloudRecordDataService.insertRecord(stockGnshyxRecordDataDO);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.gnshyx.service;
|
|
||||||
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.entity.StockGnshyxRecordDataDO;
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.mapper.StockGnshyxRecordDataMapper;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class CloudRecordDataServiceImpl implements ICloudRecordDataService {
|
|
||||||
private final StockGnshyxRecordDataMapper stockGnshyxRecordDataMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean insertRecord(StockGnshyxRecordDataDO entity) {
|
|
||||||
return stockGnshyxRecordDataMapper.insert(entity) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean batchInsertRecord(List<StockGnshyxRecordDataDO> list) {
|
|
||||||
return stockGnshyxRecordDataMapper.batchInsertRecord(list) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<StockGnshyxRecordDataDO> getList() {
|
|
||||||
return stockGnshyxRecordDataMapper.getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean updateRecord(StockGnshyxRecordDataDO entity) {
|
|
||||||
return stockGnshyxRecordDataMapper.update(entity) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StockGnshyxRecordDataDO getByStockCode(String stockCode) {
|
|
||||||
return stockGnshyxRecordDataMapper.getByStockCode(stockCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.stock.gnshyx.service;
|
|
||||||
|
|
||||||
import com.xiang.xservice.application.script.stock.gnshyx.entity.StockGnshyxRecordDataDO;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface ICloudRecordDataService {
|
|
||||||
|
|
||||||
Boolean insertRecord(StockGnshyxRecordDataDO entity);
|
|
||||||
|
|
||||||
Boolean batchInsertRecord(List<StockGnshyxRecordDataDO> list);
|
|
||||||
|
|
||||||
List<StockGnshyxRecordDataDO> getList();
|
|
||||||
|
|
||||||
Boolean updateRecord(StockGnshyxRecordDataDO entity);
|
|
||||||
|
|
||||||
StockGnshyxRecordDataDO getByStockCode(String stockCode);
|
|
||||||
}
|
|
||||||
@@ -2,12 +2,12 @@ package com.xiang.xservice.application.script.xb.schedule.xb;
|
|||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
|
||||||
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundCount;
|
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundCount;
|
||||||
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
|
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
|
||||||
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
|
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
|
||||||
import com.xiang.xservice.application.script.xb.service.DingTalkRobotService;
|
|
||||||
import com.xiang.xservice.application.script.xb.service.FundService;
|
import com.xiang.xservice.application.script.xb.service.FundService;
|
||||||
|
import com.xiang.xservice.basic.utils.DateUtils;
|
||||||
|
import com.xiang.xservice.common.service.dingTalk.StockDingTalkFactory;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
@@ -39,7 +39,7 @@ import java.util.stream.Collectors;
|
|||||||
public class FundCountJob {
|
public class FundCountJob {
|
||||||
|
|
||||||
private final FundService fundService;
|
private final FundService fundService;
|
||||||
private final DingTalkRobotService dingTalkService;
|
private final StockDingTalkFactory dingTalkService;
|
||||||
@Scheduled(cron = "0 0 22 * * ?")
|
@Scheduled(cron = "0 0 22 * * ?")
|
||||||
public void countFundJob() {
|
public void countFundJob() {
|
||||||
// 周六周日过滤
|
// 周六周日过滤
|
||||||
@@ -97,7 +97,7 @@ public class FundCountJob {
|
|||||||
sb.append("【").append(fundCounts.get(0).getName()).append("】本周平均涨跌幅为:").append(avg).append("\n");
|
sb.append("【").append(fundCounts.get(0).getName()).append("】本周平均涨跌幅为:").append(avg).append("\n");
|
||||||
});
|
});
|
||||||
if (StringUtils.isNotBlank(sb)) {
|
if (StringUtils.isNotBlank(sb)) {
|
||||||
dingTalkService.sendXbMsg(sb.toString());
|
dingTalkService.sendMsg(sb.toString());
|
||||||
}
|
}
|
||||||
log.info("==========================[基金统计] 基金本周涨跌幅消息发送定时任务结束!==========================");
|
log.info("==========================[基金统计] 基金本周涨跌幅消息发送定时任务结束!==========================");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,17 @@
|
|||||||
package com.xiang.xservice.application.script.xb.schedule.xb;
|
package com.xiang.xservice.application.script.xb.schedule.xb;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.xiang.xservice.basic.config.MyThreadFactory;
|
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
|
||||||
import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService;
|
|
||||||
import com.xiang.xservice.cache.service.IRedisService;
|
|
||||||
import com.xiang.xservice.common.entity.DayResult;
|
|
||||||
import com.xiang.xservice.common.enums.RedisConstant;
|
|
||||||
import com.xiang.xservice.application.script.xb.entity.pojo.xb.FundMessage;
|
import com.xiang.xservice.application.script.xb.entity.pojo.xb.FundMessage;
|
||||||
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
|
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
|
||||||
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundInfo;
|
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundInfo;
|
||||||
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
|
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
|
||||||
import com.xiang.xservice.application.script.xb.repository.XBFundMapper;
|
import com.xiang.xservice.application.script.xb.repository.XBFundMapper;
|
||||||
import com.xiang.xservice.application.script.xb.service.FundService;
|
import com.xiang.xservice.application.script.xb.service.FundService;
|
||||||
|
import com.xiang.xservice.basic.config.MyThreadFactory;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -31,7 +24,6 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@@ -50,9 +42,7 @@ import java.util.stream.Collectors;
|
|||||||
public class FundInfoQueryJob {
|
public class FundInfoQueryJob {
|
||||||
|
|
||||||
private final FundService fundService;
|
private final FundService fundService;
|
||||||
private final DingTalkService dingTalkService;
|
|
||||||
private final XBFundMapper xbFundMapper;
|
private final XBFundMapper xbFundMapper;
|
||||||
private final IRedisService redisService;
|
|
||||||
private final ExecutorService es =
|
private final ExecutorService es =
|
||||||
new ThreadPoolExecutor(
|
new ThreadPoolExecutor(
|
||||||
10,
|
10,
|
||||||
@@ -64,42 +54,7 @@ public class FundInfoQueryJob {
|
|||||||
new ThreadPoolExecutor.AbortPolicy());
|
new ThreadPoolExecutor.AbortPolicy());
|
||||||
@Value("${xiaobei.codeArr}")
|
@Value("${xiaobei.codeArr}")
|
||||||
private String codeArr;
|
private String codeArr;
|
||||||
@Value("${dingtalk.chatId}")
|
|
||||||
private String chatId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 基金涨跌幅5分钟超过2%重点通知
|
|
||||||
*/
|
|
||||||
@Scheduled(cron = "0 0/5 9,10,11,13,14,15 * * ? ")
|
|
||||||
public void queryFundEmergencyJob() throws Exception {
|
|
||||||
// 周六周日过滤
|
|
||||||
if (DateUtils.validWeekTime()) return;
|
|
||||||
LocalDate now = LocalDate.now();
|
|
||||||
String dayResult = (String) redisService.hGet(RedisConstant.DAY_INFO_PREFIX_KEY, DateUtils.getDateFromDate(now));
|
|
||||||
if (com.xiang.xservice.common.utils.DateUtils.validHoliday(JSON.parseObject(dayResult, DayResult.class))) return;
|
|
||||||
|
|
||||||
List<com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo> fundInfos = xbFundMapper.queryListIn2Min();
|
|
||||||
if (CollectionUtils.isEmpty(fundInfos)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Map<String, List<com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo>> map = fundInfos.stream().collect(Collectors.groupingBy(com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo::getCode));
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
map.entrySet().parallelStream().forEach(entry -> {
|
|
||||||
List<com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo> infos = entry.getValue();
|
|
||||||
BigDecimal sum = new BigDecimal("0");
|
|
||||||
for (int i = 0; i < infos.size() - 1; i++) {
|
|
||||||
BigDecimal subtract = new BigDecimal(infos.get(i + 1).getChange()).subtract(new BigDecimal(infos.get(i).getChange()));
|
|
||||||
sum = sum.add(subtract);
|
|
||||||
}
|
|
||||||
BigDecimal avg = sum.divide(new BigDecimal(String.valueOf(infos.size())), 2, RoundingMode.HALF_UP);
|
|
||||||
if (avg.abs().compareTo(new BigDecimal("2")) > 0) {
|
|
||||||
sb.append("基金").append(entry.getValue().get(0).getName()).append("5分钟的平均涨跌幅超过2%,涨跌幅达到").append(avg).append("\n");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (StringUtils.isNotBlank(sb)) {
|
|
||||||
dingTalkService.sendChatMessage(chatId, sb.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基金每分钟涨幅记录
|
* 基金每分钟涨幅记录
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package com.xiang.xservice.application.script.xb.schedule.xb;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
|
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
|
||||||
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
|
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
|
||||||
import com.xiang.xservice.application.script.xb.service.DingTalkRobotService;
|
|
||||||
import com.xiang.xservice.application.script.xb.service.FundService;
|
import com.xiang.xservice.application.script.xb.service.FundService;
|
||||||
|
import com.xiang.xservice.common.service.dingTalk.StockDingTalkFactory;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
@@ -38,7 +38,7 @@ import java.util.stream.Collectors;
|
|||||||
public class FundMsgReportJob {
|
public class FundMsgReportJob {
|
||||||
|
|
||||||
private final FundService fundService;
|
private final FundService fundService;
|
||||||
private final DingTalkRobotService dingTalkService;
|
private final StockDingTalkFactory dingTalkService;
|
||||||
private static final Integer TYPE_A = 1;
|
private static final Integer TYPE_A = 1;
|
||||||
private static final Integer TYPE_M = 3;
|
private static final Integer TYPE_M = 3;
|
||||||
private static final Integer TYPE_G = 2;
|
private static final Integer TYPE_G = 2;
|
||||||
@@ -68,7 +68,7 @@ public class FundMsgReportJob {
|
|||||||
log.info("http查询基金信息:{}", JSON.toJSONString(funds));
|
log.info("http查询基金信息:{}", JSON.toJSONString(funds));
|
||||||
StringBuilder msg = new StringBuilder(date).append("===》A股基金变化通知:\n");
|
StringBuilder msg = new StringBuilder(date).append("===》A股基金变化通知:\n");
|
||||||
buildMsg(funds, fundMap, msg);
|
buildMsg(funds, fundMap, msg);
|
||||||
dingTalkService.sendXbMsg(msg.toString());
|
dingTalkService.sendMsg(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 1,31 9,10,11,13,14,15 * * ?")
|
@Scheduled(cron = "0 1,31 9,10,11,13,14,15 * * ?")
|
||||||
@@ -95,7 +95,7 @@ public class FundMsgReportJob {
|
|||||||
log.info("http查询港股基金信息:{}", JSON.toJSONString(funds));
|
log.info("http查询港股基金信息:{}", JSON.toJSONString(funds));
|
||||||
StringBuilder msg = new StringBuilder(date).append("===》港股基金变化通知:\n");
|
StringBuilder msg = new StringBuilder(date).append("===》港股基金变化通知:\n");
|
||||||
buildMsg(funds, fundMap, msg);
|
buildMsg(funds, fundMap, msg);
|
||||||
dingTalkService.sendXbMsg(msg.toString());
|
dingTalkService.sendMsg(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 9 * * ?")
|
@Scheduled(cron = "0 0 9 * * ?")
|
||||||
@@ -122,7 +122,7 @@ public class FundMsgReportJob {
|
|||||||
log.info("http查询美股基金信息:{}", JSON.toJSONString(funds));
|
log.info("http查询美股基金信息:{}", JSON.toJSONString(funds));
|
||||||
StringBuilder msg = new StringBuilder(date).append("===》美股基金变化通知:\n");
|
StringBuilder msg = new StringBuilder(date).append("===》美股基金变化通知:\n");
|
||||||
buildMsg(funds, fundMap, msg);
|
buildMsg(funds, fundMap, msg);
|
||||||
dingTalkService.sendXbMsg(msg.toString());
|
dingTalkService.sendMsg(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void buildMsg(List<FundList> funds, Map<String, XbFundList> fundMap, StringBuilder msg) {
|
private static void buildMsg(List<FundList> funds, Map<String, XbFundList> fundMap, StringBuilder msg) {
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.xb.service;
|
|
||||||
|
|
||||||
import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService;
|
|
||||||
import com.xiang.xservice.config.DingTalkRobotXbConfig;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-08-07 11:02
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Slf4j
|
|
||||||
public class DingTalkRobotService {
|
|
||||||
private final DingTalkService dingTalkService;
|
|
||||||
private final DingTalkRobotXbConfig dingTalkRobotConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送脚本消息
|
|
||||||
* @param msg 消息
|
|
||||||
*/
|
|
||||||
public void sendXbMsg(String msg) {
|
|
||||||
try {
|
|
||||||
dingTalkService.sendRobotMessage(dingTalkRobotConfig.getSecret(), dingTalkRobotConfig.getToken(), dingTalkRobotConfig.getUsers(), msg);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("信息发送异常, 信息:{}", msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.xiang.xservice.common.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-12-08 16:39
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class SysConfigDO{
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String value;
|
||||||
|
private Integer status;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.xiang.xservice.common.enums;
|
||||||
|
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.enums.BaseDingTalkBizType;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-01-04 16:13
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum DingTalkBizTypeEnum implements BaseDingTalkBizType {
|
||||||
|
|
||||||
|
JT("venue", "江南体育中心"),
|
||||||
|
XB("xb", "股票基金变化通知"),
|
||||||
|
SCRIPT("script", "脚本运行通知群")
|
||||||
|
;
|
||||||
|
private final String bizName;
|
||||||
|
private final String desc;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.xiang.xservice.common.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.xiang.xservice.common.entity.SysConfigDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-12-08 17:01
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@Repository
|
||||||
|
public interface SysConfigMapper extends BaseMapper<SysConfigDO> {
|
||||||
|
|
||||||
|
SysConfigDO getByName(@Param("name") String name);
|
||||||
|
}
|
||||||
@@ -3,9 +3,9 @@ package com.xiang.xservice.common.schedule;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
import com.xiang.xservice.basic.utils.DateUtils;
|
||||||
import com.xiang.xservice.basic.utils.HttpUtils;
|
import com.xiang.xservice.basic.utils.HttpUtils;
|
||||||
import com.xiang.xservice.cache.service.IRedisService;
|
|
||||||
import com.xiang.xservice.common.entity.DayResult;
|
import com.xiang.xservice.common.entity.DayResult;
|
||||||
import com.xiang.xservice.common.enums.RedisConstant;
|
import com.xiang.xservice.common.enums.RedisConstant;
|
||||||
import com.xiang.xservice.common.enums.UrlConstant;
|
import com.xiang.xservice.common.enums.UrlConstant;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.xiang.xservice.common.service;
|
||||||
|
|
||||||
|
import com.xiang.xservice.common.entity.SysConfigDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-12-16 11:19
|
||||||
|
*/
|
||||||
|
public interface ISysConfigService {
|
||||||
|
|
||||||
|
SysConfigDO getByName(String name);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.xiang.xservice.common.service;
|
||||||
|
|
||||||
|
import com.xiang.xservice.common.entity.SysConfigDO;
|
||||||
|
import com.xiang.xservice.common.mapper.SysConfigMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-12-16 11:20
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SysConfigServiceImpl implements ISysConfigService {
|
||||||
|
private final SysConfigMapper sysConfigMapper;
|
||||||
|
@Override
|
||||||
|
public SysConfigDO getByName(String name) {
|
||||||
|
return sysConfigMapper.getByName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.xiang.xservice.common.service.dingTalk;
|
||||||
|
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.config.DingTalkRobotProperties;
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.service.AbstractDingTalkFactory;
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.service.DingTalkSender;
|
||||||
|
import com.xiang.xservice.common.enums.DingTalkBizTypeEnum;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2026-01-04 16:19
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class JtDingTalkFactory extends AbstractDingTalkFactory {
|
||||||
|
public JtDingTalkFactory(DingTalkRobotProperties dingTalkRobotProperties, DingTalkSender dingTalkSender) {
|
||||||
|
super(dingTalkRobotProperties, dingTalkSender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMsg(String msg) {
|
||||||
|
getClient(DingTalkBizTypeEnum.JT).sendDingTalkMsg(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.xiang.xservice.common.service.dingTalk;
|
||||||
|
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.config.DingTalkRobotProperties;
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.service.AbstractDingTalkFactory;
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.service.DingTalkSender;
|
||||||
|
import com.xiang.xservice.common.enums.DingTalkBizTypeEnum;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ScriptDingTalkFactory extends AbstractDingTalkFactory {
|
||||||
|
public ScriptDingTalkFactory(DingTalkRobotProperties dingTalkRobotProperties, DingTalkSender dingTalkSender) {
|
||||||
|
super(dingTalkRobotProperties, dingTalkSender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMsg(String msg) {
|
||||||
|
getClient(DingTalkBizTypeEnum.SCRIPT).sendDingTalkMsg(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.xiang.xservice.common.service.dingTalk;
|
||||||
|
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.config.DingTalkRobotProperties;
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.service.AbstractDingTalkFactory;
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.service.DingTalkSender;
|
||||||
|
import com.xiang.xservice.common.enums.DingTalkBizTypeEnum;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class StockDingTalkFactory extends AbstractDingTalkFactory {
|
||||||
|
public StockDingTalkFactory(DingTalkRobotProperties dingTalkRobotProperties, DingTalkSender dingTalkSender) {
|
||||||
|
super(dingTalkRobotProperties, dingTalkSender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMsg(String msg) {
|
||||||
|
getClient(DingTalkBizTypeEnum.XB).sendDingTalkMsg(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,44 @@
|
|||||||
package com.xiang.xservice.common.utils;
|
package com.xiang.xservice.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import com.xiang.xmc.service.cache.service.IRedisService;
|
||||||
import com.xiang.xservice.common.entity.DayResult;
|
import com.xiang.xservice.common.entity.DayResult;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: xiang
|
* @Author: xiang
|
||||||
* @Date: 2025-10-04 10:34
|
* @Date: 2025-10-04 10:34
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class DateUtils {
|
public class DateUtils {
|
||||||
|
|
||||||
public static Boolean validHoliday(DayResult result) {
|
private IRedisService redisService;
|
||||||
return com.xiang.xservice.basic.utils.DateUtils.validHolidayTime(
|
public Boolean validHoliday(DayResult result) {
|
||||||
result.getDate(), result.getStatusDesc(), result.getWeek(), result.getStatus());
|
if (validHolidayTime(result.getDate(), result.getStatusDesc(), result.getWeek(), result.getStatus()))
|
||||||
|
return Boolean.TRUE;
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean validHolidayTime(String date, String statusDesc, String week, String status) {
|
||||||
|
if (StringUtils.equals(status, "1")) {
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
if (StringUtils.equals(status, "2")) {
|
||||||
|
log.info("当前日期:{}, {}, 是工作日", date, week);
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(status)) {
|
||||||
|
if (StringUtils.equals(week, "周六") || StringUtils.equals(week, "周日")) {
|
||||||
|
log.info("当前日期:{}, {}, 是周末", date, week);
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.xiang.xservice.config;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-12-15 15:20
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties(prefix = "dingtalk.robot.venue")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DingTalkRobotVenueConfig {
|
||||||
|
private String token;
|
||||||
|
private String secret;
|
||||||
|
private List<String> users;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.xiang.xservice.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("/statics/**").addResourceLocations("classpath:/statics/");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,16 +12,16 @@ spring:
|
|||||||
primary: master
|
primary: master
|
||||||
datasource:
|
datasource:
|
||||||
master:
|
master:
|
||||||
url: jdbc:mysql://rm-bp15t34gqx62jm069ro.mysql.rds.aliyuncs.com:3306/xservice-script-test?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
url: jdbc:mysql://120.27.153.87:3306/xservice-script-test?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||||
username: root
|
username: root
|
||||||
password: xb#UWqnhH24&XpX
|
password: sdkljfikdfn@123
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
sshConnect: false
|
sshConnect: false
|
||||||
redis:
|
redis:
|
||||||
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
||||||
port: 6379
|
port: 6379
|
||||||
password: Xiang0000 # 如果无密码可以省略
|
password: Xiang0000 # 如果无密码可以省略
|
||||||
database: 0
|
database: 10
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
@@ -29,6 +29,21 @@ spring:
|
|||||||
max-idle: 8
|
max-idle: 8
|
||||||
min-idle: 0
|
min-idle: 0
|
||||||
max-wait: 1000
|
max-wait: 1000
|
||||||
|
freemarker:
|
||||||
|
request-context-attribute: request
|
||||||
|
suffix: .html
|
||||||
|
content-type: text/html
|
||||||
|
enabled: true
|
||||||
|
cache: false
|
||||||
|
charset: UTF-8
|
||||||
|
allow-request-override: false
|
||||||
|
expose-request-attributes: true
|
||||||
|
expose-session-attributes: true
|
||||||
|
expose-spring-macro-helpers: true
|
||||||
|
settings:
|
||||||
|
number_format: 0.##
|
||||||
|
default_encoding: UTF-8
|
||||||
|
|
||||||
|
|
||||||
aliyun:
|
aliyun:
|
||||||
dns:
|
dns:
|
||||||
@@ -36,18 +51,23 @@ aliyun:
|
|||||||
- local
|
- local
|
||||||
|
|
||||||
dingtalk:
|
dingtalk:
|
||||||
# 钉钉消息用户,用逗号隔开
|
|
||||||
userList: "450841600726084717"
|
|
||||||
# 钉钉消息群ID,需要调用/chat/create api创建群返回
|
|
||||||
chatId: "chatd16d8daeea33b36b73588c676d508096"
|
|
||||||
robot:
|
robot:
|
||||||
script:
|
properties:
|
||||||
token: 797be7f32062e31dec1d567f8b490a5649a5366083618e236c7a1263df1f4af3
|
venue:
|
||||||
secret: SEC9aca642c0c29c9da261462869c464d34623247583d98fc82343a0a4464abbe91
|
name: 江南体育中心通知群
|
||||||
users:
|
token: 6a218646972c684c75832b0229ea93a234778af537d7469ce96bef290faf530e
|
||||||
- 450841600726084717
|
secret: SEC9018755ba86d3e5c1ed2fbfa1d6953d84bb2a6c8ebe7ed4e318457bfed5e0465
|
||||||
xb:
|
users:
|
||||||
token: ad21ead99f0fdc63aa00d6732b7b0888c17590f7612c68297edfcb71844d1437
|
- 450841600726084717
|
||||||
secret: SECc09d8aad6635f1a4cbadb7c0ab365523c46299f138438cd885e445e0f5f4d730
|
script:
|
||||||
users:
|
name: 脚本运行通知群
|
||||||
- 450841600726084717
|
token: 797be7f32062e31dec1d567f8b490a5649a5366083618e236c7a1263df1f4af3
|
||||||
|
secret: SEC9aca642c0c29c9da261462869c464d34623247583d98fc82343a0a4464abbe91
|
||||||
|
users:
|
||||||
|
- 450841600726084717
|
||||||
|
xb:
|
||||||
|
name: 股票基金变化通知群
|
||||||
|
token: ad21ead99f0fdc63aa00d6732b7b0888c17590f7612c68297edfcb71844d1437
|
||||||
|
secret: SECc09d8aad6635f1a4cbadb7c0ab365523c46299f138438cd885e445e0f5f4d730
|
||||||
|
users:
|
||||||
|
- 450841600726084717
|
||||||
@@ -12,15 +12,15 @@ spring:
|
|||||||
primary: master
|
primary: master
|
||||||
datasource:
|
datasource:
|
||||||
master:
|
master:
|
||||||
url: jdbc:mysql://192.168.2.10:3306/xservice-script?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
url: jdbc:mysql://rm-bp15t34gqx62jm069ro.mysql.rds.aliyuncs.com:3306/xservice-script?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||||
username: root
|
username: xservice
|
||||||
password: Admin@123
|
password: xb#UWqnhH24&XpX
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
sshConnect: false
|
sshConnect: false
|
||||||
redis:
|
redis:
|
||||||
host: 192.168.2.10
|
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
||||||
port: 6379
|
port: 6379
|
||||||
password: Admin@123 # 如果无密码可以省略
|
password: Xiang0000 # 如果无密码可以省略
|
||||||
database: 0
|
database: 0
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
lettuce:
|
lettuce:
|
||||||
@@ -29,6 +29,20 @@ spring:
|
|||||||
max-idle: 8
|
max-idle: 8
|
||||||
min-idle: 0
|
min-idle: 0
|
||||||
max-wait: 1000
|
max-wait: 1000
|
||||||
|
freemarker:
|
||||||
|
request-context-attribute: request
|
||||||
|
suffix: .html
|
||||||
|
content-type: text/html
|
||||||
|
enabled: true
|
||||||
|
cache: false
|
||||||
|
charset: UTF-8
|
||||||
|
allow-request-override: false
|
||||||
|
expose-request-attributes: true
|
||||||
|
expose-session-attributes: true
|
||||||
|
expose-spring-macro-helpers: true
|
||||||
|
settings:
|
||||||
|
number_format: 0.##
|
||||||
|
default_encoding: UTF-8
|
||||||
|
|
||||||
aliyun:
|
aliyun:
|
||||||
dns:
|
dns:
|
||||||
@@ -38,18 +52,23 @@ aliyun:
|
|||||||
- nexus
|
- nexus
|
||||||
|
|
||||||
dingtalk:
|
dingtalk:
|
||||||
# 钉钉消息用户,用逗号隔开
|
|
||||||
userList: "450841600726084717"
|
|
||||||
# 钉钉消息群ID,需要调用/chat/create api创建群返回
|
|
||||||
chatId: "chatd16d8daeea33b36b73588c676d508096"
|
|
||||||
robot:
|
robot:
|
||||||
script:
|
properties:
|
||||||
token: 4709b708d961846e0aee523c5abc3b67e8fa424ee292501d85efd4e504f15a8b
|
venue:
|
||||||
secret: SEC768ed578c0fb31a9aec84b1c1db4f195f5aca203985bbb9d549e23e41c8874d1
|
name: 江南体育中心通知群
|
||||||
users:
|
token: 6a218646972c684c75832b0229ea93a234778af537d7469ce96bef290faf530e
|
||||||
- 450841600726084717
|
secret: SEC9018755ba86d3e5c1ed2fbfa1d6953d84bb2a6c8ebe7ed4e318457bfed5e0465
|
||||||
xb:
|
users:
|
||||||
token: 340a9d39a5b0b6a52ba2262f9c27179cf50e3c8cfe6883ca082649d306038f41
|
- 450841600726084717
|
||||||
secret: SECe10ade3058880b84df5c6f46ab072c11f4ac2a5ef9f134d684705c2a3b004de2
|
script:
|
||||||
users:
|
name: 脚本运行通知群
|
||||||
- 450841600726084717
|
token: 4709b708d961846e0aee523c5abc3b67e8fa424ee292501d85efd4e504f15a8b
|
||||||
|
secret: SEC768ed578c0fb31a9aec84b1c1db4f195f5aca203985bbb9d549e23e41c8874d1
|
||||||
|
users:
|
||||||
|
- 450841600726084717
|
||||||
|
xb:
|
||||||
|
name: 股票基金变化通知群
|
||||||
|
token: 340a9d39a5b0b6a52ba2262f9c27179cf50e3c8cfe6883ca082649d306038f41
|
||||||
|
secret: SECe10ade3058880b84df5c6f46ab072c11f4ac2a5ef9f134d684705c2a3b004de2
|
||||||
|
users:
|
||||||
|
- 450841600726084717
|
||||||
@@ -12,16 +12,16 @@ spring:
|
|||||||
primary: master
|
primary: master
|
||||||
datasource:
|
datasource:
|
||||||
master:
|
master:
|
||||||
url: jdbc:mysql://rm-bp15t34gqx62jm069ro.mysql.rds.aliyuncs.com:3306/xservice-script-test?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
url: jdbc:mysql://120.27.153.87:3306/xservice-script-test?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||||
username: root
|
username: root
|
||||||
password: xb#UWqnhH24&XpX
|
password: sdkljfikdfn@123
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
sshConnect: false
|
sshConnect: false
|
||||||
redis:
|
redis:
|
||||||
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
||||||
port: 6379
|
port: 6379
|
||||||
password: Xiang0000 # 如果无密码可以省略
|
password: Xiang0000 # 如果无密码可以省略
|
||||||
database: 0
|
database: 10
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
@@ -29,6 +29,20 @@ spring:
|
|||||||
max-idle: 8
|
max-idle: 8
|
||||||
min-idle: 0
|
min-idle: 0
|
||||||
max-wait: 1000
|
max-wait: 1000
|
||||||
|
freemarker:
|
||||||
|
request-context-attribute: request
|
||||||
|
suffix: .html
|
||||||
|
content-type: text/html
|
||||||
|
enabled: true
|
||||||
|
cache: false
|
||||||
|
charset: UTF-8
|
||||||
|
allow-request-override: false
|
||||||
|
expose-request-attributes: true
|
||||||
|
expose-session-attributes: true
|
||||||
|
expose-spring-macro-helpers: true
|
||||||
|
settings:
|
||||||
|
number_format: 0.##
|
||||||
|
default_encoding: UTF-8
|
||||||
|
|
||||||
aliyun:
|
aliyun:
|
||||||
dns:
|
dns:
|
||||||
@@ -36,18 +50,23 @@ aliyun:
|
|||||||
- test
|
- test
|
||||||
|
|
||||||
dingtalk:
|
dingtalk:
|
||||||
# 钉钉消息用户,用逗号隔开
|
|
||||||
userList: "450841600726084717"
|
|
||||||
# 钉钉消息群ID,需要调用/chat/create api创建群返回
|
|
||||||
chatId: "chatd16d8daeea33b36b73588c676d508096"
|
|
||||||
robot:
|
robot:
|
||||||
script:
|
properties:
|
||||||
token: 797be7f32062e31dec1d567f8b490a5649a5366083618e236c7a1263df1f4af3
|
venue:
|
||||||
secret: SEC9aca642c0c29c9da261462869c464d34623247583d98fc82343a0a4464abbe91
|
name: 江南体育中心通知群
|
||||||
users:
|
token: 6a218646972c684c75832b0229ea93a234778af537d7469ce96bef290faf530e
|
||||||
- 450841600726084717
|
secret: SEC9018755ba86d3e5c1ed2fbfa1d6953d84bb2a6c8ebe7ed4e318457bfed5e0465
|
||||||
xb:
|
users:
|
||||||
token: ad21ead99f0fdc63aa00d6732b7b0888c17590f7612c68297edfcb71844d1437
|
- 450841600726084717
|
||||||
secret: SECc09d8aad6635f1a4cbadb7c0ab365523c46299f138438cd885e445e0f5f4d730
|
script:
|
||||||
users:
|
name: 脚本运行通知群
|
||||||
- 450841600726084717
|
token: 797be7f32062e31dec1d567f8b490a5649a5366083618e236c7a1263df1f4af3
|
||||||
|
secret: SEC9aca642c0c29c9da261462869c464d34623247583d98fc82343a0a4464abbe91
|
||||||
|
users:
|
||||||
|
- 450841600726084717
|
||||||
|
xb:
|
||||||
|
name: 股票基金变化通知群
|
||||||
|
token: ad21ead99f0fdc63aa00d6732b7b0888c17590f7612c68297edfcb71844d1437
|
||||||
|
secret: SECc09d8aad6635f1a4cbadb7c0ab365523c46299f138438cd885e445e0f5f4d730
|
||||||
|
users:
|
||||||
|
- 450841600726084717
|
||||||
@@ -16,11 +16,14 @@ server:
|
|||||||
|
|
||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
active: test
|
active: local
|
||||||
application:
|
application:
|
||||||
name: xservice-script-center
|
name: xservice-script-center
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
|
autoconfigure:
|
||||||
|
exclude:
|
||||||
|
- com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration
|
||||||
|
|
||||||
http:
|
http:
|
||||||
maxAttempts: 10
|
maxAttempts: 10
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<!--设置输出格式-->
|
<!--设置输出格式-->
|
||||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||||
<pattern>%boldGreen(%contextName): %boldCyan(%d{yyyy-MM-dd HH:mm:ss:SSS}) %highlight([%c]) %boldMagenta([%t]) %boldCyan([%L]) %highlight([traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}]) %boldGreen([%p]) - %msg%n
|
<pattern>%boldGreen(%contextName): %boldCyan(%d{yyyy-MM-dd HH:mm:ss:SSS}) %highlight([%c]) %boldMagenta([%t]) %boldCyan([%L]) %highlight([traceId:%X{traceId:-})] %boldGreen([%p]) - %msg%n
|
||||||
</pattern>
|
</pattern>
|
||||||
<!--设置编码-->
|
<!--设置编码-->
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
||||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-}] - %msg%n</pattern>
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
<!-- 此日志文件只记录debug级别的 -->
|
<!-- 此日志文件只记录debug级别的 -->
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
||||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-}] - %msg%n</pattern>
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||||
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
<!--格式化输出:%d表示日期,%c类名,%t表示线程名,%L行, %p日志级别 %msg:日志消息,%n是换行符 -->
|
||||||
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-},spanId:%X{spanId:-},localIp:%X{localIp:-}] - %msg%n</pattern>
|
<pattern>%contextName: %d{yyyy-MM-dd HH:mm:ss.SSS} [%c][%t][%L][%p] [traceId:%X{traceId:-}] - %msg%n</pattern>
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
<!-- 此日志文件只记录error级别的 -->
|
<!-- 此日志文件只记录error级别的 -->
|
||||||
|
|||||||
29
script/src/main/resources/mapper/SysConfigMapper.xml
Normal file
29
script/src/main/resources/mapper/SysConfigMapper.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.xiang.xservice.common.mapper.SysConfigMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.xiang.xservice.common.entity.SysConfigDO" >
|
||||||
|
<result column="id" property="id"/>
|
||||||
|
<result column="name" property="name" />
|
||||||
|
<result column="value" property="value" />
|
||||||
|
<result column="status" property="status" />
|
||||||
|
<result column="create_time" property="createTime" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_sql">
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
status,
|
||||||
|
create_time
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="getByName" resultMap="BaseResultMap" parameterType="String">
|
||||||
|
select <include refid="Base_sql"/>
|
||||||
|
from sys_config
|
||||||
|
where name = #{name} and status = 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.xiang.xservice.fwd.mapper.FwdAudienceConfigMapper">
|
<mapper namespace="com.xiang.xservice.application.script.fwd.mapper.FwdAudienceConfigMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.xiang.xservice.application.script.fwd.entity.pojo.FAudienceConfig">
|
<resultMap id="BaseResultMap" type="com.xiang.xservice.application.script.fwd.entity.pojo.FAudienceConfig">
|
||||||
<result column="id" property="id"/>
|
<result column="id" property="id"/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.xiang.xservice.fwd.mapper.FwdPerformConfigMapper">
|
<mapper namespace="com.xiang.xservice.application.script.fwd.mapper.FwdPerformConfigMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig" >
|
<resultMap id="BaseResultMap" type="com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig" >
|
||||||
<result column="id" property="id"/>
|
<result column="id" property="id"/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.xiang.xservice.fwd.mapper.FwdPerformProjectInfoMapper">
|
<mapper namespace="com.xiang.xservice.application.script.fwd.mapper.FwdPerformProjectInfoMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo" >
|
<resultMap id="BaseResultMap" type="com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo" >
|
||||||
<result column="id" property="id"/>
|
<result column="id" property="id"/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.xiang.xservice.fwd.mapper.FwdPerformSeatInfoMapper">
|
<mapper namespace="com.xiang.xservice.application.script.fwd.mapper.FwdPerformSeatInfoMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo" >
|
<resultMap id="BaseResultMap" type="com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo" >
|
||||||
<result column="id" property="id"/>
|
<result column="id" property="id"/>
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user