Commit eb8fd19985147d5ccbdfee95c77e0bb0c6278a6d
1 parent
0a41155d4e
Exists in
master
and in
6 other branches
登陆优化
Showing 1 changed file with 68 additions and 6 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AccessPermissionFacade.java
View file @
eb8fd19
... | ... | @@ -4,14 +4,22 @@ |
4 | 4 | import java.util.Iterator; |
5 | 5 | import java.util.List; |
6 | 6 | import java.util.Set; |
7 | +import java.util.concurrent.Callable; | |
8 | +import java.util.concurrent.Future; | |
7 | 9 | |
8 | 10 | import com.lyms.platform.common.enums.OptActionEnums; |
9 | 11 | import com.lyms.platform.common.enums.YnEnums; |
12 | +import com.lyms.platform.common.utils.ExceptionUtils; | |
13 | +import com.lyms.platform.operate.web.result.BabyManageListResult; | |
14 | +import com.lyms.platform.operate.web.utils.BabyListTask; | |
10 | 15 | import com.lyms.platform.permission.model.OrganizationQuery; |
16 | +import com.lyms.platform.pojo.BabyModel; | |
11 | 17 | import org.apache.commons.collections.CollectionUtils; |
12 | 18 | import org.apache.commons.lang.StringUtils; |
13 | 19 | import org.apache.commons.lang.math.NumberUtils; |
14 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
21 | +import org.springframework.beans.factory.annotation.Qualifier; | |
22 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |
15 | 23 | import org.springframework.stereotype.Component; |
16 | 24 | |
17 | 25 | import com.lyms.platform.biz.service.DataPermissionService; |
... | ... | @@ -48,6 +56,10 @@ |
48 | 56 | private DataPermissionService dataPermissionService; |
49 | 57 | |
50 | 58 | @Autowired |
59 | + @Qualifier("commonThreadPool") | |
60 | + private ThreadPoolTaskExecutor commonThreadPool; | |
61 | + | |
62 | + @Autowired | |
51 | 63 | private OrganizationService organizationService; |
52 | 64 | |
53 | 65 | |
54 | 66 | |
55 | 67 | |
56 | 68 | |
... | ... | @@ -104,18 +116,68 @@ |
104 | 116 | public List<Organization> getOrganization(List<DataPermissionsModel> data) { |
105 | 117 | List<Organization> dataList = new ArrayList<>(); |
106 | 118 | if (CollectionUtils.isNotEmpty(data)) { |
119 | + | |
120 | + List<String> list = new ArrayList<>(); | |
121 | + | |
107 | 122 | Set<String> set = data.get(0).getData().keySet(); |
108 | 123 | Iterator<String> it = set.iterator(); |
109 | 124 | while (it.hasNext()) { |
110 | - String id = it.next(); | |
111 | - try { | |
112 | - Organization organization = organizationService.getOrganization(Integer.valueOf(id)); | |
113 | - if (null != organization) { | |
114 | - dataList.add(organization); | |
125 | + list.add(it.next()); | |
126 | + } | |
127 | + | |
128 | + int batchSize = 20; | |
129 | + int end = 0; | |
130 | + List<Future> futures = new ArrayList<>(); | |
131 | + for (int i = 0; i < list.size(); i += batchSize) { | |
132 | + end = (end + batchSize); | |
133 | + if (end > list.size()) { | |
134 | + end = list.size(); | |
135 | + } | |
136 | + final List<String> ms = list.subList(i, end); | |
137 | + Callable c = new Callable() { | |
138 | + @Override | |
139 | + public List<Organization> call() throws Exception { | |
140 | + List<Organization> tempdataList = new ArrayList<>(); | |
141 | + if (CollectionUtils.isNotEmpty(ms)) | |
142 | + { | |
143 | + for (String id : ms) | |
144 | + { | |
145 | + Organization organization = organizationService.getOrganization(Integer.valueOf(id)); | |
146 | + if (null != organization) { | |
147 | + tempdataList.add(organization); | |
148 | + } | |
149 | + } | |
150 | + } | |
151 | + return tempdataList; | |
115 | 152 | } |
116 | - } catch (Exception e) { | |
153 | + }; | |
154 | + Future f = commonThreadPool.submit(c); | |
155 | + futures.add(f); | |
156 | + } | |
157 | + if (CollectionUtils.isNotEmpty(futures)) | |
158 | + { | |
159 | + for (Future f : futures) | |
160 | + { | |
161 | + try { | |
162 | + dataList.addAll((List<Organization>) f.get()); | |
163 | + } catch (Exception e) { | |
164 | + ExceptionUtils.catchException(e, "get organization error."); | |
165 | + } | |
117 | 166 | } |
118 | 167 | } |
168 | + | |
169 | +// Set<String> set = data.get(0).getData().keySet(); | |
170 | +// Iterator<String> it = set.iterator(); | |
171 | +// while (it.hasNext()) { | |
172 | +// String id = it.next(); | |
173 | +// try { | |
174 | +// Organization organization = organizationService.getOrganization(Integer.valueOf(id)); | |
175 | +// if (null != organization) { | |
176 | +// dataList.add(organization); | |
177 | +// } | |
178 | +// } catch (Exception e) { | |
179 | +// } | |
180 | +// } | |
119 | 181 | } |
120 | 182 | return dataList; |
121 | 183 | } |