| | |
| | | @Override |
| | | public String create(PricingDetail pricingDetail) { |
| | | |
| | | //校验参数合法性 |
| | | checkPricingDetail(pricingDetail); |
| | | |
| | | LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | UpdateWrapper<PricingDetail> wrapper = new UpdateWrapper<>(); |
| | | wrapper.lambda() |
| | | .set(PricingDetail::getIsdeleted,Constants.ONE) |
| | | .set(PricingDetail::getEditDate,new Date()) |
| | | .set(PricingDetail::getEditor,principal.getId()) |
| | | .eq(PricingDetail::getBikeTypeId,pricingDetail.getBikeTypeId()) |
| | | .eq(PricingDetail::getPricePramId,pricingDetail.getPricePramId()); |
| | | pricingDetailMapper.update(null, wrapper);//删除老的配置 |
| | | |
| | | PricingDetail insert = new PricingDetail(); |
| | | insert.setId(Constants.getUUID()); |
| | | insert.setCreateDate(new Date()); |
| | | insert.setCreator(principal.getId()); |
| | | insert.setEditDate(new Date()); |
| | | insert.setEditor(principal.getId()); |
| | | insert.setIsdeleted(Constants.ZERO); |
| | | insert.setPricePramId(pricingDetail.getPricePramId()); |
| | | insert.setBikeTypeId(pricingDetail.getBikeTypeId()); |
| | |
| | | insert.setHolidayBasePrice(Constants.formatDecimalNum(pricingDetail.getHolidayBasePrice()).multiply(new BigDecimal(100))); |
| | | insert.setHolidayUnitPrice(Constants.formatDecimalNum(pricingDetail.getHolidayUnitPrice()).multiply(new BigDecimal(100))); |
| | | insert.setInfo(pricingDetail.getInfo()); |
| | | insert.setTitle(pricingDetail.getTitle()); |
| | | String title = getRoleNameByParam(insert.getBasePrice(),insert.getBaseTime(),insert.getUnitPrice(),insert.getUnitTime()); |
| | | String info = getRoleNameByParam(insert.getHolidayBasePrice(),insert.getHolidayBaseTime(),insert.getHolidayUnitPrice(),insert.getHolidayUnitTime());; |
| | | insert.setTitle(title);//工作日计价配置规则 |
| | | insert.setInfo(info);//节假日计价配置规则 |
| | | pricingDetailMapper.insert(insert); |
| | | return pricingDetail.getId(); |
| | | } |
| | | |
| | | public static String getRoleNameByParam(BigDecimal basePrice, Integer baseTime, BigDecimal unitPrice, Integer unitTime) { |
| | | String title = "计费规则:"; |
| | | if(baseTime < 0){ |
| | | title += (basePrice.divide(new BigDecimal(100))).doubleValue()+"元畅骑一整天"; |
| | | }else { |
| | | title += "起步"; |
| | | int time = baseTime / 60; |
| | | int min = baseTime % 60; |
| | | if(time > 0){ |
| | | title += time+"小时"; |
| | | } |
| | | if(min >0){ |
| | | title += min+"分钟"; |
| | | } |
| | | title += basePrice.divide(new BigDecimal(100)).doubleValue() |
| | | +"元,超过后"+unitPrice.divide(new BigDecimal(100)).doubleValue()+"元/" |
| | | +unitTime+"分钟"; |
| | | } |
| | | return title; |
| | | } |
| | | |
| | | 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(StringUtils.isBlank(pricingDetail.getPricePramId()) |
| | | ||StringUtils.isBlank(pricingDetail.getBikeTypeId()) |
| | | ||pricingDetail.getBaseTime() == null |
| | | ||pricingDetail.getBaseTime()==0 |
| | | ||Constants.formatDecimalNum(pricingDetail.getBasePrice() ).doubleValue()<0 |
| | | ||Constants.formatDecimalNum(pricingDetail.getHolidayBasePrice() ).doubleValue()<0 |
| | | ||pricingDetail.getHolidayBaseTime() == null |
| | | || pricingDetail.getHolidayBaseTime()==0){ |
| | | //参数错误 |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | 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(),"阶梯定价参数不可为空"); |
| | | pricingDetail.setUnitPrice(Constants.formatDecimalNum(pricingDetail.getUnitPrice())); |
| | | pricingDetail.setHolidayUnitPrice(Constants.formatDecimalNum(pricingDetail.getHolidayUnitPrice())); |
| | | pricingDetail.setUnitTime(Constants.formatIntegerNum(pricingDetail.getUnitTime())); |
| | | pricingDetail.setHolidayUnitTime(Constants.formatIntegerNum(pricingDetail.getHolidayUnitTime())); |
| | | if ( pricingDetail.getBaseTime() < 0){ |
| | | pricingDetail.setBaseTime(-1); |
| | | } |
| | | |
| | | if ( (Objects.nonNull(pricingDetail.getHolidayBaseTime()) && pricingDetail.getHolidayBaseTime() < 0) |
| | | && ( Objects.isNull(pricingDetail.getHolidayBasePrice())) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"节假一口价价格不可为空"); |
| | | if ( pricingDetail.getHolidayBaseTime() < 0){ |
| | | pricingDetail.setHolidayBaseTime(-1); |
| | | } |
| | | |
| | | 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()) |
| | | .last("limit 1"); |
| | | PricingDetail exitCount = pricingDetailMapper.selectOne(wrapper); |
| | | |
| | | if (Objects.nonNull(exitCount) && !Objects.equals(exitCount.getId(),pricingDetail.getId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"该车型已配置"); |
| | | } |
| | | // PricingDetail exitCount = pricingDetailMapper.selectOne(wrapper); |
| | | |
| | | } |
| | | |
| | |
| | | put.setBikeTypeId(s.getId()); |
| | | put.setPricePramId(pricingDetail.getPricePramId()); |
| | | put.setBikeTypeName(s.getName()); |
| | | put.setSortnum(s.getSortnum()); |
| | | put.setBasePrice(Objects.nonNull(put.getBasePrice()) ? Constants.translateMoney(put.getBasePrice()) : null); |
| | | put.setHolidayBasePrice(Objects.nonNull(put.getHolidayBasePrice()) ? Constants.translateMoney(put.getHolidayBasePrice()):null); |
| | | put.setUnitPrice(Objects.nonNull(put.getUnitPrice()) ? Constants.translateMoney(put.getUnitPrice()):null); |