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
f106616f
Commit
f106616f
authored
Oct 19, 2020
by
lzxry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
流量同步
parent
ed285c85
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
646 additions
and
4 deletions
+646
-4
CalculationFlow.java
src/main/java/common/model/CalculationFlow.java
+79
-0
Contract.java
src/main/java/common/model/Contract.java
+1
-1
TkioFlow.java
src/main/java/common/model/TkioFlow.java
+60
-0
CalculationFlowRepository.java
...ain/java/common/repository/CalculationFlowRepository.java
+15
-0
ContractRepository.java
src/main/java/common/repository/ContractRepository.java
+6
-0
TkioFlowRepository.java
src/main/java/common/repository/TkioFlowRepository.java
+18
-0
ContractServiceImpl.java
src/main/java/common/service/impl/ContractServiceImpl.java
+93
-1
AccountTask.java
src/main/java/track/task/AccountTask.java
+0
-2
TrackingFlowTask.java
src/main/java/track/task/TrackingFlowTask.java
+362
-0
applicationContext-schedule.xml
src/main/resources/spring/applicationContext-schedule.xml
+12
-0
No files found.
src/main/java/common/model/CalculationFlow.java
0 → 100644
View file @
f106616f
package
common
.
model
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
/**
* @author liyin
* @description
* @date
*/
@Entity
public
class
CalculationFlow
{
private
Long
id
;
private
String
email
;
private
String
contractCode
;
private
String
triggerType
;
private
Boolean
isAll
;
private
Integer
status
;
private
String
createTime
;
@Id
@GeneratedValue
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getContractCode
()
{
return
contractCode
;
}
public
void
setContractCode
(
String
contractCode
)
{
this
.
contractCode
=
contractCode
;
}
public
String
getTriggerType
()
{
return
triggerType
;
}
public
void
setTriggerType
(
String
triggerType
)
{
this
.
triggerType
=
triggerType
;
}
public
Integer
getStatus
()
{
return
status
;
}
public
void
setStatus
(
Integer
status
)
{
this
.
status
=
status
;
}
public
Boolean
getIsAll
()
{
return
isAll
;
}
public
void
setIsAll
(
Boolean
isAll
)
{
this
.
isAll
=
isAll
;
}
public
String
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
String
createTime
)
{
this
.
createTime
=
createTime
;
}
}
src/main/java/common/model/Contract.java
View file @
f106616f
...
...
@@ -94,7 +94,7 @@ public class Contract {
private
String
barrioName
;
//行政区域名称
private
String
belongGroup
;
//隶属集团
private
Double
trackFlow
;
//流量,tkio的
private
Double
trackFlow
;
//流量,tkio的
,万单位
private
Double
unitPrice
;
//单价,tkio
private
Double
clickFlow
;
//区间点击数,tkio
...
...
src/main/java/common/model/TkioFlow.java
0 → 100644
View file @
f106616f
package
common
.
model
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
/**
* @author liyin
* @description
* @date
*/
@Entity
public
class
TkioFlow
{
@Id
private
String
ds
;
private
String
email
;
private
String
contractCode
;
private
Long
flow
;
private
Long
costFlow
;
public
String
getDs
()
{
return
ds
;
}
public
void
setDs
(
String
ds
)
{
this
.
ds
=
ds
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getContractCode
()
{
return
contractCode
;
}
public
void
setContractCode
(
String
contractCode
)
{
this
.
contractCode
=
contractCode
;
}
public
Long
getFlow
()
{
return
flow
;
}
public
void
setFlow
(
Long
flow
)
{
this
.
flow
=
flow
;
}
public
Long
getCostFlow
()
{
return
costFlow
;
}
public
void
setCostFlow
(
Long
costFlow
)
{
this
.
costFlow
=
costFlow
;
}
}
src/main/java/common/repository/CalculationFlowRepository.java
0 → 100644
View file @
f106616f
package
common
.
repository
;
import
common.model.CalculationFlow
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
@Transactional
public
interface
CalculationFlowRepository
extends
JpaRepository
<
CalculationFlow
,
Long
>
{
@Query
(
value
=
"select * from calculation_flow where status = ?1"
,
nativeQuery
=
true
)
List
<
CalculationFlow
>
findByStatus
(
int
status
);
}
src/main/java/common/repository/ContractRepository.java
View file @
f106616f
...
...
@@ -122,4 +122,10 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query
(
value
=
"select * from contract where contract_code=?1 limit 1 "
,
nativeQuery
=
true
)
Contract
checkByCode
(
String
code
);
@Query
(
value
=
"select distinct email from contract where platform = ?1"
,
nativeQuery
=
true
)
List
<
String
>
findDistinctEmailByPlatform
(
String
platform
);
@Query
(
value
=
"SELECT * from contract where platform = ?1 and email = ?2"
,
nativeQuery
=
true
)
List
<
Contract
>
findByPlatformAndEmail
(
String
platform
,
String
email
);
}
src/main/java/common/repository/TkioFlowRepository.java
0 → 100644
View file @
f106616f
package
common
.
repository
;
import
common.model.TkioFlow
;
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
;
public
interface
TkioFlowRepository
extends
JpaRepository
<
TkioFlow
,
Long
>
{
@Query
(
value
=
"select sum(flow) from tkio_flow where email = ?1 and contract_code = ?2"
,
nativeQuery
=
true
)
Long
sumFlowByEmailAndContractCode
(
String
email
,
String
contractCode
);
@Transactional
@Modifying
@Query
(
value
=
"delete from tkio_flow where email = ?1"
,
nativeQuery
=
true
)
void
deleteByEmail
(
String
email
);
}
src/main/java/common/service/impl/ContractServiceImpl.java
View file @
f106616f
...
...
@@ -220,6 +220,9 @@ public class ContractServiceImpl implements ContractService {
@Autowired
private
BarrioCityRepository
barrioCityRepository
;
@Autowired
private
CalculationFlowRepository
calculationFlowRepository
;
@Override
public
Map
<
String
,
Object
>
checkAccount
(
String
email
,
String
platfrom
)
{
...
...
@@ -564,11 +567,33 @@ public class ContractServiceImpl implements ContractService {
//this.calculateShareIncome(resource);//判断是否计算调整金
//判断库里是否已有合同的主账号
if
(
"tkio"
.
equals
(
resource
.
getPlatform
())){
List
<
Contract
>
contracts
=
contractRepository
.
findByPlatformAndEmail
(
resource
.
getPlatform
(),
resource
.
getEmail
());
CalculationFlow
calculationFlow
=
new
CalculationFlow
();
calculationFlow
.
setEmail
(
resource
.
getEmail
());
calculationFlow
.
setContractCode
(
resource
.
getContractCode
());
calculationFlow
.
setStatus
(
0
);
calculationFlow
.
setTriggerType
(
"新建"
);
calculationFlow
.
setCreateTime
(
DateUtil
.
getCurrentDateStr
());
calculationFlow
.
setIsAll
(
false
);
if
(
contracts
==
null
||
contracts
.
size
()>
0
){
for
(
Contract
contract
:
contracts
)
{
if
(
intersection
(
contract
,
resource
)){
//有交集
calculationFlow
.
setIsAll
(
true
);
break
;
}
}
}
calculationFlowRepository
.
save
(
calculationFlow
);
}
resource
=
contractRepository
.
save
(
resource
);
this
.
saveContractRelations
(
resource
,
resource
.
getId
());
List
<
String
>
codes
=
contractRepository
.
findContractBodyNames
(
resource
.
getCustomerBody
(),
resource
.
getContractCode
());
if
(!
codes
.
isEmpty
())
{
// 合同编号已存在
...
...
@@ -866,9 +891,40 @@ public class ContractServiceImpl implements ContractService {
resource
.
setId
(
contract
.
getId
());
//判断库里是否已有合同的主账号
if
(
"tkio"
.
equals
(
resource
.
getPlatform
())
&&
(
contract
.
getStartDate
()!=
resource
.
getStartDate
()&&
contract
.
getEndDate
()!=
resource
.
getEndDate
())){
List
<
Contract
>
contracts
=
contractRepository
.
findByPlatformAndEmail
(
resource
.
getPlatform
(),
resource
.
getEmail
());
CalculationFlow
calculationFlow
=
new
CalculationFlow
();
calculationFlow
.
setEmail
(
resource
.
getEmail
());
calculationFlow
.
setContractCode
(
resource
.
getContractCode
());
calculationFlow
.
setStatus
(
0
);
calculationFlow
.
setTriggerType
(
"编辑"
);
calculationFlow
.
setCreateTime
(
DateUtil
.
getCurrentDateStr
(
DateUtil
.
C_TIME_PATTON_DEFAULT
));
calculationFlow
.
setIsAll
(
false
);
if
(
contracts
==
null
||
contracts
.
size
()>
0
){
for
(
Contract
contract1
:
contracts
)
{
if
(
contract1
.
getId
()!=
contract
.
getId
()){
if
(
intersection
(
contract1
,
resource
)
||
intersection
(
contract1
,
contract
)){
//有交集
calculationFlow
.
setIsAll
(
true
);
break
;
}
}
}
}
calculationFlowRepository
.
save
(
calculationFlow
);
}
return
contractRepository
.
save
(
resource
);
}
public
Boolean
intersection
(
Contract
contract1
,
Contract
contract2
){
return
(
DateUtil
.
getDate
(
contract1
.
getStartDate
()).
getTime
()<=
DateUtil
.
getDate
(
contract2
.
getStartDate
()).
getTime
()&&
DateUtil
.
getDate
(
contract1
.
getEndDate
()).
getTime
()>=
DateUtil
.
getDate
(
contract2
.
getStartDate
()).
getTime
()
)||
(
DateUtil
.
getDate
(
contract1
.
getStartDate
()).
getTime
()<=
DateUtil
.
getDate
(
contract2
.
getEndDate
()).
getTime
()&&
DateUtil
.
getDate
(
contract1
.
getEndDate
()).
getTime
()>=
DateUtil
.
getDate
(
contract2
.
getEndDate
()).
getTime
())
||
(
DateUtil
.
getDate
(
contract2
.
getStartDate
()).
getTime
()<=
DateUtil
.
getDate
(
contract1
.
getStartDate
()).
getTime
()&&
DateUtil
.
getDate
(
contract2
.
getEndDate
()).
getTime
()>=
DateUtil
.
getDate
(
contract1
.
getEndDate
()).
getTime
());
}
private
List
<
ChangeDelDetail
>
changeDelInfoForContract
(
Contract
byfind
,
Contract
resource
,
Long
pid
,
String
ip
)
{
...
...
@@ -1679,6 +1735,28 @@ public class ContractServiceImpl implements ContractService {
resource
.
setContent
(
ContractStatusEnum
.
SUSPEND
.
getValue
());
contract
.
setStatus
(
ContractStatusEnum
.
SUSPEND
.
getKey
());
showTip
=
true
;
//判断库里是否已有合同的主账号
if
(
"tkio"
.
equals
(
resource
.
getPlatform
())){
List
<
Contract
>
contracts
=
contractRepository
.
findByPlatformAndEmail
(
resource
.
getPlatform
(),
resource
.
getEmail
());
CalculationFlow
calculationFlow
=
new
CalculationFlow
();
calculationFlow
.
setEmail
(
resource
.
getEmail
());
calculationFlow
.
setContractCode
(
resource
.
getContractCode
());
calculationFlow
.
setStatus
(
0
);
calculationFlow
.
setTriggerType
(
"终止"
);
calculationFlow
.
setCreateTime
(
DateUtil
.
getCurrentDateStr
());
calculationFlow
.
setIsAll
(
false
);
if
(
contracts
==
null
||
contracts
.
size
()>
0
){
for
(
Contract
contract1
:
contracts
)
{
if
(
contract1
.
getId
()!=
contract
.
getId
()){
if
(
intersection
(
contract1
,
contract
)){
//有交集
calculationFlow
.
setIsAll
(
true
);
break
;
}
}
}
}
calculationFlowRepository
.
save
(
calculationFlow
);
}
}
}
...
...
@@ -2321,6 +2399,7 @@ public class ContractServiceImpl implements ContractService {
Map
<
String
,
String
>
codeUniqueDic
=
new
HashMap
<>();
List
<
String
>
accountsEmail
=
new
ArrayList
<>();
List
<
String
>
moreEmail
=
new
ArrayList
<>();
for
(
int
j
=
1
;
j
<=
rowNumber
;
j
++)
{
Row
row_data
=
sheet
.
getRow
(
j
);
Object
[]
s_data
=
new
Object
[
titleKey
.
size
()
+
extend_size
];
...
...
@@ -2434,6 +2513,9 @@ public class ContractServiceImpl implements ContractService {
s_data
[
w
]
=
dataSTR
;
if
(
"email"
.
equals
(
sheetTitle
)
&&
!
StringUtils
.
isEmpty
(
dataSTR
)
&&
"tkio"
.
equals
(
platformexcl
))
{
if
(!
accountsEmail
.
contains
(
dataSTR
.
trim
())){
moreEmail
.
add
(
dataSTR
.
trim
());
}
accountsEmail
.
add
(
dataSTR
.
trim
());
}
}
...
...
@@ -2509,7 +2591,17 @@ public class ContractServiceImpl implements ContractService {
// TransactionStatus transactionStatus = transactionUtils.begin();
jdbcTemplate
.
batchUpdate
(
sql
.
toString
(),
args_data
);
// transactionUtils.commit(transactionStatus);
if
(
"tkio"
.
equals
(
platform
)){
for
(
String
email
:
moreEmail
)
{
CalculationFlow
calculationFlow
=
new
CalculationFlow
();
calculationFlow
.
setEmail
(
email
);
calculationFlow
.
setStatus
(
0
);
calculationFlow
.
setTriggerType
(
"导入"
);
calculationFlow
.
setCreateTime
(
DateUtil
.
getCurrentDateStr
());
calculationFlow
.
setIsAll
(
true
);
calculationFlowRepository
.
save
(
calculationFlow
);
}
}
return
ResultModel
.
OK
();
}
...
...
src/main/java/track/task/AccountTask.java
View file @
f106616f
package
track
.
task
;
import
common.model.Account4Web
;
import
common.model.TrackAccount4Web
;
import
common.repository.TrackAccount4WebRepository
;
import
org.jsoup.helper.DataUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
track.model.Account
;
import
track.repository.TrackAccountRepository
;
...
...
src/main/java/track/task/TrackingFlowTask.java
0 → 100644
View file @
f106616f
package
track
.
task
;
import
common.model.CalculationFlow
;
import
common.model.Contract
;
import
common.model.ContractChange
;
import
common.model.TkioFlow
;
import
common.repository.CalculationFlowRepository
;
import
common.repository.ContractChangeRepository
;
import
common.repository.ContractRepository
;
import
common.repository.TkioFlowRepository
;
import
dic.ContractStatusEnum
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
tkio.model.Account
;
import
tkio.repository.AccountRepository
;
import
tkio.repository.AppRepository
;
import
tkio.service.AccountFlowRestrictService
;
import
util.DateUtil
;
import
javax.persistence.Entity
;
import
java.math.BigInteger
;
import
java.text.ParseException
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author liyin
* @description
* @date
*/
public
class
TrackingFlowTask
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
TrackingFlowTask
.
class
);
@Autowired
private
ContractRepository
contractRepository
;
@Autowired
private
AccountRepository
accountRepository
;
@Autowired
private
AppRepository
appRepository
;
@Autowired
private
AccountFlowRestrictService
accountFlowRestrictService
;
@Autowired
private
TkioFlowRepository
tkioFlowRepository
;
@Autowired
private
ContractChangeRepository
contractChangeRepository
;
@Autowired
private
CalculationFlowRepository
calculationFlowRepository
;
public
void
syncFlow
(){
List
<
CalculationFlow
>
calculationFlows
=
calculationFlowRepository
.
findByStatus
(
0
);
for
(
CalculationFlow
calculationFlow
:
calculationFlows
)
{
List
<
TkioFlow
>
tkioFlowList
=
new
ArrayList
<>();
calculationFlow
.
setStatus
(
1
);
calculationFlowRepository
.
save
(
calculationFlow
);
tkioFlowRepository
.
deleteByEmail
(
calculationFlow
.
getEmail
());
String
email
=
calculationFlow
.
getEmail
();
//查询用户下所有appkey
Account
account
=
accountRepository
.
findByEmail
(
email
);
List
<
Account
>
accountList
=
accountRepository
.
findByRootParent
(
account
.
getRootParent
());
List
<
Long
>
idList
=
new
ArrayList
<>();
for
(
Account
ac
:
accountList
)
{
idList
.
add
(
ac
.
getId
());
}
List
<
String
>
appkeys
=
appRepository
.
findAppkeysNotDebug
(
idList
);
String
appkeyStr
=
String
.
join
(
"','"
,
appkeys
);
appkeyStr
=
"'"
+
appkeyStr
+
"'"
;
String
ago
=
DateUtil
.
format
(
account
.
getCreateTime
(),
DateUtil
.
C_DATE_PATTON_DEFAULT
);
//查找最早一天的流量
if
(
ago
==
null
){
calculationFlow
.
setStatus
(
2
);
calculationFlowRepository
.
save
(
calculationFlow
);
continue
;
}
int
between
=
0
;
try
{
between
=
DateUtil
.
daysBetween
(
ago
,
DateUtil
.
getBeforeDays
(
1
))+
1
;
}
catch
(
ParseException
e
)
{
logger
.
error
(
"强转错误:"
,
e
);
}
int
startInt
=
0
;
if
(
Integer
.
valueOf
(
DateUtil
.
getHH
())>
10
){
startInt
=
-
1
;
}
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"
);
if
(
clickNum
!=
null
&&
clickNum
.
longValue
()>
0
){
List
<
Contract
>
contracts
=
contractRepository
.
findByPlatformAndEmail
(
"tkio"
,
email
);
if
(
contracts
.
size
()==
1
){
//只有一个合同
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contracts
.
get
(
0
));
if
(
tkioFlow
!=
null
){
tkioFlowList
.
add
(
tkioFlow
);
}
}
else
{
//多个合同
//看昨日被哪几个合同包含了
List
<
Contract
>
correlationContract
=
new
ArrayList
<>();
for
(
Contract
contract
:
contracts
)
{
if
(
ContractStatusEnum
.
CANCEL
.
getKey
().
equals
(
contract
.
getStatus
())
||
ContractStatusEnum
.
SUSPEND
.
getKey
().
equals
(
contract
.
getStatus
()))
{
//中止或作废合同处理结束时间,以方便昨日流量的归属计算
ContractChange
contractChange
=
contractChangeRepository
.
findByContentCode
(
ContractStatusEnum
.
CANCEL
.
getValue
(),
contract
.
getContractCode
());
if
(
contractChange
!=
null
){
contract
.
setEndDate
(
contractChange
.
getDs
());
}
}
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
()){
correlationContract
.
add
(
contract
);
}
}
//多个合同时,进行排序,如果第一个合同流量超出就要看第二个合同,以此往下
if
(
correlationContract
.
size
()>
1
){
//冒泡
//第一优先级:合同开始日期,第二优先级,合同编号大小
Contract
[]
contractsArray
=
new
Contract
[
correlationContract
.
size
()];
contractsArray
=
correlationContract
.
toArray
(
contractsArray
);
contractsArray
=
orderByContract
(
contractsArray
);
for
(
int
i
=
0
;
i
<
contractsArray
.
length
;
i
++)
{
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contractsArray
[
i
]);
if
(
tkioFlow
!=
null
&&
i
<
contractsArray
.
length
-
1
&&
tkioFlow
.
getCostFlow
()>
0L
){
//处理成本流量,如果超出了,依次算在下一个合同上
clickNum
=
BigInteger
.
valueOf
(
tkioFlow
.
getCostFlow
());
tkioFlow
.
setCostFlow
(
null
);
tkioFlowList
.
add
(
tkioFlow
);
}
else
{
if
(
tkioFlow
!=
null
){
tkioFlowList
.
add
(
tkioFlow
);
}
break
;
}
}
}
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
){
int
j
=
0
;
if
(
i
!=
0
){
j
=
i
-
1
;
}
if
(
i
==
contractsArray
.
length
-
1
){
j
=
i
;
}
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contractsArray
[
j
]);
if
(
tkioFlow
!=
null
){
tkioFlowList
.
add
(
tkioFlow
);
}
break
;
}
}
}
else
{
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
correlationContract
.
get
(
0
));
if
(
tkioFlow
!=
null
){
tkioFlowList
.
add
(
tkioFlow
);
}
}
}
}
}
}
if
(
tkioFlowList
.
size
()>
0
){
tkioFlowRepository
.
save
(
tkioFlowList
);
}
calculationFlow
.
setStatus
(
2
);
calculationFlowRepository
.
save
(
calculationFlow
);
}
}
public
void
task
(){
List
<
String
>
emails
=
contractRepository
.
findDistinctEmailByPlatform
(
"tkio"
);
List
<
TkioFlow
>
tkioFlowList
=
new
ArrayList
<>();
for
(
String
email
:
emails
)
{
//查询用户下所有appkey
Account
account
=
accountRepository
.
findByEmail
(
email
);
List
<
Account
>
accountList
=
accountRepository
.
findByRootParent
(
account
.
getRootParent
());
List
<
Long
>
idList
=
new
ArrayList
<>();
for
(
Account
ac
:
accountList
)
{
idList
.
add
(
ac
.
getId
());
}
List
<
String
>
appkeys
=
appRepository
.
findAppkeysNotDebug
(
idList
);
String
appkeyStr
=
String
.
join
(
"','"
,
appkeys
);
appkeyStr
=
"'"
+
appkeyStr
+
"'"
;
String
yesterday
=
DateUtil
.
getBeforeDays
(
1
);
//昨日
BigInteger
clickNum
=
accountFlowRestrictService
.
getTotalNum
(
yesterday
,
yesterday
,
appkeyStr
,
"account_track_flow_restrict"
,
"click_sum"
);
if
(
clickNum
!=
null
&&
clickNum
.
longValue
()>
0
){
List
<
Contract
>
contracts
=
contractRepository
.
findByPlatformAndEmail
(
"tkio"
,
email
);
if
(
contracts
.
size
()==
1
){
//只有一个合同
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contracts
.
get
(
0
));
if
(
tkioFlow
!=
null
){
tkioFlowList
.
add
(
tkioFlow
);
}
}
else
{
//多个合同
//看昨日被哪几个合同包含了
List
<
Contract
>
correlationContract
=
new
ArrayList
<>();
for
(
Contract
contract
:
contracts
)
{
if
(
ContractStatusEnum
.
CANCEL
.
getKey
().
equals
(
contract
.
getStatus
())
||
ContractStatusEnum
.
SUSPEND
.
getKey
().
equals
(
contract
.
getStatus
()))
{
//中止或作废合同处理结束时间,以方便昨日流量的归属计算
ContractChange
contractChange
=
contractChangeRepository
.
findByContentCode
(
ContractStatusEnum
.
CANCEL
.
getValue
(),
contract
.
getContractCode
());
if
(
contractChange
!=
null
){
contract
.
setEndDate
(
contractChange
.
getDs
());
}
}
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
()){
correlationContract
.
add
(
contract
);
}
}
//多个合同时,进行排序,如果第一个合同流量超出就要看第二个合同,以此往下
if
(
correlationContract
.
size
()>
1
){
//冒泡
//第一优先级:合同开始日期,第二优先级,合同编号大小
Contract
[]
contractsArray
=
new
Contract
[
correlationContract
.
size
()];
contractsArray
=
correlationContract
.
toArray
(
contractsArray
);
contractsArray
=
orderByContract
(
contractsArray
);
for
(
int
i
=
0
;
i
<
contractsArray
.
length
;
i
++)
{
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contractsArray
[
i
]);
if
(
tkioFlow
!=
null
&&
i
<
contractsArray
.
length
-
1
&&
tkioFlow
.
getCostFlow
()>
0L
){
//处理成本流量,如果超出了,依次算在下一个合同上
clickNum
=
BigInteger
.
valueOf
(
tkioFlow
.
getCostFlow
());
tkioFlow
.
setCostFlow
(
null
);
tkioFlowList
.
add
(
tkioFlow
);
}
else
{
if
(
tkioFlow
!=
null
){
tkioFlowList
.
add
(
tkioFlow
);
}
break
;
}
}
}
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
){
int
j
=
0
;
if
(
i
!=
0
){
j
=
i
-
1
;
}
if
(
i
==
contractsArray
.
length
-
1
){
j
=
i
;
}
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
contractsArray
[
j
]);
if
(
tkioFlow
!=
null
){
tkioFlowList
.
add
(
tkioFlow
);
}
break
;
}
}
}
else
{
TkioFlow
tkioFlow
=
getTkioFlow
(
clickNum
,
yesterday
,
correlationContract
.
get
(
0
));
if
(
tkioFlow
!=
null
){
tkioFlowList
.
add
(
tkioFlow
);
}
}
}
}
}
}
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
++)
{
if
(
DateUtil
.
getDate
(
contractsArray
[
j
].
getStartDate
()).
getTime
()
>
DateUtil
.
getDate
(
contractsArray
[
j
+
1
].
getStartDate
()).
getTime
()){
Contract
temp
=
contractsArray
[
j
];
contractsArray
[
j
]
=
contractsArray
[
j
+
1
];
contractsArray
[
j
+
1
]
=
temp
;
}
else
if
(
DateUtil
.
getDate
(
contractsArray
[
j
].
getStartDate
()).
getTime
()
==
DateUtil
.
getDate
(
contractsArray
[
j
+
1
].
getStartDate
()).
getTime
()){
String
contractCode
=
contractsArray
[
j
].
getContractCode
().
replaceAll
(
"BJ-TKIO-"
,
""
).
replaceAll
(
"-"
,
""
);
String
contractCodeMin
=
contractsArray
[
j
+
1
].
getContractCode
().
replaceAll
(
"BJ-TKIO-"
,
""
).
replaceAll
(
"-"
,
""
);
if
(
Long
.
valueOf
(
contractCode
)>
Long
.
valueOf
(
contractCodeMin
)){
Contract
temp
=
contractsArray
[
j
];
contractsArray
[
j
]
=
contractsArray
[
j
+
1
];
contractsArray
[
j
+
1
]
=
temp
;
}
}
}
}
return
contractsArray
;
}
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
){
//昨日日期早于合同开始日期
//设置为成本流量
tkioFlow
.
setCostFlow
(
clickNum
.
longValue
());
}
else
{
//查看历史总消耗流量是否超出
Long
totalFlow
=
tkioFlowRepository
.
sumFlowByEmailAndContractCode
(
contract
.
getEmail
(),
contract
.
getContractCode
());
if
(
totalFlow
!=
null
){
Double
contractTrackFlow
=
contract
.
getTrackFlow
()
*
4
;
if
(
contractTrackFlow
.
longValue
()-
totalFlow
-
clickNum
.
longValue
()>=
0
){
tkioFlow
.
setFlow
(
clickNum
.
longValue
());
}
else
{
tkioFlow
.
setFlow
(
contractTrackFlow
.
longValue
()
-
totalFlow
);
tkioFlow
.
setCostFlow
(
clickNum
.
longValue
()-
tkioFlow
.
getFlow
());
}
}
else
{
tkioFlow
.
setFlow
(
clickNum
.
longValue
());
}
}
return
tkioFlow
;
}
catch
(
ParseException
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
;
System
.
out
.
println
(
between
);
for
(
int
i
=
between
;
i
>
0
;
i
--)
{
System
.
out
.
println
(
DateUtil
.
getBeforeDays
(
i
));
}
}
}
src/main/resources/spring/applicationContext-schedule.xml
View file @
f106616f
...
...
@@ -63,4 +63,16 @@
<!--<task:scheduled ref="accountTaskCheck" method="task" cron="0 10 8 * * ?"/>-->
<!--</task:scheduled-tasks>-->
<bean
id=
"syncTrackingFlowTask"
class=
"track.task.TrackingFlowTask"
></bean>
<task:scheduled-tasks>
<!--定时同步昨日流量(每天10点执行一次)-->
<task:scheduled
ref=
"syncTrackingFlowTask"
method=
"task"
cron=
"* * 10 * * ?"
/>
</task:scheduled-tasks>
<bean
id=
"syncCalculationFlowTask"
class=
"track.task.TrackingFlowTask"
></bean>
<task:scheduled-tasks>
<!--定时同步流量(每7分钟执行一次)-->
<task:scheduled
ref=
"syncCalculationFlowTask"
method=
"syncFlow"
cron=
"* 0/7 * * * ? "
/>
</task:scheduled-tasks>
</beans>
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