|
@@ -1,20 +1,28 @@
|
|
|
package cn.cslg.pas.service.business;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.business.AssoTaskFileDTO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.Personnel;
|
|
|
import cn.cslg.pas.common.model.cronModel.PersonnelVO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.SystemFile;
|
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.common.vo.business.AssoTaskFileVO;
|
|
|
import cn.cslg.pas.domain.business.AssoTaskFile;
|
|
|
import cn.cslg.pas.exception.UnLoginException;
|
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import cn.cslg.pas.mapper.AssoTaskFileMapper;
|
|
|
+import cn.cslg.pas.service.common.FileManagerService;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 任务与文件关联表的Service
|
|
@@ -29,15 +37,21 @@ public class AssoTaskFileService extends ServiceImpl<AssoTaskFileMapper, AssoTas
|
|
|
@Autowired
|
|
|
private LoginUtils loginUtils;
|
|
|
|
|
|
- public Integer addTaskFile(AssoTaskFileDTO assoTaskFileDTO){
|
|
|
+ @Autowired
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加任务与文件关联
|
|
|
+ * @param assoTaskFileDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Integer> addTaskFile(AssoTaskFileDTO assoTaskFileDTO){
|
|
|
if (assoTaskFileDTO.getTaskId() == null) {
|
|
|
throw new XiaoShiException("任务id不能为空");
|
|
|
}
|
|
|
- if (assoTaskFileDTO.getFileGuid() == null || assoTaskFileDTO.getFileGuid() == "") {
|
|
|
- throw new XiaoShiException("文件id不能为空");
|
|
|
+ if (assoTaskFileDTO.getFileGuids() == null || assoTaskFileDTO.getFileGuids().size() == 0) {
|
|
|
+ throw new XiaoShiException("文件ids不能为空");
|
|
|
}
|
|
|
- AssoTaskFile assoTaskFile = new AssoTaskFile();
|
|
|
- BeanUtils.copyProperties(assoTaskFileDTO, assoTaskFile);
|
|
|
//获取登陆人信息 用于设置创建人
|
|
|
PersonnelVO personnelVO = new PersonnelVO();
|
|
|
try {
|
|
@@ -45,22 +59,58 @@ public class AssoTaskFileService extends ServiceImpl<AssoTaskFileMapper, AssoTas
|
|
|
} catch (Exception e) {
|
|
|
throw new UnLoginException("未登录");
|
|
|
}
|
|
|
- assoTaskFile.setCreateId(personnelVO.getId());
|
|
|
- assoTaskFile.insert();
|
|
|
- return assoTaskFile.getId();
|
|
|
+ List<String> fileGuids = assoTaskFileDTO.getFileGuids();
|
|
|
+ List<AssoTaskFile> assoTaskFiles = new ArrayList<>();
|
|
|
+ for (String item : fileGuids) {
|
|
|
+ AssoTaskFile assoTaskFile = new AssoTaskFile();
|
|
|
+ BeanUtils.copyProperties(assoTaskFileDTO, assoTaskFile);
|
|
|
+ assoTaskFile.setFileGuid(item);
|
|
|
+ assoTaskFile.setCreateId(personnelVO.getId());
|
|
|
+ assoTaskFiles.add(assoTaskFile);
|
|
|
+ }
|
|
|
+ this.saveBatch(assoTaskFiles);
|
|
|
+ List<Integer> ids = assoTaskFiles.stream().map(AssoTaskFile::getId).collect(Collectors.toList());
|
|
|
+ return ids;
|
|
|
}
|
|
|
|
|
|
- public List<AssoTaskFile> getAssoTaskFile(Integer taskId) {
|
|
|
- if (taskId != null) {
|
|
|
- LambdaQueryWrapper<AssoTaskFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(AssoTaskFile::getTaskId, taskId);
|
|
|
- List<AssoTaskFile> assoTaskFiles = this.list(queryWrapper);
|
|
|
- return assoTaskFiles;
|
|
|
- } else {
|
|
|
- throw new XiaoShiException("任务id不能为空");
|
|
|
+ /**
|
|
|
+ * 查询文件与任务关联
|
|
|
+ * @param taskId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<AssoTaskFileVO> getAssoTaskFile(Integer taskId) throws IOException {
|
|
|
+ LambdaQueryWrapper<AssoTaskFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AssoTaskFile::getTaskId, taskId);
|
|
|
+ List<AssoTaskFile> assoTaskFiles = this.list(queryWrapper);
|
|
|
+
|
|
|
+ List<String> fileGuids = assoTaskFiles.stream().map(AssoTaskFile::getFileGuid).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<SystemFile> systemFiles = new ArrayList<>();
|
|
|
+ //调用文件系统查询文件信息接口
|
|
|
+ if (fileGuids.size() != 0) {
|
|
|
+ String res = fileManagerService.getSystemFileFromFMS(fileGuids);
|
|
|
+ systemFiles = JSONObject.parseArray(res, SystemFile.class);
|
|
|
}
|
|
|
+ List<AssoTaskFileVO> assoTaskFileVOS = new ArrayList<>();
|
|
|
+ if (systemFiles.size() != 0) {
|
|
|
+ for (AssoTaskFile assoTaskFile : assoTaskFiles) {
|
|
|
+ AssoTaskFileVO assoTaskFileVO = new AssoTaskFileVO();
|
|
|
+ //装载文件信息
|
|
|
+ SystemFile systemFile = systemFiles.stream().filter(item -> item.getGuid().equals(assoTaskFile.getFileGuid())).findFirst().orElse(null);
|
|
|
+ if (systemFile != null) {
|
|
|
+ BeanUtils.copyProperties(assoTaskFile, assoTaskFileVO);
|
|
|
+ assoTaskFileVO.setFileType(systemFile.getType());
|
|
|
+ assoTaskFileVO.setFileName(systemFile.getOriginalName());
|
|
|
+ }
|
|
|
+ assoTaskFileVOS.add(assoTaskFileVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return assoTaskFileVOS;
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 删除任务与文件关联表
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
public void deleteAssoTaskFile(List<Integer> ids){
|
|
|
if (ids.size() != 0) {
|
|
|
this.removeBatchByIds(ids);
|