临时提交

This commit is contained in:
磷叶 2024-11-27 09:07:03 +08:00
parent 62d765fe58
commit 9289f17d71
6 changed files with 86 additions and 34 deletions

View File

@ -2,7 +2,6 @@ package com.ruoyi.ss.store.service;
import com.ruoyi.common.core.domain.ValidateResult;
import com.ruoyi.ss.store.domain.Store;
import com.ruoyi.ss.store.domain.StoreBO;
import com.ruoyi.ss.store.domain.StoreVo;
import java.time.LocalTime;
@ -109,4 +108,21 @@ public interface StoreValidator {
* 后校验
*/
void afterCheck(StoreVo vo);
/**
* 校验是否能操作店铺
* @param store 店铺
* @param userId 用户
*/
boolean canOperaStore(StoreVo store, Long userId);
/**
* 校验是否能操作店铺
*/
boolean canOperaStore(Long storeId, Long userId);
/**
* 校验是否能操作所有店铺
*/
boolean canOperaAllStore(List<Long> storeIds, Long userId);
}

View File

@ -13,6 +13,7 @@ import com.ruoyi.ss.store.domain.StoreVo;
import com.ruoyi.ss.store.domain.enums.StoreStatus;
import com.ruoyi.ss.store.service.StoreService;
import com.ruoyi.ss.store.service.StoreValidator;
import com.ruoyi.ss.storeStaff.service.StoreStaffValidator;
import com.ruoyi.ss.user.service.UserValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -40,6 +41,9 @@ public class StoreValidatorImpl extends BaseValidator implements StoreValidator
@Autowired
private UserValidator userValidator;
@Autowired
private StoreStaffValidator storeStaffValidator;
/**
* 逻辑删除前校验
* @param ids 店铺id列表
@ -76,10 +80,6 @@ public class StoreValidatorImpl extends BaseValidator implements StoreValidator
return result;
}
if (!this.isStoreBelongUser(storeIds, SecurityUtils.getUserId())) {
return error("当前店铺不属于当前用户");
}
return success();
}
@ -193,16 +193,6 @@ public class StoreValidatorImpl extends BaseValidator implements StoreValidator
return error("数据不能为空");
}
List<Long> storeIds = list.stream().map(Store::getStoreId).collect(Collectors.toList());
if (!this.isExist(storeIds)) {
return error("店铺不存在,请刷新后重试");
}
if (!this.isStoreBelongUser(storeIds, SecurityUtils.getUserId())) {
return error("存在店铺不属于当前用户");
}
return success();
}
@ -271,9 +261,6 @@ public class StoreValidatorImpl extends BaseValidator implements StoreValidator
if (userId == null || storeId == null) {
return error("参数错误userId 与 storeId 不允许为空");
}
if (!this.isStoreBelongUser(Collections.singletonList(storeId), userId)) {
return error("当前店铺不属于当前用户");
}
return success();
}
@ -339,6 +326,33 @@ public class StoreValidatorImpl extends BaseValidator implements StoreValidator
}
@Override
public boolean canOperaStore(StoreVo store, Long userId) {
return this.isStoreBelongUser(store, userId) || storeStaffValidator.canOperaStore(store, userId);
}
@Override
public boolean canOperaStore(Long storeId, Long userId) {
StoreVo store = storeService.selectSmStoreById(storeId);
return this.canOperaStore(store, userId);
}
@Override
public boolean canOperaAllStore(List<Long> storeIds, Long userId) {
if (CollectionUtils.isEmptyElement(storeIds)) {
return true;
}
List<StoreVo> storeList = storeService.selectStoreByIds(storeIds);
for (StoreVo store : storeList) {
if (!this.canOperaStore(store, userId)) {
return false;
}
}
return true;
}
/**
* 校验时间是符合规则

View File

@ -1,5 +1,6 @@
package com.ruoyi.ss.storeStaff.service;
import com.ruoyi.ss.store.domain.StoreVo;
import com.ruoyi.ss.storeStaff.domain.StoreStaff;
import com.ruoyi.ss.storeStaff.domain.StoreStaffVO;
@ -32,4 +33,9 @@ public interface StoreStaffValidator {
* @param userId 员工ID
*/
boolean canOperaStore(Long storeId, Long userId);
/**
* 是否允许操作店铺
*/
boolean canOperaStore(StoreVo store, Long userId);
}

View File

@ -6,6 +6,7 @@ import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceAssembler;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.device.service.DeviceValidator;
import com.ruoyi.ss.store.domain.StoreVo;
import com.ruoyi.ss.storeStaff.domain.StoreStaff;
import com.ruoyi.ss.storeStaff.domain.StoreStaffQuery;
import com.ruoyi.ss.storeStaff.domain.StoreStaffVO;
@ -107,6 +108,11 @@ public class StoreStaffValidatorImpl implements StoreStaffValidator {
return storeStaffService.selectCount(query) > 0;
}
@Override
public boolean canOperaStore(StoreVo store, Long userId) {
return store != null && this.canOperaStore(store.getStoreId(), userId);
}
private void checkRepeatUser(Long storeId, Long userId, Long employId) {
if (storeId == null || userId == null) {
return;

View File

@ -9,6 +9,7 @@ import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.store.domain.*;
import com.ruoyi.ss.store.service.StoreService;
import com.ruoyi.ss.store.service.StoreAssembler;
@ -69,8 +70,8 @@ public class AppStoreController extends BaseController {
@PutMapping
public AjaxResult edit(@RequestBody @Validated(ValidGroup.FrontUpdate.class) StoreBO data) {
StoreVo store = storeService.selectSmStoreById(data.getStoreId());
if (!storeValidator.isStoreBelongUser(store, getUserId())) {
return error("这不是您的店铺,无法修改");
if (!storeValidator.canOperaStore(store, getUserId())) {
return error("您无权操作该店铺");
}
data = data.filterUpdateByApp();
ServiceUtil.assertion(storeValidator.preUpdateByApp(data));
@ -81,8 +82,8 @@ public class AppStoreController extends BaseController {
@PutMapping("/config")
public AjaxResult configStore(@RequestBody @Validated(ValidGroup.FrontUpdate.class) StoreBO data) {
StoreVo store = storeService.selectSmStoreById(data.getStoreId());
if (!storeValidator.isStoreBelongUser(store, getUserId())) {
return error("这不是您的店铺,无法修改");
if (!storeValidator.canOperaStore(store, getUserId())) {
return error("您无权操作该店铺");
}
data = data.filterConfigByApp();
return toAjax(storeService.updateSmStore(data));
@ -97,6 +98,9 @@ public class AppStoreController extends BaseController {
@ApiOperation("删除店铺信息")
@DeleteMapping("/{storeId}")
public AjaxResult delete(@PathVariable Long storeId) {
if (!storeValidator.canOperaStore(storeId, getUserId())) {
return error("您无权操作该店铺");
}
List<Long> storeIds = Collections.singletonList(storeId);
ServiceUtil.assertion(storeValidator.preLogicDelByApp(storeIds));
return AjaxResult.success(storeService.logicDel(storeIds));
@ -117,6 +121,9 @@ public class AppStoreController extends BaseController {
@ApiOperation("调整店铺排序")
@PutMapping("/changeSort")
public AjaxResult changeSort(@RequestBody List<Store> list) {
if (!storeValidator.canOperaAllStore(CollectionUtils.map(list, Store::getStoreId), getUserId())) {
return error("您无权操作这些店铺");
}
ServiceUtil.assertion(storeValidator.preChangeSortByApp(list));
return AjaxResult.success(storeService.changeSort(list));
}
@ -171,6 +178,9 @@ public class AppStoreController extends BaseController {
@PutMapping("/{storeId}/setDefault")
public AjaxResult setDefaultStore(@PathVariable Long storeId) {
Long userId = getUserId();
if (!storeValidator.canOperaStore(storeId, userId)) {
return error("您无权操作该店铺");
}
ServiceUtil.assertion(storeValidator.preSetDefaultByApp(userId, storeId));
return success(storeService.setDefault(userId, storeId));
}

View File

@ -52,17 +52,17 @@ public class StaffStoreController extends BaseController {
query.setStoreId(storeId);
return success(storeService.selectStaffStoreOne(query));
}
// TODO 建议还是合在商户的接口中使用
@ApiOperation("员工申请修改店铺信息")
@PutMapping
public AjaxResult update(@RequestBody @Validated(ValidGroup.FrontUpdate.class) StoreBO data) {
if (!storeStaffValidator.canOperaStore(data.getStoreId(), getUserId())) {
return error("您无权修改该店铺");
}
data = data.filterUpdateByAppStaff();
ServiceUtil.assertion(storeValidator.preUpdateByApp(data));
return toAjax(storeService.updateApply(data));
}
//
// // TODO 建议还是合在商户的接口中使用
// @ApiOperation("员工申请修改店铺信息")
// @PutMapping
// public AjaxResult update(@RequestBody @Validated(ValidGroup.FrontUpdate.class) StoreBO data) {
// if (!storeStaffValidator.canOperaStore(data.getStoreId(), getUserId())) {
// return error("您无权修改该店铺");
// }
// data = data.filterUpdateByAppStaff();
// ServiceUtil.assertion(storeValidator.preUpdateByApp(data));
// return toAjax(storeService.updateApply(data));
// }
}