yanghb
2024-12-17 1287337fd0b0c156ec79712f9a600ebeffefe3a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.zzg.system.service.system.impl;
 
import cn.hutool.core.text.StrPool;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzg.common.constant.SysConstants;
import com.zzg.common.utils.SecurityUtils;
import com.zzg.system.domain.AttachFile;
import com.zzg.system.mapper.system.AttachFileMapper;
import com.zzg.system.service.system.IAttachFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * attach_file
 */
@Slf4j
@Service
public class AttachFileServiceImpl extends ServiceImpl<AttachFileMapper, AttachFile> implements IAttachFileService {
 
    @Override
    public AttachFile transFile(String filePath, String foreignId, Integer fileType) {
        return transFile(filePath, foreignId, fileType, AttachFile.UP_TYPE_PROJECT);
    }
 
    @Override
    public AttachFile transFile(String filePath, String foreignId, Integer fileType, Integer upType) {
        AttachFile file = new AttachFile();
        file.setInventoryId(foreignId);
        file.setFileType(fileType);
        file.setFilePath(SysConstants.Path.UPLOAD + filePath.substring(filePath.lastIndexOf("/")));
        file.setOriginName(filePath.substring(filePath.indexOf(StrPool.UNDERLINE) + 1));
        file.setSuffix(filePath.substring(filePath.lastIndexOf(StrPool.DOT) + 1));
        file.setUpType(upType);
        file.setCreateTime(new Date());
        file.setCreateName(SecurityUtils.getUsername());
        return file;
    }
 
    @Override
    public List<AttachFile> transFile(List<String> filePaths, String foreignId, Integer fileType) {
        List<AttachFile> fileList = new ArrayList<>();
        for (String path : filePaths) {
            fileList.add(transFile(path, foreignId, fileType));
        }
        return fileList;
    }
 
    @Override
    public List<AttachFile> transFile(List<String> filePaths, String foreignId, Integer fileType, Integer upType) {
        List<AttachFile> fileList = new ArrayList<>();
        for (String path : filePaths) {
            fileList.add(transFile(path, foreignId, fileType, upType));
        }
        return fileList;
    }
 
    @Override
    public AttachFile createByAgree(String surveyId, String inventoryId, Integer inventoryType, String path, Integer fileType) {
        AttachFile file = new AttachFile();
        file.setSurveyId(surveyId);
        file.setInventoryId(inventoryId);
        file.setInventoryType(inventoryType);
        file.setFilePath(path);
        file.setFileType(fileType);
        file.setOriginName(path.substring(path.lastIndexOf(StrPool.SLASH) + 1));
        file.setCreateName(SecurityUtils.getUsername());
        file.setCreateTime(new Date());
        return file;
    }
 
}