huliguo
2025-06-04 7e9508a252df668c3f7472be02595c79b21be11a
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
65
66
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<CompanyTypeMapper, CompanyType> implements CompanyTypeService {
 
    @Override
    public IPage<CompanyTypePageVO> getCompanyTypePage(Integer pageNum, Integer pageSize, String name) {
        IPage<CompanyTypePageVO> page=new Page<>(pageNum, pageSize);
        return this.baseMapper.getCompanyTypePage(page,name);
    }
 
    @Override
    public void add(AddCompanyTypeDTO dto) {
        //根据名称查看是否已存在
        CompanyType companyType = this.baseMapper.selectOne(new LambdaQueryWrapper<CompanyType>().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<CompanyType>().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);
    }
}