1a08f4bca167b1dbdf1ed43ed79f0dfb8ed50753.svn-base 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.yihu.platform.api;
  2. import com.yihu.platform.apiservice.IHealthService;
  3. import com.yihu.platform.cache.DBCache;
  4. import com.yihu.platform.utils.ApiUtil;
  5. import com.yihu.platform.utils.Pinyin4jUtil;
  6. import com.yihu.platform.utils.StringUtil;
  7. import com.yihu.wsgw.api.InterfaceMessage;
  8. import net.sf.json.JSONArray;
  9. import net.sf.json.JSONException;
  10. import net.sf.json.JSONObject;
  11. /**
  12. * 医院接口
  13. *
  14. * @author wengsb----yihu.com
  15. * 2017年8月17日下午3:00:15
  16. */
  17. public class HospitalApi {
  18. /**
  19. * 通过省市医院id等获取医院信息
  20. *
  21. * @param msg
  22. * @return
  23. */
  24. public String queryComplexHospitalList_v2(InterfaceMessage msg) {
  25. try {
  26. JSONObject json = JSONObject.fromObject(msg.getParam());
  27. String hospitalId = StringUtil.isEmpty(json.get("hospitalId")) ? "" : json.getString("hospitalId");
  28. String provinceId = StringUtil.isEmpty(json.get("provinceId")) ? "" : json.getString("provinceId");
  29. String cityId = StringUtil.isEmpty(json.get("cityId")) ? "" : json.getString("cityId");
  30. Integer page = json.get("page") == null ? 1 : json.getInt("page");
  31. Integer pageSize = json.get("pageSize") == null ? 10 : json.getInt("pageSize");
  32. if(StringUtil.isNotEmpty(provinceId))provinceId = DBCache.provinceGBCodeMap.get(provinceId);
  33. if(StringUtil.isNotEmpty(cityId))cityId = DBCache.cityGBCodeMap.get(cityId);
  34. IHealthService api = new IHealthService();
  35. String resp = api.queryHospital(hospitalId, provinceId, cityId, page, pageSize);
  36. JSONObject objRet = ApiUtil.getRespJSON(10000, "成功");
  37. JSONArray result = new JSONArray();
  38. if(StringUtil.isNotEmpty(resp)){
  39. JSONObject re = JSONObject.fromObject(resp);
  40. if (re.getInt("status") != 10000) {
  41. return ApiUtil.getRespJSON(-10000, "查询医院信息失败:" + re).toString();
  42. }
  43. JSONArray array = re.getJSONArray("result");
  44. for(Object o :array){
  45. JSONObject obj = (JSONObject) o;
  46. JSONObject j = new JSONObject();
  47. j.put("hospitalId", obj.get("code"));
  48. j.put("hosName", obj.get("name"));
  49. j.put("spells", Pinyin4jUtil.getPinyin(obj.getString("name")));
  50. String levelName = "";
  51. if(obj.get("level").equals(1))levelName = "医院";
  52. if(obj.get("level").equals(2))levelName = "社区医院";
  53. j.put("levelId", obj.get("level"));
  54. j.put("levelName", levelName);
  55. j.put("provinceId", obj.get("province"));
  56. j.put("provinceName", obj.get("provinceName"));
  57. j.put("cityId", obj.get("city"));
  58. j.put("cityName", obj.get("cityName"));
  59. j.put("address", obj.get("address"));
  60. j.put("contact", obj.get("phone"));
  61. j.put("clinicTime", obj.get(""));
  62. j.put("traffic", obj.get("centerSite"));
  63. j.put("url", obj.get(""));
  64. j.put("intro", obj.get("intro"));
  65. j.put("photoUri", obj.get("photo"));
  66. result.add(j);
  67. }
  68. objRet.put("Count", re.getInt("allNum"));
  69. }else{
  70. objRet.put("Count", 0);
  71. }
  72. objRet.put("Result", result);
  73. return objRet.toString();
  74. } catch (JSONException e) {
  75. return ApiUtil.getRespJSON(-10000, "非标准json:[" + msg.getParam() + "]").toString();
  76. } catch (Exception e) {
  77. e.printStackTrace();
  78. return ApiUtil.getRespJSON(-14444, "加载异常!" + StringUtil.getException(e)).toString();
  79. }
  80. }
  81. }