fast()获取实时信息,重构电子围栏

car-ser
王熙朝 2024-06-18 22:18:26 +08:00
parent f878804bf7
commit 598dff8d71
10 changed files with 409 additions and 4 deletions

View File

@ -0,0 +1,102 @@
package com.business.common.dev;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
*
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CarFenceDev {
private Long carId;
/** 车辆识别码 */
@Excel(name = "车辆识别码")
private String vin;
/** 品牌 */
@Excel(name = "品牌")
private String brand;
/** 型号 */
@Excel(name = "型号")
private String model;
/** 生产年份 */
@Excel(name = "生产年份")
private Long manufactureYear;
/** 车身类型 */
@Excel(name = "车身类型")
private String bodyType;
/** 车辆颜色 */
@Excel(name = "车辆颜色")
private String color;
/** 发动机排量 */
@Excel(name = "发动机排量")
private Long engineCapacity;
/** 燃油类型 */
@Excel(name = "燃油类型")
private String fuelType;
/** 变速器类型 */
@Excel(name = "变速器类型")
private String transmission;
/** 驱动类型 */
@Excel(name = "驱动类型")
private String driveType;
/** 行驶里程 */
@Excel(name = "行驶里程")
private Long mileage;
/** 注册日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "注册日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date registrationDate;
/** 车牌号 */
@Excel(name = "车牌号")
private String registrationNumber;
/** 所有者 */
@Excel(name = "所有者")
private Long ownerId;
/**
*
*/
private Long fenceId;
/**
*
*/
private String fenceName;
/**
*
*/
private String fenceType = "多边形";
/**
*
*/
private String eventType = "N";
/**
*
*/
private String staut = "Y";
/**
*
*/
private String polygonPoints;
}

View File

@ -0,0 +1,87 @@
package com.business.common.dev;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
*
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CarGroupsDev {
private Long carId;
/** 车辆识别码 */
@Excel(name = "车辆识别码")
private String vin;
/** 品牌 */
@Excel(name = "品牌")
private String brand;
/** 型号 */
@Excel(name = "型号")
private String model;
/** 生产年份 */
@Excel(name = "生产年份")
private Long manufactureYear;
/** 车身类型 */
@Excel(name = "车身类型")
private String bodyType;
/** 车辆颜色 */
@Excel(name = "车辆颜色")
private String color;
/** 发动机排量 */
@Excel(name = "发动机排量")
private Long engineCapacity;
/** 燃油类型 */
@Excel(name = "燃油类型")
private String fuelType;
/** 变速器类型 */
@Excel(name = "变速器类型")
private String transmission;
/** 驱动类型 */
@Excel(name = "驱动类型")
private String driveType;
/** 行驶里程 */
@Excel(name = "行驶里程")
private Long mileage;
/** 注册日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "注册日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date registrationDate;
/** 车牌号 */
@Excel(name = "车牌号")
private String registrationNumber;
/** 所有者 */
@Excel(name = "所有者")
private Long ownerId;
/**
* id
*/
private Long groupsId;
/**
*
*/
private String groupsName;
}

View File

@ -0,0 +1,48 @@
package com.business.common.dev;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class GroupFenceDev {
/**
* id
*/
private Long groupsId;
/**
*
*/
private String groupsName;
/**
*
*/
private Long fenceId;
/**
*
*/
private String fenceName;
/**
*
*/
private String fenceType = "多边形";
/**
*
*/
private String eventType = "N";
/**
*
*/
private String staut = "Y";
/**
*
*/
private String polygonPoints;
}

View File

@ -1,13 +1,18 @@
package com.muyu.goods.controller;
import com.business.common.dev.CarFenceDev;
import com.business.common.dev.CarGroupsDev;
import com.business.common.dev.GroupFenceDev;
import com.business.common.domain.Fence;
import com.business.common.domain.FenceGroups;
import com.business.common.domain.Path;
import com.business.common.psvm.Pences;
import com.dtflys.forest.annotation.Post;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.goods.service.IMapService;
import com.muyu.goods.service.impl.MapService;
import net.sf.jsqlparser.statement.select.Select;
import org.apache.commons.codec.language.bm.Rule;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
@ -88,4 +93,31 @@ public class MapController extends BaseController {
public Result updateFence(@PathVariable Long fenceId) {
return success(iMapService.updateFence(fenceId));
}
/**
*
* @return
*/
@PostMapping("selectCarFence")
public Result<List<CarFenceDev>> selectCarFence() {
return success(iMapService.selectCarFence());
}
/**
*
* @return
*/
@PostMapping("selectCarGroups")
public Result<List<CarGroupsDev>> selectCarGroups() {
return success(iMapService.selectCarGroups());
}
/**
*
* @return
*/
@PostMapping("selectGroupFence")
public Result<List<GroupFenceDev>> selectGroupFence() {
return success(iMapService.selectGroupFence());
}
}

View File

@ -1,6 +1,8 @@
package com.muyu.goods.mapper;
import com.business.common.domain.Car;
import com.business.common.dev.CarFenceDev;
import com.business.common.dev.CarGroupsDev;
import com.business.common.dev.GroupFenceDev;
import com.business.common.domain.Fence;
import com.business.common.domain.FenceGroups;
import org.apache.ibatis.annotations.Param;
@ -18,4 +20,20 @@ public interface MapMapper {
Fence queryFence(@Param("fenceId") Long fenceId);
int updateFence(@Param("fenceId") Long fenceId, @Param("status") String status);
void indexCarGroupsMiddle(@Param("carId") Long carId);
List<GroupFenceDev> selectGroupFenceMiddleOne();
List<CarFenceDev> selectCarFence();
List<CarGroupsDev> selectCarGroups();
List<GroupFenceDev> selectGroupFence();
void indexCarFence(@Param("carId") Long carId, @Param("fenceId") Long fenceId);
void deleteCarGroups(@Param("carId") Long carId);
void deleteCarFence(@Param("carId") Long carId);
}

View File

@ -1,5 +1,8 @@
package com.muyu.goods.service;
import com.business.common.dev.CarFenceDev;
import com.business.common.dev.CarGroupsDev;
import com.business.common.dev.GroupFenceDev;
import com.business.common.domain.Fence;
import com.business.common.domain.FenceGroups;
import com.business.common.domain.Path;
@ -24,4 +27,10 @@ public interface IMapService {
Fence queryFence(Long fenceId);
String updateFence(Long fenceId);
List<CarFenceDev> selectCarFence();
List<CarGroupsDev> selectCarGroups();
List<GroupFenceDev> selectGroupFence();
}

View File

@ -6,7 +6,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.business.common.dev.LongitudeAndLatitude;
import com.business.common.dev.*;
import com.business.common.domain.*;
import com.business.common.pojo.HttpCar;
import com.muyu.goods.client.ManageApi;
@ -19,6 +19,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* Service
*
@ -37,6 +39,8 @@ public class CarServiceImpl implements ICarService
private MapMapper mapMapper;
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Resource
private ExecuteService service;
/**
*
@ -94,6 +98,7 @@ public class CarServiceImpl implements ICarService
int i = carMapper.insertCar(car);
if (i>0) {
Car car1 = carMapper.carByCar();
service.indexGroupFence(car1);
}
return i;
}
@ -119,7 +124,13 @@ public class CarServiceImpl implements ICarService
@Override
public int deleteCarByCarIds(Long[] carIds)
{
return carMapper.deleteCarByCarIds(carIds);
int i = carMapper.deleteCarByCarIds(carIds);
if (i>0){
for (Long carId : carIds) {
service.deleteCarGroupFence(carId);
}
}
return i;
}
/**
@ -131,7 +142,11 @@ public class CarServiceImpl implements ICarService
@Override
public int deleteCarByCarId(Long carId)
{
return carMapper.deleteCarByCarId(carId);
int i = carMapper.deleteCarByCarId(carId);
if (i>0) {
service.deleteCarGroupFence(carId);
}
return i;
}
@Override

View File

@ -0,0 +1,38 @@
package com.muyu.goods.service.impl;
import com.business.common.dev.GroupFenceDev;
import com.business.common.domain.Car;
import com.muyu.goods.mapper.MapMapper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Log4j2
public class ExecuteService {
@Autowired
private MapMapper mapMapper;
@Async
public void indexGroupFence(Car car) {
mapMapper.indexCarGroupsMiddle(car.getCarId());
List<GroupFenceDev> list = mapMapper.selectGroupFenceMiddleOne();
List<GroupFenceDev> groupFenceDevList = list.stream().filter(fence -> fence.getGroupsId() == 1).collect(Collectors.toList());
System.out.println(groupFenceDevList);
for (GroupFenceDev groupFenceDev : groupFenceDevList) {
mapMapper.indexCarFence(car.getCarId(),groupFenceDev.getFenceId());
}
log.info("indexGroupFence完成");
}
@Async
public void deleteCarGroupFence(Long carId){
mapMapper.deleteCarGroups(carId);
mapMapper.deleteCarFence(carId);
log.info("delete完成");
}
}

View File

@ -3,6 +3,9 @@ package com.muyu.goods.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.business.common.dev.CarFenceDev;
import com.business.common.dev.CarGroupsDev;
import com.business.common.dev.GroupFenceDev;
import com.business.common.domain.Fence;
import com.business.common.domain.FenceGroups;
import com.business.common.domain.Path;
@ -105,4 +108,19 @@ public class MapService implements IMapService {
}
return "失败";
}
@Override
public List<CarFenceDev> selectCarFence() {
return mapMapper.selectCarFence();
}
@Override
public List<CarGroupsDev> selectCarGroups() {
return mapMapper.selectCarGroups();
}
@Override
public List<GroupFenceDev> selectGroupFence() {
return mapMapper.selectGroupFence();
}
}

View File

@ -48,6 +48,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="polygonPoints != null">#{polygonPoints},</if>
</trim>
</insert>
<insert id="indexCarGroupsMiddle">
insert into car_groups_middle
values (0,#{carId},1);
</insert>
<insert id="indexCarFence">
insert into car_fence_middle
values (0,#{carId},#{fenceId});
</insert>
<update id="updateFence">
update fence
set staut = #{status}
@ -58,6 +66,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from fence
where fence_id = #{fenceId};
</delete>
<delete id="deleteCarGroups">
delete
from car_groups_middle
where car_id = #{carId};
</delete>
<delete id="deleteCarFence">
delete
from car_fence_middle
where car_id = #{carId};
</delete>
<select id="selectFenceGroups" resultType="com.business.common.domain.FenceGroups">
<include refid="FenceGroupsVo"></include>
</select>
@ -68,6 +86,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="FencesVo"></include>
where fence_id = #{fenceId}
</select>
<select id="selectGroupFenceMiddleOne" resultType="com.business.common.dev.GroupFenceDev">
select g.*,f.* from fence f
left join group_fence_middle m on f.fence_id = m.fence_id
left join fence_groups g on m.groups_id = g.groups_id;
</select>
<select id="selectCarFence" resultType="com.business.common.dev.CarFenceDev">
select c.*,f.* from car c
left join car_fence_middle m on c.car_id = m.car_id
left join fence f on f.fence_id = m.fence_id
</select>
<select id="selectCarGroups" resultType="com.business.common.dev.CarGroupsDev">
select c.*,g.* from car c
left join car_groups_middle m on c.car_id = m.car_id
left join fence_groups g on m.groups_id = g.groups_id
</select>
<select id="selectGroupFence" resultType="com.business.common.dev.GroupFenceDev">
select g.*,f.* from fence f
left join group_fence_middle m on f.fence_id = m.fence_id
left join fence_groups g on m.groups_id = g.groups_id
</select>
</mapper>