新增配置中心
This commit is contained in:
34
build.gradle
34
build.gradle
@@ -24,23 +24,23 @@ dependencyManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
|
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' // Spring Data JDBC
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
|
implementation 'org.springframework.boot:spring-boot-starter-data-redis' // Redis 缓存
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
|
implementation 'org.springframework.boot:spring-boot-starter-jdbc' // JDBC 支持
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web' // Web MVC
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
implementation 'org.springframework.boot:spring-boot-starter-validation' // 参数校验
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-mail'
|
implementation 'org.springframework.boot:spring-boot-starter-mail' // 邮件发送
|
||||||
implementation 'com.baomidou:mybatis-plus-boot-starter'
|
implementation 'com.baomidou:mybatis-plus-boot-starter' // MyBatis Plus
|
||||||
implementation 'com.baomidou:mybatis-plus-generator'
|
implementation 'com.baomidou:mybatis-plus-generator' // 代码生成器
|
||||||
implementation("com.baomidou:mybatis-plus-jsqlparser")
|
implementation("com.baomidou:mybatis-plus-jsqlparser") // SQL 解析器
|
||||||
implementation 'cn.dev33:sa-token-spring-boot-starter:1.44.0'
|
implementation 'cn.dev33:sa-token-spring-boot-starter:1.44.0' // 权限认证
|
||||||
implementation 'com.alibaba:druid-spring-boot-starter:1.2.27'
|
implementation 'com.alibaba:druid-spring-boot-starter:1.2.27' // 数据库连接池
|
||||||
implementation 'org.lionsoul:ip2region:2.7.0'
|
implementation 'org.lionsoul:ip2region:2.7.0' // IP 归属地
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok' // Lombok
|
||||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
developmentOnly 'org.springframework.boot:spring-boot-devtools' // 热重载
|
||||||
runtimeOnly 'com.mysql:mysql-connector-j'
|
runtimeOnly 'com.mysql:mysql-connector-j' // MySQL 驱动
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
annotationProcessor 'org.projectlombok:lombok' // Lombok 注解处理
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test' // 测试框架
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
|
|||||||
383
docs/API接口说明-参数配置中心.md
Normal file
383
docs/API接口说明-参数配置中心.md
Normal file
@@ -0,0 +1,383 @@
|
|||||||
|
# API 接口说明 - 参数配置中心
|
||||||
|
|
||||||
|
## 参数配置中心相关接口
|
||||||
|
|
||||||
|
### 1. 创建参数配置
|
||||||
|
|
||||||
|
**接口地址:** `POST /params`
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
```
|
||||||
|
Authorization: your-token(必填)
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求参数:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"paramName": "默认参数配置", // 参数名称(必填)
|
||||||
|
"fcModel": "Pixhawk 4", // 飞控型号(必填)
|
||||||
|
"fcType": "PX4", // 飞控类型(必填)
|
||||||
|
"paramVersion": "1.0.0", // 参数版本(必填)
|
||||||
|
"paramDetail": "参数详细配置内容..." // 参数详情(可选)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "参数创建成功",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2. 更新参数配置
|
||||||
|
|
||||||
|
**接口地址:** `PUT /params`
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
```
|
||||||
|
Authorization: your-token(必填)
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求参数:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": 1, // 参数ID(必填)
|
||||||
|
"paramName": "更新后的参数配置", // 参数名称(必填)
|
||||||
|
"fcModel": "Pixhawk 6X", // 飞控型号(必填)
|
||||||
|
"fcType": "PX4", // 飞控类型(必填)
|
||||||
|
"paramVersion": "1.0.1", // 参数版本(必填)
|
||||||
|
"paramDetail": "更新后的参数详情..." // 参数详情(可选)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "参数更新成功",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明:**
|
||||||
|
- 只能更新自己创建的参数配置
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. 删除参数配置
|
||||||
|
|
||||||
|
**接口地址:** `DELETE /params/{id}`
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
```
|
||||||
|
Authorization: your-token(必填)
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "参数删除成功",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明:**
|
||||||
|
- 只能删除自己创建的参数配置
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. 根据ID查询参数配置
|
||||||
|
|
||||||
|
**接口地址:** `GET /params/{id}`
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
```
|
||||||
|
Authorization: your-token(必填)
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "success",
|
||||||
|
"data": {
|
||||||
|
"id": 1,
|
||||||
|
"userId": 1,
|
||||||
|
"paramName": "默认参数配置",
|
||||||
|
"fcModel": "Pixhawk 4",
|
||||||
|
"fcType": "PX4",
|
||||||
|
"paramVersion": "1.0.0",
|
||||||
|
"paramDetail": "参数详细配置内容...",
|
||||||
|
"downloadCount": 10,
|
||||||
|
"createTime": "2025-01-01T12:00:00",
|
||||||
|
"updateTime": "2025-01-01T12:00:00"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明:**
|
||||||
|
- 只能查询自己创建的参数配置
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 5. 查询所有参数列表(公开)
|
||||||
|
|
||||||
|
**接口地址:** `GET /params/all/list`
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
```
|
||||||
|
无需认证
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求参数:**
|
||||||
|
```
|
||||||
|
fcModel: 飞控型号(可选,用于筛选)
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求示例:**
|
||||||
|
```
|
||||||
|
GET /params/all/list
|
||||||
|
GET /params/all/list?fcModel=Pixhawk%204
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "success",
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"userId": 1,
|
||||||
|
"paramName": "默认参数配置",
|
||||||
|
"fcModel": "Pixhawk 4",
|
||||||
|
"fcType": "PX4",
|
||||||
|
"paramVersion": "1.0.0",
|
||||||
|
"paramDetail": "参数详细配置内容...",
|
||||||
|
"downloadCount": 10,
|
||||||
|
"createTime": "2025-01-01T12:00:00",
|
||||||
|
"updateTime": "2025-01-01T12:00:00"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明:**
|
||||||
|
- 返回所有用户创建的参数配置
|
||||||
|
- 支持按飞控型号过滤
|
||||||
|
- 按更新时间倒序排序
|
||||||
|
- 不需要登录
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 6. 分页查询所有参数列表(公开)
|
||||||
|
|
||||||
|
**接口地址:** `GET /params/all/page`
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
```
|
||||||
|
无需认证
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求参数:**
|
||||||
|
```
|
||||||
|
current: 当前页码(默认1)
|
||||||
|
size: 每页数量(默认10)
|
||||||
|
fcModel: 飞控型号(可选,用于筛选)
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求示例:**
|
||||||
|
```
|
||||||
|
GET /params/all/page?current=1&size=10
|
||||||
|
GET /params/all/page?current=1&size=10&fcModel=Pixhawk%204
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "success",
|
||||||
|
"data": {
|
||||||
|
"records": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"userId": 1,
|
||||||
|
"paramName": "默认参数配置",
|
||||||
|
"fcModel": "Pixhawk 4",
|
||||||
|
"fcType": "PX4",
|
||||||
|
"paramVersion": "1.0.0",
|
||||||
|
"paramDetail": "参数详细配置内容...",
|
||||||
|
"downloadCount": 10,
|
||||||
|
"createTime": "2025-01-01T12:00:00",
|
||||||
|
"updateTime": "2025-01-01T12:00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"total": 50,
|
||||||
|
"size": 10,
|
||||||
|
"current": 1,
|
||||||
|
"pages": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明:**
|
||||||
|
- 返回所有用户创建的参数配置
|
||||||
|
- 支持分页和飞控型号过滤
|
||||||
|
- 按更新时间倒序排序
|
||||||
|
- 不需要登录
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 7. 查询我的参数列表
|
||||||
|
|
||||||
|
**接口地址:** `GET /params/my/list`
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
```
|
||||||
|
Authorization: your-token(必填)
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求参数:**
|
||||||
|
```
|
||||||
|
fcModel: 飞控型号(可选,用于筛选)
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求示例:**
|
||||||
|
```
|
||||||
|
GET /params/my/list
|
||||||
|
GET /params/my/list?fcModel=Pixhawk%204
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "success",
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"userId": 1,
|
||||||
|
"paramName": "默认参数配置",
|
||||||
|
"fcModel": "Pixhawk 4",
|
||||||
|
"fcType": "PX4",
|
||||||
|
"paramVersion": "1.0.0",
|
||||||
|
"paramDetail": "参数详细配置内容...",
|
||||||
|
"downloadCount": 10,
|
||||||
|
"createTime": "2025-01-01T12:00:00",
|
||||||
|
"updateTime": "2025-01-01T12:00:00"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明:**
|
||||||
|
- 返回当前用户创建的所有参数配置
|
||||||
|
- 支持按飞控型号过滤
|
||||||
|
- 按更新时间倒序排序
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 8. 分页查询我的参数列表
|
||||||
|
|
||||||
|
**接口地址:** `GET /params/my/page`
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
```
|
||||||
|
Authorization: your-token(必填)
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求参数:**
|
||||||
|
```
|
||||||
|
current: 当前页码(默认1)
|
||||||
|
size: 每页数量(默认10)
|
||||||
|
fcModel: 飞控型号(可选,用于筛选)
|
||||||
|
```
|
||||||
|
|
||||||
|
**请求示例:**
|
||||||
|
```
|
||||||
|
GET /params/my/page?current=1&size=10
|
||||||
|
GET /params/my/page?current=1&size=10&fcModel=Pixhawk%204
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "success",
|
||||||
|
"data": {
|
||||||
|
"records": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"userId": 1,
|
||||||
|
"paramName": "默认参数配置",
|
||||||
|
"fcModel": "Pixhawk 4",
|
||||||
|
"fcType": "PX4",
|
||||||
|
"paramVersion": "1.0.0",
|
||||||
|
"paramDetail": "参数详细配置内容...",
|
||||||
|
"downloadCount": 10,
|
||||||
|
"createTime": "2025-01-01T12:00:00",
|
||||||
|
"updateTime": "2025-01-01T12:00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"total": 50,
|
||||||
|
"size": 10,
|
||||||
|
"current": 1,
|
||||||
|
"pages": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明:**
|
||||||
|
- 返回当前用户创建的参数配置
|
||||||
|
- 支持分页和飞控型号过滤
|
||||||
|
- 按更新时间倒序排序
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 9. 下载
|
||||||
|
|
||||||
|
**接口地址:** `POST /params/{id}/download`
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
```
|
||||||
|
无需认证
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "下载成功",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 错误码说明
|
||||||
|
|
||||||
|
| 错误码 | 说明 |
|
||||||
|
|--------|------|
|
||||||
|
| 200 | 成功 |
|
||||||
|
| 500 | 失败 |
|
||||||
|
|
||||||
|
**常见错误消息:**
|
||||||
|
|
||||||
|
| 消息 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| 参数创建成功 | 创建参数配置成功 |
|
||||||
|
| 参数创建失败 | 创建参数配置失败 |
|
||||||
|
| 参数更新成功 | 更新参数配置成功 |
|
||||||
|
| 参数更新失败 | 更新参数配置失败 |
|
||||||
|
| 参数删除成功 | 删除参数配置成功 |
|
||||||
|
| 参数删除失败 | 删除参数配置失败 |
|
||||||
|
| 参数不存在 | 根据ID未找到参数配置 |
|
||||||
|
| 无权限操作该参数 | 只能操作自己创建的参数配置 |
|
||||||
|
| 下载成功 | 下载次数增加成功 |
|
||||||
|
| 下载失败 | 下载次数增加失败 |
|
||||||
@@ -0,0 +1,228 @@
|
|||||||
|
package com.corewing.app.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.corewing.app.common.Result;
|
||||||
|
import com.corewing.app.dto.CreateParamRequest;
|
||||||
|
import com.corewing.app.dto.UpdateParamRequest;
|
||||||
|
import com.corewing.app.entity.AppParamsCenter;
|
||||||
|
import com.corewing.app.service.AppParamsCenterService;
|
||||||
|
import com.corewing.app.util.I18nUtil;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数配置中心 Controller
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/params")
|
||||||
|
public class AppParamsCenterController {
|
||||||
|
|
||||||
|
private final AppParamsCenterService paramsService;
|
||||||
|
|
||||||
|
public AppParamsCenterController(AppParamsCenterService paramsService) {
|
||||||
|
this.paramsService = paramsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建参数配置
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public Result<String> create(@Valid @RequestBody CreateParamRequest request) {
|
||||||
|
try {
|
||||||
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
|
|
||||||
|
AppParamsCenter params = new AppParamsCenter();
|
||||||
|
params.setUserId(userId);
|
||||||
|
params.setParamName(request.getParamName());
|
||||||
|
params.setFcModel(request.getFcModel());
|
||||||
|
params.setFcType(request.getFcType());
|
||||||
|
params.setParamVersion(request.getParamVersion());
|
||||||
|
params.setParamDetail(request.getParamDetail());
|
||||||
|
params.setDownloadCount(0); // 初始化下载次数为0
|
||||||
|
|
||||||
|
boolean success = paramsService.save(params);
|
||||||
|
if (success) {
|
||||||
|
return Result.success(I18nUtil.getMessage("params.create.success"));
|
||||||
|
}
|
||||||
|
return Result.error(I18nUtil.getMessage("params.create.failed"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新参数配置
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
public Result<String> update(@Valid @RequestBody UpdateParamRequest request) {
|
||||||
|
try {
|
||||||
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
|
|
||||||
|
// 先查询参数是否存在且属于当前用户
|
||||||
|
AppParamsCenter existingParam = paramsService.getById(request.getId());
|
||||||
|
if (existingParam == null) {
|
||||||
|
return Result.error(I18nUtil.getMessage("params.not.found"));
|
||||||
|
}
|
||||||
|
if (!existingParam.getUserId().equals(userId)) {
|
||||||
|
return Result.error(I18nUtil.getMessage("params.no.permission"));
|
||||||
|
}
|
||||||
|
|
||||||
|
AppParamsCenter params = new AppParamsCenter();
|
||||||
|
params.setId(request.getId());
|
||||||
|
params.setParamName(request.getParamName());
|
||||||
|
params.setFcModel(request.getFcModel());
|
||||||
|
params.setFcType(request.getFcType());
|
||||||
|
params.setParamVersion(request.getParamVersion());
|
||||||
|
params.setParamDetail(request.getParamDetail());
|
||||||
|
|
||||||
|
boolean success = paramsService.updateById(params);
|
||||||
|
if (success) {
|
||||||
|
return Result.success(I18nUtil.getMessage("params.update.success"));
|
||||||
|
}
|
||||||
|
return Result.error(I18nUtil.getMessage("params.update.failed"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除参数配置
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public Result<String> delete(@PathVariable Long id) {
|
||||||
|
try {
|
||||||
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
|
|
||||||
|
// 先查询参数是否存在且属于当前用户
|
||||||
|
AppParamsCenter existingParam = paramsService.getById(id);
|
||||||
|
if (existingParam == null) {
|
||||||
|
return Result.error(I18nUtil.getMessage("params.not.found"));
|
||||||
|
}
|
||||||
|
if (!existingParam.getUserId().equals(userId)) {
|
||||||
|
return Result.error(I18nUtil.getMessage("params.no.permission"));
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean success = paramsService.removeById(id);
|
||||||
|
if (success) {
|
||||||
|
return Result.success(I18nUtil.getMessage("params.delete.success"));
|
||||||
|
}
|
||||||
|
return Result.error(I18nUtil.getMessage("params.delete.failed"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询参数配置
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Result<AppParamsCenter> getById(@PathVariable Long id) {
|
||||||
|
try {
|
||||||
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
|
|
||||||
|
AppParamsCenter params = paramsService.getById(id);
|
||||||
|
if (params == null) {
|
||||||
|
return Result.error(I18nUtil.getMessage("params.not.found"));
|
||||||
|
}
|
||||||
|
if (!params.getUserId().equals(userId)) {
|
||||||
|
return Result.error(I18nUtil.getMessage("params.no.permission"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.success(params);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有参数列表(公开接口,支持飞控型号过滤)
|
||||||
|
*/
|
||||||
|
@GetMapping("/all/list")
|
||||||
|
public Result<List<AppParamsCenter>> listAll(@RequestParam(required = false) String fcModel) {
|
||||||
|
try {
|
||||||
|
List<AppParamsCenter> list = paramsService.listAllByFcModel(fcModel);
|
||||||
|
return Result.success(list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当前用户的参数列表(支持飞控型号过滤)
|
||||||
|
*/
|
||||||
|
@GetMapping("/my/list")
|
||||||
|
public Result<List<AppParamsCenter>> listMy(@RequestParam(required = false) String fcModel) {
|
||||||
|
try {
|
||||||
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
|
List<AppParamsCenter> list = paramsService.listByUserIdAndFcModel(userId, fcModel);
|
||||||
|
return Result.success(list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询所有参数列表(公开接口,支持飞控型号过滤)
|
||||||
|
*/
|
||||||
|
@GetMapping("/all/page")
|
||||||
|
public Result<IPage<AppParamsCenter>> pageAll(
|
||||||
|
@RequestParam(defaultValue = "1") Long current,
|
||||||
|
@RequestParam(defaultValue = "10") Long size,
|
||||||
|
@RequestParam(required = false) String fcModel) {
|
||||||
|
try {
|
||||||
|
Page<AppParamsCenter> page = new Page<>(current, size);
|
||||||
|
IPage<AppParamsCenter> result = paramsService.pageAllByFcModel(fcModel, page);
|
||||||
|
return Result.success(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询当前用户的参数列表(支持飞控型号过滤)
|
||||||
|
*/
|
||||||
|
@GetMapping("/my/page")
|
||||||
|
public Result<IPage<AppParamsCenter>> pageMy(
|
||||||
|
@RequestParam(defaultValue = "1") Long current,
|
||||||
|
@RequestParam(defaultValue = "10") Long size,
|
||||||
|
@RequestParam(required = false) String fcModel) {
|
||||||
|
try {
|
||||||
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
|
Page<AppParamsCenter> page = new Page<>(current, size);
|
||||||
|
IPage<AppParamsCenter> result = paramsService.pageByUserIdAndFcModel(userId, fcModel, page);
|
||||||
|
return Result.success(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加下载次数
|
||||||
|
*/
|
||||||
|
@PostMapping("/{id}/download")
|
||||||
|
public Result<String> incrementDownloadCount(@PathVariable Long id) {
|
||||||
|
try {
|
||||||
|
AppParamsCenter params = paramsService.getById(id);
|
||||||
|
if (params == null) {
|
||||||
|
return Result.error(I18nUtil.getMessage("params.not.found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增加下载次数
|
||||||
|
AppParamsCenter updateParams = new AppParamsCenter();
|
||||||
|
updateParams.setId(id);
|
||||||
|
updateParams.setDownloadCount(params.getDownloadCount() + 1);
|
||||||
|
|
||||||
|
boolean success = paramsService.updateById(updateParams);
|
||||||
|
if (success) {
|
||||||
|
return Result.success(I18nUtil.getMessage("params.download.success"));
|
||||||
|
}
|
||||||
|
return Result.error(I18nUtil.getMessage("params.download.failed"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
41
src/main/java/com/corewing/app/dto/CreateParamRequest.java
Normal file
41
src/main/java/com/corewing/app/dto/CreateParamRequest.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package com.corewing.app.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建参数配置请求
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CreateParamRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "参数名称不能为空")
|
||||||
|
private String paramName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞控型号
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "飞控型号不能为空")
|
||||||
|
private String fcModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞控类型
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "飞控类型不能为空")
|
||||||
|
private String fcType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数版本
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "参数版本不能为空")
|
||||||
|
private String paramVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数详情
|
||||||
|
*/
|
||||||
|
private String paramDetail;
|
||||||
|
}
|
||||||
48
src/main/java/com/corewing/app/dto/UpdateParamRequest.java
Normal file
48
src/main/java/com/corewing/app/dto/UpdateParamRequest.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package com.corewing.app.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新参数配置请求
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UpdateParamRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "参数ID不能为空")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "参数名称不能为空")
|
||||||
|
private String paramName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞控型号
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "飞控型号不能为空")
|
||||||
|
private String fcModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞控类型
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "飞控类型不能为空")
|
||||||
|
private String fcType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数版本
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "参数版本不能为空")
|
||||||
|
private String paramVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数详情
|
||||||
|
*/
|
||||||
|
private String paramDetail;
|
||||||
|
}
|
||||||
74
src/main/java/com/corewing/app/entity/AppParamsCenter.java
Normal file
74
src/main/java/com/corewing/app/entity/AppParamsCenter.java
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package com.corewing.app.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数配置中心实体类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("app_params_center")
|
||||||
|
public class AppParamsCenter implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数名称
|
||||||
|
*/
|
||||||
|
private String paramName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞控型号
|
||||||
|
*/
|
||||||
|
private String fcModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞控类型
|
||||||
|
*/
|
||||||
|
private String fcType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数版本
|
||||||
|
*/
|
||||||
|
private String paramVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数详情
|
||||||
|
*/
|
||||||
|
private String paramDetail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载次数
|
||||||
|
*/
|
||||||
|
private Integer downloadCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.corewing.app.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.corewing.app.entity.AppParamsCenter;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数配置中心 Mapper 接口
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface AppParamsCenterMapper extends BaseMapper<AppParamsCenter> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.corewing.app.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.corewing.app.entity.AppParamsCenter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数配置中心 Service 接口
|
||||||
|
*/
|
||||||
|
public interface AppParamsCenterService extends IService<AppParamsCenter> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID查询参数列表
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 参数列表
|
||||||
|
*/
|
||||||
|
List<AppParamsCenter> listByUserId(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID和飞控型号查询参数列表
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param fcModel 飞控型号
|
||||||
|
* @return 参数列表
|
||||||
|
*/
|
||||||
|
List<AppParamsCenter> listByUserIdAndFcModel(Long userId, String fcModel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询用户的参数列表
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param page 分页对象
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
IPage<AppParamsCenter> pageByUserId(Long userId, Page<AppParamsCenter> page);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询用户的参数列表(支持飞控型号过滤)
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param fcModel 飞控型号(可选)
|
||||||
|
* @param page 分页对象
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
IPage<AppParamsCenter> pageByUserIdAndFcModel(Long userId, String fcModel, Page<AppParamsCenter> page);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有参数列表
|
||||||
|
*
|
||||||
|
* @return 参数列表
|
||||||
|
*/
|
||||||
|
List<AppParamsCenter> listAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据飞控型号查询所有参数列表
|
||||||
|
*
|
||||||
|
* @param fcModel 飞控型号
|
||||||
|
* @return 参数列表
|
||||||
|
*/
|
||||||
|
List<AppParamsCenter> listAllByFcModel(String fcModel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询所有参数列表(支持飞控型号过滤)
|
||||||
|
*
|
||||||
|
* @param fcModel 飞控型号(可选)
|
||||||
|
* @param page 分页对象
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
IPage<AppParamsCenter> pageAllByFcModel(String fcModel, Page<AppParamsCenter> page);
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.corewing.app.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.corewing.app.entity.AppParamsCenter;
|
||||||
|
import com.corewing.app.mapper.AppParamsCenterMapper;
|
||||||
|
import com.corewing.app.service.AppParamsCenterService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数配置中心 Service 实现类
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class AppParamsCenterServiceImpl extends ServiceImpl<AppParamsCenterMapper, AppParamsCenter> implements AppParamsCenterService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AppParamsCenter> listByUserId(Long userId) {
|
||||||
|
LambdaQueryWrapper<AppParamsCenter> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(AppParamsCenter::getUserId, userId)
|
||||||
|
.orderByDesc(AppParamsCenter::getUpdateTime);
|
||||||
|
return this.list(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AppParamsCenter> listByUserIdAndFcModel(Long userId, String fcModel) {
|
||||||
|
LambdaQueryWrapper<AppParamsCenter> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(AppParamsCenter::getUserId, userId)
|
||||||
|
.eq(StringUtils.hasText(fcModel), AppParamsCenter::getFcModel, fcModel)
|
||||||
|
.orderByDesc(AppParamsCenter::getUpdateTime);
|
||||||
|
return this.list(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<AppParamsCenter> pageByUserId(Long userId, Page<AppParamsCenter> page) {
|
||||||
|
LambdaQueryWrapper<AppParamsCenter> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(AppParamsCenter::getUserId, userId)
|
||||||
|
.orderByDesc(AppParamsCenter::getUpdateTime);
|
||||||
|
return this.page(page, wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<AppParamsCenter> pageByUserIdAndFcModel(Long userId, String fcModel, Page<AppParamsCenter> page) {
|
||||||
|
LambdaQueryWrapper<AppParamsCenter> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(AppParamsCenter::getUserId, userId)
|
||||||
|
.eq(StringUtils.hasText(fcModel), AppParamsCenter::getFcModel, fcModel)
|
||||||
|
.orderByDesc(AppParamsCenter::getUpdateTime);
|
||||||
|
return this.page(page, wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AppParamsCenter> listAll() {
|
||||||
|
LambdaQueryWrapper<AppParamsCenter> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.orderByDesc(AppParamsCenter::getUpdateTime);
|
||||||
|
return this.list(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AppParamsCenter> listAllByFcModel(String fcModel) {
|
||||||
|
LambdaQueryWrapper<AppParamsCenter> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(StringUtils.hasText(fcModel), AppParamsCenter::getFcModel, fcModel)
|
||||||
|
.orderByDesc(AppParamsCenter::getUpdateTime);
|
||||||
|
return this.list(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<AppParamsCenter> pageAllByFcModel(String fcModel, Page<AppParamsCenter> page) {
|
||||||
|
LambdaQueryWrapper<AppParamsCenter> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(StringUtils.hasText(fcModel), AppParamsCenter::getFcModel, fcModel)
|
||||||
|
.orderByDesc(AppParamsCenter::getUpdateTime);
|
||||||
|
return this.page(page, wrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/main/resources/db/app_params_center.sql
Normal file
14
src/main/resources/db/app_params_center.sql
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
CREATE TABLE `app_params_center` (
|
||||||
|
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||||
|
`user_id` BIGINT NOT NULL COMMENT '用户ID',
|
||||||
|
`param_name` VARCHAR(100) NOT NULL COMMENT '参数名称',
|
||||||
|
`fc_model` VARCHAR(50) NOT NULL COMMENT '飞控型号',
|
||||||
|
`fc_type` VARCHAR(50) NOT NULL COMMENT '飞控类型',
|
||||||
|
`param_version` VARCHAR(20) NOT NULL COMMENT '参数版本',
|
||||||
|
`param_detail` TEXT COMMENT '参数详情',
|
||||||
|
`download_count` INT NOT NULL DEFAULT 0 COMMENT '下载次数',
|
||||||
|
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
INDEX `idx_user_id` (`user_id`) COMMENT '用户ID索引'
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='参数配置中心表';
|
||||||
@@ -116,3 +116,16 @@ dingtalk.send.message=Sending DingTalk message: {0}
|
|||||||
dingtalk.push.success=DingTalk message pushed successfully, response: {0}
|
dingtalk.push.success=DingTalk message pushed successfully, response: {0}
|
||||||
dingtalk.push.failed=DingTalk message push failed, HTTP status code: {0}, response: {1}
|
dingtalk.push.failed=DingTalk message push failed, HTTP status code: {0}, response: {1}
|
||||||
dingtalk.push.exception=DingTalk message push exception: {0}
|
dingtalk.push.exception=DingTalk message push exception: {0}
|
||||||
|
|
||||||
|
# ==================== Parameters Center Module ====================
|
||||||
|
# Parameters Center Controller
|
||||||
|
params.create.success=Parameter created successfully
|
||||||
|
params.create.failed=Failed to create parameter
|
||||||
|
params.update.success=Parameter updated successfully
|
||||||
|
params.update.failed=Failed to update parameter
|
||||||
|
params.delete.success=Parameter deleted successfully
|
||||||
|
params.delete.failed=Failed to delete parameter
|
||||||
|
params.not.found=Parameter not found
|
||||||
|
params.no.permission=No permission to operate this parameter
|
||||||
|
params.download.success=Download successful
|
||||||
|
params.download.failed=Download failed
|
||||||
|
|||||||
@@ -116,3 +116,16 @@ dingtalk.send.message=发送钉钉消息: {0}
|
|||||||
dingtalk.push.success=钉钉消息推送成功, 响应: {0}
|
dingtalk.push.success=钉钉消息推送成功, 响应: {0}
|
||||||
dingtalk.push.failed=钉钉消息推送失败, HTTP 状态码: {0}, 响应: {1}
|
dingtalk.push.failed=钉钉消息推送失败, HTTP 状态码: {0}, 响应: {1}
|
||||||
dingtalk.push.exception=钉钉消息推送异常: {0}
|
dingtalk.push.exception=钉钉消息推送异常: {0}
|
||||||
|
|
||||||
|
# ==================== 参数配置中心模块 ====================
|
||||||
|
# 参数配置Controller
|
||||||
|
params.create.success=参数创建成功
|
||||||
|
params.create.failed=参数创建失败
|
||||||
|
params.update.success=参数更新成功
|
||||||
|
params.update.failed=参数更新失败
|
||||||
|
params.delete.success=参数删除成功
|
||||||
|
params.delete.failed=参数删除失败
|
||||||
|
params.not.found=参数不存在
|
||||||
|
params.no.permission=无权限操作该参数
|
||||||
|
params.download.success=下载成功
|
||||||
|
params.download.failed=下载失败
|
||||||
|
|||||||
Reference in New Issue
Block a user