zhangyeguang
4 weeks ago
16 changed files with 214 additions and 185 deletions
@ -0,0 +1,12 @@ |
|||
package com.jiagutech.ams.model; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class ZhongNongTrackData { |
|||
private double breadth; |
|||
|
|||
private List<ZhongNongTrack> vehicleLocusList; |
|||
} |
@ -1,75 +1,75 @@ |
|||
package com.jiagutech.ams.service; |
|||
|
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.alibaba.fastjson2.JSON; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|||
import com.jiagutech.ams.mapper.DeviceMapper; |
|||
import com.jiagutech.ams.mapper.SortieMapper; |
|||
import com.jiagutech.ams.model.SortieMapping; |
|||
import com.jiagutech.ams.model.UavSortie; |
|||
import com.jiagutech.ams.model.dto.DeviceDTO; |
|||
import com.jiagutech.ams.model.dto.SortieDTO; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.amqp.core.Message; |
|||
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.nio.charset.StandardCharsets; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @ClassName SortieService |
|||
* @author: zhangyeguang |
|||
* @create: 2024-09-09 09:32 |
|||
* @Version 1.0 |
|||
* @description: |
|||
**/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class SortieService { |
|||
|
|||
private final SortieMapper sortieMapper; |
|||
private final DeviceMapper deviceMapper; |
|||
|
|||
@RabbitListener(queues = "queue_ams_social_sortie") |
|||
public void receiveMessage(Message message) { |
|||
byte[] body = message.getBody(); |
|||
String jsonString = new String(body, StandardCharsets.UTF_8); |
|||
log.info("receiveMessage: {}", jsonString); |
|||
try { |
|||
UavSortie uavSortie = JSON.parseObject(jsonString, UavSortie.class); |
|||
SortieDTO sortieDTO = SortieMapping.INSTANCE.convertToSortieDTOByUavSortie(uavSortie); |
|||
SortieDTO hasSorties = sortieMapper.selectOne(Wrappers.lambdaQuery(SortieDTO.class).eq(SortieDTO::getVehicleId, sortieDTO.getVehicleId()) |
|||
.eq(SortieDTO::getStartAt, sortieDTO.getStartAt())); |
|||
if (ObjectUtil.isNotEmpty(sortieDTO)) { |
|||
if (ObjectUtil.isNotEmpty(hasSorties)) { |
|||
sortieDTO.setId(hasSorties.getId()); |
|||
sortieMapper.updateById(sortieDTO); |
|||
|
|||
} else { |
|||
sortieMapper.insert(sortieDTO); |
|||
} |
|||
QueryWrapper<DeviceDTO> queryWrapper = new QueryWrapper<>(); |
|||
queryWrapper.lambda().eq(DeviceDTO::getBoxNum, sortieDTO.getVehicleId()).lt(DeviceDTO::getUpdateTime, sortieDTO.getEndAt()); |
|||
DeviceDTO deviceDTO = new DeviceDTO().setUpdateTime(sortieDTO.getEndAt()).setLat(sortieDTO.getLatitude()).setLng(sortieDTO.getLongitude()); |
|||
deviceMapper.update(deviceDTO,queryWrapper); |
|||
|
|||
} |
|||
} catch (Exception e) { |
|||
log.error("receiveMessage error", e); |
|||
} |
|||
|
|||
} |
|||
// QueryWrapper<DeviceDTO> queryWrapper = Wrappers.query();
|
|||
// DeviceDTO deviceDTO = deviceMapper.selectOne(queryWrapper.eq("device_id", sortieDTO.getVehicleId()));
|
|||
// if (ObjectUtil.isNotEmpty(deviceDTO)) {
|
|||
// Long DeviceId = deviceDTO.getId();
|
|||
//package com.jiagutech.ams.service;
|
|||
//
|
|||
//import cn.hutool.core.util.ObjectUtil;
|
|||
//import com.alibaba.fastjson2.JSON;
|
|||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||
//import com.jiagutech.ams.mapper.DeviceMapper;
|
|||
//import com.jiagutech.ams.mapper.SortieMapper;
|
|||
//import com.jiagutech.ams.model.SortieMapping;
|
|||
//import com.jiagutech.ams.model.UavSortie;
|
|||
//import com.jiagutech.ams.model.dto.DeviceDTO;
|
|||
//import com.jiagutech.ams.model.dto.SortieDTO;
|
|||
//import lombok.RequiredArgsConstructor;
|
|||
//import lombok.extern.slf4j.Slf4j;
|
|||
//import org.springframework.amqp.core.Message;
|
|||
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|||
//import org.springframework.stereotype.Component;
|
|||
//
|
|||
//import java.nio.charset.StandardCharsets;
|
|||
//import java.util.Map;
|
|||
//
|
|||
///**
|
|||
// * @ClassName SortieService
|
|||
// * @author: zhangyeguang
|
|||
// * @create: 2024-09-09 09:32
|
|||
// * @Version 1.0
|
|||
// * @description:
|
|||
// **/
|
|||
//@Slf4j
|
|||
//@Component
|
|||
//@RequiredArgsConstructor
|
|||
//public class SortieService {
|
|||
//
|
|||
// private final SortieMapper sortieMapper;
|
|||
// private final DeviceMapper deviceMapper;
|
|||
//
|
|||
// @RabbitListener(queues = "queue_ams_social_sortie")
|
|||
// public void receiveMessage(Message message) {
|
|||
// byte[] body = message.getBody();
|
|||
// String jsonString = new String(body, StandardCharsets.UTF_8);
|
|||
// log.info("receiveMessage: {}", jsonString);
|
|||
// try {
|
|||
// UavSortie uavSortie = JSON.parseObject(jsonString, UavSortie.class);
|
|||
// SortieDTO sortieDTO = SortieMapping.INSTANCE.convertToSortieDTOByUavSortie(uavSortie);
|
|||
// SortieDTO hasSorties = sortieMapper.selectOne(Wrappers.lambdaQuery(SortieDTO.class).eq(SortieDTO::getVehicleId, sortieDTO.getVehicleId())
|
|||
// .eq(SortieDTO::getStartAt, sortieDTO.getStartAt()));
|
|||
// if (ObjectUtil.isNotEmpty(sortieDTO)) {
|
|||
// if (ObjectUtil.isNotEmpty(hasSorties)) {
|
|||
// sortieDTO.setId(hasSorties.getId());
|
|||
// sortieMapper.updateById(sortieDTO);
|
|||
//
|
|||
// } else {
|
|||
// sortieMapper.insert(sortieDTO);
|
|||
// }
|
|||
// QueryWrapper<DeviceDTO> queryWrapper = new QueryWrapper<>();
|
|||
// queryWrapper.lambda().eq(DeviceDTO::getBoxNum, sortieDTO.getVehicleId()).lt(DeviceDTO::getUpdateTime, sortieDTO.getEndAt());
|
|||
// DeviceDTO deviceDTO = new DeviceDTO().setUpdateTime(sortieDTO.getEndAt()).setLat(sortieDTO.getLatitude()).setLng(sortieDTO.getLongitude());
|
|||
// deviceMapper.update(deviceDTO,queryWrapper);
|
|||
//
|
|||
// }
|
|||
// } catch (Exception e) {
|
|||
// log.error("receiveMessage error", e);
|
|||
// }
|
|||
|
|||
|
|||
} |
|||
|
|||
//
|
|||
// }
|
|||
//// QueryWrapper<DeviceDTO> queryWrapper = Wrappers.query();
|
|||
//// DeviceDTO deviceDTO = deviceMapper.selectOne(queryWrapper.eq("device_id", sortieDTO.getVehicleId()));
|
|||
//// if (ObjectUtil.isNotEmpty(deviceDTO)) {
|
|||
//// Long DeviceId = deviceDTO.getId();
|
|||
////
|
|||
//// }
|
|||
//
|
|||
//
|
|||
//}
|
|||
//
|
|||
|
@ -1,45 +1,45 @@ |
|||
package com.jiagutech.ams.common; |
|||
|
|||
import org.springframework.amqp.core.*; |
|||
import org.springframework.amqp.rabbit.connection.ConnectionFactory; |
|||
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
|||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* @ClassName RabbitConfig |
|||
* @author: zhangyeguang |
|||
* @create: 2024-09-10 09:58 |
|||
* @Version 1.0 |
|||
* @description: |
|||
**/ |
|||
@Configuration |
|||
public class RabbitConfig { |
|||
public static final String EXCHANGE_NAME = "topic.exchange"; |
|||
public static final String QUEUE_FARM_SORTIE = "queue_ams_social_sortie"; |
|||
|
|||
@Bean |
|||
public Exchange exchange() { |
|||
//durable(true) 持久化,mq重启之后交换机还在
|
|||
return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build(); |
|||
} |
|||
|
|||
@Bean(QUEUE_FARM_SORTIE) |
|||
public Queue farmsortieQueue() { |
|||
return new Queue(QUEUE_FARM_SORTIE); |
|||
} |
|||
|
|||
|
|||
@Bean |
|||
public Binding bindingFarmSortie() { |
|||
return BindingBuilder.bind(farmsortieQueue()).to(exchange()).with("ams.sortie.key").noargs(); |
|||
} |
|||
@Bean |
|||
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) { |
|||
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); |
|||
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter()); |
|||
return rabbitTemplate; |
|||
} |
|||
|
|||
} |
|||
//package com.jiagutech.ams.common;
|
|||
//
|
|||
//import org.springframework.amqp.core.*;
|
|||
//import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|||
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|||
//import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
|||
//import org.springframework.context.annotation.Bean;
|
|||
//import org.springframework.context.annotation.Configuration;
|
|||
//
|
|||
///**
|
|||
// * @ClassName RabbitConfig
|
|||
// * @author: zhangyeguang
|
|||
// * @create: 2024-09-10 09:58
|
|||
// * @Version 1.0
|
|||
// * @description:
|
|||
// **/
|
|||
//@Configuration
|
|||
//public class RabbitConfig {
|
|||
// public static final String EXCHANGE_NAME = "topic.exchange";
|
|||
// public static final String QUEUE_FARM_SORTIE = "queue_ams_social_sortie";
|
|||
//
|
|||
// @Bean
|
|||
// public Exchange exchange() {
|
|||
// //durable(true) 持久化,mq重启之后交换机还在
|
|||
// return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
|
|||
// }
|
|||
//
|
|||
// @Bean(QUEUE_FARM_SORTIE)
|
|||
// public Queue farmsortieQueue() {
|
|||
// return new Queue(QUEUE_FARM_SORTIE);
|
|||
// }
|
|||
//
|
|||
//
|
|||
// @Bean
|
|||
// public Binding bindingFarmSortie() {
|
|||
// return BindingBuilder.bind(farmsortieQueue()).to(exchange()).with("ams.sortie.key").noargs();
|
|||
// }
|
|||
// @Bean
|
|||
// public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
|||
// RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
|||
// rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
|
|||
// return rabbitTemplate;
|
|||
// }
|
|||
//
|
|||
//}
|
|||
|
Loading…
Reference in new issue