@源码地址来源: https://minglisoft.cn/honghu/business.html
package com.honghu.cloud.controller;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.google.common.collect.Maps;
import com.honghu.cloud.bean.Video;
import com.honghu.cloud.bean.VideoClass;
import com.honghu.cloud.bean.VideoComment;
import com.honghu.cloud.bean.VideoCommentLike;
import com.honghu.cloud.bean.VideoLike;
import com.honghu.cloud.bean.VideoTopic;
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.GoodsDto;
import com.honghu.cloud.dto.SnapshotDto;
import com.honghu.cloud.dto.StoreDto;
import com.honghu.cloud.dto.UserDto;
import com.honghu.cloud.dto.UserVideoDto;
import com.honghu.cloud.feign.AccessoryFeignClient;
import com.honghu.cloud.feign.GoodsFeignClient;
import com.honghu.cloud.feign.ModularClassFeignClient;
import com.honghu.cloud.feign.OrderFormFeignClient;
import com.honghu.cloud.feign.StoreFeignClient;
import com.honghu.cloud.feign.TXTemplateFeignClient;
import com.honghu.cloud.feign.UserFeignClient;
import com.honghu.cloud.service.IVideoClassService;
import com.honghu.cloud.service.IVideoCommentService;
import com.honghu.cloud.service.IVideoService;
import com.honghu.cloud.service.IVideoTopicService;
import com.honghu.cloud.tools.AliSmsUtil;
import com.honghu.cloud.tools.QueryTools;
import com.honghu.cloud.tools.SecurityUserHolder;
import com.honghu.cloud.util.CommUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
/**
* 短视频带货
* @author Administrator
*
*/
@Slf4j
@RestController
@RequestMapping(value="/video")
public class VideoController {
@Autowired
private IVideoService videoService;
@Autowired
private IVideoClassService videoClassService;
@Autowired
private AccessoryFeignClient accessoryFeignClient;
@Autowired
private IVideoTopicService videoTopicService;
@Autowired
private QueryTools queryTools;
@Autowired
private UserFeignClient userFeignClient;
@Autowired
private IVideoCommentService videoCommentService;
@Autowired
private GoodsFeignClient goodsFeignClient;
@Autowired
private StoreFeignClient storeFeignClient;
@Autowired
private OrderFormFeignClient orderFormFeignClient;
@Autowired
private ModularClassFeignClient modularClassFeignClient;
@Autowired
private TXTemplateFeignClient tXTemplateFeignClient;
@RequestMapping(value = "/apiForFeign/selectByPrimaryKey", method = RequestMethod.GET)
public Video selectByPrimaryKey(@RequestParam("id")Long id) {
return videoService.selectByPrimaryKey(id);
}
@RequestMapping(value = "/apiForFeign/selectCount", method = RequestMethod.GET)
public int selectCount(@RequestBody Map<String, Object> params) {
return videoService.selectCount(params);
}
/**
* 视频首页
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/videoIndex", method = RequestMethod.POST)
public Map<String, Object> videoIndex(HttpServletRequest request,@RequestBody JSONObject json) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if(user_id != 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<>();
HashMap<String, Object> params = new HashMap<>();
String currentPage =null;
if (json.containsKey("currentPage")) {
currentPage = json.optString("currentPage");
}
/*String type = json.optString("type");
if ("same_city".equals(type)) { // 附近的人 ,按位置排序
String lat = json.optString("lat");
String lng = json.optString("lng");
if (StringUtils.isNotBlank(lat) && StringUtils.isNotBlank(lng)) {
Map<String, Object> params2 = queryTools.getParams(currentPage, "distance", "asc");
params2.put("lat", lat);
params2.put("lng", lng);
params2.put("distance_no_exceed", 5000000); // 筛选不超过50,000米的 (50千米)
params2.put("video_distance", "video_distance"); // 经纬度
if (json.containsKey("time_stamp")) {
params2.put("a_add_Time_less_than_equal", json.optString("time_stamp")); // 时间戳
}
Page<Video> list = videoService.list(params2);
result.put("list", list.getResult());
return ResponseCode.buildSuccessMap(result);
}
}*/
//大厅小视频
//查询视频分类
params.put("display", 1); //是否显示
params.put("orderBy", "sequence"); //排序
params.put("orderType", "asc");
List<VideoClass> VideoClass = videoClassService.queryPageList(params);
result.put("VideoClass", VideoClass);
if (VideoClass.size()>0) {
Map<String, Object> params2 = queryTools.getParams(currentPage, "a.sequence is null ,a.sequence asc , a.create_date", "desc");
if (json.containsKey("time_stamp")) {
params2.put("a_add_Time_less_than_equal", json.optString("time_stamp")); //时间戳
}
if (StringUtils.isNotBlank(json.optString("id"))) {
params2.put("a_video_class_id", json.optString("id")); //传分类id
}else {
params2.put("a_video_class_id", VideoClass.get(0).getId()); //查询第一个分类数据
}
params2.put("a_status", 1); //已审核
params2.put("a_watch_status_no", 1); //已审核
if (user_id!=null) {
params2.put("userId", user_id); //已审核
// params2.put("a_userid_no", user_id); //排除自己视频
}
Page<Video> list = videoService.list(params2);
result.put("list", list.getResult());
}
return ResponseCode.buildSuccessMap(result);
}
/**
* 某用户的视频列表
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/videoStore", method = RequestMethod.POST)
public Map<String, Object> videoStore(HttpServletRequest request,@RequestBody JSONObject json) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
Long store_user_id = json.optLong("store_user_id");
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<>();
String currentPage =null;
if (json.containsKey("currentPage")) {
currentPage = json.optString("currentPage");
}
Map<String, Object> params2 = queryTools.getParams(currentPage, "a.create_date", "desc");
if (json.containsKey("time_stamp")) {
params2.put("a_add_Time_less_than_equal", json.optString("time_stamp")); //时间戳
}
params2.put("a_status", 1); //已审核
params2.put("userId", user.getId());
params2.put("a_user_id", store_user_id);
Page<Video> list = videoService.list(params2);
result.put("list", list.getResult());
return ResponseCode.buildSuccessMap(result);
}
/**
* 某用户的视频列表
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/videoUser", method = RequestMethod.POST)
public Map<String, Object> videoUser(HttpServletRequest request,@RequestBody JSONObject json) {
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<>();
String currentPage =null;
if (json.containsKey("currentPage")) {
currentPage = json.optString("currentPage");
}
Map<String, Object> params2 = queryTools.getParams(currentPage, "a.create_date", "desc");
if (json.containsKey("time_stamp")) {
params2.put("a_add_Time_less_than_equal", json.optString("time_stamp")); //时间戳
}
String status = json.optString("status");
if (StringUtils.isNoneBlank(status)) {
params2.put("a_status", status); //已审核
}
params2.put("userId", user.getId());
params2.put("a_user_id", user_id);
Page<Video> list = videoService.list(params2);
result.put("list", list.getResult());
return ResponseCode.buildSuccessMap(result);
}
/**
* 视频详情
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/updateWatchStatus", method = RequestMethod.POST)
public Map<String, Object> updateWatchStatus(HttpServletRequest request, HttpServletResponse response,
@RequestBody JSONObject json) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id != null) {
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildReturnMap(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
}
String id = json.optString("id");
if (StringUtils.isBlank(id)) {
// 用户不存在
return ResponseCode.buildReturnMap(ResponseCode.QUERY_NO_DATA, null);
}
Video video = videoService.selectByPrimaryKey(CommUtil.null2Long(id));
if (video==null) {
return ResponseCode.buildReturnMap(ResponseCode.GOODSCLASS_CODE_NULL, null);
}
if (video.getWatch_status()!=null&&video.getWatch_status()==1) {
video.setWatch_status(0);
}else{
video.setWatch_status(1);
}
videoService.updateById(video);
return ResponseCode.buildSuccessMap(null);
}
/**
* 视频详情
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/delvideo", method = RequestMethod.POST)
public Map<String, Object> delvideo(HttpServletRequest request, HttpServletResponse response,
@RequestBody JSONObject json) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id != null) {
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if (user == null) {
// 用户不存在
return ResponseCode.buildReturnMap(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
}
String id = json.optString("id");
if (StringUtils.isBlank(id)) {
// id不存在
return ResponseCode.buildReturnMap(ResponseCode.QUERY_NO_DATA, null);
}
Video video = videoService.selectByPrimaryKey(CommUtil.null2Long(id));
if (video!=null) {
video.setDeleteStatus(1);
videoService.updateById(video);
}
return ResponseCode.buildSuccessMap(null);
}
/**
* 视频详情
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/videoItems", method = RequestMethod.POST)
public Map<String, Object> videoItems(HttpServletRequest request, HttpServletResponse response,
@RequestBody JSONObject json) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if (user_id != 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<>();
Long id = null;
if (json.containsKey("id")) {
id = json.optLong("id");
}
Video video = videoService.selectByPrimaryKey(id);
if (video != null) {
AccessoryDto selectByPrimaryKey = accessoryFeignClient.selectByPrimaryKey(video.getFile_id());
video.setFile(selectByPrimaryKey);
if (video.getVideo_topic_id()!=null) {
VideoTopic VideoTopic = videoTopicService.selectByPrimaryKey(video.getVideo_topic_id());
video.setTopic_name(VideoTopic!=null?VideoTopic.getName():null);
}
if (video.getUser_id()!=null) {
UserDto UserDto = userFeignClient.selectByPrimaryKey(video.getUser_id());
UserVideoDto userVideoDto = new UserVideoDto();
userVideoDto.setNickName(UserDto.getNickName());
if (UserDto.getPhoto()!=null) {
userVideoDto.setPhoto(UserDto.getPhoto());
}
video.setUser(UserDto!=null?userVideoDto:null);
}
// 用户存在的话
if (user_id!=null) {
VideoLike VideoLike = videoService.selectByUserLike(user_id, video.getId());
if (VideoLike != null) { // 是否点赞
video.setUserlike(1);
}
}
if (video.getGoods_id()!=null) {
GoodsDto goodsDto = goodsFeignClient.selectByPrimaryKey(video.getGoods_id());
video.setGoods(goodsDto);
}
result.put("video", video);
return ResponseCode.buildSuccessMap(result);
}
return ResponseCode.buildFailMap("信息有误", null);
}
/**
* 视频详情
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/add_forward", method = RequestMethod.POST)
public Map<String, Object> add_forward(HttpServletRequest request, HttpServletResponse response,
@RequestBody JSONObject json) {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<>();
Long id = null;
if (json.containsKey("id")) {
id = json.optLong("id");
}
Video video = videoService.selectByPrimaryKey(id);
if (video != null) {
// 转发数+1
video.setForward_num(video.getForward_num()+1);
videoService.updateById(video);
return ResponseCode.buildSuccessMap(result);
}
return ResponseCode.buildFailMap("信息有误", null);
}
/**
* (发布视频)查看话题
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/addvideoTopic", method = RequestMethod.POST)
public Map<String, Object> addvideoTopic(HttpServletRequest request, HttpServletResponse response,
@RequestBody JSONObject json) {
String currentPage = "0";
if (json.containsKey("currentPage")) {
currentPage = json.optString("currentPage");
}
HashMap<String, Object> result = new HashMap<>();
Map<String, Object> params = queryTools.getParams(currentPage, "update_date", "desc");
params.put("display", true); // 显示话题
if (json.containsKey("name")) {
params.put("name", json.optString("name"));
}
List<VideoTopic> queryPageList = videoTopicService.queryPageList(params);
result.put("VideoTopicList", queryPageList);
return ResponseCode.buildSuccessMap(result);
}
/**
* 发布视频,选择商品数据
* @param request
* @param json
* currentPage:当前页数
* pageSize:每页大小
* @return
*/
@RequestMapping("/userGoodsPage")
public Map<String, Object> userGoodsPage(HttpServletRequest request, HttpServletResponse response,
@RequestBody JSONObject json) {
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);
}
String type = json.optString("type");
String name = json.optString("name");
HashMap<Object, Object> result = new HashMap<>();
Map<String, Object> paraMap = queryTools.getParams(json.optString("currentPage"), null, null);
if (StringUtils.isNotBlank(name)) {
paraMap.put("honghu_goods_name", name); // 搜索商品名
}
// 查询平台商品
if ("1".equals(type)) {
paraMap.put("goods_status", 0); // 商品状态(已上架的商品)
paraMap.put("live_uid", user.getId()); // 中间表(已上架的商品)
if (user.getStore_id()!=null) {
paraMap.put("no_goods_store_id", user.getStore_id()); // 商品状态(已上架的商品)
}
/*paraMap.put("hall_goods", 1); // 大厅商品
List<GoodsDto> queryPageList = goodsFeignClient.queryPageList(paraMap); // 查询店铺商品列表*/
Map<String, Object> queryPageList = goodsFeignClient.goodsPageList(paraMap);
result.put("queryPageList", queryPageList);
}
// 查询已购
if ("2".equals(type)) {
paraMap.put("user_id", user.getId()); // 购买的商品
List<SnapshotDto> querySnapShotList = orderFormFeignClient.querySnapShotList(paraMap); // 查询店铺商品列表
result.put("queryPageList", querySnapShotList);
}
// 查询店铺商品
if ("3".equals(type) && user.getStore_id() != null) {
StoreDto storeDto = storeFeignClient.selectByPrimaryKey(user.getStore_id());
if (storeDto != null && storeDto.getStore_status() == 15) { // 店铺存在且正常开店
paraMap.put("goods_store_id", user.getStore_id()); // 店铺id
paraMap.put("goods_status", 0); // 商品状态(已上架的商品)
// List<GoodsDto> queryPageList = goodsFeignClient.queryPageList(paraMap); // 查询店铺商品列表
Map<String, Object> queryPageList = goodsFeignClient.goodsPageList(paraMap);
result.put("queryPageList", queryPageList);
}
}
return ResponseCode.buildSuccessMap(result);
}
/**
* 发布视频保存
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/videoSave", method = RequestMethod.POST)
public Map<String, Object> videoSave(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json) {
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<>();
String video_topic_id = json.optString("video_topic_id");
String goods_id = json.optString("goods_id");
String file_id = json.optString("file_id");
String description = json.optString("description");
String file_photo_id = json.optString("file_photo_id");
String lat = json.optString("lat");
String lng = json.optString("lng");
Video video = new Video();
video.setAddTime(new Date());
if (StringUtils.isNotBlank(goods_id)) {
GoodsDto goodsDto = goodsFeignClient.selectByPrimaryKey(CommUtil.null2Long(goods_id));
if (goodsDto==null) {
return ResponseCode.buildFailMap("商品不存在", null);
}
video.setGoods_id(CommUtil.null2Long(goods_id));
if (goodsDto.getGoods_store_id() != null && user.getStore_id() != null
&& user.getStore_id().toString().equals(goodsDto.getGoods_store_id().toString())
&& goodsDto.getGoods_nearby() == 1) { // 为附近配送, 显示店铺
video.setStore_id(goodsDto.getGoods_store_id());
}
}
if (StringUtils.isNotBlank(video_topic_id)) {
video.setVideo_topic_id(CommUtil.null2Long(video_topic_id));
}
if (StringUtils.isNotBlank(video_topic_id)) {
video.setVideo_topic_id(CommUtil.null2Long(video_topic_id));
}
if (StringUtils.isNotBlank(file_id)) {
video.setFile_id(CommUtil.null2Long(file_id));
}
if (StringUtils.isNotBlank(file_photo_id)) {
video.setFile_photo_id(CommUtil.null2Long(file_photo_id));
}
if (StringUtils.isNotBlank(lat)&&StringUtils.isNotBlank(lng)) {
video.setLng(Double.valueOf(lng));
video.setLat(Double.valueOf(lat));
}
video.setDescription(description);
video.setLike_num(0);
video.setStatus(0);
video.setComment_num(0);
video.setUser_id(user.getId());
video.setCreate_date(new Date());
video.setUpdate_date(new Date());
videoService.saveEntity(video);
//通知用户审核
try{
Map<String, Object> params = new HashMap<String, Object>();
params.put("kind", "视频");
params.put("nickname", user.getNickName());
tXTemplateFeignClient.auditNsgNote(params);
}catch(Exception e){
log.error("VideoController >> videoSave >> auditNsgNote " + e.getMessage());
}
return ResponseCode.buildSuccessMap(result);
}
/**
* 视频点赞
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/addVideoUserLike", method = RequestMethod.POST)
public Map<String, Object> addVideoUserLike(HttpServletRequest request, HttpServletResponse response,
@RequestBody JSONObject json) {
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);
}
String video_id=null;
if (json.containsKey("video_id")) {
video_id=json.optString("video_id");
}
if (StringUtils.isBlank(video_id)) {
return ResponseCode.buildFailMap("参数信息错误", null);
}
Video video = videoService.selectByPrimaryKey(CommUtil.null2Long(video_id));
if (video==null) {
return ResponseCode.buildFailMap("视频不存在", null);
}
video.setLike_num(video.getLike_num()+1); //喜欢数+1
videoService.updateById(video);
VideoLike videoLike = new VideoLike();
videoLike.setCreate_date(new Date());
videoLike.setUser_id(user.getId());
videoLike.setVideo_id(CommUtil.null2Long(video_id));
videoService.saveVideoLike(videoLike); //保存
return ResponseCode.buildSuccessMap(null);
}
/**
* 视频取消赞
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/delVideoUserLike", method = RequestMethod.POST)
public Map<String, Object> delVideoUserLike(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json) {
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);
}
String video_id=null;
if (json.containsKey("video_id")) {
video_id=json.optString("video_id");
}
if (StringUtils.isBlank(video_id)) {
return ResponseCode.buildFailMap("参数信息错误", null);
}
Video video = videoService.selectByPrimaryKey(CommUtil.null2Long(video_id));
if (video==null) {
return ResponseCode.buildFailMap("视频不存在", null);
}
video.setLike_num(video.getLike_num()-1); //点赞数-1
videoService.updateById(video);
videoService.delVideoLike(user.getId(),CommUtil.null2Long(video_id)); //删除中间表
return ResponseCode.buildSuccessMap(null);
}
/**
* 查看评论
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/videoComment", method = RequestMethod.POST)
public Map<String, Object> videoComment(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json) {
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if(user_id == null){
return ResponseCode.buildFailMap("token无效", null);
}
HashMap<String, Object> result = new HashMap<>();
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if(user == null){
// 用户不存在
return ResponseCode.buildReturnMap(ResponseCode.USER_NOT_EXISTS_ERROR, null);
}
Map<String, Object> params = queryTools.getParams(json.optString("currentPage"), "a.update_date", "desc");
params.put("video_id", json.optString("video_id"));
params.put("userId", user.getId());
Page<VideoComment> list = videoCommentService.list(params);
result.put("queryPageList", list.getResult());
return ResponseCode.buildSuccessMap(result);
}
/**
* 查看详细评论(二级页面
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/videoCommentDetailed", method = RequestMethod.POST)
public Map<String, Object> videoCommentDetailed(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json) {
HashMap<String, Object> result = new HashMap<>();
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(!json.containsKey("p_id")){
// p_id不存在
return ResponseCode.buildReturnMap(ResponseCode.PARAMETER_ERROR, null);
}
Map<String, Object> params =Maps.newHashMap();
params.put("a_id", json.optLong("p_id"));
params.put("userId", user.getId()); //查看用户是否点赞
List<VideoComment> queryPages = videoCommentService.queryPages(params);
if (queryPages.size()<1) { //改评论不存在
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
}
result.put("videocomment", queryPages.get(0));
//
params.clear();
params = queryTools.getParams(json.optString("currentPage"), "a.update_date", "desc");
params.put("p_id", json.optString("p_id")); //上级id
params.put("userId", user.getId()); //查看用户是否点赞
Page<VideoComment> list = videoCommentService.list(params);
result.put("queryPageList", list.getResult());
return ResponseCode.buildSuccessMap(result);
}
/**
* 发布评论保存
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/videoCommentSave", method = RequestMethod.POST)
public Map<String, Object> videoCommentSave(HttpServletRequest request, HttpServletResponse response,
@RequestBody JSONObject json) {
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<>();
String content = json.optString("content");
String video_id = json.optString("video_id");
String p_id = json.optString("p_id");
boolean aliSecurity = AliSmsUtil.aliSecurity(content);
if(!aliSecurity){//内容检测不合法
return ResponseCode.buildReturnMap(ResponseCode.ALISECURITY_ERROR, null);
}
if (StringUtils.isNotBlank(video_id)) {
Video video = videoService.selectByPrimaryKey(CommUtil.null2Long(video_id));
if (video == null) {// 数据不存在
return ResponseCode.buildReturnMap(ResponseCode.GOODSCLASS_CODE_NULL, null);
} /*
* else { video.setComment_num(video.getComment_num()+1);
* //评论数+1 videoService.updateById(video); }
*/
VideoComment videoComment = new VideoComment();
videoComment.setUser_id(user.getId());
if (StringUtils.isNotBlank(p_id)) {
videoComment.setP_id(CommUtil.null2Long(p_id));
}
videoComment.setCreate_date(new Date());
videoComment.setLike_num(0);
videoComment.setVideo_id(CommUtil.null2Long(video_id));
videoComment.setDeleteStatus(0);
videoComment.setUpdate_date(new Date());
if (json.containsKey("reply_user_id")) {
videoComment.setReply_user_id(json.optLong("reply_user_id"));
}
videoComment.setStatus(1);
videoComment.setContent(content);
videoCommentService.saveEntity(videoComment);
video.setComment_num(video.getComment_num() + 1);
videoService.updateById(video);
return ResponseCode.buildSuccessMap(result);
} else { // 参数没传
return ResponseCode.buildReturnMap(ResponseCode.PARAM_ERROR, null);
}
}
/**
* 删除
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/delVideoComment", method = RequestMethod.POST)
public Map<String, Object> delVideoComment(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json) {
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);
}
String id = json.optString("id");
VideoComment videoComment = videoCommentService.selectByPrimaryKey(CommUtil.null2Long(id));
if (videoComment==null||!videoComment.getUser_id().toString().equals(user_id.toString())) {
return ResponseCode.buildReturnMap(ResponseCode.GOODSCLASS_CODE_NULL, null);
}
Video video = videoService.selectByPrimaryKey(videoComment.getVideo_id());
video.setComment_num(video.getComment_num()-1);
videoService.updateById(video);
videoCommentService.deleteById(CommUtil.null2Long(id));
return ResponseCode.buildSuccessMap(null);
}
/**
* 评论点赞
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/addVideoCommentLike", method = RequestMethod.POST)
public Map<String, Object> addVideoCommentLike(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json) {
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);
}
String id=null;
if (json.containsKey("id")) {
id=json.optString("id");
}
if (StringUtils.isBlank(id)) {
return ResponseCode.buildFailMap("参数信息错误", null);
}
VideoComment videoComment = videoCommentService.selectByPrimaryKey(CommUtil.null2Long(id));
if (videoComment==null) {
return ResponseCode.buildFailMap("评论不存在", null);
}
videoComment.setLike_num(videoComment.getLike_num()+1); //喜欢数+1
videoCommentService.updateById(videoComment);
VideoCommentLike videoCommentLike = new VideoCommentLike();
videoCommentLike.setCreate_date(new Date());
videoCommentLike.setUser_id(user.getId());
videoCommentLike.setVideo_comment_id(CommUtil.null2Long(id));
videoCommentService.saveVideoCommentLike(videoCommentLike); //保存
return ResponseCode.buildSuccessMap(null);
}
/**
* 评论取消点赞
* @param order
* @param localPath
* @param buyer
*/
@RequestMapping(value = "/delVideoCommentLike", method = RequestMethod.POST)
public Map<String, Object> delVideoCommentLike(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json) {
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);
}
String id=null;
if (json.containsKey("id")) {
id=json.optString("id");
}
if (StringUtils.isBlank(id)) {
return ResponseCode.buildFailMap("参数信息错误", null);
}
VideoComment videoComment = videoCommentService.selectByPrimaryKey(CommUtil.null2Long(id));
if (videoComment==null) {
return ResponseCode.buildFailMap("评论不存在", null);
}
videoComment.setLike_num(videoComment.getLike_num()-1); //喜欢数-1
videoCommentService.updateById(videoComment);
videoCommentService.delVideoCommentLike(user.getId(),CommUtil.null2Long(id)); //删除中间表
return ResponseCode.buildSuccessMap(null);
}
//推荐视频
@RequestMapping(value = "/recomVideo", method = RequestMethod.POST)
public Map<String, Object> recomVideo(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json){
String currentPage = json.optString("currentPage");
Map<String, Object> params = queryTools.getParams(currentPage, "a.create_date", "desc");
params.put("a_video_class_id", 1);
Page<Video> list = videoService.list(params);
return ResponseCode.buildSuccessMap(list);
}
/**
* 我的视频
*/
@RequestMapping(value = "/myVideoList", method = RequestMethod.POST)
public Map<String, Object> myVideoList(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json) {
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);
}
String currentPage = json.optString("currentPage");
String status = json.optString("status");
HashMap<String, Object> result = new HashMap<>();
Map<String, Object> params = queryTools.getParams(currentPage, "a.create_date", "desc");
if (StringUtils.isNotBlank(status)) {
params.put("a_status",status);
}
params.put("a_user_id",user_id);
Page<Video> list = videoService.list(params);
result.put("list", list);
//获取获赞数
Long selectCountUserLike = videoService.selectCountUserLike(user_id);
result.put("UserLike", selectCountUserLike);
return ResponseCode.buildSuccessMap(result);
}
/**
* 主播添加的商品
* @param json
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/myLiveGoodsApp", method = RequestMethod.POST)
public ResponseVO myLiveGoods(@RequestBody JSONObject json, HttpServletRequest request, HttpServletResponse response) {
String currentPage = json.optString("currentPage");
Integer pageSize = json.optInt("pageSize"); //数据长度
String orderBy = json.optString("orderBy"); //排序字段(默认添加的时间)
String orderType = json.optString("orderType"); //排序方式(倒序)
String type = json.optString("type"); //hall_goods 大厅商品 store_goods 店铺商品
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if(user_id == null){
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_CANNOT_EMPTY, null); //用户userName不能为空
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if(user == null){
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null); //用户不存在
}
if(StringUtils.isEmpty(type)){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_USER_GOODS_TYPE_ISNULL, null); //用户我的商品类型不能为空
}
Map<String,Object> maps= queryTools.getParams(currentPage, pageSize, orderBy, orderType);
maps.put("goods_status", 0);
if(StringUtils.equals(type, "hall_goods")){
maps.put("live_uid", user.getId());
if(user.getStore_id() != null){
maps.put("no_goods_store_id", user.getStore_id());
}
}
Map<String, Object> resultMap = new HashMap<String, Object>();
if(StringUtils.equals(type, "store_goods")){
maps.put("goods_store_id", user.getStore_id());
if(user.getStore_id() == null){
resultMap.put("currentPage", 0);
resultMap.put("pages", 0);
resultMap.put("pageSize", 12);
List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
resultMap.put("result", list);
resultMap.put("rowCount", 0);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);
}
}
resultMap = goodsFeignClient.getQueryPageList(maps);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);
}
/**
* 大厅商品
* @param json
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/hallGoodsApp", method = RequestMethod.POST)
public ResponseVO hallGoods(@RequestBody JSONObject json, HttpServletRequest request, HttpServletResponse response) {
String currentPage = json.optString("currentPage");
Integer pageSize = json.optInt("pageSize"); //数据长度
String orderBy = json.optString("orderBy"); //排序字段(默认添加的时间)
String orderType = json.optString("orderType"); //排序方式(倒序)
String goods_name = json.optString("goods_name"); //模糊查询商品名称
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if(user_id == null){
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_CANNOT_EMPTY, null); //用户userName不能为空
}
UserDto user = userFeignClient.selectByPrimaryKey(user_id);
if(user == null){
return ResponseCode.buildEnumResponseVO(ResponseCode.USER_DOES_NOT_EXIST, null); //用户不存在
}
Map<String,Object> maps= queryTools.getParams(currentPage, pageSize, orderBy, orderType);
maps.put("goods_status", 0);
maps.put("hall_goods", 1);
if (StringUtils.isNotBlank(goods_name)) {
maps.put("honghu_goods_name", goods_name);
}
maps.put("uid", user.getId());
maps.put("liveUserAdd", "yes");
maps.put("is_distribution", "yes");
Map<String, Object> resultMap = goodsFeignClient.getQueryPageList(maps);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, resultMap);
}
/**
* 添加商品
* @param json
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/userLiveGoodsAddApp", method = RequestMethod.POST)
public ResponseVO user_live_goods_add(@RequestBody JSONObject json, HttpServletRequest request) {
Long goods_id = json.optLong("goods_id"); //商品编号
if(goods_id == null || goods_id <=0){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_ID_ISNULL, null); //商品编号不能为空
}
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if(user_id == null){
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_CANNOT_EMPTY, null); //用户userName不能为空
}
Integer count = goodsFeignClient.findUserLiveGoods(user_id, goods_id);
if(count != null && count > 0 ){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_ADD_REPEAT_ISNULL, null); //重复添加数据
}
Map<String, Object> params = new HashMap<String,Object>();
params.put("uid", user_id);
params.put("goods_id", goods_id);
goodsFeignClient.addUserLiveGoods(params);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null);
}
/**
* 移除商品
* @param json
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/userLiveGoodsDelApp", method = RequestMethod.POST)
public ResponseVO user_live_goods_del(@RequestBody JSONObject json, HttpServletRequest request) {
Long goods_id = json.optLong("goods_id"); //商品编号
if(goods_id == null || goods_id <=0){
return ResponseCode.buildEnumResponseVO(ResponseCode.LIVE_GOODS_ID_ISNULL, null); //商品编号不能为空
}
String tokenStr = request.getHeader("token");
Long user_id = SecurityUserHolder.getTokenUserId(tokenStr);
if(user_id == null){
return ResponseCode.buildEnumResponseVO(ResponseCode.TOKEN_CANNOT_EMPTY, null); //用户userName不能为空
}
Map<String, Object> params = new HashMap<String,Object>();
params.put("uid", CommUtil.null2Long(user_id));
params.put("goods_id", CommUtil.null2Long(goods_id));
goodsFeignClient.delUserLiveGoods(params);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, null);
}
}
|