huliguo
2025-05-28 340a6a4ba1297249af7f03c0974818bb5baae497
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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);
    }
}