商品模块代码提交
This commit is contained in:
parent
62b05eb0f3
commit
41116b8d7b
|
|
@ -46,7 +46,7 @@ public class ShopProdSpecController {
|
|||
|
||||
@PostMapping
|
||||
@OperationLog("商品规格-新增")
|
||||
//@SaAdminCheckPermission("shopProductSpec:save")
|
||||
//@SaAdminCheckPermission("shopProductSpec:add")
|
||||
public CzgResult<Void> save(@RequestBody ShopProdSpecDTO dto) {
|
||||
//效验数据
|
||||
ValidatorUtil.validateEntity(dto, InsertGroup.class, DefaultGroup.class);
|
||||
|
|
@ -97,4 +97,29 @@ public class ShopProdSpecController {
|
|||
shopProdSpecService.enableShopProdSpec(id);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("quickAdd")
|
||||
@OperationLog("商品规格-快捷添加")
|
||||
//@SaAdminCheckPermission("shopProductSpec:add")
|
||||
public CzgResult<Void> quickAdd(@RequestBody ShopProdSpecDTO dto) {
|
||||
shopProdSpecService.quickAddShopProdSpec(dto);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("/tree/{id}")
|
||||
@OperationLog("商品规格-快捷编辑详情")
|
||||
//@SaAdminCheckPermission("shopProductSpec:info")
|
||||
public CzgResult<ShopProdSpecDTO> getTree(@PathVariable("id") Long id) {
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
ShopProdSpecDTO data = shopProdSpecService.getShopProdSpecTreeById(id);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
@PutMapping("quickUpdate")
|
||||
@OperationLog("商品规格-快捷更新")
|
||||
//@SaAdminCheckPermission("shopProductSpec:update")
|
||||
public CzgResult<Void> quickUpdate(@RequestBody ShopProdSpecDTO dto) {
|
||||
shopProdSpecService.quickUpdateShopProdSpec(dto);
|
||||
return CzgResult.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -90,11 +90,9 @@ public class OperationLogAspect {
|
|||
}
|
||||
|
||||
//登录用户信息
|
||||
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
Long createUserId = StpKit.USER.getLoginIdAsLong();
|
||||
//TODO SA-TOKEN 暂未整合当前登录人信息,此处仅为临时账号
|
||||
String createUserName = "temp-account";
|
||||
String createUserName = StpKit.USER.getAccount();
|
||||
|
||||
log.set("createUserId", createUserId);
|
||||
log.set("createUserName", createUserName);
|
||||
|
|
|
|||
|
|
@ -30,4 +30,26 @@ public interface ShopProdSpecService extends IService<ShopProdSpec> {
|
|||
|
||||
boolean enableShopProdSpec(Long id);
|
||||
|
||||
/**
|
||||
* 快速添加商品规格
|
||||
*
|
||||
* @param dto 商品规格DTO(树形数据结构)
|
||||
*/
|
||||
void quickAddShopProdSpec(ShopProdSpecDTO dto);
|
||||
|
||||
/**
|
||||
* 获取树状结构规格详情数据
|
||||
*
|
||||
* @param id 规格id
|
||||
* @return ShopProdSpecDTO 规格详情数据
|
||||
*/
|
||||
ShopProdSpecDTO getShopProdSpecTreeById(Long id);
|
||||
|
||||
/**
|
||||
* 快速更新商品规格
|
||||
*
|
||||
* @param dto 商品规格DTO(树形数据结构)
|
||||
*/
|
||||
void quickUpdateShopProdSpec(ShopProdSpecDTO dto);
|
||||
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ public class TreeUtils {
|
|||
/**
|
||||
* 根据pid,构建树节点
|
||||
*/
|
||||
public static <T extends TreeNode> List<T> build(List<T> treeNodes, Long pid) {
|
||||
public static <T extends TreeNode<T>> List<T> build(List<T> treeNodes, Long pid) {
|
||||
//pid不能为空
|
||||
AssertUtil.isNull(pid, "pid不能为空");
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ public class TreeUtils {
|
|||
/**
|
||||
* 查找子节点
|
||||
*/
|
||||
private static <T extends TreeNode> T findChildren(List<T> treeNodes, T rootNode) {
|
||||
private static <T extends TreeNode<T>> T findChildren(List<T> treeNodes, T rootNode) {
|
||||
for(T treeNode : treeNodes) {
|
||||
if(rootNode.getId().equals(treeNode.getPid())) {
|
||||
rootNode.getChildren().add(findChildren(treeNodes, treeNode));
|
||||
|
|
@ -47,7 +47,7 @@ public class TreeUtils {
|
|||
/**
|
||||
* 构建树节点
|
||||
*/
|
||||
public static <T extends TreeNode> List<T> build(List<T> treeNodes) {
|
||||
public static <T extends TreeNode<T>> List<T> build(List<T> treeNodes) {
|
||||
List<T> result = new ArrayList<>();
|
||||
|
||||
//list转map
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.constant.GlobalConstant;
|
||||
import com.czg.enums.StatusEnum;
|
||||
|
|
@ -10,6 +11,7 @@ import com.czg.product.entity.ShopProdSpec;
|
|||
import com.czg.product.service.ShopProdSpecService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.product.mapper.ShopProdSpecMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.czg.utils.TreeUtils;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
|
|
@ -36,6 +38,13 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
|
|||
|
||||
private QueryWrapper buildQueryWrapper(ShopProdSpecDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
if (ObjUtil.isNotNull(param.getPid())) {
|
||||
queryWrapper.and(q -> {
|
||||
q.eq(ShopProdSpec::getId, param.getPid()).or(r -> {
|
||||
r.like(ShopProdSpec::getPids, "," + param.getPid() + ",");
|
||||
});
|
||||
});
|
||||
}
|
||||
if (StrUtil.isNotEmpty(param.getName())) {
|
||||
queryWrapper.like(ShopProdSpec::getName, param.getName());
|
||||
}
|
||||
|
|
@ -72,6 +81,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
|
|||
boolean exists = super.exists(query()
|
||||
.eq(ShopProdSpec::getName, dto.getName())
|
||||
.eq(ShopProdSpec::getPid, dto.getPid())
|
||||
.eq(ShopProdSpec::getLevel, dto.getLevel())
|
||||
.eq(ShopProdSpec::getShopId, shopId));
|
||||
if (exists) {
|
||||
throw new CzgException("商品规格已存在");
|
||||
|
|
@ -88,7 +98,9 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
|
|||
}
|
||||
entity.setStatus(StatusEnum.ENABLED.value());
|
||||
entity.setShopId(shopId);
|
||||
return super.save(entity);
|
||||
super.save(entity);
|
||||
dto.setId(entity.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -103,6 +115,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
|
|||
boolean exists = super.exists(query()
|
||||
.eq(ShopProdSpec::getName, dto.getName())
|
||||
.eq(ShopProdSpec::getPid, dto.getPid())
|
||||
.eq(ShopProdSpec::getLevel, dto.getLevel())
|
||||
.eq(ShopProdSpec::getShopId, shopId)
|
||||
.ne(ShopProdSpec::getId, dto.getId()));
|
||||
if (exists) {
|
||||
|
|
@ -154,4 +167,68 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
|
|||
.and(SHOP_PROD_SPEC.ID.eq(id).or(SHOP_PROD_SPEC.PIDS.like("," + id + ",")))).update();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void quickAddShopProdSpec(ShopProdSpecDTO dto) {
|
||||
String name = dto.getName();
|
||||
AssertUtil.isBlank(name, "1级规格名称不能为空");
|
||||
List<ShopProdSpecDTO> level2List = dto.getChildren();
|
||||
AssertUtil.isListEmpty(level2List, "2级规格数据不能为空");
|
||||
for (ShopProdSpecDTO level2Dto : level2List) {
|
||||
AssertUtil.isBlank(level2Dto.getName(), "2级规格名称不能为空");
|
||||
}
|
||||
long count = level2List.stream().map(ShopProdSpecDTO::getName).distinct().count();
|
||||
if (count != level2List.size()) {
|
||||
throw new CzgException("2级规格名称不能重复");
|
||||
}
|
||||
for (ShopProdSpecDTO level2Dto : level2List) {
|
||||
List<ShopProdSpecDTO> level3List = level2Dto.getChildren();
|
||||
AssertUtil.isListEmpty(level3List, "3级规格数据不能为空");
|
||||
level3List.forEach(level3Dto -> {
|
||||
AssertUtil.isBlank(level3Dto.getName(), "3级规格名称不能为空");
|
||||
});
|
||||
count = level3List.stream().map(ShopProdSpecDTO::getName).distinct().count();
|
||||
if (count != level3List.size()) {
|
||||
throw new CzgException("3级规格名称不能重复");
|
||||
}
|
||||
}
|
||||
dto.setLevel(1);
|
||||
Long maxId = super.mapper.selectOneByQueryAs(query().select("max(id)").eq(ShopProdSpec::getShopId, StpKit.USER.getShopId()), Long.class);
|
||||
dto.setSort(ObjUtil.defaultIfNull(maxId, 0).intValue() + 1);
|
||||
dto.setPid(GlobalConstant.TREE_ROOT);
|
||||
addShopProdSpec(dto);
|
||||
int xIndex = 0;
|
||||
for (ShopProdSpecDTO level2Dto : level2List) {
|
||||
xIndex++;
|
||||
level2Dto.setLevel(2);
|
||||
level2Dto.setSort(xIndex);
|
||||
level2Dto.setPid(dto.getId());
|
||||
addShopProdSpec(level2Dto);
|
||||
List<ShopProdSpecDTO> level3List = level2Dto.getChildren();
|
||||
int yIndex = 0;
|
||||
for (ShopProdSpecDTO level3Dto : level3List) {
|
||||
yIndex++;
|
||||
level3Dto.setLevel(3);
|
||||
level3Dto.setSort(yIndex);
|
||||
level3Dto.setPid(level2Dto.getId());
|
||||
addShopProdSpec(level3Dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopProdSpecDTO getShopProdSpecTreeById(Long id) {
|
||||
ShopProdSpecDTO param = new ShopProdSpecDTO();
|
||||
param.setPid(id);
|
||||
List<ShopProdSpecDTO> list = getShopProdSpecList(param);
|
||||
AssertUtil.isListEmpty(list, "规格信息不存在");
|
||||
return list.getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void quickUpdateShopProdSpec(ShopProdSpecDTO dto) {
|
||||
deleteShopProdSpec(dto.getId());
|
||||
quickAddShopProdSpec(dto);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue