style:设备运行参数分析/表管理/设备分组修改树状接口

main
黄伟杰 3 days ago
parent 2b905e8749
commit aa0eca7ede

@ -23,8 +23,8 @@ export const DeviceLineApi = {
return await request.get({ url: `/mes/device-line/get?id=` + id })
},
getDeviceLineTree: async () => {
return await request.get({ url: `/mes/device-line/tree` })
getDeviceLineTree: async (params?: { filterNoDeviceLine?: number }) => {
return await request.get({ url: `/mes/device-line/tree`, params })
},
regenerateCode: async (id: number, code: string) => {

@ -73,7 +73,7 @@ export const OrganizationApi = {
return await request.download({ url: `/mes/organization/export-excel`, params })
},
deviceParameterAnalysis: async (params: { keyword?: string, showDevices?: number }) => {
deviceParameterAnalysis: async (params: { keyword?: string, showDevices?: number, filterNoDeviceLine?: number }) => {
return await request.get({ url: `/mes/device-line/deviceParameterAnalysis`, params })
}
}

@ -851,7 +851,7 @@ export default {
packageCount: 'Package Count',
outPackageCount: 'Outbound Package Count',
outLockedPackageCount: 'Outbound Locked Package Count',
outPackageCountExceededWarning: 'Outbound package count cannot exceed package count minus outbound locked package count. It has been adjusted to {count}.',
outPackageCountExceededWarning: 'Pallet code {code}: outbound package count cannot exceed package count minus outbound locked package count. It has been adjusted to {count}.',
inPackageCount: 'Inbound Package Count',
inItemCount: 'Inbound Count',
inCount: 'Inbound Quantity',

@ -851,7 +851,7 @@ export default {
packageCount: '包数',
outPackageCount: '出库包数',
outLockedPackageCount: '出库锁定包数',
outPackageCountExceededWarning: '出库包数不能大于包数减出库锁定包数,已自动调整为{count}',
outPackageCountExceededWarning: '托盘编码{code}出库包数不能大于包数减出库锁定包数,已自动调整为{count}',
inPackageCount: '入库包数',
inItemCount: '入库个数',
inCount: '入库数量',

@ -382,7 +382,11 @@ const extractApiOrgs = (res: any): ApiTreeOrg[] => {
const loadTree = async () => {
treeLoading.value = true
try {
const res = await OrganizationApi.deviceParameterAnalysis({ keyword: keyword.value || undefined, showDevices: 1 })
const res = await OrganizationApi.deviceParameterAnalysis({
keyword: keyword.value || undefined,
showDevices: 1,
filterNoDeviceLine: 1
})
treeData.value = buildTreeFromApi(extractApiOrgs(res))
defaultExpandedKeys.value = buildDefaultExpandedKeys(treeData.value, 'pipeline')
await nextTick()

@ -255,7 +255,7 @@ const getDeviceLedgerOptions = async (groupId?: string) => {
}
const getFilterOptions = async () => {
const deviceLineTree = await DeviceLineApi.getDeviceLineTree()
const deviceLineTree = await DeviceLineApi.getDeviceLineTree({ filterNoDeviceLine: 1 })
groupOptions.value = normalizeDeviceLineTree(Array.isArray(deviceLineTree) ? deviceLineTree : [])
await getDeviceLedgerOptions(queryParams.value.groupId)
}

@ -247,6 +247,12 @@
@click="openIotDeviceDialog"
>
<template #append>
<el-button
v-if="iotDeviceDisplay"
@click.stop.prevent="clearIotDevice"
>
<Icon icon="ep:close" />
</el-button>
<el-button @click.stop="openIotDeviceDialog">
<Icon icon="ep:search" />
</el-button>
@ -1475,6 +1481,11 @@ const openIotDeviceDialog = async () => {
const clearIotDevice = () => {
formData.value.dvId = undefined
delete formData.value.iotDeviceCode
delete formData.value.iotDeviceName
delete formData.value.iotDeviceLabel
delete formData.value.iotDevice
delete formData.value.device
iotDeviceSelectedLabel.value = ''
iotDeviceDraftId.value = undefined
iotDeviceDraftRow.value = undefined
@ -1682,6 +1693,11 @@ const buildSubmitData = () => {
delete (data as any).deviceManagerIds
delete (data as any).componentIds
delete (data as any).beijianIds
delete (data as any).iotDeviceCode
delete (data as any).iotDeviceName
delete (data as any).iotDeviceLabel
delete (data as any).iotDevice
delete (data as any).device
return data
}

@ -73,7 +73,7 @@
clearable
class="!w-full"
:placeholder="t('EnergyManagement.EnergyDevice.dialogRulesPointPlaceholder')"
:loading="devicePointLoading"
:loading="analysisLoading"
@change="(val) => handlePointSelected(index, val)"
/>
@ -131,8 +131,7 @@
<script setup lang="ts">
import { EnergyDeviceApi, EnergyDeviceVO } from '@/api/mes/energydevice'
import { EnergyTypeApi, EnergyTypeVO } from '@/api/mes/energytype'
import { DeviceLineApi, DeviceLineTreeVO } from '@/api/mes/deviceline'
import { DeviceApi } from '@/api/iot/device'
import { OrganizationApi } from '@/api/mes/organization'
import { Remove } from '@element-plus/icons-vue'
/** 能源设备 表单 */
@ -205,8 +204,48 @@ const formRules = reactive({
const formRef = ref() // Ref
const analysisLoading = ref(false)
type OrgSelectNode = DeviceLineTreeVO & { children?: OrgSelectNode[] }
type AnalysisParameter = {
id: number | string
name: string
code?: string
type?: string | null
dataType?: string | null
unit?: string | null
}
type AnalysisEquipment = {
id: number | string
name: string
parameters?: AnalysisParameter[]
}
type AnalysisOrgNode = {
id: number | string
name: string
orgClass?: string
parentId?: number | string | null
equipments?: AnalysisEquipment[]
children?: AnalysisOrgNode[]
}
type OrgSelectNode = {
id: number | string
name: string
orgClass?: string
parentId?: number | string | null
children?: OrgSelectNode[]
}
type EquipmentTreeNode = {
id: string
name: string
disabled?: boolean
dataType?: string | null
children?: EquipmentTreeNode[]
}
const analysisTree = ref<AnalysisOrgNode[]>([])
const orgSelectTree = ref<OrgSelectNode[]>([])
const orgTreeSelectProps = {
@ -240,121 +279,109 @@ const findOrgNode = (nodes: OrgSelectNode[], id: any): OrgSelectNode | undefined
return undefined
}
const devicePointLoading = ref(false)
const devicePointTree = ref<any[]>([])
const normalizeAnalysisId = (value: any) => String(value ?? '')
const normalizeAnalysisTree = (nodes: any[] = []): AnalysisOrgNode[] => {
return nodes.map((node) => ({
id: node?.id,
name: String(node?.name ?? ''),
orgClass: node?.orgClass ? String(node.orgClass) : undefined,
parentId: node?.parentId ?? undefined,
equipments: Array.isArray(node?.equipments) ? node.equipments : [],
children: Array.isArray(node?.children) ? normalizeAnalysisTree(node.children) : undefined
}))
}
const loadDevicePointTree = async () => {
if (devicePointTree.value.length > 0) {
return
}
devicePointLoading.value = true
try {
const res: any = await DeviceApi.devicePointList()
const list = Array.isArray(res) ? res : Array.isArray(res?.data) ? res.data : []
const normalizeToString = (v: any) => String(v ?? '')
const isNonEmptyArray = (v: any) => Array.isArray(v) && v.length > 0
const deviceGroups = new Map<string, { deviceId: string; deviceName: string; points: any[] }>()
const pushPoint = (
deviceId: any,
deviceName: any,
pointId: any,
pointName: any,
dataType?: any
) => {
const dId = normalizeToString(deviceId)
if (!dId) return
const group = deviceGroups.get(dId) ?? {
deviceId: dId,
deviceName: String(deviceName ?? ''),
points: []
}
if (!group.deviceName) group.deviceName = String(deviceName ?? '')
const pId = normalizeToString(pointId)
if (!pId) {
deviceGroups.set(dId, group)
return
}
group.points.push({
id: `${dId}:${pId}`,
name: `${group.deviceName}: ${String(pointName ?? '')}`.trim(),
dataType
})
deviceGroups.set(dId, group)
}
const buildOrgSelectTree = (nodes: AnalysisOrgNode[] = []): OrgSelectNode[] => {
return nodes.map((node) => ({
id: node.id,
name: node.name,
orgClass: node.orgClass,
parentId: node.parentId,
children: Array.isArray(node.children) ? buildOrgSelectTree(node.children) : undefined
}))
}
if (
isNonEmptyArray(list) &&
((list[0] as any)?.deviceId !== undefined || (list[0] as any)?.deviceName !== undefined)
) {
;(list as any[]).forEach((row) => {
const deviceId = row?.deviceId ?? row?.devId ?? row?.device_id
const deviceName = row?.deviceName ?? row?.devName ?? row?.device_name
const points =
row?.contactModelDOList ??
row?.points ??
row?.pointList ??
row?.devicePoints ??
row?.devicePointList ??
row?.parameters
if (Array.isArray(points)) {
points.forEach((p) => {
const pointId = p?.pointId ?? p?.id
const pointName = p?.attributeName ?? p?.pointName ?? p?.name
pushPoint(deviceId, deviceName, pointId, pointName, (p as any)?.dataType)
})
} else {
const pointId = row?.pointId ?? row?.attributeId ?? row?.devicePointId
const pointName = row?.attributeName ?? row?.pointName ?? row?.attributeName
pushPoint(deviceId, deviceName, pointId, pointName)
}
})
} else if (isNonEmptyArray(list)) {
;(list as any[]).forEach((row) => {
const deviceId = row?.deviceId ?? row?.devId
const deviceName = row?.deviceName ?? row?.devName
const pointId = row?.pointId ?? row?.id
const pointName = row?.attributeName ?? row?.pointName ?? row?.name
pushPoint(deviceId, deviceName, pointId, pointName, (row as any)?.dataType)
})
const extractAnalysisOrgs = (res: any): AnalysisOrgNode[] => {
if (Array.isArray(res)) return normalizeAnalysisTree(res)
if (Array.isArray(res?.data)) return normalizeAnalysisTree(res.data)
if (Array.isArray(res?.result)) return normalizeAnalysisTree(res.result)
if (Array.isArray(res?.list)) return normalizeAnalysisTree(res.list)
return []
}
const findAnalysisNode = (nodes: AnalysisOrgNode[], id: any): AnalysisOrgNode | undefined => {
for (const node of nodes) {
if (isSameId(node.id, id)) return node
const children = Array.isArray(node.children) ? node.children : []
if (children.length) {
const found = findAnalysisNode(children, id)
if (found) return found
}
}
return undefined
}
devicePointTree.value = Array.from(deviceGroups.values())
.map((g) => {
const children = (g.points ?? []).filter((p) => p?.id)
if (!children.length) return null
return { id: `device:${g.deviceId}`, name: g.deviceName, disabled: true, children }
})
.filter(Boolean) as any[]
} finally {
devicePointLoading.value = false
const collectEquipmentTree = (nodes: AnalysisOrgNode[] = []): EquipmentTreeNode[] => {
const equipmentNodes: EquipmentTreeNode[] = []
const walk = (node: AnalysisOrgNode) => {
const equipments = Array.isArray(node.equipments) ? node.equipments : []
equipments.forEach((equipment) => {
const deviceId = normalizeAnalysisId(equipment?.id)
if (!deviceId) return
const parameterNodes = (Array.isArray(equipment.parameters) ? equipment.parameters : [])
.map((parameter) => {
const pointId = normalizeAnalysisId(parameter?.id)
if (!pointId) return undefined
return {
id: deviceId + ':' + pointId,
name: String(parameter?.name ?? parameter?.code ?? pointId),
dataType: parameter?.dataType ?? parameter?.type ?? undefined
}
})
.filter(Boolean) as EquipmentTreeNode[]
if (parameterNodes.length) {
equipmentNodes.push({
id: 'device:' + deviceId,
name: String(equipment?.name ?? deviceId),
disabled: true,
children: parameterNodes
})
}
})
const children = Array.isArray(node.children) ? node.children : []
children.forEach(walk)
}
nodes.forEach(walk)
return equipmentNodes
}
const equipmentTree = computed(() => {
return devicePointTree.value
if (!formData.value.orgId) return []
const selectedOrg = findAnalysisNode(analysisTree.value, formData.value.orgId)
return selectedOrg ? collectEquipmentTree([selectedOrg]) : []
})
const findPointDataType = (deviceId: any, pointId: any): string | undefined => {
const dId = String(deviceId ?? '')
const pId = String(pointId ?? '')
if (!dId || !pId) return undefined
const key = `${dId}:${pId}`
const groups = devicePointTree.value ?? []
for (const g of groups) {
const children = Array.isArray((g as any).children) ? (g as any).children : []
for (const c of children) {
if (String((c as any).id ?? '') === key) {
return (c as any).dataType as string | undefined
const deviceKey = normalizeAnalysisId(deviceId)
const pointKey = normalizeAnalysisId(pointId)
if (!deviceKey || !pointKey) return undefined
const key = deviceKey + ':' + pointKey
for (const group of collectEquipmentTree(analysisTree.value)) {
const children = Array.isArray(group.children) ? group.children : []
for (const child of children) {
if (String(child.id ?? '') === key) {
return child.dataType as string | undefined
}
}
}
return undefined
}
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
@ -362,7 +389,6 @@ const open = async (type: string, id?: number) => {
resetForm()
await loadAnalysis()
await loadDevicePointTree()
//
if (id) {
formLoading.value = true
@ -446,13 +472,17 @@ onMounted(async () => {
})
const loadAnalysis = async () => {
if (orgSelectTree.value.length > 0) {
if (analysisTree.value.length > 0) {
return
}
analysisLoading.value = true
try {
const res = await DeviceLineApi.getDeviceLineTree()
orgSelectTree.value = (Array.isArray(res) ? res : []) as OrgSelectNode[]
const res = await OrganizationApi.deviceParameterAnalysis({
showDevices: 1,
filterNoDeviceLine: 1
})
analysisTree.value = extractAnalysisOrgs(res)
orgSelectTree.value = buildOrgSelectTree(analysisTree.value)
} finally {
analysisLoading.value = false
}
@ -464,9 +494,17 @@ const handleDeviceTypeChange = () => {
)?.unit
}
const resetOperationRules = () => {
formData.value.operationRulesVOList = [
{ deviceId: undefined, pointId: undefined, operator: undefined, pointValue: undefined }
]
}
const handleOrgChange = () => {
const org = findOrgNode(orgSelectTree.value ?? [], formData.value.orgId)
formData.value.orgName = org?.name
resetOperationRules()
formRef.value?.clearValidate('operationRulesVOList')
}
const handlePointSelected = (index: number, val: any) => {

Loading…
Cancel
Save