package com.changhong.epc.form.service.budget.tool.impl; import com.changhong.epc.bean.form.FormType; import com.changhong.epc.bean.tenant.log.BudgetLog; import com.changhong.epc.bean.tenant.log.BudgetUpdateType; import com.changhong.epc.form.mapper.tenant.log.BudgetLogMapper; import com.changhong.epc.form.service.budget.tool.entity.UpdateBudgetEntity; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import lombok.*; import org.apache.commons.lang3.math.NumberUtils; import javax.annotation.Resource; import java.util.Date; import java.util.Map; import java.util.Objects; /** * 添加预算log抽象类 */ public abstract class AbstractBudgetLog extends AbstractBudgetLock { @Resource private BudgetLogMapper budgetLogMapper; @Getter @Setter private boolean rollback; protected void addBudgetLogMoney(Map budgetSubInfo, double updateText, String sourceFormId, Map sourceInfo, double sourceText){ addBudgetLogMoney( getSubDataRowNum(budgetSubInfo) , getDataRowNum(budgetSubInfo) , Objects.toString(getBudgetBalance(budgetSubInfo), "") , String.valueOf(updateText) , new SourceBean(sourceFormId , getDataRowNum(sourceInfo) , null , getDataNumber(sourceInfo) , String.valueOf(sourceText) ) , new SourceBean() ); } protected void addParentBudgetLogMoney(Map budgetSubInfo, double updateText, String sourceFormId, Map sourceInfo, double sourceText){ addBudgetLogMoney( getSubDataRowNum(budgetSubInfo) , getDataRowNum(budgetSubInfo) , Objects.toString(getBudgetBalance(budgetSubInfo), "") , String.valueOf(updateText) , new SourceBean(sourceFormId , getSubDataRowNum(sourceInfo) , getDataRowNum(sourceInfo) , getDataNumber(sourceInfo) , String.valueOf(sourceText) ) , new SourceBean() ); } protected void addBudgetLogMoney(Map budgetSubInfo, double updateText , String sourceFormId, Map sourceInfo, double sourceText , String joinSourceFormId, Map joinSourceInfo, double joinSourceText){ addBudgetLogMoney( getSubDataRowNum(budgetSubInfo) , getDataRowNum(budgetSubInfo) , Objects.toString(getBudgetBalance(budgetSubInfo), "") , String.valueOf(updateText) , new SourceBean(sourceFormId , getDataRowNum(sourceInfo) , null , getDataNumber(sourceInfo) , String.valueOf(sourceText) ) , new SourceBean(joinSourceFormId , getDataRowNum(joinSourceInfo) , null , getDataNumber(joinSourceInfo) , String.valueOf(joinSourceText)) ); } protected void addBudgetLogMoney(Integer budgetId , Integer budgetChildId , String originalText , String updateText , SourceBean sourceBean , SourceBean joinSourceBean ){ addBudgetLog(BudgetUpdateType.MONEY, budgetId, budgetChildId, originalText, updateText , sourceBean, joinSourceBean); } protected void addBudgetLog(BudgetUpdateType budgetUpdateType , Integer budgetId , Integer budgetChildId , String originalText , String updateText , SourceBean sourceBean , SourceBean joinSourceBean ){ addBudgetLog(budgetUpdateType, getFormType(), budgetId, budgetChildId, originalText, updateText , sourceBean, joinSourceBean); } protected void addBudgetLog(BudgetUpdateType budgetUpdateType , FormType formType , Integer budgetId , Integer budgetChildId , String originalText , String updateText , SourceBean sourceBean , SourceBean joinSourceBean ){ BudgetLog budgetLog = new BudgetLog(); budgetLog.setBudgetId(budgetId); budgetLog.setBudgetChildId(budgetChildId); budgetLog.setOriginalText(originalText); budgetLog.setUpdateDate(new Date()); budgetLog.setUpdateText(updateText); budgetLog.setUpdateType(budgetUpdateType); budgetLog.setUpdateSourceFormid(sourceBean.getSourceFormid()); budgetLog.setUpdateSourceId(sourceBean.getSourceId()); budgetLog.setUpdateSourceChildId(sourceBean.getSourceChildId()); budgetLog.setUpdateSourceNumber(sourceBean.getSourceNumber()); budgetLog.setUpdateSourceText(sourceBean.getSourceText()); budgetLog.setUpdateSourceType(formType); budgetLog.setJoinSourceFormid(joinSourceBean.getSourceFormid()); budgetLog.setJoinSourceId(joinSourceBean.getSourceId()); budgetLog.setJoinSourceNumber(joinSourceBean.getSourceNumber()); budgetLog.setJoinSourceText(joinSourceBean.getSourceText()); addBudgetLog(budgetLog); } public void addBudgetLog(BudgetLog budgetLog){ budgetLog.initParam(); if(isRollback()){ budgetLog.setDataStart(1); } budgetLogMapper.insert(budgetLog); } /** * 获得数据上级id * @param data * @return */ protected Integer getSubDataRowNum(Map data){ return NumberUtils.createInteger( Objects.toString(data.get(SUNMDATAROWNUMBER), "0") ); } /** * 获得数据id * @param data * @return */ public static Integer getDataRowNum(Map data){ return NumberUtils.createInteger( Objects.toString(data.get(DATAROWNUMBER), "0") ); } public static String getDataNumber(Map data){ for(Map.Entry entry : data.entrySet()){ if(entry.getKey().matches("(?i)number.*")){ return Objects.toString(entry.getValue(), ""); } } return ""; } /** * 转换浮点类型 * @param obj * @return */ protected double toDouble(Object obj){ String money = Objects.toString(obj, "0"); if(!NumberUtils.isNumber(money)){ money = "0"; } return NumberUtils.createDouble(money); } /** * 获得关联控件id * @param formInfo * @return */ protected Integer getParentId(Map formInfo){ if(formInfo == null){ return null; } Object parentId = formInfo.get(TO_WRITE_BUDGET); if(ObjectUtil.empty(parentId)){ return null; } return NumberUtils.createInteger(parentId.toString()); } protected Object getBudgetBalance(Map data){ return data.get(BUDGET_ITEM_BALANCE); } @Override public void rollback(UpdateBudgetEntity updateBudgetEntity) { setRollback(true); } @Data @AllArgsConstructor @NoArgsConstructor public static class SourceBean{ /** * 来源表单id */ private String sourceFormid; /** * 来源id */ private Integer sourceId; /** * 来源子id */ private Integer sourceChildId; /** * 来源编号 */ private String sourceNumber; /** * 来源内容 */ private String sourceText; } }