dcs 4 месяцев назад
Родитель
Сommit
01a61f55bd

+ 15 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/controller/ReminderController.java

@@ -8,6 +8,10 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 @RestController
 @RequestMapping({"reminder"})
 @Api(tags = {"提醒管理"})
@@ -16,6 +20,17 @@ public class ReminderController {
     @Autowired
     ReminderService reminderService;
 
+    @ApiOperation("获取分页")
+    @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.POST)
+    public Response list(@RequestBody Reminder reminder, @PathVariable int currPage, @PathVariable int pageSize) {
+        int totalCount = reminderService.getTotalCount(reminder);
+        List<Reminder> dataList = reminderService.getLimit(reminder, currPage, pageSize);
+        Map<String, Object> result = new HashMap<>();
+        result.put("dataList", dataList);
+        result.put("totalCount", totalCount);
+        return Response.ok(result);
+    }
+
     @ApiOperation("详情")
     @RequestMapping(value = "/{id}", method = RequestMethod.GET)
     public Response get(@PathVariable long id) {

+ 5 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/ReminderDao.java

@@ -2,6 +2,7 @@ package com.bosshand.virgo.api.dao;
 
 import com.bosshand.virgo.api.model.Reminder;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -18,4 +19,8 @@ public interface ReminderDao {
 
     List<Reminder> getList(Reminder reminder);
 
+    int getTotalCount(Reminder reminder);
+
+    List<Reminder> getLimit(@Param("p") Reminder p, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
+
 }

+ 39 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/model/Reminder.java

@@ -7,6 +7,21 @@ public class Reminder {
 
     private long id;
 
+    /**
+     * 创建者Id
+     */
+    private long creator;
+
+    /**
+     * DTO-创建者名称
+     */
+    private String creatorName;
+
+    /**
+     * DTO-创建者头像
+     */
+    private String creatorPortrait;
+
     /**
      * 组织id
      */
@@ -56,6 +71,30 @@ public class Reminder {
         this.id = id;
     }
 
+    public long getCreator() {
+        return creator;
+    }
+
+    public void setCreator(long creator) {
+        this.creator = creator;
+    }
+
+    public String getCreatorName() {
+        return creatorName;
+    }
+
+    public void setCreatorName(String creatorName) {
+        this.creatorName = creatorName;
+    }
+
+    public String getCreatorPortrait() {
+        return creatorPortrait;
+    }
+
+    public void setCreatorPortrait(String creatorPortrait) {
+        this.creatorPortrait = creatorPortrait;
+    }
+
     public long getOrganizationId() {
         return organizationId;
     }

+ 9 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/service/ReminderService.java

@@ -13,6 +13,15 @@ public class ReminderService {
     @Autowired
     ReminderDao reminderDao;
 
+    public int getTotalCount(Reminder reminder) {
+        return reminderDao.getTotalCount(reminder);
+    }
+
+    public List<Reminder> getLimit(Reminder reminder, int currPage, int pageSize) {
+        int currIndex = (currPage - 1) * pageSize;
+        return reminderDao.getLimit(reminder, currIndex, pageSize);
+    }
+
     public Reminder get(long id) {
         return reminderDao.get(id);
     }

+ 76 - 2
virgo.api/src/main/resources/mapper/ReminderMapper.xml

@@ -6,6 +6,9 @@
 
     <resultMap type="com.bosshand.virgo.api.model.Reminder" id="result">
         <id column="id" property="id"/>
+        <result column="creator" property="creator"/>
+        <result column="creatorName" property="creatorName"/>
+        <result column="creatorPortrait" property="creatorPortrait"/>
         <result column="organizationId" property="organizationId"/>
         <result column="projectId" property="projectId"/>
         <result column="name" property="name"/>
@@ -28,6 +31,9 @@
             <if test="id != 0">
                 and id = #{id}
             </if>
+            <if test="creator != 0">
+                and creator = #{creator}
+            </if>
             <if test="organizationId != 0">
                 and organizationId = #{organizationId}
             </if>
@@ -53,8 +59,8 @@
     </select>
 
     <insert id="insert" useGeneratedKeys="true" keyProperty="id">
-        INSERT INTO reminder (`organizationId`, `projectId`, `name`, `type`, `content`, `date`, `frequency`, `userList`, `attachment`, `state`)
-        VALUES (#{organizationId}, #{projectId}, #{name}, #{type}, #{content}, #{date}, #{frequency}, #{userList}, #{attachment}, #{state})
+        INSERT INTO reminder (`creator`, `organizationId`, `projectId`, `name`, `type`, `content`, `date`, `frequency`, `userList`, `attachment`, `state`)
+        VALUES (#{creator}, #{organizationId}, #{projectId}, #{name}, #{type}, #{content}, #{date}, #{frequency}, #{userList}, #{attachment}, #{state})
     </insert>
 
     <update id="delete">
@@ -64,6 +70,7 @@
     <update id="update" parameterType="com.bosshand.virgo.api.model.Reminder">
         UPDATE reminder
         <trim prefix="set" suffixOverrides=",">
+            <if test="creator!=0">creator=#{creator},</if>
             <if test="organizationId!=0">organizationId=#{organizationId},</if>
             <if test="projectId!=0">projectId=#{projectId},</if>
             <if test="name!=null">name=#{name},</if>
@@ -78,4 +85,71 @@
         WHERE id=#{id}
     </update>
 
+    <select id="getTotalCount" parameterType="com.bosshand.virgo.api.model.Reminder" resultType="Integer">
+        SELECT count(*) FROM reminder
+        <where>
+            <if test="id != 0">
+                and id = #{id}
+            </if>
+            <if test="creator != 0">
+                and creator = #{creator}
+            </if>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="projectId != 0">
+                and projectId = #{projectId}
+            </if>
+            <if test="name != null">
+                and name = #{name}
+            </if>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="date != null">
+                and date = #{date}
+            </if>
+            <if test="frequency != null">
+                and frequency = #{frequency}
+            </if>
+            <if test="state != null">
+                and state = #{state}
+            </if>
+        </where>
+    </select>
+
+    <select id="getLimit" resultMap="result">
+        SELECT a.*, b.name as creatorName, b.portrait as creatorPortrait FROM reminder a LEFT JOIN mgr_user b ON a.creator = b.id
+        <where>
+            <if test="p.id != 0">
+                and a.id = #{p.id}
+            </if>
+            <if test="p.creator != 0">
+                and a.creator = #{p.creator}
+            </if>
+            <if test="p.organizationId != 0">
+                and a.organizationId = #{p.organizationId}
+            </if>
+            <if test="p.projectId != 0">
+                and a.projectId = #{p.projectId}
+            </if>
+            <if test="p.name != null">
+                and a.name = #{p.name}
+            </if>
+            <if test="p.type != null">
+                and a.type = #{p.type}
+            </if>
+            <if test="p.date != null">
+                and a.date = #{p.date}
+            </if>
+            <if test="p.frequency != null">
+                and a.frequency = #{p.frequency}
+            </if>
+            <if test="p.state != null">
+                and a.state = #{p.state}
+            </if>
+        </where>
+        limit #{currIndex} , #{pageSize}
+    </select>
+
 </mapper>