提交 01e67bc6 authored 作者: zgy's avatar zgy

点赞,取消点赞,查询评论添加点赞标识

上级 18cde5ad
...@@ -43,8 +43,12 @@ public class KeyConstant { ...@@ -43,8 +43,12 @@ public class KeyConstant {
//订单失效 //订单失效
public final static Integer ORDER_EXPIRE = 0; public final static Integer ORDER_EXPIRE = 0;
//搜索 //搜索
public final static String USER_SEARCH="user_search"; public final static String USER_SEARCH = "user_search";
//搜索记录时长 //搜索记录时长
public final static Integer SEARCH_EXPIRE=259200; public final static Integer SEARCH_EXPIRE = 259200;
//点赞
public final static String GIVE_LIKE = "give_like";
public final static String YES="yes";
} }
...@@ -93,9 +93,10 @@ public class ShopifyController { ...@@ -93,9 +93,10 @@ public class ShopifyController {
*/ */
@ApiOperation(value = "查询商品评论") @ApiOperation(value = "查询商品评论")
@GetMapping("/querylastcomment") @GetMapping("/querylastcomment")
public Result queryLastComment(@ApiParam("商品ID") @RequestParam("itemId") String itemId) { public Result queryLastComment(@ApiParam("商品ID") @RequestParam("itemId") String itemId,
@ApiParam("商品ID") @RequestParam("userId") String userId) {
return tbCfItemCommentService.queryLastComment(itemId); return tbCfItemCommentService.queryLastComment(itemId,userId);
} }
/** /**
...@@ -110,8 +111,9 @@ public class ShopifyController { ...@@ -110,8 +111,9 @@ public class ShopifyController {
@GetMapping("/querycomments") @GetMapping("/querycomments")
public Result queryComments(@ApiParam("商品ID") @RequestParam("itemId") String itemId, public Result queryComments(@ApiParam("商品ID") @RequestParam("itemId") String itemId,
@ApiParam(value = "页数 默认1") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @ApiParam(value = "页数 默认1") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@ApiParam(value = "每页大小 默认10") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { @ApiParam(value = "每页大小 默认10") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
return tbCfItemCommentService.querycomments(itemId, pageNum, pageSize); @ApiParam("商品ID") @RequestParam("userId") String userId) {
return tbCfItemCommentService.querycomments(itemId, pageNum, pageSize,userId);
} }
/** /**
...@@ -198,9 +200,11 @@ public class ShopifyController { ...@@ -198,9 +200,11 @@ public class ShopifyController {
* @return * @return
*/ */
@ApiOperation("点赞") @ApiOperation("点赞")
@GetMapping("/giveLike/{commentId}") @GetMapping("/giveLike/{commentId}/{userId}/{itemId}")
public Result giveLike(@ApiParam("评论ID") @PathVariable String commentId) { public Result giveLike(@ApiParam("评论ID") @PathVariable String commentId,
return tbCfItemCommentService.giveLike(commentId); @ApiParam("用户ID") @PathVariable String userId,
@ApiParam("商品ID") @PathVariable String itemId) {
return tbCfItemCommentService.giveLike(commentId, userId, itemId);
} }
......
...@@ -79,6 +79,16 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -79,6 +79,16 @@ public class TbCfItemCommentEntity implements Serializable {
private String orderNo; private String orderNo;
private String itemName; private String itemName;
private boolean isLike;
public boolean isLike() {
return isLike;
}
public void setLike(boolean like) {
isLike = like;
}
public String getUserName() { public String getUserName() {
return userName; return userName;
} }
...@@ -120,6 +130,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -120,6 +130,7 @@ public class TbCfItemCommentEntity implements Serializable {
public String getId() { public String getId() {
return id; return id;
} }
/** /**
* 设置:评论人 * 设置:评论人
*/ */
...@@ -133,6 +144,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -133,6 +144,7 @@ public class TbCfItemCommentEntity implements Serializable {
public String getUserId() { public String getUserId() {
return userId; return userId;
} }
/** /**
* 设置:订单ID * 设置:订单ID
*/ */
...@@ -146,6 +158,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -146,6 +158,7 @@ public class TbCfItemCommentEntity implements Serializable {
public String getOrderId() { public String getOrderId() {
return orderId; return orderId;
} }
/** /**
* 设置:商品ID * 设置:商品ID
*/ */
...@@ -159,6 +172,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -159,6 +172,7 @@ public class TbCfItemCommentEntity implements Serializable {
public String getItemId() { public String getItemId() {
return itemId; return itemId;
} }
/** /**
* 设置:类型 0: 只有文本内容 1:带图片 * 设置:类型 0: 只有文本内容 1:带图片
*/ */
...@@ -172,6 +186,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -172,6 +186,7 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getType() { public Integer getType() {
return type; return type;
} }
/** /**
* 设置:图片或视频的url * 设置:图片或视频的url
*/ */
...@@ -185,6 +200,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -185,6 +200,7 @@ public class TbCfItemCommentEntity implements Serializable {
public String getUrls() { public String getUrls() {
return urls; return urls;
} }
/** /**
* 设置:商品评分 * 设置:商品评分
*/ */
...@@ -198,6 +214,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -198,6 +214,7 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getItemScore() { public Integer getItemScore() {
return itemScore; return itemScore;
} }
/** /**
* 设置:服务评分 * 设置:服务评分
*/ */
...@@ -211,6 +228,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -211,6 +228,7 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getServiceScore() { public Integer getServiceScore() {
return serviceScore; return serviceScore;
} }
/** /**
* 设置:物流评分 * 设置:物流评分
*/ */
...@@ -224,6 +242,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -224,6 +242,7 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getLogisticsScore() { public Integer getLogisticsScore() {
return logisticsScore; return logisticsScore;
} }
/** /**
* 设置:价格评分 * 设置:价格评分
*/ */
...@@ -237,6 +256,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -237,6 +256,7 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getPriceScore() { public Integer getPriceScore() {
return priceScore; return priceScore;
} }
/** /**
* 设置:商品评论 * 设置:商品评论
*/ */
...@@ -250,6 +270,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -250,6 +270,7 @@ public class TbCfItemCommentEntity implements Serializable {
public String getItemReview() { public String getItemReview() {
return itemReview; return itemReview;
} }
/** /**
* 设置:点赞人数 * 设置:点赞人数
*/ */
...@@ -263,6 +284,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -263,6 +284,7 @@ public class TbCfItemCommentEntity implements Serializable {
public Long getLikeNum() { public Long getLikeNum() {
return likeNum; return likeNum;
} }
/** /**
* 设置:删除标志 0:正常 1:已删除 * 设置:删除标志 0:正常 1:已删除
*/ */
...@@ -276,6 +298,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -276,6 +298,7 @@ public class TbCfItemCommentEntity implements Serializable {
public Integer getDelFlag() { public Integer getDelFlag() {
return delFlag; return delFlag;
} }
/** /**
* 设置:创建时间 * 设置:创建时间
*/ */
...@@ -289,6 +312,7 @@ public class TbCfItemCommentEntity implements Serializable { ...@@ -289,6 +312,7 @@ public class TbCfItemCommentEntity implements Serializable {
public Date getCreateTime() { public Date getCreateTime() {
return createTime; return createTime;
} }
/** /**
* 设置:更新时间 * 设置:更新时间
*/ */
......
...@@ -76,15 +76,15 @@ public interface TbCfItemCommentService { ...@@ -76,15 +76,15 @@ public interface TbCfItemCommentService {
*/ */
int deleteBatch(String[] ids); int deleteBatch(String[] ids);
Result queryLastComment(String itemId); Result queryLastComment(String itemId, String userId);
Result querycomments(String itemId, Integer pageNum, Integer pageSize); Result querycomments(String itemId, Integer pageNum, Integer pageSize,String userId);
Result addComment(TbCfItemCommentEntity comment); Result addComment(TbCfItemCommentEntity comment);
Result delComment(String commentId); Result delComment(String commentId);
Result giveLike(String commentId); Result giveLike(String commentId, String userId, String itemId);
} }
package com.diaoyun.zion.chinafrica.service.impl; package com.diaoyun.zion.chinafrica.service.impl;
import com.diaoyun.zion.chinafrica.constant.KeyConstant;
import com.diaoyun.zion.chinafrica.dao.TbCfItemCommentDao; import com.diaoyun.zion.chinafrica.dao.TbCfItemCommentDao;
import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity; import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity;
import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntityExtends; import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntityExtends;
import com.diaoyun.zion.chinafrica.service.TbCfItemCommentService; import com.diaoyun.zion.chinafrica.service.TbCfItemCommentService;
import com.diaoyun.zion.master.base.Result; import com.diaoyun.zion.master.base.Result;
import com.diaoyun.zion.master.common.RedisCache;
import com.diaoyun.zion.master.enums.ResultCodeEnum; import com.diaoyun.zion.master.enums.ResultCodeEnum;
import com.diaoyun.zion.master.util.IdUtil; import com.diaoyun.zion.master.util.IdUtil;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -15,11 +17,9 @@ import org.slf4j.LoggerFactory; ...@@ -15,11 +17,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.github.pagehelper.page.PageMethod.startPage; import static com.github.pagehelper.page.PageMethod.startPage;
...@@ -34,6 +34,8 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService { ...@@ -34,6 +34,8 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService {
private static Logger logger = LoggerFactory.getLogger(TbCfItemCommentServiceImpl.class); private static Logger logger = LoggerFactory.getLogger(TbCfItemCommentServiceImpl.class);
@Autowired @Autowired
private TbCfItemCommentDao tbCfItemCommentDao; private TbCfItemCommentDao tbCfItemCommentDao;
@Resource
private RedisCache<Object> redisCache;
@Override @Override
public TbCfItemCommentEntity queryObject(String id) { public TbCfItemCommentEntity queryObject(String id) {
...@@ -78,15 +80,21 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService { ...@@ -78,15 +80,21 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService {
* @return * @return
*/ */
@Override @Override
public Result queryLastComment(String itemId) { public Result queryLastComment(String itemId, String userId) {
Result result = new Result(); Result result = new Result();
try { try {
TbCfItemCommentEntity lastComment = tbCfItemCommentDao.queryLastComment(itemId); TbCfItemCommentEntity lastComment = tbCfItemCommentDao.queryLastComment(itemId);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
boolean isLike = false;
if (lastComment != null) { if (lastComment != null) {
double totalScore = lastComment.getItemScore() + lastComment.getLogisticsScore() + lastComment.getPriceScore() + lastComment.getServiceScore(); double totalScore = lastComment.getItemScore() + lastComment.getLogisticsScore() + lastComment.getPriceScore() + lastComment.getServiceScore();
BigDecimal total = new BigDecimal(totalScore); BigDecimal total = new BigDecimal(totalScore);
double score = total.divide(new BigDecimal(4), 1, BigDecimal.ROUND_UP).doubleValue(); double score = total.divide(new BigDecimal(4), 1, BigDecimal.ROUND_UP).doubleValue();
String give_like = (String) redisCache.get(KeyConstant.GIVE_LIKE + userId + itemId);
if (!StringUtils.isBlank(give_like) && KeyConstant.YES.equals(give_like)) {
isLike = true;
}
map.put("isLike", isLike);
map.put("score", score); map.put("score", score);
map.put("lastComment", lastComment); map.put("lastComment", lastComment);
result.setData(map).setMessage("success"); result.setData(map).setMessage("success");
...@@ -111,12 +119,23 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService { ...@@ -111,12 +119,23 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService {
* @return * @return
*/ */
@Override @Override
public Result querycomments(String itemId, Integer pageNum, Integer pageSize) { public Result querycomments(String itemId, Integer pageNum, Integer pageSize, String userId) {
Result<PageInfo> result = new Result(); Result<PageInfo> result = new Result();
try { try {
startPage(pageNum, pageSize); startPage(pageNum, pageSize);
List<TbCfItemCommentEntity> comments = tbCfItemCommentDao.querycomments(itemId); List<TbCfItemCommentEntity> comments = tbCfItemCommentDao.querycomments(itemId);
PageInfo<TbCfItemCommentEntity> pageInfo = new PageInfo<>(comments); List<TbCfItemCommentEntity> commentList = new ArrayList<>();
for (TbCfItemCommentEntity comment : comments) {
TbCfItemCommentEntity commentEntity = tbCfItemCommentDao.queryObject(comment.getId());
commentEntity.setLike(false);
System.err.println(comment.getUserId());
String give_like = (String) redisCache.get(KeyConstant.GIVE_LIKE + comment.getUserId() + comment.getItemId());
if (!StringUtils.isBlank(give_like) && KeyConstant.YES.equals(give_like)) {
commentEntity.setLike(true);
}
commentList.add(commentEntity);
}
PageInfo<TbCfItemCommentEntity> pageInfo = new PageInfo<>(commentList);
result.setData(pageInfo); result.setData(pageInfo);
} catch (Exception e) { } catch (Exception e) {
result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage(e.getMessage()); result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage(e.getMessage());
...@@ -133,7 +152,13 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService { ...@@ -133,7 +152,13 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService {
*/ */
public Result addComment(TbCfItemCommentEntity comment) { public Result addComment(TbCfItemCommentEntity comment) {
Result result = new Result(); Result result = new Result();
try { try {
TbCfItemCommentEntity commentEntity = tbCfItemCommentDao.queryByUser(comment.getItemId(), comment.getUserId());
if (commentEntity != null) {
result.setMessage("Already reviewed this product!");
return result;
}
comment.setId(IdUtil.createIdbyUUID()); comment.setId(IdUtil.createIdbyUUID());
comment.setDelFlag(0); comment.setDelFlag(0);
comment.setLikeNum(0L); comment.setLikeNum(0L);
...@@ -182,13 +207,29 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService { ...@@ -182,13 +207,29 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService {
return result; return result;
} }
/**
* 点赞
*
* @param commentId
* @param userId
* @param itemId
* @return
*/
@Override @Override
public Result giveLike(String commentId) { public Result giveLike(String commentId, String userId, String itemId) {
Result result = new Result(); Result result = new Result();
try { try {
String give_like = (String) redisCache.get(KeyConstant.GIVE_LIKE + userId + itemId);
TbCfItemCommentEntity comment = tbCfItemCommentDao.queryObject(commentId); TbCfItemCommentEntity comment = tbCfItemCommentDao.queryObject(commentId);
Long likeNum = comment.getLikeNum(); Long likeNum = comment.getLikeNum();
comment.setLikeNum(++likeNum); if (!StringUtils.isBlank(give_like) && KeyConstant.YES.equals(give_like)) {
comment.setLikeNum(--likeNum);
redisCache.delete(KeyConstant.GIVE_LIKE + userId + itemId);
} else {
comment.setLikeNum(++likeNum);
redisCache.set(KeyConstant.GIVE_LIKE + userId + itemId, KeyConstant.YES);
}
tbCfItemCommentDao.update(comment); tbCfItemCommentDao.update(comment);
result.setMessage(ResultCodeEnum.SUCCESS.getDesc()); result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
} catch (Exception e) { } catch (Exception e) {
...@@ -199,5 +240,4 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService { ...@@ -199,5 +240,4 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService {
} }
} }
...@@ -217,7 +217,6 @@ public class TbCfOrderServiceImpl implements TbCfOrderService { ...@@ -217,7 +217,6 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
@Override @Override
public Result getUserOrderList(Integer pageNum, Integer pageSize, Integer orderStatus) throws InterruptedException { public Result getUserOrderList(Integer pageNum, Integer pageSize, Integer orderStatus) throws InterruptedException {
Result<PageInfo<TbCfOrderVo>> result = new Result<>(); Result<PageInfo<TbCfOrderVo>> result = new Result<>();
boolean isCommented = false;
//获取用户 //获取用户
synchronized (this) { synchronized (this) {
String token = jwtTokenProvider.resolveToken(request); String token = jwtTokenProvider.resolveToken(request);
...@@ -238,6 +237,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService { ...@@ -238,6 +237,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
//返回的订单商品详情 //返回的订单商品详情
List<TbCfCartItemDetailVo> itemDetailVoList = new ArrayList<>(); List<TbCfCartItemDetailVo> itemDetailVoList = new ArrayList<>();
for (TbCfItemDetailEntity tbCfItemDetail : tbCfItemDetailList) { for (TbCfItemDetailEntity tbCfItemDetail : tbCfItemDetailList) {
boolean isCommented = false;
//判断商品是否评论过 //判断商品是否评论过
TbCfItemCommentEntity comment = tbCfItemCommentDao.queryByUser(tbCfItemDetail.getItemId(), tbCfUserInfoVo.getUserId()); TbCfItemCommentEntity comment = tbCfItemCommentDao.queryByUser(tbCfItemDetail.getItemId(), tbCfUserInfoVo.getUserId());
if (comment != null) { if (comment != null) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论