ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.vci.web.controller;
import com.vci.corba.common.PLException;
import com.vci.dto.LogQueryCriteriaDTO;
import com.vci.starter.web.annotation.log.VciBusinessLog;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.util.ControllerUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.web.service.LogBasicServiceI;
import com.vci.starter.web.util.Lcm.Func;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
 
/**
 * 平台日志控制器
 * @author yuxc
 * @date 2024-9-11
 */
@Controller
@RequestMapping("/loginBasicController")
@VciBusinessLog(modelName="日志服务")
public class LogBasicController {
 
    /**
     * 登录服务
     */
    @Autowired
    private LogBasicServiceI logBasicServiceI;
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 获取日期保存期限下拉列表框
     * @return 查询结果
     */
    @VciBusinessLog(operateName="日期保存期限")
    @GetMapping(value = "/getPeroid")
    @ResponseBody
    public BaseResult getPeroid(){
        try {
            return logBasicServiceI.getPeroid();
        }catch (Exception e){
            e.printStackTrace();
            String errorMsg = "查询出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
            logger.error(errorMsg);
            throw new VciBaseException(errorMsg);
        }
    }
 
    /**
     * 保存期限设置
     * period 期限编码
     * @return 保存结果
     */
    @VciBusinessLog(operateName="保存期限设置")
    @PostMapping(value = "/savePeriod")
    @ResponseBody
    public BaseResult savePeriod(String period){
        try {
            return logBasicServiceI.savePeriod(period);
        }catch (Exception e){
            e.printStackTrace();
            String errorMsg = "保存出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
            logger.error(errorMsg);
            throw new VciBaseException(errorMsg);
        }
    }
 
    /**
     * 删除日志
     * period 期限编码
     * @return 保存结果
     */
    @VciBusinessLog(operateName="删除日志")
    @DeleteMapping(value = "/deleteLog")
    @ResponseBody
    public BaseResult deleteLog(String deleteDate){
        try {
            return logBasicServiceI.deleteLog(deleteDate);
        }catch (Exception e){
            e.printStackTrace();
            String errorMsg = "删除出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
            logger.error(errorMsg);
            throw new VciBaseException(errorMsg);
        }
    }
 
    /**
     * 查询日志
     * @param dto 查询条件传输对象
     * @return 查询数据
     * @throws PLException
     */
    @VciBusinessLog(operateName="日志查询")
    @PostMapping(value = "/getLogListByContion")
    @ResponseBody
    public BaseResult getLogListByContion(@RequestBody LogQueryCriteriaDTO dto){
        try {
            return logBasicServiceI.getLogListByContion(dto);
        }catch (Exception e){
            e.printStackTrace();
            String errorMsg = "查询日志出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
            logger.error(errorMsg);
            throw new VciBaseException(errorMsg);
        }
    }
 
    /**
     * 操作用户获取
     */
    @VciBusinessLog(operateName="获取操作用户")
    @GetMapping(value = "/getOperatingUsers")
    @ResponseBody
    public BaseResult getOperatingUsers(){
        try {
            return logBasicServiceI.getOperatingUsers();
        }catch (Exception e){
            e.printStackTrace();
            String errorMsg = "查询日志出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
            logger.error(errorMsg);
            throw new VciBaseException(errorMsg);
        }
    }
 
    /**
     * 导出日志
     * @param dto 导出查询传参数对象
     * @param response
     */
    @PostMapping( "/exportLogs")
    @VciBusinessLog(operateName = "导出日志")
    public void exportLogs(@RequestBody LogQueryCriteriaDTO dto, HttpServletResponse response){
        try {
            String excelPath = logBasicServiceI.exportLogs(dto);
            ControllerUtil.writeFileToResponse(response,excelPath);
        } catch (Exception e) {
            String msg = "导出日志时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            try {
                //出错时
                e.printStackTrace();
                ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        }
    }
 
}