package com.yihu.platform.api; import java.io.IOException; import com.coreframework.db.DB; import com.coreframework.ioc.Ioc; import com.coreframework.util.AppConfig; import com.yihu.platform.apiservice.IHealthService; import com.yihu.platform.service.IUserMappingService; import com.yihu.platform.utils.ApiUtil; import com.yihu.platform.utils.DesUtil; import com.yihu.platform.utils.Pinyin4jUtil; import com.yihu.platform.utils.StringUtil; import com.yihu.wsgw.api.InterfaceMessage; import net.sf.json.JSONArray; import net.sf.json.JSONException; import net.sf.json.JSONObject; /** * 医生接口 * @author wengsb----yihu.com * 2017年8月17日下午3:00:15 */ public class DoctorApi { private static final IUserMappingService userMappingService = Ioc.get(IUserMappingService.class); /** * 通过医院id,医生id获取医生列表 * @param msg * @return */ public String queryComplexDoctorList_v2(InterfaceMessage msg) { try { JSONObject json = JSONObject.fromObject(msg.getParam()); Integer pageIndex = StringUtil.isEmpty(json.get("pageIndex")) ? 1 : json.getInt("pageIndex"); Integer pageSize = StringUtil.isEmpty(json.get("pageSize")) ? 10 : json.getInt("pageSize"); String hosDeptId = StringUtil.isEmpty(json.get("hosDeptId")) ? "" : json.getString("hosDeptId"); String doctorUid = StringUtil.isEmpty(json.get("doctorUid")) ? "" : json.getString("doctorUid"); String doctorUids = StringUtil.isEmpty(json.get("doctorUids")) ? "" : json.getString("doctorUids"); String hospitalId = StringUtil.isEmpty(json.get("hospitalId")) ? "" : json.getString("hospitalId"); String userId = StringUtil.isEmpty(json.get("userId")) ? "" : json.getString("userId"); if(StringUtil.isEmpty(userId)){ return ApiUtil.getRespJSON(-10000, "userId不能为空:").toString(); } IHealthService api = new IHealthService(); String resp = api.queryDoctor(hospitalId,userId,pageIndex,pageSize); JSONObject re = JSONObject.fromObject(resp); if (re.getInt("status") != 10000) { return ApiUtil.getRespJSON(-10000, "查询医生信息失败:" + re).toString(); } JSONArray array = re.getJSONArray("result"); JSONArray result = new JSONArray(); for(Object o :array){ JSONObject obj = (JSONObject) o; JSONObject j = new JSONObject(); j.put("hosDeptId", obj.get("dept")); j.put("doctorUid", obj.get("code")); j.put("doctorName", obj.get("name")); j.put("doctorSex", obj.get("sex")); j.put("lczc", obj.get("job")); j.put("lczcName", obj.get("jobName")); j.put("spells", Pinyin4jUtil.getPinyin(obj.getString("name"))); j.put("skill", obj.get("expertise")); j.put("intro", obj.get("introduce")); j.put("photoUri", obj.get("photo")); j.put("provinceId", obj.get("province")); j.put("provinceName", obj.get("provinceName")); j.put("cityId", obj.get("city")); j.put("cityName", obj.get("cityName")); j.put("hospitalId", obj.get("hospital")); j.put("hosName", obj.get("hospitalName")); j.put("deptName", obj.get("deptName")); result.add(j); } JSONObject obj = ApiUtil.getRespJSON(10000, "成功"); obj.put("Result", result); obj.put("Count", 10); return obj.toString(); } catch (JSONException e) { return ApiUtil.getRespJSON(-10000, "非标准json:[" + msg.getParam() + "]").toString(); } catch (Exception e) { e.printStackTrace(); return ApiUtil.getRespJSON(-14444, "加载异常!" + StringUtil.getException(e)).toString(); } } /** * 根据医生id查询医生信息 * @param msg * @return */ public String queryDoctorInfoByUid(InterfaceMessage msg) { try { JSONObject json = JSONObject.fromObject(msg.getParam()); String userId = StringUtil.isEmpty(json.get("userId")) ? "" : json.getString("userId"); if(StringUtil.isEmpty(userId)){ return ApiUtil.getRespJSON(-10000, "userId不能为空:").toString(); } IHealthService api = new IHealthService(); String resp = api.queryDoctorByUserId(userId); JSONObject re = JSONObject.fromObject(resp); if (re.getInt("status") != 10000) { return ApiUtil.getRespJSON(-10000, "查询医生信息失败:" + re).toString(); } JSONObject obj = re.getJSONObject("result"); JSONObject retJSON = new JSONObject(); if(obj!=null && obj.size()>0 && StringUtil.isNotEmpty(obj.get("code"))) { retJSON.put("userId", obj.get("code")); retJSON.put("doctorName", obj.get("name")); retJSON.put("doctorSex", obj.get("name")); retJSON.put("doctorSex", obj.get("sex")); retJSON.put("lczc", obj.get("job")); retJSON.put("lczcName", obj.get("jobName")); if(StringUtil.isNotEmpty(obj.get("name"))){ retJSON.put("spells", Pinyin4jUtil.getPinyin(obj.getString("name"))); }else{ retJSON.put("spells", ""); } retJSON.put("skill", obj.get("expertise")); retJSON.put("intro", obj.get("introduce")); retJSON.put("photoUri", obj.get("photo")); retJSON.put("provinceId", obj.get("province")); retJSON.put("provinceName", obj.get("provinceName")); retJSON.put("cityId", obj.get("city")); retJSON.put("cityName", obj.get("cityName")); retJSON.put("hospitalId", obj.get("hospital")); retJSON.put("hosName", obj.get("hospitalName")); retJSON.put("deptName", obj.get("deptName")); Integer userType = userMappingService.getUserType4UserMapping(obj.get("code").toString()); if(userType == null || userType<=0){ return ApiUtil.getRespJSON(-10000, "查询医生信息失败").toString(); } retJSON.put("userType",userType); } retJSON.put("Code", 10000); retJSON.put("Message", "成功"); return retJSON.toString(); } catch (JSONException e) { return ApiUtil.getRespJSON(-10000, "非标准json:[" + msg.getParam() + "]").toString(); } catch (Exception e) { e.printStackTrace(); return ApiUtil.getRespJSON(-14444, "加载异常!" + StringUtil.getException(e)).toString(); } } }