fix: 修复雪花算法ID精度丢失问题

main
zhongwenkai 14 hours ago
parent 6c723087c0
commit 208778df3f

@ -2,8 +2,8 @@ import request from '@/config/axios'
// ERP 产品分类 VO
export interface ProductCategoryVO {
id: number // 分类编号
parentId: number // 父分类编号
id?: number | string // 分类编号
parentId?: number | string // 父分类编号
name: string // 分类名称
code: string // 分类编码
sort: number // 分类排序
@ -34,7 +34,7 @@ export const ProductCategoryApi = {
},
// 查询产品分类详情
getProductCategory: async (id: number) => {
getProductCategory: async (id: number | string) => {
return await request.get({ url: `/erp/product-category/get?id=` + id })
},
@ -49,7 +49,7 @@ export const ProductCategoryApi = {
},
// 删除产品分类
deleteProductCategory: async (id: number) => {
deleteProductCategory: async (id: number | string) => {
return await request.delete({ url: `/erp/product-category/delete?id=` + id })
},

@ -2,16 +2,16 @@ import request from '@/config/axios'
// ERP 产品 VO
export interface ProductVO {
id: number // 产品编号
id?: number | string // 产品编号
name: string // 产品名称
barCode: string // 产品条码
isCode?: boolean
qrcodeUrl?: string
templateJson?: string | any
categoryId: number // 产品类型编号
subCategoryId: number // 产品类型子类编号
categoryId?: number | string // 产品类型编号
subCategoryId?: number | string // 产品类型子类编号
subCategoryName: string // 产品类型子类名称
unitId: number // 单位编号
unitId?: number | string // 单位编号
unitName?: string // 单位名字
status: number // 产品状态
standard: string // 产品规格
@ -23,19 +23,19 @@ export interface ProductVO {
minPrice: number // 最低价格,单位:元
deviceIds?: string // 关联设备ID列表
moldIds?: string // 关联模具ID列表
devices?: { id: number; name: string }[] // 关联设备列表
molds?: { id: number; name: string }[] // 关联模具列表
devices?: { id: number | string; name: string }[] // 关联设备列表
molds?: { id: number | string; name: string }[] // 关联模具列表
deviceList?: any[]
moldList?: any[]
}
export interface ErpProductCategoryProcessRouteItemRespVO {
id?: number
categoryId?: number
processRouteId?: number
processRouteItemId?: number
id?: number | string
categoryId?: number | string
processRouteId?: number | string
processRouteItemId?: number | string
sort?: number
processParameterId?: number
processParameterId?: number | string
processParameterCode?: string
processParameterName?: string
remark?: string
@ -44,8 +44,8 @@ export interface ErpProductCategoryProcessRouteItemRespVO {
}
export interface ErpProductProcessRouteRespVO {
productId?: number
processRouteId?: number
productId?: number | string
processRouteId?: number | string
processRouteName?: string
processRouteItems?: ErpProductCategoryProcessRouteItemRespVO[]
}
@ -83,7 +83,7 @@ export const ProductApi = {
},
// 查询产品详情
getProduct: async (id: number) => {
getProduct: async (id: number | string) => {
return await request.get({ url: `/erp/product/get?id=` + id })
},
@ -98,14 +98,14 @@ export const ProductApi = {
},
// 刷新产品二维码
regenerateCode: async (id: number, code: string) => {
regenerateCode: async (id: number | string, code: string) => {
return await request.post({
url: `/erp/product/regenerate-code?id=${id}&code=${encodeURIComponent(code)}`
})
},
// 删除产品
deleteProduct: async (id: number) => {
deleteProduct: async (id: number | string) => {
return await request.delete({ url: `/erp/product/delete?id=` + id })
},

@ -199,7 +199,7 @@ watch(() => operateFormData.deviceId, async (deviceId) => {
displayTopCategory.value = detail?.topCategoryName || ''
// fallback: 线
if (!displayTopCategory.value && detail?.deviceLine != null && deviceLineTree.value.length) {
const lineId = Number(detail.deviceLine)
const lineId = String(detail.deviceLine)
const containsId = (nodes: DeviceLineTreeVO[] | undefined, id: number): boolean => {
if (!nodes) return false
return nodes.some((n) => n.id === id || containsId(n.children, id))

@ -526,7 +526,7 @@ const message = useMessage()
const route = useRoute()
const router = useRouter()
const MoldListComp = defineAsyncComponent(() => import('../components/MoldList.vue') as any)
const brandId = computed(() => Number(route.params.id))
const brandId = computed(() => String(route.params.id || ''))
const detailLoading = ref(false)
const detailData = ref<(MoldBrandVO & Record<string, any>) | null>(null)
const childMolds = ref<any[]>([])
@ -871,7 +871,7 @@ const getChildMolds = async () => {
const collectByChildMolds = async (worker: (moldId: number) => Promise<any>, mergeList = true) => {
const molds = childMolds.value.length ? childMolds.value : await getChildMolds()
const ids = molds.map((item) => Number(item.id)).filter(Boolean)
const ids = molds.map((item) => String(item.id)).filter(Boolean)
if (!ids.length) return []
const results = await Promise.all(ids.map((id) => worker(id).catch(() => [])))
return mergeList ? results.flat() : results

@ -520,7 +520,7 @@ const repairGroups = computed<RepairHistoryGroup[]>(() => {
})
const fetchRepairHistory = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) return
const params: any = { moldId: id }
if (repairDateRange.value && repairDateRange.value.length === 2) {
@ -532,7 +532,7 @@ const fetchRepairHistory = async () => {
}
const handleQueryRepair = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
return
@ -541,7 +541,7 @@ const handleQueryRepair = async () => {
}
const handleResetRepair = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
return
@ -551,7 +551,7 @@ const handleResetRepair = async () => {
}
const handleExportRepair = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
return
@ -571,7 +571,7 @@ const handleExportRepair = async () => {
}
const fetchMaintainHistory = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) return
const params: any = { moldId: id }
if (maintainDateRange.value && maintainDateRange.value.length === 2) {
@ -583,7 +583,7 @@ const fetchMaintainHistory = async () => {
}
const handleQueryMaintain = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
return
@ -592,7 +592,7 @@ const handleQueryMaintain = async () => {
}
const handleResetMaintain = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
return
@ -602,7 +602,7 @@ const handleResetMaintain = async () => {
}
const handleExportMaintain = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
return
@ -622,7 +622,7 @@ const handleExportMaintain = async () => {
}
const fetchInspectionHistory = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) return
const params: any = { moldId: id }
if (inspectionDateRange.value && inspectionDateRange.value.length === 2) {
@ -634,7 +634,7 @@ const fetchInspectionHistory = async () => {
}
const handleQueryInspection = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
return
@ -643,7 +643,7 @@ const handleQueryInspection = async () => {
}
const handleResetInspection = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
return
@ -653,7 +653,7 @@ const handleResetInspection = async () => {
}
const handleExportInspection = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
return
@ -677,7 +677,7 @@ const close = () => {
}
const getDetail = async () => {
const id = Number(route.params.id)
const id = String(route.params.id || '')
if (!id) {
message.error('参数错误,模具不能为空')
close()

@ -441,9 +441,9 @@ onMounted(async () => {
//
const { operateType: queryOperateType, moldId: queryMoldId } = route.query
if (queryOperateType && queryMoldId) {
const moldRow = list.value.find((item) => item.id === Number(queryMoldId))
const moldRow = list.value.find((item) => String(item.id) === String(queryMoldId))
if (moldRow) {
await openOperateForm(Number(queryOperateType), moldRow)
await openOperateForm(String(queryOperateType), moldRow)
}
// query
push({ path: route.path })

@ -258,10 +258,10 @@ const selectedProcessRouteId = ref<string | number | undefined>()
const selectedProcessRouteRow = ref<ProcessRouteVO | undefined>()
const processRouteDisplayName = computed(() => {
if (!formData.value.processRouteId) return ''
if (formData.value.processRouteId == null) return ''
return formData.value.processRouteName || String(formData.value.processRouteId)
})
const isProductType = computed(() => Number(formData.value.type) === 1)
const isProductType = computed(() => String(formData.value.type) === '1')
const isEnabledProcessRoute = (row?: ProcessRouteVO) => {
if (!row) return false
@ -270,7 +270,7 @@ const isEnabledProcessRoute = (row?: ProcessRouteVO) => {
}
/** 打开弹窗 */
const open = async (type: string, id?: number, defaultData?: any) => {
const open = async (type: string, id?: string | number, defaultData?: any) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
@ -352,9 +352,9 @@ const handleTypeChange = async () => {
}
const syncProcessRouteName = async () => {
if (!formData.value.processRouteId || formData.value.processRouteName) return
if (formData.value.processRouteId == null || formData.value.processRouteName) return
try {
const data = await ProcessRouteApi.getProcessRoute(Number(formData.value.processRouteId))
const data = await ProcessRouteApi.getProcessRoute(formData.value.processRouteId)
formData.value.processRouteName = data?.name
} catch {}
}
@ -378,9 +378,9 @@ const getProcessRouteList = async () => {
const openProcessRouteDialog = async () => {
selectedProcessRouteId.value = undefined
selectedProcessRouteRow.value = undefined
if (formData.value.processRouteId) {
if (formData.value.processRouteId != null) {
try {
const data = await ProcessRouteApi.getProcessRoute(Number(formData.value.processRouteId))
const data = await ProcessRouteApi.getProcessRoute(formData.value.processRouteId)
if (isEnabledProcessRoute(data)) {
selectedProcessRouteId.value = formData.value.processRouteId
selectedProcessRouteRow.value = data

@ -435,10 +435,10 @@ const formData = ref({
salePrice: undefined,
minPrice: undefined,
safetyNumber: undefined,
devices: [] as { id: number; name: string }[],
molds: [] as { id: number; name: string }[],
packagingSchemes: [] as { packagingSchemeId: number | undefined; defaultStatus: number }[],
suppliers: [] as { supplierId: number | undefined; defaultStatus: number }[],
devices: [] as { id: string | number; name: string }[],
molds: [] as { id: string | number; name: string }[],
packagingSchemes: [] as { packagingSchemeId: string | number | undefined; defaultStatus: number }[],
suppliers: [] as { supplierId: string | number | undefined; defaultStatus: number }[],
fragileFlag: undefined as number | undefined,
purchaseCycle: undefined as number | undefined,
brand: undefined as string | undefined,
@ -450,13 +450,13 @@ const formData = ref({
})
const selectedDeviceRows = ref<any[]>([])
const selectedMoldRows = ref<any[]>([])
const findCategoryNameById = (id: number | undefined, tree: any[]): string => {
if (!id || !Array.isArray(tree) || !tree.length) return ''
const findCategoryNameById = (id: string | number | undefined, tree: any[]): string => {
if (id == null || !Array.isArray(tree) || !tree.length) return ''
const queue = [...tree]
while (queue.length) {
const node = queue.shift()
if (!node) continue
if (Number(node.id) === Number(id)) {
if (String(node.id) === String(id)) {
return String(node.name || node.label || '')
}
if (Array.isArray(node.children) && node.children.length) {
@ -467,7 +467,7 @@ const findCategoryNameById = (id: number | undefined, tree: any[]): string => {
}
const selectedCategoryName = computed(() => findCategoryNameById(formData.value.categoryId as any, categoryList.value))
const isProductCategory = computed(() => selectedCategoryName.value === '产品')
const getRelationName = (item: Record<string, any>, nameKeys: string[], fallbackPrefix: string, id: number) => {
const getRelationName = (item: Record<string, any>, nameKeys: string[], fallbackPrefix: string, id: string | number) => {
for (const key of nameKeys) {
const value = item[key]
if (value !== undefined && value !== null && String(value).trim() !== '') {
@ -481,11 +481,10 @@ const normalizeRelationList = (
fallbackRows: any[] | undefined,
nameKeys: string[],
fallbackPrefix: string
): { id: number; name: string }[] => {
const fallbackMap = new Map<number, string>()
): { id: string | number; name: string }[] => {
const fallbackMap = new Map<string | number, string>()
; (fallbackRows || []).forEach((row) => {
const id = Number(row?.id)
if (!Number.isFinite(id)) return
const id = String(row?.id)
fallbackMap.set(id, getRelationName(row, nameKeys, fallbackPrefix, id))
})
const parseArray = (source: unknown): any[] => {
@ -505,30 +504,31 @@ const normalizeRelationList = (
return parseArray(value)
.map((item) => {
if (typeof item === 'object' && item !== null) {
const id = Number((item as any).id)
if (!Number.isFinite(id)) return undefined
const rawId = (item as any).id
if (rawId == null) return undefined
const id = rawId
return {
id,
name: getRelationName(item as any, nameKeys, fallbackPrefix, id)
}
}
const id = Number(item)
if (!Number.isFinite(id)) return undefined
const rawId = String(item).trim()
if (!rawId) return undefined
return {
id,
name: fallbackMap.get(id) || `${fallbackPrefix}ID:${id}`
id: rawId,
name: fallbackMap.get(rawId) || `${fallbackPrefix}ID:${rawId}`
}
})
.filter((item): item is { id: number; name: string } => Boolean(item))
.filter((item): item is { id: string | number; name: string } => Boolean(item))
}
const toDeviceRows = (devices: { id: number; name: string }[]) => {
const toDeviceRows = (devices: { id: string | number; name: string }[]) => {
return devices.map((item) => ({
id: item.id,
deviceName: item.name,
name: item.name
}))
}
const toMoldRows = (molds: { id: number; name: string }[]) => {
const toMoldRows = (molds: { id: string | number; name: string }[]) => {
return molds.map((item) => ({
id: item.id,
name: item.name
@ -565,7 +565,7 @@ const fetchDeviceLedgerPage = (params: Record<string, any>) => {
}
const openDeviceSelectDialog = () => {
const rows = selectedDeviceRows.value.length
? selectedDeviceRows.value.map((item) => ({ ...item, id: Number(item.id) }))
? selectedDeviceRows.value.map((item) => ({ ...item, id: String(item.id) }))
: toDeviceRows(formData.value.devices)
deviceSelectDialogRef.value?.open(rows)
}
@ -578,27 +578,25 @@ const openMoldSelectDialog = () => {
const handleDeviceSelectConfirm = (payload: { ids: (number | string)[]; rows: any[] }) => {
formData.value.devices = payload.rows
.map((item) => {
const id = Number(item.id)
if (!Number.isFinite(id)) return undefined
const id = String(item.id)
return {
id,
name: item.deviceName || item.name || item.code || `设备ID:${id}`
}
})
.filter((item): item is { id: number; name: string } => Boolean(item))
.filter((item): item is { id: string | number; name: string } => Boolean(item))
selectedDeviceRows.value = payload.rows
}
const handleMoldSelectConfirm = (payload: { ids: (number | string)[]; rows: any[] }) => {
formData.value.molds = payload.rows
.map((item) => {
const id = Number(item.id)
if (!Number.isFinite(id)) return undefined
const id = String(item.id)
return {
id,
name: item.name || item.code || `模具ID:${id}`
}
})
.filter((item): item is { id: number; name: string } => Boolean(item))
.filter((item): item is { id: string | number; name: string } => Boolean(item))
selectedMoldRows.value = payload.rows
}
const validateBarCode = (_rule, value, callback) => {
@ -935,7 +933,7 @@ const supplierList = ref<any[]>([])
let openRequestId = 0
const open = async (type: string, id?: number) => {
const open = async (type: string, id?: string | number) => {
const currentOpenId = ++openRequestId
dialogTitle.value = t('action.' + type)
formType.value = type
@ -1114,8 +1112,8 @@ const handleQrcodeRefreshSuccess = async (data: any) => {
formData.value.barCode = productData?.barCode ?? formData.value.barCode
}
const buildRelationIdListString = (list: { id: number; name: string }[]) => {
return list.map((item) => Number(item.id)).filter((id) => Number.isFinite(id))
const buildRelationIdListString = (list: { id: string | number; name: string }[]) => {
return list.map((item) => String(item.id)).filter((id) => id !== '')
}
const getDefaultPackagingSchemeId = () => {

@ -673,10 +673,10 @@ async function fillProductStockAreaInfo(stockList) {
const warehouse = await WarehouseApi.getWarehouse(warehouseId)
const areaList = warehouse?.areaList || []
stockList
.filter((item) => Number(getStockWarehouseId(item)) === Number(warehouseId))
.filter((item) => String(getStockWarehouseId(item)) === String(warehouseId))
.forEach((item) => {
const area = areaList.find(
(areaItem) => Number(areaItem.id) === Number(getStockAreaId(item))
(areaItem) => String(areaItem.id) === String(getStockAreaId(item))
)
if (!area) return
item.areaCode = area.areaCode
@ -714,7 +714,7 @@ function getFromWarehouseOptions(row) {
function getFromAreaOptions(row) {
if (!row.fromWarehouseId) return []
const areaOptions = (row.productStockList || []).filter(
(item) => Number(getStockWarehouseId(item)) === Number(row.fromWarehouseId)
(item) => Number(getStockWarehouseId(item)) === String(row.fromWarehouseId)
)
return appendOptionIfMissing(
areaOptions,
@ -753,7 +753,7 @@ function getToAreaOptions(row) {
const areaOptions =
Array.isArray(row.toAreaList) && row.toAreaList.length > 0
? row.toAreaList
: warehouseList.value.find((item) => Number(item.id) === Number(row.toWarehouseId))
: warehouseList.value.find((item) => String(item.id) === String(row.toWarehouseId))
?.areaList || []
return appendOptionIfMissing(
areaOptions,
@ -780,7 +780,7 @@ async function setStockCount(row) {
const stock = row.productStockList.find(
(item) =>
Number(getStockWarehouseId(item)) === Number(row.fromWarehouseId) &&
Number(getStockAreaId(item)) === Number(row.fromAreaId)
Number(getStockAreaId(item)) === String(row.fromAreaId)
)
row.stockCount = stock ? getStockCount(stock) : 0
}

@ -654,7 +654,7 @@ const applyPalletDetail = async (data: PalletVO) => {
const handleQrcodeRefreshSuccess = async () => {
if (!formData.value.id) return
const data = await PalletApi.getPallet(Number(formData.value.id))
const data = await PalletApi.getPallet(String(formData.value.id))
await applyPalletDetail(data)
}
@ -695,7 +695,7 @@ const hydrateSelectedWarehouseArea = async () => {
const hydrateSelectedProduct = async () => {
selectedProduct.value = undefined
if (!formData.value.productId) return
selectedProduct.value = await ProductApi.getProduct(Number(formData.value.productId))
selectedProduct.value = await ProductApi.getProduct(String(formData.value.productId))
}
const getProductTableList = async () => {

@ -155,7 +155,7 @@ const getList = async () => {
if (!recipeId.value) return
loading.value = true
try {
const data = await RecipePointApi.getRecipePointList(Number(recipeId.value))
const data = await RecipePointApi.getRecipePointList(String(recipeId.value))
setPageData(data)
} finally {
loading.value = false

@ -398,7 +398,7 @@ const handleRead = async (row: RecipePlanDetailVO) => {
handleRowClick(row)
const recipeName = row?.recipeName
const { hasDeviceRecords, hasManualRecords } = await checkRecipeRecords(recipeId)
const data = await RecipePointApi.getRecipePointList(Number(recipeId))
const data = await RecipePointApi.getRecipePointList(String(recipeId))
if (!data?.length) {
await message.confirm(
`${t('RecipeManagement.RecipeLibrary.readDeviceConfirmMessage')}(${t('RecipeManagement.RecipeLibrary.readDialogOverwriteTip')})`

@ -287,9 +287,9 @@ const buildTreeFromApi = (orgs: ApiTreeOrg[]): DeviceTreeNode[] => {
const normalizeOrg = (org: any): ApiTreeOrg => {
const children = Array.isArray(org?.children) ? org.children.map(normalizeOrg) : undefined
const equipments = Array.isArray(org?.equipments) ? org.equipments : undefined
const parentId = typeof org?.parentId === 'number' ? org.parentId : Number(org?.parentId ?? 0) || 0
const parentId = org?.parentId ?? 0
return {
id: Number(org?.id ?? 0) || 0,
id: org?.id ?? 0,
name: String(org?.name ?? ''),
orgClass: org?.orgClass ? String(org.orgClass) : undefined,
parentId,

@ -155,7 +155,7 @@ onMounted(() => {
close()
return
}
customerId.value = params.id as unknown as number
customerId.value = params.id as unknown as string
getCustomer()
})
</script>

@ -428,7 +428,7 @@ const selectedCaiJiRows = ref<any[]>([])
const handleDeviceSelectConfirm = (payload: { ids: (number | string)[]; rows: any[] }) => {
formData.value.devices = payload.rows
.map((item) => {
const id = Number(item.id)
const id = String(item.id)
if (!Number.isFinite(id)) return undefined
return {
id,
@ -438,7 +438,7 @@ const handleDeviceSelectConfirm = (payload: { ids: (number | string)[]; rows: an
.filter((item): item is { id: number; name: string } => Boolean(item))
selectedDeviceRows.value = payload.rows
formData.value.machineId = payload.ids.join(',')
ids.value = payload.ids.map((id) => Number(id))
ids.value = payload.ids.map((id) => String(id))
}
/*打开关联设备*/
const openCriticalComponentDialog = async () => {

@ -347,7 +347,7 @@ const updatePlanTableMaxHeight = async () => {
const availableHeight = window.innerHeight - tableTop - paginationHeight - pageBottomGap
planTableMaxHeight.value = Math.min(window.innerHeight, Math.max(240, Math.floor(availableHeight)))
}
const inspectableMap = reactive<Record<number, boolean | undefined>>({})
const inspectableMap = reactive<Record<string, boolean | undefined>>({})
type LineChangeRouteItem = PlanProcessRouteItemVO & {
planProcessRouteItemId?: number | string
originalDeviceId?: number | string
@ -669,7 +669,7 @@ const openZjTaskForm = (row: PlanVO) => {
const refreshInspectableMap = async (rows: PlanVO[]) => {
const ids = rows
.filter((row) => row?.id && String(row.status) === '6')
.map((row) => row.id as number)
.map((row) => row.id as string)
const idSet = new Set(ids)
for (const key of Object.keys(inspectableMap)) {
const id = Number(key)

@ -386,7 +386,7 @@ const hydrateCustomerName = async () => {
const customerId = formData.value.customerId
if (!customerId || formData.value.customerName) return
try {
const customer = await CustomerApi.getCustomer(Number(customerId))
const customer = await CustomerApi.getCustomer(String(customerId))
formData.value.customerName = getCustomerName(customer)
} catch {}
}

@ -297,7 +297,7 @@ const handleDelete = async (id: number) => {
}
const handleSelectionChange = (rows: ZjTaskVO[]) => {
selectedIds.value = (rows.map((row) => row.id).filter((id) => id !== undefined && id !== null) as number[])
selectedIds.value = (rows.map((row) => row.id).filter((id) => id !== undefined && id !== null) as string[])
}
const handleBatchCancel = async () => {

Loading…
Cancel
Save