[后端] 添加OpenFeign RPC框架;添加access微服务项目;添加进出码接口;添加postman-collection JSON
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
Reference in New Issue
Block a user