commit | author | age
|
a18bfa
|
1 |
package com.changhong.epc.bean.tenant.bill; |
Z |
2 |
|
|
3 |
import com.alibaba.fastjson.annotation.JSONField; |
|
4 |
import com.changhong.epc.constter.parsing.ConstRuleMsg; |
|
5 |
import com.iemsoft.framework.cloud.core.tools.ObjectUtil; |
|
6 |
import lombok.Data; |
|
7 |
import lombok.extern.slf4j.Slf4j; |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
9 |
|
|
10 |
import java.math.BigDecimal; |
|
11 |
import java.util.*; |
|
12 |
import java.util.function.Consumer; |
|
13 |
|
|
14 |
@Slf4j |
|
15 |
@Data |
|
16 |
public class OCRBillHeaderEntity implements IOCRBill, ConstRuleMsg { |
|
17 |
|
|
18 |
/** |
|
19 |
* 票据原始信息 |
|
20 |
*/ |
|
21 |
private Map<String, String> billHeadMap = new HashMap<>(); |
|
22 |
|
|
23 |
/* |
|
24 |
* 票据基础信息 |
|
25 |
*/ |
|
26 |
private Map<String, String> billKeyName = new HashMap<>(); |
|
27 |
|
|
28 |
private Map<String, String> billKeyCode = new HashMap<>(); |
|
29 |
|
|
30 |
private Map<String, String> billMasterName = new HashMap<>(); |
|
31 |
|
|
32 |
private Map<String, String> billMasterCode = new HashMap<>(); |
|
33 |
|
|
34 |
/** |
|
35 |
* 错误级别 |
|
36 |
*/ |
|
37 |
private List<RuleMsg> ruleMsg = new ArrayList<>(); |
|
38 |
|
|
39 |
|
|
40 |
/* |
|
41 |
* 费用类型 |
|
42 |
*/ |
|
43 |
private CostType costType; |
|
44 |
|
|
45 |
/* |
|
46 |
* 票据编号(唯一标识) |
|
47 |
*/ |
|
48 |
private String billCode; |
|
49 |
|
|
50 |
/* |
|
51 |
* 票据模板code |
|
52 |
*/ |
|
53 |
private String billModelCode; |
|
54 |
|
|
55 |
/* |
|
56 |
* 关联行程id |
|
57 |
*/ |
|
58 |
private Integer bhJouneryId; |
|
59 |
|
|
60 |
/** |
|
61 |
* 汇率 |
|
62 |
*/ |
|
63 |
private String exchangeRate; |
|
64 |
|
|
65 |
/* |
|
66 |
* 票据行数据集合,如果票据不包含行数据,该集合为空 |
|
67 |
*/ |
|
68 |
private List<OCRBillBodyEntity> billBodyEntityList = new ArrayList<>(); |
|
69 |
|
|
70 |
private List<Map<String, String>> billBodyList; |
|
71 |
|
|
72 |
/** |
|
73 |
* @Author WangYX |
|
74 |
* @Description 合并的票据信息 |
|
75 |
* @Date 2019/1/17 下午2:06 |
|
76 |
*/ |
|
77 |
private List<IOCRBill> child = new ArrayList<>(); |
|
78 |
|
|
79 |
/** |
|
80 |
* json 转换时调用此方法。 |
|
81 |
* @param billBodyList |
|
82 |
*/ |
|
83 |
public void setBillBodyList(List<Map<String, String>> billBodyList){ |
|
84 |
// this.billBodyList = billBodyList; |
|
85 |
if(ObjectUtil.empty(billBodyList)) |
|
86 |
return; |
|
87 |
List<OCRBillBodyEntity> billBodyEntityList = new ArrayList<>(billBodyList.size()); |
|
88 |
int i = 1; |
|
89 |
for(Map<String, String> body: billBodyList){ |
|
90 |
OCRBillBodyEntity ocrBillBodyEntity = new OCRBillBodyEntity(); |
|
91 |
ocrBillBodyEntity.setBodyDataMap(body); |
|
92 |
billBodyEntityList.add(ocrBillBodyEntity); |
|
93 |
} |
|
94 |
this.billBodyEntityList = billBodyEntityList; |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public Boolean isIgnore() { |
|
99 |
return !isAllotTenant(); |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* 通过返回true 否则返回 false |
|
104 |
* @Title: isAllotTenant |
|
105 |
* @param @return 设定文件 |
|
106 |
* @return boolean 返回类型 |
|
107 |
* @throws |
|
108 |
*/ |
|
109 |
public boolean isAllotTenant(){ |
|
110 |
for (RuleMsg rule : ruleMsg) { |
|
111 |
if(rule.getLevel() == LEVEL_20 && |
|
112 |
rule.getResult() == ERROR && |
|
113 |
StringUtils.isNotBlank((rule.getBillCode()))){ |
|
114 |
return false; |
|
115 |
} |
|
116 |
} |
|
117 |
return true; |
|
118 |
} |
|
119 |
|
|
120 |
public static void forEach(Consumer<IOCRBill> action, List<OCRBillHeaderEntity> bills){ |
|
121 |
if(ObjectUtil.empty(bills)){ |
|
122 |
return; |
|
123 |
} |
|
124 |
bills.stream().forEach(bill->{ |
|
125 |
action.accept(bill); |
|
126 |
if(ObjectUtil.notEmpty(bill.getBillBodyEntityList())){ |
|
127 |
bill.getBillBodyEntityList().stream().forEach(body->{ |
|
128 |
action.accept(body); |
|
129 |
}); |
|
130 |
} |
|
131 |
}); |
|
132 |
} |
|
133 |
|
|
134 |
@JSONField(serialize=false) |
|
135 |
@Override |
|
136 |
public Double getBillMoney() { |
|
137 |
// log.debug("参数-{}:{}", AMOUNT, getMoney(AMOUNT)); |
|
138 |
// log.debug("参数-{}:{}", PREMIUM, getMoney(PREMIUM)); |
|
139 |
// log.debug("参数-{}:{}", SERVICE_AMOUNT, getMoney(SERVICE_AMOUNT)); |
|
140 |
// log.debug("参数-{}:{}", BS_AMOUNT, getMoney(BS_AMOUNT)); |
|
141 |
// log.debug("参数-{}:{}", O_TAX_AMOUNT, getMoney(O_TAX_AMOUNT)); |
|
142 |
// log.debug("参数-{}:{}", "childMoney", getChildMoney()); |
|
143 |
return BigDecimal.valueOf(getMoney(AMOUNT)) |
|
144 |
.add(BigDecimal.valueOf(getMoney(PREMIUM))) |
|
145 |
.add(BigDecimal.valueOf(getMoney(SERVICE_AMOUNT))) |
|
146 |
.add(BigDecimal.valueOf(getMoney(BS_AMOUNT))) |
|
147 |
.add(BigDecimal.valueOf(getMoney(O_TAX_AMOUNT))) |
|
148 |
.add(BigDecimal.valueOf(getChildMoney())) |
|
149 |
.doubleValue(); |
|
150 |
} |
|
151 |
|
|
152 |
private Double getChildMoney() { |
|
153 |
if(ObjectUtil.empty(child)){ |
|
154 |
return 0D; |
|
155 |
} |
|
156 |
return child.stream() |
|
157 |
.filter(ioc->ioc.isAssignableFrom(OCRBillBodyEntity.class)) |
|
158 |
.map(ioc->BigDecimal.valueOf(ioc.getBillMoney())) |
|
159 |
.reduce(BigDecimal.valueOf(0), (a1, a2)->a1.add(a2)) |
|
160 |
.doubleValue(); |
|
161 |
// if(ObjectUtil.empty(child)){ |
|
162 |
// return 0D; |
|
163 |
// } |
|
164 |
// return this.child.stream() |
|
165 |
// .map(IOCRBill::getBillMoney) |
|
166 |
// .reduce(0D, (a1, a2)->a1+a2); |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
@JSONField(serialize=false) |
|
171 |
public Boolean getBillByType(String type) { |
|
172 |
if(costType == null){ |
|
173 |
return Boolean.FALSE; |
|
174 |
} |
|
175 |
return Objects.equals(costType.getCode(), type); |
|
176 |
} |
|
177 |
|
|
178 |
@Override |
|
179 |
@JSONField(serialize=false) |
|
180 |
public String getBillType() { |
|
181 |
return costType.getCode(); |
|
182 |
} |
|
183 |
|
|
184 |
@Override |
|
185 |
public Map<String, String> getBillOriginalInfo() { |
|
186 |
return this.billHeadMap; |
|
187 |
} |
|
188 |
|
|
189 |
@Override |
|
190 |
public void appendBill(IOCRBill bill) { |
|
191 |
this.child.add(bill); |
|
192 |
} |
|
193 |
|
|
194 |
@Override |
|
195 |
public Map<String, String> getBillKeyName() { |
|
196 |
Map<String, String> result = new HashMap<>(billKeyName); |
|
197 |
child.stream().forEach(c->meage(result, c.getBillKeyName())); |
|
198 |
// getBillBodyEntityList().stream().forEach(body->result.putAll(body.getBillKeyName())); |
|
199 |
return result; |
|
200 |
} |
|
201 |
@Override |
|
202 |
public void setBillKeyName(String key, String val) { |
|
203 |
this.billKeyName.put(key, val); |
|
204 |
} |
|
205 |
|
|
206 |
@Override |
|
207 |
public Map<String, String> getBillKeyCode() { |
|
208 |
Map<String, String> result = new HashMap<>(billKeyCode); |
|
209 |
child.stream().forEach(c->meage(result, c.getBillKeyCode())); |
|
210 |
// getBillBodyEntityList().stream().forEach(body->result.putAll(body.getBillKeyCode())); |
|
211 |
return result; |
|
212 |
} |
|
213 |
@Override |
|
214 |
public void setBillKeyCode(String key, String val) { |
|
215 |
this.billKeyCode.put(key, val); |
|
216 |
} |
|
217 |
|
|
218 |
@Override |
|
219 |
public Map<String, String> getBillMasterName() { |
|
220 |
Map<String, String> result = new HashMap<>(billMasterName); |
|
221 |
// getBillBodyEntityList().stream().forEach(body->result.putAll(body.getBillMasterName())); |
|
222 |
return result; |
|
223 |
} |
|
224 |
@Override |
|
225 |
public void setBillMasterName(String key, String val) { |
|
226 |
this.billMasterName.put(key, val); |
|
227 |
} |
|
228 |
|
|
229 |
@Override |
|
230 |
public Map<String, String> getBillMasterCode() { |
|
231 |
Map<String, String> result = new HashMap<>(billMasterCode); |
|
232 |
// getBillBodyEntityList().stream().forEach(body->result.putAll(body.getBillMasterCode())); |
|
233 |
return result; |
|
234 |
} |
|
235 |
@Override |
|
236 |
public void setBillMasterCode(String key, String val) { |
|
237 |
this.billMasterCode.put(key, val); |
|
238 |
} |
|
239 |
} |