lxw
2023-05-17 fc2173606fd7b8dc3e3a6b5fec7f82871e5fdc43
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.whyc.controller;
 
import com.whyc.alarm.Fbs5100AlarmData;
import com.whyc.charge.Fbs5100ChargeData;
import com.whyc.charge.Fbs5100DisChargeData;
import com.whyc.pojo.Response;
import com.whyc.service.ExcelExportService;
import com.whyc.service.Fbs5100AlarmDataService;
import com.whyc.service.Fbs5100ChargeDataService;
import com.whyc.service.Fbs5100DisChargeDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
 
@RestController
@Api(tags = "解析文件")
@RequestMapping("analysis")
public class AnalysisController {
    @Autowired
    private Fbs5100DisChargeDataService disChargeDataService;
 
    @Autowired
    private Fbs5100ChargeDataService chargeDataService;
 
    @Autowired
    private Fbs5100AlarmDataService alarmDataService;
 
    @Autowired
    private ExcelExportService exportService;
 
 
    @GetMapping("/readFboFile")
    @ApiOperation(value = "根据文件后缀解析不同的文件")
    public Response readFboFile(@RequestParam String filePath){
        String suffix=filePath.substring(filePath.lastIndexOf(".")+1).toLowerCase(Locale.ROOT);
        Response response=new Response();
        switch (suffix){
            case "bcp"://放电数据
                Fbs5100DisChargeData disChargeData = disChargeDataService.readFboFile(filePath);
                response.set(1,disChargeData,filePath);
                break;
            case "chr"://充电数据
                Fbs5100ChargeData chargeData=chargeDataService.readFileData(filePath);
                response.set(1,chargeData,filePath);
                break;
            case "alm"://告警数据
                Fbs5100AlarmData alarmData=alarmDataService.readFileData(filePath);
                response.set(1,alarmData,filePath);
                break;
            default:response.set(1,false,filePath);
        }
 
        return response;
    }
 
    @PostMapping("/export")
    @ApiOperation(value = "文件导出")
    public void export(HttpServletRequest req, HttpServletResponse resp ){
        String filePath = req.getParameter("filePath");
        String suffix=filePath.substring(filePath.lastIndexOf(".")+1).toLowerCase(Locale.ROOT);
        switch (suffix){
            case "bcp":exportService.exportBcp(req,resp);
                break;
            case "chr":exportService.exportChr(req,resp);
                break;
            case "alm":exportService.exportAlm(req,resp);
                break;
        }
    }
}