Compare commits

...

4 Commits

@ -0,0 +1,58 @@
package com.itmk.web.goods_comment.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itmk.utils.ResultUtils;
import com.itmk.utils.ResultVo;
import com.itmk.web.goods_comment.entity.GoodsComment;
import com.itmk.web.goods_comment.service.GoodsCommentService;
import com.itmk.web.order_detail.entity.UserOrderDetail;
import com.itmk.web.order_detail.service.UserOrderDetailService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @Author java
* @Version 2383404558
*/
@RestController
@RequestMapping("/wxapi/comment")
public class GoodsCommentController {
@Autowired
private GoodsCommentService goodsCommentService;
@Resource
private UserOrderDetailService userOrderDetailService;
//新增评论
@PostMapping("/addComment")
public ResultVo addComment(@RequestBody GoodsComment goodsComment){
//根据订单id查询商品
QueryWrapper<UserOrderDetail> query = new QueryWrapper<>();
query.lambda().eq(UserOrderDetail::getOrderId,goodsComment.getOrderId());
List<UserOrderDetail> list = userOrderDetailService.list(query);
List<GoodsComment> goodsCommentList = new ArrayList<>();
if(list.size() >0){
for (int i=0;i<list.size();i++){
GoodsComment goodsC = new GoodsComment();
BeanUtils.copyProperties(goodsComment,goodsC);
goodsC.setCreateTime(new Date());
goodsC.setGoodsId(list.get(i).getGoodsId());
goodsCommentList.add(goodsC);
}
}
//批量插入
goodsCommentService.saveBatch(goodsCommentList);
return ResultUtils.success("评论成功!");
}
//小程序评论列表
@GetMapping("/commentList")
public ResultVo commentList(Long goodsId){
List<GoodsComment> list = goodsCommentService.commentList(goodsId);
return ResultUtils.success("查询成功",list);
}
}

@ -0,0 +1,30 @@
package com.itmk.web.goods_comment.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
@Data
@TableName("goods_comment")
public class GoodsComment {
@TableId(type = IdType.AUTO)
private Long commentId;
private Long goodsId;
@TableField(exist = false)
private Long orderId;
private String openid;
private String commentText;
@TableField(exist = false)
private String nickName;
@TableField(exist = false)
private String avatarUrl;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date createTime;
}

@ -0,0 +1,12 @@
package com.itmk.web.goods_comment.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itmk.web.goods_comment.entity.GoodsComment;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface GoodsCommentMapper extends BaseMapper<GoodsComment> {
List<GoodsComment> commentList(@Param("goodsId") Long goodsId);
}

@ -0,0 +1,11 @@
package com.itmk.web.goods_comment.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.itmk.web.goods_comment.entity.GoodsComment;
import java.util.List;
public interface GoodsCommentService extends IService<GoodsComment> {
List<GoodsComment> commentList(Long goodsId);
}

@ -0,0 +1,17 @@
package com.itmk.web.goods_comment.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itmk.web.goods_comment.entity.GoodsComment;
import com.itmk.web.goods_comment.mapper.GoodsCommentMapper;
import com.itmk.web.goods_comment.service.GoodsCommentService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class GoodsCommentServiceImpl extends ServiceImpl<GoodsCommentMapper, GoodsComment> implements GoodsCommentService {
@Override
public List<GoodsComment> commentList(Long goodsId) {
return this.baseMapper.commentList(goodsId);
}
}

@ -0,0 +1,28 @@
package com.itmk.web.wx_user.controller;
import com.itmk.utils.ResultUtils;
import com.itmk.utils.ResultVo;
import com.itmk.web.wx_user.entity.WxUser;
import com.itmk.web.wx_user.service.WxUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/wxapi/wxUser")
public class WxUserController {
@Autowired
private WxUserService wxUserService;
@PostMapping("/saveOrUpdate")
public ResultVo saveOrUpdate(@RequestBody WxUser wxUser){
wxUserService.saveOrUpdate(wxUser);
return ResultUtils.success("更新成功!");
}
//查询头像昵称
@GetMapping("/getUserInfo")
public ResultVo getUserInfo(String openid) {
WxUser user = wxUserService.getById(openid);
return ResultUtils.error("查询成功!",user);
}
}

@ -0,0 +1,14 @@
package com.itmk.web.wx_user.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("wx_user")
public class WxUser {
@TableId
private String openid;
private String nickName;
private String avatarUrl;
}

@ -0,0 +1,9 @@
package com.itmk.web.wx_user.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itmk.web.wx_user.entity.WxUser;
import org.apache.ibatis.annotations.Param;
public interface WxUserMapper extends BaseMapper<WxUser> {
int saveOrUpdateInfo(@Param("user") WxUser user);
}

@ -0,0 +1,8 @@
package com.itmk.web.wx_user.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.itmk.web.wx_user.entity.WxUser;
public interface WxUserService extends IService<WxUser> {
int saveOrUpdateInfo(WxUser user);
}

@ -0,0 +1,18 @@
package com.itmk.web.wx_user.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itmk.web.wx_user.entity.WxUser;
import com.itmk.web.wx_user.mapper.WxUserMapper;
import com.itmk.web.wx_user.service.WxUserService;
import org.springframework.stereotype.Service;
@Service
public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUser> implements WxUserService {
@Override
public int saveOrUpdateInfo(WxUser user) {
return this.baseMapper.saveOrUpdateInfo(user);
}
}

@ -0,0 +1,10 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itmk.web.goods_comment.mapper.GoodsCommentMapper">
<select id="commentList" resultType="com.itmk.web.goods_comment.entity.GoodsComment">
select w.nick_name,w.avatar_url,g.* from goods_comment as g inner join wx_user as w on g.openid = w.openid
where g.goods_id =#{goodsId}
</select>
</mapper>
Loading…
Cancel
Save