zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.changhong.epc.parsing.service.util;
 
import com.changhong.epc.bean.admin.CorresElField;
import com.changhong.epc.bean.tenant.bill.OCRBillBodyEntity;
import com.changhong.epc.bean.tenant.bill.OCRBillHeaderEntity;
import com.changhong.epc.constter.parsing.subassembly.billinfo.TransverterConstKey;
import com.changhong.epc.rely.api.epc.admin.CorresElFieldApi;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import lombok.extern.slf4j.Slf4j;
 
import java.util.*;
 
/**
 * 票据解析工具类
 */
@Slf4j
public class BillTool implements TransverterConstKey {
 
//    public static final Set<String> JOURNEY_BILL_MODEL_CODE = new HashSet<>(3);
//
//    static {
//        JOURNEY_BILL_MODEL_CODE.add("B02500010000"); // 火车票
//        JOURNEY_BILL_MODEL_CODE.add("B02500000000"); // 飞机票、联程机票
//        JOURNEY_BILL_MODEL_CODE.add("B02500030000"); // 汽车票
//    }
 
    /**
     * 是行程票据
     * @param iocrBill
     * @return
     */
    public static boolean isJourneyBill(OCRBillHeaderEntity iocrBill){
        log.debug("票据code:{}", iocrBill.getBillModelCode());
        CorresElField corresElField = SpringUtil.getBean(CorresElFieldApi.class).getCorresElField(BILL_CODES);
        if(ObjectUtil.empty(corresElField)){
            return false;
        }
        return new HashSet(Arrays.asList(corresElField.getMdCode().split(","))).contains(iocrBill.getBillModelCode());
    }
 
 
    /**
     * 拆封body
     * @param ocrBillHeaderEntity
     * @return
     */
    public static List<OCRBillHeaderEntity> splitBody(OCRBillHeaderEntity ocrBillHeaderEntity){
        if(ObjectUtil.empty(ocrBillHeaderEntity.getBillBodyEntityList()))
            return Arrays.asList(ocrBillHeaderEntity);
        List<OCRBillHeaderEntity> resultBodys = new ArrayList<>(ocrBillHeaderEntity.getBillBodyEntityList().size());
        List<OCRBillBodyEntity> bodys = ocrBillHeaderEntity.getBillBodyEntityList();
        ocrBillHeaderEntity.setBillBodyEntityList(Collections.EMPTY_LIST);
        bodys.stream().forEach(body->{
            OCRBillHeaderEntity ocrBillHeader = JSONTool.toObj(JSONTool.toJson(ocrBillHeaderEntity), OCRBillHeaderEntity.class);
            ocrBillHeader.getBillBodyEntityList().add(body);
            resultBodys.add(ocrBillHeader);
        });
        return resultBodys;
    }
 
}