切换店铺统计 √

下单选择会员 √
注册会员 √
完善手机号 √
会员流水信息同步 √
This commit is contained in:
谭凯凯 2025-04-10 15:37:17 +08:00 committed by Tankaikai
parent e17a2ee5d1
commit 63e608a208
26 changed files with 263 additions and 64 deletions

View File

@ -1,9 +1,7 @@
package com.czg.controller.admin; package com.czg.controller.admin;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.shopuser.*; import com.czg.account.dto.shopuser.*;
import com.czg.account.entity.ShopUser; import com.czg.account.entity.ShopUser;
import com.czg.account.entity.ShopUserFlow;
import com.czg.account.service.ShopUserFlowService; import com.czg.account.service.ShopUserFlowService;
import com.czg.account.service.ShopUserService; import com.czg.account.service.ShopUserService;
import com.czg.account.vo.ShopUserFlowVO; import com.czg.account.vo.ShopUserFlowVO;
@ -12,9 +10,7 @@ import com.czg.annotation.SaStaffCheckPermission;
import com.czg.enums.ShopUserFlowBizEnum; import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -47,7 +43,7 @@ public class ShopUserController {
@GetMapping("/summary") @GetMapping("/summary")
@SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi") @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi")
public CzgResult<ShopUserSummaryDTO> summary(Integer isVip) { public CzgResult<ShopUserSummaryDTO> summary(Integer isVip) {
return CzgResult.success(shopUserService.getSummary(StpKit.USER.getShopId(), isVip)); return CzgResult.success(shopUserService.getSummary(StpKit.USER.getHeadShopId(), isVip));
} }
/** /**
@ -71,7 +67,7 @@ public class ShopUserController {
@GetMapping("/flow") @GetMapping("/flow")
@SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi") @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi")
public CzgResult<Page<ShopUserFlowVO>> flow(Integer userId, String bizCode, String startTime, String endTime) { public CzgResult<Page<ShopUserFlowVO>> flow(Integer userId, String bizCode, String startTime, String endTime) {
return CzgResult.success(shopUserFlowService.pageInfo(StpKit.USER.getShopId(), userId, bizCode, startTime, endTime)); return CzgResult.success(shopUserFlowService.pageInfo(StpKit.USER.getHeadShopId(), userId, bizCode, startTime, endTime));
} }
/** /**
@ -87,7 +83,7 @@ public class ShopUserController {
@GetMapping("/flow/download") @GetMapping("/flow/download")
@SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi") @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi")
public void flowDownload(Integer userId, String bizCode, String startTime, String endTime, HttpServletResponse response) throws IOException { public void flowDownload(Integer userId, String bizCode, String startTime, String endTime, HttpServletResponse response) throws IOException {
shopUserFlowService.flowDownload(StpKit.USER.getShopId(), userId, bizCode, startTime, endTime, response); shopUserFlowService.flowDownload(StpKit.USER.getHeadShopId(), userId, bizCode, startTime, endTime, response);
} }
/** /**
@ -129,7 +125,7 @@ public class ShopUserController {
@SaAdminCheckPermission(value = "shopUser:add", name = "店铺用户添加") @SaAdminCheckPermission(value = "shopUser:add", name = "店铺用户添加")
@PostMapping @PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated ShopUserAddDTO shopUserAddDTO) { public CzgResult<Boolean> add(@RequestBody @Validated ShopUserAddDTO shopUserAddDTO) {
return CzgResult.success(shopUserService.add(StpKit.USER.getShopId(), shopUserAddDTO)); return CzgResult.success(shopUserService.add(StpKit.USER.getHeadShopId(), shopUserAddDTO));
} }
/** /**
@ -141,7 +137,7 @@ public class ShopUserController {
@SaAdminCheckPermission(value = "shopUser:edit", name = "店铺用户修改") @SaAdminCheckPermission(value = "shopUser:edit", name = "店铺用户修改")
@PutMapping @PutMapping
public CzgResult<Boolean> edit(@RequestBody @Validated ShopUserEditDTO shopUserEditDTO) { public CzgResult<Boolean> edit(@RequestBody @Validated ShopUserEditDTO shopUserEditDTO) {
return CzgResult.success(shopUserService.updateInfo(StpKit.USER.getShopId(), shopUserEditDTO)); return CzgResult.success(shopUserService.updateInfo(StpKit.USER.getHeadShopId(), shopUserEditDTO));
} }
/** /**
@ -154,7 +150,7 @@ public class ShopUserController {
@PutMapping("/money") @PutMapping("/money")
public CzgResult<Boolean> editMoney(@RequestBody @Validated ShopUserMoneyEditDTO shopUserMoneyEditDTO) { public CzgResult<Boolean> editMoney(@RequestBody @Validated ShopUserMoneyEditDTO shopUserMoneyEditDTO) {
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.ADMIN_IN); shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.ADMIN_IN);
return CzgResult.success(shopUserService.updateMoney(StpKit.USER.getShopId(), shopUserMoneyEditDTO) > 0L); return CzgResult.success(shopUserService.updateMoney(StpKit.USER.getHeadShopId(), shopUserMoneyEditDTO) > 0L);
} }
} }

View File

@ -4,7 +4,6 @@ import com.czg.account.dto.shopuser.ShopUserAddDTO;
import com.czg.account.dto.shopuser.ShopUserDetailDTO; import com.czg.account.dto.shopuser.ShopUserDetailDTO;
import com.czg.account.dto.shopuser.ShopUserVipCardDTO; import com.czg.account.dto.shopuser.ShopUserVipCardDTO;
import com.czg.account.entity.MemberPointsLog; import com.czg.account.entity.MemberPointsLog;
import com.czg.account.entity.PointsExchangeRecord;
import com.czg.account.entity.ShopUser; import com.czg.account.entity.ShopUser;
import com.czg.account.entity.ShopUserFlow; import com.czg.account.entity.ShopUserFlow;
import com.czg.account.service.MemberPointsLogService; import com.czg.account.service.MemberPointsLogService;
@ -18,14 +17,9 @@ import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashSet;
import java.util.Objects;
/** /**
* 店铺会员相关 * 店铺会员相关
* *
@ -51,7 +45,7 @@ public class UShopUserController {
*/ */
@GetMapping @GetMapping
public CzgResult<ShopUserDetailDTO> get(Long shopId) { public CzgResult<ShopUserDetailDTO> get(Long shopId) {
return CzgResult.success(shopUserService.getInfo(shopId == null ? StpKit.USER.getShopId() : shopId, StpKit.USER.getLoginIdAsLong())); return CzgResult.success(shopUserService.getInfo(shopId == null ? StpKit.USER.getHeadShopId() : shopId, StpKit.USER.getLoginIdAsLong()));
} }
/** /**
@ -71,7 +65,7 @@ public class UShopUserController {
*/ */
@GetMapping("/code") @GetMapping("/code")
public CzgResult<String> code(Long shopId) { public CzgResult<String> code(Long shopId) {
return shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), shopId == null ? StpKit.USER.getShopId() : shopId); return shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), shopId == null ? StpKit.USER.getHeadShopId() : shopId);
} }
/** /**
@ -82,7 +76,7 @@ public class UShopUserController {
@PostMapping @PostMapping
@Debounce("#shopUserAddDTO.phone") @Debounce("#shopUserAddDTO.phone")
public CzgResult<Boolean> join(@RequestBody @Validated ShopUserAddDTO shopUserAddDTO) { public CzgResult<Boolean> join(@RequestBody @Validated ShopUserAddDTO shopUserAddDTO) {
return CzgResult.success(shopUserService.join(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong(), shopUserAddDTO)); return CzgResult.success(shopUserService.join(StpKit.USER.getHeadShopId(), StpKit.USER.getLoginIdAsLong(), shopUserAddDTO));
} }

View File

@ -1,15 +1,11 @@
package com.czg.controller.user; package com.czg.controller.user;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.czg.account.dto.user.userinfo.UserInfoDTO; import com.czg.account.dto.user.userinfo.UserInfoDTO;
import com.czg.account.dto.user.userinfo.UserInfoEditDTO; import com.czg.account.dto.user.userinfo.UserInfoEditDTO;
import com.czg.account.dto.user.userinfo.UserInfoPwdEditDTO; import com.czg.account.dto.user.userinfo.UserInfoPwdEditDTO;
import com.czg.account.entity.UserInfo;
import com.czg.account.service.UserInfoService; import com.czg.account.service.UserInfoService;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -38,7 +34,7 @@ public class UserController {
*/ */
@PutMapping @PutMapping
public CzgResult<Boolean> update(@RequestBody UserInfoEditDTO userInfoEditDTO) { public CzgResult<Boolean> update(@RequestBody UserInfoEditDTO userInfoEditDTO) {
return CzgResult.success(userInfoService.updateInfo(StpKit.USER.getShopId(-1L), StpKit.USER.getLoginIdAsLong(), userInfoEditDTO)); return CzgResult.success(userInfoService.updateInfo(StpKit.USER.getHeadShopId(), StpKit.USER.getLoginIdAsLong(), userInfoEditDTO));
} }
/** /**

View File

@ -1,14 +1,18 @@
package com.czg.controller.admin; package com.czg.controller.admin;
import cn.hutool.core.thread.ThreadUtil;
import com.czg.log.annotation.OperationLog; import com.czg.log.annotation.OperationLog;
import com.czg.product.dto.ConsGroupDTO; import com.czg.product.dto.ConsGroupDTO;
import com.czg.product.service.ConsGroupService; import com.czg.product.service.ConsGroupService;
import com.czg.product.service.ShopSyncService;
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;
import com.czg.validator.group.UpdateGroup; import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -27,6 +31,8 @@ import java.util.List;
@RequestMapping("/admin/product/consGroup") @RequestMapping("/admin/product/consGroup")
public class ConsGroupController { public class ConsGroupController {
private final ConsGroupService consGroupService; private final ConsGroupService consGroupService;
@Resource
private ShopSyncService shopSyncService;
/** /**
* 分页 * 分页
@ -72,6 +78,7 @@ public class ConsGroupController {
//@SaAdminCheckPermission("consGroup:add") //@SaAdminCheckPermission("consGroup:add")
public CzgResult<Void> addConsGroup(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ConsGroupDTO dto) { public CzgResult<Void> addConsGroup(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ConsGroupDTO dto) {
consGroupService.addConsGroup(dto); consGroupService.addConsGroup(dto);
asyncToBranchShop(dto.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -83,6 +90,7 @@ public class ConsGroupController {
//@SaAdminCheckPermission("consGroup:update") //@SaAdminCheckPermission("consGroup:update")
public CzgResult<Void> updateConsGroup(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ConsGroupDTO dto) { public CzgResult<Void> updateConsGroup(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ConsGroupDTO dto) {
consGroupService.updateConsGroup(dto); consGroupService.updateConsGroup(dto);
asyncToBranchShop(dto.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -98,6 +106,7 @@ public class ConsGroupController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
consGroupService.disableConsGroup(id); consGroupService.disableConsGroup(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
@ -113,6 +122,15 @@ public class ConsGroupController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
consGroupService.enableConsGroup(id); consGroupService.enableConsGroup(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
private void asyncToBranchShop(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
shopSyncService.syncConsGroupBySourceShop(shopId, id, sysUserId);
});
}
} }

View File

@ -1,12 +1,13 @@
package com.czg.controller.admin; package com.czg.controller.admin;
import cn.hutool.core.thread.ThreadUtil;
import com.czg.enums.CrudEnum; import com.czg.enums.CrudEnum;
import com.czg.log.annotation.OperationLog; import com.czg.log.annotation.OperationLog;
import com.czg.product.dto.ConsInfoDTO; import com.czg.product.dto.ConsInfoDTO;
import com.czg.product.param.ConsInfoParam; import com.czg.product.param.ConsInfoParam;
import com.czg.product.param.ConsReportDamageParam;
import com.czg.product.param.ConsSubUnitParam; import com.czg.product.param.ConsSubUnitParam;
import com.czg.product.service.ConsInfoService; import com.czg.product.service.ConsInfoService;
import com.czg.product.service.ShopSyncService;
import com.czg.product.vo.ConsStatisticsVo; import com.czg.product.vo.ConsStatisticsVo;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
@ -16,6 +17,7 @@ import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup; import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup; import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -34,6 +36,8 @@ import java.util.List;
@RequestMapping("/admin/product/cons") @RequestMapping("/admin/product/cons")
public class ConsInfoController { public class ConsInfoController {
private final ConsInfoService consInfoService; private final ConsInfoService consInfoService;
@Resource
private ShopSyncService shopSyncService;
/** /**
* 分页 * 分页
@ -79,6 +83,7 @@ public class ConsInfoController {
//@SaAdminCheckPermission("consInfo:add") //@SaAdminCheckPermission("consInfo:add")
public CzgResult<Void> addConsInfo(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ConsInfoDTO dto) { public CzgResult<Void> addConsInfo(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ConsInfoDTO dto) {
consInfoService.addConsInfo(dto); consInfoService.addConsInfo(dto);
asyncToBranchShop(dto.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -90,6 +95,7 @@ public class ConsInfoController {
//@SaAdminCheckPermission("consInfo:update") //@SaAdminCheckPermission("consInfo:update")
public CzgResult<Void> updateConsInfo(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ConsInfoDTO dto) { public CzgResult<Void> updateConsInfo(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ConsInfoDTO dto) {
consInfoService.updateConsInfo(dto); consInfoService.updateConsInfo(dto);
asyncToBranchShop(dto.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -120,6 +126,7 @@ public class ConsInfoController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
consInfoService.disableConsInfo(id); consInfoService.disableConsInfo(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
@ -135,6 +142,7 @@ public class ConsInfoController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
consInfoService.enableConsInfo(id); consInfoService.enableConsInfo(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
@ -167,6 +175,7 @@ public class ConsInfoController {
ValidatorUtil.validateEntity(param, InsertGroup.class); ValidatorUtil.validateEntity(param, InsertGroup.class);
} }
consInfoService.modifySubUnit(param); consInfoService.modifySubUnit(param);
asyncToBranchShop(param.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -183,4 +192,12 @@ public class ConsInfoController {
return CzgResult.success(data); return CzgResult.success(data);
} }
private void asyncToBranchShop(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
shopSyncService.syncConsInfoBySourceShop(shopId, id, sysUserId);
});
}
} }

View File

@ -6,6 +6,7 @@ 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.product.service.ShopSyncService;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
import com.czg.utils.AssertUtil; import com.czg.utils.AssertUtil;
@ -13,6 +14,7 @@ import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup; import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup; import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -32,6 +34,8 @@ import java.util.List;
public class ProdGroupController { public class ProdGroupController {
private final ProdGroupService prodGroupService; private final ProdGroupService prodGroupService;
private final RabbitPublisher rabbitPublisher; private final RabbitPublisher rabbitPublisher;
@Resource
private ShopSyncService shopSyncService;
/** /**
* 分页 * 分页
@ -79,6 +83,7 @@ public class ProdGroupController {
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId); dto.setShopId(shopId);
prodGroupService.addProdGroup(dto); prodGroupService.addProdGroup(dto);
asyncToBranchShop(dto.getId());
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@ -95,6 +100,7 @@ public class ProdGroupController {
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId); dto.setShopId(shopId);
prodGroupService.updateProdGroup(dto,true); prodGroupService.updateProdGroup(dto,true);
asyncToBranchShop(dto.getId());
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@ -111,6 +117,7 @@ public class ProdGroupController {
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId); dto.setShopId(shopId);
prodGroupService.updateProdGroup(dto,false); prodGroupService.updateProdGroup(dto,false);
asyncToBranchShop(dto.getId());
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@ -145,6 +152,7 @@ public class ProdGroupController {
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
prodGroupService.disableProdGroup(shopId, id); prodGroupService.disableProdGroup(shopId, id);
asyncToBranchShop(id);
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@ -162,9 +170,18 @@ public class ProdGroupController {
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
prodGroupService.enableProdGroup(shopId, id); prodGroupService.enableProdGroup(shopId, id);
asyncToBranchShop(id);
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
return CzgResult.success(); return CzgResult.success();
} }
private void asyncToBranchShop(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
shopSyncService.syncGroupBySourceShop(shopId, id, sysUserId);
});
}
} }

View File

@ -15,6 +15,7 @@ import com.czg.product.entity.ProductStockFlow;
import com.czg.product.param.*; import com.czg.product.param.*;
import com.czg.product.service.ProdConsRelationService; import com.czg.product.service.ProdConsRelationService;
import com.czg.product.service.ProductService; import com.czg.product.service.ProductService;
import com.czg.product.service.ShopSyncService;
import com.czg.product.vo.ProductStatisticsVo; import com.czg.product.vo.ProductStatisticsVo;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
@ -24,6 +25,7 @@ import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup; import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup; import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -44,6 +46,8 @@ public class ProductController {
private final ProductService productService; private final ProductService productService;
private final ProdConsRelationService prodConsRelationService; private final ProdConsRelationService prodConsRelationService;
private final RabbitPublisher rabbitPublisher; private final RabbitPublisher rabbitPublisher;
@Resource
private ShopSyncService shopSyncService;
/** /**
* 商品-分页 * 商品-分页
@ -109,6 +113,7 @@ public class ProductController {
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId); dto.setShopId(shopId);
productService.addProduct(dto); productService.addProduct(dto);
asyncToBranchShop(dto.getId());
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@ -137,6 +142,7 @@ public class ProductController {
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId); dto.setShopId(shopId);
productService.updateProduct(dto); productService.updateProduct(dto);
asyncToBranchShop(dto.getId());
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@ -168,6 +174,7 @@ public class ProductController {
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
productService.deleteProduct(shopId, id); productService.deleteProduct(shopId, id);
asyncToBranchShop(id);
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@ -216,6 +223,7 @@ public class ProductController {
//@SaAdminCheckPermission("product:bind") //@SaAdminCheckPermission("product:bind")
public CzgResult<Void> bindCons(@RequestBody @Validated({DefaultGroup.class}) ProdConsBindDTO param) { public CzgResult<Void> bindCons(@RequestBody @Validated({DefaultGroup.class}) ProdConsBindDTO param) {
prodConsRelationService.saveProdConsRelation(param); prodConsRelationService.saveProdConsRelation(param);
asyncToBranchShop2(param.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -227,6 +235,7 @@ public class ProductController {
//@SaAdminCheckPermission("product:update") //@SaAdminCheckPermission("product:update")
public CzgResult<Void> refundToStock(@RequestBody @Validated({DefaultGroup.class}) ProdRefundToStockParam param) { public CzgResult<Void> refundToStock(@RequestBody @Validated({DefaultGroup.class}) ProdRefundToStockParam param) {
productService.refundToStock(param); productService.refundToStock(param);
asyncToBranchShop(param.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -282,4 +291,20 @@ public class ProductController {
return CzgResult.success(data); return CzgResult.success(data);
} }
private void asyncToBranchShop(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
shopSyncService.syncProductBySourceShop(shopId, id, sysUserId);
});
}
private void asyncToBranchShop2(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
shopSyncService.syncConsProBySourceShop(shopId, id, sysUserId);
});
}
} }

View File

@ -1,14 +1,18 @@
package com.czg.controller.admin; package com.czg.controller.admin;
import cn.hutool.core.thread.ThreadUtil;
import com.czg.log.annotation.OperationLog; import com.czg.log.annotation.OperationLog;
import com.czg.product.dto.ShopProdCategoryDTO; import com.czg.product.dto.ShopProdCategoryDTO;
import com.czg.product.service.ShopProdCategoryService; import com.czg.product.service.ShopProdCategoryService;
import com.czg.product.service.ShopSyncService;
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;
import com.czg.validator.group.UpdateGroup; import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -27,6 +31,8 @@ import java.util.List;
@RequestMapping("/admin/prod/category") @RequestMapping("/admin/prod/category")
public class ShopProdCategoryController { public class ShopProdCategoryController {
private final ShopProdCategoryService shopProdCategoryService; private final ShopProdCategoryService shopProdCategoryService;
@Resource
private ShopSyncService shopSyncService;
@GetMapping("page") @GetMapping("page")
@OperationLog("商品分类-分页") @OperationLog("商品分类-分页")
@ -58,6 +64,7 @@ public class ShopProdCategoryController {
//@SaAdminCheckPermission("shopProdCategory:add") //@SaAdminCheckPermission("shopProdCategory:add")
public CzgResult<Void> addShopProdCategory(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ShopProdCategoryDTO dto) { public CzgResult<Void> addShopProdCategory(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ShopProdCategoryDTO dto) {
shopProdCategoryService.addShopProdCategory(dto); shopProdCategoryService.addShopProdCategory(dto);
asyncToBranchShop(dto.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -66,6 +73,7 @@ public class ShopProdCategoryController {
//@SaAdminCheckPermission("shopProdCategory:update") //@SaAdminCheckPermission("shopProdCategory:update")
public CzgResult<Void> updateShopProdCategory(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ShopProdCategoryDTO dto) { public CzgResult<Void> updateShopProdCategory(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ShopProdCategoryDTO dto) {
shopProdCategoryService.updateShopProdCategory(dto); shopProdCategoryService.updateShopProdCategory(dto);
asyncToBranchShop(dto.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -86,6 +94,7 @@ public class ShopProdCategoryController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
shopProdCategoryService.disableShopProdCategory(id); shopProdCategoryService.disableShopProdCategory(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
@ -96,7 +105,16 @@ public class ShopProdCategoryController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
shopProdCategoryService.enableShopProdCategory(id); shopProdCategoryService.enableShopProdCategory(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
private void asyncToBranchShop(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
shopSyncService.syncCategoryBySourceShop(shopId, id, sysUserId);
});
}
} }

View File

@ -1,14 +1,19 @@
package com.czg.controller.admin; package com.czg.controller.admin;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.czg.log.annotation.OperationLog; import com.czg.log.annotation.OperationLog;
import com.czg.product.dto.ShopProdSpecDTO; import com.czg.product.dto.ShopProdSpecDTO;
import com.czg.product.service.ShopProdSpecService; import com.czg.product.service.ShopProdSpecService;
import com.czg.product.service.ShopSyncService;
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.ValidatorUtil; import com.czg.validator.ValidatorUtil;
import com.czg.validator.group.DefaultGroup; import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup; import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup; import com.czg.validator.group.UpdateGroup;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -26,6 +31,9 @@ import java.util.List;
@RequestMapping("/admin/prod/spec") @RequestMapping("/admin/prod/spec")
public class ShopProdSpecController { public class ShopProdSpecController {
private final ShopProdSpecService shopProdSpecService; private final ShopProdSpecService shopProdSpecService;
@Resource
private ShopSyncService shopSyncService;
@GetMapping("list") @GetMapping("list")
@OperationLog("商品规格-列表") @OperationLog("商品规格-列表")
@ -50,9 +58,8 @@ public class ShopProdSpecController {
public CzgResult<Void> addShopProdSpec(@RequestBody ShopProdSpecDTO dto) { public CzgResult<Void> addShopProdSpec(@RequestBody ShopProdSpecDTO dto) {
//效验数据 //效验数据
ValidatorUtil.validateEntity(dto, InsertGroup.class, DefaultGroup.class); ValidatorUtil.validateEntity(dto, InsertGroup.class, DefaultGroup.class);
shopProdSpecService.addShopProdSpec(dto); shopProdSpecService.addShopProdSpec(dto);
asyncToBranchShop(dto.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -62,9 +69,11 @@ public class ShopProdSpecController {
public CzgResult<Void> updateShopProdSpec(@RequestBody ShopProdSpecDTO dto) { public CzgResult<Void> updateShopProdSpec(@RequestBody ShopProdSpecDTO dto) {
//效验数据 //效验数据
ValidatorUtil.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); ValidatorUtil.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
shopProdSpecService.updateShopProdSpec(dto); shopProdSpecService.updateShopProdSpec(dto);
List<Long> affectedIdList = dto.getAffectedIdList();
if (CollUtil.isNotEmpty(affectedIdList)) {
affectedIdList.parallelStream().forEach(this::asyncToBranchShop);
}
return CzgResult.success(); return CzgResult.success();
} }
@ -85,6 +94,7 @@ public class ShopProdSpecController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
shopProdSpecService.disableShopProdSpec(id); shopProdSpecService.disableShopProdSpec(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
@ -95,6 +105,7 @@ public class ShopProdSpecController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
shopProdSpecService.enableShopProdSpec(id); shopProdSpecService.enableShopProdSpec(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
@ -103,6 +114,10 @@ public class ShopProdSpecController {
//@SaAdminCheckPermission("shopProductSpec:add") //@SaAdminCheckPermission("shopProductSpec:add")
public CzgResult<Void> quickAddShopProdSpec(@RequestBody ShopProdSpecDTO dto) { public CzgResult<Void> quickAddShopProdSpec(@RequestBody ShopProdSpecDTO dto) {
shopProdSpecService.quickAddShopProdSpec(dto); shopProdSpecService.quickAddShopProdSpec(dto);
List<Long> affectedIdList = dto.getAffectedIdList();
if (CollUtil.isNotEmpty(affectedIdList)) {
affectedIdList.parallelStream().forEach(this::asyncToBranchShop);
}
return CzgResult.success(); return CzgResult.success();
} }
@ -120,6 +135,19 @@ public class ShopProdSpecController {
//@SaAdminCheckPermission("shopProductSpec:update") //@SaAdminCheckPermission("shopProductSpec:update")
public CzgResult<Void> quickUpdateShopProdSpec(@RequestBody ShopProdSpecDTO dto) { public CzgResult<Void> quickUpdateShopProdSpec(@RequestBody ShopProdSpecDTO dto) {
shopProdSpecService.quickUpdateShopProdSpec(dto); shopProdSpecService.quickUpdateShopProdSpec(dto);
List<Long> affectedIdList = dto.getAffectedIdList();
if (CollUtil.isNotEmpty(affectedIdList)) {
affectedIdList.parallelStream().forEach(this::asyncToBranchShop);
}
return CzgResult.success(); return CzgResult.success();
} }
private void asyncToBranchShop(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
ThreadUtil.safeSleep(1000L);
shopSyncService.syncSpecBySourceShop(shopId, id, sysUserId);
});
}
} }

View File

@ -1,14 +1,18 @@
package com.czg.controller.admin; package com.czg.controller.admin;
import cn.hutool.core.thread.ThreadUtil;
import com.czg.log.annotation.OperationLog; import com.czg.log.annotation.OperationLog;
import com.czg.product.dto.ShopProdUnitDTO; import com.czg.product.dto.ShopProdUnitDTO;
import com.czg.product.service.ShopProdUnitService; import com.czg.product.service.ShopProdUnitService;
import com.czg.product.service.ShopSyncService;
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;
import com.czg.validator.group.UpdateGroup; import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -28,6 +32,9 @@ import java.util.List;
public class ShopProdUnitController { public class ShopProdUnitController {
private final ShopProdUnitService shopProdUnitService; private final ShopProdUnitService shopProdUnitService;
@Resource
private ShopSyncService shopSyncService;
@GetMapping("page") @GetMapping("page")
@OperationLog("商品单位-分页") @OperationLog("商品单位-分页")
@ -58,9 +65,8 @@ public class ShopProdUnitController {
@OperationLog("商品单位-新增") @OperationLog("商品单位-新增")
//@SaAdminCheckPermission("shopProdUnit:add") //@SaAdminCheckPermission("shopProdUnit:add")
public CzgResult<Void> addShopProdUnit(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ShopProdUnitDTO dto) { public CzgResult<Void> addShopProdUnit(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ShopProdUnitDTO dto) {
Long id = shopProdUnitService.addShopProdUnit(dto);
shopProdUnitService.addShopProdUnit(dto); asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
@ -68,9 +74,8 @@ public class ShopProdUnitController {
@OperationLog("商品单位-修改") @OperationLog("商品单位-修改")
//@SaAdminCheckPermission("shopProdUnit:update") //@SaAdminCheckPermission("shopProdUnit:update")
public CzgResult<Void> updateShopProdUnit(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ShopProdUnitDTO dto) { public CzgResult<Void> updateShopProdUnit(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ShopProdUnitDTO dto) {
shopProdUnitService.updateShopProdUnit(dto); shopProdUnitService.updateShopProdUnit(dto);
asyncToBranchShop(dto.getId());
return CzgResult.success(); return CzgResult.success();
} }
@ -91,6 +96,7 @@ public class ShopProdUnitController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
shopProdUnitService.disableShopProdUnit(id); shopProdUnitService.disableShopProdUnit(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
@ -101,8 +107,16 @@ public class ShopProdUnitController {
//效验数据 //效验数据
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
shopProdUnitService.enableShopProdUnit(id); shopProdUnitService.enableShopProdUnit(id);
asyncToBranchShop(id);
return CzgResult.success(); return CzgResult.success();
} }
private void asyncToBranchShop(Long id) {
long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> {
shopSyncService.syncUnitBySourceShop(shopId, id, sysUserId);
});
}
} }

View File

@ -28,6 +28,11 @@
<groupId>cn.dev33</groupId> <groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot3-starter</artifactId> <artifactId>sa-token-spring-boot3-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.tomcat.embed</groupId> <groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId> <artifactId>tomcat-embed-core</artifactId>

View File

@ -16,6 +16,7 @@ import cn.dev33.satoken.stp.StpLogic;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.czg.exception.ApiNotPrintException; import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
import com.mybatisflex.core.row.DbChain;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -57,12 +58,13 @@ public class MyStpLogic {
/** /**
* 身份切换 * 身份切换
* @param id 用户id *
* @param account 账户名 * @param id 用户id
* @param shopId 店铺id * @param account 账户名
* @param shopName 店铺名称 * @param shopId 店铺id
* @param shopName 店铺名称
* @param loginType 登录类型 * @param loginType 登录类型
* @param isAdmin 是否管理员 * @param isAdmin 是否管理员
*/ */
public void switchTo(boolean isMain, Long id, String account, Long shopId, String shopName, LoginType loginType, boolean isAdmin) { public void switchTo(boolean isMain, Long id, String account, Long shopId, String shopName, LoginType loginType, boolean isAdmin) {
StpLogic logic = getLogic(); StpLogic logic = getLogic();
@ -113,7 +115,6 @@ public class MyStpLogic {
} }
/** /**
* 获取当前登录账号名称 管理端为用户账号 客户端为openId * 获取当前登录账号名称 管理端为用户账号 客户端为openId
* *
@ -137,6 +138,7 @@ public class MyStpLogic {
/** /**
* 获取主店铺id * 获取主店铺id
*
* @return id * @return id
*/ */
public Long getHeadId() { public Long getHeadId() {
@ -200,6 +202,19 @@ public class MyStpLogic {
return shopId == null ? defaultVal : shopId; return shopId == null ? defaultVal : shopId;
} }
/**
* 获取主店id
* @return 主店id
*/
public Long getHeadShopId() {
Long shopId = getShopId(0L);
Long mainId = DbChain.table("tb_shop_config").select("main_id").where("id = ? and is_enable_vip_sync = ?", shopId, 1).objAs(Long.class);
if (mainId != null) {
return mainId;
}
return shopId;
}
/** /**
* 校验是否为管理端登录 * 校验是否为管理端登录
*/ */
@ -941,9 +956,6 @@ public class MyStpLogic {
} }
public void endSwitch() { public void endSwitch() {
getLogic().endSwitch(); getLogic().endSwitch();
} }

View File

@ -12,6 +12,7 @@ import lombok.EqualsAndHashCode;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* 商品规格 * 商品规格
@ -81,5 +82,9 @@ public class ShopProdSpecDTO extends TreeNode<ShopProdSpecDTO> implements Serial
*/ */
@JSONField(format = "yyyy-MM-dd HH:mm:ss") @JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime; private LocalDateTime updateTime;
/**
* 受影响的规格id列表
*/
@JSONField(serialize = false)
private List<Long> affectedIdList;
} }

View File

@ -25,6 +25,7 @@ public interface ShopProdUnitService extends IService<ShopProdUnit> {
/** /**
* 获取商品单位列表 * 获取商品单位列表
*
* @param param 查询参数 * @param param 查询参数
* @return 商品单位列表数据 * @return 商品单位列表数据
*/ */
@ -32,6 +33,7 @@ public interface ShopProdUnitService extends IService<ShopProdUnit> {
/** /**
* 获取商品单位详情 * 获取商品单位详情
*
* @param id 商品单位ID * @param id 商品单位ID
* @return 商品单位详情数据 * @return 商品单位详情数据
*/ */
@ -41,8 +43,9 @@ public interface ShopProdUnitService extends IService<ShopProdUnit> {
* 新增商品单位 * 新增商品单位
* *
* @param dto 商品单位数据 * @param dto 商品单位数据
* @return 新增商品单位ID
*/ */
void addShopProdUnit(ShopProdUnitDTO dto); Long addShopProdUnit(ShopProdUnitDTO dto);
/** /**
* 更新商品单位 * 更新商品单位

View File

@ -2,7 +2,6 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.hutool.log.Log;
import com.czg.account.dto.ShopBranchDTO; import com.czg.account.dto.ShopBranchDTO;
import com.czg.account.entity.ShopConfig; import com.czg.account.entity.ShopConfig;
import com.czg.account.entity.ShopInfo; import com.czg.account.entity.ShopInfo;
@ -109,12 +108,14 @@ public class ShopBranchServiceImpl implements ShopBranchService {
branchConfig.setIsEnableConsSync(YesNoEnum.YES.value()); branchConfig.setIsEnableConsSync(YesNoEnum.YES.value());
branchConfig.setIsEnableVipSync(YesNoEnum.YES.value()); branchConfig.setIsEnableVipSync(YesNoEnum.YES.value());
shopConfigMapper.update(branchConfig); shopConfigMapper.update(branchConfig);
// ThreadUtil.execAsync(() -> { long sysUserId = StpKit.USER.getLoginIdAsLong();
log.info("开始同步店铺id{}分店id{} 操作人Id:{}", shopId, branchShop.getId(), StpKit.USER.getLoginIdAsLong()); ThreadUtil.execAsync(() -> {
ThreadUtil.safeSleep(3000L);
log.info("开始同步店铺id{}分店id{} 操作人Id:{}", shopId, branchShop.getId(), sysUserId);
// 同步商品和耗材 // 同步商品和耗材
shopSyncService.sync(shopId, branchShop.getId(), StpKit.USER.getLoginIdAsLong()); shopSyncService.sync(shopId, branchShop.getId(), sysUserId);
log.info("同步结束店铺id{}分店id{} 操作人Id:{}", shopId, branchShop.getId(), StpKit.USER.getLoginIdAsLong()); log.info("同步结束店铺id{}分店id{} 操作人Id:{}", shopId, branchShop.getId(), sysUserId);
// }); });
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
// 同步会员信息 // 同步会员信息
shopUserSyncService.syncMergeShopUser(shopId, branchShop.getId()); shopUserSyncService.syncMergeShopUser(shopId, branchShop.getId());

View File

@ -9,6 +9,7 @@ import com.czg.account.entity.*;
import com.czg.account.service.*; import com.czg.account.service.*;
import com.czg.config.RedisCst; import com.czg.config.RedisCst;
import com.czg.enums.ShopUserFlowBizEnum; import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.enums.YesNoEnum;
import com.czg.exception.ApiNotPrintException; import com.czg.exception.ApiNotPrintException;
import com.czg.order.entity.OrderInfo; import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderDetailService; import com.czg.order.service.OrderDetailService;
@ -16,6 +17,7 @@ import com.czg.order.service.OrderInfoService;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
import com.czg.service.RedisService; import com.czg.service.RedisService;
import com.czg.service.account.mapper.ShopConfigMapper;
import com.czg.service.account.mapper.ShopInfoMapper; import com.czg.service.account.mapper.ShopInfoMapper;
import com.czg.service.account.mapper.ShopUserMapper; import com.czg.service.account.mapper.ShopUserMapper;
import com.czg.system.entity.SysParams; import com.czg.system.entity.SysParams;
@ -67,6 +69,8 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
private ShopExtendService shopExtendService; private ShopExtendService shopExtendService;
@Resource @Resource
private FreeDineConfigService freeDineConfigService; private FreeDineConfigService freeDineConfigService;
@Resource
private ShopConfigMapper shopConfigMapper;
private ShopUser getUserInfo(Long shopId, Long shopUserId) { private ShopUser getUserInfo(Long shopId, Long shopUserId) {
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one(); ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one();
@ -80,7 +84,7 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override @Override
public Page<ShopUserDTO> getPage(String key, Integer isVip, BigDecimal amount) { public Page<ShopUserDTO> getPage(String key, Integer isVip, BigDecimal amount) {
PageHelper.startPage(PageUtil.buildPageHelp()); PageHelper.startPage(PageUtil.buildPageHelp());
return PageUtil.convert(new PageInfo<>(mapper.selectPageByKeyAndIsVip(StpKit.USER.getShopId(), isVip, key, amount))); return PageUtil.convert(new PageInfo<>(mapper.selectPageByKeyAndIsVip(StpKit.USER.getHeadShopId(), isVip, key, amount)));
} }
@Override @Override
@ -148,6 +152,10 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override @Override
public ShopUser getShopUserInfo(Long shopId, long userId) { public ShopUser getShopUserInfo(Long shopId, long userId) {
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopId);
if (shopConfig != null && shopConfig.getIsEnableVipSync() == YesNoEnum.YES.value() && shopConfig.getMainId() != null) {
shopId = shopConfig.getMainId();
}
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userId).one(); ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userId).one();
if (shopUser == null) { if (shopUser == null) {
shopUser = new ShopUser(); shopUser = new ShopUser();
@ -185,6 +193,10 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override @Override
public CzgResult<String> getCode(long userInfoId, long shopId) { public CzgResult<String> getCode(long userInfoId, long shopId) {
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopId);
if (shopConfig != null && shopConfig.getIsEnableVipSync() == YesNoEnum.YES.value() && shopConfig.getMainId() != null) {
shopId = shopConfig.getMainId();
}
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfoId).one(); ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfoId).one();
AssertUtil.isNull(shopUser, "会员信息不存在"); AssertUtil.isNull(shopUser, "会员信息不存在");
if (shopUser.getIsVip().equals(0)) { if (shopUser.getIsVip().equals(0)) {
@ -300,6 +312,10 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override @Override
public ShopUserDetailDTO getInfo(Long shopId, long userId) { public ShopUserDetailDTO getInfo(Long shopId, long userId) {
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopId);
if (shopConfig != null && shopConfig.getIsEnableVipSync() == YesNoEnum.YES.value() && shopConfig.getMainId() != null) {
shopId = shopConfig.getMainId();
}
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userId)); ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userId));
UserInfo userInfo = userInfoService.getById(userId); UserInfo userInfo = userInfoService.getById(userId);
if (userInfo == null) { if (userInfo == null) {
@ -336,11 +352,11 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override @Override
public ShopUser getDetail(Integer id, Integer userId) { public ShopUser getDetail(Integer id, Integer userId) {
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getShopId()).eq(ShopUser::getId, id).eq(ShopUser::getUserId, userId)); ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getHeadShopId()).eq(ShopUser::getId, id).eq(ShopUser::getUserId, userId));
long count = shopActivateCouponRecordService.count(new QueryWrapper().eq(ShopActivateCouponRecord::getShopUserId, shopUser.getId()).eq(ShopActivateCouponRecord::getStatus, 0)); long count = shopActivateCouponRecordService.count(new QueryWrapper().eq(ShopActivateCouponRecord::getShopUserId, shopUser.getId()).eq(ShopActivateCouponRecord::getStatus, 0));
ShopUserDTO shopUserDTO = BeanUtil.copyProperties(shopUser, ShopUserDTO.class); ShopUserDTO shopUserDTO = BeanUtil.copyProperties(shopUser, ShopUserDTO.class);
shopUserDTO.setCouponNum(count); shopUserDTO.setCouponNum(count);
shopUserDTO.setOrderNumber(orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId).eq(OrderInfo::getShopId, shopUser.getShopId()).eq(OrderInfo::getStatus, "done"))); shopUserDTO.setOrderNumber(orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId).eq(OrderInfo::getShopId, StpKit.USER.getShopId(0L)).eq(OrderInfo::getStatus, "done")));
return shopUserDTO; return shopUserDTO;
} }
} }

View File

@ -9,9 +9,11 @@ import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter; import com.alibaba.fastjson2.JSONWriter;
import com.czg.account.entity.ShopUser; import com.czg.account.entity.ShopUser;
import com.czg.account.entity.ShopUserFlow;
import com.czg.account.service.ShopUserSyncService; import com.czg.account.service.ShopUserSyncService;
import com.czg.service.account.mapper.ShopUserMapper; import com.czg.service.account.mapper.ShopUserMapper;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -56,12 +58,20 @@ public class ShopUserSyncServiceImpl implements ShopUserSyncService {
})); }));
// 分店没有绑定手机号的会员 // 分店没有绑定手机号的会员
for (ShopUser shopUser : branchShopNotPhoneUserList) { for (ShopUser shopUser : branchShopNotPhoneUserList) {
Long historyShopId = shopUser.getShopId();
Long historyUserId = shopUser.getUserId();
JSONObject branch = JSONObject.from(shopUser, JSONWriter.Feature.WriteMapNullValue); JSONObject branch = JSONObject.from(shopUser, JSONWriter.Feature.WriteMapNullValue);
JSONArray objects = new JSONArray(); JSONArray objects = new JSONArray();
objects.add(branch); objects.add(branch);
shopUser.setShopId(headShopId); shopUser.setShopId(headShopId);
shopUser.setMergedUsers(objects.toJSONString(JSONWriter.Feature.WriteMapNullValue)); shopUser.setMergedUsers(objects.toJSONString(JSONWriter.Feature.WriteMapNullValue));
shopUserMapper.update(shopUser); shopUserMapper.update(shopUser);
// 更新会员流水记录到主店
UpdateChain.of(ShopUserFlow.class)
.set(ShopUserFlow::getShopId, headShopId)
.eq(ShopUserFlow::getShopId, historyShopId)
.eq(ShopUserFlow::getUserId, historyUserId)
.update();
} }
List<ShopUser> headShopUserList = shopUserMapper.selectListByQuery(QueryWrapper.create().eq(ShopUser::getShopId, headShopId).isNotNull(ShopUser::getPhone)); List<ShopUser> headShopUserList = shopUserMapper.selectListByQuery(QueryWrapper.create().eq(ShopUser::getShopId, headShopId).isNotNull(ShopUser::getPhone));
List<ShopUser> branchShopUserList = shopUserMapper.selectListByQuery(QueryWrapper.create().eq(ShopUser::getShopId, branchShopId).isNotNull(ShopUser::getPhone)); List<ShopUser> branchShopUserList = shopUserMapper.selectListByQuery(QueryWrapper.create().eq(ShopUser::getShopId, branchShopId).isNotNull(ShopUser::getPhone));
@ -114,6 +124,12 @@ public class ShopUserSyncServiceImpl implements ShopUserSyncService {
objects.add(JSONObject.from(branchShopUser, JSONWriter.Feature.WriteMapNullValue)); objects.add(JSONObject.from(branchShopUser, JSONWriter.Feature.WriteMapNullValue));
headShopUser.setMergedUsers(JSON.toJSONString(objects, JSONWriter.Feature.WriteMapNullValue)); headShopUser.setMergedUsers(JSON.toJSONString(objects, JSONWriter.Feature.WriteMapNullValue));
shopUserMapper.update(headShopUser); shopUserMapper.update(headShopUser);
// 更新会员流水记录到主店
UpdateChain.of(ShopUserFlow.class)
.set(ShopUserFlow::getShopId, headShopUser.getShopId())
.eq(ShopUserFlow::getShopId, branchShopUser.getShopId())
.eq(ShopUserFlow::getUserId, branchShopUser.getUserId())
.update();
shopUserMapper.delete(branchShopUser); shopUserMapper.delete(branchShopUser);
} }
@ -135,12 +151,20 @@ public class ShopUserSyncServiceImpl implements ShopUserSyncService {
*/ */
public void toMergeCase3(Long headShopId, ShopUser branchShopUser) { public void toMergeCase3(Long headShopId, ShopUser branchShopUser) {
// 合并逻辑3主店没有分店有把shop_id改为主店shop_id把分店会员信息jsonArray格式化存储至merged_users字段中 // 合并逻辑3主店没有分店有把shop_id改为主店shop_id把分店会员信息jsonArray格式化存储至merged_users字段中
Long historyShopId = branchShopUser.getShopId();
Long historyUserId = branchShopUser.getUserId();
JSONObject branch = JSONObject.from(branchShopUser, JSONWriter.Feature.WriteMapNullValue); JSONObject branch = JSONObject.from(branchShopUser, JSONWriter.Feature.WriteMapNullValue);
JSONArray objects = new JSONArray(); JSONArray objects = new JSONArray();
objects.add(branch); objects.add(branch);
branchShopUser.setShopId(headShopId); branchShopUser.setShopId(headShopId);
branchShopUser.setMergedUsers(objects.toJSONString(JSONWriter.Feature.WriteMapNullValue)); branchShopUser.setMergedUsers(objects.toJSONString(JSONWriter.Feature.WriteMapNullValue));
shopUserMapper.update(branchShopUser); shopUserMapper.update(branchShopUser);
// 更新会员流水记录到主店
UpdateChain.of(ShopUserFlow.class)
.set(ShopUserFlow::getShopId, headShopId)
.eq(ShopUserFlow::getShopId, historyShopId)
.eq(ShopUserFlow::getUserId, historyUserId)
.update();
} }
} }

View File

@ -6,7 +6,6 @@ import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO; import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.*; import com.czg.account.entity.*;
@ -43,7 +42,6 @@ import com.czg.system.service.SysParamsService;
import com.czg.utils.AssertUtil; import com.czg.utils.AssertUtil;
import com.czg.utils.MD5Util; import com.czg.utils.MD5Util;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import lombok.NonNull; import lombok.NonNull;
@ -656,7 +654,7 @@ public class PayServiceImpl implements PayService {
.setType(1) .setType(1)
.setRelationId(orderInfo.getId()) .setRelationId(orderInfo.getId())
.setBizEnum(ShopUserFlowBizEnum.ORDER_REFUND); .setBizEnum(ShopUserFlowBizEnum.ORDER_REFUND);
shopUserService.updateMoney(orderInfo.getShopId(), shopUserMoneyEditDTO); shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
} else if (orderInfo.getPayType().equals(PayEnums.CREDIT_PAY.getValue())) { } else if (orderInfo.getPayType().equals(PayEnums.CREDIT_PAY.getValue())) {
AssertUtil.isNull(orderInfo.getCreditBuyerId(), "挂账单退款失败,未查询到挂账人"); AssertUtil.isNull(orderInfo.getCreditBuyerId(), "挂账单退款失败,未查询到挂账人");
buyerOrderService.partRefund(orderInfo.getCreditBuyerId().toString(), orderInfo.getId(), param.getRefundAmount()); buyerOrderService.partRefund(orderInfo.getCreditBuyerId().toString(), orderInfo.getId(), param.getRefundAmount());

View File

@ -82,6 +82,7 @@ public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup
//entity.setStatus(StatusEnum.ENABLED.value()); //entity.setStatus(StatusEnum.ENABLED.value());
entity.setShopId(shopId); entity.setShopId(shopId);
super.save(entity); super.save(entity);
dto.setId(entity.getId());
} }
@Override @Override

View File

@ -128,6 +128,7 @@ public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> i
entity.setIsStock(YesNoEnum.NO.value()); entity.setIsStock(YesNoEnum.NO.value());
entity.setShopId(shopId); entity.setShopId(shopId);
super.save(entity); super.save(entity);
dto.setId(entity.getId());
return true; return true;
} }

View File

@ -31,8 +31,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.czg.constant.CacheConstant.ADMIN_CLIENT_PRODUCT_LIST;
/** /**
* 商品分组 * 商品分组
* *
@ -98,6 +96,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
ProdGroup entity = BeanUtil.copyProperties(dto, ProdGroup.class); ProdGroup entity = BeanUtil.copyProperties(dto, ProdGroup.class);
entity.setShopId(shopId); entity.setShopId(shopId);
super.save(entity); super.save(entity);
dto.setId(entity.getId());
Long[] productIds = dto.getProductIds(); Long[] productIds = dto.getProductIds();
if (ArrayUtil.isNotEmpty(productIds)) { if (ArrayUtil.isNotEmpty(productIds)) {
int sort = 0; int sort = 0;

View File

@ -278,6 +278,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
flow.setInOutType(InOutTypeEnum.IN.value()); flow.setInOutType(InOutTypeEnum.IN.value());
flow.setInOutItem(InOutItemEnum.WIN_IN.value()); flow.setInOutItem(InOutItemEnum.WIN_IN.value());
productStockFlowService.saveFlow(flow); productStockFlowService.saveFlow(flow);
dto.setId(entity.getId());
} }
@Override @Override

View File

@ -74,6 +74,7 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
entity.setPid(0L); entity.setPid(0L);
entity.setShopId(shopId); entity.setShopId(shopId);
super.save(entity); super.save(entity);
dto.setId(entity.getId());
} }
@Override @Override

View File

@ -67,7 +67,7 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
} }
@Override @Override
public void addShopProdUnit(ShopProdUnitDTO dto) { public Long addShopProdUnit(ShopProdUnitDTO dto) {
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query().eq(ShopProdUnit::getName, dto.getName()) boolean exists = super.exists(query().eq(ShopProdUnit::getName, dto.getName())
.and(q -> { .and(q -> {
@ -88,6 +88,7 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
entity.setStatus(StatusEnum.ENABLED.value()); entity.setStatus(StatusEnum.ENABLED.value());
entity.setShopId(shopId); entity.setShopId(shopId);
super.save(entity); super.save(entity);
return entity.getId();
} }
@Override @Override

View File

@ -17,11 +17,13 @@ import com.czg.utils.PageUtil;
import com.czg.utils.TreeUtils; import com.czg.utils.TreeUtils;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.DbChain;
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 org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.czg.product.entity.table.ShopProdSpecTableDef.SHOP_PROD_SPEC; import static com.czg.product.entity.table.ShopProdSpecTableDef.SHOP_PROD_SPEC;
@ -36,7 +38,6 @@ import static com.czg.product.entity.table.ShopProdSpecTableDef.SHOP_PROD_SPEC;
@Service @Service
public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper, ShopProdSpec> implements ShopProdSpecService { public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper, ShopProdSpec> implements ShopProdSpecService {
private QueryWrapper buildQueryWrapper(ShopProdSpecDTO param) { private QueryWrapper buildQueryWrapper(ShopProdSpecDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper(); QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
if (ObjUtil.isNotNull(param.getPid())) { if (ObjUtil.isNotNull(param.getPid())) {
@ -110,6 +111,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateShopProdSpec(ShopProdSpecDTO dto) { public void updateShopProdSpec(ShopProdSpecDTO dto) {
List<Long> affectedIdList = new ArrayList<>();
//上级规格不能为自身 //上级规格不能为自身
if (dto.getId().equals(dto.getPid())) { if (dto.getId().equals(dto.getPid())) {
throw new CzgException("上级规格不能为自身"); throw new CzgException("上级规格不能为自身");
@ -142,6 +144,10 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
.like(ShopProdSpec::getPids, "," + entity.getId() + ",") .like(ShopProdSpec::getPids, "," + entity.getId() + ",")
.eq(ShopProdSpec::getShopId, entity.getShopId()).update(); .eq(ShopProdSpec::getShopId, entity.getShopId()).update();
super.updateById(entity); super.updateById(entity);
affectedIdList.add(entity.getId());
List<Long> ids = DbChain.table("tb_shop_prod_spec").select("id").where("pids like concat('%,',?,',%') and shop_id = ?", entity.getId(), entity.getShopId()).listAs(Long.class);
affectedIdList.addAll(ids);
dto.setAffectedIdList(affectedIdList);
} }
@Override @Override
@ -174,6 +180,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void quickAddShopProdSpec(ShopProdSpecDTO dto) { public void quickAddShopProdSpec(ShopProdSpecDTO dto) {
List<Long> affectedIdList = new ArrayList<>();
String name = dto.getName(); String name = dto.getName();
AssertUtil.isBlank(name, "1级规格名称不能为空"); AssertUtil.isBlank(name, "1级规格名称不能为空");
List<ShopProdSpecDTO> level2List = dto.getChildren(); List<ShopProdSpecDTO> level2List = dto.getChildren();
@ -201,6 +208,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
dto.setSort(ObjUtil.defaultIfNull(maxId, 0).intValue() + 1); dto.setSort(ObjUtil.defaultIfNull(maxId, 0).intValue() + 1);
dto.setPid(GlobalConstant.TREE_ROOT); dto.setPid(GlobalConstant.TREE_ROOT);
addShopProdSpec(dto); addShopProdSpec(dto);
affectedIdList.add(dto.getId());
int xIndex = 0; int xIndex = 0;
for (ShopProdSpecDTO level2Dto : level2List) { for (ShopProdSpecDTO level2Dto : level2List) {
xIndex++; xIndex++;
@ -208,6 +216,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
level2Dto.setSort(xIndex); level2Dto.setSort(xIndex);
level2Dto.setPid(dto.getId()); level2Dto.setPid(dto.getId());
addShopProdSpec(level2Dto); addShopProdSpec(level2Dto);
affectedIdList.add(level2Dto.getId());
List<ShopProdSpecDTO> level3List = level2Dto.getChildren(); List<ShopProdSpecDTO> level3List = level2Dto.getChildren();
int yIndex = 0; int yIndex = 0;
for (ShopProdSpecDTO level3Dto : level3List) { for (ShopProdSpecDTO level3Dto : level3List) {
@ -216,8 +225,10 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
level3Dto.setSort(yIndex); level3Dto.setSort(yIndex);
level3Dto.setPid(level2Dto.getId()); level3Dto.setPid(level2Dto.getId());
addShopProdSpec(level3Dto); addShopProdSpec(level3Dto);
affectedIdList.add(level3Dto.getId());
} }
} }
dto.setAffectedIdList(affectedIdList);
} }
@Override @Override

View File

@ -3,7 +3,6 @@ package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
@ -18,14 +17,12 @@ import com.czg.exception.CzgException;
import com.czg.product.entity.*; import com.czg.product.entity.*;
import com.czg.product.service.*; import com.czg.product.service.*;
import com.czg.product.vo.ProductGroupVo; import com.czg.product.vo.ProductGroupVo;
import com.czg.sa.StpKit;
import com.czg.utils.AssertUtil; import com.czg.utils.AssertUtil;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;