| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | |
| | | @Override |
| | | public String create(PricingDetail pricingDetail) { |
| | | |
| | | if ((pricingDetail.getBaseTime() < 0) && |
| | | Objects.isNull(pricingDetail.getBasePrice())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"一口价价格不可为空"); |
| | | } |
| | | |
| | | if ((pricingDetail.getBaseTime() > 0) && |
| | | (Objects.isNull(pricingDetail.getBasePrice()) |
| | | || Objects.isNull(pricingDetail.getUnitTime()) |
| | | || Objects.isNull(pricingDetail.getUnitPrice()))){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"阶梯定价参数不可为空"); |
| | | } |
| | | |
| | | if ((pricingDetail.getHolidayBasePrice() < 0) && |
| | | Objects.isNull(pricingDetail.getBasePrice()) ){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"节假一口价价格不可为空"); |
| | | } |
| | | |
| | | if ((pricingDetail.getHolidayBasePrice() > 0) && |
| | | (Objects.isNull(pricingDetail.getHolidayBasePrice()) |
| | | || Objects.isNull(pricingDetail.getHolidayBasePrice()) |
| | | || Objects.isNull(pricingDetail.getHolidayBasePrice()))){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"节假阶梯定价参数不可为空"); |
| | | } |
| | | checkPricingDetail(pricingDetail); |
| | | LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | PricingDetail insert = new PricingDetail(); |
| | | insert.setCreateDate(new Date()); |
| | |
| | | return pricingDetail.getId(); |
| | | } |
| | | |
| | | private void checkPricingDetail(PricingDetail pricingDetail){ |
| | | if ((Objects.nonNull(pricingDetail.getBaseTime()) && pricingDetail.getBaseTime() < 0) && |
| | | Objects.isNull(pricingDetail.getBasePrice())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"一口价价格不可为空"); |
| | | } |
| | | |
| | | if ((Objects.nonNull(pricingDetail.getBaseTime()) && pricingDetail.getBaseTime() > 0) && |
| | | (Objects.isNull(pricingDetail.getBasePrice()) |
| | | || Objects.isNull(pricingDetail.getUnitTime()) |
| | | || Objects.isNull(pricingDetail.getUnitPrice()))){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"阶梯定价参数不可为空"); |
| | | } |
| | | |
| | | if ( (Objects.nonNull(pricingDetail.getHolidayBaseTime()) && pricingDetail.getHolidayBaseTime() < 0) |
| | | && ( Objects.isNull(pricingDetail.getHolidayBasePrice())) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"节假一口价价格不可为空"); |
| | | } |
| | | |
| | | if (((Objects.nonNull(pricingDetail.getHolidayBaseTime()) && pricingDetail.getHolidayBaseTime() > 0)) |
| | | && (Objects.isNull(pricingDetail.getHolidayBasePrice()) |
| | | || Objects.isNull(pricingDetail.getHolidayUnitTime()) |
| | | || Objects.isNull(pricingDetail.getHolidayUnitPrice()))){ |
| | | |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"节假阶梯定价参数不可为空"); |
| | | } |
| | | |
| | | QueryWrapper<PricingDetail> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda() |
| | | .eq(PricingDetail::getIsdeleted,Constants.ZERO) |
| | | .eq(PricingDetail::getBikeTypeId,pricingDetail.getBikeTypeId()) |
| | | .eq(PricingDetail::getPricePramId,pricingDetail.getPricePramId()); |
| | | Integer exitCount = pricingDetailMapper.selectCount(wrapper); |
| | | |
| | | if (exitCount > Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"该车型已配置"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(String id) { |
| | | pricingDetailMapper.deleteById(id); |
| | |
| | | |
| | | @Override |
| | | public void updateById(PricingDetail pricingDetail) { |
| | | checkPricingDetail(pricingDetail); |
| | | LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | pricingDetail.setEditDate(new Date()); |
| | | pricingDetail.setEditor(principal.getId()); |
| | | pricingDetailMapper.updateById(pricingDetail); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public PricingDetail findOne(PricingDetail pricingDetail) { |
| | | QueryWrapper<PricingDetail> wrapper = new QueryWrapper<>(pricingDetail); |
| | | return pricingDetailMapper.selectOne(wrapper); |
| | | return pricingDetailMapper.selectOne(wrapper.last(" limit 1")); |
| | | } |
| | | |
| | | @Override |
| | | public List<PricingDetail> findList(PricingDetail pricingDetail) { |
| | | MPJLambdaWrapper<PricingDetail> wrapper = new MPJLambdaWrapper<>(); |
| | | wrapper.leftJoin(BaseParam.class,BaseParam::getId,PricingDetail::getBikeTypeId) |
| | | .eq(PricingDetail::getPricePramId,pricingDetail.getPricePramId()) |
| | | .eq(BaseParam::getType,Constants.THREE); |
| | | wrapper.selectAll(PricingDetail.class) |
| | | .selectAs(BaseParam::getName,PricingDetail::getBikeTypeName); |