jiaosong
2023-10-16 c49f540e8d63958c37cde739b874d6fa0a5b92d4
server/services/src/main/java/com/doumee/service/business/impl/PricingDetailServiceImpl.java
@@ -23,6 +23,7 @@
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;
@@ -44,29 +45,7 @@
    @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());
@@ -90,6 +69,46 @@
        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);
@@ -111,6 +130,10 @@
    @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);
    }
@@ -139,6 +162,7 @@
    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);