diff --git a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/UserMessageFormDTO.java b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/UserMessageFormDTO.java index f3298183d6..e00bb88342 100644 --- a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/UserMessageFormDTO.java +++ b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/UserMessageFormDTO.java @@ -58,7 +58,7 @@ public class UserMessageFormDTO implements Serializable { private String readFlag; /** - * 调用者 + * 调用者 【分内部调用和外部调用,内部调用值为空,外部默认为:外挂-站内信】 */ private String referer; } diff --git a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/topic/form/AddNoticeFormDTO.java b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/topic/form/AddNoticeFormDTO.java new file mode 100644 index 0000000000..767bb639ca --- /dev/null +++ b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/topic/form/AddNoticeFormDTO.java @@ -0,0 +1,43 @@ +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 AddNoticeFormDTO { + + /** + * 小组Id + */ + @NotBlank(message = "小组Id不能为空",groups = {AddNoticeFormDTO.Add.class}) + private String groupId; + /** + * 通知标题 + */ + @NotBlank(message = "通知标题不能为空",groups = {AddNoticeFormDTO.Add.class}) + @Length(max = 20, message = "通知标题不能超过20个字符") + private String title; + /** + * 通知内容 + */ + @NotBlank(message = "通知内容不能为空",groups = {AddNoticeFormDTO.Add.class}) + @Length(max = 1000, message = "通知内容不能超过1000个字符") + private String content; + /** + * 图片附件集合 + */ + private List imageList; + /** + * 文件附件url集合 + */ + private List docList; + + public interface Add{} +} diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/constant/UserMessageConstant.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/constant/UserMessageConstant.java index eff45ac9a5..374e056117 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/constant/UserMessageConstant.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/constant/UserMessageConstant.java @@ -99,4 +99,13 @@ public interface UserMessageConstant { * 原组长下台 * */ String ORIGINAL_LEADER_DOWN="您已失去【%s】的组长身份,请查看。"; + + /** + * 小组通知发布 + * */ + String GROUP_NOTICE_ADD = "【%s】发布了%s通知,请查看。"; + /** + * 小组通知变更 + * */ + String GROUP_NOTICE_EDIT = "【%s】变更了%s通知,请查看。"; } diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/dao/ResiGroupMemberDao.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/dao/ResiGroupMemberDao.java index db3b286b5f..6c6618cc9a 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/dao/ResiGroupMemberDao.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/dao/ResiGroupMemberDao.java @@ -145,6 +145,12 @@ public interface ResiGroupMemberDao extends BaseDao { **/ List queryMemberRemovedRecs(@Param("groupId")String groupId, @Param("userId")String userId); + /** + * @Description 查询组内有效人员列表 + * @author sun + */ + List getMemberList(@Param("groupId") String groupId); + /** * @return java.lang.Integer * @param groupId 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 b2a8478edd..6b1c5cb5b6 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 @@ -17,7 +17,9 @@ package com.epmet.modules.notice.controller; +import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.AssertUtils; @@ -28,6 +30,7 @@ import com.epmet.commons.tools.validator.group.UpdateGroup; 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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -91,4 +94,17 @@ public class NoticeController { ExcelUtils.exportExcelToTarget(response, null, list, NoticeExcel.class); } + /** + * @param formDTO + * @return + * @Author sun + * @Description 小组通知保存 + **/ + @PostMapping(value = "add") + public Result add(@LoginUser TokenDto tokenDto, @RequestBody AddNoticeFormDTO formDTO){ + ValidatorUtils.validateEntity(formDTO, AddNoticeFormDTO.Add.class); + noticeService.add(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/service/NoticeService.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeService.java index 4ae16bbce4..fb153f03c4 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 @@ -19,8 +19,10 @@ package com.epmet.modules.notice.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; +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 java.util.List; import java.util.Map; @@ -92,4 +94,12 @@ public interface NoticeService extends BaseService { * @date 2021-04-19 */ void delete(String[] ids); + + /** + * @param formDTO + * @return + * @Author sun + * @Description 小组通知保存 + **/ + void add(TokenDto tokenDto, AddNoticeFormDTO 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 0478a8cca6..6080c245ea 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 @@ -17,25 +17,55 @@ package com.epmet.modules.notice.service.impl; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.scan.param.ImgScanParamDTO; +import com.epmet.commons.tools.scan.param.ImgTaskDTO; +import com.epmet.commons.tools.scan.param.TextScanParamDTO; +import com.epmet.commons.tools.scan.param.TextTaskDTO; +import com.epmet.commons.tools.scan.result.SyncScanResult; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.utils.ScanContentUtils; +import com.epmet.constant.ReadFlagConstant; +import com.epmet.dto.form.LoginUserDetailsFormDTO; +import com.epmet.dto.form.UserMessageFormDTO; +import com.epmet.dto.result.LoginUserDetailsResultDTO; +import com.epmet.feign.EpmetMessageOpenFeignClient; +import com.epmet.feign.EpmetUserOpenFeignClient; +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.NoticeDao; import com.epmet.modules.notice.entity.NoticeEntity; import com.epmet.modules.notice.redis.NoticeRedis; 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.FileDTO; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; /** * 小组通知表 @@ -45,9 +75,24 @@ import java.util.Map; */ @Service public class NoticeServiceImpl extends BaseServiceImpl implements NoticeService { - + private final Log logger = LogFactory.getLog(getClass()); @Autowired private NoticeRedis noticeRedis; + @Value("${openapi.scan.server.url}") + private String scanApiUrl; + @Value("${openapi.scan.method.textSyncScan}") + private String textSyncScanMethod; + @Value("${openapi.scan.method.imgSyncScan}") + private String imgSyncScanMethod; + @Autowired + private ResiGroupMemberDao resiGroupMemberDao; + @Autowired + private ResiGroupDao resiGroupDao; + @Autowired + private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + @Autowired + private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; + @Override public PageData page(Map params) { @@ -101,4 +146,131 @@ public class NoticeServiceImpl extends BaseServiceImpl baseDao.deleteBatchIds(Arrays.asList(ids)); } + /** + * @param formDTO + * @return + * @Author sun + * @Description 小组通知保存 + **/ + @Override + @Transactional(rollbackFor = Exception.class) + public void add(TokenDto tokenDto, AddNoticeFormDTO formDTO) { + //1.查询组内成员数据 + List memberList = resiGroupMemberDao.getMemberList(formDTO.getGroupId()); + 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())){ + bl.set(false); + } + }); + if(bl.get()){ + throw new RenException(String.format("保存小组通知,当前操作人员不是群组长,小组Id->", formDTO.getGroupId())); + } + + //3.文字、图片安全校验 + 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); + + //4.保存小组通知基础数据 + //4-1.获取小组信息 + ResiGroupEntity groupEntity = resiGroupDao.selectById(formDTO.getGroupId()); + if(null == groupEntity){ + throw new RenException(String.format("保存小组通知,获取小组数据失败,小组Id->", tokenDto.getUserId())); + } + //4-2.获取token用户所属组织信息 + LoginUserDetailsFormDTO dto = new LoginUserDetailsFormDTO(); + dto.setApp(tokenDto.getApp()); + dto.setClient(tokenDto.getClient()); + dto.setUserId(tokenDto.getUserId()); + Result result = epmetUserOpenFeignClient.getLoginUserDetails(dto); + if (!result.success() || org.springframework.util.StringUtils.isEmpty(result.getData().getAgencyId())) { + throw new RenException(String.format("调用user服务查询用户数据失败,userId->", tokenDto.getUserId())); + } + LoginUserDetailsResultDTO resultDTO = result.getData(); + + //4-3.保存通知数据 + NoticeEntity entity = new NoticeEntity(); + entity.setCustomerId(resultDTO.getCustomerId()); + entity.setAgencyId(resultDTO.getAgencyId()); + entity.setGridId(groupEntity.getGridId()); + entity.setGroupId(formDTO.getGroupId()); + entity.setTitle(formDTO.getTitle()); + entity.setContent(formDTO.getContent()); + entity.setIsChange("no"); + entity.setChangeTime(new Date()); + insert(entity); + + //5.组内成员推送站内信 + List userMessageFormDTOS = new ArrayList<>(); + memberList.forEach(m->{ + if(!"".equals(m.getGroupLeaderFlag())){ + UserMessageFormDTO userMessageFormDTO = new UserMessageFormDTO(); + userMessageFormDTO.setCustomerId(resultDTO.getCustomerId()); + userMessageFormDTO.setUserId(m.getCustomerUserId()); + userMessageFormDTO.setGridId(groupEntity.getGridId()); + userMessageFormDTO.setApp(AppClientConstant.APP_RESI); + userMessageFormDTO.setTitle(UserMessageConstant.GROUP_TITLE); + userMessageFormDTO.setReadFlag(ReadFlagConstant.UN_READ); + userMessageFormDTO.setMessageContent(String.format(UserMessageConstant.GROUP_NOTICE_ADD, 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->{ + //创建话题内容审核 + TextScanParamDTO textScanParamDTO = new TextScanParamDTO(); + TextTaskDTO taskDTO = new TextTaskDTO(); + taskDTO.setContent(word); + taskDTO.setDataId(UUID.randomUUID().toString().replace("-", "")); + textScanParamDTO.getTasks().add(taskDTO); + Result textSyncScanResult = ScanContentUtils.textSyncScan(scanApiUrl.concat(textSyncScanMethod), textScanParamDTO); + if (!textSyncScanResult.success()) { + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } else { + if (!textSyncScanResult.getData().isAllPass()) { + logger.error(String.format(TopicConstant.CREATE_TOPIC, word)); + throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode()); + } + } + }); + } + //创建话题图片审核 + if (imageList.size() != NumConstant.ZERO){ + ImgScanParamDTO imgScanParamDTO = new ImgScanParamDTO(); + imageList.forEach(url -> { + ImgTaskDTO task = new ImgTaskDTO(); + task.setDataId(UUID.randomUUID().toString().replace("-", "")); + task.setUrl(url); + imgScanParamDTO.getTasks().add(task); + }); + Result imgScanResult = ScanContentUtils.imgSyncScan(scanApiUrl.concat(imgSyncScanMethod), imgScanParamDTO); + if (!imgScanResult.success()){ + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } else { + if (!imgScanResult.getData().isAllPass()) { + throw new RenException(EpmetErrorCode.IMG_SCAN_FAILED.getCode()); + } + } + } + } + } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/member/ResiGroupMemberDao.xml b/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/member/ResiGroupMemberDao.xml index 867b18eb4c..ac0217c6fe 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/member/ResiGroupMemberDao.xml +++ b/epmet-module/resi-group/resi-group-server/src/main/resources/mapper/member/ResiGroupMemberDao.xml @@ -192,6 +192,19 @@ rgm.CREATED_TIME DESC + +