feat(resource): 添加模型图片上传和评论功能

- 新增 ModelImage、ModelImageComment 和 ModelImageLike 等相关实体类
- 实现图片上传、发布和点赞功能
- 添加评论和评论点赞功能
- 集成支付宝支付相关配置和接口
feature/comment
yang 2025-01-10 13:58:06 +08:00
parent 9cd8da3803
commit 1eeec91626
23 changed files with 702 additions and 17 deletions

View File

@ -28,11 +28,11 @@
<!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java -->
<!-- <dependency>-->
<!-- <groupId>com.alipay.sdk</groupId>-->
<!-- <artifactId>alipay-sdk-java</artifactId>-->
<!-- <version>4.40.30.ALL</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.40.30.ALL</version>
</dependency>
<dependency>

View File

@ -1,6 +1,7 @@
package com.mcwl;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.mcwl.pay.config.AliConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
@ -8,6 +9,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
/**
@ -16,6 +18,7 @@ import org.springframework.context.annotation.Bean;
* @author mcwl
*/
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@EnableConfigurationProperties(AliConfig.class)
public class McWlApplication
{
public static void main(String[] args)

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,65 @@
package com.mcwl.web.controller.resource;
import cn.hutool.core.bean.BeanUtil;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.common.utils.oss.OssUtil;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageLike;
import com.mcwl.resource.domain.dto.ModelImageRes;
import com.mcwl.resource.service.ModelImageLikeService;
import com.mcwl.resource.service.ModelImageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
import java.util.Objects;
@RestController
@RequestMapping("/modelImage")
@RequiredArgsConstructor
public class ModelImageController {
private final ModelImageService modelImageService;
private final ModelImageLikeService modelImageLikeService;
/**
*
*/
@GetMapping("/upload")
public AjaxResult upload(MultipartFile file) {
return AjaxResult.success("上传成功", OssUtil.uploadMultipartFile(file));
}
/**
*
*/
@PostMapping("/publish")
public AjaxResult publish(@RequestBody ModelImageRes modelImageRes) {
ModelImage modelImage = new ModelImage();
BeanUtil.copyProperties(modelImageRes, modelImage);
modelImage.setCreateBy(SecurityUtils.getUsername());
modelImage.setUpdateBy(SecurityUtils.getUsername());
modelImage.setUpdateTime(new Date());
modelImage.setStatus(3);
modelImageService.save(modelImage);
return AjaxResult.success();
}
/**
* /
*/
@GetMapping("/like/{imageId}")
public AjaxResult like(@PathVariable Long imageId) {
modelImageLikeService.like(imageId);
return AjaxResult.success();
}
}

View File

@ -0,0 +1,19 @@
package com.mcwl.pay.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
@Data
@ConfigurationProperties(prefix = "mall.mgt.aliPayConfig")
@Configuration
@Component
public class AliConfig {
private String appId;
private String privateKey;
private String publicKey;
private String gatewayUrl;
}

View File

@ -1,8 +1,11 @@
package com.mcwl.resource.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.mcwl.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
@ -16,47 +19,66 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("model_image")
public class ModelImage {
public class ModelImage extends BaseEntity {
/**
* ID
*/
@TableId
private Long id;
/**
* 8
*/
private Long image_paths;
private String imagePaths;
/**
*
*/
private Long has_watermark;
private Integer hasWatermark;
/**
*
*/
private Long is_member_download;
private Integer isMemberDownload;
/**
*
*/
private Long is_not_downloadable;
private Integer isNotDownloadable;
/**
*
*/
private Long hide_gen_info;
private Integer hideGenInfo;
/**
* 30
*/
private Long title;
private String title;
/**
*
*/
private Long tags;
private String tags;
/**
* 500
*/
private Long description;
private String description;
/**
* 0 2
* 线
*/
private Long del_flag;
private Integer onlineGenNum;
/**
*
*/
private Integer downloadNum;
/**
*
*/
private Integer returnNum;
/**
*
*/
private Integer likeNum;
/**
*
*/
private Integer status;
}

View File

@ -0,0 +1,45 @@
package com.mcwl.resource.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.mcwl.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("model_image_comment")
public class ModelImageComment extends BaseEntity {
@TableId
private Long id;
/**
* id
*/
private Long userId;
/**
* id
*/
private Long modelImageId;
/**
*
*/
private String content;
/**
* id
*/
private Long parentId;
/**
*
*/
private Integer likeNum;
}

View File

@ -0,0 +1,30 @@
package com.mcwl.resource.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.mcwl.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
*
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("model_image_comment_like")
public class ModelImageCommentLike extends BaseEntity {
@TableId
private Long id;
/**
* id
*/
private Long userId;
private Long modelImageCommentId;
}

View File

@ -0,0 +1,35 @@
package com.mcwl.resource.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mcwl.common.core.domain.BaseEntity;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
*
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Data
public class ModelImageLike extends BaseEntity {
@TableId
private Long id;
/**
* id
*/
private Long userId;
/**
* id
*/
private Long modelImageId;
}

View File

@ -0,0 +1,45 @@
package com.mcwl.resource.domain.dto;
import lombok.Builder;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class ModelImageRes {
/**
* 8
*/
@NotBlank(message = "图片地址不能为空")
private String imagePaths;
/**
*
*/
private Integer hasWatermark;
/**
*
*/
private Integer isMemberDownload;
/**
*
*/
private Integer isNotDownloadable;
/**
*
*/
private Integer hideGenInfo;
/**
* 30
*/
@NotBlank(message = "图片标题不能为空")
private String title;
/**
*
*/
private String tags;
/**
* 500
*/
private String description;
}

View File

@ -0,0 +1,10 @@
package com.mcwl.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.resource.domain.ModelImageComment;
import com.mcwl.resource.domain.ModelImageCommentLike;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ModelImageCommentLikeMapper extends BaseMapper<ModelImageCommentLike> {
}

View File

@ -0,0 +1,10 @@
package com.mcwl.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageComment;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ModelImageCommentMapper extends BaseMapper<ModelImageComment> {
}

View File

@ -0,0 +1,11 @@
package com.mcwl.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageLike;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ModelImageLikeMapper extends BaseMapper<ModelImageLike> {
ModelImageLike getLikeImage(Long userId, Long imageId);
}

View File

@ -0,0 +1,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;
@Mapper
public interface ModelImageMapper extends BaseMapper<ModelImage> {
}

View File

@ -0,0 +1,9 @@
package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.resource.domain.ModelImageComment;
import com.mcwl.resource.domain.ModelImageCommentLike;
public interface ModelImageCommentLikeService extends IService<ModelImageCommentLike> {
}

View File

@ -0,0 +1,9 @@
package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageComment;
public interface ModelImageCommentService extends IService<ModelImageComment> {
}

View File

@ -0,0 +1,11 @@
package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageLike;
public interface ModelImageLikeService extends IService<ModelImageLike> {
void like(Long imageId);
}

View File

@ -0,0 +1,12 @@
package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelProduct;
import com.mcwl.resource.domain.vo.MallProductVo;
public interface ModelImageService extends IService<ModelImage> {
}

View File

@ -0,0 +1,15 @@
package com.mcwl.resource.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.resource.domain.ModelImageComment;
import com.mcwl.resource.domain.ModelImageCommentLike;
import com.mcwl.resource.mapper.ModelImageCommentLikeMapper;
import com.mcwl.resource.mapper.ModelImageCommentMapper;
import com.mcwl.resource.service.ModelImageCommentLikeService;
import com.mcwl.resource.service.ModelImageCommentService;
import org.springframework.stereotype.Service;
@Service
public class ModelImageCommentLikeServiceImpl extends ServiceImpl<ModelImageCommentLikeMapper, ModelImageCommentLike> implements ModelImageCommentLikeService {
}

View File

@ -0,0 +1,15 @@
package com.mcwl.resource.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageComment;
import com.mcwl.resource.mapper.ModelImageCommentMapper;
import com.mcwl.resource.mapper.ModelImageMapper;
import com.mcwl.resource.service.ModelImageCommentService;
import com.mcwl.resource.service.ModelImageService;
import org.springframework.stereotype.Service;
@Service
public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentMapper, ModelImageComment> implements ModelImageCommentService {
}

View File

@ -0,0 +1,63 @@
package com.mcwl.resource.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.exception.ServiceException;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageLike;
import com.mcwl.resource.mapper.ModelImageLikeMapper;
import com.mcwl.resource.mapper.ModelImageMapper;
import com.mcwl.resource.service.ModelImageLikeService;
import com.mcwl.resource.service.ModelImageService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.Objects;
@Service
@RequiredArgsConstructor
public class ModelImageLikeServiceImpl extends ServiceImpl<ModelImageLikeMapper, ModelImageLike> implements ModelImageLikeService {
private final ModelImageMapper modelImageMapper;
@Override
@Transactional
public void like(Long imageId) {
ModelImage modelImage = modelImageMapper.selectById(imageId);
if (Objects.isNull(modelImage)) {
throw new ServiceException("该图片不存在或已下架");
}
Long userId = SecurityUtils.getUserId();
ModelImageLike modelImageLike = baseMapper.getLikeImage(userId, imageId);
if (Objects.nonNull(modelImageLike)) {
if (Objects.equals(modelImageLike.getDelFlag(), "0")) {
modelImageLike.setDelFlag("1");
modelImage.setLikeNum(modelImage.getLikeNum() - 1);
} else {
modelImageLike.setDelFlag("0");
modelImage.setLikeNum(modelImage.getLikeNum() + 1);
}
// 更新点赞记录
baseMapper.updateById(modelImageLike);
// 更新图片点赞数
modelImageMapper.updateById(modelImage);
return;
}
// 添加点赞记录
modelImageLike = new ModelImageLike();
modelImageLike.setUserId(userId);
modelImageLike.setModelImageId(imageId);
modelImageLike.setCreateBy(SecurityUtils.getUsername());
modelImageLike.setUpdateBy(SecurityUtils.getUsername());
modelImageLike.setUpdateTime(new Date());
baseMapper.insert(modelImageLike);
// 更新图片点赞数
modelImage.setLikeNum(modelImage.getLikeNum() + 1);
modelImageMapper.updateById(modelImage);
}
}

View File

@ -0,0 +1,25 @@
package com.mcwl.resource.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.resource.domain.MallProductLike;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelProduct;
import com.mcwl.resource.domain.vo.MallProductVo;
import com.mcwl.resource.mapper.MallProductLikeMapper;
import com.mcwl.resource.mapper.ModelImageMapper;
import com.mcwl.resource.service.MallProductLikeService;
import com.mcwl.resource.service.MallProductService;
import com.mcwl.resource.service.ModelImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelImage> implements ModelImageService {
}

View File

@ -0,0 +1,38 @@
<?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.ModelImageLikeMapper">
<resultMap type="modelImageLike" id="ModelImageLikeResult">
<id property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="modelImageId" column="model_image_id"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectModelImageLikeVo">
select id,
user_id,
model_image_id,
create_by,
create_time,
update_by,
update_time,
del_flag,
remark
from model_image_like
</sql>
<select id="getLikeImage" resultMap="ModelImageLikeResult">
<include refid="selectModelImageLikeVo"/>
where user_id = #{userId}
and model_image_id = #{imageId}
</select>
</mapper>