商品模块属性组增删改

product
yaoxin 2024-03-01 19:25:04 +08:00
parent 1c064d826b
commit 7310116a85
17 changed files with 238 additions and 1 deletions

View File

@ -32,6 +32,7 @@ public class TreeEntity extends BaseEntity {
/** /**
* ID * ID
*/ */
private Long parentId; private Long parentId;
/** /**

View File

@ -17,6 +17,13 @@
<dependencies> <dependencies>
<!-- 阿里云OSS -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.10.2</version>
</dependency>
<!-- SpringCloud Alibaba Nacos --> <!-- SpringCloud Alibaba Nacos -->
<dependency> <dependency>
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>

View File

@ -1,6 +1,7 @@
package com.muyu.file.service; package com.muyu.file.service;
import com.muyu.file.utils.FileUploadUtils; import com.muyu.file.utils.FileUploadUtils;
import com.muyu.file.utils.OssUtil;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -44,7 +45,9 @@ public class LocalSysFileServiceImpl implements ISysFileService {
@Override @Override
public String uploadFile (MultipartFile file) throws Exception { public String uploadFile (MultipartFile file) throws Exception {
String name = FileUploadUtils.upload(localFilePath, file); 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; return url;
} }
} }

View File

@ -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 AccessKeyaccessKeySecretAPI访 访
*/
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;
}
/**
* 使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

@ -52,4 +52,10 @@ public class AsAttributeGroup extends BaseEntity {
.attributeId(attributeId) .attributeId(attributeId)
.build(); .build();
} }
public static AsAttributeGroup buildGroup (Long attributeGroupId) {
return AsAttributeGroup.builder()
.groupId(attributeGroupId)
.build();
}
} }

View File

@ -78,6 +78,7 @@ public class CategoryInfo extends TreeEntity {
.image(categoryInfoSaveReq.getImage()) .image(categoryInfoSaveReq.getImage())
.start(categoryInfoSaveReq.getStart()) .start(categoryInfoSaveReq.getStart())
.introduction(categoryInfoSaveReq.getIntroduction()) .introduction(categoryInfoSaveReq.getIntroduction())
.parentId(categoryInfoSaveReq.getParentId())
.build(); .build();
} }
@ -91,6 +92,7 @@ public class CategoryInfo extends TreeEntity {
.image(categoryInfoEditReq.getImage()) .image(categoryInfoEditReq.getImage())
.start(categoryInfoEditReq.getStart()) .start(categoryInfoEditReq.getStart())
.introduction(categoryInfoEditReq.getIntroduction()) .introduction(categoryInfoEditReq.getIntroduction())
.parentId(categoryInfoEditReq.getParentId())
.build(); .build();
} }

View File

@ -1,6 +1,8 @@
package com.muyu.product.domain.req; package com.muyu.product.domain.req;
import java.util.Date; import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -33,5 +35,8 @@ public class AttributeGroupEditReq extends BaseEntity {
@ApiModelProperty(name = "状态", value = "状态", required = true) @ApiModelProperty(name = "状态", value = "状态", required = true)
private String states; private String states;
private List<Long> attributeIdList;
} }

View File

@ -48,4 +48,5 @@ public class CategoryInfoSaveReq extends TreeEntity {
@ApiModelProperty(name = "介绍", value = "介绍") @ApiModelProperty(name = "介绍", value = "介绍")
private String introduction; private String introduction;
} }

View File

@ -99,6 +99,7 @@ public class AttributeGroupController extends BaseController {
@PutMapping("/{id}") @PutMapping("/{id}")
@ApiOperation("修改属性组") @ApiOperation("修改属性组")
public Result<String> edit(@PathVariable Long id, @RequestBody AttributeGroupEditReq attributeGroupEditReq) { public Result<String> edit(@PathVariable Long id, @RequestBody AttributeGroupEditReq attributeGroupEditReq) {
attributeGroupService.updateAsAttributeGrop(attributeGroupEditReq,id);
return toAjax(attributeGroupService.updateById(AttributeGroup.editBuild(id,attributeGroupEditReq))); return toAjax(attributeGroupService.updateById(AttributeGroup.editBuild(id,attributeGroupEditReq)));
} }

View File

@ -3,6 +3,7 @@ package com.muyu.product.controller;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.muyu.product.service.AsAttributeGroupService;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -39,6 +40,9 @@ public class AttributeInfoController extends BaseController {
@Autowired @Autowired
private AttributeInfoService attributeInfoService; private AttributeInfoService attributeInfoService;
@Autowired
private AsAttributeGroupService asAttributeGroupService;
/** /**
* *
*/ */

View File

@ -3,6 +3,8 @@ package com.muyu.product.mapper;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.product.domain.AsAttributeGroup; import com.muyu.product.domain.AsAttributeGroup;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/** /**
* Mapper * Mapper
@ -10,6 +12,8 @@ import com.muyu.product.domain.AsAttributeGroup;
* @author DongZeLiang * @author DongZeLiang
* @date 2024-02-27 * @date 2024-02-27
*/ */
@Mapper
public interface AsAttributeGroupMapper extends BaseMapper<AsAttributeGroup> { public interface AsAttributeGroupMapper extends BaseMapper<AsAttributeGroup> {
void deleteAsAttributeGroup(@Param("attributeIds") List<Long> attributeIds);
} }

View File

@ -19,4 +19,6 @@ public interface AsAttributeGroupService extends IService<AsAttributeGroup> {
*/ */
public List<AsAttributeGroup> list(AsAttributeGroup asAttributeGroup); public List<AsAttributeGroup> list(AsAttributeGroup asAttributeGroup);
void deleteAsAttributeGroup(List<Long> attributeId);
} }

View File

@ -7,6 +7,7 @@ import com.muyu.product.domain.AttributeGroup;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.product.domain.AttributeInfo; import com.muyu.product.domain.AttributeInfo;
import com.muyu.product.domain.model.AttributeGroupSaveModel; 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.domain.resp.AttributeGroupPageResp;
/** /**
@ -39,4 +40,5 @@ public interface AttributeGroupService extends IService<AttributeGroup> {
*/ */
public Boolean save(AttributeGroupSaveModel attributeGroupSaveModel); public Boolean save(AttributeGroupSaveModel attributeGroupSaveModel);
void updateAsAttributeGrop(AttributeGroupEditReq attributeGroupEditReq,Long groupId);
} }

View File

@ -4,6 +4,7 @@ import java.util.List;
import com.muyu.common.core.utils.ObjUtils; import com.muyu.common.core.utils.ObjUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.muyu.product.mapper.AsAttributeGroupMapper; import com.muyu.product.mapper.AsAttributeGroupMapper;
import com.muyu.product.domain.AsAttributeGroup; import com.muyu.product.domain.AsAttributeGroup;
@ -21,6 +22,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@Service @Service
public class AsAttributeGroupServiceImpl extends ServiceImpl<AsAttributeGroupMapper, AsAttributeGroup> implements AsAttributeGroupService { 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); return list(queryWrapper);
} }
@Override
public void deleteAsAttributeGroup(List<Long> attributeId) {
asAttributeGroupMapper.deleteAsAttributeGroup(attributeId);
}
} }

View File

@ -9,6 +9,7 @@ import com.muyu.product.domain.AsAttributeGroup;
import com.muyu.product.domain.AttributeGroup; import com.muyu.product.domain.AttributeGroup;
import com.muyu.product.domain.AttributeInfo; import com.muyu.product.domain.AttributeInfo;
import com.muyu.product.domain.model.AttributeGroupSaveModel; 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.domain.resp.AttributeGroupPageResp;
import com.muyu.product.mapper.AttributeGroupMapper; import com.muyu.product.mapper.AttributeGroupMapper;
import com.muyu.product.service.AsAttributeGroupService; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -39,6 +41,9 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
@Autowired @Autowired
private AttributeInfoService attributeInfoService; private AttributeInfoService attributeInfoService;
@Autowired
private AsAttributeGroupService asAttributeGroupService;
/** /**
* *
* *
@ -107,4 +112,21 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
); );
return save; 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()
);
}
} }

View File

@ -1,5 +1,6 @@
package com.muyu.product.service.impl; package com.muyu.product.service.impl;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.muyu.common.core.exception.ServiceException; import com.muyu.common.core.exception.ServiceException;
@ -64,6 +65,11 @@ public class AttributeInfoServiceImpl extends ServiceImpl<AttributeInfoMapper, A
} }
LambdaQueryWrapper<AsAttributeGroup> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AsAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsAttributeGroup::getGroupId, groupId); 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( return this.listByIds(
asAttributeGroupService.list(queryWrapper).stream() asAttributeGroupService.list(queryWrapper).stream()
.map(AsAttributeGroup::getAttributeId) .map(AsAttributeGroup::getAttributeId)

View File

@ -18,4 +18,11 @@
<sql id="selectAsAttributeGroupVo"> <sql id="selectAsAttributeGroupVo">
select id, group_id, attribute_id, remark, create_by, create_time, update_by, update_time from as_attribute_group select id, group_id, attribute_id, remark, create_by, create_time, update_by, update_time from as_attribute_group
</sql> </sql>
<delete id="deleteAsAttributeGroup">
delete from as_attribute_group where attribute_id in (
<foreach collection="attributeIds" item="attributeId" separator=",">
#{attributeId}
</foreach>
)
</delete>
</mapper> </mapper>