xiejun
2023-11-26 c4d687aacfb4e7b6ee5ce67df93cf2f8d8df80c1
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
package com.vci.ubcs.log.controller;
 
import com.alibaba.nacos.common.utils.StringUtils;
import com.vci.ubcs.log.vo.LocalLogVO;
import com.vci.ubcs.log.service.ILogLocalService;
import com.vci.ubcs.log.entity.LocalLog;
import com.vci.ubcs.resource.utils.FileDownloadUtil;
import com.vci.ubcs.starter.web.util.ControllerUtil;
import com.vci.ubcs.starter.web.util.LangBaseUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.rmi.ServerException;
import java.util.List;
 
/**
 * 本地系统日志
 * @author ludc
 * @date 2023/10/31 15:37
 */
@NonDS
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/localLog")
public class LogLocalController {
 
    private final ILogLocalService logLocalService;
 
    /**
     * 获取日志文件列表
     * @param localLog
     * @return
     */
    @PostMapping("/lazy-list")
    public R<List<LocalLog>> getSystemLogList(@RequestBody LocalLog localLog){
         return R.data(logLocalService.getSystemLogList(localLog.getLogPath()));
    }
 
    /**
     * 下载日志文件
     * @param localLogVO 下载日志的全路径集合
     * @param response
     * @return
     */
    @RequestMapping(value = "/downLoadLog",method = {RequestMethod.GET,RequestMethod.POST})
    public void downloadLogByServiceName(@RequestBody LocalLogVO localLogVO, HttpServletResponse response) throws IOException {
        try {
            //ControllerUtil.writeFileToResponse(response,excelName);
            FileDownloadUtil.downloadFileLocal(response, logLocalService.downloadLogByServiceNameAndFileName(localLogVO),true);
        } catch (Throwable e) {
            //如果出错,把错误信息写到text
            String msg = LangBaseUtil.getErrorMsg(e);
            if(StringUtils.isBlank(msg)){
                msg = "未知错误";
            }
            ControllerUtil.writeDataToResponse(response,msg.getBytes(StandardCharsets.UTF_8),null);
        }
    }
 
    /**
     * 删除日志文件
     * @param localLogVO
     * @return
     * @throws ServerException
     */
    @DeleteMapping("/deleteLogFile")
    public R deleteLogFile(@RequestBody LocalLogVO localLogVO) throws ServerException {
        return logLocalService.deleteLogFile(localLogVO);
    }
 
}