import http from '@/utils/request'

// 获取字典
export function dataFactoryDictList (params) {
  return http.post('/pipeline/production/line/list', params)
  // return http.post('/dataFactory/dict/list', params)
}

/** ================================= 数据源 START ==================================================== */
// 获取数据源列表
export function getSourcePage (params) {
  return http.post('/dataFactory/data/source/config/page', params)
}

// 数据源管理 查看详情
export function sourceDetail (params) {
  return http.post('/dataFactory/data/source/config/detail', params)
}

// 数据源管理 查看详情
export function sourceConfigTest (params) {
  return http.post('/dataFactory/data/source/config/test', params)
}

// 数据源管理 新增
export function sourceAdd (params) {
  return http.post('/dataFactory/data/source/config/add', params)
}

// 数据源管理 更新
export function sourceUpdate (params) {
  return http.post('/dataFactory/data/source/config/update', params)
}

// 数据源管理 更新
export function sourceDelete (params) {
  return http.post('/dataFactory/data/source/config/del', params)
}

/** ================================= 数据源 END ==================================================== */

/** ================================= 任务监控 START ==================================================== */
// ============= 数据接入 ================ //
// 获取列表
export function getMonitorAccessPage (params) {
  return http.post('/dataFactory/task/monitor/data/access/page', params)
}

// ============= 数据加工 ================ //
export function getMonitorProcessingPage (params) {
  return http.post('/dataFactory/task/monitor/data/processing/page', params)
}

// ============= 数据集成 ================ //
export function getMonitorIntegrationPage (params) {
  return http.post('/dataFactory/task/monitor/data/integration/page', params)
}

// ============= 公用 查看日志 ================ //
export function getLastLog (params) {
  return http.post('/dataFactory/task/log/get/last', params)
}

// ============= 公用 分页查询 ================ //
export function getLogPage (params) {
  return http.post('/dataFactory/task/log/page', params)
}

// ============= 数据加工 运行 ================ //
export function runMonitor (params) {
  return http.post('/dataFactory/task/monitor/data/access/start', params)
}

// ============= 数据接入 运行 ================ //
export function runProcess (params) {
  return http.post('/dataFactory/task/monitor/data/processing/start', params)
}

// ============= 数据集成 运行 ================ //
export function runIntegration (params) {
  return http.post('/dataFactory/task/monitor/data/integration/start', params)
}

/** ================================= 任务监控 END ==================================================== */

/** ================================= 任务管理 START ==================================================== */

// ============= 数据接入 ================ //
// 分页数据
export function getAccessPage (params) {
  return http.post('/dataFactory/data/access/page', params)
}

// 获取文件夹
export function getFileDirectory (params) {
  return http.post('dataFactory/file/directory', params)
}

// 获取excel工作簿列表
export function excelSheetList (params) {
  return http.post('dataFactory/file/get/excel/sheet/list', params)
}

// excel文件上传
export function excelHead (params) {
  return http.formData('dataFactory/file/get/excel/head', params)
}

// 更新excel标题
export function updateExcelHead (params) {
  return http.post('dataFactory/file/update/excel/head', params)
}
// 新增
export function addAccess (params) {
  return http.post('/dataFactory/data/access/add', params)
}
// 详情
export function getAccessDetail (params) {
  return http.post('/dataFactory/data/access/detail', params)
}
// 修改
export function updateAccess (params) {
  return http.post('/dataFactory/data/access/update', params)
}
// 删除
export function deleteAccess (params) {
  return http.post('/dataFactory/data/access/del', params)
}

// 备份
export function accessBackup () {
  return http.download('/dataFactory/data/access/backup')
}

// 备份
export function accessRestore (params) {
  return http.upload('/dataFactory/data/access/restore', params)
}

// ============= 数据加工 ================ //
// 增
export function addProcessing (params) {
  return http.post('/dataFactory/data/processing/add', params)
}
// 删
export function deleteProcessing (params) {
  return http.post('/dataFactory/data/processing/del', params)
}
// 改
export function updateProcessing (params) {
  return http.post('/dataFactory/data/processing/update', params)
}
// 查 详细
export function getProcessingDetail (params) {
  return http.post('/dataFactory/data/processing/detail', params)
}
// 查 分页数据
export function getProcessingPage (params) {
  return http.post('/dataFactory/data/processing/page', params)
}

// 加工绩效数据
export function processDataAll (params) {
  return http.post('/dataFactory/tmp/process/data/all', params)
}
// 加工按钮1
export function processData1 (params) {
  return http.post('/dataFactory/tmp/process/data1', params)
}
// 加工按钮2
export function processData2 (params) {
  return http.post('/dataFactory/tmp/process/data2', params)
}
// 加工按钮5
export function processData5 (params) {
  return http.post('/dataFactory/tmp/process/sql/data5', params)
}
// 数据源列表
export function sourceList (params) {
  return http.post('/dataFactory/data/source/config/list', params)
}

// 预览sql
export function previewSql (params) {
  return http.post('/dataFactory/custom/processing/preview/sql', params)
}
// 获取历史数据
export function getHistory (params) {
  return http.post('/dataFactory/platform/data/processing/history/page', params)
}
// 备份
export function processingBackup () {
  return http.download('/dataFactory/data/processing/backup')
}

// 备份
export function processingRestore (params) {
  return http.upload('/dataFactory/data/processing/restore', params)
}

// 解锁
export function taskMonitorUnlock (params) {
  return http.post('/dataFactory/task/monitor/unlock', params)
}

// ============= 数据集成 ================ //
// 列表
export function getIntegration (params) {
  return http.post('/dataFactory/platform/data/integration/page', params)
}

// 新增
export function addIntegration (params) {
  return http.post('/dataFactory/platform/data/integration/add', params)
}

// 修改
export function updateIntegration (params) {
  return http.post('/dataFactory/platform/data/integration/update', params)
}

// 删除
export function deleteIntegration (params) {
  return http.post('/dataFactory/platform/data/integration/del', params)
}

// 查询
export function findIntegration (params) {
  return http.post('/dataFactory/platform/data/integration/detail', params)
}

// 备份
export function integrationBackup () {
  return http.download('/dataFactory/platform/data/integration/backup')
}

// 还原
export function integrationRestore (params) {
  return http.upload('/dataFactory/platform/data/integration/restore', params)
}

// ============= 查询元数据组合 ================ //
export function getCombinationPage (params) {
  return http.post('/dataFactory/meta/data/combination/page', params)
}

/** ================================= 任务管理 END ==================================================== */

// 生成亲属关系
export function familyMakeAtlas () {
  return http.post('/family/make/atlas')
}

/** ================================= 任务组管理 START ==================================================== */

// 任务组 列表查询
export function taskGroupList (params) {
  return http.post('/dataFactory/platform/task/group/list', params)
}

// 任务组 分页查询
export function taskGroupPage (params) {
  return http.post('/dataFactory/platform/task/group/page', params)
}

// 任务组 新增
export function taskGroupAdd (params) {
  return http.post('/dataFactory/platform/task/group/add', params)
}

// 任务组 更新
export function taskGroupUpdate (params) {
  return http.post('/dataFactory/platform/task/group/update', params)
}

// 获取任务名称
export function getTaskName (params) {
  return http.post('/dataFactory/task/monitor/queryTaskNameMapByIdList', params)
}

// 根据任务id集合查询数据域id
export function queryTaskProductIdMapByIdList (params) {
  return http.post('/dataFactory/task/monitor/queryTaskProductIdMapByIdList', params)
}

// 删除任务组
export function taskGroupDelete (params) {
  return http.post('/dataFactory/platform/task/group/del', params)
}

// 任务组备份
export function groupBackup () {
  return http.download('/dataFactory/platform/task/group/backup')
}

// 任务组备份
export function groupRestore (params) {
  return http.upload('/dataFactory/platform/task/group/restore', params)
}

/**
 * 加工 运行 任务组
 * @param {*} params {mark: ''}
 * @returns
 */
export function taskGroupRun (params) {
  return http.post('/dataFactory/platform/task/group/run', params)
}

// 绩效计算-加工历史记录
export function platformTaskGroupLogList (params) {
  return http.post('/dataFactory/platform/task/group/log/page', params)
}

// 获取绩效文件清单
export function getFileDetail (params) {
  return http.post('/dataFactory/data/task/file/detail', params)
}

// 检查绩效文件是否已经齐全,并且为加工准备数据
export function checkFile (params) {
  return http.post('/dataFactory/data/task/file/check', params)
}

// 查询绩效文件清单(checkFile1为必传文件)
export function checkSettingFile (params) {
  return http.post('/dataFactory/performance/setting/files', params)
}

// 上传数据接入文件
export function fileUpload (params) {
  return http.formData('/dataFactory/data/task/file/upload', params)
}

// 检查是否存在未操作的月份,不包含即将启动任务的月份
export function checkDistribution (params) {
  return http.post('/digitizationData/institutional/performance/distribution/check', params)
}

/** ================================= 生产线 START ==================================================== */
// 分页查询
export function productionLinePage (params) {
  return http.post('/dataFactory/platform/production/line/info/page', params)
}
// 列表查询
export function productionLineList (params) {
  return http.post('/dataFactory/platform/production/line/info/list', params)
}
// 新增
export function productionLineAdd (params) {
  return http.post('/dataFactory/platform/production/line/info/add', params)
}
// 删除
export function productionLineDelete (params) {
  return http.post('/dataFactory/platform/production/line/info/del', params)
}
// 修改
export function productionLineUpdate (params) {
  return http.post('/dataFactory/platform/production/line/info/update', params)
}
// 查询
export function productionLineDetail (params) {
  return http.post('/dataFactory/platform/production/line/info/detail', params)
}

// 读取文件
export function readFile (params) {
  return http.download('/dataFactory/file/read', params)
}

// 节点分页查询
export function getNodeList (params) {
  return http.post('/dataFactory/platform/production/line/node/list', params)
}

// 节点分页查询
export function getNodePage (params) {
  return http.post('/dataFactory/platform/production/line/node/page', params)
}

// 节点查询
export function getNodePageDetail (params) {
  return http.post('/dataFactory/platform/production/line/node/detail', params)
}

// 节点新增
export function addNode (params) {
  return http.post('/dataFactory/platform/production/line/node/add', params)
}

// 节点删除
export function deleteNode (params) {
  return http.post('/dataFactory/platform/production/line/node/del', params)
}

// 节点修改
export function updateNode (params) {
  return http.post('/dataFactory/platform/production/line/node/update', params)
}

// V2

// 分页查询
export function productionLineBasePage (params) {
  return http.post('/dataFactory/platform/production/line/base/info/page', params)
}

// 列表查询
export function productionLineBaseList (params) {
  return http.post('/dataFactory/platform/production/line/base/info/list', params)
}

// 新增
export function productionLineBaseAdd (params) {
  return http.post('/dataFactory/platform/production/line/base/info/add', params)
}

// 删除
export function productionLineBaseDelete (params) {
  return http.post('/dataFactory/platform/production/line/base/info/del', params)
}

// 修改
export function productionLineBaseUpdate (params) {
  return http.post('/dataFactory/platform/production/line/base/info/update', params)
}

// 查询
export function productionLineBaseDetail (params) {
  return http.post('/dataFactory/platform/production/line/base/info/detail', params)
}

// 设置调度
export function productionLineBaseDispatch (params) {
  return http.post('/dataFactory/platform/production/line/base/info/dispatch', params)
}

// 启动
export function productionLineBaseStart (params) {
  return http.post('/dataFactory/platform/production/line/base/info/start', params)
}

// 停止
export function productionLineBaseStop (params) {
  return http.post('/dataFactory/platform/production/line/base/info/stop', params)
}

// 解锁任务
export function productionLineBaseUnlock (params) {
  return http.post('/dataFactory/platform/production/line/base/info/unlock', params)
}

// 标记模板
export function productionLineBaseTemplate (params) {
  return http.post('/dataFactory/platform/production/line/base/info/mark/template', params)
}

// 生产线最近一条日志
export function productionLineLog (params) {
  return http.post('/dataFactory/platform/production/line/log/get/last', params)
}

// 生产线日志
export function productionLineLogDetail (params) {
  return http.post('/dataFactory/platform/production/line/log/detail', params)
}

// 生产线监控
export function productionLineLogPage (params) {
  return http.post('/dataFactory/platform/production/line/log/page', params)
}

/** ================================= 生产线 END ==================================================== */
/** ================================= 生产线 监控 START ==================================================== */
// 生产线监控 数量
export function productionLineMonitor (data) {
  return http.get('/dags/exec-results', data)
  // return http.post('/dataFactory/platform/production/line/monitor/statistics', params)
}

// 生产线钻取
export function getProductionLineList (params) {
  return http.post('/dags/exec-results/all', params)
}

// 生产线 常规状态钻取
export function getProductionLineTasks (params) {
  return http.post('/dags/exec-results/tasks', params)
}

// 生产线 未调度钻取
export function getProductionLineUnscheduled () {
  return http.get('/dags/unscheduled-scripts')
}

// 生产线 钻取日志
export function getProductionLineTasksLogs (params) {
  return http.post('/dags/exec-results/task-logs', params)
}
/** ================================= 生产线 监控 END ==================================================== */

/** ================================= n8n 工作流管理 START ==================================================== */
// 获取工作流列表
export function getWorkflows (params) {
  return http.get('/datafactory/workflows', params)
}

// 获取工作流详情
export function getWorkflow (workflowId) {
  return http.get(`/datafactory/workflows/${workflowId}`)
}

// 获取工作流状态
export function getWorkflowStatus (workflowId) {
  return http.get(`/datafactory/workflows/${workflowId}/status`)
}

// 激活工作流
export function activateWorkflow (workflowId) {
  return http.post(`/datafactory/workflows/${workflowId}/activate`)
}

// 停用工作流
export function deactivateWorkflow (workflowId) {
  return http.post(`/datafactory/workflows/${workflowId}/deactivate`)
}

// 获取工作流执行记录列表
export function getWorkflowExecutions (workflowId, params) {
  return http.get(`/datafactory/workflows/${workflowId}/executions`, params)
}

// 获取所有执行记录列表
export function getAllExecutions (params) {
  return http.get('/datafactory/executions', params)
}

// 获取执行详情
export function getExecution (executionId) {
  return http.get(`/datafactory/executions/${executionId}`)
}

// 触发工作流执行
export function triggerWorkflow (workflowId, data) {
  return http.post(`/datafactory/workflows/${workflowId}/execute`, data)
}

// 健康检查
export function healthCheck () {
  return http.get('/datafactory/health')
}
/** ================================= n8n 工作流管理 END ==================================================== */
