专题数据统计
Showing
10 changed files
with
113 additions
and
102 deletions
... | @@ -16,13 +16,5 @@ import java.util.Optional; | ... | @@ -16,13 +16,5 @@ import java.util.Optional; |
16 | */ | 16 | */ |
17 | public interface PvUvRepository extends JpaRepository<PvUv, Long>, JpaSpecificationExecutor<PvUv> { | 17 | public interface PvUvRepository extends JpaRepository<PvUv, Long>, JpaSpecificationExecutor<PvUv> { |
18 | 18 | ||
19 | @Modifying | 19 | Optional<PvUv> findBySubjectId(Long mActivityId); |
20 | @Transactional | ||
21 | @Query(value = "update act_pv_uv set pv = :#{#resources.pv} , uv = :#{#resources.uv} , " + | ||
22 | "update_time = :#{#resources.updateTime} where marketing_activity_code = :#{#resources.marketingActivityCode} " , nativeQuery = true) | ||
23 | void updateByMarketingActivityId(@Param("resources") PvUv resources); | ||
24 | |||
25 | Optional<PvUv> findByMarketingActivityCode(String marketingActivityCode); | ||
26 | |||
27 | Optional<PvUv> findByMarketingActivityId(Long mActivityId); | ||
28 | } | 20 | } | ... | ... |
... | @@ -41,14 +41,11 @@ public interface PvUvService { | ... | @@ -41,14 +41,11 @@ public interface PvUvService { |
41 | 41 | ||
42 | void create(PvUv resources); | 42 | void create(PvUv resources); |
43 | 43 | ||
44 | @Transactional(rollbackFor = Exception.class) | ||
45 | void updateByMarketingActivityId(PvUv resources); | ||
46 | |||
47 | void update(PvUv resources); | 44 | void update(PvUv resources); |
48 | 45 | ||
49 | void delete(Long id); | 46 | void delete(Long id); |
50 | 47 | ||
51 | PvUv findByMarketingActivityCode(String code); | 48 | // PvUv findByMarketingActivityCode(String code); |
52 | 49 | ||
53 | PvUv findByMarketingActivityId(Long parseLong); | 50 | PvUv findByMarketingActivityId(Long parseLong); |
54 | } | 51 | } | ... | ... |
... | @@ -65,11 +65,11 @@ public class PvUvServiceImpl implements PvUvService { | ... | @@ -65,11 +65,11 @@ public class PvUvServiceImpl implements PvUvService { |
65 | PvUvRepository.save(resources); | 65 | PvUvRepository.save(resources); |
66 | } | 66 | } |
67 | 67 | ||
68 | @Override | 68 | // @Override |
69 | @Transactional(rollbackFor = Exception.class) | 69 | // @Transactional(rollbackFor = Exception.class) |
70 | public void updateByMarketingActivityId(PvUv resources) { | 70 | // public void updateByMarketingActivityId(PvUv resources) { |
71 | PvUvRepository.updateByMarketingActivityId(resources); | 71 | // PvUvRepository.updateByMarketingActivityId(resources); |
72 | } | 72 | // } |
73 | 73 | ||
74 | @Override | 74 | @Override |
75 | @Transactional(rollbackFor = Exception.class) | 75 | @Transactional(rollbackFor = Exception.class) |
... | @@ -89,15 +89,15 @@ public class PvUvServiceImpl implements PvUvService { | ... | @@ -89,15 +89,15 @@ public class PvUvServiceImpl implements PvUvService { |
89 | PvUvRepository.delete(PvUv); | 89 | PvUvRepository.delete(PvUv); |
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | // @Override |
93 | public PvUv findByMarketingActivityCode(String code) { | 93 | // public PvUv findByMarketingActivityCode(String code) { |
94 | PvUv PvUv = PvUvRepository.findByMarketingActivityCode(code).orElseGet(PvUv::new); | 94 | // PvUv PvUv = PvUvRepository.findByMarketingActivityCode(code).orElseGet(PvUv::new); |
95 | return PvUv; | 95 | // return PvUv; |
96 | } | 96 | // } |
97 | 97 | ||
98 | @Override | 98 | @Override |
99 | public PvUv findByMarketingActivityId(Long mActivityId) { | 99 | public PvUv findByMarketingActivityId(Long mActivityId) { |
100 | return PvUvRepository.findByMarketingActivityId(mActivityId).orElseGet(PvUv::new); | 100 | return PvUvRepository.findBySubjectId(mActivityId).orElseGet(PvUv::new); |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ... | ... |
... | @@ -16,14 +16,14 @@ import java.util.Optional; | ... | @@ -16,14 +16,14 @@ import java.util.Optional; |
16 | */ | 16 | */ |
17 | public interface PvUvDayRepository extends JpaRepository<PvUvDay, Long>, JpaSpecificationExecutor<PvUvDay> { | 17 | public interface PvUvDayRepository extends JpaRepository<PvUvDay, Long>, JpaSpecificationExecutor<PvUvDay> { |
18 | 18 | ||
19 | Optional<PvUvDay> findByMarketingActivityCodeAndDay(String marketingActivityCode, String day); | 19 | Optional<PvUvDay> findBySubjectCodeAndDay(String marketingActivityCode, String day); |
20 | 20 | ||
21 | @Modifying | 21 | @Modifying |
22 | @Transactional | 22 | @Transactional |
23 | @Query(value = "update act_pv_uv_day set pv = :#{#resources.pv} , uv = :#{#resources.uv} , " + | 23 | @Query(value = "update sub_pv_uv_day set pv = :#{#resources.pv} , uv = :#{#resources.uv} , " + |
24 | " update_time = :#{#resources.updateTime} where marketing_activity_code = :#{#resources.marketingActivityCode} and " + | 24 | " update_time = :#{#resources.updateTime} where subject_code = :#{#resources.subjectCode} and " + |
25 | " `day` = :#{#resources.day}" , nativeQuery = true) | 25 | " `day` = :#{#resources.day}" , nativeQuery = true) |
26 | void updateByMarketingActivityCodeAndDay(@Param("resources") PvUvDay pvUvDay); | 26 | void updateBySubjectCodeAndDay(@Param("resources") PvUvDay pvUvDay); |
27 | 27 | ||
28 | Optional<PvUvDay> findByMarketingActivityIdAndDay(Long mActivityId, String day); | 28 | Optional<PvUvDay> findBySubjectIdAndDay(Long mActivityId, String day); |
29 | } | 29 | } | ... | ... |
... | @@ -85,18 +85,18 @@ public class PvUvDayServiceImpl implements PvUvDayService { | ... | @@ -85,18 +85,18 @@ public class PvUvDayServiceImpl implements PvUvDayService { |
85 | 85 | ||
86 | @Override | 86 | @Override |
87 | public PvUvDay findByMarketingActivityCodeAndDay(String code, String day) { | 87 | public PvUvDay findByMarketingActivityCodeAndDay(String code, String day) { |
88 | PvUvDay PvUvDay = PvUvDayRepository.findByMarketingActivityCodeAndDay(code,day).orElseGet(PvUvDay::new); | 88 | PvUvDay PvUvDay = PvUvDayRepository.findBySubjectCodeAndDay(code,day).orElseGet(PvUvDay::new); |
89 | return PvUvDay; | 89 | return PvUvDay; |
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | @Override |
93 | public void updateByMarketingActivityCodeAndDay(PvUvDay pvUvDay) { | 93 | public void updateByMarketingActivityCodeAndDay(PvUvDay pvUvDay) { |
94 | PvUvDayRepository.updateByMarketingActivityCodeAndDay(pvUvDay); | 94 | PvUvDayRepository.updateBySubjectCodeAndDay(pvUvDay); |
95 | } | 95 | } |
96 | 96 | ||
97 | @Override | 97 | @Override |
98 | public PvUvDay findByMarketingActivityIdAndDay(Long mActivityId, String day) { | 98 | public PvUvDay findByMarketingActivityIdAndDay(Long mActivityId, String day) { |
99 | return PvUvDayRepository.findByMarketingActivityIdAndDay(mActivityId, day).orElseGet(PvUvDay::new); | 99 | return PvUvDayRepository.findBySubjectIdAndDay(mActivityId, day).orElseGet(PvUvDay::new); |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ... | ... |
... | @@ -16,18 +16,18 @@ import java.util.Optional; | ... | @@ -16,18 +16,18 @@ import java.util.Optional; |
16 | */ | 16 | */ |
17 | public interface PvUvHourRepository extends JpaRepository<PvUvHour, Long>, JpaSpecificationExecutor<PvUvHour> { | 17 | public interface PvUvHourRepository extends JpaRepository<PvUvHour, Long>, JpaSpecificationExecutor<PvUvHour> { |
18 | 18 | ||
19 | Optional<PvUvHour> findByMarketingActivityCodeAndDayAndHour(String code, String day, int hour); | 19 | Optional<PvUvHour> findBySubjectCodeAndDayAndHour(String code, String day, int hour); |
20 | 20 | ||
21 | Optional<PvUvHour> findByMarketingActivityIdAndDayAndHour(Long id, String day, int hour); | 21 | Optional<PvUvHour> findBySubjectIdAndDayAndHour(Long id, String day, int hour); |
22 | 22 | ||
23 | @Modifying | 23 | @Modifying |
24 | @Transactional | 24 | @Transactional |
25 | @Query(value = "update act_pv_uv_hour set pv = :#{#resources.pv} , uv = :#{#resources.uv} , " + | 25 | @Query(value = "update sub_pv_uv_hour set pv = :#{#resources.pv} , uv = :#{#resources.uv} , " + |
26 | "update_time = :#{#resources.updateTime} where marketing_activity_code = :#{#resources.marketingActivityCode} and " + | 26 | "update_time = :#{#resources.updateTime} where subject_code = :#{#resources.subjectCode} and " + |
27 | " `day` = :#{#resources.day} and `hour` = :#{#resources.hour}" , nativeQuery = true) | 27 | " `day` = :#{#resources.day} and `hour` = :#{#resources.hour}" , nativeQuery = true) |
28 | void updateByMarketingActivityCodeAndDayAndHour(@Param("resources") PvUvHour pvUvHour); | 28 | void updateBySubjectCodeAndDayAndHour(@Param("resources") PvUvHour pvUvHour); |
29 | 29 | ||
30 | @Query(value = "select SUM(pv) pv ,SUM(uv) pv from (\n" + | 30 | @Query(value = "select SUM(pv) pv ,SUM(uv) pv from (\n" + |
31 | "select pv,uv from act_pv_uv_hour where `marketing_activity_code` = ?1 and `day` = ?2 and `hour` = ?3) t " , nativeQuery = true) | 31 | "select pv,uv from sub_pv_uv_hour where `subject_code` = ?1 and `day` = ?2 and `hour` = ?3) t " , nativeQuery = true) |
32 | Integer calculatePvDay(@Param("code") String code, @Param("day") String day, @Param("hour") int hour); | 32 | Integer calculatePvDay(@Param("code") String code, @Param("day") String day, @Param("hour") int hour); |
33 | } | 33 | } | ... | ... |
... | @@ -74,13 +74,13 @@ public class PvUvHourServiceImpl implements PvUvHourService { | ... | @@ -74,13 +74,13 @@ public class PvUvHourServiceImpl implements PvUvHourService { |
74 | 74 | ||
75 | @Override | 75 | @Override |
76 | public PvUvHour findByMarketingActivityCodeAndDayAndHour(String code, String day, int hour) { | 76 | public PvUvHour findByMarketingActivityCodeAndDayAndHour(String code, String day, int hour) { |
77 | PvUvHour PvUvHour = PvUvHourRepository.findByMarketingActivityCodeAndDayAndHour(code,day,hour).orElseGet(PvUvHour::new); | 77 | PvUvHour PvUvHour = PvUvHourRepository.findBySubjectCodeAndDayAndHour(code,day,hour).orElseGet(PvUvHour::new); |
78 | return PvUvHour; | 78 | return PvUvHour; |
79 | } | 79 | } |
80 | 80 | ||
81 | @Override | 81 | @Override |
82 | public void updateByMarketingActivityCodeAndDayAndHour(PvUvHour pvUvHour) { | 82 | public void updateByMarketingActivityCodeAndDayAndHour(PvUvHour pvUvHour) { |
83 | PvUvHourRepository.updateByMarketingActivityCodeAndDayAndHour(pvUvHour); | 83 | PvUvHourRepository.updateBySubjectCodeAndDayAndHour(pvUvHour); |
84 | } | 84 | } |
85 | 85 | ||
86 | @Override | 86 | @Override |
... | @@ -91,7 +91,7 @@ public class PvUvHourServiceImpl implements PvUvHourService { | ... | @@ -91,7 +91,7 @@ public class PvUvHourServiceImpl implements PvUvHourService { |
91 | 91 | ||
92 | @Override | 92 | @Override |
93 | public PvUvHour findByMarketingActivityIdAndDayAndHour(Long mActivityId, String day, int hour) { | 93 | public PvUvHour findByMarketingActivityIdAndDayAndHour(Long mActivityId, String day, int hour) { |
94 | return PvUvHourRepository.findByMarketingActivityIdAndDayAndHour(mActivityId, day, hour).orElseGet(PvUvHour::new); | 94 | return PvUvHourRepository.findBySubjectIdAndDayAndHour(mActivityId, day, hour).orElseGet(PvUvHour::new); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ... | ... |
... | @@ -52,7 +52,7 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -52,7 +52,7 @@ public class ActivityBtnClickPvUcCalculateTask { |
52 | 52 | ||
53 | 53 | ||
54 | private List<Map<String,Object>> getAllSubjectCode(){ | 54 | private List<Map<String,Object>> getAllSubjectCode(){ |
55 | String sql = "SELECT tadr.`id` AS `id`,tadr.`code` AS `code` FROM `x_subject` tadr " + | 55 | String sql = "SELECT tadr.`id` AS `id`,tadr.`code` AS `code` FROM `cms_subject` tadr " + |
56 | " GROUP BY `code`"; | 56 | " GROUP BY `code`"; |
57 | return this.jdbcTemplate.queryForList(sql); | 57 | return this.jdbcTemplate.queryForList(sql); |
58 | } | 58 | } |
... | @@ -84,25 +84,28 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -84,25 +84,28 @@ public class ActivityBtnClickPvUcCalculateTask { |
84 | if (Objects.nonNull(codeAndBtnIds) && CollectionUtils.isNotEmpty(codeAndBtnIds)){ | 84 | if (Objects.nonNull(codeAndBtnIds) && CollectionUtils.isNotEmpty(codeAndBtnIds)){ |
85 | for (String s1 : codeAndBtnIds) { | 85 | for (String s1 : codeAndBtnIds) { |
86 | log.info("codeAndBtnId ==>> {}", s1); | 86 | log.info("codeAndBtnId ==>> {}", s1); |
87 | String[] split = s1.split("#"); | 87 | // String[] split = s1.split("#"); |
88 | 88 | // | |
89 | if (split.length == 0) { | 89 | // if (split.length == 0) { |
90 | split = s1.split("-"); | 90 | // split = s1.split("-"); |
91 | } | 91 | // } |
92 | 92 | // | |
93 | if (split.length == 0) { | 93 | // if (split.length == 0) { |
94 | continue; | 94 | // continue; |
95 | } | 95 | // } |
96 | log.info("分割后的结果 ==>> {}", split); | 96 | // log.info("分割后的结果 ==>> {}", split); |
97 | try { | 97 | try { |
98 | subjectCode = code; | 98 | subjectCode = code; |
99 | log.info("专题code ==>> {}", subjectCode); | 99 | log.info("专题code ==>> {}", subjectCode); |
100 | subjectId = this.findSubjectByCode(subjectCode); | 100 | subjectId = this.findSubjectByCode(subjectCode); |
101 | if (Objects.isNull(subjectId)) { | 101 | log.info("专题subjectId ==>> {}", subjectId); |
102 | if (subjectId == null) { | ||
103 | log.info("subjectId is null"); | ||
102 | log.error("模板按钮点击次数统计异常,通过活动code无法获取专题, subjectCode ==>> {}", subjectCode); | 104 | log.error("模板按钮点击次数统计异常,通过活动code无法获取专题, subjectCode ==>> {}", subjectCode); |
103 | continue; | 105 | continue; |
104 | } | 106 | } |
105 | paramValueId = Long.valueOf(split[1]); | 107 | log.info("subjectId is not null"); |
108 | paramValueId = Long.valueOf(s1); | ||
106 | log.info("模板属性id ==>> {}", paramValueId); | 109 | log.info("模板属性id ==>> {}", paramValueId); |
107 | name = this.findParamValueByValueId(paramValueId); | 110 | name = this.findParamValueByValueId(paramValueId); |
108 | log.info("模板属性名称 ==>> {}", name); | 111 | log.info("模板属性名称 ==>> {}", name); |
... | @@ -111,7 +114,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -111,7 +114,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
111 | name = "#"; | 114 | name = "#"; |
112 | // continue; | 115 | // continue; |
113 | } | 116 | } |
114 | } catch (Exception e) { | 117 | } |
118 | catch (Exception e) { | ||
115 | log.error(e.getMessage()); | 119 | log.error(e.getMessage()); |
116 | continue; | 120 | continue; |
117 | } | 121 | } |
... | @@ -138,7 +142,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -138,7 +142,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
138 | activityBtnPvUvHour.setUv(hourUv); | 142 | activityBtnPvUvHour.setUv(hourUv); |
139 | this.activityBtnPvUvHourService.create(activityBtnPvUvHour); | 143 | this.activityBtnPvUvHourService.create(activityBtnPvUvHour); |
140 | 144 | ||
141 | } else { | 145 | } |
146 | else { | ||
142 | 147 | ||
143 | // 修改 | 148 | // 修改 |
144 | Integer hourPv = this.getHourPV(subjectCode, paramValueId); | 149 | Integer hourPv = this.getHourPV(subjectCode, paramValueId); |
... | @@ -181,7 +186,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -181,7 +186,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
181 | activityBtnPvUvDay.setUv(dayUv); | 186 | activityBtnPvUvDay.setUv(dayUv); |
182 | this.activityBtnPvUvDayService.create(activityBtnPvUvDay); | 187 | this.activityBtnPvUvDayService.create(activityBtnPvUvDay); |
183 | 188 | ||
184 | } else { | 189 | } |
190 | else { | ||
185 | 191 | ||
186 | Integer dayPv = this.getDayPV(subjectCode, paramValueId); | 192 | Integer dayPv = this.getDayPV(subjectCode, paramValueId); |
187 | Integer dayUv = this.getDayUV(subjectCode, paramValueId); | 193 | Integer dayUv = this.getDayUV(subjectCode, paramValueId); |
... | @@ -222,7 +228,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -222,7 +228,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
222 | 228 | ||
223 | this.activityBtnPvUvService.create(activityBtnPvUv); | 229 | this.activityBtnPvUvService.create(activityBtnPvUv); |
224 | 230 | ||
225 | } else { | 231 | } |
232 | else { | ||
226 | 233 | ||
227 | Integer allPV = this.getAllPV(subjectCode, paramValueId); | 234 | Integer allPV = this.getAllPV(subjectCode, paramValueId); |
228 | Integer allUv = this.getAllUV(subjectCode, paramValueId); | 235 | Integer allUv = this.getAllUV(subjectCode, paramValueId); |
... | @@ -256,8 +263,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -256,8 +263,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
256 | 263 | ||
257 | 264 | ||
258 | private Integer getAllUV(String code, Long btnId) { | 265 | private Integer getAllUV(String code, Long btnId) { |
259 | String key = "SUBJECT_BTN_UV|"+code+"#"+btnId; | 266 | String key = "SUBJECT_BTN_CLICK_UV|"+code+"#"+btnId; |
260 | log.info("getAllUV ==>> key ==>> {}", key); | 267 | log.info("getBtnClickAllUV ==>> key ==>> {}", key); |
261 | Object hourBtnClickUV = this.redisUtils.hget(key, "ALL"); | 268 | Object hourBtnClickUV = this.redisUtils.hget(key, "ALL"); |
262 | if (Objects.nonNull(hourBtnClickUV)) { | 269 | if (Objects.nonNull(hourBtnClickUV)) { |
263 | return Integer.valueOf(hourBtnClickUV.toString()); | 270 | return Integer.valueOf(hourBtnClickUV.toString()); |
... | @@ -272,8 +279,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -272,8 +279,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
272 | } | 279 | } |
273 | 280 | ||
274 | private Integer getAllPV(String code, Long btnId) { | 281 | private Integer getAllPV(String code, Long btnId) { |
275 | String key = "SUBJECT_BTN_PV|"+code+"#"+btnId; | 282 | String key = "SUBJECT_BTN_CLICK_PV|"+code+"#"+btnId; |
276 | log.info("getAllPV ==>> key ==>> {}", key); | 283 | log.info("getBtnClickAllPV ==>> key ==>> {}", key); |
277 | Object hourBtnClickPV = this.redisUtils.hget(key, "ALL"); | 284 | Object hourBtnClickPV = this.redisUtils.hget(key, "ALL"); |
278 | if (Objects.nonNull(hourBtnClickPV)) { | 285 | if (Objects.nonNull(hourBtnClickPV)) { |
279 | return Integer.valueOf(hourBtnClickPV.toString()); | 286 | return Integer.valueOf(hourBtnClickPV.toString()); |
... | @@ -288,8 +295,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -288,8 +295,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
288 | } | 295 | } |
289 | 296 | ||
290 | private Integer getDayUV(String code, Long btnId) { | 297 | private Integer getDayUV(String code, Long btnId) { |
291 | String key = "SUBJECT_BTN_UV|"+code+"#"+btnId+ "|" + LocalDate.now(); | 298 | String key = "SUBJECT_BTN_CLICK_UV|"+code+"#"+btnId+ "|" + LocalDate.now(); |
292 | log.info("getDayUV ==>> key ==>> {}", key); | 299 | log.info("getBtnClickDayUV ==>> key ==>> {}", key); |
293 | Object hourBtnClickUV = this.redisUtils.hget(key, "ALL"); | 300 | Object hourBtnClickUV = this.redisUtils.hget(key, "ALL"); |
294 | if (Objects.nonNull(hourBtnClickUV)) { | 301 | if (Objects.nonNull(hourBtnClickUV)) { |
295 | return Integer.valueOf(hourBtnClickUV.toString()); | 302 | return Integer.valueOf(hourBtnClickUV.toString()); |
... | @@ -304,8 +311,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -304,8 +311,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
304 | } | 311 | } |
305 | 312 | ||
306 | private Integer getDayPV(String code, Long btnId) { | 313 | private Integer getDayPV(String code, Long btnId) { |
307 | String key = "SUBJECT_BTN_PV|"+code+"#"+btnId+ "|" + LocalDate.now(); | 314 | String key = "SUBJECT_BTN_CLICK_PV|"+code+"#"+btnId+ "|" + LocalDate.now(); |
308 | log.info("getDayUV ==>> key ==>> {}", key); | 315 | log.info("getBtnClickDayUV ==>> key ==>> {}", key); |
309 | Object hourBtnClickPV = this.redisUtils.hget(key, "ALL"); | 316 | Object hourBtnClickPV = this.redisUtils.hget(key, "ALL"); |
310 | if (Objects.nonNull(hourBtnClickPV)) { | 317 | if (Objects.nonNull(hourBtnClickPV)) { |
311 | return Integer.valueOf(hourBtnClickPV.toString()); | 318 | return Integer.valueOf(hourBtnClickPV.toString()); |
... | @@ -328,8 +335,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -328,8 +335,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
328 | hourStr = String.valueOf(hour); | 335 | hourStr = String.valueOf(hour); |
329 | } | 336 | } |
330 | 337 | ||
331 | String key = "SUBJECT_BTN_UV|"+code+"#"+btnId+ "|" + LocalDate.now()+"|"+hourStr; | 338 | String key = "SUBJECT_BTN_CLICK_UV|"+code+"#"+btnId+ "|" + LocalDate.now()+"|"+hourStr; |
332 | log.info("getHourUV ==>> key ==>> {}", key); | 339 | log.info("getBtnClickHourUV ==>> key ==>> {}", key); |
333 | Object hourBtnClickUV = this.redisUtils.hget(key, "ALL"); | 340 | Object hourBtnClickUV = this.redisUtils.hget(key, "ALL"); |
334 | if (Objects.nonNull(hourBtnClickUV)) { | 341 | if (Objects.nonNull(hourBtnClickUV)) { |
335 | return Integer.valueOf(hourBtnClickUV.toString()); | 342 | return Integer.valueOf(hourBtnClickUV.toString()); |
... | @@ -351,8 +358,8 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -351,8 +358,8 @@ public class ActivityBtnClickPvUcCalculateTask { |
351 | } else { | 358 | } else { |
352 | hourStr = String.valueOf(hour); | 359 | hourStr = String.valueOf(hour); |
353 | } | 360 | } |
354 | String key = "SUBJECT_BTN_PV|"+code+"#"+btnId+ "|" + LocalDate.now()+"|"+hourStr; | 361 | String key = "SUBJECT_BTN_CLICK_PV|"+code+"#"+btnId+ "|" + LocalDate.now()+"|"+hourStr; |
355 | log.info("getHourPV ==>> key ==>> {}", key); | 362 | log.info("getBtnClickHourPV ==>> key ==>> {}", key); |
356 | Object hourBtnClickPV = this.redisUtils.hget(key, "ALL"); | 363 | Object hourBtnClickPV = this.redisUtils.hget(key, "ALL"); |
357 | if (Objects.nonNull(hourBtnClickPV)) { | 364 | if (Objects.nonNull(hourBtnClickPV)) { |
358 | return Integer.valueOf(hourBtnClickPV.toString()); | 365 | return Integer.valueOf(hourBtnClickPV.toString()); |
... | @@ -377,8 +384,9 @@ public class ActivityBtnClickPvUcCalculateTask { | ... | @@ -377,8 +384,9 @@ public class ActivityBtnClickPvUcCalculateTask { |
377 | } | 384 | } |
378 | 385 | ||
379 | private Long findSubjectByCode(String subjectCode) { | 386 | private Long findSubjectByCode(String subjectCode) { |
380 | String sql = "SELECT am.`id` FROM `x_subject` AS am WHERE `code` = '"+subjectCode+"'"; | 387 | String sql = "SELECT am.`id` FROM `cms_subject` AS am WHERE `code` = '"+subjectCode+"'"; |
381 | List<Map<String, Object>> objectMap = this.jdbcTemplate.queryForList(sql); | 388 | List<Map<String, Object>> objectMap = this.jdbcTemplate.queryForList(sql); |
389 | log.info("findSubjectByCode result: {}", objectMap); | ||
382 | if (CollectionUtils.isNotEmpty(objectMap)) { | 390 | if (CollectionUtils.isNotEmpty(objectMap)) { |
383 | Map<String, Object> map = objectMap.get(0); | 391 | Map<String, Object> map = objectMap.get(0); |
384 | return Long.valueOf(map.get("id").toString()); | 392 | return Long.valueOf(map.get("id").toString()); | ... | ... |
... | @@ -249,7 +249,7 @@ public class PvUvCalculateTask { | ... | @@ -249,7 +249,7 @@ public class PvUvCalculateTask { |
249 | 249 | ||
250 | 250 | ||
251 | private Integer getDayUV(String code){ | 251 | private Integer getDayUV(String code){ |
252 | log.info("getDayBtnClickUV ==>> key ==>> {}", "SUBJECT_UV" + "|" + code + "|" + LocalDate.now()); | 252 | log.info("getDayUV ==>> key ==>> {}", "SUBJECT_UV" + "|" + code + "|" + LocalDate.now()); |
253 | Object hourBtnClickUV = this.redisUtils.hget("SUBJECT_UV" + "|" + code + "|" + LocalDate.now(), "ALL"); | 253 | Object hourBtnClickUV = this.redisUtils.hget("SUBJECT_UV" + "|" + code + "|" + LocalDate.now(), "ALL"); |
254 | if (Objects.nonNull(hourBtnClickUV)) { | 254 | if (Objects.nonNull(hourBtnClickUV)) { |
255 | return Integer.valueOf(hourBtnClickUV.toString()); | 255 | return Integer.valueOf(hourBtnClickUV.toString()); |
... | @@ -272,7 +272,7 @@ public class PvUvCalculateTask { | ... | @@ -272,7 +272,7 @@ public class PvUvCalculateTask { |
272 | private List<Map<String,Object>> getAllSubjectCode(){ | 272 | private List<Map<String,Object>> getAllSubjectCode(){ |
273 | 273 | ||
274 | String sql = "SELECT adr.`id` AS `id`, adr.`code` AS `code` FROM " + | 274 | String sql = "SELECT adr.`id` AS `id`, adr.`code` AS `code` FROM " + |
275 | " `x_subject` adr " + | 275 | " `cms_subject` adr " + |
276 | " GROUP BY `code`"; | 276 | " GROUP BY `code`"; |
277 | return this.jdbcTemplate.queryForList(sql); | 277 | return this.jdbcTemplate.queryForList(sql); |
278 | 278 | ... | ... |
1 | package com.topdraw.redis.config; | 1 | package com.topdraw.redis.config; |
2 | 2 | ||
3 | import lombok.extern.slf4j.Slf4j; | 3 | import lombok.extern.slf4j.Slf4j; |
4 | import org.apache.commons.lang.StringUtils; | ||
4 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; | 5 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; |
5 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
6 | import org.springframework.beans.factory.annotation.Qualifier; | 7 | import org.springframework.beans.factory.annotation.Qualifier; |
... | @@ -13,7 +14,6 @@ import org.springframework.data.redis.connection.*; | ... | @@ -13,7 +14,6 @@ import org.springframework.data.redis.connection.*; |
13 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | 14 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
14 | import org.springframework.data.redis.core.RedisTemplate; | 15 | import org.springframework.data.redis.core.RedisTemplate; |
15 | import org.springframework.data.redis.core.StringRedisTemplate; | 16 | import org.springframework.data.redis.core.StringRedisTemplate; |
16 | import org.springframework.util.StringUtils; | ||
17 | import redis.clients.jedis.Jedis; | 17 | import redis.clients.jedis.Jedis; |
18 | import redis.clients.jedis.JedisPool; | 18 | import redis.clients.jedis.JedisPool; |
19 | import redis.clients.jedis.JedisPoolConfig; | 19 | import redis.clients.jedis.JedisPoolConfig; |
... | @@ -37,25 +37,16 @@ import java.util.Set; | ... | @@ -37,25 +37,16 @@ import java.util.Set; |
37 | public class MyJedisConfig { | 37 | public class MyJedisConfig { |
38 | 38 | ||
39 | /***生产环境要打开此配置*/ | 39 | /***生产环境要打开此配置*/ |
40 | @Value("${spring.redis.sentinel.master}") | 40 | @Value("${spring.redis.sentinel.master:''}") |
41 | private String master; | 41 | private String master; |
42 | 42 | @Value("${spring.redis.sentinel.nodes:''}") | |
43 | @Value("${spring.redis.sentinel.nodes}") | ||
44 | private String sentinelHost; | 43 | private String sentinelHost; |
45 | 44 | @Value(("${spring.redis.host:''}")) | |
46 | @Bean | 45 | private String host; |
47 | public Jedis jedisPool(JedisPoolConfig jedisPoolConfig) { | 46 | @Value(("${spring.redis.port:''}")) |
48 | String[] split = sentinelHost.split(","); | 47 | private String port; |
49 | Set<String> sentinels = new HashSet<>(); | 48 | @Value(("${spring.redis.timeout:''}")) |
50 | for (int i = 0; i < split.length; i++) { | 49 | private String timeout; |
51 | String s = split[i]; | ||
52 | sentinels.add(s); | ||
53 | } | ||
54 | |||
55 | JedisSentinelPool jedisPool = new JedisSentinelPool(master, sentinels, jedisPoolConfig); | ||
56 | Jedis jedis = jedisPool.getResource(); | ||
57 | return jedis; | ||
58 | } | ||
59 | 50 | ||
60 | @Bean | 51 | @Bean |
61 | public JedisPoolConfig jedisPoolConfig() { | 52 | public JedisPoolConfig jedisPoolConfig() { |
... | @@ -65,20 +56,43 @@ public class MyJedisConfig { | ... | @@ -65,20 +56,43 @@ public class MyJedisConfig { |
65 | jedisPoolConfig.setMinIdle(5); | 56 | jedisPoolConfig.setMinIdle(5); |
66 | jedisPoolConfig.setMaxWaitMillis(10000); | 57 | jedisPoolConfig.setMaxWaitMillis(10000); |
67 | jedisPoolConfig.setTestOnBorrow(true); | 58 | jedisPoolConfig.setTestOnBorrow(true); |
68 | |||
69 | return jedisPoolConfig; | 59 | return jedisPoolConfig; |
70 | } | 60 | } |
71 | 61 | ||
72 | /*@Bean | 62 | @Bean |
73 | public Jedis jedisPool(@Value("${spring.redis.host}") String host, | 63 | public Jedis jedisPool(JedisPoolConfig jedisPoolConfig) { |
74 | @Value("${spring.redis.port}") int port, | 64 | log.info("spring.redis.sentinel.nodes: {}", sentinelHost); |
75 | @Value("${spring.redis.timeout}") int timeout, | 65 | if (StringUtils.isNotEmpty(sentinelHost) && !"''".equals(sentinelHost)) { |
76 | // @Value("${spring.redis.password}") String password, | 66 | log.info("哨兵模式"); |
77 | JedisPoolConfig jedisPoolConfig) { | 67 | String[] split = sentinelHost.split(","); |
68 | Set<String> sentinels = new HashSet<>(); | ||
69 | for (int i = 0; i < split.length; i++) { | ||
70 | String s = split[i]; | ||
71 | sentinels.add(s); | ||
72 | } | ||
73 | |||
74 | JedisSentinelPool jedisPool = new JedisSentinelPool(master, sentinels, jedisPoolConfig); | ||
75 | Jedis jedis = jedisPool.getResource(); | ||
76 | return jedis; | ||
77 | }else { | ||
78 | log.info("单台Redis, host: {}, port: {}, timeout: {}", host, port, timeout); | ||
79 | JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, Integer.parseInt(port), Integer.parseInt(timeout)); | ||
80 | return jedisPool.getResource(); | ||
81 | } | ||
82 | } | ||
83 | |||
78 | 84 | ||
79 | // JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout,"redis123"); | 85 | // @Bean |
80 | JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout); | 86 | // public Jedis jedisPool(@Value("${spring.redis.host}") String host, |
87 | // @Value("${spring.redis.port}") int port, | ||
88 | // @Value("${spring.redis.timeout}") int timeout, | ||
89 | //// @Value("${spring.redis.password}") String password, | ||
90 | // JedisPoolConfig jedisPoolConfig) { | ||
91 | // | ||
92 | //// JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout,"redis123"); | ||
93 | // JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout); | ||
94 | // | ||
95 | // return jedisPool.getResource(); | ||
96 | // } | ||
81 | 97 | ||
82 | return jedisPool.getResource(); | ||
83 | }*/ | ||
84 | } | 98 | } | ... | ... |
-
Please register or sign in to post a comment