From 11bf503e0fa891ee023e68cc439e1662247bf75e Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Tue, 20 Apr 2021 10:01:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E9=80=9A=E7=9F=A5=E8=AF=84?= =?UTF-8?q?=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/notice/form/NoticeCommentFormDTO.java | 28 +++++ .../controller/NoticeCommentController.java | 16 +++ .../notice/service/NoticeCommentService.java | 10 ++ .../impl/NoticeCommentServiceImpl.java | 101 +++++++++++++++++- 4 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/notice/form/NoticeCommentFormDTO.java diff --git a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/notice/form/NoticeCommentFormDTO.java b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/notice/form/NoticeCommentFormDTO.java new file mode 100644 index 0000000000..b2f91f22f9 --- /dev/null +++ b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/notice/form/NoticeCommentFormDTO.java @@ -0,0 +1,28 @@ +package com.epmet.resi.group.dto.notice.form; + +import lombok.Data; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotBlank; + +/** + * @Author sun + * @Description 小组通知编辑-接口入参 + */ +@Data +public class NoticeCommentFormDTO { + + /** + * 通知Id + */ + @NotBlank(message = "通知Id不能为空",groups = {NoticeCommentFormDTO.Comment.class}) + private String noticeId; + /** + * 评论内容300 + */ + @NotBlank(message = "评论内容不能为空",groups = {NoticeCommentFormDTO.Comment.class}) + @Length(max = 20, message = "评论内容不能超过300个字符") + private String commentContent; + + public interface Comment{} +} diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeCommentController.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeCommentController.java index a7114f3834..4d85bbe530 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeCommentController.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeCommentController.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.NoticeCommentExcel; import com.epmet.modules.notice.service.NoticeCommentService; import com.epmet.resi.group.dto.notice.NoticeCommentDTO; +import com.epmet.resi.group.dto.notice.form.NoticeCommentFormDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -91,4 +94,17 @@ public class NoticeCommentController { ExcelUtils.exportExcelToTarget(response, null, list, NoticeCommentExcel.class); } + /** + * @param formDTO + * @return + * @Author sun + * @Description 发布通知评论 + **/ + @PostMapping(value = "noticecomment") + public Result noticeComment(@LoginUser TokenDto tokenDto, @RequestBody NoticeCommentFormDTO formDTO){ + ValidatorUtils.validateEntity(formDTO, NoticeCommentFormDTO.Comment.class); + noticeCommentService.noticeComment(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/NoticeCommentService.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeCommentService.java index 0204df5cc9..c0cadd139f 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeCommentService.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeCommentService.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.NoticeCommentEntity; import com.epmet.resi.group.dto.notice.NoticeCommentDTO; +import com.epmet.resi.group.dto.notice.form.NoticeCommentFormDTO; import java.util.List; import java.util.Map; @@ -92,4 +94,12 @@ public interface NoticeCommentService extends BaseService { * @date 2021-04-19 */ void delete(String[] ids); + + /** + * @param formDTO + * @return + * @Author sun + * @Description 发布通知评论 + **/ + void noticeComment(TokenDto tokenDto, NoticeCommentFormDTO 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/NoticeCommentServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/impl/NoticeCommentServiceImpl.java index 81ed00809a..c4847f0581 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/impl/NoticeCommentServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/impl/NoticeCommentServiceImpl.java @@ -21,21 +21,44 @@ 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.FieldConstant; +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.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.modules.member.service.ResiGroupMemberService; import com.epmet.modules.notice.dao.NoticeCommentDao; import com.epmet.modules.notice.entity.NoticeCommentEntity; +import com.epmet.modules.notice.entity.NoticeEntity; import com.epmet.modules.notice.redis.NoticeCommentRedis; import com.epmet.modules.notice.service.NoticeCommentService; +import com.epmet.modules.notice.service.NoticeService; +import com.epmet.modules.topic.service.ResiTopicService; +import com.epmet.modules.utils.ModuleConstant; +import com.epmet.resi.group.constant.MemberStateConstant; +import com.epmet.resi.group.constant.TopicConstant; +import com.epmet.resi.group.dto.member.ResiGroupMemberDTO; import com.epmet.resi.group.dto.notice.NoticeCommentDTO; +import com.epmet.resi.group.dto.notice.NoticeDTO; +import com.epmet.resi.group.dto.notice.form.NoticeCommentFormDTO; +import com.epmet.resi.group.dto.topic.ResiTopicDTO; 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.UUID; /** * 小组通知评论表 @@ -45,9 +68,18 @@ import java.util.Map; */ @Service public class NoticeCommentServiceImpl extends BaseServiceImpl implements NoticeCommentService { - + private final Log logger = LogFactory.getLog(getClass()); @Autowired private NoticeCommentRedis noticeCommentRedis; + @Autowired + private NoticeService noticeService; + @Autowired + private ResiGroupMemberService resiGroupMemberService; + @Value("${openapi.scan.server.url}") + private String scanApiUrl; + @Value("${openapi.scan.method.textSyncScan}") + private String textSyncScanMethod; + @Override public PageData page(Map params) { @@ -65,8 +97,8 @@ public class NoticeCommentServiceImpl extends BaseServiceImpl 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); @@ -101,4 +133,67 @@ public class NoticeCommentServiceImpl extends BaseServiceImpl 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.REVIEW_TOPIC, commentContent)); + throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode()); + } + } + } + + //2.判断当前用户是否被禁言、移除、非本组成员 + NoticeDTO notice = noticeService.get(formDTO.getNoticeId()); + if (null == notice) { + logger.error(ModuleConstant.NO_SUCH_TOPIC); + throw new RenException(ModuleConstant.NO_SUCH_TOPIC); + } + + ResiGroupMemberDTO resiGroupMemberDTO = + resiGroupMemberService.getResiGroupMember(notice.getGroupId(), tokenDto.getUserId()); + //查看当前用户是否被禁言或者被移除 + if (null != resiGroupMemberDTO) { + if (MemberStateConstant.SILENT.equals(resiGroupMemberDTO.getStatus())) { + //当前用户被禁言 + logger.error(ModuleConstant.SLIENT_MEMBER); + throw new RenException(ModuleConstant.SLIENT_MEMBER); + } else if (MemberStateConstant.REMOVED.equals(resiGroupMemberDTO.getStatus())) { + //当前用户已被移出群 + logger.error(ModuleConstant.REMOVED_MEMBER); + throw new RenException(ModuleConstant.REMOVED_MEMBER); + } + } else { + //当前用户非组内成员 + logger.error(ModuleConstant.NOT_BELONG_TO_CURRENT_GROUP); + throw new RenException(ModuleConstant.NOT_BELONG_TO_CURRENT_GROUP); + } + + //3.通知评论表新增数据 + NoticeCommentEntity entity = new NoticeCommentEntity(); + entity.setCustomerId(notice.getCustomerId()); + entity.setNoticeId(formDTO.getNoticeId()); + entity.setCommentContent(formDTO.getCommentContent()); + insert(entity); + } + } \ No newline at end of file