parent
52b0ccfa26
commit
e9528c8e4b
6
pom.xml
6
pom.xml
|
@ -69,6 +69,12 @@
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.42</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.muyu.common;
|
package com.muyu.common;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author DongZeLiang
|
* @author DongZeLiang
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
|
@ -8,4 +11,10 @@ package com.muyu.common;
|
||||||
*/
|
*/
|
||||||
public class SystemConstant {
|
public class SystemConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 百公里电耗
|
||||||
|
*/
|
||||||
|
public final static BigDecimal powerConsumption = new BigDecimal(10000);
|
||||||
|
|
||||||
|
public final static BigDecimal hundredKilometers = new BigDecimal(100);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,133 +0,0 @@
|
||||||
package com.muyu.controller;
|
|
||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.muyu.common.Result;
|
|
||||||
import com.muyu.domain.User;
|
|
||||||
import com.muyu.service.UserService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* com.muyu.controller 测试
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/user")
|
|
||||||
public class UserController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造方法注入
|
|
||||||
*/
|
|
||||||
@Autowired
|
|
||||||
UserService userService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存数据
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GetMapping("/save")
|
|
||||||
public Result save() {
|
|
||||||
User user = new User();
|
|
||||||
user.setId(10);
|
|
||||||
user.setUsername("miaolinlin");
|
|
||||||
user.setPwd("121212");
|
|
||||||
userService.save(user);
|
|
||||||
return Result.success(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改数据
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GetMapping("/update")
|
|
||||||
public Result update(Integer id) {
|
|
||||||
User user = new User();
|
|
||||||
user.setId(id);
|
|
||||||
user.setPwd("1111111111");
|
|
||||||
userService.updateById(user);
|
|
||||||
return Result.success("{}");
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/list")
|
|
||||||
public Result list() {
|
|
||||||
// 返回所有
|
|
||||||
List<User> list = userService.list();
|
|
||||||
return Result.success(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/listByContion")
|
|
||||||
public Result listByContion() {
|
|
||||||
/**
|
|
||||||
* 条件查询, 通过QueryWrapper来实现查询的条件:
|
|
||||||
* eq: 代表相等
|
|
||||||
* like: 模糊匹配
|
|
||||||
* orderBy: 排序
|
|
||||||
* in, notin
|
|
||||||
* 大于,小于,between等
|
|
||||||
*/
|
|
||||||
List<User> list = userService.list(new LambdaQueryWrapper<User>()
|
|
||||||
// 查询年龄=11的
|
|
||||||
.eq(User::getUsername, "miao")
|
|
||||||
// 模糊匹配
|
|
||||||
.like(User::getPwd, "%111%")
|
|
||||||
// 排序,按照创建时间
|
|
||||||
.orderByDesc(User::getCreateTime)
|
|
||||||
);
|
|
||||||
return Result.success(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据id获取数据
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GetMapping("/getById")
|
|
||||||
public Result getById(Integer id) {
|
|
||||||
User user = userService.getById(id);
|
|
||||||
return Result.success(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除数据
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GetMapping("/delete")
|
|
||||||
public Result delete(Integer id) {
|
|
||||||
userService.removeById(id);
|
|
||||||
return Result.success("success");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询
|
|
||||||
*
|
|
||||||
* @param pageNum
|
|
||||||
* @param pageSize
|
|
||||||
* @param name
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GetMapping("/page")
|
|
||||||
public Result page(int pageNum, int pageSize, String name) {
|
|
||||||
IPage<User> page = new Page<>(pageNum, pageSize);
|
|
||||||
|
|
||||||
IPage<User> page1 = userService.page(page, new LambdaQueryWrapper<User>()
|
|
||||||
// 主要演示这里可以加条件。在name不为空的时候执行
|
|
||||||
.like(StringUtils.isNotEmpty(name), User::getUsername, "%" + name + "%"));
|
|
||||||
|
|
||||||
return Result.success(page1);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.muyu.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 路径信息
|
||||||
|
* @Date 2023-11-20 上午 09:28
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@TableName("route_info")
|
||||||
|
public class RouteInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId("id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
@TableField(value = "name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据
|
||||||
|
*/
|
||||||
|
@TableField(value = "data")
|
||||||
|
private String routeData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "create_time")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
|
@ -1,98 +0,0 @@
|
||||||
package com.muyu.domain;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 用户表
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Leo825
|
|
||||||
* @since 2022-07-05
|
|
||||||
*/
|
|
||||||
@TableName("t_user")
|
|
||||||
public class User implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户主键
|
|
||||||
*/
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户名称
|
|
||||||
*/
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 密码
|
|
||||||
*/
|
|
||||||
private String pwd;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间,MyMetaObjectHandler 配合使用,入库的时候自动填充
|
|
||||||
*/
|
|
||||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
|
||||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改时间,MyMetaObjectHandler 配合使用,入库的时候自动填充
|
|
||||||
*/
|
|
||||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
|
||||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
private Date updateTime;
|
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
public String getPwd() {
|
|
||||||
return pwd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPwd(String pwd) {
|
|
||||||
this.pwd = pwd;
|
|
||||||
}
|
|
||||||
public Date getCreateTime() {
|
|
||||||
return createTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreateTime(Date createTime) {
|
|
||||||
this.createTime = createTime;
|
|
||||||
}
|
|
||||||
public Date getUpdateTime() {
|
|
||||||
return updateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdateTime(Date updateTime) {
|
|
||||||
this.updateTime = updateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "User{" +
|
|
||||||
"id=" + id +
|
|
||||||
", username=" + username +
|
|
||||||
", pwd=" + pwd +
|
|
||||||
", createTime=" + createTime +
|
|
||||||
", updateTime=" + updateTime +
|
|
||||||
"}";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.muyu.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 位置模型
|
||||||
|
* @Date 2023-11-20 上午 09:36
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PositionModel {
|
||||||
|
/**
|
||||||
|
* 经度
|
||||||
|
*/
|
||||||
|
private String longitude;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 维度
|
||||||
|
*/
|
||||||
|
private String latitude;
|
||||||
|
|
||||||
|
public static PositionModel strBuild (String positionStr) {
|
||||||
|
String[] split = positionStr.split(",");
|
||||||
|
return PositionModel.builder()
|
||||||
|
.longitude(split[0])
|
||||||
|
.latitude(split[1])
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.muyu.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.muyu.domain.RouteInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 轨迹路径 mapper
|
||||||
|
* @Date 2023-11-20 上午 09:32
|
||||||
|
*/
|
||||||
|
public interface RouteMapper extends BaseMapper<RouteInfo> {
|
||||||
|
}
|
|
@ -1,16 +0,0 @@
|
||||||
package com.muyu.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.muyu.domain.User;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 用户表 Mapper 接口
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Leo825
|
|
||||||
* @since 2022-07-05
|
|
||||||
*/
|
|
||||||
public interface UserMapper extends BaseMapper<User> {
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,10 +5,10 @@ import com.muyu.domain.Vehicle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 用户表 Mapper 接口
|
* 车辆 Mapper 接口
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Leo825
|
* @author DongZeLiang
|
||||||
* @since 2022-07-05
|
* @since 2022-07-05
|
||||||
*/
|
*/
|
||||||
public interface VehicleMapper extends BaseMapper<Vehicle> {
|
public interface VehicleMapper extends BaseMapper<Vehicle> {
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.muyu.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.domain.RouteInfo;
|
||||||
|
import com.muyu.domain.model.PositionModel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 路径轨迹业务层
|
||||||
|
* @Date 2023-11-20 上午 09:33
|
||||||
|
*/
|
||||||
|
public interface RouteService extends IService<RouteInfo> {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据轨迹ID获取轨迹详情
|
||||||
|
* @param routeId 轨迹ID
|
||||||
|
* @return 轨迹ID
|
||||||
|
*/
|
||||||
|
public List<PositionModel> getPositionModelByRouteId(Long routeId);
|
||||||
|
}
|
|
@ -1,16 +0,0 @@
|
||||||
package com.muyu.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.muyu.domain.User;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 用户表 服务类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Leo825
|
|
||||||
* @since 2022-07-05
|
|
||||||
*/
|
|
||||||
public interface UserService extends IService<User> {
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,10 +5,10 @@ import com.muyu.domain.Vehicle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 用户表 服务类
|
* 车辆 服务类
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Leo825
|
* @author DongZeLiang
|
||||||
* @since 2022-07-05
|
* @since 2022-07-05
|
||||||
*/
|
*/
|
||||||
public interface VehicleService extends IService<Vehicle> {
|
public interface VehicleService extends IService<Vehicle> {
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.muyu.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.domain.RouteInfo;
|
||||||
|
import com.muyu.domain.model.PositionModel;
|
||||||
|
import com.muyu.mapper.RouteMapper;
|
||||||
|
import com.muyu.service.RouteService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 路径轨迹业务实现层
|
||||||
|
* @Date 2023-11-20 上午 09:34
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class RouteServiceImpl extends ServiceImpl<RouteMapper, RouteInfo> implements RouteService {
|
||||||
|
/**
|
||||||
|
* 根据轨迹ID获取轨迹详情
|
||||||
|
*
|
||||||
|
* @param routeId 轨迹ID
|
||||||
|
*
|
||||||
|
* @return 轨迹ID
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<PositionModel> getPositionModelByRouteId (Long routeId) {
|
||||||
|
RouteInfo routeInfo = this.getById(routeId);
|
||||||
|
return JSONArray.parseArray(routeInfo.getRouteData(), String.class)
|
||||||
|
.stream()
|
||||||
|
.map(PositionModel::strBuild)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
package com.muyu.service.impl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.muyu.domain.User;
|
|
||||||
import com.muyu.mapper.UserMapper;
|
|
||||||
import com.muyu.service.UserService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 用户表 服务实现类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Leo825
|
|
||||||
* @since 2022-07-05
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
||||||
|
|
||||||
}
|
|
|
@ -13,10 +13,10 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 用户表 服务实现类
|
* 车辆 服务实现类
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Leo825
|
* @author DongZeLiang
|
||||||
* @since 2022-07-05
|
* @since 2022-07-05
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.muyu.utils;
|
package com.muyu.utils;
|
||||||
|
|
||||||
import com.muyu.common.SystemConstant;
|
import com.muyu.common.SystemConstant;
|
||||||
|
import com.muyu.domain.model.PositionModel;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class VehicleUtils {
|
public class VehicleUtils {
|
||||||
|
@ -29,7 +31,52 @@ public class VehicleUtils {
|
||||||
* @return 电池额度
|
* @return 电池额度
|
||||||
*/
|
*/
|
||||||
public static BigDecimal genBattery(){
|
public static BigDecimal genBattery(){
|
||||||
return BigDecimal.valueOf(random.nextInt(54, 60) * 1000L);
|
return BigDecimal.valueOf(random.nextInt(60, 80) * 1000L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两点之间的距离
|
||||||
|
* @param startPositionModel 开始定位点
|
||||||
|
* @param endPositionModel 结束定位点
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BigDecimal distance(PositionModel startPositionModel, PositionModel endPositionModel){
|
||||||
|
double lon1 = Double.parseDouble(startPositionModel.getLongitude());
|
||||||
|
double lat1 = Double.parseDouble(startPositionModel.getLatitude());
|
||||||
|
double lon2 = Double.parseDouble(endPositionModel.getLongitude());
|
||||||
|
double lat2 = Double.parseDouble(endPositionModel.getLatitude());
|
||||||
|
double lon1Rad = Math.toRadians(lon1);
|
||||||
|
double lat1Rad = Math.toRadians(lat1);
|
||||||
|
double lon2Rad = Math.toRadians(lon2);
|
||||||
|
double lat2Rad = Math.toRadians(lat2);
|
||||||
|
double earthRadius = 6371; // 地球半径(以公里为单位)
|
||||||
|
|
||||||
|
double latDiff = lat2Rad - lat1Rad;
|
||||||
|
double lonDiff = lon2Rad - lon1Rad;
|
||||||
|
|
||||||
|
double a = Math.sin(latDiff / 2) * Math.sin(latDiff / 2) +
|
||||||
|
Math.cos(lat1Rad) * Math.cos(lat2Rad) *
|
||||||
|
Math.sin(lonDiff / 2) * Math.sin(lonDiff / 2);
|
||||||
|
|
||||||
|
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||||
|
|
||||||
|
double distance = earthRadius * c;
|
||||||
|
return BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成电池浮动
|
||||||
|
* @return 电池浮动值
|
||||||
|
*/
|
||||||
|
public static BigDecimal batteryFloat(){
|
||||||
|
Random rand = new Random();
|
||||||
|
// 生成0.00-0.31之间的随机数
|
||||||
|
double num = rand.nextDouble() * 0.31;
|
||||||
|
// 加上0.90,得到0.90-1.21之间的随机数
|
||||||
|
num += 0.90;
|
||||||
|
// 保留两位小数
|
||||||
|
num = (double) Math.round(num * 100) / 100;
|
||||||
|
return BigDecimal.valueOf(num);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package com.muyu.vehicle;
|
package com.muyu.vehicle;
|
||||||
|
|
||||||
|
import com.muyu.common.SystemConstant;
|
||||||
import com.muyu.common.ThreadPool;
|
import com.muyu.common.ThreadPool;
|
||||||
import com.muyu.domain.Vehicle;
|
import com.muyu.domain.Vehicle;
|
||||||
|
import com.muyu.domain.model.PositionModel;
|
||||||
|
import com.muyu.utils.VehicleUtils;
|
||||||
import com.muyu.vehicle.model.VehicleData;
|
import com.muyu.vehicle.model.VehicleData;
|
||||||
import com.muyu.vehicle.model.properties.MqttProperties;
|
import com.muyu.vehicle.model.properties.MqttProperties;
|
||||||
import com.muyu.vehicle.thread.VehicleThread;
|
import com.muyu.vehicle.thread.VehicleThread;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||||
|
@ -16,11 +18,12 @@ import org.eclipse.paho.client.mqttv3.MqttException;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
import static java.lang.Thread.sleep;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author DongZeLiang
|
* @author DongZeLiang
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
|
@ -44,6 +47,16 @@ public class VehicleInstance {
|
||||||
*/
|
*/
|
||||||
private VehicleData vehicleData;
|
private VehicleData vehicleData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上一个定位点
|
||||||
|
*/
|
||||||
|
private PositionModel lastPosition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路径队列
|
||||||
|
*/
|
||||||
|
private final LinkedBlockingQueue<PositionModel> positionQueue = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆工作线程
|
* 车辆工作线程
|
||||||
|
@ -155,4 +168,59 @@ public class VehicleInstance {
|
||||||
this.scheduledFuture = null;
|
this.scheduledFuture = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模拟车辆数据
|
||||||
|
*/
|
||||||
|
public void imitateData () {
|
||||||
|
// 获取上一次定位点
|
||||||
|
PositionModel lastPositionModel = this.lastPosition;
|
||||||
|
// 获取当前定位点
|
||||||
|
PositionModel currentPositionModel = positionQueue.poll();
|
||||||
|
if (currentPositionModel == null) {
|
||||||
|
// TODO 表示当前定位点已经跑完,需要其他操作
|
||||||
|
}
|
||||||
|
// 两点之间的距离
|
||||||
|
BigDecimal distance = VehicleUtils.distance(lastPositionModel, currentPositionModel);
|
||||||
|
// 车辆总里程 相加
|
||||||
|
vehicleData.setMileage(vehicleData.getMileage().add(distance));
|
||||||
|
// 定位点填写
|
||||||
|
vehicleData.setLongitude(currentPositionModel.getLongitude());
|
||||||
|
vehicleData.setLatitude(currentPositionModel.getLatitude());
|
||||||
|
// 当前电量减少
|
||||||
|
// 电池浮动
|
||||||
|
BigDecimal batteryFloat = VehicleUtils.batteryFloat();
|
||||||
|
// 百公里占比
|
||||||
|
BigDecimal hundredKMScale = distance.divide(SystemConstant.hundredKilometers).setScale(3, RoundingMode.HALF_UP);
|
||||||
|
// 使用电量
|
||||||
|
BigDecimal powerUsage = SystemConstant.powerConsumption.multiply(hundredKMScale)
|
||||||
|
.multiply(batteryFloat)
|
||||||
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
vehicleData.setRemainingBattery(vehicleData.getRemainingBattery().subtract(powerUsage));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public static void main (String[] args) {
|
||||||
|
PositionModel lastPositionModel = PositionModel.builder()
|
||||||
|
.longitude("116.664053")
|
||||||
|
.latitude("39.531791")
|
||||||
|
.build();
|
||||||
|
PositionModel currentPositionModel = PositionModel.builder()
|
||||||
|
.longitude("116.655091")
|
||||||
|
.latitude("39.52091")
|
||||||
|
.build();
|
||||||
|
// 两点之间的距离
|
||||||
|
BigDecimal distance = VehicleUtils.distance(lastPositionModel, currentPositionModel);
|
||||||
|
|
||||||
|
// 当前电量减少
|
||||||
|
// 电池浮动
|
||||||
|
BigDecimal batteryFloat = VehicleUtils.batteryFloat();
|
||||||
|
BigDecimal divide = distance.divide(SystemConstant.hundredKilometers).setScale(4, RoundingMode.HALF_UP);
|
||||||
|
BigDecimal multiply = SystemConstant.powerConsumption.multiply(divide)
|
||||||
|
.multiply(batteryFloat)
|
||||||
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
System.out.println("移动距离:" + distance);
|
||||||
|
System.out.println("浮动量:" + batteryFloat);
|
||||||
|
System.out.println("百公里占比:" + divide);
|
||||||
|
System.out.println("当前减少电池量:" + multiply);
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,11 +1,3 @@
|
||||||
create table if not exists t_user (
|
|
||||||
`id` int primary key not null ,
|
|
||||||
`username` char (50) not null,
|
|
||||||
`pwd` char(50) not null,
|
|
||||||
`create_time` datetime not null,
|
|
||||||
`update_time` datetime
|
|
||||||
) ;
|
|
||||||
|
|
||||||
create table if not exists vehicle (
|
create table if not exists vehicle (
|
||||||
`vin` char (50) primary key not null,
|
`vin` char (50) primary key not null,
|
||||||
`remaining_battery` DOUBLE not null,
|
`remaining_battery` DOUBLE not null,
|
||||||
|
@ -13,3 +5,10 @@ create table if not exists vehicle (
|
||||||
`battery_level` DOUBLE not null,
|
`battery_level` DOUBLE not null,
|
||||||
`create_time` datetime not null
|
`create_time` datetime not null
|
||||||
) ;
|
) ;
|
||||||
|
|
||||||
|
create table if not exists route_info (
|
||||||
|
`id` int primary key not null ,
|
||||||
|
`name` char (50) not null,
|
||||||
|
`data` CLOB not null,
|
||||||
|
`create_time` datetime not null
|
||||||
|
) ;
|
||||||
|
|
Loading…
Reference in New Issue