Browse Source

小组通知变更

dev_shibei_match
sunyuchao 4 years ago
parent
commit
6b1a6192d7
  1. 41
      epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/topic/form/EditNoticeFormDTO.java
  2. 14
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeController.java
  3. 6
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeAttachmentDao.java
  4. 6
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/dao/NoticeReafdRecordDao.java
  5. 9
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeService.java
  6. 207
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/impl/NoticeServiceImpl.java
  7. 7
      epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeAttachmentDao.xml
  8. 7
      epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeReafdRecordDao.xml

41
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<FileDTO> imageList;
/**
* 文件附件url集合
*/
private List<FileDTO> docList;
public interface Edit{}
}

14
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();
}
}

6
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;
/**
* 小组通知附件表
@ -30,4 +31,9 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface NoticeAttachmentDao extends BaseDao<NoticeAttachmentEntity> {
/**
* @Author sun
* @Description 删除通知附件-物理删除
**/
void delByNoticeId(@Param("noticeId") String noticeId);
}

6
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;
/**
* 小组通知组成员阅读记录表
@ -30,4 +31,9 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface NoticeReafdRecordDao extends BaseDao<NoticeReafdRecordEntity> {
/**
* @Author sun
* @Description 删除通知已读未读数据-物理删除
**/
void delByNoticeId(@Param("noticeId") String noticeId);
}

9
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<NoticeEntity> {
* @Description 小组通知保存
**/
void add(TokenDto tokenDto, AddNoticeFormDTO formDTO);
/**
* @param formDTO
* @return
* @Author sun
* @Description 小组通知变更
**/
void edit(TokenDto tokenDto, EditNoticeFormDTO formDTO);
}

207
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<NoticeDao, NoticeEntity>
private EpmetUserOpenFeignClient epmetUserOpenFeignClient;
@Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
@Autowired
private NoticeAttachmentService noticeAttachmentService;
@Autowired
private NoticeAttachmentDao noticeAttachmentDao;
@Autowired
private NoticeReafdRecordService noticeReafdRecordService;
@Autowired
private NoticeReafdRecordDao noticeReafdRecordDao;
@Override
@ -174,7 +191,8 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeDao, NoticeEntity>
//3.文字、图片安全校验
List<String> wordList = new ArrayList<>();
wordList.add(formDTO.getTitle());wordList.add(formDTO.getContent());
wordList.add(formDTO.getTitle());
wordList.add(formDTO.getContent());
List<String> imageList = formDTO.getImageList().stream().map(FileDTO::getUrl).collect(Collectors.toList());
safetyCheck(wordList, imageList);
@ -207,7 +225,68 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeDao, NoticeEntity>
entity.setChangeTime(new Date());
insert(entity);
//5.组内成员推送站内信
//5.保存附件数据
List<NoticeAttachmentEntity> 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<NoticeReafdRecordEntity> 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<UserMessageFormDTO> userMessageFormDTOS = new ArrayList<>();
memberList.forEach(m -> {
if (!"".equals(m.getGroupLeaderFlag())) {
@ -229,6 +308,130 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeDao, NoticeEntity>
}
/**
* @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<String> wordList = new ArrayList<>();
wordList.add(formDTO.getTitle());
wordList.add(formDTO.getContent());
List<String> imageList = formDTO.getImageList().stream().map(FileDTO::getUrl).collect(Collectors.toList());
safetyCheck(wordList, imageList);
//3.查询组成员列表数据
List<ResiGroupMemberDTO> 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<NoticeAttachmentEntity> 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<NoticeReafdRecordEntity> 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<UserMessageFormDTO> 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 文字图片安全校验

7
epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeAttachmentDao.xml

@ -3,5 +3,12 @@
<mapper namespace="com.epmet.modules.notice.dao.NoticeAttachmentDao">
<delete id="delByNoticeId">
DELETE
FROM
notice_attachment
WHERE
notice_id = #{noticeId}
</delete>
</mapper>

7
epmet-module/resi-group/resi-group-server/src/main/resources/mapper/notice/NoticeReafdRecordDao.xml

@ -3,5 +3,12 @@
<mapper namespace="com.epmet.modules.notice.dao.NoticeReafdRecordDao">
<delete id="delByNoticeId">
DELETE
FROM
notice_reafd_record
WHERE
notice_id = #{noticeId}
</delete>
</mapper>
Loading…
Cancel
Save