From 230187426ea55da1a71ef7ccbc8f085ceccef712 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, 26 Jul 2017 15:46:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A0=B9=E6=8D=AE=E6=91=84=E5=83=8F=E5=A4=B4?= =?UTF-8?q?ID=E8=8E=B7=E5=8F=96=E8=AF=A6=E6=83=85=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=82=AE=E7=AE=B1=E7=99=BB=E9=99=86=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=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 +++++- src/main/java/com/ifish/controller/Login.java | 2 +- .../java/com/ifish/helper/LiveRoomHelper.java | 66 ++++++++++++++----- .../com/ifish/helper/LiveRoomHelperI.java | 10 ++- .../java/com/ifish/helper/RedisKeyHelper.java | 14 ++++ .../com/ifish/helper/RedisKeyHelperI.java | 8 +++ .../java/com/ifish/helper/UserHelper.java | 36 +++++----- .../ifish/mapper/Tbl_Live_Room_Mapper.java | 9 +++ src/main/java/com/ifish/util/RedisKey.java | 5 ++ 9 files changed, 133 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/ifish/controller/LiveRoom.java b/src/main/java/com/ifish/controller/LiveRoom.java index cec105b..a81bb58 100644 --- a/src/main/java/com/ifish/controller/LiveRoom.java +++ b/src/main/java/com/ifish/controller/LiveRoom.java @@ -107,10 +107,25 @@ public class LiveRoom { * @param roomId * @return */ - @RequestMapping(value = "/liveRoom/v3/getLiveRoomInfo.do", method = RequestMethod.GET) + @RequestMapping(value = "/liveRoom/v3/getLiveRoomInfoByRoomId", method = RequestMethod.GET) public Object getLiveRoomInfo(Integer roomId) { try { - return liveRoomHelperI.getLiveRoomInfo(roomId); + return liveRoomHelperI.getLiveRoomInfoByRoomId(roomId); + } catch (Exception e) { + } + return IfishUtil.returnJson(ResultEnum.fail101.getKey(), ""); + } + + /** + * 获取直播间信息 + * + * @param roomId + * @return + */ + @RequestMapping(value = "/liveRoom/v3/getLiveRoomInfoByCameraId", method = RequestMethod.GET) + public Object getLiveRoomInfo(String cameraId) { + try { + return liveRoomHelperI.getLiveRoomInfoByCameraId(cameraId); } catch (Exception e) { } return IfishUtil.returnJson(ResultEnum.fail101.getKey(), ""); diff --git a/src/main/java/com/ifish/controller/Login.java b/src/main/java/com/ifish/controller/Login.java index 2f0437f..abd5215 100644 --- a/src/main/java/com/ifish/controller/Login.java +++ b/src/main/java/com/ifish/controller/Login.java @@ -73,7 +73,7 @@ public class Login { * @param md5 * @return */ - @RequestMapping(value = "/registerEmail", method = RequestMethod.GET) + @RequestMapping(value = "/registerEmail", method = RequestMethod.GET, produces = "application/json;charset=utf-8") public Object registerEmailUser(String md5) { return userHelperI.registerEmail(md5); } diff --git a/src/main/java/com/ifish/helper/LiveRoomHelper.java b/src/main/java/com/ifish/helper/LiveRoomHelper.java index 007438f..7fed8b7 100644 --- a/src/main/java/com/ifish/helper/LiveRoomHelper.java +++ b/src/main/java/com/ifish/helper/LiveRoomHelper.java @@ -131,14 +131,14 @@ public class LiveRoomHelper implements LiveRoomHelperI { * @param roomId * @return */ - public Tbl_Live_Room getLive_RoomById(Integer roomId) throws Exception { + public Tbl_Live_Room getTbl_Live_RoomByCameraId(String cameraId) throws Exception { Tbl_Live_Room live_Room = null; - String key = redisKeyHelperI.getTbl_Live_RoomRedisKeyByRoomId(roomId); + String key = redisKeyHelperI.getTbl_Live_RoomRedisKeyByCameraId(cameraId); String redisString = redisHelperI.getRedis(key); if (StringUtils.isNotBlank(redisString)) { live_Room = (Tbl_Live_Room) IfishUtil.JsonToBean(redisString, Tbl_Live_Room.class); } else { - live_Room = tbl_Live_Room_Mapper.getTbl_Live_RoomById(roomId); + live_Room = tbl_Live_Room_Mapper.getTbl_Live_RoomByCameraId(cameraId); if (live_Room != null && live_Room.getRoomId() > 0) { redisHelperI.setRedis(key, IfishUtil.ObjectToJson(live_Room)); } @@ -152,19 +152,19 @@ public class LiveRoomHelper implements LiveRoomHelperI { * @param roomId * @return */ - public Tbl_Live_Room getTbl_Live_RoomById(Integer roomId) throws Exception { - Tbl_Live_Room device = null; + public Tbl_Live_Room getTbl_Live_RoomByRoomId(Integer roomId) throws Exception { + Tbl_Live_Room live_Room = null; String key = redisKeyHelperI.getTbl_Live_RoomRedisKeyByRoomId(roomId); String redisString = redisHelperI.getRedis(key); if (StringUtils.isNotBlank(redisString)) { - device = (Tbl_Live_Room) IfishUtil.JsonToBean(redisString, Tbl_Live_Room.class); + live_Room = (Tbl_Live_Room) IfishUtil.JsonToBean(redisString, Tbl_Live_Room.class); } else { - device = tbl_Live_Room_Mapper.getTbl_Live_RoomById(roomId); - if (device != null && device.getRoomId() > 0) { - redisHelperI.setRedis(key, IfishUtil.ObjectToJson(device)); + live_Room = tbl_Live_Room_Mapper.getTbl_Live_RoomById(roomId); + if (live_Room != null && live_Room.getRoomId() > 0) { + redisHelperI.setRedis(key, IfishUtil.ObjectToJson(live_Room)); } } - return device; + return live_Room; } /** @@ -212,7 +212,7 @@ public class LiveRoomHelper implements LiveRoomHelperI { // return IfishUtil.returnJson(ResultEnum.success.getKey(), map); // } // } - Tbl_Live_Room live = getLive_RoomById(roomId); + Tbl_Live_Room live = getTbl_Live_RoomByRoomId(roomId); if (live != null) { if (live.getZanNum() != null && live.getZanNum() >= 0) { live.setZanNum(live.getZanNum() + 1); @@ -249,7 +249,7 @@ public class LiveRoomHelper implements LiveRoomHelperI { String messageContent = new String(liveMessage.getMessageContent().getBytes("ISO-8859-1"), "UTF-8"); liveMessage.setMessageContent(messageContent); if (roomId != null && userId != null && StringUtils.isNotBlank(messageContent)) { - Tbl_Live_Room live_Room = getLive_RoomById(roomId); + Tbl_Live_Room live_Room = getTbl_Live_RoomByRoomId(roomId); Tbl_User user = userHelperI.getUserById(userId); if (live_Room != null && user != null) { liveMessage.setCreateTime(new Date()); @@ -325,15 +325,49 @@ public class LiveRoomHelper implements LiveRoomHelperI { * @return */ @Override - public Object getLiveRoomInfo(Integer roomId) { + public Object getLiveRoomInfoByRoomId(Integer roomId) { try { if (roomId != null) { //查找直播间信息 - Tbl_Live_Room curLiveRoom = getLive_RoomById(roomId); + Tbl_Live_Room curLiveRoom = getTbl_Live_RoomByRoomId(roomId); if (curLiveRoom != null) { Map map = new HashMap(); map.put("roomId", roomId); map.put("userId", curLiveRoom.getUserId()); + map.put("cameraId", curLiveRoom.getCameraId()); + map.put("roomName", curLiveRoom.getRoomName()); + map.put("roomDesc", curLiveRoom.getRoomDesc()); + map.put("popularityValue", curLiveRoom.getPopularityValue()); + map.put("roomStatus", curLiveRoom.getRoomStatus()); + map.put("roomImg", curLiveRoom.getRoomImg()); + map.put("createTime", curLiveRoom.getCreateTime()); + map.put("zanNum", curLiveRoom.getZanNum()); + return IfishUtil.toJson(ResultEnum.success.getKey(), map); + } + } + return IfishUtil.toJson(ResultEnum.success.getKey(), ""); + } catch (Exception e) { + return IfishUtil.toJson(ResultEnum.fail101.getKey(), ""); + } + } + + /** + * 根据摄像头ID获取直播间信息 + * + * @param userId + * @return + */ + @Override + public Object getLiveRoomInfoByCameraId(String cameraId) { + try { + if (cameraId != null) { + //查找直播间信息 + Tbl_Live_Room curLiveRoom = getTbl_Live_RoomByCameraId(cameraId); + if (curLiveRoom != null) { + Map map = new HashMap(); + map.put("roomId", curLiveRoom.getRoomId()); + map.put("cameraId", curLiveRoom.getCameraId()); + map.put("userId", curLiveRoom.getUserId()); map.put("roomName", curLiveRoom.getRoomName()); map.put("roomDesc", curLiveRoom.getRoomDesc()); map.put("popularityValue", curLiveRoom.getPopularityValue()); @@ -420,7 +454,7 @@ public class LiveRoomHelper implements LiveRoomHelperI { int i = tbl_Live_Room_Mapper.updateLiveRoom(liveRoom); if (i > 0) { redisKeyHelperI.deleteRedisByTbl_Live_Room(liveRoom); - Tbl_Live_Room live = getLive_RoomById(liveRoom.getRoomId()); + Tbl_Live_Room live = getTbl_Live_RoomByRoomId(liveRoom.getRoomId()); return IfishUtil.toJson(ResultEnum.success.getKey(), live); } } catch (Exception e) { @@ -456,7 +490,7 @@ public class LiveRoomHelper implements LiveRoomHelperI { tbl_Live_Room_Mapper.insertTbl_Live_Watch(browseRoom); } //查找直播间信息 - Tbl_Live_Room curLiveRoom = getLive_RoomById(roomId); + Tbl_Live_Room curLiveRoom = getTbl_Live_RoomByRoomId(roomId); if (curLiveRoom != null) { Integer popularityValue = null; if (curLiveRoom.getPopularityValue() == null) { diff --git a/src/main/java/com/ifish/helper/LiveRoomHelperI.java b/src/main/java/com/ifish/helper/LiveRoomHelperI.java index 160afa1..e2054b9 100644 --- a/src/main/java/com/ifish/helper/LiveRoomHelperI.java +++ b/src/main/java/com/ifish/helper/LiveRoomHelperI.java @@ -55,7 +55,15 @@ public interface LiveRoomHelperI { * @param userId * @return */ - Object getLiveRoomInfo(Integer rommId); + Object getLiveRoomInfoByRoomId(Integer rommId); + + /** + * 根据摄像头ID获取直播间信息 + * + * @param userId + * @return + */ + public Object getLiveRoomInfoByCameraId(String cameraId); /** * 根据条件查询直播间列表 diff --git a/src/main/java/com/ifish/helper/RedisKeyHelper.java b/src/main/java/com/ifish/helper/RedisKeyHelper.java index a3e2cf7..955f4fa 100644 --- a/src/main/java/com/ifish/helper/RedisKeyHelper.java +++ b/src/main/java/com/ifish/helper/RedisKeyHelper.java @@ -193,6 +193,17 @@ public class RedisKeyHelper implements RedisKeyHelperI { return RedisKey.LIVEROOM_ROOMID + roomId; } + /** + * 根据摄像头Id获取Tbl_Live_Room的redis缓存key键值 + * + * @param roomId + * @return + */ + @Override + public String getTbl_Live_RoomRedisKeyByCameraId(String cameraId) { + return RedisKey.LIVEROOM_CAMERAID + cameraId; + } + /** * 根据用户Id获取Tbl_Live_Room的redis缓存key键值 * @@ -342,6 +353,9 @@ public class RedisKeyHelper implements RedisKeyHelperI { if (live_Room.getRoomId() != null && live_Room.getRoomId() > 0) { redisHelperI.deleteRedis(getTbl_Live_RoomRedisKeyByRoomId(live_Room.getRoomId())); } + if (StringUtils.isNotBlank(live_Room.getCameraId())) { + redisHelperI.deleteRedis(live_Room.getCameraId()); + } if (live_Room.getUserId() != null && live_Room.getUserId() > 0) { redisHelperI.deleteRedis(getTbl_Live_RoomRedisKeyByUserId(live_Room.getUserId())); } diff --git a/src/main/java/com/ifish/helper/RedisKeyHelperI.java b/src/main/java/com/ifish/helper/RedisKeyHelperI.java index 04c2967..04d77f1 100644 --- a/src/main/java/com/ifish/helper/RedisKeyHelperI.java +++ b/src/main/java/com/ifish/helper/RedisKeyHelperI.java @@ -140,6 +140,14 @@ public interface RedisKeyHelperI { */ public String getTbl_Live_RoomRedisKeyByRoomId(Integer roomId); + /** + * 根据摄像头Id获取Tbl_Live_Room的redis缓存key键值 + * + * @param roomId + * @return + */ + public String getTbl_Live_RoomRedisKeyByCameraId(String cameraId); + /** * 根据用户Id获取Tbl_Live_Room的redis缓存key键值 * diff --git a/src/main/java/com/ifish/helper/UserHelper.java b/src/main/java/com/ifish/helper/UserHelper.java index 07d4dad..d5f8abe 100644 --- a/src/main/java/com/ifish/helper/UserHelper.java +++ b/src/main/java/com/ifish/helper/UserHelper.java @@ -50,19 +50,19 @@ public class UserHelper implements UserHelperI { */ @Autowired private Tbl_User_Mapper tbl_User_Mapper; - + @Autowired private DeviceHelperI deviceHelperI; - + @Autowired private HardWareTypeHelperI hardWareTypeHelperI; - + @Autowired private RedisKeyHelperI redisKeyHelperI; - + @Autowired private SendMobile sendMobile; - + @Autowired private FastDFSClientI fastDFSClientI; @@ -86,7 +86,7 @@ public class UserHelper implements UserHelperI { return checkUserPassword(tmpUser, user); } //如果用户邮箱不为空,进行邮箱登陆 else if (StringUtils.isNotBlank(user.getUserEmail())) { - tmpUser = tbl_User_Mapper.getUserByUserEmail(user.getPhoneNumber()); + tmpUser = tbl_User_Mapper.getUserByUserEmail(user.getUserEmail()); return checkUserPassword(tmpUser, user); } //如果用户手机邮箱都为空,用户ID不为空,则进行游客登陆 else if (user.getUserId() != null && user.getUserId() > 0) { @@ -149,7 +149,7 @@ public class UserHelper implements UserHelperI { dataMap.put("userSex", user.getUserSex()); dataMap.put("userImg", user.getUserImg()); dataMap.put("nickName", user.getNickName()); - + return IfishUtil.returnJson(ResultEnum.success.getKey(), dataMap); } @@ -162,6 +162,10 @@ public class UserHelper implements UserHelperI { if (StringUtils.isBlank(user.getUserEmail()) || StringUtils.isBlank(user.getUserPassword())) { return IfishUtil.returnJson(ResultEnum.error401.getKey(), ""); } else { + Tbl_User tmpUser = getUserByEmail(user.getUserEmail()); + if (tmpUser != null) { + return IfishUtil.returnJson(ResultEnum.warn201.getKey(), ""); + } String md5 = IfishUtil.EncoderByMd5(user.getUserEmail() + user.getUserPassword()); Map map = new HashMap(); map.put("email", user.getUserEmail()); @@ -353,7 +357,7 @@ public class UserHelper implements UserHelperI { return IfishUtil.returnJson(ResultEnum.fail101.getKey(), ""); } } - + @Override public Object updateUser(Tbl_User user) { try { @@ -382,7 +386,7 @@ public class UserHelper implements UserHelperI { curUser.setUserSex(userSex); bln = true; } - + String registerId = user.getJiguangUserid(); if (StringUtils.isNotBlank(registerId)) { curUser.setJiguangUserid(registerId); @@ -431,7 +435,7 @@ public class UserHelper implements UserHelperI { return IfishUtil.returnJson(ResultEnum.fail101.getKey(), ""); } } - + Tbl_User user = getUserById(userId); user.setUserImg(img); int i = tbl_User_Mapper.updateUser(user); @@ -482,7 +486,7 @@ public class UserHelper implements UserHelperI { Map userMap = getUserMap(user); return IfishUtil.returnJson(ResultEnum.success.getKey(), userMap); } - + } catch (Exception e) { } return IfishUtil.toJson(ResultEnum.fail101.getKey(), ""); @@ -662,7 +666,7 @@ public class UserHelper implements UserHelperI { dataMap.put("device", deviceMap.get("list")); dataMap.put("camera", deviceMap.get("list2")); return IfishUtil.returnJson(ResultEnum.success.getKey(), dataMap); - + } /** @@ -762,7 +766,7 @@ public class UserHelper implements UserHelperI { if (tmpUser.getUpdateTime() != null) { userMap.put("updateTime", IfishUtil.format(tmpUser.getUpdateTime())); } - + return userMap; } @@ -791,9 +795,9 @@ public class UserHelper implements UserHelperI { //封装设备返回信息 list.add(getDeviceInfo(device, deviceUser)); } - + } - + Map map = new HashMap(); map.put("list", list); map.put("list2", list2); @@ -909,5 +913,5 @@ public class UserHelper implements UserHelperI { return IfishUtil.returnJson(ResultEnum.fail101.getKey(), ""); } } - + } diff --git a/src/main/java/com/ifish/mapper/Tbl_Live_Room_Mapper.java b/src/main/java/com/ifish/mapper/Tbl_Live_Room_Mapper.java index 440ff78..42c4022 100644 --- a/src/main/java/com/ifish/mapper/Tbl_Live_Room_Mapper.java +++ b/src/main/java/com/ifish/mapper/Tbl_Live_Room_Mapper.java @@ -91,6 +91,15 @@ public interface Tbl_Live_Room_Mapper { @Select("SELECT ROOM_ID,USER_ID,CAMERA_ID,ROOM_NAME,ROOM_DESC,ROOM_STATUS,POPULARITY_VALUE,CREATE_TIME,UPDATE_TIME,room_Img,zanNum FROM TBL_LIVE_ROOM WHERE ROOM_ID = #{roomid}") Tbl_Live_Room getTbl_Live_RoomById(@Param("roomid") Integer roomid); + /** + * 根据摄像头ID查询直播间信息 + * + * @param roomid + * @return + */ + @Select("SELECT ROOM_ID,USER_ID,CAMERA_ID,ROOM_NAME,ROOM_DESC,ROOM_STATUS,POPULARITY_VALUE,CREATE_TIME,UPDATE_TIME,room_Img,zanNum FROM TBL_LIVE_ROOM WHERE CAMERA_ID = #{cameraid}") + Tbl_Live_Room getTbl_Live_RoomByCameraId(@Param("cameraid") String cameraid); + /** * 根据开播时间来查询直播间 * diff --git a/src/main/java/com/ifish/util/RedisKey.java b/src/main/java/com/ifish/util/RedisKey.java index 0bc4124..1e0cc1e 100644 --- a/src/main/java/com/ifish/util/RedisKey.java +++ b/src/main/java/com/ifish/util/RedisKey.java @@ -85,6 +85,11 @@ public class RedisKey { */ public static final String LIVEROOM_ROOMID = "liveroomE:id_"; + /** + * 直播间详情表缓存前缀,以摄像头ID进行存储 + */ + public static final String LIVEROOM_CAMERAID = "liveroomE:cid_"; + /** * 直播间详情表缓存前缀,以直播间ID进行存储 */