在通知公告发布页面增加上传附件功能

This commit is contained in:
lijiaqi 2022-08-05 14:48:05 +08:00
parent 38ed005942
commit 429de207af
9 changed files with 82 additions and 23 deletions

View File

@ -92,12 +92,14 @@ public class ApiNoticeController extends ApiBaseController {
@ApiImplicitParam(name = "top", value = "是否置顶0不置顶1置顶"), @ApiImplicitParam(name = "top", value = "是否置顶0不置顶1置顶"),
@ApiImplicitParam(name = "coverNames", value = "封面名,多个英文逗号间隔"), @ApiImplicitParam(name = "coverNames", value = "封面名,多个英文逗号间隔"),
@ApiImplicitParam(name = "coverPaths", value = "封面路径,多个英文逗号间隔"), @ApiImplicitParam(name = "coverPaths", value = "封面路径,多个英文逗号间隔"),
@ApiImplicitParam(name = "fileNames", value = "附件名,多个英文逗号间隔"),
@ApiImplicitParam(name = "filePaths", value = "附件路径,多个英文逗号间隔"),
@ApiImplicitParam(name = "type", value = "分类tz / gg"), @ApiImplicitParam(name = "type", value = "分类tz / gg"),
@ApiImplicitParam(name = "obj", value = "公告对象 admin机关办公/ rddb代表/ voter选民 多个用英文逗号间隔 ") @ApiImplicitParam(name = "obj", value = "公告对象 admin机关办公/ rddb代表/ voter选民 多个用英文逗号间隔 ")
}) })
@ApiOperation("发布公告") @ApiOperation("发布公告")
@PostMapping("/save") @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(); Notice bean = new Notice();
bean.setTitle(title); bean.setTitle(title);
bean.setContent(content); bean.setContent(content);
@ -107,7 +109,7 @@ public class ApiNoticeController extends ApiBaseController {
bean.setCreatedId(getApiUserId()); bean.setCreatedId(getApiUserId());
bean.setType(type); bean.setType(type);
bean.setObj(obj); 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()); render(!flag ? Ret.fail("操作失败") : Ret.ok());
} }

View File

@ -51,4 +51,9 @@ public class NoticeAttachment extends BaseEntity{
*/ */
private String size; private String size;
/**
* 文件类型1封面2附件
*/
private String type;
} }

View File

@ -10,4 +10,5 @@ import lombok.Data;
@Data @Data
public class NoticeBo extends Notice { public class NoticeBo extends Notice {
String coverAttachmentArrStr; String coverAttachmentArrStr;
String fileAttachmentArrStr;
} }

View File

@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Type;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -57,9 +58,13 @@ public class NoticeService extends ServiceImpl<NoticeMapper, Notice> {
} }
flag = this.updateById(entity); flag = this.updateById(entity);
} }
//附件 //封面
String coverAttachmentArrStr = noticeBo.getCoverAttachmentArrStr(); 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<Message> messageList = new ArrayList(); List<Message> messageList = new ArrayList();
//发送消息 //发送消息
@ -87,10 +92,12 @@ public class NoticeService extends ServiceImpl<NoticeMapper, Notice> {
* @param noticeId * @param noticeId
* @param attachmentArrStr * @param attachmentArrStr
* @param loginUser * @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<NoticeAttachment>() noticeAttachmentService.remove(new LambdaQueryWrapper<NoticeAttachment>()
.eq(NoticeAttachment::getNoticeId, noticeId) .eq(NoticeAttachment::getNoticeId, noticeId)
.eq(NoticeAttachment::getType,type)
); );
if (StrUtil.isNotBlank(attachmentArrStr)) { if (StrUtil.isNotBlank(attachmentArrStr)) {
List<NoticeAttachment> attachmentList = JSONObject.parseArray(attachmentArrStr, NoticeAttachment.class); List<NoticeAttachment> attachmentList = JSONObject.parseArray(attachmentArrStr, NoticeAttachment.class);
@ -98,6 +105,7 @@ public class NoticeService extends ServiceImpl<NoticeMapper, Notice> {
item.setNoticeId(noticeId); item.setNoticeId(noticeId);
item.setCreatedId(loginUser.getId()); item.setCreatedId(loginUser.getId());
item.setCreatedAt(LocalDateTime.now()); item.setCreatedAt(LocalDateTime.now());
item.setType(type);
}); });
noticeAttachmentService.saveBatch(attachmentList); noticeAttachmentService.saveBatch(attachmentList);
} }
@ -108,10 +116,12 @@ public class NoticeService extends ServiceImpl<NoticeMapper, Notice> {
* @param attachmentName * @param attachmentName
* @param attachmentPath * @param attachmentPath
* @param loginUser * @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<NoticeAttachment>() noticeAttachmentService.remove(new LambdaQueryWrapper<NoticeAttachment>()
.eq(NoticeAttachment::getNoticeId, noticeId) .eq(NoticeAttachment::getNoticeId, noticeId)
.eq(NoticeAttachment::getType,type)
); );
if (StrUtil.isNotBlank(attachmentName)) { if (StrUtil.isNotBlank(attachmentName)) {
String[] nameArr = attachmentName.split(","); String[] nameArr = attachmentName.split(",");
@ -121,6 +131,7 @@ public class NoticeService extends ServiceImpl<NoticeMapper, Notice> {
noticeAttachment.setNoticeId(noticeId) noticeAttachment.setNoticeId(noticeId)
.setTitle(nameArr[i]) .setTitle(nameArr[i])
.setAttachment(pathArr[i]) .setAttachment(pathArr[i])
.setType(type)
.setCreatedId(loginUser.getId()) .setCreatedId(loginUser.getId())
.setCreatedAt(LocalDateTime.now()); .setCreatedAt(LocalDateTime.now());
noticeAttachmentService.save(noticeAttachment); noticeAttachmentService.save(noticeAttachment);
@ -129,9 +140,10 @@ public class NoticeService extends ServiceImpl<NoticeMapper, Notice> {
} }
@Transactional @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); 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; return flag;
} }
} }

View File

@ -19,6 +19,9 @@ public class NoticeVO extends Notice {
*/ */
private String createdName; private String createdName;
@ApiModelProperty(value = "封面附件 一个在右边,多个在下边,最多显示三张") @ApiModelProperty(value = "封面 一个在右边,多个在下边,最多显示三张")
List<NoticeAttachment> coverAttachmentList; List<NoticeAttachment> coverAttachmentList;
@ApiModelProperty(value = "附件")
List<NoticeAttachment> fileAttachmentList;
} }

View File

@ -63,8 +63,17 @@ public class NoticeController extends BaseAdminController {
List<NoticeAttachment> coverAttachmentList = noticeAttachmentService.list(new LambdaQueryWrapper<NoticeAttachment>() List<NoticeAttachment> coverAttachmentList = noticeAttachmentService.list(new LambdaQueryWrapper<NoticeAttachment>()
.eq(NoticeAttachment::getNoticeId, id) .eq(NoticeAttachment::getNoticeId, id)
.eq(NoticeAttachment::getType, "1")
.orderByDesc(NoticeAttachment::getCreatedAt)); .orderByDesc(NoticeAttachment::getCreatedAt));
model.addAttribute("coverAttachmentListStr", JsonMapper.getInstance().writeValueAsString(coverAttachmentList)); model.addAttribute("coverAttachmentListStr", JsonMapper.getInstance().writeValueAsString(coverAttachmentList));
List<NoticeAttachment> fileAttachmentList = noticeAttachmentService.list(new LambdaQueryWrapper<NoticeAttachment>()
.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(); if (StrUtil.isBlank(type)) type = bean.getType();
} }
NoticeVO noticeVO = NoticeWrapper.build().entityVO(bean); NoticeVO noticeVO = NoticeWrapper.build().entityVO(bean);

View File

@ -39,9 +39,18 @@ public class NoticeWrapper extends BaseWrapper<Notice, NoticeVO> {
} }
List<NoticeAttachment> coverAttachmentList = noticeAttachmentSErvice.list(new LambdaQueryWrapper<NoticeAttachment>() List<NoticeAttachment> coverAttachmentList = noticeAttachmentSErvice.list(new LambdaQueryWrapper<NoticeAttachment>()
.eq(NoticeAttachment::getNoticeId, notice.getId()) .eq(NoticeAttachment::getNoticeId, notice.getId())
.eq(NoticeAttachment::getType, "1")
.orderByDesc(NoticeAttachment::getCreatedAt)); .orderByDesc(NoticeAttachment::getCreatedAt));
noticeVO.setCoverAttachmentList(coverAttachmentList); noticeVO.setCoverAttachmentList(coverAttachmentList);
List<NoticeAttachment> fileAttachmentList = noticeAttachmentSErvice.list(new LambdaQueryWrapper<NoticeAttachment>()
.eq(NoticeAttachment::getNoticeId, notice.getId())
.eq(NoticeAttachment::getType, "2")
.orderByDesc(NoticeAttachment::getCreatedAt));
noticeVO.setFileAttachmentList(fileAttachmentList);
return noticeVO; return noticeVO;
} }

View File

@ -31,7 +31,7 @@
</div> </div>
</div> </div>
<act:mupload text="封面" name="coverAttachment" listStr="${coverAttachmentListStr!}"/> <act:mupload text="封面" name="coverAttachment" listStr="${coverAttachmentListStr!}"/>
<act:mupload text="附件" name="fileAttachment" listStr="${fileAttachmentListStr!}"/>
</div> </div>
<div class="box-footer"> <div class="box-footer">
@ -59,6 +59,7 @@
sHTML= sHTML.replace(new RegExp("'","gm"), "\""); sHTML= sHTML.replace(new RegExp("'","gm"), "\"");
$("#content").val(sHTML); $("#content").val(sHTML);
//封面
var coverAttachmentArr = new Array(); var coverAttachmentArr = new Array();
$.each($(".coverAttachment"), function (i, n) { $.each($(".coverAttachment"), function (i, n) {
var val = $(n).data("val"); var val = $(n).data("val");
@ -66,6 +67,14 @@
}); });
$("[name='coverAttachmentArrStr']").val(JSON.stringify(coverAttachmentArr)); $("[name='coverAttachmentArrStr']").val(JSON.stringify(coverAttachmentArr));
//附件
var fileAttachment = new Array();
$.each($(".fileAttachment"), function (i, n) {
var val = $(n).data("val");
fileAttachment.push(val)
});
$("[name='fileAttachmentArrStr']").val(JSON.stringify(fileAttachment));
return true; return true;
} }

View File

@ -31,7 +31,7 @@
</div> </div>
</div> </div>
<act:mupload text="封面" name="coverAttachment" listStr="${coverAttachmentListStr!}"/> <act:mupload text="封面" name="coverAttachment" listStr="${coverAttachmentListStr!}"/>
<act:mupload text="附件" name="fileAttachment" listStr="${fileAttachmentListStr!}"/>
</div> </div>
<div class="box-footer"> <div class="box-footer">
@ -59,6 +59,7 @@
sHTML= sHTML.replace(new RegExp("'","gm"), "\""); sHTML= sHTML.replace(new RegExp("'","gm"), "\"");
$("#content").val(sHTML); $("#content").val(sHTML);
//封面
var coverAttachmentArr = new Array(); var coverAttachmentArr = new Array();
$.each($(".coverAttachment"), function (i, n) { $.each($(".coverAttachment"), function (i, n) {
var val = $(n).data("val"); var val = $(n).data("val");
@ -66,6 +67,14 @@
}); });
$("[name='coverAttachmentArrStr']").val(JSON.stringify(coverAttachmentArr)); $("[name='coverAttachmentArrStr']").val(JSON.stringify(coverAttachmentArr));
//附件
var fileAttachment = new Array();
$.each($(".fileAttachment"), function (i, n) {
var val = $(n).data("val");
fileAttachment.push(val)
});
$("[name='fileAttachmentArrStr']").val(JSON.stringify(fileAttachment));
return true; return true;
} }