/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2025-06-10 12:15:25
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2025-07-04 16:14:15
 * @FilePath: /pfmBackMana/src/pages/checkUnitMana/service.ts
 * @Description: 查核单位管理服务
 */

import { request } from 'umi';

// 获取部门树
export async function getDeptTree(params?: any) {
  return request('/api/dept/tree', {
    method: 'GET',
    params,
  });
}

// 获取部门详情
export async function getDeptDetail(id: string) {
  return request(`/api/dept/${id}`, {
    method: 'GET',
  });
}

// 获取部门人员列表
export async function getDeptPersonnel(params: any) {
  return request('/api/dept/personnel', {
    method: 'GET',
    params,
  });
}

// 获取查核单位人员列表
export async function getDeptEmployee(params: {
  deptId: number;
  filter?: string;
  deptType?: number;
}) {
  return request('/manager/Department/getDeptEmployee', {
    method: 'GET',
    params,
  });
}

// 获取可选择的待添加人员列表
export async function getDeptPendingEmployee(params: {
  deptId: number;
  filter?: string;
  deptType?: number;
}) {
  return request('/manager/Department/getDeptPendingEmployee', {
    method: 'GET',
    params,
  });
}

// 添加部门人员
export async function addDeptPersonnel(data: any) {
  return request('/api/dept/personnel', {
    method: 'POST',
    data,
  });
}

// 删除部门人员
export async function deleteDeptPersonnel(id: string) {
  return request(`/api/dept/personnel/${id}`, {
    method: 'DELETE',
  });
}

// 设置部门负责人
export async function setDeptManager(data: {
  empId: number;
  empName: string;
  deptId: number;
  deptType: number;
}) {
  return request('/manager/Department/setDeptManager', {
    method: 'POST',
    data,
  });
}

// 获取部门责任事项
export async function getDeptResponsibilities(params: any) {
  return request('/api/dept/responsibilities', {
    method: 'GET',
    params,
  });
}

// 获取单位分类列表
export async function getDeptClassList(params?: any) {
  return request('/manager/Department/getDeptClassList', {
    method: 'GET',
    params,
  });
}

// 获取单位分类树
export async function getDeptClassTree(params?: any) {
  return request('/manager/Department/getDeptClassTree', {
    method: 'GET',
    params,
  });
}

// 新增单位分类
export async function addDeptClass(data: { name: string; depType: number }) {
  return request('/manager/Department/addDeptClass', {
    method: 'POST',
    data,
  });
}

// 修改单位分类
export async function updateDeptClass(data: {
  id: number;
  name: string;
  depType: number;
}) {
  return request('/manager/Department/updateDeptClass', {
    method: 'POST',
    data,
  });
}

// 删除单位分类
export async function delDeptClass(data: number[]) {
  return request('/manager/Department/delDeptClass', {
    method: 'POST',
    data,
  });
}

// 新增查核单位
export async function addDepartmentByClass(data: {
  deptClassId: string;
  name: string;
  sort: number;
  deptType: number;
}) {
  return request('/manager/Department/addDepartmentByClass', {
    method: 'POST',
    data,
  });
}

// 修改查核单位
export async function updateDepartmentByClass(data: {
  deptClassId: number;
  id: number;
  name: string;
  sort: number;
  deptType: number;
}) {
  return request('/manager/Department/updateDepartmentByClass', {
    method: 'POST',
    data,
  });
}

// 删除查核单位
export async function delDepartmentByClass(params: {
  deptId: number;
  deptType: number;
}) {
  return request('/manager/Department/delDepartmentByClass', {
    method: 'POST',
    params,
  });
}

// 获取条件列表
export async function getDeptClassFilterConditionList(params: {
  deptClassId?: string;
  conditionType?: number;
  filter?: string;
}) {
  return request('/manager/Department/getDeptclassFilterConditionList', {
    method: 'GET',
    params,
  });
}

// 保存查核条件
export async function applyDeptClassFilterCondition(data: {
  id: string;
  mapIdList: string[];
}) {
  return request('/manager/Department/applyDeptclassFilterCondition', {
    method: 'POST',
    data,
  });
}

// 添加部门人员
export async function addDeptEmployee(data: {
  id: string; // 查核单位ID
  type: string; // 单位类型：0普通单位1职能科室
  mapIdList: string[]; // 人员ID列表
}) {
  return request('/manager/Department/addDeptEmployee', {
    method: 'POST',
    data,
  });
}

// 删除单位人员
export async function delDeptEmp(data: { id: string; type: string }[]) {
  return request('/manager/Department/delDeptEmp', {
    method: 'POST',
    data,
  });
}

// 获取可选择的查核要点列表
export async function getDeptPendingCheckpoint(params: {
  deptId: number | string;
  filter?: string;
  deptType?: number;
}) {
  return request('/manager/Department/getDeptPendingCheckpoint', {
    method: 'GET',
    params,
  });
}

// 获取查核要点列表
export async function getDeptCheckpoint(params: {
  deptId: number | string;
  filter?: string;
  deptType?: number;
}) {
  return request('/manager/Department/getDeptCheckpoint', {
    method: 'GET',
    params,
  });
}

// 添加查核要点
export async function addDeptCheckpoint(data: {
  id: string;
  type: string;
  mapIdList: string[];
}) {
  return request('/manager/Department/addDeptCheckpoint', {
    method: 'POST',
    data,
  });
}

// 删除查核要点
export async function delDeptCheckpoint(data: (string | number)[]) {
  return request('/manager/Department/delDeptCheckpoint', {
    method: 'POST',
    data,
  });
}
