From b8bf9615093b5d1ea3ebe3a0f52b05577d81d9d6 Mon Sep 17 00:00:00 2001 From: yang <2119157836@qq.com> Date: Tue, 14 Jan 2025 15:21:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(resource):=20=E9=87=8D=E6=9E=84=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=9B=B8=E5=85=B3=20mapper=20=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -重命名 MallProductMapper 为 ModelMapper - 在 ModelImageMapper 和 ModelMapper 中添加新的查询方法- 更新 ModelProduct 实体,添加 likeNum 字段 - 重构 ModelServiceImpl 和 SysUserAttentionServiceImpl,使用新的 mapper 方法 - 更新 SysUserInfo 实体,增加模型相关统计字段 --- .../mcwl/resource/domain/ModelProduct.java | 4 ++ .../com/mcwl/resource/domain/SysUserInfo.java | 20 ++++++-- .../resource/mapper/ModelImageMapper.java | 2 + ...allProductMapper.java => ModelMapper.java} | 10 ++-- .../service/impl/ModelLikeServiceImpl.java | 12 ++--- ...ServiceImpl.java => ModelServiceImpl.java} | 12 ++--- .../impl/SysUserAttentionServiceImpl.java | 50 +++++++++++++++---- .../mapper/resource/ModelImageMapper.xml | 11 ++++ ...{MallProductMapper.xml => ModelMapper.xml} | 11 +++- 9 files changed, 94 insertions(+), 38 deletions(-) rename mcwl-resource/src/main/java/com/mcwl/resource/mapper/{MallProductMapper.java => ModelMapper.java} (64%) rename mcwl-resource/src/main/java/com/mcwl/resource/service/impl/{MallProductServiceImpl.java => ModelServiceImpl.java} (93%) create mode 100644 mcwl-resource/src/main/resources/mapper/resource/ModelImageMapper.xml rename mcwl-resource/src/main/resources/mapper/resource/{MallProductMapper.xml => ModelMapper.xml} (85%) diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelProduct.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelProduct.java index 41bf7d6..0977b8a 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelProduct.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelProduct.java @@ -79,6 +79,10 @@ public class ModelProduct extends BaseEntity { * 下载次数 */ private Integer numbers; + /** + * 点赞数 + */ + private Integer likeNum; /** * 审核状态 */ diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/SysUserInfo.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/SysUserInfo.java index 626986b..64b7333 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/domain/SysUserInfo.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/SysUserInfo.java @@ -29,12 +29,24 @@ public class SysUserInfo { private Long bean = 0L; /** - * 下载次数 + * 模型下载次数 */ - private Long download = 0L; + private Long modelDownloadNum = 0L; /** - * 点赞次数 + * 模型运行次数 */ - private Long likeCount = 0L; + private Long modelRunNum = 0L; + + + /** + * 模型点赞次数 + */ + private Long modelLikeNum = 0L; + + /** + * 图片点赞次数 + */ + private Long imageLikeNum = 0L; + } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageMapper.java index 76579d0..b7e422c 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageMapper.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageMapper.java @@ -3,7 +3,9 @@ package com.mcwl.resource.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.mcwl.resource.domain.ModelImage; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; @Mapper public interface ModelImageMapper extends BaseMapper { + Long sumLikeNumber(@Param("userId") Long userId); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/MallProductMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelMapper.java similarity index 64% rename from mcwl-resource/src/main/java/com/mcwl/resource/mapper/MallProductMapper.java rename to mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelMapper.java index 394a47d..63bc3a8 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/MallProductMapper.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelMapper.java @@ -1,16 +1,11 @@ package com.mcwl.resource.mapper; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mcwl.resource.domain.ModelProduct; -import com.mcwl.resource.domain.ModelVersion; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import java.util.Date; - /** * @Author:ChenYan * @Project:McWl @@ -20,7 +15,7 @@ import java.util.Date; * @Date:2024/12/30 18:23 */ @Mapper -public interface MallProductMapper extends BaseMapper { +public interface ModelMapper extends BaseMapper { @@ -29,4 +24,7 @@ public interface MallProductMapper extends BaseMapper { void updateModel(ModelProduct modelProduct); + Long sumLikeNumber(@Param("userId") Long userId); + + Long sumRunNumber(Long userId); } 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 0226104..b0f2810 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 @@ -4,14 +4,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mcwl.common.exception.ServiceException; import com.mcwl.common.utils.SecurityUtils; import com.mcwl.resource.domain.*; -import com.mcwl.resource.domain.vo.MallProductVo; -import com.mcwl.resource.mapper.MallProductMapper; +import com.mcwl.resource.mapper.ModelMapper; import com.mcwl.resource.mapper.ModelLikeMapper; import com.mcwl.resource.service.ModelLikeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import springfox.documentation.swagger2.mappers.ModelMapper; import java.util.Date; import java.util.Objects; @@ -29,12 +27,12 @@ public class ModelLikeServiceImpl extends ServiceImpl implements ModelService { +public class ModelServiceImpl extends ServiceImpl implements ModelService { @Autowired private RedisCache redisCache; @Autowired private ModelVersionMapper modelVersionMapper; @Autowired - private MallProductMapper postMapper; + private ModelMapper postMapper; @Autowired private ISysUserService sysUserService; diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SysUserAttentionServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SysUserAttentionServiceImpl.java index 5971fea..ff7e245 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SysUserAttentionServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SysUserAttentionServiceImpl.java @@ -1,12 +1,18 @@ package com.mcwl.resource.service.impl; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.mcwl.common.core.domain.AjaxResult; import com.mcwl.common.utils.SecurityUtils; +import com.mcwl.resource.domain.ModelProduct; import com.mcwl.resource.domain.SysUserAttention; import com.mcwl.resource.domain.SysUserInfo; import com.mcwl.resource.mapper.MallProductLikeMapper; -import com.mcwl.resource.mapper.MallProductMapper; +import com.mcwl.resource.mapper.ModelImageMapper; +import com.mcwl.resource.mapper.ModelMapper; import com.mcwl.resource.mapper.SysUserAttentionMapper; +import com.mcwl.resource.service.ModelImageService; +import com.mcwl.resource.service.ModelService; import com.mcwl.resource.service.SysUserAttentionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -26,7 +32,7 @@ public class SysUserAttentionServiceImpl implements SysUserAttentionService { @Autowired - private MallProductMapper mallProductMapper; + private ModelMapper modelMapper; @Autowired private MallProductLikeMapper mallProductLikeMapper; @@ -34,14 +40,17 @@ public class SysUserAttentionServiceImpl implements SysUserAttentionService { @Autowired private SysUserAttentionMapper sysUserAttentionMapper; + @Autowired + private ModelImageMapper modelImageMapper; + @Override public AjaxResult addAttention(Long userId) { //查看是否已关注 Boolean aBoolean = selectAttention(userId); - if (aBoolean == true){ + if (aBoolean == true) { //取关 - sysUserAttentionMapper.deleteByUserId(SecurityUtils.getUserId(),userId); + sysUserAttentionMapper.deleteByUserId(SecurityUtils.getUserId(), userId); return AjaxResult.success(false); } @@ -58,9 +67,9 @@ public class SysUserAttentionServiceImpl implements SysUserAttentionService { @Override public Boolean selectAttention(Long userId) { - SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserId(),userId); + SysUserAttention sysUserAttention = sysUserAttentionMapper.selectAttention(SecurityUtils.getUserId(), userId); - if (sysUserAttention == null){ + if (sysUserAttention == null) { return false; } @@ -71,9 +80,30 @@ public class SysUserAttentionServiceImpl implements SysUserAttentionService { public SysUserInfo selectUserInfo() { Long userId = SecurityUtils.getUserId(); - return SysUserInfo.builder().bean(sysUserAttentionMapper.selectBean(userId)) -// .download(mallProductMapper.sumNumber(userId)) - .likeCount(mallProductLikeMapper.countLike(userId)) - .attention(sysUserAttentionMapper.selectAttentionCount(userId)).build(); + // 粉丝数 + Long userBeanNum = sysUserAttentionMapper.selectBean(userId); + + // 关注数 + Long userAttentionNum = sysUserAttentionMapper.selectAttentionCount(userId); + + // 模型下载数 + Long modelDownloadNum = modelMapper.sumNumber(userId); + + // 模型运行次数 + Long modelRunNum = modelMapper.sumRunNumber(userId); + + // 模型点赞次数 + Long modelLikeNum = modelMapper.sumLikeNumber(userId); + + // 图片点赞次数 + Long imageLikeNum = modelImageMapper.sumLikeNumber(userId); + + return SysUserInfo.builder().bean(userBeanNum) + .attention(userAttentionNum) + .modelDownloadNum(modelDownloadNum) + .modelRunNum(modelRunNum) + .modelLikeNum(modelLikeNum) + .imageLikeNum(imageLikeNum) + .build(); } } diff --git a/mcwl-resource/src/main/resources/mapper/resource/ModelImageMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/ModelImageMapper.xml new file mode 100644 index 0000000..03e7d4b --- /dev/null +++ b/mcwl-resource/src/main/resources/mapper/resource/ModelImageMapper.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/mcwl-resource/src/main/resources/mapper/resource/MallProductMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/ModelMapper.xml similarity index 85% rename from mcwl-resource/src/main/resources/mapper/resource/MallProductMapper.xml rename to mcwl-resource/src/main/resources/mapper/resource/ModelMapper.xml index 4a24f81..dea5ddd 100644 --- a/mcwl-resource/src/main/resources/mapper/resource/MallProductMapper.xml +++ b/mcwl-resource/src/main/resources/mapper/resource/ModelMapper.xml @@ -2,7 +2,7 @@ - + update model @@ -72,7 +72,14 @@ + + +