|
@@ -2,6 +2,9 @@ package org.springblade.business.service.impl;
|
|
|
|
|
|
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.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;
|
|
@@ -9,22 +12,29 @@ import org.springblade.business.mapper.StandardInfoMapper;
|
|
|
import org.springblade.business.mapper.StandardInfoPrivateJoinMapper;
|
|
|
import org.springblade.business.service.PrivateStandardService;
|
|
|
import org.springblade.business.mapper.PrivateStandardMapper;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.secure.BladeUser;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.resource.feign.NewIOSSClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
-* @author LHB
|
|
|
-* @description 针对表【u_wbs_private_standard(规范文件夹及规范文件表)】的数据库操作Service实现
|
|
|
-* @createDate 2025-06-10 10:48:37
|
|
|
-*/
|
|
|
+ * @author LHB
|
|
|
+ * @description 针对表【u_wbs_private_standard(规范文件夹及规范文件表)】的数据库操作Service实现
|
|
|
+ * @createDate 2025-06-10 10:48:37
|
|
|
+ */
|
|
|
@Service
|
|
|
public class PrivateStandardServiceImpl extends ServiceImpl<PrivateStandardMapper, PrivateStandard>
|
|
|
- implements PrivateStandardService {
|
|
|
+ implements PrivateStandardService {
|
|
|
@Resource
|
|
|
private StandardInfoMapper standardInfoMapper;
|
|
|
@Resource
|
|
@@ -32,19 +42,118 @@ public class PrivateStandardServiceImpl extends ServiceImpl<PrivateStandardMappe
|
|
|
@Resource
|
|
|
private StandardInfoPrivateJoinMapper standardInfoPrivateJoinMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private StandardFileService standardFileService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对象存储构建类
|
|
|
+ */
|
|
|
+ @Resource
|
|
|
+ private NewIOSSClient newIOSSClient;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean insert(PrivateStandard uWbsPrivateStandard) {
|
|
|
+ public boolean insert(PrivateStandardDTO uWbsPrivateStandard) {
|
|
|
BladeUser user = SecureUtil.getUser();
|
|
|
uWbsPrivateStandard.setCreateUser(user.getUserId());
|
|
|
- if(uWbsPrivateStandard.getType() == 2){
|
|
|
+ Boolean isUploadFile = false;
|
|
|
+ if (uWbsPrivateStandard.getType() == 2 && uWbsPrivateStandard.getFiles().length > 0) {
|
|
|
+ isUploadFile = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //先上传文件,上传成功在执行添加
|
|
|
+ if (isUploadFile) {
|
|
|
+ List<StandardFile> standardFiles = new ArrayList<>();
|
|
|
+ MultipartFile[] files = uWbsPrivateStandard.getFiles();
|
|
|
+
|
|
|
+ try {
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ StandardFile standardFile = new StandardFile();
|
|
|
+ standardFile.setId(SnowFlakeUtil.getId());
|
|
|
+ standardFile.setStandardId(uWbsPrivateStandard.getId());
|
|
|
+ standardFile.setCreateUser(user.getUserId());
|
|
|
+
|
|
|
+
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ standardFile.setFileName(originalFilename);
|
|
|
+ originalFilename = "standard/" + uWbsPrivateStandard.getId() + "|" + originalFilename;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //Oss上传 传特殊文件名 在oss中做特殊路径处理
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFileByInputStream2(file.getOriginalFilename(), file.getInputStream());
|
|
|
+
|
|
|
+ standardFile.setStandardFileUrl(bladeFile.getLink());
|
|
|
+ standardFiles.add(standardFile);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ //删除之前上传的文件
|
|
|
+ for (StandardFile standardFile : standardFiles) {
|
|
|
+ this.newIOSSClient.removeFile(standardFile.getStandardFileUrl());
|
|
|
+ }
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("文件上传失败!请检查Oss");
|
|
|
+ }
|
|
|
+ standardFileService.saveBatch(standardFiles);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (uWbsPrivateStandard.getType() == 2) {
|
|
|
//修改之前的规则为过期
|
|
|
baseMapper.updateStatus(uWbsPrivateStandard.getParentId());
|
|
|
}
|
|
|
return baseMapper.insert(uWbsPrivateStandard) > 0;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean update(List<PrivateStandardDTO> privateStandards) {
|
|
|
+ BladeUser user = SecureUtil.getUser();
|
|
|
+
|
|
|
+ List<PrivateStandard> privateStandards1 = new ArrayList<>();
|
|
|
+
|
|
|
+ for (PrivateStandardDTO privateStandard : privateStandards) {
|
|
|
+ List<StandardFile> standardFiles = new ArrayList<>();
|
|
|
+ MultipartFile[] files = privateStandard.getFiles();
|
|
|
+
|
|
|
+ try {
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ StandardFile standardFile = new StandardFile();
|
|
|
+ standardFile.setId(SnowFlakeUtil.getId());
|
|
|
+ standardFile.setStandardId(privateStandard.getId());
|
|
|
+ standardFile.setCreateUser(user.getUserId());
|
|
|
+
|
|
|
+
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ standardFile.setFileName(originalFilename);
|
|
|
+ originalFilename = "standard/" + privateStandard.getId() + "|" + originalFilename;
|
|
|
+
|
|
|
+ //Oss上传 传特殊文件名 在oss中做特殊路径处理
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFileByInputStream2(originalFilename, file.getInputStream());
|
|
|
+
|
|
|
+ standardFile.setStandardFileUrl(bladeFile.getLink());
|
|
|
+ standardFiles.add(standardFile);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ //删除之前上传的文件
|
|
|
+ for (StandardFile standardFile : standardFiles) {
|
|
|
+ this.newIOSSClient.removeFile(standardFile.getStandardFileUrl());
|
|
|
+ }
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("文件上传失败!请检查Oss");
|
|
|
+ }
|
|
|
+
|
|
|
+ standardFileService.saveBatch(standardFiles);
|
|
|
+
|
|
|
+
|
|
|
+ PrivateStandard privateStandard1 = BeanUtil.copyProperties(privateStandard, PrivateStandard.class);
|
|
|
+ privateStandards1.add(privateStandard1);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.updateBatchById(privateStandards1);
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean delete(Long id) {
|
|
@@ -62,21 +171,40 @@ public class PrivateStandardServiceImpl extends ServiceImpl<PrivateStandardMappe
|
|
|
//TODO 后续还要删除规范详细信息
|
|
|
|
|
|
|
|
|
-
|
|
|
int update1 = standardInfoMapper.update(null, Wrappers.<StandardInfo>lambdaUpdate()
|
|
|
.set(StandardInfo::getIsDeleted, 1)
|
|
|
.set(StandardInfo::getUpdateUser, user.getUserId())
|
|
|
.eq(StandardInfo::getStandardId, id));
|
|
|
//TODO 还要删除关联信息
|
|
|
- standardInfoJoinMapper.updateJoin(user.getUserId(),1,id);
|
|
|
+ standardInfoJoinMapper.updateJoin(user.getUserId(), 1, id);
|
|
|
//TODo 还要删除与表单的关联信息
|
|
|
- standardInfoPrivateJoinMapper.updateJoin(user.getUserId(),1,id);
|
|
|
+ standardInfoPrivateJoinMapper.updateJoin(user.getUserId(), 1, id);
|
|
|
return update > 0;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
throw new ServiceException("删除失败");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean deleteFile(Long id) {
|
|
|
+ StandardFile byId = standardFileService.getById(id);
|
|
|
+ if (byId != null) {
|
|
|
+ try {
|
|
|
+ this.newIOSSClient.removeFile(byId.getStandardFileUrl());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("文件删除失败,Oss异常");
|
|
|
+ }
|
|
|
+ standardFileService.update(Wrappers.<StandardFile>lambdaUpdate()
|
|
|
+ .set(StandardFile::getIsDeleted, 1)
|
|
|
+ .set(StandardFile::getUpdateUser, SecureUtil.getUser().getUserId())
|
|
|
+ .eq(StandardFile::getId, id));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|