Explorar el Código

实时位置、小程序接口

shs hace 1 año
padre
commit
49f6e95fe0

+ 25 - 4
aidex-controller/src/main/java/com/aidex/web/controller/app/AppController.java

@@ -1,18 +1,18 @@
 package com.aidex.web.controller.app;
 
 
+import com.aidex.common.app.domain.vo.SysWharfVO;
 import com.aidex.common.app.server.IAppService;
 import com.aidex.common.core.domain.R;
+import com.aidex.common.gps.domain.LocationEntity;
 import com.aidex.system.domain.SysNotice;
+import com.aidex.system.domain.SysWharf;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -48,4 +48,25 @@ public class AppController {
     {
         return R.data(iAppService.findCarouselAndNoticeDetails(id));
     }
+
+    @GetMapping("/wharf")
+    @ApiOperation(value = "获取全部站点列表", notes = "获取全部站点列表", produces = "application/json")
+    public R<List<SysWharf>> findSysWharfList()
+    {
+        return R.data(iAppService.findSysWharfList());
+    }
+
+    @GetMapping("/location")
+    @ApiOperation(value = "获取全部船只位置", notes = "获取全部船只位置", produces = "application/json")
+    public R<List<LocationEntity>> getLocationAll()
+    {
+        return R.data(iAppService.findAllLocation());
+    }
+
+    @GetMapping("/wharf/my")
+    @ApiOperation(value = "获取离我最近的站点及距离", notes = "获取离我最近的站点及距离", produces = "application/json")
+    public R<List<SysWharfVO>> getWharfMy(@RequestParam(defaultValue = "",name = "lat") String lat, @RequestParam(defaultValue = "",name = "lon") String lon )
+    {
+        return R.data(iAppService.findNearestStation(lat,lon));
+    }
 }

+ 10 - 0
aidex-system/src/main/java/com/aidex/common/app/domain/vo/SysWharfVO.java

@@ -0,0 +1,10 @@
+package com.aidex.common.app.domain.vo;
+
+import com.aidex.system.domain.SysWharf;
+import lombok.Data;
+
+@Data
+public class SysWharfVO extends SysWharf {
+
+    private Double distance;
+}

+ 9 - 0
aidex-system/src/main/java/com/aidex/common/app/server/IAppService.java

@@ -1,6 +1,9 @@
 package com.aidex.common.app.server;
 
+import com.aidex.common.app.domain.vo.SysWharfVO;
+import com.aidex.common.gps.domain.LocationEntity;
 import com.aidex.system.domain.SysNotice;
+import com.aidex.system.domain.SysWharf;
 
 import java.util.List;
 
@@ -11,4 +14,10 @@ public interface IAppService {
     List<SysNotice> getNoticeList();
 
     SysNotice findCarouselAndNoticeDetails(String id);
+
+    List<SysWharf> findSysWharfList();
+
+    List<LocationEntity> findAllLocation();
+
+    List<SysWharfVO> findNearestStation(String lat, String lng);
 }

+ 42 - 0
aidex-system/src/main/java/com/aidex/common/app/server/impl/AppService.java

@@ -1,21 +1,37 @@
 package com.aidex.common.app.server.impl;
 
+import com.aidex.common.app.domain.vo.SysWharfVO;
 import com.aidex.common.app.server.IAppService;
+import com.aidex.common.exception.SysException;
 import com.aidex.common.gps.common.GeneratorGspApi;
+import com.aidex.common.gps.domain.LocationEntity;
+import com.aidex.common.gps.server.IGpsService;
+import com.aidex.common.utils.StringUtils;
+import com.aidex.common.utils.dist.CalcDist;
 import com.aidex.system.domain.SysNotice;
 import com.aidex.system.domain.SysShip;
+import com.aidex.system.domain.SysWharf;
 import com.aidex.system.service.SysNoticeService;
 import com.aidex.system.service.SysShipService;
+import com.aidex.system.service.SysWharfService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
 public class AppService implements IAppService {
 
     @Autowired
     private SysNoticeService sysNoticeService;
+    @Autowired
+    private SysWharfService sysWharfService;
+    @Autowired
+    private IGpsService iGpsService;
 
 
     public List<SysNotice> getCarouselList(){
@@ -32,4 +48,30 @@ public class AppService implements IAppService {
     public SysNotice findCarouselAndNoticeDetails(String id){
         return sysNoticeService.get(id);
     }
+
+    public List<SysWharf> findSysWharfList(){
+        return sysWharfService.findList(new SysWharf());
+    }
+
+    public List<LocationEntity> findAllLocation(){
+        return iGpsService.getLocationBatch();
+    }
+
+    public List<SysWharfVO> findNearestStation(String lat, String lon){
+        if(StringUtils.isEmpty(lat) || StringUtils.isEmpty(lon))
+            throw new SysException(4441,"请告诉我你在哪");
+        List<SysWharf> listWharf = sysWharfService.findList(new SysWharf());
+        List<SysWharfVO> vos = new ArrayList<>();
+        for (SysWharf sysWharf : listWharf) {
+            SysWharfVO wharfVO = new SysWharfVO();
+            BeanUtils.copyProperties(sysWharf,wharfVO);
+            wharfVO.setDistance(CalcDist.calculateDistance(Double.valueOf(lat),Double.valueOf(lon),
+                    Double.valueOf(sysWharf.getLat()),Double.valueOf(sysWharf.getLng())));
+            vos.add(wharfVO);
+        }
+        return  vos.stream().sorted(Comparator.comparing(SysWharfVO::getDistance))
+                .collect(Collectors.toList());
+    }
+
+
 }

+ 19 - 17
aidex-system/src/main/java/com/aidex/common/gps/common/GpsRequest.java

@@ -4,7 +4,9 @@ import cn.hutool.http.HttpRequest;
 import com.aidex.common.exception.SysException;
 import com.aidex.common.utils.StringUtils;
 import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.alibaba.fastjson2.TypeReference;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -13,113 +15,113 @@ import java.util.List;
 import java.util.Map;
 
 @Component
-public class GpsRequest<T> {
+public class GpsRequest {
 
     @Autowired
     private GeneratorGspApi generatorGspApi;
 
 
-    public List<T> postArray(Map<String,Object> params, Integer timeOut){
+    public JSONArray postArray(Map<String,Object> params, Integer timeOut){
         JSONObject res = postRequest(params,timeOut);
         Boolean status = res.getBoolean("success");
         Integer code = res.getInteger("errorCode");
         String msg = res.getString("errorDescribe");
 
         if(status){
-            return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
+            return res.getJSONArray("data");
         }
         throw new SysException(code,"GPS数据获取错误:"+msg);
 
     }
 
-    public List<T> postArray(Map<String,Object> params){
+    public JSONArray postArray(Map<String,Object> params){
         JSONObject res = postRequest(params,1000);
         Boolean status = res.getBoolean("success");
         Integer code = res.getInteger("errorCode");
         String msg = res.getString("errorDescribe");
 
         if(status){
-            return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
+            return res.getJSONArray("data");
         }
         throw new SysException(code,"GPS数据获取错误:"+msg);
 
     }
 
 
-    public T post(Map<String,Object> params, Integer timeOut){
+    public JSONObject post(Map<String,Object> params, Integer timeOut){
         JSONObject res = postRequest(params,timeOut);
         Boolean status = res.getBoolean("success");
         Integer code = res.getInteger("errorCode");
         String msg = res.getString("errorDescribe");
 
         if(status){
-            return (T) JSONObject.parseObject(res.getString("data"), Map.class);
+            return res.getJSONObject("data");
         }
         throw new SysException(code,"GPS数据获取错误:"+msg);
 
     }
 
-    public T post(Map<String,Object> params){
+    public JSONObject post(Map<String,Object> params){
         JSONObject res = postRequest(params,1000);
         Boolean status = res.getBoolean("success");
         Integer code = res.getInteger("errorCode");
         String msg = res.getString("errorDescribe");
 
         if(status){
-            return (T) JSONObject.parseObject(res.getString("data"), Map.class);
+            return res.getJSONObject("data");
         }
         throw new SysException(code,"GPS数据获取错误:"+msg);
 
     }
 
-    public List<T> getArray(Map<String,Object> params, Integer timeOut){
+    public JSONArray getArray(Map<String,Object> params, Integer timeOut){
         JSONObject res = postRequest(params,timeOut);
         Boolean status = res.getBoolean("success");
         Integer code = res.getInteger("errorCode");
         String msg = res.getString("errorDescribe");
 
         if(status){
-            return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
+            return res.getJSONArray("data");
         }
         throw new SysException(code,"GPS数据获取错误:"+msg);
 
     }
 
-    public List<T> getArray(Map<String,Object> params){
+    public JSONArray getArray(Map<String,Object> params){
         JSONObject res = postRequest(params,1000);
         Boolean status = res.getBoolean("success");
         Integer code = res.getInteger("errorCode");
         String msg = res.getString("errorDescribe");
 
         if(status){
-            return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
+            return res.getJSONArray("data");
         }
         throw new SysException(code,"GPS数据获取错误:"+msg);
 
     }
 
 
-    public T get(Map<String,Object> params, Integer timeOut){
+    public JSONObject get(Map<String,Object> params, Integer timeOut){
         JSONObject res = postRequest(params,timeOut);
         Boolean status = res.getBoolean("success");
         Integer code = res.getInteger("errorCode");
         String msg = res.getString("errorDescribe");
 
         if(status){
-            return (T) JSONObject.parseObject(res.getString("data"), Map.class);
+            return res.getJSONObject("data");
         }
         throw new SysException(code,"GPS数据获取错误:"+msg);
 
     }
 
-    public T get(Map<String,Object> params){
+    public JSONObject get(Map<String,Object> params){
         JSONObject res = postRequest(params,1000);
         Boolean status = res.getBoolean("success");
         Integer code = res.getInteger("errorCode");
         String msg = res.getString("errorDescribe");
 
         if(status){
-            return (T) JSONObject.parseObject(res.getString("data"), Map.class);
+            return res.getJSONObject("data");
         }
         throw new SysException(code,"GPS数据获取错误:"+msg);
 

+ 7 - 6
aidex-system/src/main/java/com/aidex/common/gps/server/impl/GpsService.java

@@ -7,6 +7,7 @@ import com.aidex.common.gps.domain.LocationEntity;
 import com.aidex.common.gps.server.IGpsService;
 import com.aidex.system.domain.SysShip;
 import com.aidex.system.service.SysShipService;
+import com.alibaba.fastjson2.JSON;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -21,7 +22,7 @@ public class GpsService implements IGpsService {
     @Autowired
     private GeneratorGspApi generatorGspApi;
     @Autowired
-    private GpsRequest<LocationEntity> gpsRequest;
+    private GpsRequest gpsRequest;
     @Autowired
     private SysShipService sysShipService;
 
@@ -33,20 +34,20 @@ public class GpsService implements IGpsService {
 
     public LocationEntity getLocation(String shipId){
         SysShip sysShip = sysShipService.get(shipId);
-        Map<String, Object> params = generatorGspApi.GeneratorQueryParams(GpsApi.findLocationByBatch);
-        params.put("macid",sysShip.getGpsDeviceNum());
+        Map<String, Object> params = generatorGspApi.GeneratorQueryParams(GpsApi.findLocation);
+        params.put("macid",sysShip.getShipNum());
         params.put("mapType", GeneratorGspApi.GpsMapType.QQ);
-        LocationEntity locationEntitie = gpsRequest.post(params);
+        LocationEntity locationEntitie = gpsRequest.post(params).toJavaObject(LocationEntity.class);
         return locationEntitie;
     }
 
     public List<LocationEntity> getLocationBatch(){
         List<SysShip> sysShips = sysShipService.findList(new SysShip());
-        String macIds = sysShips.stream().map(SysShip::getGpsDeviceNum).collect(Collectors.joining(","));
+        String macIds = sysShips.stream().map(SysShip::getShipNum).collect(Collectors.joining(","));
         Map<String, Object> params = generatorGspApi.GeneratorQueryParams(GpsApi.findLocationByBatch);
         params.put("macids",macIds);
         params.put("mapType", GeneratorGspApi.GpsMapType.QQ);
-        List<LocationEntity> locationEntities = gpsRequest.postArray(params);
+        List<LocationEntity> locationEntities = gpsRequest.postArray(params).toJavaList(LocationEntity.class);
          return locationEntities;
     }
 }

+ 0 - 2
aidex-ui/package.json

@@ -24,8 +24,6 @@
     "mockjs2": "1.0.8",
     "moment": "^2.24.0",
     "nprogress": "^0.2.0",
-    "qmap": "^0.2.3",
-    "qqmap": "^1.0.1",
     "sortablejs": "^1.10.2",
     "store": "^2.0.12",
     "v-viewer": "^1.5.1",

+ 1 - 1
aidex-ui/src/api/gps/gps.js

@@ -1,7 +1,7 @@
 import request from '@/utils/request'
 
 // 当前定位地点获取
-export function locationUrl (query) {
+export function location (query) {
   return request({
     url: '/monit/gps/location',
     method: 'get',

+ 70 - 46
aidex-ui/src/views/operation/location/index.vue

@@ -12,8 +12,7 @@
         </template>
         <template slot="paneR">
           <div class="table-page-search-wrapper">
-            <h2>{{ selShipData.shipNanme }}-实时位置</h2>
-            位置数据: {{ batchLocation }}
+            <h2>{{ selShipData.shipNanme?selShipData.shipNanme:'全部船只' }}-实时位置</h2>
           </div>
           <a-divider />
 
@@ -26,13 +25,13 @@
 
 <script>
 import { listAllSysShip } from '@/api/system/sysShip'
-import { locationBatch } from '@/api/gps/gps'
+import { locationBatch, location } from '@/api/gps/gps'
 import ShipTree from './modules/ShipTree'
 import Split from '@/components/pt/split/Index'
 import qq from 'qq'
 
 export default {
-  name: 'User',
+  name: 'TencentMapLocation',
   components: {
     Split,
     ShipTree
@@ -45,6 +44,7 @@ export default {
       longitude: 103.760104, // 经度
       latitude: 36.079945, // 纬度
       batchLocation: [],
+      marker: '',
       map: ''
     }
   },
@@ -64,8 +64,8 @@ export default {
       locationBatch().then(res => {
         this.batchLocation = res.data
         if (this.batchLocation.length > 0) {
-          this.longitude = '116.380945'// this.batchLocation[0].lon
-          this.latitude = '39.953416'// this.batchLocation[0].lat
+          this.longitude = this.batchLocation[0].lon
+          this.latitude = this.batchLocation[0].lat
         }
         this.init()
       })
@@ -77,50 +77,64 @@ export default {
       var myLatlng = new qq.maps.LatLng(this.latitude, this.longitude)
       // 定义工厂模式函数
       var myOptions = {
-        zoom: 12, // 设置地图缩放级别
-        center: myLatlng, // 设置中心点样式
-        mapTypeId: qq.maps.MapTypeId.ROADMAP // 设置地图样式详情参见MapType
+        rotation: 20, // 设置地图旋转角度
+        pitch: 30, // 设置俯仰角度(0~45)
+        zoom: 13, // 设置地图缩放级别
+        center: myLatlng // 设置中心点样式
       }
       // 获取dom元素添加地图信息
-      this.map = new qq.maps.Map(document.getElementById('mapLocation'), myOptions)
+      this.map = new qq.maps.Map('mapLocation', myOptions)
 
-      var marker = new qq.maps.Marker({
-          position: new qq.maps.LatLng(39.953416, 116.480945),
-          map: this.map
-      })
-      console.log(marker)
+      console.log(qq.maps)
+
+      var anchor = new qq.maps.Point(6, 6)
+      var size = new qq.maps.Size(24, 24)
+      var origin = new qq.maps.Point(0, 0)
+      var icon = new qq.maps.MarkerImage('https://mapapi.qq.com/web/lbs/javascriptV2/demo/img/center.gif', size, origin, anchor)
+
+      if (this.batchLocation.length > 0) {
+        var marks = []
+        var infos = []
+        this.batchLocation.forEach(element => {
+          marks.push(new qq.maps.Marker({
+            id: element.objectid,
+            icon: icon,
+            map: this.map,
+            position: new qq.maps.LatLng(element.lat, element.lon)
+          }))
+          infos.push(new qq.maps.InfoWindow({
+              id: element.objectid,
+              map: this.map,
+              content: `<div class="location_info"><h3>${element.platenumber}</h3><p>航向:${element.dir}</p><p>速度:${element.speed}</p><p>纬度:${element.lat}</p><p>经度:${element.lon}</p></div>`,
+              position: new qq.maps.LatLng(element.lat, element.lon)
+          }))
+        })
+
+        this.marker = new qq.maps.MarkerCluster({
+          map: this.map,
+          markers: marks
+        })
 
-      // var marker = new qq.maps.MarkerCluster({
-      //   map: this.map,
-      //   styles: {
-      //       'marker': qq.maps.MarkerStyle({
-      //           'width': 25,
-      //           'height': 35,
-      //           'anchor': { x: 16, y: 32 },
-      //           'src': 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/markerDefault.png'
-      //       })
-      //   },
-      //   geometries: [
-      //     // 点标记数据数组
-      //     {
-      //       position: new qq.maps.LatLng(39.953416, 116.480945),
-      //       properties: {
-      //           title: 'dsadsad',
-      //           assetClassification: 'dddd',
-      //           userDepartment: '2222'
-      //       }
-      //     },
-      //     {
-      //       position: new qq.maps.LatLng(39.984104, 116.407503),
-      //       properties: {
-      //         title: '2222',
-      //           assetClassification: '3232',
-      //           userDepartment: 'ssas'
-      //       }
-      //     }
-      //   ]
-      // })
-      // console.log(marker)
+        marks.forEach(mark => {
+          qq.maps.event.addListener(mark, 'click', function() {
+            var info = infos.findIndex(item => { return item.id === mark.id })
+            infos[info].open()
+          })
+        })
+
+        infos.forEach(info => {
+          info.open()
+        })
+      }
+    },
+    getLocal() {
+      location({ shipId: this.selShipData.id }).then(res => {
+        this.batchLocation = []
+        this.batchLocation.push(res.data)
+        this.longitude = this.batchLocation[0].lon
+        this.latitude = this.batchLocation[0].lat
+        this.init()
+      })
     },
     /** 查询部门下拉树结构 */
     getTreeselect() {
@@ -132,6 +146,7 @@ export default {
       var selectItem = node.$options.propsData.dataRef
       if (this.selShipData.id !== selectItem.id) {
         this.selShipData = node.$options.propsData.dataRef
+        this.getLocal()
       }
     }
   }
@@ -155,3 +170,12 @@ export default {
   margin-right: 8px;
 }
 </style>
+<style>
+.location_info{
+  width: 130px;
+}
+.location_info p{
+  margin: 0;
+  padding: 0;
+}
+</style>

+ 2 - 7
aidex-ui/vue.config.js

@@ -27,9 +27,7 @@ const assetsCDN = {
     vue: 'Vue',
     'vue-router': 'VueRouter',
     vuex: 'Vuex',
-    axios: 'axios',
-    qq: 'qq',
-		TMap: 'TMap'
+    axios: 'axios'
   },
   css: [],
   // https://unpkg.com/browse/vue@2.6.10/
@@ -63,10 +61,7 @@ const vueConfig = {
     ],
     // if prod, add externals
     externals: isProd ? assetsCDN.externals
-    : {
-      qq: 'qq',
-      TMap: 'TMap'
-    }
+    : {}
   },
 
   chainWebpack: (config) => {