huliguo
2 天以前 5d7b65670282a4fad015e37d567cfa171b162052
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
package com.ruoyi.errand.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.errand.constant.DelFlagConstant;
import com.ruoyi.errand.domain.AppUser;
import com.ruoyi.errand.domain.Evaluation;
import com.ruoyi.errand.domain.Order;
import com.ruoyi.errand.mapper.EvaluationMapper;
import com.ruoyi.errand.mapper.OrderMapper;
import com.ruoyi.errand.object.dto.app.AddEvaluationDTO;
import com.ruoyi.errand.service.EvaluationService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.Objects;
 
@Service
public class EvaluationServiceImpl extends ServiceImpl<EvaluationMapper, Evaluation> implements EvaluationService {
 
    private  OrderMapper orderMapper;
 
    @Override
    public void add(AddEvaluationDTO addEvaluationDTO) {
        //检查订单id是否存在
        //该用户类型是否正常
        AppUser appuser = (AppUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        //判断订单是否存在
        Order order = orderMapper.selectById(addEvaluationDTO.getOrderId());
        if (order==null ||order.getDelFlag().equals(DelFlagConstant.DELETE)){
            throw new ServiceException("订单id错误");
        }
        if (order.getOrderStatus()!=4){
            throw new ServiceException("订单状态错误");
        }
 
        if (addEvaluationDTO.getType()==0){
            //用户评价
            if (!Objects.equals(order.getAppUserId(), appuser.getId())){
                throw new ServiceException("用户与订单不匹配");
            }
        }else if (addEvaluationDTO.getType()==1){
            if (!Objects.equals(order.getCourierId(), appuser.getCourierId())){
                throw new ServiceException("跑腿与订单不匹配");
            }
        }else {
            throw new ServiceException("评价类型错误");
        }
        Evaluation evaluation = new Evaluation();
        evaluation.setOrderId(addEvaluationDTO.getOrderId());
        evaluation.setType(addEvaluationDTO.getType());
        evaluation.setRating(addEvaluationDTO.getRating());
        evaluation.setContent(addEvaluationDTO.getContent());
        evaluation.setCreateTime(LocalDateTime.now());
        this.save(evaluation);
    }
}