Compare commits
5 Commits
08acad4531
...
0463fde303
Author | SHA1 | Date |
---|---|---|
|
0463fde303 | |
|
b8de8285b7 | |
|
3c1b9cef33 | |
|
2c2854506e | |
|
55d398940f |
|
@ -0,0 +1,41 @@
|
|||
package com.zhilian.business;
|
||||
|
||||
import com.zhilian.business.controller.FenceController;
|
||||
import com.zhilian.business.controller.VehicleController;
|
||||
import com.zhilian.common.security.annotation.EnableCustomConfig;
|
||||
import com.zhilian.common.security.annotation.EnableMyFeignClients;
|
||||
import com.zhilian.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @BelongsProject: smart-cloud-server
|
||||
* @BelongsPackage: com.zhiLian.business
|
||||
* @Description 启动类
|
||||
* @Author: LiYuan
|
||||
* @CreateTime: 2024-03-31 10:13
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class ZhiLianBusinessApplication implements ApplicationRunner {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ZhiLianBusinessApplication.class);
|
||||
}
|
||||
@Autowired
|
||||
private FenceController fenceController;
|
||||
@Autowired
|
||||
private VehicleController vehicleController;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
fenceController.fenceRedisData();
|
||||
vehicleController.vehicleSelectAllData();
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.zhilian.business;
|
||||
|
||||
import com.zhilian.common.security.annotation.EnableCustomConfig;
|
||||
import com.zhilian.common.security.annotation.EnableMyFeignClients;
|
||||
import com.zhilian.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @BelongsProject: smart-cloud-server
|
||||
* @BelongsPackage: com.zhilian.business
|
||||
* @Description 启动类
|
||||
* @Author: LiYuan
|
||||
* @CreateTime: 2024-03-31 10:13
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class ZhilianBusinessApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ZhilianBusinessApplication.class);
|
||||
}
|
||||
}
|
|
@ -32,8 +32,7 @@ import com.zhilian.common.core.web.page.*;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/break")
|
||||
public class BusinessBreakController extends BaseController
|
||||
{
|
||||
public class BusinessBreakController extends BaseController{
|
||||
@Autowired
|
||||
private IBusinessBreakService businessBreakService;
|
||||
|
||||
|
|
|
@ -36,6 +36,14 @@ public class FenceController extends BaseController {
|
|||
return getDataTable(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加所有围栏信息进入redis
|
||||
*/
|
||||
public void fenceRedisData() {
|
||||
fenceService.fenceRedisData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增围栏
|
||||
* @param fence
|
||||
|
@ -45,7 +53,7 @@ public class FenceController extends BaseController {
|
|||
public Result fenceAdd(@RequestBody Fence fence) {
|
||||
fence.setUpdateBy(SecurityUtils.getUsername());
|
||||
fence.setUpdateTime(new Date());
|
||||
return toAjax(fenceService.save(fence));
|
||||
return toAjax(fenceService.saveFence(fence));
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,7 +78,7 @@ public class FenceController extends BaseController {
|
|||
public Result fenceUpdateMap(@RequestBody Fence fence) {
|
||||
fence.setUpdateBy(SecurityUtils.getUsername());
|
||||
fence.setUpdateTime(new Date());
|
||||
return toAjax(fenceService.updateById(fence));
|
||||
return toAjax(fenceService.updateByMap(fence));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +88,7 @@ public class FenceController extends BaseController {
|
|||
*/
|
||||
@PostMapping("/fenceDelete/{fenceId}")
|
||||
public Result fenceDelete(@PathVariable String fenceId) {
|
||||
return toAjax(fenceService.removeById(fenceId));
|
||||
return toAjax(fenceService.removeByFence(fenceId));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.zhilian.business.controller;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zhilian.business.domain.Vehicle;
|
||||
import com.zhilian.business.domain.VehicleFence;
|
||||
import com.zhilian.business.domain.middle.VehicleMarkers;
|
||||
import com.zhilian.business.service.MarkersService;
|
||||
import com.zhilian.business.service.VehicleMarkersService;
|
||||
|
@ -46,6 +47,12 @@ public class VehicleController extends BaseController {
|
|||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("/vehicleSelectAllData")
|
||||
public List<VehicleFence> vehicleSelectAllData(){
|
||||
List<VehicleFence> selectSelectAllData = vehicleService.selectSelectAllData();
|
||||
return selectSelectAllData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增车辆
|
||||
* @param vehicle
|
||||
|
@ -76,6 +83,9 @@ public class VehicleController extends BaseController {
|
|||
|
||||
//重新添加中间表数据
|
||||
vehicleMarkersService.insert(vehicle);
|
||||
|
||||
//判断添加完成后的标识与围栏是否绑定事件 如果没有绑定全部删除围栏事件 然后进行给予绑定
|
||||
vehicleService.selectRedisData(vehicle);
|
||||
return toAjax(update);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package com.zhilian.business.controller;
|
||||
|
||||
import com.zhilian.business.domain.middle.VehicleMarkers;
|
||||
import com.zhilian.business.service.VehicleMarkersService;
|
||||
import com.zhilian.common.core.domain.Result;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package com.zhilian.business.controller;
|
||||
|
||||
import com.zhilian.business.domain.VehicleType;
|
||||
import com.zhilian.business.service.VehicleTypeService;
|
||||
import com.zhilian.common.core.domain.Result;
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.zhilian.business.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
@SuperBuilder
|
||||
public class VehicleFence {
|
||||
private Long vehicleId;
|
||||
private String vehicleVIN;
|
||||
private String fences;
|
||||
|
||||
private List<String> fenceIds;
|
||||
}
|
|
@ -2,11 +2,16 @@ package com.zhilian.business.mapper;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zhilian.business.domain.Vehicle;
|
||||
import com.zhilian.business.domain.VehicleFence;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Component
|
||||
public interface VehicleMapper extends BaseMapper<Vehicle> {
|
||||
|
||||
List<VehicleFence> selectListAll();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.zhilian.business.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import com.zhilian.business.domain.VehicleType;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
|
@ -7,4 +7,12 @@ import java.util.List;
|
|||
|
||||
public interface FenceService extends IService<Fence> {
|
||||
List<Fence> fenceList(Fence fence);
|
||||
|
||||
void fenceRedisData();
|
||||
|
||||
boolean saveFence(Fence fence);
|
||||
|
||||
boolean updateByMap(Fence fence);
|
||||
|
||||
boolean removeByFence(String fenceId);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.zhilian.business.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import com.zhilian.business.domain.Vehicle;
|
||||
import com.zhilian.business.domain.middle.VehicleMarkers;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.zhilian.business.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zhilian.business.domain.Vehicle;
|
||||
import com.zhilian.business.domain.VehicleFence;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -12,4 +13,8 @@ public interface VehicleService extends IService<Vehicle> {
|
|||
Vehicle getVehicleByVIN(String vehicleVIN);
|
||||
|
||||
boolean updateState(Vehicle vehicle);
|
||||
|
||||
void selectRedisData(Vehicle vehicle);
|
||||
|
||||
List<VehicleFence> selectSelectAllData();
|
||||
}
|
||||
|
|
|
@ -6,12 +6,19 @@ import com.zhilian.business.domain.Fence;
|
|||
import com.zhilian.business.mapper.FenceMapper;
|
||||
import com.zhilian.business.service.FenceService;
|
||||
import com.zhilian.common.core.utils.StringUtils;
|
||||
import com.zhilian.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements FenceService {
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
private static final String FENCE_INFO_KEY = "fence_info:";
|
||||
//电子围栏信息查询
|
||||
@Override
|
||||
public List<Fence> fenceList(Fence fence) {
|
||||
if (fence.getFenceName() == null && fence.getFenceTypeId() == null && fence.getFenceState() == null) {
|
||||
|
@ -34,7 +41,54 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
|
|||
if (fence.getFenceState() != null) {
|
||||
queryWrapper.eq(Fence::getFenceState, fence.getFenceState());
|
||||
}
|
||||
|
||||
if(!redisService.hasKey(FENCE_INFO_KEY)){
|
||||
fenceRedisData();
|
||||
}
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
//缓存电子围栏信息
|
||||
@Override
|
||||
public void fenceRedisData() {
|
||||
List<Fence> list = this.list();
|
||||
for (Fence fence : list) {
|
||||
redisService.setCacheSet(FENCE_INFO_KEY+fence.getFenceId(),fence.getFenceMessage());
|
||||
}
|
||||
}
|
||||
//删除电子围栏全部数据
|
||||
private void fenceRedisDelete(){
|
||||
List<Fence> list = this.list();
|
||||
for (Fence fence : list) {
|
||||
redisService.deleteObject(FENCE_INFO_KEY+fence.getFenceId());
|
||||
}
|
||||
}
|
||||
//添加电子围栏信息
|
||||
@Override
|
||||
public boolean saveFence(Fence fence) {
|
||||
boolean save = this.save(fence);
|
||||
return save;
|
||||
}
|
||||
//绑定经纬度地图
|
||||
@Override
|
||||
public boolean updateByMap(Fence fence) {
|
||||
boolean updateByMap = this.updateById(fence);
|
||||
if(redisService.hasKey(FENCE_INFO_KEY+fence.getFenceId())){
|
||||
redisService.deleteObject(FENCE_INFO_KEY+fence.getFenceId());
|
||||
}
|
||||
redisService.setCacheSet(FENCE_INFO_KEY+fence.getFenceId(),fence.getFenceMessage());
|
||||
return updateByMap;
|
||||
}
|
||||
|
||||
|
||||
//删除电子围栏
|
||||
@Override
|
||||
public boolean removeByFence(String fenceId) {
|
||||
boolean remove = this.removeById(Integer.parseInt(fenceId));
|
||||
if(redisService.hasKey(FENCE_INFO_KEY+fenceId)){
|
||||
redisService.deleteObject(FENCE_INFO_KEY+fenceId);
|
||||
}
|
||||
return remove;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.zhilian.business.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhilian.business.domain.Markers;
|
||||
import com.zhilian.business.domain.middle.MarkersFence;
|
||||
import com.zhilian.business.service.FenceService;
|
||||
import com.zhilian.business.mapper.MarkersFenceMapper;
|
||||
import com.zhilian.business.service.MarkersFenceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
|
@ -1,18 +1,39 @@
|
|||
package com.zhilian.business.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhilian.business.domain.Vehicle;
|
||||
import com.zhilian.business.domain.middle.VehicleMarkers;
|
||||
import com.zhilian.business.mapper.VehicleMarkersMapper;
|
||||
import com.zhilian.business.mapper.*;
|
||||
import com.zhilian.business.service.VehicleMarkersService;
|
||||
import com.zhilian.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class VehicleMarkersServiceImpl extends ServiceImpl<VehicleMarkersMapper, VehicleMarkers> implements VehicleMarkersService {
|
||||
// @Autowired
|
||||
// private VehicleMapper vehicleMapper;
|
||||
//
|
||||
// @Autowired
|
||||
// private VehicleMarkersMapper vehicleMarkersMapper;
|
||||
//
|
||||
// @Autowired
|
||||
// private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private MarkersMapper markersMapper;
|
||||
|
||||
@Autowired
|
||||
private MarkersFenceMapper markersFenceMapper;
|
||||
|
||||
@Autowired
|
||||
private FenceMapper fenceMapper;
|
||||
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
|
@ -25,6 +46,24 @@ public class VehicleMarkersServiceImpl extends ServiceImpl<VehicleMarkersMapper,
|
|||
list.add(vehicleMarkers);
|
||||
});
|
||||
return this.saveBatch(list);
|
||||
|
||||
// String vehicleVIN = vehicle.getVehicleVIN();
|
||||
// //标识
|
||||
// List<Markers> markers = markersMapper.selectBatchIds(vehicle.getMarkersIds());
|
||||
// //中间表
|
||||
// List<MarkersFence> markersFences = markersFenceMapper.selectBatchIds(markers);
|
||||
// //围栏
|
||||
// List<Long> fenceIds = markersFences.stream().map(MarkersFence::getFenceId).collect(Collectors.toList());
|
||||
// List<Fence> fences = fenceMapper.selectBatchIds(fenceIds);
|
||||
//
|
||||
// System.out.println("**********************"+fences);
|
||||
// List<MarkersFence> markersFences = markersFenceMapper.selectList(new LambdaQueryWrapper<MarkersFence>().in(MarkersFence::getMarkersId, vehicle.getMarkersIds()));
|
||||
// List<Fence> fences = fenceMapper.selectBatchIds(markersFences.stream().map(MarkersFence::getFenceId).distinct().toArray(Long[]::new));
|
||||
// markersFences.forEach(markersFence -> {
|
||||
// markersFence.setFence(fences.stream().filter(fence -> fence.getFenceId().equals(markersFence.getFenceId())).findFirst().get());
|
||||
// });
|
||||
//
|
||||
// redisService.set(vehicle.getVehicleId(), markersFences);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,19 +3,29 @@ package com.zhilian.business.service.impl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhilian.business.domain.Vehicle;
|
||||
import com.zhilian.business.mapper.VehicleMapper;
|
||||
import com.zhilian.business.domain.VehicleFence;
|
||||
import com.zhilian.business.mapper.*;
|
||||
import com.zhilian.business.service.VehicleService;
|
||||
import com.zhilian.common.core.utils.StringUtils;
|
||||
import com.zhilian.common.redis.service.RedisService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Log4j2
|
||||
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> implements VehicleService {
|
||||
@Autowired
|
||||
private VehicleMapper vehicleMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
private final String VEHICLE_PEOPLE_KEY = "vehicle_fence:";
|
||||
@Override
|
||||
public List<Vehicle> selectVehicleList(Vehicle vehicle) {
|
||||
LambdaQueryWrapper<Vehicle> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
@ -74,4 +84,31 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectRedisData(Vehicle vehicle) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VehicleFence> selectSelectAllData() {
|
||||
List<VehicleFence> vehicleMarkersFence = vehicleMapper.selectListAll();
|
||||
for (VehicleFence vehicleFence : vehicleMarkersFence) {
|
||||
// 切割 fenceIds 字段为数组
|
||||
String[] fenceIdsArray = vehicleFence.getFences().split(",");
|
||||
|
||||
// 将数组转换为 ArrayList
|
||||
ArrayList<String> fenceIdsArrayList = new ArrayList<>(Arrays.asList( fenceIdsArray));
|
||||
|
||||
vehicleFence.setFenceIds(fenceIdsArrayList);
|
||||
}
|
||||
// 缓存
|
||||
for (VehicleFence vehicleFence : vehicleMarkersFence) {
|
||||
redisService.setCacheList(VEHICLE_PEOPLE_KEY + vehicleFence.getVehicleVIN(), vehicleFence.getFenceIds());
|
||||
}
|
||||
|
||||
log.info(vehicleMarkersFence);
|
||||
return vehicleMarkersFence;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zhilian.business.mapper.VehicleMapper">
|
||||
|
||||
|
||||
<select id="selectListAll" resultType="com.zhilian.business.domain.VehicleFence">
|
||||
SELECT
|
||||
BV.vehicle_id,
|
||||
BV.vehicle_vin,
|
||||
GROUP_CONCAT(BF.fence_id) AS fenceIds
|
||||
FROM
|
||||
business_vehicle AS BV
|
||||
JOIN
|
||||
business_vehicle_markers AS BVM ON BV.vehicle_id = BVM.vehicle_id
|
||||
JOIN
|
||||
business_markers_fence AS BMF ON BVM.markers_id = BMF.markers_id
|
||||
JOIN
|
||||
business_fence AS BF ON BMF.fence_id = BF.fence_id
|
||||
GROUP BY
|
||||
BV.vehicle_id, BV.vehicle_vin
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue