package com.changhong.epc.count.service.count.performer.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.changhong.epc.bean.tenant.norm.extend.AppStanderExtend;
|
import com.changhong.epc.bean.tenant.norm.extend.SuppStanderExtend;
|
import com.changhong.epc.constter.parsing.bill.ConstBill;
|
import com.changhong.epc.count.service.count.data.condition.ICountConditionIter;
|
import com.changhong.epc.count.service.count.data.paramiter.IParamIter;
|
import com.changhong.epc.count.service.count.logic.ICountLogic;
|
import com.changhong.epc.count.service.count.logic.ILastMoneyCount;
|
import com.changhong.epc.count.service.count.logic.impl.CountLogicImpl;
|
import com.changhong.epc.count.service.count.model.CountResult;
|
import com.changhong.epc.count.service.count.model.CountResultExtend;
|
import com.changhong.epc.count.service.count.model.CountResultLast;
|
import com.changhong.epc.count.service.count.model.UnitInfo;
|
import com.changhong.epc.count.service.count.performer.ICountPerformer;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.context.annotation.Scope;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Map.Entry;
|
|
/**
|
* 计算费用执行器
|
*/
|
@Slf4j
|
@Service("countPerformer")
|
@Scope("prototype")
|
public class CountPerformer implements ICountPerformer<CountResultLast, AppStanderExtend, SuppStanderExtend, UnitInfo>,ConstBill {
|
|
private IParamIter<UnitInfo> paramIter;
|
private ICountConditionIter<AppStanderExtend, SuppStanderExtend, UnitInfo> countConditionIter;
|
|
private Map<String,List<CountResult>> countResult;
|
|
@Resource
|
private ILastMoneyCount lastMoneyCount;
|
|
private List<CountResultExtend> eachMoney;
|
|
|
/**
|
* 计算结果
|
*/
|
public CountResultLast resultMoney;
|
|
@Override
|
public CountResultLast execute() {
|
resultMoney = new CountResultLast();
|
countResult = new LinkedHashMap<>(); // 使用有序map集合,否则顺序会混乱
|
// 一、迭代单元
|
while(getIParamIter().hasNext()){
|
|
UnitInfo unitinfo = getIParamIter().next();
|
|
/**
|
* 将行程进行分组
|
*/
|
List<CountResult> unitResult = countResult.get(unitinfo.getUuid());
|
if(countResult.get(unitinfo.getUuid()) == null){
|
countResult.put(unitinfo.getUuid(), unitResult = new ArrayList<>());
|
}
|
|
while(getICountConditionIter().hasGropNext()){
|
getICountConditionIter().groupNext();
|
CountResult countResult = getICountLogic().countLogic(getIParamIter(), getICountConditionIter());
|
if(countResult == null){
|
continue;
|
}
|
countResult.setFormDay(unitinfo.getVal(FROM_DATE));
|
unitResult.add(countResult);
|
}
|
|
//补助标准从新遍历
|
getICountConditionIter().gropReset();
|
}
|
|
// 分组
|
resultGroup();
|
return getOtherMoney();
|
}
|
|
protected ICountLogic getICountLogic(){
|
return new CountLogicImpl();
|
}
|
|
@Override
|
public void setIParamIter(IParamIter<UnitInfo> inters) {
|
this.paramIter = inters;
|
}
|
|
@Override
|
public IParamIter<UnitInfo> getIParamIter() {
|
return paramIter;
|
}
|
|
/**
|
* 对结果进行打包分组
|
*/
|
public void resultGroup(){
|
eachMoney = new ArrayList<>();
|
for(Entry<String, List<CountResult>> group: countResult.entrySet()){
|
|
CountResultExtend eachGrolup = new CountResultExtend();
|
eachGrolup.setCountResults(group.getValue());
|
eachGrolup.setOtherMoney(0D);
|
eachMoney.add(eachGrolup);
|
}
|
log.warn("计算后数据:{}", JSONTool.toJson(eachMoney));
|
try{
|
eachMoney = lastMoneyCount.count(getICountConditionIter().getRecord(), eachMoney);
|
}catch (Exception e) {
|
log.error("对结果进行封装。。。。。。。。。。。。");
|
}
|
}
|
|
|
private CountResultLast getOtherMoney() {
|
CountResultLast countResultLast = new CountResultLast();
|
countResultLast.setEachMoney(eachMoney);
|
countResultLast.setNoJoinBillMoney(getNoJoinBill());
|
countResultLast.setIParamIter(this.paramIter);
|
countResultLast.setNoJoinBill(getIParamIter().getNoJoinAllBillInfo());
|
return countResultLast;
|
}
|
|
/**
|
* 返回无行程票据
|
* @return
|
*/
|
private Double getNoJoinBill() {
|
return getIParamIter().getNoJoinAllBillTotalMoney();
|
}
|
|
@Override
|
public void setICountConditionIter(ICountConditionIter<AppStanderExtend, SuppStanderExtend, UnitInfo> countConditionIter) {
|
this.countConditionIter = countConditionIter;
|
}
|
|
@Override
|
public ICountConditionIter<AppStanderExtend, SuppStanderExtend, UnitInfo> getICountConditionIter() {
|
return countConditionIter;
|
}
|
|
|
|
@Override
|
public CountResultLast getResture() {
|
return resultMoney;
|
}
|
|
/**
|
* @param s
|
* @param c
|
* @return
|
* 字符串转化为对象
|
*/
|
@SuppressWarnings("unchecked")
|
public static <T>T convertJson2Class(String s,Class<T> c){
|
Object obj = null;
|
try {
|
obj = JSON.parseObject(s, c);
|
} catch (Exception e) {
|
log.error(e.getMessage(), e);
|
}
|
return (T)obj;
|
}
|
}
|