Blame view

src/main/java/com/objecteye/service/impl/RoleServicesImpl.java 3.76 KB
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  package com.objecteye.service.impl;
  
  
  import com.alibaba.fastjson.JSONArray;
  import com.alibaba.fastjson.JSONObject;
  import com.objecteye.entity.SyPrivilege;
  import com.objecteye.entity.SyRole;
  import com.objecteye.entity.SyRoleExample;
  import com.objecteye.mapper.SyPrivilegeMapper;
  import com.objecteye.mapper.SyRoleMapper;
  import com.objecteye.mapper.SyRolePrivilegeMapper;
  import com.objecteye.service.RoleServices;
  import com.objecteye.utils.UserTools;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import java.util.List;
  
  @Service
  public class RoleServicesImpl implements RoleServices {
  
      @Autowired
      public SyRoleMapper syRoleMapper;
      @Autowired
      public SyRolePrivilegeMapper syRolePrivilegeMapper;
      @Autowired
      public SyPrivilegeMapper syPrivilegeMapper;
  
      @Override
      public int totalNum() {
          return syRoleMapper.countByExample(new SyRoleExample());
      }
  
      @Override
      public JSONObject rolePage(int currentpage, int pagevolume) {
          int startPage = (currentpage - 1) * pagevolume;
          List<SyRole> syRoles = syRoleMapper.selectRolePage(startPage, pagevolume);
          JSONObject jsonObject = new JSONObject();
          jsonObject.put("code", 200);
          jsonObject.put("message", "success");
          JSONArray rowOld = UserTools.getJSONArrayByList(syRoles);
          JSONArray rowNew = new JSONArray();
          for (int i = 0; i < rowOld.size(); i++) {
              JSONObject jsonRole = rowOld.getJSONObject(i);
              Integer id = jsonRole.getInteger("id");
              /*通过id获取相应的权限*/
              List<Integer> integers = syRolePrivilegeMapper.selectByRid(id);
              StringBuilder sb = new StringBuilder();
              for (Integer in : integers) {
                  SyPrivilege syPrivilege = syPrivilegeMapper.selectByPrimaryKey(in);
                  sb.append(syPrivilege.getPrivilegeName()).append(",");
              }
              String substring = sb.toString().substring(0, sb.length() - 1);
              jsonRole.put("jurisdiction", substring);
              jsonRole.put("rolename", jsonRole.getString("roleName"));
              jsonRole.put("createdate", jsonRole.getString("createDate"));
              jsonRole.put("isdelete", jsonRole.getString("isDelete"));
              jsonRole.remove("roleName");
              jsonRole.remove("createDate");
              jsonRole.remove("isDelete");
              rowNew.add(jsonRole);
          }
  
          int total = (int) Math.ceil(totalNum() / (double) pagevolume);
          JSONObject data = new JSONObject();
          data.put("total", total);
          data.put("row", rowNew);
          jsonObject.put("data", data);
          return jsonObject;
      }
  
      @Override
      public JSONObject roleDis() {
          JSONObject jsonObject = new JSONObject();
          try {
              List<SyRole> syRoles = syRoleMapper.selectByExample(new SyRoleExample());
              if (syRoles != null && syRoles.size() > 0) {
                  jsonObject.put("code", 200);
                  jsonObject.put("message", "success");
                  JSONArray array = new JSONArray();
                  for (SyRole sr : syRoles) {
                      JSONObject kv = new JSONObject();
                      kv.put("name", sr.getRoleName());
                      kv.put("value", sr.getId());
                      array.add(kv);
                  }
                  jsonObject.put("data", array);
              } else {
                  jsonObject.put("code", 201);
                  jsonObject.put("message", "列表信息错误");
                  jsonObject.put("date", null);
              }
          } catch (Exception e) {
              jsonObject.put("code", 202);
              jsonObject.put("message", "下拉列表失败");
              jsonObject.put("date", null);
          }
          return jsonObject;
      }
  }