Commit 0f9a0e8a9efc1c98cbc6438cdf66a0f2dfeaa88e

Authored by zhangmeiyang
1 parent 153b18c8

新增保证金扣减业务

etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/demarcate/AbstractBillHandler.java
@@ -87,7 +87,7 @@ public abstract class AbstractBillHandler<T extends BaseBillCo> extends Abstract @@ -87,7 +87,7 @@ public abstract class AbstractBillHandler<T extends BaseBillCo> extends Abstract
87 private static <T extends BaseBillCo> BiConsumer<String, List<BusinessDetailDto>> multiMapFilter(T e) { 87 private static <T extends BaseBillCo> BiConsumer<String, List<BusinessDetailDto>> multiMapFilter(T e) {
88 return (k, v) -> TRANSFER_FUNCTION_MULTI_MAP.get(k).transferDynamic(e, v); 88 return (k, v) -> TRANSFER_FUNCTION_MULTI_MAP.get(k).transferDynamic(e, v);
89 } 89 }
90 - private static <T extends BaseBillCo> BiConsumer<String, BusinessDetailDto> singleMapFilter(T e) { 90 + protected static <T extends BaseBillCo> BiConsumer<String, BusinessDetailDto> singleMapFilter(T e) {
91 return (k, v) -> TRANSFER_FUNCTION_SINGLE_MAP.get(k).transferDynamic(e, v); 91 return (k, v) -> TRANSFER_FUNCTION_SINGLE_MAP.get(k).transferDynamic(e, v);
92 } 92 }
93 93
@@ -111,7 +111,7 @@ public abstract class AbstractBillHandler&lt;T extends BaseBillCo&gt; extends Abstract @@ -111,7 +111,7 @@ public abstract class AbstractBillHandler&lt;T extends BaseBillCo&gt; extends Abstract
111 * 批量转换方法 111 * 批量转换方法
112 * 112 *
113 */ 113 */
114 - private void transferPayMethod(List<FEntityDetail> fEntityDetail, Long marketId, String systemCode) { 114 + protected void transferPayMethod(List<FEntityDetail> fEntityDetail, Long marketId, String systemCode) {
115 fEntityDetail.forEach(e -> { 115 fEntityDetail.forEach(e -> {
116 if (!ObjectUtils.isEmpty(e.getFSettleTypeID())) { 116 if (!ObjectUtils.isEmpty(e.getFSettleTypeID())) {
117 e.getFSettleTypeID().setFNumber(getPayMethod(e.getFSettleTypeID().getFNumber(), systemCode, marketId)); 117 e.getFSettleTypeID().setFNumber(getPayMethod(e.getFSettleTypeID().getFNumber(), systemCode, marketId));
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/handler/business/bill/SettleBillHandler.java
@@ -3,18 +3,20 @@ package com.diligrp.etrade.thirdparty.handler.business.bill; @@ -3,18 +3,20 @@ package com.diligrp.etrade.thirdparty.handler.business.bill;
3 import com.diligrp.etrade.core.util.JsonUtils; 3 import com.diligrp.etrade.core.util.JsonUtils;
4 import com.diligrp.etrade.thirdparty.demarcate.AbstractBillHandler; 4 import com.diligrp.etrade.thirdparty.demarcate.AbstractBillHandler;
5 import com.diligrp.etrade.thirdparty.domain.co.business.bill.SettleBillCo; 5 import com.diligrp.etrade.thirdparty.domain.co.business.bill.SettleBillCo;
  6 +import com.diligrp.etrade.thirdparty.domain.dto.BusinessDetailDto;
  7 +import com.diligrp.etrade.thirdparty.domain.dto.ChargeItemDto;
  8 +import com.diligrp.etrade.thirdparty.domain.model.FCOSTID;
6 import com.diligrp.etrade.thirdparty.domain.model.FEntityDetail; 9 import com.diligrp.etrade.thirdparty.domain.model.FEntityDetail;
7 -import com.diligrp.etrade.thirdparty.type.BailFeeType;  
8 import com.diligrp.etrade.thirdparty.type.BusinessEnum; 10 import com.diligrp.etrade.thirdparty.type.BusinessEnum;
9 import com.diligrp.etrade.thirdparty.type.DynamicType; 11 import com.diligrp.etrade.thirdparty.type.DynamicType;
  12 +import com.diligrp.etrade.thirdparty.type.SelectType;
10 import com.fasterxml.jackson.core.type.TypeReference; 13 import com.fasterxml.jackson.core.type.TypeReference;
  14 +import org.apache.commons.lang3.math.NumberUtils;
11 import org.springframework.stereotype.Component; 15 import org.springframework.stereotype.Component;
12 16
13 -import java.util.*; 17 +import java.util.List;
  18 +import java.util.Optional;
14 import java.util.function.Consumer; 19 import java.util.function.Consumer;
15 -import java.util.function.Predicate;  
16 -import java.util.stream.Collectors;  
17 -import java.util.stream.Stream;  
18 20
19 /** 21 /**
20 * @Author: zhangmeiyang 22 * @Author: zhangmeiyang
@@ -24,40 +26,65 @@ import java.util.stream.Stream; @@ -24,40 +26,65 @@ import java.util.stream.Stream;
24 @Component 26 @Component
25 public class SettleBillHandler extends AbstractBillHandler<SettleBillCo> { 27 public class SettleBillHandler extends AbstractBillHandler<SettleBillCo> {
26 28
27 - private static Consumer<SettleBillCo> action(List<SettleBillCo> bail, List<SettleBillCo> other) {  
28 - return e -> Optional.ofNullable(e).filter(predict()).ifPresentOrElse(other::add, special(e, bail)); 29 + private static Consumer<ChargeItemDto> setSystemChargeItemCode(FEntityDetail fe) {
  30 + return e -> fe.setSystemChargeItemCode(e.getChargeItemCode());
29 } 31 }
30 32
31 - private static Runnable special(SettleBillCo e, List<SettleBillCo> bail) {  
32 - return () -> {  
33 - Map<BailFeeType, List<FEntityDetail>> map = new HashMap<>();  
34 - List<FEntityDetail> fEntityDetail = e.getFEntityDetail();  
35 - fEntityDetail.forEach(prepareMap(map));  
36 - map.forEach((k,v)-> k.loadData(v,e,bail));  
37 - }; 33 + private static Consumer<BusinessDetailDto> fixedAction(FEntityDetail e) {
  34 + return f -> e.setFixChargeItemCode(f.getItemValue());
38 } 35 }
39 36
40 - private static Consumer<FEntityDetail> prepareMap(Map<BailFeeType, List<FEntityDetail>> map) {  
41 - return f -> map.computeIfAbsent(BailFeeType.fromCode(f.getFeeType()), k -> new ArrayList<>()).add(f); 37 + @Override
  38 + public void handle(String json, Long marketId, String systemCode) throws Exception {
  39 + List<SettleBillCo> settleBillCos = JsonUtils.fromJsonString(json, new TypeReference<>() {
  40 + });
  41 + List<SettleBillCo> lists = splitBill(settleBillCos, marketId, systemCode);
  42 + sendPurchaseOrder(lists, marketId, systemCode);
42 } 43 }
43 44
44 - private static Predicate<SettleBillCo> predict() {  
45 - return t -> !DynamicType.areEqual(t.getSystemDynamicCode(), DynamicType.BAIL); 45 + private List<SettleBillCo> splitBill(List<SettleBillCo> settleBillCos, Long marketId, String systemCode) {
  46 + settleBillCos.forEach(
  47 + e -> {
  48 + DynamicType dynamicType = DynamicType.fromCode(e.getSystemDynamicCode());
  49 + billTrans.transBillCo(e, marketId, systemCode);
  50 + transferPayMethod(e.getFEntityDetail(), marketId, systemCode);
  51 + getFilteredDynamicDataSingle(dynamicType, marketId, systemCode).forEach(singleMapFilter(e));
  52 + transChargeItem(e.getFEntityDetail(), marketId, systemCode);
  53 + }
  54 + );
  55 + return settleBillCos;
46 } 56 }
47 57
48 - @Override  
49 - public void handle(String json, Long marketId, String systemCode) throws Exception {  
50 - List<SettleBillCo> settleBillCos = JsonUtils.fromJsonString(json, new TypeReference<>() {});  
51 - List<SettleBillCo> lists = splitBill(settleBillCos);  
52 - transferDataListWithFeeItem(lists, marketId, systemCode);  
53 - sendPurchaseOrder(lists, marketId, systemCode); 58 + private void transChargeItem(List<FEntityDetail> fEntityDetail, Long marketId, String systemCode) {
  59 + fEntityDetail.forEach(e -> Optional.ofNullable(e.getFCOSTID()).ifPresent(chargeItemAction(marketId, systemCode, e)));
54 } 60 }
55 61
56 - private List<SettleBillCo> splitBill(List<SettleBillCo> settleBillCos) {  
57 - List<SettleBillCo> other = new ArrayList<>();  
58 - List<SettleBillCo> bail = new ArrayList<>();  
59 - settleBillCos.forEach(action(bail, other));  
60 - return Stream.of(other, bail).flatMap(List::stream).collect(Collectors.toList()); 62 + private Consumer<FCOSTID> chargeItemAction(Long marketId, String systemCode, FEntityDetail e) {
  63 + return costId -> {
  64 + var number = costId.getFNUMBER();
  65 + BusinessDetailDto detail = getBusinessDetailDto(marketId, systemCode, costId, number);
  66 + Optional.ofNullable(detail)
  67 + .filter(f -> f.getSelectType() == SelectType.FIXED)
  68 + .ifPresentOrElse(fixedAction(e), dynamicAction(number, e));
  69 + };
  70 + }
  71 +
  72 + private Runnable dynamicAction(String number, FEntityDetail fe) {
  73 + return () -> {
  74 + ChargeItemDto chargeItem = transMapper.getChargeItem(Long.valueOf(number));
  75 + Optional.ofNullable(chargeItem).ifPresent(setSystemChargeItemCode(fe));
  76 + };
  77 + }
  78 +
  79 + private BusinessDetailDto getBusinessDetailDto(Long marketId, String systemCode, FCOSTID costId, String number) {
  80 + BusinessDetailDto detail;
  81 + if (NumberUtils.isCreatable(number) && DynamicType.notContain(number)) {
  82 + detail = transMapper.getSingleBusinessDetail(getDocumentType().sign, systemCode, marketId, Long.valueOf(costId.getFNUMBER()));
  83 + } else {
  84 + detail = transMapper.getSingleFixedBusinessDetail(getDocumentType().sign, systemCode, marketId, costId.getFNUMBER());
  85 +
  86 + }
  87 + return detail;
61 } 88 }
62 89
63 @Override 90 @Override
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/mapper/TransMapper.java
@@ -40,6 +40,30 @@ public interface TransMapper extends MybatisMapperSupport { @@ -40,6 +40,30 @@ public interface TransMapper extends MybatisMapperSupport {
40 40
41 41
42 /** 42 /**
  43 + * 获取动态参数
  44 + *
  45 + * @param documentType 文档类型
  46 + * @param systemCode 系统代码
  47 + * @param marketId 市场 ID
  48 + * @param relationId 关系 ID
  49 + * @return {@link BusinessDetailDto}
  50 + */
  51 + @DataSource(DataSourceConstants.DS_KEY_SLAVE)
  52 + BusinessDetailDto getSingleBusinessDetail(@Param("documentType") String documentType,@Param("systemCode")String systemCode, @Param("marketId")Long marketId,@Param("relationId")Long relationId);
  53 +
  54 + /**
  55 + * 获取动态参数
  56 + *
  57 + * @param documentType 文档类型
  58 + * @param systemCode 系统代码
  59 + * @param marketId 市场 ID
  60 + * @param relationId 关系 ID
  61 + * @return {@link BusinessDetailDto}
  62 + */
  63 + @DataSource(DataSourceConstants.DS_KEY_SLAVE)
  64 + BusinessDetailDto getSingleFixedBusinessDetail(@Param("documentType") String documentType,@Param("systemCode")String systemCode, @Param("marketId")Long marketId,@Param("itemCode")String itemCode);
  65 +
  66 + /**
43 * 获取部门 67 * 获取部门
44 * 68 *
45 * @param departmentId 部门 ID 69 * @param departmentId 部门 ID
etrade-thirdparty/src/main/resources/com/diligrp/etrade/thirdparty/mapper/TransMapper.xml
@@ -135,4 +135,42 @@ @@ -135,4 +135,42 @@
135 AND system_code = #{systemCode} 135 AND system_code = #{systemCode}
136 AND `code` = #{dynamicType} 136 AND `code` = #{dynamicType}
137 </select> 137 </select>
  138 + <select id="getSingleBusinessDetail" resultType="com.diligrp.etrade.thirdparty.domain.dto.BusinessDetailDto">
  139 + SELECT
  140 + fbd.code AS code
  141 + , fbd.name AS name
  142 + , fbd.select_type AS selectType
  143 + , fbd.item_code AS itemCode
  144 + , fbd.item_name AS itemName
  145 + , fbd.item_relation_id AS itemRelationId
  146 + , fbd.item_value AS itemValue
  147 + FROM
  148 + `dili-basic-data`.`financial_business` fb
  149 + LEFT JOIN `dili-basic-data`.financial_business_detail fbd ON fb.id = fbd.financial_business_id
  150 + WHERE
  151 + 1 = 1
  152 + AND fbd.financial_type = #{documentType}
  153 + AND fb.market_id = #{marketId}
  154 + AND fb.system_code = #{systemCode}
  155 + AND fbd.item_relation_id = #{relationId}
  156 + </select>
  157 + <select id="getSingleFixedBusinessDetail" resultType="com.diligrp.etrade.thirdparty.domain.dto.BusinessDetailDto">
  158 + SELECT
  159 + fbd.code AS code
  160 + , fbd.name AS name
  161 + , fbd.select_type AS selectType
  162 + , fbd.item_code AS itemCode
  163 + , fbd.item_name AS itemName
  164 + , fbd.item_relation_id AS itemRelationId
  165 + , fbd.item_value AS itemValue
  166 + FROM
  167 + `dili-basic-data`.`financial_business` fb
  168 + LEFT JOIN `dili-basic-data`.financial_business_detail fbd ON fb.id = fbd.financial_business_id
  169 + WHERE
  170 + 1 = 1
  171 + AND fbd.financial_type = #{documentType}
  172 + AND fb.market_id = #{marketId}
  173 + AND fb.system_code = #{systemCode}
  174 + AND fbd.item_code = #{itemCode}
  175 + </select>
138 </mapper> 176 </mapper>