7 changed files with 297 additions and 63 deletions
@ -0,0 +1,173 @@ |
|||||
|
package com.demo; |
||||
|
|
||||
|
import com.demo.cost.TbsMapper; |
||||
|
import com.demo.cost.entity.*; |
||||
|
import com.demo.jsl.entity.user.JslUser; |
||||
|
import com.demo.util.SqlCreateUtil; |
||||
|
import lombok.SneakyThrows; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.noear.wood.DbContext; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.sql.SQLException; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/3/22 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
public class Application4 { |
||||
|
|
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
new Application4().test(); |
||||
|
} |
||||
|
|
||||
|
@SneakyThrows |
||||
|
public void test(){ |
||||
|
String sql = "select a.* from tbs_activity a left join temp_id_costapply c on c.id = a.activity_code " + |
||||
|
"where c.id is not null and a.finished_flag = 0 and year(a.act_start_date) >= 2021"; |
||||
|
|
||||
|
DbContext jslContext = TbsMapper.getJslDbContext(); |
||||
|
List<JslTbsActivity> activityList = jslContext.sql(sql).getList(JslTbsActivity.class); |
||||
|
|
||||
|
for(JslTbsActivity tbsActivity:activityList){ |
||||
|
String sql_budget_cost_item = "select * from tbs_budget_cost_item where activity_id = ?"; |
||||
|
JslTbsBudgetCostItem currCostItem = jslContext.sql(sql_budget_cost_item, tbsActivity.getId()).getItem(JslTbsBudgetCostItem.class); |
||||
|
if (currCostItem == null || currCostItem.getId() == null) { |
||||
|
System.out.println("没有命中核销的费用id:" + tbsActivity.getCostApplyId() + " 活动id:"+tbsActivity.getId()); |
||||
|
continue; |
||||
|
} |
||||
|
String sql_cost_list = "select * from tbs_cost_apply where xlt_sync = 2 and id = ?"; |
||||
|
JslTbsCostApply costApply = jslContext.sql(sql_cost_list,tbsActivity.getCostApplyId()).getItem(JslTbsCostApply.class); |
||||
|
if(costApply==null){ |
||||
|
System.out.println("没有费用申请id:" + tbsActivity.getCostApplyId() + " 活动id:"+tbsActivity.getId()); |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
JslTbsActivity updAct = new JslTbsActivity(); |
||||
|
BigDecimal totalReleaseAmt = tbsActivity.getTotalAmount(); |
||||
|
updAct.setActivityState(4); |
||||
|
updAct.setReleaseFlag(1); |
||||
|
updAct.setFinishedFlag(1); |
||||
|
updAct.setReleaseUserId("0"); |
||||
|
updAct.setReleaseUserName("系统导入"); |
||||
|
updAct.setReleaseTime(tbsActivity.getCreateTime()); |
||||
|
updAct.setReleaseAmount(totalReleaseAmt); |
||||
|
this.doNotAllowCost(currCostItem, totalReleaseAmt, jslContext, costApply, tbsActivity, totalReleaseAmt); |
||||
|
String sql_update_act_info = SqlCreateUtil.buildUpdateSql(updAct, "tbs_activity") + " where id = " + tbsActivity.getId(); |
||||
|
jslContext.sql(sql_update_act_info).execute(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @param totalReleaseAmt |
||||
|
* @param jslDbContext |
||||
|
* @param costApply |
||||
|
* @param tbsActivity |
||||
|
* @param totalApplyAmt |
||||
|
* @throws SQLException |
||||
|
*/ |
||||
|
private void doNotAllowCost(JslTbsBudgetCostItem currCostItem, BigDecimal totalReleaseAmt, DbContext jslDbContext, JslTbsCostApply costApply, JslTbsActivity tbsActivity, BigDecimal totalApplyAmt) throws SQLException { |
||||
|
//插入日志流水
|
||||
|
JslVtbFundFlow fundFlow = new JslVtbFundFlow(); |
||||
|
fundFlow.setFundType("release"); |
||||
|
fundFlow.setVerificationId(0L); |
||||
|
fundFlow.setCenterGoodsCode(tbsActivity.getActivityCode() + "_00"); |
||||
|
fundFlow.setCostApplyId(tbsActivity.getCostApplyId()); |
||||
|
fundFlow.setActivityId(tbsActivity.getId()); |
||||
|
fundFlow.setUsedAmount(totalReleaseAmt); |
||||
|
fundFlow.setSupplierId(tbsActivity.getSupplierId()); |
||||
|
fundFlow.setSupplierCode(tbsActivity.getSupplierCode()); |
||||
|
fundFlow.setSupplierName(tbsActivity.getSupplierName()); |
||||
|
fundFlow.setTenantId("001"); |
||||
|
|
||||
|
fundFlow.setSubjectId(0L); |
||||
|
fundFlow.setSubjectCode(""); |
||||
|
fundFlow.setSubjectName(""); |
||||
|
|
||||
|
fundFlow.setCenterType(currCostItem.getCenterType()); |
||||
|
fundFlow.setCenterId(currCostItem.getCenterId()); |
||||
|
fundFlow.setCenterCode(currCostItem.getCenterCode()); |
||||
|
fundFlow.setCenterName(currCostItem.getCenterName()); |
||||
|
|
||||
|
fundFlow.setTargetType(currCostItem.getTargetType()); |
||||
|
fundFlow.setTargetId(currCostItem.getTargetId()); |
||||
|
fundFlow.setTargetCode(currCostItem.getTargetCode()); |
||||
|
fundFlow.setTargetName(currCostItem.getTargetName()); |
||||
|
fundFlow.setTargetLevelPathIds(currCostItem.getTargetLevelPathIds()); |
||||
|
fundFlow.setTargetLevelPathNames(currCostItem.getTargetLevelPathNames()); |
||||
|
fundFlow.setCenterGoodItemId(currCostItem.getId()); |
||||
|
|
||||
|
fundFlow.setSupplierId(tbsActivity.getSupplierId()); |
||||
|
fundFlow.setSupplierCode(tbsActivity.getSupplierCode()); |
||||
|
fundFlow.setSupplierName(tbsActivity.getSupplierName()); |
||||
|
|
||||
|
// batchVtbFlowList.add(fundFlow);
|
||||
|
|
||||
|
jslDbContext.table("vtb_fund_flow").setEntity(fundFlow).insert(); |
||||
|
|
||||
|
|
||||
|
String sql_budget_by_ids = "select * from tbs_budget where id = " + currCostItem.getBudgetId(); |
||||
|
JslTbsBudget currentBudget = jslDbContext.sql(sql_budget_by_ids).getItem(JslTbsBudget.class); |
||||
|
|
||||
|
JslUser jslUser = new JslUser(); |
||||
|
jslUser.setId("0"); |
||||
|
jslUser.setCode("0"); |
||||
|
jslUser.setName("系统导入"); |
||||
|
|
||||
|
JslTbsBudgetLog budgetLog = this.buildTbsBudgetLog(4, jslUser, costApply, currCostItem, currentBudget, totalReleaseAmt, tbsActivity); |
||||
|
budgetLog.setTenantId("001"); |
||||
|
jslDbContext.table("tbs_budget_log").setEntity(budgetLog).insert(); |
||||
|
|
||||
|
// batchBudgetLogList.add(budgetLog);
|
||||
|
} |
||||
|
|
||||
|
public JslTbsBudgetLog buildTbsBudgetLog(Integer optType, JslUser sysUser, JslTbsCostApply costApply, |
||||
|
JslTbsBudgetCostItem item, JslTbsBudget budget, BigDecimal amount, JslTbsActivity activity) { |
||||
|
BigDecimal amountAmt = amount; |
||||
|
if (amountAmt.compareTo(BigDecimal.ZERO) <= 0) { |
||||
|
amountAmt = amountAmt.negate(); |
||||
|
} |
||||
|
JslTbsBudgetLog budgetLog = new JslTbsBudgetLog(); |
||||
|
budgetLog.setBudgetId(item.getBudgetId()); |
||||
|
budgetLog.setBudgetCode(budget.getBudgetCode()); |
||||
|
budgetLog.setOptType(optType); |
||||
|
budgetLog.setOptUserId(sysUser.getId()); |
||||
|
budgetLog.setOptUserCode(sysUser.getCode()); |
||||
|
budgetLog.setOptUserName(sysUser.getName()); |
||||
|
budgetLog.setAmount(amountAmt); |
||||
|
budgetLog.setScheduleId(item.getScheduleId()); |
||||
|
budgetLog.setScheduleItemId(item.getScheduleItemId()); |
||||
|
budgetLog.setScheduleItemBudgetId(item.getScheduleItemBudgetId()); |
||||
|
budgetLog.setItemName(item.getScheduleItemName()); |
||||
|
budgetLog.setStartDate(item.getActStartDate().atStartOfDay()); |
||||
|
budgetLog.setEndDate(item.getActEndDate().atStartOfDay()); |
||||
|
budgetLog.setSubjectId(item.getSubjectId()); |
||||
|
budgetLog.setSubjectCode(item.getSubjectCode()); |
||||
|
budgetLog.setSubjectName(item.getSubjectName()); |
||||
|
budgetLog.setCenterId(item.getCenterId()); |
||||
|
budgetLog.setCenterCode(item.getCenterCode()); |
||||
|
budgetLog.setCenterName(item.getCenterName()); |
||||
|
budgetLog.setCenterType(item.getCenterType()); |
||||
|
budgetLog.setSupplierId(item.getSupplierId()); |
||||
|
budgetLog.setSupplierCode(item.getSupplierCode()); |
||||
|
budgetLog.setSupplierName(item.getSupplierName()); |
||||
|
budgetLog.setActivityId(item.getActivityId()); |
||||
|
budgetLog.setActivityCode(item.getActivityCode()); |
||||
|
budgetLog.setActivityTheme(activity.getActTitle()); |
||||
|
budgetLog.setCostApplyId(costApply.getId()); |
||||
|
budgetLog.setCostApplyCode(costApply.getCode()); |
||||
|
budgetLog.setCostApplyTheme(costApply.getChargeTheme()); |
||||
|
budgetLog.setTargetType(item.getTargetType()); |
||||
|
budgetLog.setTargetId(item.getTargetId()); |
||||
|
budgetLog.setTargetCode(item.getTargetCode()); |
||||
|
budgetLog.setTargetName(item.getTargetName()); |
||||
|
budgetLog.setTargetLevelPathIds(item.getTargetLevelPathIds()); |
||||
|
budgetLog.setTargetLevelPathNames(item.getTargetLevelPathNames()); |
||||
|
return budgetLog; |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue