整理上线初始化SQL基线并收口管理师接口
This commit is contained in:
+239
@@ -0,0 +1,239 @@
|
||||
package com.xiaowang.fingertipdesigner.core.modules.manager.controller.admin;
|
||||
|
||||
import com.xiaowang.fingertipdesigner.core.annotation.OperationGuard;
|
||||
import com.xiaowang.fingertipdesigner.core.annotation.RequirePermission;
|
||||
import com.xiaowang.fingertipdesigner.core.common.Result;
|
||||
import com.xiaowang.fingertipdesigner.core.common.vo.PageResultVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.dto.ArtistScheduleDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.dto.NailArtistInfoDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.service.ArtistScheduleService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.service.NailArtistInfoService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.vo.ArtistScheduleVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.planning.vo.PlanningCalendarVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.product.service.ProductService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.product.vo.ProductVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.shop.dto.ShopDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.shop.service.ShopService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.shop.vo.ShopVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.dto.UserDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.service.UserService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.vo.UserVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/manager")
|
||||
@RequiredArgsConstructor
|
||||
public class AdminManagerController {
|
||||
|
||||
private final PlanningService planningService;
|
||||
private final UserService userService;
|
||||
private final NailArtistInfoService nailArtistInfoService;
|
||||
private final ArtistScheduleService artistScheduleService;
|
||||
private final ProductService productService;
|
||||
private final ShopService shopService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
@GetMapping("/planning/calendar")
|
||||
@RequirePermission("schedule:view")
|
||||
public Result<PlanningCalendarVO> calendar(HttpServletRequest request,
|
||||
@RequestParam(required = false) String startDate,
|
||||
@RequestParam(required = false) String endDate,
|
||||
@RequestParam(required = false) Long artistId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
LocalDate start = startDate == null || startDate.isBlank() ? LocalDate.now() : LocalDate.parse(startDate);
|
||||
LocalDate end = endDate == null || endDate.isBlank() ? start : LocalDate.parse(endDate);
|
||||
return Result.success(planningService.getCalendar(currentUser, start, end, artistId));
|
||||
}
|
||||
|
||||
@PostMapping("/planning/appointments")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-create-appointment", ttlSeconds = 10, message = "预约创建处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> createAppointment(HttpServletRequest request,
|
||||
@RequestBody PlanningAppointmentCreateDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.createAppointment(currentUser, dto));
|
||||
}
|
||||
|
||||
@GetMapping("/planning/appointments/{orderItemId}")
|
||||
@RequirePermission("order:view")
|
||||
public Result<PlanningAppointmentVO> appointment(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.getAppointment(currentUser, orderItemId));
|
||||
}
|
||||
|
||||
@PutMapping("/planning/appointments/{orderItemId}/time-artist")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-move-appointment", ttlSeconds = 10, message = "预约调整处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> moveAppointment(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId,
|
||||
@RequestBody PlanningAppointmentMoveDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.moveAppointment(currentUser, orderItemId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/planning/appointments/{orderId}/status")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-update-appointment-status", ttlSeconds = 10, message = "预约状态处理中,请勿重复提交")
|
||||
public Result<Boolean> updateStatus(HttpServletRequest request,
|
||||
@PathVariable Long orderId,
|
||||
@RequestBody PlanningAppointmentStatusDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.updateStatus(currentUser, orderId, dto));
|
||||
}
|
||||
|
||||
@GetMapping("/customers")
|
||||
@RequirePermission("user:view")
|
||||
public Result<PageResultVO<UserVO>> customers(HttpServletRequest request,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) Long shopId,
|
||||
@RequestParam(required = false) Boolean hasOrder) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long resolvedShopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||
PageResultVO<UserVO> result = userService.pageUsers(page, size, keyword, resolvedShopId, 0, null, null, null, null, null, null, null, null, hasOrder);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@GetMapping("/customers/{id}")
|
||||
@RequirePermission("user:view")
|
||||
public Result<UserVO> customer(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, id, "无权查看其他店铺客户");
|
||||
return Result.success(userService.getUserById(id));
|
||||
}
|
||||
|
||||
@GetMapping("/employees")
|
||||
@RequirePermission("nail_artist:view")
|
||||
public Result<List<NailArtistInfoDTO>> employees(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
if (adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
return Result.success(nailArtistInfoService.getAllNailArtists());
|
||||
}
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
return Result.success(nailArtistInfoService.getByShopId(shopId));
|
||||
}
|
||||
|
||||
@GetMapping("/employees/{userId}")
|
||||
@RequirePermission("nail_artist:view")
|
||||
public Result<NailArtistInfoDTO> employee(HttpServletRequest request, @PathVariable Long userId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userId, "无权查看其他店铺员工");
|
||||
}
|
||||
return Result.success(nailArtistInfoService.getByUserId(userId));
|
||||
}
|
||||
|
||||
@PostMapping("/employees")
|
||||
@RequirePermission("nail_artist:edit")
|
||||
@OperationGuard(action = "manager-nail-artist-save", ttlSeconds = 10, message = "员工信息保存处理中,请勿重复提交")
|
||||
public Result<NailArtistInfoDTO> saveEmployee(HttpServletRequest request,
|
||||
@RequestBody NailArtistInfoDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, dto.getUserId(), "无权编辑其他店铺员工");
|
||||
}
|
||||
return Result.success(nailArtistInfoService.saveOrUpdateNailArtistInfo(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/employees/users")
|
||||
@RequirePermission("user:create")
|
||||
@OperationGuard(action = "manager-user-create", ttlSeconds = 10, message = "员工账号创建处理中,请勿重复提交")
|
||||
public Result<Long> createEmployeeUser(HttpServletRequest request,
|
||||
@Valid @RequestBody UserDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
adminScopeHelper.ensureAssignableUserType(currentUser, dto.getType());
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
Long managedShopId = adminScopeHelper.getManagedShopId(currentUser);
|
||||
dto.setShopId(managedShopId);
|
||||
dto.setShopIds(List.of(managedShopId));
|
||||
}
|
||||
return Result.success(userService.createUser(dto));
|
||||
}
|
||||
|
||||
@GetMapping("/employees/schedules")
|
||||
@RequirePermission("schedule:view")
|
||||
public Result<List<ArtistScheduleVO>> schedules(HttpServletRequest request,
|
||||
@RequestParam(required = false) Long artistId,
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
return Result.success(artistScheduleService.listSchedules(shopId, artistId, startDate, endDate));
|
||||
}
|
||||
|
||||
@PostMapping("/employees/schedules")
|
||||
@RequirePermission("schedule:edit")
|
||||
@OperationGuard(action = "manager-artist-schedule-save", ttlSeconds = 10, message = "排班保存处理中,请勿重复提交")
|
||||
public Result<ArtistScheduleVO> saveSchedule(HttpServletRequest request,
|
||||
@RequestBody ArtistScheduleDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
dto.setShopId(adminScopeHelper.resolveShopScope(currentUser, dto.getShopId()));
|
||||
return Result.success(artistScheduleService.saveSchedule(dto));
|
||||
}
|
||||
|
||||
@GetMapping("/products")
|
||||
@RequirePermission("product:view")
|
||||
public Result<PageResultVO<ProductVO>> products(HttpServletRequest request,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) Long shopId,
|
||||
@RequestParam(required = false) Long tagId,
|
||||
@RequestParam(required = false) java.math.BigDecimal minPrice,
|
||||
@RequestParam(required = false) java.math.BigDecimal maxPrice,
|
||||
@RequestParam(required = false) String createdFrom,
|
||||
@RequestParam(required = false) String createdTo) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long resolvedShopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||
return Result.success(productService.pageProducts(page, size, keyword, resolvedShopId, tagId, minPrice, maxPrice, createdFrom, createdTo));
|
||||
}
|
||||
|
||||
@GetMapping("/shop")
|
||||
@RequirePermission("shop:view")
|
||||
public Result<ShopVO> shop(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
adminScopeHelper.requireShopContext(currentUser);
|
||||
return Result.success(shopService.getShopById(shopId));
|
||||
}
|
||||
|
||||
@PutMapping("/shop")
|
||||
@RequirePermission("shop:edit")
|
||||
@OperationGuard(action = "manager-shop-update", ttlSeconds = 10, message = "店铺设置保存处理中,请勿重复提交")
|
||||
public Result<Boolean> updateShop(HttpServletRequest request, @RequestBody ShopDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
adminScopeHelper.requireShopContext(currentUser);
|
||||
ShopVO shop = shopService.getShopById(shopId);
|
||||
if (shop == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
dto.setAuthorizationExpireTime(shop.getAuthorizationExpireTime());
|
||||
}
|
||||
return Result.success(shopService.updateShop(shopId, dto));
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -2,6 +2,7 @@ package com.xiaowang.fingertipdesigner.core.modules.integration.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xiaowang.fingertipdesigner.core.config.BrandProperties;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.integration.entity.MessageHubPushConfigDO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.integration.service.MessageHubPushConfigService;
|
||||
import com.xiaowang.fingertipdesigner.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
@@ -34,6 +35,9 @@ class MessageHubClientServiceImplTest {
|
||||
@Mock
|
||||
private MessageHubPushConfigService messageHubPushConfigService;
|
||||
|
||||
@Mock
|
||||
private BrandProperties brandProperties;
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private MessageHubClientServiceImpl service;
|
||||
@@ -45,7 +49,8 @@ class MessageHubClientServiceImplTest {
|
||||
rabbitTemplate,
|
||||
objectMapper,
|
||||
snowflakeIdGenerator,
|
||||
messageHubPushConfigService
|
||||
messageHubPushConfigService,
|
||||
brandProperties
|
||||
);
|
||||
when(snowflakeIdGenerator.nextIdString()).thenReturn("sms-message-1");
|
||||
}
|
||||
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
package com.xiaowang.fingertipdesigner.core.modules.manager.controller.admin;
|
||||
|
||||
import com.xiaowang.fingertipdesigner.core.common.Result;
|
||||
import com.xiaowang.fingertipdesigner.core.common.vo.PageResultVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.dto.ArtistScheduleDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.dto.NailArtistInfoDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.service.ArtistScheduleService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.service.NailArtistInfoService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.artist.vo.ArtistScheduleVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.product.service.ProductService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.product.vo.ProductVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.shop.dto.ShopDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.shop.service.ShopService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.shop.vo.ShopVO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.dto.UserDTO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.service.UserService;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.vo.UserVO;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class AdminManagerControllerTest {
|
||||
|
||||
@Mock
|
||||
private PlanningService planningService;
|
||||
|
||||
@Mock
|
||||
private UserService userService;
|
||||
|
||||
@Mock
|
||||
private NailArtistInfoService nailArtistInfoService;
|
||||
|
||||
@Mock
|
||||
private ArtistScheduleService artistScheduleService;
|
||||
|
||||
@Mock
|
||||
private ProductService productService;
|
||||
|
||||
@Mock
|
||||
private ShopService shopService;
|
||||
|
||||
@Mock
|
||||
private AdminScopeHelper adminScopeHelper;
|
||||
|
||||
private AdminManagerController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
controller = new AdminManagerController(planningService, userService, nailArtistInfoService, artistScheduleService, productService, shopService, adminScopeHelper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void controllerShouldExposeManagerBoundary() {
|
||||
RequestMapping mapping = AdminManagerController.class.getAnnotation(RequestMapping.class);
|
||||
|
||||
assertThat(mapping.value()).containsExactly("/admin/manager");
|
||||
}
|
||||
|
||||
@Test
|
||||
void customersShouldResolveShopScopeAndForceCustomerType() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
UserDO manager = new UserDO();
|
||||
manager.setType(2);
|
||||
manager.setShopId(8L);
|
||||
PageResultVO<UserVO> pageResult = new PageResultVO<>();
|
||||
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
|
||||
when(adminScopeHelper.resolveShopScope(manager, 99L)).thenReturn(8L);
|
||||
when(userService.pageUsers(1, 10, "ann", 8L, 0, null, null, null, null, null, null, null, null, true)).thenReturn(pageResult);
|
||||
|
||||
Result<PageResultVO<UserVO>> result = controller.customers(request, 1, 10, "ann", 99L, true);
|
||||
|
||||
assertThat(result.getData()).isSameAs(pageResult);
|
||||
verify(adminScopeHelper).resolveShopScope(manager, 99L);
|
||||
verify(userService).pageUsers(1, 10, "ann", 8L, 0, null, null, null, null, null, null, null, null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createEmployeeUserShouldBindNonPlatformUserToManagedShop() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
UserDO manager = new UserDO();
|
||||
manager.setType(2);
|
||||
manager.setShopId(8L);
|
||||
UserDTO dto = new UserDTO();
|
||||
dto.setType(3);
|
||||
dto.setShopId(99L);
|
||||
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
|
||||
when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false);
|
||||
when(adminScopeHelper.getManagedShopId(manager)).thenReturn(8L);
|
||||
when(userService.createUser(dto)).thenReturn(101L);
|
||||
|
||||
Result<Long> result = controller.createEmployeeUser(request, dto);
|
||||
|
||||
assertThat(result.getData()).isEqualTo(101L);
|
||||
assertThat(dto.getShopId()).isEqualTo(8L);
|
||||
assertThat(dto.getShopIds()).containsExactly(8L);
|
||||
verify(adminScopeHelper).ensureAssignableUserType(manager, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveScheduleShouldResolveShopScopeBeforeSaving() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
UserDO manager = new UserDO();
|
||||
ArtistScheduleDTO dto = new ArtistScheduleDTO();
|
||||
dto.setShopId(99L);
|
||||
ArtistScheduleVO vo = new ArtistScheduleVO();
|
||||
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
|
||||
when(adminScopeHelper.resolveShopScope(manager, 99L)).thenReturn(8L);
|
||||
when(artistScheduleService.saveSchedule(dto)).thenReturn(vo);
|
||||
|
||||
Result<ArtistScheduleVO> result = controller.saveSchedule(request, dto);
|
||||
|
||||
assertThat(result.getData()).isSameAs(vo);
|
||||
assertThat(dto.getShopId()).isEqualTo(8L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateShopShouldPreserveAuthorizationExpireTimeForNonPlatformUser() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
UserDO manager = new UserDO();
|
||||
ShopDTO dto = new ShopDTO();
|
||||
ShopVO shop = new ShopVO();
|
||||
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
|
||||
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
|
||||
when(shopService.getShopById(8L)).thenReturn(shop);
|
||||
when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false);
|
||||
when(shopService.updateShop(8L, dto)).thenReturn(true);
|
||||
|
||||
Result<Boolean> result = controller.updateShop(request, dto);
|
||||
|
||||
assertThat(result.getData()).isTrue();
|
||||
verify(adminScopeHelper).requireShopContext(manager);
|
||||
verify(shopService).updateShop(8L, dto);
|
||||
}
|
||||
|
||||
@Test
|
||||
void employeesShouldReturnScopedArtistsForNonPlatformUser() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
UserDO manager = new UserDO();
|
||||
List<NailArtistInfoDTO> artists = List.of(new NailArtistInfoDTO());
|
||||
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
|
||||
when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false);
|
||||
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
|
||||
when(nailArtistInfoService.getByShopId(8L)).thenReturn(artists);
|
||||
|
||||
Result<List<NailArtistInfoDTO>> result = controller.employees(request);
|
||||
|
||||
assertThat(result.getData()).isSameAs(artists);
|
||||
}
|
||||
|
||||
@Test
|
||||
void productsShouldResolveShopScope() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
UserDO manager = new UserDO();
|
||||
PageResultVO<ProductVO> pageResult = new PageResultVO<>();
|
||||
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
|
||||
when(adminScopeHelper.resolveShopScope(manager, 99L)).thenReturn(8L);
|
||||
when(productService.pageProducts(1, 10, "gel", 8L, null, null, null, null, null)).thenReturn(pageResult);
|
||||
|
||||
Result<PageResultVO<ProductVO>> result = controller.products(request, 1, 10, "gel", 99L, null, null, null, null, null);
|
||||
|
||||
assertThat(result.getData()).isSameAs(pageResult);
|
||||
verify(productService).pageProducts(1, 10, "gel", 8L, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
+5
@@ -1,6 +1,7 @@
|
||||
package com.xiaowang.fingertipdesigner.core.modules.user.service.impl;
|
||||
|
||||
import com.xiaowang.fingertipdesigner.core.modules.security.mapper.PermissionMapper;
|
||||
import com.xiaowang.fingertipdesigner.core.config.BrandProperties;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.mapper.UserInviteCodeMapper;
|
||||
import com.xiaowang.fingertipdesigner.core.modules.user.mapper.UserMapper;
|
||||
@@ -65,6 +66,9 @@ class UserServiceImplPermissionAssignmentTest {
|
||||
@Mock
|
||||
private UserInviteCodeMapper userInviteCodeMapper;
|
||||
|
||||
@Mock
|
||||
private BrandProperties brandProperties;
|
||||
|
||||
@Mock
|
||||
private UserShopRoleMapper userShopRoleMapper;
|
||||
|
||||
@@ -110,6 +114,7 @@ class UserServiceImplPermissionAssignmentTest {
|
||||
permissionMapper,
|
||||
userRelationMapper,
|
||||
userInviteCodeMapper,
|
||||
brandProperties,
|
||||
userShopRoleMapper,
|
||||
nailArtistInfoService,
|
||||
verificationCodeService,
|
||||
|
||||
Reference in New Issue
Block a user