Преглед изворни кода

添加CustomerAuth、MerchantAuth

wangzhijun пре 1 недеља
родитељ
комит
c1aeeb39ca

+ 2 - 6
nightFragrance-admin/src/main/java/com/ylx/web/controller/point/UserPointController.java

@@ -17,12 +17,14 @@ import com.ylx.point.service.IPointUserActivityTaskCompletionService;
 import com.ylx.point.service.IPointUserLogService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.List;
 
+@PreAuthorize("@customerAuth.isCustomer()")
 @RestController
 @RequestMapping("/user/point")
 @Api(tags = {"用户积分"})
@@ -37,12 +39,6 @@ public class UserPointController extends BaseController {
     @Resource
     private IPointAccountService pointAccountService;
 
-    /**
-     * 获取当前用户的积分信息
-     *
-     * @param cityCode
-     * @return R<UserPointInfoVO>
-     */
     @ApiOperation("获取当前用户的积分信息")
     @GetMapping
     public R<UserPointInfoVO> getUserPointInfo(@RequestParam String cityCode) {

+ 20 - 0
nightFragrance-common/src/main/java/com/ylx/common/component/CustomerAuth.java

@@ -0,0 +1,20 @@
+package com.ylx.common.component;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.ylx.common.utils.SecurityUtils;
+import org.springframework.stereotype.Component;
+
+/**
+ * 自定义客户权限校验类
+ */
+@Component("customerAuth")
+public class CustomerAuth {
+
+    private static final Integer CUSTOMER = 0;
+
+    public boolean isCustomer() {
+        Integer role = SecurityUtils.getWxLoginUser().getRole();
+        return ObjectUtil.equals(CUSTOMER, role);
+    }
+
+}

+ 20 - 0
nightFragrance-common/src/main/java/com/ylx/common/component/MerchantAuth.java

@@ -0,0 +1,20 @@
+package com.ylx.common.component;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.ylx.common.utils.SecurityUtils;
+import org.springframework.stereotype.Component;
+
+/**
+ * 自定义商家权限校验类
+ */
+@Component("merchantAuth")
+public class MerchantAuth {
+
+    private static final Integer MERCHANT = 1;
+
+    public boolean isMerchant() {
+        Integer role = SecurityUtils.getWxLoginUser().getRole();
+        return ObjectUtil.equals(MERCHANT, role);
+    }
+
+}