1
This commit is contained in:
@@ -3,6 +3,10 @@ package com.ruoyi.web.controller.publicapi;
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -15,15 +19,23 @@ import java.util.*;
|
||||
@RequestMapping("/public/comment")
|
||||
public class CommentPublicController extends BaseController {
|
||||
|
||||
// TODO: 可改为读取配置
|
||||
private static final String JD_BASE = "http://192.168.8.88:6666/jd";
|
||||
private static final String SKEY = "2192057370ef8140c201079969c956a3";
|
||||
|
||||
/**
|
||||
* 获取可选型号/类型(示例)
|
||||
*/
|
||||
@GetMapping("/types")
|
||||
public AjaxResult types() {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
list.add(map("烟灶套餐", "ZQD150F-EB150"));
|
||||
list.add(map("单烟机", "CXW-298-IQ92DPRO"));
|
||||
return AjaxResult.success(list);
|
||||
try {
|
||||
String url = JD_BASE + "/comment/types?skey=" + SKEY;
|
||||
String result = HttpUtils.sendGet(url);
|
||||
Object parsed = JSON.parse(result);
|
||||
return AjaxResult.success(parsed);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("types failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,29 +44,22 @@ public class CommentPublicController extends BaseController {
|
||||
*/
|
||||
@PostMapping("/generate")
|
||||
public AjaxResult generate(@RequestBody Map<String, String> body) {
|
||||
String productType = body != null ? body.getOrDefault("productType", "") : "";
|
||||
List<Map<String, Object>> comments = new ArrayList<>();
|
||||
comments.add(comment("到货很快,安装专业,使用体验不错,噪音小,性价比高。"));
|
||||
comments.add(comment("外观大气,做工扎实,吸力强劲,细节处理到位,家人都满意。"));
|
||||
Map<String, Object> resp = new HashMap<>();
|
||||
resp.put("productType", productType);
|
||||
resp.put("list", comments);
|
||||
return AjaxResult.success(resp);
|
||||
try {
|
||||
String url = JD_BASE + "/comment/generate";
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("skey", SKEY);
|
||||
if (body != null && body.get("productType") != null) {
|
||||
param.put("productType", body.get("productType"));
|
||||
}
|
||||
String result = HttpUtils.sendJsonPost(url, param.toJSONString());
|
||||
Object parsed = JSON.parse(result);
|
||||
return AjaxResult.success(parsed);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("generate failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> map(String name, String value) {
|
||||
Map<String, String> m = new HashMap<>();
|
||||
m.put("name", name);
|
||||
m.put("value", value);
|
||||
return m;
|
||||
}
|
||||
|
||||
private Map<String, Object> comment(String text) {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
m.put("commentText", text);
|
||||
m.put("images", Collections.emptyList());
|
||||
return m;
|
||||
}
|
||||
// 原示例方法移除
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user