Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
commit
1cf66e67ea
@ -1,22 +1,6 @@
|
||||
{
|
||||
"taskLocation": [
|
||||
"浙江横店",
|
||||
"陕西宝鸡",
|
||||
"甘肃兰州"
|
||||
],
|
||||
"aircraftName": [
|
||||
"载机名称一",
|
||||
"载机名称二",
|
||||
"载机名称三"
|
||||
],
|
||||
"sensorDescription": [
|
||||
"电阻式传感器",
|
||||
"电容式传感器"
|
||||
],
|
||||
"taskLabel": [
|
||||
"试验标签一",
|
||||
"试验标签二",
|
||||
"试验标签三",
|
||||
"试验标签四"
|
||||
]
|
||||
"taskLocation" : [ "浙江横店", "陕西宝鸡", "甘肃兰州", "标签1", "标签2", "标签3", "标签4" ],
|
||||
"aircraftName" : [ "载机名称一", "载机名称二", "载机名称三" ],
|
||||
"sensorDescription" : [ "电阻式传感器", "电容式传感器", "电容式传感器二" ],
|
||||
"taskLabel" : [ "试验标签一", "试验标签二", "试验标签三", "试验标签四", "试验标签五" ]
|
||||
}
|
||||
@ -3,7 +3,12 @@ package com.yfd.platform.modules.experimentalData.controller;
|
||||
import com.yfd.platform.modules.experimentalData.dto.ItemReq;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@ -55,6 +60,33 @@ public class CommonItemController {
|
||||
}
|
||||
}
|
||||
|
||||
/** 新增多个标签 */
|
||||
@PostMapping("/batch")
|
||||
public Map<String, Object> addBatch(@RequestBody ItemReq req) throws IOException {
|
||||
validateForBatch(req);
|
||||
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
Map<String, List<String>> data = readData();
|
||||
List<String> list = data.computeIfAbsent(req.getType(), k -> new ArrayList<>());
|
||||
|
||||
// 批量添加不重复的标签
|
||||
for (String label : req.getLabels()) {
|
||||
if (!list.contains(label)) {
|
||||
list.add(label);
|
||||
}
|
||||
}
|
||||
|
||||
writeData(data);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(req.getType(), list);
|
||||
return success(result);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
@DeleteMapping
|
||||
public Map<String, Object> delete(@RequestBody ItemReq req) throws IOException {
|
||||
@ -89,6 +121,15 @@ public class CommonItemController {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateForBatch(ItemReq req) {
|
||||
if (req == null
|
||||
|| (!"taskLocation".equals(req.getType()) && !"aircraftName".equals(req.getType())
|
||||
&& !"sensorDescription".equals(req.getType()) && !"taskLabel".equals(req.getType()))
|
||||
|| req.getLabels() == null || req.getLabels().isEmpty()) {
|
||||
throw new IllegalArgumentException("参数无效");
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, List<String>> readData() throws IOException {
|
||||
// 获取项目根目录下的data文件夹路径
|
||||
String userDir = System.getProperty("user.dir");
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.yfd.platform.modules.experimentalData.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemReq {
|
||||
|
||||
private String type; // treatment | suggestion
|
||||
private String label; // 内容
|
||||
private List<String> labels; // 多个标签
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
@ -21,5 +22,12 @@ public class ItemReq {
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public void setLabels(List<String> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user