“mitao”
2026-01-20 4e5beb844f03daec12f2b039365730b0683f8a9e
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
107
108
109
110
111
package com.estate.expert.admin.io.processor.impl;
 
import com.estate.expert.admin.TestCommon;
import com.estate.expert.admin.io.processor.impl.business.DeviceProcessor;
import com.estate.expert.admin.io.processor.impl.business.PlanProcessor;
import com.estate.expert.admin.io.processor.impl.business.ProjectProcessor;
import com.estate.expert.admin.io.processor.impl.record.DeviceErrorRecordProcessor;
import com.estate.expert.admin.io.processor.impl.record.SystemErrorRecordProcessor;
import com.estate.expert.admin.io.processor.impl.record.WarningRecordProcessor;
import com.estate.expert.admin.service.*;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.io.FileOutputStream;
import java.io.IOException;
 
@Slf4j
@SpringBootTest
@ExtendWith(SpringExtension.class)
@Transactional
class ExportProcessorTest {
 
    @Resource
    private ClientService clientService;
 
    @Resource
    private ErrorRecordService errorRecordService;
 
    @Resource
    private WarningRecordService warningRecordService;
 
    @Resource
    private ProjectService projectService;
 
    @Resource
    private DeviceService deviceService;
 
    @Resource
    private PlanService planService;
 
    @Resource
    private CheckTaskService checkTaskService;
 
    @Test
    void systemErrors() throws IOException {
        var records = errorRecordService.listSystemErrors(1);
 
        var processor = new SystemErrorRecordProcessor();
        // write to file
        try(var fos = new FileOutputStream(TestCommon.getTmpPath("system_errors.xlsx"))) {
            processor.saveWorkbook(fos, records);
        }
    }
 
    @Test
    void deviceErrors() throws IOException {
        var records = errorRecordService.listDeviceErrors(1);
 
        var processor = new DeviceErrorRecordProcessor();
        // write to file
        try(var fos = new FileOutputStream(TestCommon.getTmpPath("device_errors.xlsx"))) {
            processor.saveWorkbook(fos, records);
        }
    }
 
    @Test
    void warningRecords() throws IOException {
        var records = warningRecordService.findAll();
 
        var processor = new WarningRecordProcessor();
        // write to file
        try(var fos = new FileOutputStream(TestCommon.getTmpPath("warning_records.xlsx"))) {
            processor.saveWorkbook(fos, records);
        }
    }
 
    @Test
    void projects() throws IOException {
        var projects = projectService.findAll();
 
        var processor = new ProjectProcessor(clientService, projectService);
        try(var fos = new FileOutputStream(TestCommon.getTmpPath("projects.xlsx"))) {
            processor.saveWorkbook(fos, projects);
        }
    }
 
    @Test
    void devices() throws IOException {
        var devices = deviceService.findAll();
 
        var processor = new DeviceProcessor();
        try(var fos = new FileOutputStream(TestCommon.getTmpPath("devices.xlsx"))) {
            processor.saveWorkbook(fos, devices);
        }
    }
 
    @Test
    void plans() throws IOException {
         var plans = planService.findAll();
 
         var processor = new PlanProcessor(checkTaskService);
         try(var fos = new FileOutputStream(TestCommon.getTmpPath("plans.xlsx"))) {
             processor.saveWorkbook(fos, plans);
         }
    }
}