diff --git a/cash-api/account-server/src/main/java/com/czg/controller/admin/ShopPagePermissionController.java b/cash-api/account-server/src/main/java/com/czg/controller/admin/ShopPagePermissionController.java index 32bf9561..1b98294c 100644 --- a/cash-api/account-server/src/main/java/com/czg/controller/admin/ShopPagePermissionController.java +++ b/cash-api/account-server/src/main/java/com/czg/controller/admin/ShopPagePermissionController.java @@ -56,12 +56,10 @@ public class ShopPagePermissionController { */ @GetMapping("/detail") public CzgResult> detail(@RequestParam Long staffId) { - Set pageIdList = shopStaffPagePermissionService.list(new QueryWrapper().eq(ShopStaffPagePermission::getShopId, - StpKit.USER.getShopId()).eq(ShopStaffPagePermission::getStaffId, staffId)).stream().map(ShopStaffPagePermission::getPagePathId).collect(Collectors.toSet()); - if (pageIdList.isEmpty()) { - return CzgResult.success(new ArrayList<>()); + if (StpKit.USER.isStaff() && StpKit.USER.getLoginIdAsLong() != staffId) { + return CzgResult.failure("员工无权限"); } - return CzgResult.success(shopPagePathService.list(new QueryWrapper().in(ShopPagePath::getId, pageIdList))); + return CzgResult.success(shopPagePathService.detail(staffId)); } /** diff --git a/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopPagePathService.java b/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopPagePathService.java index 8f4d95c9..76e2e9c5 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopPagePathService.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/account/service/ShopPagePathService.java @@ -3,6 +3,8 @@ package com.czg.account.service; import com.mybatisflex.core.service.IService; import com.czg.account.entity.ShopPagePath; +import java.util.List; + /** * 服务层。 * @@ -11,4 +13,5 @@ import com.czg.account.entity.ShopPagePath; */ public interface ShopPagePathService extends IService { + List detail(Long staffId); } diff --git a/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopPagePathServiceImpl.java b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopPagePathServiceImpl.java index 02cf681d..be3b2357 100644 --- a/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopPagePathServiceImpl.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/ShopPagePathServiceImpl.java @@ -1,10 +1,22 @@ package com.czg.service.account.service.impl; +import com.czg.account.entity.ShopStaffPagePermission; +import com.czg.account.service.ShopStaffPagePermissionService; +import com.czg.resp.CzgResult; +import com.czg.sa.StpKit; +import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.spring.service.impl.ServiceImpl; import com.czg.account.entity.ShopPagePath; import com.czg.account.service.ShopPagePathService; import com.czg.service.account.mapper.ShopPagePathMapper; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * 服务层实现。 @@ -14,5 +26,24 @@ import org.springframework.stereotype.Service; */ @Service public class ShopPagePathServiceImpl extends ServiceImpl implements ShopPagePathService{ + @Resource + private ShopStaffPagePermissionService shopStaffPagePermissionService; + @Override + public List detail(Long staffId) { + Set pageIdList = shopStaffPagePermissionService.list(new QueryWrapper().eq(ShopStaffPagePermission::getShopId, + StpKit.USER.getShopId()).eq(ShopStaffPagePermission::getStaffId, staffId)).stream().map(ShopStaffPagePermission::getPagePathId).collect(Collectors.toSet()); + if (pageIdList.isEmpty()) { + list().forEach(item -> { + ShopStaffPagePermission permission = new ShopStaffPagePermission(); + permission.setShopId(StpKit.USER.getShopId()); + permission.setStaffId(staffId); + permission.setPagePathId(item.getId()); + shopStaffPagePermissionService.save(permission); + pageIdList.add(permission.getPagePathId()); + }); + } + + return list(new QueryWrapper().in(ShopPagePath::getId, pageIdList)); + } }