package com.doumee.service.business.impl; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Utils; import com.doumee.dao.business.SegmentsMapper; import com.doumee.dao.business.model.Segments; import com.doumee.service.business.SegmentsService; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.List; /** * 志邦营销区域信息表Service实现 * @author 江蹄蹄 * @date 2024/07/04 14:40 */ @Service public class SegmentsServiceImpl implements SegmentsService { @Autowired private SegmentsMapper segmentsMapper; @Override public Long create(Segments segments) { segmentsMapper.insert(segments); return segments.getId(); } @Override public void deleteById(Long id) { segmentsMapper.deleteById(id); } @Override public void delete(Segments segments) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(segments); segmentsMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) { return; } segmentsMapper.deleteBatchIds(ids); } @Override public void updateById(Segments segments) { segmentsMapper.updateById(segments); } @Override public void updateByIdInBatch(List segmentss) { if (CollectionUtils.isEmpty(segmentss)) { return; } for (Segments segments: segmentss) { this.updateById(segments); } } @Override public Segments findById(Long id) { return segmentsMapper.selectById(id); } @Override public Segments findOne(Segments segments) { QueryWrapper wrapper = new QueryWrapper<>(segments); return segmentsMapper.selectOne(wrapper); } @Override public List findList(Segments segments) { QueryWrapper wrapper = new QueryWrapper<>(segments); return segmentsMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); QueryWrapper queryWrapper = new QueryWrapper<>(); Utils.MP.blankToNull(pageWrap.getModel()); if (pageWrap.getModel().getId() != null) { queryWrapper.lambda().eq(Segments::getId, pageWrap.getModel().getId()); } if (pageWrap.getModel().getCreator() != null) { queryWrapper.lambda().eq(Segments::getCreator, pageWrap.getModel().getCreator()); } if (pageWrap.getModel().getCreateDate() != null) { queryWrapper.lambda().ge(Segments::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); queryWrapper.lambda().le(Segments::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); } if (pageWrap.getModel().getEditor() != null) { queryWrapper.lambda().eq(Segments::getEditor, pageWrap.getModel().getEditor()); } if (pageWrap.getModel().getEditDate() != null) { queryWrapper.lambda().ge(Segments::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); queryWrapper.lambda().le(Segments::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); } if (pageWrap.getModel().getIsdeleted() != null) { queryWrapper.lambda().eq(Segments::getIsdeleted, pageWrap.getModel().getIsdeleted()); } if (pageWrap.getModel().getRemark() != null) { queryWrapper.lambda().eq(Segments::getRemark, pageWrap.getModel().getRemark()); } if (pageWrap.getModel().getSegmentId() != null) { queryWrapper.lambda().eq(Segments::getSegmentId, pageWrap.getModel().getSegmentId()); } if (pageWrap.getModel().getName() != null) { queryWrapper.lambda().eq(Segments::getName, pageWrap.getModel().getName()); } if (pageWrap.getModel().getParentId() != null) { queryWrapper.lambda().eq(Segments::getParentId, pageWrap.getModel().getParentId()); } if (pageWrap.getModel().getStatus() != null) { queryWrapper.lambda().eq(Segments::getStatus, pageWrap.getModel().getStatus()); } if (pageWrap.getModel().getOrderNum() != null) { queryWrapper.lambda().eq(Segments::getOrderNum, pageWrap.getModel().getOrderNum()); } if (pageWrap.getModel().getType() != null) { queryWrapper.lambda().eq(Segments::getType, pageWrap.getModel().getType()); } if (pageWrap.getModel().getSyncDate() != null) { queryWrapper.lambda().ge(Segments::getSyncDate, Utils.Date.getStart(pageWrap.getModel().getSyncDate())); queryWrapper.lambda().le(Segments::getSyncDate, Utils.Date.getEnd(pageWrap.getModel().getSyncDate())); } if (pageWrap.getModel().getSyncInfo() != null) { queryWrapper.lambda().eq(Segments::getSyncInfo, pageWrap.getModel().getSyncInfo()); } for(PageWrap.SortData sortData: pageWrap.getSorts()) { if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { queryWrapper.orderByDesc(sortData.getProperty()); } else { queryWrapper.orderByAsc(sortData.getProperty()); } } return PageData.from(segmentsMapper.selectPage(page, queryWrapper)); } @Override public long count(Segments segments) { QueryWrapper wrapper = new QueryWrapper<>(segments); return segmentsMapper.selectCount(wrapper); } }