196 lines
5.8 KiB
Java
196 lines
5.8 KiB
Java
package com.peanut.modules.book.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.peanut.common.utils.PageUtils;
|
|
import com.peanut.common.utils.R;
|
|
import com.peanut.modules.book.entity.*;
|
|
import com.peanut.modules.book.service.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.*;
|
|
|
|
import static com.peanut.common.utils.R.error;
|
|
|
|
@RestController
|
|
@RequestMapping("/user/followUp")
|
|
public class UserFollowUpController {
|
|
|
|
|
|
@Autowired
|
|
private UserFollowUpService userFollowUpService;
|
|
@Autowired
|
|
private UserRecordService userRecordService;
|
|
@Autowired
|
|
private MyUserService myUserService;
|
|
@Autowired
|
|
private BuyOrderService buyOrderService;
|
|
@Autowired
|
|
private BuyOrderDetailService buyOrderDetailService;
|
|
|
|
|
|
|
|
/**
|
|
* 列表
|
|
*/
|
|
@RequestMapping("/list")
|
|
public R list(@RequestParam Map<String, Object> params ){
|
|
PageUtils page = userFollowUpService.queryPage(params);
|
|
return R.ok().put("page", page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 我的评价
|
|
*/
|
|
@RequestMapping("/Allevaluations")
|
|
public R Allevaluations(@RequestBody UserFollowUpEntity userFollowUpEntity){
|
|
List<UserFollowUpEntity> userid = userFollowUpService.getBaseMapper().selectList(new QueryWrapper<UserFollowUpEntity>().eq("userid", userFollowUpEntity.getUserId()));
|
|
return R.ok().put("Allevaluations",userid);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 全部评价
|
|
*/
|
|
@RequestMapping("/Alllevas")
|
|
public R Alllevas(@RequestBody UserFollowUpEntity users){
|
|
HashMap<Object, Object> maps = new HashMap<>();
|
|
List list = new ArrayList<>();
|
|
List<UserFollowUpEntity> bookid = userFollowUpService.getBaseMapper().selectList(new QueryWrapper<UserFollowUpEntity>().eq("bookid", users.getBookid()));
|
|
for (UserFollowUpEntity userRecord : bookid) {
|
|
HashMap<Object, Object> map = new HashMap<>();
|
|
Integer bookid1 = userRecord.getBookid();
|
|
Integer userid1 = userRecord.getUserId();
|
|
List<MyUserEntity> id = myUserService.getBaseMapper().selectList(new QueryWrapper<MyUserEntity>().eq("id", userid1));
|
|
String usser="";
|
|
String name = "";
|
|
for (MyUserEntity user : id) {
|
|
usser = user.getAvatar();
|
|
name =user.getNickname();
|
|
|
|
}
|
|
map.put("Avatar",usser);
|
|
map.put("name",name);
|
|
map.put("userId", users.getUserId());
|
|
map.put("bookid",bookid1);
|
|
map.put("userid",userid1);
|
|
map.put("content",users.getConTent());
|
|
map.put("create_date",users.getCreateDate());
|
|
map.put("oid",users.getOid());
|
|
map.put("praIse",users.getPraIse());
|
|
|
|
list.add(map);
|
|
|
|
|
|
|
|
|
|
}
|
|
maps.put("list",list);
|
|
|
|
return R.ok().put("list",list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* 追加评论(用户只可评论一次)
|
|
*
|
|
* */
|
|
@RequestMapping("/userFollowUp")
|
|
public Object UserFollowUp(@RequestBody UserFollowUpEntity userFollowUpEntity ) {
|
|
|
|
|
|
//根据传过来的userid和oid查询出来userRecordEntity中关联数据
|
|
UserRecordEntity userRecord = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>()
|
|
.eq("userid", userFollowUpEntity.getUserId()).last("LIMIT 1")
|
|
.eq("bookid", userFollowUpEntity.getBookid())
|
|
.eq("id",userFollowUpEntity.getOid())
|
|
);
|
|
if (userRecord==null){
|
|
return R.error("请先评论再追评");
|
|
}
|
|
String orderSn = userRecord.getOrderSn();
|
|
BuyOrderEntity buyOrderEntity =buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>()
|
|
.eq("order_sn",orderSn).last("LIMIT 1")
|
|
);
|
|
|
|
Integer orderId = buyOrderEntity.getOrderId();
|
|
Integer bookid = userRecord.getBookid();
|
|
Integer userid = userRecord.getUserid();
|
|
Integer id1 = userRecord.getId();
|
|
BuyOrderDetail detailEntity = buyOrderDetailService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderDetail>()
|
|
.eq("Order_id", orderId).eq("product_id",bookid));
|
|
|
|
UserFollowUpEntity followUpEntity = userFollowUpService.getBaseMapper().selectOne(new QueryWrapper<UserFollowUpEntity>().eq("userid", userid).eq("oid",id1).last("LIMIT 1"));
|
|
|
|
// if (followUpEntity != null) {
|
|
// return R.error("您已评价过");
|
|
// }
|
|
|
|
buyOrderEntity.setRecordId(2);
|
|
buyOrderService.saveOrUpdate(buyOrderEntity);
|
|
if (userFollowUpEntity.getImages()!=null) {
|
|
|
|
List<Map<String,String>> imageList = (ArrayList<Map<String,String>>)userFollowUpEntity.getImages();
|
|
String imageStr = "";
|
|
for(Map m : imageList){
|
|
imageStr += m.get("url") + ",";
|
|
}
|
|
|
|
userFollowUpEntity.setImages(imageStr);
|
|
|
|
}
|
|
|
|
userFollowUpEntity.setOid(id1);
|
|
userFollowUpEntity.setDelflag(0);
|
|
userFollowUpEntity.setCreateDate(new Date());
|
|
userFollowUpService.saveOrUpdate(userFollowUpEntity);
|
|
return R.ok("成功").put("userFollowUpEntity",userFollowUpEntity);
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 信息
|
|
*/
|
|
@RequestMapping("/info/{id}")
|
|
public R info(@PathVariable("id") Integer id){
|
|
UserFollowUpEntity user = userFollowUpService.getById(id);
|
|
|
|
return R.ok().put("UserFollowUpEntity", user);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 修改
|
|
*/
|
|
@RequestMapping("/update")
|
|
public R update(@RequestBody UserRecordEntity user){
|
|
userRecordService.updateById(user);
|
|
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
@RequestMapping("/delete")
|
|
public R delete(@RequestBody Integer[] ids){
|
|
userRecordService.removeByIds(Arrays.asList(ids));
|
|
|
|
|
|
return R.ok();
|
|
}
|
|
|
|
|
|
}
|