import request from '@/config/axios'
import {ItemRequisitionVO} from "@/api/mes/itemrequisition";

// 生产计划 VO
export interface PlanVO {
  id: number // ID
  code: string // 计划编码
  productId: number // 产品ID
  taskDetailId: number // 任务单明细ID
  taskId: number // 任务单ID
  productName: number // 产品
  taskCode: number // 任务单
  planNumber: number // 数量
  reyaNumber: number // 数量
  finishNumber: number // 成品数量
  status: number // 状态
  planStartTime: Date // 计划开始时间
  planEndTime: Date // 计划结束时间
  startTime: Date // 实际开始时间
  endTime: Date // 实际结束时间
  productionManagerId: number // 生产主管ID
  productionManager: number // 生产主管
  remark: string // 备注
  isEnable: boolean // 是否启用
  feedingPipeline: number //制浆线
  feedingPipelineName: string
  wangongNumber: number
  passRate: number
}

// 生产计划 API
export const PlanApi = {
  // 查询生产计划分页
  getPlanPage: async (params: any) => {
    return await request.get({ url: `/mes/plan/page`, params })
  },

  // 查询生产计划详情
  getPlan: async (id: number) => {
    return await request.get({ url: `/mes/plan/get?id=` + id })
  },

  // 新增生产计划
  createPlan: async (data: PlanVO) => {
    return await request.post({ url: `/mes/plan/create`, data })
  },

  // 修改生产计划
  updatePlan: async (data: PlanVO) => {
    return await request.put({ url: `/mes/plan/update`, data })
  },

  // 删除生产计划
  deletePlan: async (id: number) => {
    return await request.delete({ url: `/mes/plan/delete?id=` + id })
  },

  // 导出生产计划 Excel
  exportPlan: async (params) => {
    return await request.download({ url: `/mes/plan/export-excel`, params })
  },
  // 批量新增生产计划
  saveBatchPlan: async (data: any) => {
    return await request.post({ url: `/mes/plan/saveBatchPlan`, data })
  },
  // 派工生产计划
  arrangePlan: async (data: ItemRequisitionVO) => {
    return await request.put({ url: `/mes/plan/paigong`, data })
  },
  // 派工生产计划
  arrangePlanNum: async (data: ItemRequisitionVO) => {
    return await request.put({ url: `/mes/plan/typePaigong`, data })
  },
  // 更新状态生产计划
  updatePlanStatus: async (data: PlanVO) => {
    return await request.put({ url: `/mes/plan/updateStatus`, data })
  },
  // 查询正在开工和完工的计划的产品列表
  getStartAndFinishPlanProduct: async () => {
    return await request.get({ url: `/mes/plan/getProductByStatus` })
  },
  // 查询正在开工和完工的计划的产品列表
  getStartPlanProduct: async (orgType) => {
    return await request.get({ url: `/mes/app/org-worker/getPlanProductList?orgType=`+orgType })
  },
  // 更新质检状态生产计划
  updatePlanZjStatus: async (data: PlanVO) => {
    return await request.put({ url: `/mes/plan/updatePlanZjStatus`, data })
  },
  // 根据状态查询生产计划详情
  getPlanByStatus: async (status: number) => {
    return await request.get({ url: `/mes/plan/getByStatus?status=` + status })
  },

  // 根据质检类型查询生产计划
  getPlanByTicketType: async (status: number) => {
    return await request.get({ url: `/mes/plan/getByTicketType?status=` + status })
  },
      // 产线任务看板
  getProductPlans: async (params?: any) => {
    return await request.get({ url: `/mes/plan/getProductPlans`, params })
  },
      // 周生产趋势
  getWeekTrend: async (params?: any) => {
    return await request.get({ url: `/mes/plan/getWeekTrend`, params })
  },
  getPlanCapacity: async (type: number, orgId?: any) => {
    let url = `/mes/plan/getPlanCapacity?type=` + type
    if (orgId) {
      url += `&orgId=` + orgId
    }
    return await request.get({ url })
  },
  getLastDaysRate: async (params?: any) => {
    return await request.get({ url: `/mes/plan/getLastDaysRate`, params })
  },
	getLastSevenDaysCompletedCount: async (params?: any) => {
		return await request.get({ url: `/mes/plan/getLastSevenDaysCompletedCount`, params })
  }
}
