|
@@ -1,26 +1,42 @@
|
|
|
package com.etotem.cfc.controller.admin;
|
|
package com.etotem.cfc.controller.admin;
|
|
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.etotem.cfc.common.Result;
|
|
import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.entity.FileRecord;
|
|
import com.etotem.cfc.entity.FileRecord;
|
|
|
import com.etotem.cfc.entity.FileTag;
|
|
import com.etotem.cfc.entity.FileTag;
|
|
|
-import com.etotem.cfc.entity.FileTagRel;
|
|
|
|
|
-import com.etotem.cfc.mapper.FileRecordMapper;
|
|
|
|
|
-import com.etotem.cfc.mapper.FileTagMapper;
|
|
|
|
|
-import com.etotem.cfc.mapper.FileTagRelMapper;
|
|
|
|
|
|
|
+import com.etotem.cfc.service.FileRecordService;
|
|
|
import com.etotem.cfc.service.StorageService;
|
|
import com.etotem.cfc.service.StorageService;
|
|
|
|
|
+import com.etotem.cfc.service.api.WechatServiceInterface;
|
|
|
|
|
+import com.etotem.cfc.util.ParamUtils;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.LinkedHashSet;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
-import com.etotem.cfc.util.ParamUtils;
|
|
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 后台素材库:文件记录(上传/检索/维护)与标签字典管理。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>接口约定:
|
|
|
|
|
+ * <ul>
|
|
|
|
|
+ * <li>全部为 POST,admin 角色守卫(@RequestAttribute("role") == "admin")</li>
|
|
|
|
|
+ * <li>统一返回 Result<T>(code/message/data)</li>
|
|
|
|
|
+ * <li>/upload 为 multipart 上传,字段名 file;tagIds 支持数组或逗号分隔字符串</li>
|
|
|
|
|
+ * </ul>
|
|
|
|
|
+ */
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/api/admin/file-record")
|
|
@RequestMapping("/api/admin/file-record")
|
|
|
public class FileRecordController {
|
|
public class FileRecordController {
|
|
@@ -28,16 +44,13 @@ public class FileRecordController {
|
|
|
private static final Logger log = LoggerFactory.getLogger(FileRecordController.class);
|
|
private static final Logger log = LoggerFactory.getLogger(FileRecordController.class);
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
- private FileRecordMapper fileRecordMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private FileTagMapper fileTagMapper;
|
|
|
|
|
|
|
+ private FileRecordService fileRecordService;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
- private FileTagRelMapper fileTagRelMapper;
|
|
|
|
|
|
|
+ private StorageService storageService;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
- private StorageService storageService;
|
|
|
|
|
|
|
+ private WechatServiceInterface wechatService;
|
|
|
|
|
|
|
|
@PostMapping("/list")
|
|
@PostMapping("/list")
|
|
|
public Result<Map<String, Object>> list(@RequestBody Map<String, Object> params,
|
|
public Result<Map<String, Object>> list(@RequestBody Map<String, Object> params,
|
|
@@ -50,91 +63,86 @@ public class FileRecordController {
|
|
|
String search = params.get("search") != null ? params.get("search").toString() : null;
|
|
String search = params.get("search") != null ? params.get("search").toString() : null;
|
|
|
String dateFrom = params.get("dateFrom") != null ? params.get("dateFrom").toString() : null;
|
|
String dateFrom = params.get("dateFrom") != null ? params.get("dateFrom").toString() : null;
|
|
|
String dateTo = params.get("dateTo") != null ? params.get("dateTo").toString() : null;
|
|
String dateTo = params.get("dateTo") != null ? params.get("dateTo").toString() : null;
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
|
- List<Integer> tagIds = params.get("tagIds") != null ? (List<Integer>) params.get("tagIds") : null;
|
|
|
|
|
-
|
|
|
|
|
- LambdaQueryWrapper<FileRecord> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
- if (category != null && !category.isEmpty()) wrapper.eq(FileRecord::getCategory, category);
|
|
|
|
|
- if (fileType != null && !fileType.isEmpty()) wrapper.eq(FileRecord::getFileType, fileType);
|
|
|
|
|
- if (search != null && !search.isEmpty()) {
|
|
|
|
|
- wrapper.and(w -> w.like(FileRecord::getOriginalFilename, search)
|
|
|
|
|
- .or().like(FileRecord::getDescription, search));
|
|
|
|
|
- }
|
|
|
|
|
- if (dateFrom != null && !dateFrom.isEmpty()) wrapper.ge(FileRecord::getCreatedAt, dateFrom + " 00:00:00");
|
|
|
|
|
- if (dateTo != null && !dateTo.isEmpty()) wrapper.le(FileRecord::getCreatedAt, dateTo + " 23:59:59");
|
|
|
|
|
- wrapper.orderByDesc(FileRecord::getCreatedAt);
|
|
|
|
|
-
|
|
|
|
|
- IPage<FileRecord> page = fileRecordMapper.selectPage(new Page<>(pageNo, pageSize), wrapper);
|
|
|
|
|
-
|
|
|
|
|
- List<Long> fileIds = page.getRecords().stream().map(FileRecord::getId).collect(Collectors.toList());
|
|
|
|
|
- Map<Long, List<FileTag>> fileTagsMap = new HashMap<>();
|
|
|
|
|
- if (!fileIds.isEmpty()) {
|
|
|
|
|
- List<FileTagRel> rels = fileTagRelMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<FileTagRel>().in(FileTagRel::getFileId, fileIds));
|
|
|
|
|
- if (!rels.isEmpty()) {
|
|
|
|
|
- Set<Long> tagIdSet = rels.stream().map(FileTagRel::getTagId).collect(Collectors.toSet());
|
|
|
|
|
- List<FileTag> tags = fileTagMapper.selectBatchIds(tagIdSet);
|
|
|
|
|
- Map<Long, FileTag> tagMap = tags.stream().collect(Collectors.toMap(FileTag::getId, t -> t));
|
|
|
|
|
- for (FileTagRel rel : rels) {
|
|
|
|
|
- fileTagsMap.computeIfAbsent(rel.getFileId(), k -> new ArrayList<>()).add(tagMap.get(rel.getTagId()));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<Long> tagIds = parseTagIds(params.get("tagIds"));
|
|
|
|
|
|
|
|
- List<FileRecord> filteredRecords = page.getRecords();
|
|
|
|
|
- if (tagIds != null && !tagIds.isEmpty()) {
|
|
|
|
|
- filteredRecords = filteredRecords.stream()
|
|
|
|
|
- .filter(r -> {
|
|
|
|
|
- List<FileTag> ft = fileTagsMap.get(r.getId());
|
|
|
|
|
- return ft != null && ft.stream().anyMatch(t -> tagIds.contains(t.getId().intValue()));
|
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ IPage<FileRecord> page = fileRecordService.pageRecords(
|
|
|
|
|
+ pageNo, pageSize, category, fileType, search, dateFrom, dateTo, tagIds);
|
|
|
|
|
+
|
|
|
|
|
+ List<FileRecord> records = page.getRecords();
|
|
|
|
|
+ Map<Long, List<FileTag>> fileTagsMap = fileRecordService.tagsByFileIds(
|
|
|
|
|
+ records.stream().map(FileRecord::getId).collect(Collectors.toList()));
|
|
|
|
|
|
|
|
- List<Map<String, Object>> records = new ArrayList<>();
|
|
|
|
|
- for (FileRecord r : filteredRecords) {
|
|
|
|
|
- Map<String, Object> item = new LinkedHashMap<>();
|
|
|
|
|
- item.put("id", r.getId());
|
|
|
|
|
- item.put("hash", r.getHash());
|
|
|
|
|
- item.put("url", r.getUrl());
|
|
|
|
|
- item.put("fileSize", r.getFileSize());
|
|
|
|
|
- item.put("contentType", r.getContentType());
|
|
|
|
|
- item.put("originalFilename", r.getOriginalFilename());
|
|
|
|
|
- item.put("category", r.getCategory());
|
|
|
|
|
- item.put("fileType", r.getFileType());
|
|
|
|
|
- item.put("description", r.getDescription());
|
|
|
|
|
- item.put("createdAt", r.getCreatedAt());
|
|
|
|
|
- item.put("updatedAt", r.getUpdatedAt());
|
|
|
|
|
- item.put("tags", fileTagsMap.getOrDefault(r.getId(), Collections.emptyList()));
|
|
|
|
|
- records.add(item);
|
|
|
|
|
|
|
+ List<Map<String, Object>> items = new ArrayList<>();
|
|
|
|
|
+ for (FileRecord r : records) {
|
|
|
|
|
+ items.add(buildRecordMap(r, fileTagsMap.getOrDefault(r.getId(), java.util.Collections.emptyList())));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Map<String, Object> result = new LinkedHashMap<>();
|
|
Map<String, Object> result = new LinkedHashMap<>();
|
|
|
- result.put("records", records);
|
|
|
|
|
|
|
+ result.put("records", items);
|
|
|
result.put("total", page.getTotal());
|
|
result.put("total", page.getTotal());
|
|
|
result.put("page", pageNo);
|
|
result.put("page", pageNo);
|
|
|
result.put("pageSize", pageSize);
|
|
result.put("pageSize", pageSize);
|
|
|
return Result.success(result);
|
|
return Result.success(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 统一上传入库:存储(含去重)→ 写入 file_record → 关联标签 → 返回记录。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>重复 hash 命中时返回已存在的记录,并补打本次上传携带的标签。</p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param file multipart 文件字段(富文本编辑器/普通上传控件统一用 "file")
|
|
|
|
|
+ * @param category 素材分类,默认 general
|
|
|
|
|
+ * @param tagIds 标签ID列表,支持数组(tagIds=1&tagIds=2)或逗号分隔(tagIds=1,2)
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/upload")
|
|
|
|
|
+ public Result<Map<String, Object>> upload(@RequestParam("file") MultipartFile file,
|
|
|
|
|
+ @RequestParam(value = "category", required = false) String category,
|
|
|
|
|
+ @RequestParam(value = "tagIds", required = false) List<String> tagIds,
|
|
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
|
|
+ if (!"admin".equals(role)) return Result.error("无权限");
|
|
|
|
|
+ if (file == null || file.isEmpty()) {
|
|
|
|
|
+ return Result.error("文件为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 图片内容安全检测(与 AdminArticleController#uploadImage 保持一致;微信检测 fail-open)
|
|
|
|
|
+ if (file.getContentType() != null && file.getContentType().startsWith("image")) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ byte[] imageBytes = file.getBytes();
|
|
|
|
|
+ if (!wechatService.checkImage(imageBytes)) {
|
|
|
|
|
+ return Result.error("图片内容包含敏感信息,上传失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (java.io.IOException e) {
|
|
|
|
|
+ return Result.error("图片读取失败: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ FileRecord record = storageService.storeFileRecord(file, category);
|
|
|
|
|
+ List<Long> tagIdList = parseTagIds(tagIds);
|
|
|
|
|
+ fileRecordService.addTags(record.getId(), tagIdList);
|
|
|
|
|
+ Map<String, Object> map = buildRecordMap(record, fileRecordService.getTags(record.getId()));
|
|
|
|
|
+ log.info("素材库上传成功: id={}, category={}, fileType={}, url={}, tags={}",
|
|
|
|
|
+ record.getId(), record.getCategory(), record.getFileType(), record.getUrl(), tagIdList);
|
|
|
|
|
+ return Result.success(map);
|
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
|
+ return Result.error(e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("素材库上传失败", e);
|
|
|
|
|
+ return Result.error("上传失败: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@PostMapping("/update")
|
|
@PostMapping("/update")
|
|
|
public Result<String> update(@RequestBody Map<String, Object> params,
|
|
public Result<String> update(@RequestBody Map<String, Object> params,
|
|
|
@RequestAttribute("role") String role) {
|
|
@RequestAttribute("role") String role) {
|
|
|
if (!"admin".equals(role)) return Result.error("无权限");
|
|
if (!"admin".equals(role)) return Result.error("无权限");
|
|
|
Long id = ParamUtils.getLong(params.get("id"));
|
|
Long id = ParamUtils.getLong(params.get("id"));
|
|
|
- FileRecord record = fileRecordMapper.selectById(id);
|
|
|
|
|
|
|
+ FileRecord record = fileRecordService.getById(id);
|
|
|
if (record == null) return Result.error("文件不存在");
|
|
if (record == null) return Result.error("文件不存在");
|
|
|
- if (params.get("description") != null) record.setDescription(params.get("description").toString());
|
|
|
|
|
- fileRecordMapper.updateById(record);
|
|
|
|
|
|
|
+ if (params.get("description") != null) {
|
|
|
|
|
+ fileRecordService.updateDescription(id, params.get("description").toString());
|
|
|
|
|
+ }
|
|
|
if (params.get("tagIds") != null) {
|
|
if (params.get("tagIds") != null) {
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
|
- List<Integer> tagIds = (List<Integer>) params.get("tagIds");
|
|
|
|
|
- fileTagRelMapper.delete(new LambdaQueryWrapper<FileTagRel>().eq(FileTagRel::getFileId, id));
|
|
|
|
|
- for (Integer tagId : tagIds) {
|
|
|
|
|
- FileTagRel rel = new FileTagRel();
|
|
|
|
|
- rel.setFileId(id);
|
|
|
|
|
- rel.setTagId(tagId.longValue());
|
|
|
|
|
- fileTagRelMapper.insert(rel);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<Long> tagIds = parseTagIds(params.get("tagIds"));
|
|
|
|
|
+ fileRecordService.replaceTags(id, tagIds);
|
|
|
}
|
|
}
|
|
|
return Result.success("更新成功");
|
|
return Result.success("更新成功");
|
|
|
}
|
|
}
|
|
@@ -144,34 +152,118 @@ public class FileRecordController {
|
|
|
@RequestAttribute("role") String role) {
|
|
@RequestAttribute("role") String role) {
|
|
|
if (!"admin".equals(role)) return Result.error("无权限");
|
|
if (!"admin".equals(role)) return Result.error("无权限");
|
|
|
Long id = ParamUtils.getLong(params.get("id"));
|
|
Long id = ParamUtils.getLong(params.get("id"));
|
|
|
- FileRecord record = fileRecordMapper.selectById(id);
|
|
|
|
|
|
|
+ FileRecord record = fileRecordService.getById(id);
|
|
|
if (record == null) return Result.error("文件不存在");
|
|
if (record == null) return Result.error("文件不存在");
|
|
|
try { storageService.deleteFile(record.getUrl()); }
|
|
try { storageService.deleteFile(record.getUrl()); }
|
|
|
catch (Exception e) { log.warn("OSS删除失败: {}", record.getUrl(), e); }
|
|
catch (Exception e) { log.warn("OSS删除失败: {}", record.getUrl(), e); }
|
|
|
- fileTagRelMapper.delete(new LambdaQueryWrapper<FileTagRel>().eq(FileTagRel::getFileId, id));
|
|
|
|
|
- fileRecordMapper.deleteById(id);
|
|
|
|
|
|
|
+ fileRecordService.deleteRecord(id);
|
|
|
return Result.success("删除成功");
|
|
return Result.success("删除成功");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/tags")
|
|
@PostMapping("/tags")
|
|
|
public Result<List<FileTag>> getTags(@RequestAttribute("role") String role) {
|
|
public Result<List<FileTag>> getTags(@RequestAttribute("role") String role) {
|
|
|
if (!"admin".equals(role)) return Result.error("无权限");
|
|
if (!"admin".equals(role)) return Result.error("无权限");
|
|
|
- return Result.success(fileTagMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<FileTag>().orderByAsc(FileTag::getSortOrder)));
|
|
|
|
|
|
|
+ return Result.success(fileRecordService.listTags());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/tag/create")
|
|
|
|
|
+ public Result<FileTag> tagCreate(@RequestBody Map<String, Object> params,
|
|
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
|
|
+ if (!"admin".equals(role)) return Result.error("无权限");
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Result.success(fileRecordService.createTag(
|
|
|
|
|
+ str(params.get("name")), str(params.get("color")), integer(params.get("sortOrder"))));
|
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
|
+ return Result.error(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/tag/update")
|
|
|
|
|
+ public Result<FileTag> tagUpdate(@RequestBody Map<String, Object> params,
|
|
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
|
|
+ if (!"admin".equals(role)) return Result.error("无权限");
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Result.success(fileRecordService.updateTag(
|
|
|
|
|
+ ParamUtils.getLong(params.get("id")),
|
|
|
|
|
+ str(params.get("name")), str(params.get("color")), integer(params.get("sortOrder"))));
|
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
|
+ return Result.error(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/tag/delete")
|
|
|
|
|
+ public Result<String> tagDelete(@RequestBody Map<String, Object> params,
|
|
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
|
|
+ if (!"admin".equals(role)) return Result.error("无权限");
|
|
|
|
|
+ try {
|
|
|
|
|
+ fileRecordService.deleteTag(ParamUtils.getLong(params.get("id")));
|
|
|
|
|
+ return Result.success("删除成功");
|
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
|
+ return Result.error(e.getMessage());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/stats")
|
|
@PostMapping("/stats")
|
|
|
public Result<Map<String, Object>> stats(@RequestAttribute("role") String role) {
|
|
public Result<Map<String, Object>> stats(@RequestAttribute("role") String role) {
|
|
|
if (!"admin".equals(role)) return Result.error("无权限");
|
|
if (!"admin".equals(role)) return Result.error("无权限");
|
|
|
- Map<String, Object> stats = new LinkedHashMap<>();
|
|
|
|
|
- stats.put("byCategory", fileRecordMapper.selectMaps(
|
|
|
|
|
- new QueryWrapper<FileRecord>().select("category, COUNT(*) AS cnt").groupBy("category")));
|
|
|
|
|
- stats.put("byFileType", fileRecordMapper.selectMaps(
|
|
|
|
|
- new QueryWrapper<FileRecord>().select("file_type, COUNT(*) AS cnt").groupBy("file_type")));
|
|
|
|
|
- stats.put("total", fileRecordMapper.selectCount(null));
|
|
|
|
|
- List<Map<String, Object>> ts = fileRecordMapper.selectMaps(
|
|
|
|
|
- new QueryWrapper<FileRecord>().select("SUM(file_size) AS total_bytes"));
|
|
|
|
|
- stats.put("totalBytes", ts.get(0).get("total_bytes"));
|
|
|
|
|
- return Result.success(stats);
|
|
|
|
|
|
|
+ return Result.success(fileRecordService.stats());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 工具方法 ====================
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析 tagIds 参数:支持 List(数组)、逗号分隔字符串,空/非法值忽略。
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<Long> parseTagIds(Object raw) {
|
|
|
|
|
+ Set<Long> result = new LinkedHashSet<>();
|
|
|
|
|
+ if (raw == null) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (raw instanceof List) {
|
|
|
|
|
+ for (Object o : (List<?>) raw) {
|
|
|
|
|
+ Long id = ParamUtils.getLong(o);
|
|
|
|
|
+ if (id != null) result.add(id);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ String s = raw.toString();
|
|
|
|
|
+ for (String part : s.split(",")) {
|
|
|
|
|
+ Long id = ParamUtils.getLong(part);
|
|
|
|
|
+ if (id != null) result.add(id);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return new ArrayList<>(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构建前端使用的记录 map(含 id/url/fileType/originalFilename/category/description/tags)。
|
|
|
|
|
+ */
|
|
|
|
|
+ private Map<String, Object> buildRecordMap(FileRecord r, List<FileTag> tags) {
|
|
|
|
|
+ Map<String, Object> item = new LinkedHashMap<>();
|
|
|
|
|
+ item.put("id", r.getId());
|
|
|
|
|
+ item.put("hash", r.getHash());
|
|
|
|
|
+ item.put("url", r.getUrl());
|
|
|
|
|
+ item.put("fileSize", r.getFileSize());
|
|
|
|
|
+ item.put("contentType", r.getContentType());
|
|
|
|
|
+ item.put("originalFilename", r.getOriginalFilename());
|
|
|
|
|
+ item.put("category", r.getCategory());
|
|
|
|
|
+ item.put("fileType", r.getFileType());
|
|
|
|
|
+ item.put("description", r.getDescription());
|
|
|
|
|
+ item.put("createdAt", r.getCreatedAt());
|
|
|
|
|
+ item.put("updatedAt", r.getUpdatedAt());
|
|
|
|
|
+ item.put("tags", tags == null ? new ArrayList<>() : tags);
|
|
|
|
|
+ return item;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String str(Object o) {
|
|
|
|
|
+ return o != null ? o.toString() : null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Integer integer(Object o) {
|
|
|
|
|
+ if (o == null) return null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Integer.parseInt(o.toString().trim());
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|