liulingling.177216
2024-08-26 349f1cfc5fa77fbc636d542df0d8050fddec48c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.dingzhuo.energy.data.model.controller;
 
import com.dingzhuo.energy.data.model.domain.AuthType;
import com.dingzhuo.energy.data.model.service.DataAuthService;
import com.dingzhuo.energy.framework.web.controller.BaseController;
import com.dingzhuo.energy.framework.web.domain.AjaxResult;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@RequestMapping("/data/auth")
public class DataAuthController extends BaseController {
 
  @Autowired
  private DataAuthService dataAuthService;
 
  @GetMapping("/{authType}/{modelCode}/{userOrRoleId}")
  public AjaxResult selectDataAuth(
      @PathVariable("authType") String authType,
      @PathVariable("modelCode") String modelCode,
      @PathVariable("userOrRoleId") String userOrRoleId) {
    List<String> authIds;
    if (AuthType.valueOf(authType.toUpperCase()) == AuthType.USER) {
      authIds = dataAuthService.getUserDataAuth(modelCode, userOrRoleId);
    } else {
      authIds = dataAuthService.getRoleDataAuth(modelCode, userOrRoleId);
    }
 
    return AjaxResult.success(authIds);
  }
 
  @PostMapping("/{authType}/{modelCode}/{userOrRoleId}")
  public AjaxResult setDataAuth(
      @PathVariable("authType") String authType,
      @PathVariable("modelCode") String modelCode,
      @PathVariable("userOrRoleId") String userOrRoleId,
      @RequestBody List<String> ids) {
    if (AuthType.valueOf(authType.toUpperCase()) == AuthType.USER) {
      dataAuthService.setUserDataAuth(userOrRoleId, modelCode, ids);
    } else {
      dataAuthService.setRoleDataAuth(userOrRoleId, modelCode, ids);
    }
 
    return AjaxResult.success();
  }
}