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 MemberRidesMapper memberRidesMapper; @Autowired BaseParamMapper baseParamMapper; @Override public PricingRuleDTO getPricingRule(String goodaorderId) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.lambda() .eq(MemberRides::getOrdreId,goodaorderId); List memberRides = memberRidesMapper.selectList(wrapper); if (CollectionUtils.isEmpty(memberRides)){ return null; } PricingRuleDTO pricingRule = getPricingRule(memberRides); return pricingRule; } @Override public PricingRuleDTO getPricingRule(List memberRidesList) { if (!CollectionUtils.isEmpty(memberRidesList)){ List collect = memberRidesList.stream() .filter(s -> Objects.nonNull(s.getActualPrice())) .map(s -> s.getParamId()) .collect(Collectors.toList()); QueryWrapper 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; } }