提交 208869a4 authored 作者: zgy's avatar zgy

评论点赞,商品评分计算

上级 4483bd96
......@@ -190,4 +190,16 @@ public class ShopifyController {
public Result searchProducts(@ApiParam("商品标题") @RequestParam("title") String title) {
return shopifyService.searchProductByTitle(title);
}
/**
* 点赞(评论)
*
* @param commentId
* @return
*/
@ApiOperation("点赞")
@GetMapping("/giveLike/{commentId}")
public Result giveLike(@ApiParam("评论ID") @PathVariable String commentId) {
return tbCfItemCommentService.giveLike(commentId);
}
}
......@@ -15,6 +15,9 @@ import java.util.List;
*/
public interface TbCfItemCommentDao extends BaseDao<TbCfItemCommentEntity> {
public TbCfItemCommentEntityExtends queryLastComment(String itemId);
TbCfItemCommentEntity queryLastComment(String itemId);
List<TbCfItemCommentEntity> querycomments(String itemId);
List<TbCfItemCommentEntity> queryScore(String itemId);
}
......@@ -7,7 +7,7 @@ import java.util.Date;
* @Date: 2019/11/18
* @Description: 商品评论(默认显示最新条信息)
*/
public class TbCfItemCommentEntityExtends {
public class TbCfItemCommentEntityExtends {
/**
* 商品评论ID
*/
......
......@@ -20,4 +20,5 @@ public interface ShopifyService {
Result queryAllProducts(String product_id);
Result searchProductByTitle(String title);
}
......@@ -84,5 +84,7 @@ public interface TbCfItemCommentService {
Result delComment(String commentId);
Result giveLike(String commentId);
}
......@@ -232,4 +232,6 @@ public class ShopifyServiceImpl implements ShopifyService {
}
}
......@@ -14,7 +14,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -78,9 +80,15 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService {
public Result queryLastComment(String itemId) {
Result result = new Result();
try {
TbCfItemCommentEntityExtends lastComment = tbCfItemCommentDao.queryLastComment(itemId);
TbCfItemCommentEntity lastComment = tbCfItemCommentDao.queryLastComment(itemId);
Map<String, Object> map = new HashMap<>();
if (lastComment != null) {
result.setData(lastComment).setMessage("success");
double totalScore = lastComment.getItemScore() + lastComment.getLogisticsScore() + lastComment.getPriceScore() + lastComment.getServiceScore();
BigDecimal total = new BigDecimal(totalScore);
double score = total.divide(new BigDecimal(4), 1, BigDecimal.ROUND_UP).doubleValue();
map.put("score", score);
map.put("lastComment", lastComment);
result.setData(map).setMessage("success");
logger.info("query comment success,the itemId is:" + itemId);
} else {
result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage("comment is null");
......@@ -169,5 +177,20 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService {
return result;
}
@Override
public Result giveLike(String commentId) {
Result result = new Result();
try {
TbCfItemCommentEntity comment = tbCfItemCommentDao.queryObject(commentId);
Long likeNum = comment.getLikeNum();
comment.setLikeNum(++likeNum);
tbCfItemCommentDao.update(comment);
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
} catch (Exception e) {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage(e.getMessage());
logger.error(e.getMessage());
}
return result;
}
}
......@@ -51,6 +51,9 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
@Resource
private RedisCache<Object> redisCache;
@Autowired
private TbCfItemCommentDao tbCfItemCommentDao;
@Override
public TbCfStationItemEntity queryObject(String itemId) {
return tbCfStationItemDao.queryObject(itemId);
......@@ -156,6 +159,21 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
itemOption.setOptionList(optionList);
itemOptionList.add(itemOption);
}
//商品评论
List<TbCfItemCommentEntity> itemCommentList = tbCfItemCommentDao.queryScore(itemId);
double totalScore = 0;
double score = 5;
double total = 0;
if (itemCommentList != null && itemCommentList.size() > 0) {
for (int i = 0; i < itemCommentList.size(); i++) {
total = itemCommentList.get(i).getItemScore() + itemCommentList.get(i).getLogisticsScore() + itemCommentList.get(i).getServiceScore() + itemCommentList.get(i).getPriceScore();
totalScore += total;
}
int num = 4 * itemCommentList.size();
BigDecimal to = new BigDecimal(totalScore);
BigDecimal count = new BigDecimal(num);
score = to.divide(count,1,BigDecimal.ROUND_UP).doubleValue();
}
//商品sku
List<BigDecimal> priceList = new ArrayList<>();
......@@ -190,6 +208,7 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
map.put("itemDesc", itemDesc);
map.put("itemDetail", skuInfoList);
// map.put("categoryList", categoryList);
map.put("score", score);
map.put("optionList", itemOptionList);
// map.put("priceRange", priceRange);
result.setData(map).setMessage(ResultCodeEnum.SUCCESS.getDesc());
......@@ -349,5 +368,4 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
}
}
......@@ -49,11 +49,9 @@
AND c.del_flag = 0
ORDER BY c.create_time DESC
</select>
<select id="queryLastComment" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntityExtends">
<select id="queryLastComment" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity">
SELECT
c.id,
c.create_time,
c.item_review,
c.*,
u.nick username,
m.count count
FROM
......@@ -68,6 +66,24 @@
c.create_time DESC
LIMIT 1
</select>
<select id="queryScore" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity">
select
`id`,
`user_id`,
`order_id`,
`item_id`,
`item_score`,
`service_score`,
`logistics_score`,
`price_score`,
`item_review`,
`like_num`,
`del_flag`,
`create_time`,
`update_time`
from tb_cf_item_comment
WHERE item_id=#{itemId}
</select>
<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity">
select
`id`,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论