kongzy
2023-11-24 ebe94e19812a1b24257d60831ec932756855e94b
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.gkhy.assess.system.service.impl;
 
import cn.hutool.core.util.ObjectUtil;
import com.gkhy.assess.common.api.CommonPage;
import com.gkhy.assess.common.exception.ApiException;
import com.gkhy.assess.common.utils.PageUtil;
import com.gkhy.assess.system.domain.SysDictData;
import com.gkhy.assess.system.domain.SysDictType;
import com.gkhy.assess.system.domain.SysLaw;
import com.gkhy.assess.system.mapper.SysDictDataMapper;
import com.gkhy.assess.system.mapper.SysDictTypeMapper;
import com.gkhy.assess.system.service.SysDictTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * <p>
 * 字典类型表 服务实现类
 * </p>
 *
 * @author kzy
 * @since 2023-11-01 15:37:51
 */
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements SysDictTypeService {
    @Autowired
    private SysDictDataMapper dictDataMapper;
 
    @Override
    public CommonPage dictTypeList(SysDictType dictType) {
        PageUtil.startPage();
        List<SysDictType> dictList=baseMapper.dictTypeList(dictType);
        return CommonPage.restPage(dictList);
    }
 
    @Override
    public SysDictType getDictTypeById(Long dictId) {
        return baseMapper.getDictTypeById(dictId);
    }
 
    @Override
    public int addDictType(SysDictType dictType) {
        boolean b=save(dictType);
        if(!b){
            throw new ApiException("新增字典类型失败");
        }
        return 1;
    }
 
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int editDictType(SysDictType dict) {
        SysDictType oldDict= baseMapper.getDictTypeById(dict.getId());
        dictDataMapper.updateDictDataDictType(oldDict.getDictType(), dict.getDictType());
        boolean b=updateById(dict);
        if(!b){
            throw new ApiException("修改数据字典类型失败");
        }
        return 1;
    }
 
    @Override
    public int deleteDictTypeById(Long dictId) {
        SysDictType dictType=getDictTypeById(dictId);
        if(dictDataMapper.countDictDataByType(dictType.getDictType())>0){
            throw new ApiException(String.format("%1$s已分配,不能删除", dictType.getName()));
        }
        boolean b=removeById(dictId);
        if(!b){
            throw new ApiException("删除字典类型失败");
        }
        return 1;
    }
 
    @Override
    public int changeDictTypeStatus(SysDictType dictType) {
        boolean b=updateById(dictType);
        if(!b){
            throw new ApiException("修改数据字典类型失败");
        }
        return 1;
    }
 
    @Override
    public boolean checkDictTypeUnique(SysDictType dict) {
        Long dictId = ObjectUtil.isNull(dict.getId()) ? -1L : dict.getId();
        SysDictType dictType = baseMapper.checkDictTypeUnique(dict.getDictType());
        if (ObjectUtil.isNotNull(dictType) && dictType.getId().longValue() != dictId.longValue())
        {
            return false;
        }
        return true;
    }
 
    @Override
    public List<SysDictData> getDictDataByType(String dictType) {
        return dictDataMapper.getDictDataByType(dictType);
    }
 
    @Override
    public SysDictType getDictTypeByType(String dictType) {
        return baseMapper.getDictTypeByType(dictType);
    }
}