源代码
import com.example.entity.Department;
import com.example.mapper.DepartmentMapper;
import com.example.request.DelDepartmentPermissionRequest;
import com.example.response.DelDepartmentPermissionResponse;
import com.example.service.DepartmentPermissionService;
import com.example.utils.RespUtils;
import com.example.exception.TitanException;
import com.example.enums.ErrorCodeEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class DepartmentServiceImpl {
@Autowired
private DepartmentMapper departmentMapper;
@Autowired
private DepartmentPermissionService permissionService;
@Transactional(rollbackFor = Exception.class)
@Override
public DelDepartmentPermissionResponse deleteDepartmentPermission(DelDepartmentPermissionRequest request) {
DelDepartmentPermissionResponse response = new DelDepartmentPermissionResponse();
// 参数校验
if (StringUtils.isEmpty(request.getDepartmentId()) ||CollectionUtils.isEmpty(request.getIndexPatternNameList())) {
log.error("删除团队关联索引请求参数为空");
throw new TitanException("所传参数为空!");
}
// 获取部门信息
Department department = getDepartmentById(request.getDepartmentId());
if (department == null) {
RespUtils.setError(ErrorCodeEnum.DEPARTMENT_NOT_FOUND, response);
return response;
}
// 删除权限
List
permissionService.deletePermissionForDepartment(department.getDepartmentId(), indexIdList);
// 设置成功响应
RespUtils.setSuccess(response);
return response;
}