| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xiaopeng.api.dto.account.GetUserCouponDto; |
| | | import com.xiaopeng.api.dto.map.RouteAndFareDto; |
| | |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserCouponClient; |
| | | import com.xiaopeng.api.feignClient.map.XpMapClient; |
| | | import com.xiaopeng.api.feignClient.order.XpOrderClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient; |
| | | import com.xiaopeng.api.model.account.XpAppUser; |
| | | import com.xiaopeng.api.model.operation.*; |
| | | import com.xiaopeng.api.model.order.XpOrder; |
| | |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.DateUtils; |
| | | import com.xiaopeng.common.core.utils.uuid.UUID; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.common.redis.service.RedisService; |
| | | import com.xiaopeng.operation.constant.I18nKeyConstant; |
| | | import com.xiaopeng.operation.dto.PricingAddDTO; |
| | | import com.xiaopeng.operation.dto.PricingSetPriceDTO; |
| | | import com.xiaopeng.operation.dto.PricingSetRuleDTO; |
| | | import com.xiaopeng.operation.dto.XpOrderDto; |
| | | import com.xiaopeng.api.model.operation.XpGeoQueryEntity; |
| | | import com.xiaopeng.operation.mapper.*; |
| | | import com.xiaopeng.operation.query.PricingPageListQuery; |
| | | import com.xiaopeng.operation.service.IXpGeoQueryEntityService; |
| | | import com.xiaopeng.operation.service.XpPricingService; |
| | | import com.xiaopeng.operation.utils.XpPricingUtil; |
| | | import com.xiaopeng.operation.utils.holiday.HolidayUtil; |
| | | import com.xiaopeng.operation.utils.map.FastDistanceCalculator; |
| | | import com.xiaopeng.operation.vo.PricingPageListVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PreDestroy; |
| | | import javax.annotation.Resource; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.*; |
| | |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<PricingPageListVO> pageList(PricingPageListQuery query) { |
| | | PageInfo<PricingPageListVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | Page<PricingPageListVO> page = this.baseMapper.pageList(pageInfo, query); |
| | | pageInfo.setRecords(page.getRecords()); |
| | | pageInfo.setTotal(page.getTotal()); |
| | | return pageInfo; |
| | | } |
| | | |
| | | @Override |
| | | public void add(PricingAddDTO dto) { |
| | | XpOpenCity openCity = xpOpenCityMapper.selectById(dto.getCityId()); |
| | | if (openCity == null) { |
| | | throw new ServiceException("开通城市不存在"); |
| | | } |
| | | |
| | | Long count = this.lambdaQuery() |
| | | .eq(XpPricing::getVehicleModel, dto.getVehicleModel()) |
| | | .eq(XpPricing::getChannel, dto.getChannel()) |
| | | .eq(XpPricing::getCityId, dto.getCityId().intValue()) |
| | | .count(); |
| | | if (count != null && count > 0) { |
| | | throw new ServiceException("该车型/渠道/城市的定价已存在", I18nKeyConstant.PRICING_EXISTS); |
| | | } |
| | | |
| | | XpPricing pricing = new XpPricing(); |
| | | pricing.setVehicleModel(dto.getVehicleModel()); |
| | | pricing.setChannel(dto.getChannel()); |
| | | pricing.setCityId(dto.getCityId().intValue()); |
| | | pricing.setRemark(dto.getRemark()); |
| | | pricing.setPricingType(dto.getPricingType()); |
| | | pricing.setBasicPricingJson("{}"); |
| | | pricing.setStartingFareJson("[]"); |
| | | pricing.setDynamicPricingJson("{}"); |
| | | pricing.setIsDynamicPrice(0); |
| | | this.save(pricing); |
| | | } |
| | | |
| | | @Override |
| | | public void setPrice(PricingSetPriceDTO dto) { |
| | | XpPricing pricing = this.getById(dto.getId()); |
| | | if (pricing == null) { |
| | | throw new ServiceException("定价不存在", I18nKeyConstant.PRICING_NOT_EXIST); |
| | | } |
| | | |
| | | try { |
| | | JSONObject.parseObject(dto.getBasicPricingJson()); |
| | | JSONArray.parseArray(dto.getStartingFareJson()); |
| | | JSONObject.parseObject(dto.getDynamicPricingJson()); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("价格配置JSON格式不正确", I18nKeyConstant.PRICING_JSON_INVALID); |
| | | } |
| | | |
| | | XpPricing update = new XpPricing(); |
| | | update.setId(dto.getId()); |
| | | update.setBasicPricingJson(dto.getBasicPricingJson()); |
| | | update.setStartingFareJson(dto.getStartingFareJson()); |
| | | update.setDynamicPricingJson(dto.getDynamicPricingJson()); |
| | | this.updateById(update); |
| | | } |
| | | |
| | | @Override |
| | | public void setRule(PricingSetRuleDTO dto) { |
| | | XpPricing pricing = this.getById(dto.getId()); |
| | | if (pricing == null) { |
| | | throw new ServiceException("定价不存在", I18nKeyConstant.PRICING_NOT_EXIST); |
| | | } |
| | | |
| | | XpPricing update = new XpPricing(); |
| | | update.setId(dto.getId()); |
| | | update.setPriceRule(dto.getPriceRule()); |
| | | this.updateById(update); |
| | | } |
| | | |
| | | } |