package com.ruoyi.oa.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.http.HttpStatus; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.core.page.PagePlus; import com.ruoyi.common.core.page.TableDataInfo; import org.springframework.stereotype.Service; import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.oa.domain.bo.SgConstructionBatchBo; import com.ruoyi.oa.domain.vo.SgConstructionBatchVo; import com.ruoyi.oa.domain.SgConstructionBatch; import com.ruoyi.oa.mapper.SgConstructionBatchMapper; import com.ruoyi.oa.service.ISgConstructionBatchService; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; import java.util.Collection; /** * 施工批次Service业务层处理 * * @author ruoyi * @date 2022-05-09 */ @Service public class SgConstructionBatchServiceImpl extends ServicePlusImpl implements ISgConstructionBatchService { @Override public SgConstructionBatchVo queryById(Long id){ return getVoById(id); } @Override public TableDataInfo queryPageList(SgConstructionBatchBo bo) { PagePlus result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo)); return PageUtils.buildDataInfo(result); } @Override public List queryList(SgConstructionBatchBo bo) { return listVo(buildQueryWrapper(bo)); } private LambdaQueryWrapper buildQueryWrapper(SgConstructionBatchBo bo) { Map params = bo.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); lqw.like(StringUtils.isNotBlank(bo.getBatch()), SgConstructionBatch::getBatch, bo.getBatch()); lqw.eq(SgConstructionBatch::getSchoolId, bo.getSchoolId()); lqw.orderByDesc(SgConstructionBatch::getUpdateTime); return lqw; } @Override @Transactional(rollbackFor = Exception.class) public Boolean insertByBo(SgConstructionBatchBo bo) { List list = baseMapper.selectList(new LambdaQueryWrapper() .eq(SgConstructionBatch::getBatch, bo.getBatch()).eq(SgConstructionBatch::getSchoolId, bo.getSchoolId())); if (list.size() > 0) { throw new ServiceException("施工批次重复", HttpStatus.HTTP_PARTIAL); } SgConstructionBatch add = BeanUtil.toBean(bo, SgConstructionBatch.class); validEntityBeforeSave(add); boolean flag = save(add); if (flag) { bo.setId(add.getId()); } return flag; } @Override @Transactional(rollbackFor = Exception.class) public Boolean updateByBo(SgConstructionBatchBo bo) { List list = baseMapper.selectList(new LambdaQueryWrapper() .eq(SgConstructionBatch::getBatch, bo.getBatch()) .ne(SgConstructionBatch::getId, bo.getId()) .eq(SgConstructionBatch::getSchoolId, bo.getSchoolId())); if (list.size() > 0) { throw new ServiceException("施工批次重复", HttpStatus.HTTP_PARTIAL); } SgConstructionBatch update = BeanUtil.toBean(bo, SgConstructionBatch.class); validEntityBeforeSave(update); return updateById(update); } /** * 保存前的数据校验 * * @param entity 实体类数据 */ private void validEntityBeforeSave(SgConstructionBatch entity){ //TODO 做一些数据校验,如唯一约束 } @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { if(isValid){ //TODO 做一些业务上的校验,判断是否需要校验 } return removeByIds(ids); } }