商品模块代码提交
This commit is contained in:
parent
2244fee745
commit
9d86c376ec
|
|
@ -1,8 +1,8 @@
|
||||||
package com.czg.controller;
|
package com.czg.controller;
|
||||||
|
|
||||||
import com.czg.log.annotation.OperationLog;
|
import com.czg.log.annotation.OperationLog;
|
||||||
import com.czg.product.dto.ShopProductSpecDTO;
|
import com.czg.product.dto.ShopProdSpecDTO;
|
||||||
import com.czg.product.service.ShopProductSpecService;
|
import com.czg.product.service.ShopProdSpecService;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import com.czg.validator.ValidatorUtil;
|
import com.czg.validator.ValidatorUtil;
|
||||||
|
|
@ -16,85 +16,85 @@ import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品规格
|
* 商品规格
|
||||||
*
|
*
|
||||||
* @author Tankaikai tankaikai@aliyun.com
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
* @since 1.0 2025-02-13
|
* @since 1.0 2025-02-13
|
||||||
*/
|
*/
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/admin/prod/spec")
|
@RequestMapping("/admin/prod/spec")
|
||||||
public class ShopProductSpecController {
|
public class ShopProdSpecController {
|
||||||
private final ShopProductSpecService shopProductSpecService;
|
private final ShopProdSpecService shopProdSpecService;
|
||||||
|
|
||||||
@GetMapping("list")
|
@GetMapping("list")
|
||||||
@OperationLog("商品规格-列表")
|
@OperationLog("商品规格-列表")
|
||||||
//@SaAdminCheckPermission("product:spec:list")
|
//@SaAdminCheckPermission("shopProductSpec:list")
|
||||||
public CzgResult<List<ShopProductSpecDTO>> list(ShopProductSpecDTO param){
|
public CzgResult<List<ShopProdSpecDTO>> list(ShopProdSpecDTO param) {
|
||||||
List<ShopProductSpecDTO> data = shopProductSpecService.list(param);
|
List<ShopProdSpecDTO> data = shopProdSpecService.getShopProdSpecList(param);
|
||||||
return CzgResult.success(data);
|
return CzgResult.success(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("{id}")
|
@GetMapping("{id}")
|
||||||
@OperationLog("商品规格-详情")
|
@OperationLog("商品规格-详情")
|
||||||
//@SaAdminCheckPermission("product:spec:info")
|
//@SaAdminCheckPermission("shopProductSpec:info")
|
||||||
public CzgResult<ShopProductSpecDTO> get(@PathVariable("id") Long id){
|
public CzgResult<ShopProdSpecDTO> get(@PathVariable("id") Long id) {
|
||||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
ShopProductSpecDTO data = shopProductSpecService.get(id);
|
ShopProdSpecDTO data = shopProdSpecService.getShopProdSpecById(id);
|
||||||
return CzgResult.success(data);
|
return CzgResult.success(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@OperationLog("商品规格-新增")
|
@OperationLog("商品规格-新增")
|
||||||
//@SaAdminCheckPermission("product:spec:save")
|
//@SaAdminCheckPermission("shopProductSpec:save")
|
||||||
public CzgResult<Void> save(@RequestBody ShopProductSpecDTO dto){
|
public CzgResult<Void> save(@RequestBody ShopProdSpecDTO dto) {
|
||||||
//效验数据
|
//效验数据
|
||||||
ValidatorUtil.validateEntity(dto, InsertGroup.class, DefaultGroup.class);
|
ValidatorUtil.validateEntity(dto, InsertGroup.class, DefaultGroup.class);
|
||||||
|
|
||||||
shopProductSpecService.save(dto);
|
shopProdSpecService.addShopProdSpec(dto);
|
||||||
|
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@OperationLog("商品规格-修改")
|
@OperationLog("商品规格-修改")
|
||||||
//@SaAdminCheckPermission("product:spec:update")
|
//@SaAdminCheckPermission("shopProductSpec:update")
|
||||||
public CzgResult<Void> update(@RequestBody ShopProductSpecDTO dto){
|
public CzgResult<Void> update(@RequestBody ShopProdSpecDTO dto) {
|
||||||
//效验数据
|
//效验数据
|
||||||
ValidatorUtil.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
ValidatorUtil.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
||||||
|
|
||||||
shopProductSpecService.update(dto);
|
shopProdSpecService.updateShopProdSpec(dto);
|
||||||
|
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("{id}")
|
@DeleteMapping("{id}")
|
||||||
@OperationLog("商品规格-删除")
|
@OperationLog("商品规格-删除")
|
||||||
//@SaAdminCheckPermission("product:spec:delete")
|
//@SaAdminCheckPermission("shopProductSpec:delete")
|
||||||
public CzgResult<Void> delete(@PathVariable("id") Long id){
|
public CzgResult<Void> delete(@PathVariable("id") Long id) {
|
||||||
//效验数据
|
//效验数据
|
||||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
shopProductSpecService.delete(id);
|
shopProdSpecService.deleteShopProdSpec(id);
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("disable/{id}")
|
@PostMapping("disable/{id}")
|
||||||
@OperationLog("商品规格-禁用")
|
@OperationLog("商品规格-禁用")
|
||||||
//@SaAdminCheckPermission("product:spec:able")
|
//@SaAdminCheckPermission("shopProductSpec:able")
|
||||||
public CzgResult<Void> disable(@PathVariable("id") Long id) {
|
public CzgResult<Void> disable(@PathVariable("id") Long id) {
|
||||||
//效验数据
|
//效验数据
|
||||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
shopProductSpecService.disable(id);
|
shopProdSpecService.disableShopProdSpec(id);
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("enable/{id}")
|
@PostMapping("enable/{id}")
|
||||||
@OperationLog("商品规格-启用")
|
@OperationLog("商品规格-启用")
|
||||||
//@SaAdminCheckPermission("product:spec:able")
|
//@SaAdminCheckPermission("shopProductSpec:able")
|
||||||
public CzgResult<Void> enable(@PathVariable("id") Long id) {
|
public CzgResult<Void> enable(@PathVariable("id") Long id) {
|
||||||
//效验数据
|
//效验数据
|
||||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
shopProductSpecService.enable(id);
|
shopProdSpecService.enableShopProdSpec(id);
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ import java.time.LocalDateTime;
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class ShopProductSpecDTO extends TreeNode<ShopProductSpecDTO> implements Serializable {
|
public class ShopProdSpecDTO extends TreeNode<ShopProdSpecDTO> implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
@ -37,6 +37,10 @@ public class ShopProductSpecDTO extends TreeNode<ShopProductSpecDTO> implements
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "规格名称不能为空", groups = DefaultGroup.class)
|
@NotBlank(message = "规格名称不能为空", groups = DefaultGroup.class)
|
||||||
private String name;
|
private String name;
|
||||||
|
/**
|
||||||
|
* 完整规格名称
|
||||||
|
*/
|
||||||
|
private String fullName;
|
||||||
/**
|
/**
|
||||||
* 规格级别
|
* 规格级别
|
||||||
*/
|
*/
|
||||||
|
|
@ -55,6 +59,10 @@ public class ShopProductSpecDTO extends TreeNode<ShopProductSpecDTO> implements
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "请选择上级规格", groups = DefaultGroup.class)
|
@NotNull(message = "请选择上级规格", groups = DefaultGroup.class)
|
||||||
private Long pid;
|
private Long pid;
|
||||||
|
/**
|
||||||
|
* 所有上级id,用逗号分隔
|
||||||
|
*/
|
||||||
|
private String pids;
|
||||||
/**
|
/**
|
||||||
* 店铺 id
|
* 店铺 id
|
||||||
*/
|
*/
|
||||||
|
|
@ -73,6 +73,6 @@ public class ShopProdCategory implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 更新时间
|
* 更新时间
|
||||||
*/
|
*/
|
||||||
@Column(onUpdateValue = "now()")
|
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.czg.product.entity;
|
package com.czg.product.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
import com.mybatisflex.annotation.Id;
|
import com.mybatisflex.annotation.Id;
|
||||||
import com.mybatisflex.annotation.KeyType;
|
import com.mybatisflex.annotation.KeyType;
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
|
|
@ -17,8 +18,8 @@ import java.time.LocalDateTime;
|
||||||
* @since 1.0 2025-02-13
|
* @since 1.0 2025-02-13
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table("tb_shop_product_spec")
|
@Table("tb_shop_prod_spec")
|
||||||
public class ShopProductSpec implements Serializable {
|
public class ShopProdSpec implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
@ -32,6 +33,10 @@ public class ShopProductSpec implements Serializable {
|
||||||
* 规格名称
|
* 规格名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
/**
|
||||||
|
* 完整规格名称
|
||||||
|
*/
|
||||||
|
private String fullName;
|
||||||
/**
|
/**
|
||||||
* 规格级别
|
* 规格级别
|
||||||
*/
|
*/
|
||||||
|
|
@ -44,6 +49,10 @@ public class ShopProductSpec implements Serializable {
|
||||||
* 上级 id
|
* 上级 id
|
||||||
*/
|
*/
|
||||||
private Long pid;
|
private Long pid;
|
||||||
|
/**
|
||||||
|
* 所有上级id,用逗号分隔
|
||||||
|
*/
|
||||||
|
private String pids;
|
||||||
/**
|
/**
|
||||||
* 店铺 id
|
* 店铺 id
|
||||||
*/
|
*/
|
||||||
|
|
@ -55,9 +64,11 @@ public class ShopProductSpec implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
|
@Column(onInsertValue = "now()")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
/**
|
/**
|
||||||
* 更新时间
|
* 更新时间
|
||||||
*/
|
*/
|
||||||
|
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
}
|
}
|
||||||
|
|
@ -22,41 +22,41 @@ import java.time.LocalDateTime;
|
||||||
public class ShopProdUnit implements Serializable {
|
public class ShopProdUnit implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* id
|
* id
|
||||||
*/
|
*/
|
||||||
@Id(keyType = KeyType.Generator, value = KeyGenerators.snowFlakeId)
|
@Id(keyType = KeyType.Generator, value = KeyGenerators.snowFlakeId)
|
||||||
private Long id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* 单位名称
|
* 单位名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
/**
|
/**
|
||||||
* 单位类型 number-计数 weight-记重
|
* 单位类型 number-计数 weight-记重
|
||||||
*/
|
*/
|
||||||
private String unitType;
|
private String unitType;
|
||||||
/**
|
/**
|
||||||
* 单位来源 1-系统预设 0-商家创建
|
* 单位来源 1-系统预设 0-商家创建
|
||||||
*/
|
*/
|
||||||
private Integer isSystem;
|
private Integer isSystem;
|
||||||
/**
|
/**
|
||||||
* 状态 0-禁用 1-启用
|
* 状态 0-禁用 1-启用
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
/**
|
/**
|
||||||
* 店铺id
|
* 店铺id
|
||||||
*/
|
*/
|
||||||
private Long shopId;
|
private Long shopId;
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@Column(onInsertValue = "now()")
|
@Column(onInsertValue = "now()")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
/**
|
/**
|
||||||
* 更新时间
|
* 更新时间
|
||||||
*/
|
*/
|
||||||
@Column(onUpdateValue = "now()")
|
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.czg.product.service;
|
||||||
|
|
||||||
|
import com.czg.product.dto.ShopProdSpecDTO;
|
||||||
|
import com.czg.product.entity.ShopProdSpec;
|
||||||
|
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-13
|
||||||
|
*/
|
||||||
|
public interface ShopProdSpecService extends IService<ShopProdSpec> {
|
||||||
|
Page<ShopProdSpecDTO> getShopProdSpecPage(ShopProdSpecDTO param);
|
||||||
|
|
||||||
|
List<ShopProdSpecDTO> getShopProdSpecList(ShopProdSpecDTO param);
|
||||||
|
|
||||||
|
ShopProdSpecDTO getShopProdSpecById(Long id);
|
||||||
|
|
||||||
|
boolean addShopProdSpec(ShopProdSpecDTO dto);
|
||||||
|
|
||||||
|
boolean deleteShopProdSpec(Long id);
|
||||||
|
|
||||||
|
boolean updateShopProdSpec(ShopProdSpecDTO dto);
|
||||||
|
|
||||||
|
boolean disableShopProdSpec(Long id);
|
||||||
|
|
||||||
|
boolean enableShopProdSpec(Long id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
package com.czg.product.service;
|
|
||||||
|
|
||||||
import com.czg.product.dto.ShopProductSpecDTO;
|
|
||||||
import com.czg.product.entity.ShopProductSpec;
|
|
||||||
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-13
|
|
||||||
*/
|
|
||||||
public interface ShopProductSpecService extends IService<ShopProductSpec> {
|
|
||||||
Page<ShopProductSpecDTO> page(ShopProductSpecDTO param);
|
|
||||||
|
|
||||||
List<ShopProductSpecDTO> list(ShopProductSpecDTO param);
|
|
||||||
|
|
||||||
ShopProductSpecDTO get(Long id);
|
|
||||||
|
|
||||||
boolean save(ShopProductSpecDTO dto);
|
|
||||||
|
|
||||||
boolean delete(Long id);
|
|
||||||
|
|
||||||
boolean update(ShopProductSpecDTO dto);
|
|
||||||
|
|
||||||
boolean disable(Long id);
|
|
||||||
|
|
||||||
boolean enable(Long id);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.czg.service.product.mapper;
|
package com.czg.service.product.mapper;
|
||||||
|
|
||||||
import com.czg.product.entity.ShopProductSpec;
|
import com.czg.product.entity.ShopProdSpec;
|
||||||
import com.mybatisflex.core.BaseMapper;
|
import com.mybatisflex.core.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
|
@ -11,6 +11,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
* @since 1.0 2025-02-13
|
* @since 1.0 2025-02-13
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ShopProductSpecMapper extends BaseMapper<ShopProductSpec> {
|
public interface ShopProductSpecMapper extends BaseMapper<ShopProdSpec> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,10 +5,9 @@ import cn.hutool.core.util.StrUtil;
|
||||||
import com.czg.constant.GlobalConstant;
|
import com.czg.constant.GlobalConstant;
|
||||||
import com.czg.enums.StatusEnum;
|
import com.czg.enums.StatusEnum;
|
||||||
import com.czg.exception.CzgException;
|
import com.czg.exception.CzgException;
|
||||||
import com.czg.product.dto.ShopProductSpecDTO;
|
import com.czg.product.dto.ShopProdSpecDTO;
|
||||||
import com.czg.product.entity.ShopProdCategory;
|
import com.czg.product.entity.ShopProdSpec;
|
||||||
import com.czg.product.entity.ShopProductSpec;
|
import com.czg.product.service.ShopProdSpecService;
|
||||||
import com.czg.product.service.ShopProductSpecService;
|
|
||||||
import com.czg.sa.StpKit;
|
import com.czg.sa.StpKit;
|
||||||
import com.czg.service.product.mapper.ShopProductSpecMapper;
|
import com.czg.service.product.mapper.ShopProductSpecMapper;
|
||||||
import com.czg.utils.PageUtil;
|
import com.czg.utils.PageUtil;
|
||||||
|
|
@ -18,9 +17,12 @@ import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.core.update.UpdateChain;
|
import com.mybatisflex.core.update.UpdateChain;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.czg.product.entity.table.ShopProdSpecTableDef.SHOP_PROD_SPEC;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品规格
|
* 商品规格
|
||||||
|
|
@ -29,117 +31,126 @@ import java.util.List;
|
||||||
* @since 1.0 2025-02-13
|
* @since 1.0 2025-02-13
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProductSpecMapper, ShopProductSpec> implements ShopProductSpecService {
|
public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProductSpecMapper, ShopProdSpec> implements ShopProdSpecService {
|
||||||
|
|
||||||
|
|
||||||
private QueryWrapper buildQueryWrapper(ShopProductSpecDTO param) {
|
private QueryWrapper buildQueryWrapper(ShopProdSpecDTO param) {
|
||||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||||
if (StrUtil.isNotEmpty(param.getName())) {
|
if (StrUtil.isNotEmpty(param.getName())) {
|
||||||
queryWrapper.like(ShopProductSpec::getName, param.getName());
|
queryWrapper.like(ShopProdSpec::getName, param.getName());
|
||||||
}
|
}
|
||||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
queryWrapper.eq(ShopProductSpec::getShopId, shopId);
|
queryWrapper.eq(ShopProdSpec::getShopId, shopId);
|
||||||
queryWrapper.orderBy(ShopProductSpec::getId, false);
|
queryWrapper.orderBy(ShopProdSpec::getSort, true);
|
||||||
|
queryWrapper.orderBy(ShopProdSpec::getId, false);
|
||||||
return queryWrapper;
|
return queryWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<ShopProductSpecDTO> page(ShopProductSpecDTO param) {
|
public Page<ShopProdSpecDTO> getShopProdSpecPage(ShopProdSpecDTO param) {
|
||||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||||
return super.pageAs(PageUtil.buildPage(), queryWrapper, ShopProductSpecDTO.class);
|
return super.pageAs(PageUtil.buildPage(), queryWrapper, ShopProdSpecDTO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ShopProductSpecDTO> list(ShopProductSpecDTO param) {
|
public List<ShopProdSpecDTO> getShopProdSpecList(ShopProdSpecDTO param) {
|
||||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||||
queryWrapper.eq(ShopProductSpec::getStatus, StatusEnum.ENABLED.value());
|
queryWrapper.eq(ShopProdSpec::getStatus, StatusEnum.ENABLED.value());
|
||||||
List<ShopProductSpecDTO> list = super.listAs(queryWrapper, ShopProductSpecDTO.class);
|
List<ShopProdSpecDTO> list = super.listAs(queryWrapper, ShopProdSpecDTO.class);
|
||||||
return TreeUtils.build(list, GlobalConstant.TREE_ROOT);
|
return TreeUtils.build(list, GlobalConstant.TREE_ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShopProductSpecDTO get(Long id) {
|
public ShopProdSpecDTO getShopProdSpecById(Long id) {
|
||||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
return super.getOneAs(query().eq(ShopProductSpec::getId, id).eq(ShopProductSpec::getShopId, shopId), ShopProductSpecDTO.class);
|
return super.getOneAs(query().eq(ShopProdSpec::getId, id).eq(ShopProdSpec::getShopId, shopId), ShopProdSpecDTO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean save(ShopProductSpecDTO dto) {
|
public boolean addShopProdSpec(ShopProdSpecDTO dto) {
|
||||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
boolean exists = super.exists(query()
|
boolean exists = super.exists(query()
|
||||||
.eq(ShopProductSpec::getName, dto.getName())
|
.eq(ShopProdSpec::getName, dto.getName())
|
||||||
.eq(ShopProductSpec::getLevel, dto.getLevel())
|
.eq(ShopProdSpec::getPid, dto.getPid())
|
||||||
.eq(ShopProductSpec::getShopId, shopId));
|
.eq(ShopProdSpec::getShopId, shopId));
|
||||||
if (exists) {
|
if (exists) {
|
||||||
throw new CzgException("商品规格已存在");
|
throw new CzgException("商品规格已存在");
|
||||||
}
|
}
|
||||||
ShopProductSpec entity = BeanUtil.copyProperties(dto, ShopProductSpec.class);
|
ShopProdSpec entity = BeanUtil.copyProperties(dto, ShopProdSpec.class);
|
||||||
|
if (GlobalConstant.TREE_ROOT.equals(entity.getPid())) {
|
||||||
|
entity.setFullName(entity.getName());
|
||||||
|
entity.setPids(GlobalConstant.TREE_ROOT.toString());
|
||||||
|
} else {
|
||||||
|
ShopProdSpec parent = super.getById(entity.getPid());
|
||||||
|
entity.setFullName(parent.getFullName() + " - " + entity.getName());
|
||||||
|
String pids = parent.getPids();
|
||||||
|
entity.setPids(pids + "," + entity.getPid());
|
||||||
|
}
|
||||||
entity.setStatus(StatusEnum.ENABLED.value());
|
entity.setStatus(StatusEnum.ENABLED.value());
|
||||||
entity.setShopId(shopId);
|
entity.setShopId(shopId);
|
||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update(ShopProductSpecDTO dto) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean updateShopProdSpec(ShopProdSpecDTO dto) {
|
||||||
//上级规格不能为自身
|
//上级规格不能为自身
|
||||||
if (dto.getId().equals(dto.getPid())) {
|
if (dto.getId().equals(dto.getPid())) {
|
||||||
throw new CzgException("上级规格不能为自身");
|
throw new CzgException("上级规格不能为自身");
|
||||||
}
|
}
|
||||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
|
dto.setShopId(shopId);
|
||||||
boolean exists = super.exists(query()
|
boolean exists = super.exists(query()
|
||||||
.eq(ShopProductSpec::getName, dto.getName())
|
.eq(ShopProdSpec::getName, dto.getName())
|
||||||
.eq(ShopProductSpec::getLevel, dto.getLevel())
|
.eq(ShopProdSpec::getPid, dto.getPid())
|
||||||
.eq(ShopProductSpec::getShopId, shopId)
|
.eq(ShopProdSpec::getShopId, shopId)
|
||||||
.ne(ShopProductSpec::getId, dto.getId()));
|
.ne(ShopProdSpec::getId, dto.getId()));
|
||||||
if (exists) {
|
if (exists) {
|
||||||
throw new CzgException("商品规格已存在");
|
throw new CzgException("商品规格已存在");
|
||||||
}
|
}
|
||||||
ShopProductSpec entity = BeanUtil.copyProperties(dto, ShopProductSpec.class);
|
ShopProdSpec old = super.getById(dto.getId());
|
||||||
|
ShopProdSpec entity = BeanUtil.copyProperties(dto, ShopProdSpec.class);
|
||||||
|
if (GlobalConstant.TREE_ROOT.equals(entity.getPid())) {
|
||||||
|
entity.setFullName(entity.getName());
|
||||||
|
entity.setPids(GlobalConstant.TREE_ROOT.toString());
|
||||||
|
} else {
|
||||||
|
ShopProdSpec parent = super.getById(entity.getPid());
|
||||||
|
entity.setFullName(parent.getFullName() + " - " + entity.getName());
|
||||||
|
String pids = parent.getPids();
|
||||||
|
entity.setPids(pids + "," + entity.getPid());
|
||||||
|
}
|
||||||
|
String oldName = old.getName();
|
||||||
|
UpdateChain.of(ShopProdSpec.class)
|
||||||
|
.setRaw(ShopProdSpec::getFullName, StrUtil.format("replace(full_name, '{}', '{}')", oldName, entity.getName()))
|
||||||
|
.eq(ShopProdSpec::getShopId, entity.getShopId()).update();
|
||||||
return super.updateById(entity);
|
return super.updateById(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(Long id) {
|
public boolean deleteShopProdSpec(Long id) {
|
||||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
return super.remove(
|
return super.remove(query()
|
||||||
query().eq(ShopProdCategory::getShopId, shopId)
|
.where(SHOP_PROD_SPEC.SHOP_ID.eq(shopId)
|
||||||
.and(wrapper -> {
|
.and(SHOP_PROD_SPEC.ID.eq(id).or(SHOP_PROD_SPEC.PIDS.like("," + id))))
|
||||||
wrapper.eq(ShopProductSpec::getId, id)
|
|
||||||
.or(wrapper1 -> {
|
|
||||||
wrapper1.eq(ShopProductSpec::getPid, id);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean disable(Long id) {
|
public boolean disableShopProdSpec(Long id) {
|
||||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
return UpdateChain.of(ShopProductSpec.class)
|
return UpdateChain.of(ShopProdSpec.class)
|
||||||
.set(ShopProductSpec::getStatus, StatusEnum.DISABLE.value())
|
.set(SHOP_PROD_SPEC.STATUS, StatusEnum.DISABLE.value())
|
||||||
.where(ShopProductSpec::getShopId).eq(shopId)
|
.where(SHOP_PROD_SPEC.SHOP_ID.eq(shopId)
|
||||||
.and(wrapper -> {
|
.and(SHOP_PROD_SPEC.ID.eq(id).or(SHOP_PROD_SPEC.PIDS.like("," + id)))).update();
|
||||||
wrapper.eq(ShopProductSpec::getId, id)
|
|
||||||
.or(wrapper1 -> {
|
|
||||||
wrapper1.eq(ShopProductSpec::getPid, id);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enable(Long id) {
|
public boolean enableShopProdSpec(Long id) {
|
||||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
return UpdateChain.of(ShopProductSpec.class)
|
return UpdateChain.of(ShopProdSpec.class)
|
||||||
.set(ShopProductSpec::getStatus, StatusEnum.ENABLED.value())
|
.set(SHOP_PROD_SPEC.STATUS, StatusEnum.ENABLED.value())
|
||||||
.where(ShopProductSpec::getShopId).eq(shopId)
|
.where(SHOP_PROD_SPEC.SHOP_ID.eq(shopId)
|
||||||
.and(wrapper -> {
|
.and(SHOP_PROD_SPEC.ID.eq(id).or(SHOP_PROD_SPEC.PIDS.like("," + id)))).update();
|
||||||
wrapper.eq(ShopProductSpec::getId, id)
|
|
||||||
.or(wrapper1 -> {
|
|
||||||
wrapper1.eq(ShopProductSpec::getPid, id);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue