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.bean.tenant.system.SystemForm; import com.changhong.epc.form.service.budget.tool.UpdateBudgetFactory; import com.changhong.epc.form.service.budget.tool.entity.UpdateBudgetEntity; import com.codingapi.tx.annotation.TxTransaction; import com.iemsoft.framework.cloud.core.thread.Keys; import com.iemsoft.framework.cloud.core.thread.ThreadData; import com.iemsoft.framework.cloud.core.tools.Assert; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.ModelMap; import java.util.Date; import java.util.Map; import java.util.Objects; /** * 还款 * @author DELL * */ @Service(UpdateBudgetFactory.AMOUNT_TYPE) @Slf4j @Scope("prototype") public class AmountRepaymentupdate extends AbstractUpdateBudget{ @Override public void checkBudget(UpdateBudgetEntity updateBudgetEntity) { log.debug("开始执行还款:————->"); //还款单主表数据 Map repMap = getFormInfo(updateBudgetEntity); //借款单dataRowNum Integer amDataRowNum = Integer.parseInt(Objects.toString(repMap.get(REPAYMENT_SUPER_LOAN),"0")); //本次还款金额 Double currMoney = tB(repMap.get(AMOUNT_REPAYMENT)); //借款单主表id String formId = getFormId(SystemForm.LOAN_FORM_ID); UpdateBudgetEntity amUpdate = new UpdateBudgetEntity(); amUpdate.setDataRowNum(amDataRowNum); amUpdate.setFormId(formId); //还款单主表数据 Map amMap = getFormInfo(amUpdate); log.debug("判断还款金额是否超出?-"); Assert.condition(tB(amMap.get(OUTSTANDING_AMOUNT)) < currMoney, ALREADY_REPAID_OUT); } /** * 执行还款 */ @Override @TxTransaction @Transactional public void updateBudget(UpdateBudgetEntity updateBudgetEntity) { log.debug("开始执行还款:————->"); //还款单主表数据 Map repMap = getFormInfo(updateBudgetEntity); //借款单dataRowNum Integer amDataRowNum = Integer.parseInt(Objects.toString(repMap.get(REPAYMENT_SUPER_LOAN),"0")); //本次还款金额 Double currMoney = tB(repMap.get(AMOUNT_REPAYMENT)); //借款单主表id String formId = getFormId(SystemForm.LOAN_FORM_ID); UpdateBudgetEntity amUpdate = new UpdateBudgetEntity(); amUpdate.setDataRowNum(amDataRowNum); amUpdate.setFormId(formId); //还款单主表数据 Map amMap = getFormInfo(amUpdate); log.debug("判断还款金额是否超出?-"); Assert.condition(tB(amMap.get(OUTSTANDING_AMOUNT)) < currMoney, ALREADY_REPAID_OUT); log.debug("本次还款金额{}:{}", currMoney,amMap.get(ALREADY_REPAID)); /** * 还款没有预算id * 原始内容:未款款金额 * */ BudgetLog budgetLog = new BudgetLog(); //原始内容 budgetLog.setOriginalText(tB(amMap.get(OUTSTANDING_AMOUNT)).toString()); budgetLog.setUpdateDate(new Date()); //变更内容 String updateText=Objects.toString(tB(amMap.get(OUTSTANDING_AMOUNT))-currMoney,"0"); budgetLog.setUpdateText(updateText); budgetLog.setUpdateType(BudgetUpdateType.MONEY); budgetLog.setUpdateSourceType(FormType.HK); //来源表单id : 还款单id budgetLog.setUpdateSourceFormid(updateBudgetEntity.getFormId()); budgetLog.setUpdateSourceId(Integer.parseInt(Objects.toString(repMap.get(DATAROWNUMBER),"0"))); budgetLog.setUpdateSourceText(currMoney.toString()); addBudgetLog(budgetLog); updateData(formId, null, amDataRowNum, new ModelMap(OUTSTANDING_AMOUNT,format(tB(amMap.get(OUTSTANDING_AMOUNT))-currMoney,getFormBase(formId),OUTSTANDING_AMOUNT)) .addAttribute(ALREADY_REPAID, format(tB(amMap.get(ALREADY_REPAID))+currMoney,getFormBase(formId),ALREADY_REPAID)) ); } @Override public void flowAfterCall(UpdateBudgetEntity updateBudgetEntity) { //记账 account(updateBudgetEntity.getFormId(), ThreadData.get(Keys.TENANT_ID), Objects.toString(updateBudgetEntity.getDataRowNum(), "")); } @Override public void rollback(UpdateBudgetEntity updateBudgetEntity) { } @Override public FormType getFormType() { return FormType.HK; } public Double tB(Object o){ return Double.parseDouble(Objects.toString(o,"0")); } }