package com.changhong.epc.bean.tenant.bill; import com.alibaba.fastjson.annotation.JSONField; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import com.iemsoft.framework.cloud.core.tools.StringUtil; import lombok.Data; import lombok.extern.slf4j.Slf4j; import java.math.BigDecimal; import java.util.*; @Slf4j @Data public class OCRBillBodyEntity implements IOCRBill { /** * 票据原始信息 */ private Map bodyDataMap = new HashMap<>(); /* * 票据基础信息 */ private Map billKeyName = new HashMap<>(); private Map billKeyCode = new HashMap<>(); private Map billMasterName = new HashMap<>(); private Map billMasterCode = new HashMap<>(); /* * 行-费用类型 */ private CostType costType; /** * 汇率 */ private String exchangeRate; /** * @Author WangYX * @Description 合并的票据信息 * @Date 2019/1/17 下午2:06 */ private List child = new ArrayList<>(); @Override public Double getBillMoney() { // log.debug("参数-{}:{}", R_EAMOUT, getMoney(R_EAMOUT)); // log.debug("参数-{}:{}", R_VTAX, getMoney(R_VTAX)); // log.debug("参数-{}:{}", "cliendM", getChildMoney()); return BigDecimal.valueOf(getMoney(R_EAMOUT)) .add(BigDecimal.valueOf(getMoney(R_VTAX))) .add(BigDecimal.valueOf(getChildMoney())) .doubleValue(); } private Double getChildMoney() { if(ObjectUtil.empty(child)){ return 0D; } return child.stream() .filter(ioc->ioc.isAssignableFrom(OCRBillHeaderEntity.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 public Boolean getBillByType(String type) { return Objects.equals(Optional.ofNullable(costType).map(CostType::getCode).orElse(null), type); } private String billCode; @Override public String getBillCode() { if(billCode == null){ this.billCode = StringUtil.getUUID(); } return this.billCode; } @Override @JSONField(serialize=false) public String getBillType() { return costType.getCode(); } @Override public Map getBillOriginalInfo() { return this.bodyDataMap; } @Override public void setCostType(CostType costType) { this.costType = costType; } @Override public CostType getCostType() { return this.costType; } @Override public void appendBill(IOCRBill bill) { 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); } }