1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.matrix.system.shopXcx.api.action;
 
import com.matrix.core.pojo.AjaxResult;
import com.matrix.system.hive.bean.SysVipInfo;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.system.common.constance.AppConstance;
 
import com.matrix.system.shopXcx.bean.ShopOrder;
import com.matrix.system.shopXcx.bean.ShopProductComment;
import com.matrix.system.shopXcx.dao.ShopOrderDao;
import com.matrix.system.shopXcx.dao.ShopProductCommentDao;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @description 产品评价接口
 * @author jiangyouyao
 * @date 2019-06-14 11:15
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Controller
@RequestMapping(value = "wxapi/ProductComment")
public class WxProductCommentAction {
    @Autowired
    private ShopProductCommentDao productCommentDao;
    @Autowired
    private RedisUserLoginUtils redisUserLoginUtils;
    @Autowired
    private ShopOrderDao shopOrderDao;
 
    /**
     * 根据ID逻辑删除产品评价
     * @param
     * @return
     */
    @PostMapping("/deleteByComId/{comId}")
    @ResponseBody
    public AjaxResult deleteByComId(@PathVariable("comId") Integer comId){
        Map<String, Object> modifyMap = new HashMap<>();
        modifyMap.put("delFlag", AppConstance.DATA_DISABLE);
        modifyMap.put("comId", comId);
        int i = productCommentDao.updateByMap(modifyMap);
        if (i == 0) {
            return new AjaxResult(AjaxResult.STATUS_FAIL, "删除失败");
        }
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, "删除成功");
    }
 
    /**
     * 接收保存产品评价数据
     */
    @PostMapping(value = "/saveProductComment")
    public @ResponseBody
    AjaxResult saveProductComment(@RequestBody List<ShopProductComment> commentList) {
        SysVipInfo loginUser = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
        int flag = 0;
        if(CollectionUtils.isNotEmpty(commentList)){
            for(ShopProductComment productComment : commentList){
                productComment.setCreateBy(loginUser.getOpenId());
                productComment.setUpdateBy(loginUser.getOpenId());
                productComment.setUserId(loginUser.getOpenId());
                productComment.setComAuditStatus(AppConstance.NOT_AUDITED);
                productComment.setDelFlag(AppConstance.DATA_USEABLE);
                productComment.setCompanyId(loginUser.getCompanyId());
            }
            flag = productCommentDao.batchInsert(commentList);
        }
 
        if (flag == 0) {
            return new AjaxResult(AjaxResult.STATUS_FAIL, "保存失败");
        }
        //将订单状态改为已评价
        Integer orderId = commentList.get(0).getOrderId();
        Map<String, Object> modifyMap = new HashMap<>();
        modifyMap.put("id", orderId);
        modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_ALREADY_REMARK);
        shopOrderDao.updateByMap(modifyMap);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, "保存成功");
    }
 
    /**
     * 根据用户ID查询产品评价
     * @param
     * @return
     */
    @PostMapping("/findProductComment")
    @ResponseBody
    public AjaxResult getProductCommentByUserId(@RequestBody ShopProductComment productComment) {
        SysVipInfo loginUser = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
        String userId = loginUser.getOpenId();
        productComment.setUserId(userId);
        List<ShopProductComment> list = productCommentDao.selectByUserId(productComment);
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, list);
        return result;
    }
 
    /**
     * 根据产品ID查询产品评价
     * @param
     * @return
     */
    @PostMapping("/findByProductId")
    @ResponseBody
    public AjaxResult findByProductId(@RequestBody ShopProductComment productComment) {
        List<ShopProductComment> list = productCommentDao.selectByProductId(productComment);
        int total = productCommentDao.selectByProductTotal(productComment);
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, list,total);
        return result;
    }
}