会员 mainShopId

This commit is contained in:
2025-09-23 13:43:27 +08:00
parent eb31057b3e
commit fc2757ff17
20 changed files with 599 additions and 482 deletions

View File

@@ -2,6 +2,8 @@ package com.czg.controller.admin;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.thread.ThreadUtil;
import com.czg.account.entity.ShopInfo;
import com.czg.account.service.ShopInfoService;
import com.czg.annotation.SaStaffCheckPermission;
import com.czg.config.RabbitPublisher;
import com.czg.exception.CzgException;
@@ -49,6 +51,8 @@ public class ProductController {
private ShopSyncService shopSyncService;
@Resource
private UProductService uProductService;
@Resource
private ShopInfoService shopInfoService;
/**
* 商品-分页
@@ -104,7 +108,7 @@ public class ProductController {
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
productService.addProduct(dto);
asyncToBranchShop(dto.getId());
asyncProductToShop(dto.getId());
ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
});
@@ -133,7 +137,7 @@ public class ProductController {
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
productService.updateProduct(dto);
asyncToBranchShop(dto.getId());
asyncProductToShop(dto.getId());
ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
});
@@ -168,7 +172,7 @@ public class ProductController {
AssertUtil.isNull(id, "{}不能为空", "id");
Long shopId = StpKit.USER.getShopId(0L);
productService.deleteProduct(shopId, id);
asyncToBranchShop(id);
asyncProductToShop(id);
ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
});
@@ -217,7 +221,7 @@ public class ProductController {
//@SaAdminCheckPermission("product:bind")
public CzgResult<Void> bindCons(@RequestBody @Validated({DefaultGroup.class}) ProdConsBindDTO param) {
prodConsRelationService.saveProdConsRelation(param);
asyncToBranchShop2(param.getId());
asyncConsProToShop(param.getId());
return CzgResult.success();
}
@@ -229,7 +233,7 @@ public class ProductController {
//@SaAdminCheckPermission("product:update")
public CzgResult<Void> refundToStock(@RequestBody @Validated({DefaultGroup.class}) ProdRefundToStockParam param) {
productService.refundToStock(param);
asyncToBranchShop(param.getId());
asyncProductToShop(param.getId());
return CzgResult.success();
}
@@ -293,36 +297,34 @@ public class ProductController {
//@SaAdminCheckPermission("product:sync")
public CzgResult<Void> sync() {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
boolean isEnableSync = StpKit.USER.isEnableSync(shopId);
long headShopId = StpKit.USER.getHeadShopId();
if (!isEnableSync) {
throw new CzgException("主店未开启商品资料同步功能");
ShopInfo shopInfo = shopInfoService.getById(shopId);
if (shopInfo == null) {
throw new CzgException("店铺不存在");
}
if (shopId == headShopId) {
AssertUtil.isNotEqual(shopInfo.getIsEnableProdSync(), 1, "主店未开启商品资料同步功能");
if (shopInfo.getMainId() == null || shopId == shopInfo.getMainId()) {
throw new CzgException("不存在主子店铺关系,无需同步商品信息");
}
ThreadUtil.execAsync(() -> {
shopSyncService.sync(headShopId, shopId, sysUserId);
shopSyncService.sync(shopInfo.getMainId(), shopId, shopId);
});
CzgResult<Void> ret = CzgResult.success();
ret.setMsg("操作成功,数据正在后台同步中...");
return ret;
}
private void asyncToBranchShop(Long id) {
private void asyncProductToShop(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
shopSyncService.syncProductBySourceShop(shopId, id, sysUserId);
shopSyncService.syncProductBySourceShop(shopId, id, shopId);
});
}
private void asyncToBranchShop2(Long id) {
private void asyncConsProToShop(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
shopSyncService.syncConsProBySourceShop(shopId, id, sysUserId);
shopSyncService.syncConsProBySourceShop(shopId, id, shopId);
});
}
}