package com.matrix.system.shopXcx.api.action;
|
|
import com.matrix.core.pojo.AjaxResult;
|
import com.matrix.biz.bean.BizUser;
|
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) {
|
BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.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) {
|
BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.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;
|
}
|
}
|