Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张云鹏
/
moss-statistic
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
c230ae90
...
c230ae90d2218cb685ac47bc42d4fa124ffb2027
authored
2023-03-29 17:17:31 +0800
by
张云鹏
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
专题数据统计
1 parent
0fe13b58
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
109 additions
and
98 deletions
src/main/java/com/topdraw/business/module/uv/all/repository/PvUvRepository.java
src/main/java/com/topdraw/business/module/uv/all/service/PvUvService.java
src/main/java/com/topdraw/business/module/uv/all/service/impl/PvUvServiceImpl.java
src/main/java/com/topdraw/business/module/uv/day/repository/PvUvDayRepository.java
src/main/java/com/topdraw/business/module/uv/day/service/impl/PvUvDayServiceImpl.java
src/main/java/com/topdraw/business/module/uv/hour/repository/PvUvHourRepository.java
src/main/java/com/topdraw/business/module/uv/hour/service/impl/PvUvHourServiceImpl.java
src/main/java/com/topdraw/business/process/calculate/task/ActivityBtnClickPvUcCalculateTask.java
src/main/java/com/topdraw/business/process/calculate/task/PvUvCalculateTask.java
src/main/java/com/topdraw/redis/config/MyJedisConfig.java
src/main/java/com/topdraw/business/module/uv/all/repository/PvUvRepository.java
View file @
c230ae9
...
...
@@ -16,13 +16,5 @@ import java.util.Optional;
*/
public
interface
PvUvRepository
extends
JpaRepository
<
PvUv
,
Long
>,
JpaSpecificationExecutor
<
PvUv
>
{
@Modifying
@Transactional
@Query
(
value
=
"update act_pv_uv set pv = :#{#resources.pv} , uv = :#{#resources.uv} , "
+
"update_time = :#{#resources.updateTime} where marketing_activity_code = :#{#resources.marketingActivityCode} "
,
nativeQuery
=
true
)
void
updateByMarketingActivityId
(
@Param
(
"resources"
)
PvUv
resources
);
Optional
<
PvUv
>
findByMarketingActivityCode
(
String
marketingActivityCode
);
Optional
<
PvUv
>
findByMarketingActivityId
(
Long
mActivityId
);
Optional
<
PvUv
>
findBySubjectId
(
Long
mActivityId
);
}
...
...
src/main/java/com/topdraw/business/module/uv/all/service/PvUvService.java
View file @
c230ae9
...
...
@@ -41,14 +41,11 @@ public interface PvUvService {
void
create
(
PvUv
resources
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
void
updateByMarketingActivityId
(
PvUv
resources
);
void
update
(
PvUv
resources
);
void
delete
(
Long
id
);
PvUv
findByMarketingActivityCode
(
String
code
);
//
PvUv findByMarketingActivityCode(String code);
PvUv
findByMarketingActivityId
(
Long
parseLong
);
}
...
...
src/main/java/com/topdraw/business/module/uv/all/service/impl/PvUvServiceImpl.java
View file @
c230ae9
...
...
@@ -65,11 +65,11 @@ public class PvUvServiceImpl implements PvUvService {
PvUvRepository
.
save
(
resources
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateByMarketingActivityId
(
PvUv
resources
)
{
PvUvRepository
.
updateByMarketingActivityId
(
resources
);
}
//
@Override
//
@Transactional(rollbackFor = Exception.class)
//
public void updateByMarketingActivityId(PvUv resources) {
//
PvUvRepository.updateByMarketingActivityId(resources);
//
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
...
...
@@ -89,15 +89,15 @@ public class PvUvServiceImpl implements PvUvService {
PvUvRepository
.
delete
(
PvUv
);
}
@Override
public
PvUv
findByMarketingActivityCode
(
String
code
)
{
PvUv
PvUv
=
PvUvRepository
.
findByMarketingActivityCode
(
code
).
orElseGet
(
PvUv:
:
new
);
return
PvUv
;
}
//
@Override
//
public PvUv findByMarketingActivityCode(String code) {
//
PvUv PvUv = PvUvRepository.findByMarketingActivityCode(code).orElseGet(PvUv::new);
//
return PvUv;
//
}
@Override
public
PvUv
findByMarketingActivityId
(
Long
mActivityId
)
{
return
PvUvRepository
.
findBy
MarketingActivity
Id
(
mActivityId
).
orElseGet
(
PvUv:
:
new
);
return
PvUvRepository
.
findBy
Subject
Id
(
mActivityId
).
orElseGet
(
PvUv:
:
new
);
}
...
...
src/main/java/com/topdraw/business/module/uv/day/repository/PvUvDayRepository.java
View file @
c230ae9
...
...
@@ -16,14 +16,14 @@ import java.util.Optional;
*/
public
interface
PvUvDayRepository
extends
JpaRepository
<
PvUvDay
,
Long
>,
JpaSpecificationExecutor
<
PvUvDay
>
{
Optional
<
PvUvDay
>
findBy
MarketingActivity
CodeAndDay
(
String
marketingActivityCode
,
String
day
);
Optional
<
PvUvDay
>
findBy
Subject
CodeAndDay
(
String
marketingActivityCode
,
String
day
);
@Modifying
@Transactional
@Query
(
value
=
"update
act
_pv_uv_day set pv = :#{#resources.pv} , uv = :#{#resources.uv} , "
+
" update_time = :#{#resources.updateTime} where
marketing_activity_code = :#{#resources.marketingActivity
Code} and "
+
@Query
(
value
=
"update
sub
_pv_uv_day set pv = :#{#resources.pv} , uv = :#{#resources.uv} , "
+
" update_time = :#{#resources.updateTime} where
subject_code = :#{#resources.subject
Code} and "
+
" `day` = :#{#resources.day}"
,
nativeQuery
=
true
)
void
updateBy
MarketingActivity
CodeAndDay
(
@Param
(
"resources"
)
PvUvDay
pvUvDay
);
void
updateBy
Subject
CodeAndDay
(
@Param
(
"resources"
)
PvUvDay
pvUvDay
);
Optional
<
PvUvDay
>
findBy
MarketingActivity
IdAndDay
(
Long
mActivityId
,
String
day
);
Optional
<
PvUvDay
>
findBy
Subject
IdAndDay
(
Long
mActivityId
,
String
day
);
}
...
...
src/main/java/com/topdraw/business/module/uv/day/service/impl/PvUvDayServiceImpl.java
View file @
c230ae9
...
...
@@ -85,18 +85,18 @@ public class PvUvDayServiceImpl implements PvUvDayService {
@Override
public
PvUvDay
findByMarketingActivityCodeAndDay
(
String
code
,
String
day
)
{
PvUvDay
PvUvDay
=
PvUvDayRepository
.
findBy
MarketingActivity
CodeAndDay
(
code
,
day
).
orElseGet
(
PvUvDay:
:
new
);
PvUvDay
PvUvDay
=
PvUvDayRepository
.
findBy
Subject
CodeAndDay
(
code
,
day
).
orElseGet
(
PvUvDay:
:
new
);
return
PvUvDay
;
}
@Override
public
void
updateByMarketingActivityCodeAndDay
(
PvUvDay
pvUvDay
)
{
PvUvDayRepository
.
updateBy
MarketingActivity
CodeAndDay
(
pvUvDay
);
PvUvDayRepository
.
updateBy
Subject
CodeAndDay
(
pvUvDay
);
}
@Override
public
PvUvDay
findByMarketingActivityIdAndDay
(
Long
mActivityId
,
String
day
)
{
return
PvUvDayRepository
.
findBy
MarketingActivity
IdAndDay
(
mActivityId
,
day
).
orElseGet
(
PvUvDay:
:
new
);
return
PvUvDayRepository
.
findBy
Subject
IdAndDay
(
mActivityId
,
day
).
orElseGet
(
PvUvDay:
:
new
);
}
...
...
src/main/java/com/topdraw/business/module/uv/hour/repository/PvUvHourRepository.java
View file @
c230ae9
...
...
@@ -16,18 +16,18 @@ import java.util.Optional;
*/
public
interface
PvUvHourRepository
extends
JpaRepository
<
PvUvHour
,
Long
>,
JpaSpecificationExecutor
<
PvUvHour
>
{
Optional
<
PvUvHour
>
findBy
MarketingActivity
CodeAndDayAndHour
(
String
code
,
String
day
,
int
hour
);
Optional
<
PvUvHour
>
findBy
Subject
CodeAndDayAndHour
(
String
code
,
String
day
,
int
hour
);
Optional
<
PvUvHour
>
findBy
MarketingActivity
IdAndDayAndHour
(
Long
id
,
String
day
,
int
hour
);
Optional
<
PvUvHour
>
findBy
Subject
IdAndDayAndHour
(
Long
id
,
String
day
,
int
hour
);
@Modifying
@Transactional
@Query
(
value
=
"update
act
_pv_uv_hour set pv = :#{#resources.pv} , uv = :#{#resources.uv} , "
+
"update_time = :#{#resources.updateTime} where
marketing_activity_code = :#{#resources.marketingActivity
Code} and "
+
@Query
(
value
=
"update
sub
_pv_uv_hour set pv = :#{#resources.pv} , uv = :#{#resources.uv} , "
+
"update_time = :#{#resources.updateTime} where
subject_code = :#{#resources.subject
Code} and "
+
" `day` = :#{#resources.day} and `hour` = :#{#resources.hour}"
,
nativeQuery
=
true
)
void
updateBy
MarketingActivity
CodeAndDayAndHour
(
@Param
(
"resources"
)
PvUvHour
pvUvHour
);
void
updateBy
Subject
CodeAndDayAndHour
(
@Param
(
"resources"
)
PvUvHour
pvUvHour
);
@Query
(
value
=
"select SUM(pv) pv ,SUM(uv) pv from (\n"
+
"select pv,uv from
act_pv_uv_hour where `marketing_activity
_code` = ?1 and `day` = ?2 and `hour` = ?3) t "
,
nativeQuery
=
true
)
"select pv,uv from
sub_pv_uv_hour where `subject
_code` = ?1 and `day` = ?2 and `hour` = ?3) t "
,
nativeQuery
=
true
)
Integer
calculatePvDay
(
@Param
(
"code"
)
String
code
,
@Param
(
"day"
)
String
day
,
@Param
(
"hour"
)
int
hour
);
}
...
...
src/main/java/com/topdraw/business/module/uv/hour/service/impl/PvUvHourServiceImpl.java
View file @
c230ae9
...
...
@@ -74,13 +74,13 @@ public class PvUvHourServiceImpl implements PvUvHourService {
@Override
public
PvUvHour
findByMarketingActivityCodeAndDayAndHour
(
String
code
,
String
day
,
int
hour
)
{
PvUvHour
PvUvHour
=
PvUvHourRepository
.
findBy
MarketingActivity
CodeAndDayAndHour
(
code
,
day
,
hour
).
orElseGet
(
PvUvHour:
:
new
);
PvUvHour
PvUvHour
=
PvUvHourRepository
.
findBy
Subject
CodeAndDayAndHour
(
code
,
day
,
hour
).
orElseGet
(
PvUvHour:
:
new
);
return
PvUvHour
;
}
@Override
public
void
updateByMarketingActivityCodeAndDayAndHour
(
PvUvHour
pvUvHour
)
{
PvUvHourRepository
.
updateBy
MarketingActivity
CodeAndDayAndHour
(
pvUvHour
);
PvUvHourRepository
.
updateBy
Subject
CodeAndDayAndHour
(
pvUvHour
);
}
@Override
...
...
@@ -91,7 +91,7 @@ public class PvUvHourServiceImpl implements PvUvHourService {
@Override
public
PvUvHour
findByMarketingActivityIdAndDayAndHour
(
Long
mActivityId
,
String
day
,
int
hour
)
{
return
PvUvHourRepository
.
findBy
MarketingActivity
IdAndDayAndHour
(
mActivityId
,
day
,
hour
).
orElseGet
(
PvUvHour:
:
new
);
return
PvUvHourRepository
.
findBy
Subject
IdAndDayAndHour
(
mActivityId
,
day
,
hour
).
orElseGet
(
PvUvHour:
:
new
);
}
...
...
src/main/java/com/topdraw/business/process/calculate/task/ActivityBtnClickPvUcCalculateTask.java
View file @
c230ae9
...
...
@@ -52,7 +52,7 @@ public class ActivityBtnClickPvUcCalculateTask {
private
List
<
Map
<
String
,
Object
>>
getAllSubjectCode
(){
String
sql
=
"SELECT tadr.`id` AS `id`,tadr.`code` AS `code` FROM `
x
_subject` tadr "
+
String
sql
=
"SELECT tadr.`id` AS `id`,tadr.`code` AS `code` FROM `
cms
_subject` tadr "
+
" GROUP BY `code`"
;
return
this
.
jdbcTemplate
.
queryForList
(
sql
);
}
...
...
@@ -84,25 +84,28 @@ public class ActivityBtnClickPvUcCalculateTask {
if
(
Objects
.
nonNull
(
codeAndBtnIds
)
&&
CollectionUtils
.
isNotEmpty
(
codeAndBtnIds
)){
for
(
String
s1
:
codeAndBtnIds
)
{
log
.
info
(
"codeAndBtnId ==>> {}"
,
s1
);
String
[]
split
=
s1
.
split
(
"#"
);
if
(
split
.
length
==
0
)
{
split
=
s1
.
split
(
"-"
);
}
if
(
split
.
length
==
0
)
{
continue
;
}
log
.
info
(
"分割后的结果 ==>> {}"
,
split
);
//
String[] split = s1.split("#");
//
//
if (split.length == 0) {
//
split = s1.split("-");
//
}
//
//
if (split.length == 0) {
//
continue;
//
}
//
log.info("分割后的结果 ==>> {}", split);
try
{
subjectCode
=
code
;
log
.
info
(
"专题code ==>> {}"
,
subjectCode
);
subjectId
=
this
.
findSubjectByCode
(
subjectCode
);
if
(
Objects
.
isNull
(
subjectId
))
{
log
.
info
(
"专题subjectId ==>> {}"
,
subjectId
);
if
(
subjectId
==
null
)
{
log
.
info
(
"subjectId is null"
);
log
.
error
(
"模板按钮点击次数统计异常,通过活动code无法获取专题, subjectCode ==>> {}"
,
subjectCode
);
continue
;
}
paramValueId
=
Long
.
valueOf
(
split
[
1
]);
log
.
info
(
"subjectId is not null"
);
paramValueId
=
Long
.
valueOf
(
s1
);
log
.
info
(
"模板属性id ==>> {}"
,
paramValueId
);
name
=
this
.
findParamValueByValueId
(
paramValueId
);
log
.
info
(
"模板属性名称 ==>> {}"
,
name
);
...
...
@@ -111,7 +114,8 @@ public class ActivityBtnClickPvUcCalculateTask {
name
=
"#"
;
// continue;
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
continue
;
}
...
...
@@ -138,7 +142,8 @@ public class ActivityBtnClickPvUcCalculateTask {
activityBtnPvUvHour
.
setUv
(
hourUv
);
this
.
activityBtnPvUvHourService
.
create
(
activityBtnPvUvHour
);
}
else
{
}
else
{
// 修改
Integer
hourPv
=
this
.
getHourPV
(
subjectCode
,
paramValueId
);
...
...
@@ -181,7 +186,8 @@ public class ActivityBtnClickPvUcCalculateTask {
activityBtnPvUvDay
.
setUv
(
dayUv
);
this
.
activityBtnPvUvDayService
.
create
(
activityBtnPvUvDay
);
}
else
{
}
else
{
Integer
dayPv
=
this
.
getDayPV
(
subjectCode
,
paramValueId
);
Integer
dayUv
=
this
.
getDayUV
(
subjectCode
,
paramValueId
);
...
...
@@ -222,7 +228,8 @@ public class ActivityBtnClickPvUcCalculateTask {
this
.
activityBtnPvUvService
.
create
(
activityBtnPvUv
);
}
else
{
}
else
{
Integer
allPV
=
this
.
getAllPV
(
subjectCode
,
paramValueId
);
Integer
allUv
=
this
.
getAllUV
(
subjectCode
,
paramValueId
);
...
...
@@ -256,8 +263,8 @@ public class ActivityBtnClickPvUcCalculateTask {
private
Integer
getAllUV
(
String
code
,
Long
btnId
)
{
String
key
=
"SUBJECT_BTN_UV|"
+
code
+
"#"
+
btnId
;
log
.
info
(
"getAllUV ==>> key ==>> {}"
,
key
);
String
key
=
"SUBJECT_BTN_
CLICK_
UV|"
+
code
+
"#"
+
btnId
;
log
.
info
(
"get
BtnClick
AllUV ==>> key ==>> {}"
,
key
);
Object
hourBtnClickUV
=
this
.
redisUtils
.
hget
(
key
,
"ALL"
);
if
(
Objects
.
nonNull
(
hourBtnClickUV
))
{
return
Integer
.
valueOf
(
hourBtnClickUV
.
toString
());
...
...
@@ -272,8 +279,8 @@ public class ActivityBtnClickPvUcCalculateTask {
}
private
Integer
getAllPV
(
String
code
,
Long
btnId
)
{
String
key
=
"SUBJECT_BTN_PV|"
+
code
+
"#"
+
btnId
;
log
.
info
(
"getAllPV ==>> key ==>> {}"
,
key
);
String
key
=
"SUBJECT_BTN_
CLICK_
PV|"
+
code
+
"#"
+
btnId
;
log
.
info
(
"get
BtnClick
AllPV ==>> key ==>> {}"
,
key
);
Object
hourBtnClickPV
=
this
.
redisUtils
.
hget
(
key
,
"ALL"
);
if
(
Objects
.
nonNull
(
hourBtnClickPV
))
{
return
Integer
.
valueOf
(
hourBtnClickPV
.
toString
());
...
...
@@ -288,8 +295,8 @@ public class ActivityBtnClickPvUcCalculateTask {
}
private
Integer
getDayUV
(
String
code
,
Long
btnId
)
{
String
key
=
"SUBJECT_BTN_UV|"
+
code
+
"#"
+
btnId
+
"|"
+
LocalDate
.
now
();
log
.
info
(
"getDayUV ==>> key ==>> {}"
,
key
);
String
key
=
"SUBJECT_BTN_
CLICK_
UV|"
+
code
+
"#"
+
btnId
+
"|"
+
LocalDate
.
now
();
log
.
info
(
"get
BtnClick
DayUV ==>> key ==>> {}"
,
key
);
Object
hourBtnClickUV
=
this
.
redisUtils
.
hget
(
key
,
"ALL"
);
if
(
Objects
.
nonNull
(
hourBtnClickUV
))
{
return
Integer
.
valueOf
(
hourBtnClickUV
.
toString
());
...
...
@@ -304,8 +311,8 @@ public class ActivityBtnClickPvUcCalculateTask {
}
private
Integer
getDayPV
(
String
code
,
Long
btnId
)
{
String
key
=
"SUBJECT_BTN_PV|"
+
code
+
"#"
+
btnId
+
"|"
+
LocalDate
.
now
();
log
.
info
(
"getDayUV ==>> key ==>> {}"
,
key
);
String
key
=
"SUBJECT_BTN_
CLICK_
PV|"
+
code
+
"#"
+
btnId
+
"|"
+
LocalDate
.
now
();
log
.
info
(
"get
BtnClick
DayUV ==>> key ==>> {}"
,
key
);
Object
hourBtnClickPV
=
this
.
redisUtils
.
hget
(
key
,
"ALL"
);
if
(
Objects
.
nonNull
(
hourBtnClickPV
))
{
return
Integer
.
valueOf
(
hourBtnClickPV
.
toString
());
...
...
@@ -328,8 +335,8 @@ public class ActivityBtnClickPvUcCalculateTask {
hourStr
=
String
.
valueOf
(
hour
);
}
String
key
=
"SUBJECT_BTN_UV|"
+
code
+
"#"
+
btnId
+
"|"
+
LocalDate
.
now
()+
"|"
+
hourStr
;
log
.
info
(
"getHourUV ==>> key ==>> {}"
,
key
);
String
key
=
"SUBJECT_BTN_
CLICK_
UV|"
+
code
+
"#"
+
btnId
+
"|"
+
LocalDate
.
now
()+
"|"
+
hourStr
;
log
.
info
(
"get
BtnClick
HourUV ==>> key ==>> {}"
,
key
);
Object
hourBtnClickUV
=
this
.
redisUtils
.
hget
(
key
,
"ALL"
);
if
(
Objects
.
nonNull
(
hourBtnClickUV
))
{
return
Integer
.
valueOf
(
hourBtnClickUV
.
toString
());
...
...
@@ -351,8 +358,8 @@ public class ActivityBtnClickPvUcCalculateTask {
}
else
{
hourStr
=
String
.
valueOf
(
hour
);
}
String
key
=
"SUBJECT_BTN_PV|"
+
code
+
"#"
+
btnId
+
"|"
+
LocalDate
.
now
()+
"|"
+
hourStr
;
log
.
info
(
"getHourPV ==>> key ==>> {}"
,
key
);
String
key
=
"SUBJECT_BTN_
CLICK_
PV|"
+
code
+
"#"
+
btnId
+
"|"
+
LocalDate
.
now
()+
"|"
+
hourStr
;
log
.
info
(
"get
BtnClick
HourPV ==>> key ==>> {}"
,
key
);
Object
hourBtnClickPV
=
this
.
redisUtils
.
hget
(
key
,
"ALL"
);
if
(
Objects
.
nonNull
(
hourBtnClickPV
))
{
return
Integer
.
valueOf
(
hourBtnClickPV
.
toString
());
...
...
@@ -377,8 +384,9 @@ public class ActivityBtnClickPvUcCalculateTask {
}
private
Long
findSubjectByCode
(
String
subjectCode
)
{
String
sql
=
"SELECT am.`id` FROM `
x
_subject` AS am WHERE `code` = '"
+
subjectCode
+
"'"
;
String
sql
=
"SELECT am.`id` FROM `
cms
_subject` AS am WHERE `code` = '"
+
subjectCode
+
"'"
;
List
<
Map
<
String
,
Object
>>
objectMap
=
this
.
jdbcTemplate
.
queryForList
(
sql
);
log
.
info
(
"findSubjectByCode result: {}"
,
objectMap
);
if
(
CollectionUtils
.
isNotEmpty
(
objectMap
))
{
Map
<
String
,
Object
>
map
=
objectMap
.
get
(
0
);
return
Long
.
valueOf
(
map
.
get
(
"id"
).
toString
());
...
...
src/main/java/com/topdraw/business/process/calculate/task/PvUvCalculateTask.java
View file @
c230ae9
...
...
@@ -249,7 +249,7 @@ public class PvUvCalculateTask {
private
Integer
getDayUV
(
String
code
){
log
.
info
(
"getDay
BtnClick
UV ==>> key ==>> {}"
,
"SUBJECT_UV"
+
"|"
+
code
+
"|"
+
LocalDate
.
now
());
log
.
info
(
"getDayUV ==>> key ==>> {}"
,
"SUBJECT_UV"
+
"|"
+
code
+
"|"
+
LocalDate
.
now
());
Object
hourBtnClickUV
=
this
.
redisUtils
.
hget
(
"SUBJECT_UV"
+
"|"
+
code
+
"|"
+
LocalDate
.
now
(),
"ALL"
);
if
(
Objects
.
nonNull
(
hourBtnClickUV
))
{
return
Integer
.
valueOf
(
hourBtnClickUV
.
toString
());
...
...
@@ -272,7 +272,7 @@ public class PvUvCalculateTask {
private
List
<
Map
<
String
,
Object
>>
getAllSubjectCode
(){
String
sql
=
"SELECT adr.`id` AS `id`, adr.`code` AS `code` FROM "
+
" `
x
_subject` adr "
+
" `
cms
_subject` adr "
+
" GROUP BY `code`"
;
return
this
.
jdbcTemplate
.
queryForList
(
sql
);
...
...
src/main/java/com/topdraw/redis/config/MyJedisConfig.java
View file @
c230ae9
package
com
.
topdraw
.
redis
.
config
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.pool2.impl.GenericObjectPoolConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
...
@@ -13,7 +14,6 @@ import org.springframework.data.redis.connection.*;
import
org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.util.StringUtils
;
import
redis.clients.jedis.Jedis
;
import
redis.clients.jedis.JedisPool
;
import
redis.clients.jedis.JedisPoolConfig
;
...
...
@@ -37,14 +37,33 @@ import java.util.Set;
public
class
MyJedisConfig
{
/***生产环境要打开此配置*/
@Value
(
"${spring.redis.sentinel.master}"
)
@Value
(
"${spring.redis.sentinel.master
:''
}"
)
private
String
master
;
@Value
(
"${spring.redis.sentinel.nodes}"
)
@Value
(
"${spring.redis.sentinel.nodes:''}"
)
private
String
sentinelHost
;
@Value
((
"${spring.redis.host:''}"
))
private
String
host
;
@Value
((
"${spring.redis.port:''}"
))
private
String
port
;
@Value
((
"${spring.redis.timeout:''}"
))
private
String
timeout
;
@Bean
public
JedisPoolConfig
jedisPoolConfig
()
{
JedisPoolConfig
jedisPoolConfig
=
new
JedisPoolConfig
();
jedisPoolConfig
.
setMaxTotal
(
15
);
jedisPoolConfig
.
setMaxIdle
(
10
);
jedisPoolConfig
.
setMinIdle
(
5
);
jedisPoolConfig
.
setMaxWaitMillis
(
10000
);
jedisPoolConfig
.
setTestOnBorrow
(
true
);
return
jedisPoolConfig
;
}
@Bean
public
Jedis
jedisPool
(
JedisPoolConfig
jedisPoolConfig
)
{
log
.
info
(
"spring.redis.sentinel.nodes: {}"
,
sentinelHost
);
if
(
StringUtils
.
isNotEmpty
(
sentinelHost
)
&&
!
"''"
.
equals
(
sentinelHost
))
{
log
.
info
(
"哨兵模式"
);
String
[]
split
=
sentinelHost
.
split
(
","
);
Set
<
String
>
sentinels
=
new
HashSet
<>();
for
(
int
i
=
0
;
i
<
split
.
length
;
i
++)
{
...
...
@@ -55,30 +74,25 @@ public class MyJedisConfig {
JedisSentinelPool
jedisPool
=
new
JedisSentinelPool
(
master
,
sentinels
,
jedisPoolConfig
);
Jedis
jedis
=
jedisPool
.
getResource
();
return
jedis
;
}
else
{
log
.
info
(
"单台Redis, host: {}, port: {}, timeout: {}"
,
host
,
port
,
timeout
);
JedisPool
jedisPool
=
new
JedisPool
(
jedisPoolConfig
,
host
,
Integer
.
parseInt
(
port
),
Integer
.
parseInt
(
timeout
));
return
jedisPool
.
getResource
();
}
@Bean
public
JedisPoolConfig
jedisPoolConfig
()
{
JedisPoolConfig
jedisPoolConfig
=
new
JedisPoolConfig
();
jedisPoolConfig
.
setMaxTotal
(
15
);
jedisPoolConfig
.
setMaxIdle
(
10
);
jedisPoolConfig
.
setMinIdle
(
5
);
jedisPoolConfig
.
setMaxWaitMillis
(
10000
);
jedisPoolConfig
.
setTestOnBorrow
(
true
);
return
jedisPoolConfig
;
}
/*@Bean
public Jedis jedisPool(@Value("${spring.redis.host}") String host,
@Value("${spring.redis.port}") int port,
@Value("${spring.redis.timeout}") int timeout,
// @Value("${spring.redis.password}") String password,
JedisPoolConfig jedisPoolConfig) {
// JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout,"redis123");
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout);
// @Bean
// public Jedis jedisPool(@Value("${spring.redis.host}") String host,
// @Value("${spring.redis.port}") int port,
// @Value("${spring.redis.timeout}") int timeout,
//// @Value("${spring.redis.password}") String password,
// JedisPoolConfig jedisPoolConfig) {
//
//// JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout,"redis123");
// JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout);
//
// return jedisPool.getResource();
// }
return jedisPool.getResource();
}*/
}
...
...
Please
register
or
sign in
to post a comment