1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

[后端] 添加OpenFeign RPC框架;添加access微服务项目;添加进出码接口;添加postman-collection JSON

This commit is contained in:
2022-11-27 21:01:38 +08:00
parent eaecc486df
commit 941ba4f306
23 changed files with 446 additions and 2 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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 {
}

View File

@@ -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);
}

View File

@@ -0,0 +1,7 @@
package com.cxyxiaomo.epp.access.service;
import com.cxyxiaomo.epp.common.pojo.User;
public interface AccessService {
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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>

View File

@@ -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>