# Staffs_StaffApi2
**Repository Path**: heptagram/StaffApi2
## Basic Information
- **Project Name**: Staffs_StaffApi2
- **Description**: staff 项目的 api 微服务应用
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: develop
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2019-07-18
- **Last Updated**: 2021-04-08
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# StaffApi项目简介
此项目为员工系统`Staff`的接口项目, 提供员工的查询、认证等功能。
此项目为老接口[StaffApi](https://gitlab.ops.heptagram.tech/DevOps/BootStrap/Staffs/StaffApi)的重构版本, 新的系统请使用新项目, 之前的项目作废。
## 项目说明
* `staff-api`: `staff-api`为操作及数据契约工具包, 里面包含了`staff`的接口定义和数据定义;
* `staff-api-web`: 提供`rest api`访问的`web`项目;
* `staff-api-tools`: 封装了`rest api`的 `jdk`工具包;
* `staff-api-spring-boot-starter`: `staff-api` spring boot starter, 做了一些自动化的流入工作。
## staff-api-web 地址
### 开发环境
* url: https://staffapi.dev.intranet.heptagram.tech
* swagger-ui: https://staffapi.dev.intranet.heptagram.tech/swagger-ui.html
* check-url: https://staffapi.dev.intranet.heptagram.tech/health
### 生产环境
* url: https://staffapi.7mxing.com
* 容器内url: http://staff-api2.pro-service-intranet
* check-url: https://staffapi.7mxing.com/health
> 建议使用容器内地址, 速度会比较快
## 使用说明
有三种方式可以使用`staff-api`接口, 分别如下:
### 1. 在项目中调用`staff-api`的rest接口
和调用其他第三方接口一样, 自己在项目中调用`staff-api` rest api接口, 接口地址见上面所述, 接口内容见 [swagger-ui](https://staffapi.dev.intranet.heptagram.tech/swagger-ui.html)
### 2. 使用`staff-api-tools` jdk包
1. 在项目的`pom`文件中引用已封装好的`staff-api-tools`工具包:
```xml
tech.heptagram.staff
staff-api-tools
1.0.0-SNAPSHOT
```
2. 自己配置`StaffV3Service` `Bean`
```java
@Configuration
public class StaffConfig {
@Value("${staff.api.domain}")
private String staffApiDomain;
@Bean
@ConditionalOnMissingBean
public StaffService staffService(RestTemplate restTemplate) {
StaffServiceRestTemplateImpl staffServiceRestTemplate = new StaffServiceRestTemplateImpl(staffApiDomain, restTemplate);
return staffServiceRestTemplate;
}
}
```
> 注: 1. `application.yaml配置文件中需要有staff.api.domain`的配置项, 用于配置`staff-api`地址。2. 项目中须已存在`restTemplate` bean, 否则会报错。
3. 现在可以在项目中使用`staffService`进行接口调用了。
```java
@Service
@Slf4j
public class StaffGet {
@Resource
private StaffService staffService;
public Staff getStaff() {
StaffQuery staffQuery = StaffQueryBuilder.builder().staffName("wangyuchuan").build();
Staff staff = staffService.getStaff(staffQuery);
log.info(" get staff: {}", staff);
return staff;
}
}
```
### 3. 使用`staff-api-spring-boot-starter`
这是使用`staff-api`的正确姿势, 强烈推荐!
只需要在项目的`pom`文件中添加引用:
```xml
tech.heptagram.staff
staff-api-spring-boot-starter
1.0.0-SNAPSHOT
```
就可以在任何地方注入`staffService`了:
```java
@Resource
private StaffService staffService;
```
## 关于缓存
项目中查询`staff`的部分内容使用了redis缓存, 缓存过期时间为5分钟。
如果你有需要立即清除缓存的话, 请使用缓存处理相关`api`:
* `/api/v3/cache/redis/keys`: 查询当前缓存里有哪些`key`
* `/api/v3/cache/redis/get/{key}`: 根据指定`key`获取其缓存内容
* `/api/v3/cache/redis/del/{key}`: 清除指定`key`的缓存
* `/api/v3/cache/redis/delall/{prefix}`: 清除指定字符串开头的`key`s