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