package com.changhong.epc.bean.tenant.bill; import com.alibaba.fastjson.annotation.JSONField; import com.changhong.epc.constter.parsing.ConstRuleMsg; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import java.math.BigDecimal; import java.util.*; import java.util.function.Consumer; @Slf4j @Data public class OCRBillHeaderEntity implements IOCRBill, ConstRuleMsg { /** * 票据原始信息 */ private Map billHeadMap = new HashMap<>(); /* * 票据基础信息 */ private Map billKeyName = new HashMap<>(); private Map billKeyCode = new HashMap<>(); private Map billMasterName = new HashMap<>(); private Map billMasterCode = new HashMap<>(); /** * 错误级别 */ private List ruleMsg = new ArrayList<>(); /* * 费用类型 */ private CostType costType; /* * 票据编号(唯一标识) */ private String billCode; /* * 票据模板code */ private String billModelCode; /* * 关联行程id */ private Integer bhJouneryId; /** * 汇率 */ private String exchangeRate; /* * 票据行数据集合,如果票据不包含行数据,该集合为空 */ private List billBodyEntityList = new ArrayList<>(); private List> billBodyList; /** * @Author WangYX * @Description 合并的票据信息 * @Date 2019/1/17 下午2:06 */ private List child = new ArrayList<>(); /** * json 转换时调用此方法。 * @param billBodyList */ public void setBillBodyList(List> billBodyList){ // this.billBodyList = billBodyList; if(ObjectUtil.empty(billBodyList)) return; List billBodyEntityList = new ArrayList<>(billBodyList.size()); int i = 1; for(Map body: billBodyList){ OCRBillBodyEntity ocrBillBodyEntity = new OCRBillBodyEntity(); ocrBillBodyEntity.setBodyDataMap(body); billBodyEntityList.add(ocrBillBodyEntity); } this.billBodyEntityList = billBodyEntityList; } @Override public Boolean isIgnore() { return !isAllotTenant(); } /** * 通过返回true 否则返回 false * @Title: isAllotTenant * @param @return 设定文件 * @return boolean 返回类型 * @throws */ public boolean isAllotTenant(){ for (RuleMsg rule : ruleMsg) { if(rule.getLevel() == LEVEL_20 && rule.getResult() == ERROR && StringUtils.isNotBlank((rule.getBillCode()))){ return false; } } return true; } public static void forEach(Consumer action, List bills){ if(ObjectUtil.empty(bills)){ return; } bills.stream().forEach(bill->{ action.accept(bill); if(ObjectUtil.notEmpty(bill.getBillBodyEntityList())){ bill.getBillBodyEntityList().stream().forEach(body->{ action.accept(body); }); } }); } @JSONField(serialize=false) @Override public Double getBillMoney() { // log.debug("参数-{}:{}", AMOUNT, getMoney(AMOUNT)); // log.debug("参数-{}:{}", PREMIUM, getMoney(PREMIUM)); // log.debug("参数-{}:{}", SERVICE_AMOUNT, getMoney(SERVICE_AMOUNT)); // log.debug("参数-{}:{}", BS_AMOUNT, getMoney(BS_AMOUNT)); // log.debug("参数-{}:{}", O_TAX_AMOUNT, getMoney(O_TAX_AMOUNT)); // log.debug("参数-{}:{}", "childMoney", getChildMoney()); return BigDecimal.valueOf(getMoney(AMOUNT)) .add(BigDecimal.valueOf(getMoney(PREMIUM))) .add(BigDecimal.valueOf(getMoney(SERVICE_AMOUNT))) .add(BigDecimal.valueOf(getMoney(BS_AMOUNT))) .add(BigDecimal.valueOf(getMoney(O_TAX_AMOUNT))) .add(BigDecimal.valueOf(getChildMoney())) .doubleValue(); } private Double getChildMoney() { if(ObjectUtil.empty(child)){ return 0D; } return child.stream() .filter(ioc->ioc.isAssignableFrom(OCRBillBodyEntity.class)) .map(ioc->BigDecimal.valueOf(ioc.getBillMoney())) .reduce(BigDecimal.valueOf(0), (a1, a2)->a1.add(a2)) .doubleValue(); // if(ObjectUtil.empty(child)){ // return 0D; // } // return this.child.stream() // .map(IOCRBill::getBillMoney) // .reduce(0D, (a1, a2)->a1+a2); } @Override @JSONField(serialize=false) public Boolean getBillByType(String type) { if(costType == null){ return Boolean.FALSE; } return Objects.equals(costType.getCode(), type); } @Override @JSONField(serialize=false) public String getBillType() { return costType.getCode(); } @Override public Map getBillOriginalInfo() { return this.billHeadMap; } @Override public void appendBill(IOCRBill bill) { this.child.add(bill); } @Override public Map getBillKeyName() { Map result = new HashMap<>(billKeyName); child.stream().forEach(c->meage(result, c.getBillKeyName())); // getBillBodyEntityList().stream().forEach(body->result.putAll(body.getBillKeyName())); return result; } @Override public void setBillKeyName(String key, String val) { this.billKeyName.put(key, val); } @Override public Map getBillKeyCode() { Map result = new HashMap<>(billKeyCode); child.stream().forEach(c->meage(result, c.getBillKeyCode())); // getBillBodyEntityList().stream().forEach(body->result.putAll(body.getBillKeyCode())); return result; } @Override public void setBillKeyCode(String key, String val) { this.billKeyCode.put(key, val); } @Override public Map getBillMasterName() { Map result = new HashMap<>(billMasterName); // getBillBodyEntityList().stream().forEach(body->result.putAll(body.getBillMasterName())); return result; } @Override public void setBillMasterName(String key, String val) { this.billMasterName.put(key, val); } @Override public Map getBillMasterCode() { Map result = new HashMap<>(billMasterCode); // getBillBodyEntityList().stream().forEach(body->result.putAll(body.getBillMasterCode())); return result; } @Override public void setBillMasterCode(String key, String val) { this.billMasterCode.put(key, val); } }