Commit 6675f7fb authored by 万成波's avatar 万成波

优化代码

parent 51a7dd2c
......@@ -222,7 +222,6 @@ public class MBbsMomentController {
/**
* 置顶评论
*/
@ApiOperation("置顶评论")
@PostMapping("/comment/top")
public AjaxResult topComment(@RequestBody BbsCommentTopBO bo) {
ValidateOperations.generalValidate(bo);
......
......@@ -7,6 +7,7 @@ import com.tangguo.common.core.page.TableDataInfo;
import com.tangguo.common.enums.BusinessType;
import com.tangguo.common.utils.poi.ExcelUtil;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.bo.BbsMomentTopBO;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.service.IBbsMomentService;
import io.swagger.annotations.Api;
......@@ -84,4 +85,17 @@ public class BbsMomentController extends BaseController {
return AjaxResult.success();
}
/**
* 置顶动态
*/
@ApiOperation("置顶动态")
@PreAuthorize("@ss.hasPermi('bbs:moment:edit')")
@Log(title = "动态", businessType = BusinessType.DELETE)
@PutMapping("/top")
public AjaxResult top(@RequestBody BbsMomentTopBO bo) {
this.bbsMomentService.topComment(bo);
return AjaxResult.success();
}
}
......@@ -107,6 +107,14 @@ public class BbsMoment extends BaseEntity {
@ApiModelProperty("动态投票人数")
private Integer voteCount;
/** 是否置顶:0 否、1 是 */
@ApiModelProperty("评论是否置顶:0 否、1 是")
private Integer isTop;
/** 置顶时间 */
@ApiModelProperty("评论置顶时间")
private Date topTime;
/** 用户姓名 */
@Excel(name = "姓名", sort = 1)
......
package com.tangguo.domain.bo;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
*
*
* @author 谈笑
* @createTime 2025-11-05 16:12:43 星期三
*/
@Data
public class BbsMomentTopBO {
/**
* 动态Id
*/
@NotNull(message = "动态Id不能为空")
private Long momentId;
/**
* 置顶状态:0 取消置顶、1 置顶
*/
@NotNull(message = "置顶状态不能为空")
private Integer isTop;
}
......@@ -81,6 +81,9 @@ public class BbsMomentListVO {
/** 是否本人动态:0 否、1 是 */
private Integer isSelf;
/** 是否置顶:0 否、1 是 */
private Integer isTop;
/** 动态附件 */
private List<BbsAttachmentVO> attachments;
......
......@@ -33,7 +33,6 @@ public interface IBbsMomentService extends IService<BbsMoment> {
*/
BbsMomentListVO selectBbsMoment(Long momentId);
/**
* 删除动态
*
......@@ -42,6 +41,14 @@ public interface IBbsMomentService extends IService<BbsMoment> {
void deleteMoment(Long id);
/**
* 置顶动态
*
* @param bo 动态
*/
void topComment(BbsMomentTopBO bo);
/**
* 查询用户动态统计
*
......
......@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.dfa.FoundWord;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.core.domain.entity.SysUser;
......@@ -79,11 +80,14 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
.collect(Collectors.toList());
dbMoment.setAttachments(atts);
String[] deptIds = dbMoment.getAncestors().split(",");
if (ArrayUtil.isNotEmpty(deptIds)) {
String deptName = this.baseMapper.selectBbsMomentDept(deptIds);
dbMoment.setFullDeptName(deptName);
}
String ancestors = dbMoment.getAncestors();
if (StrUtil.isNotBlank(ancestors)) {
String[] deptIds = ancestors.split(",");
if (ArrayUtil.isNotEmpty(deptIds)) {
String deptName = this.baseMapper.selectBbsMomentDept(deptIds);
dbMoment.setFullDeptName(deptName);
}
}
}
return dbMoments;
}
......@@ -127,8 +131,32 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
}
/**
* 置顶动态
*
* @param bo 动态
*/
@Override
public void topComment(BbsMomentTopBO bo) {
BbsMoment dbMoment = this.getById(bo.getMomentId());
if (Objects.isNull(dbMoment)) {
throw new ServiceException("操作失败,未查询到当前动态数据。");
}
/**
LambdaUpdateWrapper<BbsMoment> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(BbsMoment::getId, dbMoment.getId());
if (bo.getIsTop() == 1) {
wrapper.set(BbsMoment::getIsTop, 1);
wrapper.set(BbsMoment::getTopTime, new Date());
} else {
wrapper.set(BbsMoment::getIsTop, 0);
wrapper.set(BbsMoment::getTopTime, null);
}
this.update(wrapper);
}
/**
* 查询用户动态统计
*
* @return 动态统计
......@@ -404,7 +432,7 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
this.baseMapper.incrMomentCommentCount(dbMomentId, 1);
// 发布用户操作事件
OperateEvent operateEvent = new OperateEvent(dbUser.getUserName(), OperateType.TPDT);
OperateEvent operateEvent = new OperateEvent(dbUser.getUserName(), OperateType.PLDT);
this.eventPublisher.publishEvent(operateEvent);
}
......
......@@ -40,7 +40,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</where>
ORDER BY
m.create_time DESC
m.is_top DESC, m.top_time DESC, m.create_time DESC
</select>
......@@ -106,7 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</where>
ORDER BY
m.create_time DESC
m.is_top DESC, m.top_time DESC, m.create_time DESC
</select>
......@@ -154,7 +154,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</where>
ORDER BY
m.create_time DESC
m.is_top DESC, m.top_time DESC, m.create_time DESC
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment