| 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; | 
| import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
| import com.baomidou.mybatisplus.core.metadata.IPage; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import org.apache.shiro.SecurityUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.util.CollectionUtils; | 
|   | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.Objects; | 
| import java.util.stream.Collectors; | 
|   | 
| /** | 
|  * 定价方案配置Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2023/09/27 18:06 | 
|  */ | 
| @Service | 
| public class PricingParamServiceImpl implements PricingParamService { | 
|   | 
|     @Autowired | 
|     private PricingParamMapper pricingParamMapper; | 
|   | 
|     @Autowired | 
|     private PricingDetailMapper pricingDetailMapper; | 
|   | 
|     @Autowired | 
|     private BaseParamMapper baseParamMapper; | 
|   | 
|     @Override | 
|     public String create(PricingParam pricingParam) { | 
|   | 
|         LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         PricingParam insert = new PricingParam(); | 
|         insert.setCreateDate(new Date()); | 
|         insert.setCreator(principal.getId()); | 
| //        insert.setEditDate(new Date()); | 
| //        insert.setEditor(principal.getId()); | 
|         insert.setIsdeleted(Constants.ZERO); | 
|         insert.setName(pricingParam.getName()); | 
|         insert.setStartDate(pricingParam.getStartDate()); | 
|         insert.setEndDate(pricingParam.getEndDate()); | 
|         insert.setSortnum(pricingParam.getSortnum()); | 
|         insert.setStatus(Constants.ONE); | 
|         insert.setInfo(pricingParam.getInfo()); | 
|         pricingParamMapper.insert(insert); | 
|         return insert.getId(); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteById(String id) { | 
|         pricingParamMapper.deleteById(id); | 
|     } | 
|   | 
|     @Override | 
|     public void delete(PricingParam pricingParam) { | 
|         UpdateWrapper<PricingParam> deleteWrapper = new UpdateWrapper<>(pricingParam); | 
|         pricingParamMapper.delete(deleteWrapper); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteByIdInBatch(List<String> ids) { | 
|         if (CollectionUtils.isEmpty(ids)) { | 
|             return; | 
|         } | 
|         pricingParamMapper.deleteBatchIds(ids); | 
|     } | 
|   | 
|     @Override | 
|     public void update(PricingParam pricingParam) { | 
|   | 
|         LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         UpdateWrapper<PricingParam> wrapper = new UpdateWrapper<>(); | 
|         wrapper.lambda() | 
|                 .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,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); | 
|             long 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) { | 
|         pricingParamMapper.updateById(pricingParam); | 
|     } | 
|   | 
|     @Override | 
|     public void updateByIdInBatch(List<PricingParam> pricingParams) { | 
|         if (CollectionUtils.isEmpty(pricingParams)) { | 
|             return; | 
|         } | 
|         for (PricingParam pricingParam: pricingParams) { | 
|             this.updateById(pricingParam); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public PricingParam findById(String id) { | 
|         return pricingParamMapper.selectById(id); | 
|     } | 
|   | 
|     @Override | 
|     public PricingParam findOne(PricingParam pricingParam) { | 
|         QueryWrapper<PricingParam> wrapper = new QueryWrapper<>(pricingParam); | 
|         return pricingParamMapper.selectOne(wrapper.last(" limit 1")); | 
|     } | 
|   | 
|     @Override | 
|     public List<PricingParam> findList(PricingParam pricingParam) { | 
|         QueryWrapper<PricingParam> wrapper = new QueryWrapper<>(pricingParam); | 
|         return pricingParamMapper.selectList(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public PageData<PricingParam> findPage(PageWrap<PricingParam> pageWrap) { | 
|         IPage<PricingParam> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         QueryWrapper<PricingParam> queryWrapper = new QueryWrapper<>(); | 
|         Utils.MP.blankToNull(pageWrap.getModel()); | 
|         if (pageWrap.getModel().getId() != null) { | 
|             queryWrapper.lambda().eq(PricingParam::getId, pageWrap.getModel().getId()); | 
|         } | 
|         if (pageWrap.getModel().getCreateDate() != null) { | 
|             queryWrapper.lambda().ge(PricingParam::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
|             queryWrapper.lambda().le(PricingParam::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
|         } | 
|         if (pageWrap.getModel().getCreator() != null) { | 
|             queryWrapper.lambda().eq(PricingParam::getCreator, pageWrap.getModel().getCreator()); | 
|         } | 
|         if (pageWrap.getModel().getEditDate() != null) { | 
|             queryWrapper.lambda().ge(PricingParam::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
|             queryWrapper.lambda().le(PricingParam::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
|         } | 
|         if (pageWrap.getModel().getEditor() != null) { | 
|             queryWrapper.lambda().eq(PricingParam::getEditor, pageWrap.getModel().getEditor()); | 
|         } | 
|         if (pageWrap.getModel().getIsdeleted() != null) { | 
|             queryWrapper.lambda().eq(PricingParam::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|         } | 
|         if (pageWrap.getModel().getName() != null) { | 
|             queryWrapper.lambda().like(PricingParam::getName, pageWrap.getModel().getName()); | 
|         } | 
|         if (pageWrap.getModel().getStartDate() != null) { | 
|             queryWrapper.lambda().ge(PricingParam::getStartDate, Utils.Date.getStart(pageWrap.getModel().getStartDate())); | 
|             queryWrapper.lambda().le(PricingParam::getStartDate, Utils.Date.getEnd(pageWrap.getModel().getStartDate())); | 
|         } | 
|         if (pageWrap.getModel().getEndDate() != null) { | 
|             queryWrapper.lambda().ge(PricingParam::getEndDate, Utils.Date.getStart(pageWrap.getModel().getEndDate())); | 
|             queryWrapper.lambda().le(PricingParam::getEndDate, Utils.Date.getEnd(pageWrap.getModel().getEndDate())); | 
|         } | 
|         if (pageWrap.getModel().getSortnum() != null) { | 
|             queryWrapper.lambda().eq(PricingParam::getSortnum, pageWrap.getModel().getSortnum()); | 
|         } | 
|         if (pageWrap.getModel().getStatus() != null) { | 
|             queryWrapper.lambda().eq(PricingParam::getStatus, pageWrap.getModel().getStatus()); | 
|         } | 
|         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)); | 
|     } | 
|   | 
|     @Override | 
|     public long count(PricingParam pricingParam) { | 
|         QueryWrapper<PricingParam> wrapper = new QueryWrapper<>(pricingParam); | 
|         return pricingParamMapper.selectCount(wrapper); | 
|     } | 
| } |