zhongrj
2024-12-24 64e6ac37d0bc034f849efa1d94792a7ef97c3adb
新增按前缀上传文件,相关查询修改
5 files modified
1 files added
147 ■■■■ changed files
src/main/java/org/springblade/modules/resource/builder/OssBuilder.java 58 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/rule/context/OssContext.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/rule/oss/MyOssRule.java 35 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/rule/oss/OssDataRule.java 22 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/service/impl/RiskSourceServiceImpl.java 14 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/builder/OssBuilder.java
@@ -1,19 +1,3 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.resource.builder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -28,14 +12,15 @@
import org.springblade.core.oss.enums.OssEnum;
import org.springblade.core.oss.enums.OssStatusEnum;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.modules.resource.entity.Oss;
import org.springblade.modules.resource.rule.context.OssContext;
import org.springblade.modules.resource.rule.oss.MyOssRule;
import org.springblade.modules.resource.service.IOssService;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -144,4 +129,43 @@
        }
    }
    /**
     * 获取template
     * @param prefixPath 上传文件前缀路径
     * @return OssTemplate
     */
    public OssTemplate templateByPrefix(String prefixPath) {
        return templateByPath(StringPool.EMPTY,prefixPath);
    }
    /**
     * 自定义路径前缀获取template
     *
     * @param code 资源编号
     * @param prefixPath 上传文件前缀路径
     * @return OssTemplate
     */
    public OssTemplate templateByPath(String code,String prefixPath) {
        String tenantId = AuthUtil.getTenantId();
        if (Strings.isBlank(tenantId)){
            tenantId = "000000";
        }
        Oss oss = getOss(tenantId, code);
        OssContext ossContext = new OssContext();
        ossContext.setPrefix(prefixPath);
        ossContext.setOss(oss);
        ossContext.setOssProperties(ossProperties);
        ossContext.setOssPool(ossPool);
        ossContext.setTemplatePool(templatePool);
        LiteflowResponse resp = flowExecutor.execute2Resp("ossChain", tenantId, ossContext);
        if (resp.isSuccess()) {
            OssContext contextBean = resp.getFirstContextBean();
            return contextBean.getOssTemplate();
        } else {
            throw new ServiceException("未获取到对应的对象存储配置");
        }
    }
}
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
@@ -170,6 +170,19 @@
     * @return ObjectStat
     */
    @SneakyThrows
    @PostMapping("/put-file-by-prefix")
    public R<BladeFile> putFileByPrefix(@RequestParam MultipartFile file,@RequestParam(required = false) String prefixPath) {
        BladeFile bladeFile = ossBuilder.templateByPrefix(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream());
        return R.data(bladeFile);
    }
    /**
     * 上传文件并保存至附件表
     *
     * @param file 文件
     * @return ObjectStat
     */
    @SneakyThrows
    @PostMapping("/put-file-attach")
    public R<BladeFile> putFileAttach(@RequestParam MultipartFile file) {
        String fileName = file.getOriginalFilename();
src/main/java/org/springblade/modules/resource/rule/context/OssContext.java
@@ -35,6 +35,11 @@
     * 是否有缓存
     */
    private Boolean isCached;
    /**
     * 前缀
     */
    private String prefix;
    /**
     * oss数据
     */
src/main/java/org/springblade/modules/resource/rule/oss/MyOssRule.java
New file
@@ -0,0 +1,35 @@
package org.springblade.modules.resource.rule.oss;
import org.apache.logging.log4j.util.Strings;
import org.springblade.core.oss.rule.BladeOssRule;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.FileUtil;
import org.springblade.core.tool.utils.StringUtil;
public class MyOssRule extends BladeOssRule {
    private String prefixPath;
    @Override
    public String bucketName(String bucketName) {
        return super.bucketName(bucketName);
    }
    public MyOssRule(Boolean tenantMode) {
        super(tenantMode);
    }
    public MyOssRule(Boolean tenantMode, String prefixPath) {
        super(tenantMode);
        if (!Strings.isBlank(prefixPath)) {
            this.prefixPath = prefixPath;
        }else {
            this.prefixPath = "upload";
        }
    }
    @Override
    public String fileName(String originalFilename) {
        return this.prefixPath + "/" + DateUtil.today() + "/" + StringUtil.randomUUID() + "." + FileUtil.getFileExtension(originalFilename);
    }
}
src/main/java/org/springblade/modules/resource/rule/oss/OssDataRule.java
@@ -1,25 +1,8 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.resource.rule.oss;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.BladeOssRule;
import org.springblade.modules.resource.rule.context.OssContext;
import org.springblade.modules.resource.entity.Oss;
@@ -33,13 +16,14 @@
    @Override
    public void process() throws Exception {
        OssContext contextBean = this.getContextBean(OssContext.class);
        String prefix = contextBean.getPrefix();
        Oss oss = contextBean.getOss();
        OssProperties ossProperties = contextBean.getOssProperties();
        // 若采用默认设置则开启多租户模式, 若是用户自定义oss则不开启
        if (oss.getEndpoint().equals(ossProperties.getEndpoint()) && oss.getAccessKey().equals(ossProperties.getAccessKey()) && ossProperties.getTenantMode()) {
            contextBean.setOssRule(new BladeOssRule(Boolean.TRUE));
            contextBean.setOssRule(new MyOssRule(Boolean.TRUE,prefix));
        } else {
            contextBean.setOssRule(new BladeOssRule(Boolean.FALSE));
            contextBean.setOssRule(new MyOssRule(Boolean.FALSE,prefix));
        }
    }
}
src/main/java/org/springblade/modules/yw/service/impl/RiskSourceServiceImpl.java
@@ -41,13 +41,13 @@
    @Override
    public IPage<RiskSourceVO> selectRiskSourcePage(IPage<RiskSourceVO> page, RiskSourceVO riskSource) {
        List<RiskSourceVO> riskSourceVOS = baseMapper.selectRiskSourcePage(page, riskSource);
        for (RiskSourceVO riskSourceVO : riskSourceVOS) {
            if (!Strings.isBlank(riskSourceVO.getCategory())){
                riskSourceVO.setCategory(
                    DictBizCache.getValues("industry_category",riskSourceVO.getCategory())
                );
            }
        }
//        for (RiskSourceVO riskSourceVO : riskSourceVOS) {
//            if (!Strings.isBlank(riskSourceVO.getCategory())){
//                riskSourceVO.setCategory(
//                    DictBizCache.getValues("industry_category",riskSourceVO.getCategory())
//                );
//            }
//        }
        return page.setRecords(riskSourceVOS);
    }