package com.changhong.epc.parsing.service.bill.impl;
|
|
import com.changhong.epc.bean.form.CpnVal;
|
import com.changhong.epc.bean.form.Fieldsets;
|
import com.changhong.epc.bean.form.FormBaseEntity;
|
import com.changhong.epc.bean.parsing.BillInfo;
|
import com.changhong.epc.bean.parsing.BillLevel;
|
import com.changhong.epc.bean.tenant.bill.OCRBillEntity;
|
import com.changhong.epc.bean.tenant.bill.OCRBillHeaderEntity;
|
import com.changhong.epc.bean.tenant.system.extend.ErrSystemMsgExtend;
|
import com.changhong.epc.constter.form.FormConst;
|
import com.changhong.epc.constter.system.SystemClients;
|
import com.changhong.epc.parsing.service.bill.cpnval.IBillToCpnValData;
|
import com.changhong.epc.parsing.service.bill.cpnval.imp.BillToCpnValData;
|
import com.changhong.epc.parsing.service.bill.group.AbstractGroupBill;
|
import com.changhong.epc.parsing.service.util.BillTool;
|
import com.changhong.epc.parsing.service.util.IFromOperate;
|
import com.iemsoft.framework.cloud.core.exception.IEMRuntimeException;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.context.annotation.Scope;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
@Slf4j
|
@Service("autoAllotJourney")
|
@Scope("prototype")
|
public class AutoAllotJourneyImpl extends AbstractGroupBill implements SystemClients, FormConst{
|
|
private OCRBillEntity bill;
|
private OCRBillEntity oldBill;
|
|
@Resource
|
private IFromOperate fromOperate;
|
|
private IBillToCpnValData<List<BillLevel>> allotJourney = new BillToCpnValData();
|
/**
|
* 分配行程入口
|
* @param bill
|
* @param billInfo
|
* @return
|
*/
|
@Override
|
@Transactional
|
public Fieldsets addBillInfo(OCRBillEntity bill, BillInfo billInfo) {
|
//未实现 -> 检查是否可分配行程(根据规则检查信息)
|
// int pNum = getPDataRowNum(billInfo.getFormId(),JSONTool.toObj(billInfo.getInfo(), Map.class).get("tenantId"),billInfo.getOrderCode());
|
// billInfo.setFormDataId(pNum);
|
// System.out.println("票据列表:"+JSONTool.toJson(bill.getBillDatas()));
|
billInfoCheck(bill);
|
// System.out.println(JSONTool.toJson(bill));
|
/*
|
* 分配行程
|
*/
|
OCRBillEntity cloneBill;
|
|
//yuezhw 18.1.2,扩展实体,加一个formId;
|
bill.setFormId(billInfo.getFormId());
|
this.bill = bill;
|
|
this.oldBill = JSONTool.toObj(JSONTool.toJson(bill), OCRBillEntity.class);
|
|
mappingJourney(billInfo);
|
cloneBill = resultOCRBillEntity();
|
insertBillData(billInfo, cloneBill);
|
|
return getFieldsets();
|
}
|
|
@Override
|
public OCRBillEntity resultOCRBillEntity() {
|
return getOCRBillEntity();
|
}
|
|
@Override
|
public List<ErrSystemMsgExtend> getRecordErrCode() {
|
return null;
|
}
|
|
@Override
|
protected void editJourney(BillInfo billInfo) {
|
FormBaseEntity formAll = fromOperate.selectFromAll(billInfo);
|
allotJourney.setDatSource(blAll,formAll);
|
allotJourney.analysisSource();
|
String tenantId = Objects.toString(JSONTool.toObj(billInfo.getInfo(), Map.class).get("tenantId"),"0");
|
|
// 获得已经处理 全部行程
|
List<List<CpnVal>> allJourneyCpn = allotJourney.getAllJourneyCpn();
|
// 获得行程子表单
|
CpnVal journeySubForm = allotJourney.getJourneySubForm();
|
/**
|
* 删除之前的行程数据
|
*/
|
try {
|
fromOperate.deleteFormData(billInfo, journeySubForm);
|
} catch (Exception e) {
|
log.error("调用自定表单删除接口失败 !\n\n\n");
|
}
|
try {
|
if(ObjectUtil.empty(allJourneyCpn)){
|
log.debug("行程为空");
|
}else {
|
//向子表单添加行程
|
List<Integer> insertCpnVal = fromOperate.insertCpnVal(billInfo, journeySubForm, allJourneyCpn);
|
log.debug("获得所有行程的行程ID" + Arrays.toString(insertCpnVal.toArray()));
|
/**
|
* 为每一张票据添加行程ID
|
*/
|
allotJourney.setEachBillJourneyId(insertCpnVal);
|
}
|
|
} catch (Exception e) {
|
|
log.debug("调用自定表单删除接口失败 !\n\n\n");
|
throw new IEMRuntimeException("E0100","调用Form自定表单插入接口失败 !");
|
}
|
|
}
|
|
// @Override
|
// protected void setCityBill() {
|
// List<OCRBillHeaderEntity> allBill = getOCRBillEntity().getBillDatas();
|
// splitCityBodyBill(allBill);
|
// super.setCityBill();
|
// }
|
|
/**
|
* 拆分body中的城市间交通费
|
* @param allBill
|
*/
|
protected void splitCityBodyBill(List<OCRBillHeaderEntity> allBill){
|
|
List<OCRBillHeaderEntity> cityBodyBills = new ArrayList<>();
|
// 获得城市间交通费在body中的。
|
Iterator<OCRBillHeaderEntity> ite = allBill.listIterator();
|
while(ite.hasNext()){
|
OCRBillHeaderEntity ocrBillHeaderEntity = ite.next();
|
if(BillTool.isJourneyBill(ocrBillHeaderEntity)
|
&& ObjectUtil.notEmpty(ocrBillHeaderEntity.getBillBodyEntityList())){
|
cityBodyBills.add(ocrBillHeaderEntity);
|
ite.remove();
|
}
|
}
|
if(ObjectUtil.empty(cityBodyBills)){
|
return;
|
}
|
cityBodyBills.stream().forEach(cityBodyBill->allBill.addAll(BillTool.splitBody(cityBodyBill)));
|
}
|
|
@Override
|
protected OCRBillEntity getOCRBillEntity() {
|
return bill;
|
}
|
|
@Override
|
protected OCRBillEntity getOldOCRBillEntity() {
|
return oldBill;
|
}
|
|
public Fieldsets getFieldsets() {
|
return fieldsets;
|
}
|
|
// public int getPDataRowNum(String formId,Object tenantId,String orderCode){
|
// Map<String,Object> map = new HashMap<>();
|
// map.put("formId", formId);
|
// map.put("tenantId", tenantId);
|
// map.put("orderCode", orderCode);
|
// RestInterface restInterface = SpringUtil.getBean(SERVER_FORM.getBeanName(), RestInterface.class);
|
// Object fromRest = restInterface.post(FormUrlConst.SELECT_DATAROWNUM, map, ResMsg.class).getData();
|
// return Integer.parseInt(java.util.Objects.toString(fromRest,"0"));
|
// }
|
}
|