diff --git a/src/main/java/com/ifish/dao/DevicePetUserDao.java b/src/main/java/com/ifish/dao/DevicePetUserDao.java new file mode 100644 index 0000000..fafd8e5 --- /dev/null +++ b/src/main/java/com/ifish/dao/DevicePetUserDao.java @@ -0,0 +1,18 @@ +package com.ifish.dao; + +import com.ifish.entity.DevicePetUser; +import org.hibernate.criterion.Criterion; + +import java.util.List; + +/** + * @ClassName: DeviceUserDao + * @Description: TODO + * @author ggw + * + */ +public interface DevicePetUserDao{ + + List getListByProperty(Criterion... criterions); + +} diff --git a/src/main/java/com/ifish/daoImpl/DevicePetUserDaoImpl.java b/src/main/java/com/ifish/daoImpl/DevicePetUserDaoImpl.java new file mode 100644 index 0000000..c81a050 --- /dev/null +++ b/src/main/java/com/ifish/daoImpl/DevicePetUserDaoImpl.java @@ -0,0 +1,32 @@ +package com.ifish.daoImpl; + +import com.ifish.dao.DevicePetUserDao; +import com.ifish.entity.DevicePetUser; +import com.ifish.entity.DeviceUser; +import com.ifish.entity.PriId; +import com.ifish.hibernate.HibernateBaseDao; +import org.hibernate.criterion.Criterion; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @ClassName: DeviceUserDaoImpl + * @Description: TODO + * @author ggw + * + */ + +@Repository("devicePetUserDao") +public class DevicePetUserDaoImpl extends HibernateBaseDao implements DevicePetUserDao { + + @Override + protected Class getEntityClass() { + return DevicePetUser.class; + } + + @Override + public List getListByProperty(Criterion... criterions) { + return this.findByProperty(criterions); + } +} diff --git a/src/main/java/com/ifish/entity/DevicePetUser.java b/src/main/java/com/ifish/entity/DevicePetUser.java new file mode 100644 index 0000000..331ae90 --- /dev/null +++ b/src/main/java/com/ifish/entity/DevicePetUser.java @@ -0,0 +1,87 @@ +package com.ifish.entity; + +import java.io.Serializable; +import java.util.Date; + +/** + * @ClassName: tbl_device_user + * @date 2015年7月2日 下午16:40:00 + * + */ +public class DevicePetUser implements Serializable{ + + private static final long serialVersionUID = -6056043883433438749L; + //ID + private PriId priId = new PriId(); + //显示名称 + private String showName; + private String storeName; + private Integer isMaster; + //创建时间 + private Date createTime; + + //用户 + private User user = new User(); + //设备 + private Device device = new Device(); + public DevicePetUser() {} + + public DevicePetUser(PriId priId, String showName, String storeName) { + this.priId = priId; + this.showName = showName; + this.storeName = storeName; + } + + public PriId getPriId() { + return priId; + } + public void setPriId(PriId priId) { + this.priId = priId; + } + public String getShowName() { + return showName; + } + public void setShowName(String showName) { + this.showName = showName; + } + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public Integer getIsMaster() { + return isMaster; + } + + public void setIsMaster(Integer isMaster) { + this.isMaster = isMaster; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Device getDevice() { + return device; + } + + public void setDevice(Device device) { + this.device = device; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } +} diff --git a/src/main/java/com/ifish/entity/hbm/DevicePetUser.hbm.xml b/src/main/java/com/ifish/entity/hbm/DevicePetUser.hbm.xml new file mode 100644 index 0000000..b654b5d --- /dev/null +++ b/src/main/java/com/ifish/entity/hbm/DevicePetUser.hbm.xml @@ -0,0 +1,17 @@ + + + + + false + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/ifish/service/DeviceService.java b/src/main/java/com/ifish/service/DeviceService.java index e812e7f..a522177 100644 --- a/src/main/java/com/ifish/service/DeviceService.java +++ b/src/main/java/com/ifish/service/DeviceService.java @@ -32,7 +32,9 @@ public interface DeviceService { DeviceUser getUniqueByProperty(String macAddress); List getListByProperty(Integer deviceId); - + + List getPetListByProperty(Integer deviceId); + LoginRecord save(LoginRecord loginRecord); FactoryList getFactoryListById(String factoryCode); diff --git a/src/main/java/com/ifish/serviceImpl/DeviceServiceImpl.java b/src/main/java/com/ifish/serviceImpl/DeviceServiceImpl.java index aa87840..28ad3fc 100644 --- a/src/main/java/com/ifish/serviceImpl/DeviceServiceImpl.java +++ b/src/main/java/com/ifish/serviceImpl/DeviceServiceImpl.java @@ -44,6 +44,8 @@ public class DeviceServiceImpl implements DeviceService { @Autowired private DeviceUserDao deviceUserDao; @Autowired + private DevicePetUserDao devicePetUserDao; + @Autowired private FactoryListDao factoryListDao; @Autowired private HardwareTypeDao hardwareTypeDao; @@ -145,6 +147,11 @@ public class DeviceServiceImpl implements DeviceService { return deviceUserDao.getListByProperty(Restrictions.eq("priId.deviceId", deviceId)); } + @Override + public List getPetListByProperty(Integer deviceId) { + return devicePetUserDao.getListByProperty(Restrictions.eq("priId.deviceId", deviceId)); + } + @Override public void updateWarnOnoff(String macAddress,String onOff) { Device device = this.deviceDao.getUniqueByProperty("macAddress", macAddress); diff --git a/src/main/java/com/ifish/socketNew/SomeServer.java b/src/main/java/com/ifish/socketNew/SomeServer.java index 71346a2..2cd2896 100644 --- a/src/main/java/com/ifish/socketNew/SomeServer.java +++ b/src/main/java/com/ifish/socketNew/SomeServer.java @@ -364,32 +364,7 @@ public class SomeServer { Integer userId = deviceUser.getPriId().getUserId(); String showName = deviceUser.getShowName(); String msg = "【" + title + "】你的水族箱“" + showName + "”" + contont; - User user = userService.findById(userId); - if(user!=null){ - //推送记录 - PushList pushList = new PushList(); - //记录推送 - pushList.setUserId(userId); - pushList.setDeviceId(deviceId); - pushList.setPhoneType("ALL"); - pushList.setShowName(showName); - pushList.setPushType(PushTypeEnum.ph_warn.getKey()); - pushList.setPushTitle(title); - pushList.setPushContext(msg); - pushList.setNumber1(device.getNumber1()); - pushList.setNumber2(device.getNumber2()); - pushList.setNumber3(device.getNumber3()); - pushList.setNumber4(device.getNumber4()); - pushList.setNumber5(device.getNumber5()); - JSONObject data = JSON.parseObject(JSON.toJSONString(pushList)); - QueueEventEntity eventEntity = new QueueEventEntity(); - eventEntity.setEventName("com.ifish7.mq.queues.event.PushNotifcationEvent"); - eventEntity.setEventProcess("deviceNotifcationPlus"); - QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.user.entity.TblPushList",data); - eventEntity.setEventBody(eventBody); - //推送至消息推送队列 - sendPushQueueMessage(JSONObject.toJSONString(eventEntity)); - } + setPushMsg(title, device, deviceId, userId, showName, msg, PushTypeEnum.ph_warn); } } }catch (Exception e) { @@ -412,38 +387,25 @@ public class SomeServer { //是否开启预警 String onOff = device.getOnOff(); if(onOff!=null && onOff.equals(BooleanEnum.YES.getKey())){ - //绑定设备的用户 - List list = deviceService.getListByProperty(device.getDeviceId()); - for (DeviceUser deviceUser : list) { - Integer userId = deviceUser.getPriId().getUserId(); - String showName = deviceUser.getShowName(); - String timestamp = IfishUtil.format(new Date()); - String msg = "【"+title+"】你的水族箱“"+showName+"”在"+timestamp+contont; - User user = userService.findById(userId); - if(user!=null){ - //推送记录 - PushList pushList = new PushList(); - //记录推送 - pushList.setUserId(userId); - pushList.setDeviceId(deviceId); - pushList.setPhoneType("ALL"); - pushList.setShowName(showName); - pushList.setPushType(PushTypeEnum.wendu_warn.getKey()); - pushList.setPushTitle(title); - pushList.setPushContext(msg); - pushList.setNumber1(device.getNumber1()); - pushList.setNumber2(device.getNumber2()); - pushList.setNumber3(device.getNumber3()); - pushList.setNumber4(device.getNumber4()); - pushList.setNumber5(device.getNumber5()); - JSONObject data = JSON.parseObject(JSON.toJSONString(pushList)); - QueueEventEntity eventEntity = new QueueEventEntity(); - eventEntity.setEventName("com.ifish7.mq.queues.event.PushNotifcationEvent"); - eventEntity.setEventProcess("deviceNotifcationPlus"); - QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.user.entity.TblPushList",data); - eventEntity.setEventBody(eventBody); - //推送至消息推送队列 - sendPushQueueMessage(JSONObject.toJSONString(eventEntity)); + //宠物笼设备 + if (device.getHardwareType().equals("3f")) { + List petUserList = deviceService.getPetListByProperty(deviceId); + for (DevicePetUser deviceUser : petUserList) { + Integer userId = deviceUser.getPriId().getUserId(); + String showName = deviceUser.getShowName(); + String timestamp = IfishUtil.format(new Date()); + String msg = "【"+title+"】你的宠物笼“"+showName+"”在"+timestamp+contont; + setPushMsg(title, device, deviceId, userId, showName, msg, PushTypeEnum.wendu_warn); + } + } else { + //绑定设备的用户 + List list = deviceService.getListByProperty(device.getDeviceId()); + for (DeviceUser deviceUser : list) { + Integer userId = deviceUser.getPriId().getUserId(); + String showName = deviceUser.getShowName(); + String timestamp = IfishUtil.format(new Date()); + String msg = "【"+title+"】你的水族箱“"+showName+"”在"+timestamp+contont; + setPushMsg(title, device, deviceId, userId, showName, msg, PushTypeEnum.wendu_warn); } } } @@ -453,6 +415,35 @@ public class SomeServer { } } + private void setPushMsg(String title, Device device, Integer deviceId, Integer userId, String showName, String msg, PushTypeEnum wendu_warn) throws JMSException { + User user = userService.findById(userId); + if (user != null) { + //推送记录 + PushList pushList = new PushList(); + //记录推送 + pushList.setUserId(userId); + pushList.setDeviceId(deviceId); + pushList.setPhoneType("ALL"); + pushList.setShowName(showName); + pushList.setPushType(wendu_warn.getKey()); + pushList.setPushTitle(title); + pushList.setPushContext(msg); + pushList.setNumber1(device.getNumber1()); + pushList.setNumber2(device.getNumber2()); + pushList.setNumber3(device.getNumber3()); + pushList.setNumber4(device.getNumber4()); + pushList.setNumber5(device.getNumber5()); + JSONObject data = JSON.parseObject(JSON.toJSONString(pushList)); + QueueEventEntity eventEntity = new QueueEventEntity(); + eventEntity.setEventName("com.ifish7.mq.queues.event.PushNotifcationEvent"); + eventEntity.setEventProcess("deviceNotifcationPlus"); + QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.user.entity.TblPushList", data); + eventEntity.setEventBody(eventBody); + //推送至消息推送队列 + sendPushQueueMessage(JSONObject.toJSONString(eventEntity)); + } + } + /** * 推送Push消息队列