[后端] 添加OpenFeign RPC框架;添加access微服务项目;添加进出码接口;添加postman-collection JSON
This commit is contained in:
parent
eaecc486df
commit
941ba4f306
8
TODOs.md
8
TODOs.md
@ -1 +1,7 @@
|
||||
用户登录接口 后端返回结构有变动,小程序需要同步修改
|
||||
体温填报接口:
|
||||
今日是否填报过,上报体温,上报的体温的历史记录
|
||||
|
||||
更多:
|
||||
完成项目代码中的 TODO 部分
|
||||
用户登录接口 后端返回结构有变动,小程序需要同步修改
|
||||
身份码后端接口考虑与其他系统的集成逻辑
|
2
backend/.idea/encodings.xml
generated
2
backend/.idea/encodings.xml
generated
@ -5,6 +5,8 @@
|
||||
<file url="file://$PROJECT_DIR$/microservice-common/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/microservice-gateway/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/microservice-gateway/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/microservice-provider-access-8002/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/microservice-provider-access-8002/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/microservice-provider-miniprogram-8080/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/microservice-provider-miniprogram-8080/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/microservice-provider-test-8011/src/main/java" charset="UTF-8" />
|
||||
|
1
backend/.idea/misc.xml
generated
1
backend/.idea/misc.xml
generated
@ -7,6 +7,7 @@
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/microservice-api/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/microservice-common/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/microservice-provider-access-8002/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
|
10
backend/.idea/runConfigurations/AccessProvider.xml
generated
Normal file
10
backend/.idea/runConfigurations/AccessProvider.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="AccessProvider" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
|
||||
<option name="ACTIVE_PROFILES" />
|
||||
<module name="microservice-provider-access-8002" />
|
||||
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.access.AccessProvider" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
10
backend/.idea/runConfigurations/UserProvider.xml
generated
Normal file
10
backend/.idea/runConfigurations/UserProvider.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="UserProvider" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
|
||||
<option name="ACTIVE_PROFILES" />
|
||||
<module name="microservice-provider-user-8001" />
|
||||
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.user.UserProvider" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
@ -20,6 +20,11 @@ spring:
|
||||
predicates:
|
||||
- Path=/user/**
|
||||
- Method=GET,POST
|
||||
- id: access
|
||||
uri: lb://microservice-provider-access
|
||||
predicates:
|
||||
- Path=/access/**
|
||||
- Method=GET,POST
|
||||
|
||||
- id: test1
|
||||
uri: lb://microservice-provider-test
|
||||
|
114
backend/microservice-provider-access-8002/pom.xml
Normal file
114
backend/microservice-provider-access-8002/pom.xml
Normal file
@ -0,0 +1,114 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>epp</artifactId>
|
||||
<groupId>com.cxyxiaomo</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>microservice-provider-access</artifactId>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 实体类 -->
|
||||
<dependency>
|
||||
<groupId>com.cxyxiaomo</groupId>
|
||||
<artifactId>microservice-common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- mybatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- mysql -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
</dependency>
|
||||
<!-- logback -->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- OpenFeign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.7.5</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,17 @@
|
||||
package com.cxyxiaomo.epp.access;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
// 启动类
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class AccessProvider {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AccessProvider.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.cxyxiaomo.epp.access.controller;
|
||||
|
||||
import com.cxyxiaomo.epp.common.pojo.User;
|
||||
import com.cxyxiaomo.epp.common.response.Res;
|
||||
import com.cxyxiaomo.epp.access.rpc.UserServiceFeign;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/access")
|
||||
public class CodeController {
|
||||
|
||||
@Autowired
|
||||
private UserServiceFeign userService;
|
||||
|
||||
@PostMapping("/getCodeInfo")
|
||||
@ResponseBody
|
||||
public Res getCodeInfo(@RequestParam("id") Integer id) {
|
||||
User user = userService.getUserById(id);
|
||||
if (user == null) {
|
||||
return Res.error("用户不存在");
|
||||
}
|
||||
|
||||
// TODO 判断用户的健康状态(昨日是否体温打卡,管理员是否禁止该用户进出,用户所属楼栋是否允许出入等)
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
map.put("qrcodeColor", "green");
|
||||
map.put("infoText", "绿码 请通行");
|
||||
map.put("infoTextColor", "green");
|
||||
map.put("extra", user);
|
||||
return Res.success(map);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.cxyxiaomo.epp.access.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface AccessDao {
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.cxyxiaomo.epp.access.rpc;
|
||||
|
||||
import com.cxyxiaomo.epp.common.pojo.User;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@FeignClient("microservice-provider-user")
|
||||
public interface UserServiceFeign {
|
||||
/**
|
||||
* 返回值、参数要对应,方法名随意
|
||||
* 在 OpenFeign 中方法参数前如果没有注解,默认添加 @RequestBody 注解,最多只能存在一个不带注解的参数
|
||||
* 普通表单参数必须添加 @Requestparam 注解。如果变量名和参数名称对应可以不写name
|
||||
*/
|
||||
@PostMapping("/user/rpc/getUserById")
|
||||
User getUserById(@RequestParam("id") Integer id);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.cxyxiaomo.epp.access.service;
|
||||
|
||||
import com.cxyxiaomo.epp.common.pojo.User;
|
||||
|
||||
public interface AccessService {
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.cxyxiaomo.epp.access.service;
|
||||
|
||||
import com.cxyxiaomo.epp.common.pojo.User;
|
||||
import com.cxyxiaomo.epp.access.dao.AccessDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AccessServiceImpl implements AccessService {
|
||||
|
||||
@Autowired
|
||||
private AccessDao accessDao;
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://39.99.244.156:3306/epp?useUnicode=true&characterEncoding=utf8&useSSL=false
|
||||
username: root
|
||||
password: root
|
@ -0,0 +1,23 @@
|
||||
server:
|
||||
port: 8002
|
||||
|
||||
# Mybatis 配置
|
||||
mybatis:
|
||||
type-aliases-package: com.cxyxiaomo.epp.pojo
|
||||
config-location: classpath:mybatis/mybatis-config.xml
|
||||
mapper-locations: classpath:mybatis/mapper/*.xml
|
||||
|
||||
# Spring 配置
|
||||
spring:
|
||||
application:
|
||||
name: microservice-provider-access
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/epp?useUnicode=true&characterEncoding=utf8&useSSL=false
|
||||
username: root
|
||||
password: root
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cxyxiaomo.epp.access.dao.AccessDao">
|
||||
|
||||
</mapper>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE configuration
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
<settings>
|
||||
<!--开启二级缓存-->
|
||||
<setting name="cacheEnabled" value="true"/>
|
||||
</settings>
|
||||
</configuration>
|
@ -0,0 +1,20 @@
|
||||
package com.cxyxiaomo.epp.access;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
{
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@Test
|
||||
public void shouldAnswerWithTrue()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
@ -20,7 +20,13 @@ public class UserController {
|
||||
@Autowired
|
||||
private UserServiceImpl userService;
|
||||
|
||||
// @RequestMapping("/login")
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
@ResponseBody
|
||||
public Res login(@RequestParam("username") String username, @RequestParam("password") String password) {
|
||||
@ -39,6 +45,18 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户ID获取用户信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/rpc/getUserById")
|
||||
@ResponseBody
|
||||
public User getUserById(Long id) {
|
||||
return userService.getUserById(id);
|
||||
}
|
||||
|
||||
@RequestMapping("/person")
|
||||
@ResponseBody
|
||||
public User person(String username) {
|
||||
|
@ -5,4 +5,6 @@ import com.cxyxiaomo.epp.common.pojo.User;
|
||||
public interface UserService {
|
||||
|
||||
User getUserByUsername(String username);
|
||||
|
||||
User getUserById(Long id);
|
||||
}
|
||||
|
@ -15,4 +15,9 @@ public class UserServiceImpl implements UserService {
|
||||
public User getUserByUsername(String username) {
|
||||
return userDao.getUserByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserById(Long id) {
|
||||
return userDao.getUserById(id);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
<module>microservice-gateway</module>
|
||||
<module>microservice-common</module>
|
||||
<module>microservice-provider-user-8001</module>
|
||||
<module>microservice-provider-access-8002</module>
|
||||
<module>microservice-provider-miniprogram-8080</module>
|
||||
<module>microservice-provider-test-8011</module>
|
||||
</modules>
|
||||
@ -92,6 +93,13 @@
|
||||
<version>2021.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- OpenFeign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<version>3.1.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Database -->
|
||||
<!-- mysql -->
|
||||
<dependency>
|
||||
|
92
postman-collection/epp.postman_collection.json
Normal file
92
postman-collection/epp.postman_collection.json
Normal file
@ -0,0 +1,92 @@
|
||||
{
|
||||
"info": {
|
||||
"_postman_id": "0d464ada-cc15-4b2f-a0b7-5ee5fc690c39",
|
||||
"name": "epp",
|
||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||
},
|
||||
"item": [
|
||||
{
|
||||
"name": "用户登录 微服务域名",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "http://localhost:8001/user/login?username=root&password=63a9f0ea7bb98050796b649e85481845",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8001",
|
||||
"path": [
|
||||
"user",
|
||||
"login"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "username",
|
||||
"value": "root"
|
||||
},
|
||||
{
|
||||
"key": "password",
|
||||
"value": "63a9f0ea7bb98050796b649e85481845"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "获取用户进出码信息 微服务域名",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "http://localhost:8002/access/getCodeInfo?id=1",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8002",
|
||||
"path": [
|
||||
"access",
|
||||
"getCodeInfo"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "id",
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "获取用户进出码信息 线上域名",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "http://epp.only4.work/access/getCodeInfo?id=1",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"epp",
|
||||
"only4",
|
||||
"work"
|
||||
],
|
||||
"path": [
|
||||
"access",
|
||||
"getCodeInfo"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "id",
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user