Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.czg.product.entity.ProdGroup;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 商品分组
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProdGroupMapper extends BaseMapper<ProdGroup> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.czg.product.entity.ProdGroupRelation;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 商品分组关系
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProdGroupRelationMapper extends BaseMapper<ProdGroupRelation> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import com.czg.product.dto.ProdGroupRelationDTO;
|
||||
import com.czg.product.entity.ProdGroupRelation;
|
||||
import com.czg.product.service.ProdGroupRelationService;
|
||||
import com.czg.service.product.mapper.ProdGroupRelationMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 商品分组关系
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
@Service
|
||||
public class ProdGroupRelationServiceImpl extends ServiceImpl<ProdGroupRelationMapper, ProdGroupRelation> implements ProdGroupRelationService {
|
||||
|
||||
private QueryWrapper buildQueryWrapper(ProdGroupRelationDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.enums.StatusEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.product.dto.ProdGroupDTO;
|
||||
import com.czg.product.dto.ProductBriefDTO;
|
||||
import com.czg.product.entity.ProdGroup;
|
||||
import com.czg.product.entity.ProdGroupRelation;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.service.ProdGroupService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.product.mapper.ProdGroupMapper;
|
||||
import com.czg.service.product.mapper.ProdGroupRelationMapper;
|
||||
import com.czg.service.product.mapper.ProductMapper;
|
||||
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 lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品分组
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup> implements ProdGroupService {
|
||||
|
||||
private final ProdGroupRelationMapper prodGroupRelationMapper;
|
||||
|
||||
private final ProductMapper productMapper;
|
||||
|
||||
private QueryWrapper buildQueryWrapper(ProdGroupDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
if (StrUtil.isNotEmpty(param.getName())) {
|
||||
queryWrapper.like(ProdGroup::getName, param.getName());
|
||||
}
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
queryWrapper.eq(ProdGroup::getShopId, shopId);
|
||||
queryWrapper.orderBy(ProdGroup::getId, false);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProdGroupDTO> getProdGroupPage(ProdGroupDTO param) {
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||
return super.pageAs(PageUtil.buildPage(), queryWrapper, ProdGroupDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProdGroupDTO> getProdGroupList(ProdGroupDTO param) {
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||
queryWrapper.eq(ProdGroup::getStatus, StatusEnum.ENABLED.value());
|
||||
return super.listAs(queryWrapper, ProdGroupDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProdGroupDTO getProdGroupById(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
ProdGroupDTO dto = super.getOneAs(query().eq(ProdGroup::getId, id).eq(ProdGroup::getShopId, shopId), ProdGroupDTO.class);
|
||||
List<Long> productIdList = prodGroupRelationMapper.selectObjectListByQueryAs(query().select(ProdGroupRelation::getProductId).eq(ProdGroupRelation::getProdGroupId, id), Long.class);
|
||||
if (CollUtil.isNotEmpty(productIdList)) {
|
||||
List<ProductBriefDTO> productList = productMapper.selectListByQueryAs(query().select(Product::getId, Product::getName, Product::getCoverImg).in(Product::getId, productIdList), ProductBriefDTO.class);
|
||||
dto.setProductList(productList);
|
||||
} else {
|
||||
dto.setProductList(new ArrayList<>());
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean addProdGroup(ProdGroupDTO dto) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
boolean exists = super.exists(query().eq(ProdGroup::getName, dto.getName()).eq(ProdGroup::getShopId, shopId));
|
||||
if (exists) {
|
||||
throw new CzgException("商品分组已存在");
|
||||
}
|
||||
ProdGroup entity = BeanUtil.copyProperties(dto, ProdGroup.class);
|
||||
entity.setShopId(shopId);
|
||||
super.save(entity);
|
||||
Long[] productIds = dto.getProductIds();
|
||||
if (ArrayUtil.isNotEmpty(productIds)) {
|
||||
int sort = 0;
|
||||
for (Long productId : productIds) {
|
||||
sort++;
|
||||
ProdGroupRelation prodGroupRelation = new ProdGroupRelation();
|
||||
prodGroupRelation.setProductId(productId);
|
||||
prodGroupRelation.setProdGroupId(entity.getId());
|
||||
prodGroupRelation.setSort(sort);
|
||||
prodGroupRelationMapper.insert(prodGroupRelation);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateProdGroup(ProdGroupDTO dto) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
dto.setShopId(shopId);
|
||||
boolean exists = super.exists(query().eq(ProdGroup::getName, dto.getName()).eq(ProdGroup::getShopId, shopId).ne(ProdGroup::getId, dto.getId()));
|
||||
if (exists) {
|
||||
throw new CzgException("商品分组已存在");
|
||||
}
|
||||
ProdGroup entity = BeanUtil.copyProperties(dto, ProdGroup.class);
|
||||
super.updateById(entity);
|
||||
prodGroupRelationMapper.deleteByQuery(query().eq(ProdGroupRelation::getProdGroupId, entity.getId()));
|
||||
Long[] productIds = dto.getProductIds();
|
||||
if (ArrayUtil.isNotEmpty(productIds)) {
|
||||
int sort = 0;
|
||||
for (Long productId : productIds) {
|
||||
sort++;
|
||||
ProdGroupRelation prodGroupRelation = new ProdGroupRelation();
|
||||
prodGroupRelation.setProductId(productId);
|
||||
prodGroupRelation.setProdGroupId(entity.getId());
|
||||
prodGroupRelation.setSort(sort);
|
||||
prodGroupRelationMapper.insert(prodGroupRelation);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteProdGroup(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
super.remove(query().eq(ProdGroup::getId, id).eq(ProdGroup::getShopId, shopId));
|
||||
prodGroupRelationMapper.deleteByQuery(query().eq(ProdGroupRelation::getProdGroupId, id));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disableProdGroup(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
return UpdateChain.of(ProdGroup.class)
|
||||
.set(ProdGroup::getStatus, StatusEnum.DISABLE.value())
|
||||
.eq(ProdGroup::getId, id)
|
||||
.eq(ProdGroup::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enableProdGroup(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
return UpdateChain.of(ProdGroup.class)
|
||||
.set(ProdGroup::getStatus, StatusEnum.ENABLED.value())
|
||||
.eq(ProdGroup::getId, id)
|
||||
.eq(ProdGroup::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?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.czg.service.product.mapper.ProdGroupMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?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.czg.service.product.mapper.ProdGroupRelationMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user