diff --git a/pom.xml b/pom.xml
index e43c74d..2034a78 100644
--- a/pom.xml
+++ b/pom.xml
@@ -98,11 +98,21 @@
org.springframework.boot
spring-boot-starter-undertow
+
+
+ org.springframework.boot
+ spring-boot-starter-integration
+
+
+
+ org.springframework.integration
+ spring-integration-jdbc
+
-
+
org.springframework.boot
diff --git a/src/main/java/jj/tech/paolu/biz/webadmin/component/Hgt8Component.java b/src/main/java/jj/tech/paolu/biz/webadmin/component/Hgt8Component.java
index 0a604fa..ca6fe2d 100644
--- a/src/main/java/jj/tech/paolu/biz/webadmin/component/Hgt8Component.java
+++ b/src/main/java/jj/tech/paolu/biz/webadmin/component/Hgt8Component.java
@@ -30,6 +30,7 @@ import com.microsoft.playwright.options.RequestOptions;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
+import jj.tech.paolu.biz.webadmin.service.G24Service;
import jj.tech.paolu.biz.webadmin.service.Idc9998Sevice;
import jj.tech.paolu.config.enums.Games;
import jj.tech.paolu.repository.mybatis.dao.Idc9998AdminInfoMapper;
@@ -54,6 +55,7 @@ public class Hgt8Component{
@Autowired Idc9998Sevice idc9998Sevice;
@Autowired Idc9998AdminInfoMapper idc9998AdminInfoMapper;
+ @Autowired G24Service g24Service;
@Value("${idc9998.headless}")
public void setHeadless(Boolean headless){
@@ -78,8 +80,8 @@ public class Hgt8Component{
.setSlowMo(200)
);
- Idc9998AdminInfo admin = idc9998Sevice.getByUserName("bk7897");
- this.addInstance(admin.getUser_name());
+// Idc9998AdminInfo admin = idc9998Sevice.getByUserName("bk7897");
+// this.addInstance(admin.getUser_name());
logger.info("playwright started");
}
@@ -111,6 +113,7 @@ public class Hgt8Component{
inst.admin = bean;
inst.idc9998Sevice = this.idc9998Sevice;
inst.idc9998AdminInfoMapper = this.idc9998AdminInfoMapper;
+ inst.g24Service = this.g24Service;
Hgt8Component.instances.put(userName, inst);
return inst;
}else {
@@ -174,6 +177,7 @@ public class Hgt8Component{
YMHttp.customApi(Base64.encodeBase64String(image_bytes));
JsonNode code_num = root.get("data").get("data");
ifr_main.getByTestId("userName").fill(this.admin.getUser_name());
+ this.page.waitForTimeout(1_500);
ifr_main.getByTestId("password").fill(this.admin.getUser_password());
ifr_main.getByTestId("code").fill(code_num.asText());
this.page.waitForTimeout(5_500); //wait 2500
@@ -190,41 +194,22 @@ public class Hgt8Component{
ifr_main.getByTestId("tc_Close")
.click();
- this.page.frameLocator("#ifr_main")
- .locator("xpath=//input[@class='protocol-btn-y']")
- .click();
-
+ //及时注单
this.page.frameLocator("#ifr_main")
.locator("#jishi-order")
.click();
- Response s = page.waitForResponse(resp -> {
- System.err.println(resp.url());
- if(resp.status() == 200 ) {
-
- return true;
- }else {
- return false;
- }
- },
- () -> {
- System.out.println("所有返回相应");
- }
- );
+ //this.G_24_Curr().join();
//更新用户登录状态
- String loginInfo = this.aPIRequestContext.storageState();
-
+// String loginInfo = this.aPIRequestContext.storageState();
// idc9998Sevice.updateLoginInfo(this.admin.getUser_name(), loginInfo, 1);
// this.admin.setIs_online(1);
// this.admin.setLogin_info(loginInfo);
- //关闭弹窗
- //ifr_main.getByTestId("tc_Close")
- //.click();
return true;
@@ -237,34 +222,39 @@ public class Hgt8Component{
public CompletableFuture G_24_Curr() {
CompletableFuture future = CompletableFuture.supplyAsync(() -> {
- Response response = page.waitForResponse(resp -> {
- System.err.println(resp.url());
- if(resp.status() == 200 ) {
- return true;
- }else {
- return false;
- }
- },
- () -> {
- System.out.println("所有返回相应");
- }
+ Response response = this.page.waitForResponse(resp ->
+ {
+ //System.err.println(resp.url());
+ String g24curr_url = this.admin.getDomain()+"/wb2/jd001/m018";
+ if(resp.status() == 200 && g24curr_url.equals(resp.url())) {
+ return true;
+ }else {
+ return false;
+ }
+ },
+ () -> {
+ //System.out.println("所有返回响应");
+ }
);
+ g24Service.getCurretG24Data(response.text());
+
return response;
});
return future.handleAsync((Response re, Throwable ex) -> {
if(ex != null) {
- ex.printStackTrace();
- wrong_times.getAndIncrement();
- if(wrong_times.get()>3) {
- return future;
+ logger.error(ex.getMessage());
+ this.wrong_times.getAndIncrement();
+ if(this.wrong_times.get()>3) {
+ return CompletableFuture.completedFuture(re);
}
-
return G_24_Curr();
} else {
+ this.wrong_times = new AtomicInteger(0);
return G_24_Curr();
}
+
})
.thenCompose(Function.identity());
diff --git a/src/main/java/jj/tech/paolu/biz/webadmin/controller/Idc9998Controller.java b/src/main/java/jj/tech/paolu/biz/webadmin/controller/Idc9998Controller.java
index e0297bb..cc3a6c0 100644
--- a/src/main/java/jj/tech/paolu/biz/webadmin/controller/Idc9998Controller.java
+++ b/src/main/java/jj/tech/paolu/biz/webadmin/controller/Idc9998Controller.java
@@ -2,8 +2,11 @@ package jj.tech.paolu.biz.webadmin.controller;
import java.util.HashMap;
import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.jdbc.lock.JdbcLockRegistry;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -26,7 +29,7 @@ import jj.tech.paolu.utils.R;
@RequestMapping(value = "/op/idc9998",name = "游戏报告列表")
@Tag(name = "Idc9998Controller", description = "游戏报告列表")
public class Idc9998Controller {
-
+ @Autowired JdbcLockRegistry jdbcLockRegistry;
@Autowired CurrentG24Mapper currentG24Mapper;
@Autowired HistoryG24Mapper historyG24Mapper;
@@ -73,10 +76,25 @@ public class Idc9998Controller {
//// Idc9998AdminInfo admin = idc9998Sevice.getByUserName("bk7897");
// hgt8Component.getInstance("bk7897").login();
//
-// return R.FALSE("无法找到该游戏数据");
+// return R.FALSE("");
//
// }
+ @Operation(summary = "test lock")
+ @PostMapping("/lock")
+ public Object lock() throws Exception {
+ Lock lock = jdbcLockRegistry.obtain("account-lock");
+ if (lock.tryLock()) {
+ System.out.println("拿到锁");
+ } else {
+ System.out.println("拿不到锁");
+ }
+ return R.FALSE("");
+
+ }
+
+
+
}
diff --git a/src/main/java/jj/tech/paolu/biz/webadmin/service/G24Service.java b/src/main/java/jj/tech/paolu/biz/webadmin/service/G24Service.java
index 8e1d89c..fac9474 100644
--- a/src/main/java/jj/tech/paolu/biz/webadmin/service/G24Service.java
+++ b/src/main/java/jj/tech/paolu/biz/webadmin/service/G24Service.java
@@ -5,6 +5,8 @@ import static org.mybatis.dynamic.sql.SqlBuilder.*;
import java.time.LocalDateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -14,6 +16,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import jj.tech.paolu.biz.webadmin.component.Hgt8Component;
import jj.tech.paolu.repository.mybatis.dao.CurrentG24Mapper;
import jj.tech.paolu.repository.mybatis.dao.HistoryG24Mapper;
import jj.tech.paolu.repository.mybatis.dao.support.HistoryG24DynamicSqlSupport;
@@ -23,6 +26,7 @@ import jj.tech.paolu.utils.IDHelp;
@Service
public class G24Service {
+ private static Logger logger = LoggerFactory.getLogger(G24Service.class);
@Autowired CurrentG24Mapper currentG24Mapper;
@Autowired HistoryG24Mapper historyG24Mapper;
@@ -80,6 +84,7 @@ public class G24Service {
}
} catch (Exception e) {
+ logger.error(e.getMessage());
throw new RuntimeException(e);
}
diff --git a/src/main/java/jj/tech/paolu/config/lock/LockRegistryConfiguration.java b/src/main/java/jj/tech/paolu/config/lock/LockRegistryConfiguration.java
new file mode 100644
index 0000000..e90db7b
--- /dev/null
+++ b/src/main/java/jj/tech/paolu/config/lock/LockRegistryConfiguration.java
@@ -0,0 +1,24 @@
+package jj.tech.paolu.config.lock;
+
+import javax.sql.DataSource;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.integration.jdbc.lock.DefaultLockRepository;
+import org.springframework.integration.jdbc.lock.JdbcLockRegistry;
+import org.springframework.integration.jdbc.lock.LockRepository;
+
+@Configuration
+public class LockRegistryConfiguration {
+
+ @Bean
+ public DefaultLockRepository defaultLockRepository(DataSource dataSource){
+ return new DefaultLockRepository(dataSource); //DefaultLockRepository.setTimeToLive(1000 * 100);
+ }
+
+ @Bean
+ public JdbcLockRegistry jdbcLockRegistry(DefaultLockRepository lockRepository){
+ return new JdbcLockRegistry(lockRepository);
+ }
+
+}
diff --git a/src/main/java/jj/tech/paolu/config/start/StartCloseConfig.java b/src/main/java/jj/tech/paolu/config/start/StartCloseConfig.java
deleted file mode 100644
index 954afd4..0000000
--- a/src/main/java/jj/tech/paolu/config/start/StartCloseConfig.java
+++ /dev/null
@@ -1,16 +0,0 @@
-//package jj.tech.paolu.config.start;
-//
-//import org.springframework.context.annotation.Bean;
-//import org.springframework.context.annotation.Configuration;
-//
-//import jj.tech.paolu.biz.webadmin.component.Hgt8Component;
-//
-//@Configuration
-//public class StartCloseConfig {
-//
-// @Bean
-// public Hgt8Component messageProcessor() {
-// return new Hgt8Component();
-// }
-//
-//}
diff --git a/src/main/java/jj/tech/paolu/task/Hgt8Timer.java b/src/main/java/jj/tech/paolu/task/Hgt8Timer.java
index 6a1ffe8..df83e47 100644
--- a/src/main/java/jj/tech/paolu/task/Hgt8Timer.java
+++ b/src/main/java/jj/tech/paolu/task/Hgt8Timer.java
@@ -1,43 +1,124 @@
-//package jj.tech.paolu.task;
-//
-//import java.time.LocalDate;
-//import java.time.format.DateTimeFormatter;
-//
-//import org.slf4j.Logger;
-//import org.slf4j.LoggerFactory;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.stereotype.Component;
-//
-//import jj.tech.paolu.biz.webadmin.component.Hgt8Component;
-//import jj.tech.paolu.biz.webadmin.service.Idc9998Sevice;
-//import jj.tech.paolu.repository.mybatis.dao.Idc9998AdminInfoMapper;
-//import jj.tech.paolu.repository.mybatis.entity.Idc9998AdminInfo;
-//
-//@Component
-//public class Hgt8Timer {
-// private static Logger logger = LoggerFactory.getLogger(Hgt8Timer.class);
-//
-// @Autowired Idc9998Sevice idc9998Sevice;
-// @Autowired Idc9998AdminInfoMapper idc9998AdminInfoMapper;
-// @Autowired Hgt8Component hgt8Component;
-//
-// @Scheduled(cron = "0/180 * * * * ?")//60s
-// public void login() {
-// Idc9998AdminInfo admin =
-// idc9998Sevice.getByUserName("bk7897");
-// if(admin != null && admin.getIs_online() != 1) {
-//
-// hgt8Component.addInstance(admin.getUser_name())
-// .forceLogin();
-//
-// }else {
-// hgt8Component.addInstance(admin.getUser_name());
+package jj.tech.paolu.task;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.jdbc.lock.JdbcLockRegistry;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import jj.tech.paolu.biz.webadmin.component.Hgt8Component;
+import jj.tech.paolu.biz.webadmin.service.Idc9998Sevice;
+import jj.tech.paolu.repository.mybatis.dao.Idc9998AdminInfoMapper;
+import jj.tech.paolu.repository.mybatis.entity.Idc9998AdminInfo;
+
+import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
+
+
+@Component
+public class Hgt8Timer {
+ private static Logger logger = LoggerFactory.getLogger(Hgt8Timer.class);
+
+ @Autowired Idc9998Sevice idc9998Sevice;
+ @Autowired Idc9998AdminInfoMapper idc9998AdminInfoMapper;
+ @Autowired Hgt8Component hgt8Component;
+
+ @Autowired JdbcLockRegistry jdbcLockRegistry;
+
+ //@Scheduled(cron = "0/180 * * * * ?")//60s
+ @Scheduled(fixedDelay = 180) //上一次执行完毕之后,执行的时间间隔
+ public void login() {
+ Lock lock = jdbcLockRegistry.obtain("login");
+ if(lock.tryLock()) {
+ Idc9998AdminInfo admin = idc9998Sevice.getByUserName("bk7897");
+ if(admin != null && admin.getIs_online() != 1) {
+ Boolean login_ok =
+ hgt8Component
+ .addInstance(admin.getUser_name())
+ .forceLogin();
+ if(login_ok) {
+ //更新用户登录状态
+ String loginInfo = hgt8Component.addInstance(admin.getUser_name()).aPIRequestContext.storageState();
+ idc9998Sevice.updateLoginInfo(hgt8Component.addInstance(admin.getUser_name()).admin.getUser_name(), loginInfo, 1);
+ hgt8Component.addInstance(admin.getUser_name()).admin.setIs_online(1);
+ hgt8Component.addInstance(admin.getUser_name()).admin.setLogin_info(loginInfo);
+ }
+
+ }
+ lock.unlock();
+ }
+
+ }
+
+
+ @Scheduled(fixedDelay=60)
+ public void isLogin() {
+ Lock lock = jdbcLockRegistry.obtain("login");
+ if(lock.tryLock()) {
+ Hgt8Component bk = hgt8Component.getInstance("bk7897");
+ if(bk!=null && bk.admin!=null) {
+ Boolean isLogin = bk.page.frameLocator("#ifr_main").locator("#jishi-order").isVisible();
+
+ if(!isLogin) {
+ bk.admin.setIs_online(0);
+ idc9998Sevice.updateLoginInfo("bk7897", bk.aPIRequestContext.storageState(), 0);
+ }
+
+ }
+ lock.unlock();
+ }
+ }
+
+ @Scheduled(cron = "0/60 * * * * ?")//5秒
+ public void get_g21_curr() {
+
+ Lock lock = jdbcLockRegistry.obtain("get_g21_curr");
+ if(lock.tryLock()) {
+ Hgt8Component bk = hgt8Component.getInstance("bk7897");
+
+ if(bk.admin.getIs_online()==1) {
+ bk.wrong_times=new AtomicInteger(0);
+ bk.G_24_Curr().join();
+ }
+ lock.unlock();
+ }
+
+ }
+
+// //@Scheduled(cron = "0/60 * * * * ?")//5秒
+// @Scheduled(initialDelay = 1000 * 3, fixedDelay=Long.MAX_VALUE)
+// public void get_g21_curr() {
+//
+// Lock lock = jdbcLockRegistry.obtain("get_g21_curr");
+// if(lock.tryLock()) {
+// Hgt8Component bk = hgt8Component.getInstance("bk7897");
+// if(bk==null || bk.admin==null) {
+// idc9998Sevice.updateIsOnline("bk7897", 0);
+// lock.unlock();
+// return;
+// }
+// if(bk.admin.getIs_online()==1) {
+// //bk.wrong_times=new AtomicInteger(0);
+// bk.G_24_Curr().join();
+//
+//// bk.admin.setIs_online(0);
+//// idc9998Sevice.updateIsOnline("bk7897", 0);
+//
+// }
+// lock.unlock();
// }
+//
// }
-//
+
+
+
// @Scheduled(cron = "0/20 * * * * ?")//5秒
-// public void get_g21() {
+// public void get_g21_his() {
// try {
//
// Hgt8Component bk = hgt8Component.getInstance("bk7897");
@@ -52,7 +133,7 @@
// }
//
// }
-//
-//
-//
-//}
+
+
+
+}
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index 7f5c078..4c9fd2e 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -99,6 +99,8 @@ logging:
root: info
org.jooq: info
org.springframework.amqp: info
+ org.springframework.integration: debug
org.mybatis: debug
org.mybatis.dynamic.sql: debug
- jj.tech.paolu: debug
\ No newline at end of file
+ jj.tech.paolu: debug
+
\ No newline at end of file
diff --git a/src/main/resources/sql/schema-h2.sql b/src/main/resources/sql/schema-h2.sql
index 4496d98..d674c50 100644
--- a/src/main/resources/sql/schema-h2.sql
+++ b/src/main/resources/sql/schema-h2.sql
@@ -181,3 +181,13 @@ create table history_g24 (
unique (newIssue)
);
+
+drop table if exists INT_LOCK;
+CREATE TABLE INT_LOCK (
+ LOCK_KEY CHAR(36) NOT NULL,
+ REGION VARCHAR(100) NOT NULL,
+ CLIENT_ID CHAR(36),
+ CREATED_DATE DATETIME(6) NOT NULL,
+ constraint INT_LOCK_PK primary key (LOCK_KEY, REGION)
+) ENGINE=InnoDB;
+