|
|
@@ -0,0 +1,77 @@
|
|
|
+package com.mokamrp.privates.task.pangu;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.mokamrp.privates.constant.RedisKey;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.DomainFirst;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.DomainSecond;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.PromoteCode;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.PromoteQrcodePool;
|
|
|
+import com.mokamrp.privates.service.pangu.DomainFirstService;
|
|
|
+import com.mokamrp.privates.service.pangu.DomainSecondService;
|
|
|
+import com.mokamrp.privates.service.pangu.PromoteCodeService;
|
|
|
+import com.mokamrp.privates.service.pangu.PromoteQrcodePoolService;
|
|
|
+import com.mokamrp.privates.utils.Cmd;
|
|
|
+import com.mokamrp.privates.utils.http.HttpUtils;
|
|
|
+import net.javacrumbs.shedlock.core.SchedulerLock;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.data.redis.core.ZSetOperations;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class CheckPromoteView {
|
|
|
+ @Autowired
|
|
|
+ public PromoteQrcodePoolService promoteQrcodePoolService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public PromoteCodeService promoteCodeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public ResetCustserviceViewTask resetCustserviceViewTask;
|
|
|
+
|
|
|
+ private final String feishu = "https://open.feishu.cn/open-apis/bot/v2/hook/d2b5556d-30fb-400e-b10f-cb9310dbc705";
|
|
|
+
|
|
|
+ @Scheduled(cron = "* */1 * * * ?") //.间隔 5分钟
|
|
|
+ @SchedulerLock(name = "pangu:CheckPromoteView", lockAtLeastForString = "PT5S", lockAtMostForString = "PT15M")
|
|
|
+ public void execute() {
|
|
|
+ System.out.println("[cronjob]:检测个微活码访问上限");
|
|
|
+ List<PromoteCode> list = promoteCodeService.list();
|
|
|
+ for (PromoteCode promoteCode : list){
|
|
|
+ Boolean hasKey = stringRedisTemplate.hasKey(RedisKey.PanCustServiceIdView + promoteCode.getId());
|
|
|
+ if (!hasKey){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Set<ZSetOperations.TypedTuple<String>> res = stringRedisTemplate.opsForZSet().rangeByScoreWithScores(RedisKey.PanCustServiceIdView + promoteCode.getId(),-1,promoteCode.getHourUvMax()-1);
|
|
|
+ if (res.size() == 0){
|
|
|
+ if (promoteCode.getHourResumeType().equals(1)){
|
|
|
+ List<PromoteQrcodePool> pool = promoteQrcodePoolService.list(new QueryWrapper<PromoteQrcodePool>().eq("promote_id",promoteCode.getId()));
|
|
|
+ for (PromoteQrcodePool promoteQrcodePool :pool) {
|
|
|
+ resetCustserviceViewTask.addRedis(promoteQrcodePool.getPromoteId(),promoteQrcodePool.getCustserviceId(),promoteQrcodePool.getWeight());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ Cmd.sendFeishuMsg(feishu,"[警告]:活码ID:"+promoteCode.getId()+"|"+promoteCode.getName()+",当前小时所有二维码阈值上限,需要人工添加二维码");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private PromoteQrcodePool getPool(List<PromoteQrcodePool> row,Integer promoteId,Integer custserviceId){
|
|
|
+ for (PromoteQrcodePool promoteQrcodePool : row){
|
|
|
+ if (promoteQrcodePool.getPromoteId().equals(promoteId) && promoteQrcodePool.getCustserviceId().equals(custserviceId)){
|
|
|
+ return promoteQrcodePool;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|