Kaynağa Gözat

通知模块 分页查询接口

ZhangManMan 2 yıl önce
ebeveyn
işleme
503f386789

+ 33 - 0
src/main/java/com/sky/ioc/controller/notice/NoticeController.java

@@ -0,0 +1,33 @@
+package com.sky.ioc.controller.notice;
+
+import com.sky.ioc.entity.domain.notice.Notice;
+import com.sky.ioc.entity.params.IocParam;
+import com.sky.ioc.entity.params.notice.NoticeParam;
+import com.sky.ioc.service.notice.NoticeService;
+import com.sky.ioc.tool.ReturnMsg;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags ="通知")
+@Slf4j
+@RestController
+@RequestMapping("/notice")
+public class NoticeController {
+
+
+    @Autowired
+    NoticeService noticeService;
+
+    @ApiOperation("分页列表")
+    @PostMapping("/getList")
+    public ReturnMsg getList(@RequestBody NoticeParam noticeParam){
+
+        return noticeService.listPage(noticeParam);
+    }
+}

+ 3 - 1
src/main/java/com/sky/ioc/entity/domain/notice/Notice.java

@@ -1,10 +1,12 @@
 package com.sky.ioc.entity.domain.notice;
 
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
 import lombok.Data;
 
 @Data
 public class Notice {
-
+    @TableId(type = IdType.AUTO)
     private Integer id;
     /**
      * 标题

+ 32 - 0
src/main/java/com/sky/ioc/entity/params/notice/NoticeParam.java

@@ -0,0 +1,32 @@
+package com.sky.ioc.entity.params.notice;
+
+import lombok.Data;
+
+@Data
+public class NoticeParam {
+
+    /**
+     * 通知类型
+     * 1 站内通知
+     * 2 更新通知
+     * */
+    private Integer type;
+
+    private Integer status;
+    /**
+     * 分页数
+     */
+    private Integer pageSize =10;
+
+    /**
+     * 分页数
+     */
+    private Integer pageStart =0;
+
+    /** 开始时间 */
+    private String startTime;
+
+    /** 结束时间 */
+    private String endTime;
+
+}

+ 43 - 0
src/main/java/com/sky/ioc/enums/NoticeTypeEnums.java

@@ -0,0 +1,43 @@
+package com.sky.ioc.enums;
+
+public enum NoticeTypeEnums {
+
+    NOTICE_TYPE_INSTATION(1, "站内通知"),
+    NOTICE_TYPE_UPDATE(2, "更新通知");
+    private Integer type;
+
+    private String desc;
+
+    private NoticeTypeEnums(Integer type, String desc) {
+        this.type = type;
+        this.desc = desc;
+    }
+
+    public static String getValue(Integer type) {
+        NoticeTypeEnums[] NoticeTypeEnums = values();
+        for (NoticeTypeEnums noticeTypeEnums : NoticeTypeEnums) {
+            if (noticeTypeEnums.type().equals(type)) {
+                return noticeTypeEnums.desc();
+            }
+        }
+        return null;
+    }
+
+    public static Integer getType(String desc) {
+        NoticeTypeEnums[] NoticeTypeEnumss = values();
+        for (NoticeTypeEnums NoticeTypeEnums : NoticeTypeEnumss) {
+            if (NoticeTypeEnums.desc().equals(desc)) {
+                return NoticeTypeEnums.type();
+            }
+        }
+        return null;
+    }
+
+    private Integer type() {
+        return this.type;
+    }
+
+    private String desc() {
+        return this.desc;
+    }
+}

+ 36 - 1
src/main/java/com/sky/ioc/mapper/notice/NoticeMapper.java

@@ -1,11 +1,46 @@
 package com.sky.ioc.mapper.notice;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sky.ioc.entity.domain.notice.Notice;
+import com.sky.ioc.entity.params.notice.NoticeParam;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+import java.util.Map;
 
 @Mapper
-public interface NoticeMapper extends BaseMapper {
+public interface NoticeMapper extends BaseMapper<Notice> {
+
+    @Select("<script>" +
+            "select id,title,content,address,type,time from notice where is_del=0 " +
+            "<if test='noticeParam!=null and noticeParam.startTime != null '>" +
+            "<![CDATA[ and time >= #{noticeParam.startTime} AND time <= #{noticeParam.endTime} ]]> " +
+            "</if>" +
+            "<if test='noticeParam!=null and noticeParam.type != null '>" +
+            " and type=#{noticeParam.type} " +
+            "</if>"+
+            "<if test='noticeParam!=null and noticeParam.status != null '>" +
+            " and status=#{noticeParam.status} " +
+            "</if>"+
+            " order by time desc limit #{noticeParam.pageSize} offset #{noticeParam.pageStart}" +
+            "</script>")
+    List<Map<String,Object>> listPage(@Param("noticeParam")NoticeParam noticeParam);
 
 
+    @Select("<script>" +
+            "select count(1) from notice where is_del=0 " +
+            "<if test='noticeParam!=null and noticeParam.startTime != null '>" +
+            "<![CDATA[ and time >= #{noticeParam.startTime} AND time <= #{noticeParam.endTime} ]]> " +
+            "</if>" +
+            "<if test='noticeParam!=null and noticeParam.type != null '>" +
+            " and type=#{noticeParam.type} " +
+            "</if>"+
+            "<if test='noticeParam!=null and noticeParam.status != null '>" +
+            " and status=#{noticeParam.status} " +
+            "</if>"+
+            "</script>")
+    long  countPage(@Param("noticeParam")NoticeParam noticeParam);
 
 }

+ 2 - 1
src/main/java/com/sky/ioc/service/notice/NoticeService.java

@@ -1,9 +1,10 @@
 package com.sky.ioc.service.notice;
 
+import com.sky.ioc.entity.params.notice.NoticeParam;
 import com.sky.ioc.tool.ReturnMsg;
 
 public interface NoticeService {
 
 
-   // ReturnMsg listPage();
+    ReturnMsg listPage(NoticeParam noticeParam);
 }

+ 27 - 0
src/main/java/com/sky/ioc/service/notice/impl/NoticeServiceImpl.java

@@ -1,9 +1,36 @@
 package com.sky.ioc.service.notice.impl;
 
+import com.alibaba.fastjson.JSONObject;
+import com.sky.ioc.entity.domain.notice.Notice;
+import com.sky.ioc.entity.params.notice.NoticeParam;
+import com.sky.ioc.enums.NoticeTypeEnums;
+import com.sky.ioc.mapper.notice.NoticeMapper;
 import com.sky.ioc.service.notice.NoticeService;
+import com.sky.ioc.tool.ReturnMsg;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
 @Service
 public class NoticeServiceImpl implements NoticeService {
 
+    @Autowired
+    NoticeMapper noticeMapper;
+
+    @Override
+    public ReturnMsg listPage(NoticeParam noticeParam) {
+        long count = noticeMapper.countPage(noticeParam);
+        JSONObject jsonObject = new JSONObject();
+        List<Map<String,Object>> lists = noticeMapper.listPage(noticeParam);
+        for(Map<String,Object> map:lists){
+            Integer type = Integer.parseInt(String.valueOf( map.get("type")));
+            map.put("type",NoticeTypeEnums.getValue(type));
+        }
+        jsonObject.put("total",count);
+        jsonObject.put("data",lists);
+        return ReturnMsg.ok(jsonObject);
+    }
 }