perf:glados签到优化
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -27,6 +27,11 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiang.pom</groupId>
|
||||||
|
<artifactId>xmc-common</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.xiang</groupId>
|
<groupId>com.xiang</groupId>
|
||||||
<artifactId>xservice-common</artifactId>
|
<artifactId>xservice-common</artifactId>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class GladosCheckInJob {
|
|||||||
|
|
||||||
private final GLaDOSService glaDOSService;
|
private final GLaDOSService glaDOSService;
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 8,16 1/1 * ?")
|
@Scheduled(cron = "0 0 7 1/1 * ?")
|
||||||
public void checkInJon() {
|
public void checkInJon() {
|
||||||
log.info("[job] Glados Check In Job start, time:{}", LocalDateTime.now());
|
log.info("[job] Glados Check In Job start, time:{}", LocalDateTime.now());
|
||||||
glaDOSService.checkIn();
|
glaDOSService.checkIn();
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package com.xiang.xservice.application.script.glados.service;
|
|||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.xiang.xservice.basic.utils.HttpUtils;
|
|
||||||
import com.xiang.xservice.application.script.glados.common.GladosConstants;
|
import com.xiang.xservice.application.script.glados.common.GladosConstants;
|
||||||
import com.xiang.xservice.application.script.glados.common.URLConstants;
|
import com.xiang.xservice.application.script.glados.common.URLConstants;
|
||||||
import com.xiang.xservice.application.script.glados.entity.GladosRunLog;
|
import com.xiang.xservice.application.script.glados.entity.GladosRunLog;
|
||||||
import com.xiang.xservice.application.script.glados.entity.resp.GLaDOSResponse;
|
import com.xiang.xservice.application.script.glados.entity.resp.GLaDOSResponse;
|
||||||
import com.xiang.xservice.application.script.glados.repository.GladosMapper;
|
import com.xiang.xservice.application.script.glados.repository.GladosMapper;
|
||||||
import com.xiang.xservice.application.script.xb.entity.pojo.User;
|
import com.xiang.xservice.application.script.xb.entity.pojo.User;
|
||||||
|
import com.xiang.xservice.basic.utils.HttpUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -46,7 +46,16 @@ public class GLaDOSServiceImpl implements GLaDOSService{
|
|||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
users.parallelStream().forEach(user -> {
|
users.parallelStream().forEach(user -> {
|
||||||
try {
|
try {
|
||||||
checkIn(user, sb);
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (checkIn(user, sb)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(10000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("线程暂停10s失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("签到失败,", e);
|
log.error("签到失败,", e);
|
||||||
}
|
}
|
||||||
@@ -54,7 +63,7 @@ public class GLaDOSServiceImpl implements GLaDOSService{
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkIn(User user, StringBuffer sb) {
|
private boolean checkIn(User user, StringBuffer sb) {
|
||||||
|
|
||||||
Map<String, String> header = Maps.newHashMap();
|
Map<String, String> header = Maps.newHashMap();
|
||||||
header.put("Cookie", user.getCookie());
|
header.put("Cookie", user.getCookie());
|
||||||
@@ -72,6 +81,8 @@ public class GLaDOSServiceImpl implements GLaDOSService{
|
|||||||
GLaDOSResponse gLaDOSResponse =JSONObject.parseObject(response, GLaDOSResponse.class);
|
GLaDOSResponse gLaDOSResponse =JSONObject.parseObject(response, GLaDOSResponse.class);
|
||||||
if (Objects.nonNull(gLaDOSResponse)) {
|
if (Objects.nonNull(gLaDOSResponse)) {
|
||||||
log.info("http do post success, response:{}", response);
|
log.info("http do post success, response:{}", response);
|
||||||
|
|
||||||
|
// 成功签到记录
|
||||||
if (0 == gLaDOSResponse.getCode() && Objects.nonNull(gLaDOSResponse.getPoints())) {
|
if (0 == gLaDOSResponse.getCode() && Objects.nonNull(gLaDOSResponse.getPoints())) {
|
||||||
log.info("签到成功, 签到积分:{}, 签到消息:{}", gLaDOSResponse.getPoints(), gLaDOSResponse.getMessage());
|
log.info("签到成功, 签到积分:{}, 签到消息:{}", gLaDOSResponse.getPoints(), gLaDOSResponse.getMessage());
|
||||||
sb.append(user.getEmail()).append("签到成功,获得积分:").append(gLaDOSResponse.getPoints()).append("\n");
|
sb.append(user.getEmail()).append("签到成功,获得积分:").append(gLaDOSResponse.getPoints()).append("\n");
|
||||||
@@ -81,11 +92,27 @@ public class GLaDOSServiceImpl implements GLaDOSService{
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("发送钉钉消息失败", e);
|
log.error("发送钉钉消息失败", e);
|
||||||
}
|
}
|
||||||
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(1).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重复签到,表示当日签到成功
|
||||||
if (1 == gLaDOSResponse.getCode()) {
|
if (1 == gLaDOSResponse.getCode()) {
|
||||||
log.warn("签到失败,重复签到,用户:{}, 签到消息:{}", user.getEmail(), gLaDOSResponse.getMessage());
|
log.warn("签到失败,重复签到,用户:{}, 签到消息:{}", user.getEmail(), gLaDOSResponse.getMessage());
|
||||||
sb.append(user).append("签到失败,重复签到,用户:").append(user).append(",签到消息:").append(gLaDOSResponse.getMessage());
|
sb.append(user).append("签到失败,重复签到,用户:").append(user).append(",签到消息:").append(gLaDOSResponse.getMessage());
|
||||||
|
try {
|
||||||
|
dingTalkService.sendScriptMsg("[时间:" + LocalDateTime.now() + "] 用户: " +
|
||||||
|
user.getEmail() + "当天已经签到成功!获得积分" + gLaDOSResponse.getList().get(0));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送钉钉消息失败", e);
|
||||||
}
|
}
|
||||||
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(1).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cookie过期
|
||||||
if (-2 == gLaDOSResponse.getCode()) {
|
if (-2 == gLaDOSResponse.getCode()) {
|
||||||
log.warn("签到失败,用户:{}, cookie过期:{}", user.getEmail(), gLaDOSResponse.getMessage());
|
log.warn("签到失败,用户:{}, cookie过期:{}", user.getEmail(), gLaDOSResponse.getMessage());
|
||||||
String message = "[时间:" + LocalDateTime.now() + "] 用户: " + user.getEmail() + ",签到消息: " + gLaDOSResponse.getMessage();
|
String message = "[时间:" + LocalDateTime.now() + "] 用户: " + user.getEmail() + ",签到消息: " + gLaDOSResponse.getMessage();
|
||||||
@@ -95,15 +122,25 @@ public class GLaDOSServiceImpl implements GLaDOSService{
|
|||||||
log.error("发送钉钉消息失败", e);
|
log.error("发送钉钉消息失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 其余的异常情况
|
||||||
if (gLaDOSResponse.getCode() != 1) {
|
if (gLaDOSResponse.getCode() != 1) {
|
||||||
log.warn("签到异常,返回的消息:{}", gLaDOSResponse.getMessage());
|
log.warn("签到异常,返回的消息:{}", gLaDOSResponse.getMessage());
|
||||||
sb.append(user.getEmail()).append("签到异常,返回的消息:").append(gLaDOSResponse.getMessage()).append("\n");
|
sb.append(user.getEmail()).append("签到异常,返回的消息:").append(gLaDOSResponse.getMessage()).append("\n");
|
||||||
}
|
}
|
||||||
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(1).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(0).code(Integer.valueOf(gLaDOSResponse.getCode().toString())).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
gladosMapper.insertScriptRunLog(build);
|
gladosMapper.insertScriptRunLog(build);
|
||||||
return;
|
return Boolean.FALSE;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
String mes = "[时间:" + LocalDateTime.now() + "] 用户: " + user.getEmail() + ",签到异常,请求结果为空。";
|
||||||
|
dingTalkService.sendScriptMsg(mes);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送钉钉消息失败", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(0).response(response).user(user.getEmail()).userId(user.getId()).build();
|
GladosRunLog build = GladosRunLog.builder().time(LocalDateTime.now()).status(0).response(response).user(user.getEmail()).userId(user.getId()).build();
|
||||||
gladosMapper.insertScriptRunLog(build);
|
gladosMapper.insertScriptRunLog(build);
|
||||||
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,8 @@ public class FundInfoQueryJob {
|
|||||||
if (DateUtils.validWeekTime()) return;
|
if (DateUtils.validWeekTime()) return;
|
||||||
LocalDate now = LocalDate.now();
|
LocalDate now = LocalDate.now();
|
||||||
com.alibaba.fastjson.JSONObject dayResult = (com.alibaba.fastjson.JSONObject) redisService.hGet(RedisConstant.DAY_INFO_PREFIX_KEY + RedisConstant.getDate4Key(), DateUtils.getDateFromDate(now));
|
com.alibaba.fastjson.JSONObject dayResult = (com.alibaba.fastjson.JSONObject) redisService.hGet(RedisConstant.DAY_INFO_PREFIX_KEY + RedisConstant.getDate4Key(), DateUtils.getDateFromDate(now));
|
||||||
if (com.xiang.xservice.common.utils.DateUtils.validHoliday(JSON.toJavaObject(dayResult, DayResult.class))) return;
|
com.xiang.xservice.common.utils.DateUtils dateUtils = new com.xiang.xservice.common.utils.DateUtils();
|
||||||
|
if (dateUtils.validHoliday(JSON.toJavaObject(dayResult, DayResult.class))) return;
|
||||||
|
|
||||||
List<com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo> fundInfos = xbFundMapper.queryListIn2Min();
|
List<com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo> fundInfos = xbFundMapper.queryListIn2Min();
|
||||||
if (CollectionUtils.isEmpty(fundInfos)) {
|
if (CollectionUtils.isEmpty(fundInfos)) {
|
||||||
|
|||||||
@@ -1,16 +1,50 @@
|
|||||||
package com.xiang.xservice.common.utils;
|
package com.xiang.xservice.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xiang.xservice.cache.service.IRedisService;
|
||||||
import com.xiang.xservice.common.entity.DayResult;
|
import com.xiang.xservice.common.entity.DayResult;
|
||||||
|
import com.xiang.xservice.common.enums.RedisConstant;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: xiang
|
* @Author: xiang
|
||||||
* @Date: 2025-10-04 10:34
|
* @Date: 2025-10-04 10:34
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class DateUtils {
|
public class DateUtils {
|
||||||
|
|
||||||
public static Boolean validHoliday(DayResult result) {
|
private IRedisService redisService;
|
||||||
return com.xiang.xservice.basic.utils.DateUtils.validHolidayTime(
|
public Boolean validHoliday(DayResult result) {
|
||||||
result.getDate(), result.getStatusDesc(), result.getWeek(), result.getStatus());
|
LocalDate now = LocalDate.now();
|
||||||
|
JSONObject dayResult = (JSONObject) redisService.hGet(RedisConstant.DAY_INFO_PREFIX_KEY + RedisConstant.getDate4Key(), com.xiang.xservice.basic.utils.DateUtils.getDateFromDate(now));
|
||||||
|
DayResult day = JSON.toJavaObject(dayResult, DayResult.class);
|
||||||
|
if (validHolidayTime(day.getDate(), day.getStatusDesc(), day.getWeek(), day.getStatus()))
|
||||||
|
return Boolean.TRUE;
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean validHolidayTime(String date, String statusDesc, String week, String status) {
|
||||||
|
if (StringUtils.equals(status, "1")) {
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
if (StringUtils.equals(status, "2")) {
|
||||||
|
log.info("当前日期:{}, {}, 是工作日", date, week);
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(status)) {
|
||||||
|
if (StringUtils.equals(week, "周六") || StringUtils.equals(week, "周日")) {
|
||||||
|
log.info("当前日期:{}, {}, 是周末", date, week);
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user