当前位置:网站首页>Commodity comment information and comment information classification
Commodity comment information and comment information classification
2022-07-27 18:50:00 【Fantasia of the cat】
Product detail analysis - Display product comment information :
Database implementation :

Entity class :
package com.qfedu.fmmall.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProductCommentsVO {
/**
* ID
*/
private String commId;
/**
* goods id
*/
private String productId;
/**
* Name of commodity
*/
private String productName;
/**
* Order items ( Product snapshot )ID May be empty
*/
private String orderItemId;
/**
* Anonymity or not (1: yes ,0: no )
*/
private Integer isAnonymous;
/**
* Evaluation type (1 Praise ,0 Chinese commentary ,-1 Bad review )
*/
private Integer commType;
/**
* Rating 1: Praise 2: Chinese commentary 3: Bad review
*/
private Integer commLevel;
/**
* Evaluation content
*/
private String commContent;
/**
* Evaluation print (JSON {img1:url1,img2:url2} )
*/
private String commImgs;
/**
* Evaluation time May be empty
*/
private Date sepcName;
/**
* Whether to reply (0: No reply ,1: Has replied to )
*/
private Integer replyStatus;
/**
* Reply content
*/
private String replyContent;
/**
* Reply time
*/
private Date replyTime;
/**
* Whether or not shown (1: yes ,0: no )
*/
private Integer isShow;
/**
* users attribute : Encapsulate the data corresponding to the comment
*/
/**
* Comment users id User name must be desensitized
*/
private String userId;
private String username;
private String nickname;
private String userImg;
}In the file mapper Interface definition query method :
package com.qfedu.fmmall.dao;
import com.qfedu.fmmall.entity.ProductComments;
import com.qfedu.fmmall.entity.ProductCommentsVO;
import com.qfedu.fmmall.general.GeneralDAO;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ProductCommentsMapper extends GeneralDAO<ProductComments> {
public List<ProductCommentsVO> selectCommentsByProductId(String productId);
}The mapping file :
<?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.qfedu.fmmall.dao.ProductCommentsMapper" >
<resultMap id="BaseResultMap" type="com.qfedu.fmmall.entity.ProductComments" >
<id column="comm_id" property="commId" jdbcType="VARCHAR" />
<result column="product_id" property="productId" jdbcType="VARCHAR" />
<result column="product_name" property="productName" jdbcType="VARCHAR" />
<result column="order_item_id" property="orderItemId" jdbcType="VARCHAR" />
<result column="user_id" property="userId" jdbcType="VARCHAR" />
<result column="is_anonymous" property="isAnonymous" jdbcType="INTEGER" />
<result column="comm_type" property="commType" jdbcType="INTEGER" />
<result column="comm_level" property="commLevel" jdbcType="INTEGER" />
<result column="comm_content" property="commContent" jdbcType="VARCHAR" />
<result column="comm_imgs" property="commImgs" jdbcType="VARCHAR" />
<result column="sepc_name" property="sepcName" jdbcType="TIMESTAMP" />
<result column="reply_status" property="replyStatus" jdbcType="INTEGER" />
<result column="reply_content" property="replyContent" jdbcType="VARCHAR" />
<result column="reply_time" property="replyTime" jdbcType="TIMESTAMP" />
<result column="is_show" property="isShow" jdbcType="INTEGER" />
</resultMap>
<resultMap id="ProductCommentsVOMap" type="com.qfedu.fmmall.entity.ProductCommentsVO" >
<id column="comm_id" property="commId" jdbcType="VARCHAR" />
<result column="product_id" property="productId" jdbcType="VARCHAR" />
<result column="product_name" property="productName" jdbcType="VARCHAR" />
<result column="order_item_id" property="orderItemId" jdbcType="VARCHAR" />
<result column="is_anonymous" property="isAnonymous" jdbcType="INTEGER" />
<result column="comm_type" property="commType" jdbcType="INTEGER" />
<result column="comm_level" property="commLevel" jdbcType="INTEGER" />
<result column="comm_content" property="commContent" jdbcType="VARCHAR" />
<result column="comm_imgs" property="commImgs" jdbcType="VARCHAR" />
<result column="sepc_name" property="sepcName" jdbcType="TIMESTAMP" />
<result column="reply_status" property="replyStatus" jdbcType="INTEGER" />
<result column="reply_content" property="replyContent" jdbcType="VARCHAR" />
<result column="reply_time" property="replyTime" jdbcType="TIMESTAMP" />
<result column="is_show" property="isShow" jdbcType="INTEGER" />
<result column="user_id" property="userId" jdbcType="VARCHAR" />
<result column="username" property="username" jdbcType="VARCHAR" />
<result column="nickname" property="nickname" jdbcType="VARCHAR" />
<result column="user_img" property="userImg" jdbcType="VARCHAR" />
</resultMap>
<select id="selectCommentsByProductId" resultMap="ProductCommentsVOMap">
select
u.username,
u.nickname,
u.user_img,
c.comm_id,
c.product_id,
c.product_name,
c.order_item_id,
c.user_id,
c.is_anonymous,
c.comm_type,
c.comm_level,
c.comm_content,
c.comm_imgs,
c.sepc_name,
c.reply_status,
c.reply_content,
c.reply_time,
c.is_show
from product_comments c
inner join users u
on u.user_id = c.user_id
where c.product_id = #{productId}
</select>
</mapper>productCommentsServiceImpl class :
package com.qfedu.fmmall.service.impl;
import com.qfedu.fmmall.dao.ProductCommentsMapper;
import com.qfedu.fmmall.entity.ProductCommentsVO;
import com.qfedu.fmmall.service.ProductCommentsService;
import com.qfedu.fmmall.vo.R;
import com.qfedu.fmmall.vo.ResStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Description:
* @Author : Jerry
* @create : 2022-06-27 16:44
*/
@Service
public class ProductCommentsServiceImpl implements ProductCommentsService {
@Autowired
private ProductCommentsMapper productCommentsMapper;
@Override
public R listCommentsByProductId(String productId) {
List<ProductCommentsVO> productCommentsVOS = productCommentsMapper.selectCommentsByProductId(productId);
R r = new R(ResStatus.OK, "success", productCommentsVOS);
return r;
}
}
test :
@Test
public void testSelectComments(){
List<ProductCommentsVO> productCommentsVOS = productCommentsMapper.selectCommentsByProductId("3");
for(ProductCommentsVO p:productCommentsVOS){
System.out.println(p);
}
}test result :
ProductCommentsVO(commId=1, productId=3, productName= Mimi shrimp strips , orderItemId=10000001, isAnonymous=1, commType=1, commLevel=1, commContent= I didn't buy it to eat , Just play , commImgs={}, sepcName=Tue Apr 27 14:51:10 CST 2021, replyStatus=0, replyContent=null, replyTime=Tue Apr 27 14:51:32 CST 2021, isShow=1, userId=4, username=heihei, nickname= Two dogs , userImg=img/default.png)
ProductCommentsVO(commId=2, productId=3, productName= Mimi shrimp strips , orderItemId=10000002, isAnonymous=0, commType=1, commLevel=1, commContent=nice, commImgs={img1:“mmxt2.png”}, sepcName=Tue Apr 27 14:53:20 CST 2021, replyStatus=1, replyContent= Hello, I'm fine , replyTime=Tue Apr 27 14:53:37 CST 2021, isShow=1, userId=5, username=Tony, nickname= Tony , userImg=img/default.png)According to the user id Check product information comments , And display user information and comment information ;
Comment information paging :

Definition pageHelper:
package com.qfedu.fmmall.utils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageHelper<T> {
// Total number of records
private int count;
// Total number of pages
private int pageCount;
// Paging data
private List<T> list;
}
Transform the product comment interface :
Paging query :
modify mapper Interface :
package com.qfedu.fmmall.dao;
import com.qfedu.fmmall.entity.ProductComments;
import com.qfedu.fmmall.entity.ProductCommentsVO;
import com.qfedu.fmmall.general.GeneralDAO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ProductCommentsMapper extends GeneralDAO<ProductComments> {
/**
* According to the goods id Paging query comment information
* @param productId goods id
* @param start Starting index
* @param pageSize Number of queries
* @return
*/
public List<ProductCommentsVO> selectCommentsByProductId(@Param("productId") String productId,
@Param("start") int start,
@Param("pageSize") int pageSize);
}In the mapping file of product reviews mapper Add on :

service Interface :
package com.qfedu.fmmall.service;
import com.qfedu.fmmall.vo.R;
import org.springframework.stereotype.Service;
/**
* @Description:
* @Author : Jerry
* @create : 2022-06-27 16:42
*/
public interface ProductCommentsService {
/**
* According to the goods id Realize the paging query of comments
* @param productId goods id
* @param pageNum Look up the page number
* @param pageSize Number of bars per page
* @return
*/
public R listCommentsByProductId(String productId,int pageNum,int pageSize);
}
productCommentsService Implementation class of ;
package com.qfedu.fmmall.service.impl;
import com.qfedu.fmmall.dao.ProductCommentsMapper;
import com.qfedu.fmmall.entity.ProductComments;
import com.qfedu.fmmall.entity.ProductCommentsVO;
import com.qfedu.fmmall.service.ProductCommentsService;
import com.qfedu.fmmall.utils.PageHelper;
import com.qfedu.fmmall.vo.R;
import com.qfedu.fmmall.vo.ResStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
/**
* @Description:
* @Author : Jerry
* @create : 2022-06-27 16:44
*/
@Service
public class ProductCommentsServiceImpl implements ProductCommentsService {
@Autowired
private ProductCommentsMapper productCommentsMapper;
@Override
public R listCommentsByProductId(String productId,int pageNum,int pageSize ) {
// List<ProductCommentsVO> productCommentsVOS = productCommentsMapper.selectCommentsByProductId(productId);
//1. According to the goods id Total number of records queried
Example example = new Example(ProductComments.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("productId",productId);
int count = productCommentsMapper.selectCountByExample(example);
//2. Calculate the total number of pages ( You must determine how many items are displayed on each page pageSize)
int pageCount = count%pageSize==0?count/pageSize : count/pageSize+1;
//3. Query the current data ( Because user information is needed in comments , Therefore, you need to query the linked list -- Customize )
int start = (pageNum - 1)* pageSize;
List<ProductCommentsVO> list = productCommentsMapper.selectCommentsByProductId(productId, start, pageSize);
R r = new R(ResStatus.OK, "success", new PageHelper<ProductCommentsVO>(count,pageCount,list));
return r;
}
}
Evaluation statistics interface implementation :
productCommentsService Interface :
/**
* According to the goods id Count the evaluation information of current products
* @param productId
* @return
*/
public R getCommentsCountByProductId(String productId);productCommentsServiceImpl Implementation class :
@Override
public R getCommentsCountByProductId(String productId) {
//1. Query the total number of current product reviews
Example example = new Example(ProductComments.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("productId",productId);
int total = productCommentsMapper.selectCountByExample(example);
//2. Query the number of positive comments
criteria.andEqualTo("commType",1);
int goodTotal = productCommentsMapper.selectCountByExample(example);
//3. The number of comments in the query
Example example1 = new Example(ProductComments.class);
Example.Criteria criteria1 = example1.createCriteria();
criteria1.andEqualTo("productId",productId);
criteria1.andEqualTo("commType",0);
int midTotal = productCommentsMapper.selectCountByExample(example1);
//4. Query the number of bad reviews
Example example2 = new Example(ProductComments.class);
Example.Criteria criteria2 = example2.createCriteria();
criteria2.andEqualTo("productId",productId);
criteria2.andEqualTo("commType",-1);
int badTotal = productCommentsMapper.selectCountByExample(example2);
//5. Calculate the praise rate
double percent = (Double.parseDouble(goodTotal+"") / Double.parseDouble(total+""))*100;
String percentValue = (percent+"").substring(0,(percent+"").lastIndexOf(".")+3);
HashMap<String,Object> map = new HashMap<>();
map.put("total",total);
map.put("goodTotal",goodTotal);
map.put("midTotal",midTotal);
map.put("badTotal",badTotal);
map.put("percent",percentValue);
R r = new R(ResStatus.OK, "success", map);
return r;
}边栏推荐
- LED学习护眼台灯触摸芯片-DLT8T10S-杰力科创
- Meituan Er Mian: why does redis have sentinels?
- 微信支付及支付回调
- TS study notes class
- 2021.7.18 notes MySQL data type
- What if MySQL database forgets its password???
- 阿里p8总结的10条 SQL 优化方案(非常实用)
- MySQL learning day3 multi table query / transaction / DCL
- 阿里架构师耗时280个小时整理的1015页分布式全栈小册,轻松入手分布式系统
- 面试官:你觉得你最大的缺点是什么?
猜你喜欢
随机推荐
Run the uniapp to the mobile phone (real machine debugging)
Matplotlib(基本用法)
Must the MySQL query column be consistent with the group by field?
全自动吸奶器芯片-DLTAP703SD
使用jieba、pyhanlp工具实现关键字词句的提取
家用静音驱蚊灯芯片-DLTAP703SD-杰力科创
js中的函数与DOM获取元素和事件属性的使用
JDBC learning day1:jdbc
filebeat.yml配置文件关于多个服务的配置问题
The song of the virtual idol was originally generated in this way!
Uni app for wechat login (to be finished)
订单的提交
机器学习分类任务效果评估指标大全(包含ROC和AUC)
Class not found: "the com.parkmanagement.dao.daotest test cannot find the test class
这样的API网关查询接口优化,我是被迫的
Solve the problem of JSP cascading
Canvas draws graphics according to coordinate points
Complete set of machine learning classification task effect evaluation indicators (including ROC and AUC)
微信小程序微信支付概述
Preliminary introduction to C miscellaneous lecture linked list









