|  | @ -2,11 +2,23 @@ package com.yihu.jw.wlyy.service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.dict.dao.DictDoctorDutyDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.dict.dao.DictHospitalDeptDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.dict.DictDoctorDutyDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.dict.DictHospitalDeptDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.org.BaseOrgDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.org.dao.BaseOrgDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
	
		
			
				|  | @ -17,6 +29,7 @@ import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -43,6 +56,24 @@ public class WlyyBusinessService {
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao basePatientDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseOrgDao baseOrgDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DictHospitalDeptDao dictHospitalDeptDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorHospitalDao baseDoctorHospitalDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorRoleDao baseDoctorRoleDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DoctorMappingDao doctorMappingDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 推送系统门诊wlyy系统消息
 | 
	
		
			
				|  |  |      * @param doctor
 | 
	
	
		
			
				|  | @ -338,4 +369,186 @@ public class WlyyBusinessService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String findWlyyHospital(){
 | 
	
		
			
				|  |  |         JSONObject re = wlyyHttpService.sendWlyyMes("findWlyyHospital",null,null);
 | 
	
		
			
				|  |  |         if(re!=null){
 | 
	
		
			
				|  |  |             JSONArray hospitals = JSONArray.parseArray(re.getString("data"));
 | 
	
		
			
				|  |  |             logger.info("hospitals size:"+hospitals.size());
 | 
	
		
			
				|  |  |             if(hospitals!=null&&hospitals.size()>0){
 | 
	
		
			
				|  |  |                 for(int i=0;i<hospitals.size();i++){
 | 
	
		
			
				|  |  |                     JSONObject h = (JSONObject) hospitals.get(i);
 | 
	
		
			
				|  |  |                     String code = h.getString("code");
 | 
	
		
			
				|  |  |                     if(!baseOrgDao.existsByCode(code)){
 | 
	
		
			
				|  |  |                         BaseOrgDO org = new BaseOrgDO();
 | 
	
		
			
				|  |  |                         org.setCode(code);
 | 
	
		
			
				|  |  |                         org.setName(h.getString("name"));
 | 
	
		
			
				|  |  |                         org.setProvinceCode(h.getString("province"));
 | 
	
		
			
				|  |  |                         org.setProvinceName(h.getString("provinceName"));
 | 
	
		
			
				|  |  |                         org.setCityCode(h.getString("city"));
 | 
	
		
			
				|  |  |                         org.setCityName(h.getString("cityName"));
 | 
	
		
			
				|  |  |                         org.setTownCode(h.getString("town"));
 | 
	
		
			
				|  |  |                         org.setTownName(h.getString("townName"));
 | 
	
		
			
				|  |  |                         org.setType("1");
 | 
	
		
			
				|  |  |                         org.setWinNo("-1");
 | 
	
		
			
				|  |  |                         baseOrgDao.save(org);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return "ok";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String findWlyyDept(){
 | 
	
		
			
				|  |  |         JSONObject re = wlyyHttpService.sendWlyyMes("findWlyyDept",null,null);
 | 
	
		
			
				|  |  |         if(re!=null){
 | 
	
		
			
				|  |  |             JSONArray depts = JSONArray.parseArray(re.getString("data"));
 | 
	
		
			
				|  |  |             logger.info("depts size:"+depts.size());
 | 
	
		
			
				|  |  |             if(depts!=null&&depts.size()>0){
 | 
	
		
			
				|  |  |                 for(int i=0;i<depts.size();i++){
 | 
	
		
			
				|  |  |                     JSONObject d = (JSONObject) depts.get(i);
 | 
	
		
			
				|  |  |                     String code = d.getString("code");
 | 
	
		
			
				|  |  |                     String hospital = d.getString("hospital");
 | 
	
		
			
				|  |  |                     if(!dictHospitalDeptDao.existsByCodeAndOrgCode(code,hospital)){
 | 
	
		
			
				|  |  |                         DictHospitalDeptDO deptDO = new DictHospitalDeptDO();
 | 
	
		
			
				|  |  |                         deptDO.setCode(code);
 | 
	
		
			
				|  |  |                         deptDO.setName(d.getString("name"));
 | 
	
		
			
				|  |  |                         deptDO.setOrgCode(hospital);
 | 
	
		
			
				|  |  |                         deptDO.setConsultDeptFlag("1");
 | 
	
		
			
				|  |  |                         deptDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                         dictHospitalDeptDao.save(deptDO);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return "ok";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String findWlyyDoctor()throws Exception{
 | 
	
		
			
				|  |  |         JSONObject re = wlyyHttpService.sendWlyyMes("findWlyyDoctor",null,null);
 | 
	
		
			
				|  |  |         if(re!=null){
 | 
	
		
			
				|  |  |             JSONArray doctors = JSONArray.parseArray(re.getString("data"));
 | 
	
		
			
				|  |  |             logger.info("doctors size:"+doctors.size());
 | 
	
		
			
				|  |  |             if(doctors!=null&&doctors.size()>0){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //获取全部职称
 | 
	
		
			
				|  |  |                 List<Map<String,Object>> dutys = findDutys();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 for(int i=0;i<doctors.size();i++){
 | 
	
		
			
				|  |  |                     try {
 | 
	
		
			
				|  |  |                         JSONObject doctorJson = (JSONObject) doctors.get(i);
 | 
	
		
			
				|  |  |                         String idcard = doctorJson.getString("idcard");
 | 
	
		
			
				|  |  |                         if(StringUtils.isNotBlank(idcard)) {
 | 
	
		
			
				|  |  |                             List<BaseDoctorDO> ds = baseDoctorDao.findByIdcard(idcard);
 | 
	
		
			
				|  |  |                             if (ds != null && ds.size() > 0) {
 | 
	
		
			
				|  |  |                                 //已有账号不更新
 | 
	
		
			
				|  |  |                             } else {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 BaseDoctorDO doctor = new BaseDoctorDO();
 | 
	
		
			
				|  |  |                                 doctor.setName(doctorJson.getString("name"));
 | 
	
		
			
				|  |  |                                 doctor.setIdcard(doctorJson.getString("idcard"));
 | 
	
		
			
				|  |  |                                 doctor.setMobile(doctorJson.getString("mobile"));
 | 
	
		
			
				|  |  |                                 doctor.setSex(Integer.parseInt(IdCardUtil.getSexForIdcard_new(idcard)));
 | 
	
		
			
				|  |  |                                 doctor.setBirthday(IdCardUtil.getBirthdayForIdcard(idcard));
 | 
	
		
			
				|  |  |                                 doctor.setProvinceCode(doctorJson.getString("province"));
 | 
	
		
			
				|  |  |                                 doctor.setProvinceName(doctorJson.getString("provinceName"));
 | 
	
		
			
				|  |  |                                 doctor.setTownCode(doctorJson.getString("town"));
 | 
	
		
			
				|  |  |                                 doctor.setTownName(doctorJson.getString("townName"));
 | 
	
		
			
				|  |  |                                 doctor.setCityCode(doctorJson.getString("city"));
 | 
	
		
			
				|  |  |                                 doctor.setCityName(doctorJson.getString("cityName"));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 //认证信息设置
 | 
	
		
			
				|  |  |                                 String salt = randomString(5);
 | 
	
		
			
				|  |  |                                 String pw = idcard.substring(idcard.length() - 6);
 | 
	
		
			
				|  |  |                                 doctor.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
 | 
	
		
			
				|  |  |                                 doctor.setDel("1");
 | 
	
		
			
				|  |  |                                 doctor.setEnabled(1);
 | 
	
		
			
				|  |  |                                 doctor.setLocked(0);
 | 
	
		
			
				|  |  |                                 doctor.setCreateTime(new Date());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 String jobName = doctorJson.getString("jobName");
 | 
	
		
			
				|  |  |                                 doctor.setJobTitleCode(getDutysCode(dutys, jobName));
 | 
	
		
			
				|  |  |                                 doctor.setJobTitleName(jobName);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 BaseDoctorDO temp = baseDoctorDao.save(doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 //机构信息部门信息
 | 
	
		
			
				|  |  |                                 BaseDoctorHospitalDO hospitalDO = new BaseDoctorHospitalDO();
 | 
	
		
			
				|  |  |                                 hospitalDO.setDoctorCode(temp.getId());
 | 
	
		
			
				|  |  |                                 hospitalDO.setOrgCode(doctorJson.getString("hospital"));
 | 
	
		
			
				|  |  |                                 hospitalDO.setOrgName(doctorJson.getString("hospitalName"));
 | 
	
		
			
				|  |  |                                 hospitalDO.setDeptCode(doctorJson.getString("dept"));
 | 
	
		
			
				|  |  |                                 hospitalDO.setDeptName(doctorJson.getString("deptName"));
 | 
	
		
			
				|  |  |                                 hospitalDO.setDel("1");
 | 
	
		
			
				|  |  |                                 baseDoctorHospitalDao.save(hospitalDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 Integer level = doctorJson.getInteger("level");
 | 
	
		
			
				|  |  |                                 BaseDoctorRoleDO role = new BaseDoctorRoleDO();
 | 
	
		
			
				|  |  |                                 if (level != null && level == 1) {
 | 
	
		
			
				|  |  |                                     role.setRoleCode("specialist");
 | 
	
		
			
				|  |  |                                 } else {
 | 
	
		
			
				|  |  |                                     role.setRoleCode("generalDoctor");
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                                 role.setDoctorCode(temp.getId());
 | 
	
		
			
				|  |  |                                 role.setRoleCode("generalDoctor");
 | 
	
		
			
				|  |  |                                 baseDoctorRoleDao.save(role);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 DoctorMappingDO mappingDO = new DoctorMappingDO();
 | 
	
		
			
				|  |  |                                 mappingDO.setIdcard(idcard);
 | 
	
		
			
				|  |  |                                 mappingDO.setDoctor(temp.getId());
 | 
	
		
			
				|  |  |                                 mappingDO.setOrgCode(doctorJson.getString("hospital"));
 | 
	
		
			
				|  |  |                                 mappingDO.setOrgName(doctorJson.getString("hospitalName"));
 | 
	
		
			
				|  |  |                                 mappingDO.setMappingCode(temp.getId());
 | 
	
		
			
				|  |  |                                 mappingDO.setDoctorName(temp.getName());
 | 
	
		
			
				|  |  |                                 mappingDO.setMappingDeptName(temp.getName());
 | 
	
		
			
				|  |  |                                 mappingDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                                 doctorMappingDao.save(mappingDO);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     }catch (Exception e){
 | 
	
		
			
				|  |  |                         logger.info("data error");
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return "ok";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取全部职称
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> findDutys(){
 | 
	
		
			
				|  |  |         String sql = "select code,name from dict_doctor_duty";
 | 
	
		
			
				|  |  |         return jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String getDutysCode(List<Map<String,Object>> dutys,String name){
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(name)){
 | 
	
		
			
				|  |  |             for(Map<String,Object> d:dutys){
 | 
	
		
			
				|  |  |                 String duty = (String)d.get("name");
 | 
	
		
			
				|  |  |                 if(name.equals(duty)){
 | 
	
		
			
				|  |  |                     return (String)d.get("code");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return "";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String randomString(int length) {
 | 
	
		
			
				|  |  |         String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 | 
	
		
			
				|  |  |         StringBuffer buffer = new StringBuffer();
 | 
	
		
			
				|  |  |         Random random = new Random();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for(int i = 0; i < length; ++i) {
 | 
	
		
			
				|  |  |             int pos = random.nextInt(str.length());
 | 
	
		
			
				|  |  |             buffer.append(str.charAt(pos));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return buffer.toString();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |