提交 6ffa77ab authored 作者: 林业通's avatar 林业通

推送修改

上级 4a67f458
......@@ -42,7 +42,7 @@ public interface OtherShDeviceDao extends BaseMapper<ShDeviceEntity> {
Map<String, Object> info(Integer id);
@Select("select id from sh_device where online_status = 2 and online_time is not null and now() > date_add(online_time,interval 5 minute)")
@Select("select id from sh_device where online_status = 2 and online_time is not null and now() > date_add(online_time,interval 2 minute)")
List<Map<String, Object>> timeout();
@Select("<script>" +
......
package tech.glinfo.enbao.modules.sh.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;
import tech.glinfo.enbao.common.utils.Constant;
import tech.glinfo.enbao.common.utils.MapUtils;
import tech.glinfo.enbao.common.utils.PageUtils;
import tech.glinfo.enbao.common.utils.StringUtils;
import tech.glinfo.enbao.modules.sh.dao.OtherShDeviceDao;
import tech.glinfo.enbao.modules.sh.entity.ShDeviceEntity;
import tech.glinfo.enbao.modules.sh.service.OtherShDeviceService;
import javax.jms.Topic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -21,6 +28,11 @@ import java.util.Map;
@Service("otherShDeviceService")
public class OtherShDeviceServiceImpl extends ServiceImpl<OtherShDeviceDao, ShDeviceEntity> implements OtherShDeviceService {
@Autowired
private Topic socketioTopic;
@Autowired
private JmsMessagingTemplate jmsTemplate;
@Override
public PageUtils queryPage(Map<String, Object> params) {
......@@ -34,8 +46,6 @@ public class OtherShDeviceServiceImpl extends ServiceImpl<OtherShDeviceDao, ShDe
start = time + " 00:00:00";
end = time + " 59:59:59";
}
System.out.println(start);
System.out.println(end);
params.put("start", start);
params.put("end", end);
page.setRecords(this.baseMapper.list(page, params));
......@@ -51,13 +61,24 @@ public class OtherShDeviceServiceImpl extends ServiceImpl<OtherShDeviceDao, ShDe
@Override
public void timeout() {
List<Map<String, Object>> list = this.baseMapper.timeout();
List<Map<String, String>> mapList = new ArrayList<>();
for (Map<String, Object> map : list) {
ShDeviceEntity entity = new ShDeviceEntity();
entity.setId((Integer) map.get("id"));
Integer id = (Integer) map.get("id");
entity.setId(id);
entity.setOnlineStatus(3);
this.updateById(entity);
Map<String, String> map1 = new HashMap<>();
map1.put("deviceId", String.valueOf(id));
map1.put("status", "3");
mapList.add(map1);
//发送到单个设备
jmsTemplate.convertAndSend(socketioTopic, JSON.toJSONString(new MapUtils().put("deviceId", String.valueOf(id)).put("status", "3")));
}
//发送到主页所有设备
if (mapList.size() > 0) {
jmsTemplate.convertAndSend(socketioTopic, JSON.toJSONString(new MapUtils().put("deviceId", "onlineStatus").put("list", JSON.toJSONString(mapList))));
}
//智能锁密码过期
this.baseMapper.updateDevicePassword();
}
......
......@@ -25,8 +25,7 @@ import tech.glinfo.enbao.modules.websocket.WebSocketServer;
import javax.jms.Topic;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Map;
import java.util.*;
@Component
public class MqConsumer {
......@@ -132,6 +131,12 @@ public class MqConsumer {
return;
}
if (device.getOnlineStatus() == 1 || device.getOnlineStatus() == 3) {
List<Map<String, String>> mapList = new ArrayList<>();
Map<String, String> map1 = new HashMap<>();
map1.put("deviceId", String.valueOf(device.getId()));
map1.put("status", "2");
mapList.add(map1);
jmsTemplate.convertAndSend(socketioTopic, JSON.toJSONString(new MapUtils().put("deviceId", "onlineStatus").put("list", JSON.toJSONString(mapList))));
//更新设备状态为在线
new Thread(() -> {
ShDeviceEntity deviceEntity = new ShDeviceEntity();
......
......@@ -46,6 +46,7 @@ public class OtherShFamilyServiceImpl extends ServiceImpl<OtherShFamilyDao, ShFa
member.setFamilyId(family.getId());
member.setUserId(user.getId());
member.setIsAdmin(1);//管理员
member.setStatus(2);
shFamilyMemberService.save(member);
return R.ok();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论