数据库表名更改
parent
f59bfde2a0
commit
b8d3a56e89
|
@ -27,10 +27,12 @@
|
|||
<dependency>
|
||||
<groupId>com.fate</groupId>
|
||||
<artifactId>fate-common-core</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fate</groupId>
|
||||
<artifactId>fate-common-redis</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -53,24 +55,28 @@
|
|||
<dependency>
|
||||
<groupId>com.fate</groupId>
|
||||
<artifactId>fate-common-datasource</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- fate Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.fate</groupId>
|
||||
<artifactId>fate-common-datascope</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- fate Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.fate</groupId>
|
||||
<artifactId>fate-common-log</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- fate Common Swagger -->
|
||||
<dependency>
|
||||
<groupId>com.fate</groupId>
|
||||
<artifactId>fate-common-swagger</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.shiyi.internet.constants;
|
||||
|
||||
/**
|
||||
* @author Yanghaoyu
|
||||
* @Date 2023/11/2 15:27
|
||||
*/
|
||||
public class FaultConstant {
|
||||
/**
|
||||
* 故障信息存储
|
||||
*/
|
||||
public static final String FAULT_INFO_PREFIX = "fault:";
|
||||
|
||||
/**
|
||||
* 故障信息集合
|
||||
*/
|
||||
public static final String FAULT_LIST = "fault_list";
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.shiyi.internet.constants;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Description : Rabbit常量
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-11-30 20:42
|
||||
*/
|
||||
@Component
|
||||
public class RabbitContants {
|
||||
|
||||
/**
|
||||
* 故障处理队列
|
||||
*/
|
||||
public static final String FAULT_HANDLER_QUEUE = "fault_handler_queue";
|
||||
|
||||
/**
|
||||
* 围栏处理队列
|
||||
*/
|
||||
public static final String FENCE_HANDLER_QUEUE = "fence_handler_queue";
|
||||
}
|
|
@ -45,19 +45,19 @@ public class Car extends BaseEntity {
|
|||
@TableField("car_status")
|
||||
private String carStatus;
|
||||
|
||||
@ApiModelProperty("车辆类型")
|
||||
@ApiModelProperty("车辆类型id")
|
||||
@TableField("type_id")
|
||||
private Integer typeId;
|
||||
|
||||
@ApiModelProperty("车辆围栏")
|
||||
@TableField("fence_id")
|
||||
private Integer fenceId;
|
||||
@ApiModelProperty("车辆围栏id")
|
||||
@TableField("fencing_id")
|
||||
private String fencingId;
|
||||
|
||||
@ApiModelProperty("车辆零件ID")
|
||||
@TableField("drive_id")
|
||||
private Integer driveId;
|
||||
|
||||
@ApiModelProperty("车辆电池")
|
||||
@ApiModelProperty("车辆电池id")
|
||||
@TableField("battery_id")
|
||||
private Integer batteryId;
|
||||
|
||||
|
|
|
@ -49,6 +49,10 @@ public class Fencing extends BaseEntity {
|
|||
@TableField(value = "fencing_time")
|
||||
private Date fencingTime ;
|
||||
|
||||
@ApiModelProperty("围栏类型")
|
||||
@TableField(value = "fencing_type_id")
|
||||
private Integer fencingTypeId;
|
||||
|
||||
@ApiModelProperty("操作者")
|
||||
@TableField(value = "create_user_id")
|
||||
private Integer createUserId ;
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
package com.shiyi.internet.domain.fault;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fate.common.core.annotation.Excel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:
|
||||
* @Date:
|
||||
* @Description 故障码信息管理列表
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FaultCode {
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障码ID
|
||||
*/
|
||||
@NotEmpty(message = "故障码ID不能为空")
|
||||
private Integer faultId;
|
||||
|
||||
@NotEmpty(message = "车辆vin")
|
||||
private String vin;
|
||||
|
||||
@NotEmpty(message = "故障码")
|
||||
private String faultCode;
|
||||
|
||||
/**
|
||||
* @Description 故障内容
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
*/
|
||||
@NotEmpty(message = "故障内容不能为空")
|
||||
private String faultContent;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障级别
|
||||
*/
|
||||
|
||||
@NotEmpty(message = "故障级别不能为空")
|
||||
private Integer priorityId;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障时间
|
||||
*/
|
||||
@NotEmpty(message = "故障时间不能为空")
|
||||
private Date faultTime;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障类型
|
||||
*/
|
||||
@NotEmpty(message = "故障类型不能为空")
|
||||
private Integer faultTypeId;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障异常指标
|
||||
*/
|
||||
@NotEmpty(message = "故障异常指标不能为空")
|
||||
private Integer faultErrorInformation;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障正常指标
|
||||
*/
|
||||
@NotEmpty(message = "故障正常指标不能为空")
|
||||
private Integer faultSucceedInformation;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障状态
|
||||
*/
|
||||
@NotEmpty(message = "故障状态不能为空")
|
||||
private Integer faultFlag;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 车辆ID
|
||||
*/
|
||||
@NotEmpty(message = "车辆ID不能为空")
|
||||
private Integer carId;
|
||||
|
||||
/** 开始报警时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:dd:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "开始报警时间", width = 30, dateFormat = "yyyy-MM-dd HH:dd:ss")
|
||||
private Date warningTime;
|
||||
|
||||
/** 结束报警时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:dd:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "结束报警时间", width = 30, dateFormat = "yyyy-MM-dd HH:dd:ss")
|
||||
private Date normalTime;
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.shiyi.internet.domain.fault;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:
|
||||
* @Date:
|
||||
* @Description
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FaultCodeRequest {
|
||||
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障内容
|
||||
*/
|
||||
@NotEmpty(message = "内容不能为空")
|
||||
private String faultContent;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障级别
|
||||
*/
|
||||
@NotEmpty(message = "故障级别不能为空")
|
||||
private String priorityId;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障时间
|
||||
*/
|
||||
@NotEmpty(message = "故障时间不能为空")
|
||||
private Date faultTime;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障类型
|
||||
*/
|
||||
@NotEmpty(message = "故障类型不能为空")
|
||||
private Integer faultTypeId;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障异常指标
|
||||
*/
|
||||
@NotEmpty(message = "故障异常指标不能为空")
|
||||
private Integer faultErrorInformation;
|
||||
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 故障正常指标
|
||||
*/
|
||||
|
||||
@NotEmpty(message = "故障正常指标不能为空")
|
||||
private Integer faultSucceedInformation;
|
||||
/**
|
||||
* @Author:shixuchao
|
||||
* @Date:
|
||||
* @Description 车辆ID
|
||||
*/
|
||||
@NotEmpty(message = "车辆ID不能为空")
|
||||
private Integer carId;
|
||||
|
||||
}
|
|
@ -46,8 +46,8 @@ public class ResponseCar {
|
|||
private Integer typeId ;
|
||||
/** 车辆围栏 */
|
||||
@ApiModelProperty(name = "车辆围栏")
|
||||
@TableField("fence_id")
|
||||
private Integer fenceId ;
|
||||
@TableField("fencing_id")
|
||||
private Integer fencingId ;
|
||||
/** 围栏名称 */
|
||||
@ApiModelProperty(name = "围栏名称")
|
||||
@TableField("fencing_name")
|
||||
|
|
|
@ -22,9 +22,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- 继承common依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.fate</groupId>
|
||||
<artifactId>fance-menghang-common</artifactId>
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package com.fate.vehicle.factory;
|
||||
|
||||
import com.fate.common.core.domain.Result;
|
||||
import com.shiyi.internet.domain.fault.FaultCode;
|
||||
import com.fate.vehicle.feign.LogFeign;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
|
||||
/**
|
||||
* @Description : 熔断
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-12-04 21:08
|
||||
*/
|
||||
public class LogFeignFactory implements FallbackFactory<LogFeign> {
|
||||
/**
|
||||
* @param cause
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public LogFeign create(Throwable cause) {
|
||||
return new LogFeign() {
|
||||
|
||||
/**
|
||||
* 添加故障日志
|
||||
*
|
||||
* @param faultCodeRequest
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result faultInsert(FaultCode faultCodeRequest) {
|
||||
return Result.error("200");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改故障日志
|
||||
*
|
||||
* @param faultCode
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result faultUpdate(FaultCode faultCode) {
|
||||
return Result.error();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.fate.vehicle.feign;
|
||||
|
||||
import com.fate.common.core.domain.Result;
|
||||
import com.fate.vehicle.factory.LogFeignFactory;
|
||||
import com.shiyi.internet.domain.fault.FaultCode;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-11-30 14:41
|
||||
*/
|
||||
@FeignClient( value = "fate-fault",fallbackFactory = LogFeignFactory.class)
|
||||
public interface LogFeign {
|
||||
|
||||
/**
|
||||
* 添加故障日志
|
||||
* @param faultCodeRequest
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("fault/faultInsert")
|
||||
public Result faultInsert(@RequestBody FaultCode faultCodeRequest);
|
||||
|
||||
|
||||
/**
|
||||
* 修改故障日志
|
||||
* @param faultCode
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("fault/faultUpdate")
|
||||
public Result faultUpdate(@RequestBody FaultCode faultCode);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.shiyi.vehicle.feign;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
||||
/**
|
||||
* @Description : 接口调用
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-11-23 11:13
|
||||
*/
|
||||
@FeignClient(name = "fate-fence")
|
||||
public interface VehicleFeign {
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.fate.vehicle.factory.LogFeignFactory
|
|
@ -62,6 +62,17 @@
|
|||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fate</groupId>
|
||||
<artifactId>fance-menghang-remote</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<!--WebSocket-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.fate.common.swagger.annotation.EnableCustomSwagger2;
|
|||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* @Description : 业务启动类
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
package com.shiyi.internet.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.shiyi.internet.constants.FaultConstant;
|
||||
import com.shiyi.internet.constants.RabbitContants;
|
||||
import com.shiyi.internet.constants.VehicleConstant;
|
||||
import com.shiyi.internet.domain.Car;
|
||||
import com.shiyi.internet.domain.Fencing;
|
||||
import com.shiyi.internet.domain.VehicleMessage;
|
||||
import com.shiyi.internet.domain.fault.FaultCode;
|
||||
import com.shiyi.internet.handler.LocationHandler;
|
||||
import com.shiyi.internet.handler.VehicleData;
|
||||
import com.fate.vehicle.feign.LogFeign;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @Description : RabbitMQ收到围栏处理消息
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-11-30 14:37
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class RabbitConfig {
|
||||
@Autowired
|
||||
private LogFeign logFeign;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
private final ExecutorService executorService = Executors.newFixedThreadPool(20);
|
||||
|
||||
@RabbitListener(queues = RabbitContants.FENCE_HANDLER_QUEUE)
|
||||
public void fenceHandler(String jsonMessage){
|
||||
|
||||
//将JSON消息转换成对象
|
||||
VehicleMessage message = JSONObject.parseObject(jsonMessage, new TypeReference<VehicleMessage>() {
|
||||
});
|
||||
//从Redis中获取所有车辆数据
|
||||
Car carInfo = (Car) redisTemplate.opsForHash().get(VehicleConstant.VEHICLE_INFO_MAP, message.getVin());
|
||||
//判断车辆是否存在围栏 Id
|
||||
if (StringUtils.isNotEmpty(carInfo.getFenceId())){
|
||||
//获取围栏信息
|
||||
Fencing fencingInfo = VehicleData.fencingInfoMap.get(carInfo.getFenceId());
|
||||
String[] split = fencingInfo.getFencingLat().split(";");
|
||||
ArrayList<Point2D.Double> locations = new ArrayList<>();
|
||||
for (String location : split) {
|
||||
String[] temp = location.split(",");
|
||||
locations.add(new Point2D.Double(Double.parseDouble(temp[0]), Double.parseDouble(temp[1])));
|
||||
}
|
||||
boolean ptInPoly = LocationHandler.isPtInPoly(new Point2D.Double(Double.parseDouble(message.getLatitude()), Double.parseDouble(message.getLongitude())), locations);
|
||||
if(fencingInfo.getFencingTypeId()==0 && !ptInPoly){
|
||||
log.info("vin:{};驶出电子围栏告警",carInfo.getCarVin());
|
||||
FaultCode log = (FaultCode) redisTemplate.opsForValue().get(FaultConstant.FAULT_INFO_PREFIX + carInfo.getCarVin() + "OUT");
|
||||
if (log == null){
|
||||
FaultCode faultCode = new FaultCode();
|
||||
faultCode.setFaultContent("OUT");
|
||||
faultCode.setVin(message.getVin());
|
||||
faultCode.setWarningTime(new Date());
|
||||
redisTemplate.opsForValue().set(FaultConstant.FAULT_INFO_PREFIX + carInfo.getCarVin() + ":OUT", faultCode);
|
||||
logFeign.faultInsert(faultCode);
|
||||
}
|
||||
}
|
||||
if (fencingInfo.getFencingTypeId()==0 && ptInPoly){
|
||||
FaultCode log = (FaultCode) redisTemplate.opsForValue().get(FaultConstant.FAULT_INFO_PREFIX + carInfo.getCarVin() + "OUT");
|
||||
if (log != null){
|
||||
log.setNormalTime(new Date());
|
||||
logFeign.faultUpdate(log);
|
||||
redisTemplate.delete(FaultConstant.FAULT_INFO_PREFIX + carInfo.getCarVin() + ":OUT");
|
||||
}
|
||||
}
|
||||
if (fencingInfo.getFencingTypeId()==1 && ptInPoly){
|
||||
log.info("vin:{};驶入非法区域告警", carInfo.getCarVin());
|
||||
FaultCode log = (FaultCode) redisTemplate.opsForValue().get(FaultConstant.FAULT_INFO_PREFIX + carInfo.getCarVin() + "IN");
|
||||
if (log == null){
|
||||
FaultCode faultCode = new FaultCode();
|
||||
faultCode.setFaultCode("IN");
|
||||
faultCode.setVin(message.getVin());
|
||||
faultCode.setWarningTime(new Date());
|
||||
redisTemplate.opsForValue().set(FaultConstant.FAULT_INFO_PREFIX + carInfo.getCarVin()+ ":IN", faultCode);
|
||||
}
|
||||
}
|
||||
if (fencingInfo.getFencingTypeId()==1 &&!ptInPoly){
|
||||
FaultCode log = (FaultCode) redisTemplate.opsForValue().get(FaultConstant.FAULT_INFO_PREFIX + carInfo.getCarVin() + "IN");
|
||||
if (log != null){
|
||||
log.setNormalTime(new Date());
|
||||
logFeign.faultUpdate(log);
|
||||
redisTemplate.delete(FaultConstant.FAULT_INFO_PREFIX + carInfo.getCarVin() + ":IN");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,8 @@ import com.fate.common.core.web.controller.BaseController;
|
|||
import com.shiyi.internet.domain.Fencing;
|
||||
import com.shiyi.internet.domain.response.ResponseFencing;
|
||||
import com.shiyi.internet.service.FencingService;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -28,13 +30,14 @@ public class FencingController extends BaseController {
|
|||
private HttpServletRequest request;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Description: 列表
|
||||
No such property: code for class: Script1
|
||||
* @return: com.fate.common.core.domain.Result<java.util.List<com.shiyi.internet.domain.response.ResponseFencing>>
|
||||
* @Author: YHY
|
||||
* @Updator: YHY
|
||||
* @Date 2023/11/18 13:31
|
||||
*/
|
||||
@ApiOperation("电子围栏查询")
|
||||
@GetMapping("/fencingList")
|
||||
public Result<List<ResponseFencing>> fencingList(){
|
||||
Result<List<ResponseFencing>> result = fencingService.fencingList();
|
||||
|
@ -49,6 +52,7 @@ public class FencingController extends BaseController {
|
|||
* @Updator: YHY
|
||||
* @Date 2023/11/18 13:54
|
||||
*/
|
||||
@ApiOperation("添加电子围栏")
|
||||
@PostMapping("/addfencing")
|
||||
public Result addfencing(@RequestBody Fencing fencing){
|
||||
fencingService.addfencing(fencing);
|
||||
|
@ -64,6 +68,7 @@ public class FencingController extends BaseController {
|
|||
* @Updator: YHY
|
||||
* @Date 2023/11/18 14:00
|
||||
*/
|
||||
@ApiOperation("删除电子围栏")
|
||||
@PostMapping("/deleteFence/{fencingId}")
|
||||
public Result deleteFencingById(@PathVariable Integer fencingId){
|
||||
Result result = fencingService.deleteFencingById(fencingId);
|
||||
|
@ -78,6 +83,7 @@ public class FencingController extends BaseController {
|
|||
* @Updator: YHY
|
||||
* @Date 2023/11/18 14:02
|
||||
*/
|
||||
@ApiOperation("修改电子围栏")
|
||||
@PostMapping("/updateFencing")
|
||||
public Result updateFencing(@RequestBody Fencing fencing){
|
||||
Result result = fencingService.updateFencing(fencing);
|
||||
|
@ -93,6 +99,7 @@ public class FencingController extends BaseController {
|
|||
* @Updator: YHY
|
||||
* @Date 2023/11/19 19:44
|
||||
*/
|
||||
@ApiOperation("精准查找电子围栏")
|
||||
@PostMapping("/findFencingById/{fencingId}")
|
||||
public Result findFencingById(@PathVariable Integer fencingId){
|
||||
ResponseFencing responseFencing = fencingService.findFencingById(fencingId);
|
||||
|
@ -109,6 +116,7 @@ public class FencingController extends BaseController {
|
|||
* @Updator: YHY
|
||||
* @Date 2023/11/19 19:50
|
||||
*/
|
||||
@ApiOperation("删除多个电子围栏")
|
||||
@PostMapping("/deleteFencingAllIds/{ids}")
|
||||
public Result deleteFencingAllIds(@PathVariable Integer[] ids){
|
||||
Result result = fencingService.deleteFencingAllIds(ids);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.shiyi.internet.handler;
|
||||
|
||||
import com.shiyi.internet.domain.Car;
|
||||
import com.shiyi.internet.domain.Fencing;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-11-30 20:58
|
||||
*/
|
||||
public class VehicleData {
|
||||
|
||||
/**
|
||||
* 车辆信息Map
|
||||
*/
|
||||
public static Map<String, Car> carInfoMap = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* 电子围栏Map
|
||||
*/
|
||||
public static Map<String, Fencing> fencingInfoMap = new HashMap<>();
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ public class DrivingRecordServiceimpl extends ServiceImpl<DrivingRecordMapper, D
|
|||
@Autowired
|
||||
private DrivingRecordMapper drivingRecordMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 车辆行驶记录
|
||||
* @return
|
||||
|
@ -38,6 +39,7 @@ public class DrivingRecordServiceimpl extends ServiceImpl<DrivingRecordMapper, D
|
|||
*/
|
||||
@Override
|
||||
public DrivingRecord fingCarRecordById(Integer recordId) {
|
||||
|
||||
return drivingRecordMapper.fingCarRecordById(recordId);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.shiyi.internet.webSocket.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
|
||||
/**
|
||||
* @Description : 连接WebSocket
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-12-01 19:49
|
||||
*/
|
||||
@Configuration
|
||||
public class WebSocketConfig {
|
||||
|
||||
@Bean
|
||||
public ServerEndpointExporter serverEndpointExporter(){
|
||||
return new ServerEndpointExporter();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.shiyi.internet.webSocket.controller;
|
||||
|
||||
import com.shiyi.internet.webSocket.handler.SocketBatchHandler;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.tomcat.util.net.SocketBufferHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
/**
|
||||
* @Description : 建立连接成功方法
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-12-01 20:42
|
||||
*/
|
||||
@ServerEndpoint("/vehicle/batch")
|
||||
@Component
|
||||
@Log4j2
|
||||
public class WebSocketBatchServer {
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session){
|
||||
log.info("数据大屏新连接:"+ session.getId());
|
||||
SocketBatchHandler.sessions.add(session);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.shiyi.internet.webSocket.controller;
|
||||
|
||||
import com.shiyi.internet.webSocket.handler.SocketHandler;
|
||||
import com.shiyi.internet.webSocket.mqtt.SocketData;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.PathParam;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
|
||||
/**
|
||||
* @Description :连接建立成功调用的方法
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-12-01 21:05
|
||||
*/
|
||||
@ServerEndpoint("/vehicle/realTime/{vin}")
|
||||
@Component
|
||||
@Log4j2
|
||||
public class WebSocketServer {
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session, @PathParam("vin")String vin){
|
||||
log.info("车辆实时轨迹,新连接:{}", session.getId());
|
||||
SocketData socketData = new SocketData();
|
||||
socketData.setVin(vin);
|
||||
socketData.setSession(session);
|
||||
SocketHandler.socketList.add(socketData);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.shiyi.internet.webSocket.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.shiyi.internet.constants.RedisConstants;
|
||||
import com.shiyi.internet.domain.VehicleMessage;
|
||||
import com.shiyi.internet.handler.VehicleData;
|
||||
import com.shiyi.internet.mapper.VehicleMapper;
|
||||
import com.shiyi.internet.webSocket.mqtt.VehicleAllData;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.Session;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-12-01 20:46
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class SocketBatchHandler {
|
||||
|
||||
public static CopyOnWriteArrayList<Session> sessions = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Autowired
|
||||
private VehicleMapper vehicleMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@Scheduled(cron = "0/1 * * * * ?")
|
||||
public void sendMessageFlush(){
|
||||
for (Session session : sessions) {
|
||||
List<String> ids = vehicleMapper.getOnlineVehicleIds();
|
||||
List<VehicleMessage> messages = ids.stream().map(id -> {
|
||||
VehicleMessage message =(VehicleMessage) redisTemplate.opsForValue().get(RedisConstants.CURRENT_INFO + ".");
|
||||
return message;
|
||||
}).collect(Collectors.toList());
|
||||
Integer day =(Integer) redisTemplate.opsForValue().get(RedisConstants.VEHICLE_INFO_TOKEN + RedisConstants.CURRENT_DAY_FAULT);
|
||||
Integer month =(Integer) redisTemplate.opsForValue().get(RedisConstants.VEHICLE_INFO_TOKEN + RedisConstants.CURRENT_MONTH_FAULT);
|
||||
Integer onlineCount = vehicleMapper.getOnlineCount();
|
||||
Integer unOnlineCount = vehicleMapper.getUnOnlineCount();
|
||||
VehicleAllData vehicleAllData = new VehicleAllData();
|
||||
vehicleAllData.setMessages(messages);
|
||||
vehicleAllData.setInfo(day + ":" + month + ":" + onlineCount + ":" + unOnlineCount);
|
||||
try {
|
||||
session.getBasicRemote().sendText(JSON.toJSONString(vehicleAllData));
|
||||
}catch (Exception e){
|
||||
log.info("{}连接中断", session.getId());
|
||||
sessions.remove(session);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.shiyi.internet.webSocket.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.shiyi.internet.constants.RedisConstants;
|
||||
import com.shiyi.internet.domain.VehicleMessage;
|
||||
import com.shiyi.internet.webSocket.mqtt.SocketData;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.Session;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-12-01 21:10
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class SocketHandler {
|
||||
|
||||
//存放每个客户端对应的MyWebSocket
|
||||
public static CopyOnWriteArrayList<SocketData> socketList = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@Scheduled(cron = "0/1 * * * * ?")
|
||||
public void sendMessageFlush(){
|
||||
for (SocketData socketData : socketList) {
|
||||
Session session = socketData.getSession();
|
||||
VehicleMessage msg =(VehicleMessage) redisTemplate.opsForValue().get(RedisConstants.CURRENT_INFO + ":" + socketData.getVin());
|
||||
try {
|
||||
session.getBasicRemote().sendText(JSON.toJSONString(msg));
|
||||
}catch (Exception e){
|
||||
log.info("{}:连接中断",socketData.getSession().getId());
|
||||
socketList.remove(socketData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.shiyi.internet.webSocket.mqtt;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.websocket.Session;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-12-01 21:06
|
||||
*/
|
||||
@Data
|
||||
public class SocketData {
|
||||
/**
|
||||
* vin
|
||||
*/
|
||||
private String vin;
|
||||
|
||||
/**
|
||||
* session
|
||||
*/
|
||||
private Session session;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.shiyi.internet.webSocket.mqtt;
|
||||
|
||||
import com.shiyi.internet.domain.VehicleMessage;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Author : YangHaoYu
|
||||
* @Date: 2023-12-01 20:57
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VehicleAllData {
|
||||
private List<VehicleMessage> messages;
|
||||
|
||||
private String info;
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
car_vin,
|
||||
car_status,
|
||||
type_id,
|
||||
fence_id,
|
||||
fencing_id,
|
||||
drive_id,
|
||||
battery_id,
|
||||
car_address) values(
|
||||
|
@ -19,7 +19,7 @@
|
|||
#{carVin},
|
||||
#{carStatus},
|
||||
#{typeId},
|
||||
#{fenceId},
|
||||
#{fencingId},
|
||||
#{driveId},
|
||||
#{batteryId},
|
||||
#{carAddress})
|
||||
|
@ -34,7 +34,7 @@
|
|||
car_vin=#{carVin},
|
||||
car_status=#{carStatus},
|
||||
type_id=#{typeId},
|
||||
fence_id=#{fenceId},
|
||||
fencing_id=#{fencingId},
|
||||
drive_id=#{driveId},
|
||||
battery_id=#{batteryId},
|
||||
car_address=#{carAddress} where car_id=#{carId}
|
||||
|
@ -48,11 +48,11 @@
|
|||
|
||||
<select id="vehicleList" resultType="com.shiyi.internet.domain.response.ResponseCar">
|
||||
select * from t_car ca left join t_drive dr on ca.drive_id=dr.drive_id left join
|
||||
t_battery ba on ca.battery_id=ba.battery_id left join t_fence fe on ca.fence_id=fe.fence_id
|
||||
t_battery ba on ca.battery_id=ba.battery_id left join t_fencing fe on ca.fencing_id=fe.fencing_id
|
||||
</select>
|
||||
<select id="findVehiclById" resultType="com.shiyi.internet.domain.response.ResponseCar">
|
||||
select * from t_car ca left join t_drive dr on ca.drive_id=dr.drive_id left join
|
||||
t_battery ba on ca.battery_id=ba.battery_id left join t_fence fe on ca.fence_id=fe.fence_id
|
||||
t_battery ba on ca.battery_id=ba.battery_id left join t_fencing fe on ca.fencing_id=fe.fencing_id
|
||||
where car_id=#{carId}
|
||||
</select>
|
||||
<select id="getVehicleInfoByVin" resultType="com.shiyi.internet.domain.Car">
|
||||
|
@ -75,11 +75,11 @@
|
|||
<where>
|
||||
<if test="carId != null and carId != ''"> and car_id = #{carId}</if>
|
||||
<if test="carName != null "> and car_name = #{carName}</if>
|
||||
<if test="carLicense != null and carLicense != ''"> and fence_id = #{carLicense}</if>
|
||||
<if test="carLicense != null and carLicense != ''"> and fencing_id = #{carLicense}</if>
|
||||
<if test="carVin != null "> and car_vin = #{carVin}</if>
|
||||
<if test="carStatus != null and carStatus != ''"> and car_status = #{carStatus}</if>
|
||||
<if test="typeId != null and typeId != ''"> and type_id = #{typeId}</if>
|
||||
<if test="fenceId != null and fenceId != ''"> and fence_-d = #{fenceId}</if>
|
||||
<if test="fencingId != null and fencingId != ''"> and fence_-d = #{fencingId}</if>
|
||||
<if test="driveId != null and driveId != ''"> and drive_id = #{driveId}</if>
|
||||
<if test="batteryId != null and batteryId != ''"> and battery_id = #{batteryId}</if>
|
||||
<if test="carAddress != null and carAddress != ''"> and car_address = #{carAddress}</if>
|
||||
|
|
Loading…
Reference in New Issue