|
@@ -6,10 +6,7 @@ import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.dao.TBAttachmentMapper;
|
|
import com.qmth.themis.business.dao.TBAttachmentMapper;
|
|
import com.qmth.themis.business.entity.TBAttachment;
|
|
import com.qmth.themis.business.entity.TBAttachment;
|
|
import com.qmth.themis.business.service.TBAttachmentService;
|
|
import com.qmth.themis.business.service.TBAttachmentService;
|
|
-import com.qmth.themis.business.util.JacksonUtil;
|
|
|
|
import com.qmth.themis.business.util.OssUtil;
|
|
import com.qmth.themis.business.util.OssUtil;
|
|
-import com.qmth.themis.business.util.RedisUtil;
|
|
|
|
-import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
@@ -17,7 +14,6 @@ import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
-import org.springframework.util.FileCopyUtils;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -47,24 +43,27 @@ public class TBAttachmentServiceImpl extends ServiceImpl<TBAttachmentMapper, TBA
|
|
* @param file
|
|
* @param file
|
|
* @param md5
|
|
* @param md5
|
|
* @param path
|
|
* @param path
|
|
|
|
+ * @param map
|
|
|
|
+ * @param orgId
|
|
|
|
+ * @param userId
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public TBAttachment saveAttachment(MultipartFile file, String md5, String path) throws IOException {
|
|
|
|
|
|
+ public TBAttachment saveAttachment(MultipartFile file, String md5, String path, Map<String, Object> map, Long orgId, Long userId) throws IOException {
|
|
TBAttachment tbAttachment = null;
|
|
TBAttachment tbAttachment = null;
|
|
try {
|
|
try {
|
|
int temp = file.getOriginalFilename().indexOf(".");
|
|
int temp = file.getOriginalFilename().indexOf(".");
|
|
String fileName = file.getOriginalFilename().substring(0, temp);
|
|
String fileName = file.getOriginalFilename().substring(0, temp);
|
|
String format = file.getOriginalFilename().substring(temp, file.getOriginalFilename().length());
|
|
String format = file.getOriginalFilename().substring(temp, file.getOriginalFilename().length());
|
|
-// List<String> attachmentTypeList = dictionaryConfig.sysDomain().getAttachmentType();
|
|
|
|
-// if (Objects.nonNull(format)) {
|
|
|
|
-// long count = attachmentTypeList.stream().filter(s -> format.equalsIgnoreCase(s)).count();
|
|
|
|
-// if (count == 0) {
|
|
|
|
-// throw new BusinessException("文件格式只能为" + attachmentTypeList.toString());
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
|
|
+ List<String> attachmentTypeList = (List<String>) map.get(SystemConstant.ATTACHMENT_TYPE);
|
|
|
|
+ if (Objects.nonNull(format)) {
|
|
|
|
+ long count = attachmentTypeList.stream().filter(s -> format.equalsIgnoreCase(s)).count();
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ throw new BusinessException("文件格式只能为" + attachmentTypeList.toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
long size = file.getSize();
|
|
long size = file.getSize();
|
|
BigDecimal b = new BigDecimal(size);
|
|
BigDecimal b = new BigDecimal(size);
|
|
BigDecimal num = new BigDecimal(1024);
|
|
BigDecimal num = new BigDecimal(1024);
|
|
@@ -92,19 +91,18 @@ public class TBAttachmentServiceImpl extends ServiceImpl<TBAttachmentMapper, TBA
|
|
tbAttachment.setSize(b);
|
|
tbAttachment.setSize(b);
|
|
tbAttachment.setMd5(fileMd5);
|
|
tbAttachment.setMd5(fileMd5);
|
|
|
|
|
|
- boolean oss = true;
|
|
|
|
-// boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
|
|
|
+ boolean oss = (boolean) map.get(SystemConstant.OSS);
|
|
LocalDateTime nowTime = LocalDateTime.now();
|
|
LocalDateTime nowTime = LocalDateTime.now();
|
|
StringJoiner stringJoiner = new StringJoiner("")
|
|
StringJoiner stringJoiner = new StringJoiner("")
|
|
-// .add(dictionaryConfig.sysDomain().getLocalhostPath())
|
|
|
|
-// .add(File.separator).add(String.valueOf(schoolId))
|
|
|
|
|
|
+ .add(String.valueOf(map.get(SystemConstant.LOCALHOST_PATH)))
|
|
|
|
+ .add(File.separator).add(String.valueOf(orgId))
|
|
.add(File.separator).add(String.valueOf(nowTime.getYear()))
|
|
.add(File.separator).add(String.valueOf(nowTime.getYear()))
|
|
.add(File.separator).add(String.valueOf(nowTime.getMonthValue()))
|
|
.add(File.separator).add(String.valueOf(nowTime.getMonthValue()))
|
|
.add(File.separator).add(String.valueOf(nowTime.getDayOfMonth()));
|
|
.add(File.separator).add(String.valueOf(nowTime.getDayOfMonth()));
|
|
if (oss) {//上传至oss
|
|
if (oss) {//上传至oss
|
|
stringJoiner.add(File.separator).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
|
|
stringJoiner.add(File.separator).add(String.valueOf(UUID.randomUUID()).replaceAll("-", ""))
|
|
.add(tbAttachment.getType());
|
|
.add(tbAttachment.getType());
|
|
-// ossUtil.ossUpload(stringJoiner.toString(), file.getInputStream());
|
|
|
|
|
|
+ ossUtil.ossUpload(map, stringJoiner.toString(), file.getInputStream());
|
|
} else {//上传至服务器
|
|
} else {//上传至服务器
|
|
File mkdir = new File(stringJoiner.toString());
|
|
File mkdir = new File(stringJoiner.toString());
|
|
if (!mkdir.exists()) {
|
|
if (!mkdir.exists()) {
|
|
@@ -122,15 +120,11 @@ public class TBAttachmentServiceImpl extends ServiceImpl<TBAttachmentMapper, TBA
|
|
}
|
|
}
|
|
jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
|
|
jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
|
|
tbAttachment.setRemark(jsonObject.toJSONString());
|
|
tbAttachment.setRemark(jsonObject.toJSONString());
|
|
-// TcPBasicUser currentUser = (TcPBasicUser) RedisUtil.getUser(userId);
|
|
|
|
-// if (Objects.isNull(currentUser)) {
|
|
|
|
-// throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
|
|
|
|
-// }
|
|
|
|
-// tbAttachment.setCreateId(currentUser.getId());
|
|
|
|
|
|
+ tbAttachment.setCreateId(userId);
|
|
this.save(tbAttachment);
|
|
this.save(tbAttachment);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- deleteAttachment(tbAttachment);
|
|
|
|
|
|
+ deleteAttachment(map, tbAttachment);
|
|
if (e instanceof BusinessException) {
|
|
if (e instanceof BusinessException) {
|
|
throw new BusinessException(e.getMessage());
|
|
throw new BusinessException(e.getMessage());
|
|
} else {
|
|
} else {
|
|
@@ -143,15 +137,16 @@ public class TBAttachmentServiceImpl extends ServiceImpl<TBAttachmentMapper, TBA
|
|
/**
|
|
/**
|
|
* 删除附件
|
|
* 删除附件
|
|
*
|
|
*
|
|
|
|
+ * @param map
|
|
* @param tbAttachment
|
|
* @param tbAttachment
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public void deleteAttachment(TBAttachment tbAttachment) {
|
|
|
|
|
|
+ public void deleteAttachment(Map<String, Object> map, TBAttachment tbAttachment) {
|
|
if (Objects.nonNull(tbAttachment) && Objects.nonNull(tbAttachment.getRemark())) {
|
|
if (Objects.nonNull(tbAttachment) && Objects.nonNull(tbAttachment.getRemark())) {
|
|
JSONObject jsonObject = JSONObject.parseObject(tbAttachment.getRemark());
|
|
JSONObject jsonObject = JSONObject.parseObject(tbAttachment.getRemark());
|
|
String type = String.valueOf(jsonObject.get(SystemConstant.TYPE));
|
|
String type = String.valueOf(jsonObject.get(SystemConstant.TYPE));
|
|
if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.OSS)) {//删除阿里云附件
|
|
if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.OSS)) {//删除阿里云附件
|
|
-// ossUtil.ossDelete(jsonObject.get(SystemConstant.PATH).toString());
|
|
|
|
|
|
+ ossUtil.ossDelete(map, jsonObject.get(SystemConstant.PATH).toString());
|
|
} else {//删除服务器附件
|
|
} else {//删除服务器附件
|
|
File file = new File(jsonObject.get(SystemConstant.PATH).toString());
|
|
File file = new File(jsonObject.get(SystemConstant.PATH).toString());
|
|
file.delete();
|
|
file.delete();
|
|
@@ -163,21 +158,22 @@ public class TBAttachmentServiceImpl extends ServiceImpl<TBAttachmentMapper, TBA
|
|
* 批量删除附件
|
|
* 批量删除附件
|
|
*
|
|
*
|
|
* @param map
|
|
* @param map
|
|
|
|
+ * @param list
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public void batchDeleteAttachment(List<Map> map) {
|
|
|
|
|
|
+ public void batchDeleteAttachment(Map<String, Object> map, List<Map> list) {
|
|
List<String> paths = null;
|
|
List<String> paths = null;
|
|
String type = null;
|
|
String type = null;
|
|
if (Objects.nonNull(map)) {
|
|
if (Objects.nonNull(map)) {
|
|
paths = new ArrayList<>();
|
|
paths = new ArrayList<>();
|
|
- for (Map m : map) {
|
|
|
|
|
|
+ for (Map m : list) {
|
|
JSONObject jsonObject = JSONObject.parseObject((String) m.get("remark"));
|
|
JSONObject jsonObject = JSONObject.parseObject((String) m.get("remark"));
|
|
type = (String) jsonObject.get("type");
|
|
type = (String) jsonObject.get("type");
|
|
paths.add((String) jsonObject.get("path"));
|
|
paths.add((String) jsonObject.get("path"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.OSS)) {//删除阿里云附件
|
|
if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.OSS)) {//删除阿里云附件
|
|
-// ossUtil.ossBatchDelete(paths);
|
|
|
|
|
|
+ ossUtil.ossBatchDelete(map, paths);
|
|
} else if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.LOCAL)) {//删除服务器附件
|
|
} else if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.LOCAL)) {//删除服务器附件
|
|
for (String s : paths) {
|
|
for (String s : paths) {
|
|
File file = new File(s);
|
|
File file = new File(s);
|