diff --git a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/topic/form/EditNoticeFormDTO.java b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/topic/form/EditNoticeFormDTO.java new file mode 100644 index 0000000000..effa23bc47 --- /dev/null +++ b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/topic/form/EditNoticeFormDTO.java @@ -0,0 +1,41 @@ +package com.epmet.resi.group.dto.topic.form; + +import lombok.Data; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotBlank; +import java.util.List; + +/** + * @Author sun + * @Description 小组通知编辑-接口入参 + */ +@Data +public class EditNoticeFormDTO { + + /** + * 通知Id + */ + @NotBlank(message = "通知Id不能为空",groups = {EditNoticeFormDTO.Edit.class}) + private String noticeId; + /** + * 通知标题 + */ + @Length(max = 20, message = "通知标题不能超过20个字符") + private String title; + /** + * 通知内容 + */ + @Length(max = 1000, message = "通知内容不能超过1000个字符") + private String content; + /** + * 图片附件集合 + */ + private List imageList; + /** + * 文件附件url集合 + */ + private List docList; + + public interface Edit{} +} diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeController.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeController.java index 6b1c5cb5b6..81504025c2 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeController.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeController.java @@ -31,6 +31,7 @@ import com.epmet.modules.notice.excel.NoticeExcel; import com.epmet.modules.notice.service.NoticeService; import com.epmet.resi.group.dto.notice.NoticeDTO; import com.epmet.resi.group.dto.topic.form.AddNoticeFormDTO; +import com.epmet.resi.group.dto.topic.form.EditNoticeFormDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -107,4 +108,17 @@ public class NoticeController { return new Result(); } + /** + * @param formDTO + * @return + * @Author sun + * @Description 小组通知变更 + **/ + @PostMapping(value = "edit") + public Result edit(@LoginUser TokenDto tokenDto, @RequestBody EditNoticeFormDTO formDTO){ + ValidatorUtils.validateEntity(formDTO, EditNoticeFormDTO.Edit.class); + noticeService.edit(tokenDto, formDTO); + return new Result(); + } + } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeAttachmentDao.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeAttachmentDao.java index 5561248f73..34aef12db5 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeAttachmentDao.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeAttachmentDao.java @@ -20,6 +20,7 @@ package com.epmet.modules.notice.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.modules.notice.entity.NoticeAttachmentEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 小组通知附件表 @@ -29,5 +30,10 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface NoticeAttachmentDao extends BaseDao { - + + /** + * @Author sun + * @Description 删除通知附件-物理删除 + **/ + void delByNoticeId(@Param("noticeId") String noticeId); } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeReafdRecordDao.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeReafdRecordDao.java index 3cfb9389a4..bc16f1881b 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeReafdRecordDao.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeReafdRecordDao.java @@ -20,6 +20,7 @@ package com.epmet.modules.notice.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.modules.notice.entity.NoticeReafdRecordEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 小组通知组成员阅读记录表 @@ -29,5 +30,10 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface NoticeReafdRecordDao extends BaseDao { - + + /** + * @Author sun + * @Description 删除通知已读未读数据-物理删除 + **/ + void delByNoticeId(@Param("noticeId") String noticeId); } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeService.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeService.java index fb153f03c4..abc9a43894 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeService.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeService.java @@ -23,6 +23,7 @@ import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.modules.notice.entity.NoticeEntity; import com.epmet.resi.group.dto.notice.NoticeDTO; import com.epmet.resi.group.dto.topic.form.AddNoticeFormDTO; +import com.epmet.resi.group.dto.topic.form.EditNoticeFormDTO; import java.util.List; import java.util.Map; @@ -102,4 +103,12 @@ public interface NoticeService extends BaseService { * @Description 小组通知保存 **/ void add(TokenDto tokenDto, AddNoticeFormDTO formDTO); + + /** + * @param formDTO + * @return + * @Author sun + * @Description 小组通知变更 + **/ + void edit(TokenDto tokenDto, EditNoticeFormDTO formDTO); } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/impl/NoticeServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/impl/NoticeServiceImpl.java index 6080c245ea..b87d78f76e 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/impl/NoticeServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/impl/NoticeServiceImpl.java @@ -46,15 +46,23 @@ import com.epmet.modules.constant.UserMessageConstant; import com.epmet.modules.group.dao.ResiGroupDao; import com.epmet.modules.group.entity.ResiGroupEntity; import com.epmet.modules.member.dao.ResiGroupMemberDao; +import com.epmet.modules.notice.dao.NoticeAttachmentDao; import com.epmet.modules.notice.dao.NoticeDao; +import com.epmet.modules.notice.dao.NoticeReafdRecordDao; +import com.epmet.modules.notice.entity.NoticeAttachmentEntity; import com.epmet.modules.notice.entity.NoticeEntity; +import com.epmet.modules.notice.entity.NoticeReafdRecordEntity; import com.epmet.modules.notice.redis.NoticeRedis; +import com.epmet.modules.notice.service.NoticeAttachmentService; +import com.epmet.modules.notice.service.NoticeReafdRecordService; import com.epmet.modules.notice.service.NoticeService; import com.epmet.resi.group.constant.TopicConstant; import com.epmet.resi.group.dto.member.ResiGroupMemberDTO; import com.epmet.resi.group.dto.notice.NoticeDTO; import com.epmet.resi.group.dto.topic.form.AddNoticeFormDTO; +import com.epmet.resi.group.dto.topic.form.EditNoticeFormDTO; import com.epmet.resi.group.dto.topic.form.FileDTO; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -64,6 +72,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -92,6 +101,14 @@ public class NoticeServiceImpl extends BaseServiceImpl private EpmetUserOpenFeignClient epmetUserOpenFeignClient; @Autowired private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; + @Autowired + private NoticeAttachmentService noticeAttachmentService; + @Autowired + private NoticeAttachmentDao noticeAttachmentDao; + @Autowired + private NoticeReafdRecordService noticeReafdRecordService; + @Autowired + private NoticeReafdRecordDao noticeReafdRecordDao; @Override @@ -110,8 +127,8 @@ public class NoticeServiceImpl extends BaseServiceImpl return ConvertUtils.sourceToTarget(entityList, NoticeDTO.class); } - private QueryWrapper getWrapper(Map params){ - String id = (String)params.get(FieldConstant.ID_HUMP); + private QueryWrapper getWrapper(Map params) { + String id = (String) params.get(FieldConstant.ID_HUMP); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); @@ -157,31 +174,32 @@ public class NoticeServiceImpl extends BaseServiceImpl public void add(TokenDto tokenDto, AddNoticeFormDTO formDTO) { //1.查询组内成员数据 List memberList = resiGroupMemberDao.getMemberList(formDTO.getGroupId()); - if(CollUtil.isEmpty(memberList)){ + if (CollUtil.isEmpty(memberList)) { throw new RenException(String.format("保存小组通知,获取组内成员列表失败,小组Id->", formDTO.getGroupId())); } //2.校验当前操作人员是否为组长 AtomicReference bl = new AtomicReference<>(true); - memberList.forEach(m->{ - if(m.getCustomerUserId().equals(tokenDto.getUserId())&&"leader".equals(m.getGroupLeaderFlag())){ + memberList.forEach(m -> { + if (m.getCustomerUserId().equals(tokenDto.getUserId()) && "leader".equals(m.getGroupLeaderFlag())) { bl.set(false); } }); - if(bl.get()){ + if (bl.get()) { throw new RenException(String.format("保存小组通知,当前操作人员不是群组长,小组Id->", formDTO.getGroupId())); } //3.文字、图片安全校验 List wordList = new ArrayList<>(); - wordList.add(formDTO.getTitle());wordList.add(formDTO.getContent()); + wordList.add(formDTO.getTitle()); + wordList.add(formDTO.getContent()); List imageList = formDTO.getImageList().stream().map(FileDTO::getUrl).collect(Collectors.toList()); safetyCheck(wordList, imageList); //4.保存小组通知基础数据 //4-1.获取小组信息 ResiGroupEntity groupEntity = resiGroupDao.selectById(formDTO.getGroupId()); - if(null == groupEntity){ + if (null == groupEntity) { throw new RenException(String.format("保存小组通知,获取小组数据失败,小组Id->", tokenDto.getUserId())); } //4-2.获取token用户所属组织信息 @@ -207,10 +225,71 @@ public class NoticeServiceImpl extends BaseServiceImpl entity.setChangeTime(new Date()); insert(entity); - //5.组内成员推送站内信 + //5.保存附件数据 + List AttachmentEntityList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(formDTO.getImageList())) { + AtomicInteger sort = new AtomicInteger(); + formDTO.getImageList().forEach(img -> { + NoticeAttachmentEntity attachment = new NoticeAttachmentEntity(); + attachment.setCustomerId(resultDTO.getCustomerId()); + attachment.setNoticeId(entity.getId()); + attachment.setFileName(img.getName()); + attachment.setAttachmentName(""); + attachment.setAttachmentSize(img.getSize()); + attachment.setAttachmentFormat(img.getFormat()); + attachment.setAttachmentType(img.getType()); + attachment.setAttachmentUrl(img.getUrl()); + attachment.setSort(sort.get()); + attachment.setDuration(img.getDuration()); + sort.getAndIncrement(); + AttachmentEntityList.add(attachment); + + }); + } + if (CollectionUtils.isNotEmpty(formDTO.getDocList())) { + AtomicInteger i = new AtomicInteger(); + formDTO.getDocList().forEach(doc -> { + NoticeAttachmentEntity attachment = new NoticeAttachmentEntity(); + attachment.setCustomerId(resultDTO.getCustomerId()); + attachment.setNoticeId(entity.getId()); + attachment.setFileName(doc.getName()); + attachment.setAttachmentName(""); + attachment.setAttachmentSize(doc.getSize()); + attachment.setAttachmentFormat(doc.getFormat()); + attachment.setAttachmentType(doc.getType()); + attachment.setAttachmentUrl(doc.getUrl()); + attachment.setSort(i.get()); + attachment.setDuration(doc.getDuration()); + i.getAndIncrement(); + AttachmentEntityList.add(attachment); + }); + } + if (AttachmentEntityList.size() > NumConstant.ZERO) { + noticeAttachmentService.insertBatch(AttachmentEntityList); + } + + //6.通知已读未读表初始数据 + List reafdRecordList = new ArrayList<>(); + memberList.forEach(m -> { + if (!"".equals(m.getGroupLeaderFlag())) { + NoticeReafdRecordEntity reafdRecord = new NoticeReafdRecordEntity(); + reafdRecord.setCustomerId(resultDTO.getCustomerId()); + reafdRecord.setGridId(groupEntity.getGridId()); + reafdRecord.setGroupId(formDTO.getGroupId()); + reafdRecord.setNoticeId(entity.getId()); + reafdRecord.setUserId(m.getCustomerUserId()); + reafdRecord.setReadFlag(ReadFlagConstant.UN_READ); + reafdRecordList.add(reafdRecord); + } + }); + if (reafdRecordList.size() > NumConstant.ZERO) { + noticeReafdRecordService.insertBatch(reafdRecordList); + } + + //7.组内成员推送站内信 List userMessageFormDTOS = new ArrayList<>(); - memberList.forEach(m->{ - if(!"".equals(m.getGroupLeaderFlag())){ + memberList.forEach(m -> { + if (!"".equals(m.getGroupLeaderFlag())) { UserMessageFormDTO userMessageFormDTO = new UserMessageFormDTO(); userMessageFormDTO.setCustomerId(resultDTO.getCustomerId()); userMessageFormDTO.setUserId(m.getCustomerUserId()); @@ -229,13 +308,137 @@ public class NoticeServiceImpl extends BaseServiceImpl } + /** + * @param formDTO + * @return + * @Author sun + * @Description 小组通知变更 + **/ + @Override + public void edit(TokenDto tokenDto, EditNoticeFormDTO formDTO) { + //1.查询通知是否存在 + NoticeEntity entity = baseDao.selectById(formDTO.getNoticeId()); + if(null == entity){ + throw new RenException(String.format("小组通知变更,获取通知数据失败,通知Id->", formDTO.getNoticeId())); + } + //2.文字、图片安全校验 + List wordList = new ArrayList<>(); + wordList.add(formDTO.getTitle()); + wordList.add(formDTO.getContent()); + List imageList = formDTO.getImageList().stream().map(FileDTO::getUrl).collect(Collectors.toList()); + safetyCheck(wordList, imageList); + + //3.查询组成员列表数据 + List memberList = resiGroupMemberDao.getMemberList(entity.getGroupId()); + if (CollUtil.isEmpty(memberList)) { + throw new RenException(String.format("保存小组通知,获取组内成员列表失败,小组Id->", entity.getGroupId())); + } + + //4.通知基础数据修改 + entity.setTitle(formDTO.getTitle()); + entity.setContent(formDTO.getContent()); + entity.setIsChange("yes"); + entity.setChangeTime(new Date()); + baseDao.updateById(entity); + + //5.通知附件表数据先删后增 + noticeAttachmentDao.delByNoticeId(formDTO.getNoticeId()); + //保存附件数据 + List AttachmentEntityList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(formDTO.getImageList())) { + AtomicInteger sort = new AtomicInteger(); + formDTO.getImageList().forEach(img -> { + NoticeAttachmentEntity attachment = new NoticeAttachmentEntity(); + attachment.setCustomerId(entity.getCustomerId()); + attachment.setNoticeId(entity.getId()); + attachment.setFileName(img.getName()); + attachment.setAttachmentName(""); + attachment.setAttachmentSize(img.getSize()); + attachment.setAttachmentFormat(img.getFormat()); + attachment.setAttachmentType(img.getType()); + attachment.setAttachmentUrl(img.getUrl()); + attachment.setSort(sort.get()); + attachment.setDuration(img.getDuration()); + sort.getAndIncrement(); + AttachmentEntityList.add(attachment); + + }); + } + if (CollectionUtils.isNotEmpty(formDTO.getDocList())) { + AtomicInteger i = new AtomicInteger(); + formDTO.getDocList().forEach(doc -> { + NoticeAttachmentEntity attachment = new NoticeAttachmentEntity(); + attachment.setCustomerId(entity.getCustomerId()); + attachment.setNoticeId(entity.getId()); + attachment.setFileName(doc.getName()); + attachment.setAttachmentName(""); + attachment.setAttachmentSize(doc.getSize()); + attachment.setAttachmentFormat(doc.getFormat()); + attachment.setAttachmentType(doc.getType()); + attachment.setAttachmentUrl(doc.getUrl()); + attachment.setSort(i.get()); + attachment.setDuration(doc.getDuration()); + i.getAndIncrement(); + AttachmentEntityList.add(attachment); + }); + } + if (AttachmentEntityList.size() > NumConstant.ZERO) { + noticeAttachmentService.insertBatch(AttachmentEntityList); + } + + //6.通知已读未读消息表数据先删后增 + noticeReafdRecordDao.delByNoticeId(formDTO.getNoticeId()); + List reafdRecordList = new ArrayList<>(); + memberList.forEach(m -> { + if (!"".equals(m.getGroupLeaderFlag())) { + NoticeReafdRecordEntity reafdRecord = new NoticeReafdRecordEntity(); + reafdRecord.setCustomerId(entity.getCustomerId()); + reafdRecord.setGridId(entity.getGridId()); + reafdRecord.setGroupId(entity.getGroupId()); + reafdRecord.setNoticeId(entity.getId()); + reafdRecord.setUserId(m.getCustomerUserId()); + reafdRecord.setReadFlag(ReadFlagConstant.UN_READ); + reafdRecordList.add(reafdRecord); + } + }); + if (reafdRecordList.size() > NumConstant.ZERO) { + noticeReafdRecordService.insertBatch(reafdRecordList); + } + + //7.推送站内信 + //7-1.获取小组信息 + ResiGroupEntity groupEntity = resiGroupDao.selectById(entity.getGroupId()); + if (null == groupEntity) { + throw new RenException(String.format("保存小组通知,获取小组数据失败,小组Id->", tokenDto.getUserId())); + } + //7-2.推送站内信信息 + List userMessageFormDTOS = new ArrayList<>(); + memberList.forEach(m -> { + if (!"".equals(m.getGroupLeaderFlag())) { + UserMessageFormDTO userMessageFormDTO = new UserMessageFormDTO(); + userMessageFormDTO.setCustomerId(entity.getCustomerId()); + userMessageFormDTO.setUserId(m.getCustomerUserId()); + userMessageFormDTO.setGridId(entity.getGridId()); + userMessageFormDTO.setApp(AppClientConstant.APP_RESI); + userMessageFormDTO.setTitle(UserMessageConstant.GROUP_TITLE); + userMessageFormDTO.setReadFlag(ReadFlagConstant.UN_READ); + userMessageFormDTO.setMessageContent(String.format(UserMessageConstant.GROUP_NOTICE_EDIT, groupEntity.getGroupName(), formDTO.getTitle())); + userMessageFormDTOS.add(userMessageFormDTO); + } + }); + Result sendMessageRes = epmetMessageOpenFeignClient.saveUserMessageList(userMessageFormDTOS); + if (!sendMessageRes.success()) { + logger.warn("小组通知,给组内成员推送站内信失败。"); + } + } + /** * @Author sun * @Description 文字、图片安全校验 **/ - private void safetyCheck(List wordList, List imageList){ - if (imageList.size() != NumConstant.ZERO){ - wordList.forEach(word->{ + private void safetyCheck(List wordList, List imageList) { + if (imageList.size() != NumConstant.ZERO) { + wordList.forEach(word -> { //创建话题内容审核 TextScanParamDTO textScanParamDTO = new TextScanParamDTO(); TextTaskDTO taskDTO = new TextTaskDTO(); @@ -254,7 +457,7 @@ public class NoticeServiceImpl extends BaseServiceImpl }); } //创建话题图片审核 - if (imageList.size() != NumConstant.ZERO){ + if (imageList.size() != NumConstant.ZERO) { ImgScanParamDTO imgScanParamDTO = new ImgScanParamDTO(); imageList.forEach(url -> { ImgTaskDTO task = new ImgTaskDTO(); @@ -263,7 +466,7 @@ public class NoticeServiceImpl extends BaseServiceImpl imgScanParamDTO.getTasks().add(task); }); Result imgScanResult = ScanContentUtils.imgSyncScan(scanApiUrl.concat(imgSyncScanMethod), imgScanParamDTO); - if (!imgScanResult.success()){ + if (!imgScanResult.success()) { throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); } else { if (!imgScanResult.getData().isAllPass()) { diff --git a/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeAttachmentDao.xml b/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeAttachmentDao.xml index 0fda19e6bf..6ee12ce2e0 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeAttachmentDao.xml +++ b/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeAttachmentDao.xml @@ -3,5 +3,12 @@ + + DELETE + FROM + notice_attachment + WHERE + notice_id = #{noticeId} + \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeReafdRecordDao.xml b/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeReafdRecordDao.xml index c726525ef0..95935efdd0 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeReafdRecordDao.xml +++ b/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeReafdRecordDao.xml @@ -3,5 +3,12 @@ + + DELETE + FROM + notice_reafd_record + WHERE + notice_id = #{noticeId} + \ No newline at end of file