package com.ruoyi.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.system.domain.Licence; import com.ruoyi.system.mapper.LicenceMapper; import com.ruoyi.system.pojo.dto.AddLicenceDTO; import com.ruoyi.system.pojo.dto.EditLicenceDTO; import com.ruoyi.system.pojo.vo.LicencePageVO; import com.ruoyi.system.service.LicenceService; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; @Service public class LicenceServiceImpl extends ServiceImpl implements LicenceService { @Override public IPage getLicencePage(Integer pageNum, Integer pageSize, String name) { IPage page=new Page<>(pageNum, pageSize); return this.baseMapper.getIndustryPage(page,name); } @Override public void add(AddLicenceDTO dto) { //判断是否存在 Licence licence = this.baseMapper.selectOne(new LambdaQueryWrapper().eq(Licence::getName, dto.getName()).eq(Licence::getDelFlag, 0)); if (null != licence) { throw new ServiceException("许可证名称重复"); } licence = new Licence(); BeanUtils.copyProperties(dto, licence); String grand = String.join(";", dto.getGrandNameList());//多个以分号相隔 licence.setGradeName(grand); this.baseMapper.insert(licence); } @Override public void edit(EditLicenceDTO dto) { Licence licence = this.baseMapper.selectById(dto.getId()); if (null == licence || licence.getDelFlag() != 0) { throw new ServiceException("该许可证不存在"); } if (!licence.getName().equals(dto.getName())) { Licence licence1 = this.baseMapper.selectOne(new LambdaQueryWrapper().eq(Licence::getName, dto.getName()).eq(Licence::getDelFlag, 0)); if (null != licence1) { throw new ServiceException("修改的许可证名称重复"); } } BeanUtils.copyProperties(dto, licence); String grand = String.join(";", dto.getGrandNameList());//多个以分号相隔 licence.setGradeName(grand); this.baseMapper.updateById(licence); } @Override public void delete(Integer id) { Licence licence = this.baseMapper.selectById(id); if (null == licence || licence.getDelFlag() != 0) { throw new ServiceException("该许可证不存在"); } licence.setDelFlag(1); this.baseMapper.updateById(licence); } }