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;
|
}
|
}
|