| | |
| | | import com.doumee.dao.business.model.MqttLog; |
| | | import com.doumee.service.business.DeviceService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.Date; |
| | |
| | | private MqttLogMapper mqttLogMapper; |
| | | @Autowired |
| | | private MqttConfig mqttConfig; |
| | | @Override |
| | | @PostConstruct |
| | | public void startSubcribe() { |
| | | mqttToolService.subscribe(new String[]{ Constants.MqttTopic.openLock, Constants.MqttTopic.closeLock}); |
| | | } |
| | | |
| | | /** |
| | | * 发起开锁指令 |
| | | * @param locks |
| | |
| | | */ |
| | | @Override |
| | | public MqttLog openLock(Locks locks) { |
| | | String topic = Constants.MqttTopic.openLock.replace("+", locks.getId()); |
| | | String topic = Constants.MqttTopic.pub_openLock.replace("{siteId}", locks.getSiteId()).replace("{lockId}", locks.getCode()+""); |
| | | int result = mqttToolService.pubMessage("{}",topic); |
| | | MqttLog mqttLog = createPushLog(topic,result,"请求开锁_"+locks.getId()); |
| | | return mqttLog; |
| | |
| | | */ |
| | | @Override |
| | | public MqttLog getLockInfo(Locks locks) { |
| | | String topic = Constants.MqttTopic.getLockInfo.replace("+", locks.getId()); |
| | | String topic = Constants.MqttTopic.pub_getLockInfo.replace("{siteId}", locks.getSiteId()).replace("{lockId}", locks.getCode()+""); |
| | | int result = mqttToolService.pubMessage("{}",topic); |
| | | MqttLog mqttLog = createPushLog(topic,result,"实时查询锁信息_"+locks.getId()); |
| | | return mqttLog; |
| | | } |
| | | @Override |
| | | @Async |
| | | public void testPush(String topic, String json){ |
| | | int result = mqttToolService.pubMessage(json,topic); |
| | | } |
| | | |
| | | private MqttLog createPushLog(String topic, int result,String info) { |
| | |
| | | log.setType(Constants.ONE); |
| | | log.setMsg(""); |
| | | log.setInfo(info); |
| | | log.setIsdeleted(Constants.ZERO); |
| | | mqttLogMapper.insert(log); |
| | | return log; |
| | | } |