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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.changhong.epc.bean.count.format;
 
import com.changhong.epc.bean.tenant.bill.IOCRBill;
import com.iemsoft.framework.cloud.core.tools.MsgTool;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
 
import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
 
@Data
public class CpnInfo {
    
    private String fieldKey;
    
    private String mdCode;
    
    private CpnType type;
    
    private Object value;
    
    private List<ItemInfo> child;
    
    private boolean flag;
    
    private Map<CpnMsgCode, TreeSet<CpnMsgInfo>> msgInfo = new HashMap<>();
 
    public  CpnInfo() {
    }
    
//    public String getMdCode(){
//        return StringUtils.isNoneBlank(fieldKey) ? fieldKey : mdCode;
//    }
 
    public Object getValue() {
        if(value instanceof List){
            if(ObjectUtil.notEmpty(value)){
                return ((List)value).get(0);
            }
            return "";
        }
        return value;
    }
 
    /*
     * 信息位置
     */
    public static enum CpnMsgCode{
        /**
         * 位置
         */
        header
        
    }
    
    /*
     * 信息数据
     */
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
//    @EqualsAndHashCode(exclude={"value", "validate"})
    @EqualsAndHashCode(exclude={"name"})
    public static class CpnMsgInfo implements Comparable<CpnMsgInfo>{
 
        /**
         * 消息名头
         */
        private String name;
 
        /**
         * 显示值
         */
        private Object value;
 
        /**
         * 验证值
         */
        private Object validateValue;
 
        /**
         * 是否验证
         */
        private Boolean validate;
 
        /**
         * 票据详情
         */
        private BillDetail hint;
 
        public CpnMsgInfo(String name, Object value, Boolean validate) {
            super();
            this.name = name;
            this.validateValue = this.value = value;
            this.validate = validate;
        }
 
        public CpnMsgInfo(String name, Object value, Object validateValue, Boolean validate) {
            super();
            this.name = name;
            this.validateValue = validateValue;
            this.value = value;
            this.validate = validate;
        }
 
        public CpnMsgInfo(String name) {
            super();
            this.name = name;
            this.validate = Boolean.FALSE;
        }
 
        public void setCpnMsgInfo(CpnInfo.CpnMsgInfo billCpn){
            this.setName(billCpn.getName());
            this.setValidate(billCpn.getValidate());
            this.setValidateValue(billCpn.getValidate());
            this.setValue(billCpn.getValue());
        }
 
        public void addBillDetail(FormInfo formInfo, List<IOCRBill> bills, Map<String, BiFunction<FormInfo, IOCRBill, Object>> title) {
            if(ObjectUtil.empty(bills)){
                return;
            }
            hint = new BillDetail();
            hint.setTitle(title.keySet().stream().map(MsgTool::get).collect(Collectors.toList()));
            hint.setData(
                    bills.stream().map(bill->{
                        Map<String, Object> info = new HashMap<>();
                        title.entrySet().stream().forEach(entry->
                                info.put(MsgTool.get(entry.getKey()), entry.getValue().apply(formInfo, bill)));
                        return info;
                    }).collect(Collectors.toList())
            );
 
        }
 
        @Override
        public int compareTo(CpnMsgInfo o) {
            return o.getName().compareTo(this.getName());
        }
    }
 
    @Data
    public static class BillDetail{
 
        private List<String> title;
 
        private List<Map<String, Object>> data;
 
    }
}