| | |
| | | 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 java.io.IOException; |
| | | |
| | | import org.apache.commons.io.FileUtils; |
| | | import com.qianwen.smartman.common.constant.ExcelConstant; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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.common.constant.ExcelConstant; |
| | | 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; |
| | | |
| | | import me.zhyd.oauth.log.Log; |
| | | |
| | | @Service |
| | | /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/resource/service/impl/SystemResourceServiceImpl.class */ |
| | |
| | | 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; |
| | |
| | | |
| | | @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; |
| | | try { |
| | | String fileName = templateEnum.getFileName() + ExcelConstant.SUFFIX; |
| | | Attach target = this.attachService.getOne((new QueryWrapper<Attach>()).lambda().eq(Attach::getOriginalName, fileName)); |
| | | /* |
| | | 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; |
| | | } catch (IOException e) { |
| | | Log.error("获取业务模板失败",e); |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |