/*
 *    Copyright (c) 2018-2025, cyweb All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 */

import request from '/@/utils/request';

/**
 * 获取树形列表
 * @param query
 */
export const fetchTree = (query?: any) => {
	return request({
		url: '/basic/basicdept/tree',
		method: 'get',
		params: query,
	});
};

/**
 * 获取二级树形列表
 * @param query
 */
export const fetchSecondTree = (query?: any) => {
	return request({
		url: '/basic/basicdept/secondTree',
		method: 'get',
		params: query,
	});
};

/**
 * 获取开放部门树形列表
 * @param query
 */
export const fetchOpenDeptTree = (query?: any) => {
	return request({
		url: '/basic/basicdept/openDeptTree',
		method: 'get',
		params: query,
	});
};

/**
 * 获取级联选择器树形列表
 * @param query
 */
export const treeForCascader = (query?: any) => {
	return request({
		url: '/basic/basicdept/treeForCascader',
		method: 'get',
		params: query,
	});
};

/**
 * 获取培训树形列表
 * @param query
 */
export const treeForTrain = (query?: any) => {
	return request({
		url: '/basic/basicdept/treeForTrain',
		method: 'get',
		params: query,
	});
};

/**
 * 获取列表
 * @param query
 */
export const fetchList = (query?: any) => {
	return request({
		url: '/basic/basicdept/page',
		method: 'get',
		params: query,
	});
};

/**
 * 新增
 * @param obj
 */
export const addObj = (obj: any) => {
	return request({
		url: '/basic/basicdept',
		method: 'post',
		data: obj,
	});
};

/**
 * 获取详情
 * @param id
 */
export const getObj = (id: string | number) => {
	return request({
		url: `/basic/basicdept/${id}`,
		method: 'get',
	});
};

/**
 * 根据部门代码获取部门信息
 * @param code
 */
export const getDeptByCode = (code: string | number) => {
	return request({
		url: `/basic/basicdept/deptcode/${code}`,
		method: 'get',
	});
};

/**
 * 删除
 * @param id
 */
export const delObj = (id: string | number) => {
	return request({
		url: `/basic/basicdept/${id}`,
		method: 'delete',
	});
};

/**
 * 更新
 * @param obj
 */
export const putObj = (obj: any) => {
	return request({
		url: '/basic/basicdept',
		method: 'put',
		data: obj,
	});
};

/**
 * 根据部门代码获取培训部门
 * @param obj
 */
export const getTrainDeptByDeptCode = (obj: string | number) => {
	return request({
		url: `/basic/basicdept/getTrainDeptByDeptCode/${obj}`,
		method: 'get',
	});
};

/**
 * 获取教务开课部门
 */
export const getTeachDept = () => {
	return request({
		url: '/basic/basicdept/getDeptList?teachFlag=1',
		method: 'get',
	});
};

/**
 * 获取培训部门
 */
export const getTrainDept = () => {
	return request({
		url: '/basic/basicdept/getDeptList?trainFlag=1',
		method: 'get',
	});
};

/**
 * 获取合同起草部门 - 二级部门
 */
export const getDeptListByLevelTwo = () => {
	return request({
		url: '/basic/basicdept/getDeptListByLevelTwo',
		method: 'get',
	});
};

/**
 * 人事人员调动 - 二级联动查询子级部门列表
 * @param deptCode
 */
export const getDeptListByParent = (deptCode: string | number) => {
	return request({
		url: `/basic/basicdept/getDeptListByParent/${deptCode}`,
		method: 'get',
	});
};

/**
 * 获取带教师的部门列表
 * @param query
 */
export const getDeptWithTeacher = (query?: any) => {
	return request({
		url: '/basic/basicdept/getDeptWithTeacher',
		method: 'get',
		params: query,
	});
};

