package com.changhong.epc.bean.count.format;
|
|
import com.changhong.epc.bean.form.CpnVal;
|
import com.changhong.epc.bean.parsing.BillInfo;
|
import com.changhong.epc.bean.parsing.submit.FormulaParam.TriggerCondition;
|
import com.changhong.epc.bean.tenant.system.ErrSystemMsg;
|
import com.iemsoft.framework.cloud.core.exception.IEMRuntimeException;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import lombok.Data;
|
import org.apache.commons.lang3.StringUtils;
|
|
import java.util.*;
|
|
@Data
|
public class FormInfo implements CpnInfoCommons{
|
|
private List<TriggerCondition> trigger;
|
|
/**
|
* 数据id
|
*/
|
private String id;
|
|
/**
|
* 费用类型id
|
*/
|
private String ctId;
|
/**
|
* 云帐仿订单号
|
*/
|
private String orderCode;
|
|
/**
|
* 表单id
|
*/
|
private String formId;
|
|
/**
|
* 控件id
|
*/
|
private List<CpnInfo> data;
|
|
/**
|
* 表单按钮
|
*/
|
private List<ButtonInfo> button = new ArrayList<>();
|
|
/**
|
* 错误信息
|
*/
|
private List<ErrSystemMsg> errSystemMsgs = new ArrayList<>();
|
|
/**
|
* 消息信息
|
*/
|
private Set<FormMsgInfo> msgInfo = new HashSet<>();
|
|
public FormInfo() {
|
}
|
|
@Override
|
public List<CpnInfo> cpnInfos() {
|
return getData();
|
}
|
|
/**
|
* 提供给模拟计算费用使用
|
* @param billInfo
|
* @param fillCpnVal
|
* @param journeyCpnVal
|
* @param ctId
|
*/
|
public FormInfo(BillInfo billInfo,
|
Map<CpnVal, List<List<CpnVal>>> fillCpnVal, CpnVal journeyCpnVal, Integer ctId){
|
|
data = new ArrayList<>();
|
// 封装主控件
|
fillCpnVal.get(null).get(0).forEach(s->data.add(cpnValToCpnInfo(s)));
|
// 封装行程
|
List<List<CpnVal>> journeyCpnVals = fillCpnVal.get(journeyCpnVal);
|
|
data.add(cpnValToCpnInfo(journeyCpnVal, journeyCpnVals));
|
this.ctId = ctId.toString();
|
this.orderCode = billInfo.getOrderCode();
|
this.formId = billInfo.getFormId();
|
}
|
|
private CpnInfo cpnValToCpnInfo(CpnVal cpnval) {
|
CpnInfo cpnInfo = new CpnInfo();
|
cpnInfo.setFieldKey(cpnval.getAlias());
|
cpnInfo.setMdCode(cpnval.getMdCode());
|
cpnInfo.setType(CpnType.valueOf(cpnval.getTagType()));
|
cpnInfo.setValue(cpnval.getValCode());
|
return cpnInfo;
|
}
|
|
private CpnInfo cpnValToCpnInfo(CpnVal cpnval,List<List<CpnVal>> journeyCpnVals) {
|
CpnInfo cpnInfo = cpnValToCpnInfo(cpnval);
|
List<ItemInfo> childs = new ArrayList<>();
|
cpnInfo.setChild(childs);
|
|
journeyCpnVals.forEach(o->{
|
ItemInfo jData = new ItemInfo();
|
childs.add(jData);
|
List<CpnInfo> items = new ArrayList<>();
|
jData.setCId(findJourneyId(o));
|
jData.setItems(items);
|
// System.out.println();
|
o.forEach(s->items.add(cpnValToCpnInfo(s)));
|
|
});
|
return cpnInfo;
|
}
|
|
protected Integer findJourneyId(List<CpnVal> cpnVals){
|
if(ObjectUtil.notEmpty(cpnVals)) {
|
for (CpnVal s : cpnVals) {
|
if (Objects.equals("DATAROWNUM", s.getAlias())) {
|
return Integer.valueOf(Objects.toString(s.getValCode()));
|
}
|
}
|
}
|
throw new IEMRuntimeException("E001", "找不到行程ID");
|
}
|
|
protected void findOrderCode(){
|
if(data== null)
|
return ;
|
for (CpnInfo cpnInfo : data) {
|
if(Objects.equals(cpnInfo.getFieldKey(), "orderCode")){
|
this.setOrderCode(Objects.toString(cpnInfo.getValue()));
|
}
|
|
}
|
}
|
|
public String getOrderCode(){
|
if(StringUtils.isBlank(orderCode)){
|
findOrderCode();
|
}
|
return orderCode;
|
}
|
|
|
}
|