From 2c4f2eef6559b27ecbd37ce0c30acc9bb007d808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E6=B4=AA=E9=BE=99?= <599179587@qq.com> Date: Wed, 2 Aug 2017 13:17:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ifish/controller/LiveRoom.java | 19 ++++++++-- .../java/com/ifish/helper/DeviceHelper.java | 23 ++++++++++++ .../java/com/ifish/helper/DeviceHelperI.java | 25 ++++++++----- .../java/com/ifish/helper/LiveRoomHelper.java | 36 +++++++++++++++++++ .../com/ifish/helper/LiveRoomHelperI.java | 9 +++++ .../java/com/ifish/helper/RedisKeyHelper.java | 36 ++++++++++++++++--- 6 files changed, 133 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/ifish/controller/LiveRoom.java b/src/main/java/com/ifish/controller/LiveRoom.java index c77412e..8893182 100644 --- a/src/main/java/com/ifish/controller/LiveRoom.java +++ b/src/main/java/com/ifish/controller/LiveRoom.java @@ -155,12 +155,27 @@ public class LiveRoom { * @return */ @RequestMapping(value = "/liveRoom/v3/updateLiveRoom.do", method = RequestMethod.POST) - public Object updateLiveRoom(MultipartFile fileUpload, Tbl_Live_Room liveRoom) { + public Object updateLiveRoom(Tbl_Live_Room liveRoom) { + try { + return liveRoomHelperI.updateLiveRoom(liveRoom); + } catch (Exception e) { + } + return IfishUtil.returnJson(ResultEnum.fail101.getKey(), ""); + } + + /** + * 修改直播间展示图片 + * + * @param fileUpload + * @param liveRoom + * @return + */ + @RequestMapping(value = "/liveRoom/v3/updateLiveRoomImg.do", method = RequestMethod.POST) + public Object updateLiveRoomImg(MultipartFile fileUpload, Tbl_Live_Room liveRoom) { try { return liveRoomHelperI.updateLiveRoom(fileUpload, liveRoom); } catch (Exception e) { } return IfishUtil.returnJson(ResultEnum.fail101.getKey(), ""); } - } diff --git a/src/main/java/com/ifish/helper/DeviceHelper.java b/src/main/java/com/ifish/helper/DeviceHelper.java index fae0c25..cfe7dc5 100644 --- a/src/main/java/com/ifish/helper/DeviceHelper.java +++ b/src/main/java/com/ifish/helper/DeviceHelper.java @@ -200,6 +200,29 @@ public class DeviceHelper implements DeviceHelperI { return device; } + /** + * 根据设备ID获取设备统计信息 + * + * @param deviceId + * @return + * @throws Exception + */ + @Override + public Tbl_Device_Statistics getDeviceStatisticsByMacAddress(String mackAddress) throws Exception { + Tbl_Device_Statistics device = null; + String key = redisKeyHelperI.getTbl_Device_StatisticsRedisKeyByMacAddress(mackAddress); + String redisString = redisHelperI.getRedis(key); + if (StringUtils.isNotBlank(redisString)) { + device = (Tbl_Device_Statistics) IfishUtil.JsonToBean(redisString, Tbl_Device_Statistics.class); + } else { + device = tbl_Device_Mapper.getDevStatisticsByMacAddress(mackAddress); + if (device != null && device.getDeviceId() > 0) { + redisHelperI.setRedis(key, IfishUtil.ObjectToJson(device)); + } + } + return device; + } + /** * 绑定设备 * diff --git a/src/main/java/com/ifish/helper/DeviceHelperI.java b/src/main/java/com/ifish/helper/DeviceHelperI.java index 081ce4e..d7e1806 100644 --- a/src/main/java/com/ifish/helper/DeviceHelperI.java +++ b/src/main/java/com/ifish/helper/DeviceHelperI.java @@ -42,6 +42,15 @@ public interface DeviceHelperI { */ public Tbl_Device_Statistics getDeviceStatisticsByDeviceId(Integer deviceId) throws Exception; + /** + * 根据设备ID获取设备统计信息 + * + * @param deviceId + * @return + * @throws Exception + */ + public Tbl_Device_Statistics getDeviceStatisticsByMacAddress(String macAddress) throws Exception; + /** * 根据设备Id获取设备详情 * @@ -61,6 +70,14 @@ public interface DeviceHelperI { */ Tbl_Device getDeviceByMacAddress(String macAddress) throws Exception; + /** + * 根据摄像头ID获取设备信息 + * + * @param cameraId + * @return + */ + Tbl_Device getDeviceByCameraId(String cameraId) throws Exception; + /** * 绑定设备 * @@ -88,14 +105,6 @@ public interface DeviceHelperI { */ Object bindCamera(Integer userId, String cameraId); - /** - * 根据摄像头ID获取设备信息 - * - * @param cameraId - * @return - */ - Tbl_Device getDeviceByCameraId(String cameraId) throws Exception; - /** * 修改设备信息 * diff --git a/src/main/java/com/ifish/helper/LiveRoomHelper.java b/src/main/java/com/ifish/helper/LiveRoomHelper.java index d35b30a..c722e96 100644 --- a/src/main/java/com/ifish/helper/LiveRoomHelper.java +++ b/src/main/java/com/ifish/helper/LiveRoomHelper.java @@ -396,8 +396,10 @@ public class LiveRoomHelper implements LiveRoomHelperI { //查找直播间信息 Tbl_Live_Room curLiveRoom = getTbl_Live_RoomByRoomId(roomId); if (curLiveRoom != null) { + Tbl_User user = userHelperI.getUserById(curLiveRoom.getUserId()); Map map = new HashMap(); map.put("roomId", roomId); + map.put("userImg", user.getUserImg()); map.put("userId", curLiveRoom.getUserId()); map.put("cameraId", curLiveRoom.getCameraId()); map.put("roomName", curLiveRoom.getRoomName()); @@ -429,8 +431,10 @@ public class LiveRoomHelper implements LiveRoomHelperI { //查找直播间信息 Tbl_Live_Room curLiveRoom = getTbl_Live_RoomByCameraId(cameraId); if (curLiveRoom != null) { + Tbl_User user = userHelperI.getUserById(curLiveRoom.getUserId()); Map map = new HashMap(); map.put("roomId", curLiveRoom.getRoomId()); + map.put("userImg", user.getUserImg()); map.put("cameraId", curLiveRoom.getCameraId()); map.put("userId", curLiveRoom.getUserId()); map.put("roomName", curLiveRoom.getRoomName()); @@ -510,12 +514,44 @@ public class LiveRoomHelper implements LiveRoomHelperI { public Object updateLiveRoom(MultipartFile fileUpload, Tbl_Live_Room liveRoom) { try { + if (StringUtils.isNotBlank(liveRoom.getRoomName())) { + String roomName = new String(liveRoom.getRoomName().getBytes("iso-8859-1"), "UTF-8"); + liveRoom.setRoomName(roomName); + } + if (StringUtils.isNotBlank(liveRoom.getRoomDesc())) { + String roomDesc = new String(liveRoom.getRoomDesc().getBytes("iso-8859-1"), "UTF-8"); + liveRoom.setRoomDesc(roomDesc); + } if (fileUpload != null && fileUpload.getSize() <= 1048576) { String file = fastDFSClientI.uploadFileToFastDFS(fileUpload); if (StringUtils.isNotBlank(file)) { liveRoom.setRoomImg(file); } } + + int i = tbl_Live_Room_Mapper.updateLiveRoom(liveRoom); + if (i > 0) { + redisKeyHelperI.deleteRedisByTbl_Live_Room(liveRoom); + Tbl_Live_Room live = getTbl_Live_RoomByRoomId(liveRoom.getRoomId()); + return IfishUtil.toJson(ResultEnum.success.getKey(), live); + } + } catch (Exception e) { + } + return IfishUtil.toJson(ResultEnum.fail101.getKey(), ""); + } + + /** + * 修改直播间 + * + * @param fileUpload + * @param liveRoom + * @return + */ + @Override + public Object updateLiveRoom(Tbl_Live_Room liveRoom) { + + try { + int i = tbl_Live_Room_Mapper.updateLiveRoom(liveRoom); if (i > 0) { redisKeyHelperI.deleteRedisByTbl_Live_Room(liveRoom); diff --git a/src/main/java/com/ifish/helper/LiveRoomHelperI.java b/src/main/java/com/ifish/helper/LiveRoomHelperI.java index 465c092..7f19d93 100644 --- a/src/main/java/com/ifish/helper/LiveRoomHelperI.java +++ b/src/main/java/com/ifish/helper/LiveRoomHelperI.java @@ -85,6 +85,15 @@ public interface LiveRoomHelperI { */ Object updateLiveRoom(MultipartFile fileUpload, Tbl_Live_Room liveRoom); + /** + * 修改直播间 + * + * @param fileUpload + * @param liveRoom + * @return + */ + Object updateLiveRoom(Tbl_Live_Room liveRoom); + /** * 直播间人气值加1 * diff --git a/src/main/java/com/ifish/helper/RedisKeyHelper.java b/src/main/java/com/ifish/helper/RedisKeyHelper.java index 3660293..a659f28 100644 --- a/src/main/java/com/ifish/helper/RedisKeyHelper.java +++ b/src/main/java/com/ifish/helper/RedisKeyHelper.java @@ -26,9 +26,10 @@ public class RedisKeyHelper implements RedisKeyHelperI { @Autowired private RedisHelperI redisHelperI; - @Autowired private DeviceHelperI deviceHelper; + @Autowired + private UserHelperI userHelperI; /** * 根据phoneNumber获取Tbl_User用户信息的Redis缓存key键值 @@ -376,8 +377,18 @@ public class RedisKeyHelper implements RedisKeyHelperI { */ @Override public void deleteRedisByTbl_Device(Tbl_Device device) { - deleteTbl_DeviceInfo(device); + try { + if (device.getDeviceId() != null && device.getDeviceId() != 0 && StringUtils.isBlank(device.getMacAddress())) { + device = deviceHelper.getDeviceById(device.getDeviceId()); + } + if (StringUtils.isNotBlank(device.getMacAddress()) && (device.getDeviceId() == null || device.getDeviceId() == 0)) { + device = deviceHelper.getDeviceByMacAddress(device.getMacAddress()); + } + if (StringUtils.isNotBlank(device.getCameraId()) && (device.getDeviceId() == null || device.getDeviceId() == 0)) { + device = deviceHelper.getDeviceByCameraId(device.getCameraId()); + } + deleteTbl_DeviceInfo(device); Tbl_Device_Statistics device_Statistics = deviceHelper.getDeviceStatisticsByDeviceId(device.getDeviceId()); deleteTbl_Device_StatisticsInfo(device_Statistics); } catch (Exception e) { @@ -404,8 +415,15 @@ public class RedisKeyHelper implements RedisKeyHelperI { */ @Override public void deleteRedisByTbl_Device_Statistics(Tbl_Device_Statistics device) { - deleteTbl_Device_StatisticsInfo(device); + try { + if (device.getDeviceId() != null && device.getDeviceId() != 0 && StringUtils.isBlank(device.getMacAddress())) { + device = deviceHelper.getDeviceStatisticsByDeviceId(device.getDeviceId()); + } + if (StringUtils.isNotBlank(device.getMacAddress()) && (device.getDeviceId() == null || device.getDeviceId() == 0)) { + device = deviceHelper.getDeviceStatisticsByMacAddress(device.getMacAddress()); + } + deleteTbl_Device_StatisticsInfo(device); Tbl_Device device1 = deviceHelper.getDeviceById(device.getDeviceId()); deleteTbl_DeviceInfo(device1); } catch (Exception e) { @@ -414,10 +432,10 @@ public class RedisKeyHelper implements RedisKeyHelperI { public void deleteTbl_Device_StatisticsInfo(Tbl_Device_Statistics device) { if (device.getDeviceId() != null && device.getDeviceId() > 0) { - redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByDeviceId(device.getDeviceId())); + redisHelperI.deleteRedis(getTbl_Device_StatisticsRedisKeyByDeviceId(device.getDeviceId())); } if (StringUtils.isNotBlank(device.getMacAddress())) { - redisHelperI.deleteRedis(getTbl_DeviceRedisKeyByMacAddress(device.getMacAddress())); + redisHelperI.deleteRedis(getTbl_Device_StatisticsRedisKeyByMacAddress(device.getMacAddress())); } } @@ -437,6 +455,7 @@ public class RedisKeyHelper implements RedisKeyHelperI { deleteTbl_Device_StatisticsInfo(device_Statistics); } catch (Exception e) { } + } public void deleteTbl_Device_UserInfo(Tbl_Device_User tbl_Device_User) { @@ -458,6 +477,12 @@ public class RedisKeyHelper implements RedisKeyHelperI { */ @Override public void deleteRedisByTbl_User(Tbl_User tbl_User) { + try { + if (tbl_User.getUserId() != null && tbl_User.getUserId() > 0) { + tbl_User = userHelperI.getUserById(tbl_User.getUserId()); + } + } catch (Exception e) { + } if (tbl_User.getUserId() != null && tbl_User.getUserId() > 0) { redisHelperI.deleteRedis(getTbl_UserRedisKeyByUserId(tbl_User.getUserId())); } @@ -482,6 +507,7 @@ public class RedisKeyHelper implements RedisKeyHelperI { */ @Override public void deleteRedisByTbl_Live_Room(Tbl_Live_Room live_Room) { + if (live_Room.getRoomId() != null && live_Room.getRoomId() > 0) { redisHelperI.deleteRedis(getTbl_Live_RoomRedisKeyByRoomId(live_Room.getRoomId())); }