Commit f2f61c8ac00fe3da66d71b4996495070753923a7

Authored by jiangjiazhi
1 parent 3219776e36

增加

Showing 1 changed file with 79 additions and 64 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/OrganizationController.java View file @ f2f61c8
... ... @@ -44,6 +44,8 @@
44 44 private DepartmentsService departmentsService;
45 45 @Autowired
46 46 private AutoMatchFacade autoMatchFacade;
  47 + @Autowired
  48 + private UserOrganizationMapsService userOrganizationMapsService;
47 49  
48 50  
49 51 /**
50 52  
... ... @@ -52,14 +54,14 @@
52 54 @RequestMapping(value = "/organization/{id}", method = RequestMethod.DELETE)
53 55 @TokenRequired
54 56 public void updateOrganization(HttpServletResponse response, @PathVariable(value = "id") Integer id) {
55   - if (id == null ) {
  57 + if (id == null) {
56 58 ResultUtils.buildParameterErrorResultAndWrite(response);
57 59 return;
58 60 }
59 61  
60 62 //判断ID是否存在
61 63 Organization organization = organizationService.getOrganization(id);
62   - if(null == organization) {
  64 + if (null == organization) {
63 65 ResultUtils.buildParameterErrorResultAndWrite(response, "id不存在!");
64 66 return;
65 67 }
... ... @@ -68,7 +70,7 @@
68 70 UsersQuery usersQuery = new UsersQuery();
69 71 usersQuery.setOrgId(organization.getId());
70 72 usersQuery.setYn(YnEnums.YES.getId());
71   - if(0 < usersService.queryUsersCount(usersQuery)) {
  73 + if (0 < usersService.queryUsersCount(usersQuery)) {
72 74 ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.DONT_DELETE, "机构下有用户信息,不能删除!");
73 75 return;
74 76 }
... ... @@ -76,7 +78,7 @@
76 78 DepartmentsQuery departmentsQuery = new DepartmentsQuery();
77 79 departmentsQuery.setYn(YnEnums.YES.getId());
78 80 departmentsQuery.setOrgId(organization.getId());
79   - if(0 < departmentsService.queryDepartmentsCount(departmentsQuery)) {
  81 + if (0 < departmentsService.queryDepartmentsCount(departmentsQuery)) {
80 82 ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.DONT_DELETE, "机构下有部门信息,不能删除!");
81 83 return;
82 84 }
83 85  
84 86  
... ... @@ -96,28 +98,28 @@
96 98 @RequestMapping(value = "/organization/{id}", method = RequestMethod.PUT)
97 99 @TokenRequired
98 100 public void updateOrganization(HttpServletResponse response,
99   - @PathVariable(value = "id") Integer id,
100   - @RequestParam(value = "name", required = false) String name,
101   - @RequestParam(value = "type", required = false) Integer type,
102   - @RequestParam(value = "level", required = false) Integer level,
103   - @RequestParam(value = "areaManage", required = false) Integer areaManage,
104   - @RequestParam(value = "provinceId", required = false) String provinceId,
105   - @RequestParam(value = "cityId", required = false) String cityId,
106   - @RequestParam(value = "areaId", required = false) String areaId,
107   - @RequestParam(value = "streetId", required = false) String streetId,
108   - @RequestParam(value = "address", required = false) String address,
109   - @RequestParam(value = "description", required = false) String description,
110   - @RequestParam(value = "shortCode", required = false) String shortCode) {
  101 + @PathVariable(value = "id") Integer id,
  102 + @RequestParam(value = "name", required = false) String name,
  103 + @RequestParam(value = "type", required = false) Integer type,
  104 + @RequestParam(value = "level", required = false) Integer level,
  105 + @RequestParam(value = "areaManage", required = false) Integer areaManage,
  106 + @RequestParam(value = "provinceId", required = false) String provinceId,
  107 + @RequestParam(value = "cityId", required = false) String cityId,
  108 + @RequestParam(value = "areaId", required = false) String areaId,
  109 + @RequestParam(value = "streetId", required = false) String streetId,
  110 + @RequestParam(value = "address", required = false) String address,
  111 + @RequestParam(value = "description", required = false) String description,
  112 + @RequestParam(value = "shortCode", required = false) String shortCode) {
111 113  
112 114  
113   - if (type == null || StringUtils.isBlank(name) ) {
  115 + if (type == null || StringUtils.isBlank(name)) {
114 116 ResultUtils.buildParameterErrorResultAndWrite(response);
115 117 return;
116 118 }
117 119  
118 120 //判断ID是否存在
119 121 Organization organization = organizationService.getOrganization(id);
120   - if(null == organization) {
  122 + if (null == organization) {
121 123 ResultUtils.buildParameterErrorResultAndWrite(response, "id不存在!");
122 124 return;
123 125 }
... ... @@ -140,7 +142,6 @@
140 142 }
141 143  
142 144  
143   -
144 145 /**
145 146 * 添加机构
146 147 */
147 148  
... ... @@ -151,11 +152,11 @@
151 152 @RequestParam(value = "name") String name,
152 153 @RequestParam(value = "type") Integer type,
153 154 @RequestParam(value = "level") Integer level,
154   - @RequestParam(value = "areaManage",required = false) Integer areaManage,
  155 + @RequestParam(value = "areaManage", required = false) Integer areaManage,
155 156 @RequestParam(value = "provinceId") String provinceId,
156 157 @RequestParam(value = "cityId") String cityId,
157 158 @RequestParam(value = "areaId") String areaId,
158   - @RequestParam(value = "streetId",required = false) String streetId,
  159 + @RequestParam(value = "streetId", required = false) String streetId,
159 160 @RequestParam(value = "address") String address,
160 161 @RequestParam(value = "description", required = false) String description,
161 162 @RequestParam(value = "shortCode", required = false) String shortCode) {
... ... @@ -172,8 +173,8 @@
172 173 OrganizationQuery organizationQuery = new OrganizationQuery();
173 174 organizationQuery.setYn(YnEnums.YES.getId());
174 175 organizationQuery.setName(name);
175   - if(0 < organizationService.queryOrganizationCount(organizationQuery)) {
176   - ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.NAME_EXIST,"机构名称已存在!");
  176 + if (0 < organizationService.queryOrganizationCount(organizationQuery)) {
  177 + ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.NAME_EXIST, "机构名称已存在!");
177 178 return;
178 179 }
179 180  
180 181  
181 182  
... ... @@ -201,17 +202,16 @@
201 202  
202 203 /**
203 204 * 根据当前登录的权限去获取下属的医院
204   - *
205 205 */
206 206 @RequestMapping(value = "/organization1", method = RequestMethod.GET)
207 207 @ResponseBody
208 208 @TokenRequired
209   - public FrontEndResult getOrganization(HttpServletRequest request){
  209 + public FrontEndResult getOrganization(HttpServletRequest request) {
210 210 LoginContext loginState = (LoginContext) request.getAttribute("loginContext");
211 211  
212   - String areaId= autoMatchFacade.match(loginState.getId());
213   - List<Map> data =new ArrayList<>();
214   - if(StringUtils.isNotEmpty(areaId)){
  212 + String areaId = autoMatchFacade.match(loginState.getId());
  213 + List<Map> data = new ArrayList<>();
  214 + if (StringUtils.isNotEmpty(areaId)) {
215 215 OrganizationQuery organizationQuery = new OrganizationQuery();
216 216 organizationQuery.setAreaId(areaId);
217 217 List<Integer> list = new ArrayList<>();
218 218  
219 219  
220 220  
... ... @@ -220,21 +220,35 @@
220 220 organizationQuery.setYn(YnEnums.YES.getId());
221 221 organizationQuery.setTypeList(list);
222 222 List<Organization> organizations = organizationService.queryOrganization(organizationQuery);
223   - if(CollectionUtils.isNotEmpty(organizations)){
224   - for(Organization organization : organizations){
225   - Map<String,Object> map = new HashMap<>();
  223 + if (CollectionUtils.isNotEmpty(organizations)) {
  224 + for (Organization organization : organizations) {
  225 + Map<String, Object> map = new HashMap<>();
226 226 map.put("id", organization.getId());
227 227 map.put("name", organization.getName());
228 228 data.add(map);
229 229 }
230 230 }
  231 + } else {
  232 + UserOrganizationMapsQuery userOrganizationMapsQuery = new UserOrganizationMapsQuery();
  233 + userOrganizationMapsQuery.setYn(YnEnums.YES.getId());
  234 + userOrganizationMapsQuery.setUserId(loginState.getId());
  235 + List<UserOrganizationMaps> userOrganizationMapsList = userOrganizationMapsService.queryUserOrganizationMaps(userOrganizationMapsQuery);
  236 + if (CollectionUtils.isNotEmpty(userOrganizationMapsList)) {
  237 + for (UserOrganizationMaps userOrganizationMaps : userOrganizationMapsList) {
  238 + if (null != userOrganizationMaps.getOrgId()) {
  239 + Organization organization = organizationService.getOrganization(userOrganizationMaps.getOrgId());
  240 + Map<String, Object> map = new HashMap<>();
  241 + map.put("id", organization.getId());
  242 + map.put("name", organization.getName());
  243 + data.add(map);
  244 + }
  245 + }
  246 + }
231 247 }
232   - return new FrontEndResult().setData(data).setErrormsg("成功").setErrorcode(ErrorCodeConstants.SUCCESS);
  248 + return new FrontEndResult().setData(data).setErrormsg("成功").setErrorcode(ErrorCodeConstants.SUCCESS);
233 249 }
234 250  
235 251  
236   -
237   -
238 252 /**
239 253 * 获取列表
240 254 */
... ... @@ -242,12 +256,12 @@
242 256 @ResponseBody
243 257 @TokenRequired
244 258 public FrontEndResult getOrganization(
245   - @RequestParam(value = "id", required = false) Integer id,
246   - @RequestParam(value = "keyword", required = false) String keyword,
247   - @RequestParam(value = "page", required = false) Integer page,
248   - @RequestParam(value = "limit", required = false) Integer limit,
249   - @RequestParam(value = "areaId", required = false) String areaId,
250   - @RequestParam(value = "lite", required = false) String f) {
  259 + @RequestParam(value = "id", required = false) Integer id,
  260 + @RequestParam(value = "keyword", required = false) String keyword,
  261 + @RequestParam(value = "page", required = false) Integer page,
  262 + @RequestParam(value = "limit", required = false) Integer limit,
  263 + @RequestParam(value = "areaId", required = false) String areaId,
  264 + @RequestParam(value = "lite", required = false) String f) {
251 265  
252 266 limit = limit == null ? 10 : limit;
253 267 page = page == null ? 1 : page;
... ... @@ -262,7 +276,7 @@
262 276 organizationQuery.setKeyword(keyword);
263 277  
264 278 BasicConfig config = null;
265   - if(null != areaId) {
  279 + if (null != areaId) {
266 280 config = basicConfigService.getOneBasicConfigById(areaId);
267 281 }
268 282 if (config != null) {
... ... @@ -279,7 +293,7 @@
279 293 } else {
280 294 // BasicConfig p3 = basicConfigService.getOneBasicConfigById(p1.getParentId());
281 295 // if (p2 != null && SystemConfig.CHINA_BASIC_ID.equals(p3.getParentId())) {
282   - organizationQuery.setStreetId(areaId);
  296 + organizationQuery.setStreetId(areaId);
283 297 // }
284 298 }
285 299 }
286 300  
... ... @@ -288,25 +302,25 @@
288 302  
289 303 List<Organization> organizations = organizationService.queryOrganization(organizationQuery);
290 304 List<Object> data = new ArrayList<>();
291   - boolean falg =StringUtils.isNotEmpty(f);
292   - for(Organization organization : organizations) {
  305 + boolean falg = StringUtils.isNotEmpty(f);
  306 + for (Organization organization : organizations) {
293 307  
294 308 organization.setTypeObj(OrganizationLevelEnum.getById(organization.getLevel()));
295 309 organization.setLevelObj(OrganizationTypeEnum.getById(organization.getType()));
296   - if(null != organization.getProvinceId()) {
297   - organization.setProvince(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getProvinceId()),falg));
298   - }
299   - if(null != organization.getCityId()) {
300   - organization.setCity(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getCityId()), falg));
301   - }
302   - if(null != organization.getAreaId()) {
303   - organization.setArea(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getAreaId()), falg));
304   - }
305   - if(null != organization.getStreetId()) {
306   - organization.setStreet(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getStreetId()), falg));
307   - }
308   - Object obj = organization;
309   - if(falg){
  310 + if (null != organization.getProvinceId()) {
  311 + organization.setProvince(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getProvinceId()), falg));
  312 + }
  313 + if (null != organization.getCityId()) {
  314 + organization.setCity(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getCityId()), falg));
  315 + }
  316 + if (null != organization.getAreaId()) {
  317 + organization.setArea(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getAreaId()), falg));
  318 + }
  319 + if (null != organization.getStreetId()) {
  320 + organization.setStreet(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getStreetId()), falg));
  321 + }
  322 + Object obj = organization;
  323 + if (falg) {
310 324 obj = convert(organization);
311 325 }
312 326 data.add(obj);
313 327  
... ... @@ -317,9 +331,10 @@
317 331 frontEndResult.setPageInfo(organizationQuery.getPageInfo());
318 332 frontEndResult.setErrorcode(ErrorCodeConstants.SUCCESS);
319 333  
320   - return frontEndResult;
  334 + return frontEndResult;
321 335 }
322   - private Map<String,Object> convert(Organization organization) {
  336 +
  337 + private Map<String, Object> convert(Organization organization) {
323 338 Map<String, Object> map = new HashMap<>();
324 339 map.put("id", organization.getId());
325 340 map.put("name", organization.getName());
... ... @@ -329,8 +344,8 @@
329 344 map.put("cityId", organization.getCityId());
330 345 map.put("province", organization.getProvince());
331 346 map.put("provinceId", organization.getProvinceId());
332   - map.put("foreignId",organization.getForeignId());
333   - map.put("code",organization.getShortCode());
  347 + map.put("foreignId", organization.getForeignId());
  348 + map.put("code", organization.getShortCode());
334 349 return map;
335 350 }
336 351 }