From f2f61c8ac00fe3da66d71b4996495070753923a7 Mon Sep 17 00:00:00 2001 From: jiangjiazhi Date: Fri, 6 May 2016 11:06:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/OrganizationController.java | 143 ++++++++++++--------- 1 file changed, 79 insertions(+), 64 deletions(-) diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/OrganizationController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/OrganizationController.java index 5e5909f..a80d94b 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/OrganizationController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/OrganizationController.java @@ -44,6 +44,8 @@ public class OrganizationController extends BaseController { private DepartmentsService departmentsService; @Autowired private AutoMatchFacade autoMatchFacade; + @Autowired + private UserOrganizationMapsService userOrganizationMapsService; /** @@ -52,14 +54,14 @@ public class OrganizationController extends BaseController { @RequestMapping(value = "/organization/{id}", method = RequestMethod.DELETE) @TokenRequired public void updateOrganization(HttpServletResponse response, @PathVariable(value = "id") Integer id) { - if (id == null ) { + if (id == null) { ResultUtils.buildParameterErrorResultAndWrite(response); return; } //判断ID是否存在 Organization organization = organizationService.getOrganization(id); - if(null == organization) { + if (null == organization) { ResultUtils.buildParameterErrorResultAndWrite(response, "id不存在!"); return; } @@ -68,7 +70,7 @@ public class OrganizationController extends BaseController { UsersQuery usersQuery = new UsersQuery(); usersQuery.setOrgId(organization.getId()); usersQuery.setYn(YnEnums.YES.getId()); - if(0 < usersService.queryUsersCount(usersQuery)) { + if (0 < usersService.queryUsersCount(usersQuery)) { ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.DONT_DELETE, "机构下有用户信息,不能删除!"); return; } @@ -76,7 +78,7 @@ public class OrganizationController extends BaseController { DepartmentsQuery departmentsQuery = new DepartmentsQuery(); departmentsQuery.setYn(YnEnums.YES.getId()); departmentsQuery.setOrgId(organization.getId()); - if(0 < departmentsService.queryDepartmentsCount(departmentsQuery)) { + if (0 < departmentsService.queryDepartmentsCount(departmentsQuery)) { ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.DONT_DELETE, "机构下有部门信息,不能删除!"); return; } @@ -96,28 +98,28 @@ public class OrganizationController extends BaseController { @RequestMapping(value = "/organization/{id}", method = RequestMethod.PUT) @TokenRequired public void updateOrganization(HttpServletResponse response, - @PathVariable(value = "id") Integer id, - @RequestParam(value = "name", required = false) String name, - @RequestParam(value = "type", required = false) Integer type, - @RequestParam(value = "level", required = false) Integer level, - @RequestParam(value = "areaManage", required = false) Integer areaManage, - @RequestParam(value = "provinceId", required = false) String provinceId, - @RequestParam(value = "cityId", required = false) String cityId, - @RequestParam(value = "areaId", required = false) String areaId, - @RequestParam(value = "streetId", required = false) String streetId, - @RequestParam(value = "address", required = false) String address, - @RequestParam(value = "description", required = false) String description, - @RequestParam(value = "shortCode", required = false) String shortCode) { - - - if (type == null || StringUtils.isBlank(name) ) { + @PathVariable(value = "id") Integer id, + @RequestParam(value = "name", required = false) String name, + @RequestParam(value = "type", required = false) Integer type, + @RequestParam(value = "level", required = false) Integer level, + @RequestParam(value = "areaManage", required = false) Integer areaManage, + @RequestParam(value = "provinceId", required = false) String provinceId, + @RequestParam(value = "cityId", required = false) String cityId, + @RequestParam(value = "areaId", required = false) String areaId, + @RequestParam(value = "streetId", required = false) String streetId, + @RequestParam(value = "address", required = false) String address, + @RequestParam(value = "description", required = false) String description, + @RequestParam(value = "shortCode", required = false) String shortCode) { + + + if (type == null || StringUtils.isBlank(name)) { ResultUtils.buildParameterErrorResultAndWrite(response); return; } //判断ID是否存在 Organization organization = organizationService.getOrganization(id); - if(null == organization) { + if (null == organization) { ResultUtils.buildParameterErrorResultAndWrite(response, "id不存在!"); return; } @@ -140,7 +142,6 @@ public class OrganizationController extends BaseController { } - /** * 添加机构 */ @@ -151,11 +152,11 @@ public class OrganizationController extends BaseController { @RequestParam(value = "name") String name, @RequestParam(value = "type") Integer type, @RequestParam(value = "level") Integer level, - @RequestParam(value = "areaManage",required = false) Integer areaManage, + @RequestParam(value = "areaManage", required = false) Integer areaManage, @RequestParam(value = "provinceId") String provinceId, @RequestParam(value = "cityId") String cityId, @RequestParam(value = "areaId") String areaId, - @RequestParam(value = "streetId",required = false) String streetId, + @RequestParam(value = "streetId", required = false) String streetId, @RequestParam(value = "address") String address, @RequestParam(value = "description", required = false) String description, @RequestParam(value = "shortCode", required = false) String shortCode) { @@ -172,8 +173,8 @@ public class OrganizationController extends BaseController { OrganizationQuery organizationQuery = new OrganizationQuery(); organizationQuery.setYn(YnEnums.YES.getId()); organizationQuery.setName(name); - if(0 < organizationService.queryOrganizationCount(organizationQuery)) { - ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.NAME_EXIST,"机构名称已存在!"); + if (0 < organizationService.queryOrganizationCount(organizationQuery)) { + ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.NAME_EXIST, "机构名称已存在!"); return; } @@ -201,17 +202,16 @@ public class OrganizationController extends BaseController { /** * 根据当前登录的权限去获取下属的医院 - * */ @RequestMapping(value = "/organization1", method = RequestMethod.GET) @ResponseBody @TokenRequired - public FrontEndResult getOrganization(HttpServletRequest request){ + public FrontEndResult getOrganization(HttpServletRequest request) { LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); - String areaId= autoMatchFacade.match(loginState.getId()); - List data =new ArrayList<>(); - if(StringUtils.isNotEmpty(areaId)){ + String areaId = autoMatchFacade.match(loginState.getId()); + List data = new ArrayList<>(); + if (StringUtils.isNotEmpty(areaId)) { OrganizationQuery organizationQuery = new OrganizationQuery(); organizationQuery.setAreaId(areaId); List list = new ArrayList<>(); @@ -220,21 +220,35 @@ public class OrganizationController extends BaseController { organizationQuery.setYn(YnEnums.YES.getId()); organizationQuery.setTypeList(list); List organizations = organizationService.queryOrganization(organizationQuery); - if(CollectionUtils.isNotEmpty(organizations)){ - for(Organization organization : organizations){ - Map map = new HashMap<>(); + if (CollectionUtils.isNotEmpty(organizations)) { + for (Organization organization : organizations) { + Map map = new HashMap<>(); map.put("id", organization.getId()); map.put("name", organization.getName()); data.add(map); } } + } else { + UserOrganizationMapsQuery userOrganizationMapsQuery = new UserOrganizationMapsQuery(); + userOrganizationMapsQuery.setYn(YnEnums.YES.getId()); + userOrganizationMapsQuery.setUserId(loginState.getId()); + List userOrganizationMapsList = userOrganizationMapsService.queryUserOrganizationMaps(userOrganizationMapsQuery); + if (CollectionUtils.isNotEmpty(userOrganizationMapsList)) { + for (UserOrganizationMaps userOrganizationMaps : userOrganizationMapsList) { + if (null != userOrganizationMaps.getOrgId()) { + Organization organization = organizationService.getOrganization(userOrganizationMaps.getOrgId()); + Map map = new HashMap<>(); + map.put("id", organization.getId()); + map.put("name", organization.getName()); + data.add(map); + } + } + } } - return new FrontEndResult().setData(data).setErrormsg("成功").setErrorcode(ErrorCodeConstants.SUCCESS); + return new FrontEndResult().setData(data).setErrormsg("成功").setErrorcode(ErrorCodeConstants.SUCCESS); } - - /** * 获取列表 */ @@ -242,12 +256,12 @@ public class OrganizationController extends BaseController { @ResponseBody @TokenRequired public FrontEndResult getOrganization( - @RequestParam(value = "id", required = false) Integer id, - @RequestParam(value = "keyword", required = false) String keyword, - @RequestParam(value = "page", required = false) Integer page, - @RequestParam(value = "limit", required = false) Integer limit, - @RequestParam(value = "areaId", required = false) String areaId, - @RequestParam(value = "lite", required = false) String f) { + @RequestParam(value = "id", required = false) Integer id, + @RequestParam(value = "keyword", required = false) String keyword, + @RequestParam(value = "page", required = false) Integer page, + @RequestParam(value = "limit", required = false) Integer limit, + @RequestParam(value = "areaId", required = false) String areaId, + @RequestParam(value = "lite", required = false) String f) { limit = limit == null ? 10 : limit; page = page == null ? 1 : page; @@ -262,7 +276,7 @@ public class OrganizationController extends BaseController { organizationQuery.setKeyword(keyword); BasicConfig config = null; - if(null != areaId) { + if (null != areaId) { config = basicConfigService.getOneBasicConfigById(areaId); } if (config != null) { @@ -279,7 +293,7 @@ public class OrganizationController extends BaseController { } else { // BasicConfig p3 = basicConfigService.getOneBasicConfigById(p1.getParentId()); // if (p2 != null && SystemConfig.CHINA_BASIC_ID.equals(p3.getParentId())) { - organizationQuery.setStreetId(areaId); + organizationQuery.setStreetId(areaId); // } } } @@ -288,25 +302,25 @@ public class OrganizationController extends BaseController { List organizations = organizationService.queryOrganization(organizationQuery); List data = new ArrayList<>(); - boolean falg =StringUtils.isNotEmpty(f); - for(Organization organization : organizations) { + boolean falg = StringUtils.isNotEmpty(f); + for (Organization organization : organizations) { organization.setTypeObj(OrganizationLevelEnum.getById(organization.getLevel())); organization.setLevelObj(OrganizationTypeEnum.getById(organization.getType())); - if(null != organization.getProvinceId()) { - organization.setProvince(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getProvinceId()),falg)); - } - if(null != organization.getCityId()) { - organization.setCity(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getCityId()), falg)); - } - if(null != organization.getAreaId()) { - organization.setArea(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getAreaId()), falg)); - } - if(null != organization.getStreetId()) { - organization.setStreet(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getStreetId()), falg)); - } - Object obj = organization; - if(falg){ + if (null != organization.getProvinceId()) { + organization.setProvince(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getProvinceId()), falg)); + } + if (null != organization.getCityId()) { + organization.setCity(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getCityId()), falg)); + } + if (null != organization.getAreaId()) { + organization.setArea(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getAreaId()), falg)); + } + if (null != organization.getStreetId()) { + organization.setStreet(CommonsHelper.convterToMap(basicConfigService.getOneBasicConfigById(organization.getStreetId()), falg)); + } + Object obj = organization; + if (falg) { obj = convert(organization); } data.add(obj); @@ -317,9 +331,10 @@ public class OrganizationController extends BaseController { frontEndResult.setPageInfo(organizationQuery.getPageInfo()); frontEndResult.setErrorcode(ErrorCodeConstants.SUCCESS); - return frontEndResult; + return frontEndResult; } - private Map convert(Organization organization) { + + private Map convert(Organization organization) { Map map = new HashMap<>(); map.put("id", organization.getId()); map.put("name", organization.getName()); @@ -329,8 +344,8 @@ public class OrganizationController extends BaseController { map.put("cityId", organization.getCityId()); map.put("province", organization.getProvince()); map.put("provinceId", organization.getProvinceId()); - map.put("foreignId",organization.getForeignId()); - map.put("code",organization.getShortCode()); + map.put("foreignId", organization.getForeignId()); + map.put("code", organization.getShortCode()); return map; } } -- 1.8.3.1