Forráskód Böngészése

新媒体局政管理 分页查询

zwq 2 éve
szülő
commit
fa643ed4df

+ 45 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/SortArticleHeadlinesController.java

@@ -0,0 +1,45 @@
+package com.example.nngkxxdp.controller;
+
+import com.example.nngkxxdp.service.SortArticleHeadlinesService;
+import com.example.nngkxxdp.util.Blank;
+import com.example.nngkxxdp.util.ConstStr;
+import com.example.nngkxxdp.util.SendUtil;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * description: 新媒体局政管理
+ *
+ * @author zwq
+ * @date 2022/8/12 9:54
+ */
+@RestController
+@RequestMapping("sortArticleHeadlines")
+@AllArgsConstructor
+public class SortArticleHeadlinesController {
+
+    private final SortArticleHeadlinesService sortArticleHeadlinesService;
+
+    /**
+     * description: 分页查询
+     * @author zwq
+     * @date 2022/8/12 10:25
+     * @param page 分页参数
+     * @param limit 分页参数
+     * @param officialAccount 公众号
+     * @param title 标题
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    @GetMapping("/page")
+    public Map<String,Object> page(Integer page, Integer limit, String officialAccount, String title) {
+        if (Blank.isEmpty(page, limit)) {
+            return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
+        }
+        return sortArticleHeadlinesService.page(page, limit, officialAccount, title);
+    }
+
+}

+ 39 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/SortArticleHeadlinesDao.java

@@ -0,0 +1,39 @@
+package com.example.nngkxxdp.dao;
+
+import com.example.nngkxxdp.entity.SortArticleHeadlinesDO;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * description: 新媒体局政
+ *
+ * @author zwq
+ * @date 2022/8/12 9:20
+ */
+@Repository
+public interface SortArticleHeadlinesDao {
+
+    /**
+     * description: 分页计数
+     * @author zwq
+     * @date 2022/8/12 10:24
+     * @param officialAccount 公众号
+     * @param title 标题
+     * @return long 计数
+     */
+    long pageCount(String officialAccount, String title);
+
+    /**
+     * description: 分页列表
+     * @author zwq
+     * @date 2022/8/12 10:24
+     * @param startRows 分页参数
+     * @param limit 分页参数
+     * @param officialAccount 公众号
+     * @param title 标题
+     * @return java.util.List<com.example.nngkxxdp.entity.SortArticleHeadlinesDO>
+     */
+    List<SortArticleHeadlinesDO> pageList(Integer startRows, Integer limit, String officialAccount, String title);
+
+}

+ 49 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/entity/SortArticleHeadlinesDO.java

@@ -0,0 +1,49 @@
+package com.example.nngkxxdp.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * description: 新媒体局政管理
+ *
+ * @author zwq
+ * @date 2022/8/12 9:07
+ */
+@Data
+public class SortArticleHeadlinesDO implements Serializable {
+
+    private static final long serialVersionUID = 7927430444024031520L;
+
+    /**
+     * id
+     */
+    private Integer id;
+
+    /**
+     * 公众号
+     */
+    private String officialAccount;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    /**
+     * 链接
+     */
+    private String url;
+
+    /**
+     * 排序
+     */
+    private Integer sort;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+}

+ 25 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/SortArticleHeadlinesService.java

@@ -0,0 +1,25 @@
+package com.example.nngkxxdp.service;
+
+import java.util.Map;
+
+/**
+ * description: 新媒体局政管理
+ *
+ * @author zwq
+ * @date 2022/8/12 9:34
+ */
+public interface SortArticleHeadlinesService {
+
+    /**
+     * description: 分页列表
+     * @author zwq
+     * @date 2022/8/12 9:36
+     * @param startRows 开始页
+     * @param limit 一页数量
+     * @param officialAccount 公众号
+     * @param title 标题
+     * @return java.util.Map 分页信息
+     */
+    Map<String, Object> page(Integer startRows, Integer limit, String officialAccount, String title);
+
+}

+ 49 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/SortArticleHeadlinesServiceImpl.java

@@ -0,0 +1,49 @@
+package com.example.nngkxxdp.service.impl;
+
+import com.example.nngkxxdp.dao.SortArticleHeadlinesDao;
+import com.example.nngkxxdp.entity.SortArticleHeadlinesDO;
+import com.example.nngkxxdp.service.SortArticleHeadlinesService;
+import com.example.nngkxxdp.util.ConstStr;
+import com.example.nngkxxdp.util.SendUtil;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * description: 新媒体局政管理
+ *
+ * @author zwq
+ * @date 2022/8/12 9:40
+ */
+@Service("SortArticleHeadlinesService")
+@AllArgsConstructor
+public class SortArticleHeadlinesServiceImpl implements SortArticleHeadlinesService {
+
+    private final SortArticleHeadlinesDao sortArticleHeadlinesDao;
+
+    /**
+     * description: 分页列表
+     * @author zwq
+     * @date 2022/8/12 9:36
+     * @param startRows 开始页
+     * @param limit 一页数量
+     * @param officialAccount 公众号
+     * @param title 标题
+     * @return java.util.Map 分页信息
+     */
+    @Override
+    public Map<String, Object> page(Integer startRows, Integer limit, String officialAccount, String title) {
+        long count = sortArticleHeadlinesDao.pageCount(officialAccount, title);
+        if (count == 0) {
+            return SendUtil.layuiTable(count, null);
+        }
+        startRows = (startRows - 1) * limit;
+        List<SortArticleHeadlinesDO> sortArticleHeadlinesDOList = sortArticleHeadlinesDao.pageList(startRows, limit, officialAccount, title);
+        if (!sortArticleHeadlinesDOList.isEmpty()){
+            return SendUtil.layuiTable(count, sortArticleHeadlinesDOList);
+        }
+        return SendUtil.send(false, ConstStr.RESULT_FAILED);
+    }
+}

+ 41 - 0
nngkxxdp/src/main/resources/mapper/SortArticleHeadlinesDao.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.example.nngkxxdp.dao.SortArticleHeadlinesDao">
+
+    <select id="pageCount" resultType="java.lang.Long">
+        select count(*)
+        from sort_article_headlines
+        <where>
+            1=1
+            <if test="officialAccount != null">
+                AND official_account LIKE CONCAT('%', #{officialAccount}, '%')
+            </if>
+            <if test="title != null">
+                AND title LIKE CONCAT('%', #{title}, '%')
+            </if>
+        </where>
+    </select>
+
+    <select id="pageList" resultType="com.example.nngkxxdp.entity.SortArticleHeadlinesDO">
+        SELECT
+        id,
+        official_account AS officialAccount,
+        title,
+        url,
+        sort,
+        create_time AS createTime
+        FROM sort_article_headlines
+        <where>
+            1 = 1
+            <if test="officialAccount != null">
+                AND official_account LIKE CONCAT('%', #{officialAccount}, '%')
+            </if>
+            <if test="title != null">
+                AND title LIKE CONCAT('%', #{title}, '%')
+            </if>
+        </where>
+        ORDER BY sort, create_time DESC
+        limit #{startRows},#{limit}
+    </select>
+
+</mapper>