1.根据定位获取运营区详细信息
This commit is contained in:
parent
35e3e1fa2a
commit
66d22c623d
electripper-admin/src/main/java/com/ruoyi/web/controller
electripper-common/src/main/java/com/ruoyi/common
electripper-framework/src/main/java/com/ruoyi/framework/web/service
electripper-system/src/main/java/com/ruoyi/system/service
|
@ -88,7 +88,23 @@ public class AppController extends BaseController
|
||||||
@GetMapping(value = "/area/{areaId}")
|
@GetMapping(value = "/area/{areaId}")
|
||||||
public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
|
public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
|
||||||
{
|
{
|
||||||
return success(etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId));
|
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId);
|
||||||
|
return success(area);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据定位获取运营区详细信息
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/area/info")
|
||||||
|
public AjaxResult areaInfo(String longitude,String latitude)
|
||||||
|
{
|
||||||
|
if(StrUtil.isBlank(longitude) || StrUtil.isBlank(latitude)){
|
||||||
|
logger.info("没有经纬度参数:【longitude={}】,【latitude={}】",longitude,latitude);
|
||||||
|
return error("请传经纬度参数"+"【longitude="+longitude+"】,【latitude="+latitude+"】");
|
||||||
|
}
|
||||||
|
EtOperatingArea area = etOperatingAreaService.getAreaInfoByLocation(longitude,latitude);
|
||||||
|
return success(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,7 +138,7 @@ public class AppController extends BaseController
|
||||||
logger.info("没有经纬度参数:【longitude={}】,【latitude={}】",longitude,latitude);
|
logger.info("没有经纬度参数:【longitude={}】,【latitude={}】",longitude,latitude);
|
||||||
return error("请传经纬度参数"+"【longitude="+longitude+"】,【latitude="+latitude+"】");
|
return error("请传经纬度参数"+"【longitude="+longitude+"】,【latitude="+latitude+"】");
|
||||||
}
|
}
|
||||||
webSocket.SendMessage("需要发送的消息", "识别唯一session");
|
// webSocket.SendMessage("需要发送的消息", "识别唯一session");
|
||||||
List<AsDevice> asDevices = asDeviceService.vehicleLocalization(longitude,latitude);
|
List<AsDevice> asDevices = asDeviceService.vehicleLocalization(longitude,latitude);
|
||||||
return success(asDevices);
|
return success(asDevices);
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,10 +128,10 @@ public class SysLoginController
|
||||||
* 微信登录
|
* 微信登录
|
||||||
*/
|
*/
|
||||||
@PostMapping("/wxlogin")
|
@PostMapping("/wxlogin")
|
||||||
public AjaxResult wxlogin(String mobileCode,String jsCode) {
|
public AjaxResult wxlogin(String mobileCode,String jsCode,String areaId) {
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
// 生成令牌
|
// 生成令牌
|
||||||
String token = loginService.wxloing(mobileCode,jsCode);
|
String token = loginService.wxloing(mobileCode,jsCode,areaId);
|
||||||
ajax.put(Constants.TOKEN, token);
|
ajax.put(Constants.TOKEN, token);
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
@ -140,10 +140,10 @@ public class SysLoginController
|
||||||
* 根据openid静默登录
|
* 根据openid静默登录
|
||||||
*/
|
*/
|
||||||
@PostMapping("/loginByopenid")
|
@PostMapping("/loginByopenid")
|
||||||
public AjaxResult loginByopenid(String jsCode) {
|
public AjaxResult loginByopenid(String jsCode,String areaId) {
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
// 生成令牌
|
// 生成令牌
|
||||||
String token = loginService.loginByopenid(jsCode);
|
String token = loginService.loginByopenid(jsCode,areaId);
|
||||||
ajax.put(Constants.TOKEN, token);
|
ajax.put(Constants.TOKEN, token);
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,17 @@ public class AsUser extends BaseEntity
|
||||||
/** 系统用户id */
|
/** 系统用户id */
|
||||||
private Long sysUserId;
|
private Long sysUserId;
|
||||||
|
|
||||||
|
/** 运营区id */
|
||||||
|
private Long areaId;
|
||||||
|
|
||||||
|
public Long getAreaId() {
|
||||||
|
return areaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaId(Long areaId) {
|
||||||
|
this.areaId = areaId;
|
||||||
|
}
|
||||||
|
|
||||||
/** 最后一笔订单 */
|
/** 最后一笔订单 */
|
||||||
private EtOrderDto latestOrder;
|
private EtOrderDto latestOrder;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.opengis.referencing.operation.MathTransform;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,4 +242,26 @@ public class GeoUtils {
|
||||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||||
return EARTH_RADIUS * c;
|
return EARTH_RADIUS * c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判获取到最近一个运营区
|
||||||
|
* */
|
||||||
|
public static boolean getNearestOperatingArea (String longitude, String latitude, List<Geometry> polygon) {
|
||||||
|
double lon = Double.parseDouble(longitude);
|
||||||
|
double lat = Double.parseDouble(latitude);
|
||||||
|
|
||||||
|
GeometryFactory geometryFactory = new GeometryFactory();
|
||||||
|
Coordinate coordinate = new Coordinate(lon, lat);
|
||||||
|
Point point = geometryFactory.createPoint(coordinate);
|
||||||
|
|
||||||
|
for (Geometry geometry : polygon) {
|
||||||
|
if (geometry.contains(point)) {
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ public class SysLoginService
|
||||||
/**
|
/**
|
||||||
* 微信登录
|
* 微信登录
|
||||||
*/
|
*/
|
||||||
public String wxloing(String mobileCode,String jsCode) {
|
public String wxloing(String mobileCode,String jsCode,String areaId) {
|
||||||
//根据jsCode换取openid
|
//根据jsCode换取openid
|
||||||
String openId = getOpenId(jsCode);
|
String openId = getOpenId(jsCode);
|
||||||
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=";
|
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=";
|
||||||
|
@ -229,8 +229,12 @@ public class SysLoginService
|
||||||
asUser.setLoginDate(DateUtils.getNowDate());
|
asUser.setLoginDate(DateUtils.getNowDate());
|
||||||
asUser.setCreateTime(DateUtils.getNowDate());
|
asUser.setCreateTime(DateUtils.getNowDate());
|
||||||
asUser.setWxopenid(openId);
|
asUser.setWxopenid(openId);
|
||||||
|
asUser.setAreaId(Long.parseLong(areaId));
|
||||||
int i = asUserService.insertUser(asUser);
|
int i = asUserService.insertUser(asUser);
|
||||||
user = asUser;
|
user = asUser;
|
||||||
|
}else{
|
||||||
|
user.setAreaId(Long.parseLong(areaId));
|
||||||
|
int i = asUserService.updateUser(user);
|
||||||
}
|
}
|
||||||
Authentication authentication = null; // 用户验证
|
Authentication authentication = null; // 用户验证
|
||||||
try {
|
try {
|
||||||
|
@ -273,12 +277,15 @@ public class SysLoginService
|
||||||
/**
|
/**
|
||||||
* 根据openid静默登录
|
* 根据openid静默登录
|
||||||
*/
|
*/
|
||||||
public String loginByopenid(String jsCode) {
|
public String loginByopenid(String jsCode,String areaId) {
|
||||||
//根据jsCode换取openid
|
//根据jsCode换取openid
|
||||||
String openid = getOpenId(jsCode);
|
String openid = getOpenId(jsCode);
|
||||||
AsUser user = asUserService.selectUserByWxopenid(openid);
|
AsUser user = asUserService.selectUserByWxopenid(openid);
|
||||||
if(ObjectUtils.isEmpty(user)){
|
if(ObjectUtils.isEmpty(user)){
|
||||||
throw new ServiceException("未查询到用户信息");
|
throw new ServiceException("未查询到用户信息");
|
||||||
|
}else{
|
||||||
|
user.setAreaId(Long.parseLong(areaId));
|
||||||
|
int i = asUserService.updateUser(user);
|
||||||
}
|
}
|
||||||
Authentication authentication = null; // 用户验证
|
Authentication authentication = null; // 用户验证
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -78,4 +78,13 @@ public interface IEtOperatingAreaService extends IService<EtOperatingArea>
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public boolean checkAreaNameUnique(EtOperatingArea etOperatingArea);
|
public boolean checkAreaNameUnique(EtOperatingArea etOperatingArea);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据定位获取运营区详细信息
|
||||||
|
*
|
||||||
|
* @param longitude 经度
|
||||||
|
* @param latitude 纬度
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
EtOperatingArea getAreaInfoByLocation(String longitude, String latitude);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
@ -12,6 +13,7 @@ import com.ruoyi.common.core.domain.entity.SysDictType;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.map.GeoUtils;
|
import com.ruoyi.common.utils.map.GeoUtils;
|
||||||
|
import com.ruoyi.system.domain.AsDevice;
|
||||||
import com.ruoyi.system.domain.EtAreaRule;
|
import com.ruoyi.system.domain.EtAreaRule;
|
||||||
import com.ruoyi.system.domain.SysStudent;
|
import com.ruoyi.system.domain.SysStudent;
|
||||||
import com.ruoyi.system.mapper.EtAreaRuleMapper;
|
import com.ruoyi.system.mapper.EtAreaRuleMapper;
|
||||||
|
@ -20,7 +22,10 @@ import com.ruoyi.system.service.IAsDeviceService;
|
||||||
import com.ruoyi.system.service.IEtFeeRuleService;
|
import com.ruoyi.system.service.IEtFeeRuleService;
|
||||||
import jdk.nashorn.internal.ir.annotations.Reference;
|
import jdk.nashorn.internal.ir.annotations.Reference;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.locationtech.jts.geom.Coordinate;
|
||||||
import org.locationtech.jts.geom.Geometry;
|
import org.locationtech.jts.geom.Geometry;
|
||||||
|
import org.locationtech.jts.geom.GeometryFactory;
|
||||||
|
import org.locationtech.jts.geom.Point;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.system.mapper.EtOperatingAreaMapper;
|
import com.ruoyi.system.mapper.EtOperatingAreaMapper;
|
||||||
|
@ -52,6 +57,9 @@ public class EtOperatingAreaServiceImpl extends ServiceImpl<EtOperatingAreaMappe
|
||||||
@Resource
|
@Resource
|
||||||
private EtAreaRuleMapper etAreaRuleMapper;
|
private EtAreaRuleMapper etAreaRuleMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IEtOperatingAreaService etOperatingAreaService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询运营区
|
* 查询运营区
|
||||||
|
@ -189,4 +197,60 @@ public class EtOperatingAreaServiceImpl extends ServiceImpl<EtOperatingAreaMappe
|
||||||
}
|
}
|
||||||
return UserConstants.UNIQUE;
|
return UserConstants.UNIQUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据定位获取运营区信息
|
||||||
|
*
|
||||||
|
* @param longitude 经度
|
||||||
|
* @param latitude 纬度
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EtOperatingArea getAreaInfoByLocation(String longitude, String latitude) {
|
||||||
|
double lon = Double.parseDouble(longitude);
|
||||||
|
double lat = Double.parseDouble(latitude);
|
||||||
|
List<EtOperatingArea> etOperatingAreas = etOperatingAreaService.selectEtOperatingAreaList(new EtOperatingArea());
|
||||||
|
EtOperatingArea area = null;
|
||||||
|
for(EtOperatingArea etOperatingArea:etOperatingAreas){
|
||||||
|
Geometry geometry = GeoUtils.fromWkt(etOperatingArea.getBoundary());
|
||||||
|
Boolean inCircle = GeoUtils.isInCircle(longitude, latitude, geometry);
|
||||||
|
if(inCircle){
|
||||||
|
area = etOperatingArea;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(ObjectUtil.isNotNull(area)){
|
||||||
|
/** 在运营区内直接返回*/
|
||||||
|
log.info("在【{}】运营区内",area.getAreaName());
|
||||||
|
return area;
|
||||||
|
}else{
|
||||||
|
/** 不在任何运营区内,获取到最近一个运营区*/
|
||||||
|
log.info("不在任何运营区内,获取到最近一个运营区");
|
||||||
|
EtOperatingArea closestArea = null;
|
||||||
|
double minDistance = Double.MAX_VALUE;
|
||||||
|
GeometryFactory geometryFactory = new GeometryFactory();
|
||||||
|
Coordinate coordinate = new Coordinate(lon, lat);
|
||||||
|
Point point = geometryFactory.createPoint(coordinate);
|
||||||
|
for(EtOperatingArea etOperatingArea:etOperatingAreas){
|
||||||
|
Geometry geometry = GeoUtils.fromWkt(etOperatingArea.getBoundary());
|
||||||
|
if (geometry.contains(point)) {
|
||||||
|
return etOperatingArea;
|
||||||
|
}else{
|
||||||
|
// 获取多边形的外边界
|
||||||
|
Coordinate[] coordinates = geometry.getCoordinates();
|
||||||
|
for (Coordinate coord : coordinates) {
|
||||||
|
double distance = GeoUtils.calculateDistance(lat, lon, coord.y, coord.x);
|
||||||
|
if (distance < minDistance) {
|
||||||
|
minDistance = distance;
|
||||||
|
closestArea = etOperatingArea;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return closestArea;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user