新增动态接口

master
zzy 2026-04-24 17:07:23 +08:00
parent 7d7314c1c4
commit 9dc4c857a5
8 changed files with 69 additions and 20 deletions

View File

@ -38,7 +38,7 @@ import static com.fjrcloud.community.framework.common.pojo.CommonResult.success;
*/
@Tag(name = "管理后台 - 社区动态")
@RestController
@RequestMapping("/community/community-post")
@RequestMapping("/community/post")
@Validated
public class CommunityPostController {

View File

@ -59,6 +59,19 @@ public class CommunityPostRespVO {
@ExcelProperty("发布时间")
private LocalDateTime publishTime;
@Schema(description = "结束类型1-长期有效2-定时结束)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty(value = "结束类型", converter = DictConvert.class)
@DictFormat("comm_post_end_type")
private Integer endType;
@Schema(description = "结束时间")
@ExcelProperty("结束时间")
private LocalDateTime endTime;
@Schema(description = "是否消息推送", example = "true")
@ExcelProperty("消息推送")
private Boolean pushEnabled;
@Schema(description = "浏览次数", example = "100")
@ExcelProperty("浏览次数")
private Integer viewCount;

View File

@ -46,6 +46,16 @@ public class CommunityPostSaveReqVO {
@Schema(description = "定时发布时间", example = "2024-01-01 00:00:00")
private LocalDateTime publishTime;
@Schema(description = "结束类型1-长期有效2-定时结束)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "结束类型不能为空")
private Integer endType;
@Schema(description = "结束时间", example = "2024-12-31 23:59:59")
private LocalDateTime endTime;
@Schema(description = "是否消息推送", example = "true")
private Boolean pushEnabled;
@Schema(description = "小区ID列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]")
@NotNull(message = "小区列表不能为空")
private List<Long> communityIds;

View File

@ -33,7 +33,7 @@ import static com.fjrcloud.community.framework.common.pojo.CommonResult.success;
*/
@Tag(name = "用户APP - 社区动态")
@RestController
@RequestMapping("/community/community-post")
@RequestMapping("/community/post")
@Validated
@Slf4j
public class AppCommunityPostController {

View File

@ -7,6 +7,8 @@ import com.fjrcloud.community.framework.mybatis.core.dataobject.BaseDO;
import com.fjrcloud.community.framework.tenant.core.aop.TenantIgnore;
import lombok.*;
import java.time.LocalDateTime;
/**
* DO
*
@ -67,7 +69,22 @@ public class CommunityPostDO extends BaseDO {
/**
*
*/
private java.time.LocalDateTime publishTime;
private LocalDateTime publishTime;
/**
* 1-2-
*/
private Integer endType;
/**
*
*/
private LocalDateTime endTime;
/**
*
*/
private Boolean pushEnabled;
/**
*

View File

@ -28,7 +28,6 @@ import java.util.Map;
import java.util.stream.Collectors;
import static com.fjrcloud.community.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.fjrcloud.community.module.community.enums.ErrorCodeConstants.NOTICE_NOT_DRAFT;
import static com.fjrcloud.community.module.community.enums.ErrorCodeConstants.NOTICE_NOT_EXISTS;
/**
@ -91,11 +90,6 @@ public class CommunityNoticeServiceImpl implements CommunityNoticeService {
// 校验存在
CommunityNoticeDO oldNotice = validateNoticeExists(updateReqVO.getId());
// 如果原状态是已发布、已过期或已撤回,不允许修改
if (oldNotice.getStatus() != 0) {
throw exception(NOTICE_NOT_DRAFT);
}
// 更新通知
CommunityNoticeDO updateObj = BeanUtils.toBean(updateReqVO, CommunityNoticeDO.class);

View File

@ -82,7 +82,7 @@ public interface CommunityPostService {
int autoPublishPosts();
/**
* 线
* 线
*
* @return 线
*/

View File

@ -1,6 +1,7 @@
package com.fjrcloud.community.module.community.service.post;
import cn.hutool.core.collection.CollUtil;
import com.fjrcloud.community.framework.common.exception.ErrorCode;
import com.fjrcloud.community.framework.common.pojo.PageResult;
import com.fjrcloud.community.framework.common.util.object.BeanUtils;
import com.fjrcloud.community.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -26,7 +27,6 @@ import java.util.Map;
import java.util.stream.Collectors;
import static com.fjrcloud.community.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.fjrcloud.community.module.community.enums.ErrorCodeConstants.COMMUNITY_POST_NOT_DRAFT;
import static com.fjrcloud.community.module.community.enums.ErrorCodeConstants.COMMUNITY_POST_NOT_EXISTS;
/**
@ -84,11 +84,6 @@ public class CommunityPostServiceImpl implements CommunityPostService {
// 校验存在
CommunityPostDO oldPost = validatePostExists(updateReqVO.getId());
// 如果原状态是已发布、已下线或已撤回,不允许修改
if (oldPost.getStatus() != 0) {
throw exception(COMMUNITY_POST_NOT_DRAFT);
}
// 更新动态
CommunityPostDO updateObj = BeanUtils.toBean(updateReqVO, CommunityPostDO.class);
@ -164,7 +159,7 @@ public class CommunityPostServiceImpl implements CommunityPostService {
// 校验状态
if (post.getStatus() != 0) {
throw exception(new com.fjrcloud.community.framework.common.exception.ErrorCode(2_005_000_001, "只有草稿状态的动态才能发布"));
throw exception(new ErrorCode(2_005_000_001, "只有草稿状态的动态才能发布"));
}
// 更新状态为已发布
@ -225,8 +220,28 @@ public class CommunityPostServiceImpl implements CommunityPostService {
@Transactional(rollbackFor = Exception.class)
public int autoOfflinePosts() {
// 查询需要下线的动态:已发布状态 + 结束类型是定时结束 + 结束时间已到
// 注:当前版本暂不支持定时下线,后续可扩展
return 0;
LocalDateTime now = LocalDateTime.now();
List<CommunityPostDO> posts = communityPostMapper.selectList(new LambdaQueryWrapperX<CommunityPostDO>()
.eq(CommunityPostDO::getStatus, 1) // 已发布状态
.eq(CommunityPostDO::getEndType, 2) // 定时结束
.le(CommunityPostDO::getEndTime, now) // 结束时间已到
);
if (CollUtil.isEmpty(posts)) {
return 0;
}
// 批量更新状态为已下线
int count = 0;
for (CommunityPostDO post : posts) {
CommunityPostDO updateObj = new CommunityPostDO();
updateObj.setId(post.getId());
updateObj.setStatus(2); // 已下线
communityPostMapper.updateById(updateObj);
count++;
}
return count;
}
@Override