fast()获取实时信息,重构电子围栏
parent
fe2ae95a94
commit
f878804bf7
|
@ -26,6 +26,7 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.business.common.dev;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LongitudeAndLatitude {
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String longitude;
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private String latitude;
|
||||
}
|
|
@ -11,10 +11,6 @@ public class Fence {
|
|||
* 电子围栏主键
|
||||
*/
|
||||
private Long fenceId;
|
||||
/**
|
||||
* 围栏组主键
|
||||
*/
|
||||
private Long groupId;
|
||||
/**
|
||||
* 围栏名称
|
||||
*/
|
||||
|
|
|
@ -13,14 +13,8 @@ public class FenceGroups {
|
|||
* 围栏组id
|
||||
*/
|
||||
private Long groupsId;
|
||||
|
||||
private Long carId;
|
||||
/**
|
||||
* 围栏组名称
|
||||
*/
|
||||
private String groupsName;
|
||||
/**
|
||||
* 电子围栏
|
||||
*/
|
||||
private List<Fence> fenceList;
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package com.business.common.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LongitudeAndLatitude {
|
||||
private String polygonItem;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.business.common.pojo;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Configuration
|
||||
public class AppConfig {
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.business.common.pojo;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
@Service
|
||||
public class HttpCar {
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
public static void http(String name) {
|
||||
//创建HttpClient实例
|
||||
java.net.http.HttpClient httpClient = java.net.http.HttpClient.newHttpClient();
|
||||
|
||||
//创建httpRequest
|
||||
HttpRequest builder = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://129.211.23.219:9100/manage/"+ name +"/JAV0VJUJYOTOK9KSY/1"))
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")// 根据需要设置Content-Type,如果服务期望其他类型的空请求体
|
||||
.POST(HttpRequest.BodyPublishers.noBody())// 使用 POST 方法并设置请求体,没有设置为空
|
||||
.build();
|
||||
//发送请求并获取响应
|
||||
try {
|
||||
HttpResponse<String> send = httpClient.send(builder, HttpResponse.BodyHandlers.ofString());
|
||||
int statusCode = send.statusCode();
|
||||
String responseBody = send.body();
|
||||
//处理响应
|
||||
System.out.println("状态码: " + statusCode);
|
||||
System.out.println("响应: " + responseBody);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -11,6 +11,6 @@ import java.util.List;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Pences {
|
||||
private Long groupsId;
|
||||
private Long pences;
|
||||
private List<Path> list;
|
||||
}
|
||||
|
|
|
@ -112,6 +112,13 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- http调用框架 -->
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot-starter</artifactId>
|
||||
<version>1.5.36</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.goods.client;
|
||||
|
||||
import com.dtflys.forest.annotation.BaseRequest;
|
||||
import com.dtflys.forest.annotation.Post;
|
||||
|
||||
/**
|
||||
* 建木webhook触发接口
|
||||
* @author GuanTieLin
|
||||
* @Date 2024/4/11 上午10:49
|
||||
*/
|
||||
@BaseRequest(
|
||||
baseURL = "http://129.211.23.219:9100",
|
||||
connectTimeout = 5000,
|
||||
readTimeout = 5000
|
||||
)
|
||||
public interface ManageApi {
|
||||
|
||||
@Post("/manage/open/JAV0VJUJYOTOK9KSY/1")
|
||||
void open();
|
||||
|
||||
@Post("/manage/close/JAV0VJUJYOTOK9KSY/1")
|
||||
void close();
|
||||
|
||||
}
|
|
@ -3,7 +3,9 @@ package com.muyu.goods.controller;
|
|||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.business.common.dev.LongitudeAndLatitude;
|
||||
import com.business.common.domain.Car;
|
||||
import com.business.common.domain.VehicleInfo;
|
||||
import com.muyu.goods.service.ICarService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
@ -139,4 +141,30 @@ public class CarController extends BaseController
|
|||
String s = redisTemplate.opsForValue().get("01");
|
||||
return Result.success(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取信息
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("read")
|
||||
public Result<VehicleInfo> read() {
|
||||
return success(carService.read());
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启事件
|
||||
*/
|
||||
@PostMapping("open")
|
||||
public void open() {
|
||||
carService.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束事件
|
||||
*/
|
||||
@PostMapping("close")
|
||||
public void close() {
|
||||
carService.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,18 +8,14 @@ import org.apache.ibatis.annotations.Param;
|
|||
import java.util.List;
|
||||
|
||||
public interface MapMapper {
|
||||
void indexFenceGroups(@Param("carId") Long carId, @Param("groupsName") String groupsName);
|
||||
|
||||
List<FenceGroups> selectFenceGroups();
|
||||
|
||||
List<Fence> selectFence();
|
||||
|
||||
int indexFence(Fence fence);
|
||||
|
||||
int deleteFence(@Param("fenceId") Long fenceId);
|
||||
|
||||
Fence queryFence(@Param("fenceId") Long fenceId);
|
||||
|
||||
int updateFence(@Param("fenceId") Long fenceId, @Param("status") String status);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.muyu.goods.service;
|
||||
|
||||
import com.business.common.dev.LongitudeAndLatitude;
|
||||
import com.business.common.domain.Car;
|
||||
import com.business.common.domain.VehicleInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -67,4 +69,10 @@ public interface ICarService
|
|||
|
||||
Car query(Long carId);
|
||||
|
||||
VehicleInfo read();
|
||||
|
||||
void open();
|
||||
|
||||
void close();
|
||||
|
||||
}
|
||||
|
|
|
@ -2,14 +2,21 @@ package com.muyu.goods.service.impl;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.business.common.domain.Car;
|
||||
import com.business.common.domain.Enterprise;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.business.common.dev.LongitudeAndLatitude;
|
||||
import com.business.common.domain.*;
|
||||
import com.business.common.pojo.HttpCar;
|
||||
import com.muyu.goods.client.ManageApi;
|
||||
import com.muyu.goods.mapper.CarMapper;
|
||||
import com.muyu.goods.mapper.MapMapper;
|
||||
import com.muyu.goods.service.ICarService;
|
||||
import com.muyu.goods.timer.Timer;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
|
@ -19,6 +26,7 @@ import org.springframework.stereotype.Service;
|
|||
* @date 2024-05-27
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class CarServiceImpl implements ICarService
|
||||
{
|
||||
@Autowired
|
||||
|
@ -27,6 +35,8 @@ public class CarServiceImpl implements ICarService
|
|||
private BusinessServiceImpl businessService;
|
||||
@Autowired
|
||||
private MapMapper mapMapper;
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
/**
|
||||
* 查询车辆信息
|
||||
|
@ -84,8 +94,6 @@ public class CarServiceImpl implements ICarService
|
|||
int i = carMapper.insertCar(car);
|
||||
if (i>0) {
|
||||
Car car1 = carMapper.carByCar();
|
||||
System.out.println(car1);
|
||||
mapMapper.indexFenceGroups(car1.getCarId(),"car"+car1.getCarId());
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
@ -130,4 +138,50 @@ public class CarServiceImpl implements ICarService
|
|||
public Car query(Long carId) {
|
||||
return carMapper.query(carId);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Timer timer;
|
||||
|
||||
@Override
|
||||
public VehicleInfo read() {
|
||||
String rightPopAndLeftPush = null;
|
||||
try {
|
||||
rightPopAndLeftPush = redisTemplate.opsForList().leftPop("event_handler:realtime_data:JAV0VJUJYOTOK9KSY"
|
||||
, 3, TimeUnit.SECONDS);
|
||||
if (rightPopAndLeftPush != null) {
|
||||
log.info("处理消息: {}", rightPopAndLeftPush);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
if (rightPopAndLeftPush != null){
|
||||
String parse = JSON.parse(rightPopAndLeftPush).toString();
|
||||
VehicleInfo vehicleInfo = JSON.parseObject(parse, VehicleInfo.class);
|
||||
// LongitudeAndLatitude longitudeAndLatitude = LongitudeAndLatitude.builder()
|
||||
// .latitude(latitude)
|
||||
// .longitude(longitude)
|
||||
// .build();
|
||||
return vehicleInfo;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ManageApi manageApi;
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
// manageApi.open();
|
||||
HttpCar.http("open");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
HttpCar.http("close");
|
||||
// manageApi.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,13 +29,6 @@ public class MapService implements IMapService {
|
|||
@Override
|
||||
public List<FenceGroups> selectFenceGroups() {
|
||||
List<FenceGroups> fenceGroupsList = mapMapper.selectFenceGroups();
|
||||
for (FenceGroups fenceGroups : fenceGroupsList) {
|
||||
if (selectFence() == null){
|
||||
continue;
|
||||
}
|
||||
List<Fence> fenceList = selectFence().stream().filter(fa -> fa.getGroupId() == fenceGroups.getGroupsId()).collect(Collectors.toList());
|
||||
fenceGroups.setFenceList(fenceList);
|
||||
}
|
||||
return fenceGroupsList;
|
||||
}
|
||||
|
||||
|
@ -56,8 +49,7 @@ public class MapService implements IMapService {
|
|||
*/
|
||||
@Override
|
||||
public FenceGroups selectFenceGroupsById(Long carId) {
|
||||
List<FenceGroups> groups = selectFenceGroups().stream().filter(car -> car.getCarId() == carId).collect(Collectors.toList());
|
||||
return groups.get(0);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,23 +59,7 @@ public class MapService implements IMapService {
|
|||
*/
|
||||
@Override
|
||||
public String getSel(Pences pences) {
|
||||
System.out.println(pences);
|
||||
if (pences.getGroupsId() == null){
|
||||
return "数据不全";
|
||||
}
|
||||
FenceGroups fenceGroups = selectFenceGroups().stream().filter(g -> g.getGroupsId() == pences.getGroupsId()).collect(Collectors.toList()).get(0);
|
||||
Fence fence = new Fence();
|
||||
fence.setGroupId(pences.getGroupsId());
|
||||
List<Path> list = pences.getList();
|
||||
String jsonString = JSONArray.toJSONString(list);
|
||||
fence.setPolygonPoints(jsonString);
|
||||
List<Path> paths = JSONArray.parseArray(jsonString, Path.class);
|
||||
fence.setFenceName("围栏"+ (fenceGroups.getFenceList().size()+1));
|
||||
int i = mapMapper.indexFence(fence);
|
||||
if (i> 0) {
|
||||
return "传入电子围栏";
|
||||
}
|
||||
return "传入电子围栏失败";
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.goods.timer;
|
||||
|
||||
import com.muyu.goods.controller.CarController;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.common.protocol.types.Field;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
|
@ -20,10 +21,9 @@ public class Timer {
|
|||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
@Scheduled(fixedDelay = 1000)
|
||||
public void generateRandomNumber() {
|
||||
// Random random = new Random();
|
||||
// int i = random.nextInt(100);
|
||||
// System.out.println(i);
|
||||
public String generateRandomNumber() {
|
||||
Random random = new Random();
|
||||
int i = random.nextInt(100);
|
||||
String rightPopAndLeftPush = null;
|
||||
try {
|
||||
rightPopAndLeftPush = redisTemplate.opsForList().leftPop("event_handler:realtime_data:JAV0VJUJYOTOK9KSY"
|
||||
|
@ -32,12 +32,14 @@ public class Timer {
|
|||
log.info("处理消息: {}", rightPopAndLeftPush);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 处理超时异常,进行持久化操作,消息没处理可进行后续处理
|
||||
// 处理超时异常,进行持久化操作,消息没处理可进行后续处理
|
||||
// if (rightPopAndLeftPush != null) {
|
||||
// redisTemplate.opsForList().leftPush("backupList", rightPopAndLeftPush);
|
||||
// }
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
rightPopAndLeftPush = String.valueOf(i);
|
||||
return rightPopAndLeftPush;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<resultMap type="com.business.common.domain.FenceGroups" id="FenceGroupsResult">
|
||||
<result property="groupsId" column="groups_id" />
|
||||
<result property="carId" column="car_id" />
|
||||
<result property="groupsName" column="groups_name" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.business.common.domain.Fence" id="FenceResult">
|
||||
<result property="fenceId" column="fence_id" />
|
||||
<result property="groupId" column="group_id" />
|
||||
<result property="fenceName" column="fence_name" />
|
||||
<result property="fenceType" column="fence_type" />
|
||||
<result property="eventType" column="event_type" />
|
||||
|
|
Loading…
Reference in New Issue