So2Controller.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. package com.ruoyi.web.controller.gas;
  2. import cn.hutool.core.convert.Convert;
  3. import cn.hutool.core.date.DateUtil;
  4. import cn.hutool.core.util.NumberUtil;
  5. import cn.hutool.core.util.ObjectUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import com.ruoyi.common.annotation.Log;
  8. import com.ruoyi.common.constant.CacheConstants;
  9. import com.ruoyi.common.constant.ElasticConstants;
  10. import com.ruoyi.common.constant.HttpStatus;
  11. import com.ruoyi.common.core.controller.BaseController;
  12. import com.ruoyi.common.core.domain.AjaxResult;
  13. import com.ruoyi.common.core.domain.entity.SysDictData;
  14. import com.ruoyi.common.core.page.PageDomain;
  15. import com.ruoyi.common.core.page.TableDataInfo;
  16. import com.ruoyi.common.core.page.TableSupport;
  17. import com.ruoyi.common.core.redis.RedisCache;
  18. import com.ruoyi.common.enums.AggsType;
  19. import com.ruoyi.common.enums.BusinessType;
  20. import com.ruoyi.common.utils.poi.ExcelUtil;
  21. import com.ruoyi.framework.config.ElasticSearchClient;
  22. import com.ruoyi.system.domain.GuapMonitorPoint;
  23. import com.ruoyi.system.domain.IllegalShip;
  24. import com.ruoyi.system.domain.XiuTanSemInstrument;
  25. import com.ruoyi.system.service.IAisDatabase;
  26. import com.ruoyi.system.service.IHeiYanService;
  27. import com.ruoyi.system.service.ISo2Service;
  28. import com.ruoyi.system.service.ISysDictTypeService;
  29. import io.swagger.annotations.Api;
  30. import io.swagger.annotations.ApiOperation;
  31. import lombok.SneakyThrows;
  32. import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
  33. import org.springframework.beans.factory.annotation.Autowired;
  34. import org.springframework.web.bind.annotation.GetMapping;
  35. import org.springframework.web.bind.annotation.RequestMapping;
  36. import org.springframework.web.bind.annotation.RequestParam;
  37. import org.springframework.web.bind.annotation.RestController;
  38. import javax.servlet.http.HttpServletRequest;
  39. import javax.servlet.http.HttpServletResponse;
  40. import java.util.ArrayList;
  41. import java.util.Date;
  42. import java.util.HashMap;
  43. import java.util.List;
  44. import java.util.Map;
  45. import java.util.stream.Collectors;
  46. /**
  47. * @Description: 硫含量
  48. * @Author: huangcheng
  49. * @Date: 2021/8/26
  50. * @Version V1.0
  51. */
  52. @RestController
  53. @RequestMapping("/so2")
  54. @Api(tags = "硫含量接口")
  55. public class So2Controller extends BaseController {
  56. @Autowired
  57. private ElasticSearchClient client;
  58. @Autowired
  59. private IAisDatabase aisDatabase;
  60. @Autowired
  61. private ISo2Service so2Service;
  62. @Autowired
  63. private IHeiYanService heiYanService;
  64. @Autowired
  65. private RedisCache redisCache;
  66. @Autowired
  67. private ISysDictTypeService dictTypeService;
  68. @GetMapping("/list")
  69. @ApiOperation("硫嫌疑船舶列表数据")
  70. public TableDataInfo list(IllegalShip illegalShip) {
  71. // 传来的参数
  72. Map<String, Object> params = illegalShip.getParams();
  73. Map<String, Object> equalsCondition = new HashMap<>();
  74. // 组装查询条件
  75. equalsCondition.put("mmsi", StrUtil.isBlank(illegalShip.getMmsi()) ? null : StrUtil.concat(true, "*", illegalShip.getMmsi(), "*"));
  76. equalsCondition.put("shipName", StrUtil.isBlank(illegalShip.getShipName()) ? null : StrUtil.concat(true, "*", illegalShip.getShipName(), "*"));
  77. equalsCondition.put("shipRegionType", illegalShip.getShipRegionType());
  78. equalsCondition.put("destination", StrUtil.isBlank(illegalShip.getDestination()) ? null : StrUtil.concat(true, "*", illegalShip.getDestination(), "*"));
  79. equalsCondition.put("orgName", illegalShip.getOrgName());
  80. equalsCondition.put("illegalStatus", illegalShip.getIllegalStatus());
  81. equalsCondition.put("dealResult", illegalShip.getDealResult());
  82. equalsCondition.put("fastResult", illegalShip.getFastResult());
  83. equalsCondition.put("uploadResult", illegalShip.getUploadResult());
  84. equalsCondition.put("illegalType", illegalShip.getIllegalType());
  85. equalsCondition.put("monitorPointName", illegalShip.getMonitorPointName());
  86. if (StrUtil.isNotBlank(illegalShip.getFilterMmsi()) && StrUtil.isBlank(illegalShip.getMmsi())) {
  87. equalsCondition.put("mmsi", illegalShip.getFilterMmsi());
  88. }
  89. // 组装范围查询条件
  90. Map<String, Object> rangeCondition = new HashMap<>();
  91. if (ObjectUtil.isNotEmpty(params.get("beginTime"))) {
  92. params.put("beginTime", params.get("beginTime") + " 00:00:00");
  93. }
  94. if (ObjectUtil.isNotEmpty(params.get("endTime"))) {
  95. params.put("endTime", params.get("endTime") + " 23:59:59");
  96. }
  97. rangeCondition.put("createTime", StrUtil.concat(true, "[", Convert.toStr(params.get("beginTime")), ",", Convert.toStr(params.get("endTime")), "]"));
  98. List<String> orderBy = new ArrayList<>();
  99. orderBy.add("-createTime");
  100. PageDomain pageDomain = TableSupport.buildPageRequest();
  101. Map<String, Object> maps = client.searchDocument(equalsCondition, rangeCondition, orderBy, pageDomain.getPageNum(), pageDomain.getPageSize(), ElasticConstants.SO2_ALERT, ElasticConstants.AIS_ILLEGAL_SHIP);
  102. // 查询so2系统的设备信息
  103. Map<String, String> so2Device = so2Service.queryDeviceMap();
  104. Map<String, String> aisDevice = aisDatabase.queryDeviceMap();
  105. TableDataInfo rspData = new TableDataInfo();
  106. rspData.setCode(HttpStatus.SUCCESS);
  107. rspData.setMsg("查询成功");
  108. List<IllegalShip> pageList = Convert.toList(IllegalShip.class, maps.get("pageList"));
  109. for (IllegalShip ship : pageList) {
  110. if ("xiutan".equals(ship.getIllegalType())) {
  111. ship.setDeviceName(aisDevice.get(ship.getSemId()));
  112. } else if ("guangpu".equals(ship.getIllegalType())) {
  113. ship.setDeviceName(so2Device.get(ship.getDeviceId()));
  114. }
  115. }
  116. rspData.setRows(pageList);
  117. rspData.setTotal(Convert.toLong(maps.get("totalNum")));
  118. return rspData;
  119. }
  120. @SneakyThrows
  121. @Log(title = "硫含量记录导出", businessType = BusinessType.EXPORT)
  122. @GetMapping("/export")
  123. public AjaxResult export(IllegalShip illegalShip, HttpServletRequest request, HttpServletResponse response) {
  124. // 传来的参数
  125. Map<String, Object> params = illegalShip.getParams();
  126. Map<String, Object> equalsCondition = new HashMap<>();
  127. // 组装查询条件
  128. equalsCondition.put("mmsi", StrUtil.isBlank(illegalShip.getMmsi()) ? null : StrUtil.concat(true, "*", illegalShip.getMmsi(), "*"));
  129. equalsCondition.put("shipName", StrUtil.isBlank(illegalShip.getShipName()) ? null : StrUtil.concat(true, "*", illegalShip.getShipName(), "*"));
  130. equalsCondition.put("shipRegionType", illegalShip.getShipRegionType());
  131. equalsCondition.put("destination", StrUtil.isBlank(illegalShip.getDestination()) ? null : StrUtil.concat(true, "*", illegalShip.getDestination(), "*"));
  132. equalsCondition.put("orgName", illegalShip.getOrgName());
  133. equalsCondition.put("illegalStatus", illegalShip.getIllegalStatus());
  134. equalsCondition.put("dealResult", illegalShip.getDealResult());
  135. equalsCondition.put("fastResult", illegalShip.getFastResult());
  136. equalsCondition.put("uploadResult", illegalShip.getUploadResult());
  137. equalsCondition.put("illegalType", illegalShip.getIllegalType());
  138. equalsCondition.put("monitorPointName", illegalShip.getMonitorPointName());
  139. if (StrUtil.isNotBlank(illegalShip.getFilterMmsi()) && StrUtil.isBlank(illegalShip.getMmsi())) {
  140. equalsCondition.put("mmsi", illegalShip.getFilterMmsi());
  141. }
  142. // 组装范围查询条件
  143. Map<String, Object> rangeCondition = new HashMap<>();
  144. if (ObjectUtil.isNotEmpty(params.get("beginTime"))) {
  145. params.put("beginTime", params.get("beginTime") + " 00:00:00");
  146. }
  147. if (ObjectUtil.isNotEmpty(params.get("endTime"))) {
  148. params.put("endTime", params.get("endTime") + " 23:59:59");
  149. }
  150. rangeCondition.put("createTime", StrUtil.concat(true, "[", Convert.toStr(params.get("beginTime")), ",", Convert.toStr(params.get("endTime")), "]"));
  151. List<String> orderBy = new ArrayList<>();
  152. orderBy.add("-createTime");
  153. Map<String, Object> maps = client.searchDocument(equalsCondition, rangeCondition, orderBy, 1, 1000000, ElasticConstants.SO2_ALERT, ElasticConstants.AIS_ILLEGAL_SHIP);
  154. ExcelUtil<IllegalShip> util = new ExcelUtil<>(IllegalShip.class);
  155. return util.exportExcel(Convert.toList(IllegalShip.class, maps.get("pageList")), "硫含量违规数据");
  156. /*util.exportExcelByEasyPoi("so2_" + DateUtil.today(),
  157. "硫含量违规数据",
  158. "硫含量违规数据",
  159. IllegalShip.class,
  160. Convert.toList(IllegalShip.class, maps.get("pageList")),
  161. request, response);
  162. ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
  163. mv.addObject(NormalExcelConstants.FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
  164. mv.addObject(NormalExcelConstants.CLASS, clazz);
  165. mv.addObject(NormalExcelConstants.PARAMS, new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title));
  166. mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
  167. return mv;*/
  168. }
  169. @GetMapping("/guangpu/monitorPoint")
  170. @ApiOperation("光谱-检测点数据")
  171. public AjaxResult monitorPoint(GuapMonitorPoint monitorPoint) {
  172. // 传来的参数
  173. Map<String, Object> equalsCondition = new HashMap<>();
  174. // 组装查询条件
  175. equalsCondition.put("name", StrUtil.isBlank(monitorPoint.getName()) ? null : StrUtil.concat(true, "*", monitorPoint.getName(), "*"));
  176. Map<String, Object> maps = client.searchDocument(equalsCondition, null, null, 1, 10000, ElasticConstants.SO2_MONITOR_POINT);
  177. return AjaxResult.success(Convert.toList(GuapMonitorPoint.class, maps.get("pageList")));
  178. }
  179. @GetMapping("/xiutan/semInstrument")
  180. @ApiOperation("嗅探-设备数据")
  181. public AjaxResult semInstrument(XiuTanSemInstrument semInstrument) {
  182. // 传来的参数
  183. Map<String, Object> equalsCondition = new HashMap<>();
  184. // 组装查询条件
  185. equalsCondition.put("name", StrUtil.isBlank(semInstrument.getName()) ? null : StrUtil.concat(true, "*", semInstrument.getName(), "*"));
  186. Map<String, Object> maps = client.searchDocument(equalsCondition, null, null, 1, 10000, ElasticConstants.AIS_SEM_INSTRUMENT);
  187. return AjaxResult.success(Convert.toList(XiuTanSemInstrument.class, maps.get("pageList")));
  188. }
  189. @GetMapping("/static/device")
  190. @ApiOperation("设备安装位置统计")
  191. public AjaxResult deviceStatic() {
  192. if (redisCache.hasKey(CacheConstants.DEVICE_STATIC)) {
  193. return AjaxResult.success(redisCache.getCacheMap(CacheConstants.DEVICE_STATIC));
  194. }
  195. List<Map<String, Object>> aisDevice = aisDatabase.queryDeviceStatic();
  196. List<Map<String, Object>> so2Device = so2Service.queryDeviceStatic();
  197. List<Map<String, Object>> heiyanDevice = heiYanService.queryDeviceStatic();
  198. // 两个结果合并
  199. Map<String, Integer> result = new HashMap<>(8);
  200. for (Map<String, Object> stringIntegerMap : aisDevice) {
  201. result.put(Convert.toStr(stringIntegerMap.get("point")), Convert.toInt(stringIntegerMap.get("count")));
  202. }
  203. for (Map<String, Object> stringIntegerMap : so2Device) {
  204. result.put(Convert.toStr(stringIntegerMap.get("point")), Convert.toInt(NumberUtil.add(result.get(Convert.toStr(stringIntegerMap.get("point"))), Convert.toInt(stringIntegerMap.get("count")))));
  205. }
  206. for (Map<String, Object> stringObjectMap : heiyanDevice) {
  207. result.put(Convert.toStr(stringObjectMap.get("point")), Convert.toInt(NumberUtil.add(result.get(Convert.toStr(stringObjectMap.get("point"))), Convert.toInt(stringObjectMap.get("count")))));
  208. }
  209. redisCache.setCacheMap(CacheConstants.DEVICE_STATIC, result);
  210. return AjaxResult.success(result);
  211. }
  212. @GetMapping("/static/semDevice")
  213. @ApiOperation("设备安装位置及设备类型统计")
  214. public AjaxResult semDevice() {
  215. if (redisCache.hasKey(CacheConstants.DEVICE_SEM_STATIC)) {
  216. return AjaxResult.success(redisCache.getCacheMap(CacheConstants.DEVICE_SEM_STATIC));
  217. }
  218. Map<String, Integer[]> result = new HashMap<>();
  219. Map<Object, Object> aisDevice = aisDatabase.queryDeviceStatic().stream().collect(Collectors.toMap(s -> s.get("point"), v -> v.get("count")));
  220. Map<Object, Object> so2Device = so2Service.queryDeviceStatic().stream().collect(Collectors.toMap(s -> s.get("point"), v -> v.get("count")));
  221. Map<Object, Object> heiyanDevice = heiYanService.queryDeviceStatic().stream().collect(Collectors.toMap(s -> s.get("point"), v -> v.get("count")));
  222. result.put("南京三桥", new Integer[]{Convert.toInt(aisDevice.getOrDefault("南京三桥", 0)), Convert.toInt(so2Device.getOrDefault("南京三桥", 0)), Convert.toInt(heiyanDevice.getOrDefault("南京三桥", 0))});
  223. result.put("南京四桥", new Integer[]{Convert.toInt(aisDevice.getOrDefault("南京四桥", 0)), Convert.toInt(so2Device.getOrDefault("南京四桥", 0)), Convert.toInt(heiyanDevice.getOrDefault("南京四桥", 0))});
  224. result.put("润扬大桥", new Integer[]{Convert.toInt(aisDevice.getOrDefault("润扬大桥", 0)), Convert.toInt(so2Device.getOrDefault("润扬大桥", 0)), Convert.toInt(heiyanDevice.getOrDefault("润扬大桥", 0))});
  225. result.put("泰州大桥", new Integer[]{Convert.toInt(aisDevice.getOrDefault("泰州大桥", 0)), Convert.toInt(so2Device.getOrDefault("泰州大桥", 0)), Convert.toInt(heiyanDevice.getOrDefault("泰州大桥", 0))});
  226. result.put("江阴大桥", new Integer[]{Convert.toInt(aisDevice.getOrDefault("江阴大桥", 0)), Convert.toInt(so2Device.getOrDefault("江阴大桥", 0)), Convert.toInt(heiyanDevice.getOrDefault("江阴大桥", 0))});
  227. result.put("苏通大桥", new Integer[]{Convert.toInt(aisDevice.getOrDefault("苏通大桥", 0)), Convert.toInt(so2Device.getOrDefault("苏通大桥", 0)), Convert.toInt(heiyanDevice.getOrDefault("苏通大桥", 0))});
  228. redisCache.setCacheMap(CacheConstants.DEVICE_SEM_STATIC, result);
  229. redisCache.expire(CacheConstants.DEVICE_SEM_STATIC, 86400);
  230. return AjaxResult.success(result);
  231. }
  232. @GetMapping("/static/deviceType")
  233. @ApiOperation("设备类型统计")
  234. public AjaxResult deviceTypeStatic() {
  235. if (redisCache.hasKey(CacheConstants.DEVICE_TYPE_STATIC)) {
  236. return AjaxResult.success(redisCache.getCacheMap(CacheConstants.DEVICE_TYPE_STATIC));
  237. }
  238. int aisDevice = aisDatabase.queryDeviceCount();
  239. int so2Device = so2Service.queryDeviceCount();
  240. int heiyanDevice = heiYanService.queryDeviceCount();
  241. // 两个结果合并
  242. Map<String, Integer> result = new HashMap<>(4);
  243. result.put("光谱", so2Device);
  244. result.put("嗅探", aisDevice);
  245. result.put("黑烟", heiyanDevice);
  246. redisCache.setCacheMap(CacheConstants.DEVICE_TYPE_STATIC, result);
  247. return AjaxResult.success(result);
  248. }
  249. @GetMapping("/snapPos/static")
  250. @ApiOperation("硫含量超标船舶分布统计")
  251. public AjaxResult so2SnapPosStatic(@RequestParam(required = false) String month) {
  252. String beginTime = "";
  253. String endTime = "";
  254. if (StrUtil.isBlank(month)) {
  255. beginTime = DateUtil.formatDate(DateUtil.beginOfMonth(new Date())) + " 00:00:00";
  256. endTime = DateUtil.formatDate(DateUtil.endOfMonth(new Date())) + " 23:59:59";
  257. } else {
  258. beginTime = month + "-01 00:00:00";
  259. endTime = DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parseDate(beginTime))) + " 23:59:59";
  260. }
  261. Map<String, Object> equalsCondition = new HashMap<>();
  262. equalsCondition.put("illegalStatus", 2);
  263. Map<String, Object> so2RangeCondition = new HashMap<>();
  264. so2RangeCondition.put("createTime", StrUtil.concat(true, "[", beginTime, ",", endTime, "]"));
  265. Map<Object, Object> so2Aggs = client.aggs(AggsType.count, "monitorPointName", "id", equalsCondition, so2RangeCondition, ElasticConstants.AIS_ILLEGAL_SHIP, ElasticConstants.SO2_ALERT);
  266. // 构造硫的数据
  267. List<SysDictData> so2_snap_pos = dictTypeService.selectDictDataByType("so2_snap_pos");
  268. Map<String, Object> result = new HashMap<>();
  269. for (SysDictData so2_snap_po : so2_snap_pos) {
  270. result.put(so2_snap_po.getDictLabel(),
  271. (ObjectUtil.isEmpty(so2Aggs.get(so2_snap_po.getDictLabel())) ? 0 : Convert.toInt(so2Aggs.get(so2_snap_po.getDictLabel()))));
  272. }
  273. return AjaxResult.success(result);
  274. }
  275. @GetMapping("/timeStatic")
  276. @ApiOperation("超标船舶统计-按时间")
  277. public AjaxResult monthStatic(@RequestParam(required = false) String interval, @RequestParam(required = false) String startMonth, @RequestParam(required = false) String endMonth) {
  278. if (StrUtil.isBlank(interval)) {
  279. // 默认值为1个月
  280. interval = "1M";
  281. }
  282. Map<String, Object> rangeCondition = new HashMap<>();
  283. if (!StrUtil.isAllBlank(startMonth, endMonth)) {
  284. if (StrUtil.isNotBlank(startMonth)) {
  285. startMonth = startMonth + "-01 00:00:00";
  286. }
  287. if (StrUtil.isNotBlank(endMonth)) {
  288. endMonth = DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parseDate(endMonth + "-01 00:00:00"))) + " 23:59:59";
  289. }
  290. rangeCondition.put("createTime", StrUtil.concat(true, "[", startMonth, ",", endMonth, "]"));
  291. }
  292. Map<String, Object> equalsCondition = new HashMap<>();
  293. equalsCondition.put("illegalStatus", 2);
  294. Map<Object, Object> aisAggs = client.dateHistogramAggs(AggsType.count, "createTime", "id", equalsCondition, rangeCondition, new DateHistogramInterval(interval), ElasticConstants.AIS_ILLEGAL_SHIP);
  295. Map<Object, Object> so2Aggs = client.dateHistogramAggs(AggsType.count, "createTime", "id", equalsCondition, rangeCondition, new DateHistogramInterval(interval), ElasticConstants.SO2_ALERT);
  296. equalsCondition.put("illegalStatus", 3);
  297. Map<Object, Object> heiyanAggs = client.dateHistogramAggs(AggsType.count, "createTime", "id", equalsCondition, rangeCondition, new DateHistogramInterval(interval), ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  298. Map<String, Map<Object, Object>> result = new HashMap<>();
  299. result.put("ais", aisAggs);
  300. result.put("so2", so2Aggs);
  301. result.put("black", heiyanAggs);
  302. return AjaxResult.success(result);
  303. }
  304. @GetMapping("/third/timeStatic")
  305. @ApiOperation("for-Third-超标船舶统计-按时间")
  306. public AjaxResult thirdMonthStatic(@RequestParam(required = false) String interval, @RequestParam(required = false) String startMonth, @RequestParam(required = false) String endMonth) {
  307. if (StrUtil.isBlank(interval)) {
  308. // 默认值为1个月
  309. interval = "1M";
  310. }
  311. Map<String, Object> rangeCondition = new HashMap<>();
  312. if (!StrUtil.isAllBlank(startMonth, endMonth)) {
  313. if (StrUtil.isNotBlank(startMonth)) {
  314. startMonth = startMonth + "-01 00:00:00";
  315. }
  316. if (StrUtil.isNotBlank(endMonth)) {
  317. endMonth = DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parseDate(endMonth + "-01 00:00:00"))) + " 23:59:59";
  318. }
  319. rangeCondition.put("createTime", StrUtil.concat(true, "[", startMonth, ",", endMonth, "]"));
  320. }
  321. Map<String, Object> equalsCondition = new HashMap<>();
  322. equalsCondition.put("illegalStatus", 2);
  323. Map<Object, Object> so2Aggs = client.dateHistogramAggs(AggsType.count, "createTime", "id", equalsCondition, rangeCondition, new DateHistogramInterval(interval), ElasticConstants.SO2_ALERT, ElasticConstants.AIS_ILLEGAL_SHIP);
  324. equalsCondition.put("illegalStatus", 3);
  325. Map<Object, Object> heiyanAggs = client.dateHistogramAggs(AggsType.count, "createTime", "id", equalsCondition, rangeCondition, new DateHistogramInterval(interval), ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  326. Map<String, Map<Object, Object>> result = new HashMap<>();
  327. result.put("so2", so2Aggs);
  328. result.put("black", heiyanAggs);
  329. return AjaxResult.success(result);
  330. }
  331. }