tangbin пре 9 месеци
родитељ
комит
159a1662d1

+ 45 - 0
yezhu-api/src/main/java/com/kioor/messageboard/PostTypeEnum.java

@@ -0,0 +1,45 @@
+package com.kioor.messageboard;
+
+/**
+ * 项目名称: toby-yezhu
+ * 文件名称: PostTypeEnum
+ * 描述: 帖子类型
+ * <p>
+ * 创建人: 唐斌
+ * 创建时间: 2024/7/31
+ * <p>
+ * 版权所有 © 2024 TANG BIN. All Rights Reserved.
+ */
+public enum PostTypeEnum {
+    NEIGHBORHOOD_CHAT("小区闲聊", 1),
+    PROPERTY_SERVICE("物业服务", 2),
+    EVENT_REGISTRATION("活动报名", 3),
+    REAL_ESTATE("房屋租售", 4),
+    PERSONAL_GOODS("个人闲置", 5);
+
+    private final String name;
+    private final int code;
+
+    PostTypeEnum(String name, int code) {
+        this.name = name;
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    // 可以添加更多方法,例如根据代码获取枚举实例
+    public static PostTypeEnum fromCode(int code) {
+        for (PostTypeEnum type : values()) {
+            if (type.getCode() == code) {
+                return type;
+            }
+        }
+        throw new IllegalArgumentException("Invalid code: " + code);
+    }
+}

+ 22 - 0
yezhu-api/src/main/java/com/kioor/messageboard/controller/ApiMessageController.java

@@ -79,6 +79,28 @@ public class ApiMessageController {
         return new Result<PageData<MessageDTO>>().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)")
+    })
+    public Result<PageData<MessageDTO>> mypage(@Parameter(hidden = true) @RequestParam Map<String, Object> params, @Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
+        params.put("editUser", userId);
+        PageData<MessageDTO> page = messageService.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<MessageDTO>>().ok(page);
+    }
 
     @Login
     @Operation(summary = "信息")

+ 59 - 4
yezhu-api/src/main/java/com/kioor/messageboard/controller/ApiMessagePostController.java

@@ -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);
+    }
+
 }

+ 35 - 0
yezhu-api/src/main/java/com/kioor/messageboard/dto/EnumListDTO.java

@@ -0,0 +1,35 @@
+/**
+ * /**
+ * Copyright (c) 2018 业主系统 All rights reserved.
+ * <p>
+ * https://www.kioor.com
+ * <p>
+ * 版权所有,侵权必究!
+ */
+
+package com.kioor.messageboard.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+
+/**
+ * 枚举中间类
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+@Data
+@Schema(description = "枚举中间类")
+public class EnumListDTO {
+
+    @Schema(description = "标签")
+    private String label;
+
+    @Schema(description = "值")
+    private int value;
+
+    public EnumListDTO(String name, int code) {
+        this.label = name;
+        this.value = code;
+    }
+}

+ 6 - 0
yezhu-api/src/main/java/com/kioor/messageboard/dto/MessagePostDTO.java

@@ -47,6 +47,12 @@ public class MessagePostDTO {
     @Schema(description = "是否显示房号")
     private Integer showRoomFlag;
 
+    @Schema(description = "是否置顶")
+    private Integer topFlag;
+
     @Schema(description = "编辑人房号")
     private String roomName;
+
+    @Schema(description = "帖子类型")
+    private int type;
 }

+ 8 - 0
yezhu-api/src/main/java/com/kioor/messageboard/entity/MessagePostEntity.java

@@ -40,6 +40,10 @@ public class MessagePostEntity implements Serializable {
      * 帖子内容
      */
     private String content;
+    /**
+     * 帖子类型
+     */
+    private int type;
     /**
      * 编辑人
      */
@@ -52,5 +56,9 @@ public class MessagePostEntity implements Serializable {
      * 是否显示房号
      */
     private int showRoomFlag;
+    /**
+     * 是否置顶
+     */
+    private int topFlag;
 
 }

+ 1 - 1
yezhu-api/src/main/java/com/kioor/messageboard/service/impl/MessagePostServiceImpl.java

@@ -37,7 +37,7 @@ public class MessagePostServiceImpl extends BaseServiceImpl<MessagePostDao, Mess
     public PageData<MessagePostDTO> page(Map<String, Object> params) {
 
         //分页
-        IPage<MessagePostEntity> page = getPage(params, "edit_time", true);
+        IPage<MessagePostEntity> page = getPage(params, "top_flag", false);
 
         //查询
         List<MessagePostDTO> list = baseDao.getList(params);

+ 3 - 0
yezhu-api/src/main/resources/mapper/messageboard/MessageDao.xml

@@ -14,6 +14,9 @@
             <if test="messagePostId != null">
                 and tm.message_post_id = #{messagePostId}
             </if>
+            <if test="editUser != null">
+                and tm.edit_user = #{editUser}
+            </if>
         </where>
         order by tm.edit_time asc
     </select>

+ 10 - 1
yezhu-api/src/main/resources/mapper/messageboard/MessagePostDao.xml

@@ -16,8 +16,17 @@
             <if test="housingEstateId != null">
                 and tmb.housing_estate_id = #{housingEstateId}
             </if>
+            <if test="title != null and title != ''">
+                and tmp.title like concat( '%',#{title},'%')
+            </if>
+            <if test="type != null and type != 0">
+                and tmp.type = #{type}
+            </if>
+            <if test="editUser != null">
+                and tmp.edit_user = #{editUser}
+            </if>
         </where>
-        order by tmp.edit_time asc
+        order by tmp.top_flag desc,tmp.edit_time desc
     </select>
 
     <select id="get" resultType="com.kioor.messageboard.dto.MessagePostDTO">