Browse Source

:sparkles: 进港船舶预测

lag 1 year ago
parent
commit
3b8a2b0802

+ 160 - 0
ghjg-item-server/src/main/java/com/shanghaichengdi/ghjgitem/controller/ForecastOfIncomingShipsController.java

@@ -0,0 +1,160 @@
+package com.shanghaichengdi.ghjgitem.controller;
+
+import static com.shanghaigeography.Util.DateUtils.dateToString;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.fastjson.JSONObject;
+import com.shanghaichengdi.ghjgitem.controller.model.res.ForecastOfIncomingShipsTo;
+import com.shanghaichengdi.ghjgitem.enums.OutsideInterface;
+import com.shanghaichengdi.ghjgitem.service.IForecastOfIncomingShipsService;
+import com.shanghaichengdi.ghjgitem.util.CommonTools;
+import com.shanghaichengdi.ghjgitem.vo.BoatPredictInfoVo;
+import com.shanghaichengdi.ghjgitem.vo.ForecastBoatInfoVo;
+import com.shanghaichengdi.ghjgitem.vo.ForecastOfIncomingShipsVo;
+import com.shanghaichengdi.ghjgitem.vo.ReportBoatInfo;
+import com.shanghaigeography.entity.ResultMsg;
+import com.shanghaigeography.eum.ResultState;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import java.io.File;
+import java.util.*;
+import javax.annotation.Resource;
+import org.springframework.beans.BeanUtils;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author gengaoliu
+ */
+@Api("进港船舶预测")
+@RestController
+@CrossOrigin
+@RequestMapping("/ghjg/forecastOfIncomingShips")
+public class ForecastOfIncomingShipsController {
+  @Resource IForecastOfIncomingShipsService forecastOfIncomingShipsService;
+
+  String ghjgFileservice = OutsideInterface.GHJG_FILE_SERVICE.getUrlString();
+
+  String url = OutsideInterface.GHJG_FILE_LOAD.getUrlString();
+
+  @PostMapping("/getAllPage")
+  @ApiOperation("进港船舶预测报表")
+  public String getAllPage(@RequestBody Map<String, Object> map) {
+    List<ForecastOfIncomingShipsVo> voList = forecastOfIncomingShipsService.getAllPage(map);
+    int count = CommonTools.getTotal(voList);
+    if (CollectionUtils.isEmpty(voList)) {
+      return new ResultMsg<String>()
+          .setCode(ResultState.ERROR_NEEDDATA)
+          .setMsg("暂无数据")
+          .setData(null)
+          .toJSON();
+    }
+    return new ResultMsg<String>()
+        .setCode(ResultState.SUCCESS)
+        .setMsg(String.valueOf(count))
+        .setData(JSONObject.toJSONString(voList))
+        .toJSON();
+  }
+
+  @ApiOperation("进港船舶预测导出excel")
+  @PostMapping("/getExcel")
+  public String getExcel(@RequestBody Map<String, Object> map) {
+    String newye = dateToString(new Date(), "yyyy");
+    long s = System.nanoTime();
+    String tkk =
+        url
+            + "supervise/shipIdentification/rectify/"
+            + newye
+            + "/"
+            + dateToString(new Date(), "MM")
+            + "/excel/";
+    new File(tkk).mkdirs();
+    String towofile = tkk + s + "进港船舶预测报表.xlsx";
+    List<ForecastOfIncomingShipsTo> toList = new ArrayList<>();
+    map.replace("size", 50000);
+    JSONObject j = JSONObject.parseObject(this.getAllPage(map));
+    if (!"无数据".equals(j.get("msg"))) {
+      int i = 1;
+      List<ForecastOfIncomingShipsVo> forecastOfIncomingShipsVoList =
+          j.getJSONArray("data").toJavaList(ForecastOfIncomingShipsVo.class);
+      for (ForecastOfIncomingShipsVo vo : forecastOfIncomingShipsVoList) {
+        ForecastOfIncomingShipsTo forecastOfIncomingShipsTo = new ForecastOfIncomingShipsTo();
+        BeanUtils.copyProperties(vo, forecastOfIncomingShipsTo);
+        forecastOfIncomingShipsTo.setNum(i);
+        toList.add(forecastOfIncomingShipsTo);
+        i++;
+      }
+    }
+    if (toList.size() >= 8000) {
+      return new ResultMsg<String>()
+          .setCode(ResultState.ERROR_NEEDDATA)
+          .setMsg("导出数量庞大,请选择条件以缩小导出范围")
+          .toJSON();
+    }
+    EasyExcel.write(towofile, ForecastOfIncomingShipsTo.class)
+        .sheet("非现场执法报表信息")
+        .doWrite(() -> toList);
+    String pdfUrl = towofile.replace(url.replace("/test", ""), (ghjgFileservice + "supervise/"));
+    return new ResultMsg<String>().setCode(ResultState.SUCCESS).setMsg(pdfUrl).toJSON();
+  }
+
+  @ApiOperation("船舶基本信息")
+  @GetMapping("/getBasicInfo/{mmsi}/{boatName}")
+  public String getBasicInfo(
+      @PathVariable("mmsi") String mmsi, @PathVariable("boatName") String boatName) {
+    Optional<ForecastBoatInfoVo> voOptional =
+        forecastOfIncomingShipsService.findBoatBasicInfo(mmsi, boatName);
+    if (!voOptional.isPresent()) {
+      return new ResultMsg<String>()
+          .setCode(ResultState.ERROR_NEEDDATA)
+          .setMsg("船舶基本信息暂无数据")
+          .toJSON();
+    }
+    return new ResultMsg<String>()
+        .setCode(ResultState.SUCCESS)
+        .setData(JSONObject.toJSONString(voOptional.get()))
+        .toJSON();
+  }
+
+  @ApiOperation("船舶预测信息")
+  @GetMapping("/getPredictInfo/{mmsi}/{boatName}")
+  public String getPredictInfo(
+      @PathVariable("mmsi") String mmsi, @PathVariable("boatName") String boatName) {
+    Optional<BoatPredictInfoVo> voOptional =
+        forecastOfIncomingShipsService.getPredictInfo(mmsi, boatName);
+    if (!voOptional.isPresent()) {
+      return new ResultMsg<String>()
+          .setCode(ResultState.ERROR_NEEDDATA)
+          .setMsg("船舶预测信息暂无数据")
+          .toJSON();
+    }
+    BoatPredictInfoVo vo = voOptional.get();
+    vo.setSpeed(Optional.ofNullable(vo.getSpeed()).orElse("0"));
+    return new ResultMsg<String>()
+        .setCode(ResultState.SUCCESS)
+        .setData(JSONObject.toJSONString(vo))
+        .toJSON();
+  }
+
+  @ApiOperation("船舶到港信息")
+  @GetMapping("/getPortInfo/{mmsi}/{boatName}")
+  public String getPortInfo(
+      @PathVariable("mmsi") String mmsi, @PathVariable("boatName") String boatName) {
+    List<ReportBoatInfo> infoList = forecastOfIncomingShipsService.getPortInfo(mmsi, boatName);
+    if (CollectionUtils.isEmpty(infoList)) {
+      return new ResultMsg<String>()
+          .setCode(ResultState.ERROR_NEEDDATA)
+          .setMsg("船舶到港信息暂无数据")
+          .toJSON();
+    }
+    List<ReportBoatInfo> reportBoatInfos = new ArrayList<>(5);
+    for (int i = 0; i < 5; i++) {
+      reportBoatInfos.add(infoList.get(i));
+    }
+    return new ResultMsg<String>()
+        .setCode(ResultState.SUCCESS)
+        .setMsg(String.valueOf(reportBoatInfos.size()))
+        .setData(JSONObject.toJSONString(reportBoatInfos))
+        .toJSON();
+  }
+}

+ 37 - 0
ghjg-item-server/src/main/java/com/shanghaichengdi/ghjgitem/controller/model/res/ForecastOfIncomingShipsTo.java

@@ -0,0 +1,37 @@
+package com.shanghaichengdi.ghjgitem.controller.model.res;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+/**
+ * @author gengaoliu
+ */
+@Data
+public class ForecastOfIncomingShipsTo {
+  @ExcelProperty({"进港船舶预测报表", "序号"})
+  Integer num;
+
+  @ExcelProperty({"进港船舶预测报表", "船舶名称"})
+  String boatName;
+
+  @ExcelProperty({"进港船舶预测报表", "mmsi"})
+  String mmsi;
+
+  @ExcelProperty({"进港船舶预测报表", "船舶所有人"})
+  String shipOwner;
+
+  @ExcelProperty({"进港船舶预测报表", "航速(km/h)"})
+  String speed;
+
+  @ExcelProperty({"进港船舶预测报表", "船舶类型"})
+  String shipType;
+
+  @ExcelProperty({"进港船舶预测报表", "卡口名称"})
+  String bayonetName;
+
+  @ExcelProperty({"进港船舶预测报表", "预测时间"})
+  String reportTime;
+
+  @ExcelProperty({"进港船舶预测报表", "申报状态"})
+  String isReport;
+}

+ 27 - 0
ghjg-item-server/src/main/java/com/shanghaichengdi/ghjgitem/mapper/ForecastOfIncomingShipsMapper.java

@@ -0,0 +1,27 @@
+package com.shanghaichengdi.ghjgitem.mapper;
+
+
+import com.shanghaichengdi.ghjgitem.vo.BoatPredictInfoVo;
+import com.shanghaichengdi.ghjgitem.vo.ForecastBoatInfoVo;
+import com.shanghaichengdi.ghjgitem.vo.ForecastOfIncomingShipsVo;
+import com.shanghaichengdi.ghjgitem.vo.ReportBoatInfo;
+import java.util.List;
+import java.util.Map;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * @author gengaoliu
+ */
+@Mapper
+public interface ForecastOfIncomingShipsMapper {
+  List<ForecastOfIncomingShipsVo> getList(Map<String, Object> map);
+
+  List<ForecastBoatInfoVo> findBoatBasicInfo(
+      @Param("mmsi") String mmsi, @Param("boatName") String boatName);
+
+  List<BoatPredictInfoVo> findPredictInfoList(@Param("mmsi") String mmsi);
+
+  List<ReportBoatInfo> findReportBoatInfoList(
+      @Param("mmsi") String mmsi, @Param("boatName") String boatName);
+}

+ 22 - 0
ghjg-item-server/src/main/java/com/shanghaichengdi/ghjgitem/service/IForecastOfIncomingShipsService.java

@@ -0,0 +1,22 @@
+package com.shanghaichengdi.ghjgitem.service;
+
+import com.shanghaichengdi.ghjgitem.vo.BoatPredictInfoVo;
+import com.shanghaichengdi.ghjgitem.vo.ForecastBoatInfoVo;
+import com.shanghaichengdi.ghjgitem.vo.ForecastOfIncomingShipsVo;
+import com.shanghaichengdi.ghjgitem.vo.ReportBoatInfo;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * @author gengaoliu
+ */
+public interface IForecastOfIncomingShipsService {
+  List<ForecastOfIncomingShipsVo> getAllPage(Map<String, Object> map);
+
+  Optional<ForecastBoatInfoVo> findBoatBasicInfo(String mmsi, String boatName);
+
+  Optional<BoatPredictInfoVo> getPredictInfo(String mmsi, String boatName);
+
+  List<ReportBoatInfo> getPortInfo(String mmsi, String boatName);
+}

+ 73 - 0
ghjg-item-server/src/main/java/com/shanghaichengdi/ghjgitem/service/impl/ForecastOfIncomingShipsServiceImpl.java

@@ -0,0 +1,73 @@
+package com.shanghaichengdi.ghjgitem.service.impl;
+
+import com.github.pagehelper.PageHelper;
+import com.shanghaichengdi.ghjgitem.mapper.ForecastOfIncomingShipsMapper;
+import com.shanghaichengdi.ghjgitem.service.IForecastOfIncomingShipsService;
+import com.shanghaichengdi.ghjgitem.vo.BoatPredictInfoVo;
+import com.shanghaichengdi.ghjgitem.vo.ForecastBoatInfoVo;
+import com.shanghaichengdi.ghjgitem.vo.ForecastOfIncomingShipsVo;
+import com.shanghaichengdi.ghjgitem.vo.ReportBoatInfo;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import javax.annotation.Resource;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+/**
+ * @author gengaoliu
+ */
+@Service
+public class ForecastOfIncomingShipsServiceImpl implements IForecastOfIncomingShipsService {
+
+  private static String MODEL = "名称为:%s的船舶%s经过卡口区域,系统%s到该船舶本航次进出港报告信息";
+  @Resource ForecastOfIncomingShipsMapper mapper;
+
+  @Override
+  public List<ForecastOfIncomingShipsVo> getAllPage(Map<String, Object> info) {
+    PageHelper.startPage((int) info.get("current"), (int) info.get("size"));
+    Optional<String> reportStatus = Optional.ofNullable(String.valueOf(info.get("reportStatus")));
+    if (reportStatus.isPresent() && String.valueOf(1).equals(reportStatus.get())) {
+      info.remove("reportStatus");
+      info.put("reportStatus1", "1");
+    } else if (reportStatus.isPresent() && String.valueOf(2).equals(reportStatus.get())) {
+      info.remove("reportStatus");
+      info.put("reportStatus2", "2");
+    }
+    return mapper.getList(info);
+  }
+
+  @Override
+  public Optional<ForecastBoatInfoVo> findBoatBasicInfo(String mmsi, String boatName) {
+    Objects.requireNonNull(mmsi, "mmsi cannot be null");
+    Objects.requireNonNull(boatName, "boatName cannot be null");
+    return Optional.ofNullable(mapper.findBoatBasicInfo(mmsi, boatName).get(0));
+  }
+
+  @Override
+  public Optional<BoatPredictInfoVo> getPredictInfo(String mmsi, String boatName) {
+    Objects.requireNonNull(mmsi, "mmsi cannot be null");
+    Objects.requireNonNull(boatName, "boatName cannot be null");
+    List<BoatPredictInfoVo> predictInfoList = mapper.findPredictInfoList(mmsi);
+    if (CollectionUtils.isEmpty(predictInfoList)) {
+      return Optional.empty();
+    }
+    BoatPredictInfoVo value = predictInfoList.get(0);
+    String format =
+        String.format(
+            MODEL,
+            Optional.of(boatName).orElse("xxx"),
+            Optional.ofNullable(value.getDirection()).orElse("xx"),
+            Optional.ofNullable(value.getStatus()).orElse("xxx"));
+    value.setDescription(format);
+    return Optional.ofNullable(value);
+  }
+
+  @Override
+  public List<ReportBoatInfo> getPortInfo(String mmsi, String boatName) {
+    Objects.requireNonNull(mmsi, "mmsi cannot be null");
+    Objects.requireNonNull(boatName, "boatName cannot be null");
+    return mapper.findReportBoatInfoList(mmsi, boatName);
+  }
+}

+ 15 - 0
ghjg-item-server/src/main/java/com/shanghaichengdi/ghjgitem/vo/BoatPredictInfoVo.java

@@ -0,0 +1,15 @@
+package com.shanghaichengdi.ghjgitem.vo;
+
+import lombok.Data;
+
+/**
+ * @author gengaoliu
+ */
+@Data
+public class BoatPredictInfoVo {
+  String description;
+  String direction;
+  String status;
+  String warnTime;
+  String speed;
+}

+ 33 - 0
ghjg-item-server/src/main/java/com/shanghaichengdi/ghjgitem/vo/ForecastBoatInfoVo.java

@@ -0,0 +1,33 @@
+package com.shanghaichengdi.ghjgitem.vo;
+
+import lombok.Data;
+
+/**
+ * @author gengaoliu
+ */
+@Data
+public class ForecastBoatInfoVo {
+  String boatName;
+  String mmsi;
+  String shipId;
+  String shipRegNo;
+  String shipFirstRegNo;
+  String shipInspectNo;
+  String shipBuiltDate;
+  String regportCode;
+  String length;
+  String width;
+  String height;
+  String enginePower;
+  String shipDwt;
+  String zd;
+  String shipNetton;
+  String flagStateCode;
+  String shipTypeName;
+  String shipRegionType;
+  String shipOwnerCn;
+  String ownerContactPhone;
+  String shipOwnerAddrCn;
+  String shipOperator;
+  String ownerLegalPerson;
+}

+ 18 - 0
ghjg-item-server/src/main/java/com/shanghaichengdi/ghjgitem/vo/ForecastOfIncomingShipsVo.java

@@ -0,0 +1,18 @@
+package com.shanghaichengdi.ghjgitem.vo;
+
+import lombok.Data;
+
+/**
+ * @author gengaoliu
+ */
+@Data
+public class ForecastOfIncomingShipsVo {
+	String boatName;
+    String mmsi;
+    String shipOwner;
+    String speed;
+    String shipType;
+    String bayonetName;
+    String reportTime;
+    String isReport;
+}

+ 18 - 0
ghjg-item-server/src/main/java/com/shanghaichengdi/ghjgitem/vo/ReportBoatInfo.java

@@ -0,0 +1,18 @@
+package com.shanghaichengdi.ghjgitem.vo;
+
+import lombok.Data;
+
+/**
+ * @author gengaoliu
+ */
+@Data
+public class ReportBoatInfo {
+  String reportId;
+  String portName;
+  String prePortName;
+  String nextPortName;
+  String reportTime;
+  String expectTime;
+  String specificName;
+  String capacity;
+}

+ 109 - 0
ghjg-item-server/src/main/resources/mapper/ForecastOfIncomingShipsMapper.xml

@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.shanghaichengdi.ghjgitem.mapper.ForecastOfIncomingShipsMapper">
+  <select id="getList" resultType="com.shanghaichengdi.ghjgitem.vo.ForecastOfIncomingShipsVo">
+    SELECT DISTINCT t.SHIP_NAME_CN AS boatName,
+    t.MMSI AS mmsi,
+    t.SHIP_OWNER AS shipOwner,
+    ais.VELOCITY AS speed,
+    type.ITEM_NAME_CN AS shipType,
+    bayonet.NAME AS bayonetName,
+    t.REPORT_TIME AS reportTime,
+    decode(port.REPORTCODE, null, '未报港', '已报港') isReport
+    FROM BAYONET_BUSSINESS.BOAT_IN_PORT_WARNING port
+    left join nhyw.c_cb_ship_eep_report_rec t on t.MMSI = port.MMSI
+    LEFT JOIN bayonet_dynamic.datafusion_aisinfo ais ON ais.MMSI = t.MMSI
+    LEFT JOIN GHJG_BASICS.D_CB_SHIP_TYPE type ON type.CODE = t.SHIP_TYPE_CODE
+    LEFT JOIN bayonet_dynamic.DATAFUSION fusion ON fusion.BOAT_NAME = t.SHIP_NAME_CN
+    LEFT JOIN bayonet_basics.sys_bayonet bayonet ON fusion.BAYONET_ID = bayonet.ID
+    where t.MMSI is not null
+    and t.SHIP_OWNER is not null
+    and ais.VELOCITY is not null
+    <if test="shipName != null and shipName != ''">
+      and t.SHIP_NAME_CN like '%'||#{shipName}||'%'
+    </if>
+    <if test="mmsi != null and mmsi != ''">
+      and t.MMSI = #{mmsi}
+    </if>
+    <if test="reportStatus1 != null and reportStatus1 != ''">
+      and port.REPORTCODE is null
+    </if>
+    <if test="reportStatus2 != null and reportStatus2 != ''">
+      and port.REPORTCODE is not null
+    </if>
+    <if test="shipType != null and shipType != ''">
+      and t.SHIP_TYPE_CODE = #{shipType}
+    </if>
+    <if test="bayonetName != null and bayonetName != ''">
+      and bayonet.id= #{bayonetName}
+    </if>
+    <if test="startTime != null and startTime != ''">
+      and t.REPORT_TIME >= to_date(#{startTime},'yyyy-mm-dd hh24:mi:ss')
+    </if>
+    <if test="endTime != null and endTime != ''">
+      and t.REPORT_TIME &lt;= to_date(#{endTime},'yyyy-mm-dd hh24:mi:ss')
+    </if>
+    order by t.REPORT_TIME desc
+  </select>
+
+
+  <select id="findBoatBasicInfo" resultType="com.shanghaichengdi.ghjgitem.vo.ForecastBoatInfoVo">
+    select distinct info.SHIP_NAME_CN                                     boatName,
+                    info.MMSI                                             mmsi,
+                    info.SHIP_ID                                          shipId,
+                    info.SHIP_REG_NO                                      shipRegNo,
+                    info.SHIP_FIRSTREG_NO                                 shipFirstRegNo,
+                    info.SHIP_INSPECT_NO                                  shipInspectNo,
+                    info.SHIP_BUILT_DATE                                  shipBuiltDate,
+                    info.REGPORT_CODE                                     regportCode,
+                    fusion.LENGTH                                         length,
+                    fusion.WIDTH                                          width,
+                    fusion.HEIGHT                                         height,
+                    info.SHIP_ENGINE_POWER                                enginePower,
+                    info.SHIP_DWT                                         shipDwt,
+                    info.SHIP_GROSSTON                                    zd,
+                    info.SHIP_NETTON                                      shipNetton,
+                    report.FLAG_STATE_CODE                                flagStateCode,
+                    info.SHIP_TYPE_NAME                                   shipTypeName,
+                    decode(info.SHIP_REGION_TYPE, 0, '内河船', 1, '海河') shipRegionType,
+                    info.SHIP_OWNER_CN                                    shipOwnerCn,
+                    info.OWNER_CONTACT_PHONE                              ownerContactPhone,
+                    info.SHIP_OWNER_ADDR_CN                               shipOwnerAddrCn,
+                    report.SHIP_OPERATOR                                  shipOperator,
+                    info.OWNER_LEGAL_PERSON                               ownerLegalPerson
+    from ghjg_basics.mvw_boat_info info
+           left join bayonet_dynamic.DATAFUSION fusion on fusion.BOAT_NAME = info.SHIP_NAME_CN
+           left join nhyw.c_cb_ship_eep_report_rec report on report.MMSI = info.MMSI
+    where info.MMSI = #{mmsi}
+      and info.SHIP_NAME_CN = #{boatName}
+  </select>
+
+
+  <select id="findPredictInfoList" resultType="com.shanghaichengdi.ghjgitem.vo.BoatPredictInfoVo">
+    select T.DIRECTION                                    direction,
+           decode(T.REPORTCODE, null, '未匹配', '已匹配') status,
+           T.WARNINGTIME                                  warnTime,
+           T.SPEED                                        speed
+    from BAYONET_BUSSINESS.BOAT_IN_PORT_WARNING T
+    where T.mmsi = #{mmsi}
+  </select>
+
+  <select id="findReportBoatInfoList" resultType="com.shanghaichengdi.ghjgitem.vo.ReportBoatInfo">
+    select rec.REPORT_ID                reportId,
+           rec.REPORT_PORT_NAME         portName,
+           rec.PRE_PORT_NAME            prePortName,
+           rec.NEXT_PORT_NAME           nextPortName,
+           rec.REPORT_TIME              reportTime,
+           rec.EXPECT_TIME              expectTime,
+           dec.SPECIFIC_NAME            specificName,
+           rec.ACTUAL_CARRYING_CAPACITY capacity
+    from nhyw.c_cb_ship_eep_report_rec rec
+           left join nhyw.c_cb_cargo_declare_rec dec
+    on rec.REPORT_ID = dec.REPORT_ID
+    where rec.SHIP_NAME_CN = #{boatName}
+      and rec.mmsi = #{mmsi}
+    order by rec.REPORT_TIME
+    desc
+  </select>
+</mapper>