商品模块代码提交
This commit is contained in:
parent
1daef6efba
commit
aa98f8cc89
|
|
@ -0,0 +1,101 @@
|
|||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.log.annotation.OperationLog;
|
||||
import com.czg.product.dto.ProdGroupDTO;
|
||||
import com.czg.product.service.ProdGroupService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 商品分组
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/admin/prod/group")
|
||||
public class ProdGroupController {
|
||||
private final ProdGroupService prodGroupService;
|
||||
|
||||
@GetMapping("page")
|
||||
@OperationLog("商品分组-分页")
|
||||
//@SaAdminCheckPermission("prodGroup:page")
|
||||
public CzgResult<Page<ProdGroupDTO>> getProdGroupPage(ProdGroupDTO param){
|
||||
Page<ProdGroupDTO> data = prodGroupService.getProdGroupPage(param);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
@OperationLog("商品分组-列表")
|
||||
//@SaAdminCheckPermission("prodGroup:list")
|
||||
public CzgResult<List<ProdGroupDTO>> getProdGroupList(ProdGroupDTO param){
|
||||
List<ProdGroupDTO> data = prodGroupService.getProdGroupList(param);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@OperationLog("商品分组-详情")
|
||||
//@SaAdminCheckPermission("prodGroup:info")
|
||||
public CzgResult<ProdGroupDTO> getProdGroupById(@PathVariable("id") Long id){
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
ProdGroupDTO data = prodGroupService.getProdGroupById(id);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@OperationLog("商品分组-新增")
|
||||
//@SaAdminCheckPermission("prodGroup:add")
|
||||
public CzgResult<Void> addProdGroup(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ProdGroupDTO dto){
|
||||
prodGroupService.addProdGroup(dto);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@OperationLog("商品分组-修改")
|
||||
//@SaAdminCheckPermission("prodGroup:update")
|
||||
public CzgResult<Void> updateProdGroup(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ProdGroupDTO dto){
|
||||
prodGroupService.updateProdGroup(dto);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@OperationLog("商品分组-删除")
|
||||
//@SaAdminCheckPermission("prodGroup:delete")
|
||||
public CzgResult<Void> deleteProdGroup(@PathVariable("id") Long id){
|
||||
//效验数据
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
prodGroupService.deleteProdGroup(id);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("disable/{id}")
|
||||
@OperationLog("商品分组-禁用")
|
||||
//@SaAdminCheckPermission("prodGroup:able")
|
||||
public CzgResult<Void> disableProdGroup(@PathVariable("id") Long id) {
|
||||
//效验数据
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
prodGroupService.disableProdGroup(id);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("enable/{id}")
|
||||
@OperationLog("商品分组-启用")
|
||||
//@SaAdminCheckPermission("prodGroup:able")
|
||||
public CzgResult<Void> enableProdGroup(@PathVariable("id") Long id) {
|
||||
//效验数据
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
prodGroupService.enableProdGroup(id);
|
||||
return CzgResult.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package com.czg.product.dto;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import com.czg.validator.group.Group;
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Null;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品分组
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
@Data
|
||||
public class ProdGroupDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@Null(message = "ID必须为空", groups = InsertGroup.class)
|
||||
@NotNull(message = "ID不能为空", groups = UpdateGroup.class)
|
||||
private Long id;
|
||||
/**
|
||||
* 分组名称
|
||||
*/
|
||||
@NotBlank(message = "分组名称不能为空", groups = DefaultGroup.class)
|
||||
private String name;
|
||||
/**
|
||||
* 店铺Id
|
||||
*/
|
||||
private Long shopId;
|
||||
/**
|
||||
* 图标
|
||||
*/
|
||||
private String pic;
|
||||
/**
|
||||
* 状态 0-禁用 1-启用
|
||||
*/
|
||||
@NotNull(message = "状态不能为空", groups = Group.class)
|
||||
private Integer status;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@NotNull(message = "排序值不能为空", groups = DefaultGroup.class)
|
||||
@Min(value = 0, message = "排序值不能小于0", groups = DefaultGroup.class)
|
||||
private Integer sort;
|
||||
/**
|
||||
* 排序方式 0-默认; 1-价格从高到低; 2-销量由高到低;
|
||||
*/
|
||||
@NotNull(message = "排序方式不能为空", groups = Group.class)
|
||||
private String sortMode;
|
||||
/**
|
||||
* 开启时间管控 0:否;1:是
|
||||
*/
|
||||
@NotNull(message = "售卖时间管控不能为空", groups = Group.class)
|
||||
private Integer useTime;
|
||||
/**
|
||||
* 售卖开始时间
|
||||
*/
|
||||
@JSONField(format = "HH:mm:ss")
|
||||
private LocalTime saleStartTime;
|
||||
/**
|
||||
* 售卖结束时间
|
||||
*/
|
||||
@JSONField(format = "HH:mm:ss")
|
||||
private LocalTime saleEndTime;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 商品ID数组
|
||||
*/
|
||||
private Long[] productIds;
|
||||
|
||||
/**
|
||||
* 商品简要信息列表
|
||||
*/
|
||||
private List<ProductBriefDTO> productList;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.czg.product.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品分组关系
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
@Data
|
||||
public class ProdGroupRelationDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 商品分组id
|
||||
*/
|
||||
private Long prodGroupId;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.czg.product.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品简要信息
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-16
|
||||
*/
|
||||
@Data
|
||||
public class ProductBriefDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 商品封面图
|
||||
*/
|
||||
private String coverImg;
|
||||
}
|
||||
|
|
@ -95,7 +95,7 @@ public class ProductDTO implements Serializable {
|
|||
/**
|
||||
* 商品封面图
|
||||
*/
|
||||
@NotBlank(message = "商品名称不能为空", groups = DefaultGroup.class)
|
||||
@NotBlank(message = "商品封面图不能为空", groups = DefaultGroup.class)
|
||||
private String coverImg;
|
||||
/**
|
||||
* 商品图片(第一张为缩略图,其他为详情)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
package com.czg.product.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
/**
|
||||
* 商品分组
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
@Data
|
||||
@Table("tb_prod_group")
|
||||
public class ProdGroup implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
/**
|
||||
* 分组名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 店铺Id
|
||||
*/
|
||||
private Long shopId;
|
||||
/**
|
||||
* 图标
|
||||
*/
|
||||
private String pic;
|
||||
/**
|
||||
* 状态 0-禁用 1-启用
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 排序方式 0-默认; 1-价格从高到低; 2-销量由高到低;
|
||||
*/
|
||||
private String sortMode;
|
||||
/**
|
||||
* 开启时间管控 0:否;1:是
|
||||
*/
|
||||
private Integer useTime;
|
||||
/**
|
||||
* 售卖开始时间
|
||||
*/
|
||||
private LocalTime saleStartTime;
|
||||
/**
|
||||
* 售卖结束时间
|
||||
*/
|
||||
private LocalTime saleEndTime;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.czg.product.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品分组关系
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
@Data
|
||||
@Table("tb_prod_group_relation")
|
||||
public class ProdGroupRelation implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
@Id(keyType = KeyType.None)
|
||||
private Long productId;
|
||||
/**
|
||||
* 商品分组id
|
||||
*/
|
||||
@Id(keyType = KeyType.None)
|
||||
private Long prodGroupId;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
private Integer sort;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.czg.product.service;
|
||||
|
||||
import com.czg.product.entity.ProdGroupRelation;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
/**
|
||||
* 商品分组关系
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
public interface ProdGroupRelationService extends IService<ProdGroupRelation> {
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.czg.product.service;
|
||||
|
||||
import com.czg.product.dto.ProdGroupDTO;
|
||||
import com.czg.product.entity.ProdGroup;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品分组
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-17
|
||||
*/
|
||||
public interface ProdGroupService extends IService<ProdGroup> {
|
||||
Page<ProdGroupDTO> getProdGroupPage(ProdGroupDTO param);
|
||||
|
||||
List<ProdGroupDTO> getProdGroupList(ProdGroupDTO param);
|
||||
|
||||
ProdGroupDTO getProdGroupById(Long id);
|
||||
|
||||
boolean addProdGroup(ProdGroupDTO dto);
|
||||
|
||||
boolean deleteProdGroup(Long id);
|
||||
|
||||
boolean updateProdGroup(ProdGroupDTO dto);
|
||||
|
||||
boolean disableProdGroup(Long id);
|
||||
|
||||
boolean enableProdGroup(Long id);
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package com.czg.product.vo;
|
|||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -26,6 +27,6 @@ public class ProductGroupVo {
|
|||
private String skuName;
|
||||
private BigDecimal price;
|
||||
private String number;
|
||||
private String unitName;
|
||||
private LocalTime unitName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
Loading…
Reference in New Issue