Browse Source

发布通知评论

master
sunyuchao 4 years ago
parent
commit
11bf503e0f
  1. 28
      epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/notice/form/NoticeCommentFormDTO.java
  2. 16
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/controller/NoticeCommentController.java
  3. 10
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/NoticeCommentService.java
  4. 101
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/notice/service/impl/NoticeCommentServiceImpl.java

28
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{}
}

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

10
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<NoticeCommentEntity> {
* @date 2021-04-19
*/
void delete(String[] ids);
/**
* @param formDTO
* @return
* @Author sun
* @Description 发布通知评论
**/
void noticeComment(TokenDto tokenDto, NoticeCommentFormDTO formDTO);
}

101
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<NoticeCommentDao, NoticeCommentEntity> 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<NoticeCommentDTO> page(Map<String, Object> params) {
@ -65,8 +97,8 @@ public class NoticeCommentServiceImpl extends BaseServiceImpl<NoticeCommentDao,
return ConvertUtils.sourceToTarget(entityList, NoticeCommentDTO.class);
}
private QueryWrapper<NoticeCommentEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get(FieldConstant.ID_HUMP);
private QueryWrapper<NoticeCommentEntity> getWrapper(Map<String, Object> params) {
String id = (String) params.get(FieldConstant.ID_HUMP);
QueryWrapper<NoticeCommentEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id);
@ -101,4 +133,67 @@ public class NoticeCommentServiceImpl extends BaseServiceImpl<NoticeCommentDao,
baseDao.deleteBatchIds(Arrays.asList(ids));
}
/**
* @param formDTO
* @return
* @Author sun
* @Description 发布通知评论
**/
@Override
@Transactional(rollbackFor = Exception.class)
public void noticeComment(TokenDto tokenDto, NoticeCommentFormDTO formDTO) {
//1.内容安全校验
String commentContent = formDTO.getCommentContent();
if (StringUtils.isNotBlank(commentContent)) {
//评论话题内容审核
TextScanParamDTO textScanParamDTO = new TextScanParamDTO();
TextTaskDTO taskDTO = new TextTaskDTO();
taskDTO.setContent(commentContent);
taskDTO.setDataId(UUID.randomUUID().toString().replace("-", ""));
textScanParamDTO.getTasks().add(taskDTO);
Result<SyncScanResult> 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);
}
}
Loading…
Cancel
Save