提交 bc268fdc 作者: 刘明祎-运维用途

Merge branch 'develop'

流水线 #8300 已通过 于阶段
in 2 分 57 秒
package com.mmc.csf.release.forum.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UpdateDynamicDO implements Serializable{
@ApiModelProperty(value = "动态id")
private Integer id;
@ApiModelProperty(value = "动态描述")
private String description;
@ApiModelProperty(value = "媒体资源")
private List<MediaVO> mediaVO;
}
......@@ -109,6 +109,7 @@ public class RedisConstant {
public final static String UAV_DUMMY_DATA="UAV_DUMMY_DATA_KEY";
public final static String VOTE = "VOTE";
/**
* tagInfoAllot表的缓存key
*/
......
......@@ -18,4 +18,4 @@ patches:
images:
- name: REGISTRY/NAMESPACE/IMAGE:TAG
newName: mmc-registry.cn-shenzhen.cr.aliyuncs.com/sharefly-dev/ims
newTag: f3d4b90bc2e3aa1a3d671fc4f5d79f6f6182400b
newTag: 77b23eebda554fc3bb58b646ffd8774af8280172
......@@ -8,6 +8,7 @@ import com.mmc.csf.release.entity.gambit.ForumAttentionDO;
import com.mmc.csf.release.forum.vo.CommentVO;
import com.mmc.csf.release.forum.vo.DynamicVO;
import com.mmc.csf.release.forum.vo.ReplyToAReviewVO;
import com.mmc.csf.release.forum.vo.UpdateDynamicDO;
import com.mmc.csf.release.gambit.dto.ForumGambitDTO;
import com.mmc.csf.release.gambit.dto.PostingLeaderboardDTO;
import com.mmc.csf.release.gambit.qo.ForumGambitQO;
......@@ -43,6 +44,13 @@ public class DynamicController extends BaseController {
return dynamicService.insertDynamic(dynamicVO, this.getUserLoginInfoFromRedis(request).getUserAccountId(), request);
}
@ApiOperation(value = "动态修改")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/updateDynamic")
public ResultBody updateDynamic(@RequestBody UpdateDynamicDO updateDynamicDO, HttpServletRequest request) {
return dynamicService.updateDynamic(updateDynamicDO);
}
@ApiOperation(value = "点赞或取消点赞")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@GetMapping("/likeOrCancel")
......@@ -52,6 +60,13 @@ public class DynamicController extends BaseController {
this.getUserLoginInfoFromRedis(request).getUserAccountId(), dynamicId);
}
@ApiOperation(value = "查看剩余投票次数")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@GetMapping("/getRemainingVotes")
public ResultBody getRemainingVotes(@ApiParam(value = "动态id") @RequestParam Integer gambitId,HttpServletRequest request) {
return dynamicService.getRemainingVotes(gambitId,this.getUserLoginInfoFromRedis(request).getUserAccountId());
}
@ApiOperation(value = "update-评论动态/回复")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/comment")
......@@ -96,10 +111,13 @@ public class DynamicController extends BaseController {
@RequestParam(required = false) Integer gambitId, @RequestParam(required = false) Integer id,
@RequestParam(required = false) Integer userAccountId,
@RequestParam(required = false) String description,
@RequestParam(required = false) List<String> gambitName) {
@RequestParam(required = false) List<String> gambitName,
@RequestParam(required = false) Integer needSort
) {
return ResultBody.success(
dynamicService.dynamicList(
pageNo, pageSize, this.getUserLoginInfoFromRedis(request).getUserAccountId(),gambitId,id,userAccountId,description,gambitName));
pageNo, pageSize, this.getUserLoginInfoFromRedis(request).getUserAccountId(),gambitId,id,userAccountId,description,gambitName,needSort));
}
@ApiOperation(value = "动态 列表(未登录)")
......@@ -110,10 +128,12 @@ public class DynamicController extends BaseController {
@RequestParam(required = false) Integer gambitId, @RequestParam(required = false) Integer id,
@RequestParam(required = false) Integer userAccountId,
@RequestParam(required = false) String description,
@RequestParam(required = false) List<String> gambitName) {
@RequestParam(required = false) List<String> gambitName,
@RequestParam(required = false) Integer needSort
) {
return ResultBody.success(
dynamicService.dynamicList(
pageNo, pageSize, 0,gambitId,id,userAccountId,description,gambitName));
pageNo, pageSize, 0,gambitId,id,userAccountId,description,gambitName,needSort));
}
@ApiOperation(value = "new-小程序-返回最新5条带动态的图片")
......
......@@ -94,9 +94,9 @@ public interface DynamicDao {
* @param pageSize 页面大小
* @return {@link List}<{@link ForumDynamicDO}>
*/
List<ForumDynamicDO> dynamicList(int itemIndex, Integer pageSize,Integer id,Integer userAccountIds,String description);
List<ForumDynamicDO> dynamicList(int itemIndex, Integer pageSize,Integer id,Integer userAccountIds,String description,Integer needSort);
List<ForumDynamicDO> dynamicListGambit(int itemIndex, Integer pageSize,Integer id,Integer userAccountIds,Integer gambitId);
List<ForumDynamicDO> dynamicListGambit(int itemIndex, Integer pageSize,Integer id,Integer userAccountIds,Integer gambitId,Integer needSort);
/**
* 列表动态图片
......@@ -133,6 +133,9 @@ public interface DynamicDao {
void insertResource(
@Param("dynamicId") Integer dynamicId, @Param("type") int type, @Param("url") String url);
void deleteResource(@Param("dynamicId") Integer dynamicId);
void updateDynamicDescription(@Param("dynamicId") Integer dynamicId, @Param("description") String description);
List<ForumResourceDO> listDynamicResources(Integer dynamicId);
List<ForumDynamicDO> getDynamicComment(String dynamicId);
......
......@@ -91,6 +91,8 @@ public class ForumDynamicDO extends BaseDO implements Serializable {
@ApiModelProperty("")
private Integer transpond;
@ApiModelProperty("话题id")
private Integer gambitId;
public ForumDynamicDO(DynamicVO dynamicVO) {
this.gambitIcon=dynamicVO.getGambitIcon();
this.gambitCover=dynamicVO.getGambitCover();
......
......@@ -7,6 +7,7 @@ import com.mmc.csf.common.util.web.ResultBody;
import com.mmc.csf.release.entity.gambit.ForumAttentionDO;
import com.mmc.csf.release.forum.vo.CommentVO;
import com.mmc.csf.release.forum.vo.DynamicVO;
import com.mmc.csf.release.forum.vo.UpdateDynamicDO;
import com.mmc.csf.release.gambit.qo.ForumGambitQO;
import com.mmc.csf.release.gambit.qo.PostingLeaderboardQO;
import java.util.List;
......@@ -16,7 +17,7 @@ import java.util.List;
*/
public interface DynamicService {
/**
* 插入动态
* 插入帖子
*
* @param dynamicVO 动态
* @return {@link ResultBody}
......@@ -24,6 +25,11 @@ public interface DynamicService {
ResultBody insertDynamic(DynamicVO dynamicVO, Integer userAccountId, HttpServletRequest request);
/**
* 修改帖子
* @return {@link ResultBody}
*/
ResultBody updateDynamic(UpdateDynamicDO updateDynamicDO);
/**
* 点赞动态
*
* @param userId 用户id
......@@ -33,6 +39,14 @@ public interface DynamicService {
ResultBody likeDynamic(Integer userId, Integer dynamicId);
/**
* 返回剩余可投票次数
* @param gambitId 帖子id
* @param userAccountId 用户id
* @return {@link ResultBody}
*/
ResultBody getRemainingVotes(Integer gambitId, Integer userAccountId);
/**
* 评论动态
*
* @param commentVO 评论信息
......@@ -58,7 +72,7 @@ public interface DynamicService {
ResultBody dynamicDetails(Integer dynamicId, Integer userId, HttpServletRequest request);
PageResult dynamicList(
Integer pageNo, Integer pageSize, Integer userAccountId, Integer gambitId, Integer id, Integer userId, String description, List<String> gambitName);
Integer pageNo, Integer pageSize, Integer userAccountId, Integer gambitId, Integer id, Integer userId, String description, List<String> gambitName,Integer needSort);
ResultBody recentNewsList(Integer userAccountId);
......
......@@ -10,8 +10,10 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.mmc.csf.common.util.redis.RedisConstant;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
......@@ -67,6 +69,9 @@ public class DynamicServiceImpl implements DynamicService {
@Autowired
private RestTemplate restTemplate;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Value("${iuav.userapp.url}")
private String userApp;
......@@ -167,15 +172,39 @@ public class DynamicServiceImpl implements DynamicService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public ResultBody updateDynamic(UpdateDynamicDO updateDynamicDO) {
List<MediaVO> mediaVOList = updateDynamicDO.getMediaVO();
dynamicDao.deleteResource(updateDynamicDO.getId());
if(mediaVOList != null){
for (MediaVO mediaVO : mediaVOList) {
dynamicDao.insertResource(updateDynamicDO.getId(), mediaVO.getType(), mediaVO.getUrl());
}
}
if(updateDynamicDO.getDescription() != null){
dynamicDao.updateDynamicDescription(updateDynamicDO.getId(), updateDynamicDO.getDescription());
}
return ResultBody.success("修改成功");
}
@Override
public ResultBody likeDynamic(Integer userId, Integer dynamicId) {
// 获取动态信息
ForumDynamicDO forumDynamicDO = dynamicDao.getDynamicInfo(dynamicId);
Integer gambitId = forumDynamicDO.getGambitId();
if (!likeDAO.isLiked(userId, dynamicId)) {
if(!isVoted(gambitId, userId)){
return ResultBody.error("投票已经上上限");
}
likeDAO.insertLike(userId, dynamicId);
dynamicDao.updateDynamicLikeCount(dynamicId, forumDynamicDO.getVersion());
dynamicDao.forumCount(forumDynamicDO.getUserAccountId());
//评论
} else {
if(gambitId == 1002 || gambitId == 1001 || gambitId == 1003){
return ResultBody.error("不能重复投票");
}
likeDAO.deleteLike(userId, dynamicId);
dynamicDao.updateSubDynamicLikeCount(dynamicId, forumDynamicDO.getVersion());
dynamicDao.forumCountNO(forumDynamicDO.getUserAccountId());
......@@ -183,6 +212,37 @@ public class DynamicServiceImpl implements DynamicService {
return ResultBody.success();
}
private boolean isVoted(Integer gambitId, Integer userAccountId) {
if (gambitId == 1001 || gambitId == 1002 || gambitId == 1003) {
boolean keyExists = stringRedisTemplate.hasKey(RedisConstant.VOTE + gambitId + userAccountId);
if(keyExists){
String voteStr = stringRedisTemplate.opsForValue().get(RedisConstant.VOTE + gambitId +userAccountId);
int voteCount = Integer.parseInt(voteStr);
if(voteCount >= 5){
return false;
}
stringRedisTemplate.opsForValue().set(RedisConstant.VOTE + gambitId + userAccountId, String.valueOf(voteCount+1));
return true;
}
stringRedisTemplate.opsForValue().set(RedisConstant.VOTE + gambitId + userAccountId, "1");
return true;
}
return true;
}
@Override
public ResultBody getRemainingVotes(Integer gambitId, Integer userAccountId) {
boolean keyExists = stringRedisTemplate.hasKey(RedisConstant.VOTE + gambitId + userAccountId);
if(keyExists){
String voteStr = stringRedisTemplate.opsForValue().get(RedisConstant.VOTE + gambitId +userAccountId);
int voteCount = Integer.parseInt(voteStr);
//voteCount是已经投票的次数,一个最多投五次
return ResultBody.success(5-voteCount);
}
return ResultBody.success(5);
}
@Override
@Transactional(rollbackFor = Exception.class)
public ResultBody commentDynamic(CommentVO commentVO, Integer userAccountId, HttpServletRequest request) {
......@@ -300,7 +360,7 @@ public class DynamicServiceImpl implements DynamicService {
@Override
public PageResult dynamicList(
Integer pageNo, Integer pageSize, Integer userId, Integer gambitId,Integer dynId,Integer userAccountIds,
String description,List<String> gambitName) {
String description,List<String> gambitName,Integer needSort) {
Integer tokenUserId =userId;
Integer inUserId =userAccountIds;
int count = dynamicDao.countDynamicList(dynId,userAccountIds,description);
......@@ -308,17 +368,17 @@ public class DynamicServiceImpl implements DynamicService {
return PageResult.buildPage(pageNo, pageSize, 0);
}
int itemIndex = (pageNo - 1) * pageSize;
List<ForumDynamicDO> forumDynamicList = dynamicDao.dynamicList(itemIndex, pageSize,dynId,userAccountIds,description);
List<ForumDynamicDO> forumDynamicList = dynamicDao.dynamicList(itemIndex, pageSize,dynId,userAccountIds,description,needSort);
if (gambitName!=null){
for (String s : gambitName) {
Integer integer = dynamicDao.gambitName(s);
forumDynamicList = dynamicDao.dynamicListGambit(itemIndex, pageSize,dynId,userAccountIds,integer);
forumDynamicList = dynamicDao.dynamicListGambit(itemIndex, pageSize,dynId,userAccountIds,integer,needSort);
}
}
// List<Integer> integers = dynamicDao.gambitName(gambitName);
if (gambitId!=null){
forumDynamicList = dynamicDao.dynamicListGambit(itemIndex, pageSize,dynId,userAccountIds,gambitId);
forumDynamicList = dynamicDao.dynamicListGambit(itemIndex, pageSize,dynId,userAccountIds,gambitId,needSort);
}
for (ForumDynamicDO forumDynamicDO : forumDynamicList) {
Integer dynamicId = forumDynamicDO.getDynamicId();
......
......@@ -357,6 +357,11 @@
set check_status = #{status}
where id = #{dynamicId}
</update>
<update id="updateDynamicDescription">
update forum_dynamic
set description = #{description}
where id = #{dynamicId}
</update>
<delete id="deleteDynamic">
delete
from forum_dynamic
......@@ -370,10 +375,14 @@
</foreach>
</where>
</delete>
<delete id="deleteResource">
delete from forum_resource
where dynamic_id = #{dynamicId}
</delete>
<select id="getDynamicInfo" resultType="com.mmc.csf.release.entity.forum.ForumDynamicDO">
select id,
select fd.id,
version,
user_account_id,
fd.user_account_id,
root_path,
description,
location,
......@@ -381,9 +390,11 @@
lon,
likes_count,
comments_count,
create_time
from forum_dynamic
where id = #{dynamicId}
fd.create_time,
gambit_id
from forum_dynamic fd
left join forum_dynamic_gambit on forum_dynamic_gambit.dynamic_id = fd.id
where fd.id = #{dynamicId}
and is_deleted = 0
</select>
<select id="countDynamicList" resultType="java.lang.Integer">
......@@ -428,7 +439,14 @@
<if test="description!=null and description!='' ">
and description like concat('%',#{description},'%')
</if>
order by create_time desc
<choose>
<when test="needSort != null">
order by likes_count desc
</when>
<otherwise>
order by create_time desc
</otherwise>
</choose>
LIMIT #{itemIndex}, #{pageSize}
</select>
......@@ -461,8 +479,14 @@
<if test="userAccountIds!=null">
and fd.user_account_id=#{userAccountIds}
</if>
ORDER BY
fd.create_time DESC
<choose>
<when test="needSort != null">
order by likes_count desc
</when>
<otherwise>
order by create_time desc
</otherwise>
</choose>
LIMIT #{itemIndex}, #{pageSize}
</select>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论