package com.changhong.epc.count.service.format.impl;
|
|
import com.changhong.epc.bean.admin.CorresElField;
|
import com.changhong.epc.bean.admin.CurrencyInfo;
|
import com.changhong.epc.bean.count.MeInfo;
|
import com.changhong.epc.bean.count.format.CpnInfo;
|
import com.changhong.epc.bean.count.format.FormInfo;
|
import com.changhong.epc.bean.tenant.bill.IOCRBill;
|
import com.changhong.epc.bean.tenant.master.AutoMasterVal;
|
import com.changhong.epc.constter.admin.CorresElFieldConst;
|
import com.changhong.epc.constter.parsing.bill.ConstBill;
|
import com.changhong.epc.constter.system.businesscode.BudgetBusinessMeaningCode;
|
import com.changhong.epc.count.service.count.model.CountResult;
|
import com.changhong.epc.count.service.count.model.PublicCorrencyCountResult;
|
import com.changhong.epc.rely.api.epc.admin.CorresElFieldApi;
|
import com.changhong.epc.rely.api.epc.tenant.MasterApi;
|
import com.changhong.epc.rely.api.tool.CurrencyTool;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
import java.util.*;
|
import java.util.function.BiFunction;
|
|
/**
|
* 展示票据详细信息
|
* 票据类型|币种缩写|金额|兑换后金额
|
* :---:|:---:|:---:|:---:
|
* 交通费|USD|100|600
|
* 市内交通费|USD|5|30
|
*/
|
@Slf4j
|
@Service("formatBillDetailInfoCount")
|
public class FormatBillDetailInfoCount extends FormatJourneyErrInfoCount implements BudgetBusinessMeaningCode, CorresElFieldConst, ConstBill {
|
|
public static final Map<String, BiFunction<FormInfo, IOCRBill, Object>> TITLE = Collections.unmodifiableMap(
|
new LinkedHashMap<String, BiFunction<FormInfo, IOCRBill, Object>>(){
|
{
|
put("journey.title.billType", (f, i)->Optional.ofNullable(i.getCostType()).map(IOCRBill.CostType::getName).orElse(""));
|
put("journey.title.money", (f, i)->
|
getCurrencyChar(
|
Optional.ofNullable(i.getBillKeyCode(BILL_CORRENCY))
|
.orElse(
|
Optional.ofNullable(f.seacheCpnInfoByAlias(CURRENCY)).map(CpnInfo::getValue).map(Object::toString).orElse("")
|
)
|
)
|
+
|
CurrencyTool.format(i.getBillMoney()));
|
put("journey.title.exchangeMoney", (f, i)->
|
getCurrencyChar(Optional.ofNullable(f.seacheCpnInfoByAlias(APPLYCATION_CURRENCY)).map(CpnInfo::getValue).map(Object::toString).orElse(""))
|
+
|
CurrencyTool.valueOf(i.getExchangeRate(), i.getBillMoney()));
|
}
|
}
|
);
|
|
public static String getCurrencyChar(String mini){
|
if(ObjectUtil.empty(mini)){
|
return "*";
|
}
|
CurrencyInfo currencyInfo =
|
Optional.ofNullable(SpringUtil.getBean(CorresElFieldApi.class).getVal(CURRENCY_MASTER_JSON, CorresElField::getMdCode))
|
.map(json->JSONTool.toObj(json, CurrencyInfo.class)).orElse(null);
|
if(currencyInfo == null){
|
log.error("没有配置币种主数据json");
|
return "*";
|
}
|
AutoMasterVal autoMasterVal = new AutoMasterVal();
|
autoMasterVal.setMdCode(currencyInfo.getMasterCode());
|
autoMasterVal.setMeCode(currencyInfo.getCurrencyChar());
|
autoMasterVal.setParams(
|
Arrays.asList(
|
MeInfo.of(currencyInfo.getCurrencyMini(), mini)
|
)
|
);
|
String val = SpringUtil.getBean(MasterApi.class).getMasterVal(autoMasterVal);
|
if(ObjectUtil.empty(val)){
|
log.debug("缺失币种主数据:{}", mini);
|
val = "*";
|
}
|
return val;
|
}
|
|
@Override
|
protected CpnInfo.CpnMsgInfo getBillCpnMsgInfo(Double billMoney, boolean validate, CountResult countResult) {
|
CpnInfo.CpnMsgInfo billCpn = super.getBillCpnMsgInfo(billMoney, validate, countResult);
|
if(!(countResult instanceof PublicCorrencyCountResult)){
|
return billCpn;
|
}
|
billCpn.setCpnMsgInfo(billCpn);
|
billCpn.addBillDetail(formInfo, ((PublicCorrencyCountResult) countResult).getBills(), TITLE);
|
BigDecimal sumBill =
|
((PublicCorrencyCountResult) countResult).getBills().stream()
|
.map(bill->new BigDecimal(CurrencyTool.valueOf(bill.getExchangeRate(), bill.getBillMoney())))
|
.reduce(new BigDecimal(0), (s, t)->s.add(t));
|
billCpn.setValue(sumBill);
|
billCpn.setValidateValue(sumBill);
|
return billCpn;
|
}
|
|
}
|