OrgEndPoint.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. package com.yihu.ehr.basic.org.controller;
  2. import com.fasterxml.jackson.core.type.TypeReference;
  3. import com.fasterxml.jackson.databind.node.ObjectNode;
  4. import com.yihu.ehr.basic.address.service.AddressDictService;
  5. import com.yihu.ehr.basic.org.model.Organization;
  6. import com.yihu.ehr.basic.security.service.UserSecurityService;
  7. import com.yihu.ehr.commons.constants.BasicServiceApi;
  8. import com.yihu.ehr.constants.ApiVersion;
  9. import com.yihu.ehr.constants.ServiceApi;
  10. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  11. import com.yihu.ehr.entity.address.AddressDict;
  12. import com.yihu.ehr.entity.security.UserKey;
  13. import com.yihu.ehr.entity.security.UserSecurity;
  14. import com.yihu.ehr.fastdfs.FastDFSUtil;
  15. import com.yihu.ehr.model.org.MOrganization;
  16. import com.yihu.ehr.basic.org.model.OrgDept;
  17. import com.yihu.ehr.basic.org.service.OrgDeptService;
  18. import com.yihu.ehr.basic.org.service.OrgService;
  19. import com.yihu.ehr.util.phonics.PinyinUtil;
  20. import com.yihu.ehr.util.rest.Envelop;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. import io.swagger.annotations.ApiParam;
  24. import org.apache.commons.lang.StringUtils;
  25. import org.apache.commons.lang.time.DateFormatUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.http.MediaType;
  28. import org.springframework.web.bind.annotation.*;
  29. import javax.servlet.http.HttpServletRequest;
  30. import javax.servlet.http.HttpServletResponse;
  31. import java.io.ByteArrayInputStream;
  32. import java.io.IOException;
  33. import java.io.InputStream;
  34. import java.net.URLDecoder;
  35. import java.net.URLEncoder;
  36. import java.util.*;
  37. /**
  38. * @author zlf
  39. * @version 1.0
  40. * @created 2015.08.10 17:57
  41. */
  42. @RestController
  43. @RequestMapping(ApiVersion.Version1_0)
  44. @Api(value = "org", description = "组织机构管理服务", tags = {"机构管理-机构管理服务"})
  45. public class OrgEndPoint extends EnvelopRestEndPoint {
  46. @Autowired
  47. private OrgService orgService;
  48. @Autowired
  49. private UserSecurityService userSecurityService;
  50. @Autowired
  51. private FastDFSUtil fastDFSUtil;
  52. @Autowired
  53. private OrgDeptService orgDeptService;
  54. @Autowired
  55. private AddressDictService addressDictService;
  56. @Autowired
  57. private AddressDictService geographyDictService;
  58. @RequestMapping(value = "/organizations/getAllOrgs", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  59. @ApiOperation(value = "查询所有机构列表")
  60. public List<MOrganization> getAllOrgs() throws Exception {
  61. List<MOrganization> orgs = orgService.search(null);
  62. return orgs;
  63. }
  64. /**
  65. * 机构列表查询
  66. *
  67. * @param fields
  68. * @param filters
  69. * @param sorts
  70. * @param size
  71. * @param page
  72. * @param request
  73. * @param response
  74. * @return
  75. * @throws Exception
  76. */
  77. @RequestMapping(value = "/organizations/list", method = RequestMethod.POST)
  78. @ApiOperation(value = "根据条件查询机构列表")
  79. public List<MOrganization> searchOrgs(
  80. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,name,secret,url,createTime")
  81. @RequestParam(value = "fields", required = false) String fields,
  82. @ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "")
  83. @RequestParam(value = "filters", required = false) String filters,
  84. @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "-createDate")
  85. @RequestParam(value = "sorts", required = false) String sorts,
  86. @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
  87. @RequestParam(value = "size", required = false) int size,
  88. @ApiParam(name = "page", value = "页码", defaultValue = "1")
  89. @RequestParam(value = "page", required = false) int page,
  90. HttpServletRequest request,
  91. HttpServletResponse response) throws Exception {
  92. List<Organization> organizationList = orgService.search(fields, filters, sorts, page, size);
  93. pagedResponse(request, response, orgService.getCount(filters), page, size);
  94. return (List<MOrganization>) convertToModels(organizationList, new ArrayList<MOrganization>(organizationList.size()), MOrganization.class, fields);
  95. }
  96. /**
  97. * 机构列表查询
  98. *
  99. * @param fields
  100. * @param filters
  101. * @param sorts
  102. * @param size
  103. * @param page
  104. * @return
  105. * @throws Exception
  106. */
  107. @RequestMapping(value = "/organizations/searchForCombo", method = RequestMethod.GET)
  108. @ApiOperation(value = "根据条件查询机构列表")
  109. public Envelop search(
  110. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
  111. @RequestParam(value = "fields", required = false) String fields,
  112. @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
  113. @RequestParam(value = "filters", required = false) String filters,
  114. @ApiParam(name = "searchParm", value = "关键字搜索")
  115. @RequestParam(value = "searchParm", required = false) String searchParm,
  116. @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
  117. @RequestParam(value = "sorts", required = false) String sorts,
  118. @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
  119. @RequestParam(value = "size", required = false) int size,
  120. @ApiParam(name = "page", value = "页码", defaultValue = "1")
  121. @RequestParam(value = "page", required = false) int page) throws Exception {
  122. filters = filters == null ? "" : filters;
  123. if (StringUtils.isNotEmpty(searchParm)) {
  124. filters += "orgCode?" + searchParm + " g1;fullName?" + searchParm + " g1;";
  125. }
  126. List<Organization> list = orgService.search(fields, filters, sorts, page, size);
  127. int count = (int) orgService.getCount(filters);
  128. Envelop envelop = getPageResult(list, count, page, size);
  129. return envelop;
  130. }
  131. /**
  132. * 删除机构
  133. *
  134. * @param orgCode
  135. * @return
  136. */
  137. @RequestMapping(value = "/organizations/{org_code}", method = RequestMethod.DELETE)
  138. @ApiOperation(value = "根据机构代码删除机构")
  139. public boolean deleteOrg(
  140. @ApiParam(name = "org_code", value = "机构代码", defaultValue = "")
  141. @PathVariable(value = "org_code") String orgCode) throws Exception {
  142. orgService.delete(orgCode);
  143. return true;
  144. }
  145. /**
  146. * 创建机构
  147. *
  148. * @param orgJsonData
  149. * @throws Exception
  150. */
  151. @RequestMapping(value = "/organizations", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  152. @ApiOperation(value = "创建机构")
  153. public MOrganization create(
  154. @ApiParam(name = "mOrganizationJsonData", value = "机构代码", defaultValue = "")
  155. @RequestBody String orgJsonData) throws Exception {
  156. Organization org = toEntity(orgJsonData, Organization.class);
  157. org.setCreateDate(new Date());
  158. org.setActivityFlag(1);
  159. org.setPyCode(PinyinUtil.getPinYinHeadChar(org.getFullName(), false));
  160. Organization organization = orgService.save(org);
  161. String orgId = orgService.getOrgIdByOrgCode(organization.getOrgCode());
  162. //添加默认部门
  163. OrgDept dept = new OrgDept();
  164. dept.setOrgId(String.valueOf(orgId));
  165. dept.setCode(String.valueOf(orgId) + "1");
  166. dept.setName("未分配");
  167. orgDeptService.saveOrgDept(dept);
  168. return convertToModel(org, MOrganization.class);
  169. }
  170. @RequestMapping(value = "organizations", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  171. @ApiOperation(value = "修改机构")
  172. public MOrganization update(
  173. @ApiParam(name = "mOrganizationJsonData", value = "机构代码", defaultValue = "")
  174. @RequestBody String orgJsonData) throws Exception {
  175. Organization org = toEntity(orgJsonData, Organization.class);
  176. org.setPyCode(PinyinUtil.getPinYinHeadChar(org.getFullName(), false));
  177. orgService.save(org);
  178. return convertToModel(org, MOrganization.class);
  179. }
  180. /**
  181. * 根据机构代码获取机构
  182. *
  183. * @param orgCode
  184. * @return
  185. */
  186. @RequestMapping(value = "/organizations/{org_code}", method = RequestMethod.GET)
  187. @ApiOperation(value = "根据机构代码获取机构")
  188. public MOrganization getOrg(
  189. @ApiParam(name = "org_code", value = "机构代码", defaultValue = "")
  190. @PathVariable(value = "org_code") String orgCode) throws Exception {
  191. Organization org = orgService.getOrg(orgCode);
  192. MOrganization orgModel = convertToModel(org, MOrganization.class);
  193. return orgModel;
  194. }
  195. /**
  196. * 根据机构ID获取机构
  197. *
  198. * @param orgId
  199. * @return
  200. */
  201. @RequestMapping(value = "/organizations/getOrgById/{org_id}", method = RequestMethod.GET)
  202. @ApiOperation(value = "根据机构ID获取机构")
  203. public MOrganization getOrgById(
  204. @ApiParam(name = "org_id", value = "机构代码", defaultValue = "")
  205. @PathVariable(value = "org_id") String orgId) throws Exception {
  206. Organization org = orgService.getOrgById(orgId);
  207. MOrganization orgModel = convertToModel(org, MOrganization.class);
  208. return orgModel;
  209. }
  210. /**
  211. * 根据机构代码列表批量查询机构
  212. *
  213. * @param orgCodes
  214. * @return
  215. */
  216. @RequestMapping(value = "/organizations/org_codes", method = RequestMethod.GET)
  217. @ApiOperation(value = "根据机构代码列表批量查询机构")
  218. public List<MOrganization> getOrgs(
  219. @ApiParam(name = "org_codes", value = "机构代码", defaultValue = "")
  220. @RequestParam(value = "org_codes") String[] orgCodes) throws Exception {
  221. List<String> orgCodeList = Arrays.asList(orgCodes);
  222. List<Organization> organizationList = orgService.findByOrgCodes(orgCodeList);
  223. return (List<MOrganization>) convertToModels(organizationList, new ArrayList<MOrganization>(organizationList.size()), MOrganization.class, "");
  224. }
  225. /**
  226. * 根据管理员登录帐号获取机构
  227. *
  228. * @param adminLoginCode
  229. * @return
  230. */
  231. @RequestMapping(value = "/organizations/{org_code}/admin/{admin_login_code}", method = RequestMethod.GET)
  232. @ApiOperation(value = "根据管理员登录帐号获取机构")
  233. public MOrganization getOrgByAdminLoginCode(
  234. @ApiParam(name = "org_code", value = "管理员登录帐号", defaultValue = "")
  235. @PathVariable(value = "org_code") String orgCode,
  236. @ApiParam(name = "admin_login_code", value = "机构代码", defaultValue = "")
  237. @PathVariable(value = "admin_login_code") String adminLoginCode) throws Exception {
  238. Organization org = orgService.getOrgByAdminLoginCode(orgCode, adminLoginCode);
  239. MOrganization orgModel = convertToModel(org, MOrganization.class);
  240. return orgModel;
  241. }
  242. /**
  243. * 根据name获取机构orgCodes
  244. *
  245. * @param name
  246. * @return
  247. */
  248. @ApiOperation(value = "根据名称获取机构编号列表")
  249. @RequestMapping(value = "/organizations/name", method = RequestMethod.GET)
  250. public List<String> getIdsByName(
  251. @ApiParam(name = "name", value = "机构名称", defaultValue = "")
  252. @RequestParam(value = "name") String name) {
  253. List<String> orgCodes = orgService.getCodesByName(name);
  254. return orgCodes;
  255. }
  256. @ApiOperation(value = "根据地区代码获取机构列表")
  257. @RequestMapping(value = "/organizations/areas/{area}", method = RequestMethod.GET)
  258. public List<MOrganization> getOrganizationByAreaCode(
  259. @ApiParam(name = "area", value = "地区代码", defaultValue = "")
  260. @PathVariable(value = "area") String area) {
  261. List<Organization> organizationList = orgService.findByOrgArea(area);
  262. return (List<MOrganization>) convertToModels(organizationList, new ArrayList<MOrganization>(organizationList.size()), MOrganization.class, "");
  263. }
  264. /**
  265. * 跟新机构激活状态
  266. *
  267. * @param orgCode
  268. * @return
  269. */
  270. @RequestMapping(value = "organizations/{org_code}/{activity_flag}", method = RequestMethod.PUT)
  271. @ApiOperation(value = "跟新机构激活状态")
  272. public boolean activity(
  273. @ApiParam(name = "org_code", value = "机构代码", defaultValue = "")
  274. @PathVariable(value = "org_code") String orgCode,
  275. @ApiParam(name = "activity_flag", value = "状态", defaultValue = "")
  276. @PathVariable(value = "activity_flag") int activityFlag) throws Exception {
  277. Organization org = orgService.getOrg(orgCode);
  278. if (org.getActivityFlag() == 1) {
  279. org.setActivityFlag(0);
  280. } else {
  281. org.setActivityFlag(1);
  282. }
  283. orgService.save(org);
  284. return true;
  285. }
  286. /**
  287. * 根据地址获取机构下拉列表
  288. *
  289. * @param province
  290. * @param city
  291. * @param district
  292. * @return
  293. */
  294. @RequestMapping(value = "/organizations/geography", method = RequestMethod.GET)
  295. @ApiOperation(value = "根据地址获取机构下拉列表")
  296. public List<MOrganization> getOrgsByAddress(
  297. @ApiParam(name = "province", value = "省")
  298. @RequestParam(value = "province") String province,
  299. @ApiParam(name = "city", value = "市")
  300. @RequestParam(value = "city", required = false) String city,
  301. @ApiParam(name = "district", value = "县")
  302. @RequestParam(value = "district", required = false) String district) {
  303. List<Organization> orgList = orgService.searchByAddress(province, city, district);
  304. if (orgList != null && orgList.size() > 0) {
  305. return (List<MOrganization>) convertToModels(orgList, new ArrayList<MOrganization>(orgList.size()), MOrganization.class, null);
  306. } else {
  307. return null;
  308. }
  309. }
  310. @RequestMapping(value = "/organizations/key", method = RequestMethod.POST)
  311. @ApiOperation(value = "机构分发密钥")
  312. public Map<String, String> distributeKey(
  313. @ApiParam(name = "org_code", value = "机构代码")
  314. @RequestParam(value = "org_code") String orgCode) throws Exception {
  315. UserSecurity key = userSecurityService.getKeyByOrgCode(orgCode);
  316. Map<String, String> keyMap = new HashMap<>();
  317. if (key != null) {
  318. List<UserKey> keyMaps = userSecurityService.getKeyMapByOrgCode(orgCode);
  319. userSecurityService.deleteKey(keyMaps);
  320. }
  321. key = userSecurityService.createKeyByOrgCode(orgCode);
  322. String validTime = DateFormatUtils.format(key.getFromDate(), "yyyy-MM-dd")
  323. + "~" + DateFormatUtils.format(key.getExpiryDate(), "yyyy-MM-dd");
  324. keyMap.put("publicKey", key.getPublicKey());
  325. keyMap.put("validTime", validTime);
  326. keyMap.put("startTime", DateFormatUtils.format(key.getFromDate(), "yyyy-MM-dd"));
  327. return keyMap;
  328. }
  329. @RequestMapping(value = "/organizations/existence/{org_code}", method = RequestMethod.GET)
  330. @ApiOperation(value = "判断提交的机构代码是否已经存在")
  331. boolean isOrgCodeExists(
  332. @ApiParam(name = "org_code", value = "org_code", defaultValue = "")
  333. @PathVariable(value = "org_code") String orgCode) {
  334. return orgService.isExistOrg(orgCode);
  335. }
  336. @RequestMapping(value = "/organizations/checkSunOrg", method = RequestMethod.PUT)
  337. @ApiOperation(value = "判断机构是否已经是子机构")
  338. boolean checkSunOrg(
  339. @ApiParam(name = "org_pId", value = "org_pId", defaultValue = "")
  340. @RequestParam(value = "org_pId") String orgPid,
  341. @ApiParam(name = "org_id", value = "org_id", defaultValue = "")
  342. @RequestParam(value = "org_id") String orgId) {
  343. return orgService.checkSunOrg(orgPid, orgId);
  344. }
  345. /**
  346. * 机构资质上传
  347. *
  348. * @return
  349. * @throws IOException
  350. */
  351. @RequestMapping(value = "/organizations/images", method = RequestMethod.POST)
  352. @ApiOperation(value = "上传头像,把图片转成流的方式发送")
  353. public String uploadImages(
  354. @ApiParam(name = "jsonData", value = "头像转化后的输入流")
  355. @RequestBody String jsonData) throws Exception {
  356. if (jsonData == null) {
  357. return null;
  358. }
  359. String date = URLDecoder.decode(jsonData, "UTF-8");
  360. String[] fileStreams = date.split(",");
  361. String is = URLDecoder.decode(fileStreams[0], "UTF-8").replace(" ", "+");
  362. byte[] in = Base64.getDecoder().decode(is);
  363. String pictureName = fileStreams[1].substring(0, fileStreams[1].length() - 1);
  364. String fileExtension = pictureName.substring(pictureName.lastIndexOf(".") + 1).toLowerCase();
  365. String description = null;
  366. if ((pictureName != null) && (pictureName.length() > 0)) {
  367. int dot = pictureName.lastIndexOf('.');
  368. if ((dot > -1) && (dot < (pictureName.length()))) {
  369. description = pictureName.substring(0, dot);
  370. }
  371. }
  372. InputStream inputStream = new ByteArrayInputStream(in);
  373. ObjectNode objectNode = fastDFSUtil.upload(inputStream, fileExtension, description);
  374. String groupName = objectNode.get("groupName").toString();
  375. String remoteFileName = objectNode.get("remoteFileName").toString();
  376. // String path = "{\"groupName\":" + groupName + ",\"remoteFileName\":" + remoteFileName + "}";
  377. String path = groupName.substring(1, groupName.length() - 1) + ":" + remoteFileName.substring(1, remoteFileName.length() - 1);
  378. //返回文件路径
  379. return path;
  380. }
  381. /**
  382. * 机构资质下载
  383. *
  384. * @return
  385. */
  386. @RequestMapping(value = "/organizations/images", method = RequestMethod.GET)
  387. @ApiOperation(value = "下载头像")
  388. public String downloadPicture(
  389. @ApiParam(name = "group_name", value = "分组", defaultValue = "")
  390. @RequestParam(value = "group_name") String groupName,
  391. @ApiParam(name = "remote_file_name", value = "服务器头像名称", defaultValue = "")
  392. @RequestParam(value = "remote_file_name") String remoteFileName) throws Exception {
  393. byte[] bytes = fastDFSUtil.download(groupName, remoteFileName);
  394. String fileStream = new String(Base64.getEncoder().encode(bytes));
  395. String imageStream = URLEncoder.encode(fileStream, "UTF-8");
  396. return imageStream;
  397. }
  398. @RequestMapping(value = "/organizations/getAllSaasOrgs", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  399. @ApiOperation(value = "查询所有机构列表")
  400. public List<Organization> getAllSaasOrgs(
  401. @ApiParam(name = "saasName", value = "名称", defaultValue = "")
  402. @RequestParam(value = "saasName", required = false) String saasName) throws Exception {
  403. List<Organization> orgs = orgService.getAllSaasOrgs(saasName);
  404. return orgs;
  405. }
  406. /**
  407. * 根据机构ID获取机构
  408. *
  409. * @param userOrgCode
  410. * @return
  411. */
  412. @RequestMapping(value = "/organizations/getOrgListById", method = RequestMethod.GET)
  413. @ApiOperation(value = "根据机构ID获取机构")
  414. public List<String> getOrgListById(
  415. @ApiParam(name = "userOrgCode", value = "机构代码", defaultValue = "")
  416. @RequestParam(value = "userOrgCode") List<Long> userOrgCode) throws Exception {
  417. List<String> organizationList = orgService.getOrgListById(userOrgCode);
  418. return organizationList;
  419. }
  420. @RequestMapping(value = "/organizations/getAllOrgsNoPaging", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  421. @ApiOperation(value = "查询所有机构列表不分页")
  422. public List<MOrganization> getAllOrgsNoPaging() throws Exception {
  423. List<MOrganization> orgs = orgService.search(null);
  424. return orgs;
  425. }
  426. @RequestMapping(value = "/organizations/batch", method = RequestMethod.POST)
  427. @ApiOperation("批量导入机构")
  428. public boolean createOrgBatch(
  429. @ApiParam(name = "orgs", value = "JSON", defaultValue = "")
  430. @RequestBody String orgs) throws Exception {
  431. List models = objectMapper.readValue(orgs, new TypeReference<List>() {
  432. });
  433. orgService.addOrgBatch(models);
  434. return true;
  435. }
  436. @RequestMapping(value = ServiceApi.Org.getseaOrgsByOrgCode, method = RequestMethod.POST)
  437. @ApiOperation("根据机构code获取机构code和name")
  438. public Map<String, String> seaOrgsByOrgCode(
  439. @ApiParam(name = "org_codes", value = "机构org_codes", defaultValue = "")
  440. @RequestBody String org_codes) throws Exception {
  441. Map<String, String> map = new HashMap<>();
  442. List<Object> list = (List<Object>) orgService.orgExist(toEntity(org_codes, String[].class));
  443. for (int i = 0; i < list.size(); i++) {
  444. Object[] objectList = (Object[]) list.get(i);
  445. if (null != objectList[0] && null != objectList[1]) {
  446. map.put(objectList[0].toString(), objectList[1].toString());
  447. }
  448. }
  449. return map;
  450. }
  451. ;
  452. @RequestMapping(value = "/organizations/getHospital", method = RequestMethod.GET)
  453. @ApiOperation(value = "查询所有经纬度医院列表")
  454. public Envelop getHospital() throws Exception {
  455. Envelop envelop = new Envelop();
  456. try {
  457. List<Organization> orgs = orgService.getHospital();
  458. envelop.setSuccessFlg(true);
  459. envelop.setDetailModelList(orgs);
  460. } catch (Exception e) {
  461. e.printStackTrace();
  462. envelop.setSuccessFlg(false);
  463. envelop.setErrorMsg(e.getMessage());
  464. }
  465. return envelop;
  466. }
  467. @RequestMapping(value = "/organizations/getOrgListByAddressPid", method = RequestMethod.GET)
  468. @ApiOperation(value = "根据区域查询机构列表")
  469. public Envelop getOrgListByAddressPid(
  470. @ApiParam(name = "pid", value = "区域id", defaultValue = "")
  471. @RequestParam(value = "pid") Integer pid,
  472. @ApiParam(name = "fullName", value = "机构名称", defaultValue = "")
  473. @RequestParam(value = "fullName", required = false) String fullName) {
  474. Envelop envelop = new Envelop();
  475. try {
  476. List<Organization> orgList;
  477. if (StringUtils.isEmpty(fullName)) {
  478. orgList = orgService.getOrgListByAddressPid(pid);
  479. } else {
  480. orgList = orgService.getOrgListByAddressPidAndParam(pid, fullName);
  481. }
  482. envelop.setSuccessFlg(true);
  483. envelop.setDetailModelList(orgList);
  484. } catch (Exception e) {
  485. e.printStackTrace();
  486. envelop.setSuccessFlg(false);
  487. envelop.setErrorMsg(e.getMessage());
  488. }
  489. return envelop;
  490. }
  491. @RequestMapping(value = "/organizations/getOrgListTreeByAddressPid", method = RequestMethod.GET)
  492. @ApiOperation(value = "根据区域、机构区县查询机构列表")
  493. public List<Map<String, Object>> getOrgListTreeByAddressPid(
  494. @ApiParam(name = "pid", value = "区域id", defaultValue = "")
  495. @RequestParam(value = "pid") Integer pid) {
  496. List<Map<String, Object>> listMap = new ArrayList<>();
  497. try {
  498. List<AddressDict> addList = addressDictService.getPidToAddr(pid);
  499. List<Organization> orgList;
  500. for (AddressDict addressDict : addList) {
  501. List<Map<String, Object>> childListMap = new ArrayList<>();
  502. Map<String, Object> allMap = new HashMap<>();
  503. allMap.put("text", "全部机构");
  504. childListMap.add(allMap);
  505. Map<String, Object> map = new HashMap<>();
  506. map.put("text", addressDict.getName());
  507. map.put("value", addressDict.getId());
  508. orgList = orgService.getOrgListByAddressPidAndOrgArea(pid, addressDict.getId() + "");
  509. if (null != orgList && orgList.size() > 0) {
  510. orgList.forEach(one -> {
  511. Map<String, Object> childMap = new HashMap<>();
  512. childMap.put("text", one.getFullName());
  513. childMap.put("value", one.getOrgCode());
  514. childListMap.add(childMap);
  515. });
  516. }
  517. map.put("children", childListMap);
  518. listMap.add(map);
  519. }
  520. } catch (Exception e) {
  521. e.printStackTrace();
  522. }
  523. return listMap;
  524. }
  525. @RequestMapping(value = ServiceApi.Org.getOrgCodeAndFullName, method = RequestMethod.GET)
  526. @ApiOperation("获取所有机构的机构组织机构代码和名称")
  527. public Envelop getOrgCodeAndFullName(
  528. @ApiParam(name = "field", value = "作为key值得字段")
  529. @RequestParam(value = "field", required = false) String field) throws Exception {
  530. Envelop envelop = new Envelop();
  531. Map<String, String> map = new HashMap<>();
  532. List list = orgService.getOrgCodeAndFullName(field);
  533. String orgCode = "";
  534. String fullName = "";
  535. for (int i = 0; i < list.size(); i++) {
  536. Object[] obj = (Object[]) list.get(i);
  537. if (null != obj[0] && null != obj[1]) {
  538. orgCode = obj[0].toString();
  539. fullName = obj[1].toString();
  540. map.put(orgCode, fullName);
  541. }
  542. }
  543. envelop.setSuccessFlg(true);
  544. envelop.setObj(map);
  545. return envelop;
  546. }
  547. @RequestMapping(value = "/getAdressByLocation", method = RequestMethod.GET)
  548. @ApiOperation("地址处理111111")
  549. public Map<String, String> getAdressByLocation(String location) {
  550. Map<String, String> map = new HashMap<>();
  551. String[] temp = null;
  552. temp = location.split("省");
  553. String str = "";
  554. for (int i = 0; i < temp.length; i++) {
  555. if (temp[0].indexOf("省") > 0) {
  556. //不包括直辖市、自治区
  557. map.put("provinceName", temp[0] + "省");
  558. }
  559. str = temp[temp.length - 1];
  560. }
  561. if (StringUtils.isNotEmpty(str)) {
  562. temp = str.split("市");
  563. str = temp[temp.length - 1];
  564. if (temp.length > 2) {
  565. map.put("cityName", temp[0] + "市");
  566. map.put("district", temp[1] + "市");
  567. map.put("street", temp[2]);
  568. } else if (temp.length > 1) {
  569. map.put("cityName", temp[0] + "市");
  570. map.put("district", temp[1]);
  571. temp = str.split("县");
  572. if (temp.length > 1) {
  573. map.put("district", temp[0] + "县");
  574. map.put("street", temp[1]);
  575. } else {
  576. temp = str.split("区");
  577. if (temp.length > 1) {
  578. map.put("district", temp[0] + "区");
  579. map.put("street", temp[1]);
  580. } else {
  581. map.put("street", temp[0]);
  582. }
  583. }
  584. } else {
  585. temp = str.split("县");
  586. if (temp.length > 1) {
  587. map.put("district", temp[0] + "县");
  588. map.put("street", temp[1]);
  589. } else {
  590. temp = str.split("区");
  591. if (temp.length > 1) {
  592. map.put("district", temp[0] + "区");
  593. map.put("street", temp[1]);
  594. } else {
  595. map.put("street", temp[0]);
  596. }
  597. }
  598. }
  599. }
  600. return map;
  601. }
  602. @RequestMapping(value = BasicServiceApi.Org.getAllOrgByAdministrativeDivision, method = RequestMethod.GET)
  603. @ApiOperation(value = "用户修改-按照区域获取机构;查询所有机构列表")
  604. public Envelop getAllOrgs(
  605. @ApiParam(name = "areaId", value = "区域id")
  606. @RequestParam(value = "areaId", required = false) String areaId,
  607. @ApiParam(name = "fullName", value = "机构名称")
  608. @RequestParam(value = "fullName", required = false) String fullName) {
  609. Envelop envelop = new Envelop();
  610. try {
  611. List<Organization> orgList;
  612. if (StringUtils.isEmpty(fullName)&&StringUtils.isNotEmpty(areaId)) {
  613. //区域id存在,机构名称不存在
  614. orgList = orgService.findByOrgArea(areaId.toString());
  615. } else if (StringUtils.isNotEmpty(fullName)&&StringUtils.isEmpty(areaId)) {
  616. //区域id不存在,机构名称存在
  617. String filters="fullName?" +fullName;
  618. orgList = orgService.search("", filters, "-createDate", 1, 999);
  619. }else if (StringUtils.isNotEmpty(fullName)&&StringUtils.isNotEmpty(areaId)) {
  620. //区域和机构名称都存在
  621. orgList = orgService.getOrgListByAreaidAndParam(Integer.valueOf(areaId), fullName);
  622. }else {
  623. envelop.setSuccessFlg(false);
  624. envelop.setErrorMsg("区域和机构名称不能同时为空!");
  625. return envelop;
  626. }
  627. envelop.setSuccessFlg(true);
  628. envelop.setDetailModelList(orgList);
  629. } catch (Exception e) {
  630. e.printStackTrace();
  631. envelop.setSuccessFlg(false);
  632. envelop.setErrorMsg(e.getMessage());
  633. }
  634. return envelop;
  635. }
  636. }