|
@@ -19,7 +19,11 @@ import com.kioor.common.validator.ValidatorUtils;
|
|
|
import com.kioor.common.validator.group.AddGroup;
|
|
|
import com.kioor.common.validator.group.DefaultGroup;
|
|
|
import com.kioor.common.validator.group.UpdateGroup;
|
|
|
+import com.kioor.messageboard.PostTypeEnum;
|
|
|
+import com.kioor.messageboard.dto.EnumListDTO;
|
|
|
+import com.kioor.messageboard.dto.MessageBoardDTO;
|
|
|
import com.kioor.messageboard.dto.MessagePostDTO;
|
|
|
+import com.kioor.messageboard.service.MessageBoardService;
|
|
|
import com.kioor.messageboard.service.MessagePostService;
|
|
|
import com.kioor.room.enums.HousingEstateStatus;
|
|
|
import com.kioor.room.service.HousingEstateService;
|
|
@@ -30,9 +34,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 帖子
|
|
@@ -45,6 +47,8 @@ import java.util.Map;
|
|
|
@Tag(name = "帖子")
|
|
|
public class ApiMessagePostController {
|
|
|
|
|
|
+ private final MessageBoardService messageBoardService;
|
|
|
+
|
|
|
private final MessagePostService messagePostService;
|
|
|
|
|
|
private final HousingEstateService housingEstateService;
|
|
@@ -58,7 +62,9 @@ public class ApiMessagePostController {
|
|
|
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段"),
|
|
|
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"),
|
|
|
@Parameter(name = "housingEstateId", description = "小区id"),
|
|
|
- @Parameter(name = "messageBoardId", description = "论坛id")
|
|
|
+ @Parameter(name = "messageBoardId", description = "论坛id"),
|
|
|
+ @Parameter(name = "title", description = "标题"),
|
|
|
+ @Parameter(name = "type", description = "帖子类型")
|
|
|
})
|
|
|
public Result<PageData<MessagePostDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
|
|
|
//小区和论坛id不能同时为空
|
|
@@ -77,6 +83,30 @@ public class ApiMessagePostController {
|
|
|
return new Result<PageData<MessagePostDTO>>().ok(page);
|
|
|
}
|
|
|
|
|
|
+ @Login
|
|
|
+ @GetMapping("mypage")
|
|
|
+ @Operation(summary = "我的帖子")
|
|
|
+ @Parameters({
|
|
|
+ @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true),
|
|
|
+ @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true),
|
|
|
+ @Parameter(name = Constant.ORDER_FIELD, description = "排序字段"),
|
|
|
+ @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"),
|
|
|
+ @Parameter(name = "title", description = "标题"),
|
|
|
+ @Parameter(name = "type", description = "帖子类型")
|
|
|
+ })
|
|
|
+ public Result<PageData<MessagePostDTO>> mypage(@Parameter(hidden = true) @RequestParam Map<String, Object> params, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
|
|
+ params.put("editUser", userId);
|
|
|
+ PageData<MessagePostDTO> page = messagePostService.page(params);
|
|
|
+ //校验小区状态
|
|
|
+ if(page.getList()!=null && !page.getList().isEmpty()){
|
|
|
+ int status = housingEstateService.checkStatus(page.getList().get(0).getHousingEstateId());
|
|
|
+ if(status!=1) {
|
|
|
+ return new Result().error(ErrorCode.INTERNAL_SERVER_ERROR, "无法访问,小区当前状态为" + HousingEstateStatus.fromCode(status).getDescription());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return new Result<PageData<MessagePostDTO>>().ok(page);
|
|
|
+ }
|
|
|
|
|
|
@Login
|
|
|
@Operation(summary = "信息")
|
|
@@ -99,8 +129,18 @@ public class ApiMessagePostController {
|
|
|
public Result save(@RequestBody MessagePostDTO dto, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
|
|
//效验数据
|
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
|
|
+ if(dto.getType()<1){
|
|
|
+ return new Result().error(ErrorCode.NOT_NULL,"帖子类型不能为空");
|
|
|
+ }
|
|
|
+ if(dto.getHousingEstateId()!=null && dto.getMessageBoardId() == null){
|
|
|
+ MessageBoardDTO messageBoardDTO = messageBoardService.infoByHousingEstate(dto.getHousingEstateId());
|
|
|
+ if (messageBoardDTO != null){
|
|
|
+ dto.setMessageBoardId(messageBoardDTO.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
dto.setEditUser(userId);
|
|
|
dto.setEditTime(new Date());
|
|
|
+ dto.setTopFlag(0);
|
|
|
if(dto.getShowRoomFlag()==null){
|
|
|
dto.setShowRoomFlag(1);
|
|
|
}
|
|
@@ -115,8 +155,12 @@ public class ApiMessagePostController {
|
|
|
public Result update(@RequestBody MessagePostDTO dto, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
|
|
//效验数据
|
|
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
|
|
+ if(dto.getType()<1){
|
|
|
+ return new Result().error(ErrorCode.NOT_NULL,"帖子类型不能为空");
|
|
|
+ }
|
|
|
dto.setEditUser(userId);
|
|
|
dto.setEditTime(new Date());
|
|
|
+ dto.setTopFlag(0);
|
|
|
if(dto.getShowRoomFlag()==null){
|
|
|
dto.setShowRoomFlag(1);
|
|
|
}
|
|
@@ -137,4 +181,15 @@ public class ApiMessagePostController {
|
|
|
return new Result();
|
|
|
}
|
|
|
|
|
|
+ @Login
|
|
|
+ @GetMapping("typeList")
|
|
|
+ @Operation(summary = "帖子类型")
|
|
|
+ public Result<List<EnumListDTO>> typeList(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
|
|
|
+ List<EnumListDTO> postTypes = new ArrayList<>();
|
|
|
+ for (PostTypeEnum type : PostTypeEnum.values()) {
|
|
|
+ postTypes.add(new EnumListDTO(type.getName(), type.getCode()));
|
|
|
+ }
|
|
|
+ return new Result<List<EnumListDTO>>().ok(postTypes);
|
|
|
+ }
|
|
|
+
|
|
|
}
|