package com.honghu.cloud.controller;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@源码地址来源: https://minglisoft.cn/honghu2/business.html
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.honghu.cloud.bean.Live;
import com.honghu.cloud.bean.LiveBaby;
import com.honghu.cloud.bean.LiveFollow;
import com.honghu.cloud.bean.UserSearchLog;
import com.honghu.cloud.code.ResponseCode;
import com.honghu.cloud.code.ResponseVO;
import com.honghu.cloud.common.page.Page;
import com.honghu.cloud.dto.AccessoryDto;
import com.honghu.cloud.dto.AddGoodsCarFormDto;
import com.honghu.cloud.dto.MessageDto;
import com.honghu.cloud.dto.SysConfigDto;
import com.honghu.cloud.dto.UserDto;
import com.honghu.cloud.feign.AccessoryFeignClient;
import com.honghu.cloud.feign.GoodsCartFeignClient;
import com.honghu.cloud.feign.GoodsShareFeignClient;
import com.honghu.cloud.feign.MessageFeignClient;
import com.honghu.cloud.feign.SysConfigFeignClient;
import com.honghu.cloud.feign.UserFeignClient;
import com.honghu.cloud.redis.RedisUtil;
import com.honghu.cloud.service.IUserSearchLogService;
import com.honghu.cloud.service.LiveBabyService;
import com.honghu.cloud.service.LiveFollowService;
import com.honghu.cloud.service.LiveService;
import com.honghu.cloud.tools.LiveUtils;
import com.honghu.cloud.tools.QueryTools;
import com.honghu.cloud.tools.SecurityUserHolder;
import com.honghu.cloud.util.CommUtil;
import com.honghu.cloud.utils.tools.Md5Encrypt;
import net.sf.json.JSONObject;
/**
* 直播间管理控制器
*
* @author Administrator
*
*/
@RestController
@RequestMapping(value = "/live")
public class LiveController {
private static final Logger logger = LoggerFactory.getLogger(LiveController.class);
@Autowired
private LiveService liveService;
@Autowired
private LiveFollowService liveFollowService;
@Autowired
private AccessoryFeignClient accessoryFeignClient;
@Autowired
private SysConfigFeignClient sysConfigFeignClient;
@Autowired
private LiveBabyService liveBabyService;
@Autowired
private UserFeignClient userFeignClient;
@Autowired
private MessageFeignClient messageFeignClient;
@Autowired
private GoodsShareFeignClient shareFeignClient;
@Autowired
private IUserSearchLogService userSearchLogService;
@Autowired
private GoodsCartFeignClient goodsCartFeignClient;
@Autowired
private RedisUtil redisUtil;
/**
* 根据id查询直播
*
* @param id
* @return
*/
@RequestMapping(value = "/apiForFeign/selectByPrimaryKey", method = RequestMethod.GET)
public Live selectByPrimaryKey(@RequestParam("id") Long id) {
return liveService.selectByPrimaryKey(id);
}
@RequestMapping(value = "/apiForFeign/selectByPrimaryKey1", method = RequestMethod.GET)
public Live selectByPrimaryKey1(@RequestParam("id") Long id) {
return liveService.selectByPrimaryKey1(id);
}
/**
* 我的直播间数据列表查询
*
* @param params
*/
@RequestMapping(value = "/getLiveList")
public ResponseVO getLiveList(HttpServletRequest request, @RequestBody JSONObject json) {
Map<String, Object> params = new HashMap<String, Object>();
String currentPage = json.optString("currentPage"); // 当前页数
String pageSize = json.optString("pageSize"); // 数据长度
String userName = json.getString("userName"); // 主播用户
String orderBy = json.optString("orderBy"); // 排序字段
String orderType = json.optString("orderType"); // 排序方式
if (StringUtils.isNotBlank(userName)) {
if (StringUtils.isNotBlank(currentPage)) {
params.put("currentPage", CommUtil.null2Int(currentPage));
}
if (StringUtils.isNotBlank(pageSize)) {
params.put("pageSize", CommUtil.null2Int(pageSize));
}
if (StringUtils.isNotBlank(orderBy)) {
params.put("orderBy", orderBy);
}
if (StringUtils.isNotBlank(orderType)) {
params.put("orderType", orderType);
}
params.put("creater_id", userName); // 当前用户编号
}
List<Live> results = liveService.queryPages(params);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, results);
}
/**
* 我的直播间数据列表查询
*
* @param params
*/
@RequestMapping(value = "/getLiveList_new")
public ResponseVO getLiveList_new(HttpServletRequest request, @RequestBody JSONObject json) {
Map<String, Object> params = new HashMap<String, Object>();
String currentPage = json.optString("currentPage"); // 当前页数
String pageSize = json.optString("pageSize"); // 数据长度
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
params = QueryTools.getParams(currentPage, 12, "live_status DESC ,addTime", "DESC");
params.put("user_id", user.getId()); // 当前用户编号
params.put("goods_num", "goods_num"); // 查询宝贝件数
Page<Live> results = liveService.list(params);
params.clear();
params.put("results", results);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, params);
}
/**
* 全部直播间数据列表查询
*
* @param params
*/
@RequestMapping(value = "/getLiveListAll")
public ResponseVO getLiveListAll(HttpServletRequest request, @RequestBody JSONObject json) {
Map<String, Object> params = new HashMap<String, Object>();
String currentPage = json.optString("currentPage"); // 当前页数
String pageSize = json.optString("pageSize"); // 数据长度
String orderBy = json.optString("orderBy"); // 排序字段
String orderType = json.optString("orderType"); // 排序方式
String type = json.optString("type"); // 排序方式
params = QueryTools.getParams(currentPage, CommUtil.null2Int(pageSize), orderBy, orderType);
if (StringUtils.isNotBlank(type) && "follow".equals(type)) {
// 查询用户关注的主播
params.put("orderType", type);
}
List<Live> list = liveService.queryPages(params);
HashMap<Object, Object> results = new HashMap<>();
results.put("list", list);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, results);
}
@RequestMapping(value = "/getLiveListAll1")
public ResponseVO getLiveListAll1(HttpServletRequest request, @RequestBody JSONObject json) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
Map<String, Object> params = new HashMap<String, Object>();
String currentPage = json.optString("currentPage"); // 当前页数
String pageSize = json.optString("pageSize"); // 数据长度
String type = json.optString("type"); // 排序方式
String store_id = json.optString("store_id"); // 店铺id
HashMap<Object, Object> results = new HashMap<>();
params = QueryTools.getParams(currentPage, CommUtil.null2Int(pageSize), "a.addTime", null);
if (StringUtils.isNotBlank(type) && "follow".equals(type)) {
// 查询用户关注的主播
params.put("follow", user.getId());
}
if (StringUtils.isNotBlank(store_id)) {
UserDto UserDto = userFeignClient.getUserByStoreId(CommUtil.null2Long(store_id));
if (UserDto == null) {
Page<Live> list = new Page<>();
results.put("list", list);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, results);
}
params.put("a_user_id", UserDto.getId());
}
Page<Live> list = liveService.list1(params);
results.put("list", list);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, results);
}
/**
* 查询直播间数据
*
* @param id
* @return
*/
@RequestMapping("/getLiveById")
public ResponseVO getLiveById(@RequestBody JSONObject json, HttpServletRequest request) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
String live_id = json.optString("live_id");
if (user_id == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
if (StringUtils.isEmpty(live_id)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_ID_ISNULL, null);
}
Live live = liveService.selectByPrimaryKey(CommUtil.null2Long(live_id));
if (live == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.GOODSCLASS_CODE_NULL, null);
}
UserDto anchor = userFeignClient.selectByPrimaryKey(live.getUser_id());
if (anchor == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_CONCERN_ISNULL, null);
}
HashMap<String, Object> hashMap = new HashMap<>();
AccessoryDto accessoryDto = accessoryFeignClient.selectByPrimaryKey(anchor.getPhoto_id());
if (live.getLive_status() == 1) { // 若在直播中 添加热度
int n = (int) (Math.random() * 20 + 15);
live.setPopularity_num(live.getPopularity_num() == null ? 0 : live.getPopularity_num() + n);
liveService.updateById(live);
Object currentNumber = redisUtil.get("NUMBER_" + live.getId());
redisUtil.set("NUMBER_" + live.getId(), null == currentNumber ? 1 : (int) currentNumber + 1);
}
if (user_id != null) {
hashMap.put("concern", user_id);
hashMap.put("to_concern", anchor.getId());
hashMap.put("deleteStatus", 0);
LiveFollow liveFollow = liveFollowService.getLiveFollow(hashMap);
if (liveFollow != null) {
live.setFollow(1); // 已关注
}
}
hashMap.clear();
hashMap.put("anchorname", anchor.getNickName());
hashMap.put("anchorphoto", accessoryDto);
hashMap.put("live", live);
hashMap.put("user", user);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, hashMap);
}
/**
* 创建直播间 添加直播间数据
*
* @param live
*/
@RequestMapping("/add_live_baby")
public ResponseVO add_live(HttpServletRequest request, @RequestBody JSONObject json) {
String mulitId = null; // 商品id
if (json.containsKey("goods_id")) {
mulitId = json.optString("goods_id");
}
String live_id = json.optString("live_id"); // 直播id
String userName = json.optString("userName"); // 用户userName
String live_title = json.optString("live_title"); // 直播间标题
String live_cover = json.optString("live_cover"); // 直播间封面路径完整路径
String live_status = json.optString("live_status"); // 直播状态
String play_time = json.optString("play_time"); // 直播间预播时间
// 直播间id
if (StringUtils.isEmpty(live_id)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_ID_ISNULL, null); // 直播间ID不能为空
}
if (StringUtils.isEmpty(live_title)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TITLE_ISNULL, null); // 直播间标题不能为空
}
if (StringUtils.isEmpty(live_cover)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_COVER_ISNULL, null); // 直播间封面不能为空
}
if (StringUtils.isEmpty(userName)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null); // 用户userName不能为空
}
if (StringUtils.isEmpty(live_status)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_STATUS, null); // 直播状态不能为空
}
Live live = new Live();
live.setAddTime(new Date()); // 直播间创建时间
live.setLive_title(live_title); // 直播间标题
live.setLive_cover(live_cover); // 直播间封面完整路径
live.setLive_num(CommUtil.null2Long(live_id)); // 直播间房间号
live.setCreater_id(userName); // 创建用户
live.setLive_status(Integer.valueOf(live_status)); // 直播状态
// 日期转化格式
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = simpleDateFormat.parse(play_time);
live.setPlay_time(date); // 预播时间
} catch (ParseException e) {
logger.error("LiveController >> add_live >> " + e.getMessage());
}
liveService.addLive(live); // 保存直播间数据信息
if (null != mulitId) {
String[] ids = mulitId.split(",");
for (String id : ids) {
LiveBaby liveBaby = new LiveBaby();
liveBaby.setAddTime(new Date());
liveBaby.setCreater_id(userName);
liveBaby.setGoods_id(CommUtil.null2Long(id));
liveBaby.setLive_id(CommUtil.null2Long(live_id)); // 直播间id
liveBaby.setDeleteStatus(0); // 删除标识
liveBabyService.addLiveBaby(liveBaby); // 添加直播间宝贝信息
}
}
try {
UserDto liveUser = userFeignClient.selectByUserName(userName);
Map<String, Object> maps = new HashMap<String, Object>();
maps.put("to_concern", liveUser.getId());
List<LiveFollow> list = liveFollowService.queryPages(maps);
List<MessageDto> msgs = new ArrayList<MessageDto>();
for (LiveFollow lf : list) {
// 发送站内消息
MessageDto msg = new MessageDto();
msg.setAddTime(new Date());
msg.setDeleteStatus(0);
msg.setMsg_cat(0);
msg.setReply_status(0);
msg.setStatus(0);
String nickName = liveUser.getNickName();
if (StringUtils.isBlank(nickName)) {
StringBuilder sb = new StringBuilder(liveUser.getMobile());
if (sb.length() >= 11) {
sb.replace(3, 7, "****");
}
nickName = sb.toString();
}
if (StringUtils.equals("1", live_status)) {
msg.setTitle("直播通知");
msg.setContent("你关注的" + nickName + "正在直播,请及时观看。");
// Todo 添加公众号推送
} else {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String format = sdf.format(date); // 将Date类型转换成String类型
msg.setTitle("预播通知");
msg.setContent("你关注的" + nickName + "将于" + format + "开始直播,请及时观看哦!");
}
msg.setType(2);
msg.setFromUser_id(1L);
msg.setToUser_id(lf.getConcern());
msgs.add(msg);
}
messageFeignClient.saveList(msgs);
} catch (Exception e) {
logger.error("LiveController >> add_live >> sendMsg error " + e.getMessage());
}
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null); // 请求处理成功
}
/**
* 创建直播间 添加直播间数据
*
* @param live
*/
@RequestMapping(value = "/add_live_baby_new", method = RequestMethod.POST)
public ResponseVO add_live_new(HttpServletRequest request, @RequestBody JSONObject json) {
String mulitId = null; // 商品id
if (json.containsKey("goods_id")) {
mulitId = json.optString("goods_id");
}
// String live_id = json.optString("live_id"); //直播id
String live_title = json.optString("live_title"); // 直播间标题
String live_cover = json.optString("live_cover"); // 直播间封面路径完整路径
String live_status = json.optString("live_status"); // 直播状态
String play_time = json.optString("play_time"); // 直播间预播时间
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
/*
* if(StringUtils.isEmpty(live_id)){ return
* ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_ID_ISNULL, null);
* //直播间ID不能为空 }
*/
if (StringUtils.isEmpty(live_title)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TITLE_ISNULL, null); // 直播间标题不能为空
}
if (StringUtils.isEmpty(live_cover)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_COVER_ISNULL, null); // 直播间封面不能为空
}
if (StringUtils.isEmpty(live_status)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_STATUS, null); // 直播状态不能为空
}
Map<String, Object> maps = new HashMap<String, Object>();
Live live = new Live();
Date date = null;
if (live_status.equals("3")) {
// 日期转化格式
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
date = simpleDateFormat.parse(play_time);
// 查询预播时间点是否存在
maps.put("a_user_id", user.getId());
maps.put("a_play_time", play_time);
List<Live> queryPages = liveService.queryPages(maps);
if (queryPages != null && queryPages.size() > 0) { // 该时间存在预播
// 不保存
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_PREVIEW_IS, null); // 预播已存在
}
live.setPlay_time(date); // 预播时间
} catch (ParseException e) {
logger.error("LiveController >> add_live >> " + e.getMessage());
}
}
live.setAddTime(new Date()); // 直播间创建时间
live.setLive_title(live_title); // 直播间标题
live.setLive_cover(live_cover); // 直播间封面完整路径
Long selectMaxLiveCode = liveService.selectMaxLiveCode();
live.setLive_num(selectMaxLiveCode == null ? 100000 : selectMaxLiveCode + 1); // 直播间房间号
live.setUser_id(user.getId());
live.setCreater_id(user.getUserName()); // 创建用户
live.setLive_status(Integer.valueOf(live_status)); // 直播状态
if (live_status.equals("1")) {
live.setDeleteStatus(1); // 若为直播,先置位删除状态 , 推流时修改
}
liveService.addLive(live); // 保存直播间数据信息
if (null != mulitId) {
String[] ids = mulitId.split(",");
for (String id : ids) {
if (!id.equals("")) {
LiveBaby liveBaby = new LiveBaby();
liveBaby.setAddTime(new Date());
liveBaby.setCreater_id(user.getUsername());
liveBaby.setGoods_id(CommUtil.null2Long(id));
liveBaby.setLive_id(CommUtil.null2Long(live.getId())); // 直播间id
liveBaby.setDeleteStatus(0); // 删除标识
liveBabyService.addLiveBaby(liveBaby); // 添加直播间宝贝信息
}
}
}
try {
// UserDto liveUser = userFeignClient.selectByUserName(userName);
maps.clear();
maps.put("to_concern", user.getId());
List<LiveFollow> list = liveFollowService.queryPages(maps);
List<MessageDto> msgs = new ArrayList<MessageDto>();
for (LiveFollow lf : list) {
// 发送站内消息
MessageDto msg = new MessageDto();
msg.setAddTime(new Date());
msg.setDeleteStatus(0);
msg.setMsg_cat(0);
msg.setReply_status(0);
msg.setStatus(0);
String nickName = user.getNickName();
if (StringUtils.isBlank(nickName)) {
StringBuilder sb = new StringBuilder(user.getMobile());
if (sb.length() >= 11) {
sb.replace(3, 7, "****");
}
nickName = sb.toString();
}
if (StringUtils.equals("1", live_status)) {
msg.setTitle("直播通知");
msg.setContent("你关注的" + nickName + "正在直播,请及时观看。");
// Todo 添加公众号推送
} else {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String format = sdf.format(date); // 将Date类型转换成String类型
msg.setTitle("预播通知");
msg.setContent("你关注的" + nickName + "将于" + format + "开始直播,请及时观看哦!");
}
msg.setType(2);
msg.setFromUser_id(1L);
msg.setToUser_id(lf.getConcern());
msgs.add(msg);
}
messageFeignClient.saveList(msgs);
} catch (Exception e) {
logger.error("LiveController >> add_live >> sendMsg error " + e.getMessage());
}
HashMap<Object, Object> hashMap = new HashMap<>();
hashMap.put("live", live);
hashMap.put("nickName", user.getNickName());
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, hashMap); // 请求处理成功
}
/**
* 添加主播关注数据
*
* @param live
*/
@RequestMapping("/add_live_follow")
public ResponseVO add_live_follow(@RequestBody JSONObject json) {
String concern = json.optString("concern"); // 关注者编号
String to_concern = json.optString("to_concern"); // 被关注者编号
if (StringUtils.isEmpty(concern)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_CONCERN_USERNAME_ISNULL, null); // 关注者userName不能为空
}
if (StringUtils.isEmpty(to_concern)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_USERNAME_ISNULL, null); // 被关注者userName不能为空
}
UserDto concernUser = userFeignClient.selectByUserName(concern); // 关注者用户
if (concernUser == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_CONCERN_ISNULL, null); // 关注者用户不存在
}
UserDto toConcernUser = userFeignClient.selectByUserName(to_concern); // 被关注者用户
if (toConcernUser == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_ISNULL, null); // 被关注者用户不存在
}
Map<String, Object> maps = new HashMap<String, Object>();
maps.put("concern", concernUser.getId());
maps.put("to_concern", toConcernUser.getId());
LiveFollow lFollow = liveFollowService.getLiveFollow(maps);
if (null != lFollow) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_FOLLOW, null); // 主播已关注
}
LiveFollow liveFollow = new LiveFollow();
liveFollow.setAddTime(new Date()); // 添加时间
liveFollow.setConcern(concernUser.getId()); // 关注者
liveFollow.setTo_concern(toConcernUser.getId()); // 被关注者
liveFollowService.addLiveFollow(liveFollow); // 关注信息添加
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null); // 请求处理成功
}
/**
* 添加主播关注数据
*
* @param live
*/
@RequestMapping("/add_live_follow_new")
public ResponseVO add_live_follow_new(@RequestBody JSONObject json, HttpServletRequest request) {
String user_id = json.optString("user_id"); // 被关注者编号
String tokenStr = request.getHeader("token");
Long concern = SecurityUserHolder.getTokenUserId(tokenStr);
if (concern == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto user = userFeignClient.selectByPrimaryKey(concern);// 关注者用户
if (user == null) {
// 用户不存在
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
UserDto toConcernUser = userFeignClient.selectByPrimaryKey(CommUtil.null2Long(user_id)); // 被关注者用户
if (toConcernUser == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_ISNULL, null); // 被关注者用户不存在
}
if (user.getId().toString().equals(user_id)) { // 关注者为登陆者
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_ISNULL, null); // 被关注者用户不存在
}
Map<String, Object> maps = new HashMap<String, Object>();
maps.put("concern", user.getId());
maps.put("to_concern", toConcernUser.getId());
LiveFollow lFollow = liveFollowService.getLiveFollow(maps);
if (null != lFollow) {
liveFollowService.deleteLiveFollow(maps); // 删除主播关注数据
// return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_FOLLOW,
// null); // 主播已关注
} else {
LiveFollow liveFollow = new LiveFollow();
liveFollow.setAddTime(new Date()); // 添加时间
liveFollow.setConcern(user.getId()); // 关注者
liveFollow.setTo_concern(toConcernUser.getId()); // 被关注者
liveFollowService.addLiveFollow(liveFollow); // 关注信息添加
}
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null); // 请求处理成功
}
/**
* 取消主播关注数据
*
* @param live
*/
@RequestMapping("/del_live_follow")
public ResponseVO del_live_follow(@RequestBody JSONObject json) {
String concern = json.optString("concern"); // 关注者编号
String to_concern = json.optString("to_concern"); // 被关注者编号
if (StringUtils.isEmpty(concern)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_CONCERN_USERNAME_ISNULL, null); // 关注者userName不能为空
}
if (StringUtils.isEmpty(to_concern)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_USERNAME_ISNULL, null); // 被关注者userName不能为空
}
UserDto concernUser = userFeignClient.selectByUserName(concern); // 关注者用户
if (concernUser == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_ISNULL, null); // 关注者用户不存在
}
UserDto toConcernUser = userFeignClient.selectByUserName(to_concern); // 被关注者用户
if (toConcernUser == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_ISNULL, null); // 被关注者用户不存在
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("concern", concernUser.getId());
params.put("to_concern", toConcernUser.getId());
LiveFollow lFollow = liveFollowService.getLiveFollow(params);
if (null == lFollow) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_NOT_FOLLOW, null); // 还未关注主播
}
liveFollowService.deleteLiveFollow(params); // 删除主播关注数据
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null); // 请求处理成功
}
/**
* 取消主播关注数据
*
* @param live
*/
@RequestMapping("/del_live_follow_new")
public ResponseVO del_live_follow_new(@RequestBody JSONObject json, HttpServletRequest request) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
String to_concern = json.optString("to_concern"); // 被关注者编号
if (StringUtils.isEmpty(to_concern)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_USERNAME_ISNULL, null); // 被关注者userName不能为空
}
UserDto toConcernUser = userFeignClient.selectByUserName(to_concern); // 被关注者用户
if (toConcernUser == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_ISNULL, null); // 被关注者用户不存在
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("concern", user.getId());
params.put("to_concern", toConcernUser.getId());
LiveFollow lFollow = liveFollowService.getLiveFollow(params);
if (null == lFollow) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_NOT_FOLLOW, null); // 还未关注主播
}
liveFollowService.deleteLiveFollow(params); // 删除主播关注数据
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null); // 请求处理成功
}
/**
* 关注用户数据信息列表
*
* @param live
*/
@RequestMapping("/follow_user")
public ResponseVO follow_user(HttpServletRequest request, @RequestBody JSONObject json) {
String currentPage = json.optString("currentPage"); // 当前页数
String pageSize = json.optString("pageSize"); // 数据长度
String orderBy = json.optString("orderBy"); // 排序字段
String orderType = json.optString("orderType"); // 排序方式
List<Map<String, Object>> result = new LinkedList<Map<String, Object>>();
String userName = json.getString("userName"); // 被关注者编号
if (StringUtils.isEmpty(userName)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null); // 用户userName不能为空
}
UserDto user = userFeignClient.selectByUserName(userName); // 用户
if (user == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null); // 用户不存在
}
Map<String, Object> params = new HashMap<String, Object>();
if (StringUtils.isNotBlank(currentPage)) {
params.put("currentPage", CommUtil.null2Int(currentPage));
}
if (StringUtils.isNotBlank(pageSize)) {
params.put("pageSize", CommUtil.null2Int(pageSize));
}
if (StringUtils.isNotBlank(orderBy)) {
params.put("orderBy", orderBy);
}
if (StringUtils.isNotBlank(orderType)) {
params.put("orderType", orderType);
}
if (StringUtils.isNotBlank(userName)) {
params.put("anchor_id", user.getId()); // 被关注用户
}
List<UserDto> userDtos = userFeignClient.queryPagelist(params);
SysConfigDto sysConfigDto = sysConfigFeignClient.getSysConfig();
for (UserDto userDto : userDtos) {
AccessoryDto acc = null;
if (userDto.getPhoto_id() != null) {
acc = accessoryFeignClient.selectByPrimaryKey(userDto.getPhoto_id());
}
Map<String, Object> us = new HashMap<String, Object>();
us.put("user_id", userDto.getId());
us.put("nickName", userDto.getNickName()); // 用户昵称
us.put("autograph", ""); // 用户个性签名
if (null != sysConfigDto) {
if (null != acc) {
us.put("photo", sysConfigDto.getimageWebServer() + "/" + acc.getPath() + "/" + acc.getName()); // 用户头像
} else {
us.put("photo", sysConfigDto.getimageWebServer() + "/" + sysConfigDto.getMemberIcon().getPath()
+ "/" + sysConfigDto.getMemberIcon().getName()); // 用户头像
}
}
result.add(us);
}
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null); // 请求处理成功
}
/**
* 关注用户数据信息列表
*
* @param live
*/
@RequestMapping("/follow_user_new")
public ResponseVO follow_user_new(HttpServletRequest request, @RequestBody JSONObject json) {
String currentPage = json.optString("currentPage"); // 当前页数
String pageSize = json.optString("pageSize"); // 数据长度
String orderBy = json.optString("orderBy"); // 排序字段
String orderType = json.optString("orderType"); // 排序方式
List<Map<String, Object>> result = new LinkedList<Map<String, Object>>();
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
Map<String, Object> params = new HashMap<String, Object>();
if (StringUtils.isNotBlank(currentPage)) {
params.put("currentPage", CommUtil.null2Int(currentPage));
}
if (StringUtils.isNotBlank(pageSize)) {
params.put("pageSize", CommUtil.null2Int(pageSize));
}
if (StringUtils.isNotBlank(orderBy)) {
params.put("orderBy", orderBy);
}
if (StringUtils.isNotBlank(orderType)) {
params.put("orderType", orderType);
}
params.put("anchor_id", user.getId()); // 被关注用户
List<UserDto> userDtos = userFeignClient.queryPagelist(params);
SysConfigDto sysConfigDto = sysConfigFeignClient.getSysConfig();
for (UserDto userDto : userDtos) {
AccessoryDto acc = null;
if (userDto.getPhoto_id() != null) {
acc = accessoryFeignClient.selectByPrimaryKey(userDto.getPhoto_id());
}
Map<String, Object> us = new HashMap<String, Object>();
us.put("user_id", userDto.getId());
us.put("nickName", userDto.getNickName()); // 用户昵称
us.put("autograph", ""); // 用户个性签名
if (null != sysConfigDto) {
if (null != acc) {
us.put("photo", sysConfigDto.getimageWebServer() + "/" + acc.getPath() + "/" + acc.getName()); // 用户头像
} else {
us.put("photo", sysConfigDto.getimageWebServer() + "/" + sysConfigDto.getMemberIcon().getPath()
+ "/" + sysConfigDto.getMemberIcon().getName()); // 用户头像
}
}
result.add(us);
}
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null); // 请求处理成功
}
/**
* 查询直播用户数据信息
*
* @param live
*/
@RequestMapping("/liveUser")
public ResponseVO liveUser(@RequestBody JSONObject json) {
String userName = json.optString("userName"); // 用户编号
String to_concern = json.optString("to_concern"); // 关注者userName
if (StringUtils.isEmpty(userName)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null); // 用户userName不能为空
}
if (StringUtils.isEmpty(to_concern)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_USERNAME_ISNULL, null); // 被关注者userName不能为空
}
UserDto userDto = userFeignClient.selectByUserName(userName); // 用户
if (userDto == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null); // 用户不存在
}
UserDto toConcernUser = userFeignClient.selectByUserName(to_concern); // 主播用户
if (toConcernUser == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_ISNULL, null); // 被关注用户不存在
}
SysConfigDto sysConfigDto = sysConfigFeignClient.getSysConfig();
Map<String, Object> result = new HashMap<String, Object>();
AccessoryDto acc = null;
if (userDto.getPhoto_id() != null) {
acc = accessoryFeignClient.selectByPrimaryKey(userDto.getPhoto_id());
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("concern", userDto.getId());
params.put("to_concern", toConcernUser.getId());
LiveFollow lf = liveFollowService.getLiveFollow(params); // 查询关注主播数据信息
result.put("nickName", userDto.getNickName()); // 用户昵称
result.put("autograph", ""); // 用户个性签名
if (null != sysConfigDto) {
if (null != acc) {
result.put("photo", sysConfigDto.getimageWebServer() + "/" + acc.getPath() + acc.getName()); // 用户头像
} else {
result.put("photo", sysConfigDto.getimageWebServer() + "/" + sysConfigDto.getMemberIcon().getPath()
+ "/" + sysConfigDto.getMemberIcon().getName()); // 用户头像
}
}
if (null != lf) {
result.put("anchor", true); // 是否关注主播
} else {
result.put("anchor", false); // 是否关注主播
}
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, result);
}
/**
* 查询直播用户数据信息
*
* @param live
*/
@RequestMapping("/liveUser_new")
public ResponseVO liveUser_new(@RequestBody JSONObject json, HttpServletRequest request) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto userDto = userFeignClient.selectByPrimaryKey(user_id);
if (userDto == null) {
// 用户不存在
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
String to_concern = json.optString("to_concern"); // 关注者userName
if (StringUtils.isEmpty(to_concern)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_USERNAME_ISNULL, null); // 被关注者userName不能为空
}
UserDto toConcernUser = userFeignClient.selectByUserName(to_concern); // 主播用户
if (toConcernUser == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TOCONCERN_ISNULL, null); // 被关注用户不存在
}
SysConfigDto sysConfigDto = sysConfigFeignClient.getSysConfig();
Map<String, Object> result = new HashMap<String, Object>();
AccessoryDto acc = null;
if (userDto.getPhoto_id() != null) {
acc = accessoryFeignClient.selectByPrimaryKey(userDto.getPhoto_id());
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("concern", userDto.getId());
params.put("to_concern", toConcernUser.getId());
LiveFollow lf = liveFollowService.getLiveFollow(params); // 查询关注主播数据信息
result.put("nickName", userDto.getNickName()); // 用户昵称
result.put("autograph", ""); // 用户个性签名
if (null != sysConfigDto) {
if (null != acc) {
result.put("photo", sysConfigDto.getimageWebServer() + "/" + acc.getPath() + acc.getName()); // 用户头像
} else {
result.put("photo", sysConfigDto.getimageWebServer() + "/" + sysConfigDto.getMemberIcon().getPath()
+ "/" + sysConfigDto.getMemberIcon().getName()); // 用户头像
}
}
if (null != lf) {
result.put("anchor", true); // 是否关注主播
} else {
result.put("anchor", false); // 是否关注主播
}
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, result);
}
/**
* 个人直播中心
*/
@RequestMapping("/liveCenter")
public Map<String, Object> liveCenter(HttpServletRequest request, @RequestBody JSONObject json) {
SysConfigDto sysConfigDto = sysConfigFeignClient.getSysConfig();
String user_id = json.optString("user_id"); // 获取直播用户信息
if (StringUtils.isEmpty(user_id)) {
return ResponseCode.buildCodeMap("20001", "用户id不能为空", null);
}
List<Map<String, Object>> result = new ArrayList<>();
UserDto userDto = userFeignClient.selectByUserName(user_id); // 用户
if (userDto == null) {
return ResponseCode.buildCodeMap("30001", "用户不存在", null);
}
if (null != userDto.getPhoto_id()) {
AccessoryDto acc = accessoryFeignClient.selectByPrimaryKey(userDto.getPhoto_id()); // 获取头像信息
Map<String, Object> user = new HashMap<String, Object>();
user.put("user_id", userDto.getId()); // 用户编号
user.put("userName", userDto.getUserName1()); // 用户名称
if (null != sysConfigDto) {
if (null != acc) {
user.put("photo", sysConfigDto.getimageWebServer() + "/" + acc.getPath() + acc.getName()); // 用户头像
} else {
user.put("photo", sysConfigDto.getimageWebServer() + "/" + sysConfigDto.getMemberIcon().getPath()
+ "/" + sysConfigDto.getMemberIcon().getName()); // 用户头像
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("anchor_id", userDto.getId()); // 当前用户
List<LiveFollow> liveFollows = liveFollowService.queryPages(params);
user.put("fans", liveFollows.size()); // 粉丝数量
result.add(user);
}
}
return ResponseCode.buildSuccessMap(result);
}
/**
* 个人直播中心
*/
@RequestMapping("/liveCenter_new")
public Map<String, Object> liveCenter_new(HttpServletRequest request, @RequestBody JSONObject json) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildCodeMap("508", "token已过期,请重新登录", null);
}
UserDto userDto = userFeignClient.selectByPrimaryKey(user_id);
if (userDto == null) {
// 用户不存在
return ResponseCode.buildCodeMap("30001", "用户不存在", null);
}
List<Map<String, Object>> result = new ArrayList<>();
if (null != userDto.getPhoto_id()) {
AccessoryDto acc = accessoryFeignClient.selectByPrimaryKey(userDto.getPhoto_id()); // 获取头像信息
Map<String, Object> user = new HashMap<String, Object>();
user.put("user_id", userDto.getId()); // 用户编号
user.put("userName", userDto.getUserName1()); // 用户名称
SysConfigDto sysConfigDto = sysConfigFeignClient.getSysConfig();
if (null != sysConfigDto) {
if (null != acc) {
user.put("photo", sysConfigDto.getimageWebServer() + "/" + acc.getPath() + acc.getName()); // 用户头像
} else {
user.put("photo", sysConfigDto.getimageWebServer() + "/" + sysConfigDto.getMemberIcon().getPath()
+ "/" + sysConfigDto.getMemberIcon().getName()); // 用户头像
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("anchor_id", userDto.getId()); // 当前用户
List<LiveFollow> liveFollows = liveFollowService.queryPages(params);
user.put("fans", liveFollows.size()); // 粉丝数量
result.add(user);
}
}
return ResponseCode.buildSuccessMap(result);
}
/**
* 直播账户验证(用户+密码)
*
* @param params
*/
@RequestMapping(value = "/checking/account", method = RequestMethod.POST)
public Map<String, Object> checkingAccount(@RequestBody JSONObject json, HttpServletRequest request) {
String userName = json.optString("userName");
String password = json.optString("password");
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
ResponseCode.buildCodeMap("10001", "用户名和密码不能为空", null);
}
password = Md5Encrypt.md5(password).toLowerCase();
Map<String, String> paraMap = new HashMap<String, String>();
paraMap.put("userName", userName);
paraMap.put("password", password);
Long user_id = userFeignClient.checkingAccount(paraMap);
if (user_id == null) {
return ResponseCode.buildCodeMap("10002", "你未开通主播", null);
}
// 根据用户id获取登录token
String token = SecurityUserHolder.getCurrentUser(user_id);
return ResponseCode.buildSuccessMap(token);
}
/**
* 直播账户验证(用户)
*
* @param params
*/
@RequestMapping(value = "/checking/username", method = RequestMethod.POST)
public Map<String, Object> checkingUsername(@RequestBody JSONObject json, HttpServletRequest request) {
String userName = json.optString("userName");
if (StringUtils.isEmpty(userName)) {
ResponseCode.buildCodeMap("10001", "用户名不能为空", null);
}
Map<String, String> paraMap = new HashMap<String, String>();
paraMap.put("userName", userName);
Long user_id = userFeignClient.checkingUserName(paraMap);
if (user_id == null) {
return ResponseCode.buildCodeMap("10002", "你未开通主播", null);
}
// 根据用户id获取登录token
String token = SecurityUserHolder.getCurrentUser(user_id);
return ResponseCode.buildSuccessMap(token);
}
/**
* 通过直播间id查询用户
*
* @param params
*/
@RequestMapping(value = "/getUser", method = RequestMethod.POST)
public ResponseVO getUser(@RequestBody JSONObject json) {
String live_id = json.optString("live_id");
if (StringUtils.isBlank(live_id)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_ID_ISNULL, null); // 直播间id不能为空
}
Map<String, Object> maps = new HashMap<String, Object>();
maps.put("live_num", live_id);
Live live = liveService.selectByLiveNum(maps);
UserDto userDto = null;
if (null != live && live.getCreater_id() != null) {
userDto = userFeignClient.selectByUserName(live.getCreater_id()); // 获取用户信息
}
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, userDto);
}
// 直播间分享海报
@RequestMapping(value = "/liveSharePic", method = RequestMethod.POST)
public ResponseVO liveSharePic(@RequestBody JSONObject json) {
String live_id = json.optString("live_id"); // 直播间ID
String userName = json.optString("username"); // 直播间分享用户
String anchor_id = json.optString("anchor_id"); // 直播间主播
if (StringUtils.isBlank(anchor_id)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_ANCHOR_ID_ISNULL, null); // 主播id不能为空
}
if (StringUtils.isBlank(live_id)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_ID_ISNULL, null); // 直播间id不能为空
}
if (StringUtils.isBlank(userName)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_SHARE_ID_ISNULL, null); // 直播间分享用户名不能为空
}
Map<String, Object> maps = new HashMap<String, Object>();
maps.put("live_num", live_id);
Live live = liveService.selectByLiveNum(maps);
if (null == live) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_NO_FIND, null); // 未找到直播间
}
if (StringUtils.isBlank(live.getLive_title())) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_TITLE_NO_FIND, null); // 未找到直播间
}
if (StringUtils.isBlank(live.getLive_cover())) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_COVER_NO_FIND, null); // 未找到直播间
}
if (StringUtils.isBlank(live.getCreater_id())) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_CREATER_ID_NO_FIND, null); // 未找到直播间
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("live_title", live.getLive_title());
params.put("live_cover", live.getLive_cover());
params.put("creater_id", live.getCreater_id());
params.put("live_id", live_id);
params.put("userName", userName);
params.put("anchor_id", anchor_id.toString());
params.put("live_status", live.getLive_status().toString());
Map<String, Object> result = shareFeignClient.liveSharePicture(params);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, result);
}
/**
* 查询用户搜索记录
*/
@RequestMapping(value = "/userSearchLogList", method = RequestMethod.POST)
public Map<String, Object> userSearchLogList(@RequestBody JSONObject json, HttpServletRequest request) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildFailMap("token无效", null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildreturnMap(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
HashMap<String, Object> result = new HashMap<>();
SysConfigDto sysConfig = sysConfigFeignClient.getSysConfig();
String[] split = sysConfig.getHotSearch().split(",");
ArrayList<Object> arrayList = new ArrayList<>();
for (int a = 0; a < split.length - 1; a++) {
arrayList.add(split[a]);
}
result.put("hot_search", arrayList);
Map<String, Object> params = QueryTools.getParams(null, 6, null, null);
params.put("user_id", user.getId());
Page<UserSearchLog> list = userSearchLogService.list(params);
result.put("search_log", list.getResult());
return ResponseCode.buildSuccessMap(result);
}
/**
* 清除用户搜索记录
*/
@RequestMapping(value = "/delUserSearchLog", method = RequestMethod.POST)
public Map<String, Object> delUserSearchLog(@RequestBody JSONObject json, HttpServletRequest request) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildFailMap("token无效", null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildreturnMap(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
userSearchLogService.delUserLog(user.getId());
return ResponseCode.buildSuccessMap(null);
}
/**
* 保存搜索记录
*/
@RequestMapping(value = "/saveUserSearchLog", method = RequestMethod.POST)
public Map<String, Object> saveUserSearchLog(@RequestBody JSONObject json, HttpServletRequest request) {
if (StringUtils.isBlank(json.optString("search_name"))) { // 为空不做操作
return ResponseCode.buildSuccessMap(null);
}
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id != null) {
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user != null) {// 用户存在
Map<String, Object> params = QueryTools.getParams(null, 3, null, null);
params.put("user_id", user.getId());
params.put("search_name", json.optString("search_name"));
Page<UserSearchLog> list = userSearchLogService.list(params);
if (list.getResult().size() < 1) { // 不存在, 保存记录
UserSearchLog userSearchLog = new UserSearchLog();
userSearchLog.setUser_id(user_id);
userSearchLog.setAddTime(new Date());
userSearchLog.setSearch_name(json.optString("search_name"));
userSearchLog.setDeleteStatus(0);
userSearchLogService.saveEntity(userSearchLog);
} else {
list.getResult().get(0).setAddTime(new Date()); // 更新时间
userSearchLogService.updateById(list.getResult().get(0));
}
}
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 直播添加购物车商品
*
* @param params
*/
@RequestMapping(value = "/addLiveGoodsCart", method = RequestMethod.POST)
public ResponseVO addLiveGoodsCart(@RequestBody JSONObject json, HttpServletRequest request) {
Long id = CommUtil.null2Long(json.optString("id")); // 商品id
Integer count = Integer.valueOf(json.optString("count"));
String gsp = json.optString("gsp");
String buy_type = json.optString("buy_type");
String type = json.optString("type");
String combin_version = json.optString("combin_version");
String combin_ids = json.optString("combin_ids");
String userName = json.getString("userName");
String liverName = json.getString("liverName");
String liveroom_id = null;
if (StringUtils.isNotBlank(liveroom_id) && !("-1").equals(liveroom_id)) {
liveroom_id = json.optString("liveroom_id");
}
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(liverName)) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null); // 用户userName不能为空
}
UserDto user = userFeignClient.selectByUserName(userName); // 用户
if (user == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USERNAME_ISNULL, null); // 用户不存在
}
UserDto liver = userFeignClient.selectByUserName(liverName); // 用户
if (liver == null) {
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null); // 用户不存在
}
AddGoodsCarFormDto addGoodsCarFormDto = new AddGoodsCarFormDto();
addGoodsCarFormDto.setId(id);
addGoodsCarFormDto.setCount(count);
addGoodsCarFormDto.setGsp(gsp);
addGoodsCarFormDto.setBuy_type(buy_type);
addGoodsCarFormDto.setCombin_ids(combin_ids);
addGoodsCarFormDto.setCombin_version(combin_version);
addGoodsCarFormDto.setApp_user_id(user.getId());
addGoodsCarFormDto.setType(type);
addGoodsCarFormDto.setShare_user_id(liver.getId().toString());
addGoodsCarFormDto.setLiveroom_id(liveroom_id);
Map addGoodsCart = goodsCartFeignClient.addGoodsCart(addGoodsCarFormDto);
HashMap<Object, Object> result = new HashMap<>();
result.put("map", addGoodsCart);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, result);
}
/**
* 生成直播间推流地址
*/
@RequestMapping(value = "/add_live_url", method = RequestMethod.POST)
public Map<String, Object> add_live_url(@RequestBody JSONObject json, HttpServletRequest request) {
String imgroup_id = json.optString("imgroup_id");
String live_id = json.optString("live_id");
String live_type = json.optString("live_type");
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildFailMap("token无效", null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildreturnMap(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
if (StringUtils.isEmpty(live_id)) {
return ResponseCode.buildreturnMap(ResponseCode.ParaMETER_ERROR, null);
}
if (StringUtils.isEmpty(imgroup_id)) {
return ResponseCode.buildreturnMap(ResponseCode.LIVE_IMGROUP_ISNULL, null);
}
Live live = null;
if (StringUtils.isNotEmpty(live_type) && live_type.equals("1")) {
live = liveService.selectByPrimaryKey1(CommUtil.null2Long(live_id));
} else {
live = liveService.selectByPrimaryKey(CommUtil.null2Long(live_id));
}
if (live == null) {
return ResponseCode.buildreturnMap(ResponseCode.LIVE_NO_FIND, null);
}
HashMap<String, Object> maps = new HashMap<>();
SysConfigDto sysConfig = sysConfigFeignClient.getSysConfig();
live.setImgroup_id(imgroup_id); // 聊天室id
live.setStartTime(new Date()); // 添加时间
maps.put("to_concern", live.getUser_id());
maps.put("deleteStatus", 0);
// 粉丝总数
Integer selectCount = liveFollowService.selectCount(maps);
live.setFollow_num(CommUtil.null2Long(selectCount)); // 计算当前粉丝数, 之后结束在统计
live.setDeleteStatus(0); // 进行相减 拿到本场关注数
live.setLive_status(1); // 开始直播
String live_domian = sysConfig.getLive_play_domain();
String safeUrl = LiveUtils.getSafeUrl(sysConfig.getLive_key(), live_id, 86400000L);
live.setLive_url(live_domian + "/live/" + live_id + "?" + safeUrl);
liveService.updateById(live);
String url = sysConfig.getLive_domain() + "/live/" + live_id + "?" + safeUrl;
return ResponseCode.buildSuccessMap(url);
}
/**
* 直播观看人数变化
*
* @param params
*/
@RequestMapping(value = "/updateLiveAudience")
public ResponseVO getLiveListAll(@RequestBody JSONObject json) {
String live_id = json.optString("live_id"); // 直播间id
String count = json.optString("count"); // 数量
if (StringUtils.isNotBlank(live_id)) {
// 查询用户关注的主播
Live Live = liveService.selectByPrimaryKey(CommUtil.null2Long(live_id));
if (Live != null && Live.getLive_status() == 1) {
Live.setAudience_num(CommUtil.null2Long(count));
liveService.updateAudienceById(CommUtil.null2Long(live_id), CommUtil.null2Long(count));
}
}
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null);
}
/**
* 查询当前直播关注人数
*
* @param params
*/
@RequestMapping(value = "/getFollowNum")
public Map<String, Object> getFollowNum(@RequestBody JSONObject json) {
String live_id = json.optString("live_id"); // 直播间id
if (StringUtils.isEmpty(live_id)) {
return ResponseCode.buildreturnMap(ResponseCode.ParaMETER_ERROR, null);
}
Live live = liveService.selectByPrimaryKey(CommUtil.null2Long(live_id));
if (live == null) {
return ResponseCode.buildreturnMap(ResponseCode.LIVE_NO_FIND, null);
}
HashMap<String, Object> maps = new HashMap<>();
maps.put("to_concern", live.getUser_id());
maps.put("deleteStatus", 0);
// 粉丝总数
Integer Count = liveFollowService.selectCount(maps);
// 本场关注人数 进行相减 拿到本场关注数
long liveCount = Count.longValue() - live.getFollow_num().longValue();
return ResponseCode.buildSuccessMap(liveCount);
}
/**
*
* 结束直播
*
* @param params
*/
@RequestMapping(value = "/endLive")
public Map<String, Object> endLive(@RequestBody JSONObject json, HttpServletRequest request) {
String tokenStr = request.getHeader("token");
String live_id = json.optString("live_id"); // 直播间id
String pralis_num = json.optString("pralis_num"); // 点赞数
String duration = json.optString("duration"); // 直播间id
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildreturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildreturnMap(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
if (StringUtils.isEmpty(live_id)) {
return ResponseCode.buildreturnMap(ResponseCode.ParaMETER_ERROR, null);
}
Live live = liveService.selectByPrimaryKey(CommUtil.null2Long(live_id));
if (live == null || live.getLive_status() == 2) {
return ResponseCode.buildreturnMap(ResponseCode.LIVE_NO_FIND, null);
}
HashMap<String, Object> maps = new HashMap<>();
maps.put("to_concern", live.getUser_id());
maps.put("deleteStatus", 0);
// 粉丝总数
Integer Count = liveFollowService.selectCount(maps);
// 本场关注人数 进行相减 拿到本场关注数
long liveCount = Count.longValue() - live.getFollow_num().longValue();
live.setLive_status(2); // 结束直播 改为回播
live.setFollow_num(liveCount); // 本场关注人数
live.setDuration(CommUtil.null2Long(duration));
live.setEndTime(new Date());
live.setAudience_num(CommUtil.null2Long(
null == redisUtil.get("NUMBER_" + live.getId()) ? 0 : redisUtil.get("NUMBER_" + live.getId())));// 观看人数
live.setPralis_num(CommUtil.null2Long(pralis_num));
liveService.updateById(live);
return ResponseCode.buildSuccessMap(liveCount);
}
/**
* 查询当前直播关注人数
*
* @param params
*/
@RequestMapping(value = "/delLiveById")
public Map<String, Object> delLiveById(@RequestBody JSONObject json, HttpServletRequest request) {
String live_id = json.optString("live_id"); //
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id == null) {
return ResponseCode.buildreturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildreturnMap(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
if (StringUtils.isEmpty(live_id)) {
return ResponseCode.buildreturnMap(ResponseCode.ParaMETER_ERROR, null);
}
Live live = liveService.selectByPrimaryKey(CommUtil.null2Long(live_id));
if (live != null && live.getUser_id().toString().equals(user_id + "")) {
liveService.deleteLive(live.getId());// 删除
} else {
return ResponseCode.buildreturnMap(ResponseCode.ParaMETER_ERROR, null);
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 直播结束接口回调
*
* @param params
*/
@RequestMapping(value = "/returnEndLiveUrl")
public void getEndLiveUrl(@RequestBody JSONObject json) {
String event_type = json.optString("event_type"); //
String stream_id = json.optString("stream_id"); // 观看人数
if (event_type.equals("100") && StringUtils.isNotBlank(stream_id)) {
Live live = liveService.selectByPrimaryKey(CommUtil.null2Long(stream_id));
if (live != null) {
String video_url = json.optString("video_url"); //
live.setLive_url(video_url);
liveService.updateById(live);
}
}
//
if (event_type.equals("0") && StringUtils.isNotBlank(stream_id)) {
Live live = liveService.selectByPrimaryKey(CommUtil.null2Long(stream_id));
if (live != null && live.getLive_status() == 1) {
HashMap<String, Object> maps = new HashMap<>();
maps.put("to_concern", live.getUser_id());
maps.put("deleteStatus", 0);
// 粉丝总数
Integer Count = liveFollowService.selectCount(maps);
// 本场关注人数 进行相减 拿到本场关注数
long liveCount = Count.longValue() - live.getFollow_num().longValue();
live.setLive_status(2); // 结束直播 改为回播
live.setFollow_num(liveCount); // 本场关注人数
double div = CommUtil.div(CommUtil.null2Long(json.optString("errcode")), 1000);
live.setAudience_num(CommUtil.null2Long(
null == redisUtil.get("NUMBER_" + live.getId()) ? 0 : redisUtil.get("NUMBER_" + live.getId())));// 观看人数
live.setDuration(CommUtil.null2Long(div));
long time = new Date().getTime() - live.getStartTime().getTime();
live.setDuration(CommUtil.null2Long(CommUtil.div(time, 1000)));
live.setEndTime(new Date());
liveService.updateById(live);
}
}
}
}
@源码地址来源: https://minglisoft.cn/honghu2/business.html
搜索体验小程序: 海哇