Commit 3694c093 by zzrdark

1.修改渠道管理

2.增加测试环境配置
parent c070b6b0
package com.mx.cneeds.common.constant;
/**
* @ClassName ResultCode
* @Author zzrdark
* @Date 2020-04-16 17:15
* @Description TODO
**/
public class ResultCode {
//没有发现IMEI
public static Integer NOTFOUND_IMEI = 1;
//没有设置渠道商
public static Integer NOTSET_CHANNEL = 2;
}
......@@ -20,7 +20,7 @@ public class OAuth2ResourceServer extends ResourceServerConfigurerAdapter {
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/user/login",
"/device/getChannel_nums",
"/device/device/getChannel_nums",
// "/user/info",
"/statics/**")
.permitAll()
......
package com.mx.cneeds.server.datashow.web.device;
import com.mx.cneeds.common.constant.ResultCode;
import com.mx.cneeds.common.converter.RequestParamterConverter;
import com.mx.cneeds.common.dto.*;
import com.mx.cneeds.common.result.R;
......@@ -31,11 +32,24 @@ public class DeviceController {
private DeviceClient deviceClient;
@GetMapping("/device/getChannel")
@GetMapping("/device/getChannel_nums")
public R getChannel_nums(String imei){
DeviceChannelVo channelVo = new DeviceChannelVo();
DeviceInfoDto deviceInfoDto = deviceClient.queryDeviceByImei(imei);
DeviceInfoDto deviceInfoDto = null;
try {
deviceInfoDto = deviceClient.queryDeviceByImei(imei);
if (deviceInfoDto == null){
return R.error(ResultCode.NOTFOUND_IMEI,"没有该imei的设备");
}
}catch (Exception e) {
return R.error(ResultCode.NOTFOUND_IMEI,"没有该imei的设备");
}
if (deviceInfoDto.getChannelNums() == null || deviceInfoDto.getChannelRules() == null) {
return R.error(ResultCode.NOTSET_CHANNEL,"该设备没有设置渠道商号");
}
BeanUtils.copyProperties(deviceInfoDto,channelVo);
return new R().put("data",channelVo);
}
......
......@@ -4,5 +4,5 @@ eureka:
defaultZone: http://192.168.2.244:8761/eureka/
instance:
prefer-ip-address: true
# ip-address: 192.168.2.244
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8761/eureka/
defaultZone: http://192.168.2.244:8761/eureka/
instance:
prefer-ip-address: true
ip-address: 192.168.2.244
......@@ -60,8 +60,13 @@ public class DeviceInfoController {
public DeviceInfoDto infoByimei(String imei){
DeviceInfoEntity deviceInfoEntity = deviceInfoService.queryDeviceByImei(imei);
DeviceInfoDto deviceInfoDto = new DeviceInfoDto();
BeanUtils.copyProperties(deviceInfoEntity,deviceInfoDto);
return deviceInfoDto;
if (deviceInfoEntity != null){
BeanUtils.copyProperties(deviceInfoEntity,deviceInfoDto);
return deviceInfoDto;
}else{
return null;
}
}
@RequestMapping("/infoByIds")
......
......@@ -50,29 +50,6 @@ eureka:
defaultZone: http://192.168.2.244:8761/eureka/
instance:
prefer-ip-address: true
ip-address: 192.168.2.244
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.mx.cneeds.server.entity
global-config:
#数据库相关配置
db-config:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type: AUTO
#字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
field-strategy: NOT_NULL
#驼峰下划线转换
column-underline: true
logic-delete-value: -1
logic-not-delete-value: 0
banner: false
#原生配置
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
call-setters-on-nulls: true
jdbc-type-for-null: 'null'
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/cneeds_server?useUnicode=true&characterEncoding=UTF-8&useSSL=false
url: jdbc:mysql://192.168.2.244:3306/cneeds_server?useUnicode=true&characterEncoding=UTF-8&useSSL=false
password: cneeds!QAZ1qaz
username: root
......@@ -9,6 +9,31 @@ spring:
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8761/eureka/
defaultZone: http://192.168.2.244:8761/eureka/
instance:
prefer-ip-address: true
ip-address: 192.168.2.244
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.mx.cneeds.server.entity
global-config:
#数据库相关配置
db-config:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type: AUTO
#字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
field-strategy: NOT_NULL
#驼峰下划线转换
column-underline: true
logic-delete-value: -1
logic-not-delete-value: 0
banner: false
#原生配置
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
call-setters-on-nulls: true
jdbc-type-for-null: 'null'
\ No newline at end of file
spring:
profiles:
active: dev
active: prod
application:
name: cneeds-server-device
......
......@@ -46,6 +46,8 @@
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mqtt</artifactId>
......
package com.mx.cneeds.server.user.mqtt.bean;
/**
* @ClassName BaseMqttBean
* @Author zzrdark
* @Date 2020-04-16 21:01
* @Description TODO
**/
public class BaseMqttBean {
String command;
String serialNum;
String imei;
}
package com.mx.cneeds.server.user.mqtt.bean;
/**
* @ClassName RemoteControl
* @Author zzrdark
* @Date 2020-04-16 20:53
* @Description TODO
**/
public class RemoteControl extends BaseMqttBean{
String shell;
}
......@@ -19,6 +19,8 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import java.util.Map;
/**
* @ClassName MqttConfiguration
* @author zzrdark
......@@ -61,12 +63,15 @@ public class MqttConfiguration {
@Bean
public MessageProducer inbound(@Autowired MessageChannel mqttInputChannel) {
MqttPahoMessageDrivenChannelAdapter adapter =
new MqttPahoMessageDrivenChannelAdapter(mqttProperties.getClientId()+"_inbound", mqttClientFactory(),
"hello","hello1");
new MqttPahoMessageDrivenChannelAdapter(mqttProperties.getClientId()+"_inbound", mqttClientFactory());
adapter.setCompletionTimeout(Integer.valueOf(mqttProperties.getCompletionTimeout()));
adapter.setConverter(new DefaultPahoMessageConverter());
adapter.setQos(1);
adapter.setOutputChannel(mqttInputChannel);
for (Map<String,String> map : mqttProperties.getTopics()){
adapter.addTopic(map.get("topicname"),Integer.valueOf(map.get("qos")));
}
return adapter;
}
......@@ -84,16 +89,8 @@ public class MqttConfiguration {
@Override
public void handleMessage(Message<?> message) {
String topic = message.getHeaders().get("mqtt_receivedTopic").toString();
// String type = topic.substring(topic.lastIndexOf("/")+1, topic.length());
String qos = message.getHeaders().get("mqtt_receivedQos").toString();
/*if("hello".equalsIgnoreCase(topic)){
System.out.println("hello,fuckXX,"+message.getPayload().toString());
}else if("hello1".equalsIgnoreCase(topic)){
System.out.println("hello1,fuckXX,"+message.getPayload().toString());
}*/
eventPublisher.publishEvent(new MqttEvent(this,topic,message.getPayload().toString()));
log.info("topic:"+topic+" Qos:"+qos+" message:"+message.getPayload());
}
};
}
......@@ -101,13 +98,12 @@ public class MqttConfiguration {
//发送数据
@Bean
@ServiceActivator(inputChannel = "mqttOutboundChannel")
public MessageHandler mqttOutbound() {
MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(mqttProperties.getClientId(), mqttClientFactory());
messageHandler.setAsync(true);
messageHandler.setDefaultTopic(mqttProperties.getDefaultTopic());
// messageHandler.setDefaultTopic(mqttProperties.getDefaultTopic());
return messageHandler;
}
@Bean
......
......@@ -5,6 +5,9 @@ import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* @author zzrdark
*/
......@@ -22,7 +25,7 @@ public class MqttProperties {
private String clientId;
private String defaultTopic;
private List<Map<String,String>> topics;
private String completionTimeout;
......
......@@ -19,12 +19,18 @@ public class JobListener {
* 监听topic
* @param mqttEvent
*/
@EventListener(condition = "# mqttEvent.topic.equals(T(com.zzr.mqtt.qmemqtt.defalut.utils.TopicName).ROLL_CALL_2.getValue())")
/*@EventListener(condition = "# mqttEvent.topic.equals(T(com.zzr.mqtt.qmemqtt.defalut.utils.TopicName).ROLL_CALL_2.getValue())")
public void onEmqttCall(MqttEvent mqttEvent){
log.info("接收到消息:"+mqttEvent.getMessage());
}
}*/
@EventListener(condition ="@ emqttPredicate.test(#mqttEvent)")
public void onEmqttCallTest(MqttEvent mqttEvent){
log.info("测试通过:"+mqttEvent.getMessage());
}
@EventListener(condition ="@ emqttPredicate.isDeviceTopic(#mqttEvent)")
public void executeDevice(MqttEvent mqttEvent) {
log.info("Topic:"+mqttEvent.getTopic()+"" +"\n收到设备信息:"+mqttEvent.getMessage());
}
}
......@@ -16,4 +16,12 @@ public class EmqttPredicate {
return Boolean.FALSE;
}
public Boolean isDeviceTopic(MqttEvent event){
if (event.getTopic().contains("device/")){
return true;
}else {
return false;
}
}
}
......@@ -48,13 +48,15 @@ spring:
host-url: tcp://120.25.162.101:1883
# client-id: zhjsbackground${random.value}
client-id: server
# default-topic: brokers/1
# default-topic: brokers/2
default-topic: brokers/#
# default-topic: $SYS/brokers/+/clients/#
completionTimeout: 3000
keepAlive: 60
topics[0]:
topicname: device/+/+/push
qos: 0
topics[1]:
topicname: server/receive/
qos: 0
eureka:
client:
......@@ -62,7 +64,7 @@ eureka:
defaultZone: http://192.168.2.244:8761/eureka/
instance:
prefer-ip-address: true
ip-address: 192.168.2.244
......
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/cneeds_server?useUnicode=true&characterEncoding=UTF-8&useSSL=false
url: jdbc:mysql://192.168.2.244:3306/cneeds_server?useUnicode=true&characterEncoding=UTF-8&useSSL=false
password: cneeds!QAZ1qaz
username: root
mqtt:
username: admin
password: public
host-url: tcp://120.25.162.101:1883
# client-id: zhjsbackground${random.value}
client-id: server
# default-topic: $SYS/brokers/+/clients/#
completionTimeout: 3000
keepAlive: 60
topics[0]:
topicname: device/+/+/push
qos: 0
topics[1]:
topicname: server/receive/
qos: 0
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8761/eureka/
defaultZone: http://192.168.2.244:8761/eureka/
instance:
prefer-ip-address: true
ip-address: 192.168.2.244
spring:
profiles:
active: dev
active: prod
application:
name: cneeds-server-user
......
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