Przeglądaj źródła

轨迹详情,数据导出及处置优化

minghao-chen 2 lat temu
rodzic
commit
269738bb08
17 zmienionych plików z 275 dodań i 16 usunięć
  1. 83 0
      beidou-admin/src/main/java/cn/com/taiji/beidou/web/controller/ship/ShipTrackController.java
  2. 1 1
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/archives/domain/ShipArchivesData.java
  3. 9 3
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/archives/service/impl/ShipArchivesServiceImpl.java
  4. 1 1
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/focus/domain/FocusShipResult.java
  5. 1 1
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/status/domain/ShipStatusResult.java
  6. 20 0
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/domain/ShipTrackReq.java
  7. 27 0
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/domain/ShipTrackResult.java
  8. 22 0
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/mapper/ShipTrackMapper.java
  9. 34 0
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/service/ShipTrackService.java
  10. 36 0
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/service/impl/ShipTrackServiceImpl.java
  11. 2 0
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/warning/record/domain/SimpleWarningRecordResult.java
  12. 5 2
      beidou-ship/src/main/java/cn/com/taiji/beidou/ship/warning/record/service/impl/WarningRecordServiceImpl.java
  13. 1 1
      beidou-ship/src/main/resources/mapper/FocusShipMapper.xml
  14. 4 3
      beidou-ship/src/main/resources/mapper/ShipArchivesMapper.xml
  15. 3 2
      beidou-ship/src/main/resources/mapper/ShipStatusMapper.xml
  16. 24 0
      beidou-ship/src/main/resources/mapper/ShipTrackMapper.xml
  17. 2 2
      beidou-ship/src/main/resources/mapper/WarningRecordMapper.xml

+ 83 - 0
beidou-admin/src/main/java/cn/com/taiji/beidou/web/controller/ship/ShipTrackController.java

@@ -0,0 +1,83 @@
+package cn.com.taiji.beidou.web.controller.ship;
+
+import cn.com.taiji.beidou.common.config.RuoYiConfig;
+import cn.com.taiji.beidou.common.core.controller.BaseController;
+import cn.com.taiji.beidou.common.core.domain.AjaxResult;
+import cn.com.taiji.beidou.common.core.domain.R;
+import cn.com.taiji.beidou.common.core.page.TableDataInfo;
+import cn.com.taiji.beidou.common.utils.StringUtils;
+import cn.com.taiji.beidou.common.utils.file.FileUtils;
+import cn.com.taiji.beidou.common.utils.poi.ExcelUtil;
+import cn.com.taiji.beidou.ship.track.domain.ShipTrackReq;
+import cn.com.taiji.beidou.ship.track.domain.ShipTrackResult;
+import cn.com.taiji.beidou.ship.track.service.ShipTrackService;
+import cn.com.taiji.beidou.ship.warning.record.domain.WarningRecordExcel;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * @Author CHEN
+ * @Date 2023/1/12 18:09
+ */
+@Api(tags = "北斗轨迹")
+@RestController
+public class ShipTrackController extends BaseController {
+    private static final Logger log = LoggerFactory.getLogger(ShipWarningRecordController.class);
+    @Resource
+    private ShipTrackService shipTrackService;
+
+    @ApiOperation("北斗轨迹详情")
+    @PostMapping("/getTrackDetail")
+    public TableDataInfo getTrackDetail(@RequestBody ShipTrackReq req){
+
+        startPage(req.getPageNum(),req.getPageSize());
+        return getDataTable(shipTrackService.selectShipTrackDetail(req));
+
+    }
+
+    @ApiOperation("航速分析")
+    @PostMapping("/speedAnalysis")
+    public R<List<ShipTrackResult>> speedAnalysis(@RequestBody ShipTrackReq req){
+
+        return R.ok(shipTrackService.selectShipTrackDetail(req));
+
+    }
+
+    @ApiOperation("轨迹导出")
+    @PostMapping("/getTrackExcel")
+    public void getTrackDetailExcel(@RequestBody ShipTrackReq req, HttpServletResponse response){
+
+            List<ShipTrackResult> shipTrackResults = shipTrackService.selectShipTrackDetail(req);
+            ExcelUtil<ShipTrackResult> util = new ExcelUtil<ShipTrackResult>(ShipTrackResult.class);
+            AjaxResult result = util.exportExcel(shipTrackResults, "北斗轨迹-"+req.getDeviceId());
+            String fileName = (String) result.get("msg");
+            try {
+                if (!FileUtils.checkAllowDownload(fileName)){
+                    throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
+                }
+                String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
+                String filePath = RuoYiConfig.getDownloadPath() + fileName;
+                response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+                FileUtils.setAttachmentResponseHeader(response, realFileName);
+                FileUtils.writeBytes(filePath, response.getOutputStream());
+                //是否删除已下载文件
+                FileUtils.deleteFile(filePath);
+            }
+            catch (Exception e)
+            {
+                log.error("下载文件失败", e);
+            }
+    }
+
+}

+ 1 - 1
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/archives/domain/ShipArchivesData.java

@@ -88,7 +88,7 @@ public class ShipArchivesData {
     /**
      * 最后状态
      */
-    @ApiModelProperty("最后状态 1在线,2离线,3回收,4遮挡,5损坏,6故障,7丢失,8馈电,9查扣、没收,10拆卸,0正常")
+    @ApiModelProperty("最后状态 1在线,2离线,3已标记")
     private Integer lastStatus;
 
     private String deptName;

+ 9 - 3
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/archives/service/impl/ShipArchivesServiceImpl.java

@@ -68,12 +68,18 @@ public class ShipArchivesServiceImpl implements ShipArchivesService {
 
         ShipArchivesTotal total = shipArchivesMapper.getShipTotal(deptId);
 
-        Double shipTotal = Double.parseDouble(total.getShipTotal());
-        total.setOnlineTotalRate(MathUtils.getHalfUp(Double.parseDouble(total.getOnlineTotal())/shipTotal*100,2));
+        int shipTotal = Integer.parseInt(total.getShipTotal());
+        int online = Integer.parseInt(total.getOnlineTotal());
+        int mark = Integer.parseInt(total.getMark());
+
+        //int offline = shipTotal - (online + mark);
+        //total.setOfflineTotal(String.valueOf(offline));
+
+        total.setOnlineTotalRate(MathUtils.getHalfUp((double)online/shipTotal*100,2));
         total.setOfflineTotalRate(MathUtils.getHalfUp(Double.parseDouble(total.getOfflineTotal())/shipTotal*100,2));
         total.setInPortRate(MathUtils.getHalfUp(Double.parseDouble(total.getInPort())/shipTotal*100,2));
         total.setOffPortRate(MathUtils.getHalfUp(Double.parseDouble(total.getOffPort())/shipTotal*100,2));
-        total.setMarkRate(MathUtils.getHalfUp(Double.parseDouble(total.getMark())/shipTotal*100,2));
+        total.setMarkRate(MathUtils.getHalfUp((double)mark/shipTotal*100,2));
 
         return total;
     }

+ 1 - 1
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/focus/domain/FocusShipResult.java

@@ -110,7 +110,7 @@ public class FocusShipResult {
     /**
      * 最后状态
      */
-    @ApiModelProperty("最后状态")
+    @ApiModelProperty("最后状态 1在线,2离线,3已标记")
     private Integer lastStatus;
 
     @ApiModelProperty("终端状态")

+ 1 - 1
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/status/domain/ShipStatusResult.java

@@ -128,7 +128,7 @@ public class ShipStatusResult {
     /**
      * 最后状态
      */
-    @ApiModelProperty("最后状态")
+    @ApiModelProperty("最后状态 1在线,2离线,3已标记")
     private Integer lastStatus;
 
     private String deptName;

+ 20 - 0
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/domain/ShipTrackReq.java

@@ -0,0 +1,20 @@
+package cn.com.taiji.beidou.ship.track.domain;
+
+import lombok.Data;
+
+/**
+ * @Author CHEN
+ * @Date 2023/1/12 17:55
+ */
+@Data
+public class ShipTrackReq {
+
+    private String deviceId;
+
+    private String startTime;
+    private String endTime;
+
+    private Integer pageNum;
+    private Integer pageSize;
+
+}

+ 27 - 0
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/domain/ShipTrackResult.java

@@ -0,0 +1,27 @@
+package cn.com.taiji.beidou.ship.track.domain;
+
+import cn.com.taiji.beidou.common.annotation.Excel;
+import lombok.Data;
+
+/**
+ * @Author CHEN
+ * @Date 2023/1/12 17:58
+ */
+@Data
+public class ShipTrackResult {
+
+    private String id;
+    @Excel(name = "设备编号")
+    private String deviceId;
+
+    @Excel(name = "发送位置时间")
+    private String sendTime;
+    @Excel(name = "船速")
+    private String speed;
+    @Excel(name = "船向")
+    private String direction;
+    @Excel(name = "经度")
+    private String longitude;
+    @Excel(name = "纬度")
+    private String latitude;
+}

+ 22 - 0
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/mapper/ShipTrackMapper.java

@@ -0,0 +1,22 @@
+package cn.com.taiji.beidou.ship.track.mapper;
+
+import cn.com.taiji.beidou.ship.track.domain.ShipTrackReq;
+import cn.com.taiji.beidou.ship.track.domain.ShipTrackResult;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * @Author CHEN
+ * @Date 2023/1/12 17:51
+ */
+@Mapper
+public interface ShipTrackMapper {
+
+    /**
+     * 查询轨迹详情
+     * @param shipTrackReq
+     * @return
+     */
+    List<ShipTrackResult> selectShipTrackDetail(ShipTrackReq shipTrackReq);
+}

+ 34 - 0
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/service/ShipTrackService.java

@@ -0,0 +1,34 @@
+package cn.com.taiji.beidou.ship.track.service;
+
+import cn.com.taiji.beidou.ship.track.domain.ShipTrackReq;
+import cn.com.taiji.beidou.ship.track.domain.ShipTrackResult;
+
+import java.util.List;
+
+/**
+ * @Author CHEN
+ * @Date 2023/1/12 18:06
+ */
+public interface ShipTrackService {
+    /**
+     * 查询轨迹详情
+     * @param shipTrackReq
+     * @return
+     */
+    List<ShipTrackResult> selectShipTrackDetail(ShipTrackReq shipTrackReq);
+
+
+    /**
+     * 将经纬度转换为度分秒格式
+     *
+     * @param du 116.41884740.0897315
+     * @return 116°25'7.85"       40°5'23.03"
+     */
+    default  String latLng2Dfm(double du) {
+        int du1 = (int) du;
+        double tp = (du - du1) * 60;
+        int fen = (int) tp;
+        String miao = String.format("%.0f", Math.abs(((tp - fen) * 60)));
+        return du1 + "°" + Math.abs(fen) + "'" + miao + "\"";
+    }
+}

+ 36 - 0
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/track/service/impl/ShipTrackServiceImpl.java

@@ -0,0 +1,36 @@
+package cn.com.taiji.beidou.ship.track.service.impl;
+
+import cn.com.taiji.beidou.ship.track.domain.ShipTrackReq;
+import cn.com.taiji.beidou.ship.track.domain.ShipTrackResult;
+import cn.com.taiji.beidou.ship.track.mapper.ShipTrackMapper;
+import cn.com.taiji.beidou.ship.track.service.ShipTrackService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * @Author CHEN
+ * @Date 2023/1/12 18:07
+ */
+@Service
+public class ShipTrackServiceImpl implements ShipTrackService {
+
+    @Resource
+    private ShipTrackMapper shipTrackMapper;
+
+    @Override
+    public List<ShipTrackResult> selectShipTrackDetail(ShipTrackReq shipTrackReq) {
+        List<ShipTrackResult> results = shipTrackMapper.selectShipTrackDetail(shipTrackReq);
+        //经纬度格式转换
+        results.stream().forEach(result->{
+            BigDecimal longitude = new BigDecimal(result.getLongitude());
+            result.setLongitude(latLng2Dfm(longitude.doubleValue()));
+            BigDecimal latitude = new BigDecimal(result.getLatitude());
+            result.setLatitude(latLng2Dfm(latitude.doubleValue()));
+        });
+
+        return results;
+    }
+}

+ 2 - 0
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/warning/record/domain/SimpleWarningRecordResult.java

@@ -1,6 +1,7 @@
 package cn.com.taiji.beidou.ship.warning.record.domain;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 /**
@@ -14,5 +15,6 @@ public class SimpleWarningRecordResult {
     @JsonFormat(shape =JsonFormat.Shape.STRING,pattern ="yyyy-MM-dd HH:mm:ss",timezone ="GMT+8")
     private String warningTime;
 
+    @ApiModelProperty("处置ID 有值是已读,null是未读")
     private String disposeId;
 }

+ 5 - 2
beidou-ship/src/main/java/cn/com/taiji/beidou/ship/warning/record/service/impl/WarningRecordServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.com.taiji.beidou.ship.warning.record.service.impl;
 
+import cn.com.taiji.beidou.common.constant.Constants;
 import cn.com.taiji.beidou.common.utils.SecurityUtils;
 import cn.com.taiji.beidou.common.utils.uuid.SnowFlakeIdWorker;
 import cn.com.taiji.beidou.ship.archives.domain.ShipDisposeData;
@@ -55,9 +56,11 @@ public class WarningRecordServiceImpl implements WarningRecordService {
         shipDisposeData.setDisposeUserId(String.valueOf(SecurityUtils.getUserId()));
         shipDisposeData.setId(new SnowFlakeIdWorker(1,0).nextId());
 
-        //更新处置状态
         WarningRecordData byId = warningRecordMapper.getRecordById(shipDisposeData.getWarningId());
-        shipStatusMapper.updateMark("MARK",byId.getDeviceId());
+        //更新处置状态  如果处置类型是正常,则不添加标记
+        if(!Constants.ZERO.equals(shipDisposeData.getDisposeType())){
+            shipStatusMapper.updateMark("MARK",byId.getDeviceId());
+        }
         shipDisposeData.setDevideNo(byId.getDeviceId());
         return warningRecordMapper.insertDispose(shipDisposeData);
     }

+ 1 - 1
beidou-ship/src/main/resources/mapper/FocusShipMapper.xml

@@ -78,7 +78,7 @@
         LEFT JOIN ax_beidou_ship_status st on st.device_id = focus.devide_no
         LEFT JOIN ax_beidou_ship_location location on focus.devide_no = location.device_id
         where 1=1
-        <if test="shipId != null and shipId != ''">and (archives.ship_id like concat('%', #{shipId},'%') or archives.devide_no like concat('%', #{devideNo},'%'))</if>
+        <if test="shipId != null and shipId != ''">and (archives.ship_id like concat('%', #{shipId},'%') or archives.devide_no like concat('%', #{shipId},'%'))</if>
         <if test="deptId != null and deptId != ''">and dept.xw_dept_id like concat('%',#{deptId},'%')</if>
         <if test="userId != null and userId != ''">and focus.user_id=#{userId}</if>
         <if test="sortField != null and sortField != ''">ORDER BY ${sortField} </if>

+ 4 - 3
beidou-ship/src/main/resources/mapper/ShipArchivesMapper.xml

@@ -108,8 +108,8 @@
     <select id="selectShipArchivesList" parameterType="shipArchivesREQ" resultMap="ShipResult">
         SELECT
         archives.*,
-        ( CASE sta.is_online WHEN 'ONLINE' THEN 1 WHEN 'OFFLINE' THEN 2 WHEN 'MARK' THEN 3 ELSE 1 END ) AS STATUS,
-        ( CASE ISNULL(dispose_temp.dispose_type) WHEN 0 THEN dispose_temp.dispose_type WHEN 1 THEN 1 END) AS device_status,
+        ( CASE sta.is_online WHEN 'ONLINE' THEN 1 WHEN 'OFFLINE' THEN 2 WHEN 'MARK' THEN dispose_temp.dispose_type ELSE 2 END ) AS STATUS,
+        IFNULL(dispose_temp.dispose_type,'0') as device_status,
         dept.pscmc AS dept_name,
         location.longitude,
         location.latitude,
@@ -155,9 +155,10 @@
             SUM(CASE sta.is_inport WHEN 'TRUE' THEN 1 ELSE 0 END)  as inport,
             SUM(CASE sta.is_inport WHEN 'FALSE' THEN 1 ELSE 0 END)  as offport
             from ax_beidou_ship_archives archives
+            INNER JOIN ax_beidou_dept dept ON archives.police_station_id = dept.pscbh
             LEFT JOIN ax_beidou_ship_status sta ON archives.devide_no = sta.device_id
             where 1=1
-            <if test="deptId != null and deptId != ''">and sta.dept_id like concat('%',#{deptId},'%')</if>
+            <if test="deptId != null and deptId != ''">and dept.xw_dept_id like concat('%',#{deptId},'%')</if>
     </select>
 
 

+ 3 - 2
beidou-ship/src/main/resources/mapper/ShipStatusMapper.xml

@@ -65,7 +65,7 @@
         </if>
         <if test="isStasis != null and isStasis != ''">
             and st.is_anchor = #{isStasis}
-            and TIMESTAMPDIFF(MINUTE,st.anchor_change_time,NOW())>24*60*7
+--             and TIMESTAMPDIFF(MINUTE,st.anchor_change_time,NOW())>24*60*7
         </if>
     </select>
 
@@ -132,7 +132,8 @@
         <if test="deptId != null and deptId != ''">
         inner join ax_beidou_dept dept on archives.police_station_id = dept.pscbh
         </if>
-        where st.is_anchor='TRUE' and TIMESTAMPDIFF(MINUTE,st.anchor_change_time,NOW())>24*60*7
+        where st.is_anchor='TRUE'
+--         and TIMESTAMPDIFF(MINUTE,st.anchor_change_time,NOW())>24*60*7
         <if test="shipId != null and shipId != ''">and (archives.ship_id like concat('%', #{shipId},'%') or archives.devide_no like concat('%', #{devideNo},'%'))</if>
         <if test="deptId != null and deptId != ''">and dept.xw_dept_id like concat('%',#{deptId},'%')</if>
     </select>

+ 24 - 0
beidou-ship/src/main/resources/mapper/ShipTrackMapper.xml

@@ -0,0 +1,24 @@
+<?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="cn.com.taiji.beidou.ship.track.mapper.ShipTrackMapper">
+
+    <resultMap type="shipTrackResult" id="shipTrackResult">
+        <id property="id" column="id"/>
+        <result property="deviceId" column="device_id"/>
+        <result property="sendTime" column="send_time"/>
+        <result property="longitude" column="longitude"/>
+        <result property="latitude" column="latitude"/>
+        <result property="direction" column="direction"/>
+        <result property="speed" column="speed"/>
+    </resultMap>
+
+    <select id="selectShipTrackDetail" parameterType="shipTrackReq" resultMap="shipTrackResult">
+        select id,device_id,send_time,longitude,latitude,direction,speed from ax_beidou_track track
+        where track.device_id = #{deviceId}
+        <if test="endTime != null and endTime != ''">and track.location_time &lt; #{endTime}</if>
+        <if test="startTime != null and startTime != ''">and track.location_time &gt; #{startTime}</if>
+        order by track.location_time ASC
+    </select>
+</mapper>

+ 2 - 2
beidou-ship/src/main/resources/mapper/WarningRecordMapper.xml

@@ -105,8 +105,8 @@
     </select>
 
     <select id="getRecordById" parameterType="string" resultType="warningRecordData">
-        select id,rule_id as ruleId, model_id as modelId,warning_time as warningTime,device_id as deviceId from ax_beidou_warning_record where id = #{id}
+        select id,rule_id as ruleId, model_id as modelId,warning_time as warningTime,device_id as deviceId
+        from ax_beidou_warning_record where id = #{id} and (`start` is null or `start` != 'false')
     </select>
 
-
 </mapper>