import request from '@/utils/request' // 查询质检配置列表 export function listFiihQcConfig(query) { return request({ url: '/fiihupgrade/config/list', method: 'get', params: query }) } // 查询质检配置详细 export function getFiihQcConfig(id) { return request({ url: '/fiihupgrade/config/' + id, method: 'get' }) } // 新增质检配置 export function addFiihQcConfig(data) { return request({ url: '/fiihupgrade/config', method: 'post', data: data }) } // 是否是管理员 export function isAdmin(){ return request({ url: '/fiihupgrade/config/isAdmin', method: 'get' }) } // 修改质检配置 export function updateFiihQcConfig(data) { return request({ url: '/fiihupgrade/config', method: 'put', data: data }) } // 删除质检配置 export function delFiihQcConfig(id) { return request({ url: '/fiihupgrade/config/' + id, method: 'delete' }) } // 新增质检配置(给外部使用) export function insertFiihQcConfig(data) { return request({ url: '/fiihupgrade/config/insert', method: 'post', data: data }) } // 获取所有对象名称 export function getAllObjects() { return request({ url: '/fiihupgrade/config/list', method: 'get', params: { pageNum: 1, pageSize: 1000 } }).then(res => { let names = [] if (res && res.rows) { names = [...new Set(res.rows.map(item => item.fiihObjectName).filter(n => n))] } return { data: names } }).catch(e => { console.error('Fetch objects failed', e) return { data: [] } }) } // 获取所有已有的下拉选项数据 export function getAllSelectOptions() { return request({ url: '/fiihupgrade/config/list', method: 'get', params: { pageNum: 1, pageSize: 1000 } }).then(res => { const result = { taskNames: [], linkNames: [], versions: [], leaderNames: [], dataNames: [], manufacturers: [], units: [] } if (res && res.rows) { result.taskNames = [...new Set(res.rows.map(item => item.fiihTaskName).filter(n => n))] result.linkNames = [...new Set(res.rows.map(item => item.fiihLinkName).filter(n => n))] result.versions = [...new Set(res.rows.map(item => item.fiihVersion).filter(n => n))] result.leaderNames = [...new Set(res.rows.map(item => item.fiihLeaderName).filter(n => n))] // 从通道配置中提取数据名称、供应商、单位 const dataNameSet = new Set() const manufacturerSet = new Set() const unitSet = new Set() res.rows.forEach(row => { for (let i = 0; i < 24; i++) { const configStr = row[`fiihConfigCh${i}`] if (configStr) { try { const config = typeof configStr === 'string' ? JSON.parse(configStr) : configStr if (config.data_name) dataNameSet.add(config.data_name) if (config.manufacturer) manufacturerSet.add(config.manufacturer) if (config.unit) unitSet.add(config.unit) } catch (e) { // 忽略解析错误 } } } }) result.dataNames = [...dataNameSet] result.manufacturers = [...manufacturerSet] result.units = [...unitSet] } return { data: result } }).catch(e => { console.error('Fetch select options failed', e) return { data: { taskNames: [], linkNames: [], versions: [], leaderNames: [], dataNames: [], manufacturers: [], units: [] } } }) } // 根据对象名称查询配置数据 export function listFiihQcConfigByObject(objectName, query) { return request({ url: '/fiihupgrade/config/list', method: 'get', params: { ...query, fiihObjectName: objectName } }) } // 获取所有环节名称 export function getAllLinks() { return request({ url: '/fiihupgrade/config/list', method: 'get', params: { pageNum: 1, pageSize: 1000 } }).then(res => { let names = [] if (res && res.rows) { names = [...new Set(res.rows.map(item => item.fiihLinkName).filter(n => n))] } return { data: names } }).catch(e => { console.error('Fetch links failed', e) return { data: [] } }) } // 根据环节名称查询配置数据 export function listFiihQcConfigByLink(linkName, query) { return request({ url: '/fiihupgrade/config/list', method: 'get', params: { ...query, fiihLinkName: linkName } }) } // 获取环节-对象分组数据(用于生成层级菜单) export function getLinkObjectGroups() { return request({ url: '/fiihupgrade/config/list', method: 'get', params: { pageNum: 1, pageSize: 1000 } }).then(res => { // 构建环节 -> 对象列表的映射 const linkObjectMap = {} if (res && res.rows) { res.rows.forEach(item => { const linkName = item.fiihLinkName const objectName = item.fiihObjectName if (linkName && objectName) { if (!linkObjectMap[linkName]) { linkObjectMap[linkName] = new Set() } linkObjectMap[linkName].add(objectName) } }) } // 转换为数组格式 const result = Object.keys(linkObjectMap).map(linkName => ({ linkName: linkName, objects: [...linkObjectMap[linkName]] })) return { data: result } }).catch(e => { console.error('Fetch link-object groups failed', e) return { data: [] } }) }