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);
|
}
|
}
|