dengzedong
2024-12-24 76743b009ca5ea67557fcab597b332f8d1947813
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.system.controller.admin.socail;
H 2
3 import com.iailab.framework.common.enums.UserTypeEnum;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.pojo.PageResult;
6 import com.iailab.framework.common.util.object.BeanUtils;
7 import com.iailab.module.system.controller.admin.socail.vo.user.SocialUserBindReqVO;
8 import com.iailab.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
9 import com.iailab.module.system.controller.admin.socail.vo.user.SocialUserRespVO;
10 import com.iailab.module.system.controller.admin.socail.vo.user.SocialUserUnbindReqVO;
11 import com.iailab.module.system.convert.social.SocialUserConvert;
12 import com.iailab.module.system.dal.dataobject.social.SocialUserDO;
13 import com.iailab.module.system.service.social.SocialUserService;
14 import io.swagger.v3.oas.annotations.Operation;
15 import io.swagger.v3.oas.annotations.Parameter;
16 import io.swagger.v3.oas.annotations.tags.Tag;
17 import org.springframework.security.access.prepost.PreAuthorize;
18 import org.springframework.validation.annotation.Validated;
19 import org.springframework.web.bind.annotation.*;
20
21 import javax.annotation.Resource;
22 import javax.validation.Valid;
23
24 import static com.iailab.framework.common.pojo.CommonResult.success;
25 import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
26
27 @Tag(name = "管理后台 - 社交用户")
28 @RestController
29 @RequestMapping("/system/social-user")
30 @Validated
31 public class SocialUserController {
32
33     @Resource
34     private SocialUserService socialUserService;
35
36     @PostMapping("/bind")
37     @Operation(summary = "社交绑定,使用 code 授权码")
38     public CommonResult<Boolean> socialBind(@RequestBody @Valid SocialUserBindReqVO reqVO) {
39         socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert(
40                 getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO));
41         return CommonResult.success(true);
42     }
43
44     @DeleteMapping("/unbind")
45     @Operation(summary = "取消社交绑定")
46     public CommonResult<Boolean> socialUnbind(@RequestBody SocialUserUnbindReqVO reqVO) {
47         socialUserService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getOpenid());
48         return CommonResult.success(true);
49     }
50
51     // ==================== 社交用户 CRUD ====================
52
53     @GetMapping("/get")
54     @Operation(summary = "获得社交用户")
55     @Parameter(name = "id", description = "编号", required = true, example = "1024")
56     @PreAuthorize("@ss.hasPermission('system:social-user:query')")
57     public CommonResult<SocialUserRespVO> getSocialUser(@RequestParam("id") Long id) {
58         SocialUserDO socialUser = socialUserService.getSocialUser(id);
59         return success(BeanUtils.toBean(socialUser, SocialUserRespVO.class));
60     }
61
62     @GetMapping("/page")
63     @Operation(summary = "获得社交用户分页")
64     @PreAuthorize("@ss.hasPermission('system:social-user:query')")
65     public CommonResult<PageResult<SocialUserRespVO>> getSocialUserPage(@Valid SocialUserPageReqVO pageVO) {
66         PageResult<SocialUserDO> pageResult = socialUserService.getSocialUserPage(pageVO);
67         return success(BeanUtils.toBean(pageResult, SocialUserRespVO.class));
68     }
69
70 }