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.Industry;
|
import com.ruoyi.system.mapper.IndustryMapper;
|
import com.ruoyi.system.pojo.dto.AddIndustryDTO;
|
import com.ruoyi.system.pojo.dto.EditIndustryDTO;
|
import com.ruoyi.system.pojo.vo.IndustryPageVO;
|
import com.ruoyi.system.service.IndustryService;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
|
@Service
|
public class IndustryServiceImpl extends ServiceImpl<IndustryMapper, Industry> implements IndustryService {
|
|
@Override
|
public IPage<IndustryPageVO> getIndustryPage(Integer pageNum, Integer pageSize, String name) {
|
IPage<IndustryPageVO> page=new Page<>(pageNum, pageSize);
|
return this.baseMapper.getIndustryPage(page,name);
|
}
|
|
@Override
|
public void add(AddIndustryDTO dto) {
|
//根据名称查看是否已存在
|
Industry industry = this.baseMapper.selectOne(new LambdaQueryWrapper<Industry>().eq(Industry::getName, dto.getName()).eq(Industry::getDelFlag, 0));
|
if(null !=industry && industry.getDelFlag() == 0){
|
throw new ServiceException("该行业已存在");
|
}
|
Industry industry1 = new Industry();
|
BeanUtils.copyProperties(dto, industry1);
|
this.baseMapper.insert(industry1);
|
}
|
|
@Override
|
public void edit(EditIndustryDTO dto) {
|
Industry industry = this.getById(dto.getId());
|
if (null ==industry || industry.getDelFlag() != 0){
|
throw new ServiceException("该行业不存在");
|
}
|
if (industry.getName().equals(dto.getName())) {
|
//修改名称
|
Industry byName = this.baseMapper.selectOne(new LambdaQueryWrapper<Industry>().eq(Industry::getName, dto.getName()).eq(Industry::getDelFlag, 0));
|
if(null != byName){
|
throw new ServiceException("该所属行业名称重复");
|
}
|
}
|
BeanUtils.copyProperties(dto, industry);
|
this.baseMapper.updateById(industry);
|
}
|
|
@Override
|
public void delete(Integer id) {
|
Industry industry = this.getById(id);
|
if (null == industry || industry.getDelFlag() != 0){
|
throw new ServiceException("该行业不存在");
|
}
|
industry.setDelFlag(1);
|
this.baseMapper.updateById(industry);
|
}
|
}
|