diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/communityCenter/PersonHomeController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/communityCenter/PersonHomeController.java new file mode 100644 index 0000000..f2e9fe0 --- /dev/null +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/communityCenter/PersonHomeController.java @@ -0,0 +1,31 @@ +package com.mcwl.web.controller.communityCenter; + +import com.mcwl.common.core.domain.R; +import io.swagger.annotations.Api; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 个人主页 + */ +@Api(tags = "个人主页") +@RestController +@RequiredArgsConstructor +@RequestMapping("personHome") +public class PersonHomeController { + + /** + * 发布的文章列表 + */ + @RequestMapping("list") + public R list(){ + + return R.ok(); + } + + + + + +} diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/communityCenter/PublishCommentLikeController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/communityCenter/PublishCommentLikeController.java deleted file mode 100644 index e72a3d9..0000000 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/communityCenter/PublishCommentLikeController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.mcwl.web.controller.communityCenter; - -import com.mcwl.common.core.controller.BaseController; -import com.mcwl.communityCenter.service.PublishCommentLikeService; -import io.swagger.annotations.Api; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/**社群评论区点赞 - * @Author:ChenYan - * @Project:mcwl-ai - * @Package:com.mcwl.web.controller.communityCenter - * @Filename:PublishCommissionLikeController - * @Description TODO - * @Date:2025/1/17 14:21 - */ -@Api(tags = "社群评论区点赞") -@RestController -@RequestMapping("PublishCommissionLike") -public class PublishCommentLikeController extends BaseController { - - @Autowired - private PublishCommentLikeService publishCommentLikeService; - - - -} diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/communityCenter/PublishLikeController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/communityCenter/PublishLikeController.java new file mode 100644 index 0000000..c605cf3 --- /dev/null +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/communityCenter/PublishLikeController.java @@ -0,0 +1,42 @@ +package com.mcwl.web.controller.communityCenter; + +import com.mcwl.common.core.controller.BaseController; +import com.mcwl.common.core.domain.R; +import com.mcwl.communityCenter.domain.dto.PublishCommentLikeRes; +import com.mcwl.communityCenter.domain.dto.PublishLikeRes; +import com.mcwl.communityCenter.service.PublishCommentLikeService; +import com.mcwl.communityCenter.service.PublishLikeService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +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 javax.validation.Valid; + +/** + * 社群发布点赞 + */ +@Api(tags = "社群发布点赞") +@RestController +@RequiredArgsConstructor +@RequestMapping("PublishLike") +public class PublishLikeController extends BaseController { + + + private final PublishLikeService publishLikeService; + + /** + * 点赞/取消点赞 + */ + @PostMapping("/like") + @ApiOperation(value = "点赞/取消点赞") + public R like(@RequestBody @Valid PublishLikeRes publishLikeRes) { + publishLikeService.like(publishLikeRes); + return R.ok(); + } + + +} diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/memberCenter/BenefitController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/memberCenter/BenefitController.java index 5ce3d0d..bd4725e 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/memberCenter/BenefitController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/memberCenter/BenefitController.java @@ -6,6 +6,7 @@ import com.mcwl.memberCenter.domain.Benefit; import com.mcwl.memberCenter.domain.dto.AddBenefitDto; import com.mcwl.memberCenter.domain.dto.EditBenefitDto; import com.mcwl.memberCenter.domain.vo.BenefitVo; +import com.mcwl.memberCenter.enums.MemberBenefitTypeEnum; import com.mcwl.memberCenter.service.BenefitService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -52,6 +53,19 @@ public class BenefitController { return R.ok(); } + /** + * 根据权益名称id查询权益 + */ + @ApiOperation(value = "根据权益名称id查询权益") + @GetMapping("getBenefitByBenefitId") + public R> getBenefitByBenefitId(@NotNull(message = "权益名称id不能为空") Long benefitNameId) { + List benefitList = benefitService.lambdaQuery() + .eq(Benefit::getBenefitNameId, benefitNameId) + .list(); + return R.ok(benefitList); + } + + /** * 修改权益 */ diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/mqtt/MqttController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/mqtt/MqttController.java deleted file mode 100644 index 6ba7662..0000000 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/mqtt/MqttController.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.mcwl.web.controller.mqtt; - -import com.mcwl.common.core.domain.R; -import com.mcwl.myInvitation.domain.vo.CommissionRatioVo; -import com.mcwl.resource.util.MqttTemplate; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -@RestController() -@RequiredArgsConstructor -@RequestMapping("/mqtt") -public class MqttController { - - private final MqttTemplate mqttTemplate; - - @GetMapping("/send") - public void list(String topic, String msg) { - mqttTemplate.publish(topic, msg); - } - -} diff --git a/mcwl-admin/src/main/resources/application-dev.yml b/mcwl-admin/src/main/resources/application-dev.yml index 31e7982..aa7cdd3 100644 --- a/mcwl-admin/src/main/resources/application-dev.yml +++ b/mcwl-admin/src/main/resources/application-dev.yml @@ -174,13 +174,6 @@ huawei: upload: endPoint: obs.cn-south-1.myhuaweicloud.com -mqtt: - broker-url: tcp://113.45.190.154:1883 - client-id-prefix: emqx-client - connection-timeout: 30 - keep-alive-interval: 60 - max-reconnect-attempts: 5 - clean-session: true #用户头像与背景 mcwl: diff --git a/mcwl-admin/src/main/resources/application-druid.yml b/mcwl-admin/src/main/resources/application-druid.yml index 0b3eb3f..430f5d8 100644 --- a/mcwl-admin/src/main/resources/application-druid.yml +++ b/mcwl-admin/src/main/resources/application-druid.yml @@ -161,11 +161,3 @@ huawei: upload: endPoint: obs.cn-south-1.myhuaweicloud.com -mqtt: - broker-url: tcp://192.168.136.128:1883 - client-id-prefix: emqx-client - connection-timeout: 30 - keep-alive-interval: 60 - max-reconnect-attempts: 5 - clean-session: true - diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/constant/AdviceConstant.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/constant/AdviceConstant.java new file mode 100644 index 0000000..d771be7 --- /dev/null +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/constant/AdviceConstant.java @@ -0,0 +1,29 @@ +package com.mcwl.communityCenter.constant; + +/** + * 状态常量 + */ +public class AdviceConstant { + /** + * 社区通知 + */ + public static final int COMMUNITY_NOTICE = 0; + + /** + * 回复我的 + */ + public static final int REPLY_ME = 1; + + /** + * 等我回答 + */ + public static final int WAIT_ME_ANSWER = 2; + + /** + * 点赞 + */ + public static final int LIKE = 3; + + + +} diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/CommunityAdvice.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/CommunityAdvice.java index 3070594..c3f1e87 100644 --- a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/CommunityAdvice.java +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/CommunityAdvice.java @@ -28,6 +28,14 @@ public class CommunityAdvice extends BaseEntity { * 社区id */ private Long communityId; + /** + * 发送人 + */ + private Long sendUserId; + /** + * 通知类型 0社区通知 1回复我的 2待我回复 3点赞 + */ + private Integer adviceType; /** * 通知人 */ diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/PublishCommentLike.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/PublishCommentLike.java index 45129e0..a1f8be2 100644 --- a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/PublishCommentLike.java +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/PublishCommentLike.java @@ -29,18 +29,29 @@ public class PublishCommentLike extends BaseEntity { @ApiModelProperty(value = "评论点赞id") private Long id; /** - * 用户id + * 租户id */ - @ApiModelProperty(value = "用户id") - private Long userId; + @ApiModelProperty(value = "租户id") + private Long tenantId; /** * 社群id */ @ApiModelProperty(value = "社群id") private Long communityId; + /** + * 发布id + */ + @ApiModelProperty(value = "发布id") + private Long publishId; /** * 评论id */ @ApiModelProperty(value = "评论id") private Long publishCommentId; + + /** + * 用户id + */ + @ApiModelProperty(value = "用户id") + private Long userId; } diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/PublishLike.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/PublishLike.java new file mode 100644 index 0000000..051ec60 --- /dev/null +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/PublishLike.java @@ -0,0 +1,49 @@ +package com.mcwl.communityCenter.domain; + + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.mcwl.common.core.domain.BaseEntity; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + + +/** + * 发布点赞 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder +@TableName("cc_publish_like") +public class PublishLike extends BaseEntity { + + @TableId + private Long id; + + /** + * 用户id - 租户id + */ + @TableField(fill = FieldFill.INSERT) + private Long tenantId; + + /** + * 社区id + */ + private Long communityId; + + /** + * 发布id + */ + private Long publishId; + + /** + * 用户id + */ + private Long userId; + +} diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/PublishCommentLikeRes.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/PublishCommentLikeRes.java new file mode 100644 index 0000000..ca360f2 --- /dev/null +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/PublishCommentLikeRes.java @@ -0,0 +1,44 @@ +package com.mcwl.communityCenter.domain.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 点赞/取消点赞请求参数 + */ +@Data +@ApiModel(value = "点赞/取消点赞请求参数") +public class PublishCommentLikeRes { + + /** + * 租户id + */ + @ApiModelProperty(value = "用户id", required = true) + @NotNull(message = "用户id不能为空") + private Long tenantId; + + /** + * 社区id + */ + @ApiModelProperty(value = "社区id", required = true) + @NotNull(message = "社区id不能为空") + private Long communityId; + + /** + * 发布id + */ + @ApiModelProperty(value = "发布id", required = true) + @NotNull(message = "发布id不能为空") + private Long publishId; + + /** + * 评论id + */ + @ApiModelProperty(value = "评论id", required = true) + @NotNull(message = "评论id不能为空") + private Long commentId; +} diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/PublishLikeRes.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/PublishLikeRes.java new file mode 100644 index 0000000..5241c5d --- /dev/null +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/PublishLikeRes.java @@ -0,0 +1,36 @@ +package com.mcwl.communityCenter.domain.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 点赞/取消点赞请求参数 + */ +@Data +@ApiModel(value = "点赞/取消点赞请求参数") +public class PublishLikeRes { + + /** + * 租户id + */ + @ApiModelProperty(value = "用户id", required = true) + @NotNull(message = "用户id不能为空") + private Long tenantId; + + /** + * 社区id + */ + @ApiModelProperty(value = "社区id", required = true) + @NotNull(message = "社区id不能为空") + private Long communityId; + + /** + * 发布id + */ + @ApiModelProperty(value = "发布id", required = true) + @NotNull(message = "发布id不能为空") + private Long publishId; +} diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/QuestionRes.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/QuestionRes.java index 0f8fc16..337726a 100644 --- a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/QuestionRes.java +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/domain/dto/QuestionRes.java @@ -29,6 +29,13 @@ public class QuestionRes { @ApiModelProperty(value = "社区ID", required = true, position = 1) private Long communityId; + /** + * 提问用户 + */ + @NotNull(message = "提问用户id不能为空") + @ApiModelProperty(value = "提问用户id", required = true, position = 2) + private Long questionUserId; + /** * 提问内容 */ diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/mapper/PublishCommentLikeMapper.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/mapper/PublishCommentLikeMapper.java index 383334a..315a43f 100644 --- a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/mapper/PublishCommentLikeMapper.java +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/mapper/PublishCommentLikeMapper.java @@ -1,8 +1,13 @@ package com.mcwl.communityCenter.mapper; +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.mcwl.communityCenter.domain.PublishCommentLike; +import com.mcwl.communityCenter.domain.dto.PublishCommentLikeRes; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import javax.validation.constraints.NotNull; /** * @Author:ChenYan @@ -14,4 +19,16 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface PublishCommentLikeMapper extends BaseMapper { + + @InterceptorIgnore(tenantLine = "true") + PublishCommentLike selectByTenantIdAndCommunityIdAndCommentId(@Param("tenantId") Long tenantId, + @Param("communityId") Long communityId, + @Param("commentId") Long commentId); + + @InterceptorIgnore(tenantLine = "true") + void updateDelFlagById(@Param("publishCommentLike") PublishCommentLike publishCommentLike); + + @InterceptorIgnore(tenantLine = "true") + PublishCommentLike selectLike(@Param("publishCommentLikeRes") PublishCommentLikeRes publishCommentLikeRes, + @Param("userId") Long userId); } diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/mapper/PublishLikeMapper.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/mapper/PublishLikeMapper.java new file mode 100644 index 0000000..76a39ee --- /dev/null +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/mapper/PublishLikeMapper.java @@ -0,0 +1,24 @@ +package com.mcwl.communityCenter.mapper; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mcwl.communityCenter.domain.PublishCommentLike; +import com.mcwl.communityCenter.domain.PublishLike; +import com.mcwl.communityCenter.domain.dto.PublishCommentLikeRes; +import com.mcwl.communityCenter.domain.dto.PublishLikeRes; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * + */ +@Mapper +public interface PublishLikeMapper extends BaseMapper { + + @InterceptorIgnore(tenantLine = "true") + PublishLike selectPublishLike(@Param("publishLikeRes") PublishLikeRes publishLikeRes, + @Param("userId") Long userId); + + @InterceptorIgnore(tenantLine = "true") + void updateDelFlagById(@Param("publishLike") PublishLike publishLike); +} diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/PublishCommentLikeService.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/PublishCommentLikeService.java index a0ec156..ddb26bd 100644 --- a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/PublishCommentLikeService.java +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/PublishCommentLikeService.java @@ -2,8 +2,12 @@ package com.mcwl.communityCenter.service; import com.baomidou.mybatisplus.extension.service.IService; import com.mcwl.communityCenter.domain.PublishCommentLike; +import com.mcwl.communityCenter.domain.dto.PublishCommentLikeRes; import org.springframework.stereotype.Service; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + /** * @Author:ChenYan * @Project:mcwl-ai @@ -15,4 +19,5 @@ import org.springframework.stereotype.Service; @Service public interface PublishCommentLikeService extends IService { + void like(PublishCommentLikeRes publishCommentLikeRes); } diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/PublishLikeService.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/PublishLikeService.java new file mode 100644 index 0000000..7763e5a --- /dev/null +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/PublishLikeService.java @@ -0,0 +1,25 @@ +package com.mcwl.communityCenter.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.mcwl.communityCenter.domain.PublishCommentLike; +import com.mcwl.communityCenter.domain.PublishLike; +import com.mcwl.communityCenter.domain.dto.PublishCommentLikeRes; +import com.mcwl.communityCenter.domain.dto.PublishLikeRes; +import org.springframework.stereotype.Service; + +import javax.validation.Valid; + +/** + * @Author:ChenYan + * @Project:mcwl-ai + * @Package:com.mcwl.communityCenter.service + * @Filename:PublishCommissionLikeService + * @Description TODO + * @Date:2025/1/17 14:23 + */ +@Service +public interface PublishLikeService extends IService { + + + void like(@Valid PublishLikeRes publishLikeRes); +} diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/CommunityServiceImpl.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/CommunityServiceImpl.java index 7b73009..e23fec8 100644 --- a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/CommunityServiceImpl.java +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/CommunityServiceImpl.java @@ -14,13 +14,16 @@ import com.mcwl.common.core.redis.RedisCache; import com.mcwl.common.exception.ServiceException; import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.StringUtils; +import com.mcwl.communityCenter.constant.AdviceConstant; import com.mcwl.communityCenter.domain.Community; +import com.mcwl.communityCenter.domain.CommunityAdvice; import com.mcwl.communityCenter.domain.CommunityUser; import com.mcwl.communityCenter.domain.dto.CommunityListPageRes; import com.mcwl.communityCenter.domain.dto.CommunityRes; import com.mcwl.communityCenter.domain.dto.JoinCommunityListPageRes; import com.mcwl.communityCenter.domain.dto.JoinCommunityRes; import com.mcwl.communityCenter.domain.vo.CommunityVo; +import com.mcwl.communityCenter.mapper.CommunityAdviceMapper; import com.mcwl.communityCenter.mapper.CommunityMapper; import com.mcwl.communityCenter.mapper.CommunityUserMapper; import com.mcwl.communityCenter.service.CommunityService; @@ -46,6 +49,9 @@ public class CommunityServiceImpl extends ServiceImplimplements PublishCommentLikeService { +@RequiredArgsConstructor +public class PublishCommentLikeServiceImpl extends ServiceImpl implements PublishCommentLikeService { + + + private final PublishCommentMapper publishCommentMapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public void like(PublishCommentLikeRes publishCommentLikeRes) { + + PublishComment publishComment = publishCommentMapper.selectByIdAndTenantIdAndCommunityIdAndOperatorId( + publishCommentLikeRes.getTenantId(), publishCommentLikeRes.getCommunityId(), publishCommentLikeRes.getCommentId() + ); + + if (Objects.isNull(publishComment)) { + throw new ServiceException("该评论不存在", HttpStatus.SHOW_ERROR_MSG); + } + + PublishCommentLike publishCommentLike = baseMapper.selectLike(publishCommentLikeRes, SecurityUtils.getUserId()); + + if (Objects.isNull(publishCommentLike)) { + publishCommentLike = new PublishCommentLike(); + publishCommentLike.setTenantId(publishCommentLikeRes.getTenantId()); + publishCommentLike.setCommunityId(publishCommentLikeRes.getCommunityId()); + publishCommentLike.setPublishId(publishCommentLikeRes.getPublishId()); + publishCommentLike.setPublishCommentId(publishCommentLikeRes.getCommentId()); + publishCommentLike.setUserId(SecurityUtils.getUserId()); + baseMapper.insert(publishCommentLike); + publishComment.setLikeNum(publishComment.getLikeNum() + 1); + publishCommentMapper.updateById(publishComment); + this.addLikeAdvice(); + return; + } + + if (Objects.equals(publishCommentLike.getDelFlag(), "0")) { + publishCommentLike.setDelFlag("2"); + int likeNum = publishComment.getLikeNum() - 1; + likeNum = Math.max(likeNum, 0); + publishComment.setLikeNum(likeNum); + } else { + publishCommentLike.setDelFlag("0"); + publishComment.setLikeNum(publishComment.getLikeNum() + 1); + this.addLikeAdvice(); + } + + baseMapper.updateDelFlagById(publishCommentLike); + publishCommentMapper.updateById(publishComment); + + } + + private void addLikeAdvice(PublishCommentLike publishCommentLike) { + CommunityAdvice communityAdvice = new CommunityAdvice(); + + communityAdvice.setTenantId(publishCommentLike.getTenantId()); + communityAdvice.setCommunityId(publishCommentLike.getCommunityId()); + communityAdvice.setSendUserId(SecurityUtils.getUserId()); + communityAdvice.setAdviceType(AdviceConstant.COMMUNITY_NOTICE); + communityAdvice.setUserId(publishCommentLike); + communityAdvice.setTitle(StringUtils.format("{}回复{}", + SecurityUtils.getLoginUser().getUser().getNickName(), + question.getContent())); + communityAdvice.setContent(questionCommentRes.getContent()); + + communityAdviceMapper.insert(communityAdvice); + } + + } diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/PublishLikeServiceImpl.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/PublishLikeServiceImpl.java new file mode 100644 index 0000000..bbb202a --- /dev/null +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/PublishLikeServiceImpl.java @@ -0,0 +1,90 @@ +package com.mcwl.communityCenter.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.mcwl.common.constant.HttpStatus; +import com.mcwl.common.exception.ServiceException; +import com.mcwl.common.utils.SecurityUtils; +import com.mcwl.common.utils.StringUtils; +import com.mcwl.communityCenter.constant.AdviceConstant; +import com.mcwl.communityCenter.domain.*; +import com.mcwl.communityCenter.domain.dto.PublishCommentLikeRes; +import com.mcwl.communityCenter.domain.dto.PublishLikeRes; +import com.mcwl.communityCenter.mapper.*; +import com.mcwl.communityCenter.service.PublishCommentLikeService; +import com.mcwl.communityCenter.service.PublishLikeService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Objects; + +/** + * 评论区点赞业务层 + */ +@Service +@RequiredArgsConstructor +public class PublishLikeServiceImpl extends ServiceImpl implements PublishLikeService { + + private final PublishMapper publishMapper; + + private final CommunityAdviceMapper communityAdviceMapper; + + + @Override + public void like(PublishLikeRes publishLikeRes) { + + Publish publish = publishMapper.selectByIdAndTenantIdAndCommunityId(publishLikeRes.getPublishId(), + publishLikeRes.getTenantId(), + publishLikeRes.getCommunityId()); + + if (Objects.isNull(publish)) { + throw new ServiceException("点赞失败,该内容不存在", HttpStatus.SHOW_ERROR_MSG); + } + + PublishLike publishLike = baseMapper.selectPublishLike(publishLikeRes, SecurityUtils.getUserId()); + + if (Objects.isNull(publishLike)) { + publishLike = PublishLike.builder() + .tenantId(publishLikeRes.getTenantId()) + .communityId(publishLikeRes.getCommunityId()) + .publishId(publishLikeRes.getPublishId()) + .userId(SecurityUtils.getUserId()) + .build(); + baseMapper.insert(publishLike); + + publish.setLikeNum(publish.getLikeNum() + 1); + publishMapper.updateById(publish); + this.addLikeAdvice(publish); + return; + } + + if (Objects.equals(publishLike.getDelFlag(), "0")) { + publishLike.setDelFlag("2"); + int likeNum = publish.getLikeNum() - 1; + likeNum = Math.max(likeNum, 0); + publish.setLikeNum(likeNum); + } else { + publishLike.setDelFlag("0"); + publish.setLikeNum(publish.getLikeNum() + 1); + this.addLikeAdvice(publish); + } + + baseMapper.updateDelFlagById(publishLike); + publishMapper.updateById(publish); + + } + + private void addLikeAdvice(Publish publish) { + CommunityAdvice communityAdvice = new CommunityAdvice(); + + communityAdvice.setTenantId(publish.getTenantId()); + communityAdvice.setCommunityId(publish.getCommunityId()); + communityAdvice.setSendUserId(SecurityUtils.getUserId()); + communityAdvice.setAdviceType(AdviceConstant.COMMUNITY_NOTICE); + communityAdvice.setUserId(publish.getUserId()); + communityAdvice.setContent(StringUtils.format("{}点赞了你发布的{}", + SecurityUtils.getLoginUser().getUser().getNickName(), publish.getContent())); + + communityAdviceMapper.insert(communityAdvice); + } +} diff --git a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/QuestionCommentServiceImpl.java b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/QuestionCommentServiceImpl.java index e9c0fe2..bebb6f2 100644 --- a/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/QuestionCommentServiceImpl.java +++ b/mcwl-communityCenter/src/main/java/com/mcwl/communityCenter/service/impl/QuestionCommentServiceImpl.java @@ -11,7 +11,9 @@ import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.page.TableDataInfo; import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.StringUtils; +import com.mcwl.communityCenter.constant.AdviceConstant; import com.mcwl.communityCenter.domain.Community; +import com.mcwl.communityCenter.domain.CommunityAdvice; import com.mcwl.communityCenter.domain.Question; import com.mcwl.communityCenter.domain.QuestionComment; import com.mcwl.communityCenter.domain.dto.*; @@ -38,7 +40,10 @@ public class QuestionCommentServiceImpl extends ServiceImpl comment(QuestionCommentRes questionCommentRes) { Long tenantId = questionCommentRes.getTenantId(); @@ -48,7 +53,7 @@ public class QuestionCommentServiceImpl extends ServiceImpl i // 获取租户id Long tenantId = questionRes.getTenantId(); + Long questionUserId = questionRes.getQuestionUserId(); Community community = communityMapper.getByTenantIdAndCommunityId(tenantId, communityId); if (Objects.isNull(community)) { - return R.fail(HttpStatus.SHOW_ERROR_MSG,"租户或社区不存在"); + return R.fail(HttpStatus.SHOW_ERROR_MSG, "租户或社区不存在"); } - if (Objects.equals(tenantId, userId)) { - return R.fail(HttpStatus.SHOW_ERROR_MSG,"您不能提问自己的问题"); + if (Objects.equals(questionUserId, userId)) { + return R.fail(HttpStatus.SHOW_ERROR_MSG, "您不能提问自己的问题"); } //提问人(userId)是否在社区中 Invite invite = inviteMapper.selectByTenantIdAndCommunityIdAndInviteeUserId(tenantId, communityId, userId); if (Objects.isNull(invite)) { - return R.fail(HttpStatus.SHOW_ERROR_MSG,"您不是该社区成员,不能提问"); + return R.fail(HttpStatus.SHOW_ERROR_MSG, "您不是该社区成员,不能提问"); } Question question = new Question(); @@ -100,13 +102,15 @@ public class QuestionServiceImpl extends ServiceImpl i sysUserService.updateUser(sysUser); -// CommunityAdvice communityAdvice = new CommunityAdvice(); -// communityAdvice.setTenantId(tenantId); -// communityAdvice.setCommunityId(communityId); -// communityAdvice.setUserId(tenantId); -// communityAdvice.setTitle("您有新的问题"); -// communityAdvice.setContent(questionRes.getContent()); -// communityAdviceMapper.insert(communityAdvice); + CommunityAdvice communityAdvice = new CommunityAdvice(); + communityAdvice.setTenantId(tenantId); + communityAdvice.setCommunityId(communityId); + communityAdvice.setSendUserId(SecurityUtils.getUserId()); + communityAdvice.setAdviceType(AdviceConstant.WAIT_ME_ANSWER); + communityAdvice.setUserId(questionUserId); + communityAdvice.setTitle(StringUtils.format("{}向你提问:", SecurityUtils.getLoginUser().getUser().getNickName())); + communityAdvice.setContent(questionRes.getContent()); + communityAdviceMapper.insert(communityAdvice); return R.ok(); diff --git a/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishCommentLikeMapper.xml b/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishCommentLikeMapper.xml new file mode 100644 index 0000000..ba57070 --- /dev/null +++ b/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishCommentLikeMapper.xml @@ -0,0 +1,29 @@ + + + + + update cc_comment_like + set del_flag = #{publishCommentLike.delFlag} + where tenant_id = #{publishCommentLike.tenantId} + and community_id = #{publishCommentLike.communityId} + and comment_id = #{publishCommentLike.publishCommentId} + + + + + \ No newline at end of file diff --git a/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishCommentMapper.xml b/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishCommentMapper.xml index a1b26e7..7b2bbd6 100644 --- a/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishCommentMapper.xml +++ b/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishCommentMapper.xml @@ -5,8 +5,7 @@ update cc_comment set del_flag = '2' - where id = #{id} - and tenant_id = #{tenantId} + where tenant_id = #{tenantId} and community_id = #{communityId} and operator_id = #{operatorId} and type = 0 @@ -45,8 +44,7 @@ like_num, create_time from cc_comment - where id = #{id} - and tenant_id = #{tenantId} + where tenant_id = #{tenantId} and community_id = #{communityId} and operator_id = #{operatorId} and type = 0 diff --git a/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishLikeMapper.xml b/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishLikeMapper.xml new file mode 100644 index 0000000..1613443 --- /dev/null +++ b/mcwl-communityCenter/src/main/resources/mapper/communityCenter/PublishLikeMapper.xml @@ -0,0 +1,23 @@ + + + + + update cc_publish_like + set del_flag = #{publishLike.delFlag} + where tenant_id = #{publishLike.tenantId} + and community_id = #{publishLike.communityId} + and publish_id = #{publishLike.publishId} + and user_id = #{publishLike.userId} + + + + \ No newline at end of file diff --git a/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/Benefit.java b/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/Benefit.java index d59b628..492fba2 100644 --- a/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/Benefit.java +++ b/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/Benefit.java @@ -20,7 +20,7 @@ public class Benefit extends BaseEntity { /** * 权益名称Id */ - private String benefitNameId; + private Long benefitNameId; /** * 权益描述 */ diff --git a/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/dto/AddBenefitNameDto.java b/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/dto/AddBenefitNameDto.java index 21c4cd7..b5e94c9 100644 --- a/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/dto/AddBenefitNameDto.java +++ b/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/dto/AddBenefitNameDto.java @@ -18,12 +18,12 @@ public class AddBenefitNameDto { * 权益名称 */ @ApiModelProperty(value = "权益名称", required = true) - @NotNull(message = "权益名称不能为空") + @NotBlank(message = "权益名称不能为空") private String benefitName; /** * 单位 */ - @NotBlank(message = "排序不能为空") + @NotNull(message = "排序不能为空") @ApiModelProperty(value = "排序", required = true) private Integer benefitOrder; diff --git a/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/dto/EditBenefitNameDto.java b/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/dto/EditBenefitNameDto.java index 3fb3954..497dfcf 100644 --- a/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/dto/EditBenefitNameDto.java +++ b/mcwl-memberCenter/src/main/java/com/mcwl/memberCenter/domain/dto/EditBenefitNameDto.java @@ -6,6 +6,7 @@ import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; /** * 权益 @@ -20,12 +21,12 @@ public class EditBenefitNameDto { * 权益名称 */ @ApiModelProperty(value = "权益名称", required = true) - @NotNull(message = "权益名称不能为空") + @NotBlank(message = "权益名称不能为空") private String benefitName; /** * 单位 */ - @NotBlank(message = "排序不能为空") + @NotNull(message = "排序不能为空") @ApiModelProperty(value = "排序", required = true) private Integer benefitOrder; diff --git a/mcwl-resource/pom.xml b/mcwl-resource/pom.xml index 3f06f80..20cb0f4 100644 --- a/mcwl-resource/pom.xml +++ b/mcwl-resource/pom.xml @@ -39,10 +39,10 @@ 3.1.2 - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - 1.2.2 - + + + + + diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/handler/IMessageHandler.java b/mcwl-resource/src/main/java/com/mcwl/resource/handler/IMessageHandler.java deleted file mode 100644 index 2ca9713..0000000 --- a/mcwl-resource/src/main/java/com/mcwl/resource/handler/IMessageHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.mcwl.resource.handler; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.eclipse.paho.client.mqttv3.MqttMessage; - -import java.lang.annotation.*; -import java.util.Collections; -import java.util.List; - -public interface IMessageHandler { - void handleMessage(String topic, MqttMessage message); - - @Target(ElementType.TYPE) - @Retention(RetentionPolicy.RUNTIME) - @interface Topic { - String value(); - int qos() default 1; - } - - default List getTopics() { - Topic annotation = this.getClass().getAnnotation(Topic.class); - if (annotation != null) { - return Collections.singletonList( - new TopicSubscription(annotation.value(), annotation.qos()) - ); - } - return Collections.emptyList(); - } - - @Getter - @AllArgsConstructor - class TopicSubscription { - private String topicFilter; - private int qos; - } - -} \ No newline at end of file diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ImageCommentLikeHandler.java b/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ImageCommentLikeHandler.java deleted file mode 100644 index 5f31b4b..0000000 --- a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ImageCommentLikeHandler.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.mcwl.resource.handler.impl; - -import cn.hutool.json.JSON; -import cn.hutool.json.JSONUtil; -import com.mcwl.common.constant.HttpStatus; -import com.mcwl.common.core.domain.entity.SysUser; -import com.mcwl.common.exception.ServiceException; -import com.mcwl.common.utils.SecurityUtils; -import com.mcwl.common.utils.StringUtils; -import com.mcwl.resource.domain.ModelImageComment; -import com.mcwl.resource.domain.ModelImageCommentLike; -import com.mcwl.resource.domain.SysAdvice; -import com.mcwl.resource.handler.IMessageHandler; -import com.mcwl.resource.mapper.ModelImageCommentLikeMapper; -import com.mcwl.resource.mapper.ModelImageCommentMapper; -import com.mcwl.resource.mapper.WorkFlowCommentLikeMapper; -import com.mcwl.resource.mapper.WorkFlowCommentMapper; -import com.mcwl.resource.service.ISysAdviceService; -import com.mcwl.system.domain.enums.AdviceEnum; -import com.mcwl.system.service.ISysUserService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Map; -import java.util.Objects; - -@Slf4j -@Component -@IMessageHandler.Topic(value = "imageCommentLike/#", qos = 1) -@RequiredArgsConstructor -public class ImageCommentLikeHandler implements IMessageHandler { - - private final ModelImageCommentMapper modelImageCommentMapper; - - private final ModelImageCommentLikeMapper modelImageCommentLikeMapper; - - private final ISysUserService userService; - - private final ISysAdviceService adviceService; - @Override - @Transactional(rollbackFor = Exception.class) - public void handleMessage(String topic, MqttMessage message) { - String payload = new String(message.getPayload()); - log.info("图片评论点赞: {} - {}", payload, message); - - JSON parse = JSONUtil.parse(payload); - Long commentId = Long.parseLong(parse.getByPath("commentId").toString()); - Long userId = Long.parseLong(parse.getByPath("userId").toString()); - - - - this.like(userId, commentId); - } - - - - private void like(Long userId, Long commentId) { - ModelImageComment modelImageComment = modelImageCommentMapper.selectById(commentId); - if (Objects.isNull(modelImageComment)) { - throw new ServiceException("该评论不存在", HttpStatus.SHOW_ERROR_MSG); - } - ModelImageCommentLike modelImageCommentLike = modelImageCommentLikeMapper.getLikeImageComment(userId, commentId); - if (Objects.nonNull(modelImageCommentLike)) { - if (Objects.equals(modelImageCommentLike.getDelFlag(), "0")) { - modelImageCommentLike.setDelFlag("2"); - int likeNum = modelImageComment.getLikeNum() - 1; - likeNum = Math.max(likeNum, 0); - modelImageComment.setLikeNum(likeNum); - } else { - modelImageCommentLike.setDelFlag("0"); - modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1); - this.addLikeAdvice(modelImageComment, userId); - } - // 更新点赞记录 - modelImageCommentLikeMapper.updateDelFlagById(modelImageCommentLike); - // 更新图片评论点赞数 - modelImageCommentMapper.updateById(modelImageComment); - return; - } - - // 添加点赞记录 - modelImageCommentLike = new ModelImageCommentLike(); - modelImageCommentLike.setUserId(userId); - modelImageCommentLike.setModelImageCommentId(commentId); - modelImageCommentLikeMapper.insert(modelImageCommentLike); - - // 更新图片点赞数 - modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1); - modelImageCommentMapper.updateById(modelImageComment); - - this.addLikeAdvice(modelImageComment, userId); - } - - - private void addLikeAdvice(ModelImageComment modelImageComment, Long userId) { - - Long receiverUserId = modelImageComment.getUserId(); - - if (Objects.equals(userId, receiverUserId)) { - return; - } - - SysUser sysUser = userService.selectUserById(userId); - - String content = StringUtils.format("恭喜!{}点赞了您的评论", - sysUser.getNickName()); - - SysAdvice sysAdvice = new SysAdvice(); - sysAdvice.setSenderId(userId); - sysAdvice.setReceiverId(receiverUserId); - sysAdvice.setContent(content); - sysAdvice.setProductId(modelImageComment.getModelImageId()); - sysAdvice.setProductType(2); - sysAdvice.setCommentId(modelImageComment.getId()); - sysAdvice.setIsRead(0); - sysAdvice.setType(AdviceEnum.LIKE_REMIND); - adviceService.save(sysAdvice); - - - } - - - -} \ No newline at end of file diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ImageLikeHandler.java b/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ImageLikeHandler.java deleted file mode 100644 index e172a8a..0000000 --- a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ImageLikeHandler.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.mcwl.resource.handler.impl; - -import cn.hutool.json.JSON; -import cn.hutool.json.JSONUtil; -import com.mcwl.common.constant.HttpStatus; -import com.mcwl.common.core.domain.entity.SysUser; -import com.mcwl.common.exception.ServiceException; -import com.mcwl.common.utils.SecurityUtils; -import com.mcwl.common.utils.StringUtils; -import com.mcwl.resource.domain.ModelImage; -import com.mcwl.resource.domain.ModelImageLike; -import com.mcwl.resource.domain.SysAdvice; -import com.mcwl.resource.handler.IMessageHandler; -import com.mcwl.resource.mapper.ModelImageLikeMapper; -import com.mcwl.resource.mapper.ModelImageMapper; -import com.mcwl.resource.mapper.WorkFlowLikeMapper; -import com.mcwl.resource.mapper.WorkFlowMapper; -import com.mcwl.resource.service.ISysAdviceService; -import com.mcwl.system.domain.enums.AdviceEnum; -import com.mcwl.system.service.ISysUserService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Objects; - -@Slf4j -@Component -@IMessageHandler.Topic(value = "imageLike/#", qos = 1) -@RequiredArgsConstructor -public class ImageLikeHandler implements IMessageHandler { - - - private final ModelImageMapper modelImageMapper; - - private final ModelImageLikeMapper modelImageLikeMapper; - - private final ISysUserService userService; - - private final ISysAdviceService adviceService; - - @Override - @Transactional(rollbackFor = Exception.class) - public void handleMessage(String topic, MqttMessage message) { - String payload = new String(message.getPayload()); - log.info("图片点赞: {}", payload); - - JSON parse = JSONUtil.parse(payload); - Long commentId = Long.parseLong(parse.getByPath("commentId").toString()); - Long userId = Long.parseLong(parse.getByPath("userId").toString()); - - this.like(userId, commentId); - } - - private void like(Long userId, Long imageId) { - ModelImage modelImage = modelImageMapper.selectById(imageId); - if (Objects.isNull(modelImage)) { - throw new ServiceException("该图片不存在或已下架", HttpStatus.SHOW_ERROR_MSG); - } - ModelImageLike modelImageLike = modelImageLikeMapper.getLikeImage(userId, imageId); - if (Objects.nonNull(modelImageLike)) { - if (Objects.equals(modelImageLike.getDelFlag(), "0")) { - modelImageLike.setDelFlag("2"); - int likeNum = modelImage.getLikeNum() - 1; - likeNum = Math.max(likeNum, 0); - modelImage.setLikeNum(likeNum); - } else { - modelImageLike.setDelFlag("0"); - modelImage.setLikeNum(modelImage.getLikeNum() + 1); - this.addLikeAdvice(modelImage, userId); - } - // 更新点赞记录 - modelImageLikeMapper.updateDelFlagById(modelImageLike); - // 更新图片点赞数 - modelImageMapper.updateById(modelImage); - return; - } - - // 添加点赞记录 - modelImageLike = new ModelImageLike(); - modelImageLike.setUserId(userId); - modelImageLike.setModelImageId(imageId); - modelImageLikeMapper.insert(modelImageLike); - - // 更新图片点赞数 - modelImage.setLikeNum(modelImage.getLikeNum() + 1); - modelImageMapper.updateById(modelImage); - - this.addLikeAdvice(modelImage, userId); - } - - - private void addLikeAdvice(ModelImage modelImage, Long userId) { - - Long receiverUserId = modelImage.getUserId(); - - if (Objects.equals(userId, receiverUserId)) { - return; - } - - SysUser sysUser = userService.selectUserById(userId); - - - String content = StringUtils.format("恭喜!{}点赞了您的图片:{}", - sysUser.getNickName(), modelImage.getTitle()); - - SysAdvice sysAdvice = new SysAdvice(); - sysAdvice.setSenderId(userId); - sysAdvice.setReceiverId(receiverUserId); - sysAdvice.setContent(content); - sysAdvice.setProductId(modelImage.getId()); - sysAdvice.setProductType(2); - sysAdvice.setIsRead(0); - sysAdvice.setType(AdviceEnum.LIKE_REMIND); - adviceService.save(sysAdvice); - - - } - - -} \ No newline at end of file diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ModelCommentLikeHandler.java b/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ModelCommentLikeHandler.java deleted file mode 100644 index af8749f..0000000 --- a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ModelCommentLikeHandler.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.mcwl.resource.handler.impl; - -import cn.hutool.json.JSON; -import cn.hutool.json.JSONUtil; -import com.mcwl.common.constant.HttpStatus; -import com.mcwl.common.core.domain.entity.SysUser; -import com.mcwl.common.exception.ServiceException; -import com.mcwl.common.utils.SecurityUtils; -import com.mcwl.common.utils.StringUtils; -import com.mcwl.resource.domain.*; -import com.mcwl.resource.handler.IMessageHandler; -import com.mcwl.resource.mapper.ModelCommentLikeMapper; -import com.mcwl.resource.mapper.ModelCommentMapper; -import com.mcwl.resource.mapper.WorkFlowCommentLikeMapper; -import com.mcwl.resource.mapper.WorkFlowCommentMapper; -import com.mcwl.resource.service.ISysAdviceService; -import com.mcwl.system.domain.enums.AdviceEnum; -import com.mcwl.system.service.ISysUserService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Objects; - -@Slf4j -@Component -@IMessageHandler.Topic(value = "modelCommentLike/#", qos = 1) -@RequiredArgsConstructor -public class ModelCommentLikeHandler implements IMessageHandler { - - - private final ModelCommentMapper modelCommentMapper; - - private final ModelCommentLikeMapper modelCommentLikeMapper; - - private final ISysUserService userService; - - private final ISysAdviceService adviceService; - - @Override - @Transactional(rollbackFor = Exception.class) - public void handleMessage(String topic, MqttMessage message) { - String payload = new String(message.getPayload()); - log.info("模型评论点赞: {} - {}", payload, message); - - JSON parse = JSONUtil.parse(payload); - Long commentId = Long.parseLong(parse.getByPath("commentId").toString()); - Long userId = Long.parseLong(parse.getByPath("userId").toString()); - - - this.like(userId, commentId); - } - - private void like(Long userId, Long commentId) { - ModelComment modelComment = modelCommentMapper.selectById(commentId); - if (Objects.isNull(modelComment)) { - throw new ServiceException("该评论不存在", HttpStatus.SHOW_ERROR_MSG); - } - ModelCommentLike modelCommentLike = modelCommentLikeMapper.getLikeComment(userId, commentId); - if (Objects.nonNull(modelCommentLike)) { - if (Objects.equals(modelCommentLike.getDelFlag(), "0")) { - modelCommentLike.setDelFlag("2"); - int likeNum = modelComment.getLikeNum() - 1; - likeNum = Math.max(likeNum, 0); - modelComment.setLikeNum(likeNum); - } else { - modelCommentLike.setDelFlag("0"); - modelComment.setLikeNum(modelComment.getLikeNum() + 1); - this.addLikeAdvice(modelComment, userId); - } - // 更新点赞记录 - modelCommentLikeMapper.updateDelFlagById(modelCommentLike); - // 更新图片评论点赞数 - modelCommentMapper.updateById(modelComment); - return; - } - - // 添加点赞记录 - modelCommentLike = new ModelCommentLike(); - modelCommentLike.setUserId(userId); - modelCommentLike.setModelCommentId(commentId); - modelCommentLikeMapper.insert(modelCommentLike); - - // 更新模型点赞数 - modelComment.setLikeNum(modelComment.getLikeNum() + 1); - modelCommentMapper.updateById(modelComment); - - this.addLikeAdvice(modelComment, userId); - } - - - private void addLikeAdvice(ModelComment modelComment, Long userId) { - - Long receiverUserId = modelComment.getUserId(); - - if (Objects.equals(userId, receiverUserId)) { - return; - } - SysUser sysUser = userService.selectUserById(userId); - - String content = StringUtils.format("恭喜!{}点赞了您的评论", - sysUser.getNickName()); - - SysAdvice sysAdvice = new SysAdvice(); - sysAdvice.setSenderId(userId); - sysAdvice.setReceiverId(receiverUserId); - sysAdvice.setContent(content); - sysAdvice.setProductId(modelComment.getModelId()); - sysAdvice.setProductType(0); - sysAdvice.setCommentId(modelComment.getId()); - sysAdvice.setIsRead(0); - sysAdvice.setType(AdviceEnum.LIKE_REMIND); - adviceService.save(sysAdvice); - - - } - - - -} \ No newline at end of file diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ModelLikeHandler.java b/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ModelLikeHandler.java deleted file mode 100644 index 68bd0cd..0000000 --- a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/ModelLikeHandler.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.mcwl.resource.handler.impl; - -import cn.hutool.json.JSON; -import cn.hutool.json.JSONUtil; -import com.mcwl.common.constant.HttpStatus; -import com.mcwl.common.core.domain.entity.SysUser; -import com.mcwl.common.exception.ServiceException; -import com.mcwl.common.utils.SecurityUtils; -import com.mcwl.common.utils.StringUtils; -import com.mcwl.resource.domain.*; -import com.mcwl.resource.handler.IMessageHandler; -import com.mcwl.resource.mapper.ModelLikeMapper; -import com.mcwl.resource.mapper.ModelMapper; -import com.mcwl.resource.mapper.WorkFlowLikeMapper; -import com.mcwl.resource.mapper.WorkFlowMapper; -import com.mcwl.resource.service.ISysAdviceService; -import com.mcwl.system.domain.enums.AdviceEnum; -import com.mcwl.system.service.ISysUserService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Objects; - -@Slf4j -@Component -@IMessageHandler.Topic(value = "modelLike/#", qos = 1) -@RequiredArgsConstructor -public class ModelLikeHandler implements IMessageHandler { - - private final ModelMapper modelMapper; - - - private final ModelLikeMapper modelLikeMapper; - - private final ISysUserService userService; - - private final ISysAdviceService adviceService; - - - @Override - @Transactional(rollbackFor = Exception.class) - public void handleMessage(String topic, MqttMessage message) { - String payload = new String(message.getPayload()); - log.info("模型点赞: {}", payload); - - JSON parse = JSONUtil.parse(payload); - Long commentId = Long.parseLong(parse.getByPath("commentId").toString()); - Long userId = Long.parseLong(parse.getByPath("userId").toString()); - - - this.like(userId, commentId); - } - - private void like(Long userId, Long modelId) { - ModelProduct model = modelMapper.selectById(modelId); - if (Objects.isNull(model)) { - throw new ServiceException("该模型不存在或已下架", HttpStatus.SHOW_ERROR_MSG); - } - ModelLike modelLike = modelLikeMapper.getLike(userId, modelId); - if (Objects.nonNull(modelLike)) { - if (Objects.equals(modelLike.getDelFlag(), "0")) { - modelLike.setDelFlag("2"); - int likeNum = model.getLikeNum() - 1; - likeNum = Math.max(likeNum, 0); - model.setLikeNum(likeNum); - } else { - modelLike.setDelFlag("0"); - model.setLikeNum(model.getLikeNum() + 1); - this.addLikeAdvice(model, userId); - } - // 更新点赞记录 - modelLikeMapper.updateDelFlagById(modelLike); - // 更新图片点赞数 - modelMapper.updateById(model); - return; - } - - // 添加点赞记录 - modelLike = new ModelLike(); - modelLike.setUserId(userId); - modelLike.setModelId(modelId); - modelLikeMapper.insert(modelLike); - - // 更新图片点赞数 - model.setNumbers(model.getLikeNum() + 1); - modelMapper.updateById(model); - - this.addLikeAdvice(model, userId); - } - - - private void addLikeAdvice(ModelProduct model, Long userId) { - - Long receiverUserId = model.getUserId(); - - if (Objects.equals(userId, receiverUserId)) { - return; - } - SysUser sysUser = userService.selectUserById(userId); - - String content = StringUtils.format("恭喜!{}点赞了您的模型:{}", - sysUser.getNickName(), model.getModelName()); - - SysAdvice sysAdvice = new SysAdvice(); - sysAdvice.setSenderId(userId); - sysAdvice.setReceiverId(receiverUserId); - sysAdvice.setContent(content); - sysAdvice.setProductId(model.getId()); - sysAdvice.setProductType(0); - sysAdvice.setIsRead(0); - sysAdvice.setType(AdviceEnum.LIKE_REMIND); - adviceService.save(sysAdvice); - - - } - - -} \ No newline at end of file diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/WorkFlowCommentLikeHandler.java b/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/WorkFlowCommentLikeHandler.java deleted file mode 100644 index 3042287..0000000 --- a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/WorkFlowCommentLikeHandler.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.mcwl.resource.handler.impl; - -import cn.hutool.json.JSON; -import cn.hutool.json.JSONUtil; -import com.mcwl.common.constant.HttpStatus; -import com.mcwl.common.core.domain.entity.SysUser; -import com.mcwl.common.exception.ServiceException; -import com.mcwl.common.utils.SecurityUtils; -import com.mcwl.common.utils.StringUtils; -import com.mcwl.resource.domain.SysAdvice; -import com.mcwl.resource.domain.WorkFlowComment; -import com.mcwl.resource.domain.WorkFlowCommentLike; -import com.mcwl.resource.handler.IMessageHandler; -import com.mcwl.resource.mapper.WorkFlowCommentLikeMapper; -import com.mcwl.resource.mapper.WorkFlowCommentMapper; -import com.mcwl.resource.service.ISysAdviceService; -import com.mcwl.system.domain.enums.AdviceEnum; -import com.mcwl.system.service.ISysUserService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Objects; - -@Slf4j -@Component -@IMessageHandler.Topic(value = "workFlowCommentLike/#", qos = 1) -@RequiredArgsConstructor -public class WorkFlowCommentLikeHandler implements IMessageHandler { - - - private final WorkFlowCommentMapper workFlowCommentMapper; - - - private final WorkFlowCommentLikeMapper workFlowCommentLikeMapper; - - private final ISysUserService userService; - - private final ISysAdviceService adviceService; - - - - @Override - @Transactional(rollbackFor = Exception.class) - public void handleMessage(String topic, MqttMessage message) { - String payload = new String(message.getPayload()); - log.info("工作流评论点赞: {} - {}", topic, payload); - - JSON parse = JSONUtil.parse(payload); - Long commentId = Long.parseLong(parse.getByPath("commentId").toString()); - Long userId = Long.parseLong(parse.getByPath("userId").toString()); - - - this.like(userId, commentId); - } - - private void like(Long userId, Long commentId) { - WorkFlowComment workFlowComment = workFlowCommentMapper.selectById(commentId); - if (Objects.isNull(workFlowComment)) { - throw new ServiceException("该评论不存在", HttpStatus.SHOW_ERROR_MSG); - } - WorkFlowCommentLike workFlowCommentLike = workFlowCommentLikeMapper.getLikeComment(userId, commentId); - if (Objects.nonNull(workFlowCommentLike)) { - if (Objects.equals(workFlowCommentLike.getDelFlag(), "0")) { - workFlowCommentLike.setDelFlag("2"); - int likeNum = workFlowComment.getLikeNum() - 1; - likeNum = Math.max(likeNum, 0); - workFlowComment.setLikeNum(likeNum); - } else { - workFlowCommentLike.setDelFlag("0"); - workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1); - this.addLikeAdvice(workFlowComment, userId); - } - // 更新点赞记录 - workFlowCommentLikeMapper.updateDelFlagById(workFlowCommentLike); - // 更新图片评论点赞数 - workFlowCommentMapper.updateById(workFlowComment); - return; - } - - // 添加点赞记录 - workFlowCommentLike = new WorkFlowCommentLike(); - workFlowCommentLike.setUserId(userId); - workFlowCommentLike.setWorkFlowCommentId(commentId); - workFlowCommentLikeMapper.insert(workFlowCommentLike); - - // 更新模型点赞数 - workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1); - workFlowCommentMapper.updateById(workFlowComment); - - this.addLikeAdvice(workFlowComment, userId); - } - - - private void addLikeAdvice(WorkFlowComment workFlowComment, Long userId) { - - Long receiverUserId = workFlowComment.getUserId(); - - if (Objects.equals(userId, receiverUserId)) { - return; - } - SysUser sysUser = userService.selectUserById(userId); - - String content = StringUtils.format("恭喜!{}点赞了您的评论", - sysUser.getNickName()); - - SysAdvice sysAdvice = new SysAdvice(); - sysAdvice.setSenderId(userId); - sysAdvice.setReceiverId(receiverUserId); - sysAdvice.setContent(content); - sysAdvice.setProductId(workFlowComment.getWorkFlowId()); - sysAdvice.setProductType(1); - sysAdvice.setCommentId(workFlowComment.getId()); - sysAdvice.setIsRead(0); - sysAdvice.setType(AdviceEnum.LIKE_REMIND); - adviceService.save(sysAdvice); - - - } - - - -} \ No newline at end of file diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/WorkFlowLikeHandler.java b/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/WorkFlowLikeHandler.java deleted file mode 100644 index 00c47be..0000000 --- a/mcwl-resource/src/main/java/com/mcwl/resource/handler/impl/WorkFlowLikeHandler.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.mcwl.resource.handler.impl; - -import cn.hutool.json.JSON; -import cn.hutool.json.JSONUtil; -import com.mcwl.common.constant.HttpStatus; -import com.mcwl.common.core.domain.entity.SysUser; -import com.mcwl.common.exception.ServiceException; -import com.mcwl.common.utils.SecurityUtils; -import com.mcwl.common.utils.StringUtils; -import com.mcwl.resource.domain.SysAdvice; -import com.mcwl.resource.domain.WorkFlow; -import com.mcwl.resource.domain.WorkFlowLike; -import com.mcwl.resource.handler.IMessageHandler; -import com.mcwl.resource.mapper.WorkFlowLikeMapper; -import com.mcwl.resource.mapper.WorkFlowMapper; -import com.mcwl.resource.service.ISysAdviceService; -import com.mcwl.system.domain.enums.AdviceEnum; -import com.mcwl.system.service.ISysUserService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Objects; - -@Slf4j -@Component -@IMessageHandler.Topic(value = "workFlowLike/#", qos = 1) -@RequiredArgsConstructor -public class WorkFlowLikeHandler implements IMessageHandler { - - private final WorkFlowMapper workFlowMapper; - - private final WorkFlowLikeMapper workFlowLikeMapper; - - private final ISysUserService userService; - - private final ISysAdviceService adviceService; - - @Override - @Transactional(rollbackFor = Exception.class) - public void handleMessage(String topic, MqttMessage message) { - String payload = new String(message.getPayload()); - log.info("工作流点赞: {} - {}", topic, payload); - - JSON parse = JSONUtil.parse(payload); - Long commentId = Long.parseLong(parse.getByPath("commentId").toString()); - Long userId = Long.parseLong(parse.getByPath("userId").toString()); - - - this.like(userId, commentId); - } - - private void like(Long userId, Long modelId) { - WorkFlow workFlow = workFlowMapper.selectById(modelId); - if (Objects.isNull(workFlow)) { - throw new ServiceException("该工作流不存在或已下架", HttpStatus.SHOW_ERROR_MSG); - } - WorkFlowLike workFlowLike = workFlowLikeMapper.getLike(userId, modelId); - if (Objects.nonNull(workFlowLike)) { - if (Objects.equals(workFlowLike.getDelFlag(), "0")) { - workFlowLike.setDelFlag("2"); - int likeCount = workFlow.getLikeNum() - 1; - likeCount = Math.max(likeCount, 0); - workFlow.setLikeNum(likeCount); - } else { - workFlowLike.setDelFlag("0"); - workFlow.setLikeNum(workFlow.getLikeNum() + 1); - this.addLikeAdvice(workFlow, userId); - } - // 更新点赞记录 - workFlowLikeMapper.updateStatus(workFlowLike); - // 更新图片点赞数 - workFlowMapper.updateById(workFlow); - return; - } - - // 添加点赞记录 - workFlowLike = new WorkFlowLike(); - workFlowLike.setUserId(userId); - workFlowLike.setWorkFlowId(modelId); - workFlowLikeMapper.insert(workFlowLike); - - // 更新图片点赞数 - workFlow.setLikeNum(workFlow.getLikeNum() + 1); - workFlowMapper.updateById(workFlow); - - this.addLikeAdvice(workFlow, userId); - } - - - private void addLikeAdvice(WorkFlow workFlow, Long userId) { - - Long receiverUserId = workFlow.getUserId(); - - if (Objects.equals(userId, receiverUserId)) { - return; - } - SysUser sysUser = userService.selectUserById(userId); - - String content = StringUtils.format("恭喜!{}点赞了您的工作流:{}", - sysUser.getNickName(), workFlow.getWorkflowName()); - - SysAdvice sysAdvice = new SysAdvice(); - sysAdvice.setSenderId(userId); - sysAdvice.setReceiverId(receiverUserId); - sysAdvice.setContent(content); - sysAdvice.setProductId(workFlow.getId()); - sysAdvice.setProductType(1); - sysAdvice.setIsRead(0); - sysAdvice.setType(AdviceEnum.LIKE_REMIND); - adviceService.save(sysAdvice); - - - } - - -} \ No newline at end of file diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java index f07acc8..3607430 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java @@ -7,7 +7,6 @@ import com.mcwl.common.utils.SecurityUtils; import com.mcwl.resource.domain.ModelCommentLike; import com.mcwl.resource.mapper.ModelCommentLikeMapper; import com.mcwl.resource.service.ModelCommentLikeService; -import com.mcwl.resource.util.MqttTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,8 +21,6 @@ import java.util.Map; @Service public class ModelCommentLikeServiceImpl extends ServiceImpl implements ModelCommentLikeService { - @Autowired - private MqttTemplate mqttTemplate; @Autowired private RabbitTemplate rabbitTemplate; @@ -33,7 +30,6 @@ public class ModelCommentLikeServiceImpl extends ServiceImpl map = new HashMap<>(); map.put("userId", SecurityUtils.getUserId()); map.put("commentId", commentId); -// mqttTemplate.publish("modelCommentLike", JSONUtil.toJsonStr(map), 0); rabbitTemplate.convertAndSend(QueueConstants.MODEL_COMMENT_LIKE_QUEUE, map); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentLikeServiceImpl.java index 905cb28..07e8aa9 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentLikeServiceImpl.java @@ -7,7 +7,6 @@ import com.mcwl.common.utils.SecurityUtils; import com.mcwl.resource.domain.ModelImageCommentLike; import com.mcwl.resource.mapper.ModelImageCommentLikeMapper; import com.mcwl.resource.service.ModelImageCommentLikeService; -import com.mcwl.resource.util.MqttTemplate; import lombok.RequiredArgsConstructor; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; @@ -24,7 +23,6 @@ import java.util.Map; @RequiredArgsConstructor public class ModelImageCommentLikeServiceImpl extends ServiceImpl implements ModelImageCommentLikeService { - private final MqttTemplate mqttTemplate; private final RabbitTemplate rabbitTemplate; @@ -34,7 +32,6 @@ public class ModelImageCommentLikeServiceImpl extends ServiceImpl map = new HashMap<>(); map.put("userId", SecurityUtils.getUserId()); map.put("commentId", commentId); -// mqttTemplate.publish("imageCommentLike", JSONUtil.toJsonStr(map),0); rabbitTemplate.convertAndSend(QueueConstants.IMAGE_COMMENT_LIKE_QUEUE, map); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java index 9873765..008f937 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java @@ -25,7 +25,6 @@ import com.mcwl.resource.domain.vo.PageVo; import com.mcwl.resource.mapper.ModelImageLikeMapper; import com.mcwl.resource.mapper.ModelImageMapper; import com.mcwl.resource.service.ModelImageLikeService; -import com.mcwl.resource.util.MqttTemplate; import com.mcwl.system.domain.enums.AdviceEnum; import com.mcwl.system.service.ISysUserService; import lombok.RequiredArgsConstructor; @@ -47,9 +46,6 @@ public class ModelImageLikeServiceImpl extends ServiceImpl map = new HashMap<>(); map.put("userId", SecurityUtils.getUserId()); map.put("commentId", imageId); -// mqttTemplate.publish("imageLike", JSONUtil.toJsonStr(map),0); Long userId = SecurityUtils.getUserId(); rabbitTemplate.convertAndSend(QueueConstants.IMAGE_LIKE_QUEUE, map); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelLikeServiceImpl.java index e71a24b..a0b9b4e 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelLikeServiceImpl.java @@ -20,7 +20,6 @@ import com.mcwl.resource.domain.vo.ModelLikeVo; import com.mcwl.resource.mapper.ModelLikeMapper; import com.mcwl.resource.mapper.ModelMapper; import com.mcwl.resource.service.ModelLikeService; -import com.mcwl.resource.util.MqttTemplate; import com.mcwl.system.service.ISysUserService; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; @@ -41,9 +40,6 @@ public class ModelLikeServiceImpl extends ServiceImpl map = new HashMap<>(); map.put("userId", SecurityUtils.getUserId()); map.put("commentId", modelId); -// mqttTemplate.publish("modelLike", JSONUtil.toJsonStr(map), 0); rabbitTemplate.convertAndSend(QueueConstants.MODEL_LIKE_QUEUE, map); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentLikeServiceImpl.java index fe075ad..633638c 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentLikeServiceImpl.java @@ -7,7 +7,6 @@ import com.mcwl.common.utils.SecurityUtils; import com.mcwl.resource.domain.WorkFlowCommentLike; import com.mcwl.resource.mapper.WorkFlowCommentLikeMapper; import com.mcwl.resource.service.WorkFlowCommentLikeService; -import com.mcwl.resource.util.MqttTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -27,9 +26,6 @@ import java.util.Map; @Service public class WorkFlowCommentLikeServiceImpl extends ServiceImpl implements WorkFlowCommentLikeService { - @Autowired - private MqttTemplate mqttTemplate; - @Autowired private RabbitTemplate rabbitTemplate; @@ -38,7 +34,6 @@ public class WorkFlowCommentLikeServiceImpl extends ServiceImpl map = new HashMap<>(); map.put("userId", SecurityUtils.getUserId()); map.put("commentId", commentId); -// mqttTemplate.publish("workFlowCommentLike", JSONUtil.toJsonStr(map),0); rabbitTemplate.convertAndSend(QueueConstants.WORK_FLOW_COMMENT_LIKE_QUEUE, map); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowLikeServiceImpl.java index 4afd0e5..1e5ad03 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowLikeServiceImpl.java @@ -20,7 +20,6 @@ import com.mcwl.resource.domain.vo.WorkFlowLikeVo; import com.mcwl.resource.mapper.WorkFlowLikeMapper; import com.mcwl.resource.mapper.WorkFlowMapper; import com.mcwl.resource.service.WorkFlowLikeService; -import com.mcwl.resource.util.MqttTemplate; import com.mcwl.system.service.ISysUserService; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; @@ -48,9 +47,6 @@ public class WorkFlowLikeServiceImpl extends ServiceImpl map = new HashMap<>(); map.put("userId", SecurityUtils.getUserId()); map.put("commentId", modelId); -// mqttTemplate.publish("workFlowLike", JSONUtil.toJsonStr(map),0); rabbitTemplate.convertAndSend(QueueConstants.WORK_FLOW_LIKE_QUEUE, map); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/util/MqttTemplate.java b/mcwl-resource/src/main/java/com/mcwl/resource/util/MqttTemplate.java deleted file mode 100644 index 20ede33..0000000 --- a/mcwl-resource/src/main/java/com/mcwl/resource/util/MqttTemplate.java +++ /dev/null @@ -1,264 +0,0 @@ -package com.mcwl.resource.util; - - -import com.mcwl.common.utils.StringUtils; -import com.mcwl.resource.handler.IMessageHandler; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.client.mqttv3.*; -import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.annotation.Async; - -import javax.annotation.PostConstruct; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import static com.mcwl.common.utils.Threads.sleep; - -@Slf4j -@Getter -@Configuration -@ConfigurationProperties(prefix = "mqtt") -public class MqttTemplate implements MqttCallbackExtended, DisposableBean { - - @Value("${mqtt.broker-url}") - private String brokerUrl; - - @Value("${mqtt.client-id-prefix}") - private String clientIdPrefix; - - @Value("${mqtt.connection-timeout}") - private int connectionTimeout; - - @Value("${mqtt.keep-alive-interval}") - private int keepAliveInterval; - - @Value("${mqtt.max-reconnect-attempts}") - private int maxReconnectAttempts; - - @Value("${mqtt.clean-session}") - private boolean cleanSession; - - private String clientId; - - private MqttAsyncClient client; - private final Map> topicHandlers = new ConcurrentHashMap<>(); - private final ScheduledExecutorService reconnectExecutor = Executors.newSingleThreadScheduledExecutor(); - private volatile boolean isConnecting; - private final ApplicationContext context; - - public MqttTemplate(ApplicationContext context) { - this.context = context; - } - - - @PostConstruct - public void init() throws MqttException { - if (StringUtils.isBlank(clientId)) { - clientId = clientIdPrefix + UUID.randomUUID().toString().substring(0, 8); - } - - client = new MqttAsyncClient(brokerUrl, clientId, new MemoryPersistence()); - client.setCallback(this); - connect(); -// autoRegisterHandlers(); - } - - @Override - public void destroy() throws Exception { - if (client != null && client.isConnected()) { - client.disconnect(); - } - reconnectExecutor.shutdown(); - } - - /** - * 连接管理 - * - * @throws MqttException 连接失败 - */ - private void connect() throws MqttException { - MqttConnectOptions options = new MqttConnectOptions(); - options.setCleanSession(cleanSession); - options.setConnectionTimeout(connectionTimeout); - options.setKeepAliveInterval(keepAliveInterval); - options.setAutomaticReconnect(false); // 手动控制重连 - - client.connect(options, null, new IMqttActionListener() { - @Override - public void onSuccess(IMqttToken asyncActionToken) { - log.info("MQTT连接成功"); - resubscribeAllTopics(); - autoRegisterHandlers(); - } - - @Override - public void onFailure(IMqttToken asyncActionToken, Throwable exception) { - log.error("初始连接失败", exception); - scheduleReconnect(1); - } - }); - } - - /** - * 重连管理 - * @param attempt 重连次数 - */ - private void scheduleReconnect(int attempt) { - if (attempt > maxReconnectAttempts) { - log.error("达到最大重连次数: {}", maxReconnectAttempts); - return; - } - - long delay = (long) Math.min(1000 * Math.pow(2, attempt), 30000); - reconnectExecutor.schedule(() -> { - try { - log.info("尝试第{}次重连", attempt); - if (client != null && client.isConnected()) { - client.disconnectForcibly(); // 强制断开旧连接 - client.close(true); - } - // 重新初始化客户端 - client = new MqttAsyncClient(brokerUrl, clientId, new MemoryPersistence()); - client.setCallback(this); // 关键:重新绑定回调 - client.reconnect(); - resubscribeAllTopics(); // 重连后立即订阅 - log.info("重连成功"); - } catch (MqttException e) { - log.error("重连失败", e); - scheduleReconnect(attempt + 1); - } - }, delay, TimeUnit.MILLISECONDS); - } - - /** - * 发布消息 - * @param topic 主题 - * @param payload 消息体 - * @param qos QoS等级 - */ - @Async - public void publish(String topic, String payload, int qos) { - try { - if (!client.isConnected()) { - throw new MqttException(MqttException.REASON_CODE_CLIENT_NOT_CONNECTED); - } - client.publish(topic, payload.getBytes(), qos, false); - } catch (MqttException e) { - log.error("消息发送失败 [topic: {}]", topic, e); - } - } - - @Async - public void publish(String topic, String payload) { - try { - if (!client.isConnected()) { - throw new MqttException(MqttException.REASON_CODE_CLIENT_NOT_CONNECTED); - } - client.publish(topic, payload.getBytes(), 1, false); - } catch (MqttException e) { - log.error("消息发送失败 [topic: {}]", topic, e); - } - } - - /** - * 订阅主题 - * @param topicFilter 主题过滤器 - * @param qos QoS等级 - * @param handler 消息处理器 - */ - public void subscribe(String topicFilter, int qos, IMessageHandler handler) { - try { - if (!client.isConnected()) { - log.warn("客户端未连接,延迟订阅 [topic: {}]", topicFilter); - return; - } - client.subscribe(topicFilter, qos); - topicHandlers.computeIfAbsent(topicFilter, k -> new ArrayList<>()) - .add(handler); - log.info("订阅成功: {}", topicFilter); - } catch (MqttException e) { - log.error("订阅失败 [topic: {}]", topicFilter); - e.printStackTrace(); - } - } - - private void resubscribeAllTopics() { - topicHandlers.forEach((topic, handlers) -> { - int retry = 0; - while (retry < 3) { - try { - client.subscribe(topic, 1); - log.info("主题重新订阅成功: {}", topic); - break; - } catch (MqttException e) { - retry++; - log.error("重新订阅失败 [topic: {}], 重试 {}/3", topic, retry); - sleep(1000L * retry); - } - } - }); - } - - /** - * 消息到达处理 - * @param topic 主题 - * @param message 消息 - */ - @Override - public void messageArrived(String topic, MqttMessage message) { - - topicHandlers.entrySet().stream() - .filter(entry -> MqttTopic.isMatched(entry.getKey(), topic)) - .flatMap(entry -> entry.getValue().stream()) - .forEach(handler -> { - try { - handler.handleMessage(topic, message); - } catch (Exception e) { - log.error("消息处理异常 [handler: {}]", handler.getClass(), e); - } - }); - } - - @Override - public void connectionLost(Throwable cause) { - log.error("连接丢失", cause); - scheduleReconnect(1); - } - - @Override - public void deliveryComplete(IMqttDeliveryToken token) { - // QoS处理逻辑 - } - - @Override - public void connectComplete(boolean reconnect, String serverURI) { - log.info("连接已建立 [reconnect: {}]", reconnect); - if (reconnect) { - resubscribeAllTopics(); - autoRegisterHandlers(); - } - } - - /** - * 自动注册处理器 - */ - private void autoRegisterHandlers() { - context.getBeansOfType(IMessageHandler.class).values() - .forEach(handler -> { - handler.getTopics().forEach(topic -> - subscribe(topic.getTopicFilter(), topic.getQos(), handler)); - }); - } -} \ No newline at end of file