Commit 4f6cc1ca by 胡懿

增加第二个kafka消息监听,重新导入设备信息和设备类型信息,修改设备上床接口逻辑,修改设备规则验证逻辑,修改iotdb存储时的字段

parent 3fdf2083
......@@ -83,7 +83,16 @@
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.4</version>
</dependency>
</dependencies>
<properties>
......
......@@ -31,4 +31,5 @@ public class ErrorInfo {
public static ErrorCode PT_DEPT_INFO_NOT_EXISTS = new ErrorCode(23, "平台部门不存在");
public static ErrorCode PT_USER_INFO_NOT_EXISTS = new ErrorCode(24, "平台用户不存在");
public static ErrorCode DEVICE_TYPE_NOT_EXISTS = new ErrorCode(25, "设备类型不存在");
}
......@@ -22,7 +22,11 @@ public class KafkaConsumer {
@Autowired
private DeviceConnetRuleInfoService deviceConnetRuleInfoService;
@KafkaListener(topics = "weblog.save", groupId = "weblog_consumer_group")
@KafkaListener(
topics = "weblog.save",
containerFactory = "kafkaListenerContainerFactory1",
groupId = "weblog_consumer_group"
)
public void consume(String message){
WebLogInfo webLogInfo = JSON.parseObject(JSON.parse(message).toString(), WebLogInfo.class);
if (webLogInfo.getReqType().contains("req")) {
......@@ -32,7 +36,7 @@ public class KafkaConsumer {
DeviceLogInfo deviceLogInfo = new DeviceLogInfo();
deviceLogInfo.setUserId(webLogInfo.getUserId());
deviceLogInfo.setUsername(webLogInfo.getUsername());
deviceLogInfo.setDeviceId(webLogInfo.getDeviceTypeId());
deviceLogInfo.setDeviceTypeBs(webLogInfo.getDeviceTypeBs());
deviceLogInfo.setDeviceName(webLogInfo.getDeviceTypeName());
deviceLogInfo.setAccessed(webLogInfo.getAccessed());
deviceLogInfo.setType(webLogInfo.getType());
......@@ -49,7 +53,11 @@ public class KafkaConsumer {
}
@KafkaListener(topics = "devicelog.save", groupId = "weblog_consumer_group")
@KafkaListener(
topics = "devicelog.save",
containerFactory = "kafkaListenerContainerFactory1",
groupId = "weblog_consumer_group"
)
public void consume2(String message){
DeviceLogInfo deviceLogInfo = JSON.parseObject(JSON.parse(message).toString(), DeviceLogInfo.class);
MyIotDbUtils.inserOneDeviceLogInfo(iotDbConfig, deviceLogInfo);
......
package cn.gintone.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
@Service
public class KafkaProducer {
private final KafkaTemplate<String, String> kafkaTemplate;
private static final String TOPIC = "weblog.save"; // 与消费者中配置的topic一致
private static final String GROUP_ID = "weblog_consumer_group"; // 与消费者中配置的group一致,但不是必须的,除非你需要用它来做额外的配置或验证。通常在@KafkaListener中指定。
private final KafkaTemplate<String, String> kafkaTemplate1;
private final KafkaTemplate<String, String> kafkaTemplate2;
@Autowired // 自动注入KafkaTemplate实例。默认的泛型参数是Key和Value的类型。这里都是String类型。根据需要可以更改。
public KafkaProducer(KafkaTemplate<String, String> kafkaTemplate) {
this.kafkaTemplate = kafkaTemplate;
private static final String TOPIC_WEBLOG = "weblog.save";
private static final String TOPIC_DEVICELOG = "devicelog.save";
@Autowired
public KafkaProducer(
@Qualifier("kafkaTemplate1") KafkaTemplate<String, String> kafkaTemplate1,
@Qualifier("kafkaTemplate2") KafkaTemplate<String, String> kafkaTemplate2) {
this.kafkaTemplate1 = kafkaTemplate1;
this.kafkaTemplate2 = kafkaTemplate2;
}
// 发送到第一个Kafka集群
public void sendWebLogMessage(String message) {
kafkaTemplate1.send(TOPIC_WEBLOG, message);
}
public void sendDeviceLogMessage(String message) {
kafkaTemplate1.send(TOPIC_DEVICELOG, message);
}
public void sendMessage(String message) {
kafkaTemplate.send(TOPIC, message); // 发送消息到指定的topic。这里用的是默认分区器,可以根据需要传递key来指定分区。例如:kafkaTemplate.send(TOPIC, "key", message);。 默认分区器会根据key的哈希值来决定分区。如果不需要key,则可以省略它。 例如:kafkaTemplate.send(TOPIC, null, message); 或者直接使用上面的方法。 需要注意的是,如果使用了key,那么最好在整个系统中保持key的一致性,以便于消息的顺序处理和分区策略的正确执行。如果不确定key的使用场景,可以先省略它,之后再根据需要添加。例如: kafkaTemplate.send(TOPIC, message); 这样发送的消息会被均匀地分配到各个分区上,而没有特定的顺序保证。这对于大多数场景来说是足够的,特别是当不需要保证消息顺序时。如果要保证消息的顺序,可以考虑使用同一个key发送消息到同一个分区。例如: kafkaTemplate.send(TOPIC, "someKey", message); 这样发送的消息都会被分配到同一个分区上,保证了消息的顺序。但是要注意,这可能会影响消息的并行处理能力
// 发送到第二个Kafka集群(如果需要)
public void sendToCluster2(String topic, String message) {
kafkaTemplate2.send(topic, message);
}
}
\ No newline at end of file
package cn.gintone.config;
import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.config.SaslConfigs;
import org.apache.kafka.common.serialization.StringDeserializer;
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.context.annotation.Primary;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.core.*;
import org.springframework.kafka.listener.ContainerProperties;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class MultiKafkaConfig {
// Cluster1 配置
@Value("${kafka.cluster1.bootstrap-servers}")
private String cluster1BootstrapServers;
@Value("${kafka.cluster1.consumer.group-id}")
private String cluster1GroupId;
// Cluster2 配置
@Value("${kafka.cluster2.bootstrap-servers}")
private String cluster2BootstrapServers;
@Value("${kafka.cluster2.consumer.group-id}")
private String cluster2GroupId;
@Value("${kafka.cluster2.properties.security.protocol}")
private String securityProtocol;
// @Value("${kafka.cluster2.properties.sasl.mechanism}")
// private String saslMechanism;
// @Value("${kafka.cluster2.properties.sasl.jaas.config}")
// private String saslJaasConfig;
// Cluster1 生产者配置
@Bean
@Primary
public ProducerFactory<String, String> cluster1ProducerFactory() {
Map<String, Object> props = new HashMap<>();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, cluster1BootstrapServers);
props.put(ProducerConfig.RETRIES_CONFIG, 3);
props.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, 60000);
props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 60000);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return new DefaultKafkaProducerFactory<>(props);
}
// Cluster1 消费者配置
@Bean
@Primary
public ConsumerFactory<String, String> cluster1ConsumerFactory() {
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, cluster1BootstrapServers);
props.put(ConsumerConfig.GROUP_ID_CONFIG, cluster1GroupId);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, 300000);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
return new DefaultKafkaConsumerFactory<>(props);
}
// Cluster2 生产者配置
@Bean
public ProducerFactory<String, String> cluster2ProducerFactory() {
Map<String, Object> props = new HashMap<>();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, cluster2BootstrapServers);
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol);
// props.put(SaslConfigs.SASL_MECHANISM, saslMechanism);
// props.put(SaslConfigs.SASL_JAAS_CONFIG, saslJaasConfig);
props.put(ProducerConfig.RETRIES_CONFIG, 3);
props.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, 60000);
props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 60000);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return new DefaultKafkaProducerFactory<>(props);
}
// Cluster2 消费者配置
@Bean
public ConsumerFactory<String, String> cluster2ConsumerFactory() {
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, cluster2BootstrapServers);
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol);
// props.put(SaslConfigs.SASL_MECHANISM, saslMechanism);
// props.put(SaslConfigs.SASL_JAAS_CONFIG, saslJaasConfig);
props.put(ConsumerConfig.GROUP_ID_CONFIG, cluster2GroupId);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, 300000);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
return new DefaultKafkaConsumerFactory<>(props);
}
// Cluster1 KafkaTemplate
@Bean
@Primary
public KafkaTemplate<String, String> kafkaTemplate1() {
return new KafkaTemplate<>(cluster1ProducerFactory());
}
// Cluster2 KafkaTemplate
@Bean(name = "kafkaTemplate2")
public KafkaTemplate<String, String> kafkaTemplate2() {
return new KafkaTemplate<>(cluster2ProducerFactory());
}
// Cluster1 监听容器工厂
@Bean
@Primary
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory1() {
ConcurrentKafkaListenerContainerFactory<String, String> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(cluster1ConsumerFactory());
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
return factory;
}
// Cluster2 监听容器工厂
@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory2() {
ConcurrentKafkaListenerContainerFactory<String, String> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(cluster2ConsumerFactory());
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
factory.setConcurrency(3);
return factory;
}
}
\ No newline at end of file
package cn.gintone.config;
import cn.gintone.controller.vo.DeviceReqConfListReqVO;
import cn.gintone.controller.vo.DeviceReqConfSaveReqVO;
import cn.gintone.dal.DeviceReqConfMapper;
import cn.gintone.entity.DeviceReqConfDO;
import cn.gintone.service.DeviceReqConfService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Component
public class PumpStationKafkaConsumer {
@Autowired
private DeviceReqConfMapper deviceReqConfMapper;
private static final Logger logger = LoggerFactory.getLogger(PumpStationKafkaConsumer.class);
/**
* 主消费者 - 处理大部分topic
*/
/*@KafkaListener(
topics = {
"MKLDYL_JCSJ", "BZYYZ_JCSJ", "BZPSQ_JCSJ", "BZXZY_JCSJ",
"BZZLB_JCSJ", "BZYZJ_JCSJ", "BZJSZM_JCSJ", "BZYLZM_JCSJ", "BZCSZM_JCSJ",
"BZSCZM_JCSJ", "BZTXZM_JCSJ", "BZTFFJ_JCSJ", "BZSFFJ_JCSJ", "BZPFFJ_JCSJ",
"BZFJ_JCSJ", "BZFSJ_JCSJ", "BZYWCJ_JCSJ_2", "BZQBJ_JCSJ", "BZYDYHQT_JCSJ",
"BZZF_JCSJ", "BZQSB_JCSJ", "BZGSJ_JCSJ", "BZPDJ_JCSJ", "BZLDYWJ_JCSJ",
"BZYWCJ_JCSJ", "BZYWJ_JCSJ", "BZBSF_JCSJ", "BZFF_JCSJ", "BZDF_JCSJ",
"TYJG_JCSJ", "BZSB_JCSJ", "TYYLD_JCSJ", "TYYSGW_JCSJ", "YSGWLLJ_JCSJ",
"YSGWSWJ_JCSJ"
},
containerFactory = "kafkaListenerContainerFactory2",
groupId = "pump_station_main_group" // 改为不同的组
)
public void consumePumpStationData(String message,
@Header(KafkaHeaders.RECEIVED_TOPIC) String topic,
Acknowledgment ack) {
try {
logger.info("主消费者收到泵站数据, topic: {}, 消息长度: {}", topic, message);
// 立即提交偏移量,避免阻塞
ack.acknowledge();
// 异步处理业务逻辑
processMessageAsync(message, topic);
} catch (Exception e) {
logger.error("处理泵站数据时发生错误, topic: {}, 错误: {}", topic, e.getMessage(), e);
}
}*/
/**
* BZHSZM_JCSJ专用消费者
*/
/*@KafkaListener(
topics = {"BZHSZM_JCSJ"},
containerFactory = "kafkaListenerContainerFactory2",
groupId = "pump_station_bzhszm_group" // 专用组
)
public void consumePumpStationData_BZHSZM_JCSJ(String message,
@Header(KafkaHeaders.RECEIVED_TOPIC) String topic,
Acknowledgment ack) {
logger.info("BZHSZM_JCSJ专用消费者收到数据, topic: {}, 消息长度: {}", topic, message);
ack.acknowledge();
processMessageAsync(message, topic);
}*/
/**
* BZPSZM_JCSJ专用消费者
*/
/*@KafkaListener(
topics = {"BZPSZM_JCSJ"},
containerFactory = "kafkaListenerContainerFactory2",
groupId = "pump_station_bzpszm_group" // 专用组
)
public void consumePumpStationData_BZPSZM_JCSJ(String message,
@Header(KafkaHeaders.RECEIVED_TOPIC) String topic,
Acknowledgment ack) {
logger.info("BZPSZM_JCSJ专用消费者收到数据, topic: {}, 消息长度: {}", topic, message);
ack.acknowledge();
processMessageAsync(message, topic);
}*/
/**
* 异步处理消息,避免阻塞消费者
*/
private void processMessageAsync(String message, String topic) {
CompletableFuture.runAsync(() -> {
try {
JSONObject msgJsonObject = JSON.parseObject(message);
String snCode = msgJsonObject.get("serialNo").toString();
DeviceReqConfListReqVO temDRCLRV = new DeviceReqConfListReqVO();
temDRCLRV.setSnCode(snCode);
List<DeviceReqConfDO> deviceReqConfList = deviceReqConfMapper.selectList(temDRCLRV);
if (null != deviceReqConfList && deviceReqConfList.size() > 0) {
for (DeviceReqConfDO drcd : deviceReqConfList) {
DeviceReqConfDO deviceReqConfSaveReqVO = new DeviceReqConfDO();
deviceReqConfSaveReqVO.setId(drcd.getId());
deviceReqConfSaveReqVO.setState(1);
deviceReqConfSaveReqVO.setSycnDate(new Date());
deviceReqConfMapper.update(new UpdateWrapper<DeviceReqConfDO>().lambda()
.eq(DeviceReqConfDO::getId, deviceReqConfSaveReqVO.getId())
.set(DeviceReqConfDO::getState, 1)
.set(DeviceReqConfDO::getSycnDate, deviceReqConfSaveReqVO.getSycnDate())
);
}
logger.info("异步处理完成, topic: {}, SN: {}", topic, snCode);
}
} catch (Exception e) {
logger.error("异步处理消息失败, topic: {}, 错误: {}", topic, e.getMessage(), e);
}
});
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.annotation.security.PermitAll;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
......@@ -95,9 +96,12 @@ public class DeviceReqConfController {
}
@PermitAll
@GetMapping("/syncPtUser")
@Operation(summary = "同步平台设备信息")
public CommonResult<String> syncPtDevice() {
return success(deviceReqConfService.syncPtDevice());
deviceReqConfService.exportPtDeviceType(); // 同步设备类型
deviceReqConfService.exportPtDevice(); // 同步设备
return success("同步成功");
}
}
\ No newline at end of file
package cn.gintone.controller;
import cn.gintone.controller.vo.DeviceTypePageReqVO;
import cn.gintone.controller.vo.DeviceTypeRespVO;
import cn.gintone.controller.vo.DeviceTypeSaveReqVO;
import cn.gintone.entity.DeviceTypeDO;
import cn.gintone.service.DeviceTypeService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 设备类型")
@RestController
@RequestMapping("/gintone/device-type")
@Validated
public class DeviceTypeController {
@Resource
private DeviceTypeService deviceTypeService;
@PostMapping("/create")
@Operation(summary = "创建设备类型")
@PreAuthorize("@ss.hasPermission('gintone:device-type:create')")
public CommonResult<Long> createDeviceType(@Valid @RequestBody DeviceTypeSaveReqVO createReqVO) {
return success(deviceTypeService.createDeviceType(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新设备类型")
@PreAuthorize("@ss.hasPermission('gintone:device-type:update')")
public CommonResult<Boolean> updateDeviceType(@Valid @RequestBody DeviceTypeSaveReqVO updateReqVO) {
deviceTypeService.updateDeviceType(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除设备类型")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('gintone:device-type:delete')")
public CommonResult<Boolean> deleteDeviceType(@RequestParam("id") Long id) {
deviceTypeService.deleteDeviceType(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得设备类型")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('gintone:device-type:query')")
public CommonResult<DeviceTypeRespVO> getDeviceType(@RequestParam("id") Long id) {
DeviceTypeDO deviceType = deviceTypeService.getDeviceType(id);
return success(BeanUtils.toBean(deviceType, DeviceTypeRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得设备类型分页")
@PreAuthorize("@ss.hasPermission('gintone:device-type:query')")
public CommonResult<PageResult<DeviceTypeRespVO>> getDeviceTypePage(@Valid DeviceTypePageReqVO pageReqVO) {
PageResult<DeviceTypeDO> pageResult = deviceTypeService.getDeviceTypePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, DeviceTypeRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出设备类型 Excel")
@PreAuthorize("@ss.hasPermission('gintone:device-type:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDeviceTypeExcel(@Valid DeviceTypePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<DeviceTypeDO> list = deviceTypeService.getDeviceTypePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "设备类型.xls", "数据", DeviceTypeRespVO.class,
BeanUtils.toBean(list, DeviceTypeRespVO.class));
}
}
\ No newline at end of file
......@@ -7,9 +7,11 @@ import cn.gintone.dto.WebLogInfoVo;
import cn.gintone.iotdbUtils.*;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;
......@@ -23,8 +25,14 @@ import java.util.List;
@RequestMapping("/admin-api/gintone/webLogInfo")
public class WebLogInfoController {
@Resource
private KafkaTemplate<String,String> kafkaTemplate;
@Autowired
@Qualifier("kafkaTemplate1")
private KafkaTemplate<String,String> kafkaTemplate1;
@Autowired
@Qualifier("kafkaTemplate2")
private KafkaTemplate<String,String> kafkaTemplate2;
@Autowired
private IotDbConfig iotDbConfig;
......@@ -57,6 +65,17 @@ public class WebLogInfoController {
@PermitAll
@PostMapping("/testKafkaTemplateTwo")
@Operation(summary = "测试第二个kafka消息")
public CommonResult<String> testKafkaTemplateTwo() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("serialNo", "14010000002001000300");
kafkaTemplate2.send("BZHSZM_JCSJ",jsonObject.toJSONString());
return CommonResult.success("保存成功");
}
@PermitAll
@PostMapping("/saveWebLogInfo")
@Operation(summary = "外部性请求保存日志")
public CommonResult<String> saveWebLogInfo(@RequestBody WebLogInfo webLogInfo) {
......@@ -65,7 +84,7 @@ public class WebLogInfoController {
}
String webLogInfoStr = JSON.toJSONString(webLogInfo);
// rabbitTemplate.convertAndSend("my_boot_topic_exchange", "weblog.save", webLogInfoStr);
kafkaTemplate.send("weblog.save",webLogInfoStr);
kafkaTemplate1.send("weblog.save",webLogInfoStr);
return CommonResult.success("保存成功");
}
......
......@@ -42,4 +42,8 @@ public class DeviceConnetRuleInfoPageReqVO extends PageParam {
private String deviceSn; // 设备sn
private String deviceTypeBs; // 设备类型标识
private String deviceTypeName; // 设备类型名称
private Long deviceTypeId; // 设备类型id
}
\ No newline at end of file
......@@ -48,4 +48,8 @@ public class DeviceConnetRuleInfoRespVO {
@ExcelProperty("创建时间")
private LocalDateTime createTime;
private String deviceSn; // 设备sn
private String deviceTypeBs; // 设备类型标识
private String deviceTypeName; // 设备类型名称
private Long deviceTypeId; // 设备类型id
}
\ No newline at end of file
......@@ -34,4 +34,8 @@ public class DeviceConnetRuleInfoSaveReqVO {
@Schema(description = "用户名称", example = "芋艿")
private String userName;
private String deviceSn; // 设备sn
private String deviceTypeBs; // 设备类型标识
private String deviceTypeName; // 设备类型名称
private Long deviceTypeId; // 设备类型id
}
\ No newline at end of file
......@@ -20,7 +20,7 @@ public class DeviceReqConfListReqVO {
private String deviceId;
@Schema(description = "设备类型id", example = "24373")
private String deviceTypeId;
private Long deviceTypeId;
@Schema(description = "父级id", example = "31343")
private Long parentId;
......@@ -35,4 +35,6 @@ public class DeviceReqConfListReqVO {
private String deviceEn; // 设备英文
private String regionName; // 区域名称
private String deviceTypeName;
private Integer state; // 设备状态
private Date sycnDate; // 设备状态监测时间
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ public class DeviceReqConfRespVO {
@Schema(description = "设备类型id", example = "24373")
@ExcelProperty("设备类型id")
private String deviceTypeId;
private Long deviceTypeId;
@Schema(description = "父级id", example = "31343")
@ExcelProperty("父级id")
......@@ -41,4 +41,6 @@ public class DeviceReqConfRespVO {
private String deviceEn; // 设备英文
private String regionName; // 区域名称
private String deviceTypeName;
private Integer state; // 设备状态
private Date sycnDate; // 设备状态监测时间
}
\ No newline at end of file
......@@ -20,7 +20,7 @@ public class DeviceReqConfSaveReqVO {
private String deviceId;
@Schema(description = "设备类型id", example = "24373")
private String deviceTypeId;
private Long deviceTypeId;
@Schema(description = "父级id", example = "31343")
private Long parentId;
......@@ -30,4 +30,6 @@ public class DeviceReqConfSaveReqVO {
private String deviceEn; // 设备英文
private String regionName; // 区域名称
private String deviceTypeName;
private Integer state; // 设备状态
private Date sycnDate; // 设备状态监测时间
}
\ No newline at end of file
package cn.gintone.controller.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 设备类型分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class DeviceTypePageReqVO extends PageParam {
@Schema(description = "设备类型名称", example = "赵六")
private String name;
@Schema(description = "设备类型标识")
private String modelCode;
@Schema(description = "厂家设备类型标识")
private String manufacturer;
@Schema(description = "所属集成应用")
private String integratedApplicationOwnership;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 设备类型 Response VO")
@Data
@ExcelIgnoreUnannotated
public class DeviceTypeRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "3316")
@ExcelProperty("id")
private Long id;
@Schema(description = "设备类型名称", example = "赵六")
@ExcelProperty("设备类型名称")
private String name;
@Schema(description = "设备类型标识")
@ExcelProperty("设备类型标识")
private String modelCode;
@Schema(description = "厂家设备类型标识")
@ExcelProperty("厂家设备类型标识")
private String manufacturer;
@Schema(description = "所属集成应用")
@ExcelProperty("所属集成应用")
private String integratedApplicationOwnership;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 设备类型新增/修改 Request VO")
@Data
public class DeviceTypeSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "3316")
private Long id;
@Schema(description = "设备类型名称", example = "赵六")
private String name;
@Schema(description = "设备类型标识")
private String modelCode;
@Schema(description = "厂家设备类型标识")
private String manufacturer;
@Schema(description = "所属集成应用")
private String integratedApplicationOwnership;
}
\ No newline at end of file
package cn.gintone.dal;
import java.util.*;
import cn.gintone.controller.vo.DeviceTypePageReqVO;
import cn.gintone.entity.DeviceTypeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
/**
* 设备类型 Mapper
*
* @author 安全系统管理
*/
@Mapper
public interface DeviceTypeMapper extends BaseMapperX<DeviceTypeDO> {
default PageResult<DeviceTypeDO> selectPage(DeviceTypePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DeviceTypeDO>()
.likeIfPresent(DeviceTypeDO::getName, reqVO.getName())
.eqIfPresent(DeviceTypeDO::getModelCode, reqVO.getModelCode())
.eqIfPresent(DeviceTypeDO::getManufacturer, reqVO.getManufacturer())
.eqIfPresent(DeviceTypeDO::getIntegratedApplicationOwnership, reqVO.getIntegratedApplicationOwnership())
.betweenIfPresent(DeviceTypeDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DeviceTypeDO::getId));
}
}
\ No newline at end of file
......@@ -10,10 +10,11 @@ public class DeviceIllLogInfo {
private String deviceId; // 设备id
private String deviceName; // 设备名称
private String deviceTypeId; // 设备类型id
private String deviceTypeBs; // 设备类型标识
private String deviceTypeName; // 设备类型名称
private String deviceSn; // 设备类型名称
private String accessed; // 访问时间
private String illType; // 日志类型()
private String illType; // 日志类型() noRule:无规则,disconnected:掉线
private String clientIp; // 访问端ip
private String remark; // 备注
......@@ -174,6 +175,14 @@ public class DeviceIllLogInfo {
this.deviceSn = deviceSn;
}
public String getDeviceTypeBs() {
return deviceTypeBs;
}
public void setDeviceTypeBs(String deviceTypeBs) {
this.deviceTypeBs = deviceTypeBs;
}
@Override
public String toString() {
return "DeviceIllLogInfo{" +
......@@ -186,6 +195,7 @@ public class DeviceIllLogInfo {
", deviceId='" + deviceId + '\'' +
", deviceName='" + deviceName + '\'' +
", deviceTypeId='" + deviceTypeId + '\'' +
", deviceTypeBs='" + deviceTypeBs + '\'' +
", deviceTypeName='" + deviceTypeName + '\'' +
", deviceSn='" + deviceSn + '\'' +
", accessed='" + accessed + '\'' +
......
......@@ -9,7 +9,7 @@ public class DeviceLogInfo {
private String username; // 用户名
private String deviceId; // 设备id
private String deviceName; // 设备名称
private String deviceTypeId; // 设备类型id
private String deviceTypeBs; // 设备类型id
private String deviceTypeName; // 设备类型名称
private String deviceSn; // 设备sn
private String accessed; // 访问时间
......@@ -88,12 +88,12 @@ public class DeviceLogInfo {
this.deviceName = deviceName;
}
public String getDeviceTypeId() {
return deviceTypeId;
public String getDeviceTypeBs() {
return deviceTypeBs;
}
public void setDeviceTypeId(String deviceTypeId) {
this.deviceTypeId = deviceTypeId;
public void setDeviceTypeBs(String deviceTypeBs) {
this.deviceTypeBs = deviceTypeBs;
}
public String getDeviceTypeName() {
......@@ -187,7 +187,7 @@ public class DeviceLogInfo {
", username='" + username + '\'' +
", deviceId='" + deviceId + '\'' +
", deviceName='" + deviceName + '\'' +
", deviceTypeId='" + deviceTypeId + '\'' +
", deviceTypeBs='" + deviceTypeBs + '\'' +
", deviceTypeName='" + deviceTypeName + '\'' +
", deviceSn='" + deviceSn + '\'' +
", accessed='" + accessed + '\'' +
......
package cn.gintone.dto;
public class PtExportDevice {
private String deviceSerialNo; //sn 112100021512
private String deviceName; // 设备名称
private String modelCode; // 设备标识
private String description; // 位置 万柏林区滨河西路辅路23号山西自然博物馆
private String label;
private String deviceSec; // NOJDPYO3XN8N47PR
private String classification;
// 构造函数
public PtExportDevice() {}
public PtExportDevice(String deviceSerialNo, String deviceName, String modelCode,
String description, String label, String deviceSec, String classification) {
this.deviceSerialNo = deviceSerialNo;
this.deviceName = deviceName;
this.modelCode = modelCode;
this.description = description;
this.label = label;
this.deviceSec = deviceSec;
this.classification = classification;
}
// Getter 和 Setter 方法
public String getDeviceSerialNo() {
return deviceSerialNo;
}
public void setDeviceSerialNo(String deviceSerialNo) {
this.deviceSerialNo = deviceSerialNo;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public String getModelCode() {
return modelCode;
}
public void setModelCode(String modelCode) {
this.modelCode = modelCode;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getDeviceSec() {
return deviceSec;
}
public void setDeviceSec(String deviceSec) {
this.deviceSec = deviceSec;
}
public String getClassification() {
return classification;
}
public void setClassification(String classification) {
this.classification = classification;
}
@Override
public String toString() {
return "PtExportDevice{" +
"deviceSerialNo='" + deviceSerialNo + '\'' +
", deviceName='" + deviceName + '\'' +
", modelCode='" + modelCode + '\'' +
", description='" + description + '\'' +
", label='" + label + '\'' +
", deviceSec='" + deviceSec + '\'' +
", classification='" + classification + '\'' +
'}';
}
}
package cn.gintone.dto;
// 导入的设备类型表
public class PtExportDeviceType {
private String name; // 类型名称
private String modelCode; // 标识
private String manufacturer; // 厂家
private String integratedApplicationOwnership; // 所属集成应用
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getModelCode() {
return modelCode;
}
public void setModelCode(String modelCode) {
this.modelCode = modelCode;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getIntegratedApplicationOwnership() {
return integratedApplicationOwnership;
}
public void setIntegratedApplicationOwnership(String integratedApplicationOwnership) {
this.integratedApplicationOwnership = integratedApplicationOwnership;
}
@Override
public String toString() {
return "PtExportDeviceType{" +
"name='" + name + '\'' +
", modelCode='" + modelCode + '\'' +
", manufacturer='" + manufacturer + '\'' +
", integratedApplicationOwnership='" + integratedApplicationOwnership + '\'' +
'}';
}
}
......@@ -13,7 +13,7 @@ public class WebLogInfo {
private String remark; // 备注
private String reqType; // 访问链接类型 dev:设备数据,req:系统访问
private String deviceTypeName; // 设备类型名称
private String deviceTypeId; // 设备类型ID
private String deviceTypeBs; // 设备类型标识
public Long getTimesta() {
return timesta;
......@@ -111,12 +111,12 @@ public class WebLogInfo {
this.deviceTypeName = deviceTypeName;
}
public String getDeviceTypeId() {
return deviceTypeId;
public String getDeviceTypeBs() {
return deviceTypeBs;
}
public void setDeviceTypeId(String deviceTypeId) {
this.deviceTypeId = deviceTypeId;
public void setDeviceTypeBs(String deviceTypeBs) {
this.deviceTypeBs = deviceTypeBs;
}
@Override
......@@ -134,7 +134,7 @@ public class WebLogInfo {
", remark='" + remark + '\'' +
", reqType='" + reqType + '\'' +
", deviceTypeName='" + deviceTypeName + '\'' +
", deviceTypeId='" + deviceTypeId + '\'' +
", deviceTypeBs='" + deviceTypeBs + '\'' +
'}';
}
}
......@@ -58,4 +58,8 @@ public class DeviceConnetRuleInfoDO extends BaseDO {
private String deviceSn; // 设备sn
private String deviceTypeBs; // 设备类型标识
private String deviceTypeName; // 设备类型名称
private Long deviceTypeId; // 设备类型id
}
\ No newline at end of file
......@@ -40,7 +40,7 @@ public class DeviceReqConfDO extends BaseDO {
/**
* 设备类型id
*/
private String deviceTypeId;
private Long deviceTypeId;
private String deviceTypeName;
/**
......@@ -51,5 +51,7 @@ public class DeviceReqConfDO extends BaseDO {
private String snCode; // sn
private String address; // 地址
private String deviceEn; // 设备英文
private String regionName; // 区域名称
private String regionName; // Device Sec
private Integer state; // 设备状态
private Date sycnDate; // 设备状态监测时间
}
\ No newline at end of file
package cn.gintone.entity;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 设备类型 DO
*
* @author 安全系统管理
*/
@TableName("t_device_type")
@KeySequence("t_device_type_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DeviceTypeDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* 设备类型名称
*/
private String name;
/**
* 设备类型标识
*/
private String modelCode;
/**
* 厂家设备类型标识
*/
private String manufacturer;
/**
* 所属集成应用
*/
private String integratedApplicationOwnership;
}
\ No newline at end of file
......@@ -605,7 +605,7 @@ public class MyIotDbUtils {
sessionPool.createTimeseries("root.myDeviceLogInfo.tableOne.username", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableOne.deviceId", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableOne.deviceName", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableOne.deviceTypeId", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableOne.deviceTypeBs", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableOne.deviceTypeName", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableOne.deviceSn", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableOne.accessed", TSDataType.TIMESTAMP, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
......@@ -640,6 +640,7 @@ public class MyIotDbUtils {
sessionPool.createTimeseries("root.myDeviceLogInfo.tableTwo.deviceId", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableTwo.deviceName", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableTwo.deviceTypeId", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableTwo.deviceTypeBs", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableTwo.deviceTypeName", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableTwo.deviceSn", TSDataType.TEXT, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
sessionPool.createTimeseries("root.myDeviceLogInfo.tableTwo.accessed", TSDataType.TIMESTAMP, TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
......@@ -695,7 +696,7 @@ public class MyIotDbUtils {
list5.add("username");
list5.add("deviceId");
list5.add("deviceName");
list5.add("deviceTypeId");
list5.add("deviceTypeBs");
list5.add("deviceTypeName");
list5.add("deviceSn");
list5.add("accessed");
......@@ -725,7 +726,7 @@ public class MyIotDbUtils {
values.add(deviceLogInfo.getUsername());
values.add(deviceLogInfo.getDeviceId());
values.add(deviceLogInfo.getDeviceName());
values.add(deviceLogInfo.getDeviceTypeId());
values.add(deviceLogInfo.getDeviceTypeBs());
values.add(deviceLogInfo.getDeviceTypeName());
values.add(deviceLogInfo.getDeviceSn());
values.add(MyDateUtils.stringToLong(deviceLogInfo.getAccessed()));
......@@ -782,6 +783,7 @@ public class MyIotDbUtils {
list5.add("deviceId");
list5.add("deviceName");
list5.add("deviceTypeId");
list5.add("deviceTypeBs");
list5.add("deviceTypeName");
list5.add("deviceSn");
list5.add("accessed");
......@@ -799,6 +801,7 @@ public class MyIotDbUtils {
list6.add(TSDataType.TEXT);
list6.add(TSDataType.TEXT);
list6.add(TSDataType.TEXT);
list6.add(TSDataType.TEXT);
list6.add(TSDataType.TIMESTAMP);
list6.add(TSDataType.TEXT);
list6.add(TSDataType.TEXT);
......@@ -812,6 +815,7 @@ public class MyIotDbUtils {
values.add(deviceIllLogInfo.getDeviceId());
values.add(deviceIllLogInfo.getDeviceName());
values.add(deviceIllLogInfo.getDeviceTypeId());
values.add(deviceIllLogInfo.getDeviceTypeBs());
values.add(deviceIllLogInfo.getDeviceTypeName());
values.add(deviceIllLogInfo.getDeviceSn());
values.add(MyDateUtils.stringToLong(deviceIllLogInfo.getAccessed()));
......@@ -909,7 +913,7 @@ public class MyIotDbUtils {
int offsetNum = (deviceLogInfo.getPageNum() - 1) * deviceLogInfo.getPageSize();
int limitNum = deviceLogInfo.getPageSize();
StringBuffer sb = new StringBuffer();
sb.append("select roleId, roleName, userId, username, deviceId, deviceName, deviceTypeId, deviceTypeName, deviceSn, accessed, type, clientIp, remark from root.myDeviceLogInfo.tableOne");
sb.append("select roleId, roleName, userId, username, deviceId, deviceName, deviceTypeBs, deviceTypeName, deviceSn, accessed, type, clientIp, remark from root.myDeviceLogInfo.tableOne");
if ((null != deviceLogInfo.getEndTime() && 0 != deviceLogInfo.getEndTime())
|| (null != deviceLogInfo.getBeginTime() && 0 != deviceLogInfo.getBeginTime())
|| (null != deviceLogInfo.getType() && !"".equals(deviceLogInfo.getType()))) {
......@@ -958,7 +962,7 @@ public class MyIotDbUtils {
Field field5 = fields.get(5);
String deviceName = field5.getStringValue();
Field field6 = fields.get(6);
String deviceTypeId = field6.getStringValue();
String deviceTypeBs = field6.getStringValue();
Field field7 = fields.get(7);
String deviceTypeName = field7.getStringValue();
Field field8 = fields.get(8);
......@@ -982,7 +986,7 @@ public class MyIotDbUtils {
deviceLogInfo1.setDeviceId(deviceId);
deviceLogInfo1.setDeviceName(deviceName);
deviceLogInfo1.setDeviceTypeId(deviceTypeId);
deviceLogInfo1.setDeviceTypeBs(deviceTypeBs);
deviceLogInfo1.setDeviceTypeName(deviceTypeName);
deviceLogInfo1.setDeviceSn(deviceSn);
......
......@@ -7,9 +7,11 @@ import cn.gintone.controller.vo.DeviceConnetRuleInfoRespVO;
import cn.gintone.controller.vo.DeviceConnetRuleInfoSaveReqVO;
import cn.gintone.controller.vo.VisitInfoSaveReqVO;
import cn.gintone.dal.DeviceConnetRuleInfoMapper;
import cn.gintone.dal.DeviceTypeMapper;
import cn.gintone.dal.PtDeptInfoMapper;
import cn.gintone.dto.*;
import cn.gintone.entity.DeviceConnetRuleInfoDO;
import cn.gintone.entity.DeviceTypeDO;
import cn.gintone.entity.VisitInfoDO;
import cn.gintone.iotdbUtils.MyIotDbUtils;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
......@@ -43,10 +45,9 @@ public class DeviceConnetRuleInfoServiceImpl implements DeviceConnetRuleInfoServ
private DeviceConnetRuleInfoMapper connetRuleInfoMapper;
@Autowired
private IotDbConfig iotDbConfig;
@Autowired
private UserRoleMapper userRoleMapper;
@Autowired
private PtDeptInfoMapper ptDeptInfoMapper;
private DeviceTypeMapper deviceTypeMapper;
@Override
public Long createConnetRuleInfo(DeviceConnetRuleInfoSaveReqVO createReqVO) {
......@@ -155,6 +156,14 @@ public class DeviceConnetRuleInfoServiceImpl implements DeviceConnetRuleInfoServ
@Override
public void checkDeviceLogInfo(DeviceLogInfo deviceLogInfo) {
if (null == deviceLogInfo.getDeviceTypeBs()) {
return;
}
DeviceTypeDO deviceTypeDO = deviceTypeMapper.selectOne(new QueryWrapper<DeviceTypeDO>().lambda()
.eq(DeviceTypeDO::getModelCode, deviceLogInfo.getDeviceTypeBs())
);
String userId = deviceLogInfo.getUserId();
if (null == userId || "".equals(userId)) {
DeviceIllLogInfo deviceIllLogInfo = new DeviceIllLogInfo();
......@@ -164,7 +173,8 @@ public class DeviceConnetRuleInfoServiceImpl implements DeviceConnetRuleInfoServ
deviceIllLogInfo.setUsername(deviceLogInfo.getUsername());
deviceIllLogInfo.setDeviceId(deviceLogInfo.getDeviceId());
deviceIllLogInfo.setDeviceName(deviceLogInfo.getDeviceName());
deviceIllLogInfo.setDeviceTypeId(deviceLogInfo.getDeviceTypeId());
deviceIllLogInfo.setDeviceTypeId(deviceTypeDO.getId() + "");
deviceIllLogInfo.setDeviceTypeBs(deviceLogInfo.getDeviceTypeBs());
deviceIllLogInfo.setDeviceTypeName(deviceLogInfo.getDeviceTypeName());
......@@ -175,48 +185,36 @@ public class DeviceConnetRuleInfoServiceImpl implements DeviceConnetRuleInfoServ
MyIotDbUtils.inserOneDeviceLogInfo_ill(iotDbConfig, deviceIllLogInfo);
return;
}
boolean isLegal = false; // 是否合法。false:不合法,true:合法
/*// 获取用户信息和角色信息------需要调用平台的接口
List<UserRoleDO> userRoleDOS = userRoleMapper.selectListByUserId(Long.parseLong(userId));
// 先查询角色规则
if (null != userRoleDOS && !userRoleDOS.isEmpty()) {
for (UserRoleDO userRoleDO : userRoleDOS) {
List<DeviceConnetRuleInfoDO> deviceConnetRuleInfoDOList = connetRuleInfoMapper.selectList(new LambdaQueryWrapper<DeviceConnetRuleInfoDO>()
.eq(DeviceConnetRuleInfoDO::getRoleId, userRoleDO.getRoleId())
.like(DeviceConnetRuleInfoDO::getDeviceId, deviceLogInfo.getDeviceId())
);
if (null != deviceConnetRuleInfoDOList && deviceConnetRuleInfoDOList.size() > 0) {
isLegal = true;
}
}
}*/
// 查询用户规则,如果配置了用户规则,则按照用户规则走
List<DeviceConnetRuleInfoDO> deviceConnetRuleInfoDOList = connetRuleInfoMapper.selectList(new LambdaQueryWrapper<DeviceConnetRuleInfoDO>()
.like(DeviceConnetRuleInfoDO::getUserId, deviceLogInfo.getUserId())
);
boolean isLegal = false;
if (null != deviceConnetRuleInfoDOList && deviceConnetRuleInfoDOList.size() > 0) {
isLegal = false;
List<DeviceConnetRuleInfoDO> deviceConnetRuleInfoDOS = connetRuleInfoMapper.selectList(new LambdaQueryWrapper<DeviceConnetRuleInfoDO>()
.eq(DeviceConnetRuleInfoDO::getUserId, userId)
.like(DeviceConnetRuleInfoDO::getDeviceId, deviceLogInfo.getDeviceId())
);
if (null != deviceConnetRuleInfoDOS && deviceConnetRuleInfoDOS.size() > 0) {
isLegal = true;
} else {
deviceConnetRuleInfoDOS = connetRuleInfoMapper.selectList(new LambdaQueryWrapper<DeviceConnetRuleInfoDO>()
if (null != deviceLogInfo && null != deviceLogInfo.getDeviceId()) { // 判断设备
List<DeviceConnetRuleInfoDO> deviceConnetRuleInfoDOS = connetRuleInfoMapper.selectList(new LambdaQueryWrapper<DeviceConnetRuleInfoDO>()
.eq(DeviceConnetRuleInfoDO::getUserId, userId)
.like(DeviceConnetRuleInfoDO::getDeviceTypeBs, deviceLogInfo.getDeviceTypeBs())
.like(DeviceConnetRuleInfoDO::getDeviceSn, deviceLogInfo.getDeviceSn())
);
if (null != deviceConnetRuleInfoDOS && deviceConnetRuleInfoDOS.size() > 0) {
isLegal = true;
}
} else { // 判断设备类型
List<DeviceConnetRuleInfoDO> deviceConnetRuleInfoDOS = connetRuleInfoMapper.selectList(new LambdaQueryWrapper<DeviceConnetRuleInfoDO>()
.eq(DeviceConnetRuleInfoDO::getUserId, userId)
.like(DeviceConnetRuleInfoDO::getDeviceTypeBs, deviceLogInfo.getDeviceTypeBs())
);
if (null != deviceConnetRuleInfoDOS && deviceConnetRuleInfoDOS.size() > 0) {
isLegal = true;
}
}
}
}
if (!isLegal) {
DeviceIllLogInfo deviceIllLogInfo = new DeviceIllLogInfo();
......@@ -226,7 +224,8 @@ public class DeviceConnetRuleInfoServiceImpl implements DeviceConnetRuleInfoServ
deviceIllLogInfo.setUsername(deviceLogInfo.getUsername());
deviceIllLogInfo.setDeviceId(deviceLogInfo.getDeviceId());
deviceIllLogInfo.setDeviceName(deviceLogInfo.getDeviceName());
deviceIllLogInfo.setDeviceTypeId(deviceLogInfo.getDeviceTypeId());
deviceIllLogInfo.setDeviceTypeId(deviceTypeDO.getId() + "");
deviceIllLogInfo.setDeviceTypeBs(deviceLogInfo.getDeviceTypeBs());
deviceIllLogInfo.setDeviceTypeName(deviceLogInfo.getDeviceTypeName());
deviceIllLogInfo.setAccessed(deviceLogInfo.getAccessed());
deviceIllLogInfo.setIllType(deviceLogInfo.getType());
......
......@@ -54,5 +54,9 @@ public interface DeviceReqConfService {
*/
List<DeviceReqConfDO> getDeviceReqConfList(DeviceReqConfListReqVO listReqVO);
String syncPtDevice();
// String syncPtDevice();
String exportPtDevice();
String exportPtDeviceType();
}
\ No newline at end of file
......@@ -4,16 +4,22 @@ import cn.gintone.ErrorInfo;
import cn.gintone.controller.vo.DeviceReqConfListReqVO;
import cn.gintone.controller.vo.DeviceReqConfSaveReqVO;
import cn.gintone.dal.DeviceReqConfMapper;
import cn.gintone.dal.DeviceTypeMapper;
import cn.gintone.dto.PtExportDevice;
import cn.gintone.dto.PtExportDeviceType;
import cn.gintone.dtoPt.*;
import cn.gintone.entity.DeviceReqConfDO;
import cn.gintone.entity.DeviceTypeDO;
import cn.gintone.myconf.BasicUrlConf;
import cn.gintone.utils.BasicInfoHttpUtils;
import cn.gintone.utils.PtExportDeviceUtils;
import cn.iocoder.yudao.module.system.controller.admin.auth.myVo.PtResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.io.IOException;
import java.util.*;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
......@@ -32,6 +38,8 @@ public class DeviceReqConfServiceImpl implements DeviceReqConfService {
private BasicUrlConf basicUrlConf;
@Resource
private DeviceReqConfMapper deviceReqConfMapper;
@Resource
private DeviceTypeMapper deviceTypeMapper;
@Override
public Long createDeviceReqConf(DeviceReqConfSaveReqVO createReqVO) {
......@@ -137,7 +145,7 @@ public class DeviceReqConfServiceImpl implements DeviceReqConfService {
return deviceReqConfMapper.selectList(listReqVO);
}
@Override
/*@Override
public String syncPtDevice() {
DeviceReqConfDO deviceReqConfDO_bz_type = deviceReqConfMapper.selectOne(new QueryWrapper<DeviceReqConfDO>()
.lambda()
......@@ -398,6 +406,61 @@ public class DeviceReqConfServiceImpl implements DeviceReqConfService {
}
return "同步成功";
}*/
@Override
public String exportPtDevice() {
try {
List<PtExportDevice> ptExportDeviceList = PtExportDeviceUtils.readDevicesFromExcel("D:\\yqd\\2025\\secure\\对接文档\\设备清单.xlsx");
if(null != ptExportDeviceList && ptExportDeviceList.size() > 0) {
List<DeviceTypeDO> deviceTypeDOS = deviceTypeMapper.selectList();
if(null != deviceTypeDOS && deviceTypeDOS.size() > 0) {
Map<String, DeviceTypeDO> deviceTypeDOMap = new HashMap<>();
for (DeviceTypeDO deviceTypeDO : deviceTypeDOS) {
deviceTypeDOMap.put(deviceTypeDO.getModelCode(), deviceTypeDO);
}
for (PtExportDevice ptExportDevice : ptExportDeviceList) {
DeviceReqConfDO deviceReqConf = new DeviceReqConfDO();
deviceReqConf.setSnCode(ptExportDevice.getDeviceSerialNo());
String modelCode = ptExportDevice.getModelCode();
DeviceTypeDO deviceTypeDO = deviceTypeDOMap.get(modelCode);
deviceReqConf.setDeviceTypeName(deviceTypeDO.getName());
deviceReqConf.setDeviceTypeId(deviceTypeDO.getId());
deviceReqConf.setDeviceName(ptExportDevice.getDeviceName());
deviceReqConf.setAddress(ptExportDevice.getDescription());
deviceReqConf.setDeviceEn(modelCode);
deviceReqConf.setRegionName(ptExportDevice.getDescription());
deviceReqConfMapper.insert(deviceReqConf);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return "同步成功";
}
@Override
public String exportPtDeviceType() {
try {
List<PtExportDeviceType> ptExportDeviceTypes = PtExportDeviceUtils.readDevicesTypeFromExcel("D:\\yqd\\2025\\secure\\对接文档\\产品类型.xlsx");
if (null != ptExportDeviceTypes && ptExportDeviceTypes.size() > 0) {
for (PtExportDeviceType deviceType : ptExportDeviceTypes) {
DeviceTypeDO deviceTypeDO = new DeviceTypeDO();
deviceTypeDO.setName(deviceType.getName());
deviceTypeDO.setModelCode(deviceType.getModelCode());
deviceTypeDO.setManufacturer(deviceType.getManufacturer());
deviceTypeDO.setIntegratedApplicationOwnership(deviceType.getIntegratedApplicationOwnership());
deviceTypeMapper.insert(deviceTypeDO);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
}
\ No newline at end of file
package cn.gintone.service;
import java.util.*;
import javax.validation.*;
import cn.gintone.controller.vo.DeviceTypePageReqVO;
import cn.gintone.controller.vo.DeviceTypeSaveReqVO;
import cn.gintone.entity.DeviceTypeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 设备类型 Service 接口
*
* @author 安全系统管理
*/
public interface DeviceTypeService {
/**
* 创建设备类型
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createDeviceType(@Valid DeviceTypeSaveReqVO createReqVO);
/**
* 更新设备类型
*
* @param updateReqVO 更新信息
*/
void updateDeviceType(@Valid DeviceTypeSaveReqVO updateReqVO);
/**
* 删除设备类型
*
* @param id 编号
*/
void deleteDeviceType(Long id);
/**
* 获得设备类型
*
* @param id 编号
* @return 设备类型
*/
DeviceTypeDO getDeviceType(Long id);
/**
* 获得设备类型分页
*
* @param pageReqVO 分页查询
* @return 设备类型分页
*/
PageResult<DeviceTypeDO> getDeviceTypePage(DeviceTypePageReqVO pageReqVO);
}
\ No newline at end of file
package cn.gintone.service;
import cn.gintone.ErrorInfo;
import cn.gintone.controller.vo.DeviceTypePageReqVO;
import cn.gintone.controller.vo.DeviceTypeSaveReqVO;
import cn.gintone.dal.DeviceTypeMapper;
import cn.gintone.entity.DeviceTypeDO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* 设备类型 Service 实现类
*
* @author 安全系统管理
*/
@Service
@Validated
public class DeviceTypeServiceImpl implements DeviceTypeService {
@Resource
private DeviceTypeMapper deviceTypeMapper;
@Override
public Long createDeviceType(DeviceTypeSaveReqVO createReqVO) {
// 插入
DeviceTypeDO deviceType = BeanUtils.toBean(createReqVO, DeviceTypeDO.class);
deviceTypeMapper.insert(deviceType);
// 返回
return deviceType.getId();
}
@Override
public void updateDeviceType(DeviceTypeSaveReqVO updateReqVO) {
// 校验存在
validateDeviceTypeExists(updateReqVO.getId());
// 更新
DeviceTypeDO updateObj = BeanUtils.toBean(updateReqVO, DeviceTypeDO.class);
deviceTypeMapper.updateById(updateObj);
}
@Override
public void deleteDeviceType(Long id) {
// 校验存在
validateDeviceTypeExists(id);
// 删除
deviceTypeMapper.deleteById(id);
}
private void validateDeviceTypeExists(Long id) {
if (deviceTypeMapper.selectById(id) == null) {
throw exception(ErrorInfo.DEVICE_TYPE_NOT_EXISTS);
}
}
@Override
public DeviceTypeDO getDeviceType(Long id) {
return deviceTypeMapper.selectById(id);
}
@Override
public PageResult<DeviceTypeDO> getDeviceTypePage(DeviceTypePageReqVO pageReqVO) {
return deviceTypeMapper.selectPage(pageReqVO);
}
}
\ No newline at end of file
package cn.gintone.service;
import cn.gintone.config.IotDbConfig;
import cn.gintone.controller.vo.DeviceReqConfListReqVO;
import cn.gintone.dal.DeviceReqConfMapper;
import cn.gintone.dto.DeviceIllLogInfo;
import cn.gintone.entity.DeviceReqConfDO;
import cn.gintone.iotdbUtils.MyIotDbUtils;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Component
public class MyScheduledTasks {
@Resource
private DeviceReqConfMapper deviceReqConfMapper;
@Autowired
private IotDbConfig iotDbConfig;
@Scheduled(fixedDelay = 50000)
public void updateDeviceState() {
List<DeviceReqConfDO> deviceReqConfDOS = deviceReqConfMapper.selectList(new DeviceReqConfListReqVO());
if (deviceReqConfDOS != null && deviceReqConfDOS.size() > 0) {
for (DeviceReqConfDO deviceReqConfDO : deviceReqConfDOS) {
Date sycnDate = deviceReqConfDO.getSycnDate();
if (sycnDate != null && 1 != deviceReqConfDO.getState()) {
Long t = new Date().getTime() - sycnDate.getTime();
if (t > 10 * 60 * 60) {
deviceReqConfMapper.update(new UpdateWrapper<DeviceReqConfDO>().lambda()
.eq(DeviceReqConfDO::getId, deviceReqConfDO.getId())
.set(DeviceReqConfDO::getState, 0)
);
DeviceIllLogInfo deviceIllLogInfo = new DeviceIllLogInfo();
deviceIllLogInfo.setDeviceId(deviceReqConfDO.getDeviceId());
deviceIllLogInfo.setDeviceName(deviceReqConfDO.getDeviceName());
deviceIllLogInfo.setDeviceTypeId(deviceReqConfDO.getDeviceTypeId() + "");
deviceIllLogInfo.setDeviceTypeName(deviceReqConfDO.getDeviceTypeName());
deviceIllLogInfo.setIllType("disconnected");
MyIotDbUtils.inserOneDeviceLogInfo_ill(iotDbConfig, deviceIllLogInfo);
}
}
}
}
}
}
package cn.gintone.utils;
import cn.gintone.dto.PtExportDevice;
import cn.gintone.dto.PtExportDeviceType;
import org.apache.poi.ss.usermodel.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class PtExportDeviceUtils {
public static List<PtExportDevice> readDevicesFromExcel(String filePath) throws IOException {
List<PtExportDevice> devices = new ArrayList<>();
try {
InputStream inputStream = new FileInputStream(filePath);
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
Iterator<Row> rowIterator = sheet.iterator();
// 跳过表头行(如果需要)
if (rowIterator.hasNext()) {
rowIterator.next(); // 跳过第一行(标题行)
}
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
PtExportDevice device = createDeviceFromRow(row);
if (device != null) {
devices.add(device);
}
}
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
return devices;
}
private static PtExportDevice createDeviceFromRow(Row row) {
// 检查行是否为空
if (isRowEmpty(row)) {
return null;
}
PtExportDevice device = new PtExportDevice();
// 读取每一列的数据
device.setDeviceSerialNo(getCellValue(row.getCell(0))); // Device Serial No
device.setDeviceName(getCellValue(row.getCell(1))); // Device Name
device.setModelCode(getCellValue(row.getCell(2))); // Model Code
device.setDescription(getCellValue(row.getCell(3))); // Description
device.setLabel(getCellValue(row.getCell(4))); // Label
device.setDeviceSec(getCellValue(row.getCell(5))); // Device Sec
device.setClassification(getCellValue(row.getCell(6))); // Classification
return device;
}
private static String getCellValue(Cell cell) {
if (cell == null) {
return "";
}
switch (cell.getCellType()) {
case STRING:
return cell.getStringCellValue().trim();
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue().toString();
} else {
// 防止科学计数法
return String.valueOf((long) cell.getNumericCellValue());
}
case BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case FORMULA:
return cell.getCellFormula();
default:
return "";
}
}
private static boolean isRowEmpty(Row row) {
if (row == null) {
return true;
}
if (row.getLastCellNum() <= 0) {
return true;
}
for (int cellNum = row.getFirstCellNum(); cellNum < row.getLastCellNum(); cellNum++) {
Cell cell = row.getCell(cellNum);
if (cell != null && cell.getCellType() != CellType.BLANK &&
!getCellValue(cell).isEmpty()) {
return false;
}
}
return true;
}
public static List<PtExportDeviceType> readDevicesTypeFromExcel(String filePath) throws IOException {
List<PtExportDeviceType> deviceTypes = new ArrayList<>();
try {
InputStream inputStream = new FileInputStream(filePath);
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
Iterator<Row> rowIterator = sheet.iterator();
// 跳过表头行(如果需要)
if (rowIterator.hasNext()) {
rowIterator.next(); // 跳过第一行(标题行)
}
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
PtExportDeviceType deviceType = createDeviceTypeFromRow(row);
if (deviceType != null) {
deviceTypes.add(deviceType);
}
}
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
return deviceTypes;
}
private static PtExportDeviceType createDeviceTypeFromRow(Row row) {
// 检查行是否为空
if (isRowEmpty(row)) {
return null;
}
PtExportDeviceType deviceType = new PtExportDeviceType();
// 读取每一列的数据
deviceType.setName(getCellValue(row.getCell(0))); // Device Serial No
deviceType.setModelCode(getCellValue(row.getCell(1))); // Device Name
deviceType.setManufacturer(getCellValue(row.getCell(2))); // Model Code
deviceType.setIntegratedApplicationOwnership(getCellValue(row.getCell(3))); // Description
return deviceType;
}
}
<?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="cn.gintone.dal.DeviceTypeMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
\ No newline at end of file
......@@ -54,51 +54,55 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
MyReadApplicationUtils.readApplication();
String pdToken = request.getHeader("pdToken");
StringBuffer requestURL = request.getRequestURL();
stringRedisTemplate.opsForValue().set("pdToken", pdToken);
boolean b = false;
if (b) {
String pdToken = request.getHeader("pdToken");
StringBuffer requestURL = request.getRequestURL();
stringRedisTemplate.opsForValue().set("pdToken", pdToken);
// System.out.println(requestURL.toString());
if (requestURL.toString().contains("system/") || requestURL.toString().contains("get-by-website") || requestURL.toString().contains("checkPdToken") || requestURL.toString().contains("initIotDBDatabase")) {
if (requestURL.toString().contains("system/") || requestURL.toString().contains("get-by-website") || requestURL.toString().contains("checkPdToken") || requestURL.toString().contains("initIotDBDatabase")) {
} else {
if (StrUtil.isBlank(pdToken)) {
CommonResult<?> result = new CommonResult<>();
result.setCode(403);
result.setMsg("未登录");
ServletUtils.writeJSON(response, result);
return;
} else {
Map<String, String> headers = new HashMap<>();
headers.put("appkey", MyReadApplicationUtils.getAppkey());
headers.put("Authorization", pdToken);
String rStr = MyHttpTwoUtils.get(MyReadApplicationUtils.getUserByToken(), headers, null);
PtResult<LoginUserInfo> result = JSON.parseObject(rStr, new TypeReference<PtResult<LoginUserInfo>>() {});
if (null == result || result.getCode() != 200) {
CommonResult<?> result1 = new CommonResult<>();
result1.setCode(403);
result1.setMsg("未登录");
ServletUtils.writeJSON(response, result1);
return ;
} else if (null == result || result.getCode() == 5001) {
CommonResult<?> result1 = new CommonResult<>();
result1.setCode(402);
result1.setMsg("Token无效");
ServletUtils.writeJSON(response, result1);
return ;
if (StrUtil.isBlank(pdToken)) {
CommonResult<?> result = new CommonResult<>();
result.setCode(403);
result.setMsg("未登录");
ServletUtils.writeJSON(response, result);
return;
} else {
LoginUserInfo data = result.getData();
String accessToken = data.getAccessToken();
String refreshToken = data.getRefreshToken();
stringRedisTemplate.opsForValue().set("pdToken", accessToken);
stringRedisTemplate.opsForValue().set("refreshToken", refreshToken);
stringRedisTemplate.opsForValue().set("pdUserInfo", JSON.toJSONString(data));
Map<String, String> headers = new HashMap<>();
headers.put("appkey", MyReadApplicationUtils.getAppkey());
headers.put("Authorization", pdToken);
String rStr = MyHttpTwoUtils.get(MyReadApplicationUtils.getUserByToken(), headers, null);
PtResult<LoginUserInfo> result = JSON.parseObject(rStr, new TypeReference<PtResult<LoginUserInfo>>() {});
if (null == result || result.getCode() != 200) {
CommonResult<?> result1 = new CommonResult<>();
result1.setCode(403);
result1.setMsg("未登录");
ServletUtils.writeJSON(response, result1);
return ;
} else if (null == result || result.getCode() == 5001) {
CommonResult<?> result1 = new CommonResult<>();
result1.setCode(402);
result1.setMsg("Token无效");
ServletUtils.writeJSON(response, result1);
return ;
} else {
LoginUserInfo data = result.getData();
String accessToken = data.getAccessToken();
String refreshToken = data.getRefreshToken();
stringRedisTemplate.opsForValue().set("pdToken", accessToken);
stringRedisTemplate.opsForValue().set("refreshToken", refreshToken);
stringRedisTemplate.opsForValue().set("pdUserInfo", JSON.toJSONString(data));
}
}
}
// return;
}
}
String token = SecurityFrameworkUtils.obtainAuthorization(request,
securityProperties.getTokenHeader(), securityProperties.getTokenParameter());
if (StrUtil.isNotEmpty(token)) {
......
......@@ -121,7 +121,6 @@ spring:
rocketmq:
name-server: 127.0.0.1:9876 # RocketMQ Namesrv
spring:
# RabbitMQ 配置项,对应 RabbitProperties 配置类
# rabbitmq:
# host: 192.168.19.205
......@@ -131,22 +130,59 @@ spring:
# password: kalo
# virtual-host: /
# Kafka 配置项,对应 KafkaProperties 配置类
kafka:
kafka:
cluster1:
bootstrap-servers: 59.195.13.209:9092
# bootstrap-servers: 192.168.19.128:9092
bootstrap-servers: 59.195.13.208:9092
producer:
retries: 3
request.timeout.ms: 60000
max.block.ms: 60000 # 防止元数据获取超时
request-timeout-ms: 60000
max-block-ms: 60000
key.serializer: org.apache.kafka.common.serialization.StringSerializer
value.serializer: org.apache.kafka.common.serialization.StringSerializer
consumer:
group-id: weblog_consumer_group
auto-offset-reset: earliest
enable-auto-commit: false # 建议手动提交偏移量
max.poll.interval.ms: 300000 # 根据业务处理时间调整
enable-auto-commit: false
max-poll-interval-ms: 300000
admin:
auto-create: true
cluster2:
bootstrap-servers: 59.195.13.250:29400,59.195.13.250:29401,59.195.13.250:29402
properties:
security.protocol: PLAINTEXT
producer:
retries: 3
request-timeout-ms: 60000
max-block-ms: 60000
key.serializer: org.apache.kafka.common.serialization.StringSerializer
value.serializer: org.apache.kafka.common.serialization.StringSerializer
consumer:
group-id: pump_station_consumer_group
auto-offset-reset: earliest
enable-auto-commit: false
max-poll-interval-ms: 300000
# 添加消费者稳定性配置
session-timeout-ms: 30000
heartbeat-interval-ms: 10000
max-poll-records: 500
# cluster2:
# bootstrap-servers: 59.195.13.250:29400,59.195.13.250:29401,59.195.13.250:29402
# properties:
# security.protocol: SASL_PLAINTEXT
# sasl.mechanism: PLAIN
# sasl.jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="InOneCore" password="Vz#5\$wllNJJA1gv";
# producer:
# retries: 3
# request.timeout.ms: 60000
# max.block.ms: 60000
# key.serializer: org.apache.kafka.common.serialization.StringSerializer
# value.serializer: org.apache.kafka.common.serialization.StringSerializer
# consumer:
# group-id: pump_station_consumer_group
# auto-offset-reset: earliest
# enable-auto-commit: false
# max.poll.interval.ms: 300000
--- #################### 服务保障相关配置 ####################
# Lock4j 配置项
......
......@@ -3,8 +3,8 @@ spring:
name: yudao-server
profiles:
active: local
# active: dev
# active: local
active: dev
main:
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment