Browse Source

同步核销

master
15989082884@163.com 2 years ago
parent
commit
4a04754ce9
  1. 2
      src/main/java/com/demo/Application.java
  2. 384
      src/main/java/com/demo/cost/SyncVerificationMain.java

2
src/main/java/com/demo/Application.java

@ -45,7 +45,7 @@ public class Application {
//
// //费用核销
SyncVerificationMain verificationMain = new SyncVerificationMain();
verificationMain.testMain();
verificationMain.formain();
////
//// //更新核销中的预算费用占用
// new SyncDiscountBudget().sync();

384
src/main/java/com/demo/cost/SyncVerificationMain.java

@ -33,6 +33,16 @@ public class SyncVerificationMain {
//update
private final String tbs_activity = "tbs_activity";
private static Long vtbId = 0L;
private static Long vtbSubId = 0L;
private static Long payMaxId = 0L;
private static List<VtbVerification> batchVtbVerificationList = new ArrayList<>();
private static List<VtbVerificationSubject> batchVtbVerificationSubjectList = new ArrayList<>();
private static List<JslVtbFundFlow> batchVtbFlowList = new ArrayList<>();
private static List<JslTbsBudgetLog> batchBudgetLogList = new ArrayList<>();
private static List<PayPayment> payPaymentList = new ArrayList<>();
private static List<PayPaymentItem> payPaymentItemList = new ArrayList<>();
@Test
@SneakyThrows
@ -76,31 +86,93 @@ public class SyncVerificationMain {
}
}
@SneakyThrows
private void getMaxVtbId() {
DbContext jslDbContext = TbsMapper.getJslDbContext();
String sql = "select max(id) as maxid from vtb_verification where id < 10450001 ";
Long maxid = (Long) jslDbContext.sql(sql).getMap().get("maxid");
this.vtbId = maxid;
}
@SneakyThrows
private void getMaxVtbSubId() {
DbContext jslDbContext = TbsMapper.getJslDbContext();
String sql = "select max(id) as maxid from vtb_verification_subject where id < 10455001 ";
Long maxid = (Long) jslDbContext.sql(sql).getMap().get("maxid");
this.vtbSubId = maxid;
}
@SneakyThrows
private void getMaxPayId() {
DbContext jslDbContext = TbsMapper.getJslDbContext();
String sql = "select max(id) as maxid from pay_payment where id < 11339001 ";
Long maxid = (Long) jslDbContext.sql(sql).getMap().get("maxid");
this.payMaxId = maxid;
}
@SneakyThrows
public void formain() {
DbContext jslDbContext = TbsMapper.getJslDbContext();
getMaxVtbId();
getMaxVtbSubId();
getMaxPayId();
if (vtbId == 0L || vtbId == 10450000L) {
return;
}
if (vtbSubId == 0L || vtbSubId == 10455000L) {
return;
}
if (payMaxId == 0L || payMaxId == 11339000L) {
return;
}
Integer count = 1;
while (count > 0) {
String sql_cost_list = "select * from tbs_cost_apply where xlt_sync = 2 and budget_sync = 1 and vtb_sync !=2 order by id desc limit 300";
List<JslTbsCostApply> costList = jslDbContext.sql(sql_cost_list).getList(JslTbsCostApply.class);
if (costList.size() > 0) {
try{
testMain();
}catch (Exception e){
e.printStackTrace();
}
}
count = costList.size();
}
}
@SneakyThrows
public void testMain() {
DbContext jslDbContext = TbsMapper.getJslDbContext();
DbContext xltDbContext = TbsMapper.getXltDbContext();
// xlt_sync = 2 同步申请预算完成
// 获取已同步的费用ID(未完成的)
// budget_sync=1 代表命中预算
// vtb_sync 0 未开始,1未完成 2->成功 4无核销
//String sql_cost_list ="select * from tbs_cost_apply where code = '202212301485' "; //测试
//String sql_cost_list ="select * from tbs_cost_apply where xlt_sync = 2 and budget_sync = 1 and (vtb_sync =0 or vtb_sync = 1)";
String sql_cost_list ="select * from tbs_cost_apply where xlt_sync = 2 and budget_sync = 1 and vtb_sync !=2 order by id desc";
if(SetData.startId!=null){
int startId = SetData.startId;
int endId = startId+1000;
sql_cost_list = "select * from tbs_cost_apply where xlt_sync = 2 and budget_sync = 1 and vtb_sync !=2 and id>="+startId+" and id <"+endId;
}
String sql_cost_list = "select * from tbs_cost_apply where xlt_sync = 2 and budget_sync = 1 and vtb_sync !=2 order by id desc limit 300";
// if(SetData.startId!=null){
// int startId = SetData.startId;
// int endId = startId+1000;
// sql_cost_list = "select * from tbs_cost_apply where xlt_sync = 2 and budget_sync = 1 and vtb_sync !=2 and id>="+startId+" and id <"+endId;
// }
System.out.println("执行命令:" + sql_cost_list);
List<JslTbsCostApply> costList = jslDbContext.sql(sql_cost_list).getList(JslTbsCostApply.class);
System.out.println("未完成数量:" + costList.size());
//移除历史同步失败的
List<String> errorCostIds = new ArrayList<>();
for (JslTbsCostApply costApply : costList) {
if(!costApply.getVtbSync().equals(0)){
// if (!costApply.getVtbSync().equals(0)) {
errorCostIds.add(costApply.getId() + "");
}
// }
}
this.removeCostIds(errorCostIds);
@ -152,7 +224,7 @@ public class SyncVerificationMain {
" ON clist.mainID = cmain.id " +
" WHERE " +
" cmain.state = '120' " +
" and clist.iscancel = '0' " +
" and clist.iscancel = '1' " +
" and clist.iszuofei != 1 " +
" AND oldlistnumber in ('" + tbsActivitiesCodes.stream().collect(Collectors.joining("','")) + "')";//活动id
@ -163,6 +235,10 @@ public class SyncVerificationMain {
// 获取活动列表(未释放,以及未完成的)
for (JslTbsCostApply costApply : costList) {
// List<String> errorCostIdRemove = new ArrayList<>();
// errorCostIdRemove.add(costApply.getId().toString());
//
// this.removeCostIds(errorCostIdRemove);
System.out.println(count + "/" + costList.size() + " [" + costApply.getId() + "]");
count++;
@ -176,11 +252,28 @@ public class SyncVerificationMain {
List<JslTbsActivity> tbsActivities = tbsActivitiesMap.get(costApply.getId());
boolean isOk = buildActivity(jslDbContext, xltDbContext, costApply, tbsActivities, checkCostItemListMap, checkCostItemListCancelMap);
//完成标记状态
if (isOk) {
insertBatchVtbVerification(batchVtbVerificationList);
insertBatchVtbVerificationSubject(batchVtbVerificationSubjectList);
insertBatchVtbFlow(batchVtbFlowList);
insertBatchBudgetLog(batchBudgetLogList);
insertBatchPayment(payPaymentList);
insertBatchPaymentItem(payPaymentItemList);
String sql_cost_sync_success = "update tbs_cost_apply set vtb_sync = 2 where id = ";
jslDbContext.sql(sql_cost_sync_success + costApply.getId()).execute();
}
batchVtbVerificationList = new ArrayList<>();
batchVtbVerificationSubjectList = new ArrayList<>();
batchVtbFlowList = new ArrayList<>();
batchBudgetLogList = new ArrayList<>();
payPaymentList = new ArrayList<>();
payPaymentItemList = new ArrayList<>();
}
}
@ -192,50 +285,12 @@ public class SyncVerificationMain {
continue;
}
String activityCode = tbsActivity.getActivityCode();
// 获取销路通核销明细
// String sql_xlt_check_cost =
// " SELECT oldlistnumber as activity_code," +
// " cmain.number_ AS main_number, " +
// " clist.listNumber as list_number, " +
// " clist.isYuEBuYuHeXiao not_allow_flag, " +
// " clist.pifumoney as apply_amt, " +
// " (cList.hexiaomoney + cList.shuiJin) check_pass_amt, " +
// " cList.exedate " +
// " FROM " +
// " costreimbursementList clist " +
// " LEFT JOIN costreimbursement cmain " +
// " ON clist.mainID = cmain.id " +
// " WHERE " +
// " cmain.state = '120' " +
// " and clist.iscancel = '0' " +
// " and clist.iszuofei != 1 "+
// " AND oldlistnumber = '"+activityCode+"'";//活动id
//
// List<XltCheckCostItem> checkCostItemList = xltDbContext.sql(sql_xlt_check_cost).getList(XltCheckCostItem.class);
List<XltCheckCostItem> checkCostItemList = checkCostItemListMap.get(activityCode);
//申请人取消标识
Boolean applyRealse = false;
if (checkCostItemList == null || checkCostItemList.size() == 0) {
//申请人放弃核销 没有iscancel=0,只有iscancel=1
// String sql_xlt_release_cost =
// " SELECT " +
// " cmain.number_ AS main_number, " +
// " clist.listNumber as list_number, " +
// " clist.isYuEBuYuHeXiao not_allow_flag, " +
// " clist.pifumoney as apply_amt, " +
// " (cList.hexiaomoney + cList.shuiJin) check_pass_amt, " +
// " cList.exedate " +
// " FROM " +
// " costreimbursementList clist " +
// " LEFT JOIN costreimbursement cmain " +
// " ON clist.mainID = cmain.id " +
// " WHERE " +
// " cmain.state = '120' " +
// " and clist.iscancel = '1' " +
// " and clist.iszuofei != 1 "+
// " AND oldlistnumber = '"+activityCode+"'";//活动id
// List<XltCheckCostItem> checkCostReleaseItemList = xltDbContext.sql(sql_xlt_release_cost).getList(XltCheckCostItem.class);
List<XltCheckCostItem> checkCostReleaseItemList = checkCostItemListCancelMap.get(activityCode);
if (checkCostReleaseItemList == null || checkCostReleaseItemList.size() == 0) {
System.out.println("无相关核销,活动编码:" + activityCode);
@ -249,7 +304,7 @@ public class SyncVerificationMain {
String sql_budget_cost_item = "select * from tbs_budget_cost_item where activity_id = ?";
JslTbsBudgetCostItem currCostItem = jslDbContext.sql(sql_budget_cost_item, tbsActivity.getId()).getItem(JslTbsBudgetCostItem.class);
if (currCostItem == null || currCostItem.getId() == null) {
System.out.println("没有命中核销的费用id:"+ costApply.getId());
System.out.println("没有命中核销的费用id:" + costApply.getId() + " 活动id:"+tbsActivity.getId());
return false;
}
@ -297,7 +352,6 @@ public class SyncVerificationMain {
}
/**
*
* @param totalReleaseAmt
* @param jslDbContext
* @param costApply
@ -340,8 +394,9 @@ public class SyncVerificationMain {
fundFlow.setSupplierCode(tbsActivity.getSupplierCode());
fundFlow.setSupplierName(tbsActivity.getSupplierName());
jslDbContext.table(vtb_fund_flow).setEntity(fundFlow).insert();
batchVtbFlowList.add(fundFlow);
// jslDbContext.table(vtb_fund_flow).setEntity(fundFlow).insert();
String sql_budget_by_ids = "select * from tbs_budget where id = " + currCostItem.getBudgetId();
@ -354,12 +409,14 @@ public class SyncVerificationMain {
JslTbsBudgetLog budgetLog = this.buildTbsBudgetLog(4, jslUser, costApply, currCostItem, currentBudget, totalReleaseAmt, tbsActivity);
budgetLog.setTenantId("001");
jslDbContext.table(tbs_budget_log).setEntity(budgetLog).insert();
// jslDbContext.table(tbs_budget_log).setEntity(budgetLog).insert();
batchBudgetLogList.add(budgetLog);
}
/**
* 费用申请相关
*
* @param optType
* @param sysUser
* @param costApply
@ -440,8 +497,13 @@ public class SyncVerificationMain {
verification.setUserId("0");
verification.setUserCode("0");
verification.setUserName("数据导入");
vtbId++;
verification.setId(vtbId);
Long varifId = jslDbContext.table(vtb_verification).setEntity(verification).insert();
Long varifId = vtbId;
// jslDbContext.table(vtb_verification).setEntity(verification).insert();
batchVtbVerificationList.add(verification);
//流水记录
JslVtbFundFlow fundFlow = new JslVtbFundFlow();
@ -476,7 +538,9 @@ public class SyncVerificationMain {
fundFlow.setSupplierId(tbsActivity.getSupplierId());
fundFlow.setSupplierCode(tbsActivity.getSupplierCode());
fundFlow.setSupplierName(tbsActivity.getSupplierName());
jslDbContext.table(vtb_fund_flow).setEntity(fundFlow).insert();
// jslDbContext.table(vtb_fund_flow).setEntity(fundFlow).insert();
batchVtbFlowList.add(fundFlow);
VtbVerificationSubject verificationSubject = new VtbVerificationSubject();
verificationSubject.setVerificationId(varifId);
@ -495,8 +559,13 @@ public class SyncVerificationMain {
verificationSubject.setCountPerson(0);
verificationSubject.setCountSession(0);
verificationSubject.setTenantId("001");
vtbSubId++;
verificationSubject.setId(vtbSubId);
batchVtbVerificationSubjectList.add(verificationSubject);
// 104565
Long varifSubjectId = jslDbContext.table(vtb_verification_subject).setEntity(verificationSubject).insert();
Long varifSubjectId = vtbSubId;
// jslDbContext.table(vtb_verification_subject).setEntity(verificationSubject).insert();
PayPayment payPayment = new PayPayment();
payPayment.setPayCode(checkCostItem.getMainNumber());
@ -513,7 +582,10 @@ public class SyncVerificationMain {
payPayment.setBillNumber("");
payPayment.setPayTime(checkCostItem.getExedate());
payPayment.setTenantId("001");
Long payId = jslDbContext.table(pay_payment).setEntity(payPayment).insert();
payMaxId++;
Long payId = payMaxId;
// jslDbContext.table(pay_payment).setEntity(payPayment).insert();
payPaymentList.add(payPayment);
PayPaymentItem payPaymentItem = new PayPaymentItem();
payPaymentItem.setPayType("pay");
@ -531,9 +603,207 @@ public class SyncVerificationMain {
payPaymentItem.setActivityCode(tbsActivity.getActivityCode());
payPaymentItem.setVerificationId(varifId);
payPaymentItem.setVerificationSubjectId(varifSubjectId);
jslDbContext.table(pay_payment_item).setEntity(payPaymentItem).insert();
// jslDbContext.table(pay_payment_item).setEntity(payPaymentItem).insert();
payPaymentItemList.add(payPaymentItem);
}
private void insertBatchVtbVerification(List<VtbVerification> list) throws Exception {
DbContext jslDbContext = TbsMapper.getJslDbContext();
jslDbContext.table(vtb_verification).insertList(list, (d, m) -> {
m.set("id", d.getId());
m.set("verification_code", d.getVerificationCode());
m.set("cost_apply_id", d.getCostApplyId());
m.set("activity_id", d.getActivityId());
m.set("policy_item_id", d.getPolicyItemId());
m.set("policy_item_code", d.getPolicyItemCode());
m.set("verification_state", d.getVerificationState());
m.set("finished_time", d.getFinishedTime());
m.set("payment_state", d.getPaymentState());
m.set("amount", d.getAmount());
m.set("amount_record", d.getAmountRecord());
m.set("sy_form_id", d.getSyFormId());
m.set("sy_flow_id", d.getSyFlowId());
m.set("supplier_id", d.getSupplierId());
m.set("supplier_code", d.getSupplierCode());
m.set("supplier_name", d.getSupplierName());
m.set("remark", d.getRemark());
m.set("create_time", d.getCreateTime());
m.set("tenant_id", d.getTenantId());
m.set("user_id", d.getUserId());
m.set("user_code", d.getUserCode());
m.set("user_name", d.getUserName());
});
}
private void insertBatchVtbVerificationSubject(List<VtbVerificationSubject> list) throws Exception {
DbContext jslDbContext = TbsMapper.getJslDbContext();
jslDbContext.table(vtb_verification_subject).insertList(list, (d, m) -> {
m.set("id", d.getId());
m.set("verification_sub_code", d.getVerificationSubCode());
m.set("verification_id", d.getVerificationId());
m.set("cost_apply_id", d.getCostApplyId());
m.set("activity_id", d.getActivityId());
m.set("policy_item_id", d.getPolicyItemId());
m.set("policy_item_code", d.getPolicyItemCode());
m.set("subject_id", d.getSubjectId());
m.set("subject_code", d.getSubjectCode());
m.set("subject_name", d.getSubjectName());
m.set("supplier_id", d.getSupplierId());
m.set("supplier_code", d.getSupplierCode());
m.set("supplier_name", d.getSupplierName());
m.set("used_amount", d.getUsedAmount());
m.set("used_amount_record", d.getUsedAmountRecord());
m.set("pay_amount", d.getPayAmount());
// m.set("pay_finished_flag", d.getPayFinishedFlag());
m.set("count_session", d.getCountSession());
m.set("count_person", d.getCountPerson());
m.set("remark", d.getRemark());
m.set("tenant_id", d.getTenantId());
// m.set("effective_flag", d.getEffectiveFlag());
m.set("form_id", d.getFormId());
m.set("form_title", d.getFormTitle());
m.set("form_version", d.getFormVersion());
m.set("form_context", d.getFormContext());
m.set("form_context_value", d.getFormContextValue());
});
}
private void insertBatchVtbFlow(List<JslVtbFundFlow> list) throws Exception {
DbContext jslDbContext = TbsMapper.getJslDbContext();
jslDbContext.table(vtb_fund_flow).insertList(list, (d, m) -> {
m.set("id", d.getId());
m.set("fund_type", d.getFundType());
m.set("verification_id", d.getVerificationId());
m.set("center_goods_code", d.getCenterGoodsCode());
m.set("cost_apply_id", d.getCostApplyId());
m.set("activity_id", d.getActivityId());
m.set("subject_id", d.getSubjectId());
m.set("subject_code", d.getSubjectCode());
m.set("subject_name", d.getSubjectName());
m.set("center_type", d.getCenterType());
m.set("center_id", d.getCenterId());
m.set("center_code", d.getCenterCode());
m.set("center_name", d.getCenterName());
m.set("used_amount", d.getUsedAmount());
m.set("target_type", d.getTargetType());
m.set("target_id", d.getTargetId());
m.set("target_code", d.getTargetCode());
m.set("target_name", d.getTargetName());
m.set("target_level_path_ids", d.getTargetLevelPathIds());
m.set("target_level_path_names", d.getTargetLevelPathNames());
m.set("remark", d.getRemark());
m.set("tenant_id", d.getTenantId());
m.set("center_good_item_id", d.getCenterGoodItemId());
m.set("supplier_id", d.getSupplierId());
m.set("supplier_code", d.getSupplierCode());
m.set("supplier_name", d.getSupplierName());
});
}
private void insertBatchBudgetLog(List<JslTbsBudgetLog> list) throws Exception {
DbContext jslDbContext = TbsMapper.getJslDbContext();
jslDbContext.table(tbs_budget_log).insertList(list, (d, m) -> {
m.set("id", d.getId());
m.set("budget_id", d.getBudgetId());
m.set("budget_code", d.getBudgetCode());
m.set("opt_type", d.getOptType());
m.set("opt_user_id", d.getOptUserId());
m.set("opt_user_name", d.getOptUserName());
m.set("opt_user_code", d.getOptUserCode());
m.set("amount", d.getAmount());
m.set("schedule_id", d.getScheduleId());
m.set("schedule_item_id", d.getScheduleItemId());
m.set("schedule_item_budget_id", d.getScheduleItemBudgetId());
m.set("schedule_org_id", d.getScheduleOrgId());
m.set("schedule_item_org_id", d.getScheduleItemOrgId());
m.set("schedule_item_budget_org_id", d.getScheduleItemBudgetOrgId());
m.set("item_name", d.getItemName());
m.set("start_date", d.getStartDate());
m.set("end_date", d.getEndDate());
m.set("subject_id", d.getSubjectId());
m.set("subject_code", d.getSubjectCode());
m.set("subject_name", d.getSubjectName());
m.set("center_type", d.getCenterType());
m.set("center_id", d.getCenterId());
m.set("center_code", d.getCenterCode());
m.set("center_name", d.getCenterName());
m.set("center_org_id", d.getCenterOrgId());
m.set("center_org_code", d.getCenterOrgCode());
m.set("center_org_name", d.getCenterOrgName());
m.set("supplier_id", d.getSupplierId());
m.set("supplier_code", d.getSupplierCode());
m.set("supplier_name", d.getSupplierName());
m.set("activity_id", d.getActivityId());
m.set("activity_code", d.getActivityCode());
m.set("activity_theme", d.getActivityTheme());
m.set("policy_id", d.getPolicyId());
m.set("policy_code", d.getPolicyCode());
m.set("policy_title", d.getPolicyTitle());
m.set("policy_item_id", d.getPolicyItemId());
m.set("policy_item_code", d.getPolicyItemCode());
m.set("cost_apply_id", d.getCostApplyId());
m.set("cost_apply_code", d.getCostApplyCode());
m.set("cost_apply_theme", d.getCostApplyTheme());
m.set("remark", d.getRemark());
// m.set("rollback_flag", d.getRollbackFlag());
// m.set("migrate_flag", d.getMigrateFlag());
m.set("migrate_time", d.getMigrateTime());
m.set("tenant_id", d.getTenantId());
m.set("target_type", d.getTargetType());
m.set("target_id", d.getTargetId());
m.set("target_code", d.getTargetCode());
m.set("target_name", d.getTargetName());
m.set("target_level_path_ids", d.getTargetLevelPathIds());
m.set("target_level_path_names", d.getTargetLevelPathNames());
});
}
private void insertBatchPayment(List<PayPayment> list) throws Exception {
DbContext jslDbContext = TbsMapper.getJslDbContext();
jslDbContext.table(pay_payment).insertList(list, (d, m) -> {
m.set("id", d.getId());
m.set("pay_type", d.getPayType());
m.set("pay_code", d.getPayCode());
m.set("supplier_id", d.getSupplierId());
m.set("supplier_code", d.getSupplierCode());
m.set("supplier_name", d.getSupplierName());
m.set("pay_amount", d.getPayAmount());
m.set("erp_code", d.getErpCode());
m.set("bill_number", d.getBillNumber());
m.set("user_id", d.getUserId());
m.set("user_code", d.getUserCode());
m.set("user_name", d.getUserName());
m.set("pay_time", d.getPayTime());
m.set("cost_apply_id", d.getCostApplyId());
// m.set("cancel_flag", d.getCancelFlag());
m.set("cancel_time", d.getCancelTime());
m.set("remark", d.getRemark());
m.set("tenant_id", d.getTenantId());
});
}
private void insertBatchPaymentItem(List<PayPaymentItem> list) throws Exception {
DbContext jslDbContext = TbsMapper.getJslDbContext();
jslDbContext.table(pay_payment_item).insertList(list, (d, m) -> {
m.set("id", d.getId());
m.set("pay_type", d.getPayType());
m.set("payment_id", d.getPaymentId());
m.set("supplier_id", d.getSupplierId());
m.set("item_pay_amount", d.getItemPayAmount());
m.set("verification_id", d.getVerificationId());
m.set("verification_subject_id", d.getVerificationSubjectId());
m.set("cost_apply_id", d.getCostApplyId());
m.set("activity_id", d.getActivityId());
m.set("activity_code", d.getActivityCode());
m.set("policy_item_id", d.getPolicyItemId());
m.set("policy_item_code", d.getPolicyItemCode());
m.set("subject_id", d.getSubjectId());
m.set("subject_code", d.getSubjectCode());
m.set("subject_name", d.getSubjectName());
m.set("remark", d.getRemark());
m.set("tenant_id", d.getTenantId());
});
}
}

Loading…
Cancel
Save