yangys
2025-09-13 083df8d788c95c009a94378e620684eb5de2bd21
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package org.springblade.mdm.machinefile.service;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BizServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.utils.Func;
import org.springblade.mdm.machinefile.entity.MachineFile;
import org.springblade.mdm.machinefile.entity.MachineAcceptedFile;
import org.springblade.mdm.machinefile.mapper.MachineAcceptedFileMapper;
import org.springblade.mdm.machinefile.vo.MachineAcceptedFileHandleQueryVO;
import org.springblade.mdm.machinefile.vo.MachineBackFileQueryVO;
import org.springblade.mdm.machinefile.vo.MachineAcceptedFileVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
 
@AllArgsConstructor
@Service
public class MachineAcceptedFileService extends BizServiceImpl<MachineAcceptedFileMapper, MachineAcceptedFile> {
    private final MachineFileService machineFileService;
    private final OssTemplate ossTemplate;
    /**
     * 接受
     * @param ids
     */
    @Transactional
    public void accept(String ids) throws IOException {
 
        List<Long> idList = Func.toLongList(ids);
        for(Long id : idList){
            acceptFile(id);
        }
 
    }
 
    /**
     * 拒绝
     * @param ids
     */
    public void reject(String ids) {
        List<Long> idList = Func.toLongList(ids);
 
        MachineFile mf;
        for(Long id : idList){
            mf = machineFileService.getById(id);
            mf.reject();
            machineFileService.updateById(mf);
        }
 
    }
 
    @Transactional
    public void acceptAll() throws IOException {
        MachineBackFileQueryVO query = new MachineBackFileQueryVO();
        query.setCurrent(1);
        query.setSize(Integer.MAX_VALUE);
        IPage<MachineFile> aceptPage = machineFileService.filePageForAccept(query);
 
        for(MachineFile mf: aceptPage.getRecords()){
            acceptFile(mf.getId());
        }
    }
 
    /**
     * 接收文件
     * @param machineFileId 机床文件id
     * @throws IOException
     */
    void acceptFile(Long machineFileId) throws IOException {
        MachineFile machineFile = machineFileService.getById(machineFileId);
        machineFile.accept();
        machineFileService.updateById(machineFile);
 
        //新建一个machineaceptedfile对象,存储接收后的数据
        MachineAcceptedFile machineAcceptedFile = new MachineAcceptedFile();
        machineAcceptedFile.setMachineFileId(machineFileId);
        machineAcceptedFile.setName(machineFile.getName());
        String fullPath = machineFileService.getFilePath(machineFile);
        try(InputStream inputStream = Files.newInputStream(Paths.get(fullPath));){
            BladeFile bfile = ossTemplate.putFile(machineFile.getName(),inputStream);
            machineAcceptedFile.setOssName(bfile.getName());
        }
        save(machineAcceptedFile);
    }
 
    /**
     * 机床回传程序处理分页查询
     * @param query 查询参数对象
     * @return 分页数据
     */
 
    public IPage<MachineAcceptedFileVO> handlePageQuery(MachineAcceptedFileHandleQueryVO query) {
        IPage<MachineAcceptedFileVO> page = this.getBaseMapper().handlePageQuery(Condition.getPage(query),query);
        return page;
    }
 
 
}