优化+riskrule

This commit is contained in:
ran.shang
2026-01-06 16:37:39 +08:00
parent ea6d25ca97
commit 2b4458dc1b
11 changed files with 212 additions and 27 deletions

View File

@@ -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<String> getRiskRule() {
return AlitaResult.success(riskFileService.getRiskRule());
}
@PostMapping("/risk_file/rule")
@ApiOperation("保存风险规则")
public AlitaResult<Void> saveRiskRule(@RequestBody String riskRule) {
riskFileService.saveRiskRule(riskRule);
return AlitaResult.success();
}
}

View File

@@ -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<Long> create(@Validated @RequestBody ShareUserFileCreateDTO createDTO) {
return AlitaResult.success(shareUserFileService.create(createDTO));
}
@GetMapping("/anon/share_user_file/{id}")
@ApiOperation("匿名查询分享文件")
public AlitaResult<List<UserFileDTO>> list(@PathVariable Long id, @RequestParam String accessCode) {
return AlitaResult.success(shareUserFileService.list(id, accessCode));
}
}

View File

@@ -60,5 +60,8 @@ public class UserFileDTO extends BaseDTO {
@ApiModelProperty("访问码")
private String accessCode;
@ApiModelProperty("文件种类")
private String fileCategory;
}

View File

@@ -52,5 +52,8 @@ public class UserFileQueryDTO extends PageQueryDTO<UserFileDTO> {
@ApiModelProperty("路径(模糊查询,用于查询某个文件夹下的所有子文件)")
private String pathLike;
@ApiModelProperty("文件种类")
private String fileCategory;
}

View File

@@ -4,7 +4,7 @@
<mapper namespace="com.senmesh.sfile.dao.UserFileMapper">
<select id="list" resultType="com.senmesh.sfile.dto.UserFileDTO">
SELECT t.*, fr.file_size
SELECT t.*, fr.file_size, fc.file_category
<include refid="queryFromSql"></include>
ORDER BY t.id DESC
</select>
@@ -12,6 +12,7 @@
<sql id="queryFromSql">
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
<if test='param.id != null'>
AND t.id = #{param.id}
@@ -42,8 +43,11 @@
AND t.file_status = #{param.fileStatus}
</if>
<if test='param.pathLike != null and param.pathLike.trim() != ""'>
<bind name="pathLike" value="param.pathLike + '%'"/>
AND t.path LIKE #{pathLike}
<bind name="pathLike" value="'%' + param.pathLike + '%'" />
AND t.path like #{pathLike}
</if>
<if test='param.fileCategory != null and param.fileCategory.trim() != ""'>
AND fc.file_category = #{param.fileCategory}
</if>
</sql>

View File

@@ -0,0 +1,22 @@
package com.senmesh.sfile.service;
/**
* 风险文件Service
*/
public interface RiskFileService {
/**
* 获取风险规则
*
* @return 风险规则配置值
*/
String getRiskRule();
/**
* 保存风险规则
*
* @param riskRule 风险规则配置值
*/
void saveRiskRule(String riskRule);
}

View File

@@ -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<UserFileDTO> list(Long id, String accessCode);
}

View File

@@ -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);
}
}
}

View File

@@ -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<UserFileDTO> 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());
}
}

View File

@@ -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<UserFileDTO> 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<UserFileDTO> filesToCopy = this.list(queryDTO);
// 4. 在文件夹下创建文件对象
List<UserFileDTO> createdFiles = new java.util.ArrayList<>();