1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user