新增动态接口
parent
7d7314c1c4
commit
9dc4c857a5
|
|
@ -38,7 +38,7 @@ import static com.fjrcloud.community.framework.common.pojo.CommonResult.success;
|
||||||
*/
|
*/
|
||||||
@Tag(name = "管理后台 - 社区动态")
|
@Tag(name = "管理后台 - 社区动态")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/community/community-post")
|
@RequestMapping("/community/post")
|
||||||
@Validated
|
@Validated
|
||||||
public class CommunityPostController {
|
public class CommunityPostController {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,19 @@ public class CommunityPostRespVO {
|
||||||
@ExcelProperty("发布时间")
|
@ExcelProperty("发布时间")
|
||||||
private LocalDateTime publishTime;
|
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")
|
@Schema(description = "浏览次数", example = "100")
|
||||||
@ExcelProperty("浏览次数")
|
@ExcelProperty("浏览次数")
|
||||||
private Integer viewCount;
|
private Integer viewCount;
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,16 @@ public class CommunityPostSaveReqVO {
|
||||||
@Schema(description = "定时发布时间", example = "2024-01-01 00:00:00")
|
@Schema(description = "定时发布时间", example = "2024-01-01 00:00:00")
|
||||||
private LocalDateTime publishTime;
|
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]")
|
@Schema(description = "小区ID列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]")
|
||||||
@NotNull(message = "小区列表不能为空")
|
@NotNull(message = "小区列表不能为空")
|
||||||
private List<Long> communityIds;
|
private List<Long> communityIds;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import static com.fjrcloud.community.framework.common.pojo.CommonResult.success;
|
||||||
*/
|
*/
|
||||||
@Tag(name = "用户APP - 社区动态")
|
@Tag(name = "用户APP - 社区动态")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/community/community-post")
|
@RequestMapping("/community/post")
|
||||||
@Validated
|
@Validated
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AppCommunityPostController {
|
public class AppCommunityPostController {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import com.fjrcloud.community.framework.mybatis.core.dataobject.BaseDO;
|
||||||
import com.fjrcloud.community.framework.tenant.core.aop.TenantIgnore;
|
import com.fjrcloud.community.framework.tenant.core.aop.TenantIgnore;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 社区动态 DO
|
* 社区动态 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 浏览次数
|
* 浏览次数
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.fjrcloud.community.framework.common.exception.util.ServiceExceptionUtil.exception;
|
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;
|
import static com.fjrcloud.community.module.community.enums.ErrorCodeConstants.NOTICE_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -90,11 +89,6 @@ public class CommunityNoticeServiceImpl implements CommunityNoticeService {
|
||||||
public void updateNotice(NoticeSaveReqVO updateReqVO) {
|
public void updateNotice(NoticeSaveReqVO updateReqVO) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
CommunityNoticeDO oldNotice = validateNoticeExists(updateReqVO.getId());
|
CommunityNoticeDO oldNotice = validateNoticeExists(updateReqVO.getId());
|
||||||
|
|
||||||
// 如果原状态是已发布、已过期或已撤回,不允许修改
|
|
||||||
if (oldNotice.getStatus() != 0) {
|
|
||||||
throw exception(NOTICE_NOT_DRAFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新通知
|
// 更新通知
|
||||||
CommunityNoticeDO updateObj = BeanUtils.toBean(updateReqVO, CommunityNoticeDO.class);
|
CommunityNoticeDO updateObj = BeanUtils.toBean(updateReqVO, CommunityNoticeDO.class);
|
||||||
|
|
@ -175,7 +169,7 @@ public class CommunityNoticeServiceImpl implements CommunityNoticeService {
|
||||||
public void publishNotice(Long id) {
|
public void publishNotice(Long id) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
CommunityNoticeDO notice = validateNoticeExists(id);
|
CommunityNoticeDO notice = validateNoticeExists(id);
|
||||||
|
|
||||||
// 校验状态
|
// 校验状态
|
||||||
if (notice.getStatus() != 0) {
|
if (notice.getStatus() != 0) {
|
||||||
throw exception(new ErrorCode(2_004_000_001, "只有草稿状态的通知才能发布"));
|
throw exception(new ErrorCode(2_004_000_001, "只有草稿状态的通知才能发布"));
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ public interface CommunityPostService {
|
||||||
int autoPublishPosts();
|
int autoPublishPosts();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动下线动态
|
* 自动下线动态(定时结束)
|
||||||
*
|
*
|
||||||
* @return 下线数量
|
* @return 下线数量
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.fjrcloud.community.module.community.service.post;
|
package com.fjrcloud.community.module.community.service.post;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
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.pojo.PageResult;
|
||||||
import com.fjrcloud.community.framework.common.util.object.BeanUtils;
|
import com.fjrcloud.community.framework.common.util.object.BeanUtils;
|
||||||
import com.fjrcloud.community.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import com.fjrcloud.community.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
|
@ -26,7 +27,6 @@ import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.fjrcloud.community.framework.common.exception.util.ServiceExceptionUtil.exception;
|
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;
|
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());
|
CommunityPostDO oldPost = validatePostExists(updateReqVO.getId());
|
||||||
|
|
||||||
// 如果原状态是已发布、已下线或已撤回,不允许修改
|
|
||||||
if (oldPost.getStatus() != 0) {
|
|
||||||
throw exception(COMMUNITY_POST_NOT_DRAFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新动态
|
// 更新动态
|
||||||
CommunityPostDO updateObj = BeanUtils.toBean(updateReqVO, CommunityPostDO.class);
|
CommunityPostDO updateObj = BeanUtils.toBean(updateReqVO, CommunityPostDO.class);
|
||||||
|
|
||||||
|
|
@ -164,7 +159,7 @@ public class CommunityPostServiceImpl implements CommunityPostService {
|
||||||
|
|
||||||
// 校验状态
|
// 校验状态
|
||||||
if (post.getStatus() != 0) {
|
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)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public int autoOfflinePosts() {
|
public int autoOfflinePosts() {
|
||||||
// 查询需要下线的动态:已发布状态 + 结束类型是定时结束 + 结束时间已到
|
// 查询需要下线的动态:已发布状态 + 结束类型是定时结束 + 结束时间已到
|
||||||
// 注:当前版本暂不支持定时下线,后续可扩展
|
LocalDateTime now = LocalDateTime.now();
|
||||||
return 0;
|
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
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue