zxl
2026-03-25 74e332504d98caaf8fab951d7d24be762b169f49
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package com.tievd.jyz.controller;
 
import cn.hutool.core.io.IoUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tievd.cube.commons.annotations.AutoLog;
import com.tievd.cube.commons.annotations.DictApi;
import com.tievd.cube.commons.base.CubeController;
import com.tievd.cube.commons.base.Result;
import com.tievd.cube.commons.utils.SystemContextUtil;
import com.tievd.cube.commons.utils.web.HttpServletUtil;
import com.tievd.cube.modules.system.model.LoginUser;
import com.tievd.jyz.constants.SystemConstant;
import com.tievd.jyz.entity.OilEvent;
import com.tievd.jyz.entity.vo.EventReqVo;
import com.tievd.jyz.service.IOilEventService;
import com.tievd.jyz.service.IOiloutEventService;
import com.tievd.jyz.util.BusinessUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
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.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
 
/**
 * OilEvent
 *
 * @author cube
 * @version V2.0.0
 * @since 2023-02-27
 */
@Slf4j
@DictApi
@RestController
@RequestMapping("/jyz/oilEvent")
@Tag(name = "事件列表, 首页事件")
public class OilEventController extends CubeController<OilEvent, IOilEventService> {
    
    @Autowired
    private IOilEventService oilEventService;
    
    @Autowired
    private IOiloutEventService oiloutEventService;
    
    
    /**
     * 分页列表查询
     */
    @GetMapping("/list")
    @Operation(summary = "事件分页查询")
    public Result<IPage<OilEvent>> queryPageList(EventReqVo eventReqVo,
                                                 @RequestParam(defaultValue = "1") Integer pageNo,
                                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                                 HttpServletRequest req) {
        QueryWrapper<OilEvent> wrapper = BusinessUtil.getEventQueryWrapper(eventReqVo, new OilEvent());
        Page<OilEvent> page = new Page<>(pageNo, pageSize);
        IPage<OilEvent> pageList = oilEventService.page(page, wrapper);
        return Result.ok(pageList);
    }
    
    
    @GetMapping("/eventList")
    @Operation(summary = "首页事件列表")
    @ApiResponse(description = "增加字段 phraseDesc: 所属区域/阶段:xxx")
    public Result<List<OilEvent>> eventList(@RequestParam Map param) {
        List eventList = oilEventService.eventMergeList(param);
        currentTime = new Date();
        return Result.ok(eventList);
    }
    
    private static Date currentTime = new Date();
    
    @GetMapping("/eventPopup")
    @Operation(summary = "首页事件弹窗")
    @ApiResponse(ref = "/eventList")
    public Result<?> eventPopupList(Map param) {
        param.put("current", currentTime);
//        param.put("limit", 1);
        List eventList = oilEventService.eventMergeList(param);
        if (CollectionUtils.isNotEmpty(eventList)) {
            currentTime = new Date();
            return Result.ok(eventList.get(new Random().nextInt(eventList.size())));
        }
        return Result.ok();
    }
    
    @GetMapping("/getVideoUrl")
    public Result<?> getVideoUrl(@RequestParam String cameraCode) {
        String url = "https://prod-streaming-video-msn-com.akamaized.net/a8c412fa-f696-4ff2-9c76-e8ed9cdffe0f/604a87fc-e7bc-463e-8d56-cde7e661d690.mp4";
        return Result.ok(url);
    }
    
    /**
     * 添加
     */
    @AutoLog("OilEvent-添加")
    @PostMapping("/add")
    public Result<?> add(@RequestBody OilEvent oilEvent) {
        oilEventService.save(oilEvent);
        return Result.ok();
    }
    
    /**
     * 编辑
     */
    @AutoLog("OilEvent-编辑")
    @PutMapping("/edit")
    public Result<?> edit(@RequestBody OilEvent oilEvent) {
        oilEventService.updateById(oilEvent);
        return Result.ok();
    }
    
    @AutoLog("OilEvent-事件审核")
    @PostMapping("/audit")
    @Operation(summary = "事件审核")
    public Result<?> audit(@RequestBody OilEvent oilEvent) {
        LoginUser sysUser = SystemContextUtil.currentLoginUser();
        oilEvent.setAuditUser(sysUser.getUsername());
        oilEvent.setAuditTime(new Date());
        oilEventService.updateById(oilEvent);
        return Result.ok();
    }
    
    /**
     * 通过id删除
     */
    @AutoLog("OilEvent-通过id删除")
    @DeleteMapping("/delete")
    public Result<?> delete(@RequestParam String id) {
        oilEventService.removeById(id);
        return Result.ok();
    }
    
    /**
     * 批量删除
     */
    @AutoLog("OilEvent-批量删除")
    @DeleteMapping("/deleteBatch")
    public Result<?> deleteBatch(@RequestParam String ids) {
        this.oilEventService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok();
    }
    
    /**
     * 通过id查询
     */
    @GetMapping("/queryById")
    public Result<?> queryById(@RequestParam String id) {
        OilEvent oilEvent = oilEventService.getById(id);
        return Result.ok(oilEvent);
    }
    
    /**
     * 导出excel
     */
    @RequestMapping("/exportXls")
    public void exportXls(HttpServletRequest request, HttpServletResponse response, OilEvent oilEvent) throws IOException {
        super.exportXls(request, response, oilEvent, "OilEvent");
    }
    
    @GetMapping("/exportZip")
    @Operation(summary = "导出zip文件(异步)")
    @ApiResponse(description = "0导出中, 1导出成功")
    public Result<Integer> exportZip(EventReqVo eventReqVo) throws IOException {
        LoginUser user = SystemContextUtil.currentLoginUser();
        String fileId = SystemConstant.OIL_EVENT_PREFFIX + user.getUsername();
        Map<String, String> fileMap = oiloutEventService.getFileMap();
        if (fileMap.containsKey(fileId)) {
            String filePath = fileMap.get(fileId);
            if (StringUtils.isNotBlank(filePath)) {
                return Result.ok(1);
            } else {
                return Result.ok(0);
            }
        }
        QueryWrapper<OilEvent> wrapper = BusinessUtil.getEventQueryWrapper(eventReqVo, new OilEvent());;
        List eventList = oilEventService.list(wrapper);
        oiloutEventService.exportZip(eventList, fileId);
        return Result.ok(0);
    }
    
    @GetMapping("/getExportFile")
    @Operation(summary = "下载导出的文件")
    public void getExportFile(HttpServletResponse response, String fileName, @RequestParam(defaultValue = "1") int type) throws IOException {
        LoginUser user = SystemContextUtil.currentLoginUser();
        String fileId = type == 1 ? SystemConstant.OIL_EVENT_PREFFIX + user.getUsername()
                : SystemConstant.OILOUT_EVENT_PREFFIX + user.getUsername();
        //查看文件是否导出成功
        Map<String, String> fileMap = oiloutEventService.getFileMap();
        String zipFile = fileMap.getOrDefault(fileId, "");
        if (StringUtils.isBlank(zipFile)) {
            return;
        }
        //文件下载
        HttpServletUtil.addDownloadHeader(response, fileName + SystemConstant.ZIP_SUFFIX);
        try(InputStream zipStream = new FileInputStream(zipFile)) {
            IoUtil.copy(zipStream, response.getOutputStream());
        } catch (Exception e) {
            log.error("导出失败", e);
            throw new RuntimeException("导出失败" + e.getMessage());
        } finally {
            fileMap.remove(fileId);
        }
        
    }
    
    /**
     * 通过excel导入数据
     */
    @PostMapping("/importExcel")
    public Result<?> importExcel(HttpServletRequest request) throws Exception {
        return super.importExcel(request, OilEvent.class);
    }
}