商品模块代码提交

This commit is contained in:
Tankaikai
2025-02-13 18:52:22 +08:00
parent 5cc5e87d7f
commit c1b4f06670
16 changed files with 764 additions and 54 deletions

View File

@@ -0,0 +1,16 @@
package com.czg.service.product.mapper;
import com.czg.product.entity.ShopProductSpec;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 商品规格
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-13
*/
@Mapper
public interface ShopProductSpecMapper extends BaseMapper<ShopProductSpec> {
}

View File

@@ -1,11 +1,23 @@
package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.enums.StatusEnum;
import com.czg.exception.CzgException;
import com.czg.product.dto.ShopProdCategoryDTO;
import com.czg.product.entity.ShopProdCategory;
import com.czg.product.service.ShopProdCategoryService;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ShopProdCategoryMapper;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 店铺商品分类
*
@@ -15,4 +27,89 @@ import org.springframework.stereotype.Service;
@Service
public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMapper, ShopProdCategory> implements ShopProdCategoryService {
private QueryWrapper buildQueryWrapper(ShopProdCategoryDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ShopProdCategory::getName, param.getName());
}
Long shopId = StpKit.USER.getLoginIdAsLong();
queryWrapper.eq(ShopProdCategory::getShopId, shopId);
queryWrapper.orderBy(ShopProdCategory::getId, false);
return queryWrapper;
}
@Override
public Page<ShopProdCategoryDTO> page(ShopProdCategoryDTO param) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
return super.pageAs(PageUtil.buildPage(), queryWrapper, ShopProdCategoryDTO.class);
}
@Override
public List<ShopProdCategoryDTO> list(ShopProdCategoryDTO param) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
queryWrapper.eq(ShopProdCategory::getStatus, StatusEnum.ENABLED.value());
return super.listAs(queryWrapper, ShopProdCategoryDTO.class);
}
@Override
public ShopProdCategoryDTO get(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return super.getOneAs(query().eq(ShopProdCategory::getId, id).eq(ShopProdCategory::getShopId, shopId), ShopProdCategoryDTO.class);
}
@Override
public boolean save(ShopProdCategoryDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
boolean exists = super.exists(query().eq(ShopProdCategory::getName, dto.getName()).eq(ShopProdCategory::getShopId, shopId));
if (exists) {
throw new CzgException("商品分类已存在");
}
ShopProdCategory entity = BeanUtil.copyProperties(dto, ShopProdCategory.class);
// 简称
entity.setShortName(dto.getName());
if(entity.getStatus() == null){
entity.setStatus(StatusEnum.ENABLED.value());
}
entity.setPid(0L);
entity.setShopId(shopId);
return super.save(entity);
}
@Override
public boolean update(ShopProdCategoryDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
boolean exists = super.exists(query().eq(ShopProdCategory::getName, dto.getName()).eq(ShopProdCategory::getShopId, shopId).ne(ShopProdCategory::getId, dto.getId()));
if (exists) {
throw new CzgException("商品分类已存在");
}
ShopProdCategory entity = BeanUtil.copyProperties(dto, ShopProdCategory.class);
return super.updateById(entity);
}
@Override
public boolean delete(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return super.remove(query().eq(ShopProdCategory::getId, id).eq(ShopProdCategory::getShopId, shopId));
}
@Override
public boolean disable(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return UpdateChain.of(ShopProdCategory.class)
.set(ShopProdCategory::getStatus, StatusEnum.DISABLE.value())
.eq(ShopProdCategory::getId, id)
.eq(ShopProdCategory::getShopId, shopId)
.update();
}
@Override
public boolean enable(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return UpdateChain.of(ShopProdCategory.class)
.set(ShopProdCategory::getStatus, StatusEnum.ENABLED.value())
.eq(ShopProdCategory::getId, id)
.eq(ShopProdCategory::getShopId, shopId)
.update();
}
}

View File

@@ -0,0 +1,145 @@
package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.constant.GlobalConstant;
import com.czg.enums.StatusEnum;
import com.czg.exception.CzgException;
import com.czg.product.dto.ShopProductSpecDTO;
import com.czg.product.entity.ShopProdCategory;
import com.czg.product.entity.ShopProductSpec;
import com.czg.product.service.ShopProductSpecService;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ShopProductSpecMapper;
import com.czg.utils.PageUtil;
import com.czg.utils.TreeUtils;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 商品规格
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-13
*/
@Service
public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProductSpecMapper, ShopProductSpec> implements ShopProductSpecService {
private QueryWrapper buildQueryWrapper(ShopProductSpecDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ShopProductSpec::getName, param.getName());
}
Long shopId = StpKit.USER.getLoginIdAsLong();
queryWrapper.eq(ShopProductSpec::getShopId, shopId);
queryWrapper.orderBy(ShopProductSpec::getId, false);
return queryWrapper;
}
@Override
public Page<ShopProductSpecDTO> page(ShopProductSpecDTO param) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
return super.pageAs(PageUtil.buildPage(), queryWrapper, ShopProductSpecDTO.class);
}
@Override
public List<ShopProductSpecDTO> list(ShopProductSpecDTO param) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
queryWrapper.eq(ShopProductSpec::getStatus, StatusEnum.ENABLED.value());
List<ShopProductSpecDTO> list = super.listAs(queryWrapper, ShopProductSpecDTO.class);
return TreeUtils.build(list, GlobalConstant.TREE_ROOT);
}
@Override
public ShopProductSpecDTO get(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return super.getOneAs(query().eq(ShopProductSpec::getId, id).eq(ShopProductSpec::getShopId, shopId), ShopProductSpecDTO.class);
}
@Override
public boolean save(ShopProductSpecDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
boolean exists = super.exists(query()
.eq(ShopProductSpec::getName, dto.getName())
.eq(ShopProductSpec::getLevel, dto.getLevel())
.eq(ShopProductSpec::getShopId, shopId));
if (exists) {
throw new CzgException("商品规格已存在");
}
ShopProductSpec entity = BeanUtil.copyProperties(dto, ShopProductSpec.class);
entity.setStatus(StatusEnum.ENABLED.value());
entity.setShopId(shopId);
return super.save(entity);
}
@Override
public boolean update(ShopProductSpecDTO dto) {
//上级规格不能为自身
if (dto.getId().equals(dto.getPid())) {
throw new CzgException("上级规格不能为自身");
}
Long shopId = StpKit.USER.getLoginIdAsLong();
boolean exists = super.exists(query()
.eq(ShopProductSpec::getName, dto.getName())
.eq(ShopProductSpec::getLevel, dto.getLevel())
.eq(ShopProductSpec::getShopId, shopId)
.ne(ShopProductSpec::getId, dto.getId()));
if (exists) {
throw new CzgException("商品规格已存在");
}
ShopProductSpec entity = BeanUtil.copyProperties(dto, ShopProductSpec.class);
return super.updateById(entity);
}
@Override
public boolean delete(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return super.remove(
query().eq(ShopProdCategory::getShopId, shopId)
.and(wrapper -> {
wrapper.eq(ShopProductSpec::getId, id)
.or(wrapper1 -> {
wrapper1.eq(ShopProductSpec::getPid, id);
});
})
);
}
@Override
public boolean disable(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return UpdateChain.of(ShopProductSpec.class)
.set(ShopProductSpec::getStatus, StatusEnum.DISABLE.value())
.where(ShopProductSpec::getShopId).eq(shopId)
.and(wrapper -> {
wrapper.eq(ShopProductSpec::getId, id)
.or(wrapper1 -> {
wrapper1.eq(ShopProductSpec::getPid, id);
});
})
.update();
}
@Override
public boolean enable(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return UpdateChain.of(ShopProductSpec.class)
.set(ShopProductSpec::getStatus, StatusEnum.ENABLED.value())
.where(ShopProductSpec::getShopId).eq(shopId)
.and(wrapper -> {
wrapper.eq(ShopProductSpec::getId, id)
.or(wrapper1 -> {
wrapper1.eq(ShopProductSpec::getPid, id);
});
})
.update();
}
}