| | |
| | | } |
| | | |
| | | @Override |
| | | public Integer createEstimatedDelivery(EstimatedDeliverySaveDTO request) { |
| | | PricingRule rule = new PricingRule(); |
| | | rule.setType(Constants.TWO); |
| | | rule.setCityId(request.getCityId()); |
| | | rule.setFieldA(request.getDistance()); |
| | | rule.setFieldB(request.getDuration()); |
| | | rule.setDeleted(Constants.ZERO); |
| | | rule.setCreateTime(new Date()); |
| | | rule.setUpdateTime(new Date()); |
| | | pricingRuleMapper.insert(rule); |
| | | return rule.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void updateEstimatedDelivery(EstimatedDeliverySaveDTO request) { |
| | | if (request.getId() == null) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "主键不能为空"); |
| | | } |
| | | PricingRule existing = pricingRuleMapper.selectById(request.getId()); |
| | | if (Objects.isNull(existing) || !Constants.equalsInteger(existing.getType(), Constants.TWO)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | existing.setFieldA(request.getDistance()); |
| | | existing.setFieldB(request.getDuration()); |
| | | existing.setCityId(request.getCityId()); |
| | | existing.setUpdateTime(new Date()); |
| | | pricingRuleMapper.updateById(existing); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteEstimatedDelivery(Integer id) { |
| | | PricingRule existing = pricingRuleMapper.selectById(id); |
| | | if (Objects.isNull(existing) || !Constants.equalsInteger(existing.getType(), Constants.TWO)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | existing.setDeleted(Constants.ONE); |
| | | existing.setUpdateTime(new Date()); |
| | | pricingRuleMapper.updateById(existing); |
| | | } |
| | | |
| | | @Override |
| | | public List<EstimatedDeliveryVO> listEstimatedDelivery(Integer cityId) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void saveEstimatedDelivery(EstimatedDeliverySaveDTO request) { |
| | | // 查询已有规则 type=2, fieldA=1, cityId, deleted=0 |
| | | QueryWrapper<PricingRule> qw = new QueryWrapper<>(); |
| | | qw.lambda() |
| | | .eq(PricingRule::getType, Constants.TWO) |
| | | .eq(PricingRule::getFieldA, "1") |
| | | .eq(PricingRule::getCityId, request.getCityId()) |
| | | .eq(PricingRule::getDeleted, Constants.ZERO) |
| | | .last("limit 1"); |
| | | PricingRule existing = pricingRuleMapper.selectOne(qw); |
| | | |
| | | Date now = new Date(); |
| | | if (existing != null) { |
| | | // 更新 |
| | | existing.setFieldB(request.getStartDistance()); |
| | | existing.setFieldC(request.getStartTime()); |
| | | existing.setFieldD(request.getContinueDistance()); |
| | | existing.setFieldE(request.getContinueTime()); |
| | | existing.setUpdateTime(now); |
| | | pricingRuleMapper.updateById(existing); |
| | | } else { |
| | | // 新增 |
| | | PricingRule rule = new PricingRule(); |
| | | rule.setType(Constants.TWO); |
| | | rule.setFieldA("1"); |
| | | rule.setFieldB(request.getStartDistance()); |
| | | rule.setFieldC(request.getStartTime()); |
| | | rule.setFieldD(request.getContinueDistance()); |
| | | rule.setFieldE(request.getContinueTime()); |
| | | rule.setCityId(request.getCityId()); |
| | | rule.setDeleted(Constants.ZERO); |
| | | rule.setCreateTime(now); |
| | | rule.setUpdateTime(now); |
| | | pricingRuleMapper.insert(rule); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public EstimatedDeliveryVO getEstimatedDelivery(Integer cityId) { |
| | | QueryWrapper<PricingRule> qw = new QueryWrapper<>(); |
| | | qw.lambda() |
| | | .eq(PricingRule::getType, Constants.TWO) |
| | | .eq(PricingRule::getFieldA, "1") |
| | | .eq(PricingRule::getCityId, cityId) |
| | | .eq(PricingRule::getDeleted, Constants.ZERO) |
| | | .orderByAsc(PricingRule::getFieldA); |
| | | List<PricingRule> rules = pricingRuleMapper.selectList(qw); |
| | | if (CollectionUtils.isEmpty(rules)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return rules.stream().map(rule -> { |
| | | .last("limit 1"); |
| | | PricingRule rule = pricingRuleMapper.selectOne(qw); |
| | | |
| | | EstimatedDeliveryVO vo = new EstimatedDeliveryVO(); |
| | | vo.setCityId(cityId); |
| | | if (rule != null) { |
| | | vo.setPricingRuleId(rule.getId()); |
| | | vo.setCityId(rule.getCityId()); |
| | | vo.setDistance(rule.getFieldA()); |
| | | vo.setDuration(rule.getFieldB()); |
| | | vo.setStartDistance(rule.getFieldB()); |
| | | vo.setStartTime(rule.getFieldC()); |
| | | vo.setContinueDistance(rule.getFieldD()); |
| | | vo.setContinueTime(rule.getFieldE()); |
| | | } |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |