import request from '@/utils/request'
import state from '@/store'
import router from '@/router'

// 查询人员总工工时
export function search1(num1, num2, num3, num4, num5) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_工时统计_查询数据2',
      param: '操作者_check=' + num1 + '&姓名=' + num2 + '&时间_check=' + num3 + '&开始时间=' + num4 + '&结束时间=' + num5
    }
  })
}
export function search2(num1, num2, num3, num4, num5) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_金工工时统计_查询数据',
      param: '操作者_check=' + num1 + '&姓名=' + num2 + '&时间_check=' + num3 + '&开始时间=' + num4 + '&结束时间=' + num5
    }
  })
}
export function searchPerson() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: `select distinct 姓名 from 车间生产管理工艺_工时查询_实际工时_视图 where 加工完成时间 is not null and 是否启用 = 1`
    }
  })
}
export function search4(num1, num2, num3) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_质检数据分析_查询数据',
      param: '时间_check=' + num1 + '&开始时间=' + num2 + '&结束时间=' + num3
    }
  })
}
export function search5(num1, num2) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: ` SELECT  CAST(SUM(CONVERT(float, 持续时间))/CONVERT(float, datediff(SECOND, '${num1}','${num2}')) as decimal(38, 2)) * 100 as 持续时间,工位号
              FROM [MES_机加工MES_设备数据采集_工位信息_历史数据表]
              where 日期 >= '${num1}' and 日期 <= '${num2}'
              group by 工位号`
    }
  })
}
export function getOPname() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: ` SELECT 设备号 from MES_工作站_设备状态表`
    }
  })
}
export function search6(num, ceck, num1, num2) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: ` SELECT CAST(SUM(CONVERT(float, 持续时间))/CONVERT(float, datediff(SECOND, '${num1}','${num2}')) as decimal(38, 2)) * 100 as 持续时间
              ,DATEPART(mm,日期) as 月份
              FROM [MES_机加工MES_设备数据采集_工位信息_历史数据表]
              where 持续时间 is not null and 工位号 = '${num}' and 日期 >= '${num1}' and 日期 <= '${num2}'
              group by DATEPART(mm,日期)`
    }
  })
}
