From 6343f919db9af1fb2bed546b646a23ca0051a8f8 Mon Sep 17 00:00:00 2001 From: 21819 Date: Sat, 20 Jan 2024 18:44:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=96=E7=BD=91=E7=AE=A1=E7=90=86=E7=AB=AF?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E7=AE=A1=E7=90=86=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../outeradmin/controller/MailController.java | 54 +++++++++++-------- .../biutag/outeradmin/entity/FormPage.java | 10 ++++ .../outeradmin/entity/MailPageInfo.java | 11 ++++ .../com/biutag/outeradmin/entity/PageSet.java | 10 ++++ 4 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/FormPage.java create mode 100644 mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/MailPageInfo.java create mode 100644 mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/PageSet.java diff --git a/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java b/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java index 47ed83f..394d029 100644 --- a/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java +++ b/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java @@ -3,18 +3,14 @@ package com.biutag.outeradmin.controller; import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.biutag.outeradmin.entity.FormData; -import com.biutag.outeradmin.entity.Mail; -import com.biutag.outeradmin.entity.MailID; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.biutag.outeradmin.entity.*; import com.biutag.outeradmin.mapper.MailMapper; import com.biutag.outeradmin.service.MailService; import com.biutag.util.StringUtils; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Collection; import java.util.List; @RequiredArgsConstructor @@ -30,11 +26,15 @@ public class MailController { * @return 信件列表json */ @RequestMapping("/list") - public List list() { - List mailList = mailService.list(); - return mailList; -// String result = JSON.toJSONString(mailList); -// return result; + public MailPageInfo list(@RequestBody String req) { + PageSet pageSet = JSON.parseObject(req, PageSet.class); + Page page = new Page<>(pageSet.getCurrentPage(), pageSet.getPageSize()); + List mailPage = mailMapper.selectPage(page, null).getRecords(); + pageSet.setTotalSize((int) page.getTotal()); + MailPageInfo result = new MailPageInfo(); + result.setMails(mailPage); + result.setPageSet(pageSet); + return result; } /** @@ -44,26 +44,38 @@ public class MailController { * @return 指定信件json */ @RequestMapping("/list-submit") - public String siftList(@RequestBody String form) { + public MailPageInfo siftList(@RequestBody String form) { //todo 这里根据表单数据查询数据库,记得删掉 System.out.println(form); - FormData formData = JSON.parseObject(form, FormData.class); + FormPage formPage = JSON.parseObject(form, FormPage.class); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.lambda().like(StringUtils.isNotEmpty(formData.getContactName()), Mail::getContactName, formData.getContactName()) - .like(StringUtils.isNotEmpty(formData.getContactPhone()), Mail::getContactPhone, formData.getContactPhone()) - .like(StringUtils.isNotEmpty(formData.getContactIdCard()), Mail::getContactIdCard, formData.getContactIdCard()) - .like(StringUtils.isNotEmpty(formData.getId()), Mail::getId, formData.getId()) - .like(StringUtils.isNotEmpty(formData.getContent()), Mail::getContent, formData.getContent()); - if (CollectionUtils.isNotEmpty(formData.getDate()) && formData.getDate().size() == 2) { - queryWrapper.lambda().between(Mail::getCreateTime, formData.getDate().get(0), formData.getDate().get(1)); + if(formPage != null && formPage.getFormData()!= null && formPage.getPageData()!= null){ + FormData formData = formPage.getFormData(); + + queryWrapper.lambda().like(StringUtils.isNotEmpty(formData.getContactName()), Mail::getContactName, formData.getContactName()) + .like(StringUtils.isNotEmpty(formData.getContactPhone()), Mail::getContactPhone, formData.getContactPhone()) + .like(StringUtils.isNotEmpty(formData.getContactIdCard()), Mail::getContactIdCard, formData.getContactIdCard()) + .like(StringUtils.isNotEmpty(formData.getId()), Mail::getId, formData.getId()) + .like(StringUtils.isNotEmpty(formData.getContent()), Mail::getContent, formData.getContent()); + if (CollectionUtils.isNotEmpty(formData.getDate()) && formData.getDate().size() == 2) { + queryWrapper.lambda().between(Mail::getCreateTime, formData.getDate().get(0), formData.getDate().get(1)); + } } + PageSet pageSet = formPage.getPageData(); + Page page = new Page<>(pageSet.getCurrentPage(), pageSet.getPageSize()); + List mailPage = mailMapper.selectPage(page, queryWrapper).getRecords(); + pageSet.setTotalSize((int) page.getTotal()); + MailPageInfo result = new MailPageInfo(); + result.setMails(mailPage); + result.setPageSet(pageSet); - return JSON.toJSONString(mailMapper.selectList(queryWrapper)); + return result; } /** * 查询指定信件详情 + * * @param id 信件ID * @return 指定信件详情json */ diff --git a/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/FormPage.java b/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/FormPage.java new file mode 100644 index 0000000..74ebb03 --- /dev/null +++ b/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/FormPage.java @@ -0,0 +1,10 @@ +package com.biutag.outeradmin.entity; + +import lombok.Data; + +@Data +public class FormPage { + private FormData formData; + private PageSet pageData; + +} diff --git a/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/MailPageInfo.java b/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/MailPageInfo.java new file mode 100644 index 0000000..a8f8b36 --- /dev/null +++ b/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/MailPageInfo.java @@ -0,0 +1,11 @@ +package com.biutag.outeradmin.entity; + +import lombok.Data; + +import java.util.List; + +@Data +public class MailPageInfo { + private List mails; + private PageSet pageSet; +} diff --git a/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/PageSet.java b/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/PageSet.java new file mode 100644 index 0000000..0cad16e --- /dev/null +++ b/mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/PageSet.java @@ -0,0 +1,10 @@ +package com.biutag.outeradmin.entity; + +import lombok.Data; + +@Data +public class PageSet { + private int currentPage; + private int pageSize; + private int totalSize; +}