yangys
2024-03-27 e48aa2ac8dea1be5db11c63edf0b912c4ad5ce65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.qianwen.smartman.modules.resource.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.io.File;
import java.lang.invoke.SerializedLambda;
import org.apache.commons.io.FileUtils;
import com.qianwen.smartman.common.constant.ExcelConstant;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.tool.utils.FileUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import com.qianwen.smartman.modules.resource.convert.AttachConvert;
import com.qianwen.smartman.modules.resource.entity.Attach;
import com.qianwen.smartman.modules.resource.enums.TemplateEnum;
import com.qianwen.smartman.modules.resource.service.IAttachService;
import com.qianwen.smartman.modules.resource.service.ISystemResourceService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/resource/service/impl/SystemResourceServiceImpl.class */
public class SystemResourceServiceImpl implements ISystemResourceService {
    private final OssBuilder ossBuilder;
    private final IAttachService attachService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -530662798:
                if (implMethodName.equals("getOriginalName")) {
                    z = false;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/resource/entity/Attach") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getOriginalName();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public SystemResourceServiceImpl(final OssBuilder ossBuilder, final IAttachService attachService) {
        this.ossBuilder = ossBuilder;
        this.attachService = attachService;
    }
 
    @Override // org.springblade.modules.resource.service.ISystemResourceService
    public BladeFile getBusinessTemplateInfo(TemplateEnum templateEnum) {
        String fileName = templateEnum.getFileName() + ExcelConstant.SUFFIX;
        Attach target = (Attach) this.attachService.getOne((Wrapper) new QueryWrapper().lambda().eq((v0) -> {
            return v0.getOriginalName();
        }, fileName));
        if (!Func.isEmpty(target)) {
            return AttachConvert.INSTANCE.convert(target);
        }
        ClassPathResource classPathResource = new ClassPathResource(ExcelConstant.DIRECTORY + fileName);
        File file = new File(System.getProperty("java.io.tmpdir") + "/" + fileName);
        FileUtils.copyToFile(classPathResource.getInputStream(), file);
        MultipartFile multipartFile = ExcelUtil.fileToMultipartFile(file);
        BladeFile bladeFile = this.ossBuilder.systemTemplate().putFile(fileName, multipartFile);
        String fileExtension = FileUtil.getFileExtension(fileName);
        Attach attach = new Attach();
        attach.setDomainName(bladeFile.getDomain());
        attach.setLink(bladeFile.getLink());
        attach.setName(bladeFile.getName());
        attach.setOriginalName(bladeFile.getOriginalName());
        attach.setAttachSize(Long.valueOf(multipartFile.getSize()));
        attach.setExtension(fileExtension);
        this.attachService.save(attach);
        return bladeFile;
    }
}