This commit is contained in:
Leo
2025-12-08 14:42:44 +08:00
parent 632b9f7eb1
commit 9a8c7b1039
15 changed files with 1151 additions and 1 deletions

View File

@@ -0,0 +1,137 @@
package com.ruoyi.web.controller.jarvis;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jarvis.domain.Comment;
import com.ruoyi.jarvis.domain.dto.CommentApiStatistics;
import com.ruoyi.jarvis.domain.dto.CommentStatistics;
import com.ruoyi.jarvis.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 评论管理 Controller
*/
@RestController
@RequestMapping("/jarvis/comment")
public class CommentController extends BaseController {
@Autowired
private ICommentService commentService;
/**
* 查询京东评论列表
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:list')")
@GetMapping("/jd/list")
public TableDataInfo list(Comment comment) {
startPage();
List<Comment> list = commentService.selectCommentList(comment);
return getDataTable(list);
}
/**
* 导出京东评论列表
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:export')")
@Log(title = "京东评论", businessType = BusinessType.EXPORT)
@PostMapping("/jd/export")
public void export(HttpServletResponse response, Comment comment) {
List<Comment> list = commentService.selectCommentList(comment);
ExcelUtil<Comment> util = new ExcelUtil<Comment>(Comment.class);
util.exportExcel(response, list, "京东评论数据");
}
/**
* 获取京东评论详细信息
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:query')")
@GetMapping("/jd/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(commentService.selectCommentById(id));
}
/**
* 修改评论使用状态
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:edit')")
@Log(title = "评论管理", businessType = BusinessType.UPDATE)
@PutMapping("/jd")
public AjaxResult edit(@RequestBody Comment comment) {
return toAjax(commentService.updateCommentIsUse(comment));
}
/**
* 删除评论
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:remove')")
@Log(title = "评论管理", businessType = BusinessType.DELETE)
@DeleteMapping("/jd/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(commentService.deleteCommentByIds(ids));
}
/**
* 重置评论使用状态按商品ID
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:edit')")
@Log(title = "评论管理", businessType = BusinessType.UPDATE)
@PutMapping("/jd/reset/{productId}")
public AjaxResult resetByProductId(@PathVariable String productId) {
return toAjax(commentService.resetCommentIsUseByProductId(productId));
}
/**
* 获取评论统计信息
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:list')")
@GetMapping("/statistics")
public AjaxResult getStatistics(@RequestParam(required = false) String source) {
List<CommentStatistics> statistics = commentService.getCommentStatistics(source);
return success(statistics);
}
/**
* 获取接口调用统计
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:list')")
@GetMapping("/api/statistics")
public AjaxResult getApiStatistics(
@RequestParam(required = false) String apiType,
@RequestParam(required = false) String productType,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate) {
List<CommentApiStatistics> statistics = commentService.getApiStatistics(apiType, productType, startDate, endDate);
return success(statistics);
}
/**
* 获取Redis产品类型映射京东
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:list')")
@GetMapping("/redis/jd/map")
public AjaxResult getJdProductTypeMap() {
Map<String, String> map = commentService.getJdProductTypeMap();
return success(map);
}
/**
* 获取Redis产品类型映射淘宝
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:list')")
@GetMapping("/redis/tb/map")
public AjaxResult getTbProductTypeMap() {
Map<String, String> map = commentService.getTbProductTypeMap();
return success(map);
}
}

View File

@@ -0,0 +1,90 @@
package com.ruoyi.web.controller.jarvis;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jarvis.domain.TaobaoComment;
import com.ruoyi.jarvis.service.ITaobaoCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 淘宝评论管理 Controller
*/
@RestController
@RequestMapping("/jarvis/taobaoComment")
public class TaobaoCommentController extends BaseController {
@Autowired
private ITaobaoCommentService taobaoCommentService;
/**
* 查询淘宝评论列表
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:list')")
@GetMapping("/list")
public TableDataInfo list(TaobaoComment taobaoComment) {
startPage();
List<TaobaoComment> list = taobaoCommentService.selectTaobaoCommentList(taobaoComment);
return getDataTable(list);
}
/**
* 导出淘宝评论列表
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:export')")
@Log(title = "淘宝评论", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, TaobaoComment taobaoComment) {
List<TaobaoComment> list = taobaoCommentService.selectTaobaoCommentList(taobaoComment);
ExcelUtil<TaobaoComment> util = new ExcelUtil<TaobaoComment>(TaobaoComment.class);
util.exportExcel(response, list, "淘宝评论数据");
}
/**
* 获取淘宝评论详细信息
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:query')")
@GetMapping("/{id}")
public AjaxResult getInfo(@PathVariable("id") Integer id) {
return success(taobaoCommentService.selectTaobaoCommentById(id));
}
/**
* 修改评论使用状态
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:edit')")
@Log(title = "评论管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody TaobaoComment taobaoComment) {
return toAjax(taobaoCommentService.updateTaobaoCommentIsUse(taobaoComment));
}
/**
* 删除评论
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:remove')")
@Log(title = "评论管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Integer[] ids) {
return toAjax(taobaoCommentService.deleteTaobaoCommentByIds(ids));
}
/**
* 重置评论使用状态按商品ID
*/
@PreAuthorize("@ss.hasPermi('jarvis:comment:edit')")
@Log(title = "评论管理", businessType = BusinessType.UPDATE)
@PutMapping("/reset/{productId}")
public AjaxResult resetByProductId(@PathVariable String productId) {
return toAjax(taobaoCommentService.resetTaobaoCommentIsUseByProductId(productId));
}
}

View File

@@ -6,6 +6,8 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.jarvis.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@@ -22,18 +24,28 @@ public class CommentPublicController extends BaseController {
private static final String JD_BASE = "http://192.168.8.88:6666/jd";
private static final String SKEY = "2192057370ef8140c201079969c956a3";
@Autowired(required = false)
private ICommentService commentService;
/**
* 获取可选型号/类型(示例)
*/
@GetMapping("/types")
public AjaxResult types() {
boolean success = false;
try {
String url = JD_BASE + "/comment/types?skey=" + SKEY;
String result = HttpUtils.sendGet(url);
Object parsed = JSON.parse(result);
success = true;
return AjaxResult.success(parsed);
} catch (Exception e) {
return AjaxResult.error("types failed: " + e.getMessage());
} finally {
// 记录接口调用统计
if (commentService != null) {
commentService.recordApiCall("jd", "types", success);
}
}
}
@@ -43,18 +55,27 @@ public class CommentPublicController extends BaseController {
*/
@PostMapping("/generate")
public AjaxResult generate(@RequestBody Map<String, String> body) {
boolean success = false;
String productType = null;
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"));
productType = body.get("productType");
param.put("productType", productType);
}
String result = HttpUtils.sendJsonPost(url, param.toJSONString());
Object parsed = JSON.parse(result);
success = true;
return AjaxResult.success(parsed);
} catch (Exception e) {
return AjaxResult.error("generate failed: " + e.getMessage());
} finally {
// 记录接口调用统计
if (commentService != null && productType != null) {
commentService.recordApiCall("jd", productType, success);
}
}
}