5 changed files with 230 additions and 13 deletions
@ -0,0 +1,66 @@ |
|||||
|
package com.demo.t20230704; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/7/4 |
||||
|
**/ |
||||
|
@Data |
||||
|
public class Activity0704 { |
||||
|
|
||||
|
private String costCode; |
||||
|
|
||||
|
/** |
||||
|
* id |
||||
|
*/ |
||||
|
private Long id; |
||||
|
|
||||
|
/** |
||||
|
* 编码 |
||||
|
*/ |
||||
|
private String activityCode; |
||||
|
|
||||
|
/** |
||||
|
* 活动状态:0-待核销;1-审批中;2-完成;3-冻结;4-已释放 |
||||
|
*/ |
||||
|
private Integer activityState; |
||||
|
|
||||
|
/** |
||||
|
* 费用申请id |
||||
|
*/ |
||||
|
private Long costApplyId; |
||||
|
|
||||
|
/** |
||||
|
* 费用通过时间 |
||||
|
*/ |
||||
|
private Date costPassTime; |
||||
|
|
||||
|
/** |
||||
|
* 费用通过标识,用于已申请费用活动列表 |
||||
|
*/ |
||||
|
private Integer costPassFlag; |
||||
|
|
||||
|
/** |
||||
|
* 活动简述及目的 |
||||
|
*/ |
||||
|
private String actTitle; |
||||
|
|
||||
|
/** |
||||
|
* 客户id |
||||
|
*/ |
||||
|
private Long supplierId; |
||||
|
|
||||
|
/** |
||||
|
* 客户编码 |
||||
|
*/ |
||||
|
private String supplierCode; |
||||
|
|
||||
|
/** |
||||
|
* 客户名称 |
||||
|
*/ |
||||
|
private String supplierName; |
||||
|
|
||||
|
} |
@ -0,0 +1,147 @@ |
|||||
|
package com.demo.t20230704; |
||||
|
|
||||
|
import com.demo.cost.TbsMapper; |
||||
|
import com.demo.cost.entity.JslTbsActivity; |
||||
|
import com.demo.cost.entity.JslTbsBudgetCostItem; |
||||
|
import com.demo.cost.entity.JslVtbFundFlow; |
||||
|
import com.demo.cost.entity.XltCheckCostItem; |
||||
|
import lombok.SneakyThrows; |
||||
|
import org.junit.Test; |
||||
|
import org.noear.wood.DbContext; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/7/4 |
||||
|
**/ |
||||
|
public class SyncNotCheckMain { |
||||
|
|
||||
|
/** 查询未完成的活动 */ |
||||
|
String sql_cost_not_do_cancel = "select " + |
||||
|
" act.* "+ |
||||
|
" from tbs_activity act " + |
||||
|
" left join tbs_cost_apply cost on act.cost_apply_id = cost.id " + |
||||
|
" where cost.vtb_sync=2 and cost.do_cancel_flag = 0 " + |
||||
|
" order by cost_apply_id"; |
||||
|
|
||||
|
/** 更新已完成的 */ |
||||
|
String sql_update_do_cancel = "update tbs_cost_apply set do_cancel_flag = 1 where id = ?"; |
||||
|
|
||||
|
/** 查询销路通的不予核销记录 */ |
||||
|
String sql_xlt_check_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 oldlistnumber = ?"; |
||||
|
|
||||
|
|
||||
|
/** 统计活动的不予核销 */ |
||||
|
String sql_sum_release = "SELECT sum(used_amount) FROM `vtb_fund_flow` where activity_id = ? and fund_type = 'release'"; |
||||
|
|
||||
|
|
||||
|
//删除历史记录
|
||||
|
String del_fund_flow = "delete from vtb_fund_flow where remark = 'byCancel_1' and activity_id = ?"; |
||||
|
|
||||
|
@Test |
||||
|
@SneakyThrows |
||||
|
public void doMain(){ |
||||
|
DbContext jslDbContext = TbsMapper.getJslDbContext(); |
||||
|
DbContext xltDbContext = TbsMapper.getXltDbContext(); |
||||
|
List<Activity0704> activity0704List = jslDbContext.sql(sql_cost_not_do_cancel).getList(Activity0704.class); |
||||
|
activity0704List.forEach(a->a.setCostCode(a.getActivityCode().split("_")[0])); |
||||
|
Map<String,List<Activity0704>> map = activity0704List.stream().collect(Collectors.groupingBy(Activity0704::getCostCode)); |
||||
|
int totalCost = map.keySet().size(); |
||||
|
int count = 1; |
||||
|
for (String costCode : map.keySet()) { |
||||
|
List<Activity0704> actList = map.get(costCode); |
||||
|
for (Activity0704 tbsActivity : actList) { |
||||
|
List<XltCheckCostItem> checkCostItemList = xltDbContext.sql(sql_xlt_check_cost,tbsActivity.getActivityCode()).getList(XltCheckCostItem.class); |
||||
|
for (XltCheckCostItem costItem : checkCostItemList) { |
||||
|
|
||||
|
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("没有命中核销的费用编码:"+ tbsActivity.getCostCode()); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
//删除历史记录
|
||||
|
jslDbContext.sql(del_fund_flow,tbsActivity.getId()).execute(); |
||||
|
//添加不再支付记录
|
||||
|
BigDecimal amt = costItem.getApplyAmt(); |
||||
|
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(amt); |
||||
|
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()); |
||||
|
fundFlow.setRemark("byCancel_1"); |
||||
|
jslDbContext.table("vtb_fund_flow").setEntity(fundFlow).insert(); |
||||
|
|
||||
|
|
||||
|
BigDecimal totalRes = BigDecimal.ZERO; |
||||
|
Object val = jslDbContext.sql(sql_sum_release,tbsActivity.getId()).getValue(); |
||||
|
if(val!=null){ |
||||
|
totalRes = new BigDecimal(val.toString()); |
||||
|
} |
||||
|
JslTbsActivity updAct = new JslTbsActivity(); |
||||
|
|
||||
|
updAct.setReleaseFlag(1); |
||||
|
updAct.setFinishedFlag(1); |
||||
|
updAct.setReleaseUserId("0"); |
||||
|
updAct.setReleaseUserName("系统导入"); |
||||
|
updAct.setReleaseTime(checkCostItemList.get(0).getExedate()); |
||||
|
updAct.setReleaseAmount(totalRes); |
||||
|
updAct.setId(tbsActivity.getId()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
jslDbContext.sql(sql_update_do_cancel,actList.get(0).getCostApplyId()).execute(); |
||||
|
System.out.println("完成"+count+"/"+totalCost+":CostApplyId="+actList.get(0).getCostApplyId()); |
||||
|
count++; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue