package com.gkhy.safePlatform.account.service.baseService.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfo;
|
import com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfoDO;
|
import com.gkhy.safePlatform.account.enums.DepartmentStatusEnum;
|
import com.gkhy.safePlatform.account.repository.DepartmentInfoRepository;
|
import com.gkhy.safePlatform.account.service.baseService.DepartmentInfoService;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.exception.BusinessException;
|
import com.gkhy.safePlatform.commons.utils.StringUtils;
|
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
@Service("departmentInfoService")
|
public class DepartmentInfoServiceImpl extends ServiceImpl<DepartmentInfoRepository, DepartmentInfo> implements DepartmentInfoService {
|
|
@Autowired
|
private DepartmentInfoRepository departmentInfoRepository;
|
|
@Override
|
public List<DepartmentInfoDO> getDepartmentByStatus(DepartmentStatusEnum status) {
|
return departmentInfoRepository.getDepartmentListByStatus(status.getCode());
|
}
|
|
@Override
|
public boolean departmentExist(Long id) {
|
if (id == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
long count = this.count(new LambdaQueryWrapper<DepartmentInfo>().eq(DepartmentInfo::getId, id));
|
return count > 0;
|
}
|
|
|
@Override
|
public void saveDepartmentInfo(DepartmentInfo departmentInfo) {
|
int i = departmentInfoRepository.insertDepartmentInfo(departmentInfo);
|
if (i != 1) {
|
throw new BusinessException(ResultCodes.SERVER_ADD_ERROR);
|
}
|
}
|
|
@Override
|
public DepartmentInfo getDepartmentInfoById(Long id) {
|
if (id == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
return departmentInfoRepository.getDepartmentInfoById(id);
|
}
|
|
@Override
|
public DepartmentInfoDO getDepartmentInfoDOById(Long id) {
|
if (id == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
return departmentInfoRepository.getDepartmentInfoDOById(id);
|
}
|
|
@Override
|
public List<DepartmentInfoDO> getDepartmentByParentId(Long parentId) {
|
// id = null 有意义 查询根目录所有菜单
|
return departmentInfoRepository.listDepartmentByParentId(parentId);
|
}
|
|
@Override
|
public void updateDepartmentInfo(DepartmentInfo departmentInfo) {
|
if (departmentInfo == null || departmentInfo.getId() == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
int i = departmentInfoRepository.updateDepartmentInfo(departmentInfo);
|
if (i == 0) {
|
throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
|
}
|
if (i > 1) {
|
throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
|
}
|
}
|
|
@Override
|
public long countByParentDepId(Long depId) {
|
if (depId == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
return departmentInfoRepository.selectCount(new LambdaQueryWrapper<DepartmentInfo>()
|
.eq(DepartmentInfo::getParentId,depId)
|
.eq(DepartmentInfo::getStatus,DepartmentStatusEnum.ENABLED.getCode()));
|
}
|
|
@Override
|
public DepartmentInfoDO getParentDepartmentInfoDOByDepId(Long depId) {
|
if (depId == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
return departmentInfoRepository.getParentDepartmentInfoDOByDepId(depId);
|
}
|
|
@Override
|
public DepartmentInfo getDepartmentInfoByName(String name) {
|
if (StringUtils.isBlank(name)) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
List<DepartmentInfo> departmentInfos = departmentInfoRepository.selectList(new LambdaQueryWrapper<DepartmentInfo>()
|
.eq(DepartmentInfo::getName, name)
|
.eq(DepartmentInfo::getStatus, DepartmentStatusEnum.ENABLED.getCode()));
|
if (departmentInfos.size() == 0) {
|
return null;
|
}
|
if (departmentInfos.size() > 1) {
|
throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED);
|
}
|
return departmentInfos.get(0);
|
}
|
|
|
@Override
|
public List<Long> listSubDepIdsByParentId(Long depId) {
|
if (depId == null) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
return departmentInfoRepository.listSubDepIdsByParentId(depId);
|
}
|
|
|
@Override
|
public DepartmentInfo getDepartmentInfoByCode(String depCode) {
|
if (StringUtils.isBlank(depCode)) {
|
throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
}
|
List<DepartmentInfo> departmentInfos = departmentInfoRepository.selectList(new LambdaQueryWrapper<DepartmentInfo>()
|
.eq(DepartmentInfo::getCode, depCode)
|
.eq(DepartmentInfo::getStatus, DepartmentStatusEnum.ENABLED.getCode()));
|
if (departmentInfos.size() == 0) {
|
return null;
|
}
|
if (departmentInfos.size() > 1) {
|
throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED);
|
}
|
return departmentInfos.get(0);
|
}
|
|
|
|
|
}
|