diff --git a/backend/src/controllers/equipmentController.ts b/backend/src/controllers/equipmentController.ts index 8ed74c4..350b34b 100644 --- a/backend/src/controllers/equipmentController.ts +++ b/backend/src/controllers/equipmentController.ts @@ -64,6 +64,34 @@ const includeStorageLocation = { } } +const EQUIPMENT_UPDATE_FIELD_LABELS: Record = { + equipment_code: '资产编码', + equipment_name: '资产名称', + equipment_model: '资产型号', + equipment_type: '资产类型', + asset_type_id: '资产分类', + unit_price: '单价', + total_quantity: '库存总数量', + purchase_date: '采购日期', + supplier: '供应商', + description: '资产描述', + storage_location_id: '存放地址' +} + +const buildEquipmentUpdateOperationDetails = ( + currentEquipment: Record, + updateData: Record +) => { + const changedFields = Object.keys(EQUIPMENT_UPDATE_FIELD_LABELS).filter((field) => + Object.prototype.hasOwnProperty.call(updateData, field) + ) + return `直接维护资产资料:${changedFields.map((field) => { + const before = currentEquipment[field] ?? '-' + const after = updateData[field] ?? '-' + return `${EQUIPMENT_UPDATE_FIELD_LABELS[field]} ${before} → ${after}` + }).join(';')}` +} + const activeBorrowSelect = { borrow_records: { where: { @@ -1334,6 +1362,19 @@ export const updateEquipment = async (req: Request, res: Response) => { await refreshParentTotalValueWithChildren(tx, currentEquipment.parent_id) } + const operator = res.locals.user + await tx.operationLog.create({ + data: { + user_id: operator?.id || null, + username: operator?.username || operator?.name || '未知用户', + operation_type: 'asset_basic_update', + equipment_id: currentEquipment.id, + equipment_code: currentEquipment.equipment_code, + operation_details: buildEquipmentUpdateOperationDetails(currentEquipment, updateData), + ip_address: req.ip || null + } + }) + return true }) diff --git a/backend/src/utils/__tests__/permissions.test.ts b/backend/src/utils/__tests__/permissions.test.ts index 2a56874..19e8308 100644 --- a/backend/src/utils/__tests__/permissions.test.ts +++ b/backend/src/utils/__tests__/permissions.test.ts @@ -21,8 +21,9 @@ test('行政可以登记和审批但不能借还、调拨或挂载', () => { assert.ok(!permissions.includes(PERMISSIONS.ASSETS_MOUNT)) }) -test('IT可以流转、发起报废和盘点,但不能审批或管理用户', () => { +test('IT可以直接维护资产资料、流转、发起报废和盘点,但不能审批或管理用户', () => { const permissions = getPermissionsForRole('it') + assert.ok(permissions.includes(PERMISSIONS.ASSETS_CORRECT)) assert.ok(permissions.includes(PERMISSIONS.ASSETS_BORROW)) assert.ok(permissions.includes(PERMISSIONS.ASSETS_TRANSFER)) assert.ok(permissions.includes(PERMISSIONS.ASSETS_PRINT_LABELS)) diff --git a/backend/src/utils/permissions.ts b/backend/src/utils/permissions.ts index a3743a3..4dc7539 100644 --- a/backend/src/utils/permissions.ts +++ b/backend/src/utils/permissions.ts @@ -45,6 +45,7 @@ const ROLE_PERMISSIONS: Record = { ], it: [ PERMISSIONS.ASSETS_VIEW_ALL, + PERMISSIONS.ASSETS_CORRECT, PERMISSIONS.ASSETS_BORROW, PERMISSIONS.ASSETS_TRANSFER, PERMISSIONS.ASSETS_MAINTENANCE, diff --git a/frontend/src/views/equipment/EquipmentForm.vue b/frontend/src/views/equipment/EquipmentForm.vue index 913410b..51dae88 100644 --- a/frontend/src/views/equipment/EquipmentForm.vue +++ b/frontend/src/views/equipment/EquipmentForm.vue @@ -71,7 +71,12 @@
-