jiangping
2023-12-29 f9691d544e62d6c04dbfe45d05a6c7bc5e004291
server/services/src/main/java/com/doumee/service/business/impl/PricingParamServiceImpl.java
@@ -1,11 +1,17 @@
package com.doumee.service.business.impl;
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.BaseParamMapper;
import com.doumee.dao.business.PricingDetailMapper;
import com.doumee.dao.business.PricingParamMapper;
import com.doumee.dao.business.model.BaseParam;
import com.doumee.dao.business.model.PricingDetail;
import com.doumee.dao.business.model.PricingParam;
import com.doumee.service.business.PricingParamService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -19,6 +25,8 @@
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * 定价方案配置Service实现
@@ -30,6 +38,12 @@
    @Autowired
    private PricingParamMapper pricingParamMapper;
    @Autowired
    private PricingDetailMapper pricingDetailMapper;
    @Autowired
    private BaseParamMapper baseParamMapper;
    @Override
    public String create(PricingParam pricingParam) {
@@ -45,7 +59,7 @@
        insert.setStartDate(pricingParam.getStartDate());
        insert.setEndDate(pricingParam.getEndDate());
        insert.setSortnum(pricingParam.getSortnum());
        insert.setStatus(Constants.ZERO);
        insert.setStatus(Constants.ONE);
        insert.setInfo(pricingParam.getInfo());
        pricingParamMapper.insert(insert);
        return insert.getId();
@@ -79,12 +93,57 @@
                .eq(PricingParam::getId,pricingParam.getId())
                .set(PricingParam::getEditor,principal.getId())
                .set(PricingParam::getName,pricingParam.getName())
//                .set(PricingParam::getStatus,pricingParam.getStatus())
                .set(PricingParam::getStartDate,pricingParam.getStartDate())
                .set(PricingParam::getEndDate,pricingParam.getEndDate())
                .set(PricingParam::getEndDate,Utils.Date.getDayOfEnd(pricingParam.getEndDate()))
                .set(PricingParam::getSortnum,pricingParam.getSortnum());
        pricingParamMapper.update(null,wrapper);
    }
    @Override
    public void updateStatus(PricingParam pricingParam) {
        if (Objects.nonNull(pricingParam.getStatus()) && pricingParam.getStatus().equals(Constants.ZERO)){
            QueryWrapper<PricingDetail> wrapper = new QueryWrapper<>();
            wrapper.lambda()
                    .eq(PricingDetail::getIsdeleted,Constants.ZERO)
                    .eq(PricingDetail::getPricePramId,pricingParam.getId());
            List<PricingDetail> pricingDetails = pricingDetailMapper.selectList(wrapper);
            QueryWrapper<BaseParam> baseParamQuery = new QueryWrapper<>();
            baseParamQuery.lambda()
                            .eq(BaseParam::getIsdeleted,Constants.ZERO)
                            .eq(BaseParam::getType,Constants.THREE);
            List<BaseParam> baseParams = baseParamMapper.selectList(baseParamQuery);
            if (CollectionUtils.isEmpty(pricingDetails)){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"该定价方案下没有配置价格");
            }
            List<String> collect = pricingDetails.stream().map(s -> s.getBikeTypeId()).collect(Collectors.toList());
            boolean b = baseParams.stream().map(s -> s.getId()).allMatch(s -> collect.contains(s));
            if (!b){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"该定价方案下没有配置完整");
            }
            PricingParam pricingParam1 = new PricingParam();
            pricingParam1.setId(pricingParam.getId());
            pricingParam1.setStatus(pricingParam.getStatus());
            pricingParamMapper.updateById(pricingParam1);
        }else if (Objects.nonNull(pricingParam.getStatus()) && pricingParam.getStatus().equals(Constants.ONE)){
            QueryWrapper<PricingParam> wrapper = new QueryWrapper<>();
            wrapper.lambda()
                    .eq(PricingParam::getIsdeleted,Constants.ZERO)
                    .eq(PricingParam::getStatus,Constants.ZERO);
            Integer integer = pricingParamMapper.selectCount(wrapper);
            if (integer <= 1 ){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"该定价方案必须配置");
            }
            PricingParam pricingParam1 = new PricingParam();
            pricingParam1.setId(pricingParam.getId());
            pricingParam1.setStatus(pricingParam.getStatus());
            pricingParamMapper.updateById(pricingParam1);
        }
    }
    @Override
    public void updateById(PricingParam pricingParam) {
@@ -163,6 +222,7 @@
        if (pageWrap.getModel().getInfo() != null) {
            queryWrapper.lambda().eq(PricingParam::getInfo, pageWrap.getModel().getInfo());
        }
        queryWrapper.lambda().orderByAsc(PricingParam::getStatus);
        queryWrapper.lambda().orderByAsc(PricingParam::getSortnum);
        return PageData.from(pricingParamMapper.selectPage(page, queryWrapper));
    }