huliguo
2025-06-05 0a492b64ca1a4e40cc9ea56eddd1afe2c09a12b3
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
67
68
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<LicenceMapper, Licence> implements LicenceService {
 
    @Override
    public IPage<LicencePageVO> getLicencePage(Integer pageNum, Integer pageSize, String name) {
        IPage<LicencePageVO> page=new Page<>(pageNum, pageSize);
        return this.baseMapper.getIndustryPage(page,name);
    }
 
    @Override
    public void add(AddLicenceDTO dto) {
        //判断是否存在
        Licence licence = this.baseMapper.selectOne(new LambdaQueryWrapper<Licence>().eq(Licence::getName, dto.getName()).eq(Licence::getDelFlag, 0));
        if (null == licence) {
            throw new ServiceException("许可证名称重复");
        }
 
        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<Licence>().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);
    }
}