Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 #55

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

1 #55

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions smart-admin-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<modules>
<module>sa-common</module>
<module>sa-admin</module>
<module>sa-event</module>
</modules>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ spring:
datasource:
url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v2?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
username: root
password: Zhuoda1024lab
password: 123456
initial-size: 2
min-idle: 2
max-active: 10
Expand Down
37 changes: 37 additions & 0 deletions smart-admin-api/sa-event/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.1024lab</groupId>
<artifactId>sa-parent</artifactId>
<version>1.0.0</version>
</parent>

<groupId>com.my</groupId>
<artifactId>sa-event</artifactId>

<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependencies>
<dependency>
<groupId>net.1024lab</groupId>
<artifactId>sa-common</artifactId>
<version>${project.version}</version>
</dependency>


<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.77</version>
</dependency>

</dependencies>
</project>
9 changes: 9 additions & 0 deletions smart-admin-api/sa-event/src/main/java/com/my/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.my;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.my.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
public class WechatConfig {


@Value("${wechat.appid}")
private String appId;
@Value("${wechat.appsecret}")
private String appSecret;
@Value("${wechat.url.code2Session}")
private String code2SessionUrl;
@Value("${wechat.url.getPhoneNumber}")
private String getPhoneNumber;

@Bean
public WechatConfig wechatConfig(){
return new WechatConfig();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.my.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.my.domain.WeChatLoginData;
import com.my.service.WechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@Controller
public class WeChatLoginController {

@Autowired
private WechatService wechatService;

@PostMapping("/login")
public String login(@RequestBody WeChatLoginData data) throws JsonProcessingException {
String code = data.getCode();

wechatService.login(data);

// 返回相应的用户信息或token等
return "Login successful";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.my.domain;

import java.util.List;

public class Gymnasium {
private String name;
private String address;
//经度
private double longitude;
//纬度
private double latitude;
private List<String> courtList;


}
18 changes: 18 additions & 0 deletions smart-admin-api/sa-event/src/main/java/com/my/domain/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.my.domain;

public class Person {

private String name;

private int age;

private String cardID;

private String phoneNumber;

private Sex sex;

public enum Sex {
MALE, FEMALE, OTHER
}
}
13 changes: 13 additions & 0 deletions smart-admin-api/sa-event/src/main/java/com/my/domain/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.my.domain;

import java.util.List;

public class Team {
private String teamName;

private Person teamLeader;

private List<Person> coach;

private List<Person> players;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.my.domain;

import lombok.Data;

@Data
public class WeChatLoginData {
private String code;

public WeChatLoginData(String code){
this.code=code;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.my.domain;

import lombok.Data;

@Data
public class WeChatLoginVo {
private String code;

public WeChatLoginVo(String code){
this.code=code;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.my.domain;

import lombok.Data;

@Data
public class WeChatSessionData {
private String openid;
private String session_key;
private String unionid;
private String errmsg;
private int errcode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.my.service;

import java.util.ArrayList;
import java.util.List;
import java.time.LocalTime;
import java.time.LocalDate;
import java.time.Duration;

import com.my.domain.Gymnasium;
import com.my.domain.Person;

public class GameArrangement {
// 运动员列表
private List<Person> playerList;
// 裁判列表
private List<Person> refereeList;
// 开始日期、结束日期
private LocalDate startDate;
private LocalDate endDate;
// 每天比赛总时长,以分钟计算
private int dailyMatchMins;
// 每场比赛时间
private int matchDurationOnce;
// 比赛场馆
private List<Gymnasium> gList;
// 每天比赛时间段列表,一天可以分段时间进行比赛
private List<Duration> dailyMatchDurationList;

public static void main(String[] args) {
List<String> players = new ArrayList<>();
players.add("Player 1");
players.add("Player 2");
players.add("Player 3");

// Add more players as needed
new GameArrangement().doubleRoundRobinTournament(players);
}
/*
* 单循环比赛分组
如n为奇数,n+1补齐偶数
*偶数后,比赛轮次=n-1;
场数=n(n-1)/2
*/
public void singleRoundRobinTournament(List players){
if (players.size() % 2 != 0) {
players.add("Bye"); // If the number of players is odd, add a bye
}

int n = players.size();
int rounds = n - 1;
int matches = n * (n - 1) / 2;
System.out.println("比赛轮次:" + rounds);
System.out.println("比赛场数:" + matches);

for (int i = 0; i < players.size() - 1; i++) {
System.out.println("Round " + (i + 1) + ":");
for (int j = 0; j < players.size() / 2; j++) {
System.out.println(players.get(j) + " vs " + players.get(players.size() - 1 - j));
}
players.add(1, players.remove(players.size() - 1)); // Rotate the array
}
}

/*
* 双循环比赛分组
* 单循环循环2次
*/
public void doubleRoundRobinTournament(List players){
int n = players.size();
int rounds = n;
int matches = n * (n - 1);
System.out.println("比赛轮次:" + rounds);
System.out.println("比赛场数:" + matches);

for (int i = 0; i < players.size(); i++) {
String player1 = (String) players.get(i);
for (int j = 0; j < players.size(); j++) {
String player2 = (String) players.get(j);
if (!player1.equals(player2)) {
System.out.println(player1 + " vs " + player2);
}
}
}
}

// 计算时间差得出分钟数
public long calTimeDiffInMinutes(LocalTime startTime, LocalTime endTime) {
Duration duration = Duration.between(startTime, endTime);
return duration.toMinutes();
}

// 计算相差天数
public long calTimeDiffInDays(LocalDate start, LocalDate end){
return end.toEpochDay() - start.toEpochDay();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.my.service;

public class SingleRoundRobinArrangement extends GameArrangement {
// Add new methods specific to single round robin arrangement


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.my.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.my.config.WechatConfig;
import com.my.domain.WeChatLoginData;
import com.my.domain.WeChatSessionData;
import net.lab1024.sa.common.common.domain.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Component
public class WechatService {

@Autowired
private RestTemplate restTemplate;
@Autowired
private WechatConfig wechatConfig;

public ResponseDTO<WeChatSessionData> login(WeChatLoginData loginData) throws JsonProcessingException {
// 向微信后台发起校验请求
String loginUrl = wechatConfig.getCode2SessionUrl();
String appid=wechatConfig.getAppId();
String appSecret= wechatConfig.getAppSecret();
loginUrl=loginUrl+"?appid={appid}}&secret={secret}&js_code={code}&grant_type={grant_type}}";
Map<String, String> requestUrlParam = new HashMap<>();
// 小程序appId,自己补充
requestUrlParam.put("appid", wechatConfig.getAppId());
// 小程序secret,自己补充
requestUrlParam.put("secret", wechatConfig.getAppSecret());
// 小程序端返回的code
requestUrlParam.put("js_code", loginData.getCode());
// 默认参数
requestUrlParam.put("grant_type", "authorization_code");

WeChatSessionData sessionData = restTemplate.getForObject(loginUrl, WeChatSessionData.class, requestUrlParam);
/*
* 查找用户是否存在,不存在则存入
* 存在则返回用户信息
* */


return ResponseDTO.ok(sessionData);
}

}
Loading