feat(resource): 重构模型相关 mapper 并添加新功能

-重命名 MallProductMapper 为 ModelMapper
- 在 ModelImageMapper 和 ModelMapper 中添加新的查询方法- 更新 ModelProduct 实体,添加 likeNum 字段
- 重构 ModelServiceImpl 和 SysUserAttentionServiceImpl,使用新的 mapper 方法
- 更新 SysUserInfo 实体,增加模型相关统计字段
feature/my-invitation
yang 2025-01-14 15:21:37 +08:00
parent 1cdfb48ae3
commit b8bf961509
9 changed files with 94 additions and 38 deletions

View File

@ -79,6 +79,10 @@ public class ModelProduct extends BaseEntity {
*
*/
private Integer numbers;
/**
*
*/
private Integer likeNum;
/**
*
*/

View File

@ -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;
}

View File

@ -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<ModelImage> {
Long sumLikeNumber(@Param("userId") Long userId);
}

View File

@ -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;
/**
* @AuthorChenYan
* @ProjectMcWl
@ -20,7 +15,7 @@ import java.util.Date;
* @Date2024/12/30 18:23
*/
@Mapper
public interface MallProductMapper extends BaseMapper<ModelProduct> {
public interface ModelMapper extends BaseMapper<ModelProduct> {
@ -29,4 +24,7 @@ public interface MallProductMapper extends BaseMapper<ModelProduct> {
void updateModel(ModelProduct modelProduct);
Long sumLikeNumber(@Param("userId") Long userId);
Long sumRunNumber(Long userId);
}

View File

@ -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<ModelLikeMapper, ModelLike
@Autowired
private MallProductMapper mallProductMapper;
private ModelMapper modelMapper;
@Override
@Transactional
public void like(Long modelId) {
ModelProduct model = mallProductMapper.selectById(modelId);
ModelProduct model = modelMapper.selectById(modelId);
if (Objects.isNull(model)) {
throw new ServiceException("该模型不存在或已下架");
}
@ -51,7 +49,7 @@ public class ModelLikeServiceImpl extends ServiceImpl<ModelLikeMapper, ModelLike
// 更新点赞记录
baseMapper.updateById(modelLike);
// 更新图片点赞数
mallProductMapper.updateById(model);
modelMapper.updateById(model);
return;
}
@ -66,6 +64,6 @@ public class ModelLikeServiceImpl extends ServiceImpl<ModelLikeMapper, ModelLike
// 更新图片点赞数
model.setNumbers(model.getNumbers() + 1);
mallProductMapper.updateById(model);
modelMapper.updateById(model);
}
}

View File

@ -2,7 +2,6 @@ package com.mcwl.resource.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -12,24 +11,19 @@ import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.common.core.redis.RedisCache;
import com.mcwl.common.domain.IdsParam;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.common.utils.StringUtils;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelProduct;
import com.mcwl.resource.domain.ModelVersion;
import com.mcwl.resource.domain.WorkFlowVersion;
import com.mcwl.resource.domain.dto.ModelImagePageRes;
import com.mcwl.resource.domain.request.RequestModel;
import com.mcwl.resource.domain.request.RequestWorkFlow;
import com.mcwl.resource.domain.vo.MallProductVo;
import com.mcwl.resource.domain.vo.ModelImageVo;
import com.mcwl.resource.mapper.MallProductMapper;
import com.mcwl.resource.mapper.ModelMapper;
import com.mcwl.resource.mapper.ModelVersionMapper;
import com.mcwl.resource.service.ModelService;
import com.mcwl.system.service.ISysUserService;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -49,14 +43,14 @@ import java.util.Objects;
*/
@Log4j2
@Service
public class MallProductServiceImpl extends ServiceImpl<MallProductMapper,ModelProduct> implements ModelService {
public class ModelServiceImpl extends ServiceImpl<ModelMapper,ModelProduct> implements ModelService {
@Autowired
private RedisCache redisCache;
@Autowired
private ModelVersionMapper modelVersionMapper;
@Autowired
private MallProductMapper postMapper;
private ModelMapper postMapper;
@Autowired
private ISysUserService sysUserService;

View File

@ -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,6 +40,9 @@ public class SysUserAttentionServiceImpl implements SysUserAttentionService {
@Autowired
private SysUserAttentionMapper sysUserAttentionMapper;
@Autowired
private ModelImageMapper modelImageMapper;
@Override
public AjaxResult addAttention(Long userId) {
@ -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();
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mcwl.resource.mapper.ModelImageMapper">
<select id="sumLikeNumber" resultType="java.lang.Long">
SELECT sum(like_num)sum FROM model_image where user_id = #{userId} ORDER BY(user_id);
</select>
</mapper>

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mcwl.resource.mapper.MallProductMapper">
<mapper namespace="com.mcwl.resource.mapper.ModelMapper">
<update id="updateModel">
update model
<set>
@ -72,7 +72,14 @@
<select id="sumNumber" resultType="java.lang.Long">
SELECT sum(number)sum FROM model where user_id = #{userId} ORDER BY(user_id);
SELECT sum(numbers)sum FROM model where user_id = #{userId} ORDER BY(user_id);
</select>
<select id="sumLikeNumber" resultType="java.lang.Long">
SELECT sum(like_num)sum FROM model where user_id = #{userId} ORDER BY(user_id);
</select>
<select id="sumRunNumber" resultType="java.lang.Long">
SELECT sum(reals)sum FROM model where user_id = #{userId} ORDER BY(user_id);
</select>
</mapper>