Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,9 +1,13 @@
|
|||||||
package com.czg.controller.admin;
|
package com.czg.controller.admin;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
|
import com.czg.config.RabbitPublisher;
|
||||||
import com.czg.log.annotation.OperationLog;
|
import com.czg.log.annotation.OperationLog;
|
||||||
import com.czg.product.dto.ProdGroupDTO;
|
import com.czg.product.dto.ProdGroupDTO;
|
||||||
import com.czg.product.service.ProdGroupService;
|
import com.czg.product.service.ProdGroupService;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
|
import com.czg.sa.StpKit;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import com.czg.validator.group.DefaultGroup;
|
import com.czg.validator.group.DefaultGroup;
|
||||||
import com.czg.validator.group.InsertGroup;
|
import com.czg.validator.group.InsertGroup;
|
||||||
@@ -17,16 +21,17 @@ import java.util.List;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品分组
|
* 商品分组
|
||||||
*
|
*
|
||||||
* @author Tankaikai tankaikai@aliyun.com
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
* @since 1.0 2025-02-17
|
* @since 1.0 2025-02-17
|
||||||
*/
|
*/
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/admin/prod/group")
|
@RequestMapping("/admin/prod/group")
|
||||||
public class ProdGroupController {
|
public class ProdGroupController {
|
||||||
private final ProdGroupService prodGroupService;
|
private final ProdGroupService prodGroupService;
|
||||||
|
private final RabbitPublisher rabbitPublisher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页
|
* 分页
|
||||||
@@ -34,7 +39,7 @@ public class ProdGroupController {
|
|||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
@OperationLog("商品分组-分页")
|
@OperationLog("商品分组-分页")
|
||||||
//@SaAdminCheckPermission("prodGroup:page")
|
//@SaAdminCheckPermission("prodGroup:page")
|
||||||
public CzgResult<Page<ProdGroupDTO>> getProdGroupPage(ProdGroupDTO param){
|
public CzgResult<Page<ProdGroupDTO>> getProdGroupPage(ProdGroupDTO param) {
|
||||||
Page<ProdGroupDTO> data = prodGroupService.getProdGroupPage(param);
|
Page<ProdGroupDTO> data = prodGroupService.getProdGroupPage(param);
|
||||||
return CzgResult.success(data);
|
return CzgResult.success(data);
|
||||||
}
|
}
|
||||||
@@ -45,7 +50,7 @@ public class ProdGroupController {
|
|||||||
@GetMapping("list")
|
@GetMapping("list")
|
||||||
@OperationLog("商品分组-列表")
|
@OperationLog("商品分组-列表")
|
||||||
//@SaAdminCheckPermission("prodGroup:list")
|
//@SaAdminCheckPermission("prodGroup:list")
|
||||||
public CzgResult<List<ProdGroupDTO>> getProdGroupList(ProdGroupDTO param){
|
public CzgResult<List<ProdGroupDTO>> getProdGroupList(ProdGroupDTO param) {
|
||||||
List<ProdGroupDTO> data = prodGroupService.getProdGroupList(param);
|
List<ProdGroupDTO> data = prodGroupService.getProdGroupList(param);
|
||||||
return CzgResult.success(data);
|
return CzgResult.success(data);
|
||||||
}
|
}
|
||||||
@@ -58,7 +63,7 @@ public class ProdGroupController {
|
|||||||
@GetMapping("{id}")
|
@GetMapping("{id}")
|
||||||
@OperationLog("商品分组-详情")
|
@OperationLog("商品分组-详情")
|
||||||
//@SaAdminCheckPermission("prodGroup:info")
|
//@SaAdminCheckPermission("prodGroup:info")
|
||||||
public CzgResult<ProdGroupDTO> getProdGroupById(@PathVariable("id") Long id){
|
public CzgResult<ProdGroupDTO> getProdGroupById(@PathVariable("id") Long id) {
|
||||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
ProdGroupDTO data = prodGroupService.getProdGroupById(id);
|
ProdGroupDTO data = prodGroupService.getProdGroupById(id);
|
||||||
return CzgResult.success(data);
|
return CzgResult.success(data);
|
||||||
@@ -70,8 +75,13 @@ public class ProdGroupController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
@OperationLog("商品分组-新增")
|
@OperationLog("商品分组-新增")
|
||||||
//@SaAdminCheckPermission("prodGroup:add")
|
//@SaAdminCheckPermission("prodGroup:add")
|
||||||
public CzgResult<Void> addProdGroup(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ProdGroupDTO dto){
|
public CzgResult<Void> addProdGroup(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ProdGroupDTO dto) {
|
||||||
|
Long shopId = StpKit.USER.getShopId(0L);
|
||||||
|
dto.setShopId(shopId);
|
||||||
prodGroupService.addProdGroup(dto);
|
prodGroupService.addProdGroup(dto);
|
||||||
|
ThreadUtil.execAsync(() -> {
|
||||||
|
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
|
||||||
|
});
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +91,13 @@ public class ProdGroupController {
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
@OperationLog("商品分组-修改")
|
@OperationLog("商品分组-修改")
|
||||||
//@SaAdminCheckPermission("prodGroup:update")
|
//@SaAdminCheckPermission("prodGroup:update")
|
||||||
public CzgResult<Void> updateProdGroup(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ProdGroupDTO dto){
|
public CzgResult<Void> updateProdGroup(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ProdGroupDTO dto) {
|
||||||
|
Long shopId = StpKit.USER.getShopId(0L);
|
||||||
|
dto.setShopId(shopId);
|
||||||
prodGroupService.updateProdGroup(dto);
|
prodGroupService.updateProdGroup(dto);
|
||||||
|
ThreadUtil.execAsync(() -> {
|
||||||
|
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
|
||||||
|
});
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,10 +107,14 @@ public class ProdGroupController {
|
|||||||
@DeleteMapping("{id}")
|
@DeleteMapping("{id}")
|
||||||
@OperationLog("商品分组-删除")
|
@OperationLog("商品分组-删除")
|
||||||
//@SaAdminCheckPermission("prodGroup:delete")
|
//@SaAdminCheckPermission("prodGroup:delete")
|
||||||
public CzgResult<Void> deleteProdGroup(@PathVariable("id") Long id){
|
public CzgResult<Void> deleteProdGroup(@PathVariable("id") Long id) {
|
||||||
//效验数据
|
//效验数据
|
||||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
prodGroupService.deleteProdGroup(id);
|
Long shopId = StpKit.USER.getShopId(0L);
|
||||||
|
prodGroupService.deleteProdGroup(shopId, id);
|
||||||
|
ThreadUtil.execAsync(() -> {
|
||||||
|
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
|
||||||
|
});
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +127,11 @@ public class ProdGroupController {
|
|||||||
public CzgResult<Void> disableProdGroup(@PathVariable("id") Long id) {
|
public CzgResult<Void> disableProdGroup(@PathVariable("id") Long id) {
|
||||||
//效验数据
|
//效验数据
|
||||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
prodGroupService.disableProdGroup(id);
|
Long shopId = StpKit.USER.getShopId(0L);
|
||||||
|
prodGroupService.disableProdGroup(shopId, id);
|
||||||
|
ThreadUtil.execAsync(() -> {
|
||||||
|
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
|
||||||
|
});
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +144,11 @@ public class ProdGroupController {
|
|||||||
public CzgResult<Void> enableProdGroup(@PathVariable("id") Long id) {
|
public CzgResult<Void> enableProdGroup(@PathVariable("id") Long id) {
|
||||||
//效验数据
|
//效验数据
|
||||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
prodGroupService.enableProdGroup(id);
|
Long shopId = StpKit.USER.getShopId(0L);
|
||||||
|
prodGroupService.enableProdGroup(shopId, id);
|
||||||
|
ThreadUtil.execAsync(() -> {
|
||||||
|
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
|
||||||
|
});
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ public interface ProdGroupService extends IService<ProdGroup> {
|
|||||||
*
|
*
|
||||||
* @param id 商品分组ID
|
* @param id 商品分组ID
|
||||||
*/
|
*/
|
||||||
void deleteProdGroup(Long id);
|
void deleteProdGroup(Long shopId, Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新商品分组
|
* 更新商品分组
|
||||||
@@ -64,13 +64,13 @@ public interface ProdGroupService extends IService<ProdGroup> {
|
|||||||
*
|
*
|
||||||
* @param id 商品分组ID
|
* @param id 商品分组ID
|
||||||
*/
|
*/
|
||||||
void disableProdGroup(Long id);
|
void disableProdGroup(Long shopId, Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启用商品分组
|
* 启用商品分组
|
||||||
*
|
*
|
||||||
* @param id 商品分组ID
|
* @param id 商品分组ID
|
||||||
*/
|
*/
|
||||||
void enableProdGroup(Long id);
|
void enableProdGroup(Long shopId, Long id);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.czg.constant.CacheConstant;
|
||||||
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.ProdGroupDTO;
|
import com.czg.product.dto.ProdGroupDTO;
|
||||||
@@ -22,6 +23,7 @@ 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 lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -82,6 +84,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#dto.shopId", allEntries = true)
|
||||||
public void addProdGroup(ProdGroupDTO dto) {
|
public void addProdGroup(ProdGroupDTO dto) {
|
||||||
Long shopId = StpKit.USER.getShopId(0L);
|
Long shopId = StpKit.USER.getShopId(0L);
|
||||||
boolean exists = super.exists(query().eq(ProdGroup::getName, dto.getName()).eq(ProdGroup::getShopId, shopId));
|
boolean exists = super.exists(query().eq(ProdGroup::getName, dto.getName()).eq(ProdGroup::getShopId, shopId));
|
||||||
@@ -107,6 +110,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#dto.shopId", allEntries = true)
|
||||||
public void updateProdGroup(ProdGroupDTO dto) {
|
public void updateProdGroup(ProdGroupDTO dto) {
|
||||||
Long shopId = StpKit.USER.getShopId(0L);
|
Long shopId = StpKit.USER.getShopId(0L);
|
||||||
dto.setShopId(shopId);
|
dto.setShopId(shopId);
|
||||||
@@ -133,15 +137,15 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteProdGroup(Long id) {
|
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#shopId", allEntries = true)
|
||||||
Long shopId = StpKit.USER.getShopId(0L);
|
public void deleteProdGroup(Long shopId, Long id) {
|
||||||
super.remove(query().eq(ProdGroup::getId, id).eq(ProdGroup::getShopId, shopId));
|
super.remove(query().eq(ProdGroup::getId, id).eq(ProdGroup::getShopId, shopId));
|
||||||
prodGroupRelationMapper.deleteByQuery(query().eq(ProdGroupRelation::getProdGroupId, id));
|
prodGroupRelationMapper.deleteByQuery(query().eq(ProdGroupRelation::getProdGroupId, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disableProdGroup(Long id) {
|
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#shopId", allEntries = true)
|
||||||
Long shopId = StpKit.USER.getShopId(0L);
|
public void disableProdGroup(Long shopId, Long id) {
|
||||||
UpdateChain.of(ProdGroup.class)
|
UpdateChain.of(ProdGroup.class)
|
||||||
.set(ProdGroup::getStatus, StatusEnum.DISABLE.value())
|
.set(ProdGroup::getStatus, StatusEnum.DISABLE.value())
|
||||||
.eq(ProdGroup::getId, id)
|
.eq(ProdGroup::getId, id)
|
||||||
@@ -150,8 +154,8 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableProdGroup(Long id) {
|
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#shopId", allEntries = true)
|
||||||
Long shopId = StpKit.USER.getShopId(0L);
|
public void enableProdGroup(Long shopId, Long id) {
|
||||||
UpdateChain.of(ProdGroup.class)
|
UpdateChain.of(ProdGroup.class)
|
||||||
.set(ProdGroup::getStatus, StatusEnum.ENABLED.value())
|
.set(ProdGroup::getStatus, StatusEnum.ENABLED.value())
|
||||||
.eq(ProdGroup::getId, id)
|
.eq(ProdGroup::getId, id)
|
||||||
|
|||||||
Reference in New Issue
Block a user