Commit ba584bdc by jscat

nyx jaapp: 功能更新

1. 添加redis支持
2. 在socket里新增onClose()发送模块;
parent eebc71c7
......@@ -94,6 +94,7 @@ public class WebSocketServer {
msgMap.put("cmd", "onOpen");
msgMap.put("uid", this.uid);
msgMap.put("msg", msg);
msgMap.put("count", onlineCountMap.get(this.sid));
try {
//sendMessage(msgMap.toString());
......@@ -111,6 +112,18 @@ public class WebSocketServer {
webSocketSet.remove(this); //从set中删除
subOnlineCount(sid); //在线数减1
log.info("有一连接关闭! "+sid+" 当前在线人数为" + getOnlineCount(sid));
JSONObject msgMap = new JSONObject();
msgMap.put("cmd", "onClose");
msgMap.put("uid", this.uid);
msgMap.put("msg", "");
msgMap.put("count", onlineCountMap.get(this.sid));
try {
//sendMessage(msgMap.toString());
sendInfo(msgMap.toString(), this.sid);
} catch (IOException e) {
log.error("websocket IO异常");
}
}
/**
......
package cn.com.fun.nyxkey.api.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 活动发布-现场信息 视图表
* Created by jscat on 2020/11/27.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Rockwell_keyV_live_info{
private String liveId; // 直播的id, uuid format, like uid_001
private String liveStatus; // 直播状态: 01: 直播中; 00: 已结束
private String title; // 发布标题,比如:此生必去系列。
private String city; // 城市
private String address; // 地址
private int numWatcher; // 在看人数: 实时数据, 从redis读取
private int maxWatcher; // 峰值人数: 实时数据, 从redis读取
private String noteImage; // 封面图片; 以::做分割
private String nyxName; // nyxName
private String nickName; // nickName
private String avatarUrl; // avatarUrl
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date createDatetime; // 统计周期
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date updateDatetime; // 更新日期
}
package cn.com.fun.nyxkey.api.domain.query;
import cn.com.fun.nyxkey.api.common.Pagination;
import cn.com.fun.nyxkey.api.domain.Rockwell_keyT_match;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* Created by jscat on 2020/11/27
*/
@Data
@AllArgsConstructor
public class Rockwell_keyT_liveQuery {
private String liveId; // id
private String liveStatus; // 直播状态: 01: 直播中; 00: 已结束
private String title; // 名称
private String city; // 城市
private String address; // 地址
private String orderType; //顺序
private Pagination pagination;
//默认返回1页4条记录
public Rockwell_keyT_liveQuery()
{
this.pagination = new Pagination(1, 4);
this.orderType = "desc";
this.liveStatus = "01";
}
public void setLiveId(String strLiveId)
{
if(strLiveId.equals("0"))
{
this.liveId = null;
}
else
{
this.liveId = strLiveId;
}
}
public void setLiveStatus(String strLiveStatus)
{
if(strLiveStatus.equals("0"))
{
this.liveStatus = null;
}
else
{
this.liveStatus = strLiveStatus;
}
}
public void setTitle(String strTitle)
{
if(strTitle.equals("0"))
{
this.title = null;
}
else
{
this.title = strTitle;
}
}
public void setCity(String strCity)
{
if(strCity.equals("0"))
{
this.city = null;
}
else
{
this.city = strCity;
}
}
public void setAddress(String strAddress)
{
if(strAddress.equals("0"))
{
this.address = null;
}
else
{
this.address = strAddress;
}
}
public void setOrderType(String strOrderType)
{
if(strOrderType.equals("0"))
{
this.orderType = null;
}
else
{
this.orderType = strOrderType;
}
}
@Override
public String toString() {
return "Rockwell_keyT_liveQuery{" +
"liveId='" + liveId + '\'' +
"liveStatus='" + liveStatus + '\'' +
"title='" + title + '\'' +
"city='" + city + '\'' +
"address='" + address + '\'' +
"orderType='" + orderType + '\'' +
"pagination='" + pagination + '\'' +
'}';
}
}
......@@ -75,6 +75,10 @@ public interface Rockwell_keyMapper {
List<Rockwell_keyV_member_user> getV_member_user_by_page(Rockwell_keyV_member_userQuery rockwell_keyV_member_userQuery);
List<Rockwell_keyV_member_address> getV_member_address(Rockwell_keyT_memberQuery rockwell_keyT_memberQuery);
/* live api */
List<Rockwell_keyV_live_info> getV_live_info(Rockwell_keyT_liveQuery rockwell_keyT_liveQuery);
int addT_live(Rockwell_keyV_live_info rockwell_keyV_live_info);
/* testing */
void test(Rockwell_keyT_matchQuery rockwell_keyT_matchQuery);
......
......@@ -92,6 +92,13 @@ public interface Rockwell_keyService {
JSONResult Rockwell_keyServiceAddT_address(String memberId, String memberCity, String memberAddress);
JSONResult Rockwell_keyServicegetV_member_address(String memberId);
/*
live api
jscat 20201127
*/
JSONResult Rockwell_keyServiceGetLives(String orderType, int pageNum, int pageCount);
JSONResult Rockwell_keyServiceAddLive(String title, String city, String address, String noteImage, String liveId);
// testing
void Rockwell_keyServiceTest(List<Rockwell_keyT_match> listRockwell_keyT_match);
......
......@@ -1017,6 +1017,54 @@ public class Rockwell_keyServiceImpl implements Rockwell_keyService {
}
public JSONResult Rockwell_keyServiceGetLives(String orderType, int pageNum, int pageCount)
{
LOGGER.debug("find Rockwell_keyServiceGetLives");
List<Rockwell_keyV_live_info> listRockwell_keyV_live_info = new ArrayList<>();
Rockwell_keyT_liveQuery rockwell_keyT_liveQuery = new Rockwell_keyT_liveQuery();
//step2: 查询数据
rockwell_keyT_liveQuery.setOrderType(orderType);
rockwell_keyT_liveQuery.setPagination(new Pagination(pageNum, pageCount));
listRockwell_keyV_live_info = rockwell_keyMapper.getV_live_info(rockwell_keyT_liveQuery);
int totalCount = listRockwell_keyV_live_info.size();
JSONResult jsonResult = new JSONResult(totalCount, listRockwell_keyV_live_info);
return jsonResult;
}
public JSONResult Rockwell_keyServiceAddLive(String title, String city, String address, String noteImage, String liveId)
{
LOGGER.debug("find Rockwell_keyServiceAddLive");
Rockwell_keyV_live_info rockwell_keyV_live_info = new Rockwell_keyV_live_info();
rockwell_keyV_live_info.setLiveId(liveId);
rockwell_keyV_live_info.setLiveStatus("01");
rockwell_keyV_live_info.setTitle(title);
rockwell_keyV_live_info.setCity(city);
rockwell_keyV_live_info.setAddress(address);
rockwell_keyV_live_info.setNoteImage(noteImage);
rockwell_keyV_live_info.setNumWatcher(0);
rockwell_keyV_live_info.setMaxWatcher(0);
rockwell_keyV_live_info.setCreateDatetime(new Date());
rockwell_keyV_live_info.setUpdateDatetime(new Date());
//添加数据
int ret = rockwell_keyMapper.addT_live(rockwell_keyV_live_info);
if(ret == 1) // 成功
{
JSONResult jsonResult = new JSONResult(1, rockwell_keyV_live_info);
return jsonResult;
}
else
{
return new JSONResult(ExceptionMsg.AddAddressError);
}
}
// testing
public void Rockwell_keyServiceTest(List<Rockwell_keyT_match> listRockwell_keyT_match)
......
......@@ -670,6 +670,60 @@ public class NyxApiController {
return keyService.Rockwell_keyServicegetV_member_address(memberId);
}
/* 8 现场直播表(tbl_live/view_live_info)的相关api 获取 view_live_info 的数据 by page
- 查询记录: client -> java -> redis(当前人数, 峰值人数) -> client
- 修改记录: client -> java -> redis(当前人数, 峰值人数)
- 关闭记录: client -> java -> redis(峰值人数) -> java(live_status="00")
- 增加记录: client -> java -> redis (当前人数, 峰值人数)
8.1 live_info 的相关查询
1. 按照 user_id
2. 按照 member_id
status == '01' && member_status == '01'
order by default_member desc, create_datetime asc
返回 Rockwell_keyV_member_user
*/
@ApiOperation(value="按page获取live信息", notes="按page获取live信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "orderType", value = "排序类型, 默认desc", required = false, dataType = "String"),
@ApiImplicitParam(name = "pageNum", value = "页码,从1开始", required = false, dataType = "String", defaultValue = "1"),
@ApiImplicitParam(name = "pageCount", value = "每页的数据个数,默认是4个", required = false, dataType = "String", defaultValue = "4")
})
@RequestMapping(value = "/nyx/live/query", method = RequestMethod.GET)
public JSONResult RockwellGetLives(
@RequestParam(value = "orderType", required = false, defaultValue = "desc") String orderType,
@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
@RequestParam(value = "pageCount", required = false, defaultValue = "4") int pageCount
) {
return keyService.Rockwell_keyServiceGetLives(orderType, pageNum, pageCount);
}
/*
8.2 live_info 的添加
*/
@ApiOperation(value="添加live信息", notes="添加live信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "title", value = "标题", required = true, dataType = "String"),
@ApiImplicitParam(name = "city", value = "城市", required = true, dataType = "String"),
@ApiImplicitParam(name = "address", value = "地址", required = true, dataType = "String"),
@ApiImplicitParam(name = "noteImage", value = "图片", required = true, dataType = "String"),
@ApiImplicitParam(name = "liveId", value = "liveId", required = true, dataType = "String")
})
@RequestMapping(value = "/nyx/live/add", method = RequestMethod.GET)
public JSONResult RockwellAddLive(
@RequestParam(value = "title", required = false, defaultValue = "0") String title,
@RequestParam(value = "city", required = false, defaultValue = "0") String city,
@RequestParam(value = "address", required = false, defaultValue = "0") String address,
@RequestParam(value = "noteImage", required = false, defaultValue = "0") String noteImage,
@RequestParam(value = "liveId", required = false, defaultValue = "0") String liveId
) {
return keyService.Rockwell_keyServiceAddLive(title, city, address, noteImage, liveId);
}
// 2.0 test
@ApiOperation(value="test", notes="test")
@ApiImplicitParams({
......
......@@ -95,4 +95,87 @@ public class RedisController {
}
/*
refer: https://blog.csdn.net/tianluke1234/article/details/80431222
通过zset更新排序
key: nyx:live:num_watcher:zset:上海
socre: 10
member: uid_088a957b-78e9-49cd-980b-ce8bc47b4e11
zadd nyx:live:num_watcher:zset:上海 484 uid_088a957b-78e9-49cd-980b-ce8bc47b4e11
通过hash获取json字段信息(jscat20201201, 避免一些字段更新)
hash
key: nyx:live:num_watcher:hash:上海
field1: uid_088a957b-78e9-49cd-980b-ce8bc47b4e11
value1:
{
title: "巅峰赛第一",
city: "",
address: "",
nyxName: "",
avatarUrl: "",
note_image: "",
}
hset nyx:live:num_watcher:hash:上海 uid_088a957b-78e9-49cd-980b-ce8bc47b4e11 123
hash
key: nyx:live:userid:uid_088a957b-78e9-49cd-980b-ce8bc47b4e11
field1: num_watcher
value1: 123
*/
@ApiOperation(value="更新在线人数", notes="更新在线人数")
@ApiImplicitParams({
})
@RequestMapping(value = "/nyx/redis/update/watcher", method = RequestMethod.GET)
public JSONResult updateWatcher() throws Exception {
// 返回json显示的话 把MAP转json toJsonFromMap
String pattern = "[@#]*";
Set<String> keys = jedisUtil.keys(pattern);
Map<String, String> map = new HashMap<>();
List<String> list = new ArrayList<>(keys);
List<String> valueList = jedisUtil.mget(list.toArray(new String[list.size()]));
int i = 0;
for (String key : keys) {
map.put(key, valueList.get(i));
i++;
}
return new JSONResult(i, map);
}
/*
refer:
获取在线人数
*/
@ApiOperation(value="获取在线人数", notes="获取在线人数")
@ApiImplicitParams({
})
@RequestMapping(value = "/nyx/redis/get/watcher", method = RequestMethod.GET)
public JSONResult getWatcher() throws Exception {
// 返回json显示的话 把MAP转json toJsonFromMap
String pattern = "[@#]*";
Set<String> keys = jedisUtil.keys(pattern);
Map<String, String> map = new HashMap<>();
List<String> list = new ArrayList<>(keys);
List<String> valueList = jedisUtil.mget(list.toArray(new String[list.size()]));
int i = 0;
for (String key : keys) {
map.put(key, valueList.get(i));
i++;
}
return new JSONResult(i, map);
}
}
......@@ -699,5 +699,39 @@ limitations under the License.
</if>
</select>
<!-- live api1-1 查询live记录 jscat 20201127 -->
<select id="getV_live_info" parameterType="cn.com.fun.nyxkey.api.domain.query.Rockwell_keyT_liveQuery"
resultType="cn.com.fun.nyxkey.api.domain.Rockwell_keyV_live_info">
select * from view_live_info
where 1=1
<if test="liveStatus != null and liveStatus != '' ">
AND live_status=#{liveStatus}
</if>
<if test="orderType != null and orderType != '' ">
order by num_watcher desc
</if>
<if test="pagination != null ">
<include refid="pagination"/>
</if>
</select>
<!-- livepi1-2 新增一条 tbl_live 记录 update jscat 20201127 -->
<insert id="addT_live" parameterType="cn.com.fun.nyxkey.api.domain.Rockwell_keyV_live_info">
insert into tbl_live(live_id, live_status, title, city, address, num_watcher, max_watcher, note_image, create_datetime,update_datetime)
values
(
#{liveId},
#{liveStatus},
#{title},
#{city},
#{address},
#{numWatcher},
#{maxWatcher},
#{noteImage},
#{createDatetime},
#{updateDatetime}
)
</insert>
<!-- ending API interface -->
</mapper>
\ No newline at end of file
......@@ -44,6 +44,18 @@ spring:
max-lifetime: 100000
connection-timeout: 30000
connection-test-query: SELECT 1
redis:
host: 47.99.110.89
port: 6379
password: nyx123456
timeout: 30000
block-when-exhausted: true
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
aliyun:
oss:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论