Merge branch 'feature/admin' into preview

feature/comment
Diyu0904 2025-01-03 10:41:55 +08:00
commit 904235425f
12 changed files with 454 additions and 9 deletions

View File

@ -0,0 +1,153 @@
package com.mcwl.web.controller.common;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.PutObjectRequest;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.time.LocalDateTime;
import java.util.UUID;
/**
* Oss
*/
@Log4j2
public class OssUtil {
/**
* Endpoint AccessKeyaccessKeySecretAPI访 访
*/
private static String endPoint = "oss-cn-beijing.aliyuncs.com";
private static String accessKeyId = "LTAI5tSHZZ8wHJRP8X4r9TXT";
private static String accessKeySecret = "F82IVNx0IGJ3AnP6gSIfcyql1HCXIH";
private static String accessPre = "https://ybl2112.oss-cn-beijing.aliyuncs.com/";
/**
* bucket
* @return
*/
private static String bucketName = "ybl2112";
private static OSS ossClient ;
static {
ossClient = new OSSClientBuilder().build(
endPoint,
accessKeyId,
accessKeySecret);
log.info("oss服务连接成功");
}
/**
*
* @param filePath
*/
public static String uploadFile(String filePath){
return uploadFileForBucket(bucketName,getOssFilePath(filePath) ,filePath);
}
/**
* multipartFile
* @param multipartFile
*/
public static String uploadMultipartFile(MultipartFile multipartFile) {
return uploadMultipartFile(bucketName,getOssFilePath(multipartFile.getOriginalFilename()),multipartFile);
}
/**
* multipartFile
* @param bucketName
* @param ossPath
* @param multipartFile
*/
public static String uploadMultipartFile(String bucketName , String ossPath , MultipartFile multipartFile){
InputStream inputStream = null;
try {
inputStream = multipartFile.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
return accessPre+ossPath;
}
/**
* 使FilePutObject ** 使
* @param bucketName
* @param ossPath oss
* @param filePath
*/
public static String uploadFileForBucket(String bucketName , String ossPath , String filePath) {
// 创建PutObjectRequest对象。
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
// 上传
ossClient.putObject(putObjectRequest);
return accessPre+ossPath;
}
/**
* 使bucket
* @param bucketName
* @param ossPath oss
* @param filePath
*/
public static String uploadFileInputStreamForBucket(String bucketName , String ossPath , String filePath){
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
InputStream inputStream = null;
try {
inputStream = new FileInputStream(filePath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
return accessPre+ossPath;
}
public static void uploadFileInputStreamForBucket(String bucketName , String ossPath , InputStream inputStream ){
ossClient.putObject(bucketName, ossPath, inputStream);
}
/**
*
* @param ossFilePath
* @param filePath
*/
public static void downloadFile(String ossFilePath , String filePath ){
downloadFileForBucket(bucketName , ossFilePath , filePath);
}
/**
*
* @param bucketName
* @param ossFilePath oss
* @param filePath
*/
public static void downloadFileForBucket(String bucketName , String ossFilePath , String filePath ){
ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
}
/**
*
* @return
*/
public static String getOssDefaultPath(){
LocalDateTime now = LocalDateTime.now();
String url =
now.getYear()+"/"+
now.getMonth()+"/"+
now.getDayOfMonth()+"/"+
now.getHour()+"/"+
now.getMinute()+"/";
return url;
}
public static String getOssFilePath(String filePath){
String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
}
}

View File

@ -1,16 +1,20 @@
package com.mcwl.web.controller.resource;
import com.mcwl.common.annotation.Anonymous;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcwl.common.core.controller.BaseController;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.common.domain.IdsParam;
import com.mcwl.resource.domain.MallProduct;
import com.mcwl.resource.service.MallProductService;
import com.mcwl.resource.domain.vo.MallProductVo;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.web.controller.resource
@ -83,4 +87,15 @@ public class MallProductController extends BaseController {
return success();
}
/**
*
* @return
*/
@PostMapping("/selectByUserId")
public AjaxResult selectByUserId(@RequestBody MallProductVo mallProductVo){
Page<MallProduct> mallProductList = mallProductRuleInfoService.selectByUserId(mallProductVo);
return AjaxResult.success(mallProductList);
}
}

View File

@ -0,0 +1,31 @@
package com.mcwl.web.controller.resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.resource.domain.MallProduct;
import com.mcwl.resource.domain.vo.MallProductVo;
import com.mcwl.resource.service.MallProductLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
*
* @author DaiZibo
* @date 2025/1/2
* @apiNote
*/
@RequestMapping("like")
@RestController
public class MallProductLikeController {
@Autowired
private MallProductLikeService mallProductLikeService;
@PostMapping("/selectByUserLike")
public AjaxResult selectByUserLike(@RequestBody MallProductVo mallProductVo){
Page<MallProduct> mallProductPage = mallProductLikeService.selectByUserLike(mallProductVo);
return AjaxResult.success(mallProductPage);
}
}

View File

@ -14,13 +14,12 @@ import com.mcwl.system.domain.SysUserThirdAccount;
import com.mcwl.system.service.ISysUserService;
import com.mcwl.system.service.ISysUserThirdAccountService;
import com.mcwl.system.service.IWXService;
import com.mcwl.web.controller.common.OssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
@ -60,6 +59,14 @@ public class WXController {
@Resource
private SysPermissionService permissionService;
@Anonymous
@PostMapping("/test")
public AjaxResult test(@RequestParam MultipartFile file){
String s = OssUtil.uploadMultipartFile(file);
return AjaxResult.success(s);
}
/**
* uuid
*/

View File

@ -0,0 +1,40 @@
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.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
*
*
* @author DaiZibo
* @date 2025/1/2
* @apiNote
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class MallProductLike extends BaseEntity {
@TableId
private Long id;
private Long userId;
private Long productId;
private String createName;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
}

View File

@ -0,0 +1,60 @@
package com.mcwl.resource.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
*
*
* @author DaiZibo
* @date 2025/1/2
* @apiNote
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class MallProductVo {
/**
*
*/
private Long status;
/**
*
*/
private Long order;
/**
*
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date startTime;
/**
*
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date endTime;
/**
*
*/
private Integer pageNumber;
/**
*
*/
private Integer pageSize;
}

View File

@ -0,0 +1,18 @@
package com.mcwl.resource.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author DaiZibo
* @date 2025/1/2
* @apiNote
*/
@Mapper
public interface MallProductLikeMapper {
List<Long> selectByUserId(@Param("userId") Long userId);
}

View File

@ -0,0 +1,15 @@
package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcwl.resource.domain.MallProduct;
import com.mcwl.resource.domain.vo.MallProductVo;
/**
* @author DaiZibo
* @date 2025/1/2
* @apiNote
*/
public interface MallProductLikeService {
Page<MallProduct> selectByUserLike(MallProductVo mallProductVo);
}

View File

@ -1,9 +1,10 @@
package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.common.domain.IdsParam;
import com.mcwl.resource.domain.MallProduct;
import kotlin.Result;
import com.mcwl.resource.domain.vo.MallProductVo;
import java.util.List;
@ -29,4 +30,7 @@ public interface MallProductService extends IService<MallProduct> {
void deleteMallProductByIds(IdsParam ids);
Page<MallProduct> selectByUserId(MallProductVo mallProductVo);
Page<MallProduct> pageLike(MallProductVo mallProductVo, List<Long> list);
}

View File

@ -0,0 +1,40 @@
package com.mcwl.resource.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.resource.domain.MallProduct;
import com.mcwl.resource.domain.vo.MallProductVo;
import com.mcwl.resource.mapper.MallProductLikeMapper;
import com.mcwl.resource.service.MallProductLikeService;
import com.mcwl.resource.service.MallProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author DaiZibo
* @date 2025/1/2
* @apiNote
*/
@Service
public class MallProductLikeServiceImpl implements MallProductLikeService {
@Autowired
private MallProductLikeMapper mallProductLikeMapper;
@Autowired
private MallProductService mallProductService;
@Override
public Page<MallProduct> selectByUserLike(MallProductVo mallProductVo) {
//获取登录人
Long userId = SecurityUtils.getUserId();
List<Long> list = mallProductLikeMapper.selectByUserId(userId);
//分页查询作品数据
return mallProductService.pageLike(mallProductVo,list);
}
}

View File

@ -1,12 +1,15 @@
package com.mcwl.resource.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.domain.IdsParam;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.resource.domain.MallProduct;
import com.mcwl.resource.mapper.MallProductMapper;
import com.mcwl.resource.service.MallProductService;
import kotlin.Result;
import com.mcwl.resource.domain.vo.MallProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -24,8 +27,6 @@ import java.util.List;
@Service
public class MallProductServiceImpl extends ServiceImpl<MallProductMapper,MallProduct> implements MallProductService {
@Autowired
private MallProductMapper postMapper;
@ -59,5 +60,55 @@ public class MallProductServiceImpl extends ServiceImpl<MallProductMapper,MallPr
postMapper.deleteBatchIds(ids.getIds());
}
@Override
public Page<MallProduct> selectByUserId(MallProductVo mallProductVo) {
// 创建分页对象
Page<MallProduct> mallProductPage = new Page<>(mallProductVo.getPageNumber(), mallProductVo.getPageSize());
//获取当前登录人ID
Long userId = SecurityUtils.getUserId();
LambdaQueryWrapper<MallProduct> mallProductLambdaQueryWrapper = new LambdaQueryWrapper<>();
mallProductLambdaQueryWrapper.eq(MallProduct::getUserId,userId);
mallProductLambdaQueryWrapper.eq(MallProduct::getDelFlag,0);
if (mallProductVo.getStatus() != 0){
mallProductLambdaQueryWrapper.eq(MallProduct::getStatus,mallProductVo.getStatus());
}
if (mallProductVo.getOrder() == 1){
mallProductLambdaQueryWrapper.orderByDesc(MallProduct::getProductId);
}else {
}
// 开始时间和结束时间过滤
if (mallProductVo.getStartTime() != null && mallProductVo.getEndTime() != null) {
// 查询开始时间和结束时间之间的商品
mallProductLambdaQueryWrapper.between(MallProduct::getCreateTime, mallProductVo.getStartTime(), mallProductVo.getEndTime());
} else if (mallProductVo.getStartTime() != null) {
// 只有开始时间,查询大于等于开始时间的商品
mallProductLambdaQueryWrapper.ge(MallProduct::getCreateTime, mallProductVo.getStartTime());
} else if (mallProductVo.getEndTime() != null) {
// 只有结束时间,查询小于等于结束时间的商品
mallProductLambdaQueryWrapper.le(MallProduct::getCreateTime, mallProductVo.getEndTime());
}
return postMapper.selectPage(mallProductPage, mallProductLambdaQueryWrapper);
}
@Override
public Page<MallProduct> pageLike(MallProductVo mallProductVo, List<Long> list) {
// 创建分页对象
Page<MallProduct> mallProductPage = new Page<>(mallProductVo.getPageNumber(), mallProductVo.getPageSize());
LambdaQueryWrapper<MallProduct> mallProductLambdaQueryWrapper = new LambdaQueryWrapper<>();
mallProductLambdaQueryWrapper.in(MallProduct::getProductId,list);
return postMapper.selectPage(mallProductPage,mallProductLambdaQueryWrapper);
}
}

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.MallProductLikeMapper">
<select id="selectByUserId" resultType="java.lang.Long">
select product_id FROM mall_product_like WHERE user_id = #{userId}
</select>
</mapper>