|
@@ -0,0 +1,102 @@
|
|
|
|
+package com.jeeplus.test.oss.service;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
|
+import com.jeeplus.sys.utils.UserUtils;
|
|
|
|
+import com.jeeplus.test.oss.domain.WorkAttachment;
|
|
|
|
+import com.jeeplus.test.oss.mapper.OssServiceMapper;
|
|
|
|
+import com.jeeplus.test.oss.service.dto.OssServiceDto;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class OssService {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private OssServiceMapper ossServiceMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存数据
|
|
|
|
+ * @param dtos
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public void saveMsg(List<OssServiceDto> dtos) {
|
|
|
|
+ if (CollectionUtil.isNotEmpty(dtos)) {
|
|
|
|
+ //若数据有修改,先删除原有数据,再执行保存操作
|
|
|
|
+ String attachmentId = dtos.get(0).getAttachmentId();
|
|
|
|
+ log.info("开始执行删除操作,条件attachmentId值:{}" , attachmentId);
|
|
|
|
+ if (StringUtils.isNotEmpty(attachmentId)) {
|
|
|
|
+ LambdaQueryWrapper<WorkAttachment> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ lambdaQueryWrapper.eq(WorkAttachment::getAttachmentId, attachmentId);
|
|
|
|
+ int delete = ossServiceMapper.delete(lambdaQueryWrapper);
|
|
|
|
+ log.info("删除操作完成,共删除{}条数据" , attachmentId);
|
|
|
|
+ }
|
|
|
|
+ log.info("开始执行保存操作,入参:{}" , JSONObject.toJSONString(dtos));
|
|
|
|
+ //TODO:获取当前登录人信息
|
|
|
|
+ String id = UserUtils.getCurrentUserDTO().getId();
|
|
|
|
+ int i = 1;
|
|
|
|
+ for (OssServiceDto dto : dtos) {
|
|
|
|
+ WorkAttachment workAttachment = new WorkAttachment();
|
|
|
|
+ BeanUtils.copyProperties(dto,workAttachment);
|
|
|
|
+ //文件后缀名赋值
|
|
|
|
+ List<String> strings = Arrays.asList(dto.getUrl().split("\\."));
|
|
|
|
+ workAttachment.setType(strings.get(strings.size()-1));
|
|
|
|
+ workAttachment.setId(UUID.randomUUID().toString().replace("-",""));
|
|
|
|
+ //排序赋值
|
|
|
|
+ workAttachment.setSort(i);
|
|
|
|
+ //基础信息赋值
|
|
|
|
+ workAttachment.setCreateBy(id);
|
|
|
|
+ workAttachment.setCreateDate(new Date());
|
|
|
|
+ workAttachment.setUpdateBy(id);
|
|
|
|
+ workAttachment.setUpdateDate(new Date());
|
|
|
|
+ workAttachment.setDelFlag(0);
|
|
|
|
+ i++;
|
|
|
|
+ ossServiceMapper.insert(workAttachment);
|
|
|
|
+ }
|
|
|
|
+ log.info("保存操作执行完成");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据文件路径删除文件
|
|
|
|
+ * @param url
|
|
|
|
+ */
|
|
|
|
+ public void deleteMsgByFileName(String url) {
|
|
|
|
+ log.info("开始执行删除操作,入参:{}" , url);
|
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
|
+ map.put("url", url);
|
|
|
|
+ int i = ossServiceMapper.deleteByMap(map);
|
|
|
|
+ log.info("删除操作完成,共删除{}条数据" , i);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据附件对应父节点id查询文件列表
|
|
|
|
+ * @param attachmentId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<WorkAttachment> findFileList(String attachmentId) {
|
|
|
|
+ log.info("文件查询开始,入参:{}" , attachmentId);
|
|
|
|
+ LambdaQueryWrapper<WorkAttachment> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ lambdaQueryWrapper.eq(WorkAttachment::getAttachmentId, attachmentId);
|
|
|
|
+ lambdaQueryWrapper.orderByAsc(WorkAttachment::getSort);
|
|
|
|
+ List<WorkAttachment> list = ossServiceMapper.selectList(lambdaQueryWrapper);
|
|
|
|
+ //创建人和文件名称处理
|
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
|
+ for (WorkAttachment workAttachment : list) {
|
|
|
|
+ UserDTO userDTO = UserUtils.get(workAttachment.getCreateBy());
|
|
|
|
+ workAttachment.setCreateBy(userDTO.getName());
|
|
|
|
+ workAttachment.setAttachmentName(workAttachment.getAttachmentName()+"."+workAttachment.getType());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ log.info("文件查询结束,查询结果:{}" , JSONObject.toJSONString(list));
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+}
|