Compare commits
4 Commits
9206824efb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a8c7b1039 | ||
|
|
632b9f7eb1 | ||
|
|
eb53915bcd | ||
|
|
4dd3e9dd70 |
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -6,6 +6,8 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
|||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.ruoyi.common.utils.http.HttpUtils;
|
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 org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.*;
|
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 JD_BASE = "http://192.168.8.88:6666/jd";
|
||||||
private static final String SKEY = "2192057370ef8140c201079969c956a3";
|
private static final String SKEY = "2192057370ef8140c201079969c956a3";
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private ICommentService commentService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取可选型号/类型(示例)
|
* 获取可选型号/类型(示例)
|
||||||
*/
|
*/
|
||||||
@GetMapping("/types")
|
@GetMapping("/types")
|
||||||
public AjaxResult types() {
|
public AjaxResult types() {
|
||||||
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
String url = JD_BASE + "/comment/types?skey=" + SKEY;
|
String url = JD_BASE + "/comment/types?skey=" + SKEY;
|
||||||
String result = HttpUtils.sendGet(url);
|
String result = HttpUtils.sendGet(url);
|
||||||
Object parsed = JSON.parse(result);
|
Object parsed = JSON.parse(result);
|
||||||
|
success = true;
|
||||||
return AjaxResult.success(parsed);
|
return AjaxResult.success(parsed);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return AjaxResult.error("types failed: " + e.getMessage());
|
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")
|
@PostMapping("/generate")
|
||||||
public AjaxResult generate(@RequestBody Map<String, String> body) {
|
public AjaxResult generate(@RequestBody Map<String, String> body) {
|
||||||
|
boolean success = false;
|
||||||
|
String productType = null;
|
||||||
try {
|
try {
|
||||||
String url = JD_BASE + "/comment/generate";
|
String url = JD_BASE + "/comment/generate";
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("skey", SKEY);
|
param.put("skey", SKEY);
|
||||||
if (body != null && body.get("productType") != null) {
|
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());
|
String result = HttpUtils.sendJsonPost(url, param.toJSONString());
|
||||||
Object parsed = JSON.parse(result);
|
Object parsed = JSON.parse(result);
|
||||||
|
success = true;
|
||||||
return AjaxResult.success(parsed);
|
return AjaxResult.success(parsed);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return AjaxResult.error("generate failed: " + e.getMessage());
|
return AjaxResult.error("generate failed: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
// 记录接口调用统计
|
||||||
|
if (commentService != null && productType != null) {
|
||||||
|
commentService.recordApiCall("jd", productType, success);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.ruoyi.jarvis.domain;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
import com.ruoyi.common.annotation.Excel;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 京东评论对象 comments
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Comment extends BaseEntity {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 主键ID */
|
||||||
|
@Excel(name = "ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 商品ID */
|
||||||
|
@Excel(name = "商品ID")
|
||||||
|
private String productId;
|
||||||
|
|
||||||
|
/** 用户名 */
|
||||||
|
@Excel(name = "用户名")
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/** 评论内容 */
|
||||||
|
@Excel(name = "评论内容")
|
||||||
|
private String commentText;
|
||||||
|
|
||||||
|
/** 评论ID */
|
||||||
|
@Excel(name = "评论ID")
|
||||||
|
private String commentId;
|
||||||
|
|
||||||
|
/** 图片URLs */
|
||||||
|
@Excel(name = "图片URLs")
|
||||||
|
private String pictureUrls;
|
||||||
|
|
||||||
|
/** 创建时间 */
|
||||||
|
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date createdAt;
|
||||||
|
|
||||||
|
/** 评论日期 */
|
||||||
|
@Excel(name = "评论日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date commentDate;
|
||||||
|
|
||||||
|
/** 是否已使用 0-未使用 1-已使用 */
|
||||||
|
@Excel(name = "使用状态", readConverterExp = "0=未使用,1=已使用")
|
||||||
|
private Integer isUse;
|
||||||
|
|
||||||
|
/** 产品类型(从Redis映射获取) */
|
||||||
|
private String productType;
|
||||||
|
|
||||||
|
/** Redis映射的产品ID */
|
||||||
|
private String mappedProductId;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -44,6 +44,10 @@ public class SuperAdmin extends BaseEntity
|
|||||||
@Excel(name = "是否参与订单统计", readConverterExp = "0=否,1=是")
|
@Excel(name = "是否参与订单统计", readConverterExp = "0=否,1=是")
|
||||||
private Integer isCount;
|
private Integer isCount;
|
||||||
|
|
||||||
|
/** 接收人(企业微信用户ID,多个用逗号分隔) */
|
||||||
|
@Excel(name = "接收人")
|
||||||
|
private String touser;
|
||||||
|
|
||||||
/** 创建时间 */
|
/** 创建时间 */
|
||||||
@Excel(name = "创建时间")
|
@Excel(name = "创建时间")
|
||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
@@ -151,4 +155,14 @@ public class SuperAdmin extends BaseEntity
|
|||||||
{
|
{
|
||||||
this.isCount = isCount;
|
this.isCount = isCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTouser()
|
||||||
|
{
|
||||||
|
return touser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTouser(String touser)
|
||||||
|
{
|
||||||
|
this.touser = touser;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.ruoyi.jarvis.domain;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
import com.ruoyi.common.annotation.Excel;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 淘宝评论对象 taobao_comments
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TaobaoComment extends BaseEntity {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 主键ID */
|
||||||
|
@Excel(name = "ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/** 商品ID */
|
||||||
|
@Excel(name = "商品ID")
|
||||||
|
private String productId;
|
||||||
|
|
||||||
|
/** 用户名 */
|
||||||
|
@Excel(name = "用户名")
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/** 评论内容 */
|
||||||
|
@Excel(name = "评论内容")
|
||||||
|
private String commentText;
|
||||||
|
|
||||||
|
/** 评论ID */
|
||||||
|
@Excel(name = "评论ID")
|
||||||
|
private String commentId;
|
||||||
|
|
||||||
|
/** 图片URLs */
|
||||||
|
@Excel(name = "图片URLs")
|
||||||
|
private String pictureUrls;
|
||||||
|
|
||||||
|
/** 创建时间 */
|
||||||
|
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date createdAt;
|
||||||
|
|
||||||
|
/** 评论日期 */
|
||||||
|
@Excel(name = "评论日期")
|
||||||
|
private String commentDate;
|
||||||
|
|
||||||
|
/** 是否已使用 0-未使用 1-已使用 */
|
||||||
|
@Excel(name = "使用状态", readConverterExp = "0=未使用,1=已使用")
|
||||||
|
private Integer isUse;
|
||||||
|
|
||||||
|
/** 产品类型(从Redis映射获取) */
|
||||||
|
private String productType;
|
||||||
|
|
||||||
|
/** Redis映射的产品ID */
|
||||||
|
private String mappedProductId;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.ruoyi.jarvis.domain.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论接口调用统计
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CommentApiStatistics {
|
||||||
|
/** 统计日期 */
|
||||||
|
private Date statDate;
|
||||||
|
|
||||||
|
/** 接口类型:jd-京东,tb-淘宝 */
|
||||||
|
private String apiType;
|
||||||
|
|
||||||
|
/** 产品类型 */
|
||||||
|
private String productType;
|
||||||
|
|
||||||
|
/** 调用次数 */
|
||||||
|
private Long callCount;
|
||||||
|
|
||||||
|
/** 成功次数 */
|
||||||
|
private Long successCount;
|
||||||
|
|
||||||
|
/** 失败次数 */
|
||||||
|
private Long failCount;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.ruoyi.jarvis.domain.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论统计信息
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CommentStatistics {
|
||||||
|
/** 评论来源:jd-京东,tb-淘宝 */
|
||||||
|
private String source;
|
||||||
|
|
||||||
|
/** 产品类型 */
|
||||||
|
private String productType;
|
||||||
|
|
||||||
|
/** 产品ID */
|
||||||
|
private String productId;
|
||||||
|
|
||||||
|
/** 总评论数 */
|
||||||
|
private Long totalCount;
|
||||||
|
|
||||||
|
/** 可用评论数(未使用) */
|
||||||
|
private Long availableCount;
|
||||||
|
|
||||||
|
/** 已使用评论数 */
|
||||||
|
private Long usedCount;
|
||||||
|
|
||||||
|
/** 接口调用次数 */
|
||||||
|
private Long apiCallCount;
|
||||||
|
|
||||||
|
/** 今日调用次数 */
|
||||||
|
private Long todayCallCount;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.ruoyi.jarvis.mapper;
|
||||||
|
|
||||||
|
import com.ruoyi.jarvis.domain.Comment;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 京东评论 Mapper 接口
|
||||||
|
*/
|
||||||
|
public interface CommentMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询京东评论列表
|
||||||
|
*/
|
||||||
|
List<Comment> selectCommentList(Comment comment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询京东评论
|
||||||
|
*/
|
||||||
|
Comment selectCommentById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品ID查询评论统计
|
||||||
|
*/
|
||||||
|
Map<String, Object> selectCommentStatisticsByProductId(String productId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新评论使用状态
|
||||||
|
*/
|
||||||
|
int updateCommentIsUse(Comment comment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除评论
|
||||||
|
*/
|
||||||
|
int deleteCommentByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置评论使用状态(批量)
|
||||||
|
*/
|
||||||
|
int resetCommentIsUseByProductId(String productId);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.ruoyi.jarvis.mapper;
|
||||||
|
|
||||||
|
import com.ruoyi.jarvis.domain.TaobaoComment;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 淘宝评论 Mapper 接口
|
||||||
|
*/
|
||||||
|
public interface TaobaoCommentMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询淘宝评论列表
|
||||||
|
*/
|
||||||
|
List<TaobaoComment> selectTaobaoCommentList(TaobaoComment taobaoComment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询淘宝评论
|
||||||
|
*/
|
||||||
|
TaobaoComment selectTaobaoCommentById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品ID查询评论统计
|
||||||
|
*/
|
||||||
|
Map<String, Object> selectTaobaoCommentStatisticsByProductId(String productId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新评论使用状态
|
||||||
|
*/
|
||||||
|
int updateTaobaoCommentIsUse(TaobaoComment taobaoComment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除评论
|
||||||
|
*/
|
||||||
|
int deleteTaobaoCommentByIds(Integer[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置评论使用状态(批量)
|
||||||
|
*/
|
||||||
|
int resetTaobaoCommentIsUseByProductId(String productId);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.ruoyi.jarvis.service;
|
||||||
|
|
||||||
|
import com.ruoyi.jarvis.domain.Comment;
|
||||||
|
import com.ruoyi.jarvis.domain.dto.CommentStatistics;
|
||||||
|
import com.ruoyi.jarvis.domain.dto.CommentApiStatistics;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论管理 Service 接口
|
||||||
|
*/
|
||||||
|
public interface ICommentService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询京东评论列表
|
||||||
|
*/
|
||||||
|
List<Comment> selectCommentList(Comment comment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询京东评论
|
||||||
|
*/
|
||||||
|
Comment selectCommentById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新评论使用状态
|
||||||
|
*/
|
||||||
|
int updateCommentIsUse(Comment comment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除评论
|
||||||
|
*/
|
||||||
|
int deleteCommentByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置评论使用状态(批量)
|
||||||
|
*/
|
||||||
|
int resetCommentIsUseByProductId(String productId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取评论统计信息(包含Redis映射)
|
||||||
|
*/
|
||||||
|
List<CommentStatistics> getCommentStatistics(String source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录接口调用统计
|
||||||
|
*/
|
||||||
|
void recordApiCall(String apiType, String productType, boolean success);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取接口调用统计
|
||||||
|
*/
|
||||||
|
List<CommentApiStatistics> getApiStatistics(String apiType, String productType, String startDate, String endDate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Redis产品类型映射(京东)
|
||||||
|
*/
|
||||||
|
Map<String, String> getJdProductTypeMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Redis产品类型映射(淘宝)
|
||||||
|
*/
|
||||||
|
Map<String, String> getTbProductTypeMap();
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.ruoyi.jarvis.service;
|
||||||
|
|
||||||
|
import com.ruoyi.jarvis.domain.TaobaoComment;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 淘宝评论管理 Service 接口
|
||||||
|
*/
|
||||||
|
public interface ITaobaoCommentService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询淘宝评论列表
|
||||||
|
*/
|
||||||
|
List<TaobaoComment> selectTaobaoCommentList(TaobaoComment taobaoComment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询淘宝评论
|
||||||
|
*/
|
||||||
|
TaobaoComment selectTaobaoCommentById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新评论使用状态
|
||||||
|
*/
|
||||||
|
int updateTaobaoCommentIsUse(TaobaoComment taobaoComment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除评论
|
||||||
|
*/
|
||||||
|
int deleteTaobaoCommentByIds(Integer[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置评论使用状态(批量)
|
||||||
|
*/
|
||||||
|
int resetTaobaoCommentIsUseByProductId(String productId);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,282 @@
|
|||||||
|
package com.ruoyi.jarvis.service.impl;
|
||||||
|
|
||||||
|
import com.ruoyi.jarvis.domain.Comment;
|
||||||
|
import com.ruoyi.jarvis.domain.dto.CommentApiStatistics;
|
||||||
|
import com.ruoyi.jarvis.domain.dto.CommentStatistics;
|
||||||
|
import com.ruoyi.jarvis.mapper.CommentMapper;
|
||||||
|
import com.ruoyi.jarvis.service.ICommentService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论管理 Service 实现
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CommentServiceImpl implements ICommentService {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(CommentServiceImpl.class);
|
||||||
|
|
||||||
|
private static final String PRODUCT_TYPE_MAP_PREFIX = "product_type_map";
|
||||||
|
private static final String PRODUCT_TYPE_MAP_PREFIX_TB = "product_type_map_tb";
|
||||||
|
private static final String API_CALL_STAT_PREFIX = "comment:api:stat:";
|
||||||
|
private static final String API_CALL_TODAY_PREFIX = "comment:api:today:";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommentMapper commentMapper;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private com.ruoyi.jarvis.mapper.TaobaoCommentMapper taobaoCommentMapper;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Comment> selectCommentList(Comment comment) {
|
||||||
|
List<Comment> list = commentMapper.selectCommentList(comment);
|
||||||
|
// 填充Redis映射的产品类型信息
|
||||||
|
if (stringRedisTemplate != null) {
|
||||||
|
Map<String, String> jdMap = getJdProductTypeMap();
|
||||||
|
for (Comment c : list) {
|
||||||
|
// 查找对应的产品类型
|
||||||
|
String productId = c.getProductId();
|
||||||
|
if (jdMap != null) {
|
||||||
|
for (Map.Entry<String, String> entry : jdMap.entrySet()) {
|
||||||
|
if (entry.getValue().equals(productId)) {
|
||||||
|
c.setProductType(entry.getKey());
|
||||||
|
c.setMappedProductId(productId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Comment selectCommentById(Long id) {
|
||||||
|
Comment comment = commentMapper.selectCommentById(id);
|
||||||
|
if (comment != null && stringRedisTemplate != null) {
|
||||||
|
Map<String, String> jdMap = getJdProductTypeMap();
|
||||||
|
if (jdMap != null) {
|
||||||
|
String productId = comment.getProductId();
|
||||||
|
for (Map.Entry<String, String> entry : jdMap.entrySet()) {
|
||||||
|
if (entry.getValue().equals(productId)) {
|
||||||
|
comment.setProductType(entry.getKey());
|
||||||
|
comment.setMappedProductId(productId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateCommentIsUse(Comment comment) {
|
||||||
|
return commentMapper.updateCommentIsUse(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteCommentByIds(Long[] ids) {
|
||||||
|
return commentMapper.deleteCommentByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int resetCommentIsUseByProductId(String productId) {
|
||||||
|
return commentMapper.resetCommentIsUseByProductId(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommentStatistics> getCommentStatistics(String source) {
|
||||||
|
List<CommentStatistics> statisticsList = new ArrayList<>();
|
||||||
|
|
||||||
|
Map<String, String> productTypeMap = null;
|
||||||
|
if ("jd".equals(source) || source == null) {
|
||||||
|
productTypeMap = getJdProductTypeMap();
|
||||||
|
} else if ("tb".equals(source)) {
|
||||||
|
productTypeMap = getTbProductTypeMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (productTypeMap == null || productTypeMap.isEmpty()) {
|
||||||
|
return statisticsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : productTypeMap.entrySet()) {
|
||||||
|
String productType = entry.getKey();
|
||||||
|
String productId = entry.getValue();
|
||||||
|
|
||||||
|
CommentStatistics stats = new CommentStatistics();
|
||||||
|
stats.setSource("jd".equals(source) ? "京东评论" : "淘宝评论");
|
||||||
|
stats.setProductType(productType);
|
||||||
|
stats.setProductId(productId);
|
||||||
|
|
||||||
|
// 查询评论统计
|
||||||
|
Map<String, Object> statMap = null;
|
||||||
|
if ("jd".equals(source) || source == null) {
|
||||||
|
statMap = commentMapper.selectCommentStatisticsByProductId(productId);
|
||||||
|
} else if ("tb".equals(source) && taobaoCommentMapper != null) {
|
||||||
|
statMap = taobaoCommentMapper.selectTaobaoCommentStatisticsByProductId(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statMap != null) {
|
||||||
|
stats.setTotalCount(((Number) statMap.get("totalCount")).longValue());
|
||||||
|
stats.setAvailableCount(((Number) statMap.get("availableCount")).longValue());
|
||||||
|
stats.setUsedCount(((Number) statMap.get("usedCount")).longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取接口调用统计
|
||||||
|
if (stringRedisTemplate != null) {
|
||||||
|
String todayKey = API_CALL_TODAY_PREFIX + source + ":" + productType + ":" + getTodayDate();
|
||||||
|
String todayCount = stringRedisTemplate.opsForValue().get(todayKey);
|
||||||
|
stats.setTodayCallCount(todayCount != null ? Long.parseLong(todayCount) : 0L);
|
||||||
|
|
||||||
|
// 获取总调用次数(从Redis中统计)
|
||||||
|
String statKey = API_CALL_STAT_PREFIX + source + ":" + productType;
|
||||||
|
String totalCount = stringRedisTemplate.opsForValue().get(statKey);
|
||||||
|
stats.setApiCallCount(totalCount != null ? Long.parseLong(totalCount) : 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
statisticsList.add(stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
return statisticsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void recordApiCall(String apiType, String productType, boolean success) {
|
||||||
|
if (stringRedisTemplate == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String today = getTodayDate();
|
||||||
|
String todayKey = API_CALL_TODAY_PREFIX + apiType + ":" + productType + ":" + today;
|
||||||
|
stringRedisTemplate.opsForValue().increment(todayKey);
|
||||||
|
stringRedisTemplate.expire(todayKey, 7, TimeUnit.DAYS); // 保留7天
|
||||||
|
|
||||||
|
String statKey = API_CALL_STAT_PREFIX + apiType + ":" + productType;
|
||||||
|
stringRedisTemplate.opsForValue().increment(statKey);
|
||||||
|
|
||||||
|
// 记录成功/失败统计
|
||||||
|
String successKey = API_CALL_STAT_PREFIX + apiType + ":" + productType + ":success";
|
||||||
|
String failKey = API_CALL_STAT_PREFIX + apiType + ":" + productType + ":fail";
|
||||||
|
if (success) {
|
||||||
|
stringRedisTemplate.opsForValue().increment(successKey);
|
||||||
|
} else {
|
||||||
|
stringRedisTemplate.opsForValue().increment(failKey);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("记录接口调用统计失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CommentApiStatistics> getApiStatistics(String apiType, String productType, String startDate, String endDate) {
|
||||||
|
List<CommentApiStatistics> statisticsList = new ArrayList<>();
|
||||||
|
|
||||||
|
if (stringRedisTemplate == null) {
|
||||||
|
return statisticsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 如果指定了产品类型,只查询该类型的统计
|
||||||
|
if (productType != null && !productType.isEmpty()) {
|
||||||
|
CommentApiStatistics stats = new CommentApiStatistics();
|
||||||
|
stats.setApiType(apiType);
|
||||||
|
stats.setProductType(productType);
|
||||||
|
|
||||||
|
String statKey = API_CALL_STAT_PREFIX + apiType + ":" + productType;
|
||||||
|
String totalCount = stringRedisTemplate.opsForValue().get(statKey);
|
||||||
|
stats.setCallCount(totalCount != null ? Long.parseLong(totalCount) : 0L);
|
||||||
|
|
||||||
|
String successKey = statKey + ":success";
|
||||||
|
String successCount = stringRedisTemplate.opsForValue().get(successKey);
|
||||||
|
stats.setSuccessCount(successCount != null ? Long.parseLong(successCount) : 0L);
|
||||||
|
|
||||||
|
String failKey = statKey + ":fail";
|
||||||
|
String failCount = stringRedisTemplate.opsForValue().get(failKey);
|
||||||
|
stats.setFailCount(failCount != null ? Long.parseLong(failCount) : 0L);
|
||||||
|
|
||||||
|
statisticsList.add(stats);
|
||||||
|
} else {
|
||||||
|
// 查询所有产品类型的统计
|
||||||
|
Map<String, String> productTypeMap = "jd".equals(apiType) ? getJdProductTypeMap() : getTbProductTypeMap();
|
||||||
|
if (productTypeMap != null) {
|
||||||
|
for (String pt : productTypeMap.keySet()) {
|
||||||
|
CommentApiStatistics stats = new CommentApiStatistics();
|
||||||
|
stats.setApiType(apiType);
|
||||||
|
stats.setProductType(pt);
|
||||||
|
|
||||||
|
String statKey = API_CALL_STAT_PREFIX + apiType + ":" + pt;
|
||||||
|
String totalCount = stringRedisTemplate.opsForValue().get(statKey);
|
||||||
|
stats.setCallCount(totalCount != null ? Long.parseLong(totalCount) : 0L);
|
||||||
|
|
||||||
|
String successKey = statKey + ":success";
|
||||||
|
String successCount = stringRedisTemplate.opsForValue().get(successKey);
|
||||||
|
stats.setSuccessCount(successCount != null ? Long.parseLong(successCount) : 0L);
|
||||||
|
|
||||||
|
String failKey = statKey + ":fail";
|
||||||
|
String failCount = stringRedisTemplate.opsForValue().get(failKey);
|
||||||
|
stats.setFailCount(failCount != null ? Long.parseLong(failCount) : 0L);
|
||||||
|
|
||||||
|
statisticsList.add(stats);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取接口调用统计失败", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return statisticsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getJdProductTypeMap() {
|
||||||
|
if (stringRedisTemplate == null) {
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Map<Object, Object> rawMap = stringRedisTemplate.opsForHash().entries(PRODUCT_TYPE_MAP_PREFIX);
|
||||||
|
Map<String, String> result = new LinkedHashMap<>();
|
||||||
|
for (Map.Entry<Object, Object> entry : rawMap.entrySet()) {
|
||||||
|
result.put(entry.getKey().toString(), entry.getValue().toString());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取京东产品类型映射失败", e);
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getTbProductTypeMap() {
|
||||||
|
if (stringRedisTemplate == null) {
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Map<Object, Object> rawMap = stringRedisTemplate.opsForHash().entries(PRODUCT_TYPE_MAP_PREFIX_TB);
|
||||||
|
Map<String, String> result = new LinkedHashMap<>();
|
||||||
|
for (Map.Entry<Object, Object> entry : rawMap.entrySet()) {
|
||||||
|
result.put(entry.getKey().toString(), entry.getValue().toString());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取淘宝产品类型映射失败", e);
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTodayDate() {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
return sdf.format(new Date());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -14,6 +14,8 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,6 +129,43 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
|||||||
|
|
||||||
logger.info("检测到waybill_no: {} - 订单ID: {}", waybillNo, orderId);
|
logger.info("检测到waybill_no: {} - 订单ID: {}", waybillNo, orderId);
|
||||||
|
|
||||||
|
// 兼容处理:检查Redis中是否已有该订单的运单号记录
|
||||||
|
// 如果存在且运单号一致,说明之前已经推送过了(可能是之前没有配置接收人但推送成功的情况)
|
||||||
|
String redisKey = REDIS_WAYBILL_KEY_PREFIX + orderId;
|
||||||
|
String existingWaybillNo = stringRedisTemplate.opsForValue().get(redisKey);
|
||||||
|
|
||||||
|
if (existingWaybillNo != null && existingWaybillNo.trim().equals(waybillNo.trim())) {
|
||||||
|
// 运单号一致,说明之前已经推送过了,直接标记为已处理,跳过推送
|
||||||
|
logger.info("订单运单号已存在且一致,说明之前已推送过,跳过重复推送 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
||||||
|
// 更新过期时间,确保记录不会过期
|
||||||
|
stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 兼容处理:如果Redis中没有记录,但订单创建时间在30天之前,且获取到了运单号
|
||||||
|
// 说明可能是之前推送过但没标记的情况(比如之前没有配置接收人但推送成功,响应解析失败)
|
||||||
|
// 这种情况下,直接标记为已处理,跳过推送,避免重复推送旧订单
|
||||||
|
if (existingWaybillNo == null && order.getCreateTime() != null) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, -30); // 30天前
|
||||||
|
Date thresholdDate = calendar.getTime();
|
||||||
|
|
||||||
|
if (order.getCreateTime().before(thresholdDate)) {
|
||||||
|
// 订单创建时间在30天之前,且Redis中没有记录,但获取到了运单号
|
||||||
|
// 视为之前已推送过但未标记,直接标记为已处理,跳过推送
|
||||||
|
logger.info("订单创建时间较早({}),且Redis中无记录但已获取到运单号,视为之前已推送过,直接标记为已处理,跳过推送 - 订单ID: {}, waybill_no: {}",
|
||||||
|
order.getCreateTime(), orderId, waybillNo);
|
||||||
|
stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果Redis中有记录但运单号不一致,记录警告
|
||||||
|
if (existingWaybillNo != null && !existingWaybillNo.trim().equals(waybillNo.trim())) {
|
||||||
|
logger.warn("订单运单号发生变化 - 订单ID: {}, 旧运单号: {}, 新运单号: {}, 将重新推送",
|
||||||
|
orderId, existingWaybillNo, waybillNo);
|
||||||
|
}
|
||||||
|
|
||||||
// 调用企业应用推送,只有推送成功才记录状态
|
// 调用企业应用推送,只有推送成功才记录状态
|
||||||
boolean pushSuccess = sendEnterprisePushNotification(order, waybillNo);
|
boolean pushSuccess = sendEnterprisePushNotification(order, waybillNo);
|
||||||
if (!pushSuccess) {
|
if (!pushSuccess) {
|
||||||
@@ -135,12 +174,13 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 保存运单号到Redis(避免重复处理)- 使用原子操作确保只写入一次
|
// 保存运单号到Redis(避免重复处理)- 使用原子操作确保只写入一次
|
||||||
String redisKey = REDIS_WAYBILL_KEY_PREFIX + orderId;
|
|
||||||
Boolean setSuccess = stringRedisTemplate.opsForValue().setIfAbsent(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
Boolean setSuccess = stringRedisTemplate.opsForValue().setIfAbsent(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
||||||
|
|
||||||
if (Boolean.FALSE.equals(setSuccess)) {
|
if (Boolean.FALSE.equals(setSuccess)) {
|
||||||
// 如果Redis中已存在,说明可能被其他线程处理了,记录警告但不算失败
|
// 如果Redis中已存在,说明可能被其他线程处理了,记录警告但不算失败
|
||||||
logger.warn("订单运单号已存在(可能被并发处理),但推送已成功 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
logger.warn("订单运单号已存在(可能被并发处理),但推送已成功 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
||||||
|
// 更新过期时间,确保记录不会过期
|
||||||
|
stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("物流信息获取并推送成功 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
logger.info("物流信息获取并推送成功 - 订单ID: {}, waybill_no: {}", orderId, waybillNo);
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package com.ruoyi.jarvis.service.impl;
|
||||||
|
|
||||||
|
import com.ruoyi.jarvis.domain.TaobaoComment;
|
||||||
|
import com.ruoyi.jarvis.mapper.TaobaoCommentMapper;
|
||||||
|
import com.ruoyi.jarvis.service.ITaobaoCommentService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 淘宝评论管理 Service 实现
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TaobaoCommentServiceImpl implements ITaobaoCommentService {
|
||||||
|
|
||||||
|
private static final String PRODUCT_TYPE_MAP_PREFIX_TB = "product_type_map_tb";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaobaoCommentMapper taobaoCommentMapper;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TaobaoComment> selectTaobaoCommentList(TaobaoComment taobaoComment) {
|
||||||
|
List<TaobaoComment> list = taobaoCommentMapper.selectTaobaoCommentList(taobaoComment);
|
||||||
|
// 填充Redis映射的产品类型信息
|
||||||
|
if (stringRedisTemplate != null) {
|
||||||
|
Map<String, String> tbMap = getTbProductTypeMap();
|
||||||
|
for (TaobaoComment c : list) {
|
||||||
|
// 查找对应的产品类型
|
||||||
|
String productId = c.getProductId();
|
||||||
|
if (tbMap != null) {
|
||||||
|
for (Map.Entry<String, String> entry : tbMap.entrySet()) {
|
||||||
|
if (entry.getValue().equals(productId)) {
|
||||||
|
c.setProductType(entry.getKey());
|
||||||
|
c.setMappedProductId(productId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TaobaoComment selectTaobaoCommentById(Integer id) {
|
||||||
|
TaobaoComment comment = taobaoCommentMapper.selectTaobaoCommentById(id);
|
||||||
|
if (comment != null && stringRedisTemplate != null) {
|
||||||
|
Map<String, String> tbMap = getTbProductTypeMap();
|
||||||
|
if (tbMap != null) {
|
||||||
|
String productId = comment.getProductId();
|
||||||
|
for (Map.Entry<String, String> entry : tbMap.entrySet()) {
|
||||||
|
if (entry.getValue().equals(productId)) {
|
||||||
|
comment.setProductType(entry.getKey());
|
||||||
|
comment.setMappedProductId(productId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateTaobaoCommentIsUse(TaobaoComment taobaoComment) {
|
||||||
|
return taobaoCommentMapper.updateTaobaoCommentIsUse(taobaoComment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteTaobaoCommentByIds(Integer[] ids) {
|
||||||
|
return taobaoCommentMapper.deleteTaobaoCommentByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int resetTaobaoCommentIsUseByProductId(String productId) {
|
||||||
|
return taobaoCommentMapper.resetTaobaoCommentIsUseByProductId(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getTbProductTypeMap() {
|
||||||
|
if (stringRedisTemplate == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Map<Object, Object> rawMap = stringRedisTemplate.opsForHash().entries(PRODUCT_TYPE_MAP_PREFIX_TB);
|
||||||
|
Map<String, String> result = new java.util.LinkedHashMap<>();
|
||||||
|
for (Map.Entry<Object, Object> entry : rawMap.entrySet()) {
|
||||||
|
result.put(entry.getKey().toString(), entry.getValue().toString());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ruoyi.jarvis.mapper.CommentMapper">
|
||||||
|
|
||||||
|
<resultMap id="CommentResult" type="Comment">
|
||||||
|
<result property="id" column="id"/>
|
||||||
|
<result property="productId" column="product_id"/>
|
||||||
|
<result property="userName" column="user_name"/>
|
||||||
|
<result property="commentText" column="comment_text"/>
|
||||||
|
<result property="commentId" column="comment_id"/>
|
||||||
|
<result property="pictureUrls" column="picture_urls"/>
|
||||||
|
<result property="createdAt" column="created_at"/>
|
||||||
|
<result property="commentDate" column="comment_date"/>
|
||||||
|
<result property="isUse" column="is_use"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectCommentBase">
|
||||||
|
select id, product_id, user_name, comment_text, comment_id, picture_urls,
|
||||||
|
created_at, comment_date, is_use
|
||||||
|
from comments
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectCommentList" parameterType="Comment" resultMap="CommentResult">
|
||||||
|
<include refid="selectCommentBase"/>
|
||||||
|
<where>
|
||||||
|
<if test="productId != null and productId != ''"> and product_id = #{productId}</if>
|
||||||
|
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
|
||||||
|
<if test="commentText != null and commentText != ''"> and comment_text like concat('%', #{commentText}, '%')</if>
|
||||||
|
<if test="isUse != null"> and is_use = #{isUse}</if>
|
||||||
|
<if test="params.beginTime != null and params.beginTime != ''">
|
||||||
|
and created_at >= #{params.beginTime}
|
||||||
|
</if>
|
||||||
|
<if test="params.endTime != null and params.endTime != ''">
|
||||||
|
and created_at <= #{params.endTime}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by created_at desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectCommentById" parameterType="Long" resultMap="CommentResult">
|
||||||
|
<include refid="selectCommentBase"/>
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectCommentStatisticsByProductId" parameterType="String" resultType="java.util.Map">
|
||||||
|
select
|
||||||
|
count(*) as totalCount,
|
||||||
|
sum(case when is_use = 0 then 1 else 0 end) as availableCount,
|
||||||
|
sum(case when is_use = 1 then 1 else 0 end) as usedCount
|
||||||
|
from comments
|
||||||
|
where product_id = #{productId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="updateCommentIsUse" parameterType="Comment">
|
||||||
|
update comments
|
||||||
|
<set>
|
||||||
|
<if test="isUse != null">is_use = #{isUse},</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="resetCommentIsUseByProductId" parameterType="String">
|
||||||
|
update comments
|
||||||
|
set is_use = 0
|
||||||
|
where product_id = #{productId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteCommentByIds" parameterType="String">
|
||||||
|
delete from comments where id in
|
||||||
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
||||||
@@ -11,12 +11,13 @@
|
|||||||
<result property="secretKey" column="secret_key"/>
|
<result property="secretKey" column="secret_key"/>
|
||||||
<result property="isActive" column="is_active"/>
|
<result property="isActive" column="is_active"/>
|
||||||
<result property="isCount" column="is_count"/>
|
<result property="isCount" column="is_count"/>
|
||||||
|
<result property="touser" column="touser"/>
|
||||||
<result property="createdAt" column="created_at"/>
|
<result property="createdAt" column="created_at"/>
|
||||||
<result property="updatedAt" column="updated_at"/>
|
<result property="updatedAt" column="updated_at"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectSuperAdminVo">
|
<sql id="selectSuperAdminVo">
|
||||||
select id, wxid, name, union_id, app_key, secret_key, is_active, is_count, created_at, updated_at from super_admin
|
select id, wxid, name, union_id, app_key, secret_key, is_active, is_count, touser, created_at, updated_at from super_admin
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectSuperAdminList" parameterType="SuperAdmin" resultMap="SuperAdminResult">
|
<select id="selectSuperAdminList" parameterType="SuperAdmin" resultMap="SuperAdminResult">
|
||||||
@@ -51,6 +52,8 @@
|
|||||||
<if test="appKey != null and appKey != ''">app_key,</if>
|
<if test="appKey != null and appKey != ''">app_key,</if>
|
||||||
<if test="secretKey != null and secretKey != ''">secret_key,</if>
|
<if test="secretKey != null and secretKey != ''">secret_key,</if>
|
||||||
<if test="isActive != null">is_active,</if>
|
<if test="isActive != null">is_active,</if>
|
||||||
|
<if test="isCount != null">is_count,</if>
|
||||||
|
<if test="touser != null and touser != ''">touser,</if>
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
</trim>
|
</trim>
|
||||||
@@ -61,6 +64,8 @@
|
|||||||
<if test="appKey != null and appKey != ''">#{appKey},</if>
|
<if test="appKey != null and appKey != ''">#{appKey},</if>
|
||||||
<if test="secretKey != null and secretKey != ''">#{secretKey},</if>
|
<if test="secretKey != null and secretKey != ''">#{secretKey},</if>
|
||||||
<if test="isActive != null">#{isActive},</if>
|
<if test="isActive != null">#{isActive},</if>
|
||||||
|
<if test="isCount != null">#{isCount},</if>
|
||||||
|
<if test="touser != null and touser != ''">#{touser},</if>
|
||||||
now(),
|
now(),
|
||||||
now(),
|
now(),
|
||||||
</trim>
|
</trim>
|
||||||
@@ -76,6 +81,7 @@
|
|||||||
<if test="secretKey != null and secretKey != ''">secret_key = #{secretKey},</if>
|
<if test="secretKey != null and secretKey != ''">secret_key = #{secretKey},</if>
|
||||||
<if test="isActive != null">is_active = #{isActive},</if>
|
<if test="isActive != null">is_active = #{isActive},</if>
|
||||||
<if test="isCount != null">is_count = #{isCount},</if>
|
<if test="isCount != null">is_count = #{isCount},</if>
|
||||||
|
<if test="touser != null">touser = #{touser},</if>
|
||||||
updated_at = now(),
|
updated_at = now(),
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ruoyi.jarvis.mapper.TaobaoCommentMapper">
|
||||||
|
|
||||||
|
<resultMap id="TaobaoCommentResult" type="TaobaoComment">
|
||||||
|
<result property="id" column="id"/>
|
||||||
|
<result property="productId" column="product_id"/>
|
||||||
|
<result property="userName" column="user_name"/>
|
||||||
|
<result property="commentText" column="comment_text"/>
|
||||||
|
<result property="commentId" column="comment_id"/>
|
||||||
|
<result property="pictureUrls" column="picture_urls"/>
|
||||||
|
<result property="createdAt" column="created_at"/>
|
||||||
|
<result property="commentDate" column="comment_date"/>
|
||||||
|
<result property="isUse" column="is_use"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectTaobaoCommentBase">
|
||||||
|
select id, product_id, user_name, comment_text, comment_id, picture_urls,
|
||||||
|
created_at, comment_date, is_use
|
||||||
|
from taobao_comments
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectTaobaoCommentList" parameterType="TaobaoComment" resultMap="TaobaoCommentResult">
|
||||||
|
<include refid="selectTaobaoCommentBase"/>
|
||||||
|
<where>
|
||||||
|
<if test="productId != null and productId != ''"> and product_id = #{productId}</if>
|
||||||
|
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
|
||||||
|
<if test="commentText != null and commentText != ''"> and comment_text like concat('%', #{commentText}, '%')</if>
|
||||||
|
<if test="isUse != null"> and is_use = #{isUse}</if>
|
||||||
|
<if test="params.beginTime != null and params.beginTime != ''">
|
||||||
|
and created_at >= #{params.beginTime}
|
||||||
|
</if>
|
||||||
|
<if test="params.endTime != null and params.endTime != ''">
|
||||||
|
and created_at <= #{params.endTime}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by created_at desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectTaobaoCommentById" parameterType="Integer" resultMap="TaobaoCommentResult">
|
||||||
|
<include refid="selectTaobaoCommentBase"/>
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectTaobaoCommentStatisticsByProductId" parameterType="String" resultType="java.util.Map">
|
||||||
|
select
|
||||||
|
count(*) as totalCount,
|
||||||
|
sum(case when is_use = 0 then 1 else 0 end) as availableCount,
|
||||||
|
sum(case when is_use = 1 then 1 else 0 end) as usedCount
|
||||||
|
from taobao_comments
|
||||||
|
where product_id = #{productId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="updateTaobaoCommentIsUse" parameterType="TaobaoComment">
|
||||||
|
update taobao_comments
|
||||||
|
<set>
|
||||||
|
<if test="isUse != null">is_use = #{isUse},</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="resetTaobaoCommentIsUseByProductId" parameterType="String">
|
||||||
|
update taobao_comments
|
||||||
|
set is_use = 0
|
||||||
|
where product_id = #{productId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteTaobaoCommentByIds" parameterType="String">
|
||||||
|
delete from taobao_comments where id in
|
||||||
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
||||||
4
sql/add_super_admin_touser_field.sql
Normal file
4
sql/add_super_admin_touser_field.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
-- 为超级管理员表添加接收人字段
|
||||||
|
-- 字段说明:touser 存储企业微信用户ID,多个用逗号分隔
|
||||||
|
ALTER TABLE super_admin ADD COLUMN touser VARCHAR(500) DEFAULT NULL COMMENT '接收人(企业微信用户ID,多个用逗号分隔)';
|
||||||
|
|
||||||
Reference in New Issue
Block a user