linwei
2024-02-21 86498f43cb9e6a5f8c58cca7b5c07a5ad1e23b2f
Merge remote-tracking branch 'origin/master'
5 files modified
1 files added
123 ■■■■■ changed files
src/main/java/org/springblade/common/param/CommonParamSet.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/house/mapper/HouseRentalMapper.xml 4 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/house/vo/HouseRentalTenantVO.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/builder/oss/OssBuilder.java 40 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java 37 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/rule/MyOssRule.java 35 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/param/CommonParamSet.java
@@ -57,7 +57,7 @@
                    communityCodeField.set(t,communityCode);
                }
            }
            isAdministrator = AuthUtil.isAdministrator() == true || AuthUtil.isAdmin() == true ? 1 : 2;
            isAdministrator = Strings.isBlank(roleName) && (AuthUtil.isAdministrator() == true || AuthUtil.isAdmin() == true) ? 1 : 2;
            if (isAdministrator==2) {
                // 获取当前用户的所属行政区划编号
                regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId());
src/main/java/org/springblade/modules/house/mapper/HouseRentalMapper.xml
@@ -61,13 +61,13 @@
                    <if test="vo.roleName=='wgy'">
                        <choose>
                            <when test="gridCodeList !=null and gridCodeList.size()>0">
                                and jp.grid_code in
                                and jh.grid_code in
                                <foreach collection="gridCodeList" item="code" open="(" close=")" separator=",">
                                    #{code}
                                </foreach>
                            </when>
                            <otherwise>
                                and jp.grid_code in ('')
                                and jh.grid_code in ('')
                            </otherwise>
                        </choose>
                    </if>
src/main/java/org/springblade/modules/house/vo/HouseRentalTenantVO.java
@@ -60,5 +60,10 @@
    private Long userId;
    /**
     * 社区编号
     */
    private String communityCode;
}
src/main/java/org/springblade/modules/resource/builder/oss/OssBuilder.java
@@ -32,7 +32,9 @@
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.endpoint.OssEndpoint;
import org.springblade.modules.resource.entity.Oss;
import org.springblade.modules.resource.rule.MyOssRule;
import org.springblade.modules.resource.service.IOssService;
import java.util.Map;
@@ -169,4 +171,42 @@
        }
    }
    /**
     * 获取template
     * @param prefixPath 上传文件前缀路径
     * @return OssTemplate
     */
    public OssTemplate templateByPrefixPath(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);
        OssTemplate template = templatePool.get(tenantId);
        template = templatePool.get(tenantId);
        OssRule ossRule = new MyOssRule(Boolean.FALSE,prefixPath);
        if (oss.getCategory() == OssEnum.MINIO.getCategory()) {
            template = MinioOssBuilder.template(oss, ossRule);
        } else if (oss.getCategory() == OssEnum.QINIU.getCategory()) {
            template = QiniuOssBuilder.template(oss, ossRule);
        } else if (oss.getCategory() == OssEnum.ALI.getCategory()) {
            template = AliOssBuilder.template(oss, ossRule);
        } else if (oss.getCategory() == OssEnum.TENCENT.getCategory()) {
            template = TencentOssBuilder.template(oss, ossRule);
        }
        templatePool.put(tenantId, template);
        ossPool.put(tenantId, oss);
        return template;
    }
}
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
@@ -206,7 +206,7 @@
     */
    @SneakyThrows
    @PostMapping("/put-file-attach-by-name")
    public R<BladeFile> putFileAttach(@RequestParam String fileName, @RequestParam MultipartFile file) {
    public R<BladeFile> putFileAttach(@RequestParam(required = false) String fileName, @RequestParam MultipartFile file) {
        BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
        Long attachId = buildAttach(fileName, file.getSize(), bladeFile);
        bladeFile.setAttachId(attachId);
@@ -214,6 +214,41 @@
    }
    /**
     * 自定义前缀上传文件
     *
     * @param file 文件
     * @param prefixPath 文件
     * @return ObjectStat
     */
    @SneakyThrows
    @PostMapping("/put-file-by-prefix-path")
    public R<BladeFile> putFileByPrefixPath(@RequestParam MultipartFile file,@RequestParam(required = false) String prefixPath) {
        BladeFile bladeFile = ossBuilder.templateByPrefixPath(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream());
        // 修改link
        changeLink(bladeFile);
        return R.data(bladeFile);
    }
    /**
     * 自定义前缀上传文件并保存至附件表
     *
     * @param file 文件
     * @param prefixPath 文件
     * @return ObjectStat
     */
    @SneakyThrows
    @PostMapping("/put-file-attach-by-prefix-path")
    public R<BladeFile> putFileAttachByPrefixPath(@RequestParam MultipartFile file,@RequestParam(required = false) String prefixPath) {
        String fileName = file.getOriginalFilename();
        BladeFile bladeFile = ossBuilder.templateByPrefixPath(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream());
        Long attachId = buildAttach(fileName, file.getSize(), bladeFile);
        bladeFile.setAttachId(attachId);
        // 修改link
        changeLink(bladeFile);
        return R.data(bladeFile);
    }
    /**
     * 构建附件表
     *
     * @param fileName  文件名
src/main/java/org/springblade/modules/resource/rule/MyOssRule.java
New file
@@ -0,0 +1,35 @@
package org.springblade.modules.resource.rule;
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);
    }
}