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;
|
|
}
|
}
|