|  | @ -6,6 +6,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.enums.SystemDictEnum;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.service.org.BaseOrgService;
 | 
	
		
			
				|  |  | import com.yihu.jw.dict.dao.DictHospitalDeptDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.org.dao.BaseOrgDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.StringUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.hibernate.HibenateUtils;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
	
		
			
				|  | @ -13,9 +19,8 @@ import org.springframework.data.domain.Pageable;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.dict.DictHospitalDeptDO;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * 
 | 
	
	
		
			
				|  | @ -40,6 +45,12 @@ public class DictHospitalDeptService extends BaseJpaService<DictHospitalDeptDO,
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseOrgService baseOrgService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseOrgDao baseOrgDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private HibenateUtils hibenateUtils;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorHospitalDao baseDoctorHospitalDao;
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查询某一租户下的医院科室字典信息,如果saadId为空表示当前用户角色为超级管理员,超级管理员可以看到所有数据
 | 
	
		
			
				|  |  |      * @param saasId
 | 
	
	
		
			
				|  | @ -102,5 +113,114 @@ public class DictHospitalDeptService extends BaseJpaService<DictHospitalDeptDO,
 | 
	
		
			
				|  |  |     public void saveBatch(List<DictHospitalDeptDO> dictHospitalDeptDOS)throws Exception{
 | 
	
		
			
				|  |  |         dictHospitalDeptDao.save(dictHospitalDeptDOS);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查询单个科室信息 带医生
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Map findSingleDept(Integer id,Integer page,Integer pageSize){
 | 
	
		
			
				|  |  |         Map<String ,Object> returnMap = new HashMap<>();
 | 
	
		
			
				|  |  |         DictHospitalDeptDO dictHospitalDeptDO = dictHospitalDeptDao.findOne(id);
 | 
	
		
			
				|  |  |         if (dictHospitalDeptDO!=null){
 | 
	
		
			
				|  |  |             String sql = "select b.name as \"name\",b.id as \"id\"" +
 | 
	
		
			
				|  |  |                     " b.sex as \"sex\"," +
 | 
	
		
			
				|  |  |                     " b.idcard as \"idcard\"," +
 | 
	
		
			
				|  |  |                     " b.mobile as \"mobile\"," +
 | 
	
		
			
				|  |  |                     " b.job_title_code as \"jobTitleCode\"," +
 | 
	
		
			
				|  |  |                     " b.job_title_name as \"jobTitleName\"" +
 | 
	
		
			
				|  |  |                     " from base_doctor_hospital d " +
 | 
	
		
			
				|  |  |                     " left join dict_hospital_dept p on d.dept_code = p.code" +
 | 
	
		
			
				|  |  |                     " left join base_doctor b on d.doctor_code = b.id" +
 | 
	
		
			
				|  |  |                     " where b p.dept_code = '"+dictHospitalDeptDO.getCode()+"'";
 | 
	
		
			
				|  |  |             List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
 | 
	
		
			
				|  |  |             List<Map<String,Object>> listCount = hibenateUtils.createSQLQuery(sql);
 | 
	
		
			
				|  |  |             for (Map<String,Object> map:list){
 | 
	
		
			
				|  |  |                 if (map.get("idcard")!=null){
 | 
	
		
			
				|  |  |                     map.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard").toString()));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             returnMap.put("doctorList",list);
 | 
	
		
			
				|  |  |             if (listCount!=null){
 | 
	
		
			
				|  |  |                 returnMap.put("doctorListCount",listCount.size());
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 returnMap.put("doctorListCount",0);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         returnMap.put("dept",dictHospitalDeptDO);
 | 
	
		
			
				|  |  |         return returnMap;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 新增科室
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public DictHospitalDeptDO addDept(String jsonData,String doctorIds){
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             DictHospitalDeptDO dictHospitalDeptDO = objectMapper.readValue(jsonData,DictHospitalDeptDO.class);
 | 
	
		
			
				|  |  |             dictHospitalDeptDao.save(dictHospitalDeptDO);
 | 
	
		
			
				|  |  |             if (StringUtils.isNotBlank(doctorIds)){
 | 
	
		
			
				|  |  |                 if (doctorIds.contains(",")){
 | 
	
		
			
				|  |  |                     String[] doctorId = doctorIds.split(",");
 | 
	
		
			
				|  |  |                     for (int i = 0;i<doctorId.length;i++){
 | 
	
		
			
				|  |  |                         BaseDoctorHospitalDO baseDoctorHospitalDO = new BaseDoctorHospitalDO();
 | 
	
		
			
				|  |  |                         baseDoctorHospitalDO.setDoctorCode(doctorId[i]);
 | 
	
		
			
				|  |  |                         baseDoctorHospitalDO.setDeptName(dictHospitalDeptDO.getName());
 | 
	
		
			
				|  |  |                         baseDoctorHospitalDO.setDeptCode(dictHospitalDeptDO.getCode());
 | 
	
		
			
				|  |  |                         baseDoctorHospitalDO.setOrgCode(dictHospitalDeptDO.getOrgCode());
 | 
	
		
			
				|  |  |                         baseDoctorHospitalDO.setOrgName(dictHospitalDeptDO.getOrgName());
 | 
	
		
			
				|  |  |                         baseDoctorHospitalDO.setDel("1");
 | 
	
		
			
				|  |  |                         baseDoctorHospitalDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                         baseDoctorHospitalDao.save(baseDoctorHospitalDO);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     BaseDoctorHospitalDO baseDoctorHospitalDO = new BaseDoctorHospitalDO();
 | 
	
		
			
				|  |  |                     baseDoctorHospitalDO.setDoctorCode(doctorIds);
 | 
	
		
			
				|  |  |                     baseDoctorHospitalDO.setDeptName(dictHospitalDeptDO.getName());
 | 
	
		
			
				|  |  |                     baseDoctorHospitalDO.setDeptCode(dictHospitalDeptDO.getCode());
 | 
	
		
			
				|  |  |                     baseDoctorHospitalDO.setOrgCode(dictHospitalDeptDO.getOrgCode());
 | 
	
		
			
				|  |  |                     baseDoctorHospitalDO.setOrgName(dictHospitalDeptDO.getOrgName());
 | 
	
		
			
				|  |  |                     baseDoctorHospitalDO.setDel("1");
 | 
	
		
			
				|  |  |                     baseDoctorHospitalDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                     baseDoctorHospitalDao.save(baseDoctorHospitalDO);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             return dictHospitalDeptDO;
 | 
	
		
			
				|  |  |         } catch (IOException e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |    public void saveDeptDoctor(String doctorIds ,String deptCode){
 | 
	
		
			
				|  |  |        DictHospitalDeptDO dictHospitalDeptDO = dictHospitalDeptDao.findByCode(deptCode);
 | 
	
		
			
				|  |  |        if (dictHospitalDeptDO!=null){
 | 
	
		
			
				|  |  |            if (StringUtils.isNotBlank(doctorIds)) {
 | 
	
		
			
				|  |  |                if (doctorIds.contains(",")) {
 | 
	
		
			
				|  |  |                    String[] doctorId = doctorIds.split(",");
 | 
	
		
			
				|  |  |                    for (int i = 0; i < doctorId.length; i++) {
 | 
	
		
			
				|  |  |                        BaseDoctorHospitalDO baseDoctorHospitalDO = new BaseDoctorHospitalDO();
 | 
	
		
			
				|  |  |                        baseDoctorHospitalDO.setDoctorCode(doctorId[i]);
 | 
	
		
			
				|  |  |                        baseDoctorHospitalDO.setDeptName(dictHospitalDeptDO.getName());
 | 
	
		
			
				|  |  |                        baseDoctorHospitalDO.setDeptCode(dictHospitalDeptDO.getCode());
 | 
	
		
			
				|  |  |                        baseDoctorHospitalDO.setOrgCode(dictHospitalDeptDO.getOrgCode());
 | 
	
		
			
				|  |  |                        baseDoctorHospitalDO.setOrgName(dictHospitalDeptDO.getOrgName());
 | 
	
		
			
				|  |  |                        baseDoctorHospitalDO.setDel("1");
 | 
	
		
			
				|  |  |                        baseDoctorHospitalDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                        baseDoctorHospitalDao.save(baseDoctorHospitalDO);
 | 
	
		
			
				|  |  |                    }
 | 
	
		
			
				|  |  |                } else {
 | 
	
		
			
				|  |  |                    BaseDoctorHospitalDO baseDoctorHospitalDO = new BaseDoctorHospitalDO();
 | 
	
		
			
				|  |  |                    baseDoctorHospitalDO.setDoctorCode(doctorIds);
 | 
	
		
			
				|  |  |                    baseDoctorHospitalDO.setDeptName(dictHospitalDeptDO.getName());
 | 
	
		
			
				|  |  |                    baseDoctorHospitalDO.setDeptCode(dictHospitalDeptDO.getCode());
 | 
	
		
			
				|  |  |                    baseDoctorHospitalDO.setOrgCode(dictHospitalDeptDO.getOrgCode());
 | 
	
		
			
				|  |  |                    baseDoctorHospitalDO.setOrgName(dictHospitalDeptDO.getOrgName());
 | 
	
		
			
				|  |  |                    baseDoctorHospitalDO.setDel("1");
 | 
	
		
			
				|  |  |                    baseDoctorHospitalDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                    baseDoctorHospitalDao.save(baseDoctorHospitalDO);
 | 
	
		
			
				|  |  |                }
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    public void removeDeptDoctor(){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | }
 |