yangys
2024-10-10 c34415c583b097c5ad3a19684557d97402d2f230
appId同步
已修改4个文件
31 ■■■■ 文件已修改
collect/src/main/java/com/qianwen/mdc/collect/config/MqttConfig.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/entity/mgr/WorkstationAppMapping.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/WorkstationAppMappingService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/resources/application-dev.yml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/config/MqttConfig.java
@@ -23,6 +23,7 @@
import com.qianwen.mdc.collect.service.DeviceStateFixPointService;
import com.qianwen.mdc.collect.service.IOTMqttReceiveService;
import com.qianwen.mdc.collect.service.WorkstationAppMappingService;
import com.qianwen.mdc.collect.service.feedback.WorkstationFeedbackService;
import cn.hutool.core.date.DateTime;
@@ -47,6 +48,10 @@
    
    @Autowired
    private WorkstationFeedbackService workstationFeedbackService;
    @Autowired
    private WorkstationAppMappingService workstationAppMappingService;
    public static final String COLLECT_DATA_TOPIC = "forward/test";
    
    /**
@@ -55,6 +60,8 @@
    public static final String FEEDBACK_TOPIC = "mdc/feedback";
    
    public static final String WOCKSTATION_CREATE_TOPIC = "mdc/workstation-create";
    private final String WORKSTATION_APP_MAPPING_CHANGED_TOPIC = "mdc/workstation_app_mapping_changed";
    
    @Bean
    public MqttPahoClientFactory mqttClientFactory() {
@@ -86,7 +93,7 @@
        String clientId = "spring-boot-mqtt-client-inbound"+r.nextInt(1000);
        MqttPahoMessageDrivenChannelAdapter adapter =
                new MqttPahoMessageDrivenChannelAdapter(clientId,
                        mqttClientFactory(), COLLECT_DATA_TOPIC, FEEDBACK_TOPIC,WOCKSTATION_CREATE_TOPIC);//最后一个参数允许多个topic参数
                        mqttClientFactory(), COLLECT_DATA_TOPIC, FEEDBACK_TOPIC,WOCKSTATION_CREATE_TOPIC,WORKSTATION_APP_MAPPING_CHANGED_TOPIC);//最后一个参数允许多个topic参数
        adapter.setCompletionTimeout(5000);
        adapter.setConverter(new DefaultPahoMessageConverter());
        adapter.setQos(1);
@@ -116,6 +123,10 @@
                logger.info("工位创建接收消息={}",workstationId);
                stateFixPointService.deviceStateFixPoint(DateTime.now(), Arrays.asList(workstationId));
                recService.handle((String)message.getPayload());
            }else if(WORKSTATION_APP_MAPPING_CHANGED_TOPIC.equals(topic)) {
                String workstationId = (String)message.getPayload();
                logger.info("工位appId映射变化消息={}",workstationId);
                workstationAppMappingService.saveToCache();
            }else {//订阅了几个topic就会接收到几个,其他的不会进来
                logger.warn("topic={},msg={},无对应的处理器",topic,message.getPayload());
            }
collect/src/main/java/com/qianwen/mdc/collect/entity/mgr/WorkstationAppMapping.java
@@ -15,11 +15,12 @@
    /**
     * id
     */
    //@TableId(type=IdType.ASSIGN_ID)
    //private Long id;
   // @TableField("workstation_id")
    @TableId(type=IdType.ASSIGN_ID)
    private Long id;
    @TableField("workstation_id")
    private long workstationId;
    /**
@@ -29,14 +30,14 @@
    private String appId;
    private static final long serialVersionUID = 1L;
    /*
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    }*/
    public long getWorkstationId() {
        return workstationId;
collect/src/main/java/com/qianwen/mdc/collect/service/WorkstationAppMappingService.java
@@ -53,6 +53,7 @@
     */
    public void saveToCache() {
        List<WorkstationAppMapping> list =  allList();
        redisUtil.del(MAPPING_REDIS_KEY);
        list.forEach(m ->{
            redisUtil.hset(MAPPING_REDIS_KEY, m.getAppId(), m.getWorkstationId());
        });
collect/src/main/resources/application-dev.yml
@@ -27,9 +27,9 @@
  # mysql
datasource:
  type: mysql
  url: jdbc:mysql://localhost:3306/blade_boot?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
  url: jdbc:mysql://120.46.212.231:3306/smart_boot?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
  port: 3306
  username: root
  username: qwmdc
  password: Kknd_1234
  driver-class-name: com.mysql.cj.jdbc.Driver
#iotdb 以及其jdbc一起配置