在通知公告发布页面增加上传附件功能
This commit is contained in:
parent
38ed005942
commit
429de207af
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -51,4 +51,9 @@ public class NoticeAttachment extends BaseEntity{
|
|||
*/
|
||||
private String size;
|
||||
|
||||
/**
|
||||
* 文件类型:1封面,2附件
|
||||
*/
|
||||
private String type;
|
||||
|
||||
}
|
||||
|
|
|
@ -10,4 +10,5 @@ import lombok.Data;
|
|||
@Data
|
||||
public class NoticeBo extends Notice {
|
||||
String coverAttachmentArrStr;
|
||||
String fileAttachmentArrStr;
|
||||
}
|
||||
|
|
|
@ -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<NoticeMapper, Notice> {
|
|||
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<NoticeMapper, Notice> {
|
|||
}
|
||||
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<Message> messageList = new ArrayList();
|
||||
//发送消息
|
||||
|
@ -80,24 +85,27 @@ public class NoticeService extends ServiceImpl<NoticeMapper, Notice> {
|
|||
}
|
||||
|
||||
public IPage<Notice> _page(Page<Object> page, QueryWrapper<Notice> 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<NoticeAttachment>()
|
||||
.eq(NoticeAttachment::getNoticeId, noticeId)
|
||||
);
|
||||
.eq(NoticeAttachment::getType,type)
|
||||
);
|
||||
if (StrUtil.isNotBlank(attachmentArrStr)) {
|
||||
List<NoticeAttachment> 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<NoticeMapper, Notice> {
|
|||
* @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<NoticeAttachment>()
|
||||
.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<NoticeMapper, Notice> {
|
|||
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<NoticeMapper, Notice> {
|
|||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@ public class NoticeVO extends Notice {
|
|||
*/
|
||||
private String createdName;
|
||||
|
||||
@ApiModelProperty(value = "封面附件 一个在右边,多个在下边,最多显示三张")
|
||||
@ApiModelProperty(value = "封面 一个在右边,多个在下边,最多显示三张")
|
||||
List<NoticeAttachment> coverAttachmentList;
|
||||
|
||||
@ApiModelProperty(value = "附件")
|
||||
List<NoticeAttachment> fileAttachmentList;
|
||||
}
|
||||
|
|
|
@ -48,13 +48,13 @@ public class NoticeController extends BaseAdminController {
|
|||
@PreAuth("rddb:notice:list")
|
||||
@PostMapping("/list")
|
||||
public void list(NoticeVO noticeVO) {
|
||||
QueryWrapper<Notice> qw = getQueryWrapper(noticeVO.getTitle(),noticeVO.getType());
|
||||
QueryWrapper<Notice> qw = getQueryWrapper(noticeVO.getTitle(), noticeVO.getType());
|
||||
IPage<Notice> 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<NoticeAttachment> coverAttachmentList = noticeAttachmentService.list(new LambdaQueryWrapper<NoticeAttachment>()
|
||||
.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<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();
|
||||
}
|
||||
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<Notice> getQueryWrapper(String keywords,String type) {
|
||||
private QueryWrapper<Notice> getQueryWrapper(String keywords, String type) {
|
||||
QueryWrapper<Notice> 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;
|
||||
}
|
||||
|
|
|
@ -39,9 +39,18 @@ public class NoticeWrapper extends BaseWrapper<Notice, NoticeVO> {
|
|||
}
|
||||
List<NoticeAttachment> coverAttachmentList = noticeAttachmentSErvice.list(new LambdaQueryWrapper<NoticeAttachment>()
|
||||
.eq(NoticeAttachment::getNoticeId, notice.getId())
|
||||
.eq(NoticeAttachment::getType, "1")
|
||||
.orderByDesc(NoticeAttachment::getCreatedAt));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<act:mupload text="封面" name="coverAttachment" listStr="${coverAttachmentListStr!}"/>
|
||||
|
||||
<act:mupload text="附件" name="fileAttachment" listStr="${fileAttachmentListStr!}"/>
|
||||
</div>
|
||||
|
||||
<div class="box-footer">
|
||||
|
@ -58,14 +58,23 @@
|
|||
var sHTML = $('.summerNote').summernote('code');
|
||||
sHTML= sHTML.replace(new RegExp("'","gm"), "\"");
|
||||
$("#content").val(sHTML);
|
||||
|
||||
|
||||
//封面
|
||||
var coverAttachmentArr = new Array();
|
||||
$.each($(".coverAttachment"), function (i, n) {
|
||||
var val = $(n).data("val");
|
||||
coverAttachmentArr.push(val)
|
||||
});
|
||||
$("[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;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<act:mupload text="封面" name="coverAttachment" listStr="${coverAttachmentListStr!}"/>
|
||||
|
||||
<act:mupload text="附件" name="fileAttachment" listStr="${fileAttachmentListStr!}"/>
|
||||
</div>
|
||||
|
||||
<div class="box-footer">
|
||||
|
@ -58,13 +58,22 @@
|
|||
var sHTML = $('.summerNote').summernote('code');
|
||||
sHTML= sHTML.replace(new RegExp("'","gm"), "\"");
|
||||
$("#content").val(sHTML);
|
||||
|
||||
|
||||
//封面
|
||||
var coverAttachmentArr = new Array();
|
||||
$.each($(".coverAttachment"), function (i, n) {
|
||||
var val = $(n).data("val");
|
||||
coverAttachmentArr.push(val)
|
||||
});
|
||||
$("[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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue