From 429de207af17a00c5ff1b992bb8315e5ec5bf753 Mon Sep 17 00:00:00 2001 From: lijiaqi Date: Fri, 5 Aug 2022 14:48:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=99=84=E4=BB=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/ApiNoticeController.java | 6 ++-- .../modules/rddb/entity/NoticeAttachment.java | 5 ++++ .../boot/modules/rddb/entity/bo/NoticeBo.java | 1 + .../modules/rddb/service/NoticeService.java | 30 +++++++++++++------ .../ydool/boot/modules/rddb/vo/NoticeVO.java | 5 +++- .../modules/rddb/web/NoticeController.java | 21 +++++++++---- .../modules/rddb/wrapper/NoticeWrapper.java | 9 ++++++ .../views/modules/rddb/notice/form.html | 15 ++++++++-- .../views/modules/rddb/notice/form_gg.html | 13 ++++++-- 9 files changed, 82 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/ydool/boot/api/controller/ApiNoticeController.java b/src/main/java/com/ydool/boot/api/controller/ApiNoticeController.java index f37e78c..29f9c55 100644 --- a/src/main/java/com/ydool/boot/api/controller/ApiNoticeController.java +++ b/src/main/java/com/ydool/boot/api/controller/ApiNoticeController.java @@ -92,12 +92,14 @@ public class ApiNoticeController extends ApiBaseController { @ApiImplicitParam(name = "top", value = "是否置顶0:不置顶;1:置顶"), @ApiImplicitParam(name = "coverNames", value = "封面名,多个英文逗号间隔"), @ApiImplicitParam(name = "coverPaths", value = "封面路径,多个英文逗号间隔"), + @ApiImplicitParam(name = "fileNames", value = "附件名,多个英文逗号间隔"), + @ApiImplicitParam(name = "filePaths", value = "附件路径,多个英文逗号间隔"), @ApiImplicitParam(name = "type", value = "分类tz / gg"), @ApiImplicitParam(name = "obj", value = "公告对象 admin机关办公/ rddb代表/ voter选民 多个用英文逗号间隔 ") }) @ApiOperation("发布公告") @PostMapping("/save") - public void save(String title, String content, String noticeDate, Integer top, String coverNames, String coverPaths, String type, String obj) { + public void save(String title, String content, String noticeDate, Integer top, String coverNames, String coverPaths, String fileNames, String filePaths, String type, String obj) { Notice bean = new Notice(); bean.setTitle(title); bean.setContent(content); @@ -107,7 +109,7 @@ public class ApiNoticeController extends ApiBaseController { bean.setCreatedId(getApiUserId()); bean.setType(type); bean.setObj(obj); - boolean flag = noticeService.apiSave(bean, coverNames, coverPaths, getApiUser()); + boolean flag = noticeService.apiSave(bean, coverNames, coverPaths,fileNames,filePaths, getApiUser()); render(!flag ? Ret.fail("操作失败") : Ret.ok()); } diff --git a/src/main/java/com/ydool/boot/modules/rddb/entity/NoticeAttachment.java b/src/main/java/com/ydool/boot/modules/rddb/entity/NoticeAttachment.java index a47ac7a..0a99a30 100644 --- a/src/main/java/com/ydool/boot/modules/rddb/entity/NoticeAttachment.java +++ b/src/main/java/com/ydool/boot/modules/rddb/entity/NoticeAttachment.java @@ -51,4 +51,9 @@ public class NoticeAttachment extends BaseEntity{ */ private String size; + /** + * 文件类型:1封面,2附件 + */ + private String type; + } diff --git a/src/main/java/com/ydool/boot/modules/rddb/entity/bo/NoticeBo.java b/src/main/java/com/ydool/boot/modules/rddb/entity/bo/NoticeBo.java index 930a9ed..7af307a 100644 --- a/src/main/java/com/ydool/boot/modules/rddb/entity/bo/NoticeBo.java +++ b/src/main/java/com/ydool/boot/modules/rddb/entity/bo/NoticeBo.java @@ -10,4 +10,5 @@ import lombok.Data; @Data public class NoticeBo extends Notice { String coverAttachmentArrStr; + String fileAttachmentArrStr; } diff --git a/src/main/java/com/ydool/boot/modules/rddb/service/NoticeService.java b/src/main/java/com/ydool/boot/modules/rddb/service/NoticeService.java index ede13c6..38ae335 100644 --- a/src/main/java/com/ydool/boot/modules/rddb/service/NoticeService.java +++ b/src/main/java/com/ydool/boot/modules/rddb/service/NoticeService.java @@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.lang.reflect.Type; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -36,7 +37,7 @@ public class NoticeService extends ServiceImpl { NoticeAttachmentService noticeAttachmentService; @Transactional - public boolean saveOrUpdate(NoticeBo noticeBo,User loginUser) { + public boolean saveOrUpdate(NoticeBo noticeBo, User loginUser) { boolean flag; Notice entity = BeanUtil.copyProperties(noticeBo, Notice.class); if (StrUtil.isBlank(entity.getId())) { @@ -57,9 +58,13 @@ public class NoticeService extends ServiceImpl { } flag = this.updateById(entity); } - //附件 + //封面 String coverAttachmentArrStr = noticeBo.getCoverAttachmentArrStr(); - saveAttachment(entity.getId(),coverAttachmentArrStr,loginUser); + saveAttachment(entity.getId(), coverAttachmentArrStr, loginUser, "1"); + + //附件 + String fileAttachmentArrStr = noticeBo.getFileAttachmentArrStr(); + saveAttachment(entity.getId(), fileAttachmentArrStr, loginUser, "2"); List messageList = new ArrayList(); //发送消息 @@ -80,24 +85,27 @@ public class NoticeService extends ServiceImpl { } public IPage _page(Page page, QueryWrapper qw) { - return getBaseMapper()._page(page,qw); + return getBaseMapper()._page(page, qw); } /** * @param noticeId * @param attachmentArrStr * @param loginUser + * @param type */ - private void saveAttachment(String noticeId, String attachmentArrStr, User loginUser) { + private void saveAttachment(String noticeId, String attachmentArrStr, User loginUser, String type) { noticeAttachmentService.remove(new LambdaQueryWrapper() .eq(NoticeAttachment::getNoticeId, noticeId) - ); + .eq(NoticeAttachment::getType,type) + ); if (StrUtil.isNotBlank(attachmentArrStr)) { List attachmentList = JSONObject.parseArray(attachmentArrStr, NoticeAttachment.class); attachmentList.forEach(item -> { item.setNoticeId(noticeId); item.setCreatedId(loginUser.getId()); item.setCreatedAt(LocalDateTime.now()); + item.setType(type); }); noticeAttachmentService.saveBatch(attachmentList); } @@ -108,10 +116,12 @@ public class NoticeService extends ServiceImpl { * @param attachmentName * @param attachmentPath * @param loginUser + * @param type */ - private void saveAttachment(String noticeId, String attachmentName, String attachmentPath, User loginUser) { + private void saveAttachment(String noticeId, String attachmentName, String attachmentPath, User loginUser, String type) { noticeAttachmentService.remove(new LambdaQueryWrapper() .eq(NoticeAttachment::getNoticeId, noticeId) + .eq(NoticeAttachment::getType,type) ); if (StrUtil.isNotBlank(attachmentName)) { String[] nameArr = attachmentName.split(","); @@ -121,6 +131,7 @@ public class NoticeService extends ServiceImpl { noticeAttachment.setNoticeId(noticeId) .setTitle(nameArr[i]) .setAttachment(pathArr[i]) + .setType(type) .setCreatedId(loginUser.getId()) .setCreatedAt(LocalDateTime.now()); noticeAttachmentService.save(noticeAttachment); @@ -129,9 +140,10 @@ public class NoticeService extends ServiceImpl { } @Transactional - public boolean apiSave(Notice notice, String coverNames, String coverPaths,User loginUser) { + public boolean apiSave(Notice notice, String coverNames, String coverPaths, String fileNames, String filePaths, User loginUser) { boolean flag = saveOrUpdate(notice); - saveAttachment(notice.getId(),coverNames,coverPaths,loginUser); + saveAttachment(notice.getId(), coverNames, coverPaths, loginUser,"1"); + saveAttachment(notice.getId(), fileNames, filePaths, loginUser,"2"); return flag; } } diff --git a/src/main/java/com/ydool/boot/modules/rddb/vo/NoticeVO.java b/src/main/java/com/ydool/boot/modules/rddb/vo/NoticeVO.java index 4c8fc70..d4d8f92 100644 --- a/src/main/java/com/ydool/boot/modules/rddb/vo/NoticeVO.java +++ b/src/main/java/com/ydool/boot/modules/rddb/vo/NoticeVO.java @@ -19,6 +19,9 @@ public class NoticeVO extends Notice { */ private String createdName; - @ApiModelProperty(value = "封面附件 一个在右边,多个在下边,最多显示三张") + @ApiModelProperty(value = "封面 一个在右边,多个在下边,最多显示三张") List coverAttachmentList; + + @ApiModelProperty(value = "附件") + List fileAttachmentList; } diff --git a/src/main/java/com/ydool/boot/modules/rddb/web/NoticeController.java b/src/main/java/com/ydool/boot/modules/rddb/web/NoticeController.java index c773c38..247600e 100644 --- a/src/main/java/com/ydool/boot/modules/rddb/web/NoticeController.java +++ b/src/main/java/com/ydool/boot/modules/rddb/web/NoticeController.java @@ -48,13 +48,13 @@ public class NoticeController extends BaseAdminController { @PreAuth("rddb:notice:list") @PostMapping("/list") public void list(NoticeVO noticeVO) { - QueryWrapper qw = getQueryWrapper(noticeVO.getTitle(),noticeVO.getType()); + QueryWrapper qw = getQueryWrapper(noticeVO.getTitle(), noticeVO.getType()); IPage paged = noticeService.page(new Page<>(getPageNum(), getPageSize()), qw); render(Ret.ok().paged(NoticeWrapper.build().pageVO(paged))); } @GetMapping("/form") - public String form(String id, Model model,String type) throws Exception { + public String form(String id, Model model, String type) throws Exception { Notice bean = new Notice(); bean.setNewRecord(true); if (StrUtil.isNotBlank(id)) { @@ -63,13 +63,22 @@ public class NoticeController extends BaseAdminController { List coverAttachmentList = noticeAttachmentService.list(new LambdaQueryWrapper() .eq(NoticeAttachment::getNoticeId, id) + .eq(NoticeAttachment::getType, "1") .orderByDesc(NoticeAttachment::getCreatedAt)); + model.addAttribute("coverAttachmentListStr", JsonMapper.getInstance().writeValueAsString(coverAttachmentList)); - if(StrUtil.isBlank(type)) type= bean.getType(); + + List fileAttachmentList = noticeAttachmentService.list(new LambdaQueryWrapper() + .eq(NoticeAttachment::getNoticeId, id) + .eq(NoticeAttachment::getType, "2") + .orderByDesc(NoticeAttachment::getCreatedAt)); + + model.addAttribute("fileAttachmentListStr", JsonMapper.getInstance().writeValueAsString(fileAttachmentList)); + if (StrUtil.isBlank(type)) type = bean.getType(); } NoticeVO noticeVO = NoticeWrapper.build().entityVO(bean); model.addAttribute("bean", noticeVO); - if("gg".equals(type)){ + if ("gg".equals(type)) { return "modules/rddb/notice/form_gg.html"; } return "modules/rddb/notice/form.html"; @@ -88,12 +97,12 @@ public class NoticeController extends BaseAdminController { renderJson(!flag ? Ret.fail("操作失败") : Ret.ok()); } - private QueryWrapper getQueryWrapper(String keywords,String type) { + private QueryWrapper getQueryWrapper(String keywords, String type) { QueryWrapper queryWrapper = new QueryWrapper<>(); if (!StrUtil.isBlankOrUndefined(keywords)) { queryWrapper.like("title", keywords); } - if(StrUtil.isNotBlank(type)) queryWrapper.eq("type",type); + if (StrUtil.isNotBlank(type)) queryWrapper.eq("type", type); queryWrapper.orderByDesc("created_at"); return queryWrapper; } diff --git a/src/main/java/com/ydool/boot/modules/rddb/wrapper/NoticeWrapper.java b/src/main/java/com/ydool/boot/modules/rddb/wrapper/NoticeWrapper.java index 0f2e5a8..95c2c7b 100644 --- a/src/main/java/com/ydool/boot/modules/rddb/wrapper/NoticeWrapper.java +++ b/src/main/java/com/ydool/boot/modules/rddb/wrapper/NoticeWrapper.java @@ -39,9 +39,18 @@ public class NoticeWrapper extends BaseWrapper { } List coverAttachmentList = noticeAttachmentSErvice.list(new LambdaQueryWrapper() .eq(NoticeAttachment::getNoticeId, notice.getId()) + .eq(NoticeAttachment::getType, "1") .orderByDesc(NoticeAttachment::getCreatedAt)); + noticeVO.setCoverAttachmentList(coverAttachmentList); + List fileAttachmentList = noticeAttachmentSErvice.list(new LambdaQueryWrapper() + .eq(NoticeAttachment::getNoticeId, notice.getId()) + .eq(NoticeAttachment::getType, "2") + .orderByDesc(NoticeAttachment::getCreatedAt)); + + noticeVO.setFileAttachmentList(fileAttachmentList); + return noticeVO; } diff --git a/src/main/resources/views/modules/rddb/notice/form.html b/src/main/resources/views/modules/rddb/notice/form.html index c91a684..4f1014e 100644 --- a/src/main/resources/views/modules/rddb/notice/form.html +++ b/src/main/resources/views/modules/rddb/notice/form.html @@ -31,7 +31,7 @@ - + - +