|
|
@@ -0,0 +1,92 @@
|
|
|
+package com.mokamrp.privates.task.pangu;
|
|
|
+
|
|
|
+import com.aliyun.oss.internal.SignUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.mokamrp.privates.constant.RedisKey;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.PromoteCode;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.PromoteMaxRecord;
|
|
|
+import com.mokamrp.privates.service.pangu.FosterwxStationService;
|
|
|
+import com.mokamrp.privates.service.pangu.FosterwxTaskScheduleService;
|
|
|
+import com.mokamrp.privates.service.pangu.PromoteCodeService;
|
|
|
+import com.mokamrp.privates.service.pangu.PromoteMaxRecordService;
|
|
|
+import com.mokamrp.privates.utils.sign.Md5Utils;
|
|
|
+import net.javacrumbs.shedlock.core.SchedulerLock;
|
|
|
+import org.joda.time.DateTime;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.autoconfigure.cache.CacheProperties;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class PromoteCodeMaxRecord {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public PromoteCodeService promoteCodeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public PromoteMaxRecordService promoteMaxRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 */1 * * * ?")
|
|
|
+ @SchedulerLock(name = "pangu:PromoteCodeMaxRecord", lockAtLeastForString = "PT5S", lockAtMostForString = "PT15M")
|
|
|
+ public void execute() {
|
|
|
+ List<PromoteCode> list = promoteCodeService.list(new QueryWrapper<PromoteCode>().eq("promote_type", 2).eq("status", 1));
|
|
|
+ int maxCnt = 0;
|
|
|
+ Boolean isMax = false;
|
|
|
+ for (PromoteCode promoteCode : list) {
|
|
|
+ Set<String> hourScores = stringRedisTemplate.opsForZSet().rangeByScore(RedisKey.PanCustServiceIdView + promoteCode.getId(),0,promoteCode.getHourUvMax()-1);
|
|
|
+ Set<String> dayScores = stringRedisTemplate.opsForZSet().rangeByScore(RedisKey.PanCustServiceIdDayView + promoteCode.getId(), 0,promoteCode.getDayUvMax()-1);
|
|
|
+ if ((hourScores == null || hourScores.size() <= 0) || (dayScores == null || dayScores.size() <= 0)) {
|
|
|
+ maxCnt++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (maxCnt >= list.size()){
|
|
|
+ isMax = true;
|
|
|
+ }
|
|
|
+ String key = RedisKey.PanPromoteMaxStamp;
|
|
|
+ if (isMax.equals(true)) {
|
|
|
+ //.如果所有活码都满了
|
|
|
+ //.检查是否重复记录
|
|
|
+ if (stringRedisTemplate.opsForHyperLogLog().size(key + "max") <= 0) {
|
|
|
+ //.增加已上限标记
|
|
|
+ stringRedisTemplate.opsForHyperLogLog().add(key + "max", "1");
|
|
|
+ stringRedisTemplate.expire(key + "max", 3700, TimeUnit.SECONDS);
|
|
|
+ //.增加日志
|
|
|
+ this.addRecord(2,"所有活码阈值上限");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //.活码还有访问空位
|
|
|
+ //.如果之前标记是已满,则需要改变标记
|
|
|
+ if (stringRedisTemplate.opsForHyperLogLog().size(key + "max") > 0) {
|
|
|
+ //.删除已上限标记
|
|
|
+ stringRedisTemplate.opsForHyperLogLog().delete(key + "max");
|
|
|
+ //.增加日志
|
|
|
+ this.addRecord(1,"活码阈值恢复正常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //.增加日志
|
|
|
+ private Boolean addRecord(Integer status,String msg){
|
|
|
+ LocalDateTime dateTime = LocalDateTime.now();
|
|
|
+ PromoteMaxRecord add = new PromoteMaxRecord();
|
|
|
+ add.setStatus(status);
|
|
|
+ add.setDatetime(dateTime);
|
|
|
+ add.setCreateAt(dateTime);
|
|
|
+ add.setUpdateAt(dateTime);
|
|
|
+ add.setMsg(msg);
|
|
|
+ promoteMaxRecordService.save(add);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|