Commit f7eac94e12946c49b042f3fec3d4b786fe328b25
1 parent
2815afd7
初始化
Showing
60 changed files
with
2482 additions
and
26 deletions
shop/pom.xml
... | ... | @@ -98,6 +98,41 @@ |
98 | 98 | <groupId>com.google.guava</groupId> |
99 | 99 | <artifactId>guava</artifactId> |
100 | 100 | </dependency> |
101 | + <dependency> | |
102 | + <groupId>org.apache.httpcomponents</groupId> | |
103 | + <artifactId>httpclient</artifactId> | |
104 | + <version>4.5.14</version> | |
105 | + </dependency> | |
106 | + <dependency> | |
107 | + <groupId>com.theokanning.openai-gpt3-java</groupId> | |
108 | + <artifactId>service</artifactId> | |
109 | + <version>0.14.0</version> | |
110 | + </dependency> | |
111 | + <dependency> | |
112 | + <groupId>xyz.felh</groupId> | |
113 | + <artifactId>service</artifactId> | |
114 | + <version>1.4.4</version> | |
115 | + </dependency> | |
116 | + <dependency> | |
117 | + <groupId>com.fasterxml.jackson.core</groupId> | |
118 | + <artifactId>jackson-databind</artifactId> | |
119 | + <version>2.15.2</version> | |
120 | + </dependency> | |
121 | + <dependency> | |
122 | + <groupId>com.fasterxml.jackson.core</groupId> | |
123 | + <artifactId>jackson-core</artifactId> | |
124 | + <version>2.15.2</version> | |
125 | + </dependency> | |
126 | + <dependency> | |
127 | + <groupId>com.fasterxml.jackson.core</groupId> | |
128 | + <artifactId>jackson-annotations</artifactId> | |
129 | + <version>2.15.2</version> | |
130 | + </dependency> | |
131 | + <dependency> | |
132 | + <groupId>commons-io</groupId> | |
133 | + <artifactId>commons-io</artifactId> | |
134 | + <version>2.4</version> | |
135 | + </dependency> | |
101 | 136 | </dependencies> |
102 | 137 | <build> |
103 | 138 | <finalName>shop.services-1.0-SNAPSHOT</finalName> | ... | ... |
shop/src/main/java/com/canrd/shop/common/constant/Constant.java
... | ... | @@ -329,4 +329,13 @@ public class Constant { |
329 | 329 | */ |
330 | 330 | public static final String EXCEL_IMPORT_ERROR_PREFIX = "excel:import:error:"; |
331 | 331 | |
332 | + /** | |
333 | + * 图片前缀 | |
334 | + */ | |
335 | + public static final String FILE_PATH = "http://www.canrud.com/api/show/image?fileKey="; | |
336 | + | |
337 | + /** | |
338 | + * 默认图片 | |
339 | + */ | |
340 | + public static final String DEFAULT_FILE_KEY="57e231ee030b619d31c30c462285428c"; | |
332 | 341 | } | ... | ... |
shop/src/main/java/com/canrd/shop/common/enums/RootCategoryEnum.java
0 → 100644
1 | +package com.canrd.shop.common.enums; | |
2 | + | |
3 | +import lombok.Getter; | |
4 | + | |
5 | +/** | |
6 | + * @author hongtao.zhao | |
7 | + * @since 2023-06-04 | |
8 | + */ | |
9 | +@Getter | |
10 | +public enum RootCategoryEnum { | |
11 | + ENERGY_MATERIAL("Energy materials",10), | |
12 | + LABORATORY_CONSUMABLE("Laboratory consumables",20), | |
13 | + LOW_DIMENSIONAL_MATERIAL("Low-dimensional materials",30), | |
14 | + | |
15 | + DEVICE("Equipment",40) | |
16 | + ; | |
17 | + private String name; | |
18 | + | |
19 | + private int order; | |
20 | + | |
21 | + RootCategoryEnum(String name, int order) { | |
22 | + this.name = name; | |
23 | + this.order = order; | |
24 | + } | |
25 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/common/utils/ChatGptUtil.java
0 → 100644
1 | +package com.canrd.shop.common.utils; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSONObject; | |
4 | +import lombok.extern.slf4j.Slf4j; | |
5 | +import okhttp3.MediaType; | |
6 | +import okhttp3.OkHttpClient; | |
7 | +import okhttp3.Request; | |
8 | +import okhttp3.RequestBody; | |
9 | +import okhttp3.Response; | |
10 | +import org.springframework.beans.factory.annotation.Autowired; | |
11 | +import org.springframework.stereotype.Component; | |
12 | +import xyz.felh.openai.OpenAiService; | |
13 | +import xyz.felh.openai.completion.chat.ChatMessage; | |
14 | +import xyz.felh.openai.completion.chat.ChatMessageRole; | |
15 | +import xyz.felh.openai.completion.chat.CreateChatCompletionRequest; | |
16 | + | |
17 | +import java.io.IOException; | |
18 | +import java.util.Arrays; | |
19 | +import java.util.concurrent.TimeUnit; | |
20 | + | |
21 | +/** | |
22 | + * @author hongtao.zhao | |
23 | + * @since 2023-07-09 | |
24 | + */ | |
25 | +@Slf4j | |
26 | +@Component | |
27 | +public class ChatGptUtil { | |
28 | + | |
29 | + | |
30 | + @Autowired | |
31 | + private OpenAiService openAiService; | |
32 | + | |
33 | + public static String chatgptTranslate(String content) throws IOException, InterruptedException { | |
34 | + OkHttpClient client = new OkHttpClient().newBuilder() | |
35 | + .readTimeout(100000, TimeUnit.SECONDS) | |
36 | + .callTimeout(100000,TimeUnit.SECONDS) | |
37 | + .connectTimeout(100000,TimeUnit.SECONDS) | |
38 | + .build(); | |
39 | + long start = System.currentTimeMillis(); | |
40 | + MediaType mediaType = MediaType.parse("application/json"); | |
41 | + String str = "{\n \"model\": \"gpt-3.5-turbo\",\n \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]\n}"; | |
42 | + JSONObject jsonObject = JSONObject.parseObject(str); | |
43 | + jsonObject.getJSONArray("messages").getJSONObject(0).put("content",content); | |
44 | + jsonObject.getJSONArray("messages").getJSONObject(0).put("role","user"); | |
45 | + RequestBody body = RequestBody.create(mediaType, jsonObject.toJSONString()); | |
46 | + Request request = new Request.Builder() | |
47 | + .url("https://api.openai.com/v1/chat/completions") | |
48 | + .method("POST", body) | |
49 | + .addHeader("Accept", "application/json") | |
50 | + .addHeader("Accept-Encoding", "identity") | |
51 | + .addHeader("Authorization", "Bearer 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") | |
52 | + .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)") | |
53 | + .addHeader("Connection","close") | |
54 | + .addHeader("Content-Type", "application/json") | |
55 | + .build(); | |
56 | + Response response = client.newCall(request).execute(); | |
57 | + JSONObject responseBody = JSONObject.parseObject(response.body().string()); | |
58 | + log.info("耗时:{}",System.currentTimeMillis() - start ); | |
59 | + return responseBody.getJSONArray("choices").getJSONObject(0).getJSONObject("message").getString("content"); | |
60 | + } | |
61 | + | |
62 | + | |
63 | + public String chatgptTranslate2(String content){ | |
64 | + CreateChatCompletionRequest request = CreateChatCompletionRequest.builder() | |
65 | + .messages(Arrays.asList(new ChatMessage(ChatMessageRole.USER, content))) | |
66 | + .model("gpt-3.5-turbo") | |
67 | + //.maxTokens(4096) | |
68 | + .temperature(0.8) | |
69 | + .stream(false) | |
70 | + //.user("LOGIC_USER_KEY") | |
71 | + .build(); | |
72 | + log.info("chatCompletion Request:\n{}", JSONObject.toJSONString(request)); | |
73 | + xyz.felh.openai.completion.chat.ChatCompletion completionResult = openAiService.createChatCompletion(request); | |
74 | + log.info("chatCompletion Response:\n{}", JSONObject.toJSONString(completionResult)); | |
75 | + return completionResult.getChoices().get(0).getMessage().getContent(); | |
76 | + } | |
77 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/common/utils/TranslateHtmlV3Util.java
0 → 100644
1 | +package com.canrd.shop.common.utils; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSONObject; | |
4 | +import org.apache.http.Header; | |
5 | +import org.apache.http.HttpEntity; | |
6 | +import org.apache.http.NameValuePair; | |
7 | +import org.apache.http.client.entity.UrlEncodedFormEntity; | |
8 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
9 | +import org.apache.http.client.methods.HttpPost; | |
10 | +import org.apache.http.impl.client.CloseableHttpClient; | |
11 | +import org.apache.http.impl.client.HttpClients; | |
12 | +import org.apache.http.message.BasicNameValuePair; | |
13 | +import org.apache.http.util.EntityUtils; | |
14 | +import org.slf4j.Logger; | |
15 | +import org.slf4j.LoggerFactory; | |
16 | + | |
17 | +import java.io.IOException; | |
18 | +import java.security.MessageDigest; | |
19 | +import java.security.NoSuchAlgorithmException; | |
20 | +import java.util.ArrayList; | |
21 | +import java.util.HashMap; | |
22 | +import java.util.Iterator; | |
23 | +import java.util.List; | |
24 | +import java.util.Map; | |
25 | + | |
26 | +/** | |
27 | + * @author hongtao.zhao | |
28 | + * @since 2023-06-17 | |
29 | + */ | |
30 | +public class TranslateHtmlV3Util { | |
31 | + | |
32 | + private static Logger logger = LoggerFactory.getLogger(TranslateHtmlV3Util.class); | |
33 | + | |
34 | + private static final String YOUDAO_URL = "https://openapi.youdao.com/translate_html"; | |
35 | + | |
36 | + private static final String APP_KEY = "3d3d3dd3c89580d2"; | |
37 | + | |
38 | + private static final String APP_SECRET = "ARJPyqj45zKF0GCNV3ad5iWx8gxZk4lN"; | |
39 | + | |
40 | + public static String translate(String text) throws IOException, InterruptedException { | |
41 | + | |
42 | + Thread.sleep(1000); | |
43 | + Map<String, String> params = new HashMap<String, String>(); | |
44 | + String q = text; | |
45 | + String salt = String.valueOf(System.currentTimeMillis()); | |
46 | + String from = "zh-CHS"; | |
47 | + String to = "en"; | |
48 | + params.put("from", from); | |
49 | + params.put("to", to); | |
50 | + params.put("signType", "v3"); | |
51 | + String curtime = String.valueOf(System.currentTimeMillis() / 1000); | |
52 | + params.put("curtime", curtime); | |
53 | + String signStr = APP_KEY + truncate(q) + salt + curtime + APP_SECRET; | |
54 | + String sign = getDigest(signStr); | |
55 | + params.put("appKey", APP_KEY); | |
56 | + params.put("q", q); | |
57 | + params.put("salt", salt); | |
58 | + params.put("sign", sign); | |
59 | + /** 处理结果 */ | |
60 | + String json = requestForHttp(YOUDAO_URL, params); | |
61 | + String result = String.valueOf(JSONObject.parseObject(json).getJSONObject("data").getString("translation")); | |
62 | + return result; | |
63 | + } | |
64 | + | |
65 | + public static String requestForHttp(String url, Map<String, String> params) throws IOException { | |
66 | + | |
67 | + /** 创建HttpClient */ | |
68 | + CloseableHttpClient httpClient = HttpClients.createDefault(); | |
69 | + | |
70 | + /** httpPost */ | |
71 | + HttpPost httpPost = new HttpPost(url); | |
72 | + List<NameValuePair> paramsList = new ArrayList<NameValuePair>(); | |
73 | + Iterator<Map.Entry<String, String>> it = params.entrySet().iterator(); | |
74 | + while (it.hasNext()) { | |
75 | + Map.Entry<String, String> en = it.next(); | |
76 | + String key = en.getKey(); | |
77 | + String value = en.getValue(); | |
78 | + paramsList.add(new BasicNameValuePair(key, value)); | |
79 | + } | |
80 | + httpPost.setEntity(new UrlEncodedFormEntity(paramsList, "UTF-8")); | |
81 | + CloseableHttpResponse httpResponse = httpClient.execute(httpPost); | |
82 | + try { | |
83 | + Header[] contentType = httpResponse.getHeaders("Content-Type"); | |
84 | + logger.info("Content-Type:" + contentType[0].getValue()); | |
85 | + if ("audio/mp3".equals(contentType[0].getValue())) { | |
86 | + // | |
87 | + } else { | |
88 | + /** 响应不是音频流,直接显示结果 */ | |
89 | + HttpEntity httpEntity = httpResponse.getEntity(); | |
90 | + String json = EntityUtils.toString(httpEntity, "UTF-8"); | |
91 | + EntityUtils.consume(httpEntity); | |
92 | + logger.info(json); | |
93 | + System.out.println(json); | |
94 | + return json; | |
95 | + } | |
96 | + } finally { | |
97 | + try { | |
98 | + if (httpResponse != null) { | |
99 | + httpResponse.close(); | |
100 | + } | |
101 | + } catch (IOException e) { | |
102 | + logger.info("## release resouce error ##" + e); | |
103 | + } | |
104 | + } | |
105 | + return null; | |
106 | + } | |
107 | + | |
108 | + /** | |
109 | + * 生成加密字段 | |
110 | + */ | |
111 | + public static String getDigest(String string) { | |
112 | + if (string == null) { | |
113 | + return null; | |
114 | + } | |
115 | + char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; | |
116 | + byte[] btInput = string.getBytes(); | |
117 | + try { | |
118 | + MessageDigest mdInst = MessageDigest.getInstance("SHA-256"); | |
119 | + mdInst.update(btInput); | |
120 | + byte[] md = mdInst.digest(); | |
121 | + int j = md.length; | |
122 | + char str[] = new char[j * 2]; | |
123 | + int k = 0; | |
124 | + for (byte byte0 : md) { | |
125 | + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; | |
126 | + str[k++] = hexDigits[byte0 & 0xf]; | |
127 | + } | |
128 | + return new String(str); | |
129 | + } catch (NoSuchAlgorithmException e) { | |
130 | + return null; | |
131 | + } | |
132 | + } | |
133 | + | |
134 | + public static String truncate(String q) { | |
135 | + if (q == null) { | |
136 | + return null; | |
137 | + } | |
138 | + int len = q.length(); | |
139 | + String result; | |
140 | + return len <= 20 ? q : (q.substring(0, 10) + len + q.substring(len - 10, len)); | |
141 | + } | |
142 | + | |
143 | + public static void main(String[] args) throws IOException, InterruptedException { | |
144 | + String result = translate("<table width=\"371\" height=\"192\" cellspacing=\"0\" cellpadding=\"0\"><colgroup><col width=\"187\" style=\"width:140.25pt;\"/><col width=\"153\" style=\"width:114.75pt;\" span=\"3\"/></colgroup><tbody><tr height=\"32\" class=\"firstRow\" style=\"height:24.00pt;\"><td width=\"140\" height=\"24\" x:str=\"\">牌号</td><td width=\"114\" x:str=\"\">E-30</td><td width=\"114\" x:str=\"\">E-60</td></tr><tr height=\"32\" style=\"height:24.00pt;\"><td height=\"24\" x:str=\"\">粘度/mPa・s, 25℃</td><td x:str=\"\">40-100(2%wt)</td><td x:str=\"\">2000-4000(2%wt)</td></tr><tr height=\"32\" style=\"height:24.00pt;\"><td height=\"24\" x:str=\"\">平均分子量</td><td x:str=\"\">38W</td><td x:str=\"\">110W</td></tr><tr height=\"32\" style=\"height:24.00pt;\"><td height=\"24\" x:str=\"\">pH值</td><td x:num=\"7\">7</td><td x:num=\"7\">7</td></tr><tr height=\"32\" style=\"height:24.00pt;\"><td height=\"24\" x:str=\"\">热失重/2%</td><td x:num=\"0.5\">0.5</td><td x:num=\"0.5\">0.5</td></tr><tr height=\"32\" style=\"height:24.00pt;\"><td height=\"24\" x:str=\"\">灰分/%</td><td x:num=\"0.3\">0.3</td><td x:num=\"0.3\">0.3</td></tr></tbody></table><p><img title=\"1587452264800088226.png\" alt=\"image.png\" src=\"/ueditor/jsp/upload/image/20200421/1587452264800088226.png\"/></p><p>离子电导率(供参考)</p><p><img title=\"1587452283396014477.png\" alt=\"image.png\" src=\"/ueditor/jsp/upload/image/20200421/1587452283396014477.png\"/></p><p><img title=\"1587452292236015448.png\" alt=\"image.png\" src=\"/ueditor/jsp/upload/image/20200421/1587452292236015448.png\"/></p><p><br/></p>"); | |
145 | + System.out.println(result); | |
146 | + } | |
147 | +} | |
0 | 148 | \ No newline at end of file | ... | ... |
shop/src/main/java/com/canrd/shop/common/utils/TranslateUtil.java
0 → 100644
1 | +package com.canrd.shop.common.utils; | |
2 | + | |
3 | +/** | |
4 | + * @author hongtao.zhao | |
5 | + * @since 2023-06-10 | |
6 | + */ | |
7 | + | |
8 | +import com.alibaba.fastjson.JSONObject; | |
9 | +import org.apache.http.Header; | |
10 | +import org.apache.http.HttpEntity; | |
11 | +import org.apache.http.NameValuePair; | |
12 | +import org.apache.http.client.entity.UrlEncodedFormEntity; | |
13 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
14 | +import org.apache.http.client.methods.HttpPost; | |
15 | +import org.apache.http.impl.client.CloseableHttpClient; | |
16 | +import org.apache.http.impl.client.HttpClients; | |
17 | +import org.apache.http.message.BasicNameValuePair; | |
18 | +import org.apache.http.util.EntityUtils; | |
19 | +import org.slf4j.Logger; | |
20 | +import org.slf4j.LoggerFactory; | |
21 | + | |
22 | +import java.io.*; | |
23 | +import java.nio.charset.StandardCharsets; | |
24 | +import java.security.MessageDigest; | |
25 | +import java.security.NoSuchAlgorithmException; | |
26 | +import java.util.*; | |
27 | + | |
28 | + | |
29 | +public class TranslateUtil { | |
30 | + | |
31 | + private static Logger logger = LoggerFactory.getLogger(TranslateUtil.class); | |
32 | + | |
33 | + private static final String YOUDAO_URL = "https://openapi.youdao.com/api"; | |
34 | + | |
35 | + private static final String APP_KEY = "10dd5056f44d4225"; | |
36 | + | |
37 | + private static final String APP_SECRET = "CT1bxz8NM6gLdxqXbBnt6n4t0CzdyPgi"; | |
38 | + | |
39 | + public static String translate(String text) { | |
40 | + Map<String,String> params = new HashMap<String,String>(); | |
41 | + String q = text; | |
42 | + String salt = String.valueOf(System.currentTimeMillis()); | |
43 | + params.put("from", "zh-CHS"); | |
44 | + params.put("to", "en"); | |
45 | + params.put("signType", "v3"); | |
46 | + String curtime = String.valueOf(System.currentTimeMillis() / 1000); | |
47 | + params.put("curtime", curtime); | |
48 | + String signStr = APP_KEY + truncate(q) + salt + curtime + APP_SECRET; | |
49 | + String sign = getDigest(signStr); | |
50 | + params.put("appKey", APP_KEY); | |
51 | + params.put("q", q); | |
52 | + params.put("salt", salt); | |
53 | + params.put("sign", sign); | |
54 | + params.put("vocabId","EEA5B46A20EF44B781C2D538174D7486"); | |
55 | + String json = null; | |
56 | + try { | |
57 | + json = requestForHttp(YOUDAO_URL,params); | |
58 | + logger.info(json); | |
59 | + String result = String.valueOf(JSONObject.parseObject(json).getJSONArray("translation").get(0)); | |
60 | + return result; | |
61 | + } catch (Exception e) { | |
62 | + System.out.println(e); | |
63 | + } | |
64 | + return null; | |
65 | + } | |
66 | + | |
67 | + public static String requestForHttp(String url,Map<String,String> params) throws IOException { | |
68 | + /** 创建HttpClient */ | |
69 | + CloseableHttpClient httpClient = HttpClients.createDefault(); | |
70 | + | |
71 | + /** httpPost */ | |
72 | + HttpPost httpPost = new HttpPost(url); | |
73 | + List<NameValuePair> paramsList = new ArrayList<NameValuePair>(); | |
74 | + Iterator<Map.Entry<String,String>> it = params.entrySet().iterator(); | |
75 | + while(it.hasNext()){ | |
76 | + Map.Entry<String,String> en = it.next(); | |
77 | + String key = en.getKey(); | |
78 | + String value = en.getValue(); | |
79 | + paramsList.add(new BasicNameValuePair(key,value)); | |
80 | + } | |
81 | + httpPost.setEntity(new UrlEncodedFormEntity(paramsList,"UTF-8")); | |
82 | + CloseableHttpResponse httpResponse = httpClient.execute(httpPost); | |
83 | + try{ | |
84 | + Header[] contentType = httpResponse.getHeaders("Content-Type"); | |
85 | + logger.info("Content-Type:" + contentType[0].getValue()); | |
86 | + if("audio/mp3".equals(contentType[0].getValue())){ | |
87 | + //如果响应是wav | |
88 | + HttpEntity httpEntity = httpResponse.getEntity(); | |
89 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
90 | + httpResponse.getEntity().writeTo(baos); | |
91 | + byte[] result = baos.toByteArray(); | |
92 | + EntityUtils.consume(httpEntity); | |
93 | + if(result != null){//合成成功 | |
94 | + String file = "合成的音频存储路径"+System.currentTimeMillis() + ".mp3"; | |
95 | + byte2File(result,file); | |
96 | + } | |
97 | + }else{ | |
98 | + /** 响应不是音频流,直接显示结果 */ | |
99 | + HttpEntity httpEntity = httpResponse.getEntity(); | |
100 | + String json = EntityUtils.toString(httpEntity,"UTF-8"); | |
101 | + EntityUtils.consume(httpEntity); | |
102 | + logger.info(json); | |
103 | + return json; | |
104 | + } | |
105 | + }finally { | |
106 | + try{ | |
107 | + if(httpResponse!=null){ | |
108 | + httpResponse.close(); | |
109 | + } | |
110 | + try { | |
111 | + Thread.sleep(1000l); | |
112 | + } catch (InterruptedException e) { | |
113 | + throw new RuntimeException(e); | |
114 | + } | |
115 | + }catch(IOException e){ | |
116 | + logger.info("## release resouce error ##" + e); | |
117 | + } | |
118 | + } | |
119 | + return null; | |
120 | + } | |
121 | + | |
122 | + /** | |
123 | + * 生成加密字段 | |
124 | + */ | |
125 | + public static String getDigest(String string) { | |
126 | + if (string == null) { | |
127 | + return null; | |
128 | + } | |
129 | + char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; | |
130 | + byte[] btInput = string.getBytes(StandardCharsets.UTF_8); | |
131 | + try { | |
132 | + MessageDigest mdInst = MessageDigest.getInstance("SHA-256"); | |
133 | + mdInst.update(btInput); | |
134 | + byte[] md = mdInst.digest(); | |
135 | + int j = md.length; | |
136 | + char str[] = new char[j * 2]; | |
137 | + int k = 0; | |
138 | + for (byte byte0 : md) { | |
139 | + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; | |
140 | + str[k++] = hexDigits[byte0 & 0xf]; | |
141 | + } | |
142 | + return new String(str); | |
143 | + } catch (NoSuchAlgorithmException e) { | |
144 | + return null; | |
145 | + } | |
146 | + } | |
147 | + | |
148 | + /** | |
149 | + * | |
150 | + * @param result 音频字节流 | |
151 | + * @param file 存储路径 | |
152 | + */ | |
153 | + private static void byte2File(byte[] result, String file) { | |
154 | + File audioFile = new File(file); | |
155 | + FileOutputStream fos = null; | |
156 | + try{ | |
157 | + fos = new FileOutputStream(audioFile); | |
158 | + fos.write(result); | |
159 | + | |
160 | + }catch (Exception e){ | |
161 | + logger.info(e.toString()); | |
162 | + }finally { | |
163 | + if(fos != null){ | |
164 | + try { | |
165 | + fos.close(); | |
166 | + } catch (IOException e) { | |
167 | + e.printStackTrace(); | |
168 | + } | |
169 | + } | |
170 | + } | |
171 | + | |
172 | + } | |
173 | + | |
174 | + public static String truncate(String q) { | |
175 | + if (q == null) { | |
176 | + return null; | |
177 | + } | |
178 | + int len = q.length(); | |
179 | + String result; | |
180 | + return len <= 20 ? q : (q.substring(0, 10) + len + q.substring(len - 10, len)); | |
181 | + } | |
182 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/config/OpenAiApiConfig.java
0 → 100644
1 | +package com.canrd.shop.config; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
4 | +import lombok.Data; | |
5 | +import okhttp3.OkHttpClient; | |
6 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
7 | +import org.springframework.context.annotation.Bean; | |
8 | +import org.springframework.stereotype.Component; | |
9 | +import retrofit2.Retrofit; | |
10 | +import xyz.felh.openai.OpenAiApi; | |
11 | +import xyz.felh.openai.OpenAiService; | |
12 | + | |
13 | +import java.time.Duration; | |
14 | + | |
15 | +import static xyz.felh.openai.OpenAiService.defaultClient; | |
16 | +import static xyz.felh.openai.OpenAiService.defaultObjectMapper; | |
17 | +import static xyz.felh.openai.OpenAiService.defaultRetrofit; | |
18 | + | |
19 | +/** | |
20 | + * @author hongtao.zhao | |
21 | + * @since 2023-07-09 | |
22 | + */ | |
23 | +@Data | |
24 | +@Component | |
25 | +@ConfigurationProperties(prefix = "openai") | |
26 | +public class OpenAiApiConfig { | |
27 | + // OpenAI API token | |
28 | + private String token = "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"; | |
29 | + | |
30 | + // Init directly with token only | |
31 | + @Bean(name = "openAiService") | |
32 | + public OpenAiService openAiService() { | |
33 | + ObjectMapper mapper = defaultObjectMapper(); | |
34 | + // Add proxy if need | |
35 | + // Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 1086)); | |
36 | + OkHttpClient client = defaultClient(token, Duration.ofMillis(300000)) | |
37 | + .newBuilder() | |
38 | + .retryOnConnectionFailure(true) | |
39 | + .build(); | |
40 | + Retrofit retrofit = defaultRetrofit(client, mapper); | |
41 | + OpenAiApi api = retrofit.create(OpenAiApi.class); | |
42 | + return new OpenAiService(api, client); | |
43 | + } | |
44 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/controller/ProductController.java
... | ... | @@ -2,9 +2,12 @@ package com.canrd.shop.controller; |
2 | 2 | |
3 | 3 | import com.canrd.shop.common.constant.ServerResult; |
4 | 4 | import com.canrd.shop.common.jsr303.OperateGroup; |
5 | +import com.canrd.shop.module.vo.ProductCategoryQueryVO; | |
5 | 6 | import com.canrd.shop.module.vo.ProductQueryVO; |
6 | 7 | import com.canrd.shop.module.vo.ProductVO; |
8 | +import com.canrd.shop.service.ProductCategoryService; | |
7 | 9 | import com.canrd.shop.service.ProductService; |
10 | +import org.springframework.beans.factory.annotation.Autowired; | |
8 | 11 | import org.springframework.validation.annotation.Validated; |
9 | 12 | import org.springframework.web.bind.annotation.PostMapping; |
10 | 13 | import org.springframework.web.bind.annotation.RequestBody; |
... | ... | @@ -20,7 +23,7 @@ import javax.annotation.Resource; |
20 | 23 | * @since 2023-05-29 11:43:33 |
21 | 24 | */ |
22 | 25 | @RestController |
23 | -@RequestMapping("/canrd/shop/product") | |
26 | +@RequestMapping("/shop/product") | |
24 | 27 | public class ProductController { |
25 | 28 | /** |
26 | 29 | * 服务对象 |
... | ... | @@ -28,6 +31,25 @@ public class ProductController { |
28 | 31 | @Resource |
29 | 32 | private ProductService productService; |
30 | 33 | |
34 | + @Autowired | |
35 | + private ProductCategoryService productCategoryService; | |
36 | + | |
37 | + /** | |
38 | + * 产品分类 | |
39 | + * | |
40 | + * @param productCategoryQueryVO | |
41 | + * @return | |
42 | + */ | |
43 | + @PostMapping("/category") | |
44 | + public ServerResult category(@RequestBody ProductCategoryQueryVO productCategoryQueryVO){ | |
45 | + return productCategoryService.category(productCategoryQueryVO); | |
46 | + } | |
47 | + | |
48 | + @PostMapping("/categorySearch") | |
49 | + public ServerResult categorySearch(@RequestBody ProductQueryVO productQueryVO){ | |
50 | + return productService.categorySearch(productQueryVO); | |
51 | + } | |
52 | + | |
31 | 53 | /** |
32 | 54 | * 分页查询 |
33 | 55 | * |
... | ... | @@ -36,7 +58,7 @@ public class ProductController { |
36 | 58 | */ |
37 | 59 | @PostMapping("/list") |
38 | 60 | public ServerResult list(@RequestBody @Validated({OperateGroup.List.class}) ProductQueryVO productQueryVO) { |
39 | - return productService.list(productQueryVO); | |
61 | + return productService.listBySimilar(productQueryVO); | |
40 | 62 | } |
41 | 63 | |
42 | 64 | /** |
... | ... | @@ -45,7 +67,7 @@ public class ProductController { |
45 | 67 | * @param productQueryVO 查询条件 |
46 | 68 | * @return 单条数据 |
47 | 69 | */ |
48 | - @PostMapping("/query_by_id") | |
70 | + @PostMapping("/detail") | |
49 | 71 | public ServerResult queryById(@RequestBody ProductQueryVO productQueryVO) { |
50 | 72 | return productService.queryById(productQueryVO); |
51 | 73 | } |
... | ... | @@ -83,5 +105,10 @@ public class ProductController { |
83 | 105 | return productService.deleteById(productQueryVO); |
84 | 106 | } |
85 | 107 | |
108 | + //@PostMapping("/chatgpt") | |
109 | + public ServerResult chatgpt(@RequestBody ProductQueryVO productQueryVO){ | |
110 | + return productService.chatgpt(productQueryVO); | |
111 | + } | |
112 | + | |
86 | 113 | } |
87 | 114 | ... | ... |
shop/src/main/java/com/canrd/shop/converter/ProductCategoryConverter.java
0 → 100644
1 | +package com.canrd.shop.converter; | |
2 | + | |
3 | +import com.canrd.shop.common.constant.Constant; | |
4 | +import com.canrd.shop.common.enums.RootCategoryEnum; | |
5 | +import com.canrd.shop.common.utils.StringUtils; | |
6 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
7 | +import com.canrd.shop.module.dto.ProductFunctionDO; | |
8 | +import com.canrd.shop.module.vo.ProductCategoryDisplayVO; | |
9 | +import com.canrd.shop.module.vo.ProductCategoryResultVO; | |
10 | +import com.canrd.shop.module.vo.ProductCategoryVO; | |
11 | +import com.canrd.shop.module.vo.ProductFunctionVO; | |
12 | +import org.springframework.stereotype.Service; | |
13 | + | |
14 | +import java.util.ArrayList; | |
15 | +import java.util.List; | |
16 | + | |
17 | +/** | |
18 | + * @author hongtao.zhao | |
19 | + * @since 2023-06-03 | |
20 | + */ | |
21 | +@Service | |
22 | +public class ProductCategoryConverter { | |
23 | + | |
24 | + public ProductCategoryVO convertToProductCategoryVO(ProductCategoryDO productCategoryDO){ | |
25 | + ProductCategoryVO productCategoryVO = new ProductCategoryVO(); | |
26 | + productCategoryVO.setId(productCategoryDO.getId()); | |
27 | + productCategoryVO.setName(productCategoryDO.getName()); | |
28 | + productCategoryVO.setFileKey(productCategoryDO.getFileKey()); | |
29 | + if(StringUtils.isNotBlank(productCategoryDO.getFileKey())){ | |
30 | + productCategoryVO.setImageUrl(Constant.FILE_PATH + productCategoryDO.getFileKey()); | |
31 | + } | |
32 | + return productCategoryVO; | |
33 | + } | |
34 | + | |
35 | + public ProductCategoryResultVO convertToProductCategoryResultVO(List<ProductCategoryVO> energyMaterialCategoryList, | |
36 | + List<ProductCategoryVO> laboratoryConsumables, | |
37 | + List<ProductCategoryVO> lowDimensionalMaterials, | |
38 | + List<ProductCategoryVO> deviceCategoryList, | |
39 | + List<ProductFunctionVO> productFunctionVOS | |
40 | + ){ | |
41 | + ProductCategoryResultVO productCategoryResultVO = new ProductCategoryResultVO(); | |
42 | + List<ProductCategoryDisplayVO> list = new ArrayList<>(); | |
43 | + list.add(this.convertToProductCategoryDisplayVO(RootCategoryEnum.ENERGY_MATERIAL, energyMaterialCategoryList,productFunctionVOS)); | |
44 | + list.add(this.convertToProductCategoryDisplayVO(RootCategoryEnum.LABORATORY_CONSUMABLE, laboratoryConsumables,null)); | |
45 | + list.add(this.convertToProductCategoryDisplayVO(RootCategoryEnum.LOW_DIMENSIONAL_MATERIAL, lowDimensionalMaterials,null)); | |
46 | + list.add(this.convertToProductCategoryDisplayVO(RootCategoryEnum.DEVICE, deviceCategoryList,null)); | |
47 | + productCategoryResultVO.setRootCategoryList(list); | |
48 | + return productCategoryResultVO; | |
49 | + } | |
50 | + | |
51 | + public ProductCategoryDisplayVO convertToProductCategoryDisplayVO(RootCategoryEnum rootCategoryEnum,List<ProductCategoryVO> list,List<ProductFunctionVO> productFunctionVOS){ | |
52 | + ProductCategoryDisplayVO productCategoryDisplayVO = new ProductCategoryDisplayVO(); | |
53 | + productCategoryDisplayVO.setCategoryDisplayName(rootCategoryEnum.getName()); | |
54 | + productCategoryDisplayVO.setOrder(rootCategoryEnum.getOrder()); | |
55 | + productCategoryDisplayVO.setList(list); | |
56 | + productCategoryDisplayVO.setProductFunctions(productFunctionVOS); | |
57 | + return productCategoryDisplayVO; | |
58 | + } | |
59 | + | |
60 | + public ProductFunctionVO convertToProductFunctionVO(ProductFunctionDO productFunctionDO){ | |
61 | + ProductFunctionVO productFunctionVO = new ProductFunctionVO(); | |
62 | + productFunctionVO.setId(productFunctionDO.getId()); | |
63 | + productFunctionVO.setName(productFunctionDO.getName()); | |
64 | + return productFunctionVO; | |
65 | + } | |
66 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/converter/ProductConverter.java
0 → 100644
1 | +package com.canrd.shop.converter; | |
2 | + | |
3 | +import cn.hutool.core.collection.CollectionUtil; | |
4 | +import com.alibaba.fastjson.JSON; | |
5 | +import com.canrd.shop.common.constant.Constant; | |
6 | +import com.canrd.shop.common.utils.StringUtils; | |
7 | +import com.canrd.shop.module.dto.ProductDO; | |
8 | +import com.canrd.shop.module.dto.ProductImage; | |
9 | +import com.canrd.shop.module.dto.TicketTypeDO; | |
10 | +import com.canrd.shop.module.vo.ProductVO; | |
11 | +import com.canrd.shop.module.vo.TickeyTypeVO; | |
12 | +import org.springframework.stereotype.Service; | |
13 | + | |
14 | +import java.util.List; | |
15 | + | |
16 | +/** | |
17 | + * @author hongtao.zhao | |
18 | + * @since 2023-06-03 | |
19 | + */ | |
20 | +@Service | |
21 | +public class ProductConverter { | |
22 | + | |
23 | + public ProductVO convertToProductVO(ProductDO productDO) { | |
24 | + ProductVO productVO = new ProductVO(); | |
25 | + productVO.setId(productDO.getId()); | |
26 | + productVO.setCreatedate(productDO.getCreatedate()); | |
27 | + productVO.setModifydate(productDO.getModifydate()); | |
28 | + productVO.setDescription(productDO.getDescription()); | |
29 | + productVO.setFreezestore(productDO.getFreezestore()); | |
30 | + productVO.setHtmlfilepath(productDO.getHtmlfilepath()); | |
31 | + productVO.setIsbest(productDO.getIsbest()); | |
32 | + productVO.setIshot(productDO.getIshot()); | |
33 | + productVO.setIsmarketable(productDO.getIsmarketable()); | |
34 | + productVO.setIsnew(productDO.getIsnew()); | |
35 | + productVO.setMarketprice(productDO.getMarketprice()); | |
36 | + productVO.setMetadescription(productDO.getMetadescription()); | |
37 | + productVO.setMetakeywords(productDO.getMetakeywords()); | |
38 | + productVO.setName(productDO.getName()); | |
39 | + productVO.setEnglishname(productDO.getEnglishname()); | |
40 | + productVO.setModel(productDO.getModel()); | |
41 | + productVO.setExterior(productDO.getExterior()); | |
42 | + productVO.setBasecore1(productDO.getBasecore1()); | |
43 | + productVO.setBasename2(productDO.getBasename2()); | |
44 | + productVO.setBasecore2(productDO.getBasecore2()); | |
45 | + productVO.setBasename3(productDO.getBasename3()); | |
46 | + productVO.setBasecore3(productDO.getBasecore3()); | |
47 | + productVO.setBasename4(productDO.getBasename4()); | |
48 | + productVO.setBasecore4(productDO.getBasecore4()); | |
49 | + productVO.setBasename5(productDO.getBasename5()); | |
50 | + productVO.setBasecore5(productDO.getBasecore5()); | |
51 | + productVO.setBasename6(productDO.getBasename6()); | |
52 | + productVO.setBasecore6(productDO.getBasecore6()); | |
53 | + productVO.setBasename7(productDO.getBasename7()); | |
54 | + productVO.setBasecore7(productDO.getBasecore7()); | |
55 | + productVO.setBasename8(productDO.getBasename8()); | |
56 | + productVO.setBasecore8(productDO.getBasecore8()); | |
57 | + productVO.setBasename1(productDO.getBasename1()); | |
58 | + productVO.setPoint(productDO.getPoint()); | |
59 | + productVO.setPrice(productDO.getPrice()); | |
60 | + productVO.setProductimageliststore(productDO.getProductimageliststore()); | |
61 | + productVO.setProductsn(productDO.getProductsn()); | |
62 | + productVO.setStore(productDO.getStore()); | |
63 | + productVO.setWeight(productDO.getWeight()); | |
64 | + productVO.setWeightunit(productDO.getWeightunit()); | |
65 | + productVO.setBrandId(productDO.getBrandId()); | |
66 | + productVO.setProductcategoryId(productDO.getProductcategoryId()); | |
67 | + productVO.setProductcategoryName(productDO.getProductcategoryName()); | |
68 | + productVO.setProductTypeId(productDO.getProductTypeId()); | |
69 | + productVO.setProducttypeName(productDO.getProducttypeName()); | |
70 | + productVO.setIntroduction(productDO.getIntroduction()); | |
71 | + productVO.setStorage(productDO.getStorage()); | |
72 | + productVO.setPhysicalproperty(productDO.getPhysicalproperty()); | |
73 | + productVO.setAdvantage(productDO.getAdvantage()); | |
74 | + productVO.setWiki(productDO.getWiki()); | |
75 | + if (StringUtils.isNotBlank(productDO.getProductimageliststore())) { | |
76 | + List<ProductImage> productImageList = JSON.parseArray(productDO.getProductimageliststore(), ProductImage.class); | |
77 | + if (CollectionUtil.isNotEmpty(productImageList) && StringUtils.isNotBlank(productImageList.get(0).getFileKey())) { | |
78 | + productVO.setImageUrl(Constant.FILE_PATH + productImageList.get(0).getFileKey()); | |
79 | + } | |
80 | + } else { | |
81 | + productVO.setImageUrl(Constant.FILE_PATH + Constant.DEFAULT_FILE_KEY); | |
82 | + } | |
83 | + return productVO; | |
84 | + } | |
85 | + | |
86 | + public TickeyTypeVO convertToTickeyTypeVO(TicketTypeDO ticketTypeDO){ | |
87 | + TickeyTypeVO tickeyTypeVO = new TickeyTypeVO(); | |
88 | + tickeyTypeVO.setRank(ticketTypeDO.getRank()); | |
89 | + tickeyTypeVO.setTypeName(ticketTypeDO.getTypeName()); | |
90 | + tickeyTypeVO.setPrice(ticketTypeDO.getPrice()); | |
91 | + return tickeyTypeVO; | |
92 | + } | |
93 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/mapper/BrandMapper.java
0 → 100644
1 | +package com.canrd.shop.mapper; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
4 | +import com.canrd.shop.module.dto.BrandDO; | |
5 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
6 | + | |
7 | +/** | |
8 | + * @author hongtao.zhao | |
9 | + * @since 2023-06-03 | |
10 | + */ | |
11 | +public interface BrandMapper extends BaseMapper<BrandDO> { | |
12 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/mapper/ProductAttributeMapStoreMapper.java
0 → 100644
1 | +package com.canrd.shop.mapper; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
4 | +import com.canrd.shop.module.dto.ProductAttributeDO; | |
5 | +import com.canrd.shop.module.dto.ProductAttributeMapStoreDO; | |
6 | + | |
7 | +/** | |
8 | + * @author hongtao.zhao | |
9 | + * @since 2023-06-17 | |
10 | + */ | |
11 | +public interface ProductAttributeMapStoreMapper extends BaseMapper<ProductAttributeMapStoreDO> { | |
12 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/mapper/ProductAttributeMapper.java
0 → 100644
1 | +package com.canrd.shop.mapper; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
4 | +import com.canrd.shop.module.dto.BrandDO; | |
5 | +import com.canrd.shop.module.dto.ProductAttributeDO; | |
6 | + | |
7 | +/** | |
8 | + * @author hongtao.zhao | |
9 | + * @since 2023-06-17 | |
10 | + */ | |
11 | +public interface ProductAttributeMapper extends BaseMapper<ProductAttributeDO> { | |
12 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/mapper/ProductCategoryMapper.java
0 → 100644
1 | +package com.canrd.shop.mapper; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
4 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
5 | +import com.canrd.shop.module.dto.ProductDO; | |
6 | +import org.apache.ibatis.annotations.Mapper; | |
7 | + | |
8 | +/** | |
9 | + * @author hongtao.zhao | |
10 | + * @since 2023-06-03 | |
11 | + */ | |
12 | +@Mapper | |
13 | +public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> { | |
14 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/mapper/ProductFunctionMapper.java
0 → 100644
1 | +package com.canrd.shop.mapper; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
4 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
5 | +import com.canrd.shop.module.dto.ProductFunctionDO; | |
6 | +import org.apache.ibatis.annotations.Mapper; | |
7 | + | |
8 | +/** | |
9 | + * @author hongtao.zhao | |
10 | + * @since 2023-06-10 | |
11 | + */ | |
12 | +@Mapper | |
13 | +public interface ProductFunctionMapper extends BaseMapper<ProductFunctionDO> { | |
14 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/mapper/ProductMapper.java
1 | 1 | package com.canrd.shop.mapper; |
2 | 2 | |
3 | +import com.baomidou.mybatisplus.core.conditions.Wrapper; | |
4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
3 | 5 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
6 | +import com.baomidou.mybatisplus.core.metadata.IPage; | |
7 | +import com.baomidou.mybatisplus.core.toolkit.Constants; | |
8 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |
4 | 9 | import com.canrd.shop.module.dto.ProductDO; |
10 | +import com.canrd.shop.module.vo.ProductQueryVO; | |
5 | 11 | import org.apache.ibatis.annotations.Mapper; |
12 | +import org.apache.ibatis.annotations.Param; | |
13 | +import org.apache.ibatis.annotations.Select; | |
14 | + | |
15 | +import java.util.List; | |
6 | 16 | |
7 | 17 | /** |
8 | 18 | * (Product)表数据库访问层 |
... | ... | @@ -14,5 +24,8 @@ import org.apache.ibatis.annotations.Mapper; |
14 | 24 | public interface ProductMapper extends BaseMapper<ProductDO> { |
15 | 25 | |
16 | 26 | |
27 | + IPage<ProductDO> selectAll(Page<ProductQueryVO> productQueryVOPage, @Param(Constants.WRAPPER) Wrapper<ProductQueryVO> wrapper); | |
28 | + | |
29 | + List<ProductDO> selectList(@Param(Constants.WRAPPER) QueryWrapper<ProductQueryVO> queryWrapper); | |
17 | 30 | } |
18 | 31 | ... | ... |
shop/src/main/java/com/canrd/shop/mapper/TicketTypeMapper.java
0 → 100644
1 | +package com.canrd.shop.mapper; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
4 | +import com.canrd.shop.module.dto.ProductFunctionDO; | |
5 | +import com.canrd.shop.module.dto.TicketTypeDO; | |
6 | + | |
7 | +/** | |
8 | + * @author hongtao.zhao | |
9 | + * @since 2023-06-17 | |
10 | + */ | |
11 | +public interface TicketTypeMapper extends BaseMapper<TicketTypeDO> { | |
12 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/dto/BrandDO.java
0 → 100644
1 | +package com.canrd.shop.module.dto; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableName; | |
4 | +import lombok.AllArgsConstructor; | |
5 | +import lombok.Data; | |
6 | +import lombok.EqualsAndHashCode; | |
7 | +import lombok.NoArgsConstructor; | |
8 | +import lombok.ToString; | |
9 | +import lombok.experimental.SuperBuilder; | |
10 | + | |
11 | +/** | |
12 | + * @author hongtao.zhao | |
13 | + * @since 2023-06-03 | |
14 | + */ | |
15 | +@TableName("brand") | |
16 | +@Data | |
17 | +@AllArgsConstructor | |
18 | +@ToString | |
19 | +@NoArgsConstructor | |
20 | +@EqualsAndHashCode(callSuper = false) | |
21 | +@SuperBuilder | |
22 | +public class BrandDO { | |
23 | + | |
24 | + private String id; | |
25 | + | |
26 | + private String name; | |
27 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/dto/ProductAttributeDO.java
0 → 100644
1 | +package com.canrd.shop.module.dto; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableField; | |
4 | +import com.baomidou.mybatisplus.annotation.TableName; | |
5 | +import lombok.AllArgsConstructor; | |
6 | +import lombok.Data; | |
7 | +import lombok.EqualsAndHashCode; | |
8 | +import lombok.NoArgsConstructor; | |
9 | +import lombok.ToString; | |
10 | +import lombok.experimental.SuperBuilder; | |
11 | + | |
12 | +/** | |
13 | + * @author hongtao.zhao | |
14 | + * @since 2023-06-17 | |
15 | + */ | |
16 | +@TableName("productattribute") | |
17 | +@Data | |
18 | +@AllArgsConstructor | |
19 | +@ToString | |
20 | +@NoArgsConstructor | |
21 | +@EqualsAndHashCode(callSuper = false) | |
22 | +@SuperBuilder | |
23 | +public class ProductAttributeDO { | |
24 | + | |
25 | + private String id; | |
26 | + | |
27 | + private String name; | |
28 | + | |
29 | + @TableField(value = "orderList") | |
30 | + private Integer orderList; | |
31 | + | |
32 | + @TableField(value = "productType_id") | |
33 | + private String productTypeId; | |
34 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/dto/ProductAttributeMapStoreDO.java
0 → 100644
1 | +package com.canrd.shop.module.dto; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableField; | |
4 | +import com.baomidou.mybatisplus.annotation.TableName; | |
5 | +import lombok.AllArgsConstructor; | |
6 | +import lombok.Data; | |
7 | +import lombok.EqualsAndHashCode; | |
8 | +import lombok.Getter; | |
9 | +import lombok.NoArgsConstructor; | |
10 | +import lombok.ToString; | |
11 | +import lombok.experimental.SuperBuilder; | |
12 | + | |
13 | +/** | |
14 | + * @author hongtao.zhao | |
15 | + * @since 2023-06-17 | |
16 | + */ | |
17 | +@TableName("product_productattributemapstore") | |
18 | +@Data | |
19 | +@AllArgsConstructor | |
20 | +@ToString | |
21 | +@NoArgsConstructor | |
22 | +@EqualsAndHashCode(callSuper = false) | |
23 | +@SuperBuilder | |
24 | +@Getter | |
25 | +public class ProductAttributeMapStoreDO { | |
26 | + | |
27 | + private String productId; | |
28 | + | |
29 | + @TableField(value = "mapkey_id") | |
30 | + private String mapKeyId; | |
31 | + | |
32 | + private String element; | |
33 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/dto/ProductCategoryDO.java
0 → 100644
1 | +package com.canrd.shop.module.dto; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableField; | |
4 | +import com.baomidou.mybatisplus.annotation.TableName; | |
5 | +import lombok.AllArgsConstructor; | |
6 | +import lombok.Data; | |
7 | +import lombok.EqualsAndHashCode; | |
8 | +import lombok.NoArgsConstructor; | |
9 | +import lombok.ToString; | |
10 | +import lombok.experimental.SuperBuilder; | |
11 | + | |
12 | +import java.io.Serializable; | |
13 | + | |
14 | +/** | |
15 | + * @author hongtao.zhao | |
16 | + * @since 2023-06-03 | |
17 | + */ | |
18 | +@TableName("productcategory") | |
19 | +@Data | |
20 | +@AllArgsConstructor | |
21 | +@ToString | |
22 | +@NoArgsConstructor | |
23 | +@EqualsAndHashCode(callSuper = false) | |
24 | +@SuperBuilder | |
25 | +public class ProductCategoryDO implements Serializable { | |
26 | + | |
27 | + /** | |
28 | + * 分类id | |
29 | + */ | |
30 | + private String id; | |
31 | + | |
32 | + private String parentId; | |
33 | + | |
34 | + private String name; | |
35 | + | |
36 | + private String path; | |
37 | + | |
38 | + @TableField(value = "fileKey") | |
39 | + private String fileKey; | |
40 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/dto/ProductDO.java
1 | 1 | package com.canrd.shop.module.dto; |
2 | 2 | |
3 | +import com.baomidou.mybatisplus.annotation.TableField; | |
3 | 4 | import com.baomidou.mybatisplus.annotation.TableName; |
4 | 5 | import lombok.*; |
5 | 6 | import lombok.experimental.SuperBuilder; |
... | ... | @@ -110,8 +111,6 @@ public class ProductDO implements Serializable { |
110 | 111 | |
111 | 112 | private String productcategoryName; |
112 | 113 | |
113 | - private String producttypeId; | |
114 | - | |
115 | 114 | private String producttypeName; |
116 | 115 | |
117 | 116 | private String introduction; |
... | ... | @@ -124,4 +123,15 @@ public class ProductDO implements Serializable { |
124 | 123 | |
125 | 124 | private String wiki; |
126 | 125 | |
126 | + @TableField(value = "productFileKey") | |
127 | + private String productFileKey; | |
128 | + | |
129 | + @TableField(value = "productType_id") | |
130 | + private String productTypeId; | |
131 | + | |
132 | + @TableField(exist = false) | |
133 | + private Integer similar; | |
134 | + @TableField(exist = false) | |
135 | + private Integer ttsTotalSimilar=0; | |
136 | + | |
127 | 137 | } | ... | ... |
shop/src/main/java/com/canrd/shop/module/dto/ProductFunctionDO.java
0 → 100644
1 | +package com.canrd.shop.module.dto; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableName; | |
4 | +import lombok.AllArgsConstructor; | |
5 | +import lombok.Data; | |
6 | +import lombok.EqualsAndHashCode; | |
7 | +import lombok.NoArgsConstructor; | |
8 | +import lombok.ToString; | |
9 | +import lombok.experimental.SuperBuilder; | |
10 | + | |
11 | +/** | |
12 | + * @author hongtao.zhao | |
13 | + * @since 2023-06-10 | |
14 | + */ | |
15 | +@TableName("productfunction") | |
16 | +@Data | |
17 | +@AllArgsConstructor | |
18 | +@ToString | |
19 | +@NoArgsConstructor | |
20 | +@EqualsAndHashCode(callSuper = false) | |
21 | +@SuperBuilder | |
22 | +public class ProductFunctionDO { | |
23 | + | |
24 | + private String id; | |
25 | + | |
26 | + private String name; | |
27 | + | |
28 | + | |
29 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/dto/ProductImage.java
0 → 100644
1 | +package com.canrd.shop.module.dto; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +/** | |
11 | + * @author hongtao.zhao | |
12 | + * @since 2023-06-10 | |
13 | + */ | |
14 | +@Data | |
15 | +@AllArgsConstructor | |
16 | +@ToString | |
17 | +@NoArgsConstructor | |
18 | +@EqualsAndHashCode(callSuper = false) | |
19 | +@SuperBuilder | |
20 | +public class ProductImage { | |
21 | + | |
22 | + private String id; | |
23 | + | |
24 | + private String fileKey; | |
25 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/dto/TicketTypeDO.java
0 → 100644
1 | +package com.canrd.shop.module.dto; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableField; | |
4 | +import com.baomidou.mybatisplus.annotation.TableName; | |
5 | +import lombok.AllArgsConstructor; | |
6 | +import lombok.Data; | |
7 | +import lombok.EqualsAndHashCode; | |
8 | +import lombok.NoArgsConstructor; | |
9 | +import lombok.ToString; | |
10 | +import lombok.experimental.SuperBuilder; | |
11 | + | |
12 | +import java.math.BigDecimal; | |
13 | + | |
14 | +/** | |
15 | + * @author hongtao.zhao | |
16 | + * @since 2023-06-17 | |
17 | + */ | |
18 | +@TableName("tickettype") | |
19 | +@Data | |
20 | +@AllArgsConstructor | |
21 | +@ToString | |
22 | +@NoArgsConstructor | |
23 | +@EqualsAndHashCode(callSuper = false) | |
24 | +@SuperBuilder | |
25 | +public class TicketTypeDO { | |
26 | + | |
27 | + private String id; | |
28 | + | |
29 | + @TableField(value = "productId") | |
30 | + private String productId; | |
31 | + | |
32 | + @TableField(value = "`rank`") | |
33 | + /** | |
34 | + * 产品名称/编码 | |
35 | + */ | |
36 | + private String rank; | |
37 | + | |
38 | + /** | |
39 | + * 规格型号 | |
40 | + */ | |
41 | + @TableField(value = "typeName") | |
42 | + private String typeName; | |
43 | + | |
44 | + /** | |
45 | + * 产品价格 | |
46 | + */ | |
47 | + private BigDecimal price; | |
48 | + @TableField(value = "serialNumber") | |
49 | + private Integer serialNumber; | |
50 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/BrandQueryVO.java
0 → 100644
1 | +package com.canrd.shop.module.vo; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +import java.io.Serializable; | |
11 | + | |
12 | +/** | |
13 | + * @author hongtao.zhao | |
14 | + * @since 2023-06-03 | |
15 | + */ | |
16 | +@Data | |
17 | +@AllArgsConstructor | |
18 | +@ToString | |
19 | +@NoArgsConstructor | |
20 | +@EqualsAndHashCode(callSuper = false) | |
21 | +@SuperBuilder | |
22 | +public class BrandQueryVO extends BasePageVO implements Serializable { | |
23 | + | |
24 | + private String id; | |
25 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductAttributeVO.java
0 → 100644
1 | +package com.canrd.shop.module.vo; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +/** | |
11 | + * @author hongtao.zhao | |
12 | + * @since 2023-06-17 | |
13 | + */ | |
14 | +@Data | |
15 | +@AllArgsConstructor | |
16 | +@ToString | |
17 | +@NoArgsConstructor | |
18 | +@EqualsAndHashCode(callSuper = false) | |
19 | +@SuperBuilder | |
20 | +public class ProductAttributeVO { | |
21 | + | |
22 | + private String name; | |
23 | + | |
24 | + private String value; | |
25 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductCategoryDisplayVO.java
0 → 100644
1 | +package com.canrd.shop.module.vo; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +import java.util.List; | |
11 | + | |
12 | +/** | |
13 | + * @author hongtao.zhao | |
14 | + * @since 2023-06-04 | |
15 | + */ | |
16 | +@Data | |
17 | +@AllArgsConstructor | |
18 | +@ToString | |
19 | +@NoArgsConstructor | |
20 | +@EqualsAndHashCode(callSuper = false) | |
21 | +@SuperBuilder | |
22 | +public class ProductCategoryDisplayVO { | |
23 | + | |
24 | + private String categoryDisplayName; | |
25 | + | |
26 | + private int order; | |
27 | + | |
28 | + private List<ProductCategoryVO> list; | |
29 | + | |
30 | + /** | |
31 | + * 材料功能 | |
32 | + */ | |
33 | + private List<ProductFunctionVO> productFunctions; | |
34 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductCategoryQueryVO.java
0 → 100644
1 | +package com.canrd.shop.module.vo; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +import java.io.Serializable; | |
11 | + | |
12 | +/** | |
13 | + * @author hongtao.zhao | |
14 | + * @since 2023-06-03 | |
15 | + */ | |
16 | +@Data | |
17 | +@AllArgsConstructor | |
18 | +@ToString | |
19 | +@EqualsAndHashCode(callSuper = false) | |
20 | +@SuperBuilder | |
21 | +public class ProductCategoryQueryVO extends BasePageVO implements Serializable { | |
22 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductCategoryResultVO.java
0 → 100644
1 | +package com.canrd.shop.module.vo; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +import java.util.List; | |
11 | + | |
12 | +/** | |
13 | + * @author hongtao.zhao | |
14 | + * @since 2023-06-03 | |
15 | + */ | |
16 | +@Data | |
17 | +@AllArgsConstructor | |
18 | +@ToString | |
19 | +@NoArgsConstructor | |
20 | +@EqualsAndHashCode(callSuper = false) | |
21 | +@SuperBuilder | |
22 | +public class ProductCategoryResultVO { | |
23 | + | |
24 | + private List<ProductCategoryDisplayVO> rootCategoryList; | |
25 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductCategoryVO.java
0 → 100644
1 | +package com.canrd.shop.module.vo; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +import java.io.Serializable; | |
11 | +import java.util.List; | |
12 | + | |
13 | +/** | |
14 | + * @author hongtao.zhao | |
15 | + * @since 2023-06-03 | |
16 | + */ | |
17 | +@Data | |
18 | +@AllArgsConstructor | |
19 | +@ToString | |
20 | +@NoArgsConstructor | |
21 | +@EqualsAndHashCode(callSuper = false) | |
22 | +@SuperBuilder | |
23 | +public class ProductCategoryVO implements Serializable { | |
24 | + | |
25 | + /** | |
26 | + * 分类id | |
27 | + */ | |
28 | + private String id; | |
29 | + | |
30 | + /** | |
31 | + * 分类名称 | |
32 | + */ | |
33 | + private String name; | |
34 | + | |
35 | + /** | |
36 | + * 排序 | |
37 | + */ | |
38 | + private Integer orderList; | |
39 | + | |
40 | + /** | |
41 | + * 分类图片 | |
42 | + */ | |
43 | + private String imageUrl; | |
44 | + | |
45 | + | |
46 | + private String fileKey; | |
47 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductFunctionVO.java
0 → 100644
1 | +package com.canrd.shop.module.vo; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +/** | |
11 | + * @author hongtao.zhao | |
12 | + * @since 2023-06-10 | |
13 | + */ | |
14 | +@Data | |
15 | +@AllArgsConstructor | |
16 | +@ToString | |
17 | +@NoArgsConstructor | |
18 | +@EqualsAndHashCode(callSuper = false) | |
19 | +@SuperBuilder | |
20 | +public class ProductFunctionVO { | |
21 | + | |
22 | + private String id; | |
23 | + | |
24 | + private String name; | |
25 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductQueryVO.java
... | ... | @@ -23,9 +23,27 @@ public class ProductQueryVO extends BasePageVO implements Serializable { |
23 | 23 | |
24 | 24 | private List<Long> ids; |
25 | 25 | |
26 | - | |
26 | + /** | |
27 | + * 产品id | |
28 | + */ | |
27 | 29 | private String id; |
28 | 30 | |
31 | + private String keyword; | |
32 | + | |
33 | + /** | |
34 | + * 顶级产品分类 | |
35 | + */ | |
36 | + private String rootProductCategoryId; | |
37 | + | |
38 | + /** | |
39 | + * 产品分类id | |
40 | + */ | |
41 | + private String productCategoryId; | |
42 | + | |
43 | + /** | |
44 | + * 产品功能id | |
45 | + */ | |
46 | + private String productFunctionId; | |
29 | 47 | |
30 | 48 | } |
31 | 49 | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductVO.java
... | ... | @@ -5,6 +5,7 @@ import lombok.experimental.SuperBuilder; |
5 | 5 | |
6 | 6 | import java.io.Serializable; |
7 | 7 | import java.util.Date; |
8 | +import java.util.List; | |
8 | 9 | |
9 | 10 | /** |
10 | 11 | * (Product)实体类 |
... | ... | @@ -109,8 +110,6 @@ public class ProductVO implements Serializable { |
109 | 110 | |
110 | 111 | private String productcategoryName; |
111 | 112 | |
112 | - private String producttypeId; | |
113 | - | |
114 | 113 | private String producttypeName; |
115 | 114 | |
116 | 115 | private String introduction; |
... | ... | @@ -123,5 +122,23 @@ public class ProductVO implements Serializable { |
123 | 122 | |
124 | 123 | private String wiki; |
125 | 124 | |
125 | + private String imageUrl; | |
126 | + | |
127 | + /** | |
128 | + * 品牌名 | |
129 | + */ | |
130 | + private String brandName; | |
131 | + | |
132 | + /** | |
133 | + * 产品规格参数 | |
134 | + */ | |
135 | + private List<ProductAttributeVO> productAttributeList; | |
136 | + | |
137 | + private String productTypeId; | |
138 | + | |
139 | + /** | |
140 | + * 产品规格 | |
141 | + */ | |
142 | + private List<TickeyTypeVO> ticketTypes; | |
126 | 143 | |
127 | 144 | } | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/TickeyTypeVO.java
0 → 100644
1 | +package com.canrd.shop.module.vo; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +import java.math.BigDecimal; | |
11 | + | |
12 | +/** | |
13 | + * @author hongtao.zhao | |
14 | + * @since 2023-06-17 | |
15 | + */ | |
16 | +@Data | |
17 | +@AllArgsConstructor | |
18 | +@ToString | |
19 | +@NoArgsConstructor | |
20 | +@EqualsAndHashCode(callSuper = false) | |
21 | +@SuperBuilder | |
22 | +public class TickeyTypeVO { | |
23 | + | |
24 | + /** | |
25 | + * 产品名称/编码 | |
26 | + */ | |
27 | + private String rank; | |
28 | + | |
29 | + /** | |
30 | + * 规格型号 | |
31 | + */ | |
32 | + private String typeName; | |
33 | + | |
34 | + /** | |
35 | + * 产品价格 | |
36 | + */ | |
37 | + private BigDecimal price; | |
38 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/BrandService.java
0 → 100644
1 | +package com.canrd.shop.service; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.extension.service.IService; | |
4 | +import com.canrd.shop.common.constant.ServerResult; | |
5 | +import com.canrd.shop.module.dto.BrandDO; | |
6 | +import com.canrd.shop.module.vo.BrandQueryVO; | |
7 | +import com.canrd.shop.module.vo.ProductQueryVO; | |
8 | + | |
9 | +/** | |
10 | + * @author hongtao.zhao | |
11 | + * @since 2023-06-03 | |
12 | + */ | |
13 | +public interface BrandService extends IService<BrandDO> { | |
14 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/ProductAttributeMapStoreService.java
0 → 100644
1 | +package com.canrd.shop.service; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.extension.service.IService; | |
4 | +import com.canrd.shop.module.dto.ProductAttributeMapStoreDO; | |
5 | + | |
6 | +import java.util.List; | |
7 | + | |
8 | +/** | |
9 | + * @author hongtao.zhao | |
10 | + * @since 2023-06-17 | |
11 | + */ | |
12 | +public interface ProductAttributeMapStoreService extends IService<ProductAttributeMapStoreDO> { | |
13 | + | |
14 | + List<ProductAttributeMapStoreDO> selectByProductIdAndMapKeyIds(String productId,List<String> mapKeyIds); | |
15 | + | |
16 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/ProductAttributeService.java
0 → 100644
1 | +package com.canrd.shop.service; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.extension.service.IService; | |
4 | +import com.canrd.shop.module.dto.BrandDO; | |
5 | +import com.canrd.shop.module.dto.ProductAttributeDO; | |
6 | + | |
7 | +import java.util.List; | |
8 | + | |
9 | +/** | |
10 | + * @author hongtao.zhao | |
11 | + * @since 2023-06-17 | |
12 | + */ | |
13 | +public interface ProductAttributeService extends IService<ProductAttributeDO> { | |
14 | + | |
15 | + List<ProductAttributeDO> selectByProductTypeId(String productTypeId); | |
16 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/ProductCategoryService.java
0 → 100644
1 | +package com.canrd.shop.service; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.extension.service.IService; | |
4 | +import com.canrd.shop.common.constant.ServerResult; | |
5 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
6 | +import com.canrd.shop.module.dto.ProductDO; | |
7 | +import com.canrd.shop.module.vo.ProductCategoryQueryVO; | |
8 | +import com.canrd.shop.module.vo.ProductQueryVO; | |
9 | + | |
10 | +/** | |
11 | + * @author hongtao.zhao | |
12 | + * @since 2023-06-03 | |
13 | + */ | |
14 | +public interface ProductCategoryService extends IService<ProductCategoryDO> { | |
15 | + | |
16 | + /** | |
17 | + * 查询分类信息 | |
18 | + * @param productCategoryQueryVO | |
19 | + * @return | |
20 | + */ | |
21 | + ServerResult category(ProductCategoryQueryVO productCategoryQueryVO); | |
22 | + | |
23 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/ProductFunctionService.java
0 → 100644
1 | +package com.canrd.shop.service; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.extension.service.IService; | |
4 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
5 | +import com.canrd.shop.module.dto.ProductFunctionDO; | |
6 | + | |
7 | +/** | |
8 | + * @author hongtao.zhao | |
9 | + * @since 2023-06-10 | |
10 | + */ | |
11 | +public interface ProductFunctionService extends IService<ProductFunctionDO> { | |
12 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/ProductService.java
... | ... | @@ -3,6 +3,7 @@ package com.canrd.shop.service; |
3 | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
4 | 4 | import com.canrd.shop.common.constant.ServerResult; |
5 | 5 | import com.canrd.shop.module.dto.ProductDO; |
6 | +import com.canrd.shop.module.vo.ProductCategoryQueryVO; | |
6 | 7 | import com.canrd.shop.module.vo.ProductQueryVO; |
7 | 8 | import com.canrd.shop.module.vo.ProductVO; |
8 | 9 | |
... | ... | @@ -31,6 +32,13 @@ public interface ProductService extends IService<ProductDO> { |
31 | 32 | ServerResult list(ProductQueryVO productQueryVO); |
32 | 33 | |
33 | 34 | /** |
35 | + * 根据相似度查询 | |
36 | + * @param productQueryVO | |
37 | + * @return | |
38 | + */ | |
39 | + ServerResult listBySimilar(ProductQueryVO productQueryVO); | |
40 | + | |
41 | + /** | |
34 | 42 | * 新增数据 |
35 | 43 | * |
36 | 44 | * @param productVO 数据VO |
... | ... | @@ -54,4 +62,7 @@ public interface ProductService extends IService<ProductDO> { |
54 | 62 | */ |
55 | 63 | ServerResult deleteById(ProductQueryVO productQueryVO); |
56 | 64 | |
65 | + ServerResult categorySearch(ProductQueryVO productQueryVO); | |
66 | + | |
67 | + ServerResult chatgpt(ProductQueryVO productQueryVO); | |
57 | 68 | } | ... | ... |
shop/src/main/java/com/canrd/shop/service/TicketTypeService.java
0 → 100644
1 | +package com.canrd.shop.service; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.extension.service.IService; | |
4 | +import com.canrd.shop.module.dto.ProductDO; | |
5 | +import com.canrd.shop.module.dto.TicketTypeDO; | |
6 | + | |
7 | +import java.util.List; | |
8 | + | |
9 | +/** | |
10 | + * @author hongtao.zhao | |
11 | + * @since 2023-06-17 | |
12 | + */ | |
13 | +public interface TicketTypeService extends IService<TicketTypeDO> { | |
14 | + | |
15 | + List<TicketTypeDO> selectByProductId(String producetId); | |
16 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/BrandServiceImpl.java
0 → 100644
1 | +package com.canrd.shop.service.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |
4 | +import com.canrd.shop.common.constant.ServerResult; | |
5 | +import com.canrd.shop.mapper.BrandMapper; | |
6 | +import com.canrd.shop.mapper.ProductCategoryMapper; | |
7 | +import com.canrd.shop.module.dto.BrandDO; | |
8 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
9 | +import com.canrd.shop.module.vo.BrandQueryVO; | |
10 | +import com.canrd.shop.service.BrandService; | |
11 | +import com.canrd.shop.service.ProductCategoryService; | |
12 | +import lombok.extern.slf4j.Slf4j; | |
13 | +import org.springframework.stereotype.Service; | |
14 | + | |
15 | +/** | |
16 | + * @author hongtao.zhao | |
17 | + * @since 2023-06-03 | |
18 | + */ | |
19 | +@Slf4j | |
20 | +@Service | |
21 | +public class BrandServiceImpl extends ServiceImpl<BrandMapper, BrandDO> implements BrandService { | |
22 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/LevenshteinDistanceService.java
0 → 100644
1 | +package com.canrd.shop.service.impl; | |
2 | + | |
3 | +public class LevenshteinDistanceService { | |
4 | + public static void main(String[] args) { | |
5 | + String keyword = "Nickel"; | |
6 | + | |
7 | + String product1 = "Nickel Cobalt Manganese NCM811 (polycrystalline) - B"; | |
8 | + String product2 = "扣式电池"; | |
9 | + String product3 = "扣式电池"; | |
10 | + String product4 = "扣式电池"; | |
11 | + String product5 = "扣式电池"; | |
12 | + String product6 = "扣式电池"; | |
13 | + System.out.println(String.format("%s vs %s = %s",keyword,product1,new LevenshteinDistanceService().LevenshteinDistancePercent(keyword, product1))); | |
14 | + | |
15 | + } | |
16 | + | |
17 | + private static int LowerOfThree(int first, int second, int third) { | |
18 | + int min = Math.min(first, second); | |
19 | + | |
20 | + return Math.min(min, third); | |
21 | + } | |
22 | + | |
23 | + private static int Levenshtein_Distance(String str1, String str2) { | |
24 | + int[][] Matrix; | |
25 | + int n = str1.length(); | |
26 | + int m = str2.length(); | |
27 | + | |
28 | + int temp = 0; | |
29 | + char ch1; | |
30 | + char ch2; | |
31 | + int i = 0; | |
32 | + int j = 0; | |
33 | + if (n == 0) { | |
34 | + return m; | |
35 | + } | |
36 | + if (m == 0) { | |
37 | + | |
38 | + return n; | |
39 | + } | |
40 | + Matrix = new int[n + 1][m + 1]; | |
41 | + | |
42 | + for (i = 0; i <= n; i++) { | |
43 | + //初始化第一列 | |
44 | + Matrix[i][0] = i; | |
45 | + } | |
46 | + | |
47 | + for (j = 0; j <= m; j++) { | |
48 | + //初始化第一行 | |
49 | + Matrix[0][j] = j; | |
50 | + } | |
51 | + | |
52 | + for (i = 1; i <= n; i++) { | |
53 | + ch1 = str1.charAt(i - 1); | |
54 | + for (j = 1; j <= m; j++) { | |
55 | + ch2 = str2.charAt(j - 1); | |
56 | + if (ch1 == ch2) { | |
57 | + temp = 0; | |
58 | + } else { | |
59 | + temp = 1; | |
60 | + } | |
61 | + Matrix[i][j] = LowerOfThree(Matrix[i - 1][j] + 1, Matrix[i][j - 1] + 1, Matrix[i - 1][j - 1] + temp); | |
62 | + } | |
63 | + } | |
64 | + | |
65 | + return Matrix[n][m]; | |
66 | + } | |
67 | + | |
68 | + | |
69 | + public static int LevenshteinDistancePercent(String str1, String str2) { | |
70 | + //int maxLenth = str1.Length > str2.Length ? str1.Length : str2.Length; | |
71 | + int val = Levenshtein_Distance(str1, str2); | |
72 | + return (int)((1 - (double) val / Math.max(str1.length(), str2.length()))*100); | |
73 | + } | |
74 | +} | |
0 | 75 | \ No newline at end of file | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/ProductAttributeMapStoreServiceImpl.java
0 → 100644
1 | +package com.canrd.shop.service.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
5 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |
6 | +import com.canrd.shop.mapper.ProductAttributeMapStoreMapper; | |
7 | +import com.canrd.shop.module.dto.ProductAttributeDO; | |
8 | +import com.canrd.shop.module.dto.ProductAttributeMapStoreDO; | |
9 | +import com.canrd.shop.service.ProductAttributeMapStoreService; | |
10 | +import org.springframework.stereotype.Service; | |
11 | +import org.springframework.util.CollectionUtils; | |
12 | + | |
13 | +import java.util.ArrayList; | |
14 | +import java.util.List; | |
15 | + | |
16 | +/** | |
17 | + * @author hongtao.zhao | |
18 | + * @since 2023-06-17 | |
19 | + */ | |
20 | +@Service | |
21 | +public class ProductAttributeMapStoreServiceImpl extends ServiceImpl<ProductAttributeMapStoreMapper, ProductAttributeMapStoreDO> implements ProductAttributeMapStoreService { | |
22 | + | |
23 | + @Override | |
24 | + public List<ProductAttributeMapStoreDO> selectByProductIdAndMapKeyIds(String productId, List<String> mapKeyIds) { | |
25 | + if(CollectionUtils.isEmpty(mapKeyIds)){ | |
26 | + return new ArrayList<>(); | |
27 | + } | |
28 | + LambdaQueryWrapper<ProductAttributeMapStoreDO> queryWapper = new LambdaQueryWrapper<ProductAttributeMapStoreDO>(); | |
29 | + queryWapper.eq(ProductAttributeMapStoreDO::getProductId,productId); | |
30 | + queryWapper.in(ProductAttributeMapStoreDO::getMapKeyId,mapKeyIds); | |
31 | + return this.baseMapper.selectList(queryWapper); | |
32 | + } | |
33 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/ProductAttributeServiceImpl.java
0 → 100644
1 | +package com.canrd.shop.service.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
4 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |
5 | +import com.canrd.shop.mapper.BrandMapper; | |
6 | +import com.canrd.shop.mapper.ProductAttributeMapper; | |
7 | +import com.canrd.shop.module.dto.BrandDO; | |
8 | +import com.canrd.shop.module.dto.ProductAttributeDO; | |
9 | +import com.canrd.shop.module.vo.ProductFunctionVO; | |
10 | +import com.canrd.shop.module.vo.ProductQueryVO; | |
11 | +import com.canrd.shop.service.BrandService; | |
12 | +import com.canrd.shop.service.ProductAttributeService; | |
13 | +import lombok.extern.slf4j.Slf4j; | |
14 | +import org.springframework.stereotype.Service; | |
15 | + | |
16 | +import java.util.List; | |
17 | + | |
18 | +/** | |
19 | + * @author hongtao.zhao | |
20 | + * @since 2023-06-17 | |
21 | + */ | |
22 | +@Slf4j | |
23 | +@Service | |
24 | +public class ProductAttributeServiceImpl extends ServiceImpl<ProductAttributeMapper, ProductAttributeDO> implements ProductAttributeService { | |
25 | + | |
26 | + | |
27 | + @Override | |
28 | + public List<ProductAttributeDO> selectByProductTypeId(String productTypeId) { | |
29 | + QueryWrapper<ProductAttributeDO> queryWapper = new QueryWrapper<ProductAttributeDO>(); | |
30 | + queryWapper.eq("productType_id",productTypeId); | |
31 | + queryWapper.orderByAsc("orderList"); | |
32 | + return baseMapper.selectList(queryWapper); | |
33 | + } | |
34 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/ProductCagegoryServiceImpl.java
0 → 100644
1 | +package com.canrd.shop.service.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |
4 | +import com.canrd.shop.common.constant.ServerResult; | |
5 | +import com.canrd.shop.common.enums.RootCategoryEnum; | |
6 | +import com.canrd.shop.converter.ProductCategoryConverter; | |
7 | +import com.canrd.shop.mapper.ProductCategoryMapper; | |
8 | +import com.canrd.shop.mapper.ProductMapper; | |
9 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
10 | +import com.canrd.shop.module.dto.ProductDO; | |
11 | +import com.canrd.shop.module.dto.ProductFunctionDO; | |
12 | +import com.canrd.shop.module.vo.ProductCategoryQueryVO; | |
13 | +import com.canrd.shop.module.vo.ProductCategoryResultVO; | |
14 | +import com.canrd.shop.module.vo.ProductCategoryVO; | |
15 | +import com.canrd.shop.module.vo.ProductFunctionVO; | |
16 | +import com.canrd.shop.service.ProductCategoryService; | |
17 | +import com.canrd.shop.service.ProductFunctionService; | |
18 | +import com.canrd.shop.service.ProductService; | |
19 | +import com.google.common.collect.Lists; | |
20 | +import lombok.extern.slf4j.Slf4j; | |
21 | +import org.springframework.beans.factory.annotation.Autowired; | |
22 | +import org.springframework.stereotype.Service; | |
23 | + | |
24 | +import java.util.List; | |
25 | +import java.util.stream.Collectors; | |
26 | + | |
27 | +/** | |
28 | + * @author hongtao.zhao | |
29 | + * @since 2023-06-03 | |
30 | + */ | |
31 | +@Slf4j | |
32 | +@Service | |
33 | +public class ProductCagegoryServiceImpl extends ServiceImpl<ProductCategoryMapper, ProductCategoryDO> implements ProductCategoryService { | |
34 | + | |
35 | + | |
36 | + @Autowired | |
37 | + private ProductCategoryConverter productCategoryConverter; | |
38 | + | |
39 | + @Autowired | |
40 | + private ProductFunctionService productFunctionService; | |
41 | + | |
42 | + @Override | |
43 | + public ServerResult category(ProductCategoryQueryVO productCategoryQueryVO) { | |
44 | + List<ProductCategoryDO> productCategoryDOList = this.list(); | |
45 | + List<ProductCategoryVO> energyMaterialCategoryList = Lists.newArrayList(); | |
46 | + List<ProductCategoryVO> laboratoryConsumables = Lists.newArrayList(); | |
47 | + List<ProductCategoryVO> lowDimensionalMaterials = Lists.newArrayList(); | |
48 | + List<ProductCategoryVO> deviceCategoryList = Lists.newArrayList(); | |
49 | + ProductCategoryDO last = null; | |
50 | + for (ProductCategoryDO productCategory : productCategoryDOList) { | |
51 | + if (last != null && productCategory.getPath().split(",").length==3) { | |
52 | + if (last.getName().contains(RootCategoryEnum.ENERGY_MATERIAL.getName())) { | |
53 | + energyMaterialCategoryList.add(productCategoryConverter.convertToProductCategoryVO(productCategory)); | |
54 | + } else if (last.getName().contains(RootCategoryEnum.LABORATORY_CONSUMABLE.getName())) { | |
55 | + laboratoryConsumables.add(productCategoryConverter.convertToProductCategoryVO(productCategory)); | |
56 | + } else if (last.getName().contains(RootCategoryEnum.LOW_DIMENSIONAL_MATERIAL.getName())) { | |
57 | + lowDimensionalMaterials.add(productCategoryConverter.convertToProductCategoryVO(productCategory)); | |
58 | + } else if (last.getName().contains(RootCategoryEnum.DEVICE.getName())) { | |
59 | + deviceCategoryList.add(productCategoryConverter.convertToProductCategoryVO(productCategory)); | |
60 | + } | |
61 | + } | |
62 | + if(productCategory.getPath().split(",").length==2) { | |
63 | + last = productCategory; | |
64 | + } | |
65 | + } | |
66 | + List<ProductFunctionDO> productFunctionDOList = productFunctionService.list(); | |
67 | + List<ProductFunctionVO> productFunctionVOS = productFunctionDOList.stream().map(productCategoryConverter::convertToProductFunctionVO).collect(Collectors.toList()); | |
68 | + ProductCategoryResultVO productCategoryResultVO = productCategoryConverter.convertToProductCategoryResultVO(energyMaterialCategoryList, | |
69 | + laboratoryConsumables, | |
70 | + lowDimensionalMaterials, | |
71 | + deviceCategoryList,productFunctionVOS); | |
72 | + return ServerResult.success().setData(productCategoryResultVO); | |
73 | + } | |
74 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/ProductFunctionServiceImpl.java
0 → 100644
1 | +package com.canrd.shop.service.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |
4 | +import com.canrd.shop.mapper.ProductCategoryMapper; | |
5 | +import com.canrd.shop.mapper.ProductFunctionMapper; | |
6 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
7 | +import com.canrd.shop.module.dto.ProductFunctionDO; | |
8 | +import com.canrd.shop.service.ProductCategoryService; | |
9 | +import com.canrd.shop.service.ProductFunctionService; | |
10 | +import org.springframework.stereotype.Service; | |
11 | + | |
12 | +/** | |
13 | + * @author hongtao.zhao | |
14 | + * @since 2023-06-10 | |
15 | + */ | |
16 | +@Service | |
17 | +public class ProductFunctionServiceImpl extends ServiceImpl<ProductFunctionMapper, ProductFunctionDO> implements ProductFunctionService { | |
18 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
... | ... | @@ -2,23 +2,41 @@ package com.canrd.shop.service.impl; |
2 | 2 | |
3 | 3 | import cn.hutool.core.bean.BeanUtil; |
4 | 4 | import cn.hutool.core.collection.CollUtil; |
5 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
5 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
6 | 6 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
7 | 7 | import com.baomidou.mybatisplus.core.metadata.IPage; |
8 | +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | |
8 | 9 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
9 | 10 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
10 | 11 | import com.canrd.shop.common.constant.ServerResult; |
12 | +import com.canrd.shop.common.utils.ChatGptUtil; | |
11 | 13 | import com.canrd.shop.common.utils.PageUtils; |
14 | +import com.canrd.shop.common.utils.StringUtils; | |
15 | +import com.canrd.shop.converter.ProductConverter; | |
12 | 16 | import com.canrd.shop.mapper.ProductMapper; |
17 | +import com.canrd.shop.module.dto.BrandDO; | |
18 | +import com.canrd.shop.module.dto.ProductAttributeDO; | |
19 | +import com.canrd.shop.module.dto.ProductAttributeMapStoreDO; | |
13 | 20 | import com.canrd.shop.module.dto.ProductDO; |
21 | +import com.canrd.shop.module.dto.TicketTypeDO; | |
22 | +import com.canrd.shop.module.vo.ProductAttributeVO; | |
14 | 23 | import com.canrd.shop.module.vo.ProductQueryVO; |
15 | 24 | import com.canrd.shop.module.vo.ProductVO; |
25 | +import com.canrd.shop.service.BrandService; | |
26 | +import com.canrd.shop.service.ProductAttributeMapStoreService; | |
27 | +import com.canrd.shop.service.ProductAttributeService; | |
16 | 28 | import com.canrd.shop.service.ProductService; |
29 | +import com.canrd.shop.service.TicketTypeService; | |
30 | +import com.google.common.collect.Lists; | |
31 | +import com.google.common.collect.Sets; | |
17 | 32 | import lombok.extern.slf4j.Slf4j; |
33 | +import org.springframework.beans.factory.annotation.Autowired; | |
18 | 34 | import org.springframework.stereotype.Service; |
19 | 35 | |
20 | -import java.util.List; | |
21 | -import java.util.Objects; | |
36 | +import java.io.IOException; | |
37 | +import java.util.*; | |
38 | +import java.util.function.Function; | |
39 | +import java.util.stream.Collectors; | |
22 | 40 | |
23 | 41 | /** |
24 | 42 | * (Product)表服务实现类 |
... | ... | @@ -31,6 +49,27 @@ import java.util.Objects; |
31 | 49 | public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> implements ProductService { |
32 | 50 | |
33 | 51 | |
52 | + @Autowired | |
53 | + private ProductMapper productMapper; | |
54 | + | |
55 | + @Autowired | |
56 | + private ProductConverter productConverter; | |
57 | + | |
58 | + @Autowired | |
59 | + private BrandService brandService; | |
60 | + | |
61 | + @Autowired | |
62 | + private ProductAttributeService productAttributeService; | |
63 | + | |
64 | + @Autowired | |
65 | + private ProductAttributeMapStoreService productAttributeMapStoreService; | |
66 | + | |
67 | + @Autowired | |
68 | + private TicketTypeService ticketTypeService; | |
69 | + | |
70 | + @Autowired | |
71 | + private ChatGptUtil chatGptUtil; | |
72 | + | |
34 | 73 | /** |
35 | 74 | * 通过ID查询单条数据 |
36 | 75 | * <p> |
... | ... | @@ -43,11 +82,39 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
43 | 82 | if (Objects.isNull(productQueryVO.getId())) { |
44 | 83 | return ServerResult.fail("id 不能为空"); |
45 | 84 | } |
46 | - ProductDO ProductDo = getById(productQueryVO.getId()); | |
47 | - if (Objects.isNull(ProductDo)) { | |
85 | + ProductDO productDO = getById(productQueryVO.getId()); | |
86 | + if (Objects.isNull(productDO)) { | |
48 | 87 | return ServerResult.success(null); |
49 | 88 | } |
50 | - return ServerResult.success(BeanUtil.copyProperties(ProductDo, ProductVO.class)); | |
89 | + ProductVO productVO = productConverter.convertToProductVO(productDO); | |
90 | + if (StringUtils.isNotBlank(productDO.getBrandId())) { | |
91 | + BrandDO brandDO = brandService.getById(productDO.getBrandId()); | |
92 | + if (Objects.nonNull(brandDO)) { | |
93 | + productVO.setBrandName(brandDO.getName()); | |
94 | + } | |
95 | + } | |
96 | + List<ProductAttributeDO> productAttributeDOS = productAttributeService.selectByProductTypeId(productDO.getProductTypeId()); | |
97 | + List<String> productAttributeIds = productAttributeDOS.stream().map(ProductAttributeDO::getId).collect(Collectors.toList()); | |
98 | + List<ProductAttributeMapStoreDO> productAttributeMapStoreDOS = productAttributeMapStoreService.selectByProductIdAndMapKeyIds(productDO.getId(),productAttributeIds); | |
99 | + if(CollectionUtils.isNotEmpty(productAttributeMapStoreDOS)){ | |
100 | + Map<String,ProductAttributeMapStoreDO> map = productAttributeMapStoreDOS.stream().collect(Collectors.toMap(ProductAttributeMapStoreDO::getMapKeyId, Function.identity())); | |
101 | + List<ProductAttributeVO> productAttributeVOS = new ArrayList<>(); | |
102 | + productAttributeDOS.stream().forEach(x -> { | |
103 | + ProductAttributeVO productAttributeVO = new ProductAttributeVO(); | |
104 | + productAttributeVO.setName(x.getName()); | |
105 | + if(map.get(x.getId()) != null){ | |
106 | + productAttributeVO.setValue(map.get(x.getId()).getElement()); | |
107 | + productAttributeVOS.add(productAttributeVO); | |
108 | + } | |
109 | + }); | |
110 | + productVO.setProductAttributeList(productAttributeVOS); | |
111 | + } | |
112 | + | |
113 | + List<TicketTypeDO> ticketTypeDOS = ticketTypeService.selectByProductId(productDO.getId()); | |
114 | + if(CollectionUtils.isNotEmpty(ticketTypeDOS)){ | |
115 | + productVO.setTicketTypes(ticketTypeDOS.stream().map(productConverter::convertToTickeyTypeVO).collect(Collectors.toList())); | |
116 | + } | |
117 | + return ServerResult.success(productVO); | |
51 | 118 | } |
52 | 119 | |
53 | 120 | /** |
... | ... | @@ -58,14 +125,121 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
58 | 125 | */ |
59 | 126 | @Override |
60 | 127 | public ServerResult list(ProductQueryVO productQueryVO) { |
61 | - | |
62 | - LambdaQueryWrapper<ProductDO> queryWapper = new LambdaQueryWrapper<ProductDO>() | |
63 | - .orderByDesc(ProductDO::getId); | |
128 | + QueryWrapper<ProductQueryVO> queryWapper = new QueryWrapper<ProductQueryVO>(); | |
129 | + queryWapper.eq("p.ismarketable",true); | |
130 | + if(StringUtils.isNotBlank(productQueryVO.getProductCategoryId())){ | |
131 | + queryWapper.eq("pc.id",productQueryVO.getProductCategoryId()); | |
132 | + }else if (StringUtils.isNotBlank(productQueryVO.getRootProductCategoryId())){ | |
133 | + queryWapper.eq("pc.id",productQueryVO.getRootProductCategoryId()); | |
134 | + } | |
135 | + if(StringUtils.isNotBlank(productQueryVO.getProductFunctionId())){ | |
136 | + queryWapper.eq("pf.id",productQueryVO.getProductFunctionId()); | |
137 | + } | |
138 | + if(StringUtils.isNotBlank(productQueryVO.getKeyword())){ | |
139 | + List<TicketTypeDO> tickeyTypeDOList = ticketTypeService.lambdaQuery().like(TicketTypeDO::getRank, productQueryVO.getKeyword()).list(); | |
140 | + Set<String> productIds = tickeyTypeDOList.stream().map(TicketTypeDO::getProductId).collect(Collectors.toSet()); | |
141 | + queryWapper.and(subQueryWapper -> { | |
142 | + subQueryWapper.like("p.name", productQueryVO.getKeyword()).or().in("p.id", productIds); | |
143 | + }); | |
144 | + } | |
64 | 145 | Page page = new Page<>(productQueryVO.getPageNo(), productQueryVO.getPageSize()); |
65 | - IPage<ProductDO> iPage = page(page, queryWapper); | |
146 | + IPage<ProductDO> iPage = productMapper.selectAll(page,queryWapper); | |
66 | 147 | productQueryVO.setTotal(Long.valueOf(iPage.getTotal()).intValue()); |
148 | + return ServerResult.success().setData(PageUtils.getPageReturn(iPage.getRecords(), productQueryVO)); | |
149 | + } | |
67 | 150 | |
68 | - return ServerResult.success(PageUtils.getPageReturn(iPage.getRecords(), productQueryVO)); | |
151 | + @Override | |
152 | + public ServerResult listBySimilar(ProductQueryVO productQueryVO){ | |
153 | + if(StringUtils.isBlank(productQueryVO.getKeyword())){ | |
154 | + return list(productQueryVO); | |
155 | + } | |
156 | + QueryWrapper<ProductQueryVO> queryWapper = new QueryWrapper<ProductQueryVO>(); | |
157 | + queryWapper.eq("p.ismarketable",true); | |
158 | + if(StringUtils.isNotBlank(productQueryVO.getProductCategoryId())){ | |
159 | + queryWapper.eq("pc.id",productQueryVO.getProductCategoryId()); | |
160 | + }else if (StringUtils.isNotBlank(productQueryVO.getRootProductCategoryId())){ | |
161 | + queryWapper.eq("pc.id",productQueryVO.getRootProductCategoryId()); | |
162 | + } | |
163 | + if(StringUtils.isNotBlank(productQueryVO.getProductFunctionId())){ | |
164 | + queryWapper.eq("pf.id",productQueryVO.getProductFunctionId()); | |
165 | + } | |
166 | + Set<String> productIds = null; | |
167 | + Map<String,List<TicketTypeDO>> pId2ttDOsMap = null; | |
168 | + boolean needLikeMatch = false; | |
169 | + if(StringUtils.isNotBlank(productQueryVO.getKeyword())){ | |
170 | + List<TicketTypeDO> tickeyTypeDOList = ticketTypeService.lambdaQuery().like(TicketTypeDO::getRank, productQueryVO.getKeyword()).list(); | |
171 | + productIds = tickeyTypeDOList.stream().map(TicketTypeDO::getProductId).collect(Collectors.toSet()); | |
172 | + needLikeMatch = true; | |
173 | + pId2ttDOsMap = new HashMap<>(); | |
174 | + for (TicketTypeDO ticketTypeDO : tickeyTypeDOList) { | |
175 | + pId2ttDOsMap.computeIfAbsent(ticketTypeDO.getProductId(), k -> new ArrayList<>()); | |
176 | + pId2ttDOsMap.get(ticketTypeDO.getProductId()).add(ticketTypeDO); | |
177 | + } | |
178 | + Set<String> finalProductIds = productIds; | |
179 | + queryWapper.and(subQueryWapper -> { | |
180 | + subQueryWapper.like("p.name", productQueryVO.getKeyword()).or().in(CollUtil.isNotEmpty(finalProductIds),"p.id", finalProductIds); | |
181 | + }); | |
182 | + } | |
183 | + List<ProductDO> productDOS = this.baseMapper.selectList(queryWapper); | |
184 | + List<ProductDO> accurateProducts = Lists.newArrayList(); | |
185 | + Set<String> accurateProductIdSet = Sets.newHashSet(); | |
186 | + //区分大小写 | |
187 | + productDOS.forEach(x -> { | |
188 | + if(x.getName().trim().contains(productQueryVO.getKeyword().trim())){ | |
189 | + accurateProducts.add(x); | |
190 | + accurateProductIdSet.add(x.getId()); | |
191 | + } | |
192 | + }); | |
193 | + List<ProductDO> similarProductList = Lists.newArrayList(); | |
194 | + for(ProductDO product:productDOS){ | |
195 | + if(accurateProductIdSet.contains(product.getId())){ | |
196 | + continue; | |
197 | + } | |
198 | + String name = product.getName(); | |
199 | + int similar = LevenshteinDistanceService.LevenshteinDistancePercent(productQueryVO.getKeyword(),name); | |
200 | + if(similar>=0) {//模糊匹配 | |
201 | + similarProductList.add(product); | |
202 | + product.setSimilar(similar); | |
203 | + } | |
204 | + if(needLikeMatch&&productIds.contains(product.getId())){ | |
205 | + pId2ttDOsMap.get(product.getId()).forEach(x -> { | |
206 | + int ttSimilar = LevenshteinDistanceService.LevenshteinDistancePercent(productQueryVO.getKeyword(),x.getRank()); | |
207 | + product.setTtsTotalSimilar(product.getTtsTotalSimilar() + ttSimilar); | |
208 | + }); | |
209 | + } | |
210 | + } | |
211 | + Collections.sort(similarProductList, (o1, o2) -> | |
212 | + { | |
213 | + if (o2.getSimilar()-o1.getSimilar()!=0) { | |
214 | + return o2.getSimilar()-o1.getSimilar(); | |
215 | + }else { | |
216 | + return o2.getTtsTotalSimilar()-o1.getTtsTotalSimilar(); | |
217 | + } | |
218 | + } | |
219 | + ); | |
220 | + List<ProductDO> allProductList = Lists.newArrayList(); | |
221 | + allProductList.addAll(accurateProducts); | |
222 | + allProductList.addAll(similarProductList); | |
223 | + return pager(productQueryVO,allProductList); | |
224 | + } | |
225 | + | |
226 | + public ServerResult pager(ProductQueryVO productQueryVO,List<ProductDO> allProductList) { | |
227 | + int pageSize = productQueryVO.getPageSize(); | |
228 | + int pageNumber = productQueryVO.getPageNo(); | |
229 | + int totalPage = (allProductList.size()-1)/pageSize+1; | |
230 | + if(allProductList.size()==0){ | |
231 | + totalPage=0; | |
232 | + } | |
233 | + int startIndex = (pageNumber-1)*pageSize; | |
234 | + int toIndex = pageNumber*pageSize; | |
235 | + if(toIndex>allProductList.size()){ | |
236 | + toIndex=allProductList.size(); | |
237 | + } | |
238 | + productQueryVO.setTotal(allProductList.size()); | |
239 | + if(productQueryVO.getPageNo() > totalPage){ | |
240 | + return ServerResult.success().setData(PageUtils.getPageReturn(new ArrayList(),productQueryVO)); | |
241 | + } | |
242 | + return ServerResult.success().setData(PageUtils.getPageReturn(allProductList.subList(startIndex,toIndex),productQueryVO)); | |
69 | 243 | } |
70 | 244 | |
71 | 245 | /** |
... | ... | @@ -128,4 +302,91 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
128 | 302 | update(updateWrapper); |
129 | 303 | return ServerResult.success(); |
130 | 304 | } |
305 | + | |
306 | + @Override | |
307 | + public ServerResult categorySearch(ProductQueryVO productQueryVO){ | |
308 | + QueryWrapper<ProductQueryVO> queryWapper = new QueryWrapper<ProductQueryVO>(); | |
309 | + queryWapper.eq("p.ismarketable",true); | |
310 | + if(StringUtils.isNotBlank(productQueryVO.getProductCategoryId())){ | |
311 | + queryWapper.like("pc.path",productQueryVO.getProductCategoryId()); | |
312 | + }else{ | |
313 | + queryWapper.like("pc.path",productQueryVO.getRootProductCategoryId()); | |
314 | + } | |
315 | + if(StringUtils.isNotBlank(productQueryVO.getProductFunctionId())){ | |
316 | + queryWapper.like("pf.path",productQueryVO.getProductFunctionId()); | |
317 | + } | |
318 | + if(StringUtils.isNotBlank(productQueryVO.getKeyword())){ | |
319 | + queryWapper.like("p.name", productQueryVO.getKeyword()); | |
320 | + } | |
321 | + Page page = new Page<>(productQueryVO.getPageNo(), productQueryVO.getPageSize()); | |
322 | + IPage<ProductDO> iPage = productMapper.selectAll(page,queryWapper); | |
323 | + productQueryVO.setTotal(Long.valueOf(iPage.getTotal()).intValue()); | |
324 | + return ServerResult.success().setData(PageUtils.getPageReturn(iPage.getRecords(), productQueryVO)); | |
325 | + } | |
326 | + | |
327 | + @Override | |
328 | + public ServerResult chatgpt(ProductQueryVO productQueryVO) { | |
329 | + List<ProductDO> productDOS = this.list(); | |
330 | + productDOS.stream().forEach(x -> { | |
331 | + try { | |
332 | + x.setName(translateHtmlOneProductFieldByChatGpt2(x.getName())); | |
333 | + this.updateById(x); | |
334 | + x.setMetadescription(translateHtmlOneProductFieldByChatGpt2(x.getMetadescription())); | |
335 | + x.setMetakeywords(translateHtmlOneProductFieldByChatGpt2(x.getMetakeywords())); | |
336 | + x.setExterior(translateHtmlOneProductFieldByChatGpt2(x.getExterior())); | |
337 | + x.setProductcategoryName(translateHtmlOneProductFieldByChatGpt2(x.getProductcategoryName())); | |
338 | + x.setEnglishname(translateHtmlOneProductFieldByChatGpt2(x.getEnglishname())); | |
339 | + x.setModel(translateHtmlOneProductFieldByChatGpt2(x.getModel())); | |
340 | + | |
341 | + this.updateById(x); | |
342 | + | |
343 | + x.setBasecore1(translateHtmlOneProductFieldByChatGpt2(x.getBasecore1())); | |
344 | + x.setBasecore2(translateHtmlOneProductFieldByChatGpt2(x.getBasecore2())); | |
345 | + x.setBasecore3(translateHtmlOneProductFieldByChatGpt2(x.getBasecore3())); | |
346 | + x.setBasecore4(translateHtmlOneProductFieldByChatGpt2(x.getBasecore4())); | |
347 | + x.setBasecore5(translateHtmlOneProductFieldByChatGpt2(x.getBasecore5())); | |
348 | + x.setBasecore6(translateHtmlOneProductFieldByChatGpt2(x.getBasecore6())); | |
349 | + x.setBasecore7(translateHtmlOneProductFieldByChatGpt2(x.getBasecore7())); | |
350 | + x.setBasecore8(translateHtmlOneProductFieldByChatGpt2(x.getBasecore8())); | |
351 | + | |
352 | + this.updateById(x); | |
353 | + | |
354 | + x.setBasename1(translateHtmlOneProductFieldByChatGpt2(x.getBasename1())); | |
355 | + x.setBasename2(translateHtmlOneProductFieldByChatGpt2(x.getBasename2())); | |
356 | + x.setBasename3(translateHtmlOneProductFieldByChatGpt2(x.getBasename3())); | |
357 | + x.setBasename4(translateHtmlOneProductFieldByChatGpt2(x.getBasename4())); | |
358 | + x.setBasename5(translateHtmlOneProductFieldByChatGpt2(x.getBasename5())); | |
359 | + x.setBasename6(translateHtmlOneProductFieldByChatGpt2(x.getBasename6())); | |
360 | + x.setBasename7(translateHtmlOneProductFieldByChatGpt2(x.getBasename7())); | |
361 | + x.setBasename8(translateHtmlOneProductFieldByChatGpt2(x.getBasename8())); | |
362 | + | |
363 | + this.updateById(x); | |
364 | + | |
365 | + x.setDescription(translateHtmlOneProductFieldByChatGpt2(x.getDescription())); | |
366 | + x.setIntroduction(translateHtmlOneProductFieldByChatGpt2(x.getIntroduction())); | |
367 | + x.setStorage(translateHtmlOneProductFieldByChatGpt2(x.getStorage())); | |
368 | + x.setPhysicalproperty(translateHtmlOneProductFieldByChatGpt2(x.getPhysicalproperty())); | |
369 | + x.setAdvantage(translateHtmlOneProductFieldByChatGpt2(x.getAdvantage())); | |
370 | + x.setWiki(translateHtmlOneProductFieldByChatGpt2(x.getWiki())); | |
371 | + this.updateById(x); | |
372 | + } | |
373 | + catch (Exception e) { | |
374 | + log.error("异常",e); | |
375 | + } | |
376 | + }); | |
377 | + return null; | |
378 | + } | |
379 | + | |
380 | + private String translateHtmlOneProductFieldByChatGpt2(String source) throws IOException, InterruptedException { | |
381 | + try{ | |
382 | + Thread.sleep(1000 * 20); | |
383 | + if(Objects.nonNull(source)){ | |
384 | + String title = "以下内容是锂电池行业术语,中文翻译成英文,不要添加额外内容,保留原有格式。\n"; | |
385 | + return chatGptUtil.chatgptTranslate2(title + source); | |
386 | + } | |
387 | + return source; | |
388 | + }catch (Exception e){ | |
389 | + return source; | |
390 | + } | |
391 | + } | |
131 | 392 | } | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/TicketTypeServiceImpl.java
0 → 100644
1 | +package com.canrd.shop.service.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
4 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |
5 | +import com.canrd.shop.mapper.ProductMapper; | |
6 | +import com.canrd.shop.mapper.TicketTypeMapper; | |
7 | +import com.canrd.shop.module.dto.ProductAttributeMapStoreDO; | |
8 | +import com.canrd.shop.module.dto.ProductDO; | |
9 | +import com.canrd.shop.module.dto.TicketTypeDO; | |
10 | +import com.canrd.shop.service.ProductService; | |
11 | +import com.canrd.shop.service.TicketTypeService; | |
12 | +import org.springframework.stereotype.Service; | |
13 | + | |
14 | +import java.util.List; | |
15 | + | |
16 | +/** | |
17 | + * @author hongtao.zhao | |
18 | + * @since 2023-06-17 | |
19 | + */ | |
20 | +@Service | |
21 | +public class TicketTypeServiceImpl extends ServiceImpl<TicketTypeMapper, TicketTypeDO> implements TicketTypeService { | |
22 | + | |
23 | + @Override | |
24 | + public List<TicketTypeDO> selectByProductId(String productId) { | |
25 | + LambdaQueryWrapper<TicketTypeDO> queryWapper = new LambdaQueryWrapper<TicketTypeDO>(); | |
26 | + queryWapper.eq(TicketTypeDO::getProductId,productId); | |
27 | + queryWapper.orderByAsc(TicketTypeDO::getSerialNumber); | |
28 | + return this.baseMapper.selectList(queryWapper); | |
29 | + } | |
30 | +} | ... | ... |
shop/src/main/resources/application-local.yml
... | ... | @@ -59,9 +59,11 @@ spring: |
59 | 59 | testOnReturn: true |
60 | 60 | password: 123456 |
61 | 61 | time-between-eviction-runs-millis: 1000 |
62 | - url: jdbc:mysql://39.108.227.113:3306/jfinalshop?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true | |
62 | + url: jdbc:mysql://127.0.0.1:3306/canrd_overseas?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true | |
63 | 63 | username: root |
64 | 64 | |
65 | 65 | |
66 | 66 | logging: |
67 | - config: classpath:log4j2-dev.xml | |
68 | 67 | \ No newline at end of file |
68 | + config: classpath:log4j2-dev.xml | |
69 | +openai: | |
70 | + token: Bearer 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 | |
69 | 71 | \ No newline at end of file | ... | ... |
shop/src/main/resources/application-prod.yml
... | ... | @@ -59,7 +59,7 @@ spring: |
59 | 59 | testOnReturn: true |
60 | 60 | password: 123456 |
61 | 61 | time-between-eviction-runs-millis: 1000 |
62 | - url: jdbc:mysql://39.108.227.113:3306/jfinalshop?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true | |
62 | + url: jdbc:mysql://47.89.254.121:3306/canrd_overseas?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true | |
63 | 63 | username: root |
64 | 64 | |
65 | 65 | ... | ... |
shop/src/main/resources/application-test.yml
... | ... | @@ -57,9 +57,9 @@ spring: |
57 | 57 | testWhileIdle: true |
58 | 58 | testOnBorrow: true |
59 | 59 | testOnReturn: true |
60 | - password: 123456 | |
60 | + password: canrd@2024 | |
61 | 61 | time-between-eviction-runs-millis: 1000 |
62 | - url: jdbc:mysql://39.108.227.113:3306/jfinalshop?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true | |
62 | + url: jdbc:mysql://39.108.227.113:3307/canrd_overseas?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true | |
63 | 63 | username: root |
64 | 64 | |
65 | 65 | ... | ... |
shop/src/main/resources/application.yml
shop/src/main/resources/html/test.html
0 → 100644
1 | +<html> | |
2 | + | |
3 | +<body> | |
4 | +<p><img title="1600053287627067238.jpg" alt="1.jpg" src="/ueditor/jsp/upload/image/20200914/1600053287627067238.jpg"></p> | |
5 | +<p><br></p> | |
6 | +<p><img title="1600053297288075778.jpg" alt="2.jpg" src="/ueditor/jsp/upload/image/20200914/1600053297288075778.jpg"></p> | |
7 | +<p><br></p> | |
8 | +<p><img title="1600053307524018803.jpg" alt="3.jpg" src="/ueditor/jsp/upload/image/20200914/1600053307524018803.jpg"></p> | |
9 | +<p><br></p> | |
10 | +<p><img title="1600053331831097168.jpg" alt="4.jpg" src="/ueditor/jsp/upload/image/20200914/1600053331831097168.jpg"></p> | |
11 | +</body> | |
12 | +</html> | ... | ... |
shop/src/main/resources/mapper/ProductMapper.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
3 | +<mapper namespace="com.canrd.shop.mapper.ProductMapper"> | |
4 | + <resultMap id="BaseResultMap" type="com.canrd.shop.module.dto.ProductDO"> | |
5 | + <id column="id" jdbcType="BIGINT" property="id" /> | |
6 | + <result column="name" property="name"/> | |
7 | + </resultMap> | |
8 | + | |
9 | + <select id="selectAll" resultMap="BaseResultMap"> | |
10 | + select distinct p.id,p.name,p.productImageListStore,p.htmlFilePath | |
11 | + from product p | |
12 | + left join productcategoryrelation pcr on p.id=pcr.productId | |
13 | + left join productcategory pc on pc.id=pcr.categoryId | |
14 | + left join productfunctionrelation pfr on p.id=pfr.productId | |
15 | + left join productfunction pf on pf.id=pfr.functionId | |
16 | + ${ew.customSqlSegment} | |
17 | + </select> | |
18 | + | |
19 | + <select id="selectList" resultMap="BaseResultMap"> | |
20 | + select distinct p.id,p.name,p.productImageListStore,p.htmlFilePath | |
21 | + from product p | |
22 | + left join productcategoryrelation pcr on p.id=pcr.productId | |
23 | + left join productcategory pc on pc.id=pcr.categoryId | |
24 | + left join productfunctionrelation pfr on p.id=pfr.productId | |
25 | + left join productfunction pf on pf.id=pfr.functionId | |
26 | + left join tickettype tt on p.id=tt.productId | |
27 | + ${ew.customSqlSegment} | |
28 | + </select> | |
29 | +</mapper> | |
0 | 30 | \ No newline at end of file | ... | ... |
shop/src/test/java/com/canrd/shop/CosineSimilarity.java
0 → 100644
1 | +package com.canrd.shop; | |
2 | + | |
3 | +/** | |
4 | + * @author hongtao.zhao | |
5 | + * @since 2023-08-06 | |
6 | + */ | |
7 | +import java.util.HashMap; | |
8 | +import java.util.Map; | |
9 | + | |
10 | +public class CosineSimilarity { | |
11 | + | |
12 | + // 计算字符串的向量表示 | |
13 | + private static Map<Character, Integer> getCharacterFrequencyVector(String str) { | |
14 | + Map<Character, Integer> frequencyVector = new HashMap<>(); | |
15 | + for (char c : str.toCharArray()) { | |
16 | + frequencyVector.put(c, frequencyVector.getOrDefault(c, 0) + 1); | |
17 | + } | |
18 | + return frequencyVector; | |
19 | + } | |
20 | + | |
21 | + // 计算余弦相似度 | |
22 | + private static double cosineSimilarity(Map<Character, Integer> vectorA, Map<Character, Integer> vectorB) { | |
23 | + double dotProduct = 0.0; | |
24 | + double normA = 0.0; | |
25 | + double normB = 0.0; | |
26 | + | |
27 | + for (char c : vectorA.keySet()) { | |
28 | + int frequencyA = vectorA.getOrDefault(c, 0); | |
29 | + int frequencyB = vectorB.getOrDefault(c, 0); | |
30 | + | |
31 | + dotProduct += frequencyA * frequencyB; | |
32 | + normA += Math.pow(frequencyA, 2); | |
33 | + } | |
34 | + | |
35 | + for (char c : vectorB.keySet()) { | |
36 | + int frequencyB = vectorB.getOrDefault(c, 0); | |
37 | + normB += Math.pow(frequencyB, 2); | |
38 | + } | |
39 | + | |
40 | + if (normA == 0.0 || normB == 0.0) { | |
41 | + return 0.0; // 避免除零错误 | |
42 | + } else { | |
43 | + return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB)); | |
44 | + } | |
45 | + } | |
46 | + | |
47 | + public static void main(String[] args) { | |
48 | + String strA = "hello"; | |
49 | + String strB = "holla"; | |
50 | + | |
51 | + Map<Character, Integer> vectorA = getCharacterFrequencyVector(strA); | |
52 | + Map<Character, Integer> vectorB = getCharacterFrequencyVector(strB); | |
53 | + | |
54 | + double similarity = cosineSimilarity(vectorA, vectorB); | |
55 | + System.out.println("Cosine similarity between '" + strA + "' and '" + strB + "' is: " + similarity); | |
56 | + } | |
57 | +} | |
58 | + | ... | ... |
shop/src/test/java/com/canrd/shop/S.java
0 → 100644
shop/src/test/java/com/canrd/shop/TranslateTest.java
0 → 100644
1 | +package com.canrd.shop; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSON; | |
4 | +import com.alibaba.fastjson.JSONArray; | |
5 | +import com.alibaba.fastjson.JSONObject; | |
6 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
7 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | |
8 | +import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; | |
9 | +import com.canrd.shop.common.utils.ChatGptUtil; | |
10 | +import com.canrd.shop.common.utils.StringUtils; | |
11 | +import com.canrd.shop.common.utils.TranslateHtmlV3Util; | |
12 | +import com.canrd.shop.common.utils.TranslateUtil; | |
13 | +import com.canrd.shop.module.dto.ProductAttributeDO; | |
14 | +import com.canrd.shop.module.dto.ProductAttributeMapStoreDO; | |
15 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
16 | +import com.canrd.shop.module.dto.ProductDO; | |
17 | +import com.canrd.shop.module.dto.ProductFunctionDO; | |
18 | +import com.canrd.shop.module.dto.TicketTypeDO; | |
19 | +import com.canrd.shop.service.ProductAttributeMapStoreService; | |
20 | +import com.canrd.shop.service.ProductAttributeService; | |
21 | +import com.canrd.shop.service.ProductCategoryService; | |
22 | +import com.canrd.shop.service.ProductFunctionService; | |
23 | +import com.canrd.shop.service.ProductService; | |
24 | +import com.canrd.shop.service.TicketTypeService; | |
25 | +import lombok.extern.slf4j.Slf4j; | |
26 | +import org.apache.commons.io.FileUtils; | |
27 | +import org.junit.Test; | |
28 | +import org.junit.runner.RunWith; | |
29 | +import org.mybatis.spring.annotation.MapperScan; | |
30 | +import org.springframework.beans.factory.annotation.Autowired; | |
31 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | |
32 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | |
33 | +import org.springframework.boot.test.context.SpringBootTest; | |
34 | +import org.springframework.test.context.junit4.SpringRunner; | |
35 | + | |
36 | +import java.io.File; | |
37 | +import java.io.IOException; | |
38 | +import java.net.SocketException; | |
39 | +import java.util.List; | |
40 | +import java.util.Objects; | |
41 | +import java.util.concurrent.atomic.AtomicInteger; | |
42 | +import java.util.concurrent.atomic.AtomicReference; | |
43 | +import java.util.regex.Matcher; | |
44 | +import java.util.regex.Pattern; | |
45 | + | |
46 | +/** | |
47 | + * @author hongtao.zhao | |
48 | + * @since 2023-06-17 | |
49 | + */ | |
50 | +@Slf4j | |
51 | +@MapperScan("com.canrd.shop.**.mapper") | |
52 | +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}, scanBasePackages = {"com.canrd.shop"}) | |
53 | +@RunWith(SpringRunner.class) | |
54 | +@SpringBootTest(classes = {TranslateTest.class}) | |
55 | +public class TranslateTest { | |
56 | + | |
57 | + @Autowired | |
58 | + private ProductService productService; | |
59 | + | |
60 | + @Autowired | |
61 | + private ProductCategoryService productCategoryService; | |
62 | + | |
63 | + @Autowired | |
64 | + private ProductFunctionService productFunctionService; | |
65 | + | |
66 | + @Autowired | |
67 | + private ProductAttributeService productAttributeService; | |
68 | + | |
69 | + @Autowired | |
70 | + private ProductAttributeMapStoreService productAttributeMapStoreService; | |
71 | + | |
72 | + @Autowired | |
73 | + private TicketTypeService ticketTypeService; | |
74 | + | |
75 | + @Autowired | |
76 | + private ChatGptUtil chatGptUtil; | |
77 | + | |
78 | + @Test | |
79 | + public void translateTicketTypeTest(){ | |
80 | + List<TicketTypeDO> ticketTypeDOS = ticketTypeService.list(); | |
81 | + ticketTypeDOS.forEach(x ->{ | |
82 | + try{ | |
83 | + if(isContainChinese(x.getRank())){ | |
84 | + x.setRank(translateOneProductField(x.getRank())); | |
85 | + } | |
86 | + if(isContainChinese(x.getTypeName())){ | |
87 | + x.setTypeName(translateOneProductField(x.getTypeName())); | |
88 | + } | |
89 | + ticketTypeService.updateById(x); | |
90 | + }catch (Exception e){ | |
91 | + System.out.println(e); | |
92 | + } | |
93 | + }); | |
94 | + } | |
95 | + @Test | |
96 | + public void translateProductAttribute2Test(){ | |
97 | + List<ProductAttributeMapStoreDO> productAttributeMapStoreDOS = productAttributeMapStoreService.list(); | |
98 | + productAttributeMapStoreDOS.stream().forEach(x ->{ | |
99 | + if(isContainChinese(x.getElement())){ | |
100 | + try{ | |
101 | + x.setElement(translateHtmlOneProductField(x.getElement())); | |
102 | + LambdaUpdateWrapper<ProductAttributeMapStoreDO> updateWrapper = new LambdaUpdateWrapper<ProductAttributeMapStoreDO>(); | |
103 | + updateWrapper.eq(ProductAttributeMapStoreDO::getProductId,x.getProductId()); | |
104 | + updateWrapper.eq(ProductAttributeMapStoreDO::getMapKeyId,x.getMapKeyId()); | |
105 | + productAttributeMapStoreService.update(x,updateWrapper); | |
106 | + }catch (Exception e){ | |
107 | + System.out.println(e); | |
108 | + } | |
109 | + | |
110 | + } | |
111 | + }); | |
112 | + } | |
113 | + | |
114 | + public static boolean isContainChinese(String str) { | |
115 | + Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); | |
116 | + Matcher m = p.matcher(str); | |
117 | + if (m.find()) { | |
118 | + return true; | |
119 | + } | |
120 | + return false; | |
121 | + | |
122 | + } | |
123 | + | |
124 | + @Test | |
125 | + public void translateProductAttributeTest(){ | |
126 | + List<ProductAttributeDO> productAttributeDOS = productAttributeService.list(); | |
127 | + productAttributeDOS.stream().forEach(x ->{ | |
128 | + x.setName(translateOneProductField(x.getName())); | |
129 | + productAttributeService.updateById(x); | |
130 | + }); | |
131 | + } | |
132 | + | |
133 | + @Test | |
134 | + public void translateFunctionTest(){ | |
135 | + List<ProductFunctionDO> productFunctionDOS = productFunctionService.list(); | |
136 | + productFunctionDOS.stream().forEach(x ->{ | |
137 | + x.setName(translateOneProductField(x.getName())); | |
138 | + productFunctionService.updateById(x); | |
139 | + }); | |
140 | + } | |
141 | + | |
142 | + /** | |
143 | + * 翻译分类信息 | |
144 | + */ | |
145 | + @Test | |
146 | + public void translateProductCategory(){ | |
147 | + List<ProductCategoryDO> productCategoryDOList = productCategoryService.list(); | |
148 | + AtomicInteger total = new AtomicInteger(); | |
149 | + productCategoryDOList.stream().forEach(x ->{ | |
150 | + String result = TranslateUtil.translate(x.getName()); | |
151 | + total.getAndIncrement(); | |
152 | + log.info("num={},id={},原始值={},结果={}",total,x.getId(),x.getName(),result); | |
153 | + x.setName(result); | |
154 | + productCategoryService.updateById(x); | |
155 | + }); | |
156 | + } | |
157 | + | |
158 | + /** | |
159 | + * | |
160 | + * 翻译产品信息 | |
161 | + */ | |
162 | + @Test | |
163 | + public void translateProduct(){ | |
164 | + List<ProductDO> productDOS = productService.list(); | |
165 | + productDOS.stream().forEach(x ->{ | |
166 | + try{ | |
167 | + x.setName(translateOneProductField(x.getName())); | |
168 | + x.setMetadescription(translateOneProductField(x.getMetadescription())); | |
169 | + x.setMetakeywords(translateOneProductField(x.getMetakeywords())); | |
170 | + x.setExterior(translateOneProductField(x.getExterior())); | |
171 | + x.setProductcategoryName(translateOneProductField(x.getProductcategoryName())); | |
172 | + x.setEnglishname(translateOneProductField(x.getEnglishname())); | |
173 | + x.setModel(translateOneProductField(x.getModel())); | |
174 | + | |
175 | + x.setBasecore1(translateOneProductField(x.getBasecore1())); | |
176 | + x.setBasecore2(translateOneProductField(x.getBasecore2())); | |
177 | + x.setBasecore3(translateOneProductField(x.getBasecore3())); | |
178 | + x.setBasecore4(translateOneProductField(x.getBasecore4())); | |
179 | + x.setBasecore5(translateOneProductField(x.getBasecore5())); | |
180 | + x.setBasecore6(translateOneProductField(x.getBasecore6())); | |
181 | + x.setBasecore7(translateOneProductField(x.getBasecore7())); | |
182 | + x.setBasecore8(translateOneProductField(x.getBasecore8())); | |
183 | + | |
184 | + x.setBasename1(translateOneProductField(x.getBasename1())); | |
185 | + x.setBasename2(translateOneProductField(x.getBasename2())); | |
186 | + x.setBasename3(translateOneProductField(x.getBasename3())); | |
187 | + x.setBasename4(translateOneProductField(x.getBasename4())); | |
188 | + x.setBasename5(translateOneProductField(x.getBasename5())); | |
189 | + x.setBasename6(translateOneProductField(x.getBasename6())); | |
190 | + x.setBasename7(translateOneProductField(x.getBasename7())); | |
191 | + x.setBasename8(translateOneProductField(x.getBasename8())); | |
192 | + | |
193 | + x.setDescription(translateHtmlOneProductField(x.getDescription())); | |
194 | + x.setIntroduction(translateHtmlOneProductField(x.getIntroduction())); | |
195 | + x.setStorage(translateHtmlOneProductField(x.getStorage())); | |
196 | + x.setPhysicalproperty(translateHtmlOneProductField(x.getPhysicalproperty())); | |
197 | + x.setAdvantage(translateHtmlOneProductField(x.getAdvantage())); | |
198 | + x.setWiki(translateHtmlOneProductField(x.getWiki())); | |
199 | + productService.updateById(x); | |
200 | + log.info("翻译一条记录:id:{}",x.getId()); | |
201 | + }catch (Exception e){ | |
202 | + log.error("id={}",x.getId()); | |
203 | + } | |
204 | + | |
205 | + }); | |
206 | + } | |
207 | + | |
208 | + private String translateOneProductField(String source){ | |
209 | + if(Objects.nonNull(source)){ | |
210 | + String result = TranslateUtil.translate(source); | |
211 | + log.info("原始值={},结果={}",source,result); | |
212 | + if(result!=null){ | |
213 | + return result; | |
214 | + } | |
215 | + } | |
216 | + return source; | |
217 | + } | |
218 | + | |
219 | + private String translateHtmlOneProductField(String source){ | |
220 | + if(Objects.nonNull(source)){ | |
221 | + String result = null; | |
222 | + try { | |
223 | + result = TranslateHtmlV3Util.translate(source); | |
224 | + } catch (IOException e) { | |
225 | + throw new RuntimeException(e); | |
226 | + } catch (InterruptedException e) { | |
227 | + throw new RuntimeException(e); | |
228 | + } | |
229 | + log.info("原始值={},结果={}",source,result); | |
230 | + if(result!=null){ | |
231 | + return result; | |
232 | + } | |
233 | + } | |
234 | + return source; | |
235 | + } | |
236 | + | |
237 | + /** | |
238 | + * 三方sdk | |
239 | + * @param source | |
240 | + * @return | |
241 | + * @throws IOException | |
242 | + * @throws InterruptedException | |
243 | + */ | |
244 | + private String translateHtmlOneProductFieldByChatGpt2(String source) throws IOException, InterruptedException { | |
245 | + Thread.sleep(30 * 1000); | |
246 | + if(Objects.nonNull(source)){ | |
247 | + String title = "以下内容是锂电池行业术语,标准英文翻译一下,不要添加额外内容 \n"; | |
248 | + return chatGptUtil.chatgptTranslate2(title + source); | |
249 | + } | |
250 | + return source; | |
251 | + } | |
252 | + | |
253 | + /** | |
254 | + * okhttp 直接调用 | |
255 | + * @param source | |
256 | + * @return | |
257 | + * @throws IOException | |
258 | + * @throws InterruptedException | |
259 | + */ | |
260 | + private String translateHtmlOneProductFieldByChatGpt1(String source) throws IOException, InterruptedException { | |
261 | + if(Objects.nonNull(source)){ | |
262 | + String title = "锂电池行业术语,保留html富文本,标准翻译一下:"; | |
263 | + return chatGptUtil.chatgptTranslate(title + source); | |
264 | + } | |
265 | + return source; | |
266 | + } | |
267 | + | |
268 | + @Test | |
269 | + public void translateProductByChatGpt() { | |
270 | + List<ProductDO> productDOS = productService.list(); | |
271 | + productDOS.stream().forEach(x -> { | |
272 | + try { | |
273 | + String result = this.translateHtmlOneProductFieldByChatGpt1(x.getAdvantage()); | |
274 | + x.setAdvantage(result); | |
275 | + productService.updateById(x); | |
276 | + log.info("\n id:{},\n source:{} \n result:{}",x.getId(),x.getAdvantage(),result); | |
277 | + Thread.sleep(30000); | |
278 | + | |
279 | + log.info("==================================="); | |
280 | + } | |
281 | + catch (Exception e) { | |
282 | + log.error("异常",e); | |
283 | + } | |
284 | + }); | |
285 | + } | |
286 | + | |
287 | + @Test | |
288 | + public void test() throws IOException { | |
289 | + File file = new File("/Users/zhaohongtao/jfinalshop_product.json"); | |
290 | + String json = FileUtils.readFileToString(file,"UTF-8"); | |
291 | + JSONArray jsonArray = JSON.parseArray(json); | |
292 | + JSONArray JsonArrayResult = new JSONArray(); | |
293 | + jsonArray.forEach(x -> { | |
294 | + try { | |
295 | + String jsonResult = this.translateHtmlOneProductFieldByChatGpt2(JSONObject.toJSONString(x)); | |
296 | + JsonArrayResult.add(jsonResult); | |
297 | + } catch (IOException e) { | |
298 | + System.out.println(e); | |
299 | + } catch (InterruptedException e) { | |
300 | + System.out.println(e); | |
301 | + }catch ( Exception e){ | |
302 | + System.out.println(e); | |
303 | + } | |
304 | + }); | |
305 | + FileUtils.writeStringToFile(new File("/Users/zhaohongtao/jfinalshop_product_result.json"),JsonArrayResult.toJSONString()); | |
306 | + } | |
307 | +} | ... | ... |
shop/src/test/resources/application-local.yml
0 → 100644
1 | +mybatis-plus: | |
2 | + configuration: | |
3 | + cache-enabled: false | |
4 | + call-setters-on-nulls: true | |
5 | + jdbc-type-for-null: 'null' | |
6 | + map-underscore-to-camel-case: true | |
7 | + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl | |
8 | + global-config: | |
9 | + db-config: | |
10 | + capital-mode: false | |
11 | + field-strategy: NOT_NULL | |
12 | + id-type: AUTO | |
13 | + logic-delete-field: enable_flag | |
14 | + logic-delete-value: 20 | |
15 | + logic-not-delete-value: 10 | |
16 | + mapper-locations: classpath:/mapper/**.xml | |
17 | + type-aliases-package: com.canrd.shop.**.dto | |
18 | +#spring: | |
19 | +# datasource: | |
20 | +# dynamic: | |
21 | +# primary: overtime #设置默认的数据源或者数据源组,默认值即为master | |
22 | +# strict: false #设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候会抛出异常,不启动则使用默认数据源. | |
23 | +# datasource: | |
24 | +# wms_warehouse: | |
25 | +# url: jdbc:mysql://127.0.0.1:3306/overtime?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true&rewriteBatchedStatements=true | |
26 | +# username: root | |
27 | +# password: root | |
28 | +# driver-class-name: com.mysql.cj.jdbc.Driver # 3.2.0开始支持SPI可省略此配置 | |
29 | +# druid: | |
30 | +# initial-size: 5 | |
31 | +# max-active: 20 | |
32 | +# max-evictable-idle-time-millis: 300000 | |
33 | +# max-wait: 60000 | |
34 | +# min-evictable-idle-time-millis: 300000 | |
35 | +# min-idle: 5 | |
36 | +# time-between-eviction-runs-millis: 60000 | |
37 | +# type: com.alibaba.druid.pool.DruidDataSource | |
38 | +spring: | |
39 | + servlet: | |
40 | + multipart: | |
41 | + enabled: true | |
42 | + max-file-size: 100MB | |
43 | + max-request-size: 20MB | |
44 | + file-size-threshold: 20MB | |
45 | + datasource: | |
46 | + db-type: com.alibaba.druid.pool.DruidDataSource | |
47 | + driverClassName: com.mysql.cj.jdbc.Driver | |
48 | + initial-size: 5 | |
49 | + max-active: 30 | |
50 | + max-wait: 30000 | |
51 | + min-idle: 5 | |
52 | + #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 | |
53 | + timeBetweenEvictionRunsMillis: 30000 | |
54 | + #配置一个连接在池中最小生存的时间,单位是毫秒,30000=30s | |
55 | + minEvictableIdleTimeMillis: 30000 | |
56 | + validationQuery: SELECT 'x' | |
57 | + testWhileIdle: true | |
58 | + testOnBorrow: true | |
59 | + testOnReturn: true | |
60 | + password: 123456 | |
61 | + time-between-eviction-runs-millis: 1000 | |
62 | + url: jdbc:mysql://39.108.227.113:3307/canrd_overseas_chatgpt?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true | |
63 | + username: root | |
64 | + | |
65 | + | |
66 | +logging: | |
67 | + config: classpath:log4j2-dev.xml | |
0 | 68 | \ No newline at end of file | ... | ... |