mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 12:52:07 +08:00
1、新增组件订单数据拉取接口;2、新增上传url产生文件数据/根据文件id获取文件地址接口;
This commit is contained in:
+32
@@ -2,6 +2,7 @@ package com.cf.imes.module.infra.api.file;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.module.infra.api.file.dto.FileCreateReqDTO;
|
||||
import com.cf.imes.module.infra.api.file.dto.ExternalFileCreateReqDTO;
|
||||
import com.cf.imes.module.infra.enums.ApiConstants;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -12,6 +13,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@@ -102,4 +104,34 @@ public interface FileApi {
|
||||
@PostMapping(PREFIX + "/getFileHashByIds")
|
||||
@Operation(summary = "根据文件id请求和fileHash的对应关系")
|
||||
CommonResult<Map<Long, String>> getFileHashMapByIds(@RequestBody Set<Long> fileIds);
|
||||
|
||||
/**
|
||||
* 登记一个已由外部系统托管的文件地址,不上传或复制文件内容。
|
||||
*
|
||||
* @param createReqDTO 外部文件名称及访问地址
|
||||
* @return iMES 文件记录 ID
|
||||
*/
|
||||
@PostMapping(PREFIX + "/external")
|
||||
@Operation(summary = "登记外部文件地址并返回文件 ID")
|
||||
CommonResult<Long> createExternalFile(@Valid @RequestBody ExternalFileCreateReqDTO createReqDTO);
|
||||
|
||||
/**
|
||||
* 根据 iMES 文件记录 ID 获取外部文件地址。
|
||||
*
|
||||
* @param id iMES 文件记录 ID
|
||||
* @return 外部文件地址
|
||||
*/
|
||||
@GetMapping(PREFIX + "/external/{id}/url")
|
||||
@Operation(summary = "根据文件 ID 获取外部文件地址")
|
||||
CommonResult<String> getExternalFileUrl(@PathVariable("id") Long id);
|
||||
|
||||
/**
|
||||
* 删除外部文件在 iMES 中的登记记录,不删除外部存储中的实际文件。
|
||||
*
|
||||
* @param id iMES 文件记录 ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping(PREFIX + "/external/{id}")
|
||||
@Operation(summary = "仅删除外部文件登记记录")
|
||||
CommonResult<Boolean> deleteExternalFileRecord(@PathVariable("id") Long id);
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.cf.imes.module.infra.api.file.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 外部文件地址登记请求。
|
||||
*
|
||||
* <p>仅保存文件元数据和访问地址,不读取、校验或上传地址对应的文件内容。</p>
|
||||
*/
|
||||
@Schema(description = "RPC 服务 - 外部文件地址登记 Request DTO")
|
||||
@Data
|
||||
public class ExternalFileCreateReqDTO {
|
||||
|
||||
/**
|
||||
* 展示用文件名称;为空时由服务端使用 URL 代替。
|
||||
*/
|
||||
@Schema(description = "文件名称", example = "cad-view-26072801000449.json")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 外部存储中的文件访问地址。
|
||||
*/
|
||||
@Schema(description = "外部文件地址", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "外部文件地址不能为空")
|
||||
private String url;
|
||||
}
|
||||
+26
@@ -2,6 +2,7 @@ package com.cf.imes.module.infra.api.file;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.module.infra.api.file.dto.FileCreateReqDTO;
|
||||
import com.cf.imes.module.infra.api.file.dto.ExternalFileCreateReqDTO;
|
||||
import com.cf.imes.module.infra.dal.dataobject.file.FileDO;
|
||||
import com.cf.imes.module.infra.service.file.FileService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -54,4 +55,29 @@ public class FileApiImpl implements FileApi {
|
||||
FileDO::getName
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CommonResult<Long> createExternalFile(ExternalFileCreateReqDTO createReqDTO) {
|
||||
return success(fileService.createExternalFile(createReqDTO.getName(), createReqDTO.getUrl()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CommonResult<String> getExternalFileUrl(Long id) {
|
||||
return success(fileService.getExternalFileUrl(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CommonResult<Boolean> deleteExternalFileRecord(Long id) {
|
||||
fileService.deleteExternalFileRecord(id);
|
||||
return success(true);
|
||||
}
|
||||
}
|
||||
|
||||
+28
@@ -11,6 +11,7 @@ import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
|
||||
import com.cf.imes.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
||||
import com.cf.imes.module.infra.controller.admin.file.vo.file.FileRespVO;
|
||||
import com.cf.imes.module.infra.controller.admin.file.vo.file.FileUploadReqVO;
|
||||
import com.cf.imes.module.infra.api.file.dto.ExternalFileCreateReqDTO;
|
||||
import com.cf.imes.module.infra.dal.dataobject.file.FileDO;
|
||||
import com.cf.imes.module.infra.service.file.FileService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -59,6 +60,33 @@ public class FileController {
|
||||
return success(fileService.createFileDO(file.getOriginalFilename(), null, file.getBytes()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 登记外部文件地址并生成 iMES 文件 ID。
|
||||
*
|
||||
* @param reqDTO 外部文件登记信息
|
||||
* @return iMES 文件记录 ID
|
||||
*/
|
||||
@PostMapping("/external")
|
||||
@Operation(summary = "登记外部文件地址")
|
||||
@OperateLog(logArgs = false)
|
||||
public CommonResult<Long> createExternalFile(@Valid @RequestBody ExternalFileCreateReqDTO reqDTO) {
|
||||
return success(fileService.createExternalFile(reqDTO.getName(), reqDTO.getUrl()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 iMES 文件 ID 获取保存的文件地址。
|
||||
*
|
||||
* @param id iMES 文件记录 ID
|
||||
* @return 文件访问地址
|
||||
*/
|
||||
@GetMapping("/url/{id}")
|
||||
@Operation(summary = "根据文件 ID 获取文件地址")
|
||||
@Parameter(name = "id", description = "文件编号", required = true)
|
||||
@OperateLog(enable = false)
|
||||
public CommonResult<String> getFileUrl(@PathVariable("id") Long id) {
|
||||
return success(fileService.getExternalFileUrl(id));
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除文件")
|
||||
|
||||
+24
@@ -81,4 +81,28 @@ public interface FileService {
|
||||
* @return
|
||||
*/
|
||||
List<FileDO> getByIds(Set<Long> ids);
|
||||
|
||||
/**
|
||||
* 登记外部托管文件,不上传或读取文件内容。
|
||||
*
|
||||
* @param name 文件名称;为空时使用 URL
|
||||
* @param url 外部文件访问地址
|
||||
* @return iMES 文件记录 ID
|
||||
*/
|
||||
Long createExternalFile(String name, String url);
|
||||
|
||||
/**
|
||||
* 根据 iMES 文件记录 ID 获取外部文件地址。
|
||||
*
|
||||
* @param id iMES 文件记录 ID
|
||||
* @return 外部文件地址
|
||||
*/
|
||||
String getExternalFileUrl(Long id);
|
||||
|
||||
/**
|
||||
* 仅删除外部文件在 iMES 中的登记记录,不删除外部存储中的实际文件。
|
||||
*
|
||||
* @param id iMES 文件记录 ID
|
||||
*/
|
||||
void deleteExternalFileRecord(Long id);
|
||||
}
|
||||
|
||||
+35
@@ -24,6 +24,7 @@ import java.util.Set;
|
||||
|
||||
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
|
||||
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.FILE_REMOVE_FAIL;
|
||||
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
|
||||
|
||||
/**
|
||||
* 文件 Service 实现类
|
||||
@@ -176,4 +177,38 @@ public class FileServiceImpl implements FileService {
|
||||
public List<FileDO> getByIds(Set<Long> ids) {
|
||||
return fileMapper.selectByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Long createExternalFile(String name, String url) {
|
||||
AssertUtils.notEmpty(url, FILE_IS_EMPTY);
|
||||
FileDO file = new FileDO();
|
||||
file.setConfigId(null);
|
||||
file.setName(CharSequenceUtil.emptyToDefault(name, url));
|
||||
file.setPath(url);
|
||||
file.setUrl(url);
|
||||
file.setType("application/json");
|
||||
file.setSize(0);
|
||||
fileMapper.insert(file);
|
||||
return file.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getExternalFileUrl(Long id) {
|
||||
return validateFileExists(id).getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void deleteExternalFileRecord(Long id) {
|
||||
validateFileExists(id);
|
||||
fileMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user