| | |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.mqtt.config.MqttConfig; |
| | | import com.doumee.core.mqtt.service.MqttToolService; |
| | | import com.doumee.dao.business.MemberRidesMapper; |
| | | import com.doumee.dao.business.MqttLogMapper; |
| | | import com.doumee.dao.business.SitesMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.service.business.*; |
| | | import com.doumee.service.business.ActionLogService; |
| | | import com.doumee.service.business.DeviceSubcribeService; |
| | | import com.doumee.service.business.MemberRidesService; |
| | | import com.doumee.service.business.SitesService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | |
| | | MemberRidesService memberRidesService; |
| | | @Lazy |
| | | @Autowired |
| | | SitesMapper sitesMapper; |
| | | SitesService sitesService; |
| | | @Autowired |
| | | private MqttLogMapper mqttLogMapper; |
| | | @Autowired |
| | | @Lazy |
| | | private ActionLogService actionLogService; |
| | | @Autowired |
| | | private MqttConfig mqttConfig; |
| | | @Override |
| | |
| | | String info = Constants.MqttTopic.sub_lockInfo.substring(Constants.MqttTopic.sub_lockInfo.lastIndexOf("/")+1) ; |
| | | String closeLock = Constants.MqttTopic.sub_closeLock.substring(Constants.MqttTopic.sub_closeLock.lastIndexOf("/")+1) ; |
| | | String health = Constants.MqttTopic.sub_health.substring(Constants.MqttTopic.sub_health.lastIndexOf("/")+1) ; |
| | | String adminCard = Constants.MqttTopic.sub_adminCard.substring(Constants.MqttTopic.sub_adminCard.lastIndexOf("/")+1) ; |
| | | String siteInfo = Constants.MqttTopic.sub_siteInfo.substring(Constants.MqttTopic.sub_siteInfo.lastIndexOf("/")+1) ; |
| | | String brokers = "brokers"; |
| | | if(!StringUtils.contains(topic, brokers)){ |
| | | if(topic.indexOf(Constants.MqttTopic.topic_index)!=0 |
| | | ||topic.split("/").length < 4 |
| | | || (!StringUtils.contains(topic, info) |
| | | &&!StringUtils.contains(topic, siteInfo) |
| | | &&!StringUtils.contains(topic, adminCard) |
| | | &&!StringUtils.contains(topic, health) |
| | | &&!StringUtils.contains(topic,closeLock))){ |
| | | log.error("mqtt消息订阅===========无效数据========"+param); |
| | |
| | | MqttLog mqttLog = new MqttLog(); |
| | | mqttLog.setMsgId(msgId); |
| | | mqttLog.setTopic(topic); |
| | | int msgCount =mqttLogMapper.selectCount(new QueryWrapper<MqttLog>().lambda().eq(MqttLog::getMsg, param).eq(MqttLog::getType, Constants.ZERO)); |
| | | long msgCount =mqttLogMapper.selectCount(new QueryWrapper<MqttLog>().lambda().eq(MqttLog::getMsg, param).eq(MqttLog::getType, Constants.ZERO)); |
| | | if(msgCount>0){ |
| | | log.error("mqtt消息订阅==============已消费数据====="+param); |
| | | return; |
| | |
| | | } |
| | | if(StringUtils.contains(topic, info)){ |
| | | //如果锁头信息上报 |
| | | String lockid = ss[3];//锁头编码 |
| | | if( StringUtils.isBlank(lockid)){ |
| | | Integer lockid = Constants.formatIntegerFromStr(ss[3]) ;//锁头编码 |
| | | if( lockid == null){ |
| | | //如果锁头编码为空 |
| | | log.error("mqtt消息订阅==============无效数据====="+topic+param); |
| | | return; |
| | |
| | | log.info("mqtt消息订阅=========锁信息==========成功"); |
| | | }else if(StringUtils.contains(topic, closeLock)){ |
| | | //如果还车上报 |
| | | String lockid = ss[3];//锁头编码 |
| | | if( StringUtils.isBlank(lockid)){ |
| | | Integer lockid = Constants.formatIntegerFromStr(ss[3]);//锁头编码 |
| | | if( lockid == null){ |
| | | //如果锁头编码为空 |
| | | log.error("mqtt消息订阅==============无效数据====="+topic+param); |
| | | return; |
| | |
| | | site.setId(siteid); |
| | | site.setOnline(Constants.ZERO); |
| | | site.setLastLinkDate(new Date()); |
| | | sitesMapper.updateById(site);//更新站点状态 |
| | | sitesService.updateByMqtt(site);//更新站点状态 |
| | | logInfo = "mqtt消息订阅心跳消息"; |
| | | log.info("mqtt消息订阅=========心跳消息==========成功"); |
| | | |
| | | }else if(StringUtils.contains(topic, adminCard)){ |
| | | //管理员刷卡开锁 |
| | | JSONObject pjson = JSONObject.parseObject(param); |
| | | ActionLog actionLog = new ActionLog(); |
| | | actionLog.setParam3(pjson.getString("bikeCode")); |
| | | actionLog.setParam2(pjson.getString("lockId")); |
| | | actionLog.setTitle(pjson.getString("cardNo")); |
| | | actionLog.setParam(siteid); |
| | | actionLog.setType(Constants.TWO); |
| | | actionLog.setIsdeleted(Constants.ZERO); |
| | | actionLog.setCreateDate(new Date()); |
| | | actionLogService.create(actionLog); |
| | | logInfo = "管理员刷卡开锁"; |
| | | log.info("mqtt消息订阅=========管理员刷卡开锁==========成功"); |
| | | } else if(StringUtils.contains(topic, siteInfo)){ |
| | | //如果锁头全量信息上报 |
| | | JSONObject pjson = JSONObject.parseObject(param); |
| | | Sites sites = new Sites(); |
| | | sites.setId(siteid); |
| | | sites.setClientVersion(pjson.getString("version")); |
| | | sites.setLockNum(pjson.getInteger("locks")); |
| | | sitesService.dealSiteLocks(sites); |
| | | logInfo = "mqtt消息订阅锁头全量信息上报"; |
| | | log.info("mqtt消息订阅=========锁头全量信息上报==========成功"); |
| | | } |
| | | }else { |
| | | //如果站点上下线消息 |
| | |
| | | log.error("mqtt消息订阅==============无效订阅状态====="+topic+param); |
| | | return; |
| | | } |
| | | Sites site = sitesMapper.selectById(clientId); |
| | | Sites site = sitesService.findById(clientId); |
| | | if(site == null){ |
| | | log.error("mqtt消息订阅==============无效订阅状态====="+topic+param); |
| | | return; |
| | |
| | | site.setOnline(Constants.ZERO); |
| | | } |
| | | site.setLastLinkDate(new Date()); |
| | | sitesMapper.updateById(site);//更新站点状态 |
| | | sitesService.updateByMqtt(site);//更新站点状态 |
| | | log.info("mqtt消息订阅=========站点上下线==========成功"); |
| | | } |
| | | }catch (BusinessException e){ |
| | |
| | | } |
| | | createSubLog(topic,msgId,logId,result,param,logInfo); |
| | | } |
| | | |
| | | |
| | | |
| | | private void createSubLog(String topic, String msgId,String logId, int result,String param,String info) { |
| | | MqttLog log = new MqttLog(); |
| | | log.setId(logId); |