Browse Source

测试环境

Trick 5 years ago
parent
commit
3480a9bd3b
15 changed files with 875 additions and 484 deletions
  1. 8 1
      business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorRoleDao.java
  2. 355 3
      business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorInfoService.java
  3. 396 395
      business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorService.java
  4. 49 7
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java
  5. 30 30
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/doctor/BaseDoctorRoleDao.java
  6. 8 1
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/doctor/BaseDoctorRoleInfoDao.java
  7. 1 19
      svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorRoleInfoService.java
  8. 2 1
      svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorRoleService.java
  9. 0 10
      svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorService.java
  10. 1 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/excelImport/BaseDoctorExcelDOReader.java
  11. 1 3
      svr/svr-base/src/main/java/com/yihu/jw/base/service/team/BaseTeamMemberService.java
  12. 13 3
      svr/svr-base/src/main/resources/application.yml
  13. 2 6
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/config/DoctorServiceEndPoint.java
  14. 6 4
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/patient/PatientNoLoginEndPoint.java
  15. 3 1
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java

+ 8 - 1
business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorRoleDao.java

@ -1,10 +1,13 @@
package com.yihu.jw.doctor.dao;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleInfoDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import java.util.Set;
/**
@ -20,7 +23,11 @@ import java.util.List;
 * @since 1.
 */
public interface BaseDoctorRoleDao extends PagingAndSortingRepository<BaseDoctorRoleDO, Integer>, JpaSpecificationExecutor<BaseDoctorRoleDO>  {
    
    List<BaseDoctorRoleDO> findByRoleCode(String roleCode);
    @Query("select id from BaseDoctorRoleDO where doctorCode = ?1")
    Set<Object> findIdListByDoctorCode(String doctorCode);
    List<BaseDoctorRoleDO> findByDoctorCode(String doctorCode);
}

+ 355 - 3
business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorInfoService.java

@ -1,19 +1,371 @@
package com.yihu.jw.doctor.service;
import com.alibaba.fastjson.JSON;
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.DoctorSpecialDiseaseDo;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
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.util.date.DateUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.utils.security.MD5;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
@Service
public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoctorDao> {
    private static Logger logger = LoggerFactory.getLogger(BaseDoctorInfoService.class);
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private DoctorSpecialDiseaseDao specialDiseaseDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    /**
     * 查询医生信息分页列表.
     * @param city
     * @param hospital
     * @param status
     * @param name
     * @param page
     * @param pageSize
     */
    public Envelop queryList(String city, String hospital, String status, String name, String type, String typeCode, String dept, 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 " +
                " LEFT JOIN (SELECT * FROM wlyy_charge_dict t WHERE t.dept_type_code ='6') e ON a.charge_type = e.charge_type " +
                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
                " 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 (a.name like:name or b.dept_name like:name)";
            params.put("name",name);
        }
        if (StringUtils.isNotBlank(type)){
            type = "%"+type+"%";
            sqlTotal += " AND a.outpatient_type like:type";
            params.put("type",type);
        }
        if(StringUtils.isNotBlank(typeCode)){
            sqlTotal += " AND e.dept_type_code =:typeCode";
            params.put("typeCode",typeCode);
        }
        if(StringUtils.isNotBlank(dept)){
            sqlTotal += " AND b.dept_code =:dept";
            params.put("dept",dept);
        }
        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 " +
                " LEFT JOIN (SELECT * FROM wlyy_charge_dict t WHERE t.dept_type_code ='6') e ON a.charge_type = e.charge_type " +
                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
                " 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 (a.name like:name or b.dept_name like:name)";
        }
        if (StringUtils.isNotBlank(type)){
            sql += " AND a.outpatient_type like:type";
        }
        if(StringUtils.isNotBlank(typeCode)){
            sql += " AND e.dept_type_code =:typeCode";
        }
        if(StringUtils.isNotBlank(dept)){
            sql += " AND b.dept_code =:dept";
        }
        logger.info("queryList sql:"+sql);
        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 Object queryById(String doctorId,String typeCode) {
        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.photo AS \"photo\", " +
                " 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\", " +
                " d.disease_code AS \"diseaseCode\", " +
                " e.req_fee AS \"money\" " +
                " FROM " +
                " base_doctor a " +
                " LEFT JOIN base_doctor_hospital b ON a.id = b.doctor_code " +
                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
                " LEFT JOIN wlyy_doctor_special_disease d ON a.id = d.doctor_code " +
                " LEFT 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);
        }
        if(StringUtils.isNotBlank(typeCode)){
            sql+=" AND e.dept_type_code =:typeCode";
            params.put("typeCode",typeCode);
        }
        logger.info("queryById sql:"+sql);
        List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, params);
        StringBuilder disease = new StringBuilder();
        StringBuilder code = new StringBuilder();
        if (null != list && list.size() > 0){
            if (list.size() == 1){
                return  list.get(0);
            }else {
                for (int i=0;i<list.size();i++){
                    if (i == 0 ){
                        disease.append(list.get(i).get("diseaseName"));
                        code.append(list.get(i).get("diseaseCode"));
                    }else {
                        disease.append(","+list.get(i).get("diseaseName"));
                        code.append(","+list.get(i).get("diseaseCode"));
                    }
                }
                list.get(0).put("diseaseName",disease);
                list.get(0).put("diseaseCode",code);
                return  list.get(0);
            }
        }
        return null;
    }
    public Boolean updateList(JSONArray jsonArray){
        if(jsonArray!=null&&jsonArray.size()>0){
            for(int i=0;i<jsonArray.size();i++){
                JSONObject doctor = jsonArray.getJSONObject(i);
                try {
                    updateInfo(doctor);
                }catch (Exception e){
                    logger.info("update doctor error:"+e.toString());
                }
            }
        }
        return true;
    }
    /**
     * 修改医生服务配置
     * @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 photo = jsonObject.get("photo").toString();
        String outpatientType = jsonObject.get("outpatientType").toString();
        String newSpecialDisease = jsonObject.get("specialDisease").toString();
        String newSpecialDiseaseCode = jsonObject.get("specialDiseaseCode").toString();
        baseDoctorDao.update(doctorId,introduce,expertise,photo,outpatientType);
        //删除医生旧专病门诊,保存新专病门诊
        Map<String,Object> params = new HashedMap();
        String sqlTotal ="SELECT " +
                " COUNT(1) AS \"total\" " +
                " FROM " +
                " wlyy_doctor_special_disease a " +
                " WHERE " +
                " 1 = 1";
        sqlTotal += " AND a.doctor_code =:doctorId";
        params.put("doctorId",doctorId);
        Long count = 0L;
        List<Map<String, Object>> total = hibenateUtils.createSQLQuery(sqlTotal, params);
        //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
        count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        if (count > 0){
            specialDiseaseDao.deleteByDoctorCode(doctorId);
        }
        if(StringUtils.isNotBlank(newSpecialDisease) && StringUtils.isNotBlank(newSpecialDiseaseCode)){
            String[] split = newSpecialDisease.split(",");
            String[] splitCode = newSpecialDiseaseCode.split(",");
            specialDiseaseDao.deleteByDoctorCode(doctorId);
            for (int i=0;i<split.length;i++ ){
                DoctorSpecialDiseaseDo specialDiseaseDo = new DoctorSpecialDiseaseDo();
                specialDiseaseDo.setDoctorCode(doctorId);
                specialDiseaseDo.setDiseaseName(split[i]);
                specialDiseaseDo.setDiseaseCode(splitCode[i]);
                specialDiseaseDao.save(specialDiseaseDo);
            }
        }
        return true;
    }
    public Boolean updateInfo(JSONObject jsonObject)throws Exception{
        //取出数据
        String doctorId = jsonObject.get("doctorId").toString();
        String outpatientType = jsonObject.get("outpatientType").toString();
        logger.info("doctor:"+doctorId+" outpatientType:"+outpatientType);
        BaseDoctorDO doctorDO = baseDoctorDao.findOne(doctorId);
        doctorDO.setOutpatientType(outpatientType);
        baseDoctorDao.save(doctorDO);
        return true;
    }
    /**
     * 修改医生状态
     * @param doctorId
     * @param status
     */
    public void updateStatus(String doctorId,String status)throws Exception{
        baseDoctorDao.updateStatus(doctorId,status);
    }
    public Boolean updateDoctorPw(String id,String pw,String orgPw){
        BaseDoctorDO doctorDO = baseDoctorDao.findOne(id);
        String orgPwMd5 = MD5.md5Hex(orgPw + "{" + doctorDO.getSalt() + "}");
        if(!orgPwMd5.equals(doctorDO.getPassword())){
            return false;
        }
        //认证信息设置
        String salt = randomString(5);
        doctorDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
        doctorDO.setSalt(salt);
        baseDoctorDao.save(doctorDO);
        //设置更新时间
        saveDoctorPwlimitDate(id);
        return true;
    }
    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();
    }
    public com.alibaba.fastjson.JSONObject findDoctorPwlimitDate(String doctor){
        String key = "hlwyy:authPw:doctor:" + doctor;
        String authPw = redisTemplate.opsForValue().get(key);
        com.alibaba.fastjson.JSONObject valueJson = null;
        if(StringUtils.isNotBlank(authPw)){
            WlyyHospitalSysDictDO wlyyHospitalSysDictDO = wlyyHospitalSysDictDao.findById("pwOverDue");
            String code[] = wlyyHospitalSysDictDO.getDictCode().split(",");
            Integer maxDateInt = Integer.parseInt(code[0]);
            Integer remainDateInt = Integer.parseInt(code[1]);
            valueJson = JSON.parseObject(authPw);
            Long updateTimeLong = valueJson.getLong("updateTime");
            Date updateTime = new Date();
            updateTime.setTime(updateTimeLong);
            Date maxDate = DateUtil.getPreDays(updateTime,maxDateInt);
            Long betweenDate = (maxDate.getTime() - new Date().getTime())/(60*60*24*1000);
            valueJson.put("betweenDate",betweenDate);
            if(betweenDate<remainDateInt){
                valueJson.put("remaind",true);
            }else {
                valueJson.put("remaind",false);
            }
        }else {
            valueJson = new com.alibaba.fastjson.JSONObject();
            valueJson.put("isChanged",false);
        }
        return valueJson;
    }
    // 基于医生ID,获取医生基础信息
    public BaseDoctorDO getDoctorByCode(String id) {
        return baseDoctorDao.findById(id);
    public boolean saveDoctorPwlimitDate(String doctor){
        String key = "hlwyy:authPw:doctor:" + doctor;
        com.alibaba.fastjson.JSONObject valueJson = new com.alibaba.fastjson.JSONObject();
        valueJson.put("updateTime",new Date().getTime());
        valueJson.put("isChanged",true);
        redisTemplate.opsForValue().set(key,valueJson.toJSONString());
        return true;
    }
}

+ 396 - 395
business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorService.java

@ -1,398 +1,399 @@
package com.yihu.jw.doctor.service;
import com.alibaba.fastjson.JSON;
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.DoctorSpecialDiseaseDo;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
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.util.date.DateUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.utils.security.MD5;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
@Service
public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDao> {
    private static Logger logger = LoggerFactory.getLogger(BaseDoctorService.class);
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private DoctorSpecialDiseaseDao specialDiseaseDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    /**
     * 查询医生信息分页列表.
     * @param city
     * @param hospital
     * @param status
     * @param name
     * @param page
     * @param pageSize
     */
    public Envelop queryList(String city, String hospital, String status, String name, String type,String typeCode,String dept, 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 " +
                " LEFT JOIN (SELECT * FROM wlyy_charge_dict t WHERE t.dept_type_code ='6') e ON a.charge_type = e.charge_type " +
                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
                " 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 (a.name like:name or b.dept_name like:name)";
            params.put("name",name);
        }
        if (StringUtils.isNotBlank(type)){
            type = "%"+type+"%";
            sqlTotal += " AND a.outpatient_type like:type";
            params.put("type",type);
        }
        if(StringUtils.isNotBlank(typeCode)){
            sqlTotal += " AND e.dept_type_code =:typeCode";
            params.put("typeCode",typeCode);
        }
        if(StringUtils.isNotBlank(dept)){
            sqlTotal += " AND b.dept_code =:dept";
            params.put("dept",dept);
        }
        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 " +
                " LEFT JOIN (SELECT * FROM wlyy_charge_dict t WHERE t.dept_type_code ='6') e ON a.charge_type = e.charge_type " +
                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
                " 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 (a.name like:name or b.dept_name like:name)";
        }
        if (StringUtils.isNotBlank(type)){
            sql += " AND a.outpatient_type like:type";
        }
        if(StringUtils.isNotBlank(typeCode)){
            sql += " AND e.dept_type_code =:typeCode";
        }
        if(StringUtils.isNotBlank(dept)){
            sql += " AND b.dept_code =:dept";
        }
        logger.info("queryList sql:"+sql);
        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 Object queryById(String doctorId,String typeCode) {
        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.photo AS \"photo\", " +
                " 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\", " +
                " d.disease_code AS \"diseaseCode\", " +
                " e.req_fee AS \"money\" " +
                " FROM " +
                " base_doctor a " +
                " LEFT JOIN base_doctor_hospital b ON a.id = b.doctor_code " +
                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
                " LEFT JOIN wlyy_doctor_special_disease d ON a.id = d.doctor_code " +
                " LEFT 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);
        }
        if(StringUtils.isNotBlank(typeCode)){
            sql+=" AND e.dept_type_code =:typeCode";
            params.put("typeCode",typeCode);
        }
        logger.info("queryById sql:"+sql);
        List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, params);
        StringBuilder disease = new StringBuilder();
        StringBuilder code = new StringBuilder();
        if (null != list && list.size() > 0){
            if (list.size() == 1){
                return  list.get(0);
            }else {
                for (int i=0;i<list.size();i++){
                    if (i == 0 ){
                        disease.append(list.get(i).get("diseaseName"));
                        code.append(list.get(i).get("diseaseCode"));
                    }else {
                        disease.append(","+list.get(i).get("diseaseName"));
                        code.append(","+list.get(i).get("diseaseCode"));
                    }
                }
                list.get(0).put("diseaseName",disease);
                list.get(0).put("diseaseCode",code);
                return  list.get(0);
            }
        }
        return null;
    }
    public Boolean updateList(JSONArray jsonArray){
        if(jsonArray!=null&&jsonArray.size()>0){
            for(int i=0;i<jsonArray.size();i++){
                JSONObject doctor = jsonArray.getJSONObject(i);
                try {
                    updateInfo(doctor);
                }catch (Exception e){
                    logger.info("update doctor error:"+e.toString());
                }
            }
        }
        return true;
    }
    /**
     * 修改医生服务配置
     * @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 photo = jsonObject.get("photo").toString();
        String outpatientType = jsonObject.get("outpatientType").toString();
        String newSpecialDisease = jsonObject.get("specialDisease").toString();
        String newSpecialDiseaseCode = jsonObject.get("specialDiseaseCode").toString();
        baseDoctorDao.update(doctorId,introduce,expertise,photo,outpatientType);
        //删除医生旧专病门诊,保存新专病门诊
        Map<String,Object> params = new HashedMap();
        String sqlTotal ="SELECT " +
                " COUNT(1) AS \"total\" " +
                " FROM " +
                " wlyy_doctor_special_disease a " +
                " WHERE " +
                " 1 = 1";
        sqlTotal += " AND a.doctor_code =:doctorId";
        params.put("doctorId",doctorId);
        Long count = 0L;
        List<Map<String, Object>> total = hibenateUtils.createSQLQuery(sqlTotal, params);
        //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
        count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        if (count > 0){
            specialDiseaseDao.deleteByDoctorCode(doctorId);
        }
        if(StringUtils.isNotBlank(newSpecialDisease) && StringUtils.isNotBlank(newSpecialDiseaseCode)){
            String[] split = newSpecialDisease.split(",");
            String[] splitCode = newSpecialDiseaseCode.split(",");
            specialDiseaseDao.deleteByDoctorCode(doctorId);
            for (int i=0;i<split.length;i++ ){
                DoctorSpecialDiseaseDo specialDiseaseDo = new DoctorSpecialDiseaseDo();
                specialDiseaseDo.setDoctorCode(doctorId);
                specialDiseaseDo.setDiseaseName(split[i]);
                specialDiseaseDo.setDiseaseCode(splitCode[i]);
                specialDiseaseDao.save(specialDiseaseDo);
            }
        }
        return true;
    }
    public Boolean updateInfo(JSONObject jsonObject)throws Exception{
        //取出数据
        String doctorId = jsonObject.get("doctorId").toString();
        String outpatientType = jsonObject.get("outpatientType").toString();
        logger.info("doctor:"+doctorId+" outpatientType:"+outpatientType);
        BaseDoctorDO doctorDO = baseDoctorDao.findOne(doctorId);
        doctorDO.setOutpatientType(outpatientType);
        baseDoctorDao.save(doctorDO);
        return true;
    }
    /**
     * 修改医生状态
     * @param doctorId
     * @param status
     */
    public void updateStatus(String doctorId,String status)throws Exception{
        baseDoctorDao.updateStatus(doctorId,status);
    }
    public Boolean updateDoctorPw(String id,String pw,String orgPw){
        BaseDoctorDO doctorDO = baseDoctorDao.findOne(id);
        String orgPwMd5 = MD5.md5Hex(orgPw + "{" + doctorDO.getSalt() + "}");
        if(!orgPwMd5.equals(doctorDO.getPassword())){
            return false;
        }
        //认证信息设置
        String salt = randomString(5);
        doctorDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
        doctorDO.setSalt(salt);
        baseDoctorDao.save(doctorDO);
        //设置更新时间
        saveDoctorPwlimitDate(id);
        return true;
    }
    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();
    }
    public com.alibaba.fastjson.JSONObject findDoctorPwlimitDate(String doctor){
        String key = "hlwyy:authPw:doctor:" + doctor;
        String authPw = redisTemplate.opsForValue().get(key);
        com.alibaba.fastjson.JSONObject valueJson = null;
        if(StringUtils.isNotBlank(authPw)){
            WlyyHospitalSysDictDO wlyyHospitalSysDictDO = wlyyHospitalSysDictDao.findById("pwOverDue");
            String code[] = wlyyHospitalSysDictDO.getDictCode().split(",");
            Integer maxDateInt = Integer.parseInt(code[0]);
            Integer remainDateInt = Integer.parseInt(code[1]);
            valueJson = JSON.parseObject(authPw);
            Long updateTimeLong = valueJson.getLong("updateTime");
            Date updateTime = new Date();
            updateTime.setTime(updateTimeLong);
            Date maxDate = DateUtil.getPreDays(updateTime,maxDateInt);
            Long betweenDate = (maxDate.getTime() - new Date().getTime())/(60*60*24*1000);
            valueJson.put("betweenDate",betweenDate);
            if(betweenDate<remainDateInt){
                valueJson.put("remaind",true);
            }else {
                valueJson.put("remaind",false);
            }
        }else {
            valueJson = new com.alibaba.fastjson.JSONObject();
            valueJson.put("isChanged",false);
        }
        return valueJson;
    }
    public boolean saveDoctorPwlimitDate(String doctor){
        String key = "hlwyy:authPw:doctor:" + doctor;
        com.alibaba.fastjson.JSONObject valueJson = new com.alibaba.fastjson.JSONObject();
        valueJson.put("updateTime",new Date().getTime());
        valueJson.put("isChanged",true);
        redisTemplate.opsForValue().set(key,valueJson.toJSONString());
        return true;
    }
//    public static void main(String ag[]){
//        long betweenDate = (DateUtil.strToDate("2020-04-11","yyyy-MM-dd").getTime() - new Date().getTime())/(60*60*24*1000);
//        System.out.println(betweenDate);
//package com.yihu.jw.doctor.service;
//
//import com.alibaba.fastjson.JSON;
//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.DoctorSpecialDiseaseDo;
//import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
//import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
//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.util.date.DateUtil;
//import com.yihu.jw.utils.hibernate.HibenateUtils;
//import com.yihu.mysql.query.BaseJpaService;
//import com.yihu.utils.security.MD5;
//import net.sf.json.JSONArray;
//import net.sf.json.JSONObject;
//import org.apache.commons.collections.map.HashedMap;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.stereotype.Service;
//
//import java.util.Date;
//import java.util.List;
//import java.util.Map;
//import java.util.Random;
//
//@Service
//public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDao> {
//
//    private static Logger logger = LoggerFactory.getLogger(BaseDoctorService.class);
//
//
//    @Autowired
//    private BaseDoctorDao baseDoctorDao;
//    @Autowired
//    private DoctorSpecialDiseaseDao specialDiseaseDao;
//    @Autowired
//    private JdbcTemplate jdbcTemplate;
//    @Autowired
//    private HibenateUtils hibenateUtils;
//    @Autowired
//    private StringRedisTemplate redisTemplate;
//    @Autowired
//    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
//
//
//    /**
//     * 查询医生信息分页列表.
//     * @param city
//     * @param hospital
//     * @param status
//     * @param name
//     * @param page
//     * @param pageSize
//     */
//    public Envelop queryList(String city, String hospital, String status, String name, String type,String typeCode,String dept, 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 " +
//                " LEFT JOIN (SELECT * FROM wlyy_charge_dict t WHERE t.dept_type_code ='6') e ON a.charge_type = e.charge_type " +
//                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
//                " 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 (a.name like:name or b.dept_name like:name)";
//            params.put("name",name);
//        }
//        if (StringUtils.isNotBlank(type)){
//            type = "%"+type+"%";
//            sqlTotal += " AND a.outpatient_type like:type";
//            params.put("type",type);
//        }
//        if(StringUtils.isNotBlank(typeCode)){
//            sqlTotal += " AND e.dept_type_code =:typeCode";
//            params.put("typeCode",typeCode);
//        }
//        if(StringUtils.isNotBlank(dept)){
//            sqlTotal += " AND b.dept_code =:dept";
//            params.put("dept",dept);
//        }
//
//        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 " +
//                " LEFT JOIN (SELECT * FROM wlyy_charge_dict t WHERE t.dept_type_code ='6') e ON a.charge_type = e.charge_type " +
//                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
//                " 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 (a.name like:name or b.dept_name like:name)";
//        }
//        if (StringUtils.isNotBlank(type)){
//            sql += " AND a.outpatient_type like:type";
//        }
//        if(StringUtils.isNotBlank(typeCode)){
//            sql += " AND e.dept_type_code =:typeCode";
//        }
//        if(StringUtils.isNotBlank(dept)){
//            sql += " AND b.dept_code =:dept";
//        }
//
//        logger.info("queryList sql:"+sql);
//
//        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,params,page,pageSize);
//
//        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, pageSize, count);
//    }
//    public static void main(String ag[]){
//        String str = "[ " +
//                "{ " +
//                "\"title\":\"Java 开发\", " +
//                "\"edition\":3, " +
//                "\"author\":[\"smith\",\"张三\",\"李四\"] " +
//                "}, " +
//                "{ " +
//                "\"title\":\"Web 开发\", " +
//                "\"edition\":3, " +
//                "\"author\":[\"Allen\",\"王五\",\"赵六\"] " +
//                "} " +
//                "]";
//        JSONArray json = JSONArray.fromObject(str);
//        for(int i=0;i<json.size();i++){
//            JSONObject doctor = json.getJSONObject(i);
//            doctor.getString("doctor");
//
//    /**
//     * 根据医生ID,获取医生基础信息
//     * @param doctorId
//     * @return
//     */
//    public Object queryById(String doctorId,String typeCode) {
//        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.photo AS \"photo\", " +
//                " 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\", " +
//                " d.disease_code AS \"diseaseCode\", " +
//                " e.req_fee AS \"money\" " +
//                " FROM " +
//                " base_doctor a " +
//                " LEFT JOIN base_doctor_hospital b ON a.id = b.doctor_code " +
//                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
//                " LEFT JOIN wlyy_doctor_special_disease d ON a.id = d.doctor_code " +
//                " LEFT 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);
//        }
//        if(StringUtils.isNotBlank(typeCode)){
//            sql+=" AND e.dept_type_code =:typeCode";
//            params.put("typeCode",typeCode);
//        }
//
//        logger.info("queryById sql:"+sql);
//
//        List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, params);
//        StringBuilder disease = new StringBuilder();
//        StringBuilder code = new StringBuilder();
//        if (null != list && list.size() > 0){
//            if (list.size() == 1){
//                return  list.get(0);
//            }else {
//                for (int i=0;i<list.size();i++){
//                    if (i == 0 ){
//                        disease.append(list.get(i).get("diseaseName"));
//                        code.append(list.get(i).get("diseaseCode"));
//                    }else {
//                        disease.append(","+list.get(i).get("diseaseName"));
//                        code.append(","+list.get(i).get("diseaseCode"));
//                    }
//                }
//                list.get(0).put("diseaseName",disease);
//                list.get(0).put("diseaseCode",code);
//                return  list.get(0);
//            }
//        }
//
//        return null;
//    }
//
//    public Boolean updateList(JSONArray jsonArray){
//        if(jsonArray!=null&&jsonArray.size()>0){
//            for(int i=0;i<jsonArray.size();i++){
//                JSONObject doctor = jsonArray.getJSONObject(i);
//                try {
//                    updateInfo(doctor);
//                }catch (Exception e){
//                    logger.info("update doctor error:"+e.toString());
//                }
//            }
//        }
//        return true;
//    }
//
//    /**
//     * 修改医生服务配置
//     * @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 photo = jsonObject.get("photo").toString();
//        String outpatientType = jsonObject.get("outpatientType").toString();
//        String newSpecialDisease = jsonObject.get("specialDisease").toString();
//        String newSpecialDiseaseCode = jsonObject.get("specialDiseaseCode").toString();
//        baseDoctorDao.update(doctorId,introduce,expertise,photo,outpatientType);
//        //删除医生旧专病门诊,保存新专病门诊
//        Map<String,Object> params = new HashedMap();
//        String sqlTotal ="SELECT " +
//                " COUNT(1) AS \"total\" " +
//                " FROM " +
//                " wlyy_doctor_special_disease a " +
//                " WHERE " +
//                " 1 = 1";
//        sqlTotal += " AND a.doctor_code =:doctorId";
//        params.put("doctorId",doctorId);
//        Long count = 0L;
//        List<Map<String, Object>> total = hibenateUtils.createSQLQuery(sqlTotal, params);
//        //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
//        count = hibenateUtils.objTransformLong(total.get(0).get("total"));
//        if (count > 0){
//            specialDiseaseDao.deleteByDoctorCode(doctorId);
//        }
//        if(StringUtils.isNotBlank(newSpecialDisease) && StringUtils.isNotBlank(newSpecialDiseaseCode)){
//            String[] split = newSpecialDisease.split(",");
//            String[] splitCode = newSpecialDiseaseCode.split(",");
//            specialDiseaseDao.deleteByDoctorCode(doctorId);
//            for (int i=0;i<split.length;i++ ){
//                DoctorSpecialDiseaseDo specialDiseaseDo = new DoctorSpecialDiseaseDo();
//                specialDiseaseDo.setDoctorCode(doctorId);
//                specialDiseaseDo.setDiseaseName(split[i]);
//                specialDiseaseDo.setDiseaseCode(splitCode[i]);
//                specialDiseaseDao.save(specialDiseaseDo);
//            }
//        }
//
//        return true;
//    }
//
//    public Boolean updateInfo(JSONObject jsonObject)throws Exception{
//        //取出数据
//        String doctorId = jsonObject.get("doctorId").toString();
//        String outpatientType = jsonObject.get("outpatientType").toString();
//        logger.info("doctor:"+doctorId+" outpatientType:"+outpatientType);
//        BaseDoctorDO doctorDO = baseDoctorDao.findOne(doctorId);
//        doctorDO.setOutpatientType(outpatientType);
//        baseDoctorDao.save(doctorDO);
//        return true;
//    }
//
//
//    /**
//     * 修改医生状态
//     * @param doctorId
//     * @param status
//     */
//    public void updateStatus(String doctorId,String status)throws Exception{
//        baseDoctorDao.updateStatus(doctorId,status);
//    }
//
//    public Boolean updateDoctorPw(String id,String pw,String orgPw){
//        BaseDoctorDO doctorDO = baseDoctorDao.findOne(id);
//
//        String orgPwMd5 = MD5.md5Hex(orgPw + "{" + doctorDO.getSalt() + "}");
//        if(!orgPwMd5.equals(doctorDO.getPassword())){
//            return false;
//        }
//        //认证信息设置
//        String salt = randomString(5);
//        doctorDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
//        doctorDO.setSalt(salt);
//
//        baseDoctorDao.save(doctorDO);
//
//        //设置更新时间
//        saveDoctorPwlimitDate(id);
//
//        return true;
//    }
//
//    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();
//    }
//
//    public com.alibaba.fastjson.JSONObject findDoctorPwlimitDate(String doctor){
//        String key = "hlwyy:authPw:doctor:" + doctor;
//        String authPw = redisTemplate.opsForValue().get(key);
//        com.alibaba.fastjson.JSONObject valueJson = null;
//        if(StringUtils.isNotBlank(authPw)){
//
//            WlyyHospitalSysDictDO wlyyHospitalSysDictDO = wlyyHospitalSysDictDao.findById("pwOverDue");
//            String code[] = wlyyHospitalSysDictDO.getDictCode().split(",");
//            Integer maxDateInt = Integer.parseInt(code[0]);
//            Integer remainDateInt = Integer.parseInt(code[1]);
//
//            valueJson = JSON.parseObject(authPw);
//            Long updateTimeLong = valueJson.getLong("updateTime");
//            Date updateTime = new Date();
//            updateTime.setTime(updateTimeLong);
//            Date maxDate = DateUtil.getPreDays(updateTime,maxDateInt);
//
//            Long betweenDate = (maxDate.getTime() - new Date().getTime())/(60*60*24*1000);
//            valueJson.put("betweenDate",betweenDate);
//            if(betweenDate<remainDateInt){
//                valueJson.put("remaind",true);
//            }else {
//                valueJson.put("remaind",false);
//            }
//        }else {
//            valueJson = new com.alibaba.fastjson.JSONObject();
//            valueJson.put("isChanged",false);
//        }
//        return valueJson;
//    }
//
//    public boolean saveDoctorPwlimitDate(String doctor){
//        String key = "hlwyy:authPw:doctor:" + doctor;
//        com.alibaba.fastjson.JSONObject valueJson = new com.alibaba.fastjson.JSONObject();
//        valueJson.put("updateTime",new Date().getTime());
//        valueJson.put("isChanged",true);
//        redisTemplate.opsForValue().set(key,valueJson.toJSONString());
//        return true;
//    }
}
//
//
//
//
////    public static void main(String ag[]){
////        long betweenDate = (DateUtil.strToDate("2020-04-11","yyyy-MM-dd").getTime() - new Date().getTime())/(60*60*24*1000);
////        System.out.println(betweenDate);
////    }
//
////    public static void main(String ag[]){
////        String str = "[ " +
////                "{ " +
////                "\"title\":\"Java 开发\", " +
////                "\"edition\":3, " +
////                "\"author\":[\"smith\",\"张三\",\"李四\"] " +
////                "}, " +
////                "{ " +
////                "\"title\":\"Web 开发\", " +
////                "\"edition\":3, " +
////                "\"author\":[\"Allen\",\"王五\",\"赵六\"] " +
////                "} " +
////                "]";
////        JSONArray json = JSONArray.fromObject(str);
////        for(int i=0;i<json.size();i++){
////            JSONObject doctor = json.getJSONObject(i);
////            doctor.getString("doctor");
////        }
////    }
//}

+ 49 - 7
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
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.service.BaseDoctorService;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.entity.base.dict.DictHospitalDeptDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
@ -22,7 +22,6 @@ import com.yihu.jw.entity.hospital.doctor.WlyyDoctorWorkTimeDO;
import com.yihu.jw.entity.hospital.doctor.WlyyPatientRegisterTimeDO;
import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.hospital.prescription.*;
import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
@ -54,11 +53,8 @@ import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.PinYinUtils;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.utils.WebserviceUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.jw.wlyy.wlyyhttp.WlyyHttpService;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.utils.security.MD5;
import com.ylzinfo.ehc.EhcHandler;
@ -166,7 +162,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    @Autowired
    private WlyyHospitalWorkRuleDao wlyyHospitalWorkRuleDao;
    @Autowired
    private BaseDoctorService baseDoctorService;
    private BaseDoctorInfoService baseDoctorService;
    @Value("${demo.flag}")
@ -1171,7 +1167,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @param size
     * @return
     */
    public MixEnvelop findDoctorWithMouthWork(String orgCode, String dept, String chargeType, String date, String nameKey, Integer page, Integer size) {
    public MixEnvelop findDoctorWithMouthWork(String orgCode, String dept, String chargeType, String date, String nameKey,String iswork, Integer page, Integer size) {
        String totalSql = "SELECT " +
                " count(1) AS total " +
@ -1199,6 +1195,29 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        if (StringUtils.isNotBlank(nameKey)) {
            totalSql += " AND d.name like '%" + nameKey + "%' ";
        }
        //过滤排班
        if(StringUtils.isNotBlank(iswork)){
            if("1".equals(iswork)){
                totalSql +=" AND d.id IN ( " +
                        " SELECT DISTINCT " +
                        " t.doctor " +
                        " FROM " +
                        "  wlyy_doctor_work_time t " +
                        " WHERE " +
                        "  t.date LIKE '%"+date+"%' " +
                        " )";
            }else{
                totalSql +=" AND d.id NOT IN ( " +
                        " SELECT DISTINCT " +
                        " t.doctor " +
                        " FROM " +
                        "  wlyy_doctor_work_time t " +
                        " WHERE " +
                        "  t.date LIKE '%"+date+"%' " +
                        " )";
            }
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
        Long count = 0L;
@ -1240,6 +1259,29 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        if (StringUtils.isNotBlank(nameKey)) {
            sql += " AND d.name like '%" + nameKey + "%' ";
        }
        //过滤排班
        if(StringUtils.isNotBlank(iswork)){
            if("1".equals(iswork)){
                sql +=" AND d.id IN ( " +
                        " SELECT DISTINCT " +
                        " t.doctor " +
                        " FROM " +
                        "  wlyy_doctor_work_time t " +
                        " WHERE " +
                        "  t.date LIKE '%"+date+"%' " +
                        " )";
            }else{
                sql +=" AND d.id NOT IN ( " +
                        " SELECT DISTINCT " +
                        " t.doctor " +
                        " FROM " +
                        "  wlyy_doctor_work_time t " +
                        " WHERE " +
                        "  t.date LIKE '%"+date+"%' " +
                        " )";
            }
        }
        sql += " LIMIT " + (page - 1) * size + "," + size + "";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        if (list != null && list.size() > 0) {

+ 30 - 30
svr/svr-base/src/main/java/com/yihu/jw/base/dao/doctor/BaseDoctorRoleDao.java

@ -1,30 +1,30 @@
package com.yihu.jw.base.dao.doctor;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import java.util.Set;
/**
 * 
 * 医生与业务模块角色关联信息 数据库访问层
 * 
 * @version 
 * <pre>
 * Author	Version		Date		Changes
 * litaohong 	1.0  		2018年10月25日 	Created
 *
 * </pre>
 * @since 1.
 */
public interface BaseDoctorRoleDao extends PagingAndSortingRepository<BaseDoctorRoleDO, Integer>, JpaSpecificationExecutor<BaseDoctorRoleDO>  {
    @Query("select id from BaseDoctorRoleDO where doctorCode = ?1")
    Set<Object> findIdListByDoctorCode(String doctorCode);
    List<BaseDoctorRoleDO> findByDoctorCode(String doctorCode);
}
//package com.yihu.jw.base.dao.doctor;
//
//import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
//import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
//import org.springframework.data.jpa.repository.Query;
//import org.springframework.data.repository.PagingAndSortingRepository;
//
//import java.util.List;
//import java.util.Set;
//
//
///**
// *
// * 医生与业务模块角色关联信息 数据库访问层
// *
// * @version
// * <pre>
// * Author	Version		Date		Changes
// * litaohong 	1.0  		2018年10月25日 	Created
// *
// * </pre>
// * @since 1.
// */
//public interface BaseDoctorRoleDao extends PagingAndSortingRepository<BaseDoctorRoleDO, Integer>, JpaSpecificationExecutor<BaseDoctorRoleDO>  {
//
//    @Query("select id from BaseDoctorRoleDO where doctorCode = ?1")
//    Set<Object> findIdListByDoctorCode(String doctorCode);
//
//    List<BaseDoctorRoleDO> findByDoctorCode(String doctorCode);
//}

+ 8 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/dao/doctor/BaseDoctorRoleInfoDao.java

@ -1,9 +1,14 @@
package com.yihu.jw.base.dao.doctor;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleInfoDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import java.util.Set;
/**
 * 
@ -21,7 +26,9 @@ public interface BaseDoctorRoleInfoDao extends PagingAndSortingRepository<BaseDo
    BaseDoctorRoleInfoDO findBySaasidAndName(String saasId,String name);
    BaseDoctorRoleInfoDO findByCode(String code);
    boolean existsByCode(String code);
    BaseDoctorRoleInfoDO findByCode(String code);
}

+ 1 - 19
svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorRoleInfoService.java

@ -5,36 +5,18 @@ import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.contant.CommonContant;
import com.yihu.jw.base.dao.doctor.BaseDoctorRoleInfoDao;
import com.yihu.jw.base.dao.doctor.BaseModuleRoleDao;
import com.yihu.jw.base.dao.role.BaseRoleMenuDao;
import com.yihu.jw.base.dao.role.RoleDao;
import com.yihu.jw.base.dao.saas.SaasDao;
import com.yihu.jw.base.dao.user.UserDao;
import com.yihu.jw.base.service.module.SaasModuleService;
import com.yihu.jw.base.service.org.BaseOrgSaasService;
import com.yihu.jw.base.service.org.BaseOrgUserService;
import com.yihu.jw.base.service.org.OrgTree;
import com.yihu.jw.base.service.org.OrgTreeService;
import com.yihu.jw.base.service.role.BaseRoleMenuService;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.base.util.JavaBeanUtils;
import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleInfoDO;
import com.yihu.jw.entity.base.doctor.BaseModuleRoleDO;
import com.yihu.jw.entity.base.module.ModuleDO;
import com.yihu.jw.entity.base.module.SaasModuleDO;
import com.yihu.jw.entity.base.org.BaseOrgUserDO;
import com.yihu.jw.entity.base.role.RoleDO;
import com.yihu.jw.entity.base.saas.SaasDO;
import com.yihu.jw.entity.base.user.UserDO;
import com.yihu.jw.restmodel.base.module.ModuleVO;
import com.yihu.jw.restmodel.base.module.SaasModuleVO;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.utils.security.MD5;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

+ 2 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorRoleService.java

@ -1,6 +1,7 @@
package com.yihu.jw.base.service.doctor;
import com.yihu.jw.base.dao.doctor.BaseDoctorRoleDao;
import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;

+ 0 - 10
svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorService.java

@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.dao.dict.DictJobTitleDao;
import com.yihu.jw.base.dao.doctor.BaseDoctorRoleDao;
import com.yihu.jw.base.dao.doctor.BaseDoctorRoleInfoDao;
import com.yihu.jw.base.service.dict.DictDoctorDutyService;
import com.yihu.jw.base.service.dict.DictHospitalDeptService;
import com.yihu.jw.base.service.doctor.excelImport.BaseDoctorExcelDO;
import com.yihu.jw.base.service.org.OrgTree;
import com.yihu.jw.base.service.org.OrgTreeService;
@ -36,7 +33,6 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;
/**
@ -85,12 +81,6 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
    @Autowired
    private DictDoctorDutyService dictDoctorDutyService;
    @Autowired
    private DictHospitalDeptService dictHospitalDeptService;
    @Autowired
    private BaseDoctorRoleDao doctorRoleDao;
    @Autowired
    private BaseDoctorRoleInfoDao doctorRoleInfoDao;
    /**

+ 1 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/excelImport/BaseDoctorExcelDOReader.java

@ -6,6 +6,7 @@ import com.yihu.jw.base.dao.doctor.BaseDoctorRoleInfoDao;
import com.yihu.jw.base.endpoint.common.excel.AExcelReader;
import com.yihu.jw.dict.dao.DictDoctorDutyDao;
import com.yihu.jw.dict.dao.DictHospitalDeptDao;
import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
import com.yihu.jw.org.dao.BaseOrgDao;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Sheet;

+ 1 - 3
svr/svr-base/src/main/java/com/yihu/jw/base/service/team/BaseTeamMemberService.java

@ -1,13 +1,11 @@
package com.yihu.jw.base.service.team;
import com.yihu.jw.base.dao.doctor.BaseDoctorRoleDao;
import com.yihu.jw.base.dao.team.BaseTeamMemberDao;
import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
import com.yihu.jw.entity.base.team.BaseTeamMemberDO;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yihu.jw.entity.base.team.BaseTeamMemberDO;
import java.util.ArrayList;
import java.util.HashSet;

+ 13 - 3
svr/svr-base/src/main/resources/application.yml

@ -111,7 +111,10 @@ hospital:
  mqPwd: 123456
  SourceSysCode: S60
  TargetSysCode: S01
wlyy:
  url: http://ehr.yihu.com/wlyy/
wechat:
  id: d24d1367-7f4f-43af-910e-a0a43799e040
---
spring:
  profiles: jwtest
@ -147,7 +150,10 @@ hospital:
  mqPwd: 123456
  SourceSysCode: S60
  TargetSysCode: S01
wlyy:
  url: http://ehr.yihu.com/wlyy/
wechat:
  id: d24d1367-7f4f-43af-910e-a0a43799e040
---
spring:
  profiles: jwprod
@ -180,4 +186,8 @@ hospital:
  mqUser: JKZL
  mqPwd: 123456
  SourceSysCode: S60
  TargetSysCode: S01
  TargetSysCode: S01
wlyy:
  url: http://ehr.yihu.com/wlyy/
wechat:
  id: d24d1367-7f4f-43af-910e-a0a43799e040

+ 2 - 6
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/config/DoctorServiceEndPoint.java

@ -1,7 +1,6 @@
package com.yihu.jw.hospital.endpoint.config;
import com.yihu.jw.doctor.service.BaseDoctorService;
import com.yihu.jw.entity.base.doctor.BaseDoctorVo;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
@ -13,9 +12,6 @@ import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
 * @author zmk
 * @vsrsion 1.0
@ -27,7 +23,7 @@ import java.util.Map;
public class DoctorServiceEndPoint extends EnvelopRestEndpoint {
    @Autowired
    private BaseDoctorService baseDoctorService;
    private BaseDoctorInfoService baseDoctorService;

+ 6 - 4
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/patient/PatientNoLoginEndPoint.java

@ -2,7 +2,7 @@ package com.yihu.jw.hospital.endpoint.patient;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.dict.service.BaseDictJobTitleService;
import com.yihu.jw.doctor.service.BaseDoctorService;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.entity.base.dict.DictJobTitleDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.hospital.prescription.service.PrescriptionService;
@ -52,13 +52,15 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
    @Autowired
    private BaseDictJobTitleService baseDictJobTitleService;
    @Autowired
    private BaseDoctorService baseDoctorService;
    private BaseDoctorInfoService baseDoctorService;
    @GetMapping(value = BaseHospitalRequestMapping.PatientNoLogin.findDoctorByHospitalAndDiseaseAndDept)
    @ApiOperation(value = "根据疾病名称,热门部门查询医生", notes = "根据疾病名称,热门部门查询医生")
    public ListEnvelop findDoctorByHospitalAndDiseaseAndDept(@ApiParam(name = "orgCode", value = "机构code")
    public ListEnvelop findDoctorByHospitalAndDiseaseAndDept(@ApiParam(name = "iswork", value = "是否过滤排班,1是")
                                                             @RequestParam(value = "iswork", required = true)String iswork,
                                                             @ApiParam(name = "orgCode", value = "机构code")
                                                             @RequestParam(value = "orgCode", required = true,defaultValue = "350211A1002")String orgCode,
                                                             @ApiParam(name = "dept", value = "部门code")
                                                             @RequestParam(value = "dept", required = false)String dept,
@ -87,7 +89,7 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
    ) throws Exception{
        logger.info("findDoctorByHospitalAndDiseaseAndDept start:"+ DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss:SSS"));
        return success(prescriptionService.findDoctorByHospitalAndDiseaseAndDept(null,null,
        return success(prescriptionService.findDoctorByHospitalAndDiseaseAndDept(iswork,null,
                orgCode,dept,
                diseaseKey,doctorNameKey,
                jobTitleNameKey,outpatientType,

+ 3 - 1
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java

@ -481,12 +481,14 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
                                         @RequestParam(value = "chargeType", required = false)String chargeType,
                                         @ApiParam(name = "nameKey", value = "名字关键字")
                                         @RequestParam(value = "nameKey", required = false)String nameKey,
                                         @ApiParam(name = "iswork", value = "不传全部,1.当月已经排班,2.当月未排班")
                                         @RequestParam(value = "iswork", required = false)String iswork,
                                         @ApiParam(name = "page", value = "第几页")
                                         @RequestParam(value = "page", required = true)Integer page,
                                         @ApiParam(name = "size", value = "每页大小")
                                         @RequestParam(value = "size", required = true)Integer size) {
        return success(prescriptionService.findDoctorWithMouthWork(orgCode,dept,chargeType,date,nameKey,page,size));
        return success(prescriptionService.findDoctorWithMouthWork(orgCode,dept,chargeType,date,nameKey,iswork,page,size));
    }