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);
|
}
|
}
|