提交 1c3e0710 authored 作者: zgy's avatar zgy

完成商品评价、回复等功能

上级 43a1fcc8
package com.diaoyun.zion.chinafrica.controller;
import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity;
import com.diaoyun.zion.chinafrica.entity.TbCfReplyEntity;
import com.diaoyun.zion.chinafrica.service.ShopifyService;
import com.diaoyun.zion.chinafrica.service.TbCfItemCommentService;
import com.diaoyun.zion.chinafrica.service.TbCfReplyService;
import com.diaoyun.zion.master.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -12,7 +15,7 @@ import org.springframework.web.bind.annotation.*;
/**
* @Auther: wudepeng
* @Date: 2019/11/15
* @Description: 调用shopify API,获取商品信息
* @Description: 调用shopify API,获取商品信息;查看商品评价、回复
*/
@Api(tags = "获取shopify的商品信息")
@RestController
......@@ -23,6 +26,8 @@ public class ShopifyController {
private ShopifyService shopifyService;
@Autowired
private TbCfItemCommentService tbCfItemCommentService;
@Autowired
private TbCfReplyService tbCfReplyService;
/**
* 查询商品
......@@ -77,4 +82,84 @@ public class ShopifyController {
return tbCfItemCommentService.queryLastComment(itemId);
}
/**
* 查看商品的更多评论
*
* @param itemId
* @param pageNum
* @param pageSize
* @return
*/
@ApiOperation(value = "查看更多评论")
@GetMapping("/querycomments")
public Result queryComments(@ApiParam("商品ID") @RequestParam("itemId") String itemId,
@ApiParam(value = "页数 默认1") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@ApiParam(value = "每页大小 默认10") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
return tbCfItemCommentService.querycomments(itemId, pageNum, pageSize);
}
/**
* 查看回复信息
*
* @param commentId
* @param pageNum
* @param pageSize
* @return
*/
@ApiOperation(value = "查看回复信息")
@GetMapping("/queryreplys")
public Result queryReplys(@ApiParam("评论ID") @RequestParam("commentId") String commentId,
@ApiParam(value = "页数 默认1") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@ApiParam(value = "每页大小 默认10") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
return tbCfReplyService.queryReplys(commentId, pageNum, pageSize);
}
/**
* 商品评价
*
* @param comment
* @return
*/
@ApiOperation(value = "商品评价")
@PostMapping("/addcomment")
public Result addComment(@ApiParam("评论") @RequestBody TbCfItemCommentEntity comment) {
return tbCfItemCommentService.addComment(comment);
}
/**
* 删除评论
*
* @param commentId
* @return
*/
@DeleteMapping(value = "/delcomment")
public Result delComment(@ApiParam("评论ID") @RequestParam("commentId") String commentId) {
return tbCfItemCommentService.delComment(commentId);
}
/**
* 回复消息
*
* @param reply
* @return
*/
@ApiOperation(value = "回复消息")
@PostMapping("/addreply")
public Result addReply(@ApiParam("回复消息") @RequestBody TbCfReplyEntity reply) {
return tbCfReplyService.addReply(reply);
}
/**
* 删除回复
*
* @param replyId
* @return
*/
@ApiOperation("删除回复")
@DeleteMapping("/delreply")
public Result delReply(@ApiParam("回复ID") @RequestParam("replyId") String replyId) {
return tbCfReplyService.delReply(replyId);
}
}
......@@ -5,6 +5,8 @@ import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity;
import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntityExtends;
import com.diaoyun.zion.master.dao.BaseDao;
import java.util.List;
/**
* Dao
*
......@@ -14,4 +16,5 @@ import com.diaoyun.zion.master.dao.BaseDao;
public interface TbCfItemCommentDao extends BaseDao<TbCfItemCommentEntity> {
public TbCfItemCommentEntityExtends queryLastComment(String itemId);
List<TbCfItemCommentEntity> querycomments(String itemId);
}
......@@ -2,8 +2,11 @@ package com.diaoyun.zion.chinafrica.dao;
import com.diaoyun.zion.chinafrica.entity.TbCfReplyEntity;
import com.diaoyun.zion.chinafrica.entity.TbCfReplyEntityExtends;
import com.diaoyun.zion.master.dao.BaseDao;
import java.util.List;
/**
* Dao
*
......@@ -11,5 +14,6 @@ import com.diaoyun.zion.master.dao.BaseDao;
* @date 2019-11-18 15:10:45
*/
public interface TbCfReplyDao extends BaseDao<TbCfReplyEntity> {
List<TbCfReplyEntityExtends> queryReplys(String commentId);
}
......@@ -64,7 +64,7 @@ public class TbCfItemCommentEntity implements Serializable {
/**
* 回复时间
*/
private Date replyTime;
private Date updateTime;
private String username;
......@@ -244,17 +244,11 @@ public class TbCfItemCommentEntity implements Serializable {
return createTime;
}
/**
* 设置:回复时间
*/
public void setReplyTime(Date replyTime) {
this.replyTime = replyTime;
public Date getUpdateTime() {
return updateTime;
}
/**
* 获取:回复时间
*/
public Date getReplyTime() {
return replyTime;
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
package com.diaoyun.zion.chinafrica.entity;
/**
* @Auther: wudepeng
* @Date: 2019/11/19
* @Description:
*/
public class TbCfReplyEntityExtends extends TbCfReplyEntity {
private String user;
private String touser;
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
}
......@@ -2,7 +2,11 @@ package com.diaoyun.zion.chinafrica.service;
import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity;
import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntityExtends;
import com.diaoyun.zion.chinafrica.entity.TbCfReplyEntity;
import com.diaoyun.zion.master.base.Result;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
......@@ -73,4 +77,12 @@ public interface TbCfItemCommentService {
int deleteBatch(String[] ids);
public Result queryLastComment(String itemId);
Result querycomments(String itemId, Integer pageNum, Integer pageSize);
Result addComment(TbCfItemCommentEntity comment);
Result delComment(String commentId);
}
......@@ -2,6 +2,10 @@ package com.diaoyun.zion.chinafrica.service;
import com.diaoyun.zion.chinafrica.entity.TbCfReplyEntity;
import com.diaoyun.zion.chinafrica.entity.TbCfReplyEntityExtends;
import com.diaoyun.zion.master.base.Result;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
......@@ -69,4 +73,7 @@ public interface TbCfReplyService {
* @return 删除条数
*/
int deleteBatch(String[] ids);
Result queryReplys(String commentId,Integer pageNum,Integer pageSize);
Result addReply(TbCfReplyEntity reply);
Result delReply( String replyId);
}
......@@ -4,18 +4,23 @@ package com.diaoyun.zion.chinafrica.service.impl;
import com.diaoyun.zion.chinafrica.dao.TbCfItemCommentDao;
import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity;
import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntityExtends;
import com.diaoyun.zion.chinafrica.entity.TbCfReplyEntity;
import com.diaoyun.zion.chinafrica.service.TbCfItemCommentService;
import com.diaoyun.zion.master.base.Result;
import com.diaoyun.zion.master.enums.ResultCodeEnum;
import com.diaoyun.zion.master.util.IdUtil;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.github.pagehelper.page.PageMethod.startPage;
/**
* Service实现类
*
......@@ -88,4 +93,82 @@ public class TbCfItemCommentServiceImpl implements TbCfItemCommentService {
}
return result;
}
/**
* 查询更多评论
*
* @param itemId
* @param pageNum
* @param pageSize
* @return
*/
@Override
public Result querycomments(String itemId, Integer pageNum, Integer pageSize) {
Result<PageInfo> result = new Result();
try {
startPage(pageNum, pageSize);
List<TbCfItemCommentEntity> comments = tbCfItemCommentDao.querycomments(itemId);
PageInfo<TbCfItemCommentEntity> pageInfo = new PageInfo<>(comments);
result.setData(pageInfo);
} catch (Exception e) {
result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage(e.getMessage());
logger.error(e.getMessage());
}
return result;
}
/**
* 商品评价
*
* @param comment
* @return
*/
public Result addComment(TbCfItemCommentEntity comment) {
Result result = new Result();
try {
comment.setId(IdUtil.createIdbyUUID());
comment.setDelFlag(0);
comment.setLikeNum(0L);
comment.setCreateTime(new Date());
comment.setUpdateTime(new Date());
int i = tbCfItemCommentDao.save(comment);
if (i > 0) {
result.setCode(ResultCodeEnum.SUCCESS.getCode()).setMessage("Comment on success!");
} else {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage("Comment on failure!");
}
} catch (Exception e) {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage(e.getMessage());
logger.error(e.getMessage());
}
return result;
}
/**
* 删除商品评论
*
* @param commentId
* @return
*/
@Override
public Result delComment(String commentId) {
Result result = new Result();
try {
TbCfItemCommentEntity comment = tbCfItemCommentDao.queryObject(commentId);
comment.setDelFlag(1);
comment.setUpdateTime(new Date());
int i = tbCfItemCommentDao.update(comment);
if (i > 0) {
result.setCode(ResultCodeEnum.SUCCESS.getCode()).setMessage("Deleted successfully!");
} else {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage("Deletion failed!");
}
} catch (Exception e) {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage(e.getMessage());
logger.error(e.getMessage());
}
return result;
}
}
......@@ -2,15 +2,25 @@ package com.diaoyun.zion.chinafrica.service.impl;
import com.diaoyun.zion.chinafrica.dao.TbCfReplyDao;
import com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity;
import com.diaoyun.zion.chinafrica.entity.TbCfReplyEntity;
import com.diaoyun.zion.chinafrica.entity.TbCfReplyEntityExtends;
import com.diaoyun.zion.chinafrica.service.TbCfReplyService;
import com.diaoyun.zion.master.base.Result;
import com.diaoyun.zion.master.enums.ResultCodeEnum;
import com.diaoyun.zion.master.util.IdUtil;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.github.pagehelper.page.PageMethod.startPage;
/**
* Service实现类
*
......@@ -19,6 +29,7 @@ import java.util.Map;
*/
@Service("tbCfReplyService")
public class TbCfReplyServiceImpl implements TbCfReplyService {
private static Logger logger = LoggerFactory.getLogger(TbCfReplyServiceImpl.class);
@Autowired
private TbCfReplyDao tbCfReplyDao;
......@@ -57,4 +68,61 @@ public class TbCfReplyServiceImpl implements TbCfReplyService {
public int deleteBatch(String[] ids) {
return tbCfReplyDao.deleteBatch(ids);
}
@Override
public Result queryReplys(String commentId, Integer pageNum, Integer pageSize) {
Result result = new Result();
try {
startPage(pageNum, pageSize);
List<TbCfReplyEntityExtends> replys = tbCfReplyDao.queryReplys(commentId);
PageInfo<TbCfReplyEntityExtends> pageInfo = new PageInfo<>(replys);
result.setData(pageInfo);
} catch (Exception e) {
result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage(e.getMessage());
logger.error(e.getMessage());
}
return result;
}
@Override
public Result addReply(TbCfReplyEntity reply) {
Result result = new Result();
try {
reply.setId(IdUtil.createIdbyUUID());
reply.setReplyType(0);
reply.setDelFlag(0);
reply.setCreateTime(new Date());
reply.setUpdateTime(new Date());
int i = tbCfReplyDao.save(reply);
if (i > 0) {
result.setCode(ResultCodeEnum.SUCCESS.getCode()).setMessage("Reply successful!");
} else {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage("Reply failed!");
}
} catch (Exception e) {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage(e.getMessage());
logger.error(e.getMessage());
}
return result;
}
@Override
public Result delReply(String replyId) {
Result result = new Result();
try {
TbCfReplyEntity reply = tbCfReplyDao.queryObject(replyId);
reply.setDelFlag(1);
reply.setUpdateTime(new Date());
int i = tbCfReplyDao.update(reply);
if (i > 0) {
result.setCode(ResultCodeEnum.SUCCESS.getCode()).setMessage("Deleted successfully!");
} else {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage("Deletion failed!");
}
} catch (Exception e) {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage(e.getMessage());
logger.error(e.getMessage());
}
return result;
}
}
......@@ -34,6 +34,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -91,7 +92,6 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
private RedisCache<Object> captchaRedisCache;
@Override
public TbCfUserInfoEntity queryObject(String userId) {
return tbCfUserInfoDao.queryObject(userId);
......@@ -213,16 +213,16 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
}
@Override
public Result<TbCfUserInfoVo> registerByPhone(TbCfUserInfoVo tbCfUserInfoVo,String code) {
String phone="+"+tbCfUserInfoVo.getPhone();
public Result<TbCfUserInfoVo> registerByPhone(TbCfUserInfoVo tbCfUserInfoVo, String code) {
String phone = "+" + tbCfUserInfoVo.getPhone();
Result result = new Result();
TbCfUserInfoEntity user = tbCfUserInfoDao.checkUserByPhone(phone);
String phoneCode = (String) captchaRedisCache.get(KeyConstant.CAPTCHA_PHONE + phone);
if(code==null||!code.equals(phoneCode)){
if (code == null || !code.equals(phoneCode)) {
result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode());
result.setMessage("Verification code error");
} else{
if(user==null) {
} else {
if (user == null) {
TbCfUserInfoEntity tbCfUserInfoEntity = new TbCfUserInfoEntity();
String userid = IdUtil.createIdbyUUID();
tbCfUserInfoVo.setUserId(userid);
......@@ -280,14 +280,15 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
throw new ApplicationException(ResultCodeEnum.NEED_LOGIN.getCode(), "Invalid username/password supplied or account is disable");
}
}
public Result loginByPhone(String ip,String phoneNum,String code){
String phone="+"+phoneNum.trim();
Result result=new Result();
public Result loginByPhone(String ip, String phoneNum, String code) {
String phone = "+" + phoneNum.trim();
Result result = new Result();
TbCfUserInfoEntity user = tbCfUserInfoDao.checkUserByPhone(phone);
String phoneCode = (String) captchaRedisCache.get(KeyConstant.CAPTCHA_PHONE + phone);
if (user != null && phoneCode.equals(code)) {
result = loginByPhoneCode(ip, phone);
}else {
} else {
result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode());
result.setMessage("Login failed");
}
......@@ -295,12 +296,13 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
}
public String getUserPhoneCode(String phone) throws IOException {
phone="+"+phone.trim();
phone = "+" + phone.trim();
SMSUtil smsUtil = new SMSUtil();
String code = smsUtil.yzCode(phone);
captchaRedisCache.set(KeyConstant.CAPTCHA_PHONE + phone, code, 300);
return code;
}
/**
* 登录
*
......@@ -324,6 +326,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
result.setData(loginUser).setMessage(ResultCodeEnum.SUCCESS.getDesc());
return result;
}
public Result loginByPhoneCode(String ip, String phone) {
Result<TbCfUserInfoVo> result = new Result<>();
TbCfUserInfoEntity user = tbCfUserInfoDao.checkUserByPhone(phone);
......@@ -341,6 +344,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
return result;
}
@Override
public TbCfUserInfoEntity findByAccount(String account) {
TbCfUserInfoEntity tbCfUserInfoEntity = tbCfUserInfoDao.findByAccount(account);
......@@ -465,7 +469,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
}
@Override
public Result resetPassWord(String account,String newPassword, Integer captcha) {
public Result resetPassWord(String account, String newPassword, Integer captcha) {
Result result = new Result();
Integer identifyCode = (Integer) captchaRedisCache.get(KeyConstant.CAPTCHA + account);
if (identifyCode == null || identifyCode.intValue() != captcha) {
......
......@@ -16,7 +16,7 @@
<result property="likeNum" column="like_num"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="replyTime" column="reply_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity">
......@@ -33,10 +33,22 @@
`like_num`,
`del_flag`,
`create_time`,
`reply_time`,nick
`update_time`
from tb_cf_item_comment
where id = #{id}
</select>
<select id="querycomments" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity">
SELECT
u.nick username,
c.*
FROM
tb_cf_item_comment c
LEFT JOIN tb_cf_user_info u ON c.user_id = u.user_id
WHERE
item_id =#{itemId}
AND c.del_flag = 0
ORDER BY c.create_time DESC
</select>
<select id="queryLastComment" resultType="com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntityExtends">
SELECT
c.id,
......@@ -51,6 +63,7 @@
WHERE
c.item_id = #{itemId}
AND c.del_flag = 0
AND c.del_flag = 0
ORDER BY
c.create_time DESC
LIMIT 1
......@@ -69,7 +82,7 @@
`like_num`,
`del_flag`,
`create_time`,
`reply_time`
`update_time`
from tb_cf_item_comment
WHERE 1=1
<if test="name != null and name.trim() != ''">
......@@ -110,7 +123,7 @@
`like_num`,
`del_flag`,
`create_time`,
`reply_time`)
`update_time`)
values(
#{id},
#{userId},
......@@ -124,7 +137,7 @@
#{likeNum},
#{delFlag},
#{createTime},
#{replyTime})
#{updateTime})
</insert>
<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfItemCommentEntity">
......@@ -141,7 +154,7 @@
<if test="likeNum != null">`like_num` = #{likeNum},</if>
<if test="delFlag != null">`del_flag` = #{delFlag},</if>
<if test="createTime != null">`create_time` = #{createTime},</if>
<if test="replyTime != null">`reply_time` = #{replyTime}</if>
<if test="updateTime != null">`update_time` = #{updateTime}</if>
</set>
where id = #{id}
</update>
......
......@@ -58,7 +58,24 @@
limit #{offset}, #{limit}
</if>
</select>
<select id="queryReplys" resultType="com.diaoyun.zion.chinafrica.entity.TbCfReplyEntityExtends">
SELECT
u.nick user ,
c.id commentId,
i.touser touser,
r.*
FROM
tb_cf_reply r
LEFT JOIN tb_cf_item_comment c ON r.comment_id = c.id
LEFT JOIN tb_cf_user_info u ON r.user_id = u.user_id
LEFT JOIN ( SELECT u.user_id, u.nick touser FROM tb_cf_user_info u ) i ON r.to_user_id = i.user_id
WHERE
r.reply_type = 0
AND r.del_flag = 0
AND c.id = #{id}
ORDER BY
r.create_time DESC
</select>
<select id="queryTotal" resultType="int">
select count(*) from tb_cf_reply
WHERE 1=1
......@@ -93,13 +110,13 @@
<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfReplyEntity">
update tb_cf_reply
<set>
<if test="replyType != null">`reply_type` = #{replyType}, </if>
<if test="commentId != null">`comment_id` = #{commentId}, </if>
<if test="userId != null">`user_id` = #{userId}, </if>
<if test="toUserId != null">`to_user_id` = #{toUserId}, </if>
<if test="replyMessage != null">`reply_message` = #{replyMessage}, </if>
<if test="delFlag != null">`del_flag` = #{delFlag}, </if>
<if test="createTime != null">`create_time` = #{createTime}, </if>
<if test="replyType != null">`reply_type` = #{replyType},</if>
<if test="commentId != null">`comment_id` = #{commentId},</if>
<if test="userId != null">`user_id` = #{userId},</if>
<if test="toUserId != null">`to_user_id` = #{toUserId},</if>
<if test="replyMessage != null">`reply_message` = #{replyMessage},</if>
<if test="delFlag != null">`del_flag` = #{delFlag},</if>
<if test="createTime != null">`create_time` = #{createTime},</if>
<if test="updateTime != null">`update_time` = #{updateTime}</if>
</set>
where id = #{id}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论