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.annotation.Anonymous;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
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 org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -15,15 +19,23 @@ import java.util.*;
|
|||||||
@RequestMapping("/public/comment")
|
@RequestMapping("/public/comment")
|
||||||
public class CommentPublicController extends BaseController {
|
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")
|
@GetMapping("/types")
|
||||||
public AjaxResult types() {
|
public AjaxResult types() {
|
||||||
List<Map<String, String>> list = new ArrayList<>();
|
try {
|
||||||
list.add(map("烟灶套餐", "ZQD150F-EB150"));
|
String url = JD_BASE + "/comment/types?skey=" + SKEY;
|
||||||
list.add(map("单烟机", "CXW-298-IQ92DPRO"));
|
String result = HttpUtils.sendGet(url);
|
||||||
return AjaxResult.success(list);
|
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")
|
@PostMapping("/generate")
|
||||||
public AjaxResult generate(@RequestBody Map<String, String> body) {
|
public AjaxResult generate(@RequestBody Map<String, String> body) {
|
||||||
String productType = body != null ? body.getOrDefault("productType", "") : "";
|
try {
|
||||||
List<Map<String, Object>> comments = new ArrayList<>();
|
String url = JD_BASE + "/comment/generate";
|
||||||
comments.add(comment("到货很快,安装专业,使用体验不错,噪音小,性价比高。"));
|
JSONObject param = new JSONObject();
|
||||||
comments.add(comment("外观大气,做工扎实,吸力强劲,细节处理到位,家人都满意。"));
|
param.put("skey", SKEY);
|
||||||
Map<String, Object> resp = new HashMap<>();
|
if (body != null && body.get("productType") != null) {
|
||||||
resp.put("productType", productType);
|
param.put("productType", body.get("productType"));
|
||||||
resp.put("list", comments);
|
}
|
||||||
return AjaxResult.success(resp);
|
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