package com.changhong.epc.parsing.service.bill.group;
|
|
import com.changhong.epc.bean.parsing.BillLevel;
|
import com.changhong.epc.bean.tenant.bill.OCRBillHeaderEntity;
|
import com.changhong.epc.constter.parsing.bill.ConstBill;
|
import com.changhong.epc.parsing.service.loop.tools.impl.YMDTools;
|
import com.changhong.epc.parsing.service.util.BillTool;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
|
import java.util.Objects;
|
|
/**
|
* 票据分组规则 (将票据对应到 相应的行程上)
|
* @author wangZX
|
*
|
*/
|
|
@Slf4j
|
public class BillGroupRule implements ConstBill {
|
|
private static Long MIN_DATA_FROM = 6*60*60 * 1000L;
|
private static Long MAX_DATA_FROM = 6*60*60 * 1000L;
|
|
|
|
public static boolean billInDetail(BillLevel billLevel, OCRBillHeaderEntity billInfo){
|
try{
|
long from = YMDTools.getDate(billInfo.getVal(FROM_DATE)+ " "+ (billInfo.getVal(FROM_TIME)==null?"":billInfo.getVal(FROM_TIME))).getTime();
|
long pFrom = YMDTools.getDate( billLevel.getBeginDate()+" "+ (billLevel.getBeginTime()==null?"":billLevel.getBeginTime())).getTime();
|
|
// 行程 12:30 > 票据12:00 行程 6:30 < 票据12:00
|
if(pFrom >= from && pFrom-MIN_DATA_FROM <= from ){
|
return true;
|
}
|
|
long to = YMDTools.getDate(billInfo.getVal(TO_DATE)+ " "+ (billInfo.getVal(TO_TIME)==null?"":billInfo.getVal(TO_TIME))).getTime() ;
|
long pTo = YMDTools.getDate(billLevel.getEndDate() + " "+ billLevel.getEndTime()).getTime();
|
|
if(pTo <= from && pTo+MAX_DATA_FROM >= from){
|
return true;
|
}
|
}catch(Exception e){
|
log.debug(e.toString());
|
}
|
return false;
|
}
|
// billLevel 行程 billInfo票据
|
protected static boolean billEqueryDetail(BillLevel billLevel, OCRBillHeaderEntity billInfo,int state){
|
// 有Date 有Time
|
boolean isDate = false;
|
|
if(state == 1){
|
if(billLevel.getEndDate() == null){
|
isDate = true;
|
}else{
|
try {
|
isDate = YMDTools.getDate(billInfo.getVal(FROM_DATE) + " "+ billInfo.getVal(FROM_TIME)).
|
compareTo(YMDTools.getDate( billLevel.getEndDate() + " "+ billLevel.getEndTime())) <= 0;
|
} catch (Exception e) {
|
isDate = false;
|
}
|
}
|
return ((
|
YMDTools.getDate( billInfo.getVal(FROM_DATE) +" "+ billInfo.getVal(FROM_TIME) ).
|
compareTo(YMDTools.getDate( billLevel.getBeginDate()+" "+ billLevel.getBeginTime())) >= 0
|
&& isDate
|
|
) || billInDetail(billLevel,billInfo))
|
&&
|
(
|
Objects.equals(billInfo.getVal(FROM_SIT), billLevel.getEndSit()) ||
|
Objects.equals(billInfo.getVal(FROM_SIT), billLevel.getBeginSit())
|
);
|
}
|
// 有Date 没有Time
|
else if(state == 2){
|
|
return (
|
YMDTools.getDate( billInfo.getVal(FROM_DATE)).
|
compareTo(YMDTools.getDate( billLevel.getBeginDate())) >= 0
|
&&
|
YMDTools.getDate( billInfo.getVal(FROM_DATE)).
|
compareTo(YMDTools.getDate( billLevel.getEndDate())) <= 0
|
) ||
|
(
|
billInDetail(billLevel,billInfo)
|
&&
|
(
|
Objects.equals(billInfo.getVal(FROM_SIT), billLevel.getEndSit())
|
||
|
Objects.equals(billInfo.getVal(FROM_SIT), billLevel.getBeginSit())
|
)
|
);
|
}
|
// 没有Date
|
else if(state == 3)
|
return Objects.equals(billInfo.getVal(FROM_SIT), billLevel.getEndSit()) ||
|
Objects.equals(billInfo.getVal(FROM_SIT), billLevel.getBeginSit());
|
else
|
return false;
|
}
|
|
// billLevel 行程 billInfo票据
|
public static boolean billEquery(BillLevel billLevel, OCRBillHeaderEntity billInfo){
|
try{
|
|
/* 城市间交通费 */
|
if(BillTool.isJourneyBill(billInfo)){
|
|
// 1. 有date
|
if(StringUtils.isNoneBlank(billInfo.getVal(FROM_DATE))){
|
// 有Time
|
if(StringUtils.isNoneBlank(billInfo.getVal(FROM_TIME))){
|
// 有 Time 就判断Date 大于等于出发地的date ,<= ToDate && (票据的From出发地 = 行程的到达地To || 票据的from == 行程的 from)
|
return billEqueryDetail( billLevel, billInfo, 1);
|
}
|
// 没有Time
|
else{
|
return billEqueryDetail( billLevel, billInfo, 2);
|
}
|
}
|
else{
|
return billEqueryDetail( billLevel, billInfo, 3);
|
}
|
}
|
/* 其他票据类型 */
|
else{
|
//return YMDTools.getDate(billInfo.getVal(BILL_DATE));
|
if(StringUtils.isNoneBlank(billInfo.getVal(FROM_DATE))){
|
return billEqueryDetail( billLevel, billInfo, 2);
|
}else{
|
return billEqueryDetail( billLevel, billInfo, 3);
|
}
|
}
|
|
}catch (Exception e){
|
return false;
|
}
|
}
|
|
public static void main(String... args){
|
String json = "[\n" +
|
" {\n" +
|
" \"beginDate\": \"2017-12-14\",\n" +
|
" \"beginSit\": \"JTZD000005\",\n" +
|
" \"beginTime\": \"20:00\",\n" +
|
" \"billLevels\": [\n" +
|
" {\n" +
|
" \"allotTenant\": true,\n" +
|
" \"billBodyEntityList\": [\n" +
|
" \n" +
|
" ],\n" +
|
" \"billCode\": \"1018500180700060-002-02\",\n" +
|
" \"billHeadMap\": {\n" +
|
" \"620033\": \"20:00\",\n" +
|
" \"550025\": \"015K079125\",\n" +
|
" \"560133\": \"174.50\",\n" +
|
" \"620024\": \"20171214\",\n" +
|
" \"610013\": \"张华远\",\n" +
|
" \"520017\": \"兰州西\",\n" +
|
" \"520001\": \"西安北\",\n" +
|
" \"600013\": \"02车10A号\",\n" +
|
" \"600014\": \"二等座\",\n" +
|
" \"600004\": \"D2667\"\n" +
|
" },\n" +
|
" \"billKeyCode\": {\n" +
|
" \"Trains\": \"D2667\",\n" +
|
" \"PersonalName\": \"张华远\",\n" +
|
" \"Amount\": \"174.50\",\n" +
|
" \"trafficType\": \"F000002\",\n" +
|
" \"FromDate\": \"2017-12-14\",\n" +
|
" \"SeatLevel\": \"JTXB000009\",\n" +
|
" \"From_site\": \"JTZD000005\",\n" +
|
" \"FromTime\": \"20:00\",\n" +
|
" \"To_site\": \"JTZD000006\"\n" +
|
" },\n" +
|
" \"billKeyName\": {\n" +
|
" \"Trains\": \"D2667\",\n" +
|
" \"PersonalName\": \"张华远\",\n" +
|
" \"Amount\": \"174.50\",\n" +
|
" \"trafficType\": \"动车、高铁(G/D/C)\",\n" +
|
" \"FromDate\": \"2017-12-14\",\n" +
|
" \"SeatLevel\": \"二等座\",\n" +
|
" \"From_site\": \"西安北\",\n" +
|
" \"FromTime\": \"20:00\",\n" +
|
" \"To_site\": \"兰州西\"\n" +
|
" },\n" +
|
" \"billMasterCode\": {\n" +
|
" \"F000057\\u00A0\": \"F000002\",\n" +
|
" \"F000063\": \"JTZD000005\",\n" +
|
" \"F000048\": \"张华远\",\n" +
|
" \"F000058\": \"JTXB000009\"\n" +
|
" },\n" +
|
" \"billMasterName\": {\n" +
|
" \"F000057\\u00A0\": \"动车、高铁(G/D/C)\",\n" +
|
" \"F000063\": \"西安北\",\n" +
|
" \"F000048\": \"张华远\",\n" +
|
" \"F000058\": \"二等座\"\n" +
|
" },\n" +
|
" \"billModelCode\": \"B00000000001\",\n" +
|
" \"costType\": {\n" +
|
" \"code\": \"carFare\",\n" +
|
" \"name\": \"交通费\"\n" +
|
" },\n" +
|
" \"ignore\": false,\n" +
|
" \"ruleMsg\": [\n" +
|
" \n" +
|
" ]\n" +
|
" }\n" +
|
" ],\n" +
|
" \"cacheEndTime\": \"00:00\",\n" +
|
" \"empty\": false,\n" +
|
" \"endDate\": \"2017-12-17\",\n" +
|
" \"endSit\": \"JTZD000006\",\n" +
|
" \"endTime\": \"17:47\"\n" +
|
" },\n" +
|
" {\n" +
|
" \"beginDate\": \"2017-12-17\",\n" +
|
" \"beginSit\": \"JTZD000006\",\n" +
|
" \"beginTime\": \"17:47\",\n" +
|
" \"billLevels\": [\n" +
|
" {\n" +
|
" \"allotTenant\": true,\n" +
|
" \"billBodyEntityList\": [\n" +
|
" \n" +
|
" ],\n" +
|
" \"billCode\": \"1018500180700060-002-01\",\n" +
|
" \"billHeadMap\": {\n" +
|
" \"620033\": \"17:47\",\n" +
|
" \"550025\": \"D045616\",\n" +
|
" \"560133\": \"174.50\",\n" +
|
" \"620024\": \"20171217\",\n" +
|
" \"610013\": \"张华远\",\n" +
|
" \"520017\": \"西安北\",\n" +
|
" \"520001\": \"兰州西\",\n" +
|
" \"600013\": \"08车12F号\",\n" +
|
" \"600014\": \"二等座\",\n" +
|
" \"600004\": \"D2674\"\n" +
|
" },\n" +
|
" \"billKeyCode\": {\n" +
|
" \"Trains\": \"D2674\",\n" +
|
" \"PersonalName\": \"张华远\",\n" +
|
" \"Amount\": \"174.50\",\n" +
|
" \"trafficType\": \"F000002\",\n" +
|
" \"FromDate\": \"2017-12-17\",\n" +
|
" \"SeatLevel\": \"JTXB000009\",\n" +
|
" \"From_site\": \"JTZD000006\",\n" +
|
" \"FromTime\": \"17:47\",\n" +
|
" \"To_site\": \"JTZD000005\"\n" +
|
" },\n" +
|
" \"billKeyName\": {\n" +
|
" \"Trains\": \"D2674\",\n" +
|
" \"PersonalName\": \"张华远\",\n" +
|
" \"Amount\": \"174.50\",\n" +
|
" \"trafficType\": \"动车、高铁(G/D/C)\",\n" +
|
" \"FromDate\": \"2017-12-17\",\n" +
|
" \"SeatLevel\": \"二等座\",\n" +
|
" \"From_site\": \"兰州西\",\n" +
|
" \"FromTime\": \"17:47\",\n" +
|
" \"To_site\": \"西安北\"\n" +
|
" },\n" +
|
" \"billMasterCode\": {\n" +
|
" \"F000057\\u00A0\": \"F000002\",\n" +
|
" \"F000063\": \"JTZD000006\",\n" +
|
" \"F000048\": \"张华远\",\n" +
|
" \"F000058\": \"JTXB000009\"\n" +
|
" },\n" +
|
" \"billMasterName\": {\n" +
|
" \"F000057\\u00A0\": \"动车、高铁(G/D/C)\",\n" +
|
" \"F000063\": \"兰州西\",\n" +
|
" \"F000048\": \"张华远\",\n" +
|
" \"F000058\": \"二等座\"\n" +
|
" },\n" +
|
" \"billModelCode\": \"B00000000001\",\n" +
|
" \"costType\": {\n" +
|
" \"code\": \"carFare\",\n" +
|
" \"name\": \"交通费\"\n" +
|
" },\n" +
|
" \"ignore\": false,\n" +
|
" \"ruleMsg\": [\n" +
|
" \n" +
|
" ]\n" +
|
" }\n" +
|
" ],\n" +
|
" \"cacheEndTime\": \"00:00\",\n" +
|
" \"empty\": false,\n" +
|
" \"endSit\": \"JTZD000005\",\n" +
|
" \"endTime\": \"00:00\"\n" +
|
" }\n" +
|
"]";
|
OCRBillHeaderEntity bill = JSONTool.toObj("{\n" +
|
" \"allotTenant\": true,\n" +
|
" \"billBodyEntityList\": [\n" +
|
" \n" +
|
" ],\n" +
|
" \"billCode\": \"1018500180700060-001-01\",\n" +
|
" \"billHeadMap\": {\n" +
|
" \"590006\": \"四川省成都市国家税务局通用机打发票\",\n" +
|
" \"620033\": \"16:56\",\n" +
|
" \"560023\": \"\",\n" +
|
" \"560133\": \"10.23\",\n" +
|
" \"620024\": \"20171215\",\n" +
|
" \"620040\": \"16:56\",\n" +
|
" \"620010\": \"\",\n" +
|
" \"590010\": \"\",\n" +
|
" \"550031\": \"\",\n" +
|
" \"570001\": \"发票联\",\n" +
|
" \"550025\": \"27514722\",\n" +
|
" \"550011\": \"\",\n" +
|
" \"550099\": \"K370016946\",\n" +
|
" \"640003\": \"国家税务局监制\",\n" +
|
" \"560060\": \"\",\n" +
|
" \"520040\": \"兰州西\",\n" +
|
" \"540040\": \"\"\n" +
|
" },\n" +
|
" \"billKeyCode\": {\n" +
|
" \"trafficType\": \"F000008\",\n" +
|
" \"FromDate\": \"2017-12-15\",\n" +
|
" \"From_site\": \"JTZD000006\",\n" +
|
" \"Amount\": \"10.23\"\n" +
|
" },\n" +
|
" \"billKeyName\": {\n" +
|
" \"trafficType\": \"出租车\",\n" +
|
" \"FromDate\": \"2017-12-15\",\n" +
|
" \"From_site\": \"兰州西\",\n" +
|
" \"Amount\": \"10.23\"\n" +
|
" },\n" +
|
" \"billMasterCode\": {\n" +
|
" \"F000063\": \"JTZD000006\",\n" +
|
" \"F000057\": \"F000008\"\n" +
|
" },\n" +
|
" \"billMasterName\": {\n" +
|
" \"F000063\": \"兰州西\",\n" +
|
" \"F000057\": \"出租车\"\n" +
|
" },\n" +
|
" \"billModelCode\": \"B00000050001\",\n" +
|
" \"costType\": {\n" +
|
" \"code\": \"shineiJTF\",\n" +
|
" \"name\": \"市内交通费\"\n" +
|
" },\n" +
|
" \"ignore\": false,\n" +
|
" \"ruleMsg\": [\n" +
|
" \n" +
|
" ]\n" +
|
"}", OCRBillHeaderEntity.class);
|
JSONTool.toList(json, BillLevel.class).stream().forEach(billLevel -> {
|
// System.out.println(BillGroupRule.billEquery(billLevel, bill));
|
});
|
}
|
}
|