package cc.mrbird.febs.mall.service.impl;
|
|
import cc.mrbird.febs.common.entity.FebsResponse;
|
import cc.mrbird.febs.common.enumerates.ClothesEnum;
|
import cc.mrbird.febs.common.enumerates.StateUpDownEnum;
|
import cc.mrbird.febs.common.exception.FebsException;
|
import cc.mrbird.febs.common.utils.LoginUserUtil;
|
import cc.mrbird.febs.mall.dto.clothes.*;
|
import cc.mrbird.febs.mall.entity.*;
|
import cc.mrbird.febs.mall.mapper.*;
|
import cc.mrbird.febs.mall.service.ApiClothesService;
|
import cc.mrbird.febs.mall.vo.ApiActivityInfoVo;
|
import cc.mrbird.febs.mall.vo.clothes.*;
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Set;
|
import java.util.stream.Collectors;
|
|
@Slf4j
|
@Service
|
@RequiredArgsConstructor
|
public class ApiClothesServiceImpl extends ServiceImpl<ClothesTypeMapper, ClothesType> implements ApiClothesService {
|
|
private final ClothesTypeMapper clothesTypeMapper;
|
private final ClothesTypeClothMapper clothesTypeClothMapper;
|
private final ClothesTypePatternMapper clothesTypePatternMapper;
|
private final ClothesTypeSizeMapper clothesTypeSizeMapper;
|
private final ClothesSizeMapper clothesSizeMapper;
|
private final ClothesPatternMapper clothesPatternMapper;
|
private final ClothesLocationMapper clothesLocationMapper;
|
private final ClothesClothMapper clothesClothMapper;
|
private final ClothesArtMapper clothesArtMapper;
|
private final ClothesTypeLocationMapper clothesTypeLocationMapper;
|
private final ClothesTypeArtMapper clothesTypeArtMapper;
|
private final ClothesMemberStatureMapper clothesMemberStatureMapper;
|
private final ClothesOrderDraftMapper clothesOrderDraftMapper;
|
|
@Override
|
public FebsResponse clothesType() {
|
List<ApiClothesTypeListVo> vos = new ArrayList<>();
|
|
List<ClothesType> clothesTypes = clothesTypeMapper.selectList(
|
Wrappers.lambdaQuery(ClothesType.class)
|
.eq(ClothesType::getState, ClothesEnum.UP.getCode())
|
.orderByAsc(ClothesType::getOrderNum)
|
);
|
if (CollUtil.isNotEmpty(clothesTypes)){
|
for (ClothesType clothesType : clothesTypes){
|
ApiClothesTypeListVo vo = new ApiClothesTypeListVo();
|
vo.setId(clothesType.getId());
|
vo.setName(clothesType.getName());
|
vo.setImage(clothesType.getImage());
|
vo.setContent(clothesType.getContent());
|
vo.setOrderNum(clothesType.getOrderNum());
|
vos.add( vo);
|
}
|
}
|
|
return new FebsResponse().success().data(vos);
|
}
|
|
@Override
|
public FebsResponse typeInfo(ApiTypeInfoDto dto) {
|
ApiClothesTypeVo apiClothesTypeVo = new ApiClothesTypeVo();
|
|
Long id = dto.getId();
|
ClothesType clothesType = clothesTypeMapper.selectById(id);
|
if (ObjectUtil.isNotEmpty(clothesType)){
|
apiClothesTypeVo.setId(clothesType.getId());
|
apiClothesTypeVo.setName(clothesType.getName());
|
apiClothesTypeVo.setImage(clothesType.getImage());
|
apiClothesTypeVo.setImageFront(clothesType.getImageFront());
|
apiClothesTypeVo.setImageBack(clothesType.getImageBack());
|
apiClothesTypeVo.setContent(clothesType.getContent());
|
apiClothesTypeVo.setClothState(clothesType.getClothState());
|
apiClothesTypeVo.setArtState(clothesType.getArtState());
|
apiClothesTypeVo.setPatternState(clothesType.getPatternState());
|
apiClothesTypeVo.setLocationState(clothesType.getLocationState());
|
apiClothesTypeVo.setSizeState(clothesType.getSizeState());
|
}
|
|
return new FebsResponse().success().data(apiClothesTypeVo);
|
}
|
|
@Override
|
public FebsResponse clothList(ApiClothesClothPageDto dto) {
|
// 创建分页对象,传入当前页和每页大小
|
Page<ApiClothesClothVo> page = new Page<>(dto.getPageNow(), dto.getPageSize());
|
// 调用Mapper方法获取活动分页数据
|
Page<ApiClothesClothVo> voPage = clothesTypeClothMapper.selectPageInCloth(page, dto);
|
|
return new FebsResponse().success().data(voPage);
|
}
|
|
@Override
|
public FebsResponse patternList(ApiClothesPatternPageDto dto) {
|
// 创建分页对象,传入当前页和每页大小
|
Page<ApiClothesPatternVo> page = new Page<>(dto.getPageNow(), dto.getPageSize());
|
// 调用Mapper方法获取活动分页数据
|
Page<ApiClothesPatternVo> voPage = clothesTypePatternMapper.selectPageInPattern(page, dto);
|
|
return new FebsResponse().success().data(voPage);
|
}
|
|
@Override
|
public FebsResponse sizeList(ApiClothesSizeDto dto) {
|
List<ApiClothesSizeVo> vos = new ArrayList<>();
|
|
Long typeId = dto.getTypeId();
|
List<ClothesTypeSize> clothesTypeSizes = clothesTypeSizeMapper.selectList(
|
Wrappers.lambdaQuery(ClothesTypeSize.class)
|
.eq(ClothesTypeSize::getTypeId, typeId)
|
);
|
if (CollUtil.isNotEmpty(clothesTypeSizes)){
|
|
Set<Long> collect = clothesTypeSizes.stream().map(ClothesTypeSize::getSizeId).collect(Collectors.toSet());
|
List<ClothesSize> clothesSizes = clothesSizeMapper.selectList(
|
Wrappers.lambdaQuery(ClothesSize.class)
|
.in(ClothesSize::getId, collect)
|
|
);
|
|
if (CollUtil.isNotEmpty(clothesSizes)){
|
for (ClothesSize clothesSize : clothesSizes){
|
ApiClothesSizeVo vo = new ApiClothesSizeVo();
|
vo.setId(clothesSize.getId());
|
vo.setCode(clothesSize.getCode());
|
vo.setName(clothesSize.getName());
|
vo.setImage(clothesSize.getImage());
|
vo.setContent(clothesSize.getContent());
|
vo.setPrice(clothesSize.getPrice());
|
vo.setType(clothesSize.getType());
|
vos.add(vo);
|
}
|
}
|
}
|
|
return new FebsResponse().success().data(vos);
|
}
|
|
@Override
|
public FebsResponse locationList(ApiClothesLocationPageDto dto) {
|
// 创建分页对象,传入当前页和每页大小
|
Page<ApiClothesLocationVo> page = new Page<>(dto.getPageNow(), dto.getPageSize());
|
// 调用Mapper方法获取活动分页数据
|
Page<ApiClothesLocationVo> voPage = clothesTypeLocationMapper.selectPageInLocation(page, dto);
|
|
return new FebsResponse().success().data(voPage);
|
}
|
|
@Override
|
public FebsResponse artList(ApiClothesArtPageDto dto) {
|
// 创建分页对象,传入当前页和每页大小
|
Page<ApiClothesArtVo> page = new Page<>(dto.getPageNow(), dto.getPageSize());
|
// 调用Mapper方法获取活动分页数据
|
Page<ApiClothesArtVo> voPage = clothesTypeArtMapper.selectPageInArt(page, dto);
|
|
return new FebsResponse().success().data(voPage);
|
}
|
|
@Override
|
public FebsResponse statureList(ApiClothesMemberStatureDto dto) {
|
|
Long memberId = LoginUserUtil.getLoginUser().getId();
|
dto.setMemberId(memberId);
|
// 创建分页对象,传入当前页和每页大小
|
Page<ApiClothesMemberStatureVo> page = new Page<>(dto.getPageNow(), dto.getPageSize());
|
// 调用Mapper方法获取活动分页数据
|
Page<ApiClothesMemberStatureVo> voPage = clothesMemberStatureMapper.selectPageInMemberStature(page, dto);
|
|
return new FebsResponse().success().data(voPage);
|
}
|
|
@Override
|
public FebsResponse statureAdd(ApiClothesMemberStatureAddDto dto) {
|
|
Long memberId = LoginUserUtil.getLoginUser().getId();
|
ClothesMemberStature clothesMemberStature = new ClothesMemberStature();
|
clothesMemberStature.setMemberId(memberId);
|
clothesMemberStature.setName(dto.getName());
|
clothesMemberStature.setHeightLine(dto.getHeightLine());
|
clothesMemberStature.setBustLine(dto.getBustLine());
|
clothesMemberStature.setWaistLine(dto.getWaistLine());
|
clothesMemberStature.setWideLine(dto.getWideLine());
|
clothesMemberStature.setHipLine(dto.getHipLine());
|
clothesMemberStature.setState(dto.getState());
|
clothesMemberStatureMapper.insert(clothesMemberStature);
|
|
if(ClothesEnum.UP.getCode() == dto.getState()){
|
clothesMemberStatureMapper.update(null,
|
Wrappers.lambdaUpdate(ClothesMemberStature.class)
|
.set(ClothesMemberStature::getState, ClothesEnum.DOWN.getCode())
|
.eq(ClothesMemberStature::getMemberId, memberId)
|
.ne(ClothesMemberStature::getId, clothesMemberStature.getId())
|
.eq(ClothesMemberStature::getDelFlag, ClothesEnum.DOWN.getCode())
|
);
|
}
|
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public FebsResponse statureInfo(ApiClothesMemberStatureInfoDto dto) {
|
Long memberId = LoginUserUtil.getLoginUser().getId();
|
|
ApiClothesMemberStatureVo apiClothesMemberStatureVo = new ApiClothesMemberStatureVo();
|
ClothesMemberStature clothesMemberStature = clothesMemberStatureMapper.selectById(dto.getId());
|
if (ObjectUtil.isNotEmpty(clothesMemberStature)){
|
apiClothesMemberStatureVo.setId(clothesMemberStature.getId());
|
apiClothesMemberStatureVo.setName(clothesMemberStature.getName());
|
apiClothesMemberStatureVo.setHeightLine(clothesMemberStature.getHeightLine());
|
apiClothesMemberStatureVo.setBustLine(clothesMemberStature.getBustLine());
|
apiClothesMemberStatureVo.setWaistLine(clothesMemberStature.getWaistLine());
|
apiClothesMemberStatureVo.setWideLine(clothesMemberStature.getWideLine());
|
apiClothesMemberStatureVo.setHipLine(clothesMemberStature.getHipLine());
|
apiClothesMemberStatureVo.setState(clothesMemberStature.getState());
|
}
|
|
return new FebsResponse().success().data(apiClothesMemberStatureVo);
|
}
|
|
@Override
|
public FebsResponse statureUpdate(ApiClothesMemberStatureUpdateDto dto) {
|
|
Long memberId = LoginUserUtil.getLoginUser().getId();
|
ClothesMemberStature clothesMemberStature = clothesMemberStatureMapper.selectById(dto.getId());
|
if (ObjectUtil.isNotEmpty(clothesMemberStature)){
|
clothesMemberStature.setName(dto.getName());
|
clothesMemberStature.setHeightLine(dto.getHeightLine());
|
clothesMemberStature.setBustLine(dto.getBustLine());
|
clothesMemberStature.setWaistLine(dto.getWaistLine());
|
clothesMemberStature.setWideLine(dto.getWideLine());
|
clothesMemberStature.setHipLine(dto.getHipLine());
|
clothesMemberStature.setState(dto.getState());
|
clothesMemberStatureMapper.updateById(clothesMemberStature);
|
|
if(ClothesEnum.UP.getCode() == dto.getState()){
|
clothesMemberStatureMapper.update(null,
|
Wrappers.lambdaUpdate(ClothesMemberStature.class)
|
.set(ClothesMemberStature::getState, ClothesEnum.DOWN.getCode())
|
.eq(ClothesMemberStature::getMemberId, memberId)
|
.ne(ClothesMemberStature::getId, clothesMemberStature.getId())
|
.eq(ClothesMemberStature::getDelFlag, ClothesEnum.DOWN.getCode())
|
);
|
}
|
}
|
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public FebsResponse statureDel(ApiClothesMemberStatureInfoDto dto) {
|
Long memberId = LoginUserUtil.getLoginUser().getId();
|
clothesMemberStatureMapper.update(null,
|
Wrappers.lambdaUpdate(ClothesMemberStature.class)
|
.set(ClothesMemberStature::getDelFlag, ClothesEnum.UP.getCode())
|
.eq(ClothesMemberStature::getId, dto.getId())
|
.eq(ClothesMemberStature::getMemberId, memberId)
|
);
|
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse draftSave(ApiMyDraftSaveDto dto) {
|
Long memberId = LoginUserUtil.getLoginUser().getId();
|
|
ClothesOrderDraft clothesOrderDraft = new ClothesOrderDraft();
|
clothesOrderDraft.setMemberId(memberId);
|
|
Long typeId = ObjectUtil.defaultIfNull(dto.getTypeId(),0L);
|
ClothesType clothesType = clothesTypeMapper.selectById(typeId);
|
if (ObjectUtil.isNull(clothesType)){
|
throw new FebsException("请选择商品");
|
}
|
if (ClothesEnum.UP.getCode() != clothesType.getState()){
|
throw new FebsException("商品已下架");
|
}
|
clothesOrderDraft.setTypeId(typeId);
|
|
Long sizeId = ObjectUtil.defaultIfNull(dto.getSizeId(),0L);
|
ClothesSize clothesSize = clothesSizeMapper.selectById(sizeId);
|
if (ObjectUtil.isNull(clothesSize)){
|
throw new FebsException("请选择尺码");
|
}
|
clothesOrderDraft.setSizeId(sizeId);
|
|
Long patternId = ObjectUtil.defaultIfNull(dto.getPatternId(),0L);
|
ClothesPattern pattern = clothesPatternMapper.selectById(patternId);
|
if (ObjectUtil.isNull(pattern)){
|
throw new FebsException("请选择图案");
|
}
|
clothesOrderDraft.setPatternId(patternId);
|
if(StrUtil.isNotBlank(dto.getPatternRemark())){
|
clothesOrderDraft.setPatternRemark(dto.getPatternRemark());
|
}
|
|
Long locationId = ObjectUtil.defaultIfNull(dto.getLocationId(),0L);
|
ClothesLocation clothesLocation = clothesLocationMapper.selectById(locationId);
|
if (ObjectUtil.isNull(clothesLocation)){
|
throw new FebsException("请选择图案位置");
|
}
|
clothesOrderDraft.setLocationId(locationId);
|
|
Long clothId = ObjectUtil.defaultIfNull(dto.getClothId(),0L);
|
ClothesCloth clothesCloth = clothesClothMapper.selectById(clothId);
|
if (ObjectUtil.isNull(clothesCloth)){
|
throw new FebsException("请选择布料");
|
}
|
clothesOrderDraft.setClothId(clothId);
|
|
Long artId = ObjectUtil.defaultIfNull(dto.getArtId(),0L);
|
ClothesArt clothesArt = clothesArtMapper.selectById(artId);
|
if (ObjectUtil.isNull(clothesArt)){
|
throw new FebsException("请选择工艺");
|
}
|
clothesOrderDraft.setArtId(artId);
|
|
Long statureId = ObjectUtil.defaultIfNull(dto.getStatureId(),0L);
|
ClothesMemberStature clothesMemberStature = clothesMemberStatureMapper.selectById(statureId);
|
if (ObjectUtil.isNull(clothesMemberStature)){
|
throw new FebsException("请选择身材数据");
|
}
|
clothesOrderDraft.setStatureId(clothesMemberStature.getId());
|
|
clothesOrderDraftMapper.insert(clothesOrderDraft);
|
|
return new FebsResponse().success().message("操作成功");
|
}
|
}
|