Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
manager
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
reyun
manager
Commits
bc55e647
Commit
bc55e647
authored
Nov 30, 2020
by
kangxiaoshan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
流量查询方式更改
parent
f5cf2cbd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
66 deletions
+99
-66
TkioFlowHistoryRepository.java
...ain/java/common/repository/TkioFlowHistoryRepository.java
+0
-9
FlowService.java
src/main/java/tkio/service/FlowService.java
+8
-0
FlowServiceImpl.java
src/main/java/tkio/service/impl/FlowServiceImpl.java
+34
-0
TrackingFlowTask.java
src/main/java/track/task/TrackingFlowTask.java
+57
-57
No files found.
src/main/java/common/repository/TkioFlowHistoryRepository.java
View file @
bc55e647
...
...
@@ -2,16 +2,7 @@ package common.repository;
import
common.model.TkioFlowHistory
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.math.BigDecimal
;
public
interface
TkioFlowHistoryRepository
extends
JpaRepository
<
TkioFlowHistory
,
Long
>
{
@Transactional
@Modifying
@Query
(
value
=
" insert into tkio_flow_history select * from tkio_flow where email = ?1 and cost_flow > 0 "
,
nativeQuery
=
true
)
void
backDatasByEmail
(
String
email
);
}
src/main/java/tkio/service/FlowService.java
0 → 100644
View file @
bc55e647
package
tkio
.
service
;
import
java.math.BigInteger
;
import
java.util.List
;
public
interface
FlowService
{
BigInteger
getFlowByAccount
(
String
yesterday
,
String
yesterday1
,
List
<
String
>
appkeys
);
}
src/main/java/tkio/service/impl/FlowServiceImpl.java
0 → 100644
View file @
bc55e647
package
tkio
.
service
.
impl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
tkio.service.FlowService
;
import
java.math.BigInteger
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
FlowServiceImpl
implements
FlowService
{
@Autowired
@Qualifier
(
"tikoTemplate"
)
JdbcTemplate
etlJdbcTemplate
;
@Override
public
BigInteger
getFlowByAccount
(
String
startDate
,
String
pastDate
,
List
<
String
>
appkeys
)
{
NamedParameterJdbcTemplate
nameJdbc
=
new
NamedParameterJdbcTemplate
(
etlJdbcTemplate
);
String
sql
=
" SELECT sum(click_num+ IFNULL(num_impression,0)) as click_sum FROM tkio.measures_trackingio_new "
+
" WHERE appid in (:appids ) AND ds>= :startdate and ds<= :enddate "
;
Map
param
=
new
HashMap
();
param
.
put
(
"appids"
,
appkeys
);
param
.
put
(
"startdate"
,
startDate
);
param
.
put
(
"enddate"
,
pastDate
);
return
nameJdbc
.
queryForObject
(
sql
,
param
,
BigInteger
.
class
);
}
}
src/main/java/track/task/TrackingFlowTask.java
View file @
bc55e647
...
...
@@ -11,6 +11,7 @@ import tkio.model.Account;
import
tkio.repository.AccountRepository
;
import
tkio.repository.AppRepository
;
import
tkio.service.AccountFlowRestrictService
;
import
tkio.service.FlowService
;
import
util.Constant
;
import
util.DateUtil
;
import
util.StringUtil
;
...
...
@@ -36,8 +37,10 @@ public class TrackingFlowTask {
private
AccountRepository
accountRepository
;
@Autowired
private
AppRepository
appRepository
;
/*@Autowired
private AccountFlowRestrictService accountFlowRestrictService;*/
@Autowired
private
AccountFlowRestrictService
accountFlowRestrict
Service
;
private
FlowService
flow
Service
;
@Autowired
private
TkioFlowRepository
tkioFlowRepository
;
@Autowired
...
...
@@ -47,19 +50,17 @@ public class TrackingFlowTask {
@Autowired
private
TkioFlowHistoryRepository
tkioFlowHistoryRepository
;
public
void
syncFlow
(){
public
void
syncFlow
()
{
List
<
CalculationFlow
>
calculationFlows
=
calculationFlowRepository
.
findByStatus
(
0
);
for
(
CalculationFlow
calculationFlow
:
calculationFlows
)
{
List
<
TkioFlow
>
tkioFlowList
=
new
ArrayList
<>();
calculationFlow
.
setStatus
(
1
);
calculationFlowRepository
.
save
(
calculationFlow
);
//记录历史数据
tkioFlowHistoryRepository
.
backDatasByEmail
(
calculationFlow
.
getEmail
());
tkioFlowRepository
.
deleteByEmail
(
calculationFlow
.
getEmail
());
String
email
=
calculationFlow
.
getEmail
();
//查询用户下所有appkey
try
{
try
{
Account
account
=
accountRepository
.
findByEmail
(
email
);
List
<
Account
>
accountList
=
accountRepository
.
findByRootParent
(
account
.
getRootParent
());
List
<
Long
>
idList
=
new
ArrayList
<>();
...
...
@@ -89,7 +90,8 @@ public class TrackingFlowTask {
}
for
(
int
ii
=
between
;
ii
>
startInt
;
ii
--)
{
String
yesterday
=
DateUtil
.
getBeforeDays
(
ii
);
//昨日
BigInteger
clickNum
=
accountFlowRestrictService
.
getTotalNum
(
yesterday
,
yesterday
,
appkeyStr
,
"account_track_flow_restrict"
,
"click_sum"
);
//BigInteger clickNum = accountFlowRestrictService.getTotalNum(yesterday, yesterday, appkeyStr, "account_track_flow_restrict", "click_sum");
BigInteger
clickNum
=
flowService
.
getFlowByAccount
(
yesterday
,
yesterday
,
appkeys
);
if
(
clickNum
!=
null
&&
clickNum
.
longValue
()
>
0
)
{
List
<
Contract
>
contracts
=
contractRepository
.
findByPlatformAndEmail
(
"tkio"
,
email
);
if
(
contracts
.
size
()
==
1
)
{
//只有一个合同
...
...
@@ -127,10 +129,10 @@ public class TrackingFlowTask {
for
(
int
i
=
0
;
i
<
contractsArray
.
length
;
i
++)
{
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contractsArray
[
i
]);
if
(
tkioFlow
!=
null
&&
i
<
contractsArray
.
length
-
1
&&
tkioFlow
.
getCostFlow
()
!=
null
&&
tkioFlow
.
getCostFlow
()
>
0L
)
{
//处理成本流量,如果超出了,依次算在下一个合同上
if
(
tkioFlow
!=
null
&&
i
<
contractsArray
.
length
-
1
&&
tkioFlow
.
getCostFlow
()
!=
null
&&
tkioFlow
.
getCostFlow
()
>
0L
)
{
//处理成本流量,如果超出了,依次算在下一个合同上
clickNum
=
BigInteger
.
valueOf
(
tkioFlow
.
getCostFlow
());
tkioFlow
.
setCostFlow
(
null
);
if
(
tkioFlow
.
getFlow
()>
0
)
{
if
(
tkioFlow
.
getFlow
()
>
0
)
{
tkioFlowList
.
add
(
tkioFlow
);
tkioFlowRepository
.
save
(
tkioFlow
);
}
...
...
@@ -187,20 +189,20 @@ public class TrackingFlowTask {
}
calculationFlow
.
setStatus
(
2
);
calculationFlowRepository
.
save
(
calculationFlow
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"CalculationFlow:Id::"
+
calculationFlow
.
getId
()+
":全流量同步失败"
,
e
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"CalculationFlow:Id::"
+
calculationFlow
.
getId
()
+
":全流量同步失败"
,
e
);
calculationFlow
.
setStatus
(
3
);
calculationFlowRepository
.
save
(
calculationFlow
);
}
}
}
public
void
task
(){
public
void
task
()
{
List
<
String
>
emails
=
contractRepository
.
findDistinctEmailByPlatform
(
"tkio"
);
List
<
TkioFlow
>
tkioFlowList
=
new
ArrayList
<>();
String
yesterday
=
DateUtil
.
getBeforeDays
(
1
);
//昨日
logger
.
info
(
"昨日流量同步:"
+
yesterday
);
logger
.
info
(
"昨日流量同步:"
+
yesterday
);
for
(
String
email
:
emails
)
{
//查询用户下所有appkey
...
...
@@ -212,19 +214,19 @@ public class TrackingFlowTask {
}
List
<
String
>
appkeys
=
appRepository
.
findAppkeysNotDebug
(
idList
);
String
appkeyStr
=
String
.
join
(
"','"
,
appkeys
);
appkeyStr
=
"'"
+
appkeyStr
+
"'"
;
appkeyStr
=
"'"
+
appkeyStr
+
"'"
;
BigInteger
clickNum
=
accountFlowRestrictService
.
getTotalNum
(
yesterday
,
yesterday
,
appkeyStr
,
"account_track_flow_restrict"
,
"click_sum"
);
if
(
clickNum
!=
null
&&
clickNum
.
longValue
()>
0
){
//BigInteger clickNum = accountFlowRestrictService.getTotalNum(yesterday, yesterday, appkeyStr, "account_track_flow_restrict", "click_sum");
BigInteger
clickNum
=
flowService
.
getFlowByAccount
(
yesterday
,
yesterday
,
appkeys
);
if
(
clickNum
!=
null
&&
clickNum
.
longValue
()
>
0
)
{
List
<
Contract
>
contracts
=
contractRepository
.
findByPlatformAndEmail
(
"tkio"
,
email
);
if
(
contracts
.
size
()==
1
)
{
//只有一个合同
if
(
contracts
.
size
()
==
1
)
{
//只有一个合同
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contracts
.
get
(
0
));
if
(
tkioFlow
!=
null
)
{
if
(
tkioFlow
!=
null
)
{
tkioFlowList
.
add
(
tkioFlow
);
tkioFlowRepository
.
save
(
tkioFlow
);
}
}
else
{
//多个合同
}
else
{
//多个合同
//看昨日被哪几个合同包含了
List
<
Contract
>
correlationContract
=
new
ArrayList
<>();
for
(
Contract
contract
:
contracts
)
{
...
...
@@ -237,12 +239,12 @@ public class TrackingFlowTask {
}*/
String
startDate
=
contract
.
getStartDate
();
String
endDate
=
contract
.
getEndDate
();
if
(
DateUtil
.
getDate
(
yesterday
).
getTime
()>=
DateUtil
.
getDate
(
startDate
).
getTime
()
&&
DateUtil
.
getDate
(
yesterday
).
getTime
()<=
DateUtil
.
getDate
(
endDate
).
getTime
())
{
if
(
DateUtil
.
getDate
(
yesterday
).
getTime
()
>=
DateUtil
.
getDate
(
startDate
).
getTime
()
&&
DateUtil
.
getDate
(
yesterday
).
getTime
()
<=
DateUtil
.
getDate
(
endDate
).
getTime
())
{
correlationContract
.
add
(
contract
);
}
}
//多个合同时,进行排序,如果第一个合同流量超出就要看第二个合同,以此往下
if
(
correlationContract
.
size
()>
1
)
{
if
(
correlationContract
.
size
()
>
1
)
{
//冒泡
//第一优先级:合同开始日期,第二优先级,合同编号大小
Contract
[]
contractsArray
=
new
Contract
[
correlationContract
.
size
()];
...
...
@@ -252,15 +254,15 @@ public class TrackingFlowTask {
for
(
int
i
=
0
;
i
<
contractsArray
.
length
;
i
++)
{
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contractsArray
[
i
]);
if
(
tkioFlow
!=
null
&&
i
<
contractsArray
.
length
-
1
&&
tkioFlow
.
getCostFlow
()!=
null
&&
tkioFlow
.
getCostFlow
()>
0L
)
{
//处理成本流量,如果超出了,依次算在下一个合同上
if
(
tkioFlow
!=
null
&&
i
<
contractsArray
.
length
-
1
&&
tkioFlow
.
getCostFlow
()
!=
null
&&
tkioFlow
.
getCostFlow
()
>
0L
)
{
//处理成本流量,如果超出了,依次算在下一个合同上
clickNum
=
BigInteger
.
valueOf
(
tkioFlow
.
getCostFlow
());
tkioFlow
.
setCostFlow
(
null
);
if
(
tkioFlow
.
getFlow
()>
0
)
{
if
(
tkioFlow
.
getFlow
()
>
0
)
{
tkioFlowList
.
add
(
tkioFlow
);
tkioFlowRepository
.
save
(
tkioFlow
);
}
}
else
{
if
(
tkioFlow
!=
null
)
{
}
else
{
if
(
tkioFlow
!=
null
)
{
tkioFlowList
.
add
(
tkioFlow
);
tkioFlowRepository
.
save
(
tkioFlow
);
}
...
...
@@ -268,27 +270,27 @@ public class TrackingFlowTask {
}
}
}
else
{
if
(
correlationContract
.
size
()==
0
)
{
//昨日不包含在所有合同中
}
else
{
if
(
correlationContract
.
size
()
==
0
)
{
//昨日不包含在所有合同中
//排序
Contract
[]
contractsArray
=
new
Contract
[
contracts
.
size
()];
contractsArray
=
contracts
.
toArray
(
contractsArray
);
contractsArray
=
orderByContract
(
contractsArray
);
//如果昨日日期在第一个合同之前,则归属到第一个合同的成本,其余区间都归属到前一个合同的成本上
for
(
int
i
=
0
;
i
<
contractsArray
.
length
;
i
++)
{
if
(
DateUtil
.
getDate
(
yesterday
).
getTime
()<=
DateUtil
.
getDate
(
contractsArray
[
i
].
getStartDate
()).
getTime
()
||
i
==
contractsArray
.
length
-
1
)
{
if
(
DateUtil
.
getDate
(
yesterday
).
getTime
()
<=
DateUtil
.
getDate
(
contractsArray
[
i
].
getStartDate
()).
getTime
()
||
i
==
contractsArray
.
length
-
1
)
{
int
j
=
0
;
if
(
i
!=
0
)
{
j
=
i
-
1
;
if
(
i
!=
0
)
{
j
=
i
-
1
;
}
if
(
i
==
contractsArray
.
length
-
1
)
{
if
(
i
==
contractsArray
.
length
-
1
)
{
j
=
i
;
}
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contractsArray
[
j
]);
if
(
tkioFlow
!=
null
)
{
if
(
tkioFlow
!=
null
)
{
tkioFlowList
.
add
(
tkioFlow
);
tkioFlowRepository
.
save
(
tkioFlow
);
}
...
...
@@ -297,10 +299,9 @@ public class TrackingFlowTask {
}
}
else
{
}
else
{
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
correlationContract
.
get
(
0
));
if
(
tkioFlow
!=
null
)
{
if
(
tkioFlow
!=
null
)
{
tkioFlowList
.
add
(
tkioFlow
);
tkioFlowRepository
.
save
(
tkioFlow
);
}
...
...
@@ -311,31 +312,30 @@ public class TrackingFlowTask {
}
}
if
(
tkioFlowList
.
size
()>
0
)
{
if
(
tkioFlowList
.
size
()
>
0
)
{
//tkioFlowRepository.save(tkioFlowList);
}
}
//排序
public
Contract
[]
orderByContract
(
Contract
[]
contractsArray
){
for
(
int
i
=
0
;
i
<
contractsArray
.
length
-
1
;
i
++)
{
for
(
int
j
=
0
;
j
<
contractsArray
.
length
-
1
-
i
;
j
++)
{
public
Contract
[]
orderByContract
(
Contract
[]
contractsArray
)
{
for
(
int
i
=
0
;
i
<
contractsArray
.
length
-
1
;
i
++)
{
for
(
int
j
=
0
;
j
<
contractsArray
.
length
-
1
-
i
;
j
++)
{
String
startDate1
=
contractsArray
[
j
].
getSignedDate
()
==
null
?
contractsArray
[
j
].
getStartDate
()
:
contractsArray
[
j
].
getSignedDate
();
String
startDate2
=
contractsArray
[
j
+
1
].
getSignedDate
()
==
null
?
contractsArray
[
j
+
1
].
getStartDate
()
:
contractsArray
[
j
+
1
].
getSignedDate
();
if
(
DateUtil
.
getDate
(
startDate1
).
getTime
()
>
DateUtil
.
getDate
(
startDate2
).
getTime
())
{
if
(
DateUtil
.
getDate
(
startDate1
).
getTime
()
>
DateUtil
.
getDate
(
startDate2
).
getTime
())
{
Contract
temp
=
contractsArray
[
j
];
contractsArray
[
j
]
=
contractsArray
[
j
+
1
];
contractsArray
[
j
]
=
contractsArray
[
j
+
1
];
contractsArray
[
j
+
1
]
=
temp
;
}
else
if
(
DateUtil
.
getDate
(
startDate1
).
getTime
()
==
DateUtil
.
getDate
(
startDate2
).
getTime
())
{
}
else
if
(
DateUtil
.
getDate
(
startDate1
).
getTime
()
==
DateUtil
.
getDate
(
startDate2
).
getTime
())
{
String
contractCode
=
StringUtil
.
matchNumber
(
contractsArray
[
j
].
getContractCode
());
String
contractCodeMin
=
StringUtil
.
matchNumber
(
contractsArray
[
j
+
1
].
getContractCode
());
if
(
Long
.
valueOf
(
contractCode
)>
Long
.
valueOf
(
contractCodeMin
))
{
String
contractCodeMin
=
StringUtil
.
matchNumber
(
contractsArray
[
j
+
1
].
getContractCode
());
if
(
Long
.
valueOf
(
contractCode
)
>
Long
.
valueOf
(
contractCodeMin
))
{
Contract
temp
=
contractsArray
[
j
];
contractsArray
[
j
]
=
contractsArray
[
j
+
1
];
contractsArray
[
j
]
=
contractsArray
[
j
+
1
];
contractsArray
[
j
+
1
]
=
temp
;
}
}
...
...
@@ -344,37 +344,37 @@ public class TrackingFlowTask {
return
contractsArray
;
}
public
TkioFlow
getTkioFlow
(
BigInteger
clickNum
,
String
yesterday
,
Contract
contract
)
{
public
TkioFlow
getTkioFlow
(
BigInteger
clickNum
,
String
yesterday
,
Contract
contract
)
{
TkioFlow
tkioFlow
=
new
TkioFlow
();
tkioFlow
.
setDs
(
yesterday
);
tkioFlow
.
setEmail
(
contract
.
getEmail
());
tkioFlow
.
setContractCode
(
contract
.
getContractCode
());
try
{
if
(
DateUtil
.
daysBetween
(
contract
.
getStartDate
(),
yesterday
)<
0
||
DateUtil
.
daysBetween
(
contract
.
getEndDate
(),
yesterday
)>
0
)
{
//昨日日期早于合同开始日期
if
(
DateUtil
.
daysBetween
(
contract
.
getStartDate
(),
yesterday
)
<
0
||
DateUtil
.
daysBetween
(
contract
.
getEndDate
(),
yesterday
)
>
0
)
{
//昨日日期早于合同开始日期
//设置为成本流量
tkioFlow
.
setCostFlow
(
clickNum
.
longValue
());
}
else
{
}
else
{
//查看历史总消耗流量是否超出
BigDecimal
totalFlow
=
tkioFlowRepository
.
sumFlowByEmailAndContractCode
(
contract
.
getEmail
(),
contract
.
getContractCode
());
totalFlow
=
totalFlow
==
null
?
new
BigDecimal
(
0
):
totalFlow
;
BigDecimal
totalFlow
=
tkioFlowRepository
.
sumFlowByEmailAndContractCode
(
contract
.
getEmail
(),
contract
.
getContractCode
());
totalFlow
=
totalFlow
==
null
?
new
BigDecimal
(
0
)
:
totalFlow
;
Double
contractTrackFlow
=
contract
.
getTrackFlow
()
*
10000
;
if
(
contractTrackFlow
.
longValue
()-
totalFlow
.
longValue
()-
clickNum
.
longValue
()>=
0
||
contract
.
getPriceLevel
()==
Constant
.
tkioPriceLevelNotLimit
)
{
if
(
contractTrackFlow
.
longValue
()
-
totalFlow
.
longValue
()
-
clickNum
.
longValue
()
>=
0
||
contract
.
getPriceLevel
()
==
Constant
.
tkioPriceLevelNotLimit
)
{
tkioFlow
.
setFlow
(
clickNum
.
longValue
());
}
else
{
}
else
{
tkioFlow
.
setFlow
(
contractTrackFlow
.
longValue
()
-
totalFlow
.
longValue
());
tkioFlow
.
setCostFlow
(
clickNum
.
longValue
()
-
tkioFlow
.
getFlow
());
tkioFlow
.
setCostFlow
(
clickNum
.
longValue
()
-
tkioFlow
.
getFlow
());
}
}
return
tkioFlow
;
}
catch
(
ParseException
e
)
{
logger
.
error
(
"合同编号-"
+
contract
.
getContractCode
()+
"-同步昨日流量错误:"
,
e
);
logger
.
error
(
"合同编号-"
+
contract
.
getContractCode
()
+
"-同步昨日流量错误:"
,
e
);
}
return
null
;
}
public
static
void
main
(
String
[]
args
)
throws
ParseException
{
String
ago
=
"2020-10-01"
;
int
between
=
DateUtil
.
daysBetween
(
ago
,
DateUtil
.
getBeforeDays
(
1
))
+
1
;
int
between
=
DateUtil
.
daysBetween
(
ago
,
DateUtil
.
getBeforeDays
(
1
))
+
1
;
System
.
out
.
println
(
between
);
for
(
int
i
=
between
;
i
>
0
;
i
--)
{
System
.
out
.
println
(
DateUtil
.
getBeforeDays
(
i
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment