import request from '@/utils/request'

// 查询生产工单列表
export function listPwo(query) {
	return request({
		url: '/mes/pwo/list',
		method: 'get',
		params: query
	})
}

export function acquireOriginMat(data) {
	return request({
		url: '/mes/pwo/acquireOriginMat',
		method: 'post',
		data
	})
}

export function refreshPwo(data) {
	return request({
		url: '/mes/pwo/refreshPwo',
		method: 'post',
		data: data
	})
}

export function advListQuery(query) {
	return request({
		url: '/mes/pwo/advList',
		method: 'get',
		params: query
	})
}

export function listReworkRec(pwoCode) {
	return request({
		url: '/mes/pwo/listReworkRec/' + pwoCode,
		method: 'get',
	})
}

// 查询生产工单列表(模糊查询产品)
export function listPwoLike(query) {
	return request({
		url: '/mes/pwo/listLike',
		method: 'get',
		params: query
	})
}

// 查询生产工单列表(模糊查询产品)
export function listFinishPwoLike(query) {
	return request({
		url: '/mes/pwo/listFinishLike',
		method: 'get',
		params: query
	})
}

// 查询生产工单详细
export function getPwo(id) {
	return request({
		url: '/mes/pwo/' + id,
		method: 'get'
	})
}

export function selectPwoNeededMats(id) {
	return request({
		url: '/mes/pwo/selectPwoNeededMats/' + id,
		method: 'get'
	})
}

// 查询生产工单详细
export function getPwoByCode(pwoCode) {
	return request({
		url: '/mes/pwo/pwoCode/' + pwoCode,
		method: 'get'
	})
}

// 新增生产工单
export function addPwo(data) {
	return request({
		url: '/mes/pwo',
		method: 'post',
		data: data
	})
}

// 修改生产工单
export function updatePwo(data) {
	return request({
		url: '/mes/pwo',
		method: 'put',
		data: data
	})
}

// 删除生产工单
export function delPwo(id) {
	return request({
		url: '/mes/pwo/' + id,
		method: 'delete'
	})
}

export function schedulePwoY(id) {
	return request({
		url: '/mes/pwo/scheduleY/' + id,
		method: 'post'
	})
}

export function schedulePwoN(id) {
	return request({
		url: '/mes/pwo/scheduleN/' + id,
		method: 'post'
	})
}

export function printPwo(id) {
	return request({
		url: '/mes/pwo/print/' + id,
		method: 'post'
	})
}

// 投料
export function materialFeed(pwo) {
	return request({
		url: '/mes/pwo/materialFeed',
		method: 'post',
		data: pwo
	})
}

export function materialFeedByReturn(row) {
	return request({
		url: '/mes/pwo/materialFeedByReturn',
		method: 'post',
		data: row
	})
}

export function handleStop(id) {
	return request({
		url: '/mes/pwo/stop/' + id,
		method: 'post'
	})
}

export function handleStart(id) {
	return request({
		url: '/mes/pwo/start/' + id,
		method: 'post'
	})
}

export function handleIn(id, whCode, stockWhList) {
	return request({
		url: '/mes/pwo/warehouseInGet/' + id + '/' + whCode,
		method: 'post',
		data: stockWhList
	})
}
// 根据工时节拍计算计划完工时间
export function handlePlan(id) {
	return request({
		url: '/mes/pwo/handlePlan/' + id,
		method: 'post'
	})
}

export function calculateNum(id, type, recycleType) {
	return request({
		url: '/mes/pwo/calculateNum/' + id + '/' + type + '/' + recycleType,
		method: 'post'
	})
}

export function feedCalculateNum(id, type, recycleType) {
	return request({
		url: '/mes/pwo/feedCalculateNum/' + id + '/' + type + '/' + recycleType,
		method: 'post'
	})
}

export function feedCalculateNumByPwo(data, type) {
	return request({
		url: '/mes/pwo/feedCalculateNumByPwo/' + type,
		method: 'post',
		data: data
	})
}
export function feedCalculateNumByProcess(data) {
	return request({
		url: '/mes/pwo/feedCalculateNumByProcess',
		method: 'post',
		data: data
	})
}

export function addRework(data) {
	return request({
		url: '/mes/pwo/addRework',
		method: 'post',
		data: data
	})
}

export function addReformPwo(data) {
	return request({
		url: '/mes/pwo/addReformPwo',
		method: 'post',
		data: data
	})
}

export function getListByCodes(data) {
	return request({
		url: '/mes/pwo/getListByCodes',
		method: 'post',
		data: data
	})
}

export function reflexToMps(pwoCode, mesMpsCode) {
	return request({
		url: '/mes/pwo/reflexToMps/' + pwoCode + '/' + mesMpsCode,
		method: 'post',
	})
}

export function listApsxPwo() {
	return request({
		url: '/mes/pwo/listApsxPwo',
		method: 'get',
	})
}

export function selectMatReq(data) {
	return request({
		url: '/mes/pwo/selectMatReq',
		method: 'post',
		data: data
	})
}

export function pwoAtificialClose(data) {
	return request({
		url: '/mes/pwo/pwoAtificialClose',
		method: 'post',
		data: data
	})
}

export function mergePwoPdfs(data, command) {
	return request({
		url: '/mes/pwo/mergePwoPdfs/' + command,
		method: 'post',
		data: data
	})
}

// export function mergePwoPdfs(data) {
//   return request({
//     url: '/mes/pwo/mergePwoPdfs',
//     method: 'post',
//     data: data
//   })
// }

export function handleSyncDraw(ids) {
	return request({
		url: '/mes/pwo/syncDraw',
		method: 'post',
		data: ids
	})
}

export function reflexToPoDtl(pwoId, poDtlId) {
	return request({
		url: '/mes/pwo/reflexToPoDtl/' + pwoId + '/' + poDtlId,
		method: 'post'
	})
}

// 查询工单拆分小数精度
export function getSplitPrecision(id) {
	return request({
		url: '/mes/pwo/splitPrecision',
		method: 'get'
	})
}

export function splitPwoByReports(data) {
	return request({
		url: '/mes/pwo/splitPwoByReport',
		method: 'post',
		data: data
	})
}

//同步工单
export function synchronizeIntegrate() {
	return request({
		url: '/mes/pwo/synchronizeIntegrate',
		method: 'post',
	})
}

// 获取工单 + 流转结存表
export function getFlowStore(data) {
	return request({
		url: '/mes/pwo/list/flowStore',
		method: 'get',
		params: data
	})
}

// 工单下的作业依次绑定产线内的设备
export function setProductionLine(data) {
	return request({
		url: '/mes/pwo/productionLine',
		method: 'put',
		data: data
	})
}

// 工单下的作业批量绑定产线内的设备
export function setProductionLineBatch(data) {
	return request({
		url: '/mes/pwo/productionLineBatch',
		method: 'put',
		data: data
	})
}

export function pwoForceClose(ids) {
	return request({
		url: '/mes/pwo/forceClose',
		method: 'post',
		data: ids
	})
}

export function pwoForceReopen(ids) {
	return request({
		url: '/mes/pwo/pwoForceReopen',
		method: 'post',
		data: ids
	})
}

/**
 * 根据关联订单编码查询可报工数量总和
 * @param {*} relOrderDetailCode 关联订单编码
 * @returns
 */
export function getReportableNumByRealOrderCode(relOrderDetailCode) {
	return request({
		url: '/mes/pwo/reportableNum/' + relOrderDetailCode,
		method: 'get',
	})
}