Commit 644c0f5f by kangxiaoshan

月流量报表

parent 1a41f230
...@@ -12,6 +12,7 @@ import javax.persistence.Id; ...@@ -12,6 +12,7 @@ import javax.persistence.Id;
@Entity @Entity
public class TkioFlowHistory { public class TkioFlowHistory {
@Id @Id
@GeneratedValue
private Long id; private Long id;
private String ds; private String ds;
private String email; private String email;
...@@ -23,10 +24,8 @@ public class TkioFlowHistory { ...@@ -23,10 +24,8 @@ public class TkioFlowHistory {
private String nextCode; private String nextCode;
private Integer firstRecode; private Integer firstRecode;
public TkioFlowHistory() { public TkioFlowHistory() {
} }
public TkioFlowHistory(TkioFlow flow) { public TkioFlowHistory(TkioFlow flow) {
......
...@@ -1564,7 +1564,6 @@ public class ShareIncomeServiceImpl implements ShareIncomeService { ...@@ -1564,7 +1564,6 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
public boolean checkLateContract(DateTime dateTime, DateTime creatTime) { public boolean checkLateContract(DateTime dateTime, DateTime creatTime) {
int aferDays = dateTime.monthOfYear().get() == 12 ? 29 : 9; int aferDays = dateTime.monthOfYear().get() == 12 ? 29 : 9;
return dateTime.dayOfMonth().withMaximumValue().plusDays(aferDays).isBefore(creatTime); return dateTime.dayOfMonth().withMaximumValue().plusDays(aferDays).isBefore(creatTime);
} }
private int getDayRange(DateTime range1, DateTime range2) { private int getDayRange(DateTime range1, DateTime range2) {
......
...@@ -91,6 +91,8 @@ public class TrackingFlowTask { ...@@ -91,6 +91,8 @@ public class TrackingFlowTask {
} }
private void calculationFlowByAccount(CalculationFlow calculationFlow, String email) { private void calculationFlowByAccount(CalculationFlow calculationFlow, String email) {
System.out.println(email + " 账号正在处理流量");
try { try {
Account account = accountRepository.findByEmail(email); Account account = accountRepository.findByEmail(email);
List<Account> accountList = accountRepository.findByRootParent(account.getRootParent()); List<Account> accountList = accountRepository.findByRootParent(account.getRootParent());
...@@ -261,7 +263,6 @@ public class TrackingFlowTask { ...@@ -261,7 +263,6 @@ public class TrackingFlowTask {
skip = false; skip = false;
} }
TkioFlow tkioFlow = getTkioFlow(clickFlow, yesterday, sortedContract.get(i), true); TkioFlow tkioFlow = getTkioFlow(clickFlow, yesterday, sortedContract.get(i), true);
Long costFlow = tkioFlow.getCostFlow() == null ? 0L : tkioFlow.getCostFlow(); Long costFlow = tkioFlow.getCostFlow() == null ? 0L : tkioFlow.getCostFlow();
TkioFlowHistory flowHistory = new TkioFlowHistory(tkioFlow); TkioFlowHistory flowHistory = new TkioFlowHistory(tkioFlow);
...@@ -281,42 +282,44 @@ public class TrackingFlowTask { ...@@ -281,42 +282,44 @@ public class TrackingFlowTask {
Contract next = sortedContract.get(i + 1); Contract next = sortedContract.get(i + 1);
if (DateTime.parse(next.getStartDate()).isBefore(DateTime.parse(yesterday)) if (DateTime.parse(next.getStartDate()).isBefore(DateTime.parse(yesterday))
|| DateTime.parse(next.getStartDate()).isEqual(DateTime.parse(yesterday))) { || DateTime.parse(next.getStartDate()).isEqual(DateTime.parse(yesterday))) {
// 生效 // 生效
if (DateTime.parse(next.getStartDate()).monthOfYear().get() != new DateTime(next.getCreateTime()).monthOfYear().get() if (laterRecodeContract(DateTime.parse(next.getStartDate()), new DateTime(next.getCreateTime()))) {
&& new DateTime(next.getCreateTime()).dayOfMonth().get() > 10) { //生效且晚录
if (DateTime.parse(yesterday).isBefore(new DateTime(next.getCreateTime()).dayOfMonth().withMinimumValue())) {
//下一合同录入月1号之前的超出流量计入上分合同
flowHistory.setNextCode(next.getContractCode());//标记用于那份合同的调整流量 (该字段不为空的合同外流量之和为该字段对应合同的调整流量)
tkioFlowHistoryRepository.save(flowHistory);
break;
} else {
//下一合同录入月1号及之后的超出流量计入自己
clickFlow = new BigInteger(costFlow.toString());
fistRecode = true;//首次记录流量 (用于标记调整流量 归属在 合同所在月份中的第一个开始月份)
continue;
}
} else { } else {
//2、生效且非晚录合同 超出流量计入下一合同 //2、生效且非晚录合同 超出流量计入下一合同
clickFlow = new BigInteger(costFlow.toString()); clickFlow = new BigInteger(costFlow.toString());
fistRecode = true; fistRecode = true;
continue; continue;
} }
}
//3、未生效或晚录合同 则关联流量信息到当前合同
if (DateTime.parse(yesterday).monthOfYear().get() == DateTime.parse(next.getStartDate()).monthOfYear().get()) {
//生效当月 超出的流量关联到 该合同
clickFlow = new BigInteger(costFlow.toString());
fistRecode = true;
continue;
} else { } else {
//生效当月之前 超出的流量计入上一合同 //未生效 超出的流量计入自己
flowHistory.setNextCode(next.getContractCode());//标记用于那份合同的调整流量
tkioFlowHistoryRepository.save(flowHistory); tkioFlowHistoryRepository.save(flowHistory);
break;
} }
break;
} else { } else {
//无下一份合同 则关联流量信息到当前合同内 //无下一份合同 超出的流量计入自己
tkioFlowHistoryRepository.save(flowHistory); tkioFlowHistoryRepository.save(flowHistory);
} }
} }
return clickFlow; return clickFlow;
} }
public void task() { public void task() {
List<String> emails = contractRepository.findDistinctEmailByPlatform("tkio");
List<String> emails = contractRepository.findDistinctEmailByPlatform("tkio");
List<TkioFlow> tkioFlowList = new ArrayList<>(); List<TkioFlow> tkioFlowList = new ArrayList<>();
String yesterday = DateUtil.getBeforeDays(1);//昨日 String yesterday = DateUtil.getBeforeDays(1);//昨日
logger.info("昨日流量同步:" + yesterday); logger.info("昨日流量同步:" + yesterday);
...@@ -516,6 +519,11 @@ public class TrackingFlowTask { ...@@ -516,6 +519,11 @@ public class TrackingFlowTask {
return sortedContract; return sortedContract;
} }
public boolean laterRecodeContract(DateTime startTime, DateTime creatTime) {
int aferDays = startTime.monthOfYear().get() == 12 ? 29 : 9;
return startTime.dayOfMonth().withMaximumValue().plusDays(aferDays).isBefore(creatTime);
}
public static void main(String[] args) throws ParseException { public static void main(String[] args) throws ParseException {
String ago = "2020-10-01"; String ago = "2020-10-01";
int between = DateUtil.daysBetween(ago, DateUtil.getBeforeDays(1)) + 1; int between = DateUtil.daysBetween(ago, DateUtil.getBeforeDays(1)) + 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment