wlzboy
2025-09-21 7d81ce01560d384f15212edc40ebeaa9924913f9
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package com.ruoyi.system.service.impl;
 
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.system.mapper.CustomerEvaluationMapper;
import com.ruoyi.system.mapper.EvaluationDetailMapper;
import com.ruoyi.system.domain.CustomerEvaluation;
import com.ruoyi.system.domain.EvaluationDetail;
import com.ruoyi.system.service.ICustomerEvaluationService;
 
/**
 * 客户评价Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-27
 */
@Service
public class CustomerEvaluationServiceImpl implements ICustomerEvaluationService {
    @Autowired
    private CustomerEvaluationMapper customerEvaluationMapper;
 
    @Autowired
    private EvaluationDetailMapper evaluationDetailMapper;
 
    /**
     * 查询客户评价
     * 
     * @param evaluationId 客户评价主键
     * @return 客户评价
     */
    @Override
    public CustomerEvaluation selectCustomerEvaluationByEvaluationId(Long evaluationId) {
        CustomerEvaluation evaluation = customerEvaluationMapper.selectCustomerEvaluationByEvaluationId(evaluationId);
        if (evaluation != null) {
            // 查询评价详情
            List<EvaluationDetail> details = evaluationDetailMapper.selectEvaluationDetailByEvaluationId(evaluationId);
            evaluation.setEvaluationDetails(details);
        }
        return evaluation;
    }
 
    /**
     * 查询客户评价列表
     * 
     * @param customerEvaluation 客户评价
     * @return 客户评价
     */
    @Override
    public List<CustomerEvaluation> selectCustomerEvaluationList(CustomerEvaluation customerEvaluation) {
        return customerEvaluationMapper.selectCustomerEvaluationList(customerEvaluation);
    }
 
    /**
     * 根据车牌号查询客户评价
     * 
     * @param vehicleNo 车牌号
     * @return 客户评价集合
     */
    @Override
    public List<CustomerEvaluation> selectCustomerEvaluationByVehicleNo(String vehicleNo) {
        return customerEvaluationMapper.selectCustomerEvaluationByVehicleNo(vehicleNo);
    }
 
    /**
     * 根据微信OpenID查询客户评价
     * 
     * @param wechatOpenid 微信OpenID
     * @return 客户评价集合
     */
    @Override
    public List<CustomerEvaluation> selectCustomerEvaluationByWechatOpenid(String wechatOpenid) {
        return customerEvaluationMapper.selectCustomerEvaluationByWechatOpenid(wechatOpenid);
    }
 
    /**
     * 新增客户评价
     * 
     * @param customerEvaluation 客户评价
     * @return 结果
     */
    @Override
    public int insertCustomerEvaluation(CustomerEvaluation customerEvaluation) {
        customerEvaluation.setCreateTime(DateUtils.getNowDate());
        return customerEvaluationMapper.insertCustomerEvaluation(customerEvaluation);
    }
 
    /**
     * 修改客户评价
     * 
     * @param customerEvaluation 客户评价
     * @return 结果
     */
    @Override
    public int updateCustomerEvaluation(CustomerEvaluation customerEvaluation) {
        customerEvaluation.setUpdateTime(DateUtils.getNowDate());
        return customerEvaluationMapper.updateCustomerEvaluation(customerEvaluation);
    }
 
    /**
     * 批量删除客户评价
     * 
     * @param evaluationIds 需要删除的客户评价主键
     * @return 结果
     */
    @Override
    public int deleteCustomerEvaluationByEvaluationIds(Long[] evaluationIds) {
        return customerEvaluationMapper.deleteCustomerEvaluationByEvaluationIds(evaluationIds);
    }
 
    /**
     * 删除客户评价信息
     * 
     * @param evaluationId 客户评价主键
     * @return 结果
     */
    @Override
    public int deleteCustomerEvaluationByEvaluationId(Long evaluationId) {
        return customerEvaluationMapper.deleteCustomerEvaluationByEvaluationId(evaluationId);
    }
 
    /**
     * 提交客户评价
     * 
     * @param customerEvaluation 客户评价
     * @return 结果
     */
    @Override
    @Transactional
    public int submitCustomerEvaluation(CustomerEvaluation customerEvaluation) {
        // 计算总评分
        BigDecimal totalScore = calculateTotalScore(customerEvaluation.getEvaluationDetails());
        customerEvaluation.setTotalScore(totalScore);
        customerEvaluation.setEvaluationStatus("1");
        customerEvaluation.setEvaluationTime(DateUtils.getNowDate());
        customerEvaluation.setCreateTime(DateUtils.getNowDate());
 
        // 插入客户评价
        int result = customerEvaluationMapper.insertCustomerEvaluation(customerEvaluation);
        
        if (result > 0 && customerEvaluation.getEvaluationDetails() != null && !customerEvaluation.getEvaluationDetails().isEmpty()) {
            // 插入评价详情
            for (EvaluationDetail detail : customerEvaluation.getEvaluationDetails()) {
                detail.setEvaluationId(customerEvaluation.getEvaluationId());
                detail.setCreateTime(DateUtils.getNowDate());
                evaluationDetailMapper.insertEvaluationDetail(detail);
            }
        }
        
        return result;
    }
 
    /**
     * 统计评价数量
     * 
     * @param customerEvaluation 客户评价
     * @return 评价统计信息
     */
    @Override
    public List<CustomerEvaluation> selectEvaluationStatistics(CustomerEvaluation customerEvaluation) {
        return customerEvaluationMapper.selectEvaluationStatistics(customerEvaluation);
    }
 
    /**
     * 计算总评分
     * 
     * @param details 评价详情列表
     * @return 总评分
     */
    private BigDecimal calculateTotalScore(List<EvaluationDetail> details) {
        if (details == null || details.isEmpty()) {
            return BigDecimal.ZERO;
        }
 
        int totalScore = 0;
        int count = 0;
        
        for (EvaluationDetail detail : details) {
            if (detail.getScore() != null && detail.getScore() > 0) {
                totalScore += detail.getScore();
                count++;
            }
        }
        
        if (count == 0) {
            return BigDecimal.ZERO;
        }
        
        return new BigDecimal(totalScore).divide(new BigDecimal(count), 1, BigDecimal.ROUND_HALF_UP);
    }
}