diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 27936afa85..49514ffd1b 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -169,8 +169,9 @@ public enum EpmetErrorCode { PARTY_MEMBER_CREATE_BRANCH_GROUP(8906,"您不是党员,不能创建支部小组"), NOT_IN_GROUP_CAN_NOT_VIEW(8907,"当前内容仅允许组内成员查看"), PARTY_MEMBER_JOIN_BRANCH_GROUP(8908,"您不是党员,不能加入支部小组"), - CAN_NOT_CANCEL(8909,"活动%s,不能取消"); - + GROUP_ACT_CAN_NOT_CANCEL(8909,"活动%s,不能取消"), + //8910的msg动态赋值 + GROUP_ACT_CAN_NOT_COMMENT(8910,"当前活动,不能评论"); private int code; private String msg; diff --git a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/act/form/CommentFormDTO.java b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/act/form/CommentFormDTO.java new file mode 100644 index 0000000000..92fce732ae --- /dev/null +++ b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/act/form/CommentFormDTO.java @@ -0,0 +1,39 @@ +package com.epmet.resi.group.dto.act.form; + +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; +import lombok.Data; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 005、评论活动 + * + * @author yinzuomei@elink-cn.com + * @date 2021/4/20 12:35 + */ +@Data +public class CommentFormDTO implements Serializable { + public interface AddUserInternalGroup { + } + + public interface AddUserShowGroup extends CustomerClientShowGroup { + } + + @NotBlank(message = "groupActId不能为空", groups = AddUserInternalGroup.class) + private String groupActId; + + @NotBlank(message = "评论内容不能为空", groups = AddUserShowGroup.class) + @Length(max = 500, message = "评论内容最多输入500字", groups = AddUserShowGroup.class) + private String commentContent; + + /** + * 当前用户id + */ + @NotBlank(message = "tokenDto获取userId为空", groups = AddUserInternalGroup.class) + private String userId; + + @NotBlank(message = "tokenDto获取customerId为空", groups = AddUserInternalGroup.class) + private String customerId; +} diff --git a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/act/form/CommentQueryFormDTO.java b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/act/form/CommentQueryFormDTO.java new file mode 100644 index 0000000000..109d6f387a --- /dev/null +++ b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/act/form/CommentQueryFormDTO.java @@ -0,0 +1,25 @@ +package com.epmet.resi.group.dto.act.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 006、活动评论列表查询 + * + * @author yinzuomei@elink-cn.com + * @date 2021/4/20 12:55 + */ +@Data +public class CommentQueryFormDTO implements Serializable { + private static final long serialVersionUID = 4013876445914100561L; + + public interface AddUserInternalGroup { + } + + @NotBlank(message = "groupActId不能为空", groups = AddUserInternalGroup.class) + private String groupActId; + private Integer pageNo; + private Integer pageSize; +} diff --git a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/act/result/CommentResultDTO.java b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/act/result/CommentResultDTO.java new file mode 100644 index 0000000000..efb8066f28 --- /dev/null +++ b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/act/result/CommentResultDTO.java @@ -0,0 +1,30 @@ +package com.epmet.resi.group.dto.act.result; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 006、活动评论列表查询 + * + * @author yinzuomei@elink-cn.com + * @date 2021/4/20 12:58 + */ +@Data +public class CommentResultDTO implements Serializable { + private static final long serialVersionUID = 6487668038520643604L; + private String commentId; + + private String commentContent; + + private String commentUserHeadPhoto; + + private String commentUserName; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8") + private Date commentTime; + + private String commentUserId; +} diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/controller/ActCommentController.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/controller/ActCommentController.java index 331cf578ce..eff2910608 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/controller/ActCommentController.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/controller/ActCommentController.java @@ -17,11 +17,23 @@ package com.epmet.modules.act.controller; +import com.baomidou.mybatisplus.extension.api.R; +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.modules.act.service.ActCommentService; +import com.epmet.resi.group.dto.act.form.CommentFormDTO; +import com.epmet.resi.group.dto.act.form.CommentQueryFormDTO; +import com.epmet.resi.group.dto.act.result.CommentResultDTO; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** * 活动评论表 @@ -36,5 +48,33 @@ public class ActCommentController { @Autowired private ActCommentService actCommentService; + /** + * @param tokenDto + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @author yinzuomei + * @description 005、评论活动 + * @Date 2021/4/20 12:38 + **/ + @PostMapping("submit") + public Result submitComment(@LoginUser TokenDto tokenDto, @RequestBody CommentFormDTO formDTO) { + formDTO.setUserId(tokenDto.getUserId()); + formDTO.setCommentContent(tokenDto.getCustomerId()); + ValidatorUtils.validateEntity(formDTO,CommentFormDTO.AddUserShowGroup.class,CommentFormDTO.AddUserInternalGroup.class); + actCommentService.submitComment(formDTO); + return new Result(); + } + /** + * @return com.epmet.commons.tools.utils.Result> + * @param formDTO + * @author yinzuomei + * @description 006、活动评论列表查询 + * @Date 2021/4/20 13:01 + **/ + @PostMapping("comlist") + public Result> queryCommentList(@RequestBody CommentQueryFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, CommentQueryFormDTO.AddUserInternalGroup.class); + return new Result>().ok(actCommentService.queryCommentList(formDTO)); + } } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/dao/ActCommentDao.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/dao/ActCommentDao.java index 93a72a4913..b70207027a 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/dao/ActCommentDao.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/dao/ActCommentDao.java @@ -19,8 +19,11 @@ package com.epmet.modules.act.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.modules.act.entity.ActCommentEntity; +import com.epmet.resi.group.dto.act.result.CommentResultDTO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 活动评论表 * @@ -29,5 +32,6 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface ActCommentDao extends BaseDao { - + + List selectCommentList(String groupActId); } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/ActCommentService.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/ActCommentService.java index e8da2bae21..57e3abf651 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/ActCommentService.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/ActCommentService.java @@ -19,6 +19,11 @@ package com.epmet.modules.act.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.modules.act.entity.ActCommentEntity; +import com.epmet.resi.group.dto.act.form.CommentFormDTO; +import com.epmet.resi.group.dto.act.form.CommentQueryFormDTO; +import com.epmet.resi.group.dto.act.result.CommentResultDTO; + +import java.util.List; /** * 活动评论表 @@ -28,4 +33,19 @@ import com.epmet.modules.act.entity.ActCommentEntity; */ public interface ActCommentService extends BaseService { + /** + * 005、评论活动 + * + * @param formDTO + * @return + */ + void submitComment(CommentFormDTO formDTO); + + /** + * 006、活动评论列表查询 + * + * @param formDTO + * @return com.epmet.resi.group.dto.act.result.CommentResultDTO + */ + List queryCommentList(CommentQueryFormDTO formDTO); } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/GroupActInfoService.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/GroupActInfoService.java index a6ea5dd94d..9c066628bf 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/GroupActInfoService.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/GroupActInfoService.java @@ -20,6 +20,7 @@ package com.epmet.modules.act.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.modules.act.entity.GroupActInfoEntity; import com.epmet.resi.group.dto.act.GroupActIdDTO; +import com.epmet.resi.group.dto.act.GroupActInfoDTO; import com.epmet.resi.group.dto.act.form.ActDetailFormDTO; import com.epmet.resi.group.dto.act.form.ActReadViewFormDTO; import com.epmet.resi.group.dto.act.form.CancelActFormDTO; @@ -66,4 +67,12 @@ public interface GroupActInfoService extends BaseService { * @return com.epmet.resi.group.dto.act.GroupActIdDTO */ GroupActIdDTO cancelAct(CancelActFormDTO formDTO); + + /** + * 查询活动主信息 + * + * @param groupActId + * @return com.epmet.resi.group.dto.act.GroupActInfoDTO + */ + GroupActInfoDTO getGroupActInfoDTO(String groupActId); } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/impl/ActCommentServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/impl/ActCommentServiceImpl.java index 6f4ea05296..c249c4ec28 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/impl/ActCommentServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/impl/ActCommentServiceImpl.java @@ -18,10 +18,34 @@ package com.epmet.modules.act.service.impl; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +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.utils.Result; +import com.epmet.commons.tools.utils.ScanContentUtils; +import com.epmet.dto.result.UserBaseInfoResultDTO; +import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.modules.act.dao.ActCommentDao; import com.epmet.modules.act.entity.ActCommentEntity; import com.epmet.modules.act.service.ActCommentService; +import com.epmet.modules.act.service.GroupActInfoService; +import com.epmet.modules.constant.GroupActConstant; +import com.epmet.resi.group.dto.act.GroupActInfoDTO; +import com.epmet.resi.group.dto.act.form.CommentFormDTO; +import com.epmet.resi.group.dto.act.form.CommentQueryFormDTO; +import com.epmet.resi.group.dto.act.result.CommentResultDTO; +import com.github.pagehelper.PageHelper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; /** * 活动评论表 @@ -32,5 +56,88 @@ import org.springframework.stereotype.Service; @Service public class ActCommentServiceImpl extends BaseServiceImpl implements ActCommentService { + @Value("${openapi.scan.server.url}") + private String scanApiUrl; + @Value("${openapi.scan.method.textSyncScan}") + private String textSyncScanMethod; + + @Autowired + private GroupActInfoService groupActInfoService; + @Autowired + private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + + + /** + * 005、评论活动 + * + * @param formDTO + * @return + */ + @Override + public void submitComment(CommentFormDTO formDTO) { + //1、关闭和已取消不能评论 + GroupActInfoDTO groupActInfoDTO = groupActInfoService.getGroupActInfoDTO(formDTO.getGroupActId()); + if (GroupActConstant.CLOSED.equals(groupActInfoDTO.getStatus())) { + throw new RenException(EpmetErrorCode.GROUP_ACT_CAN_NOT_COMMENT.getCode(), "当前活动已关闭,不能评论"); + } else if (GroupActConstant.CANCELED.equals(groupActInfoDTO.getStatus())) { + throw new RenException(EpmetErrorCode.GROUP_ACT_CAN_NOT_COMMENT.getCode(), "当前活动已取消,不能评论"); + } + //2、评论内容审核 + TextScanParamDTO textScanParamDTO = new TextScanParamDTO(); + TextTaskDTO taskDTO = new TextTaskDTO(); + taskDTO.setContent(formDTO.getCommentContent()); + 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()) { + throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode(), EpmetErrorCode.TEXT_SCAN_FAILED.getMsg()); + } + } + //3、插入记录 + ActCommentEntity actCommentEntity = new ActCommentEntity(); + actCommentEntity.setCustomerId(formDTO.getCustomerId()); + actCommentEntity.setCommentContent(formDTO.getCommentContent()); + actCommentEntity.setCommentUserId(formDTO.getUserId()); + actCommentEntity.setGroupActId(formDTO.getGroupActId()); + baseDao.insert(actCommentEntity); + } + + /** + * 006、活动评论列表查询 + * + * @param formDTO + * @return com.epmet.resi.group.dto.act.result.CommentResultDTO + */ + @Override + public List queryCommentList(CommentQueryFormDTO formDTO) { + PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize()); + List list=baseDao.selectCommentList(formDTO.getGroupActId()); + if(CollectionUtils.isEmpty(list)){ + return Collections.EMPTY_LIST; + } + //2.调用user服务,查询人员基础数据 + List userIdList = list.stream().map(CommentResultDTO::getCommentUserId).collect(Collectors.toList()); + Result> result = epmetUserOpenFeignClient.queryUserBaseInfo(userIdList); + if (!result.success()) { + throw new RenException("调用user服务,获取用户基础数据失败"); + } + if (!CollectionUtils.isEmpty(result.getData())) { + //3.遍历封装数据并返回 + list.forEach(l -> { + result.getData().forEach(user -> { + if (l.getCommentUserId().equals(user.getUserId())) { + l.setCommentUserHeadPhoto(user.getHeadImgUrl()); + l.setCommentUserName(user.getSurname().concat(user.getName())); + } + }); + }); + + } + return list; + } + } \ No newline at end of file diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/impl/GroupActInfoServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/impl/GroupActInfoServiceImpl.java index 62e3816594..e37d8adae6 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/impl/GroupActInfoServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/act/service/impl/GroupActInfoServiceImpl.java @@ -52,6 +52,7 @@ import com.epmet.modules.constant.GroupActConstant; import com.epmet.modules.group.service.ResiGroupService; import com.epmet.modules.member.service.ResiGroupMemberService; import com.epmet.resi.group.dto.act.GroupActIdDTO; +import com.epmet.resi.group.dto.act.GroupActInfoDTO; import com.epmet.resi.group.dto.act.form.ActDetailFormDTO; import com.epmet.resi.group.dto.act.form.ActReadViewFormDTO; import com.epmet.resi.group.dto.act.form.CancelActFormDTO; @@ -268,7 +269,6 @@ public class GroupActInfoServiceImpl extends BaseServiceImpl textList, List imgList) { //活动标题 if (StringUtils.isNotBlank(title)) { - //创建话题内容审核 TextScanParamDTO textScanParamDTO = new TextScanParamDTO(); TextTaskDTO taskDTO = new TextTaskDTO(); taskDTO.setContent(title); @@ -547,17 +547,31 @@ public class GroupActInfoServiceImpl extends BaseServiceImpl textSyncScanResult = ScanContentUtils.textSyncScan(scanApiUrl.concat(textSyncScanMethod), textScanParamDTO); + if (!textSyncScanResult.success()) { + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } else { + if (!textSyncScanResult.getData().isAllPass()) { + throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode(), EpmetErrorCode.TEXT_SCAN_FAILED.getMsg()); + } + } + //4、记录取消时间 Date nowDate=new Date(); actInfoEntity.setCanceledTime(nowDate); actInfoEntity.setStatus(GroupActConstant.CANCELED); baseDao.updateById(actInfoEntity); - //4、插入一条操作日志 + //5、插入一条操作日志 ActOperationRecordEntity actOperationRecordEntity = new ActOperationRecordEntity(); actOperationRecordEntity.setCustomerId(actInfoEntity.getCustomerId()); actOperationRecordEntity.setOperateUserId(formDTO.getUserId()); @@ -572,4 +586,15 @@ public class GroupActInfoServiceImpl extends BaseServiceImpl - + \ No newline at end of file