| | |
| | | package com.ruoyi.sy.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.common.core.domain.entity.SysConfig; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.sy.domain.ArdSyCarRtu; |
| | | import com.ruoyi.sy.mapper.ArdSyCarRtuMapper; |
| | | import com.ruoyi.sy.service.ArdSyCarRtuService; |
| | | import com.ruoyi.system.mapper.SysConfigMapper; |
| | | import com.ruoyi.utils.mqtt.MqttConsumer; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author Administrator |
| | |
| | | |
| | | @Autowired |
| | | private ArdSyCarRtuMapper ardSyCarRtuMapper; |
| | | @Resource |
| | | private SysConfigMapper configMapper; |
| | | |
| | | @Override |
| | | public String allCarTopic() { |
| | | public String[] allCarTopic() { |
| | | List<ArdSyCarRtu> carRtus = ardSyCarRtuMapper.selectList(null); |
| | | List<String> list = new ArrayList<>(); |
| | | for (int i = 0; i < carRtus.size(); i++) { |
| | | list.add(carRtus.get(i).getTopicPublish()); |
| | | } |
| | | String[] topicArray = list.toArray(new String[list.size()]); |
| | | return Arrays.toString(topicArray); |
| | | return list.toArray(new String[list.size()]); |
| | | } |
| | | |
| | | @Override |
| | | public List<ArdSyCarRtu> allCarTopicList() { |
| | | return ardSyCarRtuMapper.selectList(null); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return ardSyCarRtuMapper.selectOne(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public String openLock(ArdSyCarRtu ardSyCarRtu) { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | // map.put("A01", 110000);//导通第一路继电器 |
| | | // map.put("A02", 110000);//导通第二路继电器 |
| | | map.put("res", String.valueOf(System.currentTimeMillis())); |
| | | MqttConsumer.publish(ardSyCarRtu.getTopicSubscribe(), String.valueOf(new JSONObject(map))); |
| | | return "已发送开锁指令"; |
| | | } |
| | | |
| | | @Override |
| | | public ArdSyCarRtu subscribeByCarId(String subscribe) { |
| | | QueryWrapper<ArdSyCarRtu> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("topic_subscribe",subscribe); |
| | | return ardSyCarRtuMapper.selectOne(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public String url(String key) { |
| | | // QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<>(); |
| | | // queryWrapper.eq("config_key",key); |
| | | // SysConfig sysConfig = configMapper.selectOne(queryWrapper); |
| | | SysConfig sysConfig = configMapper.checkConfigKeyUnique(key); |
| | | if(sysConfig!=null){ |
| | | return sysConfig.getConfigValue(); |
| | | }else { |
| | | return "配置表无地址数据"; |
| | | } |
| | | } |
| | | |
| | | } |