|  | @ -0,0 +1,192 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.doctor.service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.DoctorSpecialDiseaseDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorVo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.DoctorSpecialDiseaseDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.Envelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.MixEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.hibernate.HibenateUtils;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import net.sf.json.JSONObject;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.map.HashedMap;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDao> {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorDao baseDoctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DoctorSpecialDiseaseDao specialDiseaseDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private HibenateUtils hibenateUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查询医生信息分页列表
 | 
	
		
			
				|  |  |      * @param city
 | 
	
		
			
				|  |  |      * @param hospital
 | 
	
		
			
				|  |  |      * @param status
 | 
	
		
			
				|  |  |      * @param name
 | 
	
		
			
				|  |  |      * @param page
 | 
	
		
			
				|  |  |      * @param pageSize
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Envelop queryList(String city, String hospital, String status, String name, int page, int pageSize){
 | 
	
		
			
				|  |  |         Map<String,Object> params = new HashedMap();
 | 
	
		
			
				|  |  |         String sqlTotal ="SELECT " +
 | 
	
		
			
				|  |  |                 " COUNT(1) AS \"total\" " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " base_doctor a " +
 | 
	
		
			
				|  |  |                 " JOIN base_doctor_hospital b ON a.id = b.doctor_code " +
 | 
	
		
			
				|  |  |                 " JOIN wlyy_charge_dict e ON a.charge_type = e.charge_type " +
 | 
	
		
			
				|  |  |                 " WHERE " +
 | 
	
		
			
				|  |  |                 " 1 = 1";
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(city)){
 | 
	
		
			
				|  |  |             sqlTotal += " AND a.city_name =:city";
 | 
	
		
			
				|  |  |             params.put("city",city);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(hospital)){
 | 
	
		
			
				|  |  |             sqlTotal += " AND b.org_code =:hospital";
 | 
	
		
			
				|  |  |             params.put("hospital",hospital);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(status)){
 | 
	
		
			
				|  |  |             sqlTotal += " AND a.del =:status";
 | 
	
		
			
				|  |  |             params.put("status",status);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(name)){
 | 
	
		
			
				|  |  |             name = name+"%";
 | 
	
		
			
				|  |  |             sqlTotal += " AND b.dept_name like:name";
 | 
	
		
			
				|  |  |             params.put("name",name);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sqlTotal += " AND e.dept_type_code =:typeCode";
 | 
	
		
			
				|  |  |         params.put("typeCode",6);
 | 
	
		
			
				|  |  |         Long count = 0L;
 | 
	
		
			
				|  |  |         List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlTotal,params);
 | 
	
		
			
				|  |  |         if(count!=null){
 | 
	
		
			
				|  |  |             //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
 | 
	
		
			
				|  |  |             count = hibenateUtils.objTransformLong(total.get(0).get("total"));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String sql ="SELECT " +
 | 
	
		
			
				|  |  |                 " a.id AS \"id\", " +
 | 
	
		
			
				|  |  |                 " a.NAME AS \"name\", " +
 | 
	
		
			
				|  |  |                 " a.introduce AS \"introduce\", " +
 | 
	
		
			
				|  |  |                 " a.expertise AS \"expertise\", " +
 | 
	
		
			
				|  |  |                 " a.outpatient_type AS \"outpatientType\", " +
 | 
	
		
			
				|  |  |                 " a.del AS \"del\", " +
 | 
	
		
			
				|  |  |                 " b.dept_name AS \"deptName\", " +
 | 
	
		
			
				|  |  |                 " e.req_fee AS \"money\" " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " base_doctor a " +
 | 
	
		
			
				|  |  |                 " JOIN base_doctor_hospital b ON a.id = b.doctor_code " +
 | 
	
		
			
				|  |  |                 " JOIN wlyy_charge_dict e ON a.charge_type = e.charge_type " +
 | 
	
		
			
				|  |  |                 " WHERE 1=1";
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(city)){
 | 
	
		
			
				|  |  |             sql += " AND a.city_name =:city";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(hospital)){
 | 
	
		
			
				|  |  |             sql += " AND b.org_code =:hospital";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(status)){
 | 
	
		
			
				|  |  |             sql += " AND a.del =:status";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(name)){
 | 
	
		
			
				|  |  |             sql += " AND b.dept_name like:name";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql += " AND e.dept_type_code =:typeCode";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,params,page,pageSize);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, pageSize, count);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据医生ID,获取医生基础信息
 | 
	
		
			
				|  |  |      * @param doctorId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<Map<String, Object>> queryById(String doctorId) {
 | 
	
		
			
				|  |  |         Map<String,Object> params = new HashedMap();
 | 
	
		
			
				|  |  |         String sql ="SELECT " +
 | 
	
		
			
				|  |  |                 " a.NAME AS \"name\", " +
 | 
	
		
			
				|  |  |                 " a.job_title_name AS \"jobTitleName\", " +
 | 
	
		
			
				|  |  |                 " a.introduce AS \"introduce\", " +
 | 
	
		
			
				|  |  |                 " a.expertise AS \"expertise\", " +
 | 
	
		
			
				|  |  |                 " a.outpatient_type AS \"outpatientType\", " +
 | 
	
		
			
				|  |  |                 " b.dept_name AS \"deptName\", " +
 | 
	
		
			
				|  |  |                 " b.org_name AS \"orgName\", " +
 | 
	
		
			
				|  |  |                 " c.mapping_code AS \"jobNumber\", " +
 | 
	
		
			
				|  |  |                 " d.disease_name AS \"diseaseName\", " +
 | 
	
		
			
				|  |  |                 " e.req_fee AS \"money\" " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " base_doctor a " +
 | 
	
		
			
				|  |  |                 " JOIN base_doctor_hospital b ON a.id = b.doctor_code " +
 | 
	
		
			
				|  |  |                 " JOIN base_doctor_mapping c ON a.id = c.doctor " +
 | 
	
		
			
				|  |  |                 " JOIN wlyy_doctor_special_disease d ON a.id = d.doctor_code " +
 | 
	
		
			
				|  |  |                 " JOIN wlyy_charge_dict e ON a.charge_type = e.charge_type " +
 | 
	
		
			
				|  |  |                 " WHERE 1=1 ";
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(doctorId)){
 | 
	
		
			
				|  |  |             sql+=" AND a.id =:id";
 | 
	
		
			
				|  |  |             params.put("id",doctorId);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql+=" AND e.dept_type_code =:typeCode";
 | 
	
		
			
				|  |  |         params.put("typeCode",6);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, params);
 | 
	
		
			
				|  |  |         return  list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 修改医生服务配置
 | 
	
		
			
				|  |  |      * @param jsonObject
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Boolean update(JSONObject jsonObject)throws Exception{
 | 
	
		
			
				|  |  |         //取出数据
 | 
	
		
			
				|  |  |         String doctorId = jsonObject.get("doctorId").toString();
 | 
	
		
			
				|  |  |         String introduce = jsonObject.get("introduce").toString();
 | 
	
		
			
				|  |  |         String expertise = jsonObject.get("expertise").toString();
 | 
	
		
			
				|  |  |         String outpatientType = jsonObject.get("outpatientType").toString();
 | 
	
		
			
				|  |  |         String newSpecialDisease = jsonObject.get("specialDisease").toString();
 | 
	
		
			
				|  |  |         //医生简介、擅长不为空
 | 
	
		
			
				|  |  |         if (null == introduce || null == expertise){
 | 
	
		
			
				|  |  |             return false;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         baseDoctorDao.update(doctorId,introduce,expertise,outpatientType);
 | 
	
		
			
				|  |  |         //删除医生旧专病门诊,保存新专病门诊
 | 
	
		
			
				|  |  |         List<DoctorSpecialDiseaseDo> oldSpecialDisease = specialDiseaseDao.findByDoctorCode(doctorId);
 | 
	
		
			
				|  |  |         if (null != oldSpecialDisease && oldSpecialDisease.size()>0){
 | 
	
		
			
				|  |  |             specialDiseaseDao.deleteByDoctorCode(doctorId);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         DoctorSpecialDiseaseDo specialDiseaseDo = new DoctorSpecialDiseaseDo();
 | 
	
		
			
				|  |  |         String[] split = newSpecialDisease.split(",");
 | 
	
		
			
				|  |  |         for (String diseaseName : split) {
 | 
	
		
			
				|  |  |             specialDiseaseDo.setDoctorCode(doctorId);
 | 
	
		
			
				|  |  |             specialDiseaseDo.setDiseaseName(diseaseName);
 | 
	
		
			
				|  |  |             specialDiseaseDao.save(specialDiseaseDo);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return true;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 修改医生状态
 | 
	
		
			
				|  |  |      * @param doctorId
 | 
	
		
			
				|  |  |      * @param status
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void updateStatus(String doctorId,String status)throws Exception{
 | 
	
		
			
				|  |  |         baseDoctorDao.updateStatus(doctorId,status);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |