111
k94314517
2023-10-09 bb0a8ba2fba9f22d66a3db7f194493f7f0a96ae0
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
package com.doumee.service.business.impl;
import java.math.BigDecimal;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.dao.business.BaseParamMapper;
import com.doumee.dao.business.MemberRidesMapper;
import com.doumee.dao.business.PricingDetailMapper;
import com.doumee.dao.business.PricingParamMapper;
import com.doumee.dao.business.model.BaseParam;
import com.doumee.dao.business.model.MemberRides;
import com.doumee.dao.business.web.response.PricingRuleDTO;
import com.doumee.service.business.PricingRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 *
 * 获取计价规则
 * @author T14
 */
 
@Service
public class PricingRuleServiceImpl implements PricingRuleService {
 
 
    @Autowired
    PricingParamMapper pricingParamMapper;
 
    @Autowired
    PricingDetailMapper pricingParamMapper;
 
 
    @Autowired
    MemberRidesMapper memberRidesMapper;
 
 
    @Autowired
    BaseParamMapper baseParamMapper;
 
 
    @Override
    public PricingRuleDTO getPricingRule(String goodaorderId) {
        QueryWrapper<MemberRides> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(MemberRides::getOrdreId,goodaorderId);
        List<MemberRides> memberRides = memberRidesMapper.selectList(wrapper);
        if (CollectionUtils.isEmpty(memberRides)){
            return null;
        }
        PricingRuleDTO pricingRule = getPricingRule(memberRides);
        return pricingRule;
    }
 
 
    @Override
    public PricingRuleDTO getPricingRule(List<MemberRides> memberRidesList) {
        if (!CollectionUtils.isEmpty(memberRidesList)){
            List<String> collect = memberRidesList.stream()
                    .filter(s -> Objects.nonNull(s.getActualPrice()))
                    .map(s -> s.getParamId())
                    .collect(Collectors.toList());
            QueryWrapper<BaseParam> wrapper = new QueryWrapper<>();
            wrapper.lambda()
                    .eq(BaseParam::getIsdeleted, Constants.ZERO)
                    .eq(BaseParam::getType, Constants.THREE)
                    .in(BaseParam::getId,collect)
                    .orderByDesc(BaseParam::getSortnum)
                    .last("limit 1");
            BaseParam baseParam = baseParamMapper.selectOne(wrapper);
 
            MemberRides memberRides = memberRidesList.stream()
                    .filter(s -> baseParam.getId().equals(s.getParamId()))
                    .findFirst().orElseThrow(() -> new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "没有车辆类型编码"));
            PricingRuleDTO pricingRuleDTO = new PricingRuleDTO();
            if (memberRides.getBaseTime() < 0){
                //一口价定价
                pricingRuleDTO.setStartFare(memberRides.getBasePrice());
                pricingRuleDTO.setPrice(new BigDecimal("0"));
                pricingRuleDTO.setType(Constants.ONE);
                pricingRuleDTO.setParamId(baseParam.getId());
                pricingRuleDTO.setBikeType(baseParam.getName());
                pricingRuleDTO.setMemberRides(memberRides);
            }else {
                pricingRuleDTO.setStartFare(memberRides.getBasePrice());
                pricingRuleDTO.setPrice(memberRides.getUnitPrice());
                pricingRuleDTO.setType(Constants.TWO);
                pricingRuleDTO.setParamId(baseParam.getId());
                pricingRuleDTO.setBikeType(baseParam.getName());
                pricingRuleDTO.setMemberRides(memberRides);
            }
            return pricingRuleDTO;
        }
        return null;
    }
}