宠物笼绑定相关接口
This commit is contained in:
parent
818cff9b3f
commit
10626d44ae
|
|
@ -566,6 +566,9 @@ public class BaseServiceImpl implements BaseService {
|
||||||
}
|
}
|
||||||
//需要新增
|
//需要新增
|
||||||
if (bln) {
|
if (bln) {
|
||||||
|
if (device.getHardwareType() != null && device.getHardwareType().equals("3f")) {
|
||||||
|
return IfishUtil.returnJson(ResultEnum.fail101.getKey(), "设备类型不匹配,请重新选择入口绑定");
|
||||||
|
}
|
||||||
//新增关联关系
|
//新增关联关系
|
||||||
if (device.getHardwareType() != null && device.getHardwareType().equals("3a")) {
|
if (device.getHardwareType() != null && device.getHardwareType().equals("3a")) {
|
||||||
deviceUser.setShowName("加热器" + (int) (Math.random() * 9000 + 1000));
|
deviceUser.setShowName("加热器" + (int) (Math.random() * 9000 + 1000));
|
||||||
|
|
@ -593,8 +596,7 @@ public class BaseServiceImpl implements BaseService {
|
||||||
public Object bindPetDevice(User user, String macAddress, String storeName) {
|
public Object bindPetDevice(User user, String macAddress, String storeName) {
|
||||||
System.out.println("bindPetDevice --- userId : " + user.getUserId() + ", mac : " + macAddress + ", storeName : " + storeName);
|
System.out.println("bindPetDevice --- userId : " + user.getUserId() + ", mac : " + macAddress + ", storeName : " + storeName);
|
||||||
User tmpUser = userDao.get(user.getUserId());
|
User tmpUser = userDao.get(user.getUserId());
|
||||||
//新增用户拥有设备
|
|
||||||
DevicePetUser devicePetUser = new DevicePetUser();
|
|
||||||
Device device = this.deviceDao.findUniqueByProperty(Restrictions.eq("macAddress", macAddress));
|
Device device = this.deviceDao.findUniqueByProperty(Restrictions.eq("macAddress", macAddress));
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
//新增设备信息
|
//新增设备信息
|
||||||
|
|
@ -607,30 +609,83 @@ public class BaseServiceImpl implements BaseService {
|
||||||
device.setCreateDate(date);
|
device.setCreateDate(date);
|
||||||
device.setCreateTime(date);
|
device.setCreateTime(date);
|
||||||
device = this.deviceDao.save(device);
|
device = this.deviceDao.save(device);
|
||||||
} else if (!device.getHardwareType().equals("3f")) {
|
}
|
||||||
|
if (device.getHardwareType() != null && !device.getHardwareType().equals("3f")) {
|
||||||
return IfishUtil.returnJson(ResultEnum.fail101.getKey(), "设备类型不匹配,请重新选择入口绑定");
|
return IfishUtil.returnJson(ResultEnum.fail101.getKey(), "设备类型不匹配,请重新选择入口绑定");
|
||||||
} else {
|
}
|
||||||
List<DevicePetUser> devicePetUsers = devicePetUserDao.findByDeviceId(device.getDeviceId());
|
//新增用户拥有设备
|
||||||
|
DevicePetUser devicePetUser = devicePetUserDao.getDevicePetUserByUseridAndDeviceId(String.valueOf(user.getUserId()), String.valueOf(device.getDeviceId()));
|
||||||
|
List<DevicePetUser> devicePetUsers = devicePetUserDao.findByDeviceId(device.getDeviceId() == null ? 0 : device.getDeviceId());
|
||||||
|
if (devicePetUser != null) {
|
||||||
|
if (devicePetUser.getIsMaster() != 0) {
|
||||||
for (DevicePetUser petUser : devicePetUsers) {
|
for (DevicePetUser petUser : devicePetUsers) {
|
||||||
if (petUser.getPriId().getUserId().intValue() == user.getUserId().intValue() && petUser.getIsMaster() == 0) {
|
Integer userId = petUser.getPriId().getUserId();
|
||||||
|
Integer deviceId = petUser.getPriId().getDeviceId();
|
||||||
|
User tu = this.userDao.get(userId);
|
||||||
|
if (tu != null && tu.getUserId().intValue() != user.getUserId().intValue()) {
|
||||||
|
String timestamp = IfishUtil.format(new Date());
|
||||||
|
//基本参数
|
||||||
|
Map<String, String> baseMap = new HashMap<String, String>();
|
||||||
|
baseMap.put("title", PushTypeEnum.remove_device.getValue());
|
||||||
|
baseMap.put("content", "你已于" + timestamp + "失去对“" + petUser.getShowName() + "”设备的控制权");
|
||||||
|
baseMap.put("user_id", userId.toString());
|
||||||
|
baseMap.put("loginType", tu.getLoginType());
|
||||||
|
//推送参数
|
||||||
|
Map<String, String> pushMap = new HashMap<String, String>();
|
||||||
|
pushMap.put("device_id", deviceId.toString());
|
||||||
|
pushMap.put("device_name", petUser.getShowName());
|
||||||
|
pushMap.put("timestamp", timestamp);
|
||||||
|
pushMap.put("msg_type", PushTypeEnum.remove_device.getKey());
|
||||||
|
//推送消息
|
||||||
|
jPushNotifcation(baseMap, pushMap);
|
||||||
|
}
|
||||||
|
devicePetUserDao.delete(petUser);
|
||||||
|
//删除设备和摄像头关系
|
||||||
|
DeviceCamera deviceCamera = this.deviceCameraDao.findUniqueByProperty(Restrictions.eq("deviceCameraId.deviceId", petUser.getPriId().getDeviceId()));
|
||||||
|
if (deviceCamera != null) {
|
||||||
|
this.deviceCameraDao.delete(deviceCamera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
devicePetUser.setIsMaster(0);
|
||||||
|
devicePetUserDao.update(devicePetUser);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (DevicePetUser petUser : devicePetUsers) {
|
||||||
|
Integer userId = petUser.getPriId().getUserId();
|
||||||
|
Integer deviceId = petUser.getPriId().getDeviceId();
|
||||||
|
User tu = this.userDao.get(userId);
|
||||||
|
if (tu != null && tu.getUserId().intValue() != user.getUserId().intValue()) {
|
||||||
|
String timestamp = IfishUtil.format(new Date());
|
||||||
|
//基本参数
|
||||||
|
Map<String, String> baseMap = new HashMap<String, String>();
|
||||||
|
baseMap.put("title", PushTypeEnum.remove_device.getValue());
|
||||||
|
baseMap.put("content", "你已于" + timestamp + "失去对“" + petUser.getShowName() + "”设备的控制权");
|
||||||
|
baseMap.put("user_id", userId.toString());
|
||||||
|
baseMap.put("loginType", tu.getLoginType());
|
||||||
|
//推送参数
|
||||||
|
Map<String, String> pushMap = new HashMap<String, String>();
|
||||||
|
pushMap.put("device_id", deviceId.toString());
|
||||||
|
pushMap.put("device_name", petUser.getShowName());
|
||||||
|
pushMap.put("timestamp", timestamp);
|
||||||
|
pushMap.put("msg_type", PushTypeEnum.remove_device.getKey());
|
||||||
|
//推送消息
|
||||||
|
jPushNotifcation(baseMap, pushMap);
|
||||||
|
}
|
||||||
|
devicePetUserDao.delete(petUser);
|
||||||
|
//删除设备和摄像头关系
|
||||||
|
DeviceCamera deviceCamera = this.deviceCameraDao.findUniqueByProperty(Restrictions.eq("deviceCameraId.deviceId", petUser.getPriId().getDeviceId()));
|
||||||
|
if (deviceCamera != null) {
|
||||||
|
this.deviceCameraDao.delete(deviceCamera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
devicePetUser = new DevicePetUser();
|
||||||
devicePetUser.getPriId().setUserId(tmpUser.getUserId());
|
devicePetUser.getPriId().setUserId(tmpUser.getUserId());
|
||||||
devicePetUser.getPriId().setDeviceId(device.getDeviceId());
|
devicePetUser.getPriId().setDeviceId(device.getDeviceId());
|
||||||
devicePetUser.setShowName("宠物笼" + (int) (Math.random() * 9000 + 1000));
|
devicePetUser.setShowName("宠物笼" + (int) (Math.random() * 9000 + 1000));
|
||||||
devicePetUser.setStoreName(storeName);
|
devicePetUser.setStoreName(storeName);
|
||||||
devicePetUser.setIsMaster(0);
|
devicePetUser.setIsMaster(0);
|
||||||
this.devicePetUserDao.update(devicePetUser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
devicePetUser.getPriId().setUserId(tmpUser.getUserId());
|
|
||||||
devicePetUser.getPriId().setDeviceId(device.getDeviceId());
|
|
||||||
devicePetUser.setShowName("宠物笼" + (int) (Math.random() * 9000 + 1000));
|
|
||||||
devicePetUser.setStoreName(storeName);
|
|
||||||
devicePetUser.setIsMaster(0);
|
|
||||||
|
|
||||||
this.devicePetUserDao.save(devicePetUser);
|
this.devicePetUserDao.save(devicePetUser);
|
||||||
|
}
|
||||||
//封装设备返回信息
|
//封装设备返回信息
|
||||||
return IfishUtil.returnJson(ResultEnum.success.getKey(), getDeviceInfo(device, devicePetUser));
|
return IfishUtil.returnJson(ResultEnum.success.getKey(), getDeviceInfo(device, devicePetUser));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue