wuzeyu
2024-09-02 6418b2978c9cc4049c735b239efb223e20d33858
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
package com.dy.pipIrrMwTestWeb.rtuLog;
 
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.net.URLEncoder;
import java.util.List;
 
/**
 * @Author: liurunyu
 * @Date: 2024/8/28 14:55
 * @Description
 */
@Slf4j
@RestController
@RequestMapping(path="rtuLog")
public class RtuLogCtrl extends RtuLogSupport {
 
    @GetMapping(path = "logFile")
    public BaseResponse<List<String>> rtuLogFile(String rtuAddr, HttpServletRequest req, HttpServletResponse rep){
        ServletOutputStream out = null ;
        try{
            byte[] bs = this.requestMw4File(rtuAddr, mwUrlRtuLogFile) ;
            if(bs != null && bs.length > 0){
                String fileReName = rtuAddr + ".log" ;
                //URLEncoder.encode可以防止中文乱码
                fileReName = URLEncoder.encode(fileReName, "UTF-8").replaceAll("\\+", "%20");
                rep.addHeader("content-type", "application/octet-stream;charset=UTF-8");
                rep.addHeader("Content-Disposition", "attachment;fileName=" + fileReName);
                out = rep.getOutputStream() ;
                out.write(bs, 0, (bs==null?0:bs.length));
                out.flush();
            }else{
                return BaseResponseUtils.buildError("获取文件失败") ;
            }
        }catch (Exception e){
        }finally {
            if(out != null){
                try{
                    out.close();
                }catch(Exception e){
                }
            }
        }
        return null ;
    }
 
    @GetMapping(path="logText")
    public BaseResponse<List<String>> rtuLogText(String rtuAddr){
        BaseResponse<List<String>> response = this.requestMw4Text(rtuAddr, mwUrlRtuLogText) ;
        return response ;
    }
}