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.CompanyType; import com.ruoyi.system.mapper.CompanyTypeMapper; import com.ruoyi.system.pojo.dto.AddCompanyTypeDTO; import com.ruoyi.system.pojo.vo.CompanyTypePageVO; import com.ruoyi.system.pojo.dto.EditCompanyTypeDTO; import com.ruoyi.system.service.CompanyTypeService; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; @Service public class CompanyTypeServiceImpl extends ServiceImpl implements CompanyTypeService { @Override public IPage getCompanyTypePage(Integer pageNum, Integer pageSize, String name) { IPage page=new Page<>(pageNum, pageSize); return this.baseMapper.getCompanyTypePage(page,name); } @Override public void add(AddCompanyTypeDTO dto) { //根据名称查看是否已存在 CompanyType companyType = this.baseMapper.selectOne(new LambdaQueryWrapper().eq(CompanyType::getName, dto.getName()).eq(CompanyType::getDelFlag, 0)); if(null !=companyType){ throw new ServiceException("该类型已存在"); } CompanyType companyType1 = new CompanyType(); BeanUtils.copyProperties(dto,companyType1); this.baseMapper.insert(companyType1); } @Override public void edit(EditCompanyTypeDTO dto) { CompanyType companyType = this.getById(dto.getId()); if(null == companyType || companyType.getDelFlag() != 0){ throw new ServiceException("该类型不存在"); } if (!dto.getName().equals(companyType.getName())) { //修改了名称 //查看名称是否存在 CompanyType byName = this.baseMapper.selectOne(new LambdaQueryWrapper().eq(CompanyType::getName, dto.getName()).eq(CompanyType::getDelFlag, 0)); if(null != byName){ throw new ServiceException("该类型已存在"); } } BeanUtils.copyProperties(dto, companyType); this.baseMapper.updateById(companyType); } @Override public void delete(Integer id) { CompanyType companyType = this.getById(id); if(null == companyType || companyType.getDelFlag() != 0){ throw new ServiceException("该类型不存在"); } companyType.setDelFlag(1); this.baseMapper.updateById(companyType); } }