From 2b4458dc1b84fa573a8cf206f42741875bae628e Mon Sep 17 00:00:00 2001 From: "ran.shang" Date: Tue, 6 Jan 2026 16:37:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96+riskrule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/init-data.sql | 28 ++++++++- .../sfile/controller/RiskFileController.java | 36 +++++++++++ .../controller/ShareUserFileController.java | 21 +++---- .../com/senmesh/sfile/dto/UserFileDTO.java | 3 + .../senmesh/sfile/dto/UserFileQueryDTO.java | 3 + .../senmesh/sfile/mapper/UserFileMapper.xml | 10 ++- .../sfile/service/RiskFileService.java | 22 +++++++ .../sfile/service/ShareUserFileService.java | 11 ++++ .../service/impl/RiskFileServiceImpl.java | 61 +++++++++++++++++++ .../impl/ShareUserFileServiceImpl.java | 20 ++++++ .../service/impl/UserFileServiceImpl.java | 24 ++++---- 11 files changed, 212 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/senmesh/sfile/controller/RiskFileController.java create mode 100644 src/main/java/com/senmesh/sfile/service/RiskFileService.java create mode 100644 src/main/java/com/senmesh/sfile/service/impl/RiskFileServiceImpl.java diff --git a/db/init-data.sql b/db/init-data.sql index 15a8fb6..207ab93 100644 --- a/db/init-data.sql +++ b/db/init-data.sql @@ -17,4 +17,30 @@ VALUES(1, 1, TRUE, FALSE, 0, now(), NULL, NULL, NULL); -- 平台uc_org_relation INSERT INTO uc_org_relation (org_id, org_type, parent_id, path, platform_code, platform_name, deleted, create_by, create_time, update_by, update_time, proxy_by) -VALUES(1, 1, 0, '1', 1, NULL, FALSE, NULL, NULL, NULL, NULL, NULL); \ No newline at end of file +VALUES(1, 1, 0, '1', 1, NULL, FALSE, NULL, NULL, NULL, NULL, NULL); + +-- ---------------------------- +-- Records of x_file_category +-- ---------------------------- +INSERT INTO x_file_category (file_category, file_suffix, deleted, create_by, create_time) VALUES +('video', 'mp4', FALSE, 0, NOW()), +('video', 'mkv', FALSE, 0, NOW()), +('video', 'avi', FALSE, 0, NOW()), +('video', 'mov', FALSE, 0, NOW()), +('video', 'wmv', FALSE, 0, NOW()), +('video', 'flv', FALSE, 0, NOW()), +('audio', 'mp3', FALSE, 0, NOW()), +('audio', 'wav', FALSE, 0, NOW()), +('audio', 'flac', FALSE, 0, NOW()), +('audio', 'aac', FALSE, 0, NOW()), +('document', 'txt', FALSE, 0, NOW()), +('document', 'docx', FALSE, 0, NOW()), +('document', 'pdf', FALSE, 0, NOW()), +('document', 'epub', FALSE, 0, NOW()), +('other', 'zip', FALSE, 0, NOW()), +('other', 'rar', FALSE, 0, NOW()), +('other', '7z', FALSE, 0, NOW()), +('other', 'jpg', FALSE, 0, NOW()), +('other', 'png', FALSE, 0, NOW()), +('other', 'gif', FALSE, 0, NOW()), +('other', 'tiff', FALSE, 0, NOW()); diff --git a/src/main/java/com/senmesh/sfile/controller/RiskFileController.java b/src/main/java/com/senmesh/sfile/controller/RiskFileController.java new file mode 100644 index 0000000..f1e4d5b --- /dev/null +++ b/src/main/java/com/senmesh/sfile/controller/RiskFileController.java @@ -0,0 +1,36 @@ +package com.senmesh.sfile.controller; + +import com.senmesh.common.AlitaResult; +import com.senmesh.sfile.service.RiskFileService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +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.RestController; + +/** + * 风险文件Controller + */ +@RestController +@Api(tags = "风险文件") +public class RiskFileController { + + @Autowired + private RiskFileService riskFileService; + + @GetMapping("/risk_file/rule") + @ApiOperation("获取风险规则") + public AlitaResult getRiskRule() { + return AlitaResult.success(riskFileService.getRiskRule()); + } + + @PostMapping("/risk_file/rule") + @ApiOperation("保存风险规则") + public AlitaResult saveRiskRule(@RequestBody String riskRule) { + riskFileService.saveRiskRule(riskRule); + return AlitaResult.success(); + } + +} diff --git a/src/main/java/com/senmesh/sfile/controller/ShareUserFileController.java b/src/main/java/com/senmesh/sfile/controller/ShareUserFileController.java index c76b6a3..49fd5e8 100644 --- a/src/main/java/com/senmesh/sfile/controller/ShareUserFileController.java +++ b/src/main/java/com/senmesh/sfile/controller/ShareUserFileController.java @@ -1,30 +1,26 @@ package com.senmesh.sfile.controller; import com.senmesh.common.AlitaResult; -import com.senmesh.common.util.UserContextHolder; -import com.senmesh.sfile.constant.FileStatusEnum; -import com.senmesh.sfile.constant.RootTypeEnum; import com.senmesh.sfile.dto.ShareUserFileCreateDTO; -import com.senmesh.sfile.dto.UserFileModifyDTO; -import com.senmesh.sfile.dto.UserFileModifyStatusDTO; +import com.senmesh.sfile.dto.UserFileDTO; import com.senmesh.sfile.service.ShareUserFileService; import com.senmesh.sfile.service.UserFileService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; 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; /** * 分享用户文件Controller */ @RestController -@RequestMapping("share_user_file") @Api(tags = "分享用户文件") public class ShareUserFileController { @@ -34,13 +30,16 @@ public class ShareUserFileController { @Autowired private UserFileService userFileService; - @PostMapping("/create") + @PostMapping("share_user_file/create") @ApiOperation("创建") public AlitaResult create(@Validated @RequestBody ShareUserFileCreateDTO createDTO) { return AlitaResult.success(shareUserFileService.create(createDTO)); } - + @GetMapping("/anon/share_user_file/{id}") + @ApiOperation("匿名查询分享文件") + public AlitaResult> list(@PathVariable Long id, @RequestParam String accessCode) { + return AlitaResult.success(shareUserFileService.list(id, accessCode)); + } } - diff --git a/src/main/java/com/senmesh/sfile/dto/UserFileDTO.java b/src/main/java/com/senmesh/sfile/dto/UserFileDTO.java index e05d1ea..1df02dd 100644 --- a/src/main/java/com/senmesh/sfile/dto/UserFileDTO.java +++ b/src/main/java/com/senmesh/sfile/dto/UserFileDTO.java @@ -60,5 +60,8 @@ public class UserFileDTO extends BaseDTO { @ApiModelProperty("访问码") private String accessCode; + + @ApiModelProperty("文件种类") + private String fileCategory; } diff --git a/src/main/java/com/senmesh/sfile/dto/UserFileQueryDTO.java b/src/main/java/com/senmesh/sfile/dto/UserFileQueryDTO.java index 87e1392..080ca0b 100644 --- a/src/main/java/com/senmesh/sfile/dto/UserFileQueryDTO.java +++ b/src/main/java/com/senmesh/sfile/dto/UserFileQueryDTO.java @@ -52,5 +52,8 @@ public class UserFileQueryDTO extends PageQueryDTO { @ApiModelProperty("路径(模糊查询,用于查询某个文件夹下的所有子文件)") private String pathLike; + + @ApiModelProperty("文件种类") + private String fileCategory; } diff --git a/src/main/java/com/senmesh/sfile/mapper/UserFileMapper.xml b/src/main/java/com/senmesh/sfile/mapper/UserFileMapper.xml index d9ba785..65f9d5b 100644 --- a/src/main/java/com/senmesh/sfile/mapper/UserFileMapper.xml +++ b/src/main/java/com/senmesh/sfile/mapper/UserFileMapper.xml @@ -4,7 +4,7 @@ @@ -12,6 +12,7 @@ FROM x_user_file t LEFT JOIN xs_file_record fr ON t.file_code = fr.file_code AND fr.deleted = FALSE + LEFT JOIN x_file_category fc ON fr.file_suffix = fc.file_suffix AND fc.deleted = FALSE WHERE t.deleted = FALSE AND t.id = #{param.id} @@ -42,8 +43,11 @@ AND t.file_status = #{param.fileStatus} - - AND t.path LIKE #{pathLike} + + AND t.path like #{pathLike} + + + AND fc.file_category = #{param.fileCategory} diff --git a/src/main/java/com/senmesh/sfile/service/RiskFileService.java b/src/main/java/com/senmesh/sfile/service/RiskFileService.java new file mode 100644 index 0000000..3136552 --- /dev/null +++ b/src/main/java/com/senmesh/sfile/service/RiskFileService.java @@ -0,0 +1,22 @@ +package com.senmesh.sfile.service; + +/** + * 风险文件Service + */ +public interface RiskFileService { + + /** + * 获取风险规则 + * + * @return 风险规则配置值 + */ + String getRiskRule(); + + /** + * 保存风险规则 + * + * @param riskRule 风险规则配置值 + */ + void saveRiskRule(String riskRule); +} + diff --git a/src/main/java/com/senmesh/sfile/service/ShareUserFileService.java b/src/main/java/com/senmesh/sfile/service/ShareUserFileService.java index a6e596b..d754f10 100644 --- a/src/main/java/com/senmesh/sfile/service/ShareUserFileService.java +++ b/src/main/java/com/senmesh/sfile/service/ShareUserFileService.java @@ -1,6 +1,8 @@ package com.senmesh.sfile.service; import com.senmesh.sfile.dto.ShareUserFileCreateDTO; +import com.senmesh.sfile.dto.UserFileDTO; +import java.util.List; /** * 分享用户文件Service @@ -15,5 +17,14 @@ public interface ShareUserFileService { * @return 分享文件夹ID */ Long create(ShareUserFileCreateDTO createDTO); + + /** + * 根据ID和访问码查询分享文件 + * + * @param id 分享文件ID + * @param accessCode 访问码 + * @return + */ + List list(Long id, String accessCode); } diff --git a/src/main/java/com/senmesh/sfile/service/impl/RiskFileServiceImpl.java b/src/main/java/com/senmesh/sfile/service/impl/RiskFileServiceImpl.java new file mode 100644 index 0000000..f42a009 --- /dev/null +++ b/src/main/java/com/senmesh/sfile/service/impl/RiskFileServiceImpl.java @@ -0,0 +1,61 @@ +package com.senmesh.sfile.service.impl; + +import com.senmesh.common.constant.CommonConstants; +import com.senmesh.common.util.UserContextHolder; +import com.senmesh.config.dto.ConfigDTO; +import com.senmesh.config.dto.ConfigOperatorDTO; +import com.senmesh.config.entity.Config; +import com.senmesh.config.service.ConfigService; +import com.senmesh.sfile.service.RiskFileService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 风险文件ServiceImpl + */ +@Service +public class RiskFileServiceImpl implements RiskFileService { + + private static final String RISK_RULE_CONFIG_CODE = "risk_rule"; + + @Autowired + private ConfigService configService; + + @Override + public String getRiskRule() { + ConfigDTO configDTO = configService.queryOrgConfigByCode(UserContextHolder.getExistLoginOrgId(), RISK_RULE_CONFIG_CODE); + return configDTO == null ? null : configDTO.getConfigValue(); + } + + @Override + @Transactional + public void saveRiskRule(String riskRule) { + // 查询是否已存在配置 + ConfigDTO existConfig = configService.queryOrgConfigByCode(UserContextHolder.getExistLoginOrgId(), RISK_RULE_CONFIG_CODE); + + if (existConfig != null) { + // 存在则修改 + ConfigOperatorDTO modifyDTO = ConfigOperatorDTO.builder() + .id(existConfig.getId()) + .configCode(RISK_RULE_CONFIG_CODE) + .configValue(riskRule) + .orgId(UserContextHolder.getExistLoginOrgId()) + .enable(true) + .build(); + configService.modify(modifyDTO); + } else { + // 不存在则创建 + ConfigOperatorDTO createDTO = ConfigOperatorDTO.builder() + .configCode(RISK_RULE_CONFIG_CODE) + .configValue(riskRule) + .orgId(UserContextHolder.getExistLoginOrgId()) + .enable(true) + .build(); + configService.create(createDTO); + } + } +} + diff --git a/src/main/java/com/senmesh/sfile/service/impl/ShareUserFileServiceImpl.java b/src/main/java/com/senmesh/sfile/service/impl/ShareUserFileServiceImpl.java index 7a66f2e..b216b98 100644 --- a/src/main/java/com/senmesh/sfile/service/impl/ShareUserFileServiceImpl.java +++ b/src/main/java/com/senmesh/sfile/service/impl/ShareUserFileServiceImpl.java @@ -1,13 +1,17 @@ package com.senmesh.sfile.service.impl; +import com.senmesh.common.exception.util.Assert; import com.senmesh.common.util.RandomUtils; import com.senmesh.common.util.UserContextHolder; import com.senmesh.sfile.constant.FileStatusEnum; import com.senmesh.sfile.constant.RootTypeEnum; import com.senmesh.sfile.dto.ExpandUserFileCreateDTO; import com.senmesh.sfile.dto.ShareUserFileCreateDTO; +import com.senmesh.sfile.dto.UserFileDTO; +import com.senmesh.sfile.dto.UserFileQueryDTO; import com.senmesh.sfile.service.ShareUserFileService; import com.senmesh.sfile.service.UserFileService; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -51,5 +55,21 @@ public class ShareUserFileServiceImpl implements ShareUserFileService { .build(); return userFileService.create(expandCreateDTO).getFolder().getId(); } + + @Override + public List list(Long id, String accessCode) { + UserFileDTO userFileDTO = userFileService.findOne(UserFileQueryDTO.builder() + .id(id) + .rootType(RootTypeEnum.SHARE.getType()) + .build()); + Assert.isTrue(userFileDTO.getAccessCode().equals(accessCode), "访问码不正确"); + + return userFileService.list(UserFileQueryDTO.builder() + .rootType(RootTypeEnum.SHARE.getType()) + .pathLike(userFileDTO.getPath()) + .build()); + } + + } diff --git a/src/main/java/com/senmesh/sfile/service/impl/UserFileServiceImpl.java b/src/main/java/com/senmesh/sfile/service/impl/UserFileServiceImpl.java index f08a059..e5d0d0f 100644 --- a/src/main/java/com/senmesh/sfile/service/impl/UserFileServiceImpl.java +++ b/src/main/java/com/senmesh/sfile/service/impl/UserFileServiceImpl.java @@ -5,6 +5,7 @@ import com.senmesh.common.exception.util.Assert; import com.senmesh.common.util.ListUtil; import com.senmesh.common.util.UserContextHolder; import com.senmesh.component.file.service.FileService; +import com.senmesh.component.file.util.FileUtils; import com.senmesh.sfile.constant.FileStatusEnum; import com.senmesh.sfile.constant.FileTypeEnum; import com.senmesh.sfile.constant.RootTypeEnum; @@ -108,20 +109,10 @@ public class UserFileServiceImpl implements UserFileService { .rootType(RootTypeEnum.NORMAL.getType()) .build()); - // 3. 查询需要复制的文件列表 - UserFileQueryDTO queryDTO = UserFileQueryDTO.builder() - .userId(userId) - .rootType(RootTypeEnum.NORMAL.getType()) - .fileType(FileTypeEnum.FILE.getType()) - .pathLike(normalFile.getPath()) - .build(); - queryDTO.disablePage(); - List filesToCopy = this.list(queryDTO); - Assert.notEmpty(filesToCopy, "未查询到需要处理的文件"); - // 2. 创建文件夹,文件名 = 原文件名 + 当前时间 String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); - String folderName = normalFile.getFileName() + "_" + timestamp; + String baseFileName = FileTypeEnum.isFile(normalFile.getFileType()) ? FileUtils.getFileNameNoSuffix(normalFile.getFileName()) : normalFile.getFileName(); + String folderName = baseFileName + "_" + timestamp; UserFileCreateDTO folderCreateDTO = UserFileCreateDTO.builder() .userId(userId) @@ -137,6 +128,15 @@ public class UserFileServiceImpl implements UserFileService { Long folderId = folderDTO.getId(); String folderPath = String.valueOf(folderId); + // 3. 查询需要复制的文件列表 + UserFileQueryDTO queryDTO = UserFileQueryDTO.builder() + .userId(userId) + .rootType(RootTypeEnum.NORMAL.getType()) + .fileType(FileTypeEnum.FILE.getType()) + .pathLike(normalFile.getPath()) + .build(); + queryDTO.disablePage(); + List filesToCopy = this.list(queryDTO); // 4. 在文件夹下创建文件对象 List createdFiles = new java.util.ArrayList<>();