| 
					
				 | 
			
			
				@@ -1,14 +1,14 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package org.springblade.business.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.hutool.core.date.DateTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.core.util.ReflectUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.toolkit.Wrappers; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springblade.business.entity.StandardFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.business.entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springblade.business.service.StandardFileService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springblade.business.dto.PrivateStandardDTO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springblade.business.entity.PrivateStandard; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springblade.business.entity.StandardInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springblade.business.mapper.StandardInfoJoinMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springblade.business.mapper.StandardInfoMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springblade.business.mapper.StandardInfoPrivateJoinMapper; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -27,10 +27,17 @@ import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.multipart.MultipartFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.annotation.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.FileInputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.FileNotFoundException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.io.InputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.net.URL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.time.LocalDateTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @author LHB 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -288,6 +295,122 @@ public class PrivateStandardServiceImpl extends ServiceImpl<PrivateStandardMappe 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw new ServiceException("更新失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public boolean standardUpdate(Long id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BladeUser user = SecureUtil.getUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //获取当前规范文件信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        PrivateStandard privateStandard = baseMapper.selectById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //获取信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<StandardInfo> standardInfos = standardInfoMapper.selectList(Wrappers.<StandardInfo>lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(StandardInfo::getStandardId, id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(StandardInfo::getIsDeleted, 0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Long> infoIds = standardInfos.stream().filter(f -> f.getType() == 2).map(StandardInfo::getId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //获取绑定信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<StandardInfoJoin> standardInfoJoins = standardInfoJoinMapper.selectList(Wrappers.<StandardInfoJoin>lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .in(StandardInfoJoin::getStandardInfoLeftId, infoIds)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //获取绑定表单信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<StandardInfoPrivateJoin> standardInfoPrivateJoins = standardInfoPrivateJoinMapper.selectList(Wrappers.<StandardInfoPrivateJoin>lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .in(StandardInfoPrivateJoin::getStandardInfoId, infoIds)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //获取文件信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<StandardFile> standardFiles = standardFileService.list(Wrappers.<StandardFile>lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(StandardFile::getStandardId, id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(StandardFile::getIsDeleted, 0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //复制数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //新规范文件id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long newId = SnowFlakeUtil.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        privateStandard.setId(newId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (privateStandard.getStatus() == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            privateStandard.setName(privateStandard.getName().replace("-已过期","")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            privateStandard.setStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        privateStandard.setCreateTime(LocalDateTime.now()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        privateStandard.setCreateUser(user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //修改之前的规则为过期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        baseMapper.updateStatus(privateStandard.getParentId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        baseMapper.insert(privateStandard); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //旧id与新id的映射关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<Long, Long> map = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        standardInfos.forEach(f -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Long newInfoId = SnowFlakeUtil.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            map.put(f.getId(),newInfoId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        standardInfos.forEach(f -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setId(map.get(f.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setParentId(map.get(f.getParentId())==null?0:map.get(f.getParentId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setStandardId(newId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setCreateTime(DateTime.now()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setCreateUser(user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            standardInfoMapper.insert(f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        standardInfoJoins.forEach(f -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setId(SnowFlakeUtil.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setStandardInfoLeftId(map.get(f.getStandardInfoLeftId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setStandardInfoRightId(map.get(f.getStandardInfoRightId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setCreateTime(DateTime.now()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setCreateUser(user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            standardInfoJoinMapper.insert(f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        standardInfoPrivateJoins.forEach(f -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setId(SnowFlakeUtil.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setStandardInfoId(map.get(f.getStandardInfoId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setCreateTime(DateTime.now()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.setCreateUser(user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            standardInfoPrivateJoinMapper.insert(f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //文件集合 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<String> urls = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (StandardFile f : standardFiles) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                f.setId(SnowFlakeUtil.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                f.setStandardId(newId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                f.setCreateTime(DateTime.now()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                f.setCreateUser(user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(StringUtils.isNotEmpty(f.getStandardFileUrl())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    URL urlFile = new URL(f.getStandardFileUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    InputStream inputStream = urlFile.openStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    String originalFilename = "standard/" + f.getId() + "|" + f.getFileName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    MockMultipartFile multipartFile = new MockMultipartFile("file", originalFilename, "application/pdf", inputStream); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    //Oss上传 传特殊文件名 在oss中做特殊路径处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    BladeFile bladeFile = newIOSSClient.uploadFileByInputStream(multipartFile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (bladeFile == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        throw new ServiceException("Oss异常"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    f.setStandardFileUrl(bladeFile.getLink()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    urls.add(bladeFile.getLink()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (String url : urls) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String pdfName = url.split("upload")[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                this.newIOSSClient.removeFile("upload" + pdfName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new ServiceException("Oss异常"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        standardFileService.saveBatch(standardFiles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |