package com.changhong.epc.form.service.budget.tool; import com.changhong.epc.bean.form.FormType; import com.changhong.epc.bean.tenant.cost.CostFromMapping; import com.changhong.epc.bean.tenant.system.SystemConfig; import com.changhong.epc.bean.tenant.system.SystemForm; import com.changhong.epc.constter.form.budget.BudgetMsg; import com.changhong.epc.form.service.budget.tool.entity.UpdateBudgetEntity; import com.changhong.epc.form.service.budget.tool.impl.ApplyBudgetUpdate; import com.changhong.epc.form.service.budget.tool.impl.AssetBudgetUpdate; import com.changhong.epc.form.service.budget.tool.impl.ContractInfoUpdate; import com.changhong.epc.form.service.budget.tool.impl.ExpendBudgetUpdate; import com.changhong.epc.rely.api.epc.tenant.CostFromMappingApi; import com.changhong.epc.rely.api.epc.tenant.SystemConfigApi; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; /** * 预算修改执行器 */ @Service @Slf4j public class UpdateBudgetFactory implements BudgetMsg { // 申请类型回写 public static final String SQ_TYPE = "applyDelBudget"; // 报销类型回写 public static final String BX_TYPE = "expendDelBudget"; // 预算类型扩展 public static final String YS_ADD_TYPE = "extendBudget"; // 预算类型回收 public static final String YS_DEL_TYPE = "recoveryBudget"; // 预算类型占用上级预算 public static final String YS_PARENT_TYPE = "parentBudget"; // 固定资产 public static final String ASSET_TYPE = "assetBudget"; // 合同报销 public static final String CONTRACT_TYPE = "contractBudget"; //合同信息 public static final String CONTRACT_INFO_TYPE = "contractInfo"; // 还款 public static final String AMOUNT_TYPE = "Amount"; //借款 public static final String BORROW_MONEY = "borrowMoney"; private static final Map FORM_MAPPING_BEANNAME = new HashMap<>(); static { FORM_MAPPING_BEANNAME.put(SystemForm.BUDGET_FORM_ID , YS_PARENT_TYPE); FORM_MAPPING_BEANNAME.put(SystemForm.EXTEND_BUDGET_FORM_ID , YS_ADD_TYPE); FORM_MAPPING_BEANNAME.put(SystemForm.RECOVERY_BUDGET_FORM_ID, YS_DEL_TYPE); FORM_MAPPING_BEANNAME.put(SystemForm.ASSET_EXPEND_FORM_ID , ASSET_TYPE); FORM_MAPPING_BEANNAME.put(SystemForm.CONTRACT_EXPEND_FORM_ID, CONTRACT_TYPE); FORM_MAPPING_BEANNAME.put(SystemForm.REPAYMENT_FORM_ID, AMOUNT_TYPE); FORM_MAPPING_BEANNAME.put(SystemForm.LOAN_FORM_ID,BORROW_MONEY); FORM_MAPPING_BEANNAME.put(SystemForm.CONTRACT_FORM_ID,CONTRACT_INFO_TYPE); FORM_MAPPING_BEANNAME.put(FormType.SQ , SQ_TYPE); FORM_MAPPING_BEANNAME.put(FormType.BX , BX_TYPE); } @Resource private SystemConfigApi systemConfigApi; @Resource private CostFromMappingApi costFromMappingApi; public boolean isAutoBudgetUpdate(IUpdateBudget iUpdateBudget){ return iUpdateBudget instanceof ApplyBudgetUpdate || iUpdateBudget instanceof AssetBudgetUpdate || iUpdateBudget instanceof ContractInfoUpdate || iUpdateBudget instanceof ExpendBudgetUpdate; } /** * 获得扣减预算类型 * @param updateBudgetEntity * @return */ public IUpdateBudget getIUpdateBudget(UpdateBudgetEntity updateBudgetEntity){ List systemConfigs = systemConfigApi.getSystemConfigs(new SystemConfig("formInfo")); for(SystemConfig systemConfig : systemConfigs){ if(Objects.equals(systemConfig.getCvalue(), updateBudgetEntity.getFormId())){ String beanName = FORM_MAPPING_BEANNAME.get(SystemForm.valueOf(systemConfig.getCkey())); if(ObjectUtil.notEmpty(beanName)){ IUpdateBudget iUpdateBudget = SpringUtil.getBean(beanName, IUpdateBudget.class); iUpdateBudget.setSystemFormInfo(systemConfigs); return iUpdateBudget; } } } List costFromMappings = getCostFromMappings(updateBudgetEntity); if(ObjectUtil.empty(costFromMappings)){ log.debug("未找到对应费用类型,formId={}, datarownum={}", updateBudgetEntity.getFormId(), updateBudgetEntity.getDataRowNum()); return null; } for (CostFromMapping cost: costFromMappings) { if(Objects.equals(cost.getFId(), updateBudgetEntity.getFormId())){ IUpdateBudget iUpdateBudget = SpringUtil.getBean( FORM_MAPPING_BEANNAME.get(FormType.valueOf(cost.getType())) , IUpdateBudget.class); iUpdateBudget.setCostFromMappings(costFromMappings); iUpdateBudget.setSystemFormInfo(systemConfigs); return iUpdateBudget; } } return null; } protected List getCostFromMappings(UpdateBudgetEntity updateBudgetEntity){ return costFromMappingApi.getConstFromMappings(updateBudgetEntity.getFormId()); } }