server_five_liuyunhu
parent
4da1d7c52e
commit
9419a2f0a6
|
@ -51,4 +51,7 @@ public interface RemoteVehicleService {
|
||||||
@GetMapping("/findByVIN/{vin}")
|
@GetMapping("/findByVIN/{vin}")
|
||||||
public Result<List<Vehicle>> findByVIN(@PathVariable("vin") String vin);
|
public Result<List<Vehicle>> findByVIN(@PathVariable("vin") String vin);
|
||||||
|
|
||||||
|
@GetMapping("onOrOutLineByVIN")
|
||||||
|
public Integer onOrOutLineByVIN(@RequestParam("params") String params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,12 @@ public class RemoteVehicleFallbackFactory implements FallbackFactory<RemoteVehic
|
||||||
log.error("车辆服务调用失败:"+cause.getMessage());
|
log.error("车辆服务调用失败:"+cause.getMessage());
|
||||||
return Result.error("车辆服务调用失败:" + cause.getMessage());
|
return Result.error("车辆服务调用失败:" + cause.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer onOrOutLineByVIN(String params) {
|
||||||
|
log.error("车辆服务调用失败:"+cause.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
|
namespace: 172469
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
|
namespace: 172469
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.couplet.common.security.annotation.EnableMyFeignClients;
|
||||||
import com.couplet.common.swagger.annotation.EnableCustomSwagger2;
|
import com.couplet.common.swagger.annotation.EnableCustomSwagger2;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
|
@ -15,6 +16,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@EnableCustomSwagger2
|
@EnableCustomSwagger2
|
||||||
@EnableMyFeignClients(basePackages = ("com.couplet"))
|
@EnableMyFeignClients(basePackages = ("com.couplet"))
|
||||||
@SpringBootApplication(scanBasePackages = {"com.couplet"})
|
@SpringBootApplication(scanBasePackages = {"com.couplet"})
|
||||||
|
@EnableScheduling
|
||||||
public class CoupletBusinessApplication {
|
public class CoupletBusinessApplication {
|
||||||
public static void main (String[] args) {
|
public static void main (String[] args) {
|
||||||
SpringApplication.run(CoupletBusinessApplication.class, args);
|
SpringApplication.run(CoupletBusinessApplication.class, args);
|
||||||
|
|
|
@ -133,4 +133,19 @@ public class VehicleController extends BaseController {
|
||||||
|
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @Date: 2024/4/4 11:28
|
||||||
|
* @Description: 通过vin修改车辆上下线的状态
|
||||||
|
* @Param:
|
||||||
|
* @Return:
|
||||||
|
**/
|
||||||
|
@GetMapping("onOrOutLineByVIN")
|
||||||
|
public Integer onOrOutLineByVIN(@RequestParam("params") String params) {
|
||||||
|
String[] split = params.split(",");
|
||||||
|
|
||||||
|
|
||||||
|
return vehicleService.onOrOutLineByVIN(split[0], Integer.parseInt(split[1]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.couplet.common.domain.Vehicle;
|
import com.couplet.common.domain.Vehicle;
|
||||||
import com.couplet.common.domain.VehicleMiddle;
|
import com.couplet.common.domain.VehicleMiddle;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -24,4 +25,6 @@ public interface VehicleMapper extends BaseMapper<Vehicle> {
|
||||||
Integer addVehicle(VehicleMiddle vehicleMiddle);
|
Integer addVehicle(VehicleMiddle vehicleMiddle);
|
||||||
|
|
||||||
List<Vehicle> vehicleAll();
|
List<Vehicle> vehicleAll();
|
||||||
|
|
||||||
|
Integer onOrOutLineByVIN(@Param("vin") String vin, @Param("status") Integer status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,6 @@ public interface VehicleService extends IService<Vehicle> {
|
||||||
|
|
||||||
List<Vehicle> vehicleAll();
|
List<Vehicle> vehicleAll();
|
||||||
|
|
||||||
|
Integer onOrOutLineByVIN(String vin,Integer status);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public String deleteById(Long vehicleId) {
|
public String deleteById(Long vehicleId) {
|
||||||
String result = "";
|
String result;
|
||||||
|
|
||||||
UpdateWrapper<Vehicle> updateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<Vehicle> updateWrapper = new UpdateWrapper<>();
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public String editById(VehicleEditParams editParams) {
|
public String editById(VehicleEditParams editParams) {
|
||||||
String result = "";
|
String result;
|
||||||
|
|
||||||
if ((editParams.getLogoIds() == null || editParams.getLogoIds().isEmpty())) {
|
if ((editParams.getLogoIds() == null || editParams.getLogoIds().isEmpty())) {
|
||||||
result = "未选择电子围栏";
|
result = "未选择电子围栏";
|
||||||
|
@ -180,7 +180,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public String insert(VehicleInsertParams insertParams) {
|
public String insert(VehicleInsertParams insertParams) {
|
||||||
String result = "";
|
String result;
|
||||||
|
|
||||||
if ((insertParams.getLogoIds() == null || insertParams.getLogoIds().isEmpty())) {
|
if ((insertParams.getLogoIds() == null || insertParams.getLogoIds().isEmpty())) {
|
||||||
result = "未选择电子围栏";
|
result = "未选择电子围栏";
|
||||||
|
@ -249,9 +249,8 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public List<Long> getBindLogoById(Long vehicleId) {
|
public List<Long> getBindLogoById(Long vehicleId) {
|
||||||
List<Long> logoIds = vehicleAndLogoService.getBindLogoById(vehicleId);
|
|
||||||
|
|
||||||
return logoIds;
|
return vehicleAndLogoService.getBindLogoById(vehicleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -282,6 +281,14 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
return vehicleMapper.vehicleAll();
|
return vehicleMapper.vehicleAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//通过vin修改车辆上下线的状态
|
||||||
|
@Override
|
||||||
|
public Integer onOrOutLineByVIN(String vin, Integer status) {
|
||||||
|
|
||||||
|
return vehicleMapper.onOrOutLineByVIN(vin, status);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Vehicle> findByVIN(String vin) {
|
public List<Vehicle> findByVIN(String vin) {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.couplet.business.time;
|
||||||
|
|
||||||
|
import com.couplet.business.server.service.VehicleService;
|
||||||
|
import com.couplet.common.domain.Vehicle;
|
||||||
|
import com.couplet.common.domain.request.VehicleListParams;
|
||||||
|
import com.couplet.common.redis.service.RedisService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ProjectName: five-groups-couplet
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @CreateTime: 2024/4/4
|
||||||
|
* @Description: 车辆定时器
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class Timer {
|
||||||
|
//redis
|
||||||
|
@Autowired
|
||||||
|
private RedisService redis;
|
||||||
|
//查询车辆列表
|
||||||
|
@Autowired
|
||||||
|
private VehicleService vehicleService;
|
||||||
|
|
||||||
|
|
||||||
|
//判断车辆是否下线
|
||||||
|
@Scheduled(cron = "* * * * * *")
|
||||||
|
public void outLine() {
|
||||||
|
log.info("定时器启动");
|
||||||
|
|
||||||
|
//先查询车辆列表
|
||||||
|
List<Vehicle> list = vehicleService.list(new VehicleListParams(null, null, null, null));
|
||||||
|
|
||||||
|
list.forEach(vehicle -> {
|
||||||
|
|
||||||
|
//只针对已经上线的车辆
|
||||||
|
if (redis.hasKey(vehicle.getVin())) {
|
||||||
|
|
||||||
|
//如果vin的缓存 时间还剩一秒,则判断为已经下线
|
||||||
|
if (redis.getExpire(vehicle.getVin()) <= 3) {
|
||||||
|
log.info(vehicle.getVin() + "的车辆已经下线");
|
||||||
|
|
||||||
|
//执行修改下线状态的方法
|
||||||
|
Integer i = vehicleService.onOrOutLineByVIN(vehicle.getVin(), 0);
|
||||||
|
|
||||||
|
if (0 == 1) {
|
||||||
|
log.error("下线状态修改失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("下线状态修改成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,9 +16,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
|
namespace: 172469
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
|
namespace: 172469
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
|
|
||||||
<sql id="selectMiddleUserOrVehicle">
|
<sql id="selectMiddleUserOrVehicle">
|
||||||
SELECT
|
SELECT m.middle_id,
|
||||||
m.middle_id,
|
|
||||||
m.user_id,
|
m.user_id,
|
||||||
m.vehicle_id,
|
m.vehicle_id,
|
||||||
m.del_flag,
|
m.del_flag,
|
||||||
|
@ -19,15 +18,13 @@
|
||||||
v.vin,
|
v.vin,
|
||||||
v.vehicle_state,
|
v.vehicle_state,
|
||||||
t.vehicle_type_name
|
t.vehicle_type_name
|
||||||
FROM
|
FROM `couplet_middle` m
|
||||||
`couplet_middle` m
|
|
||||||
LEFT JOIN couplet_vehicle v ON m.vehicle_id = v.vehicle_id
|
LEFT JOIN couplet_vehicle v ON m.vehicle_id = v.vehicle_id
|
||||||
LEFT JOIN couplet_vehicle_type t ON v.vehicle_id = t.vehicle_type_id
|
LEFT JOIN couplet_vehicle_type t ON v.vehicle_id = t.vehicle_type_id
|
||||||
WHERE m.del_flag = 0
|
WHERE m.del_flag = 0
|
||||||
</sql>
|
</sql>
|
||||||
<sql id="selectVehicle">
|
<sql id="selectVehicle">
|
||||||
select
|
select v.vehicle_id,
|
||||||
v.vehicle_id,
|
|
||||||
v.motor_manufacturer,
|
v.motor_manufacturer,
|
||||||
v.battery_manufacturer,
|
v.battery_manufacturer,
|
||||||
v.motor_number,
|
v.motor_number,
|
||||||
|
@ -45,6 +42,15 @@
|
||||||
(#{userId}, #{vehicleId}, 0)
|
(#{userId}, #{vehicleId}, 0)
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
|
||||||
|
<update id="onOrOutLineByVIN">
|
||||||
|
UPDATE `couplet-cloud`.`couplet_vehicle`
|
||||||
|
SET `vehicle_state` = #{status}
|
||||||
|
WHERE `vin` = #{vin};
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
<delete id="deleteVehicle">
|
<delete id="deleteVehicle">
|
||||||
update couplet_middle
|
update couplet_middle
|
||||||
set del_flag = '2'
|
set del_flag = '2'
|
||||||
|
|
|
@ -102,6 +102,11 @@
|
||||||
<groupId>org.springframework.kafka</groupId>
|
<groupId>org.springframework.kafka</groupId>
|
||||||
<artifactId>spring-kafka</artifactId>
|
<artifactId>spring-kafka</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.apache.kafka</groupId>-->
|
||||||
|
<!-- <artifactId>kafka-clients</artifactId>-->
|
||||||
|
<!-- <version>2.0.0</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -19,6 +19,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
public class CoupletMqApplatcaion {
|
public class CoupletMqApplatcaion {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(CoupletMqApplatcaion.class, args);
|
SpringApplication.run(CoupletMqApplatcaion.class, args);
|
||||||
System.out.println("RabbitMQ模块启动成功");
|
System.out.println("MQ模块启动成功");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.couplet.mq.config;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||||
|
import org.apache.kafka.common.serialization.StringSerializer;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.kafka.annotation.EnableKafka;
|
||||||
|
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
|
||||||
|
import org.springframework.kafka.core.KafkaTemplate;
|
||||||
|
import org.springframework.kafka.core.ProducerFactory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ProjectName: five-groups-couplet
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @CreateTime: 2024/4/4
|
||||||
|
* @Description: kafka生产者配置类
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableKafka
|
||||||
|
public class KafkaProducerConfig {
|
||||||
|
@Value("${kafka.bootstrap-servers}")
|
||||||
|
private String bootstrapServers;
|
||||||
|
|
||||||
|
@Value("${kafka.producer.retries}")
|
||||||
|
private Integer retries;
|
||||||
|
|
||||||
|
@Value("${kafka.producer.batch-size}")
|
||||||
|
private Integer batchSize;
|
||||||
|
|
||||||
|
@Value("${kafka.producer.buffer-memory}")
|
||||||
|
private Integer bufferMemory;
|
||||||
|
|
||||||
|
@Value("${kafka.producer.linger}")
|
||||||
|
private Integer linger;
|
||||||
|
|
||||||
|
private Map<String, Object> producerConfigs() {
|
||||||
|
HashMap<String, Object> props = new HashMap<>(16);
|
||||||
|
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
||||||
|
props.put(ProducerConfig.RETRIES_CONFIG, retries);
|
||||||
|
props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
|
||||||
|
props.put(ProducerConfig.LINGER_MS_CONFIG, linger);
|
||||||
|
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
|
||||||
|
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
|
||||||
|
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
|
||||||
|
props.put("security.protocol", "SASL_PLAINTEXT");
|
||||||
|
props.put("sasl.mechanism", "SCRAM-SHA-512");
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProducerFactory<String, String> producerFactory() {
|
||||||
|
DefaultKafkaProducerFactory<String, String> producerFactory = new DefaultKafkaProducerFactory<>(producerConfigs());
|
||||||
|
|
||||||
|
return producerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public KafkaTemplate<String, String> KafkaTemplate() {
|
||||||
|
return new KafkaTemplate<>(producerFactory());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.couplet.mq.controller;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ProjectName: five-groups-couplet
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @CreateTime: 2024/4/4
|
||||||
|
* @Description: kafka
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/kafka")
|
||||||
|
public class KafkaController {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.couplet.mq.service;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
|
import org.springframework.kafka.annotation.KafkaListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ProjectName: five-groups-couplet
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @CreateTime: 2024/4/4
|
||||||
|
* @Description: kafka监听者1
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class KafkaConsumer {
|
||||||
|
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@RabbitListener(queues = "${mq.queueName}")
|
@RabbitListener(queues = "${mq.queueName}")
|
||||||
public class Consumer {
|
public class MqConsumer {
|
||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate redis;
|
private StringRedisTemplate redis;
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
com.couplet.mq.config.RabbitMQConfig
|
com.couplet.mq.config.RabbitMQConfig
|
||||||
|
com.couplet.mq.config.KafkaProducerConfig
|
||||||
|
|
|
@ -27,6 +27,30 @@ spring:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
|
#kafka配置信息
|
||||||
|
kafka:
|
||||||
|
bootstrap-servers: 39.103.133.136:9092
|
||||||
|
producer:
|
||||||
|
batch-size: 16384 #一次最多发送数据量 16K
|
||||||
|
retries: 3 #发送失败后的重复发送次数
|
||||||
|
buffer-memory: 33554432 #32M批处理缓冲区
|
||||||
|
linger: 5 #延迟发送时间ms,如果未达到batch-size,但是时间达到linger将发送消息
|
||||||
|
consumer:
|
||||||
|
auto-offset-reset: latest #新建消费组时从什么位置开始消费 latest:最近位置 earliest:最早位置
|
||||||
|
max-poll-records: 80 #批量消费一次最大拉取的数据量
|
||||||
|
enable-auto-commit: false #是否开启自动提交
|
||||||
|
auto-commit-interval: 1000 #自动提交的间隔时间,自动提交开启时生效
|
||||||
|
session-timeout: 20000 #连接超时时间
|
||||||
|
max-poll-interval: 15000 #手动提交设置与poll的心跳数,如果消息队列中没有消息,等待毫秒后,调用poll()方法。如果队列中有消息,立即消费消息,每次消费的消息的多少可以通过max.poll.records配置。
|
||||||
|
max-partition-fetch-bytes: 1048576 #设置拉取数据的大小,1M
|
||||||
|
group-id: test-group #消费组
|
||||||
|
listener:
|
||||||
|
batch-listener: true #是否开启批量消费,true表示批量消费
|
||||||
|
concurrencys: 5 #设置消费的线程数
|
||||||
|
poll-timeout: 1500 #只限自动提交
|
||||||
|
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.couplet.system.mapper: DEBUG
|
com.couplet.system.mapper: DEBUG
|
||||||
|
@ -47,3 +71,5 @@ mq:
|
||||||
queueName: queue
|
queueName: queue
|
||||||
exchangeName: exchange
|
exchangeName: exchange
|
||||||
routingKey: routingKey
|
routingKey: routingKey
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.couplet.common.security.annotation.EnableMyFeignClients;
|
||||||
import com.couplet.common.swagger.annotation.EnableCustomSwagger2;
|
import com.couplet.common.swagger.annotation.EnableCustomSwagger2;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ProjectName: Default (Template) Project
|
* @ProjectName: Default (Template) Project
|
||||||
|
@ -17,6 +18,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@EnableCustomSwagger2
|
@EnableCustomSwagger2
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableScheduling
|
||||||
//@EnableFeignClients
|
//@EnableFeignClients
|
||||||
public class CoupletOnlineApplication {
|
public class CoupletOnlineApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.couplet.online.utils;
|
package com.couplet.online.utils;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
|
||||||
import com.couplet.common.domain.Vehicle;
|
import com.couplet.common.domain.Vehicle;
|
||||||
import com.couplet.common.redis.service.RedisService;
|
import com.couplet.common.redis.service.RedisService;
|
||||||
import com.couplet.remote.RemoteVehicleService;
|
import com.couplet.remote.RemoteVehicleService;
|
||||||
|
@ -13,6 +12,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ProjectName: five-groups-couplet
|
* @ProjectName: five-groups-couplet
|
||||||
|
@ -132,32 +132,45 @@ public class MqttMonitor {
|
||||||
|
|
||||||
log.info("当前车辆的vin码为:" + start17);
|
log.info("当前车辆的vin码为:" + start17);
|
||||||
|
|
||||||
//判断缓存中是否有这个vin
|
// //判断缓存中是否有这个vin
|
||||||
if (redis.hasKey("不存在的车辆VIN:" + start17)) {
|
// if (redis.hasKey("不存在的车辆VIN" + start17)) {
|
||||||
|
//
|
||||||
|
// //可使用RabbitMQ发送消息
|
||||||
|
// log.error("vin码为" + start17 + "的车辆不属于本系统!");
|
||||||
|
//
|
||||||
|
// } else {//如果缓存中没有存这个vin
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
//可使用RabbitMQ发送消息
|
|
||||||
log.error("vin码为" + start17 + "的车辆不属于本系统!");
|
|
||||||
}
|
|
||||||
|
|
||||||
//调取接口,通过vin查询车辆
|
//调取接口,通过vin查询车辆
|
||||||
List<Vehicle> vehicles = remoteVehicleService.findByVIN(start17).getData();
|
List<Vehicle> vehicles = remoteVehicleService.findByVIN(start17).getData();
|
||||||
|
|
||||||
|
|
||||||
//如果不存在这个车
|
//如果不存在这个车
|
||||||
if (vehicles.isEmpty()) {
|
if (0 == vehicles.size()) {
|
||||||
//将不属于自己系统的车辆存入缓存,便于提前进行拒绝提示
|
//将不属于自己系统的车辆存入缓存,便于提前进行拒绝提示
|
||||||
redis.setCacheObject("不存在的车辆VIN:" + start17, start17);
|
// redis.setCacheObject("不存在的车辆VIN" + start17, start17);
|
||||||
log.error("未找到vin码为" + start17 + "的车辆信息");
|
log.error("未找到vin码为" + start17 + "的车辆信息");
|
||||||
} else {
|
} else {
|
||||||
//如果存在这个车
|
//如果存在这个车
|
||||||
Vehicle vehicle = vehicles.get(0);
|
Vehicle vehicle = vehicles.get(0);
|
||||||
System.out.println("***********" + vehicle + "***********");
|
log.info("远程调用查询到的车辆数据:" + vehicle);
|
||||||
//存入redis
|
|
||||||
redis.setCacheObject("存在的车辆VIN:" + start17, JSON.toJSONString(vehicle));
|
//上线车辆存入redis 6秒 用于判断车辆是否下线,还要写定时器,定时查询
|
||||||
|
redis.setCacheObject(start17, start17, 6L, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
|
||||||
log.info("vin码为" + start17 + "的车辆属于本系统,允许上线!");
|
log.info("vin码为" + start17 + "的车辆属于本系统,允许上线!");
|
||||||
|
|
||||||
|
//调用上线接口,修改上线状态
|
||||||
|
Integer i = remoteVehicleService.onOrOutLineByVIN(start17 + "," + 1);
|
||||||
|
//上线成功
|
||||||
|
if (0 != i) {
|
||||||
|
log.info("上线成功!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
76
pom.xml
76
pom.xml
|
@ -211,47 +211,47 @@
|
||||||
<artifactId>couplet-modules-system</artifactId>
|
<artifactId>couplet-modules-system</artifactId>
|
||||||
<version>${couplet.version}</version>
|
<version>${couplet.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.couplet</groupId>
|
<!-- <groupId>com.couplet</groupId>-->
|
||||||
<artifactId>couplet-trouble</artifactId>
|
<!-- <artifactId>couplet-trouble</artifactId>-->
|
||||||
<version>${couplet.version}</version>
|
<!-- <version>${couplet.version}</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.couplet</groupId>
|
<!-- <groupId>com.couplet</groupId>-->
|
||||||
<artifactId>couplet-electronic-fence-server</artifactId>
|
<!-- <artifactId>couplet-electronic-fence-server</artifactId>-->
|
||||||
<version>${couplet.version}</version>
|
<!-- <version>${couplet.version}</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.couplet</groupId>
|
<!-- <groupId>com.couplet</groupId>-->
|
||||||
<artifactId>couplet-electronic-fence-common</artifactId>
|
<!-- <artifactId>couplet-electronic-fence-common</artifactId>-->
|
||||||
<version>${couplet.version}</version>
|
<!-- <version>${couplet.version}</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.couplet</groupId>
|
<!-- <groupId>com.couplet</groupId>-->
|
||||||
<artifactId>couplet-electronic-fence-remote</artifactId>
|
<!-- <artifactId>couplet-electronic-fence-remote</artifactId>-->
|
||||||
<version>${couplet.version}</version>
|
<!-- <version>${couplet.version}</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<!-- 企业服务 模块 公共依赖 -->
|
<!-- <!– 企业服务 模块 公共依赖 –>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.couplet</groupId>
|
<!-- <groupId>com.couplet</groupId>-->
|
||||||
<artifactId>couplet-enterprisemanagement-common</artifactId>
|
<!-- <artifactId>couplet-enterprisemanagement-common</artifactId>-->
|
||||||
<version>${couplet.version}</version>
|
<!-- <version>${couplet.version}</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<!-- 企业服务 模块 远程调用依赖 -->
|
<!-- <!– 企业服务 模块 远程调用依赖 –>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.couplet</groupId>
|
<!-- <groupId>com.couplet</groupId>-->
|
||||||
<artifactId>couplet-enterprisemanagement-remote</artifactId>
|
<!-- <artifactId>couplet-enterprisemanagement-remote</artifactId>-->
|
||||||
<version>${couplet.version}</version>
|
<!-- <version>${couplet.version}</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<!-- 车辆管理模块 -->
|
<!-- <!– 车辆管理模块 –>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.couplet</groupId>
|
<!-- <groupId>com.couplet</groupId>-->
|
||||||
<artifactId>couplet-modules-vehicle</artifactId>
|
<!-- <artifactId>couplet-modules-vehicle</artifactId>-->
|
||||||
<version>${couplet.version}</version>
|
<!-- <version>${couplet.version}</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<!-- RabbitMq模块 -->
|
<!-- RabbitMq模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
Loading…
Reference in New Issue