商品模块属性组增删改
parent
1c064d826b
commit
7310116a85
|
@ -32,6 +32,7 @@ public class TreeEntity extends BaseEntity {
|
|||
/**
|
||||
* 父菜单ID
|
||||
*/
|
||||
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,13 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<!-- 阿里云OSS -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.10.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.file.service;
|
||||
|
||||
import com.muyu.file.utils.FileUploadUtils;
|
||||
import com.muyu.file.utils.OssUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -44,7 +45,9 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|||
@Override
|
||||
public String uploadFile (MultipartFile file) throws Exception {
|
||||
String name = FileUploadUtils.upload(localFilePath, file);
|
||||
String url = domain + localFilePrefix + name;
|
||||
String s = OssUtil.uploadMultipartFile(file);
|
||||
String url = s;
|
||||
System.out.println("==="+url);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
package com.muyu.file.utils;
|
||||
|
||||
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 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||
*/
|
||||
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
|
||||
private static String accessKeyId = "LTAI5tS2MAqRExUpPHy48woQ";
|
||||
private static String accessKeySecret = "tJDYdPm6YOec2glrz0Gq7rzkDdLbnw";
|
||||
private static String accessPre = "https://bwie-master.oss-cn-shanghai.aliyuncs.com/";
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
* @return
|
||||
*/
|
||||
private static String bucketName = "bwie-master";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用File上传PutObject上传文件 ** 程序默认使用次方法上传
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
|
@ -52,4 +52,10 @@ public class AsAttributeGroup extends BaseEntity {
|
|||
.attributeId(attributeId)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static AsAttributeGroup buildGroup (Long attributeGroupId) {
|
||||
return AsAttributeGroup.builder()
|
||||
.groupId(attributeGroupId)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ public class CategoryInfo extends TreeEntity {
|
|||
.image(categoryInfoSaveReq.getImage())
|
||||
.start(categoryInfoSaveReq.getStart())
|
||||
.introduction(categoryInfoSaveReq.getIntroduction())
|
||||
.parentId(categoryInfoSaveReq.getParentId())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -91,6 +92,7 @@ public class CategoryInfo extends TreeEntity {
|
|||
.image(categoryInfoEditReq.getImage())
|
||||
.start(categoryInfoEditReq.getStart())
|
||||
.introduction(categoryInfoEditReq.getIntroduction())
|
||||
.parentId(categoryInfoEditReq.getParentId())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.muyu.product.domain.req;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -33,5 +35,8 @@ public class AttributeGroupEditReq extends BaseEntity {
|
|||
@ApiModelProperty(name = "状态", value = "状态", required = true)
|
||||
private String states;
|
||||
|
||||
private List<Long> attributeIdList;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -48,4 +48,5 @@ public class CategoryInfoSaveReq extends TreeEntity {
|
|||
@ApiModelProperty(name = "介绍", value = "介绍")
|
||||
private String introduction;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@ public class AttributeGroupController extends BaseController {
|
|||
@PutMapping("/{id}")
|
||||
@ApiOperation("修改属性组")
|
||||
public Result<String> edit(@PathVariable Long id, @RequestBody AttributeGroupEditReq attributeGroupEditReq) {
|
||||
attributeGroupService.updateAsAttributeGrop(attributeGroupEditReq,id);
|
||||
return toAjax(attributeGroupService.updateById(AttributeGroup.editBuild(id,attributeGroupEditReq)));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.product.controller;
|
|||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muyu.product.service.AsAttributeGroupService;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -39,6 +40,9 @@ public class AttributeInfoController extends BaseController {
|
|||
@Autowired
|
||||
private AttributeInfoService attributeInfoService;
|
||||
|
||||
@Autowired
|
||||
private AsAttributeGroupService asAttributeGroupService;
|
||||
|
||||
/**
|
||||
* 查询商品属性列表
|
||||
*/
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.muyu.product.mapper;
|
|||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.product.domain.AsAttributeGroup;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 属性与组中间Mapper接口
|
||||
|
@ -10,6 +12,8 @@ import com.muyu.product.domain.AsAttributeGroup;
|
|||
* @author DongZeLiang
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Mapper
|
||||
public interface AsAttributeGroupMapper extends BaseMapper<AsAttributeGroup> {
|
||||
void deleteAsAttributeGroup(@Param("attributeIds") List<Long> attributeIds);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,4 +19,6 @@ public interface AsAttributeGroupService extends IService<AsAttributeGroup> {
|
|||
*/
|
||||
public List<AsAttributeGroup> list(AsAttributeGroup asAttributeGroup);
|
||||
|
||||
void deleteAsAttributeGroup(List<Long> attributeId);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.muyu.product.domain.AttributeGroup;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.product.domain.AttributeInfo;
|
||||
import com.muyu.product.domain.model.AttributeGroupSaveModel;
|
||||
import com.muyu.product.domain.req.AttributeGroupEditReq;
|
||||
import com.muyu.product.domain.resp.AttributeGroupPageResp;
|
||||
|
||||
/**
|
||||
|
@ -39,4 +40,5 @@ public interface AttributeGroupService extends IService<AttributeGroup> {
|
|||
*/
|
||||
public Boolean save(AttributeGroupSaveModel attributeGroupSaveModel);
|
||||
|
||||
void updateAsAttributeGrop(AttributeGroupEditReq attributeGroupEditReq,Long groupId);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.muyu.product.mapper.AsAttributeGroupMapper;
|
||||
import com.muyu.product.domain.AsAttributeGroup;
|
||||
|
@ -21,6 +22,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
@Service
|
||||
public class AsAttributeGroupServiceImpl extends ServiceImpl<AsAttributeGroupMapper, AsAttributeGroup> implements AsAttributeGroupService {
|
||||
|
||||
@Autowired
|
||||
private AsAttributeGroupMapper asAttributeGroupMapper;
|
||||
|
||||
/**
|
||||
* 查询属性与组中间列表
|
||||
*
|
||||
|
@ -46,4 +50,9 @@ public class AsAttributeGroupServiceImpl extends ServiceImpl<AsAttributeGroupMap
|
|||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAsAttributeGroup(List<Long> attributeId) {
|
||||
asAttributeGroupMapper.deleteAsAttributeGroup(attributeId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.muyu.product.domain.AsAttributeGroup;
|
|||
import com.muyu.product.domain.AttributeGroup;
|
||||
import com.muyu.product.domain.AttributeInfo;
|
||||
import com.muyu.product.domain.model.AttributeGroupSaveModel;
|
||||
import com.muyu.product.domain.req.AttributeGroupEditReq;
|
||||
import com.muyu.product.domain.resp.AttributeGroupPageResp;
|
||||
import com.muyu.product.mapper.AttributeGroupMapper;
|
||||
import com.muyu.product.service.AsAttributeGroupService;
|
||||
|
@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
@ -39,6 +41,9 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
|
|||
@Autowired
|
||||
private AttributeInfoService attributeInfoService;
|
||||
|
||||
@Autowired
|
||||
private AsAttributeGroupService asAttributeGroupService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
|
@ -107,4 +112,21 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
|
|||
);
|
||||
return save;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAsAttributeGrop(AttributeGroupEditReq attributeGroupEditReq,Long groupId) {
|
||||
AsAttributeGroup asAttributeGroup = AsAttributeGroup.buildGroup(groupId);
|
||||
List<AsAttributeGroup> list = asAttributeGroupService.list(asAttributeGroup);
|
||||
ArrayList<Long> asAttributeGroupIds = new ArrayList<>();
|
||||
for (AsAttributeGroup attributeGroup : list) {
|
||||
asAttributeGroupIds.add(attributeGroup.getId());
|
||||
}
|
||||
asAttributeGroupService.removeBatchByIds(asAttributeGroupIds);
|
||||
List<Long> attributeIdList = attributeGroupEditReq.getAttributeIdList();
|
||||
attributeGroupService.saveBatch(
|
||||
attributeIdList.stream()
|
||||
.map(attributeId -> AsAttributeGroup.buildGroup(groupId, attributeId))
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.product.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
|
@ -64,6 +65,11 @@ public class AttributeInfoServiceImpl extends ServiceImpl<AttributeInfoMapper, A
|
|||
}
|
||||
LambdaQueryWrapper<AsAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AsAttributeGroup::getGroupId, groupId);
|
||||
List<Long> longs = asAttributeGroupService.list(queryWrapper).stream()
|
||||
.map(AsAttributeGroup::getAttributeId)
|
||||
.toList();
|
||||
System.out.println("====="+longs.toString());
|
||||
List<Long> longs1 = new ArrayList<>();
|
||||
return this.listByIds(
|
||||
asAttributeGroupService.list(queryWrapper).stream()
|
||||
.map(AsAttributeGroup::getAttributeId)
|
||||
|
|
|
@ -18,4 +18,11 @@
|
|||
<sql id="selectAsAttributeGroupVo">
|
||||
select id, group_id, attribute_id, remark, create_by, create_time, update_by, update_time from as_attribute_group
|
||||
</sql>
|
||||
<delete id="deleteAsAttributeGroup">
|
||||
delete from as_attribute_group where attribute_id in (
|
||||
<foreach collection="attributeIds" item="attributeId" separator=",">
|
||||
#{attributeId}
|
||||
</foreach>
|
||||
)
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue