mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
添加登录注册接口
This commit is contained in:
parent
dec260c10f
commit
cabdbc6fb8
@ -26,6 +26,22 @@
|
|||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
<version>8.0.30</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package cn.jisol.game;
|
package cn.jisol.game;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
|
|
||||||
|
@MapperScan(basePackages = "cn.jisol.game.mapper")
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class JGameApplication {
|
public class JGameApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
package cn.jisol.game.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import cn.jisol.game.entity.User;
|
||||||
|
import cn.jisol.game.service.UserService;
|
||||||
|
import cn.jisol.game.service.impl.UserServiceImpl;
|
||||||
|
import cn.jisol.ngame.util.NewsContext;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家 API
|
||||||
|
*/
|
||||||
|
@Api(value = "JNGameDemo - API", tags = {"PET - API"})
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
@ResponseBody
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserServiceImpl userService;
|
||||||
|
|
||||||
|
//注册账户接口
|
||||||
|
@ApiImplicitParams({})
|
||||||
|
@ApiOperation(value = "注册账号")
|
||||||
|
@PostMapping("/register")
|
||||||
|
public NewsContext<User> register(){
|
||||||
|
User user = User.builder().userPass(RandomUtil.randomString(8)).userName("玩家名称").build();
|
||||||
|
this.userService.save(user);
|
||||||
|
return NewsContext.onSuccess("保存成功",user);
|
||||||
|
}
|
||||||
|
|
||||||
|
//登录账户
|
||||||
|
@ApiImplicitParams({})
|
||||||
|
@ApiOperation(value = "登录账号")
|
||||||
|
@PostMapping("/login")
|
||||||
|
public NewsContext<User> login(@RequestBody User user){
|
||||||
|
if(Objects.isNull(user.getUserId()) || Objects.isNull(user.getUserPass())){
|
||||||
|
return NewsContext.onFail("登录失败");
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<User> query = Wrappers.lambdaQuery();
|
||||||
|
query.eq(User::getUserId,user.getUserId());
|
||||||
|
query.eq(User::getUserPass,user.getUserPass());
|
||||||
|
if(Objects.nonNull(user = userService.getOne(query))){
|
||||||
|
return NewsContext.onSuccess("登录成功",user);
|
||||||
|
}else{
|
||||||
|
return NewsContext.onFail("登录失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package cn.jisol.game.data;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存数据 小游戏直接用内存存
|
||||||
|
*/
|
||||||
|
public class Cache {
|
||||||
|
|
||||||
|
public static Map<String,Object> DATA = new HashMap<>();
|
||||||
|
|
||||||
|
//存储数据
|
||||||
|
public void addData(String key,Object data){
|
||||||
|
DATA.put(key,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
//读取数据
|
||||||
|
public Object getData(String key){
|
||||||
|
return DATA.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除数据
|
||||||
|
public void delData(String key){
|
||||||
|
DATA.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package cn.jisol.game.data;
|
||||||
|
|
||||||
|
import cfg.Tables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置表数据
|
||||||
|
*/
|
||||||
|
public class TD {
|
||||||
|
public static Tables DATA = null;
|
||||||
|
public static Tables get(){
|
||||||
|
return TD.DATA;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package cn.jisol.game.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Data
|
||||||
|
@TableName("`user`")
|
||||||
|
public class User {
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long userId; //玩家Id
|
||||||
|
private String userPass; //玩家密码
|
||||||
|
private String userName; //玩家名称
|
||||||
|
}
|
@ -1,4 +0,0 @@
|
|||||||
package cn.jisol.game.json;
|
|
||||||
|
|
||||||
public class GRole {
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
package cn.jisol.game.listener;
|
package cn.jisol.game.listener;
|
||||||
|
|
||||||
import cfg.Tables;
|
import cfg.Tables;
|
||||||
|
import cn.jisol.game.data.TD;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import org.springframework.context.event.ContextRefreshedEvent;
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
@ -17,10 +18,12 @@ public class InitGameListener {
|
|||||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Tables tables = new Tables(file -> JsonParser.parseReader(
|
TD.DATA = new Tables(file -> {
|
||||||
new FileReader(ResourceUtils.getFile("classpath:json/"+file+".json"))
|
System.out.println("加载配置表:"+file);
|
||||||
));
|
return JsonParser.parseReader(
|
||||||
System.out.println(tables.getTbGame().get(10000).name);
|
new FileReader(ResourceUtils.getFile("classpath:json/"+file+".json"))
|
||||||
|
);
|
||||||
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package cn.jisol.game.mapper;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.User;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package cn.jisol.game.service;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.User;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
public interface UserService extends IService<User> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package cn.jisol.game.service.impl;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.User;
|
||||||
|
import cn.jisol.game.mapper.UserMapper;
|
||||||
|
import cn.jisol.game.service.UserService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package cn.jisol.game.swagger;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableSwagger2WebMvc
|
||||||
|
public class Swagger {
|
||||||
|
|
||||||
|
@Bean(value = "defaultApi")
|
||||||
|
public Docket defaultApi() {
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.apiInfo(apiInfo())
|
||||||
|
//分组名称
|
||||||
|
.groupName("Game Open")
|
||||||
|
.select()
|
||||||
|
//这里指定Controller扫描包路径
|
||||||
|
// .apis(RequestHandlerSelectors.basePackage("com.github.xiaoymin.knife4j.controller"))
|
||||||
|
//这里指定扫描有ApiOperation注解的类
|
||||||
|
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
||||||
|
//所有路径
|
||||||
|
.paths(PathSelectors.any())
|
||||||
|
//不包含^/inner/.*的路径
|
||||||
|
//.paths(input -> !input.matches("^/inner/.*"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiInfo apiInfo() {
|
||||||
|
return new ApiInfoBuilder()
|
||||||
|
.title("Game Open APIs")
|
||||||
|
.description("Game Open APIs")
|
||||||
|
.version("1.0")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
12
JisolGameServer/Main/src/main/resources/application.yml
Normal file
12
JisolGameServer/Main/src/main/resources/application.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
username: pet_jisol_cn
|
||||||
|
password: sThsBwjfDcaw2wJR
|
||||||
|
url: jdbc:mysql://kyu.jisol.cn:3306/pet_jisol_cn?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
|
||||||
|
mybatis-plus:
|
||||||
|
configuration:
|
||||||
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
Loading…
x
Reference in New Issue
Block a user