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 com.gkhy.assess.system.utils.ShiroUtils;
|
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());
|
dict.setDictType(oldDict.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) {
|
SysDictType dt=new SysDictType().setId(dictType.getId()).setDictType(dictType.getDictType());
|
dt.setUpdateBy(ShiroUtils.getSysUser().getUsername());
|
return baseMapper.updateById(dt);
|
}
|
|
@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);
|
}
|
}
|