import request from '@/config/axios'

// 设备台账 VO
export interface IotDeviceVO {
  id: number // 主键id
  totalRunTime: number // 累计运行时长H
  totalMileage: number // 累计运行里程KM
  multiAttrsTotalMileage: Record<string, number> // 多属性累计运行里程KM
  multiAttrsTotalRuntime: Record<string, number> // 多属性累计运行时长H
  deviceCode: string // 资产编码
  deviceName: string // 设备名称
  brand: number // 品牌
  model: number // 规格型号
  deptId: number // 所在部门id
  deptName: string // 所在部门名称
  deviceStatus: string // 设备状态
  deviceStatusName: string // 设备状态名称
  assetProperty: string // 资产性质
  picUrl: string // 图片
  remark: string // 备注
  manufacturerId: number // 制造商id
  supplierId: number // 供应商id
  manDate: Date // 生产日期
  nameplate: string // 铭牌信息
  expires: number // 质保到期
  plPrice: number // 采购/租赁价格
  plDate: Date // 采购/租赁日期
  plYear: number // 折旧年限
  plStartDate: number // 折旧开始日期
  plMonthed: number // 已提折旧月数
  plAmounted: number // 已提折旧金额
  remainAmount: number // 剩余金额
  infoId: number // 资料分类id
  infoType: string // 资料类型
  infoName: string // 资料名称
  infoRemark: string // 资料备注
  infoUrl: string // 资料附件
  templateJson: string // 动态模板信息
  bomNodeId: number // bom节点id
  name: string // bom节点名称
  code: string // bom节点编码
  devicePersons: string // 设备责任人 逗号分隔
  location: string
  lat: number
  lng: number
  hasSetMaintenanceBom: boolean // 当前设备是否已经配置了保养BOM
  shouldWorkOrder: boolean // 当前设备根据保养规则应当生成保养工单
  runningWorkOrder: boolean // 当前设备是否已经有待执行的保养工单
}

// 设备台账 API
export const IotDeviceApi = {
  saveMaxMin: async (data: any) => {
    return await request.post({ url: `rq/iot-alarm-setting/save`, data })
  },
  getToken: async () => {
    return await request.get({ url: `/rq/iot-device/yf/token` })
  },
  deleteMaxMin: async (params: any) => {
    return await request.delete({ url: `rq/iot-alarm-setting/delete`, params })
  },
  getCompany: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/company?id=` + params })
  },
  getDevice: async (params: any) => {
    return await request.get({ url: `rq/iot-device/ly/device`, params })
  },
  getCompanyByDevice: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/company/` + params })
  },
  getMaxCode: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/max?yfCode=` + params })
  },
  getMapDevice: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/map`, params })
  },
  getAllDeviceParams: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/all/params`, params })
  },
  // 查询设备台账分页
  getIotDevicePage: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/page`, params })
  },

  getPlanDevicePage: async (params: any) => {
    return await request.get({ url: `/rq/iot-opeation-fill/planDevPage`, params })
  },

  // 获得设备关联责任人 分页
  responsiblePage: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/responsiblePage`, params })
  },

  // 获得设备动态 分页
  deviceDynamicsPage: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/deviceDynamicsPage`, params })
  },

  // 获得设备状态调整数据 分页
  statusRelationDevices: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/statusRelationDevices`, params })
  },

  // 获得设备调拨数据 分页
  allotRelationDevices: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/allotRelationDevices`, params })
  },

  // 获得设备关联责任人 分页
  simpleDevices: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/simple-list`, params })
  },

  // 查询 设备bom关联 列表分页
  deviceAssociateBomPage: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/deviceAssociateBomPage`, params })
  },

  // 项目-任务 根据选择的部门筛选设备 忽略数据权限
  getDevicesByDepts: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/getDevicesByDepts`, params })
  },

  // 查询 设备 bom关联 列表
  deviceAssociateBomList: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/deviceAssociateBomList`, params })
  },
  deviceAssociateBomListPage: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/deviceAssociateBomListPage`, params })
  },
  // 查询设备台账详情
  getIotDevice: async (id: number) => {
    return await request.get({ url: `/rq/iot-device/get?id=` + id })
  },

  getIotDeviceTds: async (id: number) => {
    return await request.get({ url: `/rq/iot-device/get/gateway/td?id=` + id })
  },
  getIotDeviceZHBDTds: async (id: number) => {
    return await request.get({ url: `/rq/iot-device/get/zhbd/td?id=` + id })
  },
  // 新增设备台账
  createIotDevice: async (data: IotDeviceVO) => {
    return await request.post({ url: `/rq/iot-device/create`, data })
  },
  createLyDevice: async (data: any) => {
    return await request.post({ url: `/rq/ly-device/create`, data })
  },

  // 保存 设备-状态 的关联关系
  saveDeviceStatuses: async (data: any) => {
    return await request.post({ url: `/rq/iot-device/saveDeviceStatuses`, data })
  },

  // 保存 设备调拨记录
  saveDeviceAllot: async (data: any) => {
    return await request.post({ url: `/rq/iot-device/saveDeviceAllot`, data })
  },

  // 修改设备台账
  updateIotDevice: async (data: IotDeviceVO) => {
    return await request.put({ url: `/rq/iot-device/update`, data })
  },

  // 删除设备台账
  deleteIotDevice: async (id: number) => {
    return await request.delete({ url: `/rq/iot-device/delete?id=` + id })
  },

  // 导出设备台账 Excel
  exportIotDevice: async (params) => {
    return await request.download({ url: `/rq/iot-device/export-excel`, params })
  },

  exportIotDeviceAdjust: async (params) => {
    return await request.download({ url: `/pms/iot-device-status-log/export-excel`, params })
  },

  exportIotDevicePerson: async (params) => {
    return await request.download({ url: `/pms/iot-device-person-log/export-excel`, params })
  },

  exportIotDeviceAllot: async (params) => {
    return await request.download({ url: `/pms/iot-device-allot-log/export-excel`, params })
  },

  exportIotDeviceMainAlarm: async (params) => {
    return await request.download({ url: `/pms/iot-main-work-order/exportMaintenances`, params })
  },
  getIotDeviceTdPage: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/td/page`, params })
  },

  getIotDeviceOliConnectPage: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/td/ly/page`, params })
  },

  getBoardDevice: async (params: any) => {
    return await request.get({ url: `/rq/iot-device/td/ly/screen`, params })
  },

  getMonitoringQuery: async (params: any) => {
    return await request.get({ url: `rq/stat/td/ly/chart`, params })
  },

  exportMonitoringQuery: async (params: any) => {
    return await request.download({ url: `rq/ly/export`, params })
  },

  // 新增时根据部门id获取设备列表
  getIotDeviceSetOptions: async (id: any) => {
    return await request.get({ url: `/rq/iot-device/dept/${id}` })
  },

  // 设备总数量
  getIotDeviceCount: async (params: any) => {
    return await request.get({ url: `/rq/report/device/count`, params })
  },

  // 设备状态
  getIotDeviceStatus: async (params: any) => {
    return await request.get({ url: `/rq/report/device/status`, params })
  },
  // 分类top
  getIotDeviceClassify: async (params: any) => {
    return await request.get({ url: `/rq/report/device/type`, params })
  },
  // 列表
  getIotDeviceList: async (params: any) => {
    return await request.get({ url: `/rq/report/device/page`, params })
  },
  // 查看详情时获取成套设备列表
  getIotDeviceSets: async (params: any) => {
    return await request.get({ url: `/rq/iot-device-group-detail/page`, params })
  },

  // 获取成套列表
  getIotDeviceSetList: async (params: any) => {
    return await request.get({ url: `/rq/iot-device-group/page`, params })
  },
  // 添加成套
  createIotDeviceSet: async (data: any) => {
    return await request.post({ url: `/rq/iot-device-group/create`, data })
  },
  // 编辑成套
  updateIotDeviceSet: async (data: any) => {
    return await request.put({ url: `/rq/iot-device-group/update`, data })
  },
  // 删除成套
  deleteIotDeviceSet: async (id: number) => {
    return await request.delete({ url: `/rq/iot-device-group/delete?id=` + id })
  },

  // 获取关联设备
  getIotDeviceSetRelation: async (params) => {
    return await request.get({ url: `/rq/iot-device-group/device/group`, params })
  },

  // 设备报表导出
  exportDeviceReport: async (params) => {
    return await request.download({ url: `/rq/report/export-excel`, params })
  },

  // 获取成套设备参数
  getDeviceSetParams: async (id) => {
    return await request.get({ url: `/rq/iot-device-group/td/${id}` })
  },
  // 获取所有设备品牌
  getDeviceBrand: async () => {
    return await request.get({ url: `/supplier/base/all` })
  }
}
