|
@@ -3,18 +3,20 @@ package com.kym.service.miniapp.impl;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.lang.UUID;
|
|
import cn.hutool.core.lang.UUID;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
import com.kym.common.utils.CommUtil;
|
|
|
|
|
+import com.kym.common.utils.OssUtil;
|
|
|
import com.kym.entity.miniapp.Attachment;
|
|
import com.kym.entity.miniapp.Attachment;
|
|
|
import com.kym.mapper.miniapp.AttachmentMapper;
|
|
import com.kym.mapper.miniapp.AttachmentMapper;
|
|
|
import com.kym.service.miniapp.AttachmentService;
|
|
import com.kym.service.miniapp.AttachmentService;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -48,19 +50,36 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentMapper, Attachm
|
|
|
attachment.setSize(file.getSize());
|
|
attachment.setSize(file.getSize());
|
|
|
attachment.setUuid(UUID.fastUUID().toString(true) + "." + FileUtil.getSuffix(fileName));
|
|
attachment.setUuid(UUID.fastUUID().toString(true) + "." + FileUtil.getSuffix(fileName));
|
|
|
attachment.setUploadBy(userId);
|
|
attachment.setUploadBy(userId);
|
|
|
|
|
+// attachment.setUploadName("admin");
|
|
|
attachment.setUploadName(CommUtil.null2String(StpUtil.getSession().get("username")));
|
|
attachment.setUploadName(CommUtil.null2String(StpUtil.getSession().get("username")));
|
|
|
attachment.setIsDelete(false);
|
|
attachment.setIsDelete(false);
|
|
|
|
|
|
|
|
String applicationPath = System.getProperty("user.dir");
|
|
String applicationPath = System.getProperty("user.dir");
|
|
|
|
|
|
|
|
- File dir = new File(applicationPath,fileStoragePath);
|
|
|
|
|
- if(!dir.exists()){
|
|
|
|
|
- CommUtil.asserts(dir.mkdirs(),"文件上传异常");
|
|
|
|
|
|
|
+ File dir = new File(applicationPath, fileStoragePath);
|
|
|
|
|
+ if (!dir.exists()) {
|
|
|
|
|
+ CommUtil.asserts(dir.mkdirs(), "文件上传异常");
|
|
|
}
|
|
}
|
|
|
- File storeFile = new File(dir,attachment.getUuid());
|
|
|
|
|
|
|
+ File storeFile = new File(dir, attachment.getUuid());
|
|
|
file.transferTo(storeFile);
|
|
file.transferTo(storeFile);
|
|
|
|
|
|
|
|
|
|
+ OssUtil.upload(attachment.getUuid(), storeFile);
|
|
|
|
|
+
|
|
|
baseMapper.insert(attachment);
|
|
baseMapper.insert(attachment);
|
|
|
return attachment;
|
|
return attachment;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void delete(String fileId) {
|
|
|
|
|
+ StpUtil.checkLogin();
|
|
|
|
|
+ Long userId = CommUtil.null2Long(StpUtil.getSession().get("userId"));
|
|
|
|
|
+ Attachment attachment = baseMapper.selectOne(Wrappers.query(Attachment.class).eq("uuid", fileId));
|
|
|
|
|
+ CommUtil.asserts(null!=attachment&& Objects.equals(attachment.getUploadBy(), userId),"无删除权限");
|
|
|
|
|
+ String applicationPath = System.getProperty("user.dir");
|
|
|
|
|
+
|
|
|
|
|
+ File dir = new File(applicationPath, fileStoragePath);
|
|
|
|
|
+ File storeFile = new File(dir, fileId);
|
|
|
|
|
+ storeFile.delete();
|
|
|
|
|
+ OssUtil.delete(fileId);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|