瑞利声电固定资产管理系统
ycq
2026-10-16 dbbadb021c2fc171466cc82bd9a7a82cc47165f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
package zbooksoft.fams.delegate;
 
import com.ruili.wcp.common.SpringContextUtil;
import com.ruili.wcp.data.entity.management.User;
import com.ruili.wcp.web.model.AjaxResponse;
import com.ruili.wcp.web.model.ErrorInfo;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zbooksoft.fams.common.BusinessException;
import zbooksoft.fams.service.AssetApplyService;
import zbooksoft.fams.service.AssetBaseService;
import zbooksoft.fams.service.LabelService;
import zbooksoft.fams.service.PurchaseService;
import zbooksoft.fams.service.RemindService;
 
import java.util.ArrayList;
import java.util.Map;
 
/**
 * FAMS全部平台扩展点方法(表单保存前后事件、列表/表单按钮插件),由平台按“类名.方法名”反射调用,不是Spring Bean
 * @author ycq
 * @date 2026-10-16
 */
public class FamsPublicOperations {
 
    private static final Logger LOGGER = LoggerFactory.getLogger(FamsPublicOperations.class);
 
    private static final String SESSION_USER_KEY = "user";
 
    /**
     * 资产类别保存前事件
     * @param formId 表单ID
     * @param keyId 数据ID,新增时为0
     * @param formData 表单数据
     * @return 校验不通过返回失败的AjaxResponse,平台据此中断保存
     */
    public AjaxResponse beforeSaveCategory(Long formId, Long keyId, Map<String, Object> formData) {
        try {
            assetBaseService().prepareCategory(keyId, formData);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 资产类别保存后事件
     * @param formId 表单ID
     * @param keyId 已保存的数据ID
     * @param formData 表单数据
     * @return 成功返回AjaxResponse(true)
     */
    public AjaxResponse afterSaveCategory(Long formId, Long keyId, Map<String, Object> formData) {
        assetBaseService().syncCategoryTop(keyId);
        return new AjaxResponse(true);
    }
 
    /**
     * 存放位置保存前事件
     * @param formId 表单ID
     * @param keyId 数据ID,新增时为0
     * @param formData 表单数据
     * @return 校验不通过返回失败的AjaxResponse,平台据此中断保存
     */
    public AjaxResponse beforeSaveLocation(Long formId, Long keyId, Map<String, Object> formData) {
        try {
            assetBaseService().prepareLocation(keyId, formData);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 存放位置保存后事件
     * @param formId 表单ID
     * @param keyId 已保存的数据ID
     * @param formData 表单数据
     * @return 成功返回AjaxResponse(true)
     */
    public AjaxResponse afterSaveLocation(Long formId, Long keyId, Map<String, Object> formData) {
        assetBaseService().refreshLocationDescendants(keyId);
        return new AjaxResponse(true);
    }
 
    /**
     * 资产卡片保存前事件
     * @param formId 表单ID
     * @param keyId 数据ID,新增时为0
     * @param formData 表单数据
     * @return 校验不通过返回失败的AjaxResponse,平台据此中断保存
     */
    public AjaxResponse beforeSaveCard(Long formId, Long keyId, Map<String, Object> formData) {
        try {
            assetBaseService().prepareCard(keyId, formData);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 资产卡片保存后事件
     * @param formId 表单ID
     * @param keyId 已保存的数据ID
     * @param formData 表单数据
     * @return 成功返回AjaxResponse(true)
     */
    public AjaxResponse afterSaveCard(Long formId, Long keyId, Map<String, Object> formData) {
        User user = currentUser();
        assetBaseService().recordCardInbound(keyId, formData, user == null ? null : user.getUserId(), user == null ? "" : user.getTrueName());
        return new AjaxResponse(true);
    }
 
    /**
     * 资产卡片Excel导入后事件(平台以无参方法调用):补全类别/部门/人员/位置ID并生成编号
     */
    public void afterImportCards() {
        User user = currentUser();
        int[] result = assetBaseService().completeImportedCards(user == null ? null : user.getUserId(), user == null ? "" : user.getTrueName());
        LOGGER.info("资产卡片导入后补全完成:成功编号{}条,待处理{}条", result[0], result[1]);
    }
 
    /**
     * 标签模板保存前事件
     * @param formId 表单ID
     * @param keyId 数据ID,新增时为0
     * @param formData 表单数据
     * @return 校验不通过返回失败的AjaxResponse,平台据此中断保存
     */
    public AjaxResponse beforeSaveLabelTemplate(Long formId, Long keyId, Map<String, Object> formData) {
        try {
            labelService().prepareTemplate(formData);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 标签模板保存后事件
     * @param formId 表单ID
     * @param keyId 已保存的数据ID
     * @param formData 表单数据
     * @return 成功返回AjaxResponse(true)
     */
    public AjaxResponse afterSaveLabelTemplate(Long formId, Long keyId, Map<String, Object> formData) {
        labelService().keepSingleDefault(keyId);
        return new AjaxResponse(true);
    }
 
    /**
     * 资产使用流程单据(借用/调配/闲置退还/封存解封/维修/报废)保存前事件,单据类型按表单主表确定
     * @param formId 表单ID
     * @param keyId 数据ID,新增时为0
     * @param formData 表单数据
     * @return 校验不通过返回失败的AjaxResponse,平台据此中断保存
     */
    public AjaxResponse beforeSaveBill(Long formId, Long keyId, Map<String, Object> formData) {
        try {
            AssetApplyService service = assetApplyService();
            User user = currentUser();
            service.prepareBill(service.typeOfForm(formId), keyId, formData,
                    user == null ? null : user.getUserId(), user == null ? "" : user.getTrueName(),
                    user == null ? null : user.getDeptId(), user == null ? "" : user.getDeptName());
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 资产使用流程单据列表删除前事件:只允许删除草稿或已终止的单据
     * @param viewId 视图ID
     * @param idList 选中的单据ID
     * @return 有不可删除的单据时返回失败
     */
    public AjaxResponse beforeDeleteBill(Long viewId, ArrayList<Long> idList) {
        try {
            AssetApplyService service = assetApplyService();
            service.checkDeletable(service.typeOfView(viewId), idList);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 借用单列表按钮「确认归还」
     * @param viewId 视图ID
     * @param idList 选中的借用单ID
     * @return 处理结果
     */
    public AjaxResponse returnBorrow(Long viewId, ArrayList<Long> idList) {
        try {
            User user = currentUser();
            int count = assetApplyService().returnBorrow(idList, user == null ? null : user.getUserId(), user == null ? "" : user.getTrueName());
            return new AjaxResponse((Object) ("已归还 " + count + " 件资产"));
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 维修单列表按钮「维修完成」
     * @param viewId 视图ID
     * @param idList 选中的维修单ID
     * @return 处理结果
     */
    public AjaxResponse completeRepair(Long viewId, ArrayList<Long> idList) {
        try {
            User user = currentUser();
            int count = assetApplyService().completeRepair(idList, user == null ? null : user.getUserId(), user == null ? "" : user.getTrueName());
            return new AjaxResponse((Object) ("已恢复 " + count + " 件资产"));
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    // ---------------- 采购申请 / 采购明细 ----------------
 
    /**
     * 采购申请保存前事件
     * @param formId 表单ID
     * @param keyId 数据ID,新增时为0
     * @param formData 表单数据
     * @return 校验不通过返回失败的AjaxResponse
     */
    public AjaxResponse beforeSavePurchase(Long formId, Long keyId, Map<String, Object> formData) {
        try {
            User user = currentUser();
            purchaseService().preparePurchase(keyId, formData, user == null ? null : user.getUserId(), user == null ? "" : user.getTrueName(),
                    user == null ? null : user.getDeptId(), user == null ? "" : user.getDeptName());
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 采购申请列表删除前事件:只允许草稿或已终止,并删除其明细
     * @param viewId 视图ID
     * @param idList 选中的采购申请ID
     * @return 有不可删除的单据时返回失败
     */
    public AjaxResponse beforeDeletePurchase(Long viewId, ArrayList<Long> idList) {
        try {
            purchaseService().deletePurchases(idList);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 采购明细保存前事件
     * @param formId 表单ID
     * @param keyId 数据ID,新增时为0
     * @param formData 表单数据
     * @return 校验不通过返回失败的AjaxResponse
     */
    public AjaxResponse beforeSavePurchaseItem(Long formId, Long keyId, Map<String, Object> formData) {
        try {
            purchaseService().preparePurchaseItem(keyId, formData);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 采购明细保存后事件:刷新采购申请合计
     * @param formId 表单ID
     * @param keyId 已保存的数据ID
     * @param formData 表单数据
     * @return 成功返回AjaxResponse(true)
     */
    public AjaxResponse afterSavePurchaseItem(Long formId, Long keyId, Map<String, Object> formData) {
        purchaseService().afterSavePurchaseItem(keyId);
        return new AjaxResponse(true);
    }
 
    /**
     * 采购明细列表删除前事件:所属采购申请须为草稿
     * @param viewId 视图ID
     * @param idList 选中的明细ID
     * @return 不可删除时返回失败
     */
    public AjaxResponse beforeDeletePurchaseItem(Long viewId, ArrayList<Long> idList) {
        try {
            purchaseService().checkPurchaseItemsDeletable(idList);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    // ---------------- 到货入库单 / 入库明细 ----------------
 
    /**
     * 到货入库单保存前事件
     * @param formId 表单ID
     * @param keyId 数据ID,新增时为0
     * @param formData 表单数据
     * @return 校验不通过返回失败的AjaxResponse
     */
    public AjaxResponse beforeSaveReceipt(Long formId, Long keyId, Map<String, Object> formData) {
        try {
            User user = currentUser();
            purchaseService().prepareReceipt(keyId, formData, user == null ? null : user.getUserId(), user == null ? "" : user.getTrueName());
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 到货入库单保存后事件:首次保存时按采购申请生成入库明细
     * @param formId 表单ID
     * @param keyId 已保存的数据ID
     * @param formData 表单数据
     * @return 成功返回AjaxResponse(true)
     */
    public AjaxResponse afterSaveReceipt(Long formId, Long keyId, Map<String, Object> formData) {
        purchaseService().afterSaveReceipt(keyId);
        return new AjaxResponse(true);
    }
 
    /**
     * 到货入库单列表删除前事件:只允许草稿,并删除其明细
     * @param viewId 视图ID
     * @param idList 选中的入库单ID
     * @return 有不可删除的单据时返回失败
     */
    public AjaxResponse beforeDeleteReceipt(Long viewId, ArrayList<Long> idList) {
        try {
            purchaseService().deleteReceipts(idList);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 入库明细保存前事件
     * @param formId 表单ID
     * @param keyId 数据ID,新增时为0
     * @param formData 表单数据
     * @return 校验不通过返回失败的AjaxResponse
     */
    public AjaxResponse beforeSaveReceiptItem(Long formId, Long keyId, Map<String, Object> formData) {
        try {
            purchaseService().prepareReceiptItem(keyId, formData);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 入库明细保存后事件:刷新入库单合计
     * @param formId 表单ID
     * @param keyId 已保存的数据ID
     * @param formData 表单数据
     * @return 成功返回AjaxResponse(true)
     */
    public AjaxResponse afterSaveReceiptItem(Long formId, Long keyId, Map<String, Object> formData) {
        purchaseService().afterSaveReceiptItem(keyId);
        return new AjaxResponse(true);
    }
 
    /**
     * 入库明细列表删除前事件:所属入库单须为草稿
     * @param viewId 视图ID
     * @param idList 选中的明细ID
     * @return 不可删除时返回失败
     */
    public AjaxResponse beforeDeleteReceiptItem(Long viewId, ArrayList<Long> idList) {
        try {
            purchaseService().checkReceiptItemsDeletable(idList);
            return new AjaxResponse(true);
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    /**
     * 到货入库单列表按钮「确认入库」:按合格明细生成资产卡片
     * @param viewId 视图ID
     * @param idList 选中的入库单ID
     * @return 处理结果
     */
    public AjaxResponse confirmReceipt(Long viewId, ArrayList<Long> idList) {
        try {
            User user = currentUser();
            int count = purchaseService().confirmReceipts(idList, user == null ? null : user.getUserId(), user == null ? "" : user.getTrueName());
            return new AjaxResponse((Object) ("已入库,生成资产卡片 " + count + " 张"));
        } catch (BusinessException e) {
            return fail(e);
        }
    }
 
    // ---------------- 到期提醒 ----------------
 
    /**
     * 到期提醒列表按钮「标记已处理」
     * @param viewId 视图ID
     * @param idList 选中的提醒ID
     * @return 处理结果
     */
    public AjaxResponse handleReminds(Long viewId, ArrayList<Long> idList) {
        User user = currentUser();
        int count = remindService().handle(idList, user == null ? "" : user.getTrueName());
        return new AjaxResponse((Object) ("已标记 " + count + " 条提醒为已处理"));
    }
 
    /**
     * 到期提醒列表按钮「立即检查」:不等定时任务,马上扫描一次
     * @param viewId 视图ID
     * @param idList 未使用
     * @return 扫描结果
     */
    public AjaxResponse runRemindScan(Long viewId, ArrayList<Long> idList) {
        RemindService service = remindService();
        Map<String, Integer> result = service.scan(java.time.LocalDate.now(), service.daysAhead());
        return new AjaxResponse((Object) ("检查完成:新增提醒 " + result.get("created") + " 条,刷新 " + result.get("updated")
                + " 条,失效 " + result.get("expired") + " 条"));
    }
 
    private static RemindService remindService() {
        return (RemindService) SpringContextUtil.getBean(RemindService.class);
    }
 
    private static PurchaseService purchaseService() {
        return (PurchaseService) SpringContextUtil.getBean(PurchaseService.class);
    }
 
    private static AssetApplyService assetApplyService() {
        return (AssetApplyService) SpringContextUtil.getBean(AssetApplyService.class);
    }
 
    private static LabelService labelService() {
        return (LabelService) SpringContextUtil.getBean(LabelService.class);
    }
 
    private static AssetBaseService assetBaseService() {
        return (AssetBaseService) SpringContextUtil.getBean(AssetBaseService.class);
    }
 
    private static AjaxResponse fail(BusinessException e) {
        LOGGER.info("保存校验未通过:{}", e.getMessage());
        return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
    }
 
    private static User currentUser() {
        Object user = SecurityUtils.getSubject().getSession().getAttribute(SESSION_USER_KEY);
        return user instanceof User ? (User) user : null;
    }
}