ソースを参照

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

wangzhinan 3 年 前
コミット
7a309056c2
100 ファイル変更9837 行追加86 行削除
  1. 0 1
      app/app-iot-server/pom.xml
  2. 33 0
      business/base-service/pom.xml
  3. 2 0
      business/base-service/src/main/java/com/yihu/jw/area/dao/BaseCityDao.java
  4. 11 2
      business/base-service/src/main/java/com/yihu/jw/area/dao/BaseTownDao.java
  5. 21 0
      business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintDao.java
  6. 18 0
      business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintDictDao.java
  7. 23 0
      business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintDoctorDao.java
  8. 14 0
      business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintOperateDao.java
  9. 919 0
      business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintService.java
  10. 32 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseDictIcd10Dao.java
  11. 33 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseDrugDictDao.java
  12. 31 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseDrugUseDictDao.java
  13. 31 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseFollowUpDictDao.java
  14. 29 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseFrequencyDictDao.java
  15. 17 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseJobCategoryDao.java
  16. 12 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseJpushTemplateDao.java
  17. 10 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseTemplateDao.java
  18. 23 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseTemplateDictDao.java
  19. 26 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseTemplateOrgDao.java
  20. 5 1
      business/base-service/src/main/java/com/yihu/jw/dict/dao/DictHospitalDeptDao.java
  21. 18 0
      business/base-service/src/main/java/com/yihu/jw/dict/dao/PrivateDictDao.java
  22. 37 0
      business/base-service/src/main/java/com/yihu/jw/dict/service/DeptHomepageBannerService.java
  23. 63 0
      business/base-service/src/main/java/com/yihu/jw/dict/service/DiseaseHomepageBannerService.java
  24. 123 0
      business/base-service/src/main/java/com/yihu/jw/dict/service/FollowUpDictService.java
  25. 71 0
      business/base-service/src/main/java/com/yihu/jw/dict/service/PrivateDictService.java
  26. 17 0
      business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorDao.java
  27. 16 1
      business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorHospitalDao.java
  28. 29 0
      business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorMessageDao.java
  29. 2 0
      business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorRoleDao.java
  30. 9 0
      business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorSuggestDao.java
  31. 267 32
      business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorInfoService.java
  32. 156 0
      business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorSuggestService.java
  33. 19 8
      business/base-service/src/main/java/com/yihu/jw/evaluate/score/service/BaseEvaluateScoreService.java
  34. 144 0
      business/base-service/src/main/java/com/yihu/jw/file_upload/FileManageService.java
  35. 2 0
      business/base-service/src/main/java/com/yihu/jw/file_upload/FileUploadRunnable.java
  36. 295 11
      business/base-service/src/main/java/com/yihu/jw/file_upload/FileUploadService.java
  37. 14 0
      business/base-service/src/main/java/com/yihu/jw/gateway/dao/GcClientDetailsDao.java
  38. 11 0
      business/base-service/src/main/java/com/yihu/jw/gateway/dao/GcHttpLogDao.java
  39. 29 0
      business/base-service/src/main/java/com/yihu/jw/gateway/dao/GcTokenDao.java
  40. 11 0
      business/base-service/src/main/java/com/yihu/jw/gateway/dao/GcTokenLogDao.java
  41. 39 0
      business/base-service/src/main/java/com/yihu/jw/gateway/service/GcClientDetailsService.java
  42. 119 0
      business/base-service/src/main/java/com/yihu/jw/gateway/service/GcTokenService.java
  43. 1675 0
      business/base-service/src/main/java/com/yihu/jw/healthCare/service/HealthCareService.java
  44. 92 0
      business/base-service/src/main/java/com/yihu/jw/healthCare/utils/AES.java
  45. 86 0
      business/base-service/src/main/java/com/yihu/jw/healthCare/utils/ConvertUtils.java
  46. 44 0
      business/base-service/src/main/java/com/yihu/jw/healthCare/utils/MD5.java
  47. 19 0
      business/base-service/src/main/java/com/yihu/jw/healthCare/utils/ReqDto.java
  48. 269 0
      business/base-service/src/main/java/com/yihu/jw/healthCare/utils/SM4.java
  49. 99 0
      business/base-service/src/main/java/com/yihu/jw/healthCare/utils/SafeUtil.java
  50. 55 0
      business/base-service/src/main/java/com/yihu/jw/healthCare/utils/StringUtils.java
  51. 24 0
      business/base-service/src/main/java/com/yihu/jw/hospital/HospitalDao.java
  52. 14 0
      business/base-service/src/main/java/com/yihu/jw/hospital/consult/dao/BaseAdviceTreatmentDao.java
  53. 8 0
      business/base-service/src/main/java/com/yihu/jw/hospital/dict/BaseDeptHomepageBannerDao.java
  54. 8 0
      business/base-service/src/main/java/com/yihu/jw/hospital/dict/BaseDiseaseHomepageBannerDao.java
  55. 20 0
      business/base-service/src/main/java/com/yihu/jw/hospital/dict/BaseIncentiveDictDao.java
  56. 8 0
      business/base-service/src/main/java/com/yihu/jw/hospital/dict/BaseTopBannerDao.java
  57. 9 3
      business/base-service/src/main/java/com/yihu/jw/hospital/dict/WlyyChargeDictDao.java
  58. 27 0
      business/base-service/src/main/java/com/yihu/jw/hospital/dict/WlyyHospitalSysDictDao.java
  59. 107 0
      business/base-service/src/main/java/com/yihu/jw/hospital/dict/service/BaseIncentiveDictService.java
  60. 459 0
      business/base-service/src/main/java/com/yihu/jw/hospital/dict/service/WlyyHospitalSysDictService.java
  61. 19 0
      business/base-service/src/main/java/com/yihu/jw/hospital/doctor/dao/BaseDoctorBackgroundDao.java
  62. 8 0
      business/base-service/src/main/java/com/yihu/jw/hospital/doctor/dao/DoctorTimeMappingDao.java
  63. 177 0
      business/base-service/src/main/java/com/yihu/jw/hospital/doctor/dao/service/BaseDoctorBGService.java
  64. 24 0
      business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/dao/BaseDrugStoreDao.java
  65. 18 0
      business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/dao/BaseDrugStoreTimeDao.java
  66. 224 0
      business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/service/BaseDrugStoreService.java
  67. 18 0
      business/base-service/src/main/java/com/yihu/jw/hospital/family/dao/BasePatientMemberDictDao.java
  68. 30 0
      business/base-service/src/main/java/com/yihu/jw/hospital/family/dao/WlyyPatientFamilyMemberDao.java
  69. 21 0
      business/base-service/src/main/java/com/yihu/jw/hospital/family/service/PatientMemberDictService.java
  70. 719 0
      business/base-service/src/main/java/com/yihu/jw/hospital/family/service/WlyyFamilyMemberService.java
  71. 20 0
      business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicailBillDao.java
  72. 23 0
      business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicailIcdDao.java
  73. 23 0
      business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicailMxDao.java
  74. 23 0
      business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicailRelationDao.java
  75. 16 0
      business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicalPrescriptionUploadDao.java
  76. 9 0
      business/base-service/src/main/java/com/yihu/jw/hospital/httplog/dao/BaseOperateLogDao.java
  77. 15 0
      business/base-service/src/main/java/com/yihu/jw/hospital/httplog/dao/YlzHttpLogDao.java
  78. 152 0
      business/base-service/src/main/java/com/yihu/jw/hospital/httplog/service/BaseOperateLogService.java
  79. 303 0
      business/base-service/src/main/java/com/yihu/jw/hospital/httplog/service/WlyyHttpLogService.java
  80. 300 0
      business/base-service/src/main/java/com/yihu/jw/hospital/httplog/service/YlzHttpLogService.java
  81. 2 0
      business/base-service/src/main/java/com/yihu/jw/hospital/mapping/dao/DoctorMappingDao.java
  82. 3 0
      business/base-service/src/main/java/com/yihu/jw/hospital/mapping/dao/PatientMappingDao.java
  83. 46 27
      business/base-service/src/main/java/com/yihu/jw/hospital/mapping/service/PatientMappingService.java
  84. 28 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/BaseBannerDao.java
  85. 28 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/BaseBannerDoctorDao.java
  86. 28 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/BaseUserMessageDao.java
  87. 14 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/BaseUserMsgContentDao.java
  88. 11 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/MsgContentDao.java
  89. 50 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/SystemMessageDao.java
  90. 424 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/service/BaseBannerDoctorService.java
  91. 278 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/service/BaseBannerService.java
  92. 612 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/service/BaseUserMsgService.java
  93. 98 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/service/SystemMessageService.java
  94. 189 0
      business/base-service/src/main/java/com/yihu/jw/hospital/message/service/UserMsgContentService.java
  95. 26 0
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/BaseNatAppointmentDao.java
  96. 8 0
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/BaseNatInspectionDao.java
  97. 14 0
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/BaseNationalDrugDictDao.java
  98. 21 0
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/BaseSensitiveDao.java
  99. 11 0
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/OauthCaConfigDao.java
  100. 0 0
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/OutpatientDao.java

+ 0 - 1
app/app-iot-server/pom.xml

@ -93,7 +93,6 @@
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jexcelapi</groupId>

+ 33 - 0
business/base-service/pom.xml

@ -179,6 +179,39 @@
            <artifactId>lombok</artifactId>
            <version>1.18.8</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.kaptcha</groupId>
            <artifactId>kaptcha</artifactId>
            <version>2.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.jw</groupId>
            <artifactId>sms-service</artifactId>
            <version>2.0.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>cn.jpush.api</groupId>
            <artifactId>jiguang-common</artifactId>
            <version>1.1.9</version>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <!-- <scope>runtime</scope> -->
        </dependency>
        <dependency>
            <groupId>cn.jpush.api</groupId>
            <artifactId>jpush-client</artifactId>
            <version>3.4.8</version>
        </dependency>
    </dependencies>
    <build>

+ 2 - 0
business/base-service/src/main/java/com/yihu/jw/area/dao/BaseCityDao.java

@ -28,5 +28,7 @@ public interface BaseCityDao extends PagingAndSortingRepository<BaseCityDO, Inte
    @Query("select code,name from BaseCityDO")
    List<BaseCityDO> getAllCity();
    @Query("select a from BaseCityDO a where a.province = ?1 order by id")
    Iterable<BaseCityDO> findByProvince(String province);
}

+ 11 - 2
business/base-service/src/main/java/com/yihu/jw/area/dao/BaseTownDao.java

@ -1,12 +1,13 @@
package com.yihu.jw.area.dao;
import com.yihu.jw.entity.base.area.BaseTownDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.yihu.jw.entity.base.area.BaseTownDO;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
 * 区县字典 数据库访问层
 *
@ -21,4 +22,12 @@ public interface BaseTownDao extends PagingAndSortingRepository<BaseTownDO, Inte
    @Query("select name from BaseTownDO where code =:code")
    String getNameByCode(@Param("code") String code);
    @Query("select p from BaseTownDO p where p.code = ?1")
    BaseTownDO findByCode(String code);
    @Query("select a from BaseTownDO a where a.city = ?1 order by id")
    List<BaseTownDO> findByCityCode(String city);
}

+ 21 - 0
business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintDao.java

@ -0,0 +1,21 @@
package com.yihu.jw.complaint;
import com.yihu.jw.entity.base.complaint.BaseComplaintDO;
import com.yihu.jw.entity.base.complaint.BaseComplaintDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseComplaintDao extends PagingAndSortingRepository<BaseComplaintDO, String>, JpaSpecificationExecutor<BaseComplaintDO> {
    @Query("select count(1) from BaseComplaintDO t where t.isDel='1' and t.status=?1 and t.complaintId=?2")
    Integer getCountByStatusAndComplaintId(String status,String complatientId);
    @Query("select count(1) from BaseComplaintDO t where t.isDel='1' and t.status=?1 ")
    Integer getCountByStatus(String status);
    @Query("select count(1) from BaseComplaintDO t where t.isDel='1' and t.status=?1  and t.patient=?2")
    Integer getCountByStatusByPatient(String status,String patient);
}

+ 18 - 0
business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintDictDao.java

@ -0,0 +1,18 @@
package com.yihu.jw.complaint;
import com.yihu.jw.entity.base.complaint.BaseComplaintDictDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseComplaintDictDao extends PagingAndSortingRepository<BaseComplaintDictDO, String>, JpaSpecificationExecutor<BaseComplaintDictDO> {
    @Query("from BaseComplaintDictDO t where t.isDel='1' and t.id=?1")
    BaseComplaintDictDO findById(String id);
    @Query("from BaseComplaintDictDO t where t.isDel='1' and t.name like %?1% order by t.createTime desc")
    List<BaseComplaintDictDO> findByName(String name);
    @Query("from BaseComplaintDictDO t where t.isDel='1' order by t.createTime desc")
    List<BaseComplaintDictDO> findByAll();
}

+ 23 - 0
business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintDoctorDao.java

@ -0,0 +1,23 @@
package com.yihu.jw.complaint;
import com.yihu.jw.entity.base.complaint.BaseComplaintDictDO;
import com.yihu.jw.entity.base.complaint.BaseComplaintDoctorDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseComplaintDoctorDao extends PagingAndSortingRepository<BaseComplaintDoctorDO, String>, JpaSpecificationExecutor<BaseComplaintDoctorDO> {
    @Query("from BaseComplaintDoctorDO t where t.isDel='1' and t.id=?1")
    BaseComplaintDoctorDO findByDelAndId(String id);
    @Query("from BaseComplaintDoctorDO t where t.isDel='1' and t.doctor=?1")
    BaseComplaintDoctorDO findbyDoctorAndDel(String doctor);
    @Query("from BaseComplaintDoctorDO t where t.isDel='1' and t.doctor=?1 and t.complaintId=?2")
    BaseComplaintDoctorDO findbyDoctorAndDelAndType(String doctor,String complaintType);
    @Query("from BaseComplaintDoctorDO t where t.isDel='1' and t.complaintId=?1")
    List<BaseComplaintDoctorDO> findbyComplaintId(String complaintId);
}

+ 14 - 0
business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintOperateDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.complaint;
import com.yihu.jw.entity.base.complaint.BaseComplaintDoctorDO;
import com.yihu.jw.entity.base.complaint.BaseComplaintOperateLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseComplaintOperateDao  extends PagingAndSortingRepository<BaseComplaintOperateLogDO, String>, JpaSpecificationExecutor<BaseComplaintOperateLogDO> {
    @Query("from BaseComplaintOperateLogDO t where t.operateFrom=?1 and t.status='3'")
    List<BaseComplaintOperateLogDO> findbyOperateFrom(String doctor);
}

+ 919 - 0
business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintService.java

@ -0,0 +1,919 @@
package com.yihu.jw.complaint;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.dao.BaseDoctorRoleDao;
import com.yihu.jw.entity.base.complaint.BaseComplaintDO;
import com.yihu.jw.entity.base.complaint.BaseComplaintDictDO;
import com.yihu.jw.entity.base.complaint.BaseComplaintDoctorDO;
import com.yihu.jw.entity.base.complaint.BaseComplaintOperateLogDO;
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.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.jw.wechat.enterprise.EnterpriseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@Service
public class BaseComplaintService {
    @Autowired
    private BaseComplaintDictDao baseComplaintDictDao;
    @Autowired
    private BaseComplaintDoctorDao baseComplaintDoctorDao;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private BaseDoctorHospitalDao baseDoctorHospitalDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private BaseComplaintDao baseComplaintDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private DictHospitalDeptDao dictHospitalDeptDao;
    @Autowired
    private BaseComplaintOperateDao baseComplaintOperateDao;
    @Autowired
    private BaseDoctorRoleDao baseDoctorRoleDao;
    @Autowired
    private BasePatientDao basePatientDao;
    @Autowired
    private EnterpriseService enterpriseService;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Value("${wechat.id}")
    private String wxId;
    @Value("${wechat.flag}")
    private boolean flag;
    //修改新增
    public BaseComplaintDictDO createOrUpdateDict(String id, String name) {
        BaseComplaintDictDO baseComplaintDictDO = new BaseComplaintDictDO();
        if (StringUtils.isNoneBlank(id)) {
            baseComplaintDictDO = baseComplaintDictDao.findById(id);
            baseComplaintDictDO.setName(name);
            baseComplaintDictDO.setUpdateTime(new Date());
        } else {
            baseComplaintDictDO.setIsDel("1");
            baseComplaintDictDO.setName(name);
            baseComplaintDictDO.setCreateTime(new Date());
        }
        return baseComplaintDictDao.save(baseComplaintDictDO);
    }
    //删除
    public BaseComplaintDictDO deleteDict(String id) {
        BaseComplaintDictDO baseComplaintDictDO = baseComplaintDictDao.findById(id);
        if (null != baseComplaintDictDO) {
            baseComplaintDictDO.setIsDel("0");
            baseComplaintDictDO.setUpdateTime(new Date());
            baseComplaintDictDao.save(baseComplaintDictDO);
        }
        List<BaseComplaintDoctorDO> baseComplaintDoctorDOs = baseComplaintDoctorDao.findbyComplaintId(id);
        for (BaseComplaintDoctorDO baseComplaintDoctorDO:baseComplaintDoctorDOs){
            baseComplaintDoctorDO.setIsDel("0");
        }
        baseComplaintDoctorDao.save(baseComplaintDoctorDOs);
        return baseComplaintDictDO;
    }
    public BaseComplaintDictDO findOneDict(String id) {
        BaseComplaintDictDO baseComplaintDictDO = baseComplaintDictDao.findById(id);
        return baseComplaintDictDO;
    }
    //查询
    public List<BaseComplaintDictDO> findAll(String name) {
        List<BaseComplaintDictDO> list = new ArrayList<>();
        if (StringUtils.isNoneBlank(name)) {
            list = baseComplaintDictDao.findByName(name);
        } else {
            list = baseComplaintDictDao.findByAll();
        }
        return list;
    }
    //新增投诉管理医生
    @Transactional
    public void createOrUpdateComplainDoctor(String id, String complaintId, String doctorList) throws Exception {
        JSONArray jsonArray = JSON.parseArray(doctorList);
        for (int i=0;i<jsonArray.size();i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            String doctor = jsonObject.getString("doctor");
            String deptCode = jsonObject.getString("deptCode");
            String deptName = "";
            String doctorName = "";
            BaseComplaintDoctorDO preDoctor= baseComplaintDoctorDao.findbyDoctorAndDel(doctor);
            BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doctor);
            List<BaseDoctorRoleDO> baseDoctorRoleDOs = baseDoctorRoleDao.findByDoctorCode(doctor);
            if (baseDoctorRoleDOs==null||baseDoctorRoleDOs.size()==0){
                BaseDoctorRoleDO baseDoctorRoleDO = new BaseDoctorRoleDO();
                baseDoctorRoleDO.setDoctorCode(doctor);
                baseDoctorRoleDO.setRoleCode("specialist");
                baseDoctorRoleDao.save(baseDoctorRoleDO);
            }else if (baseDoctorRoleDOs!=null){
                Boolean addRoleFlag=true;//是否为对应医生添加专科医生角色表示 true即为添加
                for (BaseDoctorRoleDO baseDoctorRoleDO :baseDoctorRoleDOs){
                    if (baseDoctorRoleDO.getRoleCode().equalsIgnoreCase("specialist")){
                        addRoleFlag=false;
                    }
                }
                if(addRoleFlag){
                    BaseDoctorRoleDO baseDoctorRoleDO = new BaseDoctorRoleDO();
                    baseDoctorRoleDO.setDoctorCode(doctor);
                    baseDoctorRoleDO.setRoleCode("specialist");
                    baseDoctorRoleDao.save(baseDoctorRoleDO);
                }
            }
            if (null != baseDoctorDO) {
                doctorName = baseDoctorDO.getName();
            }
            if (preDoctor!=null){
                throw new Exception("医生"+doctorName+"已有负责的投诉类型");
            }
            List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDeptCodeDoctorCode(deptCode, doctor);
            if (baseDoctorHospitalDO != null && baseDoctorHospitalDO.size() > 0) {
                deptName = baseDoctorHospitalDO.get(0).getDeptName();
            }
            if (StringUtils.isNoneBlank(id)) {
                BaseComplaintDoctorDO baseComplaintDoctorDO = new BaseComplaintDoctorDO();
                baseComplaintDoctorDO.setDept(deptCode);
                baseComplaintDoctorDO.setDeptName(deptName);
                baseComplaintDoctorDO.setComplaintId(id);
                baseComplaintDoctorDO.setDoctor(doctor);
                baseComplaintDoctorDO.setDoctorName(doctorName);
                baseComplaintDoctorDO.setIsDel("1");
                baseComplaintDoctorDO.setCreateTime(new Date());
                baseComplaintDoctorDao.save(baseComplaintDoctorDO);
            }
        }
    }
    //删除管理医生
    public BaseComplaintDoctorDO deleteDoctorComplain(String id) {
        BaseComplaintDoctorDO baseComplaintDoctorDO = baseComplaintDoctorDao.findByDelAndId(id);
        if (null != baseComplaintDoctorDO) {
            baseComplaintDoctorDO.setIsDel("0");
            baseComplaintDoctorDO.setUpdateTime(new Date());
            baseComplaintDoctorDao.save(baseComplaintDoctorDO);
        }
        return baseComplaintDoctorDO;
    }
    public MixEnvelop findComplaintDoctor(String doctor,String doctorName, String deptName, String complaintType, Integer page, Integer pageSize) {
        String sql = "select t.id as \"id\"," +
                " t.complaint_id as \"complaintId\"," +
                " t.doctor as \"doctor\"," +
                " t.doctor_name as \"doctorName\"," +
                " t.dept as \"dept\"," +
                " t.dept_name as \"deptName\"," +
                " t.is_del as \"isDel\"," +
                " t.create_time as \"createTime\"," +
                " t.update_time as \"updateTime\"," +
                " d.photo as \"photo\"," +
                " b.name as \"name\" " +
                " from base_complaint_doctor t left join base_complaint_dict b" +
                " on t.complaint_id=b.id " +
                " left join base_doctor d on t.doctor=d.id where t.is_del='1'";
        if (StringUtils.isNoneBlank(doctorName)) {
            sql += " and t.doctor_name like '%" + doctorName + "%'";
        }
        if (StringUtils.isNoneBlank(deptName)) {
            sql += " and t.dept_name like '%" + deptName + "%'";
        }
        if (StringUtils.isNoneBlank(complaintType)) {
            sql += " and t.complaint_id = '" + complaintType + "'";
        }
        if (StringUtils.isNoneBlank(doctor)) {
            sql += " and t.doctor = '" + doctor + "'";
        }
        sql += "order by t.create_time desc";
        List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, page, pageSize);
        List<Map<String, Object>> listCount = hibenateUtils.createSQLQuery(sql);
        MixEnvelop mixEnvelop = new MixEnvelop();
        mixEnvelop.setTotalCount(listCount == null ? 0 : listCount.size());
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        mixEnvelop.setDetailModelList(list);
        return mixEnvelop;
    }
    public BaseComplaintDoctorDO findOneDoctorComplain(String id) {
        BaseComplaintDoctorDO baseComplaintDoctorDO = baseComplaintDoctorDao.findByDelAndId(id);
        return baseComplaintDoctorDO;
    }
    /*
     * 患者举报接口
     * */
    public BaseComplaintDO patiemtComplaint(String json) throws Exception{
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO= wlyyHospitalSysDictDao.findById("complaintOpenControl");
        if (wlyyHospitalSysDictDO!=null){
            if (!"1".equalsIgnoreCase(wlyyHospitalSysDictDO.getDictCode())){
                throw new Exception("投诉通道已关闭");
            }
        }else {
            throw new Exception("投诉通道已关闭");
        }
        BaseComplaintDO baseComplaintDO =objectMapper.readValue(json,BaseComplaintDO.class);
        BaseComplaintDictDO baseComplaintDictDO = baseComplaintDictDao.findById(baseComplaintDO.getComplaintId());
        if (baseComplaintDictDO!=null){
            baseComplaintDO.setComplaintName(baseComplaintDictDO.getName());
        }
        if (StringUtils.isNoneBlank(baseComplaintDO.getVisitDept())){
            DictHospitalDeptDO dictHospitalDeptDO=dictHospitalDeptDao.findByCode(baseComplaintDO.getVisitDept());
            if (dictHospitalDeptDO!=null){
                baseComplaintDO.setVisitDeptName(dictHospitalDeptDO.getName());
            }
        }
        /*if(StringUtils.isNoneBlank(baseComplaintDO.getPatient())){
            BasePatientDO basePatientDO= basePatientDao.findById(baseComplaintDO.getPatient());
            if (basePatientDO!=null){
                basePatientDO.setIdcardFront(baseComplaintDO.getIdcardFront());
                basePatientDO.setIdcardBack(baseComplaintDO.getIdcardBack());
                basePatientDao.save(basePatientDO);
            }
        }*/
        baseComplaintDO.setIsDel("1");
        baseComplaintDO.setStatus("0");
        baseComplaintDO.setCreateTime(new Date());
        baseComplaintDO.setDefaultdoctor("defalutDoctor");
        baseComplaintDO=  baseComplaintDao.save(baseComplaintDO);
        BaseComplaintOperateLogDO baseComplaintOperateLogDO = new BaseComplaintOperateLogDO();
        baseComplaintOperateLogDO.setOperateFrom(baseComplaintDO.getPatient());
        baseComplaintOperateLogDO.setStatus("0");
        baseComplaintOperateLogDO.setOperateType("投诉提交");
        baseComplaintOperateLogDO.setRelationCode(baseComplaintDO.getId());
        baseComplaintOperateLogDO.setCreateTime(new Date());
        baseComplaintOperateDao.save(baseComplaintOperateLogDO);
        try {
            List<BaseComplaintDoctorDO> doctorList=baseComplaintDoctorDao.findbyComplaintId(baseComplaintDO.getComplaintId());
            for (BaseComplaintDoctorDO baseComplaintDoctorDO:doctorList){
                String url="https://hlwyy.xmzsh.com/hlwyy/ims-app-web/#/complaint/detail?id="+baseComplaintDO.getId();
                enterpriseService.sendTWMesByDoctor("zsyy",baseComplaintDoctorDO.getDoctor(),"投诉反馈","您收到一条投诉反馈,点击查看。",url);
            }
        }catch (Exception e){
        }
       return baseComplaintDao.save(baseComplaintDO);
    }
    /*
     * 医生转交
     * */
    public BaseComplaintDO passTo(String id,String complaintId,String doctor,String operator,String reason){
        BaseComplaintDO baseComplaintDO = baseComplaintDao.findOne(id);
        BaseComplaintOperateLogDO baseComplaintOperateLogDO = new BaseComplaintOperateLogDO();
        String doctorName="";
        String complaitTypeName="";
        if (null!=baseComplaintDO){
            baseComplaintOperateLogDO.setOperateFrom(operator);
            baseComplaintOperateLogDO.setReason(reason);
            baseComplaintOperateLogDO.setOperateTo(doctor);
            baseComplaintOperateLogDO.setComplaintTo(complaintId);
            baseComplaintOperateLogDO.setComplaintFrom(baseComplaintDO.getComplaintId());
            baseComplaintOperateLogDO.setStatus("3");
            baseComplaintOperateLogDO.setOperateType("转交");
            baseComplaintOperateLogDO.setRelationCode(id);
            baseComplaintOperateLogDO.setCreateTime(new Date());
            baseComplaintOperateDao.save(baseComplaintOperateLogDO);
            /*BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doctor);
            if (null != baseDoctorDO) {
                doctorName=baseDoctorDO.getName();
                baseComplaintDO.setAcceptorName(doctorName);
            }
            baseComplaintDO.setAcceptor(doctor);*/
            if ("1".equalsIgnoreCase(baseComplaintDO.getStatus())){
                baseComplaintDO.setStatus("0");
            }
            baseComplaintDO.setDefaultdoctor(doctor);
            baseComplaintDO.setComplaintId(complaintId);
            baseComplaintDO.setPassto(doctor);
            BaseComplaintDictDO baseComplaintDictDO = baseComplaintDictDao.findById(complaintId);
            if (baseComplaintDictDO!=null){
                complaitTypeName=baseComplaintDictDO.getName();
                baseComplaintDO.setComplaintName(complaitTypeName);
            }
            baseComplaintDO= baseComplaintDao.save(baseComplaintDO);
            try {
                /*List<BaseComplaintDoctorDO> doctorList=baseComplaintDoctorDao.findbyComplaintId(baseComplaintDO.getComplaintId());
                for (BaseComplaintDoctorDO baseComplaintDoctorDO:doctorList)*/
                String url="https://hlwyy.xmzsh.com/hlwyy/ims-app-web/#/complaint/detail?id="+baseComplaintDO.getId();
                enterpriseService.sendTWMesByDoctor("zsyy",doctor,"投诉反馈","您收到一条投诉反馈,点击查看。",url);
            }catch (Exception e){
            }
            return baseComplaintDO;
        }
        return null;
    }
    //接受投诉
    public BaseComplaintDO doctorAccept(String id,String doctor) throws Exception{
        BaseComplaintDO baseComplaintDO = baseComplaintDao.findOne(id);
        if (baseComplaintDO!=null){
            baseComplaintDO.setStatus("1");
            BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doctor);
            if (null != baseDoctorDO) {
                baseComplaintDO.setAcceptorName(baseDoctorDO.getName());
            }
            baseComplaintDO.setAcceptor(doctor);
            baseComplaintDO.setDefaultdoctor(doctor);
            baseComplaintDO.setAcceptTime(new Date());
            baseComplaintDao.save(baseComplaintDO);
            BaseComplaintOperateLogDO baseComplaintOperateLogDO = new BaseComplaintOperateLogDO();
            baseComplaintOperateLogDO.setOperateFrom(doctor);
            baseComplaintOperateLogDO.setStatus("1");
            baseComplaintOperateLogDO.setOperateType("接受");
            baseComplaintOperateLogDO.setRelationCode(id);
            baseComplaintOperateLogDO.setCreateTime(new Date());
            baseComplaintOperateDao.save(baseComplaintOperateLogDO);
        }/*else if ("1".equalsIgnoreCase(baseComplaintDO.getStatus())){
            throw new Exception("该工单已被接受");
        }else {
            throw new Exception("该工单已被处理完成");
        }*/
        return baseComplaintDO;
    }
    //反馈投诉
    public BaseComplaintDO dealComplaint(String id,String operator,String content,String imgUrl ,String deptCode) throws  Exception{
        BaseComplaintDO baseComplaintDO = baseComplaintDao.findOne(id);
        if (baseComplaintDO!=null){
            baseComplaintDO.setDealTime(new Date());
            baseComplaintDO.setFeedBack(content);
            baseComplaintDO.setFeedImg(imgUrl);
            baseComplaintDO.setOperator(operator);
            baseComplaintDO.setDefaultdoctor(operator);
            baseComplaintDO.setStatus("2");
            BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(operator);
            if (null != baseDoctorDO) {
                baseComplaintDO.setOperatorName(baseDoctorDO.getName());
            }
            baseComplaintDO.setOperatorDept(deptCode);
            List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDeptCodeDoctorCode(deptCode, operator);
            if (baseDoctorHospitalDO != null && baseDoctorHospitalDO.size() > 0) {
                baseComplaintDO.setOperatorDeptName(baseDoctorHospitalDO.get(0).getDeptName());
            }
            baseComplaintDao.save(baseComplaintDO);
            BaseComplaintOperateLogDO baseComplaintOperateLogDO = new BaseComplaintOperateLogDO();
            baseComplaintOperateLogDO.setOperateFrom(operator);
            baseComplaintOperateLogDO.setStatus("2");
            baseComplaintOperateLogDO.setOperateType("反馈");
            baseComplaintOperateLogDO.setRelationCode(id);
            baseComplaintOperateLogDO.setCreateTime(new Date());
            baseComplaintOperateDao.save(baseComplaintOperateLogDO);
        }/*else if ("2".equalsIgnoreCase(baseComplaintDO.getStatus())){
            throw new Exception("该工单已被处理完成");
        }else if ("0".equalsIgnoreCase(baseComplaintDO.getStatus())){
            throw new Exception("该工单未被接收");
        }*/
        return baseComplaintDO;
    }
    //查询投诉列表
    public MixEnvelop findComplaintList(String role,String doctor,String status,String patientName,String patientId,String keyWord,String complaintId,
                                  String startTime,String endTime,Integer page ,Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        Boolean queryAll=false;
        if ("admin".equalsIgnoreCase(role)){
            queryAll=true;
        }
        String sql="select DISTINCT t.id as \"id\"," +
                " t.complaint_id as \"complaintId\"," +
                " t.complaint_name as \"complaintName\"," +
                " t.complaint_content as \"complaintContent\"," +
                " t.visit_type as \"visitType\"," +
                " case  t.visit_type when '1' then '门诊' else '住院' end  as \"visitTypeName\"," +
                " t.visit_time as \"visitTime\"," +
                " t.visit_dept as \"visitDept\"," +
                " t.visit_dept_name as \"visitDeptName\"," +
                " t.adm_no as \"admNo\"," +
                " t.patient as \"patient\"," +
                " t.patient_name as \"patientName\"," +
                " t.patient_idcard as \"patientIdcard\"," +
                " t.idcard_front as \"idcardFront\"," +
                " t.idcard_back as \"idcardBack\"," +
                " t.img_url as \"imgUrl\"," +
                " t.is_del as \"isDel\"," +
                " t.status as \"status\"," +
                " t.create_time as \"createTime\"," +
                " t.accept_time as \"acceptTime\"," +
                " t.deal_time as \"dealTime\"," +
                " t.operator_dept as \"operatorDept\"," +
                " t.operator_dept_name as \"operatorDeptName\"," +
                " t.operator as \"operator\"," +
                " t.operator_name as \"operatorName\"," +
                " t.feed_back as \"feedBack\"," +
                " t.feed_img as \"feedImg\"," +
                " t.acceptor as \"acceptor\"," +
                " t.mobile as \"mobile\"," +
                " t.passto as \"passto\"," +
                " t.acceptor_name as \"acceptorName\"" +
                " from base_complaint t  " +
                " left join base_patient b on t.patient=b.id " ;
        sql+=" left join base_complaint_operate_log g on t.id=g.relation_code where t.is_del='1 '";
        if (StringUtils.isNoneBlank(status)&&"3".equalsIgnoreCase(status)){
            sql+=" and  g.status='3' ";
        }/*else if (StringUtils.isNoneBlank(status)&&"1".equalsIgnoreCase(status)){
            sql+=" and  g.status='1' ";
        }
        else if (StringUtils.isNoneBlank(status)&&"2".equalsIgnoreCase(status)){
            sql+=" and  g.status='2' ";
        }*/
        if (!queryAll){
            BaseComplaintDoctorDO baseComplaintDoctorDO= baseComplaintDoctorDao.findbyDoctorAndDel(doctor);
            /*List<BaseComplaintOperateLogDO> logList =baseComplaintOperateDao.findbyOperateFrom(doctor);
            String types= "";
            if (logList!=null&&logList.size()>0){
                for (int i=0;i<logList.size();i++){
                    if (i==logList.size()-1){
                        types+=logList.get(i).getComplaintTo();
                    }else {
                        types+=logList.get(i).getComplaintTo()+",";
                    }
                }
            }*/
            String complaint="";
            if (baseComplaintDoctorDO!=null){
                if (baseComplaintDoctorDO.getComplaintId().equalsIgnoreCase("808080eb7a194099017a1943fa820004")){
                    complaint=baseComplaintDoctorDO.getComplaintId();
                }
            }
            //complaint=complaint+","+types;
            if (StringUtils.isNoneBlank(complaint)){
                if (!StringUtils.isNoneBlank(status)){
                    sql+=" and t.status !='-1'";
                    sql+=" and (t.defaultdoctor ='defalutDoctor' or t.defaultdoctor='"+doctor+"')";
                }
                if (StringUtils.isNoneBlank(status)&&"3".equalsIgnoreCase(status)){
                    sql+=" and g.operate_from='"+doctor+"'";
                }else {
                    sql+=" and t.complaint_id='"+complaint+"'";
                }
                if (!StringUtils.isNoneBlank(status)){
                    sql+=" or (g.operate_from='"+doctor+"'  and g.status='3')";
                }
                if (StringUtils.isNoneBlank(status)&&"3".equalsIgnoreCase(status)){
                    sql+=" and g.operate_from='"+doctor+"'";
                }else if (StringUtils.isNoneBlank(status)&&"0".equalsIgnoreCase(status)){
                    sql+=" and t.status='0' and (t.passto='"+doctor+"' or t.passto is null )";
                } else if (StringUtils.isNoneBlank(status)&&"1".equalsIgnoreCase(status)){
                    sql+="  and t.status='1' and t.acceptor='"+doctor+"' ";
                } else if (StringUtils.isNoneBlank(status)&&"2".equalsIgnoreCase(status)){
                    sql+=" and t.status='2' and t.operator='"+doctor+"' ";
                }
                //sql+=" and t.complaint_id in ('"+complaint.replace(",","','")+"')";
            }else {
                if (StringUtils.isNoneBlank(status)&&"3".equalsIgnoreCase(status)){
                    sql+=" and g.operate_from='"+doctor+"'";
                }else if (StringUtils.isNoneBlank(status)&&"0".equalsIgnoreCase(status)){
                    sql+=" and t.status='0' and t.passto='"+doctor+"'";
                } else if (StringUtils.isNoneBlank(status)&&"1".equalsIgnoreCase(status)){
                    sql+="  and t.status='1' and t.acceptor='"+doctor+"' ";
                } else if (StringUtils.isNoneBlank(status)&&"2".equalsIgnoreCase(status)){
                    sql+=" and t.status='2' and t.operator='"+doctor+"' ";
                } else {
                    sql+=" and t.id IN (select col.relation_code from base_complaint_operate_log col where col.operate_to = '"+doctor+"'  )";
                }
            }
            //complaint=complaint+","+types;
        }else {
            if (StringUtils.isNoneBlank(complaintId)){
                //sql+=" and t.complaint_id in ('"+complaint.replace(",","','")+"')";
                sql+=" and t.complaint_id='"+complaintId+"'";
            }
            if (StringUtils.isNoneBlank(status)){
                sql+=" and t.status ='"+status+"'";
            }
        }
        if (StringUtils.isNoneBlank(patientName)){
            sql+=" and t.patient_name like '%"+patientName+"%'";
        }
        if (StringUtils.isNoneBlank(patientId)){
            sql+=" and t.patient ='"+patientId+"'";
        }
        if (StringUtils.isNoneBlank(keyWord)){
            sql+=" and (t.patient_idcard like '%"+keyWord+"%' or t.patient_name like '%"+keyWord+"%')";
        }
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<='" + endTime + "'";
                }else {
                    sql+="  and t.create_time<= to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<='" + endTime + "'";
            }
        }
        sql+=" order by t.create_time desc ";
        System.out.println("sql"+sql);
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
    public BaseComplaintDO  findOnePaitentComplaint(String id){
        BaseComplaintDO baseComplaintDO = baseComplaintDao.findOne(id);
        BasePatientDO basePatientDO=basePatientDao.findById(baseComplaintDO.getPatient());
        if (null!=basePatientDO){
            baseComplaintDO.setMobile(basePatientDO.getMobile());
        }
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO =wlyyHospitalSysDictDao.findById("latestFeedBackTime");
        Integer timeOut=15;
        if (wlyyHospitalSysDictDO!=null){
            timeOut =Integer.parseInt(wlyyHospitalSysDictDO.getDictValue());
        }
        long latestDate=baseComplaintDO.getCreateTime().getTime()+timeOut*24*60*60*1000;
        baseComplaintDO.setLatestFeedTime( (new Date(latestDate)));
        baseComplaintDO.setVisitTypeName(baseComplaintDO.getVisitType().equalsIgnoreCase("1")?"门诊":"住院");
        return baseComplaintDO;
    }
    //查询投诉列表
    public MixEnvelop findPatientComplaintList(String status,String patientName,String patientId,
                                        String startTime,String endTime,String complaintType,Integer page ,Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql="select t.id as \"id\"," +
                " t.complaint_id as \"complaintId\"," +
                " t.complaint_name as \"complaintName\"," +
                " t.complaint_content as \"complaintContent\"," +
                " t.visit_type as \"visitType\"," +
                " case  t.visit_type when '1' then '门诊' else '住院' end  as \"visitTypeName\"," +
                " t.visit_time as \"visitTime\"," +
                " t.visit_dept as \"visitDept\"," +
                " t.visit_dept_name as \"visitDeptName\"," +
                " t.adm_no as \"admNo\"," +
                " t.patient as \"patient\"," +
                " t.patient_name as \"patientName\"," +
                " t.patient_idcard as \"patientIdcard\"," +
                " t.idcard_front as \"idcardFront\"," +
                " t.idcard_back as \"idcardBack\"," +
                " t.img_url as \"imgUrl\"," +
                " t.is_del as \"isDel\"," +
                " t.status as \"status\"," +
                " t.create_time as \"createTime\"," +
                " t.accept_time as \"acceptTime\"," +
                " t.deal_time as \"dealTime\"," +
                " t.operator_dept as \"operatorDept\"," +
                " t.operator_dept_name as \"operatorDeptName\"," +
                " t.operator as \"operator\"," +
                " t.operator_name as \"operatorName\"," +
                " t.feed_back as \"feedBack\"," +
                " t.feed_img as \"feedImg\"," +
                " t.acceptor as \"acceptor\"," +
                " t.mobile as \"mobile\"," +
                " t.acceptor_name as \"acceptorName\"" +
                " from base_complaint t " +
                " left join base_patient b on t.patient=b.id" +
                " where t.is_del='1'";
        if (StringUtils.isNoneBlank(status)){
            sql+=" and t.status ='"+status+"'";
        }
        if (StringUtils.isNoneBlank(patientName)){
            sql+=" and t.patient_name like '%"+patientName+"%'";
        }
        if (StringUtils.isNoneBlank(patientId)){
            sql+=" and t.patient ='"+patientId+"'";
        }
        if (StringUtils.isNoneBlank(complaintType)){
            sql+=" and t.complaint_id ='"+complaintType+"'";
        }
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<='" + endTime + "'";
                }else {
                    sql+="  and t.create_time<= to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<='" + endTime + "'";
            }
        }
        sql+=" order by t.create_time desc ";
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
    /*
    * 查询投诉数量*/
    public Map<String,Object> findComplaintCount(String doctor,String role){
        BaseComplaintDoctorDO baseComplaintDoctorDO=baseComplaintDoctorDao.findbyDoctorAndDel(doctor);
        Integer complaints=0;
        Integer recieve=0;
        Integer deal=0;
        Integer cacel=0;
        Integer passto=0;
        Integer total=0;
        if (baseComplaintDoctorDO!=null){
                Boolean queryAll=false;
                if ("admin".equalsIgnoreCase(role)){
                    queryAll=true;
                }
                if (!queryAll){
                    if ("808080eb7a194099017a1943fa820004".equalsIgnoreCase(baseComplaintDoctorDO.getComplaintId())) {
                        complaints = getCountByStatus(doctor,"0",role);
                        recieve = getCountByStatus(doctor,"1",role);
                        deal = getCountByStatus(doctor,"2",role);
                        passto = getCountByPassto(doctor);
                        total = getCountByStatus(doctor,"",role);
                    }else{
                        complaints=getCountByStatus(doctor,"0",role);
                        recieve=getCountByStatus(doctor,"1",role);
                        deal=getCountByStatus(doctor,"2",role);
                        passto=getCountByPassto(doctor);
                        total=getCountByStatus(doctor,"",role);
                    }
                    //cacel=baseComplaintDao.getCountByStatusAndComplaintId("-1",baseComplaintDoctorDO.getComplaintId());
                }else {
                    complaints=baseComplaintDao.getCountByStatus("0");
                    recieve=baseComplaintDao.getCountByStatus("1");
                    deal=baseComplaintDao.getCountByStatus("2");
                    cacel=baseComplaintDao.getCountByStatus("-1");
                    total = complaints+recieve+deal+cacel;
                }
        }
        Map map=new HashMap();
        map.put("complaints",complaints);
        map.put("recieve",recieve);
        map.put("deal",deal);
        map.put("passto",passto);
        map.put("cacel",cacel);
        map.put("total",total);
        return map;
    }
    public Integer getCountByPassto(String doctor){
        String sql ="select count(1) as \"total\" from (select  DISTINCT t.id   from base_complaint t left join base_complaint_operate_log b" +
                " on t.id=b.relation_code where t.is_del='1' and b.status='3'";
        if (StringUtils.isNoneBlank(doctor)){
            sql+=" and b.operate_from='"+doctor+"'";
        }
        sql+=") m";
        List<Map<String,Object>> listcount=hibenateUtils.createSQLQuery(sql);
        Integer count=0;
        if (listcount!=null&&listcount.size()>0){
            count=Integer.valueOf(listcount.get(0).get("total").toString());
        }
        return count;
    }
    public Integer getCountByStatus(String doctor,String status,String role){
        Boolean queryAll=false;
        if ("admin".equalsIgnoreCase(role)){
            queryAll=true;
        }
        String sql="select count(1)  as \"count\" from (select DISTINCT t.id  "+
                "  from base_complaint t  " +
                " left join base_patient b on t.patient=b.id " ;
        sql+=" left join base_complaint_operate_log g on t.id=g.relation_code where t.is_del='1' ";
        if (StringUtils.isNoneBlank(status)&&"3".equalsIgnoreCase(status)){
            sql+="  and g.status='3' ";
        } /*else if (StringUtils.isNoneBlank(status)&&"1".equalsIgnoreCase(status)){
            sql+=" and  g.status='1' ";
        }
        else if (StringUtils.isNoneBlank(status)&&"2".equalsIgnoreCase(status)){
            sql+=" and  g.status='2' ";
        }*/
        if (!queryAll){
            BaseComplaintDoctorDO baseComplaintDoctorDO= baseComplaintDoctorDao.findbyDoctorAndDel(doctor);
            /*List<BaseComplaintOperateLogDO> logList =baseComplaintOperateDao.findbyOperateFrom(doctor);
            String types= "";
            if (logList!=null&&logList.size()>0){
                for (int i=0;i<logList.size();i++){
                    if (i==logList.size()-1){
                        types+=logList.get(i).getComplaintTo();
                    }else {
                        types+=logList.get(i).getComplaintTo()+",";
                    }
                }
            }*/
            String complaint="";
            if (baseComplaintDoctorDO!=null){
                if (baseComplaintDoctorDO.getComplaintId().equalsIgnoreCase("808080eb7a194099017a1943fa820004")){
                    complaint=baseComplaintDoctorDO.getComplaintId();
                }
            }
            //complaint=complaint+","+types;
            if (StringUtils.isNoneBlank(complaint)){
                if (!StringUtils.isNoneBlank(status)){
                    sql+=" and t.status !='-1'";
                    sql+=" and (t.defaultdoctor ='defalutDoctor' or t.defaultdoctor='"+doctor+"')";
                }
                if (StringUtils.isNoneBlank(status)&&"3".equalsIgnoreCase(status)){
                    sql+=" and g.operate_from='"+doctor+"'";
                }else {
                    sql+=" and t.complaint_id='"+complaint+"'";
                }
               if (!StringUtils.isNoneBlank(status)){
                   sql+=" or (g.operate_from='"+doctor+"'  and g.status='3')";
                }
                if (StringUtils.isNoneBlank(status)&&"3".equalsIgnoreCase(status)){
                    sql+=" and g.operate_from='"+doctor+"'";
                }else if (StringUtils.isNoneBlank(status)&&"0".equalsIgnoreCase(status)){
                    sql+=" and t.status='0' and (t.passto='"+doctor+"' or t.passto is null )";
                } else if (StringUtils.isNoneBlank(status)&&"1".equalsIgnoreCase(status)){
                    sql+="  and t.status='1' and t.acceptor='"+doctor+"' ";
                } else if (StringUtils.isNoneBlank(status)&&"2".equalsIgnoreCase(status)){
                    sql+=" and t.status='2' and t.operator='"+doctor+"' ";
                }
                //sql+=" and t.complaint_id in ('"+complaint.replace(",","','")+"')";
            }else {
                if (StringUtils.isNoneBlank(status)&&"3".equalsIgnoreCase(status)){
                    sql+=" and g.operate_from='"+doctor+"'";
                }else if (StringUtils.isNoneBlank(status)&&"0".equalsIgnoreCase(status)){
                    sql+=" and t.status='0' and t.passto='"+doctor+"'";
                } else if (StringUtils.isNoneBlank(status)&&"1".equalsIgnoreCase(status)){
                    sql+="  and t.status='1' and t.acceptor='"+doctor+"' ";
                } else if (StringUtils.isNoneBlank(status)&&"2".equalsIgnoreCase(status)){
                    sql+=" and t.status='2' and t.operator='"+doctor+"' ";
                } else {
                    sql+=" and t.id IN (select col.relation_code from base_complaint_operate_log col where col.operate_to = '"+doctor+"'  )";
                }
            }
            if (!StringUtils.isNoneBlank(status)){
                sql+=" and t.status !='-1'";
            }
            //complaint=complaint+","+types;
        }
        System.out.println("sql"+sql);
        Integer count = 0;
        sql+=")g";
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sql);
        if(total!=null&&total.size()>0){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = Integer.valueOf(total.get(0).get("count").toString());
        }
        return count;
    }
    /*
     * 查询投诉数量*/
    public Map<String,Object> findComplaintCountPatient(String patient){
        Integer complaints=0;
        Integer recieve=0;
        Integer deal=0;
        Integer cacel=0;
        complaints=baseComplaintDao.getCountByStatusByPatient("0",patient);
        recieve=baseComplaintDao.getCountByStatusByPatient("1",patient);
        deal=baseComplaintDao.getCountByStatusByPatient("2",patient);
        cacel=baseComplaintDao.getCountByStatusByPatient("-1",patient);
        Integer total = complaints+recieve+deal+cacel;
        Map map=new HashMap();
        map.put("complaints",complaints);
        map.put("recieve",recieve);
        map.put("deal",deal);
        map.put("cacel",cacel);
        map.put("total",total);
        return map;
    }
    public BaseComplaintDO  cancelPaitentComplaint(String id,String patient) throws  Exception{
        BaseComplaintDO baseComplaintDO = baseComplaintDao.findOne(id);
       if (baseComplaintDO!=null){
           if ("0".equalsIgnoreCase(baseComplaintDO.getStatus())){
               baseComplaintDO.setStatus("-1");
               baseComplaintDO=baseComplaintDao.save(baseComplaintDO);
               BaseComplaintOperateLogDO baseComplaintOperateLogDO = new BaseComplaintOperateLogDO();
               baseComplaintOperateLogDO.setOperateFrom(patient);
               baseComplaintOperateLogDO.setStatus("-1");
               baseComplaintOperateLogDO.setOperateType("居民撤销投诉");
               baseComplaintOperateLogDO.setRelationCode(baseComplaintDO.getId());
               baseComplaintOperateLogDO.setCreateTime(new Date());
               baseComplaintOperateDao.save(baseComplaintOperateLogDO);
           }else {
               throw new Exception("不允许撤销");
           }
       }
       return baseComplaintDO;
    }
    public List<Map<String,Object>> findComplaintOperateLog(String complaintId){
        String sql ="select t.id as \"id\"," +
                " p.name as \"complaintNameFrom\" ," +
                " n.name as \"complaintNameto\", " +
                " t.operate_from as \"operateFrom\" ," +
                " t.reason as \"reason\" ," +
                " t.operate_to as \"operateTo\" ," +
                " t.cancel_by as \"cancelBy\", " +
                " t.operate_type as \"operateType\", " +
                " t.status as \"status\", " +
                " t.create_time as \"createTime\" ," +
                " t.relation_code as \"relationCode\" " +
                " from base_complaint_operate_log t left join base_complaint c" +
                " on t.relation_code=c.id" +
                " left join base_complaint_dict p on t.complaint_from= p.id" +
                " left join base_complaint_dict n on t.complaint_to=n.id where 1=1 " ;
        if (StringUtils.isNoneBlank(complaintId)){
            sql+=" and t.relation_code='"+complaintId+"'";
        }
        sql+=" order by t.create_time desc";
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
        List<WlyyHospitalSysDictDO> typeList=wlyyHospitalSysDictDao.findByDictName("complaintStatus");
        for (Map<String,Object> map:list){
            if (map.get("operateFrom")!=null){
                if (map.get("status")!=null){
                    for (WlyyHospitalSysDictDO wlyyHospitalSysDictDO:typeList){
                        if (map.get("status").toString().equalsIgnoreCase(wlyyHospitalSysDictDO.getDictCode())){
                            map.put("operateType",wlyyHospitalSysDictDO.getDictValue());
                        }
                    }
                    if ("0".equalsIgnoreCase(map.get("status").toString())||"-1".equalsIgnoreCase(map.get("status").toString())){
                        BasePatientDO basePatientDO = basePatientDao.findById(map.get("operateFrom").toString());
                        if (basePatientDO!=null){
                            map.put("operateFromName",basePatientDO.getName());
                        }
                    }else {
                        BaseDoctorDO baseDoctorDO= baseDoctorDao.findById(map.get("operateFrom").toString());
                        if (baseDoctorDO!=null){
                            map.put("operateFromName",baseDoctorDO.getName());
                        }
                        List<BaseDoctorHospitalDO> baseDoctorHospitalDO= baseDoctorHospitalDao.findByDoctorCode(map.get("operateFrom").toString());
                        if (baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
                            map.put("operateFromDeptName",baseDoctorHospitalDO.get(0).getDeptName());
                        }
                    }
                }
            }
            if (map.get("operateTo")!=null){
                BaseDoctorDO baseDoctorDO= baseDoctorDao.findById(map.get("operateTo").toString());
                if (baseDoctorDO!=null){
                    map.put("operateToName",baseDoctorDO.getName());
                }
                List<BaseDoctorHospitalDO> baseDoctorHospitalDO= baseDoctorHospitalDao.findByDoctorCode(map.get("operateTo").toString());
                if (baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
                    map.put("operateToDeptName",baseDoctorHospitalDO.get(0).getDeptName());
                }
            }
        }
    return list;
    }
}

+ 32 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseDictIcd10Dao.java

@ -0,0 +1,32 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseDrugDictDO;
import com.yihu.jw.entity.base.dict.BaseFrequencyDictDO;
import com.yihu.jw.entity.base.dict.DictIcd10DO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseDictIcd10Dao extends PagingAndSortingRepository<DictIcd10DO, Integer>, JpaSpecificationExecutor<DictIcd10DO> {
    List<DictIcd10DO>  findByCodeAndName(String code, String name);
    @Query("from DictIcd10DO t where t.is_del='1' and t.status ='1' order by t.createTime desc")
    List<DictIcd10DO> findByDel(Pageable pageRequest);
    @Query("select  count(1) from DictIcd10DO t where t.is_del='1' and t.status='1'")
    Integer getconuntByDel();
    @Query("from DictIcd10DO t where t.is_del='1' and t.status ='1' and t.name like %?1%  and t.code like %?2% order by t.createTime desc")
    List<DictIcd10DO> findByNameDel(String name,String code,Pageable pageRequest);
    @Query("from DictIcd10DO t where t.is_del='1' and t.status='1' and t.code=?1")
    DictIcd10DO findByCode(String code);
    @Query("from DictIcd10DO t where t.code=?1 and t.is_del='1'")
    List<DictIcd10DO>  findByIcdCode(String code);
}

+ 33 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseDrugDictDao.java

@ -0,0 +1,33 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseDrugDictDO;
import com.yihu.jw.entity.base.dict.BaseFrequencyDictDO;
import com.yihu.jw.entity.base.dict.DictJobTitleDO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseDrugDictDao  extends PagingAndSortingRepository<BaseDrugDictDO, String>, JpaSpecificationExecutor<BaseDrugDictDO> {
    @Query("from BaseDrugDictDO t where t.charge_code=?1 and t.drugname=?2 and t.dosage=?3")
    List<BaseDrugDictDO>  findByCodeAndNameAndDosage(String code,String name,String dosage);
    @Query("from BaseDrugDictDO t where t.charge_code=?1 and t.is_del='1'")
    List<BaseDrugDictDO>  findByChargeCode(String code);
    @Query("from BaseDrugDictDO t where t.is_del='1' and t.status='1' order by  t.create_time desc")
    List<BaseDrugDictDO> findByDel(Pageable pageRequest);
    @Query("select  count(1) from BaseDrugDictDO t where t.is_del='1' and t.status='1'")
    Integer getconuntByDel();
    @Query("from BaseDrugDictDO t where t.is_del='1' and t.status='1' and t.drugname like %?1%  and t.charge_code like %?2% order by  t.create_time desc")
    List<BaseDrugDictDO> findByNameDel(String name,String code ,Pageable pageRequest);
    @Query("from BaseDrugDictDO t where t.is_del='1' and t.status='1' and t.charge_code=?1")
    BaseDrugDictDO findByCode(String code);
}

+ 31 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseDrugUseDictDao.java

@ -0,0 +1,31 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseDrugDictDO;
import com.yihu.jw.entity.base.dict.BaseDrugUseDictDO;
import com.yihu.jw.entity.base.dict.DictIcd10DO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseDrugUseDictDao extends PagingAndSortingRepository<BaseDrugUseDictDO, String>, JpaSpecificationExecutor<BaseDrugUseDictDO> {
    @Query("from BaseDrugUseDictDO t where t.supply_code=?1 and t.supply_name=?2")
    List<BaseDrugUseDictDO>  findByCodeAndName(String code, String name);
    @Query("from BaseDrugUseDictDO t where t.del_flag='1' and t.status ='1' order by t.createTime desc")
    List<BaseDrugUseDictDO> findByDel(Pageable pageRequest);
    @Query("select  count(1) from BaseDrugUseDictDO t where t.del_flag='1' and t.status='1'")
    Integer getconuntByDel();
    @Query("from BaseDrugUseDictDO t where t.del_flag='1' and t.status ='1' and t.supply_name like %?1% and t.sort_code like %?2% order by t.createTime desc")
    List<BaseDrugUseDictDO> findByNameDel(String name,String code,Pageable pageRequest);
    @Query("from BaseDrugUseDictDO t where t.del_flag='1' and t.status='1' and t.supply_code=?1")
    BaseDrugUseDictDO findByCode(String code);
    @Query("from BaseDrugUseDictDO t where t.supply_code=?1 and t.del_flag='1'")
    List<BaseDrugUseDictDO>  findBySupCode(String code);
}

+ 31 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseFollowUpDictDao.java

@ -0,0 +1,31 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseDrugUseDictDO;
import com.yihu.jw.entity.base.dict.BaseFollowUpDictDO;
import com.yihu.jw.entity.base.dict.BaseFrequencyDictDO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseFollowUpDictDao extends PagingAndSortingRepository<BaseFollowUpDictDO, String>, JpaSpecificationExecutor<BaseFollowUpDictDO> {
    @Query("from BaseFollowUpDictDO t where t.code=?1 and t.name=?2")
    List<BaseFollowUpDictDO> findByCodeAndName(String code, String name);
    @Query("from BaseFollowUpDictDO t where t.isDel='1' and t.status ='1' order by t.createTime desc")
    List<BaseFollowUpDictDO> findByDel(Pageable pageRequest);
    @Query("select  count(1) from BaseFollowUpDictDO t where t.isDel='1' and t.status='1'")
    Integer getconuntByDel();
    @Query("from BaseFollowUpDictDO t where t.isDel='1' and t.status ='1' and t.name like %?1% and t.code like %?2% order by t.createTime desc")
    List<BaseFollowUpDictDO> findByNameDel(String name,String code,Pageable pageRequest);
    @Query("from BaseFollowUpDictDO t where t.isDel='1' and t.status='1' and t.code=?1")
    BaseFollowUpDictDO findByCode(String code);
    @Query("from BaseFollowUpDictDO t where t.code=?1 and t.isDel='1'")
    List<BaseFollowUpDictDO>  findBySupCode(String code);
}

+ 29 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseFrequencyDictDao.java

@ -0,0 +1,29 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseDrugUseDictDO;
import com.yihu.jw.entity.base.dict.BaseFrequencyDictDO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseFrequencyDictDao extends PagingAndSortingRepository<BaseFrequencyDictDO, String>, JpaSpecificationExecutor<BaseFrequencyDictDO> {
    @Query("from BaseFrequencyDictDO t where  t.freq_code=?1 and t.freq_name=?2")
    List<BaseFrequencyDictDO>  findByCodeAndIdName(String code, String name);
    @Query("from BaseFrequencyDictDO t where t.is_del='1' and t.status ='1' order by t.createTime desc")
    List<BaseFrequencyDictDO> findByDel(Pageable pageRequest);
    @Query("select  count(1) from BaseFrequencyDictDO t where t.is_del='1' and t.status='1'")
    Integer getconuntByDel();
    @Query("from BaseFrequencyDictDO t where t.is_del='1' and t.status ='1' and t.freq_name like %?1% and t.freq_code like %?2%  order by t.createTime desc")
    List<BaseFrequencyDictDO> findByNameDel(String name ,String code ,Pageable pageRequest);
    @Query("from BaseFrequencyDictDO t where t.is_del='1' and t.status='1' and t.freq_code=?1")
    BaseFrequencyDictDO findByCode(String code);
    @Query("from BaseFrequencyDictDO t where t.freq_code=?1 and t.is_del='1'")
    List<BaseFrequencyDictDO>  findByFrqCode(String code);
}

+ 17 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseJobCategoryDao.java

@ -0,0 +1,17 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseJobCategoryDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseJobCategoryDao extends PagingAndSortingRepository<BaseJobCategoryDO, Integer>, JpaSpecificationExecutor<BaseJobCategoryDO> {
    @Query("from BaseJobCategoryDO t where t.pid = '0' and t.del = 1")
    List<BaseJobCategoryDO> findFirstCategoryList();
    @Query("from BaseJobCategoryDO t where t.pid = ?1 and t.del = 1")
    List<BaseJobCategoryDO> findSecondCategoryList(String pid);
    @Query("from BaseJobCategoryDO t where t.name = ?1 and t.del = 1")
    BaseJobCategoryDO findByName(String name);
}

+ 12 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseJpushTemplateDao.java

@ -0,0 +1,12 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.hospital.dict.BaseDeptDict;
import com.yihu.jw.entity.hospital.dict.BaseJpushTemplateDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseJpushTemplateDao extends PagingAndSortingRepository<BaseJpushTemplateDO, String>, JpaSpecificationExecutor<BaseJpushTemplateDO> {
    @Query("from BaseJpushTemplateDO  where code = ?1 and isDel ='1'")
    BaseJpushTemplateDO findByCode(String code);
}

+ 10 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseTemplateDao.java

@ -0,0 +1,10 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseTemplateDO;
import com.yihu.jw.entity.base.dict.BaseTemplateDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseTemplateDao extends PagingAndSortingRepository<BaseTemplateDO, String>, JpaSpecificationExecutor<BaseTemplateDO> {
}

+ 23 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseTemplateDictDao.java

@ -0,0 +1,23 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseTemplateDictDO;
import com.yihu.jw.entity.base.dict.BaseTemplateOrgDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseTemplateDictDao extends PagingAndSortingRepository<BaseTemplateDictDO, String>, JpaSpecificationExecutor<BaseTemplateDictDO> {
    @Query("select  count(1) from BaseTemplateDictDO t where t.isDel = '1' and t.templateId=?1")
    Integer getCountByTemplateId(String templateId);
    @Query("from BaseTemplateDictDO t where t.dictId=?1 and t.templateId=?2")
    BaseTemplateDictDO findByDictIdAndTemplateId(String dictId,String templateId);
    @Query("from BaseTemplateDictDO t where t.templateId=?1 and t.isDel='1'")
    List<BaseTemplateDictDO> findByTemplateId(String templateId);
    @Query("from BaseTemplateDictDO t where t.dictId=?1 and t.isDel='1'")
    List<BaseTemplateDictDO> findByDictId(String dictId);
}

+ 26 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/BaseTemplateOrgDao.java

@ -0,0 +1,26 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.base.dict.BaseDrugDictDO;
import com.yihu.jw.entity.base.dict.BaseTemplateOrgDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseTemplateOrgDao extends PagingAndSortingRepository<BaseTemplateOrgDO, String>, JpaSpecificationExecutor<BaseTemplateOrgDO> {
    @Query("from BaseTemplateOrgDO t where  t.orgCode =?1 and t.templateType=?2  and t.isDel ='1'")
    BaseTemplateOrgDO findByOrgCodeAndtemplateType(String orgCode,String templateType);
    @Query("from BaseTemplateOrgDO t where  t.orgCode =?1 and t.isDel='1' ")
    List<BaseTemplateOrgDO> findByOrgCode(String saasId);
    @Query("from BaseTemplateOrgDO t where  t.templateId =?1 and t.isDel='1' ")
    List<BaseTemplateOrgDO> findByTemplateId(String templateId);
    @Query("from BaseTemplateOrgDO t where  t.templateType =?1 and t.orgCode =?2 and t.isDel='1' ")
    List<BaseTemplateOrgDO> findByTemplateType(String templateType,String orgCode);
}

+ 5 - 1
business/base-service/src/main/java/com/yihu/jw/dict/dao/DictHospitalDeptDao.java

@ -38,7 +38,8 @@ public interface DictHospitalDeptDao extends PagingAndSortingRepository<DictHosp
    List<DictHospitalDeptDO> findByOrgCodeIn(String orgCode);
    List<DictHospitalDeptDO> findByOrgCodeAndCode(String orgCode,String code);
    @Query("from DictHospitalDeptDO t where t.orgCode = ?1 and t.code = ?2")
    DictHospitalDeptDO findByOrgCodedeptCode(String orgCode,String code);
    Long countByCodeIn(String orgCode);
    boolean existsByCodeAndOrgCode(String code, String orgCode);
@ -49,4 +50,7 @@ public interface DictHospitalDeptDao extends PagingAndSortingRepository<DictHosp
    @Query("delete from DictHospitalDeptDO  where orgCode=?1")
    void deleteByOrgCode(String orgCode);
    @Query("from DictHospitalDeptDO  where usualName = ?1")
    List<DictHospitalDeptDO> findByUsuallyName(String usualName);
}

+ 18 - 0
business/base-service/src/main/java/com/yihu/jw/dict/dao/PrivateDictDao.java

@ -0,0 +1,18 @@
package com.yihu.jw.dict.dao;
import com.yihu.jw.entity.hospital.dict.PrivateDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface PrivateDictDao extends PagingAndSortingRepository<PrivateDictDO, String>, JpaSpecificationExecutor<PrivateDictDO> {
    @Query("from PrivateDictDO t where t.hospitalCode =?1 and t.dictCode= ?2 and t.isDel = 1")
    List<PrivateDictDO> findoneByCodeAndWechatId(String hospitalCode, String dictCode);
    @Query("from PrivateDictDO t where t.isDel = 1")
    List<PrivateDictDO> findALL();
    @Query("from PrivateDictDO t where t.dictCode= ?1 and t.isDel = 1")
    List<PrivateDictDO> findByDictCodeAndIsDel(String dictCode);
}

+ 37 - 0
business/base-service/src/main/java/com/yihu/jw/dict/service/DeptHomepageBannerService.java

@ -0,0 +1,37 @@
package com.yihu.jw.dict.service;
import com.yihu.jw.entity.hospital.manage.BaseDeptHomepageBannerDO;
import com.yihu.jw.entity.hospital.manage.BaseDeptHomepageBannerDO;
import com.yihu.jw.hospital.dict.BaseDeptHomepageBannerDao;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import static com.yihu.jw.util.common.BeanUtils.getNullPropertyNames;
@Service
public class DeptHomepageBannerService extends BaseJpaService<BaseDeptHomepageBannerDO, BaseDeptHomepageBannerDao> {
    @Autowired
    private BaseDeptHomepageBannerDao deptHomepageBannerDao;
    public BaseDeptHomepageBannerDO updateDeptHomepageBanner(BaseDeptHomepageBannerDO deptHomepageBannerDO) {
        //判断新增或编辑
        if (deptHomepageBannerDO.getId() == null) {
            deptHomepageBannerDO.setCreateTime(new Date());
            deptHomepageBannerDO.setDel(1);
            return deptHomepageBannerDao.save(deptHomepageBannerDO);
        } else {
            BaseDeptHomepageBannerDO oldDeptHomepageBanner = deptHomepageBannerDao.findOne(deptHomepageBannerDO.getId());
            BeanUtils.copyProperties(deptHomepageBannerDO, oldDeptHomepageBanner, getNullPropertyNames(deptHomepageBannerDO));
            return deptHomepageBannerDao.save(oldDeptHomepageBanner);
        }
    }
    public void delDeptHomepageBanner(Integer id) {
        deptHomepageBannerDao.delete(id);
    }
}

+ 63 - 0
business/base-service/src/main/java/com/yihu/jw/dict/service/DiseaseHomepageBannerService.java

@ -0,0 +1,63 @@
package com.yihu.jw.dict.service;
import com.yihu.jw.entity.hospital.manage.BaseDiseaseHomepageBannerDO;
import com.yihu.jw.hospital.dict.BaseDiseaseHomepageBannerDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import static com.yihu.jw.util.common.BeanUtils.getNullPropertyNames;
@Service
public class DiseaseHomepageBannerService extends BaseJpaService<BaseDiseaseHomepageBannerDO, BaseDiseaseHomepageBannerDao> {
    @Autowired
    private BaseDiseaseHomepageBannerDao diseaseHomepageBannerDao;
    public BaseDiseaseHomepageBannerDO updateDiseaseHomepageBanner(BaseDiseaseHomepageBannerDO diseaseHomepageBannerDO) {
        //判断新增或编辑
        if (diseaseHomepageBannerDO.getId() == null) {
            diseaseHomepageBannerDO.setCreateTime(new Date());
            diseaseHomepageBannerDO.setDel(1);
            return diseaseHomepageBannerDao.save(diseaseHomepageBannerDO);
        } else {
            BaseDiseaseHomepageBannerDO oldDiseaseHomepageBanner = diseaseHomepageBannerDao.findOne(diseaseHomepageBannerDO.getId());
            BeanUtils.copyProperties(diseaseHomepageBannerDO, oldDiseaseHomepageBanner, getNullPropertyNames(diseaseHomepageBannerDO));
            return diseaseHomepageBannerDao.save(oldDiseaseHomepageBanner);
        }
    }
    public void delDiseaseHomepageBanner(Integer id) {
        diseaseHomepageBannerDao.delete(id);
    }
    public MixEnvelop findDiseaseHomepageBanner(Integer id, String name, Integer page, Integer pageSize) throws Exception {
        MixEnvelop mixEnvelop = new MixEnvelop();
        String filters = "";
        if (id != null) {
            filters += "id=" + id + ";";
        }else {
            if (StringUtils.isNotBlank(name)) {
                filters += "name?" + name + ";";
            }
        }
        Integer count = this.search(null, filters, null).size();
        List<BaseDiseaseHomepageBannerDO> list;
        if(page!= null && pageSize!=null) {
            list = this.search(null, filters, null, page, pageSize);
        }else {
            list = this.search(null, filters, null);
        }
        mixEnvelop.setMessage("获取成功!");
        mixEnvelop.setCurrPage(page);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setTotalCount(count);
        mixEnvelop.setDetailModelList(list);
        return mixEnvelop;
    }
}

+ 123 - 0
business/base-service/src/main/java/com/yihu/jw/dict/service/FollowUpDictService.java

@ -0,0 +1,123 @@
package com.yihu.jw.dict.service;
import com.yihu.jw.dict.dao.BaseFollowUpDictDao;
import com.yihu.jw.dict.dao.BaseTemplateDictDao;
import com.yihu.jw.entity.base.dict.BaseDrugUseDictDO;
import com.yihu.jw.entity.base.dict.BaseFollowUpDictDO;
import com.yihu.jw.entity.base.dict.BaseTemplateDictDO;
import com.yihu.jw.entity.hospital.manage.BaseDiseaseHomepageBannerDO;
import com.yihu.jw.hospital.dict.BaseDiseaseHomepageBannerDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.yihu.jw.util.common.BeanUtils.getNullPropertyNames;
@Service
public class FollowUpDictService extends BaseJpaService<BaseFollowUpDictDO, BaseFollowUpDictDao> {
    @Autowired
    private BaseFollowUpDictDao baseFollowUpDictDao;
    @Autowired
    private BaseTemplateDictDao baseTemplateDictDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    public void saveFollowUp(BaseFollowUpDictDO baseFollowUpDictDO) throws  Exception{
        BaseFollowUpDictDO baseDrugUseDictDO1=baseFollowUpDictDao.findByCode(baseFollowUpDictDO.getCode());
        if (baseDrugUseDictDO1!=null&&StringUtils.isNotBlank(baseDrugUseDictDO1.getId())){
            if (baseDrugUseDictDO1!=null){
                throw  new Exception("该随访code已存在");
            }
            BaseFollowUpDictDO oldfollow= baseFollowUpDictDao.findOne(baseFollowUpDictDO.getId());
            BeanUtils.copyProperties(baseFollowUpDictDO, oldfollow, getNullPropertyNames(baseFollowUpDictDO));
            baseFollowUpDictDao.save(oldfollow);
        }else {
            if (baseDrugUseDictDO1!=null){
                if (!baseDrugUseDictDO1.getId().equalsIgnoreCase(baseFollowUpDictDO.getId())){
                    throw  new Exception("该随访code已存在");
                }
            }
            baseFollowUpDictDO.setCreateTime(new Date());
            baseFollowUpDictDO.setIsDel("1");
            baseFollowUpDictDao.save(baseFollowUpDictDO);
        }
    }
    public MixEnvelop findList(String name, String status, Integer page , Integer pageSize){
        String sql="select t.id as \"id\"," +
                " t.code as \"code\"," +
                " t.name as \"name\"," +
                " t.is_required as \"isRequired\"," +
                " t.project_content as \"project_content\"," +
                " t.status as \"status\"," +
                " t.is_del as \"is_del\"," +
                " t.create_time as \"create_time\"," +
                " t.create_user as \"create_user\"," +
                " t.create_user_name as \"create_user_name\"" +
                "from base_follow_up_dict t " +
                " where t.is_del='1'";
        String sqlCount =" select count(1) as \"count\" from base_follow_up_dict t where t.is_del='1'";
        if (StringUtils.isNoneBlank(name)){
            sql+=" and t.name like '%"+name+"%'";
            sqlCount+=" and t.name like '%"+name+"%'";
        }
        if (StringUtils.isNoneBlank(status)){
            sql+=" and t.status ='"+status+"'";
            sqlCount+=" and t.status ='"+status+"'";
        }
        List<Map<String,Object>> list=hibenateUtils.createSQLQuery(sql,page,pageSize);
        for (Map<String,Object> map:list){
            if (map.get("status")!=null&&"1".equalsIgnoreCase(map.get("status").toString())){
                map.put("statusName","生效中");
            }else {
                map.put("statusName","已失效");
            }
            if (map.get("isRequired")!=null&&"1".equalsIgnoreCase(map.get("isRequired").toString())){
                map.put("requiredName","必填");
            }else {
                map.put("requiredName","非必填");
            }
        }
        List<Map<String,Object>> countList=hibenateUtils.createSQLQuery(sqlCount);
        Integer count=0;
        if (countList!=null&&countList.size()>0) {
            count = Integer.valueOf(countList.get(0).get("count").toString());
        }
        MixEnvelop mixEnvelop = new MixEnvelop();
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setTotalCount(count);
        return mixEnvelop;
    }
    public BaseFollowUpDictDO findOneDict(String dictId){
        return baseFollowUpDictDao.findOne(dictId);
    }
    public void updateFollowUpStatus(String id,String status,String del) throws  Exception{
        BaseFollowUpDictDO baseFollowUpDictDO = baseFollowUpDictDao.findOne(id);
        if (baseFollowUpDictDO!=null){
            if (StringUtils.isNoneBlank(status)){
                baseFollowUpDictDO.setStatus(status);
            }
            if (StringUtils.isNoneBlank(del)){
                baseFollowUpDictDO.setIsDel(del);
                List<BaseTemplateDictDO> baseTemplateDictDO = baseTemplateDictDao.findByDictId(id);
                if (baseTemplateDictDO!=null&&baseTemplateDictDO.size()>0){
                    throw  new Exception("该使用方式已存在现有模板之中不允许删除");
                }
            }
            baseFollowUpDictDao.save(baseFollowUpDictDO);
        }
    }
}

+ 71 - 0
business/base-service/src/main/java/com/yihu/jw/dict/service/PrivateDictService.java

@ -0,0 +1,71 @@
package com.yihu.jw.dict.service;
import com.yihu.jw.dict.dao.PrivateDictDao;
import com.yihu.jw.entity.hospital.dict.PrivateDictDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import com.yihu.jw.hospital.message.dao.BaseBannerDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
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;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PrivateDictService extends BaseJpaService<PrivateDictDO, PrivateDictDao> {
    @Autowired
    private PrivateDictDao privateDictDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    //查找隐私策略
    public List<PrivateDictDO> findByHospitalCodeAndDictCode(String dictCode){
        return privateDictDao.findByDictCodeAndIsDel(dictCode);
        /*if (StringUtils.isNotBlank(dictCode)){
            return privateDictDao.findoneByCode(dictCode);
        }else {
            return privateDictDao.findALL();
        }*/
    }
    //添加隐私策略
    public MixEnvelop addPrivateDict(String id,String dictCode,String dictName, String dictValue,String hospitalCode,String hospitalName,String imgUrl){
        PrivateDictDO  privateDictDO = new PrivateDictDO();
        MixEnvelop mixEnvelop = new MixEnvelop();
        if (StringUtils.isNotBlank(id)){
            privateDictDO = privateDictDao.findOne(id);
        }
        if (StringUtils.isNotBlank(dictCode)){
            privateDictDO.setDictCode(dictCode);
            privateDictDO.setDictValue(dictValue);
            privateDictDO.setDictName(dictName);
            privateDictDO.setIsDel(1);
            privateDictDO.setHospitalCode(hospitalCode);
            privateDictDO.setHospitalName(hospitalName);
            privateDictDO.setImgUrl(imgUrl);
            privateDictDao.save(privateDictDO);
            mixEnvelop.setMessage("success");
            mixEnvelop.setStatus(200);
        }else{
            mixEnvelop.setMessage("隐私政策code不能为空");
            mixEnvelop.setStatus(-1);
        }
        return mixEnvelop;
    }
    //删除隐私政策
    public MixEnvelop deleteById(String id){
        PrivateDictDO  privateDictDO = privateDictDao.findOne(id);
        MixEnvelop mixEnvelop = new MixEnvelop();
        if (null!=privateDictDO){
            privateDictDao.delete(id);
            mixEnvelop.setStatus(200);
            mixEnvelop.setMessage("删除成功");
        }else {
            mixEnvelop.setStatus(-1);
            mixEnvelop.setMessage("删除失败");
        }
        return mixEnvelop;
    }
}

+ 17 - 0
business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorDao.java

@ -39,4 +39,21 @@ public interface BaseDoctorDao extends PagingAndSortingRepository<BaseDoctorDO,
    void updateStatus(String doctorId,String status);
    List<BaseDoctorDO> findByIdcard(String idcard);
    @Query("from BaseDoctorDO d where d.name = ?1 AND d.del ='1'")
    BaseDoctorDO findByNameAndDel(String name);
    @Query("from BaseDoctorDO d where d.idcard = ?1 AND d.del ='1'")
    BaseDoctorDO findByIdcardAndDel(String id);
    @Query("from BaseDoctorDO d where d.mobile = ?1")
    List<BaseDoctorDO> findByMobile(String id);
    @Query("from BaseDoctorDO d where d.yktDoctorId = ?1 AND d.del ='1'")
    BaseDoctorDO findByYktDoctorId(String yktDoctorId);
    @Query("from BaseDoctorDO d where d.idcard = ?1 AND d.del ='1'")
    BaseDoctorDO findByIdcardAndId(String idcard);
    @Query("SELECT d from BaseDoctorDO d,BaseTeamMemberDO te where d.id = te.doctorCode and te.del='1' AND d.del ='1' and te.teamCode in (?1) ")
    List<BaseDoctorDO> findDoctorsByTeam(List<String> teams);
}

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

@ -15,14 +15,18 @@ public interface BaseDoctorHospitalDao extends PagingAndSortingRepository<BaseDo
    List<BaseDoctorHospitalDO> findByDeptCodeAndDoctorCode(String deptCode, String doctorCode);
    @Query("select id from BaseDoctorHospitalDO where doctorCode = ?1")
    @Query("select id from BaseDoctorHospitalDO where doctorCode = ?1 and del=1")
    Set<Object> findIdListByOrgCodeAndDoctorCode(String doctorCode);
    @Query(value = "select org_code as orgCode,org_name as orgName,doctor_duty_code as doctorDutyCode ,doctor_duty_name as doctorDutyName from base_doctor_hospital where doctor_code = ?1 GROUP BY orgCode ORDER BY orgName DESC",nativeQuery = true)
    List<Map<String,Object>> getOrgAndDutyByDoctorCode(String doctorCode);
    @Query("select bdo from BaseDoctorHospitalDO bdo where bdo.doctorCode = ?1 and bdo.del=1")
    List<BaseDoctorHospitalDO> findByDoctorCode(String doctorCode);
    @Query("select bdo from BaseDoctorHospitalDO bdo where bdo.doctorCode = ?1 and bdo.del=1 group by bdo.orgCode")
    List<BaseDoctorHospitalDO> findDistinctOrgByDoctorCode(String doctorCode);
    List<BaseDoctorHospitalDO> findByOrgCode(String orgCode);
@ -30,4 +34,15 @@ public interface BaseDoctorHospitalDao extends PagingAndSortingRepository<BaseDo
    @Query("select bdo from BaseDoctorHospitalDO bdo where bdo.orgCode=?1 and bdo.deptCode=?2 and bdo.doctorCode = ?3 and bdo.del=1")
    List<BaseDoctorHospitalDO> findByOrgCodeAndDeptCodeAndDoctorCode(String orgCode,String deptCode,String doctorCode);
    @Query("select bdo from BaseDoctorHospitalDO bdo where bdo.orgCode=?1 and bdo.deptCode=?2 and bdo.doctorCode = ?3 and bdo.del=1")
    BaseDoctorHospitalDO findByOrgCodeAndDeptCodeAndDoctorCodeOnly(String orgCode,String deptCode,String doctorCode);
    List<BaseDoctorHospitalDO> findByOrgCodeAndDeptCodeAndDel(String orgCode,String deptCode,String del);
    @Query("select bdo from BaseDoctorHospitalDO bdo where bdo.deptCode = ?1 and bdo.doctorCode=?2 and bdo.del=1")
    List<BaseDoctorHospitalDO> findByDeptCodeDoctorCode(String dept,String doctorCode);
}

+ 29 - 0
business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorMessageDao.java

@ -0,0 +1,29 @@
package com.yihu.jw.doctor.dao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorMessageDO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
 *
 *
 * </pre>
 * @since 1.
 */
@Transactional
public interface BaseDoctorMessageDao extends PagingAndSortingRepository<BaseDoctorMessageDO, String>, JpaSpecificationExecutor<BaseDoctorMessageDO>  {
    @Query("from BaseDoctorMessageDO d where  d.del ='1' and d.doctor=?1 ")
    List<BaseDoctorMessageDO> findByDoctorAndDel(String doctor,Pageable pageRequest);
    @Query("from BaseDoctorMessageDO d where  d.del ='1' and d.id=?1 ")
    BaseDoctorMessageDO findByIdAndDel(String id);
}

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

@ -30,4 +30,6 @@ public interface BaseDoctorRoleDao extends PagingAndSortingRepository<BaseDoctor
    Set<Object> findIdListByDoctorCode(String doctorCode);
    List<BaseDoctorRoleDO> findByDoctorCode(String doctorCode);
    @Query("from BaseDoctorRoleDO where doctorCode = ?1 and roleCode = ?2")
    BaseDoctorRoleDO findByDoctorCodeAndroleCode(String doctorCode,String roleCode);
}

+ 9 - 0
business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorSuggestDao.java

@ -0,0 +1,9 @@
package com.yihu.jw.doctor.dao;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorSuggestDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseDoctorSuggestDao  extends PagingAndSortingRepository<BaseDoctorSuggestDO, String>, JpaSpecificationExecutor<BaseDoctorSuggestDO> {
}

+ 267 - 32
business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorInfoService.java

@ -1,16 +1,28 @@
package com.yihu.jw.doctor.service;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.deser.Deserializers;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
import com.yihu.jw.doctor.dao.DoctorSpecialDiseaseDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.jw.entity.base.doctor.DoctorSpecialDiseaseDo;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.dict.WlyyChargeDictDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDoctorDO;
import com.yihu.jw.hospital.dict.WlyyChargeDictDao;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.hospital.ykyy.service.YkyyService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.utils.security.MD5;
@ -18,17 +30,16 @@ 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.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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;
import java.util.*;
@Service
public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoctorDao> {
@ -47,8 +58,17 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
    private StringRedisTemplate redisTemplate;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Autowired
    private BaseDoctorRoleDao baseDoctorRoleDao;
    @Autowired
    private WlyyChargeDictDao wlyyChargeDictDao;
    @Value("${wechat.id}")
    private String wechatId;
    @Autowired
    private HttpClientUtil httpClientUtil;
    private static String yktUrl_90 = "http://www.yanketong.com:90/";
    @Autowired
    private DoctorMappingDao doctorMappingDao;
    /**
     * 查询医生信息分页列表.
     * @param city
@ -65,7 +85,7 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
                " 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 (SELECT * FROM wlyy_charge_dict t WHERE t.dept_type_code ='6' and t.is_del='1' ) e ON a.charge_type = e.charge_type " +
                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
                " WHERE " +
                " 1 = 1";
@ -83,7 +103,7 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
        }
        if (StringUtils.isNotBlank(name)){
            name = "%"+name+"%";
            sqlTotal += " AND (a.name like:name or b.dept_name like:name)";
            sqlTotal += " AND (a.name like:name or b.dept_name like:name or c.mapping_code like :name)";
            params.put("name",name);
        }
        if (StringUtils.isNotBlank(type)){
@ -114,11 +134,31 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
                " a.outpatient_type AS \"outpatientType\", " +
                " a.del AS \"del\", " +
                " b.dept_name AS \"deptName\", " +
                " e.req_fee AS \"money\" " +
                " e.req_fee AS \"money\", " +
                " a.charge_type as \"chargeType\", "+
                " c.mapping_code as \"mappingCode\", "+
                "\tm.req_fee as \"twfzFee\",\n" +
                "\tn.req_fee as \"spfzFee\",\n" +
                "\tp.req_fee as \"spzxFee\",\n" +
                "\tv.req_fee as \"twzxFee\",\n" +
                "\td.req_fee as \"xtzxFee\",\n" +
                "\tg.req_fee as \"jyzxFee\",\n" +
                "\tm.charge_type as \"twfzType\",\n" +
                "\tn.charge_type as \"spfzType\",\n" +
                "\tp.charge_type as \"spzxType\",\n" +
                "\tv.charge_type as \"twzxType\",\n" +
                "\td.charge_type as \"xtzxType\",\n" +
                "\tg.charge_type as \"jyzxType\"\n" +
                " 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 (SELECT * FROM wlyy_charge_dict t WHERE t.dept_type_code ='6' and t.is_del='1') e ON a.charge_type = e.charge_type " +
                " LEFT JOIN wlyy_charge_dict m ON a.twfz_charge_type = m.charge_type and m.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict n ON a.spfz_charge_type = n.charge_type and n.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict p ON a.spzx_charge_type = p.charge_type and p.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict v ON a.twzx_charge_type = v.charge_type and v.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict d ON a.xtfz_charge_type = d.charge_type and d.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict g ON a.jyzx_charge_type = g.charge_type and g.is_del='1'\n" +
                " LEFT JOIN base_doctor_mapping c ON a.id = c.doctor " +
                " WHERE 1=1";
        if (StringUtils.isNotBlank(city)){
@ -131,7 +171,7 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
            sql += " AND a.del =:status";
        }
        if (StringUtils.isNotBlank(name)){
            sql += " AND (a.name like:name or b.dept_name like:name)";
            sql += " AND (a.name like:name or b.dept_name like:name or c.mapping_code like:name)";
        }
        if (StringUtils.isNotBlank(type)){
            sql += " AND a.outpatient_type like:type";
@ -146,7 +186,6 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
        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);
    }
@ -169,13 +208,33 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
                " c.mapping_code AS \"jobNumber\", " +
                " d.disease_name AS \"diseaseName\", " +
                " d.disease_code AS \"diseaseCode\", " +
                " e.req_fee AS \"money\" " +
                " e.req_fee AS \"money\" ," +
                " h.dept_type_code AS \"deptTypeCode\" ," +
                "\tm.req_fee as \"twfzFee\",\n" +
                "\tn.req_fee as \"spfzFee\",\n" +
                "\tp.req_fee as \"spzxFee\",\n" +
                "\tv.req_fee as \"twzxFee\",\n" +
                "\tq.req_fee as \"xtzxFee\",\n" +
                "\tg.req_fee as \"jyzxFee\",\n" +
                "\tm.charge_type as \"twfzType\",\n" +
                "\tn.charge_type as \"spfzType\",\n" +
                "\tp.charge_type as \"spzxType\",\n" +
                "\tv.charge_type as \"twzxType\",\n" +
                "\tq.charge_type as \"xtzxType\",\n" +
                "\tg.charge_type as \"jyzxType\"\n" +
                " 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 dict_hospital_dept h ON b.dept_code = h.code " +
                " 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 " +
                " LEFT JOIN wlyy_charge_dict m ON a.twfz_charge_type = m.charge_type and m.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict n ON a.spfz_charge_type = n.charge_type and n.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict p ON a.spzx_charge_type = p.charge_type and p.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict v ON a.twzx_charge_type = v.charge_type and v.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict q ON a.xtfz_charge_type = q.charge_type and q.is_del='1'\n" +
                " LEFT JOIN wlyy_charge_dict g ON a.jyzx_charge_type = g.charge_type and g.is_del='1'\n" +
                " WHERE 1=1 ";
        if(StringUtils.isNotBlank(doctorId)){
            sql+=" AND a.id =:id";
@ -197,11 +256,16 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
            }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"));
                        if (list.get(i).get("diseaseName")!=null){
                            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"));
                        if (list.get(i).get("diseaseName")!=null){
                            disease.append(","+list.get(i).get("diseaseName"));
                            code.append(","+list.get(i).get("diseaseCode"));
                        }
                    }
                }
                list.get(0).put("diseaseName",disease);
@ -226,7 +290,6 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
        }
        return true;
    }
    /**
     * 修改医生服务配置
     * @param jsonObject
@ -240,7 +303,68 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
        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);
        BaseDoctorDO doctorDO = baseDoctorDao.findOne(doctorId);
        if (doctorDO!=null){
            doctorDO.setIntroduce(introduce);
            doctorDO.setExpertise(expertise);
            doctorDO.setPhoto(photo);
            if(StringUtils.isNoneBlank(outpatientType)){
                doctorDO.setOutpatientType(outpatientType);
            }else {
                doctorDO.setOutpatientType(null);
            }
            if (StringUtils.isNoneBlank(jsonObject.get("TWZXFee")==null?"":jsonObject.get("TWZXFee").toString())){
                String chargeType = findOrCreateChargeType(jsonObject.get("TWZXFee").toString(),doctorDO.getName());
                doctorDO.setTwzxChargeType(chargeType);
            }else {
                if (jsonObject.get("TWZXType")!=null) {
                    doctorDO.setTwzxChargeType(jsonObject.get("TWZXType").toString());
                }
            }
            if (StringUtils.isNoneBlank(jsonObject.get("SPZXFee")==null?"":jsonObject.get("SPZXFee").toString())){
                String chargeType = findOrCreateChargeType(jsonObject.get("SPZXFee").toString(),doctorDO.getName());
                doctorDO.setSpzxChargeType(chargeType);
            }else {
                if (jsonObject.get("SPZXType")!=null) {
                    doctorDO.setSpzxChargeType(jsonObject.get("SPZXType").toString());
                }
            }
            if (StringUtils.isNoneBlank(jsonObject.get("TWFZFee")==null?"":jsonObject.get("TWFZFee").toString())){
                String chargeType = findOrCreateChargeType(jsonObject.get("TWFZFee").toString(),doctorDO.getName());
                doctorDO.setTwfzChargeType(chargeType);
            }else {
                if (jsonObject.get("TWFZType")!=null){
                    doctorDO.setTwfzChargeType(jsonObject.get("TWFZType").toString());
                }
            }
            if (StringUtils.isNoneBlank(jsonObject.get("SPFZFee")==null?"":jsonObject.get("SPFZFee").toString())){
                String chargeType = findOrCreateChargeType(jsonObject.get("SPFZFee").toString(),doctorDO.getName());
                doctorDO.setSpfzChargeType(chargeType);
            }else {
                if (jsonObject.get("SPFZType")!=null){
                    doctorDO.setSpfzChargeType(jsonObject.get("SPFZType").toString());
                }
            }
            if (StringUtils.isNoneBlank(jsonObject.get("JYZXFee")==null?"":jsonObject.get("JYZXFee").toString())){
                String chargeType = findOrCreateChargeType(jsonObject.get("JYZXFee").toString(),doctorDO.getName());
                doctorDO.setJyzxChargeType(chargeType);
            }else {
                if (jsonObject.get("JYZXType")!=null){
                    doctorDO.setJyzxChargeType(jsonObject.get("JYZXType").toString());
                }
            }
            if (StringUtils.isNoneBlank(jsonObject.get("XTFZFee")==null?"":jsonObject.get("XTFZFee").toString())){
                String chargeType = findOrCreateChargeType(jsonObject.get("XTFZFee").toString(),doctorDO.getName());
                doctorDO.setXtfzChargeType(chargeType);
            }else {
                if (jsonObject.get("XTFZType")!=null){
                    doctorDO.setXtfzChargeType(jsonObject.get("XTFZType").toString());
                }
            }
        }
        //baseDoctorDao.update(doctorId,introduce,expertise,photo,outpatientType);
        baseDoctorDao.save(doctorDO);
        //删除医生旧专病门诊,保存新专病门诊
        Map<String,Object> params = new HashedMap();
        String sqlTotal ="SELECT " +
@ -294,25 +418,87 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
    public void updateStatus(String doctorId,String status)throws Exception{
        baseDoctorDao.updateStatus(doctorId,status);
    }
    /**修改眼科通密码信息
     *
     * @param doctorId
     * @param password
     * @param oldpassword
     * @return
     */
    public String resetYktPwdByPwd(String doctorId,String password,String oldpassword,String vercode){
        String response="";
        Map headermap = new HashMap();
        headermap.put("verifyCode",vercode);
        String url = yktUrl_90+"api/share/PasswordReset?doctorId="+doctorId+"&password="+password+"&oldpassword="+oldpassword;
        logger.info("url"+url);
        response = httpClientUtil.get(url,"utf-8",headermap);
        logger.info("修改眼科同密码后的信息:"+response);
        return response;
    }
/*    public static void main(String[] args) {
        String salt = "ssdq1";
        String pw6 = "250037";
        String pw = MD5.md5Hex(pw6 + "{" + salt + "}");
        System.out.println(pw);
    }*/
    public Boolean updateDoctorPw(String id,String pw,String orgPw){
        BaseDoctorDO doctorDO = baseDoctorDao.findOne(id);
        if("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
            BaseDoctorDO doctorDOs = baseDoctorDao.findById(id);
            String res = "";
            if (null!=doctorDOs){
                res =resetYktPwdByPwd(doctorDOs.getYktDoctorId(),pw,orgPw,doctorDOs.getVerifyCode());
            }
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(res)) {
                com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(res);
                if (object.getString("code").equalsIgnoreCase("10000")) {
                    return true;
                } else {
                    return false;
                }
            }else {
                return false;
            }
        }else if ("xm_zsyy_wx".equalsIgnoreCase(wechatId)){
            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);
            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);
            baseDoctorDao.save(doctorDO);
        //设置更新时间
        saveDoctorPwlimitDate(id);
            //设置更新时间
            saveDoctorPwlimitDate(id);
            return true;
        }else {
            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;
        }
        return true;
    }
    public String randomString(int length) {
@ -372,4 +558,53 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
        List<BaseDoctorDO> doctors = baseDoctorDao.findByIdcard(idcard);
        return doctors;
    }
    public BaseDoctorDO popularityIncrease(String doctor){
        BaseDoctorDO baseDoctorDO=baseDoctorDao.findById(doctor);
        if (null!=baseDoctorDO){
            baseDoctorDO.setPopularity(null==baseDoctorDO.getPopularity()?1:baseDoctorDO.getPopularity()+1);
        }
        baseDoctorDO = baseDoctorDao.save(baseDoctorDO);
        return baseDoctorDO;
    }
    public List<Map<String,Object>> selectByGuidance(){
        String sql = "SELECT dr.id as \"id\",dr.doctor_code as \"doctor_code\",dr.role_code as \"role_code\" FROM base_doctor_role dr where dr.role_code='guidance' " +
                "and dr.doctor_code IN(SELECT d.id FROM base_doctor d " +
                "where d.consult_status=1 and d.locked=0 and d.enabled=1)  ";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    public String findOrCreateChargeType(String fee,String doctorName){
        if (StringUtils.isNoneBlank(fee)){
            double chargeFee = Double.parseDouble(fee);
            WlyyChargeDictDO wlyyChargeDictDO = wlyyChargeDictDao.findByReqFee(chargeFee);
            if (null!=wlyyChargeDictDO){
                return wlyyChargeDictDO.getChargeType();
            }else {
                wlyyChargeDictDO = new WlyyChargeDictDO();
                wlyyChargeDictDO.setCreateTime(new Date());
                wlyyChargeDictDO.setReqFee(chargeFee);
                wlyyChargeDictDO.setChargeType(fee+"");
                wlyyChargeDictDO.setIsDel("1");
                wlyyChargeDictDO.setChargeName(doctorName+"创建的号别");
                wlyyChargeDictDO = wlyyChargeDictDao.save(wlyyChargeDictDO);
                return  wlyyChargeDictDO.getChargeType();
            }
        }else {
            return "";
        }
    }
    public List<WlyyChargeDictDO> findChargeDicts(){
        List<WlyyChargeDictDO> wlyyChargeDictDOS =  wlyyChargeDictDao.findByDeptTypeCode("6");
        return wlyyChargeDictDOS;
    }
    public void deleteChargeDict(String id,String del){
        WlyyChargeDictDO wlyyChargeDictDO =  wlyyChargeDictDao.findOne(id);
        if (wlyyChargeDictDO!=null){
            wlyyChargeDictDO.setIsDel(del);
            wlyyChargeDictDao.save(wlyyChargeDictDO);
        }
    }
}

+ 156 - 0
business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorSuggestService.java

@ -0,0 +1,156 @@
package com.yihu.jw.doctor.service;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorSuggestDao;
import com.yihu.jw.doctor.dao.DoctorSpecialDiseaseDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorSuggestDO;
import com.yihu.jw.entity.base.doctor.DoctorSpecialDiseaseDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
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;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class BaseDoctorSuggestService  extends BaseJpaService<BaseDoctorSuggestDO, BaseDoctorSuggestDao> {
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private BasePatientDao basePatientDao;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private BaseDoctorSuggestDao baseDoctorSuggestDao;
    @Value("${wechat.id}")
    private String wxId;
    @Value("${wechat.flag}")
    private boolean flag;
    public void saveDoctorSuggest(String suggestType,String  suggestContent,String  imgUrl,String doctor,String createUser,String relationCode,String relationType) throws  Exception{
        BaseDoctorSuggestDO baseDoctorSuggestDO=new BaseDoctorSuggestDO();
        baseDoctorSuggestDO.setCreateUser(createUser);
        baseDoctorSuggestDO.setSuggestType(suggestType);
        baseDoctorSuggestDO.setSuggestContent(suggestContent);
        baseDoctorSuggestDO.setImgUrl(imgUrl);
        baseDoctorSuggestDO.setRelationCode(relationCode);
        baseDoctorSuggestDO.setRelationType(relationType);
        baseDoctorSuggestDO.setDoctor(doctor);
        baseDoctorSuggestDO.setCreateTime(new Date());
        baseDoctorSuggestDO.setIsDel("1");
        BasePatientDO basePatientDO=basePatientDao.findById(baseDoctorSuggestDO.getCreateUser());
        if (basePatientDO!=null){
            baseDoctorSuggestDO.setCreateUserName(basePatientDO.getName());
        }
        BaseDoctorDO baseDoctorDO=baseDoctorDao.findById(baseDoctorSuggestDO.getDoctor());
        if (baseDoctorDO!=null){
            baseDoctorSuggestDO.setDoctorName(baseDoctorDO.getName());
        }
        List<WlyyHospitalSysDictDO> list =wlyyHospitalSysDictDao.findByDictName("doctorSuggestType");
        for (WlyyHospitalSysDictDO wlyyHospitalSysDictDO:list){
            if (baseDoctorSuggestDO.getSuggestType().equalsIgnoreCase(wlyyHospitalSysDictDO.getDictCode())){
                baseDoctorSuggestDO.setSuggestName(wlyyHospitalSysDictDO.getDictValue());
            }
        }
        baseDoctorSuggestDao.save(baseDoctorSuggestDO);
    }
    public MixEnvelop findDoctorSuggest(String doctor,String patient,String doctorName,String patientName,String startTime,String endTime,
                                        String suggestType,String relationType,String keyWord,Integer page,Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\"," +
                "t.suggest_type as \"suggestType\"," +
                "t.suggest_name as \"suggestName\"," +
                "t.suggest_content as \"suggestContent\"," +
                "t.relation_code as \"relationCode\"," +
                "t.relation_type as \"relationType\"," ;
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
            }else {
                sql+="  to_char(t.create_time,'yyyy-MM-dd HH24:mi:ss') as \"createTime\",";
            }
        }else{
            sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
        }
        sql+= "t.create_user as \"createUser\"," +
                "t.create_user_name as \"createUserName\"," +
                "t.doctor as \"doctor\"," +
                "t.doctor_name as \"doctorName\"," +
                "t.is_del as \"isDel\"," +
                "t.img_url as \"imgUrl\"" +
                "from base_doctor_suggest t where t.is_del ='1'";
        if (StringUtils.isNoneBlank(doctor)){
            sql+=" and t.doctor='"+doctor+"'";
        }
        if (StringUtils.isNoneBlank(patient)){
            sql+=" and t.create_user='"+patient+"'";
        }
        if (StringUtils.isNoneBlank(doctorName)){
            sql+=" and t.doctor_name like '%"+doctorName+"%'";
        }
        if (StringUtils.isNoneBlank(patientName)){
            sql+=" and t.create_user_name like '%"+patientName+"%'";
        }if (StringUtils.isNoneBlank(suggestType)){
            sql+=" and t.suggest_type='"+suggestType+"'";
        }if (StringUtils.isNoneBlank(relationType)){
            sql+=" and t.relation_type='"+relationType+"'";
        }if (StringUtils.isNoneBlank(keyWord)){
            sql+=" and t.suggest_content like '%"+keyWord+"%'";
        }
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<='" + endTime + "'";
                }else {
                    sql+="  and t.create_time<= to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<='" + endTime + "'";
            }
        }
        sql+=" order by t.create_time desc ";
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
    public BaseDoctorSuggestDO findById(String id){
        return baseDoctorSuggestDao.findOne(id);
    }
}

+ 19 - 8
business/base-service/src/main/java/com/yihu/jw/evaluate/score/service/BaseEvaluateScoreService.java

@ -6,6 +6,7 @@ import com.yihu.jw.evaluate.score.dao.BaseEvaluateScoreDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -30,7 +31,8 @@ public class BaseEvaluateScoreService extends BaseJpaService<BaseEvaluateScoreDO
    private BaseEvaluateScoreDao baseEvaluateScoreDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Value("${wechat.id}")
    private String wxId;
    /**
     * 计算总评分,周同比,日环比
@ -70,7 +72,7 @@ public class BaseEvaluateScoreService extends BaseJpaService<BaseEvaluateScoreDO
     * @return
     */
    private Double getAvgScore(String startTime,String endTime,String area,int level){
        String sql = "select count(*) as total, sum(score) as score from base.base_evaluate_score o where ";
        String sql = "select count(*) as total, sum(score) as score from base_evaluate_score o where ";
        if (level == 4){
            sql += " o.doctor IN (SELECT doctor_code FROM `base_doctor_hospital` dh where dh.org_code ='"+area+"' and dh.del=1)";
@ -81,13 +83,22 @@ public class BaseEvaluateScoreService extends BaseJpaService<BaseEvaluateScoreDO
        }else if (level == 6){
            sql += " o.doctor ='"+area+"'";
        }
        if (startTime != null){
            sql += " and o.create_time >='" + startTime + "'";
        }
        if(endTime != null){
            sql += " and o.create_time <='" + endTime + "'";
        if ("xm_ykyy_wx".equalsIgnoreCase(wxId)){
            if (startTime != null){
                sql += " and o.create_time >= to_date('" + startTime + "','yyyy-mm-dd hh24:mi:ss')";
            }
            if(endTime != null){
                sql += " and o.create_time <=to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
            }
        }else {
            if (startTime != null){
                sql += " and o.create_time >='" + startTime + "'";
            }
            if(endTime != null){
                sql += " and o.create_time <='" + endTime + "'";
            }
        }
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
        double total = 0d;
        double score = 0d;

+ 144 - 0
business/base-service/src/main/java/com/yihu/jw/file_upload/FileManageService.java

@ -0,0 +1,144 @@
package com.yihu.jw.file_upload;
import com.yihu.jw.restmodel.MutilFileInfo;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.utils.FileUtil;
import org.apache.commons.io.FileUtils;
import org.hibernate.service.spi.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Service
public class FileManageService {
    private static final Logger logger = LoggerFactory.getLogger(FileManageService.class);
    private String basePath = "/usr/local" ;
    private String fileUrl ="" ;
    /**
     * 分块上传
     * 第一步:获取RandomAccessFile,随机访问文件类的对象
     * 第二步:调用RandomAccessFile的getChannel()方法,打开文件通道 FileChannel
     * 第三步:获取当前是第几个分块,计算文件的最后偏移量
     * 第四步:获取当前文件分块的字节数组,用于获取文件字节长度
     * 第五步:使用文件通道FileChannel类的 map()方法创建直接字节缓冲器  MappedByteBuffer
     * 第六步:将分块的字节数组放入到当前位置的缓冲区内  mappedByteBuffer.put(byte[] b);
     * 第七步:释放缓冲区
     * 第八步:检查文件是否全部完成上传
     * @param param
     * @return
     * @throws IOException
     */
    public String chunkUploadByMappedByteBuffer(MutilFileInfo param,Integer chunkSize) throws IOException {
        if(param.getTaskId() == null || "".equals(param.getTaskId())){
            param.setTaskId(UUID.randomUUID().toString());
        }
        boolean copflag =false;
        if (chunkSize==null){
            chunkSize=2;
        }
        long chunkFileSize = chunkSize * 1024 * 1024;
        /**
         * basePath是我的路径,可以替换为你的
         * 1:原文件名改为UUID
         * 2:创建临时文件,和源文件一个路径
         * 3:如果文件路径不存在重新创建
         */
        String fileName = param.getFile().getOriginalFilename();
         //fileName.substring(fileName.lastIndexOf(".")) 这个地方可以直接写死 写成你的上传路径
        String tempFileName = param.getTaskId() + fileName.substring(fileName.lastIndexOf(".")) + "_tmp";
        String filePath = basePath+"/original";
        File fileDir = new File(filePath);
        if(!fileDir.exists()){
            fileDir.mkdirs();
        }
        File tempFile = new File(filePath,tempFileName);
        //第一步
        RandomAccessFile raf = new RandomAccessFile(tempFile,"rw");
        //第二步
        FileChannel fileChannel = raf.getChannel();
        //第三步
        long offset = param.getChunk() * chunkFileSize;
        //第四步
        byte[] fileData = param.getFile().getBytes();
        logger.info("offset"+offset);
        logger.info("fileData.length"+fileData.length);
        //第五步
        MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE,offset,fileData.length);
        //第六步
        mappedByteBuffer.put(fileData);
        //第七步
        FileUtil.freedMappedByteBuffer(mappedByteBuffer);
        fileChannel.close();
        raf.close();
        //第八步
        boolean isComplete = checkUploadStatus(param,fileName,filePath);
        if(isComplete){
            logger.info("unCompelete size:"+tempFile.getTotalSpace());
            renameFile(tempFile,fileName);
            return filePath+"/"+fileName;
        }else {
            logger.info("unCompelete size:"+tempFile.getTotalSpace());
            return "unCompelete";
        }
    }
    /**
     * 文件重命名
     * @param toBeRenamed   将要修改名字的文件
     * @param toFileNewName 新的名字
     * @return
     */
    public boolean renameFile(File toBeRenamed, String toFileNewName) {
        //检查要重命名的文件是否存在,是否是文件
        if (!toBeRenamed.exists() || toBeRenamed.isDirectory()) {
            return false;
        }
        String p = toBeRenamed.getParent();
        File newFile = new File(p + File.separatorChar + toFileNewName);
        //修改文件名
        return toBeRenamed.renameTo(newFile);
    }
    /**
     * 检查文件上传进度
     * @return
     */
    public boolean checkUploadStatus(MutilFileInfo param,String fileName,String filePath) throws IOException {
        File confFile = new File(filePath,fileName+".conf");
        RandomAccessFile confAccessFile = new RandomAccessFile(confFile,"rw");
        //设置文件长度
        confAccessFile.setLength(param.getChunkTotal());
        //设置起始偏移量
        confAccessFile.seek(param.getChunk());
        //将指定的一个字节写入文件中 127,
        confAccessFile.write(Byte.MAX_VALUE);
        byte[] completeStatusList = FileUtils.readFileToByteArray(confFile);
        byte isComplete = Byte.MAX_VALUE;
            //这一段逻辑有点复杂,看的时候思考了好久,创建conf文件文件长度为总分片数,每上传一个分块即向conf文件中写入一个127,那么没上传的位置就是默认的0,已上传的就是Byte.MAX_VALUE 127
        for(int i = 0; i<completeStatusList.length && isComplete==Byte.MAX_VALUE; i++){
            // 按位与运算,将&两边的数转为二进制进行比较,有一个为0结果为0,全为1结果为1  eg.3&5  即 0000 0011 & 0000 0101 = 0000 0001   因此,3&5的值得1。
            isComplete = (byte)(isComplete & completeStatusList[i]);
            System.out.println("check part " + i + " complete?:" + completeStatusList[i]);
        }
        if(isComplete == Byte.MAX_VALUE){
             //如果全部文件上传完成,删除conf文件
            confFile.delete();
            return true;
        }
        return false;
    }
}

+ 2 - 0
business/base-service/src/main/java/com/yihu/jw/file_upload/FileUploadRunnable.java

@ -66,6 +66,8 @@ public class FileUploadRunnable implements Runnable {
                e.printStackTrace();
            } catch (MyException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        callback.callback(photoUrl.toString());

+ 295 - 11
business/base-service/src/main/java/com/yihu/jw/file_upload/FileUploadService.java

@ -1,5 +1,8 @@
package com.yihu.jw.file_upload;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.exception.business.file_upload.*;
@ -22,9 +25,12 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Decoder;
import javax.activation.MimetypesFileTypeMap;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.security.NoSuchAlgorithmException;
@ -45,6 +51,8 @@ public class FileUploadService {
    @Value("${wlyy.url}")
    private String wlyyUrl;
    @Autowired
    private ObjectMapper objectMapper;
    /**
     * 文件流上传图片
@ -53,7 +61,7 @@ public class FileUploadService {
     * @return
     * @throws Exception
     */
    public UploadVO uploadImg(InputStream inputStream, String originalFileName,long fileSize,String fastdfs_file_url) throws NoSuchAlgorithmException, IOException, MyException {
    public UploadVO uploadImg(InputStream inputStream, String originalFileName,long fileSize,String fastdfs_file_url) throws Exception {
        // 得到文件的完整名称  xxx.txt
        if( null == inputStream){
            throw new FileInputStreamEmptyException("图片文件流不可为空!");
@ -72,6 +80,10 @@ public class FileUploadService {
            throw new FileWrongFormatException("图片文件格式不正确,请上传jpg,jpeg,png等任一格式!");
        }
        if (!isFileFlag(fileType)){
            throw new FileWrongFormatException("不符合文件上传格式");
        }
        long max = 5*1024*1024;
        if(fileSize > max){
            throw new FileTooLargeSizeException("图片文件过大,请不要超过5M!");
@ -151,9 +163,12 @@ public class FileUploadService {
            throw new FastfdsFileURLEmptyException("fastdfs url不可为空!");
        }
        //得到文件类型
        //得到文件类型sentitiveLog.txt
        String fileType = originalFileName.substring(originalFileName.lastIndexOf(".") + 1).toLowerCase();
        String fileName = originalFileName.substring(0, originalFileName.lastIndexOf("."));
        if (!isFileFlag(fileType)){
            throw new FileWrongFormatException("不符合文件上传格式");
        }
        //上传到fastdfs
        ObjectNode objectNode = fastDFSHelper.upload(inputStream, fileType, "");
        //解析返回的objectNode
@ -165,6 +180,10 @@ public class FileUploadService {
        return uploadVO;
    }
    public static void main(String[] args) {
        String s ="sentitiveLog.txt";
        System.out.println(s.substring(s.lastIndexOf(".") + 1).toLowerCase());
    }
    /**
     * i健康调用文件传输
     * @param multipartFile
@ -184,13 +203,17 @@ public class FileUploadService {
        String type = fs[1];
        logger.info("uploadImg type:"+type);
        //图片常见格式:bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,WMF,webp
//        List img = new ArrayList(Arrays.asList("bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp"));
//        if (!img.contains(type)) {
//            map.put("uploadStatus",2);//文件类型不对
//            map.put("accessoryUrl",null);//
//            return map;
//        }
        String response = request(wlyyUrl + "/upload/chat", multipartFile, null);
       /* List img = new ArrayList(Arrays.asList("bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp"));
        if (!img.contains(type)) {
            map.put("uploadStatus",2);//文件类型不对
            map.put("accessoryUrl",null);//
            return map;
        }*/
       if (!isFileFlag(type)){
           throw new FileWrongFormatException("不符合文件上传格式");
       }
        String response = request(wlyyUrl + "/upload/chat", multipartFile, type);
        org.json.JSONObject rs = new org.json.JSONObject(response);
        Integer status = (Integer) rs.get("status");
        if (status == 200) {
@ -248,7 +271,7 @@ public class FileUploadService {
//            return map;
//        }
            logger.info("语音文件转换file-转换-multipartFile-成功,开始调用i健康接口上传文件");
            String response = request(wlyyUrl + "/upload/chat", multipartFile, null);
            String response = request(wlyyUrl + "/upload/chat", multipartFile, type);
            org.json.JSONObject rs = new org.json.JSONObject(response);
            Integer status = (Integer) rs.get("status");
            if (status == 200) {
@ -262,6 +285,166 @@ public class FileUploadService {
        }
        return url;
    }
    /**
     * 调用内网本地fasdf
     * @param voices_Path
     * @return
     * @throws Exception
     */
    public String uploadInLocalWxVoice(String voices_Path,String remote_inner_url) throws Exception {
        UploadVO uploadVO = new UploadVO();
        String url = "";
        File f = new File(voices_Path);
        if (f.exists()) {
            logger.info("语音文件转换file-start");
            FileInputStream input = new FileInputStream(f);
            String fileContenType = "text/plain";
            try {
                logger.info("获取文件类型--开始");
                fileContenType = new MimetypesFileTypeMap().getContentType(f);
                logger.info("获取文件类型--成功--fileContenType:"+fileContenType);
            } catch (Exception e) {
                logger.info("获取文件类型--失败:"+e.getMessage());
            }
            MultipartFile multipartFile = new MockMultipartFile("file", f.getName(), fileContenType, IOUtils.toByteArray(input));
            logger.info("语音文件转换file-转换-multipartFile");
            long size = multipartFile.getSize();
            if(size<=0){
                return url;
            }
            String fileName = multipartFile.getOriginalFilename();
            String[] fs = fileName.split("\\.");
            String type = fs[1];
            logger.info("语音文件转换file-转换-multipartFile-成功,开始调用内网接口上传文件");
            String rs = request(remote_inner_url, multipartFile, type);
            logger.info(rs);
            JSONObject json = JSON.parseObject(rs);
            uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
            if (uploadVO !=null) {
                url = uploadVO.getFullUri();
                logger.info("开始调用内网接口上传文件成功:url:"+url);
//                map.put("uploadStatus", 0);//文件类型正确
//                map.put("accessory", url);//
                return url;
            }
        }
        return url;
    }
    /**
     * 调用内网上传图片.
     * @param files
     * @return
     * @throws Exception
     */
    public String uploadInLocalWxImage(String files,String tempPath,String remote_inner_url) throws Exception {
        UploadVO uploadVO = new UploadVO();
        System.out.println("files====="+files);
        System.out.println("tempPath====="+tempPath);
        // 文件保存的临时路径
        String[] fileArray = files.split(",");
        String fileUrls = "";
        for (String file : fileArray) {
            System.out.println("file+++"+file);
            File f = new File(tempPath + "/"+file);
            File fs = new File(tempPath +"/"+ file + "_small");
            if (f.exists()) {
                logger.info("图片文件转换file-start");
                FileInputStream input = new FileInputStream(f);
                String fileContenType = "text/plain";
                try {
                    logger.info("获取文件类型--开始");
                    fileContenType = new MimetypesFileTypeMap().getContentType(f);
                    logger.info("获取文件类型--成功--fileContenType:"+fileContenType);
                } catch (Exception e) {
                    logger.info("获取文件类型--失败:"+e.getMessage());
                }
                MultipartFile multipartFile = new MockMultipartFile("file", f.getName(), fileContenType, IOUtils.toByteArray(input));
                logger.info("图片文件转换file-转换-multipartFile");
                long size = multipartFile.getSize();
                if(size<=0){
                    return fileUrls;
                }
                logger.info("图片文件转换file-转换-multipartFile-成功,开始调用内网接口上传文件");
                String rs = request(remote_inner_url, multipartFile, fileContenType);
                logger.info(rs);
                JSONObject json = JSON.parseObject(rs);
                uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
                if (uploadVO != null) {
                    fileUrls += uploadVO.getFullUri();
                    f.delete();
                    if (fs.exists()) {
                        fs.delete();
                    }
                }
            }
        }
        return fileUrls;
    }
    /**
     * 调用内网上传语音文件.
     * @param voices_Path
     * @return
     * @throws Exception
     */
    public String uploadWxVoiceToEntrance(String remoteUrl,String voices_Path) throws Exception {
        String url = "";
        // 文件保存的临时路径
        FastDFSUtil fastDFSUtil = new FastDFSUtil();
        String fileUrls = "";
        File f = new File(voices_Path);
        logger.info("语音文件转换file");
        if (f.exists()) {
            logger.info("语音文件转换file-start");
            FileInputStream input = new FileInputStream(f);
            String fileContenType = "text/plain";
            try {
                logger.info("获取文件类型--开始");
                fileContenType = new MimetypesFileTypeMap().getContentType(f);
                logger.info("获取文件类型--成功--fileContenType:"+fileContenType);
            } catch (Exception e) {
                logger.info("获取文件类型--失败:"+e.getMessage());
            }
            MultipartFile multipartFile = new MockMultipartFile("file", f.getName(), fileContenType, IOUtils.toByteArray(input));
            logger.info("语音文件转换file-转换-multipartFile");
            long size = multipartFile.getSize();
            if(size<=0){
//                map.put("uploadStatus",1);//size小于0
//                map.put("accessoryUrl",null);//
                return url;
            }
            String fileName = multipartFile.getOriginalFilename();
            String[] fs = fileName.split("\\.");
            String type = fs[1];
            logger.info("uploadImg type:"+type);
            //图片常见格式:bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,WMF,webp
//        List img = new ArrayList(Arrays.asList("bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp"));
//        if (!img.contains(type)) {
//            map.put("uploadStatus",2);//文件类型不对
//            map.put("accessoryUrl",null);//
//            return map;
//        }
            logger.info("语音文件转换file-转换-multipartFile-成功,开始调用i健康接口上传文件");
            String response = request( remoteUrl, multipartFile, type);
            JSONObject json = JSON.parseObject(response);
            Integer status = json.getInteger("status");
            if (status == 200) {
                UploadVO uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
                return uploadVO.getFullUri();
            }
            throw new Exception();
        }
        return url;
    }
    
    /**
     * 调用健康上传图片.
@ -308,7 +491,7 @@ public class FileUploadService {
//            return map;
//        }
            logger.info("图片文件转换file-转换-multipartFile-成功,开始调用i健康接口上传文件");
            String response = request(wlyyUrl + "/upload/chat", multipartFile, null);
            String response = request(wlyyUrl + "/upload/chat", multipartFile, type);
            org.json.JSONObject rs = new org.json.JSONObject(response);
            Integer status = (Integer) rs.get("status");
            if (status == 200) {
@ -335,6 +518,10 @@ public class FileUploadService {
            if (!org.springframework.util.StringUtils.isEmpty(type)) {
                builder.addTextBody("type", type); //发送类型
            }
            logger.info("type===="+type);
            if (!isFileFlag(type)){
                throw new FileWrongFormatException("不符合文件上传格式");
            }
            HttpEntity entity = builder.build();
            httpPost.setEntity(entity);
            HttpResponse response = httpClient.execute(httpPost);// 执行提交
@ -400,5 +587,102 @@ public class FileUploadService {
        return uploadVO;
    }
    /***
     *
     * 将图片转换为Base64<br>
     * 将base64编码字符串解码成img图片
     * @param imgFile
     * @return
     */
    public static String getImgStr(String imgFile){
        ByteArrayOutputStream data = new ByteArrayOutputStream();
        try {
            // 创建URL
            URL url = new URL(imgFile);
            byte[] by = new byte[1024];
            // 创建链接
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setConnectTimeout(5000);
            InputStream is = conn.getInputStream();
            // 将内容放到内存中
            int len = -1;
            while ((len = is.read(by)) != -1) {
                data.write(by, 0, len);
            }
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 对字节数组Base64编码
        return Base64.getEncoder().encodeToString(data.toByteArray());
    }
    public InputStream getInputStream(String downloadFilePath) throws Exception{
        InputStream inputStream = null;
        //从文件链接里获取文件流
        URL url = new URL(downloadFilePath);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        //设置超时间为3秒
        conn.setConnectTimeout(180 * 1000);
        //防止屏蔽程序抓取而返回403错误
        conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        //得到输入流
        inputStream = conn.getInputStream();
        return inputStream;
    }
    public void deleteFile(String groupName,String fileName) throws  Exception{
        fastDFSHelper.delete(groupName,fileName);
    }
    /*
     * base64上传图片心脏
     * @param jsonData,头像转化后的输入流
     * @return
     * @throws Exception
     */
    public UploadVO uploadImagesBase64(String jsonData,String fastdfs_file_url) throws Exception {
        if(StringUtils.isBlank(jsonData)){
            throw new FileInputStreamEmptyException("图片的base64文件文件流不可为空!");
        }
        if(StringUtils.isBlank(fastdfs_file_url)){
            throw new FastfdsFileURLEmptyException("fastdfs url不可为空!");
        }
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] bfile = decoder.decodeBuffer(jsonData);
        InputStream inputStream = new ByteArrayInputStream(bfile);
        ObjectNode objectNode = fastDFSHelper.upload(inputStream, "png", "");
        String groupName = objectNode.get("groupName").toString();
        String remoteFileName = objectNode.get("remoteFileName").toString();
        //解析返回的objectNode
        UploadVO uploadVO = new UploadVO();
        uploadVO.setFileName(remoteFileName);
        uploadVO.setFileType(groupName);
        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
        //返回文件路径
        return uploadVO;
    }
    public boolean isFileFlag(String type){
        type = type.toLowerCase();
        if (type.contains(".")){
            type = type.substring(type.lastIndexOf("."),type.length()-1);
        }
        logger.info(type);
        List img = new ArrayList(Arrays.asList("jpeg","bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp","xls","xlsx","text/plain","mp4","m4v","avi","ogm","wmv","mpg","webm","ogv","mov","asx","mpeg","image/png"));
        if (!img.contains(type)) {
            return false;
        }
        return true;
    }
}

+ 14 - 0
business/base-service/src/main/java/com/yihu/jw/gateway/dao/GcClientDetailsDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.gateway.dao;
import com.yihu.jw.entity.iot.gateway.GcClientDetails;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by chenweida on 2017/8/17.
 */
public interface GcClientDetailsDao extends PagingAndSortingRepository<GcClientDetails, Long>, JpaSpecificationExecutor<GcClientDetails> {
    @Query("from GcClientDetails where appId=?1 and del=1")
    GcClientDetails findByAppid(String appid);
}

+ 11 - 0
business/base-service/src/main/java/com/yihu/jw/gateway/dao/GcHttpLogDao.java

@ -0,0 +1,11 @@
package com.yihu.jw.gateway.dao;
import com.yihu.jw.entity.iot.gateway.GcHttpLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by chenweida on 2017/8/17.
 */
public interface GcHttpLogDao extends PagingAndSortingRepository<GcHttpLog, Long>, JpaSpecificationExecutor<GcHttpLog> {
}

+ 29 - 0
business/base-service/src/main/java/com/yihu/jw/gateway/dao/GcTokenDao.java

@ -0,0 +1,29 @@
package com.yihu.jw.gateway.dao;
import com.yihu.jw.entity.iot.gateway.GcToken;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
/**
 * Created by chenweida on 2017/8/17.
 */
public interface GcTokenDao extends PagingAndSortingRepository<GcToken, Long>, JpaSpecificationExecutor<GcToken> {
    @Query("update GcToken g set g.del=0 where g.appid=?1 and g.del=1")
    @Modifying
    void updateDel(String appid);
    @Query("from GcToken where accesstoken=?1")
    GcToken findByToken(String token);
    @Query("from GcToken where appid=?1 and outTime >= ?1")
    List<GcToken> findByAppIdByDate(String token,Date date);
    @Query("from GcToken where appid=?1 and outTime >= now () ")
    List<GcToken> findByAppId(String token);
}

+ 11 - 0
business/base-service/src/main/java/com/yihu/jw/gateway/dao/GcTokenLogDao.java

@ -0,0 +1,11 @@
package com.yihu.jw.gateway.dao;
import com.yihu.jw.entity.iot.gateway.GcTokenLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by chenweida on 2017/8/17.
 */
public interface GcTokenLogDao extends PagingAndSortingRepository<GcTokenLog, Long>, JpaSpecificationExecutor<GcTokenLog> {
}

+ 39 - 0
business/base-service/src/main/java/com/yihu/jw/gateway/service/GcClientDetailsService.java

@ -0,0 +1,39 @@
package com.yihu.jw.gateway.service;
import com.yihu.jw.entity.iot.gateway.GcClientDetails;
import com.yihu.jw.gateway.dao.GcClientDetailsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import static com.sun.xml.internal.ws.util.JAXWSUtils.getUUID;
/**
 * Created by chenweida on 2017/8/17.
 */
@Service
public class GcClientDetailsService{
    @Autowired
    private GcClientDetailsDao gtClientDetailsDao;
    public GcClientDetails findByAppId(String appid) {
        return gtClientDetailsDao.findByAppid(appid);
    }
    @Transactional
    public GcClientDetails createClientDetails(String appUri,String createUserName,String creatieUser,String remark) throws Exception{
        GcClientDetails gcClientDetails = new GcClientDetails();
        gcClientDetails.setAppId(getUUID());
        gcClientDetails.setAppSecret(getUUID());
        gcClientDetails.setAppUri(appUri);
        gcClientDetails.setCreateUserName(createUserName);
        gcClientDetails.setCreatieUser(creatieUser);
        gcClientDetails.setCreatieTime(new Date());
        gcClientDetails.setDel(1);
        gcClientDetails.setRemark(remark);
        return gtClientDetailsDao.save(gcClientDetails);
    }
}

+ 119 - 0
business/base-service/src/main/java/com/yihu/jw/gateway/service/GcTokenService.java

@ -0,0 +1,119 @@
package com.yihu.jw.gateway.service;
import com.yihu.jw.entity.iot.gateway.GcToken;
import com.yihu.jw.entity.iot.gateway.GcTokenLog;
import com.yihu.jw.gateway.dao.GcTokenDao;
import com.yihu.jw.gateway.dao.GcTokenLogDao;
import com.yihu.jw.util.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * Created by chenweida on 2017/8/17.
 */
@Service
public class GcTokenService {
    @Autowired
    private GcTokenLogDao tokenLogDao;
    @Autowired
    private GcTokenDao tokenDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 根据appid生成token
     *
     * @param appid
     * @param appSecret
     * @return
     */
    @Transactional
    public GcToken createToken(String appid, String appSecret, String ip, String overTime,Integer tokenTime) {
        try {
            //把该用户之前有效的token设置为无效
            tokenDao.updateDel(appid);
            //创新新的appId
            Date date = new Date();
            String token = UUID.randomUUID().toString();
            GcToken gc = new GcToken();
            gc.setAppid(appid);
            gc.setCreateTime(date);
            //2小时过期
            if(StringUtils.isEmpty(overTime)){
                if(tokenTime==null){
                    tokenTime=2;
                }
                gc.setOutTime(DateUtil.getNextMin(date, tokenTime*60));
            }else{
                gc.setOutTime(DateUtil.strToDate(overTime));
            }
            gc.setAccesstoken(token);
            gc.setDel(1);
            tokenDao.save(gc);
            //保存日志
            GcTokenLog gcTokenLog = new GcTokenLog();
            gcTokenLog.setAppIp(appid);
            gcTokenLog.setCreateTime(new Date());
            gcTokenLog.setAppIp(ip);
            gcTokenLog.setMessage("创建token");
            gcTokenLog.setAccesstoken(token);
            gcTokenLog.setFlag(1);
            tokenLogDao.save(gcTokenLog);
            return gc;
        } catch (Exception e) {
            //保存失败日志
            GcTokenLog gcTokenLog = new GcTokenLog();
            gcTokenLog.setAppIp(appid);
            gcTokenLog.setCreateTime(new Date());
            gcTokenLog.setAppIp(ip);
            gcTokenLog.setMessage("创建token");
            gcTokenLog.setFlag(0);
            tokenLogDao.save(gcTokenLog);
        }
        return null;
    }
    /**
     * 根据token获取GcToken对象
     * @param token
     * @return
     */
    public GcToken getToken(String token) {
        return tokenDao.findByToken(token);
    }
    public List<GcToken> findByAppId(String appid,String wxId){
        if (wxId.equalsIgnoreCase("xm_ykyy_wx")){
            String sql = "select ID AS \"id\",APPID as \"appId\",ACCESSTOKEN as \"accessToken\",CREATE_TIME as \"createTime\",to_char(OUT_TIME,'yyyy-MM-dd hh24:mi:ss') as \"outTime\" from GC_TOKEN where APPID = '"+appid+"' and OUT_TIME >= to_date('"+DateUtil.getStringDate()+"','YYYY-MM-DD HH24:MI:SS')";
            List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
            List<GcToken> gcTokens = new ArrayList<>();
            for (Map<String,Object> map:mapList){
                GcToken gcToken = new GcToken();
                gcToken.setId(Integer.parseInt(map.get("id").toString()));
                gcToken.setAccesstoken(map.get("accessToken").toString());
                gcToken.setAppid(map.get("appId").toString());
                gcToken.setOutTime(DateUtil.strToDate(map.get("outTime").toString()));
                gcTokens.add(gcToken);
                System.out.print("gcToken"+gcToken.getOutTime());
            }
            return gcTokens;
        }else {
            return tokenDao.findByAppId(appid);
        }
    }
}

+ 1675 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/service/HealthCareService.java

@ -0,0 +1,1675 @@
package com.yihu.jw.healthCare.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.healthCare.*;
import com.yihu.jw.entity.hospital.httplog.YlzHttpLogDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionExpressageDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
import com.yihu.jw.healthCare.utils.AES;
import com.yihu.jw.healthCare.utils.SafeUtil;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.healthCare.*;
import com.yihu.jw.hospital.httplog.dao.YlzHttpLogDao;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionExpressageDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionInfoDao;
import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 医保对接
 * Created by wangzhinan 20211002
 */
@Service
@Transactional
public class HealthCareService {
    private Logger logger = LoggerFactory.getLogger(HealthCareService.class);
    @Autowired
    private WlyyHospitalSysDictDao hospitalSysDictDao;
    @Autowired
    private BaseDoctorHospitalDao doctorHospitalDao;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private BasePatientDao patientDao;
    @Autowired
    private OutpatientDao outpatientDao;
    @Autowired
    private DoctorMappingDao doctorMappingDao;
    @Autowired
    private PrescriptionExpressageDao prescriptionExpressageDao;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private YlzHttpLogDao ylzHttpLogDao;
    @Autowired
    private PatientMappingDao patientMappingDao;
    @Autowired
    private YlzMedicalPrescriptionUploadDao ylzMedicalPrescriptionUploadDao;
    @Autowired
    private PrescriptionInfoDao prescriptionInfoDao;
    @Autowired
    private YlzMedicailRelationDao ylzMedicailRelationDao;
    @Autowired
    private YlzMedicailBillDao ylzMedicailBillDao;
    @Autowired
    private YlzMedicailIcdDao ylzMedicailIcdDao;
    @Autowired
    private YlzMedicailMxDao ylzMedicailMxDao;
    @Autowired
    private XzzxEntranceService xzzxEntranceService;
    private String ylzConfigUrl;
    private String ylzConfigAppid;
    private String ylzConfigAppSecret;
    private String ylzConfigEncryptKey;
    private String ylzConfigSignKey;
    private String ylzConfigOrgCode;
    public static String entranceHealthCareUrl = "http://172.16.100.240:10023/healthCare/";
    public void initConfig() throws Exception{
        logger.info("初始话参数!");
        List<WlyyHospitalSysDictDO> hospitalSysDictDOS = hospitalSysDictDao.findByDictName("ylzConfig");
        if (hospitalSysDictDOS==null||hospitalSysDictDOS.size()==0){
            throw new Exception("尚未添加配置参数");
        }else {
            for (WlyyHospitalSysDictDO hospitalSysDictDO:hospitalSysDictDOS){
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigUrl")){
                    ylzConfigUrl = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigAppid")){
                    ylzConfigAppid = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigAppSecret")){
                    ylzConfigAppSecret = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigEncryptKey")){
                    ylzConfigEncryptKey = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigSignKey")){
                    ylzConfigSignKey = hospitalSysDictDO.getDictValue();
                }
                if (hospitalSysDictDO.getId().equalsIgnoreCase("ylzConfigOrgCode")){
                    ylzConfigOrgCode = hospitalSysDictDO.getDictValue();
                }
            }
        }
    }
    /**
     * 医保统一调用接口
     * @param data
     * @param funid
     * @param name
     * @return
     * @throws Exception
     */
    public String requestYlz(JSONObject data,String funid,String name) throws Exception {
        YlzHttpLogDO ylzHttpLogDO = new YlzHttpLogDO();
        initConfig();
        JSONObject object = new JSONObject();
        object.put("sign_type","md5");
        object.put("appid",ylzConfigAppid);
        String accessToken = getYlzToken();
        if (accessToken==null){
            throw new Exception("token无效");
        }
        object.put("access_token",accessToken);
        object.put("funid",funid);
        data.put("appid",ylzConfigAppid);
        data.put("org_code",ylzConfigOrgCode);
        object.put("data",data);
        String signResult = SafeUtil.sign(object.toJSONString(),ylzConfigSignKey);
        String obj = SafeUtil.encrypt(signResult,ylzConfigEncryptKey);
        JSONObject jsonObject = JSONObject.parseObject(obj);
        logger.info("请求前funid=="+funid+"data="+data.toJSONString());
        String response = httpClientUtil.postBody(ylzConfigUrl,jsonObject);
        ylzHttpLogDO.setResponseEncrpty(response);
        if (response!=null&&response!=""){
            JSONObject result = JSONObject.parseObject(response);
            if (result.getString("flag").equalsIgnoreCase("1")){
                String dataResult = result.getString("encrypt_data");
                result.remove("encrypt_data");
                if (dataResult!=null&&dataResult!=""){
                    String decryptResult = AES.aesDecrypt(dataResult,ylzConfigEncryptKey);
                    JSONObject dataObject = JSONObject.parseObject(decryptResult);
                    result.put("encrypt_data",dataObject);
                    response = result.toJSONString();
                }
            }
        }
        ylzHttpLogDO.setCode(funid);
        ylzHttpLogDO.setName(name);
        ylzHttpLogDO.setRequest(data.toJSONString());
        ylzHttpLogDO.setRequestEncrpty(obj);
        ylzHttpLogDO.setResponse(response);
        ylzHttpLogDO.setCreateTime(new Date());
        ylzHttpLogDao.save(ylzHttpLogDO);
        return response;
    }
    /**
     * 获取token
     * @return
     * @throws Exception
     */
    /**
     * 2.3.1	医师身份验证(处方权,多点执业等)
     */
    public String doctorAuthentication(String doctorId){
        try {
            BaseDoctorDO doctorDO = doctorDao.findOne(doctorId);
            if (doctorDO == null){
                throw new Exception("医生不存在");
            }
            List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(doctorId);
            if(doctorHospitalDOS.size()<=0){
                throw new Exception("未找到医生科室编码");
            }
            BaseDoctorHospitalDO doctorHospitalDO = doctorHospitalDOS.get(0);
            JSONObject data = new JSONObject();
            data.put("his_dept_code",doctorHospitalDO.getDeptCode());//his内部科室编码
            data.put("his_dept_name",doctorHospitalDO.getDeptName());//his内部科室名称
//        data.put("dept_code","");//医保科室编码	String	N
//        data.put("dept_name","");//医保科室名称	String	N
            data.put("medical_mode","10");//医疗就诊方式	10	门(急)诊
            data.put("name",doctorDO.getName());//医师姓名
            data.put("idcard",doctorDO.getIdcard());//医师证件号
            data.put("cert_type","01");//医师证件类型
            String result = requestYlz(data,"N20.17.02.01","医师身份验证");
            if(result == null){
                throw new Exception("医保请求失败");
            }
            logger.info("医师身份验证:"+result);
            JSONObject object = JSONObject.parseObject(result);
            if (object.getString("flag").equalsIgnoreCase("1")){
                JSONObject encryptData = object.getJSONObject("encrypt_data");
                return encryptData.getString("is_prescribe");
            }else {
                return "0";
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return "0";
    }
    /**
     * 2.3.2	医师人脸签到表单地址
     * @param doctorId
     * @throws Exception
     */
    public String doctorFaceCheckInAddress(String doctorId)throws Exception{
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findOne("ylzConfigFaceReturnUrl");
        if(hospitalSysDictDO == null){
            throw new Exception("未配置回调地址");
        }
        BaseDoctorDO doctorDO = doctorDao.findOne(doctorId);
        if (doctorDO == null){
            throw new Exception("医生不存在");
        }
        JSONObject data = new JSONObject();
        data.put("name",doctorDO.getName());//医师姓名
        data.put("idcard",doctorDO.getIdcard());//医师证件号
        data.put("cert_type","01");//医师证件类型
        data.put("redirect_url",hospitalSysDictDO.getDictValue());//回调地址
        String result = requestYlz(data,"N20.17.02.02","医师人脸签到表单地址");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("医师人脸签到表单地址:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.3.3	获取医师人脸签到数据
     */
    public String doctorFaceCheckInData(String doctorId)throws Exception{
        BaseDoctorDO doctorDO = doctorDao.findOne(doctorId);
        if (doctorDO == null){
            throw new Exception("医生不存在");
        }
        JSONObject data = new JSONObject();
        data.put("name",doctorDO.getName());//医师姓名
        data.put("idcard",doctorDO.getIdcard());//医师证件号
        data.put("cert_type","01");//医师证件类型
        String result = requestYlz(data,"N20.17.02.05","获取医师人脸签到数据");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("获取医师人脸签到数据:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.4.1 事前提醒
     */
    public String advanceWarning(String prescriptionId){
        try {
            WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findOne(prescriptionId);
            if (wlyyPrescriptionDO == null){
                throw new Exception("续方信息不存在");
            }
            WlyyOutpatientDO outpatientDO = outpatientDao.findOne(wlyyPrescriptionDO.getOutpatientId());
            if (outpatientDO == null){
                throw new Exception("门诊信息不存在");
            }
            WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("ylzConfigOrgCode");
            if(hospitalSysDictDO == null){
                throw new Exception("未配置网点编号");
            }
            String icCardNo = outpatientDO.getCardNo();
            String his_serial = outpatientDO.getRegisterNo();
            String org_code = hospitalSysDictDO.getDictCode();
            JSONObject data;
            //获取his处方信息
            String infoResponse = xzzxEntranceService.presUpload(icCardNo,his_serial,org_code);
            JSONObject infoObject = JSONObject.parseObject(infoResponse);
            if("0".equals(infoObject.getString("ret_code"))){
                data = infoObject;
            }else {
                throw new Exception("获取his处方信息失败:"+infoObject.getString("ret_mess"));
            }
            data.remove("ret_code");
            data.remove("ret_mess");
            data.remove("log_no");
            data.put("ticket_no",outpatientDO.getXtgzh());//	单据流水号
            String result = requestYlz(data,"N20.17.03.03","事前提醒");
            if(result == null){
                throw new Exception("医保请求失败");
            }
            logger.info("事前提醒:"+result);
            JSONObject object = JSONObject.parseObject(result);
            if (object.getString("flag").equalsIgnoreCase("1")){
                JSONObject encryptData = object.getJSONObject("encrypt_data");
                return encryptData.toJSONString();
            }
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 2.4.2	医师开方上传
     */
    public String doctorPrescriptionUpload(String prescriptionId) throws Exception{
        WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findOne(prescriptionId);
        if (wlyyPrescriptionDO == null){
            throw new Exception("续方信息不存在");
        }
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(wlyyPrescriptionDO.getOutpatientId());
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("ylzConfigOrgCode");
        if(hospitalSysDictDO == null){
            throw new Exception("未配置网点编号");
        }
        String icCardNo = outpatientDO.getCardNo();
        String his_serial = outpatientDO.getRegisterNo();
        String org_code = hospitalSysDictDO.getDictCode();
        JSONObject data;
        //获取his处方信息
        String infoResponse = xzzxEntranceService.presUpload(icCardNo,his_serial,org_code);
        JSONObject infoObject = JSONObject.parseObject(infoResponse);
        if("0".equals(infoObject.getString("ret_code"))){
            data = infoObject;
        }else {
            throw new Exception("获取his处方信息失败:"+infoObject.getString("ret_mess"));
        }
        data.remove("ret_code");
        data.remove("ret_mess");
        data.remove("log_no");
        data.put("order_id",prescriptionId);
        YlzMedicalPrescriptionUploadDO uploadDO = new YlzMedicalPrescriptionUploadDO();
        uploadDO.setOrgCode(org_code);
        uploadDO.setIcCardNo(icCardNo);
        uploadDO.setHisSerial(his_serial);
        uploadDO.setOutpatientId(wlyyPrescriptionDO.getOutpatientId());
        uploadDO.setPrescriptionId(prescriptionId);
        uploadDO.setRegionCode(data.getString("region_code"));
        uploadDO.setName(data.getString("name"));
        uploadDO.setIdcard(data.getString("idcard"));
        uploadDO.setCertType(data.getString("cert_type"));
        uploadDO.setDataSource("53");//53移动支付
        uploadDO.setInsuranceSerial(data.getString("insurance_serial"));
        String result = requestYlz(data,"N20.17.03.01","医师开方上传");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("医师开方上传:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            uploadDO.setTransactionNo(encryptData.getString("transaction_no"));
            ylzMedicalPrescriptionUploadDao.save(uploadDO);
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.4.3	医师开方上传取消(N20.17.03.06)
     */
    public String doctorPrescriptionUploadCancle(String prescriptionId,String cancelReason)throws Exception{
        YlzMedicalPrescriptionUploadDO uploadDO = ylzMedicalPrescriptionUploadDao.findByPrescriptionId(prescriptionId);
        if(uploadDO == null){
            throw new Exception("未找到开发上传记录");
        }
        JSONObject data = new JSONObject();
        data.put("transaction_no",uploadDO.getTransactionNo());//处方上传流水号  	String	Y
        data.put("insurance_serial",uploadDO.getInsuranceSerial());//医保流水号
        data.put("cancel_reason",cancelReason);//作废原因
        data.put("region_code",uploadDO.getRegionCode());//参保地区划代码
        data.put("idcard",uploadDO.getIdcard());//证件号码
        data.put("name",uploadDO.getName());//姓名
        data.put("cert_type",uploadDO.getCertType());//证件类型
        data.put("data_source",uploadDO.getDataSource());//数据来源	String	Y	参见编码附件
        String result = requestYlz(data,"N20.17.03.06","医师开方上传取消");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("医师开方上传取消:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.6.1	电子处方订单接收(N20.17.05.02)
     */
    public String electronicPrescriptionReceiving(String outpatientId)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        JSONObject data = new JSONObject();
        data.put("order_code","");//订单号
        data.put("order_time",DateUtil.dateToStrLong(outpatientDO.getCreateTime()));//订单时间
        List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByOutPatientIdList(outpatientId);
        if(wlyyPrescriptionDOS.size()==0){
            throw new Exception("处方信息不存在");
        }
        data.put("prescription_code",wlyyPrescriptionDOS.get(0).getRealOrder());//医院处方编号
        data.put("channel","1");//1、微信公众号,2、app,3、web
//        data.put("insurance_ticket_no","");//医保收费单据号	String	N	订单结算后的收费单据号
        data.put("order_state","");//订单状态    --1待发货、2配送中、3已签收、4已取消	String	Y
        List<WlyyPrescriptionExpressageDO> expressageDOList = prescriptionExpressageDao.findByOutpatientId(outpatientId);
        if(expressageDOList.size()==0){
            throw new Exception("收获信息不存在");
        }
        BasePatientDO patientDO = patientDao.findById(outpatientDO.getPatient());
        if(patientDO==null){
            throw new Exception("居民信息不存在");
        }
        WlyyPrescriptionExpressageDO expressageDO = expressageDOList.get(0);
        data.put("order_addr_detail",expressageDO.getAddress());//订单详细地址
        data.put("order_owner",expressageDO.getName());
        data.put("order_owner_idcard",patientDO.getIdcard());
        data.put("order_owner_phone",patientDO.getMobile());
        Map<String,String> map = LatitudeUtils.getGeocoderLatitude(expressageDO.getAddress());
        data.put("addr_lat",map.get("lat"));//收货地址纬度
        data.put("addr_lng",map.get("lng"));//收货地址经度
        if(expressageDO.getOneselfPickupFlg()==1){
            //自取
            data.put("delivery_way","2");//1.网订配送,2.网订自取
            data.put("qrcode_check_time","");//扫码校验时间
            data.put("receiving_time","");//药品签收时间
        }else {
            //非自取
            data.put("delivery_way","1");//配送方式 1.网订配送,2.网订自取
            data.put("delivery_number",expressageDO.getMailno());//配送单号
            data.put("delivery_org","");//配送单位
            data.put("delivery_take_time","");//配送接单时间
            data.put("delivery_name","");//配送人姓名
            data.put("delivery_id_card","");//配送人身份证
//            data.put("delivery_phone","");//配送人联系电话 N
            data.put("getmedical_time","");//骑手取药记录
            data.put("delivery_money","");//配送费
        }
//        apothecary_name	药师姓名	String	N
//        apothecary_id_card	药师身份证	String	N
//        apothecary_audit	药师审核时间	String	N
        data.put("money","");//商品金额
        data.put("settlement_time","");//结算时间
        data.put("data_source","");//数据来源
        data.put("delivery_time","");//发单时间
        data.put("elec_prescription_code",wlyyPrescriptionDOS.get(0).getId());//平台处方编号
        data.put("prescription_code",wlyyPrescriptionDOS.get(0).getRealOrder());//医院处方编号
//        data.put("insurance_serial",outpatientDO.getInsuranceSerial());//医保门诊流水号
        data.put("his_serial","");//门诊业务流水号
//        mxlist	药品明细	MXLIST	N
//        MXLIST
//        order_id	订单号	String	Y
//        settlement_no	医保结算单据号	String	Y
//        item_name	医保项目名称	String	Y
//        item_code	医保项目编码	String	Y
//        supervision_code	药品电子监管码	String	N	非必填
        String result = requestYlz(data,"N20.17.05.02","电子处方订单接收");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("电子处方订单接收:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     *2.6.2	电子处方订单取消(N20.17.05.03)
     */
    public String electronicPrescriptionCancle(String outpatientId)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        JSONObject data = new JSONObject();
        data.put("order_code","");//订单号
        data.put("order_time",DateUtil.dateToStrLong(outpatientDO.getCreateTime()));//订单时间
        List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByOutPatientIdList(outpatientId);
        if(wlyyPrescriptionDOS.size()==0){
            throw new Exception("处方信息不存在");
        }
        data.put("prescription_code",wlyyPrescriptionDOS.get(0).getRealOrder());//医院处方编号
        data.put("channel","1");//1、微信公众号,2、app,3、web
//        data.put("insurance_ticket_no","");//医保收费单据号	String	N	订单结算后的收费单据号
        data.put("order_state","");//订单状态    --1待发货、2配送中、3已签收、4已取消	String	Y
        data.put("cancel_time","");//订单取消时间  取消时必填
        data.put("cancel_reason","");//取消原因
        String result = requestYlz(data,"N20.17.05.03","电子处方订单取消");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("电子处方订单取消:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.6.3 获取处方流转平台药师审方结果(N20.17.05.04)
     */
    public String pharmacistReviewResults(String outpatientId)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        JSONObject data = new JSONObject();
//        data.put("order_code","");//订单号
        List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByOutPatientIdList(outpatientId);
        if(wlyyPrescriptionDOS.size()==0){
            throw new Exception("处方信息不存在");
        }
        data.put("prescription_code",wlyyPrescriptionDOS.get(0).getRealOrder());//医院处方编号
        String result = requestYlz(data,"N20.17.05.04","获取处方流转平台药师审方结果");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("获取处方流转平台药师审方结果:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.2.1	门诊提醒(N21.08.09.01)
     */
    public String outpatientReminder(String outpatientId,String doctorCode)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        JSONObject data = new JSONObject();
//        data.put("order_code","");//订单号
        List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByOutPatientIdList(outpatientId);
        if(wlyyPrescriptionDOS.size()==0){
            throw new Exception("处方信息不存在");
        }
        data.put("card_no",outpatientDO.getCardNo());//社保卡号
        List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(outpatientDO.getDoctor());
        if(doctorHospitalDOS.size()<=0){
            throw new Exception("未找到医生科室编码");
        }
        BaseDoctorHospitalDO doctorHospitalDO = doctorHospitalDOS.get(0);
        data.put("medical_dept_code",doctorHospitalDO.getDeptCode());//科室编码(使用医院科室编号)
        data.put("medical_dept_name",doctorHospitalDO.getDeptName());//科室名称
        data.put("doctor_code",doctorCode);//医师编号(使用医保医生编号)
        data.put("doctor_name",outpatientDO.getDoctorName());//医师姓名
        String result = requestYlz(data,"N21.08.09.01","门诊提醒");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("门诊提醒:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    /**
     * 2.2.2	门诊事中提醒(N21.08.09.02)
     */
    public String outpatientEventReminder(String outpatientId,String doctorCode)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
        if (outpatientDO == null){
            throw new Exception("门诊信息不存在");
        }
        JSONObject data = new JSONObject();
//        data.put("order_code","");//订单号
        data.put("card_no",outpatientDO.getCardNo());//社保卡号
        data.put("visit_no",outpatientDO.getRegisterNo());//门诊挂号号
        data.put("visit_type","1");//就诊类型	String	Y	(1住院、2门诊)
        data.put("medicine_type","");//医疗类别	String	Y
        List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(outpatientDO.getDoctor());
        if(doctorHospitalDOS.size()<=0){
            throw new Exception("未找到医生科室编码");
        }
        BaseDoctorHospitalDO doctorHospitalDO = doctorHospitalDOS.get(0);
        data.put("medical_dept_code",doctorHospitalDO.getDeptCode());//科室编码(使用医院科室编号)
        data.put("medical_dept_name",doctorHospitalDO.getDeptName());//科室名称
        data.put("doctor_code",doctorCode);//医师编号(使用医保医生编号)
        data.put("doctor_name",outpatientDO.getDoctorName());//医师姓名
        data.put("doctor_advice_no","");// 	处方流水号(医院内部唯一号)	String	Y
        //医嘱
        JSONArray advice_details = new JSONArray();
        List<WlyyPrescriptionDO> wlyyPrescriptionDOS = prescriptionDao.findByOutPatientIdList(outpatientId);
        if(wlyyPrescriptionDOS.size()==0){
            throw new Exception("处方信息不存在");
        }
        for (WlyyPrescriptionDO wlyyPrescriptionDO:wlyyPrescriptionDOS){
            List<WlyyPrescriptionInfoDO> prescriptionInfoDOS = prescriptionInfoDao.findByPrescriptionId(wlyyPrescriptionDO.getId(),1);
            for (WlyyPrescriptionInfoDO wlyyPrescriptionInfoDO:prescriptionInfoDOS){
                JSONObject infoObj = new JSONObject();
                infoObj.put("project_code","");//项目编码	String	Y	(使用医保三目录项目编码),正常情况必填,特殊情况,如生化全套等没有医保编码,可放空。
                infoObj.put("hospital_code","");//院内项目编码
                infoObj.put("project_name","");//项目名称
                infoObj.put("recipe_no",wlyyPrescriptionDO.getRealOrder());//处方号
                infoObj.put("invoice_project","");//发票项目编码	String	Y	(使用医保发票项目编码)
                infoObj.put("medical_specification",wlyyPrescriptionInfoDO.getSpecification());//规格型号
                infoObj.put("dose_form",wlyyPrescriptionInfoDO.getDosage());//剂型
                infoObj.put("charge_unit","");//单位
                infoObj.put("price",wlyyPrescriptionInfoDO.getPackRetprice());//单价
                infoObj.put("dose_unit",wlyyPrescriptionInfoDO.getPackRetprice());//单价
                infoObj.put("medical_number",wlyyPrescriptionInfoDO.getQuantity());//数量
                infoObj.put("amount",wlyyPrescriptionInfoDO.getPackRetprice()*Integer.parseInt(wlyyPrescriptionInfoDO.getQuantity()));//金额
                infoObj.put("single_dose_number","");//每次用量
                infoObj.put("single_dose_unit","");//每次用量
                infoObj.put("use_frequency",wlyyPrescriptionInfoDO.getUsageName());//使用频次
                infoObj.put("deliver_way","");//具体给药途径详见附录三的编码
                infoObj.put("use_day",wlyyPrescriptionInfoDO.getDays());//用药天数
/*                dose_form	剂型, 	String	Y	具体可使用剂型详见附录五的编码
                medical_specification	规格	String	Y
                price	单价	String	Y	必须使用数值型,如”12.5”
                medical_number	数量	String	Y	必须使用数值型,如”10”
                dose_unit	单价 String	Y
                amount	金额	String	Y	必须使用数值型,如”50.5”
                use_day	用药天数	String	Y	(项目为药品时非空),医嘱服用该药品天数,必须使用数值型,如”15”
                single_dose_number	单次用药量	String	Y	(项目为药品时非空),配合下一个字段的单位,如 50 mg,必须使用数值型,如”50”
                single_dose_unit	单次用药量剂量单位	String	Y	(项目为药品时非空),具体可使用剂量单位详见附录四的编码
                take_medical_number	取药总量(	String	Y	项目为药品时非空),配合下一个字段的单位,如 500 mg,必须使用数值型,如”500”
                take_medical_unit	取药总量剂量单位	String	Y	(项目为药品时非空),具体可使用剂量单位附录四的编码
                dose_day	药量天数	String	Y	(项目为药品时非空),依据医嘱服药要求,所配药品患者可以服用的天数,必须使用数值型,如”5”
                deliver_way	给药途径	String	Y	具体给药途径详见附录三的编码
                take_frequence	服用频次	String	Y
                具体可用服用频次详见附录二的编码*/
                advice_details.add(infoObj);
            }
        }
        data.put("advice_details",advice_details);
        //诊断
        JSONArray diagnoses = new JSONArray();
        String icd10 = outpatientDO.getIcd10();
        String icd10Name = outpatientDO.getIcd10Name();
        String icd[] = icd10.split(",");
        String icdName[] = icd10Name.split(",");
        for (int i=0;i<icd.length;i++){
            JSONObject icdObj = new JSONObject();
            icdObj.put("disease_code_icd10",icd[i]);//诊断或症状编码
            icdObj.put("disease_name_icd10",icdName[i]);//诊断或症状名称
            diagnoses.add(icdObj);
        }
        data.put("diagnoses",diagnoses);
        String result = requestYlz(data,"N21.08.09.02","门诊事中提醒");
        if(result == null){
            throw new Exception("医保请求失败");
        }
        logger.info("门诊事中提醒:"+result);
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            return encryptData.toJSONString();
        }
        return result;
    }
    public String getYlzToken() throws Exception {
        YlzHttpLogDO ylzHttpLogDO = new YlzHttpLogDO();
        String token = null;
        initConfig();
        String funid = "N00.00.00.01";
        JSONObject data = new JSONObject();
        data.put("appid",ylzConfigAppid);
        data.put("appsecret",ylzConfigAppSecret);
        data.put("grant_type","client_credentials");
        JSONObject object = new JSONObject();
        object.put("sign_type","md5");
        object.put("appid",ylzConfigAppid);
       /* String stringSignTemp ="appid="+ylzConfigAppid+"&appsecret="+ylzConfigAppSecret+"&data="+data+"&funid="+funid+"&sign_type=md5&key="+ylzConfigSignKey;
        String sign = MD5.md5(stringSignTemp).toUpperCase();*/
        object.put("data",data);
        object.put("funid",funid);
        String signResult = SafeUtil.sign(object.toJSONString(),ylzConfigSignKey);
        String obj = SafeUtil.encrypt(signResult,ylzConfigEncryptKey);
        JSONObject jsonObject = JSONObject.parseObject(obj);
        logger.info("请求前funid=="+funid+"data="+data);
        String response = httpClientUtil.postBody(ylzConfigUrl,jsonObject);
        ylzHttpLogDO.setResponseEncrpty(response);
        logger.info("请求后response=="+response);
        if (response!=null&&response!=""){
            JSONObject result = JSONObject.parseObject(response);
            if (result.getString("flag").equalsIgnoreCase("1")){
                String dataResult = result.getString("encrypt_data");
                result.remove("encrypt_data");
                if (dataResult!=null&&dataResult!=""){
                    String decryptResult = AES.aesDecrypt(dataResult,ylzConfigEncryptKey);
                    JSONObject dataObject = JSONObject.parseObject(decryptResult);
                    result.put("encrypt_data",dataObject);
                    response = result.toString();
                    token = dataObject.getString("access_token");
                }
            }
        }
        ylzHttpLogDO.setCode(funid);
        ylzHttpLogDO.setName("获取AccessToken");
        ylzHttpLogDO.setRequest(data.toJSONString());
        ylzHttpLogDO.setRequestEncrpty(obj);
        ylzHttpLogDO.setResponse(response);
        ylzHttpLogDO.setCreateTime(new Date());
        ylzHttpLogDao.save(ylzHttpLogDO);
        
        return token;
    }
    /**
     * 2.2.1渠道应用是否已授权(N20.17.01.01)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String authorized(String patient) throws Exception{
        String funid = "N20.17.01.01";
        BasePatientDO patientDO = patientDao.findById(patient);
        if (patientDO==null){
            throw new Exception("患者信息不存在");
        }
        PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patient);
        if (patientMappingDO==null){
            throw new Exception("患者his信息不存在");
        }
        JSONObject data = new JSONObject();
        data.put("service_id","10000");
        data.put("name",patientDO.getName());
        data.put("idcard",patientDO.getIdcard());
        data.put("cert_type","01");//TODO
        data.put("phone",patientDO.getMobile());
        data.put("user_id",patientMappingDO.getMappingCode());
        String result = requestYlz(data,funid,"渠道应用是否已授权");
        return result;
    }
    /**
     * 2.2.1渠道应用是否已授权(N20.17.01.01)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String authorizedToEntrace(String patient) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"authorized?patient="+patient;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.2.2医保在线服务授权表单(H5表单/小程序)(N20.17.01.02)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String medicareOnline(String patient) throws Exception{
        String funid = "N20.17.01.02";
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("ylzConfigRedirectUrl");
        if (hospitalSysDictDO==null){
            throw new Exception("回调地址为空!");
        }
        BasePatientDO patientDO = patientDao.findById(patient);
        if (patientDO==null){
            throw new Exception("患者信息不存在");
        }
        PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patient);
        if (patientMappingDO==null){
            throw new Exception("患者his信息不存在");
        }
        JSONObject data = new JSONObject();
        data.put("service_id","10000");
        data.put("name",patientDO.getName());
        data.put("idcard",patientDO.getIdcard());
        data.put("cert_type","01");//TODO
        data.put("phone",patientDO.getMobile());
        data.put("user_id",patientMappingDO.getMappingCode());
        data.put("redirect_url",hospitalSysDictDO.getDictValue());
        String result = requestYlz(data,funid,"医保在线服务授权表单");
        return result;
    }
    /**
     * 2.2.2医保在线服务授权表单(H5表单/小程序)(N20.17.01.02)
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public String medicareOnlineToEntrance(String patient) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"medicareOnline?patient="+patient;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.1医保挂号(N20.17.04.01)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String register(String registerNo) throws Exception{
        String funid = "N20.17.04.01";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(registerNo);
        if (ylzMedicalRelationDO==null){
            throw new Exception("上传医保挂号失败:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("his_dept_code",ylzMedicalRelationDO.getHisDeptCode());//his内部科室编码
        data.put("his_dept_name",ylzMedicalRelationDO.getHisDeptName());//his内部科室名称
        data.put("emergency_sign",ylzMedicalRelationDO.getEmergencySign());//急诊标志0 否,1 是
        data.put("trauma_sign",ylzMedicalRelationDO.getTraumaSign());//外伤标志0 否,1 是
        data.put("date", DateUtil.dateToStrLong(ylzMedicalRelationDO.getDate()));//实际门诊/入院日期 若为空,默认取系统时间
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        String result = requestYlz(data,funid,"医保挂号");
        if (result==null){
            throw new Exception("上传医保挂号失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            String insuranceSerial = encryptData.getString("insurance_serial");
            ylzMedicalRelationDO.setInsuranceSerial(insuranceSerial);
            ylzMedicailRelationDao.save(ylzMedicalRelationDO);
            logger.info("医保挂号流水号保存成功");
        }
        return result;
    }
    /**
     * 2.5.1医保挂号(N20.17.04.01)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String registerToEntrance(String registerNo) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"register?registerNo="+registerNo;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.2医保挂号冲销(N20.17.04.02)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String registerBack(String registerNo) throws Exception{
        String funid = "N20.17.04.02";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(registerNo);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保挂号冲销失败:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        String result = requestYlz(data,funid,"医保挂号冲销");
        if (result==null){
            throw new Exception("上传医保挂号冲销失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            String invalidSerial = encryptData.getString("refund_serial");
            logger.info("医保挂号冲销流水号保存成功");
        }
        return result;
    }
    /**
     * 2.5.2医保挂号冲销(N20.17.04.02)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String registerBackToEntrance(String registerNo) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"registerBack?registerNo="+registerNo;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.3医保费用明细上传(N20.17.04.03)
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String feeDetailUpload(String registerNo) throws Exception{
        String funid = "N20.17.04.03";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(registerNo);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保费用明细上传:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型 TODO
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("item_count",ylzMedicalRelationDO.getItemCount());//明细项目数量
        data.put("total_amount",ylzMedicalRelationDO.getTotalAmount());//医疗费总金额
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        List<YlzMedicalIcdDO> ylzMedicalIcdDOList = ylzMedicailIcdDao.findByMedicalId(ylzMedicalRelationDO.getId());
        if (ylzMedicalIcdDOList==null){
            throw new Exception("医保费用明细上传:诊断结算信息为空!");
        }
        JSONArray icdArray = new JSONArray();
        for (YlzMedicalIcdDO ylzMI:ylzMedicalIcdDOList){
            JSONObject icdObj = new JSONObject();
            icdObj.put("disease_code_icd10",ylzMI.getDiseaseCodeIcd10());//诊断或症状编码
            icdObj.put("disease_name_icd10",ylzMI.getDiseaseNameIcd10());//诊断或症状名称
            icdObj.put("disease_type",ylzMI.getDiseaseType());//诊断或症状类型
            icdObj.put("disease_order",ylzMI.getDiseaseOrder());//诊断或症状序号
            icdArray.add(icdObj);
        }
        data.put("zdlist",icdArray);
        List<YlzMedicalMxDO> ylzMedicalMxDOS = ylzMedicailMxDao.findByMedicalId(ylzMedicalRelationDO.getId());
        if (ylzMedicalIcdDOList==null){
            throw new Exception("医保费用明细上传:诊断结算信息为空!");
        }
        JSONArray infoArray = new JSONArray();
        for (YlzMedicalMxDO ylzMedicalMxDO:ylzMedicalMxDOS){
                JSONObject infoObj = new JSONObject();
                infoObj.put("prescription_code",ylzMedicalMxDO.getPrescriptionCode());//医院处方编号
                infoObj.put("his_detail_sn",ylzMedicalMxDO.getHisDetailSn());//his处方明细流水号
                infoObj.put("item_name",ylzMedicalMxDO.getItemName());//医保项目名称
                infoObj.put("item_code",ylzMedicalMxDO.getItemCode());//医保项目编码
                infoObj.put("specification_type",ylzMedicalMxDO.getSpecificationType());//规格型号
                infoObj.put("dosage_form",ylzMedicalMxDO.getDosageForm());//剂型
                infoObj.put("charge_unit",ylzMedicalMxDO.getChargeUnit());//单位
                infoObj.put("price",ylzMedicalMxDO.getPrice());//单价
                infoObj.put("amount",ylzMedicalMxDO.getAmount());//数量
                infoObj.put("total_money",ylzMedicalMxDO.getTotalMoney());//金额
                infoObj.put("prescription_date", DateUtil.dateToStrLong(ylzMedicalMxDO.getPrescriptionDate()));//处方日期
                infoObj.put("his_dept_code",ylzMedicalMxDO.getHisDeptCode());//his内部科室编码
                infoObj.put("his_dept_name",ylzMedicalMxDO.getHisDeptName());//his内部科室名称
                infoObj.put("medical_per_name",ylzMedicalMxDO.getMedicalPerName());//医疗服务人员姓名
                infoObj.put("medical_per_id",ylzMedicalMxDO.getMedicalPerId());//医疗服务人员证件号码
                infoObj.put("limit_type",ylzMedicalMxDO.getLimitType());//限制范围类别
                infoObj.put("actg_date",DateUtil.dateToStr(ylzMedicalMxDO.getActgDate(),DateUtil.YYYYMMDD));//记帐日期
                infoObj.put("his_item_name",ylzMedicalMxDO.getHisItemName());//HIS院内项目名称
                infoObj.put("his_item_code",ylzMedicalMxDO.getHisItemCode());//HIS院内项目编码
                infoObj.put("clerk_days",DateUtil.dateToStrLong(ylzMedicalMxDO.getClerkDays()));//记帐日期
                infoObj.put("people_type",ylzMedicalMxDO.getPeopleType());//医保服务人员类别
                infoArray.add(infoObj);
        }
        data.put("mxlist",infoArray);
        String result = requestYlz(data,funid,"医保费用明细上传");
        if (result==null){
            throw new Exception("医保费用明细上传失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            String detailSerial = encryptData.getString("detail_serial");
            ylzMedicalRelationDO.setDetailSerial(detailSerial);
            ylzMedicailRelationDao.save(ylzMedicalRelationDO);
            logger.info("医保费用明细上传失败保存成功");
        }
        return result;
    }
    /**
     * 2.5.3医保费用明细上传(N20.17.04.03)
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String feeDetailUploadToEntrance(String registerNo) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"feeDetailUpload?registerNo="+registerNo;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.4医保费用明细上传冲销(N20.17.04.04)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String feeDetailRefund(String registerNo,String remark) throws Exception{
        String funid = "N20.17.04.04";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(registerNo);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保费用明细上传:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("detail_serial",ylzMedicalRelationDO.getDetailSerial());//医保明细流水号
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("invalidation_reason",remark);//作废原因
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        String result = requestYlz(data,funid,"医保费用明细上传冲销");
        if (result==null){
            throw new Exception("医保费用明细上传冲销失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            logger.info("医保费用明细上传冲销保存成功");
        }
        return result;
    }
    /**
     * 2.5.4医保费用明细上传冲销(N20.17.04.04)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String feeDetailRefundToEntrance(String registerNo,String remark) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"feeDetailRefund?registerNo="+registerNo+"&remark="+remark;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.5医保预结算服务(N20.17.04.05)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public YlzMedicalRelationDO preSettlement(String registerNo) throws Exception{
        String funid = "N20.17.04.05";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(registerNo);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保费用明细上传:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("his_bill_serial",ylzMedicalRelationDO.getHisBillSerial());//his收费单据流水号
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("settlement_sign",0);//结算标识
        data.put("date",DateUtil.dateToStrLong(ylzMedicalRelationDO.getDate()));//实际就诊日期
        data.put("leave_method","09");//离院方式
        data.put("pre_count",ylzMedicalRelationDO.getPreCount());//处方项目数
        data.put("total_amount",ylzMedicalRelationDO.getTotalAmount());//医疗费总金额
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("doctor_level",ylzMedicalRelationDO.getDoctorLevel());//医师诊查费等级
        data.put("trt_fee_level",ylzMedicalRelationDO.getDoctorLevel());//医师诊查费等级
        data.put("dept_code",ylzMedicalRelationDO.getDeptCode());//科室编码
        data.put("charge_qty",1);//本次收费次数
        String result = requestYlz(data,funid,"医保预结算服务");
        if (result==null){
            throw new Exception("医保预结算服务失败!");
        }
        return ylzMedicalRelationDO;
    }
    /**
     * 2.5.5医保预结算服务(N20.17.04.05)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public YlzMedicalRelationDO preSettlementToEntrance(String registerNo) throws Exception{
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(registerNo);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保费用明细上传:结算信息为空!");
        }
        List<YlzMedicalIcdDO> icdDOList = ylzMedicailIcdDao.findByMedicalId(ylzMedicalRelationDO.getId());;
        if (icdDOList!=null){
            ylzMedicalRelationDO.setYlzMedicalIcdDOList(icdDOList);
        }
        List<YlzMedicalMxDO> mxDOList = ylzMedicailMxDao.findByMedicalId(ylzMedicalRelationDO.getId());;
        if (mxDOList!=null){
            ylzMedicalRelationDO.setYlzMedicalMxDOList(mxDOList);
        }
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"preSettlement?registerNo="+registerNo;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
            JSONObject jsonObject1 = JSONObject.parseObject(result);
            if (jsonObject1.getString("flag").equalsIgnoreCase("1")){
                JSONObject encryptData = jsonObject1.getJSONObject("encrypt_data");
                String billSerial = encryptData.getString("bill_serial");
                ylzMedicalRelationDO.setInsuranceSerial(encryptData.getString("insurance_serial"));
                ylzMedicalRelationDO.setBillSerial(encryptData.getString("bill_serial"));
                ylzMedicalRelationDO.setHisBillSerial(encryptData.getString("his_bill_serial"));
                ylzMedicalRelationDO.setSexMc(encryptData.getString("sex_mc"));
                ylzMedicalRelationDO.setPersonCash(encryptData.getString("person_cash"));
                ylzMedicalRelationDO.setPersonAccount(encryptData.getString("person_account"));
                ylzMedicalRelationDO.setFundPrice(encryptData.getString("fund_price"));
                ylzMedicalRelationDO.setJkzhPay(encryptData.getString("jkzh_pay"));
                ylzMedicalRelationDO.setOwnPay(encryptData.getString("own_pay"));
                ylzMedicalRelationDO.setAccountBalance(encryptData.getString("account_balance"));
                ylzMedicalRelationDO.setHospitalizationQty(encryptData.getString("hospitalization_qty"));
                ylzMedicalRelationDO.setPayDate(DateUtil.strToDateLong(encryptData.getString("pay_date")));
                ylzMedicalRelationDO.setInvoiceJj(encryptData.getString("invoice_jj"));
                ylzMedicalRelationDO.setInvoiceXj(encryptData.getString("invoice_xj"));
                ylzMedicalRelationDO.setInvoiceZh(encryptData.getString("invoice_zh"));
                ylzMedicalRelationDO.setCreateTime(new Date());
                ylzMedicalRelationDO = ylzMedicailRelationDao.save(ylzMedicalRelationDO);
                JSONArray jsonArray = encryptData.getJSONArray("fplist");
                for (int i=0;i<jsonArray.size();i++){
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    YlzMedicalBillDO ylzMb = new YlzMedicalBillDO();
                    ylzMb.setMedicalId(ylzMedicalRelationDO.getId());
                    ylzMb.setInvoicePay(jsonObject.getString("invoice_pay"));
                    ylzMb.setInvoiceType(jsonObject.getString("invoice_type"));
                    ylzMb.setInvoiceTypeName(jsonObject.getString("invoice_type_name"));
                    ylzMb.setProjectPay(jsonObject.getString("project_pay"));
                    ylzMb.setOwnPay(jsonObject.getString("own_pay"));
                    ylzMb.setSpecialPay(jsonObject.getString("special_pay"));
                    ylzMb.setUninsurancePay(jsonObject.getString("uninsurance_pay"));
                    ylzMb.setCreateTime(new Date());
                    ylzMedicailBillDao.save(ylzMb);
                }
                logger.info("医保预结算服务保存成功");
            }
        }else {
            return null;
        }
        return ylzMedicalRelationDO;
    }
    /**
     * 2.5.6医保结算冲销服务(N20.17.04.06)
     *
     * 返回值
     *
     * @param registerNo
     * @return
     * @throws Exception
     */
    public String preSettlementRefundToEntrance(String registerNo) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"feeDetailRefund?registerNo="+registerNo;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.6医保结算冲销服务(N20.17.04.06)
     *
     * 返回值
     *
     * @param registerNo
     * @return
     * @throws Exception
     */
    public String preSettlementRefund(String registerNo) throws Exception{
        String funid = "N20.17.04.06";
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(registerNo);
        if (ylzMedicalRelationDO==null){
            throw new Exception("医保结算冲销上传:结算信息为空!");
        }
        JSONObject data = new JSONObject();
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("bill_serial",ylzMedicalRelationDO.getBillSerial());//医保收费流水号
        data.put("his_bill_serial",ylzMedicalRelationDO.getHisSerial());//his收费单据流水号
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        data.put("refund_serial",ylzMedicalRelationDO.getHisSerial());//医院退费操作流水号
        String result = requestYlz(data,funid,"医保结算冲销服务");
        if (result==null){
            throw new Exception("医保结算冲销服务失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            logger.info("医保结算冲销服务保存成功");
        }
        return result;
    }
    /**
     * 2.5.7获取医保结算页面地址(N20.17.04.07)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String getSettlementResultUrl(String registerNo) throws Exception{
        String funid = "N20.17.04.07";
        JSONObject data = new JSONObject();
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(registerNo);
        if (ylzMedicalRelationDO==null){
            throw new Exception("获取医保结算页面地址:结算信息为空!");
        }
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("ResultRedirectUrl");
        if (wlyyHospitalSysDictDO==null){
            throw new Exception("获取医保结算页面地址失败:回调地址为空");
        }
        data.put("region_code",ylzMedicalRelationDO.getRegionCode());//参保地区划代码
        data.put("name",ylzMedicalRelationDO.getName());//姓名
        data.put("idcard",ylzMedicalRelationDO.getIdcard());//证件号码
        data.put("cert_type",ylzMedicalRelationDO.getCertType());//证件类型
        data.put("medical_mode",ylzMedicalRelationDO.getMedicalMode());//医疗就诊方式
        data.put("medical_type",ylzMedicalRelationDO.getMedicalType());//医疗类别
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//
        data.put("his_bill_serial",ylzMedicalRelationDO.getHisBillSerial());//his收费单据流水号
        data.put("date",ylzMedicalRelationDO.getDate());//实际就诊日期
        data.put("leave_method","09");//离院方式
        data.put("pre_count",ylzMedicalRelationDO.getPreCount());//处方项目数
        data.put("total_amount",ylzMedicalRelationDO.getTotalAmount());//医疗费总金额
        data.put("person_cash",ylzMedicalRelationDO.getPersonCash());//个人现金支付金额(实付现金)
        data.put("person_account",ylzMedicalRelationDO.getPersonAccount());//个人账户支付金额
        data.put("fund_price",ylzMedicalRelationDO.getFundPrice());//基金支付总额
        data.put("data_source",ylzMedicalRelationDO.getDataSource());//数据来源
        data.put("his_serial",ylzMedicalRelationDO.getHisSerial());//his流水号
        data.put("doctor_level",ylzMedicalRelationDO.getDoctorLevel());//医师诊查费等级
        data.put("redirect_url",wlyyHospitalSysDictDO.getDictValue());//回调地址
        String result = requestYlz(data,funid,"获取医保结算结果");
        if (result==null){
            throw new Exception("获取医保结算结果失败!");
        }
        return result;
    }
    /**
     * 2.5.7获取医保结算页面地址(N20.17.04.07)
     *
     * 返回值
     *
     * @param registerNo 挂号号
     * @return
     * @throws Exception
     */
    public String getSettlementResultUrlToEntrance(String registerNo) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"getSettlementResultUrl?registerNo="+registerNo;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.5.8获取医保结算结果(N20.17.04.08)
     *
     * 返回值
     *
     * @param code
     * @return
     * @throws Exception
     */
    public String getSettlementResult(String code) throws Exception{
        String funid = "N20.17.04.08";
        JSONObject data = new JSONObject();
        data.put("code",code);//参保地区划代码
        String result = requestYlz(data,funid,"获取医保结算结果");
        if (result==null){
            throw new Exception("获取医保结算结果失败!");
        }
        return result;
    }
    /**
     * 2.5.8获取医保结算结果(N20.17.04.08)
     *
     * 返回值
     *
     * @param code
     * @return
     * @throws Exception
     */
    public String getSettlementResultToEntrance(String code) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"getSettlementResultUrl?code="+code;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.7.1上传用户病史病情及医学报告(N20.17.06.01)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String uploadMedicalHistory(String outpatientId) throws Exception{
        String funid = "N20.17.06.01";
        JSONObject data = new JSONObject();
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(outpatientId);
        if (wlyyOutpatientDO==null){
            throw new Exception("医保上传户病史病情及医学报告失败!门诊为空");
        }
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(wlyyOutpatientDO.getRegisterNo());
        if (ylzMedicalRelationDO==null){
            throw new Exception("获取医保结算页面地址:结算信息为空!");
        }
        data.put("region_code","350200");//参保地区划代码
        data.put("idcard",wlyyOutpatientDO.getId());//身份证号
        data.put("name",wlyyOutpatientDO.getPatientName());//姓名
        data.put("cert_type","01");//证件类型
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("blood_type",wlyyOutpatientDO.getBloodType());//血型
        data.put("allergy",wlyyOutpatientDO.getAllergy());//过敏史
        data.put("diagnosis",wlyyOutpatientDO.getIcd10Name());//病理诊断
        data.put("describe",wlyyOutpatientDO.getDescription());//病情描述
        data.put("difficult_cases","无");//疑难病例
        data.put("file_list_count",0);//医学报告附件数量
        data.put("data_source","53");//数据来源
        String result = requestYlz(data,funid,"上传用户病史病情及医学报告");
        if (result==null){
            throw new Exception("上传用户病史病情及医学报告失败!");
        }
        JSONObject object = JSONObject.parseObject(result);
        if (object.getString("flag").equalsIgnoreCase("1")){
            JSONObject encryptData = object.getJSONObject("encrypt_data");
            wlyyOutpatientDO.setInsuranceMedHistserial(encryptData.getString("insurance_med_hist_serial"));
            logger.info("上传用户病史病情及医学报告保存成功");
        }
        return result;
    }
    /**
     * 2.7.1上传用户病史病情及医学报告(N20.17.06.01)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String uploadMedicalHistoryToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"uploadMedicalHistory?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.7.2作废用户病史病情及医学报告(N20.17.06.06)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String refundMedicalHistory(String outpatientId,String remark) throws Exception{
        String funid = "N20.17.06.06";
        JSONObject data = new JSONObject();
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(outpatientId);
        if (wlyyOutpatientDO==null){
            throw new Exception("医保上传户病史病情及医学报告失败!门诊为空");
        }
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(wlyyOutpatientDO.getRegisterNo());
        if (ylzMedicalRelationDO==null){
            throw new Exception("获取医保结算页面地址:结算信息为空!");
        }
        data.put("insurance_serial",ylzMedicalRelationDO.getInsuranceSerial());//医保流水号
        data.put("insurance_med_hist_serial",wlyyOutpatientDO.getInsuranceMedHistserial());//医保病史上传流水号
        data.put("invalid_reason",remark);//作废原因
        data.put("data_source","53");//数据来源
        String result = requestYlz(data,funid,"作废用户病史病情及医学报告");
        if (result==null){
            throw new Exception("作废用户病史病情及医学报告失败!");
        }
        return result;
    }
    /**
     * 2.7.2作废用户病史病情及医学报告(N20.17.06.06)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String refundMedicalHistoryToEntrance(String outpatientId,String remark) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"refundMedicalHistory?outpatientId="+outpatientId+"&remark="+remark;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    /**
     * 2.7.3获取问诊过程数据(N20.17.06.02)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String uploadIcdProcess(String outpatientId) throws Exception{
        String funid = "N20.17.06.02";
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(outpatientId);
        if (wlyyOutpatientDO==null){
            throw new Exception("获取问诊过程数据失败!门诊为空");
        }
        BaseDoctorDO doctorDO = doctorDao.findById(wlyyOutpatientDO.getDoctor());
        if (doctorDO==null){
            throw new Exception("获取问诊过程数据失败!医生信息为空");
        }
        JSONObject data = new JSONObject();
        data.put("region_code","350200");//参保地区划代码
        data.put("idcard",wlyyOutpatientDO.getIdcard());//身份证号
        data.put("name",wlyyOutpatientDO.getPatientName());//姓名
        data.put("cert_type","01");//证件类型
        data.put("service_serial_id",wlyyOutpatientDO.getRegisterNo());//问诊流水号
        data.put("doctor_id_card",doctorDO.getIdcard());//医师身份证
        data.put("doctor_name",wlyyOutpatientDO.getDoctorName());//医师姓名
        /*data.put("file_list_count","");//附件总数
        data.put("filelist","");//附件列表
        data.put("file_bytes","");//二进制字节流
        data.put("file_name","");//文件名
        data.put("order_num",0);//顺序号*/
        String result = requestYlz(data,funid,"获取问诊过程数据");
        if (result==null){
            throw new Exception("获取问诊过程数据失败!");
        }
        return result;
    }
    /**
     * 2.7.3获取问诊过程数据(N20.17.06.02)
     *
     * 返回值
     *
     * @param outpatientId
     * @return
     * @throws Exception
     */
    public String uploadIcdProcessToEntrance(String outpatientId) throws Exception{
        String result = "";
        String response="";
        String url = entranceHealthCareUrl+"uploadIcdProcess?outpatientId="+outpatientId;
        response = httpClientUtil.get(url,"GBK");
        logger.info("response:"+response);
        JSONObject object = JSONObject.parseObject(response);
        if (object.getInteger("status")==200){
            result = object.getString("obj");
        }
        return result;
    }
    public Boolean isHospitalFlag(){
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("medicalFlag");
        if (hospitalSysDictDO!=null){
            if (hospitalSysDictDO.getDictValue().equalsIgnoreCase("1")){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }
}

+ 92 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/AES.java

@ -0,0 +1,92 @@
package com.yihu.jw.healthCare.utils;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.springframework.util.StringUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class AES {
    public static final String KEY_ALGORITHM = "AES";
    public static final String CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
    public AES() {
    }
    public static String base64Encode(byte[] bytes) {
        return (new BASE64Encoder()).encode(bytes);
    }
    public static byte[] base64Decode(String base64Code) throws Exception {
        return StringUtils.isEmpty(base64Code) ? null : (new BASE64Decoder()).decodeBuffer(base64Code);
    }
    private static Key toKey(byte[] key) {
        SecretKey secretKey = new SecretKeySpec(key, "AES");
        return secretKey;
    }
    public static byte[] decrypt(byte[] data, String password) {
        try {
            Key k = toKey(initKey(password));
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(2, k);
            return cipher.doFinal(data);
        } catch (Throwable var4) {
            var4.printStackTrace();
            return null;
        }
    }
    public static String aesDecrypt(String encryptStr, String decryptKey) throws Exception {
        return aesDecrypt(encryptStr, decryptKey, "utf-8");
    }
    public static String aesDecrypt(String encryptStr, String decryptKey, String encode) throws Exception {
        return StringUtils.isEmpty(encryptStr) ? null : new String(decrypt(base64Decode(encryptStr), decryptKey), encode);
    }
    public static byte[] encrypt(byte[] data, String password) {
        try {
            Key k = toKey(initKey(password));
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(1, k);
            return cipher.doFinal(data);
        } catch (Throwable var4) {
            var4.printStackTrace();
            return null;
        }
    }
    public static String aesEncrypt(String content, String encryptKey) throws Exception {
        return aesEncrypt(content, encryptKey, "utf-8");
    }
    public static String aesEncrypt(String content, String encryptKey, String encode) throws Exception {
        return base64Encode(encrypt(content.getBytes(encode), encryptKey));
    }
    private static byte[] initKey(String password) throws NoSuchAlgorithmException {
        KeyGenerator kg = KeyGenerator.getInstance("AES");
        SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
        random.setSeed(password.getBytes());
        kg.init(128, random);
        SecretKey secretKey = kg.generateKey();
        return secretKey.getEncoded();
    }
    public static void main(String[] args) {
        try {
            System.out.println(base64Encode(aesEncrypt("jjjk", "zephyr").getBytes()));
        } catch (Exception var2) {
            var2.printStackTrace();
        }
    }
}

+ 86 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/ConvertUtils.java

@ -0,0 +1,86 @@
package com.yihu.jw.healthCare.utils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;
/**
 * @Author: lcp
 * @Date: 2020/7/6 21:28
 */
public class ConvertUtils {
    private static String[] trueStrings = new String[]{"1", "true", "y", "on", "yes"};
    public ConvertUtils() {
    }
    public static String toString(Object obj, String defaults) {
        String rlt;
        try {
            rlt = obj.toString();
        } catch (Exception var4) {
            rlt = defaults;
        }
        return rlt;
    }
    public static String toString(Object obj) {
        return toString(obj, (String)null);
    }
    public static Integer toInt(Object obj, Integer defaults) {
        Integer rlt;
        try {
            rlt = Integer.parseInt(obj.toString());
        } catch (Exception var4) {
            rlt = defaults;
        }
        return rlt;
    }
    public static int toInt(Object obj) {
        return toInt(obj, 0);
    }
    public static Long toLong(Object obj, Long defaults) {
        Long rlt;
        try {
            rlt = Long.parseLong(obj.toString());
        } catch (Exception var4) {
            rlt = defaults;
        }
        return rlt;
    }
    public static long toLong(Object obj) {
        return toLong(obj, 0L);
    }
    public static Double toDouble(Object obj, Double defaults) {
        Double rlt;
        try {
            rlt = Double.parseDouble(obj.toString());
        } catch (Exception var4) {
            rlt = defaults;
        }
        return rlt;
    }
    public static double toDouble(Object obj) {
        return toDouble(obj, 0.0D);
    }
    public static BigDecimal formatDecimal(BigDecimal num, String format) {
        DecimalFormat df = new DecimalFormat(format);
        return new BigDecimal(df.format(num));
    }
}

+ 44 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/MD5.java

@ -0,0 +1,44 @@
package com.yihu.jw.healthCare.utils;
import java.security.MessageDigest;
public class MD5 {
    public MD5() {
    }
    public static String md5(String str) {
        return md5(str, "utf-8");
    }
    public static String md5(String str, String charset) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes(charset));
            byte[] b = md.digest();
            StringBuffer buf = new StringBuffer("");
            for(int offset = 0; offset < b.length; ++offset) {
                int i = b[offset];
                if (i < 0) {
                    i += 256;
                }
                if (i < 16) {
                    buf.append("0");
                }
                buf.append(Integer.toHexString(i));
            }
            str = buf.toString();
        } catch (Exception var7) {
            var7.printStackTrace();
        }
        return str;
    }
    public static void main(String[] args) {
        System.out.println(md5("appid=test&appsecret=test1234&data={\"aid\":\"2\",\"bid\":\"1\"}&funid=ybjjtest&key=testkey").toUpperCase());
    }
}

+ 19 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/ReqDto.java

@ -0,0 +1,19 @@
package com.yihu.jw.healthCare.utils;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
/**
 *  //明文入参,json key必须包含 sign_type,encrypt_type,funid,data,access_token 这五个。顺序无所谓
 *
 * @Author: lcp
 * @Date: 2020/7/6 21:19
 */
@Data
public class ReqDto {
    private String funid;//接口id
    private JSONObject data;//数据
    private String encrypt_type="AES";//加密类型
    private String access_token;//有效凭证
    private String sign_type="MD5";//签名类型
}

+ 269 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/SM4.java

@ -0,0 +1,269 @@
package com.yihu.jw.healthCare.utils;
import org.apache.commons.lang3.ArrayUtils;
import java.io.IOException;
import java.util.Arrays;
/**
 * 国密算法SM4实现
 * @create 2019/8/7
 */
public class SM4 {
    public static final String key = "86C63180C2806ED1F47B859DE501215B";
	private static final int ENCRYPT=1;
	private static final int DECRYPT=0;
	public static final int ROUND=32;
	private static final int BLOCK=16;
    private static class SM4Holder{
        private static SM4 instance=new SM4();
    }
    public SM4(){
    }
    public static SM4 getInstance(){
        return SM4Holder.instance;
    }
	
	private byte[] Sbox={
			(byte) 0xd6,(byte) 0x90,(byte) 0xe9,(byte) 0xfe,(byte) 0xcc,(byte) 0xe1,0x3d,(byte) 0xb7,0x16,(byte) 0xb6,0x14,(byte) 0xc2,0x28,(byte) 0xfb,0x2c,0x05,
			0x2b,0x67,(byte) 0x9a,0x76,0x2a,(byte) 0xbe,0x04,(byte) 0xc3,(byte) 0xaa,0x44,0x13,0x26,0x49,(byte) 0x86,0x06,(byte) 0x99,
			(byte) 0x9c,0x42,0x50,(byte) 0xf4,(byte) 0x91,(byte) 0xef,(byte) 0x98,0x7a,0x33,0x54,0x0b,0x43,(byte) 0xed,(byte) 0xcf,(byte) 0xac,0x62,
			(byte) 0xe4,(byte) 0xb3,0x1c,(byte) 0xa9,(byte) 0xc9,0x08,(byte) 0xe8,(byte) 0x95,(byte) 0x80,(byte) 0xdf,(byte) 0x94,(byte) 0xfa,0x75,(byte) 0x8f,0x3f,(byte) 0xa6,
			0x47,0x07,(byte) 0xa7,(byte) 0xfc,(byte) 0xf3,0x73,0x17,(byte) 0xba,(byte) 0x83,0x59,0x3c,0x19,(byte) 0xe6,(byte) 0x85,0x4f,(byte) 0xa8,
			0x68,0x6b,(byte) 0x81,(byte) 0xb2,0x71,0x64,(byte) 0xda,(byte) 0x8b,(byte) 0xf8,(byte) 0xeb,0x0f,0x4b,0x70,0x56,(byte) 0x9d,0x35,
			0x1e,0x24,0x0e,0x5e,0x63,0x58,(byte) 0xd1,(byte) 0xa2,0x25,0x22,0x7c,0x3b,0x01,0x21,0x78,(byte) 0x87,
			(byte) 0xd4,0x00,0x46,0x57,(byte) 0x9f,(byte) 0xd3,0x27,0x52,0x4c,0x36,0x02,(byte) 0xe7,(byte) 0xa0,(byte) 0xc4,(byte) 0xc8,(byte) 0x9e,
			(byte) 0xea,(byte) 0xbf,(byte) 0x8a,(byte) 0xd2,0x40,(byte) 0xc7,0x38,(byte) 0xb5,(byte) 0xa3,(byte) 0xf7,(byte) 0xf2,(byte) 0xce,(byte) 0xf9,0x61,0x15,(byte) 0xa1,
			(byte) 0xe0,(byte) 0xae,0x5d,(byte) 0xa4,(byte) 0x9b,0x34,0x1a,0x55,(byte) 0xad,(byte) 0x93,0x32,0x30,(byte) 0xf5,(byte) 0x8c,(byte) 0xb1,(byte) 0xe3,
			0x1d,(byte) 0xf6,(byte) 0xe2,0x2e,(byte) 0x82,0x66,(byte) 0xca,0x60,(byte) 0xc0,0x29,0x23,(byte) 0xab,0x0d,0x53,0x4e,0x6f,
			(byte) 0xd5,(byte) 0xdb,0x37,0x45,(byte) 0xde,(byte) 0xfd,(byte) 0x8e,0x2f,0x03,(byte) 0xff,0x6a,0x72,0x6d,0x6c,0x5b,0x51,
			(byte) 0x8d,0x1b,(byte) 0xaf,(byte) 0x92,(byte) 0xbb,(byte) 0xdd,(byte) 0xbc,0x7f,0x11,(byte) 0xd9,0x5c,0x41,0x1f,0x10,0x5a,(byte) 0xd8,
			0x0a,(byte) 0xc1,0x31,(byte) 0x88,(byte) 0xa5,(byte) 0xcd,0x7b,(byte) 0xbd,0x2d,0x74,(byte) 0xd0,0x12,(byte) 0xb8,(byte) 0xe5,(byte) 0xb4,(byte) 0xb0,
			(byte) 0x89,0x69,(byte) 0x97,0x4a,0x0c,(byte) 0x96,0x77,0x7e,0x65,(byte) 0xb9,(byte) 0xf1,0x09,(byte) 0xc5,0x6e,(byte) 0xc6,(byte) 0x84,
			0x18,(byte) 0xf0,0x7d,(byte) 0xec,0x3a,(byte) 0xdc,0x4d,0x20,0x79,(byte) 0xee,0x5f,0x3e,(byte) 0xd7,(byte) 0xcb,0x39,0x48
	};
	
	private int[] CK={
			0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269,
			0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9,
			0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249,
			0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9,
			0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229,
			0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299,
			0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209,
			0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279
	};
	
	private int Rotl(int x,int y)
	{
		return x<<y|x>>>(32-y);
	}
	
	private int ByteSub(int A)
	{
		return (Sbox[A>>>24&0xFF]&0xFF)<<24|(Sbox[A>>>16&0xFF]&0xFF)<<16|(Sbox[A>>>8&0xFF]&0xFF)<<8|(Sbox[A&0xFF]&0xFF);
	}
	private int L1(int B)
	{
		return B^Rotl(B,2)^Rotl(B,10)^Rotl(B,18)^Rotl(B,24);
	}
	
	private int L2(int B)
	{
		return B^Rotl(B,13)^Rotl(B,23);
	}
	
	
	void SMS4Crypt(byte[] Input,byte[] Output,int[] rk)
	{
		int r,mid,x0,x1,x2,x3;
		int[] x= new int[4];
		int[] tmp = new int[4];
		for(int i=0;i<4;i++)
		{
			tmp[0]=Input[0+4*i]&0xff;
			tmp[1]=Input[1+4*i]&0xff;
			tmp[2]=Input[2+4*i]&0xff;
			tmp[3]=Input[3+4*i]&0xff;
			x[i]=tmp[0]<<24|tmp[1]<<16|tmp[2]<<8|tmp[3];
		}
		for(r=0;r<32;r+=4)
		{
			mid=x[1]^x[2]^x[3]^rk[r+0];
			mid=ByteSub(mid);
			x[0]=x[0]^L1(mid);   //x4
			
			mid=x[2]^x[3]^x[0]^rk[r+1];
			mid=ByteSub(mid);
			x[1]=x[1]^L1(mid);	//x5
			
			mid=x[3]^x[0]^x[1]^rk[r+2];
			mid=ByteSub(mid);
			x[2]=x[2]^L1(mid);	//x6
			
			mid=x[0]^x[1]^x[2]^rk[r+3];
			mid=ByteSub(mid);
			x[3]=x[3]^L1(mid);	//x7
		}
		
		//Reverse
		for(int j=0;j<16;j+=4)
		{
			Output[j]  =(byte) (x[3-j/4]>>>24&0xFF);
			Output[j+1]=(byte) (x[3-j/4]>>>16&0xFF);
			Output[j+2]=(byte) (x[3-j/4]>>>8&0xFF);
			Output[j+3]=(byte) (x[3-j/4]&0xFF);
		}
	}
	
	private void SMS4KeyExt(byte[] Key,int[] rk,int CryptFlag)
	{
		int r,mid;
		int[] x= new int[4];
		int[] tmp =new int[4];
		for(int i=0;i<4;i++)
		{
			tmp[0]=Key[0+4*i]&0xFF;
			tmp[1]=Key[1+4*i]&0xff;
			tmp[2]=Key[2+4*i]&0xff;
			tmp[3]=Key[3+4*i]&0xff;
			x[i]=tmp[0]<<24|tmp[1]<<16|tmp[2]<<8|tmp[3];
		}
		x[0]^=0xa3b1bac6;
		x[1]^=0x56aa3350;
		x[2]^=0x677d9197;
		x[3]^=0xb27022dc;
		for(r=0;r<32;r+=4)
		{
			mid=x[1]^x[2]^x[3]^CK[r+0];
			mid=ByteSub(mid);
			rk[r+0]=x[0]^=L2(mid);		//rk0=K4
			
			mid=x[2]^x[3]^x[0]^CK[r+1];
			mid=ByteSub(mid);
			rk[r+1]=x[1]^=L2(mid);		//rk1=K5
			
			mid=x[3]^x[0]^x[1]^CK[r+2];
			mid=ByteSub(mid);
			rk[r+2]=x[2]^=L2(mid);		//rk2=K6
			
			mid=x[0]^x[1]^x[2]^CK[r+3];
			mid=ByteSub(mid);
			rk[r+3]=x[3]^=L2(mid);		//rk3=K7
		}
		
		if(CryptFlag==DECRYPT)
		{
			for(r=0;r<16;r++)
			{
				mid=rk[r];
				rk[r]=rk[31-r];
				rk[31-r]=mid;
			}
		}
	}
	
	public byte[] sms4(byte[] in,int inLen,byte[] key,int CryptFlag)
	{
		int point=0;
		int[] round_key=new int[ROUND]; 
		//int[] round_key={0};
		SMS4KeyExt(key,round_key,CryptFlag);
		byte[] input = new byte[16];
		byte[] output = new byte[16];
		byte[] out = new byte[16];
		while(inLen>=BLOCK)
		{
			input=Arrays.copyOfRange(in, point, point+16);
			SMS4Crypt(input,output,round_key);
			System.arraycopy(output, 0, out, point, BLOCK);
			inLen-=BLOCK;
			point+=BLOCK;
		}
		
		return out;
	}
	
	public String encode(String input,String key) throws IOException{
		byte[] b_input = input.getBytes("utf-8");
		byte[] b_key = new byte[16];
		byte[] bbs = key.getBytes("utf-8");
		if(bbs.length < 16){
			for(int i=0;i<bbs.length;i++){
				b_key[i] = bbs[i];
			}
		}else{
			b_key = bbs;
		}
		
		byte[] o = new byte[0];
		for(int i=0;i<b_input.length;i+=16){
			byte[] t = ArrayUtils.subarray(b_input, i, i+16);
			o = ArrayUtils.addAll(o, sms4(t,16,b_key,1));
		}
		return new sun.misc.BASE64Encoder().encode(o);
	}
	
	public String decode(String input,String key) throws IOException{
		byte[] b_input = new sun.misc.BASE64Decoder().decodeBuffer(input);
		byte[] b_key = new byte[16];
		byte[] bbs = key.getBytes("utf-8");
		
		if(bbs.length < 16){
			for(int i=0;i<bbs.length;i++){
				b_key[i] = bbs[i];
			}
		}else{
			b_key = bbs;
		}
		
		byte[] o = new byte[0];
		for(int i=0;i<b_input.length;i+=16){
			byte[] t = ArrayUtils.subarray(b_input, i, i+16);
			byte[] t1 = sms4(t,16,b_key,0);
			o = ArrayUtils.addAll(o,t1);
		}
		
		return new String(o,"utf-8").trim();
	}
	
	public static void main(String[] args) {
		String md5 = MD5.md5("ee8b43dde7c94f0384fcbf4b4e589c74");//对密钥进行MD5
		String xmlStr="<?xml version=\"1.0\" encoding=\"GB2312\"?>\n" +
				"<Case>\n" +
				"\t\t<data>\n" +
				"    <evaluation>\n" +
				"<!--评价信息UNID,用于关联评价整改反馈-->\n" +
				"        <evaluateUnid>评价信息唯一码(评价信息unid)</evaluateUnid>\n" +
				"        <apasInfoName>办件名称</apasInfoName>\n" +
				"<businessCode>省网事项编码</businessCode>\n" +
				"<serviceName>事项名称</serviceName>\n" +
				"<projectNo>办件申报号</ projectNo>\n" +
				"                <!-- 1:pc端,2:移动端,3:二维码,4:政务大厅平板电脑,5:政务大厅其他终端),6:电话,7:短信 -->\n" +
				"<pf>评价渠道</pf>\n" +
				"<contactName>评价人姓名</contactName>\n" +
				"<contactMobile>评价人手机号码</contactMobile>\n" +
				"\t            <isReceive>是否完成省网办办件汇聚</isReceive>\n" +
				"\t            <regionCode> 6位行政区划编码</regionCode>\n" +
				"                <!-- 第一次主动评价=1,追加评价=2 -->\n" +
				"\t            <evaluateType>评价类型</evaluateType>\n" +
				"<alternate>整体满意度</alternate>\n" +
				"<appraisald>评价详情</appraisald>\n" +
				"<writingevalua>文字评价</writingevalua>\n" +
				"<assesstime>评价时间</assesstime>\n" +
				"<nodeName>环节名称</nodeName>\n" +
				"</evaluation>\n" +
				"</data>\n" +
				"</Case>";
		try {
			String str = new SM4().encode(xmlStr, md5);//sm4对数据加密
			System.out.println("加密后:"+str);
		} catch (Exception e) {
		}
	}
	
}

+ 99 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/SafeUtil.java

@ -0,0 +1,99 @@
package com.yihu.jw.healthCare.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
public class SafeUtil {
    public static void main(String[] args) throws Exception {
        //String reqStr = "{\"funid\":\"N09.00.00.01\",\"data\":{\"idNo\":\"350823199201173123\",\"first\":\"022\",\"keyword1\":\"5\",\"keyword2\":\"通过审核\",\"keyword3\":\"20200706155415\"},\"access_token\":\"4f886faf22775ccc9c8add16268ca9cd\",\"sign_type\":\"MD5\",\"encrypt_type\":\"AES\"}";
        //solution(reqStr,"signBefore");
        System.out.println(AES.aesDecrypt("BUOL01yRhFPlT2J+6wTYzNc9Hv3aAwwjOGdqoU6NIe2wvR9MMg6p0Jv4h012uwDKrBv3HGIXu1t7xVStC/nX4QKmYDelbd+hUFl5QZQ6FX1f0LPXNki99HKcSV00aB+DDb9j9ocfr/z3G091yNHAo+VD/FxFo60agRdcv1vl7Hg=", "4bfb6947baf9df93"));
    }
    public static String  solution(String reqStr,String signKey,String type) throws Exception {
        if("beforeSign".equals(type)){
            //先签名再加密
            reqStr = sign(reqStr,signKey);
            reqStr = encrypt(reqStr,signKey);
        }else{
            //先加密再签名
            reqStr = encrypt(reqStr,signKey);
            reqStr = sign(reqStr,signKey);
        }
        System.out.println("最终请求数据消息体(签名加密后的):" + reqStr);
        return reqStr;
    }
    private static String getSortSignTemp(JSONObject json) {
        String signTemp = "";
        String jsonStr = JSONObject.toJSONString(json, SerializerFeature.MapSortField);
        LinkedHashMap m = JSON.parseObject(jsonStr, LinkedHashMap.class);
        Iterator<Map.Entry> iterator = m.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = iterator.next();
            String strVal = "";
            if (entry.getValue() instanceof Map) {
                strVal = JSONObject.toJSONString(entry.getValue(), SerializerFeature.MapSortField);
            } else {
                strVal = ConvertUtils.toString(entry.getValue(), "");
            }
            signTemp += entry.getKey() + "=" + strVal + "&";
        }
        signTemp = StringUtils.trimEnd(signTemp, "&");
        return signTemp;
    }
    public static String sign(String reqStr,String signKey) {
        JSONObject md5Json = JSONObject.parseObject(reqStr);
        String sign = md5Json.getString("sign");
        md5Json.remove("sign");
        String signTemp = getSortSignTemp(md5Json) + "&key=" + signKey;
        System.out.println(signTemp);
        String md5Sign = MD5.md5(signTemp).toUpperCase();
        md5Json.put("sign", md5Sign);
        reqStr = JSON.toJSONString(md5Json);
        return reqStr;
    }
    public static   String encrypt(String reqStr,String decryptKey) {
        //key
        JSONObject encJson = JSONObject.parseObject(reqStr);
        JSONObject dataJson = encJson.getJSONObject("data");
        encJson.remove("data");
        String encData = "";
        try {
            encData = AES.aesEncrypt(JSON.toJSONString(dataJson), decryptKey);
        } catch (Exception e) {
            e.printStackTrace();
        }
        encJson.put("encrypt_data", encData);
        reqStr = JSON.toJSONString(encJson);
        reqStr = reqStr.replaceAll("\\\\r\\\\n", "");
        try {
            System.out.println("解密 : " + AES.aesDecrypt(encData, decryptKey));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return reqStr;
    }
}

+ 55 - 0
business/base-service/src/main/java/com/yihu/jw/healthCare/utils/StringUtils.java

@ -0,0 +1,55 @@
package com.yihu.jw.healthCare.utils;
/**
 * @Author: lcp
 * @Date: 2020/6/3 9:52
 */
public class StringUtils {
    public static String trimEnd(String str, String stripChars) {
        return trim(str, stripChars, 1);
    }
    private static String trim(String str, String stripChars, int mode) {
        if (str == null) {
            return null;
        } else {
            int length = str.length();
            int start = 0;
            int end = length;
            if (mode <= 0) {
                if (stripChars == null) {
                    while (start < end && Character.isWhitespace(str.charAt(start))) {
                        ++start;
                    }
                } else {
                    if (stripChars.length() == 0) {
                        return str;
                    }
                    while (start < end && stripChars.indexOf(str.charAt(start)) != -1) {
                        ++start;
                    }
                }
            }
            if (mode >= 0) {
                if (stripChars == null) {
                    while (start < end && Character.isWhitespace(str.charAt(end - 1))) {
                        --end;
                    }
                } else {
                    if (stripChars.length() == 0) {
                        return str;
                    }
                    while (start < end && stripChars.indexOf(str.charAt(end - 1)) != -1) {
                        --end;
                    }
                }
            }
            return start <= 0 && end >= length ? str : str.substring(start, end);
        }
    }
}

+ 24 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/HospitalDao.java

@ -0,0 +1,24 @@
package com.yihu.jw.hospital;
import com.yihu.jw.entity.hospital.DmHospitalDO;
import com.yihu.jw.entity.hospital.team.WlyyAdminTeamDO;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface HospitalDao extends PagingAndSortingRepository<DmHospitalDO, Integer>, JpaSpecificationExecutor<DmHospitalDO> {
    @Query("from DmHospitalDO t where t.town=?1 and t.del='1'")
    List<DmHospitalDO> findByTownCode(String town, Pageable pageRequest);
    @Query("from DmHospitalDO t where t.town=?1 and t.name like ?2 and t.del='1'")
    List<DmHospitalDO> findByTownCodeAndName(String town,String name,Pageable pageRequest);
    @Query("from DmHospitalDO t where t.code=?1 and t.del='1'")
    DmHospitalDO findByCode(String code);
    boolean existsByCode(String code);
}

+ 14 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/consult/dao/BaseAdviceTreatmentDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.hospital.consult.dao;
import com.yihu.jw.entity.hospital.consult.WlyyDoctorClinicRoomDO;
import com.yihu.jw.entity.hospital.prescription.BaseAdviceTreatmentDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseAdviceTreatmentDao   extends PagingAndSortingRepository<BaseAdviceTreatmentDO, String>, JpaSpecificationExecutor<BaseAdviceTreatmentDO> {
    @Query("from BaseAdviceTreatmentDO t where t.relationCode=?1")
    List<BaseAdviceTreatmentDO> findByRelationCode(String outpatientId);
}

+ 8 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/dict/BaseDeptHomepageBannerDao.java

@ -0,0 +1,8 @@
package com.yihu.jw.hospital.dict;
import com.yihu.jw.entity.hospital.manage.BaseDeptHomepageBannerDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseDeptHomepageBannerDao extends PagingAndSortingRepository<BaseDeptHomepageBannerDO, Integer>, JpaSpecificationExecutor<BaseDeptHomepageBannerDO> {
}

+ 8 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/dict/BaseDiseaseHomepageBannerDao.java

@ -0,0 +1,8 @@
package com.yihu.jw.hospital.dict;
import com.yihu.jw.entity.hospital.manage.BaseDiseaseHomepageBannerDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseDiseaseHomepageBannerDao extends PagingAndSortingRepository<BaseDiseaseHomepageBannerDO, Integer>, JpaSpecificationExecutor<BaseDiseaseHomepageBannerDO> {
}

+ 20 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/dict/BaseIncentiveDictDao.java

@ -0,0 +1,20 @@
package com.yihu.jw.hospital.dict;
import com.yihu.jw.entity.base.dict.BaseIncentiveDictDO;
import com.yihu.jw.entity.hospital.dict.WlyyChargeDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseIncentiveDictDao extends PagingAndSortingRepository<BaseIncentiveDictDO, String>, JpaSpecificationExecutor<BaseIncentiveDictDO> {
    @Query("from BaseIncentiveDictDO t where t.incentiveName like ?1 and t.isDel = '1'")
    List<BaseIncentiveDictDO> findBynAndIncentiveName(String name);
    @Query("from BaseIncentiveDictDO t where t.id = ?1 and t.isDel = '1'")
    BaseIncentiveDictDO findoneById(String id);
}

+ 8 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/dict/BaseTopBannerDao.java

@ -0,0 +1,8 @@
package com.yihu.jw.hospital.dict;
import com.yihu.jw.entity.hospital.manage.BaseTopBannerDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseTopBannerDao extends PagingAndSortingRepository<BaseTopBannerDO, Integer>, JpaSpecificationExecutor<BaseTopBannerDO> {
}

+ 9 - 3
business/base-service/src/main/java/com/yihu/jw/hospital/dict/WlyyChargeDictDao.java

@ -2,6 +2,7 @@ package com.yihu.jw.hospital.dict;
import com.yihu.jw.entity.hospital.dict.WlyyChargeDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import javax.transaction.Transactional;
@ -12,10 +13,15 @@ import java.util.List;
 */
@Transactional
public interface WlyyChargeDictDao extends PagingAndSortingRepository<WlyyChargeDictDO, String>, JpaSpecificationExecutor<WlyyChargeDictDO> {
    @Query("from WlyyChargeDictDO t where t.deptTypeCode=?1 and t.isDel='1'")
    List<WlyyChargeDictDO>  findByDeptTypeCode(String deptTypeCode);
    @Query("from WlyyChargeDictDO d where 1=1 and d.isDel='1'")
    List<WlyyChargeDictDO>  findAllDict();
    @Query("from WlyyChargeDictDO t where t.chargeType=?1 and t.deptTypeCode=?2 and t.isDel='1'")
    WlyyChargeDictDO  findByChargeTypeAndDeptTypeCode(String chargeType,String deptTypeCode);
    @Query("from WlyyChargeDictDO t where t.chargeType=?1  and t.isDel='1'")
    WlyyChargeDictDO  findByChargeType(String chargeType);
    @Query("from WlyyChargeDictDO d where d.reqFee = ?1 and d.isDel='1' ")
    WlyyChargeDictDO  findByReqFee(Double reqFee);
}

+ 27 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/dict/WlyyHospitalSysDictDao.java

@ -2,6 +2,8 @@ package com.yihu.jw.hospital.dict;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
@ -17,5 +19,30 @@ public interface WlyyHospitalSysDictDao extends PagingAndSortingRepository<WlyyH
    WlyyHospitalSysDictDO findById(String id);
    @Query("from WlyyHospitalSysDictDO where dictName = ?1  and  dictCode is null order by sort asc")
    List<WlyyHospitalSysDictDO> findByDictNameNotNull(String dictName);
    List<WlyyHospitalSysDictDO> findByDictName(String dictName);
    @Query("from WlyyHospitalSysDictDO where 1=1")
    List<WlyyHospitalSysDictDO> findAlldict();
    @Query("from WlyyHospitalSysDictDO where dictCode = ?1")
    List<WlyyHospitalSysDictDO> findByDictCode(String dictCode);
    List<WlyyHospitalSysDictDO> findByDictNameAndDictCode(String dictName,String dictCode);
    @Query("from WlyyHospitalSysDictDO where dictName = ?1 and hospital=?2 order by sort asc")
    List<WlyyHospitalSysDictDO> findByDictNameOrderBySort(String dictName,String orgCode);
    @Query("from WlyyHospitalSysDictDO where dictName = ?1 and hospital=?2 order by sort desc ")
    List<WlyyHospitalSysDictDO> getMaxSort(String dictName,String hospital);
    @Query("from WlyyHospitalSysDictDO where dictName = ?1 and hospital=?2 order by sort asc ")
    List<WlyyHospitalSysDictDO>  getMinSort(String dictName,String hospital);
    @Query("from WlyyHospitalSysDictDO where dictName = ?1  and  hospital=?2 and sort >= ?3 order by sort asc")
    List<WlyyHospitalSysDictDO> findByDictNameSortOrderBySort(String dictName,String hospital,Integer sort);
    @Query("from WlyyHospitalSysDictDO where dictName = ?1  and  dictCode=?2 ")
    WlyyHospitalSysDictDO findOneByDictNameAndDictCode(String dictName,String dictCode);
}

+ 107 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/dict/service/BaseIncentiveDictService.java

@ -0,0 +1,107 @@
package com.yihu.jw.hospital.dict.service;
import com.yihu.jw.entity.base.dict.BaseIncentiveDictDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.hospital.dict.BaseIncentiveDictDao;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.index.qual.SearchIndexBottom;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class BaseIncentiveDictService extends BaseJpaService<BaseIncentiveDictDO, BaseIncentiveDictDao> {
    @Autowired
    private BaseIncentiveDictDao baseIncentiveDictDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    /*
    * 查询激励词典
    * */
    public MixEnvelop findByName(String name, Integer page , Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql=" select t.id as \"id\"," +
                " t.incentive_name as \"incentiveName\"," +
                " t.incentive_img as \"incentiveImg\"," +
                " t.is_del as \"isDel\"," +
                " t.incentive_status as \"incentiveStatus\"," +
                " t.incentive_code as \"incentiveCode\""+
                " from base_incentive_dict t where 1=1 and t.is_del = '1' ";
        if (StringUtils.isNoneBlank(name)){
            sql+=" and t.incentive_name like '%"+name+"%'";
        }
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        List<WlyyHospitalSysDictDO> sysDictDOS=wlyyHospitalSysDictDao.findByDictName("drugStoreStatus");
        if (sysDictDOS!=null&&list.size()>0){
            for (Map<String,Object> map:list){
                for (WlyyHospitalSysDictDO sysDictDO:sysDictDOS){
                    if (map.get("incentiveStatus").toString().equalsIgnoreCase(sysDictDO.getDictCode())){
                        map.put("incentiveStatusName",sysDictDO.getDictValue());
                    }
                }
            }
        }
        List<Map<String,Object>> listCount = hibenateUtils.createSQLQuery(sql);
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setCurrPage(page);
        mixEnvelop.setPageSize(page);
        mixEnvelop.setTotalCount(listCount==null?0:listCount.size());
        return mixEnvelop;
    }
    /*
    * 查询单条*/
    public BaseIncentiveDictDO findOneById(String id){
        BaseIncentiveDictDO baseIncentiveDictDO = baseIncentiveDictDao.findoneById(id);
        return  baseIncentiveDictDO;
    }
    /*
    * 更新/新增*/
    public BaseIncentiveDictDO saveIncentive(String id,String code,String name ,String img ,String status){
        BaseIncentiveDictDO baseIncentiveDictDO = null;
        if(StringUtils.isNoneBlank(id)){
            baseIncentiveDictDO = baseIncentiveDictDao.findOne(id);
            baseIncentiveDictDO.setIncentiveCode(code);
            baseIncentiveDictDO.setIncentiveImg(img);
            baseIncentiveDictDO.setIncentiveStatus(status);
            baseIncentiveDictDO.setIncentiveName(name);
            baseIncentiveDictDO.setIsDel("1");
            baseIncentiveDictDao.save(baseIncentiveDictDO);
        }else {
            baseIncentiveDictDO= new BaseIncentiveDictDO();
            baseIncentiveDictDO.setIncentiveCode(code);
            baseIncentiveDictDO.setIncentiveImg(img);
            baseIncentiveDictDO.setIncentiveStatus(status);
            baseIncentiveDictDO.setIncentiveName(name);
            baseIncentiveDictDO.setIsDel("1");
            baseIncentiveDictDao.save(baseIncentiveDictDO);
        }
        return baseIncentiveDictDO;
    }
    /*
     * 删除单条*/
    public Map deleteOne(String id){
        Map<String,Object> map = new HashMap<>();
        BaseIncentiveDictDO baseIncentiveDictDO = baseIncentiveDictDao.findoneById(id);
        if (baseIncentiveDictDO!=null){
            baseIncentiveDictDO.setIsDel("0");
            baseIncentiveDictDao.save(baseIncentiveDictDO);
            map.put("status",200);
            map.put("msg","删除成功");
        }else {
            map.put("status",-1);
            map.put("msg","删除失败");
        }
        return  map;
    }
}

+ 459 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/dict/service/WlyyHospitalSysDictService.java

@ -0,0 +1,459 @@
package com.yihu.jw.hospital.dict.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.family.BasePatientMemberDictDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.family.dao.BasePatientMemberDictDao;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.eval.MissingArgEval;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class WlyyHospitalSysDictService extends BaseJpaService<WlyyHospitalSysDictDO, WlyyHospitalSysDictDao> {
    @Autowired
    private  WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private DoctorMappingDao doctorMappingDao;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Value("${wechat.id}")
    private String wechatId;
    @Autowired
    private StringRedisTemplate redisTemplate;
    //查字典
    public MixEnvelop findDictsByNameCode(String modelName,String name,String code,String value,Integer page ,Integer pageSize){
        String  sql = "select t.id as \"id\"," +
                " t.dict_name  as \"dictName\","+
                " t.model_name  as \"modelName\","+
                " t.dict_code  as \"dictCode\","+
                " t.dict_value   as \"dictValue\","+
                " t.sort   as \"sort\","+
                " t.py_code  as \"pyCode\","+
                " t.hospital  as \"hospital\","+
                " t.img_url  as \"imgUrl\","+
                " t.create_time as \"createTime\""+
                " from wlyy_hospital_sys_dict t where 1=1  ";
        if (StringUtils.isNoneBlank(name)){
            sql+=" and t.dict_name = '"+name+"'";
        }
        if (StringUtils.isNoneBlank(modelName)){
            sql+=" and t.model_name like '%"+modelName+"%'";
        }
        if (StringUtils.isNoneBlank(code)){
            sql+=" and t.dict_code like '%"+code+"%'";
        }
        if (StringUtils.isNoneBlank(value)){
            sql+=" and t.dict_value like '%"+value+"%'";
        }
        if ("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
            sql+=" and t.dict_code is not null";
        }else {
            sql+=" and t.dict_code is not null and  t.dict_code != ''";
        }
        if (page==null||page==null){
            List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
            MixEnvelop mixEnvelop = new MixEnvelop();
            mixEnvelop.setTotalCount(list==null?0:list.size());
            mixEnvelop.setDetailModelList(list);
            return  mixEnvelop;
        }else {
            List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
            List<Map<String,Object>> listCount = hibenateUtils.createSQLQuery(sql);
            MixEnvelop mixEnvelop = new MixEnvelop();
            mixEnvelop.setTotalCount(listCount==null?0:listCount.size());
            mixEnvelop.setCurrPage(page);
            mixEnvelop.setPageSize(pageSize);
            mixEnvelop.setDetailModelList(list);
            return  mixEnvelop;
        }
    }
    //根据id修改或新增字典
    public WlyyHospitalSysDictDO updateOrCreateDict(String json) throws  Exception{
        WlyyHospitalSysDictDO  wlyyHospitalSysDictDO = objectMapper.readValue(json, WlyyHospitalSysDictDO.class);
        String modelName = "";
        if (StringUtils.isNoneBlank(wlyyHospitalSysDictDO.getDictName())){
            List<WlyyHospitalSysDictDO> modelNameList=wlyyHospitalSysDictDao.findByDictName(wlyyHospitalSysDictDO.getDictName());
            if (modelNameList!=null&&modelNameList.size()>0){
                modelName= modelNameList.get(0).getModelName();
            }
        }
        wlyyHospitalSysDictDO.setModelName(modelName);
        if(StringUtils.isNoneBlank(wlyyHospitalSysDictDO.getId())){
            WlyyHospitalSysDictDO wlyyHospitalSysDictDO1 = wlyyHospitalSysDictDao.findById(wlyyHospitalSysDictDO.getId());
            if (wlyyHospitalSysDictDO1!=null){
                wlyyHospitalSysDictDO1.setDictValue(wlyyHospitalSysDictDO.getDictValue());
                wlyyHospitalSysDictDO1.setDictCode(wlyyHospitalSysDictDO.getDictCode());
                wlyyHospitalSysDictDO1.setDictName(wlyyHospitalSysDictDO.getDictName());
                wlyyHospitalSysDictDO1.setHospital(wlyyHospitalSysDictDO.getHospital());
                wlyyHospitalSysDictDO1.setPyCode(wlyyHospitalSysDictDO.getPyCode());
                wlyyHospitalSysDictDO1.setImgUrl(wlyyHospitalSysDictDO.getImgUrl());
                wlyyHospitalSysDictDO1.setSort(wlyyHospitalSysDictDO.getSort());
                wlyyHospitalSysDictDO1.setModelName(modelName);
            }else {
                wlyyHospitalSysDictDO1 = new WlyyHospitalSysDictDO();
                wlyyHospitalSysDictDO1.setDictValue(wlyyHospitalSysDictDO.getDictValue());
                wlyyHospitalSysDictDO1.setDictCode(wlyyHospitalSysDictDO.getDictCode());
                wlyyHospitalSysDictDO1.setDictName(wlyyHospitalSysDictDO.getDictName());
                wlyyHospitalSysDictDO1.setHospital(wlyyHospitalSysDictDO.getHospital());
                wlyyHospitalSysDictDO1.setPyCode(wlyyHospitalSysDictDO.getPyCode());
                wlyyHospitalSysDictDO1.setImgUrl(wlyyHospitalSysDictDO.getImgUrl());
                wlyyHospitalSysDictDO1.setSort(wlyyHospitalSysDictDO.getSort());
                wlyyHospitalSysDictDO1.setModelName(modelName);
            }
            return wlyyHospitalSysDictDao.save(wlyyHospitalSysDictDO1);
        }
        return wlyyHospitalSysDictDao.save(wlyyHospitalSysDictDO);
    }
    //根据id删除字典
    public String  deleteDictById(String id){
        String msg = "";
        if (StringUtils.isNoneBlank(id)){
           WlyyHospitalSysDictDO wlyyHospitalSysDictDO = wlyyHospitalSysDictDao.findById(id);
           if (wlyyHospitalSysDictDO!=null) {
               wlyyHospitalSysDictDao.delete(id);
               msg = "删除成功";
           }else {
               msg = "没有这条记录";
           }
        }else{
            msg = "id为空";
        }
        return msg;
    }
    public  String findByDoctorMappingCode(String code){
        String doctorId = "";
        if (StringUtils.isNoneBlank(code)){
            List<BaseDoctorDO> list = baseDoctorDao.findByIdcard(code);
            if (list!=null&&list.size()>0){
                doctorId=list.get(0).getId();
            }
        }
        return doctorId;
    }
    public WlyyHospitalSysDictDO findOne(String id){
        return  wlyyHospitalSysDictDao.findById(id);
    }
    //查字典
    public MixEnvelop findModel(String modelName, String name, Integer page , Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String  sql = "select " +
                " t.dict_name  as \"dictName\","+
                " t.model_name  as \"modelName\""+
                " from wlyy_hospital_sys_dict t where 1=1 ";
        if (StringUtils.isNoneBlank(name)){
            sql+=" and t.dict_name like '%"+name+"%'";
        }
        if (StringUtils.isNoneBlank(modelName)){
            sql+=" and t.model_name like '%"+modelName+"%'";
        }
        sql+=" group by t.dict_name,t.model_name ";
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        List<Map<String,Object>> listCount = hibenateUtils.createSQLQuery(sql);
        if (listCount!=null){
            mixEnvelop.setTotalCount(listCount.size());
        }else {
            mixEnvelop.setTotalCount(0);
        }
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setCurrPage(page);
        mixEnvelop.setPageSize(pageSize);
        return  mixEnvelop;
    }
    public Envelop updateByModelName(String jsonData) throws Exception{
        Envelop envelop = new Envelop();
        JSONObject jsonObject = JSONObject.parseObject(jsonData);
        if (StringUtils.isNoneBlank(jsonObject.getString("preDictName"))){
            String preDictName = jsonObject.get("preDictName").toString();
            List<WlyyHospitalSysDictDO> list  =  wlyyHospitalSysDictDao.findByDictName(preDictName);
            for (WlyyHospitalSysDictDO wlyyHospitalSysDictDO:list){
                if (jsonObject.get("dictName")!=null){
                    wlyyHospitalSysDictDO.setDictName(jsonObject.get("dictName").toString());
                }
                if (jsonObject.get("modelName")!=null){
                    wlyyHospitalSysDictDO.setModelName(jsonObject.get("modelName").toString());
                }
            }
            wlyyHospitalSysDictDao.save(list);
            envelop.setMessage("操作成功");
            envelop.setStatus(200);
        }else {
            if (jsonObject.get("dictName")!=null){
                List<WlyyHospitalSysDictDO> list  =  wlyyHospitalSysDictDao.findByDictName(jsonObject.get("dictName").toString());
                if (list!=null&&list.size()>0){
                    throw new Exception("该dictName已经存在");
                }else {
                    WlyyHospitalSysDictDO wlyyHospitalSysDictDO=new WlyyHospitalSysDictDO();
                    wlyyHospitalSysDictDO.setDictName(jsonObject.get("dictName").toString());
                    if (jsonObject.get("modelName")!=null){
                        wlyyHospitalSysDictDO.setModelName(jsonObject.get("modelName").toString());
                    }
                    wlyyHospitalSysDictDao.save(wlyyHospitalSysDictDO);
                }
                envelop.setMessage("操作成功");
                envelop.setStatus(200);
            }else {
                envelop.setMessage("dictName为空");
                envelop.setStatus(-1);
            }
        }
        return envelop;
    }
    public Envelop deleteByModelName(String preDictName){
        Envelop envelop = new Envelop();
        if (StringUtils.isNoneBlank(preDictName)){
            List<WlyyHospitalSysDictDO> list  =  wlyyHospitalSysDictDao.findByDictName(preDictName);
            for (WlyyHospitalSysDictDO wlyyHospitalSysDictDO:list){
                wlyyHospitalSysDictDao.delete(wlyyHospitalSysDictDO);
            }
            envelop.setMessage("操作成功");
            envelop.setStatus(200);
        }else {
            envelop.setMessage("preDictName为空");
            envelop.setStatus(-1);
        }
        return envelop;
    }
    public WlyyHospitalSysDictDO downDoctor(String id) throws Exception{
        WlyyHospitalSysDictDO sysDictDO = wlyyHospitalSysDictDao.findOne(id);
        List<WlyyHospitalSysDictDO> maxSortList =  wlyyHospitalSysDictDao.getMaxSort(sysDictDO.getDictName(),sysDictDO.getHospital());
        int maxSort =0;
        if (maxSortList!=null&&maxSortList.size()>0){
            maxSort = maxSortList.get(0).getSort();
        }
        int sort = 0;
        if(null!=sysDictDO){
            sort = sysDictDO.getSort();
        }
        if (maxSort==sort){
            throw new Exception("不能下移");
        }
        String sql = "select t.id AS \"id\" from wlyy_hospital_sys_dict t where t.dict_name='"+sysDictDO.getDictName()+"' and t.hospital='"+sysDictDO.getHospital()+"' and t.sort > "+sort+" order by t.sort asc ";
        System.out.println(sql);
        List<Map<String,Object>> list=hibenateUtils.createSQLQuery(sql,1,1);
        WlyyHospitalSysDictDO upPrevious = new WlyyHospitalSysDictDO();
        if (list.size()>0){
            String prviousId = list.get(0).get("id").toString();
            upPrevious =wlyyHospitalSysDictDao.findOne(prviousId);
        }
        //BaseBannerDO upPrevious = baseBannerDao.upBanner(sort);
        //交换sort值
        sysDictDO.setSort(upPrevious.getSort());
        upPrevious.setSort(sort);
        wlyyHospitalSysDictDao.save(sysDictDO);
        wlyyHospitalSysDictDao.save(upPrevious);
        return sysDictDO;
    }
    public WlyyHospitalSysDictDO upDoctor(String id) throws Exception{
        WlyyHospitalSysDictDO sysDictDO = wlyyHospitalSysDictDao.findOne(id);
        List<WlyyHospitalSysDictDO> minSortList =  wlyyHospitalSysDictDao.getMinSort(sysDictDO.getDictName(),sysDictDO.getHospital());
        int minSort =0;
        if (minSortList!=null&&minSortList.size()>0){
            minSort = minSortList.get(0).getSort();
        }
        int sort = 0;
        if(null!=sysDictDO){
            sort = sysDictDO.getSort();
        }
        if (minSort==sort){
            throw new Exception("不能上移");
        }
        String sql = "select t.id AS \"id\" from wlyy_hospital_sys_dict t where t.dict_name='"+sysDictDO.getDictName()+"' and t.hospital ='"+sysDictDO.getHospital()+"' and t.sort < "+sort+" order by t.sort asc ";
        System.out.println(sql);
        List<Map<String,Object>> list=hibenateUtils.createSQLQuery(sql,1,1);
        WlyyHospitalSysDictDO downPrevious = new WlyyHospitalSysDictDO();
        if (list.size()>0){
            String prviousId = list.get(0).get("id").toString();
            downPrevious =wlyyHospitalSysDictDao.findOne(prviousId);
        }
        //BaseBannerDO upPrevious = baseBannerDao.upBanner(sort);
        //交换sort值
        sysDictDO.setSort(downPrevious.getSort());
        downPrevious.setSort(sort);
        wlyyHospitalSysDictDao.save(sysDictDO);
        wlyyHospitalSysDictDao.save(downPrevious);
        return sysDictDO;
    }
    public void insertSort(String id,Integer sort){
        WlyyHospitalSysDictDO sysDictDO = wlyyHospitalSysDictDao.findOne(id);
        if (sysDictDO!=null){
            Integer  max= 0;
            List<WlyyHospitalSysDictDO> maxList = wlyyHospitalSysDictDao.getMaxSort("doctorFrontList",sysDictDO.getHospital());
            if (maxList!=null&&maxList.size()>0){
                max= maxList.get(0).getSort();
            }
            if (sort!=null&&sort<max){
                List<WlyyHospitalSysDictDO> list = wlyyHospitalSysDictDao.findByDictNameSortOrderBySort(sysDictDO.getDictName(),sysDictDO.getHospital(),sort);
                for (WlyyHospitalSysDictDO wlyyHospitalSysDictDO:list){
                    wlyyHospitalSysDictDO.setSort(wlyyHospitalSysDictDO.getSort()+1);
                    wlyyHospitalSysDictDao.save(wlyyHospitalSysDictDO);
                }
                sysDictDO.setSort(sort);
                wlyyHospitalSysDictDao.save(sysDictDO);
            }else if (sort!=null&&sort>=max){
                sysDictDO.setSort(max+1);
                wlyyHospitalSysDictDao.save(sysDictDO);
            }
        }
    }
    public void saveDictDoctor(String json) throws Exception{
        JSONArray jsonArray = JSONArray.parseArray(json);
        if (jsonArray!=null&&jsonArray.size()>0){
            for (int i=0;i<jsonArray.size();i++){
               JSONObject jsonObject = jsonArray.getJSONObject(i);
               String orgCode = jsonObject.getString("hosptial");
               JSONArray dictArray = jsonObject.getJSONArray("dictList");
               Integer  max= 0;
               List<WlyyHospitalSysDictDO> maxList = wlyyHospitalSysDictDao.getMaxSort("doctorFrontList",orgCode);
               if (maxList!=null&&maxList.size()>0){
                   max= maxList.get(0).getSort();
               }
               if (max==null){
                   max = 0;
               }
               for (int j=0;j<dictArray.size();j++){
                   JSONObject jsonObject1 = dictArray.getJSONObject(j);
                   WlyyHospitalSysDictDO wlyyHospitalSysDictDO = jsonObject1.toJavaObject(WlyyHospitalSysDictDO.class);
                   wlyyHospitalSysDictDO.setHospital(orgCode);
                   wlyyHospitalSysDictDO.setSort(max+1);
                   max++;
                   wlyyHospitalSysDictDao.save(wlyyHospitalSysDictDO);
               }
            }
        }
    }
    public MixEnvelop findSortDoctors(String orgCode,String del,String doctorName,Integer page ,Integer pageSize){
        String sql =" select DISTINCT t.id as \"id\"," +
                " t.dict_value as \"dict_value\"," +
                " t.dict_code as \"dict_code\"," +
                " t.sort as \"sort\"," +
                " t.hospital as \"hospital\"," +
                " b.idcard as \"idcard\"," +
                " b.del as \"del\"," +
                " case when b.sex =1 then '男' when b.sex =2 then '女' else '未知' end sex," +
                " b.mobile as \"mobile\"," +
                " b.job_title_name as \"jobTitleName\"," +
                " d.org_name as \"orgName\"" +
                "  from wlyy_hospital_sys_dict t left join base_doctor b on t.dict_code = b.id " +
                " left join base_doctor_hospital d on t.dict_code = d.doctor_code where 1=1 and dict_name ='doctorFrontList' ";
        if (StringUtils.isNoneBlank(orgCode)){
            sql+=" and t.hospital = '"+orgCode+"'";
        }
        if (StringUtils.isNoneBlank(del)){
            sql+=" and b.del = '"+del+"'";
        }
        if (StringUtils.isNoneBlank(doctorName)){
            sql+=" and b.name like '%"+doctorName+"%'";
        }
        sql+=" order by t.sort asc";
        System.out.println("sql++++++"+sql);
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        List<Map<String,Object>> listCount = hibenateUtils.createSQLQuery(sql);
        List<WlyyHospitalSysDictDO> sysDictDOS=wlyyHospitalSysDictDao.findByDictName("drugStoreStatus");
        if (sysDictDOS!=null&&list.size()>0){
            for (Map<String,Object> map:list){
                for (WlyyHospitalSysDictDO sysDictDO:sysDictDOS){
                    if (map.get("del").toString().equalsIgnoreCase(sysDictDO.getDictCode())){
                        map.put("delName",sysDictDO.getDictValue());
                    }
                }
            }
        }
        MixEnvelop mixEnvelop= new MixEnvelop();
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        mixEnvelop.setTotalCount(listCount==null?0:list.size());
        return mixEnvelop;
    }
    /**
     * 字典转译
     *
     * @param dictName
     * @param code
     * @return
     */
    public String getDictValue(String dictName, String code) {
        String re = "";
        /*try {
            if (!StringUtils.isEmpty(code)) {
                //判断该字典redis是否存在
                String exit = redisTemplate.opsForValue().get("systemDict:" + dictName);
                if (!StringUtils.isEmpty(exit)) {
                    re = redisTemplate.opsForValue().get("systemDict:" + dictName + ":" + code);
                    if(StringUtils.isEmpty(re)){
                        WlyyHospitalSysDictDO wlyyHospitalSysDictDO= wlyyHospitalSysDictDao.findOneByDictNameAndDictCode(dictName,code);
                        if (wlyyHospitalSysDictDO!=null){
                            re =wlyyHospitalSysDictDO.getDictValue();
                        }
//                        if (!StringUtils.isEmpty(re)) {
//                            redisTemplate.opsForValue().set("systemDict:" + dictName + ":" + code, re);
//                        }
                    }
                } else {
                    List<WlyyHospitalSysDictDO> list = wlyyHospitalSysDictDao.findByDictName(dictName);
                    if (list != null && list.size() > 0) {
                        redisTemplate.opsForValue().set("systemDict:" + dictName, "1");
                        for (WlyyHospitalSysDictDO item : list) {
                            redisTemplate.opsForValue().set("systemDict:" + dictName + ":" + item.getDictCode(), item.getDictValue());
                            if (code.equals(item.getDictCode())) {
                                re = item.getDictValue();
                            }
                        }
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }*/
        if (StringUtils.isNoneBlank(code)){
            WlyyHospitalSysDictDO wlyyHospitalSysDictDO= wlyyHospitalSysDictDao.findOneByDictNameAndDictCode(dictName,code);
            if (wlyyHospitalSysDictDO!=null){
                re =wlyyHospitalSysDictDO.getDictValue();
                System.out.println("re"+re);
            }
        }
        return re;
    }
}

+ 19 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/doctor/dao/BaseDoctorBackgroundDao.java

@ -0,0 +1,19 @@
package com.yihu.jw.hospital.doctor.dao;
import com.yihu.jw.entity.base.doctor.BaseDoctorBackgroundDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 *
 */
public interface BaseDoctorBackgroundDao extends PagingAndSortingRepository<BaseDoctorBackgroundDO, String>, JpaSpecificationExecutor<BaseDoctorBackgroundDO> {
    @Query(value = "select * from base_doctor_background t where t,doctor = ?1 ",nativeQuery = true)
    List<BaseDoctorBackgroundDO> getBackroundByDoctor(String doctor);
    @Query(value = "select * from base_doctor_background t limit ?1,?2",nativeQuery = true)
    List<BaseDoctorBackgroundDO> getBackroundAll(Integer page,Integer pageSize);
}

+ 8 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/doctor/dao/DoctorTimeMappingDao.java

@ -0,0 +1,8 @@
package com.yihu.jw.hospital.doctor.dao;
import com.yihu.jw.entity.base.doctor.BaseDoctorTimeMappingDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface DoctorTimeMappingDao extends PagingAndSortingRepository<BaseDoctorTimeMappingDO, Integer>, JpaSpecificationExecutor<BaseDoctorTimeMappingDO> {
}

+ 177 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/doctor/dao/service/BaseDoctorBGService.java

@ -0,0 +1,177 @@
package com.yihu.jw.hospital.doctor.dao.service;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorMessageDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorBackgroundDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorMessageDO;
import com.yihu.jw.hospital.doctor.dao.BaseDoctorBackgroundDao;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class BaseDoctorBGService extends BaseJpaService<BaseDoctorBackgroundDO, BaseDoctorBackgroundDao> {
    @Autowired
    private BaseDoctorBackgroundDao baseDoctorBackgroundDao;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private BaseDoctorMessageDao doctorMessageDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    //查询背景
    public List<BaseDoctorBackgroundDO> getBackground(Integer page,Integer pageSize){
        return baseDoctorBackgroundDao.getBackroundAll(page,pageSize);
    }
    //医生选定背景
    @Transactional
    public BaseDoctorDO setDoctorBackground(String doctor,String id){
        BaseDoctorBackgroundDO baseDoctorBackgroundDO = baseDoctorBackgroundDao.findOne(id);
        BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doctor);
        if(null!=baseDoctorBackgroundDO&&null!=baseDoctorDO){
            baseDoctorDO.setBackgroundId(baseDoctorBackgroundDO.getId());
            baseDoctorDO.setBackground(baseDoctorBackgroundDO.getBackground());
            baseDoctorDO = baseDoctorDao.save(baseDoctorDO);
        }
        return baseDoctorDO;
    }
    //新增背景
    public BaseDoctorBackgroundDO createBackground(String bgName,String bgUrl){
        BaseDoctorBackgroundDO baseDoctorBackgroundDO = new BaseDoctorBackgroundDO();
        if(StringUtils.isNotEmpty(bgName)){
            baseDoctorBackgroundDO.setTitle(bgName);
        }if(StringUtils.isNotEmpty(bgUrl)){
            baseDoctorBackgroundDO.setBackground(bgUrl);
        }
        baseDoctorBackgroundDO =  baseDoctorBackgroundDao.save(baseDoctorBackgroundDO);
        return baseDoctorBackgroundDO;
    }
    //删除背景
    public void deleteBg(String bgId){
        BaseDoctorBackgroundDO baseDoctorBackgroundDO = baseDoctorBackgroundDao.findOne(bgId);
        if(null!=baseDoctorBackgroundDO){
            baseDoctorBackgroundDao.delete(bgId);
        }
    }
    //修改
    public BaseDoctorBackgroundDO updateBackground(String id,String bgUrl,String bgName){
        BaseDoctorBackgroundDO baseDoctorBackgroundDO =baseDoctorBackgroundDao.findOne(id);
        if(null!=baseDoctorBackgroundDO){
            if (StringUtils.isNotEmpty(bgName)){
                baseDoctorBackgroundDO.setTitle(bgName);
            }if (StringUtils.isNotEmpty(bgUrl)){
                baseDoctorBackgroundDO.setBackground(bgUrl);
            }
        }
        baseDoctorBackgroundDO = baseDoctorBackgroundDao.save(baseDoctorBackgroundDO);
        return  baseDoctorBackgroundDO;
    }
    /**
     * 查询某个医生快捷回复列表
     * @param doctor
     * @param page
     * @param size
     * @return
     */
    public List<Map<String,Object>> selectByDoctor(String doctor, Integer contentType, String content, Integer page, Integer size){
        String sql = "select id as \"id\", doctor as \"doctor\",doctor_name as \"doctorName\",content_type as \"contentType\"," +
                "content as \"content\" , content_desc as \"contentDesc\",is_sort as \"isSort\",del as \"del\",extend as \"extend\"  " +
                " from base_doctor_message where del=1 and doctor='"+doctor+"' ";
        if (contentType!=null){
            sql +=" and content_type= "+contentType;
        }
        if (StringUtils.isNotBlank(content)){
            sql +=" and content like '%"+content+"%' ";
        }
        sql +=" order by is_sort desc ";
        List<Map<String,Object>> mapList = hibenateUtils.createSQLQuery(sql,page,size);
        return mapList;
    }
    /**
     * 增加和更新快捷回复信息
     * @param doctorMessageDO
     * @return
     */
    @Transactional
    public BaseDoctorMessageDO saveDoctorMessage(BaseDoctorMessageDO doctorMessageDO){
        if (!StringUtils.isNotBlank(doctorMessageDO.getId())){
            String sql = "select max(dm.is_sort) as total from base_doctor_message dm where dm.del=1 ";
            List<Map<String,Object>> maps = jdbcTemplate.queryForList(sql);
            Integer isSort=0;
            if (maps!=null&&maps.size()!=0){
                if (maps.get(0).get("total")!=null){
                    isSort = Integer.parseInt(maps.get(0).get("total").toString())+1;
                }else {
                    isSort=isSort+1;
                }
            }else {
                isSort=isSort+1;
            }
            doctorMessageDO.setIsSort(isSort);
        }
        doctorMessageDO.setDel(1);
        doctorMessageDO.setCreateTime(new Date());
        doctorMessageDO.setUpdateTime(new Date());
        return  doctorMessageDao.save(doctorMessageDO);
    }
    /**
     * 设置置顶
     * @param id
     * @return
     */
    @Transactional
    public BaseDoctorMessageDO setMessageHead(String id){
        BaseDoctorMessageDO doctorMessageDO = doctorMessageDao.findOne(id);
        String sql = "select max(dm.is_sort) as total from base_doctor_message dm where dm.del=1  ";
        List<Map<String,Object>> maps = jdbcTemplate.queryForList(sql);
        Integer isSort=0;
        if (maps!=null&&maps.size()!=0){
            if (maps.get(0).get("total")!=null){
                isSort = Integer.parseInt(maps.get(0).get("total").toString())+1;
            }else {
                isSort=isSort+1;
            }
        }else {
            isSort=isSort+1;
        }
        doctorMessageDO.setIsSort(isSort);
        doctorMessageDO.setCreateTime(new Date());
        doctorMessageDO.setUpdateTime(new Date());
        return doctorMessageDao.save(doctorMessageDO);
    }
    @Transactional
    public BaseDoctorMessageDO delDoctorMessage(String id){
        BaseDoctorMessageDO doctorMessageDO = doctorMessageDao.findOne(id);
        doctorMessageDO.setDel(0);
        doctorMessageDO.setCreateTime(new Date());
        doctorMessageDO.setUpdateTime(new Date());
        return doctorMessageDao.save(doctorMessageDO);
    }
    public BaseDoctorMessageDO selectById(String id){
        return doctorMessageDao.findByIdAndDel(id);
    }
}

+ 24 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/dao/BaseDrugStoreDao.java

@ -0,0 +1,24 @@
package com.yihu.jw.hospital.drugstore.dao;
import com.yihu.jw.entity.base.area.BaseDrugStoreDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseDrugStoreDao extends PagingAndSortingRepository<BaseDrugStoreDO, String>, JpaSpecificationExecutor<BaseDrugStoreDO> {
    @Query(value = " from  BaseDrugStoreDO  where (drugStoreName like %?1% or ?1 is null ) or ( hospitalName like %?1% or ?1 is null) and isDel = 1 and isUsed= '1'")
    List<BaseDrugStoreDO> findDrugByName(String storeName);
    @Query(value = " from  BaseDrugStoreDO  where drugStoreCode =?1 and hospitalCode = ?2  and isDel = '1'")
    BaseDrugStoreDO findDrugByNameAndCode(String drugStoreCode,String hospitalCode);
    @Query(value = " from  BaseDrugStoreDO  where id =?1  ")
    BaseDrugStoreDO findDrugByid(String drugStoreCode);
    @Query(value = " from  BaseDrugStoreDO  where id =?1 and isDel = 1 and isUsed ='1'")
    BaseDrugStoreDO findDrugByidAndIsUsed(String drugStoreCode);
}

+ 18 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/dao/BaseDrugStoreTimeDao.java

@ -0,0 +1,18 @@
package com.yihu.jw.hospital.drugstore.dao;
import com.yihu.jw.entity.base.area.BaseDrugStoreDO;
import com.yihu.jw.entity.base.area.BaseDrugStoreTimeDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseDrugStoreTimeDao extends PagingAndSortingRepository<BaseDrugStoreTimeDO, String>, JpaSpecificationExecutor<BaseDrugStoreTimeDO> {
    @Modifying
    @Query("delete from BaseDrugStoreTimeDO  where drugStoreId = ?1")
    void deleteByDrugStoreId(String drugStoreId);
    @Query("from BaseDrugStoreTimeDO where drugStoreId =?1 order by  weekDay asc ,amPm asc")
    List<BaseDrugStoreTimeDO> findByDrugStoreId(String drugStoreId);
}

+ 224 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/service/BaseDrugStoreService.java

@ -0,0 +1,224 @@
package com.yihu.jw.hospital.drugstore.service;
import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.j2objc.annotations.AutoreleasePool;
import com.yihu.jw.entity.base.area.BaseDrugStoreDO;
import com.yihu.jw.entity.base.area.BaseDrugStoreTimeDO;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDoctorDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.drugstore.dao.BaseDrugStoreDao;
import com.yihu.jw.hospital.drugstore.dao.BaseDrugStoreTimeDao;
import com.yihu.jw.hospital.message.dao.BaseBannerDoctorDao;
import com.yihu.jw.org.dao.BaseOrgDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.CountDistance;
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.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.provider.HibernateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Transactional
@Service
public class BaseDrugStoreService extends BaseJpaService<BaseDrugStoreDO, BaseDrugStoreDao> {
    @Autowired
    private BaseDrugStoreDao baseDrugStoreDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private BaseDrugStoreTimeDao baseDrugStoreTimeDao;
    @Autowired
    private BaseOrgDao baseOrgDao;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
   //根据经纬度计算距离通过代码
   public List<BaseDrugStoreDO> countDistanceListIncode(String latitude,String longitude,String drugStoreName,String hospitalName) throws ParseException {
       List<BaseDrugStoreDO> list = new ArrayList<>();
       if (StringUtils.isNotEmpty(drugStoreName)||StringUtils.isNotEmpty(hospitalName)){
           list = baseDrugStoreDao.findDrugByName(drugStoreName);
       }else {
           String filters="isDel=1;isUsed=1";
           list= this.search(filters);
       }
       List<BaseDrugStoreDO> resultlist = new ArrayList<>();
       CountDistance countDistance = new CountDistance();
       latitude=StringUtils.isEmpty(latitude)?"0":latitude;
       longitude=StringUtils.isEmpty(longitude)?"0":longitude;
        for (BaseDrugStoreDO baseDrugStoreDO:list){
            double storeLatitude = Double.parseDouble(baseDrugStoreDO.getLatitude());
            double storeLongitude = Double.parseDouble(baseDrugStoreDO.getLongitude());
            double distance = countDistance.getDistance(Double.parseDouble(latitude),Double.parseDouble(longitude),storeLatitude,storeLongitude);
            baseDrugStoreDO.setDistance(distance);
        }
        list.stream().sorted((x,y)->Double.compare(x.getDistance(),y.getDistance()));
        return list;
   }
    public BaseDrugStoreDO getById(String id,String latitude,String longitude){
        BaseDrugStoreDO baseDrugStoreDO = baseDrugStoreDao.findDrugByid(id);
        CountDistance countDistance = new CountDistance();
        latitude=StringUtils.isEmpty(latitude)?"0":latitude;
        longitude=StringUtils.isEmpty(longitude)?"0":longitude;
        double storeLatitude = Double.parseDouble(baseDrugStoreDO.getLatitude());
        double storeLongitude = Double.parseDouble(baseDrugStoreDO.getLongitude());
        double distance = countDistance.getDistance(Double.parseDouble(latitude),Double.parseDouble(longitude),storeLatitude,storeLongitude);
        baseDrugStoreDO.setDistance(distance);
        List<BaseDrugStoreTimeDO> list  = baseDrugStoreTimeDao.findByDrugStoreId(baseDrugStoreDO.getId());
        if (list!=null){
            baseDrugStoreDO.setBaseDrugStoreTimeDOlist(list);
        }
        if (StringUtils.isNoneBlank(baseDrugStoreDO.getOpenControl())){
            List<WlyyHospitalSysDictDO> wlyyHospitalSysDictDOList = wlyyHospitalSysDictDao.findByDictNameAndDictCode("drugStoreOpenControl",baseDrugStoreDO.getOpenControl());
            if (wlyyHospitalSysDictDOList!=null&&wlyyHospitalSysDictDOList.size()>0){
                baseDrugStoreDO.setOpenControlName(wlyyHospitalSysDictDOList.get(0).getDictValue());
            }
        }
        if (StringUtils.isNoneBlank(baseDrugStoreDO.getIsUsed())){
            List<WlyyHospitalSysDictDO> wlyyHospitalSysDictDOList = wlyyHospitalSysDictDao.findByDictNameAndDictCode("drugStoreStatus",baseDrugStoreDO.getIsUsed());
            if (wlyyHospitalSysDictDOList!=null&&wlyyHospitalSysDictDOList.size()>0){
                baseDrugStoreDO.setIsUsedName(wlyyHospitalSysDictDOList.get(0).getDictValue());
            }
        }
        return baseDrugStoreDO;
    }
    /*
    *
    */
    public BaseDrugStoreDO saveDrugStore(String jsonData,String timeDate) throws IOException {
        BaseDrugStoreDO baseDrugStoreDO = objectMapper.readValue(jsonData,BaseDrugStoreDO.class);
        if (StringUtils.isNoneBlank(baseDrugStoreDO.getId())){//修改
            if (StringUtils.isNoneBlank(timeDate)){
                //删除之前设置的药房开方时间
                baseDrugStoreTimeDao.deleteByDrugStoreId(baseDrugStoreDO.getId());
                JSONArray jsonArray = JSONArray.parseArray(timeDate);
                if (jsonArray!=null){
                    for (int i = 0;i<jsonArray.size();i++){
                        BaseDrugStoreTimeDO baseDrugStoreTimeDO = objectMapper.readValue(jsonArray.get(i).toString(), BaseDrugStoreTimeDO.class);
                        baseDrugStoreTimeDO.setDrugStoreId(baseDrugStoreDO.getId());
                        baseDrugStoreTimeDao.save(baseDrugStoreTimeDO);
                    }
                }
            }
            BaseDrugStoreDO baseDrugStorePre = baseDrugStoreDao.findOne(baseDrugStoreDO.getId());
            if (baseDrugStorePre!=null){
                BaseOrgDO baseOrgDO = baseOrgDao.findByCode(baseDrugStoreDO.getHospitalCode());
                if (baseOrgDO!=null){
                    baseDrugStorePre.setHospitalCode(baseDrugStoreDO.getHospitalCode());
                    baseDrugStorePre.setHospitalName(baseOrgDO.getName());
                }
                baseDrugStorePre.setOpenControlName(baseDrugStoreDO.getOpenControlName());
                baseDrugStorePre.setDrugStoreName(baseDrugStoreDO.getDrugStoreName());
                baseDrugStorePre.setDrugStoreCode(baseDrugStoreDO.getDrugStoreCode());
                baseDrugStorePre.setAddress(baseDrugStoreDO.getAddress());
                baseDrugStorePre.setRemark(baseDrugStoreDO.getRemark());
                baseDrugStorePre.setDrugImg(baseDrugStoreDO.getDrugImg());
                baseDrugStorePre.setOpenControl(baseDrugStoreDO.getOpenControl());
                baseDrugStorePre.setIsDel(1);
                baseDrugStorePre.setIsUsed(baseDrugStoreDO.getIsUsed());
                baseDrugStorePre.setLatitude(baseDrugStoreDO.getLatitude());
                baseDrugStorePre.setLongitude(baseDrugStoreDO.getLongitude());
                baseDrugStoreDO = baseDrugStoreDao.save(baseDrugStorePre);
            }
        }else {//新增
            baseDrugStoreDO.setIsDel(1);
            BaseOrgDO baseOrgDO = baseOrgDao.findByCode(baseDrugStoreDO.getHospitalCode());
            if (baseOrgDO!=null){
                baseDrugStoreDO.setHospitalName(baseOrgDO.getName());
            }
            baseDrugStoreDO = baseDrugStoreDao.save(baseDrugStoreDO);
            if (StringUtils.isNoneBlank(timeDate)){
                JSONArray jsonArray = JSONArray.parseArray(timeDate);
                if (jsonArray!=null){
                    for (int i = 0;i<jsonArray.size();i++){
                        BaseDrugStoreTimeDO baseDrugStoreTimeDO = objectMapper.readValue(jsonArray.get(i).toString(), BaseDrugStoreTimeDO.class);
                        baseDrugStoreTimeDO.setDrugStoreId(baseDrugStoreDO.getId());
                        baseDrugStoreTimeDao.save(baseDrugStoreTimeDO);
                    }
                }
            }
        }
        return baseDrugStoreDO;
    }
    //删除药房
    public void deleteDrugStore(String id,Integer isDel){
        BaseDrugStoreDO baseDrugStoreDO = baseDrugStoreDao.findOne(id);
        if (baseDrugStoreDO!=null){
            baseDrugStoreDO.setIsDel(isDel);
            baseDrugStoreDao.save(baseDrugStoreDO);
        }
    }
    //作废药房
    public void usedDrugStore(String id,String isUsed){
        BaseDrugStoreDO baseDrugStoreDO = baseDrugStoreDao.findOne(id);
        if (baseDrugStoreDO!=null){
            baseDrugStoreDO.setIsUsed(isUsed);
            baseDrugStoreDao.save(baseDrugStoreDO);
        }
    }
    public MixEnvelop findDrugStoreByConditions(String orgCode,String isUsed,String drugStoreName ,Integer page,Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql = "select b.id as \"id\"," +
                " b.drug_store_name as \"drugStoreName\"," +
                " b.address as \"address\"," +
                " b.drug_store_code as \"drugStoreCode\"," +
                " b.hospital_code as \"hospitalCode\"," +
                " b.hospital_name as \"hospitalName\"," +
                " b.remark as \"remark\"," +
                " b.open_control as \"openControl\"," +
                " b.is_used as \"isUsed\"," +
                " b.is_del as \"isDel\"" +
                "from base_drug_store b  where  is_del =1 ";
        if (StringUtils.isNoneBlank(orgCode)){
            sql+=" and b.hospital_code ='"+orgCode+"'";
        }
        if (StringUtils.isNoneBlank(drugStoreName)){
            sql+=" and b.drug_store_name like '%"+drugStoreName+"%'";
        }
        if (StringUtils.isNoneBlank(isUsed)){
            sql+=" and b.is_used ='"+isUsed+"' ";
        }
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        List<Map<String,Object>> listCount = hibenateUtils.createSQLQuery(sql);
        for (Map<String,Object> map:list){
            List<BaseDrugStoreTimeDO> times = baseDrugStoreTimeDao.findByDrugStoreId(map.get("id").toString());
            map.put("openTime",times);
            if (map.get("openControl")!=null){
                List<WlyyHospitalSysDictDO> wlyyHospitalSysDictDOList = wlyyHospitalSysDictDao.findByDictNameAndDictCode("drugStoreOpenControl",map.get("openControl").toString());
                if (wlyyHospitalSysDictDOList!=null&&wlyyHospitalSysDictDOList.size()>0){
                    map.put("openControlName",wlyyHospitalSysDictDOList.get(0).getDictValue());
                }
            }
            if (map.get("isUsed")!=null){
                List<WlyyHospitalSysDictDO> wlyyHospitalSysDictDOList = wlyyHospitalSysDictDao.findByDictNameAndDictCode("drugStoreStatus",map.get("isUsed").toString());
                if (wlyyHospitalSysDictDOList!=null&&wlyyHospitalSysDictDOList.size()>0){
                    map.put("isUsedName",wlyyHospitalSysDictDOList.get(0).getDictValue());
                }
            }
        }
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setTotalCount(listCount==null?0:listCount.size());
        return mixEnvelop;
    }
}

+ 18 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/family/dao/BasePatientMemberDictDao.java

@ -0,0 +1,18 @@
package com.yihu.jw.hospital.family.dao;
import com.yihu.jw.entity.hospital.family.BasePatientMemberDictDO;
import com.yihu.jw.entity.hospital.family.WlyyPatientFamilyMemberDO;
import org.checkerframework.checker.units.qual.A;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BasePatientMemberDictDao extends PagingAndSortingRepository<BasePatientMemberDictDO, String>, JpaSpecificationExecutor<BasePatientMemberDictDO> {
    @Query("from BasePatientMemberDictDO t where t.isDel = 1")
    List<BasePatientMemberDictDO> findDictAll();
    @Query("from BasePatientMemberDictDO t where t.relationName = ?1 and t.isDel = 1")
    BasePatientMemberDictDO findByRelationName(String illness);
}

+ 30 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/family/dao/WlyyPatientFamilyMemberDao.java

@ -0,0 +1,30 @@
package com.yihu.jw.hospital.family.dao;
import com.yihu.jw.entity.hospital.family.BasePatientMemberDictDO;
import com.yihu.jw.entity.hospital.family.WlyyPatientFamilyMemberDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface WlyyPatientFamilyMemberDao extends PagingAndSortingRepository<WlyyPatientFamilyMemberDO, String>, JpaSpecificationExecutor<WlyyPatientFamilyMemberDO> {
    @Query("from WlyyPatientFamilyMemberDO t where t.patient=?1 and t.familyRelation=?2 and t.isDel = 1")
    List<WlyyPatientFamilyMemberDO> findByPatientAndFamilyRelation(String patient,String familyRelation);
    @Query("from WlyyPatientFamilyMemberDO t where t.id=?1  and t.isDel = 1")
    WlyyPatientFamilyMemberDO findByIdAndDel(String id);
    @Query("from WlyyPatientFamilyMemberDO t where t.cardNo=?1 and t.patient=?2  and t.isDel =1")
    WlyyPatientFamilyMemberDO findbyCardNoAndPatient(String idCard,String patient);
    @Query("from WlyyPatientFamilyMemberDO t where t.patient=?1  and t.isDel =1")
    List<WlyyPatientFamilyMemberDO> findbyPatient(String patient);
    /**
     * 查询居民的某个成员
     *
     * @param patient 居民
     * @param member 成员
     * @return
     */
    WlyyPatientFamilyMemberDO findByPatientAndFamilyMember(String patient,String member);
}

+ 21 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/family/service/PatientMemberDictService.java

@ -0,0 +1,21 @@
package com.yihu.jw.hospital.family.service;
import com.yihu.jw.entity.hospital.family.BasePatientMemberDictDO;
import com.yihu.jw.hospital.family.dao.BasePatientMemberDictDao;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PatientMemberDictService extends BaseJpaService<BasePatientMemberDictDO, BasePatientMemberDictDao> {
    @Autowired
    private BasePatientMemberDictDao basePatientMemberDictDao;
    //获取所有关系集合
    public List<BasePatientMemberDictDO> findAllMemberDict(){
        List<BasePatientMemberDictDO> list = basePatientMemberDictDao.findDictAll();
        return list;
    }
}

+ 719 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/family/service/WlyyFamilyMemberService.java

@ -0,0 +1,719 @@
package com.yihu.jw.hospital.family.service;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.dict.dao.BaseJobCategoryDao;
import com.yihu.jw.entity.base.dict.BaseJobCategoryDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
import com.yihu.jw.entity.hospital.family.BasePatientMemberDictDO;
import com.yihu.jw.entity.hospital.family.WlyyPatientFamilyMemberDO;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.family.dao.BasePatientMemberDictDao;
import com.yihu.jw.hospital.family.dao.WlyyPatientFamilyMemberDao;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.TnyyEntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
import com.yihu.jw.hospital.ykyy.service.YkyyService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.util.common.IdCardUtil;
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 org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class WlyyFamilyMemberService extends BaseJpaService<WlyyPatientFamilyMemberDO, WlyyPatientFamilyMemberDao> {
    @Autowired
    private WlyyPatientFamilyMemberDao wlyyPatientFamilyMemberDao;
    @Autowired
    private BasePatientMemberDictDao basePatientMemberDictDao;
    @Autowired
    private EntranceService entranceService;
    @Autowired
    private PatientMappingDao patientMappingDao;
    @Autowired
    private BasePatientDao basePatientDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private YkyyEntranceService ykyyEntranceService;
    @Autowired
    private BasePatientMedicareCardDao basePatientMedicareCardDao;
    @Autowired
    private XzzxEntranceService xzzxEntranceService;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Autowired
    private TnyyEntranceService tnyyEntranceService;
    @Autowired
    private YkyyService ykyyService;
    @Value("${wechat.id}")
    private String wxId;
    @Autowired
    private BaseJobCategoryDao baseJobCategoryDao;
    //添加关联家属
    @Transactional
    public MixEnvelop addFamily(String id,String patientId, String familyName, String dictId, String cardType, String idCard, String phoneNum,boolean demo,String medicareType,String medicare,String clinicId) throws Exception {
        MixEnvelop mixEnvelop = new MixEnvelop();
        try{
        BasePatientMemberDictDO basePatientMemberDictDO = basePatientMemberDictDao.findOne(dictId);
        BasePatientDO basePatientDO = null;
        if ("xm_ykyy_wx".equalsIgnoreCase(wxId)){
            /*List<BasePatientDO> listpatients=basePatientDao.findByMobileAndDel(phoneNum,"1");
            if (listpatients!=null&&listpatients.size()>0){
                basePatientDO=listpatients.get(0);
            }*/
            basePatientDO= basePatientDao.findByIdcard(idCard);
        }else {
            basePatientDO= basePatientDao.findByIdcard(idCard);
        }
        List<BasePatientDO> list = basePatientDao.findByMobile(phoneNum);
        if ("xm_xzzx_wx".equalsIgnoreCase(wxId)){
            if (list!=null&&list.size()>0&&basePatientDO!=null){
                if (basePatientDO.getMobile().equalsIgnoreCase(phoneNum)){
                }else{
                    mixEnvelop.setStatus(408);
                    mixEnvelop.setMessage("您所添加的家属手机号已被他人占用");
                    return  mixEnvelop;
                }
            }else if (list!=null&&list.size()>0&&basePatientDO==null){
                mixEnvelop.setStatus(409);
                mixEnvelop.setMessage("您所添加的家属手机号已被他人占用");
                return  mixEnvelop;
            } else {
                if(basePatientDO==null){
                    basePatientDO = new BasePatientDO();
                }
                basePatientDO.setMobile(phoneNum);
            }
        }else{
            if(basePatientDO==null){
                basePatientDO = new BasePatientDO();
            }
        }
        Map<String,Object> resultMap = new HashMap<>();
        PatientMappingDO patientMappingDO = patientMappingDao.findByIdcard(idCard);
        if(null==patientMappingDO){
            patientMappingDO = new PatientMappingDO();
        }
        WlyyPatientFamilyMemberDO result = new WlyyPatientFamilyMemberDO();
        if (StringUtils.isNotBlank(id)){
            result = wlyyPatientFamilyMemberDao.findOne(id);
            basePatientDO = basePatientDao.findById(result.getFamilyMember());
            patientMappingDO = patientMappingDao.findByPatient(result.getFamilyMember());
        }
        String dictName = "";
        if (null!=basePatientMemberDictDO){
            dictName = basePatientMemberDictDO.getRelationName();
        }
        String familyId="";
        String birth = "";
        String yktFamilyId = "";
        int sex=3;
        //获取his家属数据
        JSONArray jsonArray = new JSONArray();
        if("xm_ykyy_wx".equalsIgnoreCase(wxId)){
            jsonArray = ykyyEntranceService.findHisPatientBymMedicare(medicare,clinicId,false);
            if(jsonArray!=null&&jsonArray.size()>0){
                net.sf.json.JSONObject jsonObject= net.sf.json.JSONObject.fromObject(jsonArray.get(0).toString());
                if (null!=jsonObject.get("brid")){
                    String Pat_name = jsonObject.getString("brxm");
                    if (!Pat_name.equalsIgnoreCase(familyName)) {
                        mixEnvelop.setStatus(408);
                        mixEnvelop.setMessage("您所添加的家属的名称有误,无法添加");
                        return mixEnvelop;
                    }
                    /*basePatientDO.setMobile(phoneNum);*/
                    familyId= jsonObject.getString("brid");
                    birth= jsonObject.getString("csny");
                    long lt = new Long(birth);
                    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
                    birth = sf.format(lt);
                    String familySex = IdCardUtil.getSexForIdcard(idCard);
                    if (familySex.equalsIgnoreCase("男")){
                        familySex= "1";
                        sex =1 ;
                    }else if (familySex.equalsIgnoreCase("女")){
                        familySex = "0";
                        sex = 2 ;
                    }else {
                        familySex = "2";
                        sex = 3;
                    }
                    String familyAge = String.valueOf(IdCardUtil.getAgeForIdcard(idCard));
                    BasePatientMemberDictDO basePatientMemberDictDO1 = basePatientMemberDictDao.findOne(dictId);
                    String relationName = "";
                    if (null!=basePatientMemberDictDO1){
                        relationName=basePatientMemberDictDO1.getRelationName();
                    }
                    BasePatientDO basePatientDO1  = basePatientDao.findById(patientId);
                    String res = "";
                    //id不为空则为修改家人关系
                    if (StringUtils.isNotBlank(id)){
                        if (null!=basePatientDO1){
                            res = ykyyService.updateYktFamily(familyName,idCard, familySex,familyAge,phoneNum,medicare,relationName,clinicId,result.getYktFamilyId(),birth);
                        }
                        if (StringUtils.isNotEmpty(res)){
                            JSONObject jsonObject1 = JSONObject.parseObject(res);
                            if ("200".equalsIgnoreCase(jsonObject1.getString("code"))){
                                /*JSONObject jsonObject2 = JSONObject.parseObject(jsonObject1.getString("data"));
                                yktFamilyId = jsonObject2.getString("ID");*/
                            }else {
                                mixEnvelop.setStatus(408);
                                mixEnvelop.setMessage("更新家人关系失败,请核对个人信息.");
                                return mixEnvelop;
                            }
                        }else {
                            mixEnvelop.setStatus(408);
                            mixEnvelop.setMessage("更新家人关系失败,请核对个人信息.");
                            return mixEnvelop;
                        }
                    }else {
                        if (null!=basePatientDO1){
                            res = ykyyService.addYktFamily(familyName,idCard, familySex,familyAge,phoneNum,medicare,relationName,clinicId,basePatientDO1.getUserId(),birth);
                        }
                        if (StringUtils.isNotEmpty(res)){
                            JSONObject jsonObject1 = JSONObject.parseObject(res);
                            if ("200".equalsIgnoreCase(jsonObject1.getString("code"))){
                                JSONObject jsonObject2 = JSONObject.parseObject(jsonObject1.getString("data"));
                                yktFamilyId = jsonObject2.getString("ID");
                                result.setYktFamilyId(yktFamilyId);
                            }else {
                                mixEnvelop.setStatus(408);
                                mixEnvelop.setMessage("添加家人关系失败,请核对个人信息.");
                                return mixEnvelop;
                            }
                        }else {
                            mixEnvelop.setStatus(408);
                            mixEnvelop.setMessage("添加家人关系失败,请核对个人信息.");
                            return mixEnvelop;
                        }
                    }
                    System.out.println("眼科转换后的csny"+birth);
                }else {
                    mixEnvelop.setStatus(409);
                    mixEnvelop.setMessage("您所添加的家属无就诊记录无法添加");
                    return mixEnvelop;
                }
            }else {
                mixEnvelop.setStatus(409);
                mixEnvelop.setMessage("您所添加的家属无就诊记录无法添加");
                return mixEnvelop;
            }
        }else if ("xm_zsyy_wx".equalsIgnoreCase(wxId)) {
            jsonArray = entranceService.BS10008(idCard, "", "", "", "", "", demo);
            if (jsonArray != null && jsonArray.size() > 0) {
                net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(jsonArray.get(0).toString());
                //如果病人id为空则没有就诊记录
                if (null != jsonObject.get("Patient_Id")) {
                    familyId = jsonObject.getString("Patient_Id");
                    String Pat_name = jsonObject.getString("Pat_Name");
                    if (null != jsonObject.get("Phone_Number_Business")) {
                        String Next_Of_Kin_Phone = jsonObject.get("Phone_Number_Business").toString();
                        if (!Next_Of_Kin_Phone.equalsIgnoreCase(phoneNum)) {
                            mixEnvelop.setStatus(408);
                            mixEnvelop.setMessage("您所添加的家属的电话有误,无法添加");
                            return mixEnvelop;
                        }
                        basePatientDO.setMobile(phoneNum);
                        basePatientDO.setPhone(phoneNum);
                    }
                    if (!Pat_name.equalsIgnoreCase(familyName)) {
                        mixEnvelop.setStatus(408);
                        mixEnvelop.setMessage("您所添加的家属的名称有误,无法添加");
                        return mixEnvelop;
                    }
                    if(null!=jsonObject.get("Birth_Date")){
                        birth = jsonObject.get("Birth_Date").toString();
                    }
                    if(null!=jsonObject.get("Sex")){
                        sex = Integer.parseInt(jsonObject.get("Sex").toString());
                    }
                }else {
                mixEnvelop.setStatus(408);
                mixEnvelop.setMessage("您所添加的家属无就诊记录,无法添加");
            }
            }
        }else if ("xm_xzzx_wx".equalsIgnoreCase(wxId)) {
            com.alibaba.fastjson.JSONArray jsonArray1 = xzzxEntranceService.selectPateintCardByIdCard(idCard);
            if (null!=jsonArray1&&jsonArray1.size()>0){
                String familySex = IdCardUtil.getSexForIdcard(idCard);
                if (familySex.equalsIgnoreCase("男")){
                    sex =1 ;
                }else if (familySex.equalsIgnoreCase("女")){
                    sex = 2 ;
                }
            }else {
                mixEnvelop.setStatus(408);
                mixEnvelop.setMessage("您所添加的家属无就诊记录,无法添加");
                return  mixEnvelop;
            }
        }else if ("sd_tnzyy_wx".equalsIgnoreCase(wxId)){
            com.alibaba.fastjson.JSONArray jsonArray1 = tnyyEntranceService.selectPatientMappingCode(idCard);
            if (jsonArray1!=null&&jsonArray1.size()>0){
                com.alibaba.fastjson.JSONObject jsonObject = JSONObject.parseObject(jsonArray1.get(0).toString());
                if (jsonObject!=null){
                    familyId = jsonObject.getString("BRID");
                    String familySex = IdCardUtil.getSexForIdcard(idCard);
                    if (familySex.equalsIgnoreCase("男")){
                        sex =1 ;
                    }else if (familySex.equalsIgnoreCase("女")){
                        sex = 2 ;
                    }
                }
            }else {
                mixEnvelop.setStatus(408);
                mixEnvelop.setMessage("您所添加的家属无就诊记录,无法添加");
                return  mixEnvelop;
            }
        }
        basePatientDO.setSex(sex);
        if ("xm_xzzx_wx".equalsIgnoreCase(wxId)){
            basePatientDO.setBirthday(IdCardUtil.getBirthdayForIdcard(idCard));
        }else if("xm_zsyy_wx".equalsIgnoreCase(wxId)||"xm_ykyy_wx".equalsIgnoreCase(wxId)) {
            SimpleDateFormat sf3 = new SimpleDateFormat("yyyy-MM-dd");
            Date saveBirth1 = sf3.parse(birth);
            System.out.println("====="+saveBirth1);
            basePatientDO.setBirthday(saveBirth1);
        }else {
            basePatientDO.setBirthday(IdCardUtil.getBirthdayForIdcard(idCard));
        }
        result.setFamilyRelation(dictId);
        result.setFamilyRelationName(dictName);
        result.setIsDel(1);
        result.setPatient(patientId);
        result.setCardNo(idCard);
        result.setCardType(cardType);
        result.setMobile(phoneNum);
        //保存到base_patient表
        basePatientDO.setName(familyName);
        basePatientDO.setIdcard(idCard);
        basePatientDO.setRegister("0");
        basePatientDO.setEnabled(1);
        basePatientDO.setDel("1");
        BasePatientDO sucessPatient= basePatientDao.save(basePatientDO);
        String patientNewId= "";
        if (sucessPatient!=null){
            patientNewId=sucessPatient.getId();
        }
            result.setFamilyMember(patientNewId);
            wlyyPatientFamilyMemberDao.save(result);
            if (!"xm_xzzx_wx".equalsIgnoreCase(wxId)){
                patientMappingDO.setIdcard(idCard);
                patientMappingDO.setSource("1");
                patientMappingDO.setPatientName(familyName);
                patientMappingDO.setMappingCode(familyId);
                patientMappingDO.setPatient(patientNewId);
                patientMappingDO.setCreateTime(new Date());
                patientMappingDao.save(patientMappingDO);
            }
            resultMap.put("patientId",patientId);
            resultMap.put("familyMember",patientNewId);
            resultMap.put("idCard",idCard);
            resultMap.put("phoneNum",phoneNum);
            resultMap.put("relationName",dictName);
            resultMap.put("name",familyName);
            resultMap.put("cardType",cardType);
            List<Map<String,Object>> resultList = new ArrayList();
            resultList.add(resultMap);
            mixEnvelop.setStatus(200);
            mixEnvelop.setMessage("添加成功");
            mixEnvelop.setDetailModelList(resultList);
            if ("xm_ykyy_wx".equalsIgnoreCase(wxId)){
                if (StringUtils.isNotBlank(clinicId)){
                    PatientMedicareCardDO patientMedicareCardDO = basePatientMedicareCardDao.findByTypeAndPatientCodeAndDel("A_02",sucessPatient.getId(),"1");
                    if (patientMedicareCardDO==null){
                        patientMedicareCardDO = new PatientMedicareCardDO();
                    }
                    patientMedicareCardDO.setCode(clinicId);
                    //patientMedicareCardDO.setType(medicareType);
                    patientMedicareCardDO.setPatientCode(patientNewId);
                    patientMedicareCardDO.setDel("1");
                    patientMedicareCardDO.setParentType("A");
                    patientMedicareCardDO.setType("A_02");
                    basePatientMedicareCardDao.save(patientMedicareCardDO);
                }
                if (StringUtils.isNotBlank(medicare)){
                    //PatientMedicareCardDO patientMedicareCardDO = basePatientMedicareCardDao.findByCode(medicare);
                    PatientMedicareCardDO patientMedicareCardDO = basePatientMedicareCardDao.findByTypeAndPatientCodeAndDel("A_01",sucessPatient.getId(),"1");
                    if (patientMedicareCardDO==null){
                        patientMedicareCardDO = new PatientMedicareCardDO();
                    }
                    patientMedicareCardDO.setCode(medicare);
                    //patientMedicareCardDO.setType(medicareType);
                    patientMedicareCardDO.setPatientCode(patientNewId);
                    patientMedicareCardDO.setDel("1");
                    patientMedicareCardDO.setParentType("A");
                    patientMedicareCardDO.setType("A_01");
                    basePatientMedicareCardDao.save(patientMedicareCardDO);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            mixEnvelop.setStatus(408);
            mixEnvelop.setMessage("添加失败");
        }
        return mixEnvelop;
    }
    //眼科同步家人信息
    @Transactional
    public void saveYktFamily(String patientId) throws Exception{
        try {
            String userId="";
            BasePatientDO basePatientDO = basePatientDao.findById(patientId);
            if (null!=basePatientDO){
                userId = basePatientDO.getUserId();
            }
            List<Map<String, String>> list=new ArrayList<Map<String, String>>();
            String res  = ykyyService.findYktFamily(userId);
            if (StringUtils.isNotEmpty(res)){
                JSONObject jsonObject = JSONObject.parseObject(res);
                if ("200".equalsIgnoreCase(jsonObject.getString("code"))){
                    JSONObject data = jsonObject.getJSONObject("data");
                    List<WlyyPatientFamilyMemberDO> patientFamilyMemberDOS = wlyyPatientFamilyMemberDao.findbyPatient(patientId);
                    if (patientFamilyMemberDOS!=null&&patientFamilyMemberDOS.size()>0){
                        wlyyPatientFamilyMemberDao.delete(patientFamilyMemberDOS);
                    }
                    com.alibaba.fastjson.JSONArray jsonArray = data.getJSONArray("list");
                    if(jsonArray!=null && jsonArray.size()>0) {
                        for (int i = 0; i < jsonArray.size(); i++) {
                            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                            System.out.println("==="+jsonArray.get(i).toString());
                            if (StringUtils.isNotEmpty(jsonObject1.getString("IDCARD"))){
                                System.out.println("同步的身份证号:"+jsonObject1.getString("IDCARD"));
                                BasePatientDO patientDO = null;
                                /*if ("xm_ykyy_wx".equalsIgnoreCase(wxId)){
                                    List<BasePatientDO> listpatients=basePatientDao.findByMobileAndDel(jsonObject1.getString("TEL"),"1");
                                    if (listpatients!=null&&listpatients.size()>0){
                                        patientDO=listpatients.get(0);
                                    }
                                }else {*/
                                patientDO= basePatientDao.findByIdcard(jsonObject1.getString("IDCARD"));
                        /*        }*/
                                if (patientDO==null){
                                    patientDO = new BasePatientDO();
                                }
                                if (StringUtils.isNotBlank(jsonObject1.getString("TEL"))){
                                    List<BasePatientDO> listpatients=basePatientDao.findByMobileAndDel(jsonObject1.getString("TEL"),"1");
                                    if (listpatients!=null&&listpatients.size()>0){
                                    }else {
                                        patientDO.setMobile(jsonObject1.getString("TEL"));
                                    }
                                }
                                if(StringUtils.isNotBlank(jsonObject1.getString("BIRTHDAY"))){
                                    patientDO.setBirthday(DateUtil.strToDate(jsonObject1.getString("BIRTHDAY")));
                                }
                                String pw = null;
                                String salt = UUID.randomUUID().toString().substring(0,5);
                                String mobile = jsonObject1.getString("TEL");
                                String idcard = jsonObject1.getString("IDCARD");
                                if(org.apache.commons.lang3.StringUtils.isNotBlank(mobile)){
                                    pw = mobile.substring(mobile.length()-6);
                                }else{
                                    pw = idcard.substring(idcard.length()-6);
                                }
                                patientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                patientDO.setSalt(salt);
                                patientDO.setIdcard(jsonObject1.getString("IDCARD"));
                                patientDO.setName(jsonObject1.getString("NAME"));
                                if(jsonObject1.getInteger("SEX")!=null){
                                    if (1==jsonObject1.getInteger("SEX")){
                                        patientDO.setSex(1);
                                    }else if (0==jsonObject1.getInteger("SEX")){
                                        patientDO.setSex(2);
                                    }else {
                                        patientDO.setSex(0);
                                    }
                                }
                                patientDO.setDel("1");
                                patientDO.setEnabled(1);
                                patientDO.setLocked(0);
                                patientDO.setCreateTime(new Date());
                                patientDO.setUpdateTime(new Date());
                                patientDO = basePatientDao.save(patientDO);
                                //取his中的病人code
                                JSONArray hisArray = ykyyEntranceService.findHisPatientBymMedicare(jsonObject1.getString("MEDICALCARD"),jsonObject1.getString("CLINICID"),false);
                                if(hisArray!=null&&hisArray.size()>0) {
                                    net.sf.json.JSONObject hisObject = net.sf.json.JSONObject.fromObject(hisArray.get(0).toString());
                                    PatientMappingDO patientMappingDO = patientMappingDao.findByIdcard(patientDO.getIdcard());
                                    if(patientMappingDO==null){
                                        patientMappingDO= new PatientMappingDO();
                                    }
                                    patientMappingDO.setPatientName(jsonObject1.getString("NAME"));
                                    patientMappingDO.setPatient(patientDO.getId());
                                    patientMappingDO.setMappingCode(hisObject.getString("brid"));
                                    patientMappingDO.setSource("1");
                                    patientMappingDO.setCreateTime(new Date());
                                    patientMappingDO.setIdcard(patientDO.getIdcard());
                                    patientMappingDao.save(patientMappingDO);
                                }
                                WlyyPatientFamilyMemberDO wlyyPatientFamilyMemberDO = new WlyyPatientFamilyMemberDO();
                                BasePatientMemberDictDO basePatientMemberDictDO =basePatientMemberDictDao.findByRelationName(jsonObject1.getString("ILLNESS"));
                                if (basePatientMemberDictDO!=null){
                                    wlyyPatientFamilyMemberDO.setIsDel(1);
                                    wlyyPatientFamilyMemberDO.setPatient(patientId);
                                    wlyyPatientFamilyMemberDO.setClinicid(jsonObject1.getString("CLINICID"));
                                    wlyyPatientFamilyMemberDO.setCardType("身份证");
                                    wlyyPatientFamilyMemberDO.setFamilyMember(patientDO.getId());
                                    wlyyPatientFamilyMemberDO.setFamilyRelation(basePatientMemberDictDO.getId());
                                    wlyyPatientFamilyMemberDO.setFamilyRelationName(basePatientMemberDictDO.getRelationName());
                                    wlyyPatientFamilyMemberDO.setCardNo(jsonObject1.getString("IDCARD"));
                                    wlyyPatientFamilyMemberDO.setYktFamilyId(jsonObject1.getString("ID"));
                                    if (StringUtils.isNotBlank(jsonObject1.getString("TEL"))){
                                        wlyyPatientFamilyMemberDO.setMobile(jsonObject1.getString("TEL"));
                                    }
                                    wlyyPatientFamilyMemberDao.save(wlyyPatientFamilyMemberDO);
                                }
                                if(jsonObject1.get("MEDICALCARD")!=null){
                                    List<PatientMedicareCardDO> patientMedicareCardDOS =  basePatientMedicareCardDao.findByPatientCode(patientDO.getId());
                                    boolean flag = false;
                                    PatientMedicareCardDO patientMedicareCardDO1 = new PatientMedicareCardDO();
                                    for (PatientMedicareCardDO medicareCardDO:patientMedicareCardDOS){
                                        if (medicareCardDO.getType().equalsIgnoreCase("A_01")){
                                            flag=true;
                                            patientMedicareCardDO1=medicareCardDO;
                                            break;
                                        }
                                    }
                                    System.out.println("flag"+flag);
                                    PatientMedicareCardDO patientMedicareCardDO = basePatientMedicareCardDao.findByCodeAndPatientCode(jsonObject1.getString("MEDICALCARD"),patientDO.getId());
                                    if (patientMedicareCardDO==null&&flag==false){
                                        patientMedicareCardDO = new PatientMedicareCardDO();
                                        patientMedicareCardDO.setCode(jsonObject1.getString("MEDICALCARD"));
                                        patientMedicareCardDO.setParentType("A");
                                        patientMedicareCardDO.setType("A_01");
                                        patientMedicareCardDO.setPatientCode(patientDO.getId());
                                        patientMedicareCardDO.setDel("1");
                                        basePatientMedicareCardDao.save(patientMedicareCardDO);
                                    }else if (patientMedicareCardDO!=null&&flag==true&&patientMedicareCardDO1!=null){
                                        patientMedicareCardDO1.setCode(jsonObject1.getString("MEDICALCARD"));
                                        patientMedicareCardDO1.setParentType("A");
                                        patientMedicareCardDO1.setType("A_01");
                                        patientMedicareCardDO1.setPatientCode(patientDO.getId());
                                        patientMedicareCardDO1.setDel("1");
                                        basePatientMedicareCardDao.save(patientMedicareCardDO1);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("同步家人关系失败");
        }
    }
    //根据患者id查询关联家属
    @Transactional
    public List<Map<String,Object>> findFamilyByPatientId(String patientId) throws ParseException {
        if("xm_ykyy_wx".equalsIgnoreCase(wxId)){
            String sql = "select t.id as \"id\",t.card_type as \"cardType\", " +
                    "t.patient as \"patient\",b.name as \"name\",b.sex as \"sex\","+
                    "to_char(b.birthday,'yyyy-MM-dd') as\"birthday\",b.idcard as \"idcard\",t.clinicid as \"clinicid\"," +
                    "t.family_member as \"familyMember\",c.relation_name as \"relationName\" "+
                    " from wlyy_patient_family_member t left join base_patient b" +
                    " on t.family_member = b.id left join base_patient_member_dict c on t.family_relation=c.id where 1=1 and t.is_del=1 ";
            if (StringUtils.isNotBlank(patientId)){
                sql += " and t.patient = '"+patientId+"'";
            }
            List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
            if (list!=null&&list.size()>0){
                for (Map<String,Object> map:list){
                    if (null!=map.get("idcard")){
                        map.put("age",IdCardUtil.getAgeForIdcard(map.get("idcard").toString()));
                    }
                    if (null!=map.get("birthday")){
                        System.out.println("birthday:"+map.get("birthday").toString());
                    }
                    List<PatientMedicareCardDO> list1 = basePatientMedicareCardDao.findByPatientCode(map.get("familyMember").toString());
                    if (null!=list1&&list1.size()>0){
                        map.put("card",list1.get(0));
                    }else {
                        map.put("card","");
                    }
                    WlyyPatientFamilyMemberDO patientFamilyMemberDO = wlyyPatientFamilyMemberDao.findByIdAndDel(map.get("id").toString());
                    if (patientFamilyMemberDO!=null){
                        map.put("mobile",patientFamilyMemberDO.getMobile());
                    }
                }
            }
            return list;
        }else {
            String sql = "select t.id as \"id\",t.card_type as \"cardType\", " +
                    "t.patient as \"patient\",b.name as \"name\",b.sex as \"sex\","+
                    "b.birthday as\"birthday\",b.idcard as \"idcard\"," +
                    "t.family_member as \"familyMember\",c.relation_name as \"relationName\" "+
                    " from wlyy_patient_family_member t left join base_patient b" +
                    " on t.family_member = b.id left join base_patient_member_dict c on t.family_relation=c.id where 1=1 and t.is_del=1 ";
            if (StringUtils.isNotBlank(patientId)){
                sql += " and t.patient = '"+patientId+"'";
            }
            List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
            if (list!=null&&list.size()>0){
                for (Map<String,Object> map:list){
                    if (map.get("birthday")!=null){
                        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
                        int age = getAgeByBirth(sp.parse(map.get("birthday").toString()));
                        map.put("age",age);
                    }
                    List<PatientMedicareCardDO> list1 = basePatientMedicareCardDao.findByPatientCode(map.get("familyMember").toString());
                    map.put("cardList",list1);
                }
            }
            return list;
        }
    }
    private static int getAgeByBirth(Date birthday) {
        int age = 0;
        try {
            Calendar now = Calendar.getInstance();
            now.setTime(new Date());// 当前时间
            Calendar birth = Calendar.getInstance();
            birth.setTime(birthday);
            if (birth.after(now)) {//如果传入的时间,在当前时间的后面,返回0岁
                age = 0;
            } else {
                age = now.get(Calendar.YEAR) - birth.get(Calendar.YEAR);
                if (now.get(Calendar.DAY_OF_YEAR) > birth.get(Calendar.DAY_OF_YEAR)) {
                    age += 1;
                }
            }
            return age;
        } catch (Exception e) {//兼容性更强,异常后返回数据
            return 0;
        }
    }
    //删除家人信息
    public Envelop delMember(String id){
        Envelop envelop = new Envelop();
        WlyyPatientFamilyMemberDO wlyyPatientFamilyMemberDO = wlyyPatientFamilyMemberDao.findOne(id);
        if (wlyyPatientFamilyMemberDO!=null){
            wlyyPatientFamilyMemberDO.setIsDel(0);
            if ("xm_ykyy_wx".equalsIgnoreCase(wxId)){
                //删除眼科通的家人关系
                String res = ykyyService.deleteYktFamily(wlyyPatientFamilyMemberDO.getYktFamilyId());
                if (StringUtils.isNotEmpty(res)){
                    JSONObject jsonObject = JSONObject.parseObject(res);
                    if ("200".equalsIgnoreCase(jsonObject.getString("code"))){
                        envelop.setMessage("删除成功");
                    }else {
                        envelop.setMessage("删除失败");
                        envelop.setStatus(-1);
                        return envelop;
                    }
                }else {
                    envelop.setMessage("删除失败");
                    envelop.setStatus(-1);
                    return envelop;
                }
            }
            wlyyPatientFamilyMemberDao.save(wlyyPatientFamilyMemberDO);
            envelop.setMessage("删除成功");
            return envelop;
        }else {
            envelop.setMessage("删除失败");
            envelop.setStatus(408);
            return envelop;
        }
    }
    //获取单个亲属详细信息
    public List<Map<String,Object>>  findMemberById(String id) throws Exception {
        String sql="select t.id as \"id\",t.card_type as \"cardType\"," +
                "t.family_member as \"familyMember\",t.patient as \"patient\"," +
                "b.name as \"name\",b.idcard as \"idcard\",b.mobile as \"mobile\",t.clinicid as \"clinicid\"," +
                "c.relation_name \"relationName\",b.birthday as\"birthday\",b.sex as\"sex\"" +
                " from wlyy_patient_family_member t left join base_patient b" +
                " on t.family_member = b.id left join base_patient_member_dict c on t.family_relation=c.id " +
                " where 1=1 and t.is_del = 1 ";
        if (StringUtils.isNotBlank(id)){
            sql+=" and t.id='"+id+"'";
        }
       List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
        if (list!=null&&list.size()>0){
            for (Map<String,Object> map:list){
                if (map.get("birthday")!=null){
                    SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
                    int age = getAgeByBirth(sp.parse(map.get("birthday").toString()));
                    map.put("age",age);
                }
                if ("xm_ykyy_wx".equalsIgnoreCase(wxId)){
                    WlyyPatientFamilyMemberDO patientFamilyMemberDO = wlyyPatientFamilyMemberDao.findByIdAndDel(map.get("id").toString());
                    if (patientFamilyMemberDO!=null){
                        map.put("mobile",patientFamilyMemberDO.getMobile());
                    }
                    if(null!=map.get("familyMember")){
                        List<PatientMedicareCardDO> list1 = basePatientMedicareCardDao.findByPatientCode(map.get("familyMember").toString());
                        if (list1!=null&&list1.size()!=0){
                            for (PatientMedicareCardDO patientMedicareCardDO:list1){
                                if (patientMedicareCardDO.getType().equalsIgnoreCase("A_02")){
                                    map.put("clinicid",patientMedicareCardDO.getCode());
                                }else {
                                    map.put("card",patientMedicareCardDO);
                                }
                            }
                            JSONObject object = ykyyEntranceService.selectByAddress(list1.get(0).getCode());
                            if (object!=null){
                                map.put("address",object.getString("address"));
                                map.put("zydm",object.getString("zydm"));
                                if (StringUtils.isNotBlank(object.getString("zydm"))){
                                    BaseJobCategoryDO jobCategoryDO = baseJobCategoryDao.findOne(Integer.parseInt(object.getString("zydm")));
                                    if (jobCategoryDO!=null){
                                        map.put("zydmName",jobCategoryDO.getName());
                                    }
                                }else {
                                    map.put("zydmName","");
                                }
                                map.put("jtdh",object.getString("jtdh"));
                            }
                        }else {
                            map.put("card","");
                            map.put("address","");
                            map.put("zydm","");
                            map.put("jtdh","");
                            map.put("zydmName","");
                        }
                    }
                }
            }
        }
        return list;
    }
}

+ 20 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicailBillDao.java

@ -0,0 +1,20 @@
package com.yihu.jw.hospital.healthCare;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalBillDO;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalIcdDO;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalRelationDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by wangzhinan 20211003
 */
public interface YlzMedicailBillDao extends PagingAndSortingRepository<YlzMedicalBillDO, String>, JpaSpecificationExecutor<YlzMedicalBillDO> {
    @Query("from YlzMedicalBillDO a where a.medicalId = ?1 ")
    List<YlzMedicalBillDO> findByMedicalId(String medicalId);
}

+ 23 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicailIcdDao.java

@ -0,0 +1,23 @@
package com.yihu.jw.hospital.healthCare;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalIcdDO;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalRelationDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by wangzhinan 20211003
 */
public interface YlzMedicailIcdDao extends PagingAndSortingRepository<YlzMedicalIcdDO, String>, JpaSpecificationExecutor<YlzMedicalIcdDO> {
    @Query("from YlzMedicalIcdDO a where a.medicalId = ?1 ")
    List<YlzMedicalIcdDO> findByMedicalId(String medicalId);
    @Modifying
    @Query("delete from YlzMedicalIcdDO  where medicalId = ?1")
    void deleteByMedicalId(String medicalId);
}

+ 23 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicailMxDao.java

@ -0,0 +1,23 @@
package com.yihu.jw.hospital.healthCare;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalIcdDO;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalMxDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by wangzhinan 20211003
 */
public interface YlzMedicailMxDao extends PagingAndSortingRepository<YlzMedicalMxDO, String>, JpaSpecificationExecutor<YlzMedicalMxDO> {
    @Query("from YlzMedicalMxDO a where a.medicalId = ?1 ")
    List<YlzMedicalMxDO> findByMedicalId(String medicalId);
    @Modifying
    @Query("delete from YlzMedicalMxDO  where medicalId = ?1")
    void deleteByMedicalId(String medicalId);
}

+ 23 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicailRelationDao.java

@ -0,0 +1,23 @@
package com.yihu.jw.hospital.healthCare;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalRelationDO;
import com.yihu.jw.entity.hospital.httplog.YlzHttpLogDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
/**
 * Created by wangzhinan 20211003
 */
public interface YlzMedicailRelationDao extends PagingAndSortingRepository<YlzMedicalRelationDO, String>, JpaSpecificationExecutor<YlzMedicalRelationDO> {
    @Query("from YlzMedicalRelationDO a where a.relationCode = ?1 ")
    YlzMedicalRelationDO findByOutpatient(String relationCode);
    @Query("from YlzMedicalRelationDO a where a.logNo = ?1 ")
    YlzMedicalRelationDO findByLog_no(String logNo);
}

+ 16 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/healthCare/YlzMedicalPrescriptionUploadDao.java

@ -0,0 +1,16 @@
package com.yihu.jw.hospital.healthCare;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalBillDO;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalPrescriptionUploadDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by yeshijie on 2021/10/4.
 */
public interface YlzMedicalPrescriptionUploadDao  extends PagingAndSortingRepository<YlzMedicalPrescriptionUploadDO, String>, JpaSpecificationExecutor<YlzMedicalPrescriptionUploadDO> {
    YlzMedicalPrescriptionUploadDO findByPrescriptionId(String prescriptionId);
}

+ 9 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/httplog/dao/BaseOperateLogDao.java

@ -0,0 +1,9 @@
package com.yihu.jw.hospital.httplog.dao;
import com.yihu.jw.entity.hospital.httplog.BaseOperateLogDO;
import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseOperateLogDao extends PagingAndSortingRepository<BaseOperateLogDO, String>, JpaSpecificationExecutor<BaseOperateLogDO> {
}

+ 15 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/httplog/dao/YlzHttpLogDao.java

@ -0,0 +1,15 @@
package com.yihu.jw.hospital.httplog.dao;
import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
import com.yihu.jw.entity.hospital.httplog.YlzHttpLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2019/6/25.
 */
public interface YlzHttpLogDao extends PagingAndSortingRepository<YlzHttpLogDO, String>, JpaSpecificationExecutor<YlzHttpLogDO> {
}

+ 152 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/httplog/service/BaseOperateLogService.java

@ -0,0 +1,152 @@
package com.yihu.jw.hospital.httplog.service;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.httplog.BaseOperateLogDO;
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.hospital.httplog.dao.BaseOperateLogDao;
import com.yihu.jw.hospital.httplog.dao.WlyyHttpLogDao;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.JDBCSqlServer;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class BaseOperateLogService extends BaseJpaService<BaseOperateLogDO, BaseOperateLogDao> {
    @Autowired
    private BaseOperateLogDao baseOperateLogDao;
    @Autowired
    private BasePatientDao basePatientDao;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private JDBCSqlServer jdbcSqlServer;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private PatientMappingDao patientMappingDao;
    @Autowired
    private DoctorMappingDao doctorMappingDao;
    @Value("${wechat.id}")
    private String wxId;
    @Value("${wechat.flag}")
    private boolean flag;
    public void saveOperateLog(String operator,String patient,String code,String name,String relationType,String relationCode){
        BaseOperateLogDO baseOperateLogDO=new BaseOperateLogDO();
        BaseDoctorDO baseDoctorDO=baseDoctorDao.findById(operator);
        baseOperateLogDO.setOperator(operator);
        baseOperateLogDO.setPatient(patient);
        baseOperateLogDO.setCode(code);
        baseOperateLogDO.setName(name);
        baseOperateLogDO.setRelationType(relationType);
        baseOperateLogDO.setCreateTime(new Date());
        baseOperateLogDO.setIsDel("1");
        if (baseDoctorDO!=null){
            baseOperateLogDO.setOperatorName(baseDoctorDO.getName());
        }
        BasePatientDO basePatientDO=basePatientDao.findById(patient);
        if (basePatientDO!=null){
            baseOperateLogDO.setPatientName(basePatientDO.getName());
        }
        baseOperateLogDO=baseOperateLogDao.save(baseOperateLogDO);
        try {
            /*PatientMappingDO patientMappingDO=patientMappingDao.findByPatient(baseOperateLogDO.getPatient());
            if (patientMappingDO!=null){
                baseOperateLogDO.setPatient(patientMappingDO.getMappingCode());
            }
            DoctorMappingDO doctorMappingDO = doctorMappingDao.findByDoctor(baseOperateLogDO.getOperator());
            if (doctorMappingDO!=null){
                baseOperateLogDO.setOperator(doctorMappingDO.getMappingCode());
            }*/
            jdbcSqlServer.insertZsSqlserver(baseOperateLogDO);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public MixEnvelop  findOperateLogList(String code,String name,String patientName,String doctorName,String startTime,String endTime,Integer page,Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql ="select t.id as \"id\"," +
                " t.code as \"code\"," +
                " t.name as \"name\"," +
                " t.operator as \"operator\"," +
                " t.operator_name as \"operator_name\"," +
                " t.patient as \"patient\"," +
                " t.patient_name as \"patient_name\"," ;
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
            }else {
                sql+="  to_char(t.create_time,'yyyy-MM-dd HH24:mi:ss') as \"createTime\",";
            }
        }else{
            sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
        }
        sql+= " t.relation_type as \"relation_type\"," +
                " t.relation_code as \"relation_code\"" +
                " from base_operate_log t where t.is_del='1'";
        if (StringUtils.isNoneBlank(code)){
            sql+=" and t.code='"+code+"'";
        }
        if (StringUtils.isNoneBlank(name)){
            sql+=" and t.name like '%"+name+"%'";
        }
        if (StringUtils.isNoneBlank(patientName)){
            sql+=" and t.patient_name like '%"+patientName+"%'";
        }
        if (StringUtils.isNoneBlank(doctorName)){
            sql+=" and t.operator_name like '%"+doctorName+"%'";
        }
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<='" + endTime + "'";
                }else {
                    sql+="  and t.create_time<= to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<='" + endTime + "'";
            }
        }
        sql+=" order by t.create_time desc ";
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
}

+ 303 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/httplog/service/WlyyHttpLogService.java

@ -0,0 +1,303 @@
package com.yihu.jw.hospital.httplog.service;
import com.yihu.jw.entity.hospital.family.WlyyPatientFamilyMemberDO;
import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
import com.yihu.jw.hospital.family.dao.WlyyPatientFamilyMemberDao;
import com.yihu.jw.hospital.httplog.dao.WlyyHttpLogDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
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;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.sound.sampled.Mixer;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class WlyyHttpLogService  extends BaseJpaService<WlyyHttpLogDO, WlyyHttpLogDao> {
    @Autowired
    private WlyyHttpLogDao wlyyHttpLogDao;
    @Value("${wechat.id}")
    private String wxId;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Value("${wechat.flag}")
    private boolean flag;
    //保存http日志接口
    public  void  saveHttpLog(String code,String name,String patient,String doctor,String request,String response,String status ){
        WlyyHttpLogDO wlyyHttpLogDO = new WlyyHttpLogDO();
        wlyyHttpLogDO.setCode(code);
        wlyyHttpLogDO.setName(name);
        wlyyHttpLogDO.setPatient(patient);
        wlyyHttpLogDO.setDoctor(doctor);
        wlyyHttpLogDO.setRequest(request);
        wlyyHttpLogDO.setResponse(response);
        wlyyHttpLogDO.setStatus(status);
        wlyyHttpLogDO.setCreateTime(new Date());
        wlyyHttpLogDao.save(wlyyHttpLogDO);
    }
    public MixEnvelop findLog(String startTime, String endTime, String faceName, String patient, String doctor, Integer page, Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\"," +
                "t.code as \"code\"," +
                "t.name as \"name\"," +
                "t.patient as \"patient\"," +
                "t.doctor as \"doctor\"," +
                "t.request as \"request\"," +
                "t.response as \"response\"," +
                "t.status as \"status\",";
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
            }else {
                sql+="  to_char(t.create_time,'yyyy-MM-dd HH24:mi:ss') as \"createTime\",";
            }
        }else{
            sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
        }
        sql+=" a.name as \"patientName\"," +
                "b.name as \"doctorName\"" +
                " from wlyy_http_log t left join base_patient a on t.patient = a.id " +
                " left join base_doctor b on t.doctor = b.id where 1=1 and ( t.name = '合理用药审核接口'  or t.code like '%Check%')";
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<'" + endTime + "'";
                }else {
                    sql+="  and t.create_time< to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<'" + endTime + "'";
            }
        }
        if (StringUtils.isNotBlank(faceName)){
            sql+=" and t.name like '%"+faceName+"%'";
        }
        if (StringUtils.isNotBlank(patient)){
            sql+=" and a.name like '%"+patient+"%'";
        }
        if (StringUtils.isNotBlank(doctor)){
            sql+=" and b.name like '%"+doctor+"%'";
        }
        sql+=" order by t.create_time desc ";
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
    public MixEnvelop findWlyyHttpLogInBase(String startTime, String endTime, String code,String faceName, String patient, String doctor,String responeKeyWord,String requestKeyWord, Integer page, Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\"," +
                "t.code as \"code\"," +
                "t.name as \"name\"," +
                "t.patient as \"patient\"," +
                "t.doctor as \"doctor\"," +
                "t.request as \"request\"," +
                "t.response as \"response\"," +
                "t.status as \"status\",";
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
            }else {
                sql+="  to_char(t.create_time,'yyyy-MM-dd HH24:mi:ss') as \"createTime\",";
            }
        }else{
            sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
        }
        sql+=" a.name as \"patientName\"," +
                "b.name as \"doctorName\"" +
                " from wlyy_http_log t left join base_patient a on t.patient = a.id " +
                " left join base_doctor b on t.doctor = b.id where 1=1 ";
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<'" + endTime + "'";
                }else {
                    sql+="  and t.create_time< to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<'" + endTime + "'";
            }
        }
        if (StringUtils.isNotBlank(code)){
            sql+=" and t.code = '"+code+"'";
        }
        if (StringUtils.isNotBlank(faceName)){
            sql+=" and (t.name like '%"+faceName+"%' or t.code = '"+faceName+"')";
        }
        if (StringUtils.isNotBlank(patient)){
            sql+=" and (a.name like '%"+patient+"%' or t.patient = '"+patient+"')";
        }
        if (StringUtils.isNotBlank(doctor)){
            sql+=" and (b.name like '%"+doctor+"%'or t.doctor = '"+doctor+"')";
        }
        if (StringUtils.isNotBlank(requestKeyWord)){
            sql+=" and t.request like '%"+requestKeyWord+"%'";
        }
        if (StringUtils.isNotBlank(responeKeyWord)){
            sql+=" and t.response like '%"+responeKeyWord+"%'";
        }
        sql+=" order by t.create_time desc";
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
    public MixEnvelop findLoginLog(String startTime, String endTime, String userId,String userName, String openId, String userAgent,String loginType,String opreateStart, String opreateEnd,  Integer page, Integer pageSize) {
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\"," +
                "t.user_id as \"userId\"," +
                "p.name as \"patientName\"," +
                "d.name as \"doctorName\"," +
                "t.user_agent as \"userAgent\"," +
                "t.login_type as \"loginType\"," +
                "t.openid as \"openid\"," ;
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
            }else {
                sql+="  to_char(t.create_time,'yyyy-MM-dd HH24:mi:ss') as \"createTime\",";
            }
        }else{
            sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
        }
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.operate_time, '%Y-%m-%d %H:%i:%s')  as \"operateTime\",";
            }else {
                sql+="  to_char(t.operate_time,'yyyy-MM-dd HH24:mi:ss') as \"operateTime\",";
            }
        }else{
            sql+="date_format(t.operate_time, '%Y-%m-%d %H:%i:%s')  as \"operateTime\",";
        }
        sql+=" a.name as \"patientName\"," +
                "b.name as \"doctorName\"" +
                " from wlyy_http_log t left join base_patient p on t.user_id = p.id " +
                " left join base_doctor d on t.user_id = d.id where 1=1 ";
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<'" + endTime + "'";
                }else {
                    sql+="  and t.create_time< to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<'" + endTime + "'";
            }
        }
        if (StringUtils.isNotBlank(userId)){
            sql+=" and t.user_id = '"+userId+"'";
        }
        if (StringUtils.isNoneBlank(userName)){
            if ("2".equalsIgnoreCase(loginType)){
                sql+=" and d.name like '%"+userName+"%'";
            }else {
                sql+=" and p.name like '%"+userName+"%'";
            }
        }
        if (StringUtils.isNotBlank(loginType)){
            sql+=" and t.login_type ='"+loginType+"'";
        }
        if (StringUtils.isNotBlank(openId)){
            sql+=" and t.openId like '%"+openId+"%'";
        }
        if (StringUtils.isNotBlank(userAgent)){
            sql+=" and t.user_agent like '%"+userAgent+"%'";
        }
        if (StringUtils.isNotBlank(opreateStart)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.operate_time > '"+opreateStart+"'";
                }else {
                    sql+=" and t.operate_time > to_date('" + opreateStart + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.operate_time > '"+opreateStart+"'";
            }
        }
        if (StringUtils.isNotBlank(opreateEnd)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.operate_time<'" + opreateEnd + "'";
                }else {
                    sql+="  and t.operate_time< to_date('" + opreateEnd + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.operate_time<'" + opreateEnd + "'";
            }
        }
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
}

+ 300 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/httplog/service/YlzHttpLogService.java

@ -0,0 +1,300 @@
package com.yihu.jw.hospital.httplog.service;
import com.yihu.jw.entity.hospital.httplog.YlzHttpLogDO;
import com.yihu.jw.hospital.httplog.dao.YlzHttpLogDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
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;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class YlzHttpLogService extends BaseJpaService<YlzHttpLogDO, YlzHttpLogDao> {
    @Autowired
    private YlzHttpLogDao wlyyHttpLogDao;
    @Value("${wechat.id}")
    private String wxId;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Value("${wechat.flag}")
    private boolean flag;
    //保存http日志接口
    public  void  saveHttpLog(String code,String name,String patient,String doctor,String request,String response,String status ){
        YlzHttpLogDO wlyyHttpLogDO = new YlzHttpLogDO();
        wlyyHttpLogDO.setCode(code);
        wlyyHttpLogDO.setName(name);
        wlyyHttpLogDO.setPatient(patient);
        wlyyHttpLogDO.setDoctor(doctor);
        wlyyHttpLogDO.setRequest(request);
        wlyyHttpLogDO.setResponse(response);
        wlyyHttpLogDO.setStatus(status);
        wlyyHttpLogDO.setCreateTime(new Date());
        wlyyHttpLogDao.save(wlyyHttpLogDO);
    }
    public MixEnvelop findLog(String startTime, String endTime, String faceName, String patient, String doctor, Integer page, Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\"," +
                "t.code as \"code\"," +
                "t.name as \"name\"," +
                "t.patient as \"patient\"," +
                "t.doctor as \"doctor\"," +
                "t.request as \"request\"," +
                "t.response as \"response\"," +
                "t.status as \"status\",";
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
            }else {
                sql+="  to_char(t.create_time,'yyyy-MM-dd HH24:mi:ss') as \"createTime\",";
            }
        }else{
            sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
        }
        sql+=" a.name as \"patientName\"," +
                "b.name as \"doctorName\"" +
                " from ylz_http_log t left join base_patient a on t.patient = a.id " +
                " left join base_doctor b on t.doctor = b.id where 1=1 ";
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<'" + endTime + "'";
                }else {
                    sql+="  and t.create_time< to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<'" + endTime + "'";
            }
        }
        if (StringUtils.isNotBlank(faceName)){
            sql+=" and t.name like '%"+faceName+"%'";
        }
        if (StringUtils.isNotBlank(patient)){
            sql+=" and a.name like '%"+patient+"%'";
        }
        if (StringUtils.isNotBlank(doctor)){
            sql+=" and b.name like '%"+doctor+"%'";
        }
        sql+=" order by t.create_time desc ";
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
    public MixEnvelop findWlyyHttpLogInBase(String startTime, String endTime, String code,String faceName, String patient, String doctor,String responeKeyWord,String requestKeyWord, Integer page, Integer pageSize){
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\"," +
                "t.code as \"code\"," +
                "t.name as \"name\"," +
                "t.patient as \"patient\"," +
                "t.doctor as \"doctor\"," +
                "t.request as \"request\"," +
                "t.response as \"response\"," +
                "t.status as \"status\",";
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
            }else {
                sql+="  to_char(t.create_time,'yyyy-MM-dd HH24:mi:ss') as \"createTime\",";
            }
        }else{
            sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
        }
        sql+=" a.name as \"patientName\"," +
                "b.name as \"doctorName\"" +
                " from ylz_http_log t left join base_patient a on t.patient = a.id " +
                " left join base_doctor b on t.doctor = b.id where 1=1 ";
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<'" + endTime + "'";
                }else {
                    sql+="  and t.create_time< to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<'" + endTime + "'";
            }
        }
        if (StringUtils.isNotBlank(code)){
            sql+=" and t.code = '"+code+"'";
        }
        if (StringUtils.isNotBlank(faceName)){
            sql+=" and (t.name like '%"+faceName+"%' or t.code = '"+faceName+"')";
        }
        if (StringUtils.isNotBlank(patient)){
            sql+=" and (a.name like '%"+patient+"%' or t.patient = '"+patient+"')";
        }
        if (StringUtils.isNotBlank(doctor)){
            sql+=" and (b.name like '%"+doctor+"%'or t.doctor = '"+doctor+"')";
        }
        if (StringUtils.isNotBlank(requestKeyWord)){
            sql+=" and t.request like '%"+requestKeyWord+"%'";
        }
        if (StringUtils.isNotBlank(responeKeyWord)){
            sql+=" and t.response like '%"+responeKeyWord+"%'";
        }
        sql+=" order by t.create_time desc";
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
    public MixEnvelop findLoginLog(String startTime, String endTime, String userId,String userName, String openId, String userAgent,String loginType,String opreateStart, String opreateEnd,  Integer page, Integer pageSize) {
        MixEnvelop mixEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\"," +
                "t.user_id as \"userId\"," +
                "p.name as \"patientName\"," +
                "d.name as \"doctorName\"," +
                "t.user_agent as \"userAgent\"," +
                "t.login_type as \"loginType\"," +
                "t.openid as \"openid\"," ;
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
            }else {
                sql+="  to_char(t.create_time,'yyyy-MM-dd HH24:mi:ss') as \"createTime\",";
            }
        }else{
            sql+="date_format(t.create_time, '%Y-%m-%d %H:%i:%s')  as \"createTime\",";
        }
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql+="date_format(t.operate_time, '%Y-%m-%d %H:%i:%s')  as \"operateTime\",";
            }else {
                sql+="  to_char(t.operate_time,'yyyy-MM-dd HH24:mi:ss') as \"operateTime\",";
            }
        }else{
            sql+="date_format(t.operate_time, '%Y-%m-%d %H:%i:%s')  as \"operateTime\",";
        }
        sql+=" a.name as \"patientName\"," +
                "b.name as \"doctorName\"" +
                " from ylz_http_log t left join base_patient p on t.user_id = p.id " +
                " left join base_doctor d on t.user_id = d.id where 1=1 ";
        if (StringUtils.isNotBlank(startTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.create_time > '"+startTime+"'";
                }else {
                    sql+=" and t.create_time > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.create_time > '"+startTime+"'";
            }
        }
        if (StringUtils.isNotBlank(endTime)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.create_time<'" + endTime + "'";
                }else {
                    sql+="  and t.create_time< to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.create_time<'" + endTime + "'";
            }
        }
        if (StringUtils.isNotBlank(userId)){
            sql+=" and t.user_id = '"+userId+"'";
        }
        if (StringUtils.isNoneBlank(userName)){
            if ("2".equalsIgnoreCase(loginType)){
                sql+=" and d.name like '%"+userName+"%'";
            }else {
                sql+=" and p.name like '%"+userName+"%'";
            }
        }
        if (StringUtils.isNotBlank(loginType)){
            sql+=" and t.login_type ='"+loginType+"'";
        }
        if (StringUtils.isNotBlank(openId)){
            sql+=" and t.openId like '%"+openId+"%'";
        }
        if (StringUtils.isNotBlank(userAgent)){
            sql+=" and t.user_agent like '%"+userAgent+"%'";
        }
        if (StringUtils.isNotBlank(opreateStart)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+=" and t.operate_time > '"+opreateStart+"'";
                }else {
                    sql+=" and t.operate_time > to_date('" + opreateStart + "', 'yyyy-mm-dd hh24:mi:ss') ";
                }
            }else{
                sql+=" and t.operate_time > '"+opreateStart+"'";
            }
        }
        if (StringUtils.isNotBlank(opreateEnd)){
            if("xm_ykyy_wx".equals(wxId)){
                if (flag){
                    sql+="  and t.operate_time<'" + opreateEnd + "'";
                }else {
                    sql+="  and t.operate_time< to_date('" + opreateEnd + "','yyyy-mm-dd hh24:mi:ss')";
                }
            }else{
                sql+="  and t.operate_time<'" + opreateEnd + "'";
            }
        }
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        mixEnvelop.setTotalCount(count.intValue());
        mixEnvelop.setDetailModelList(list);
        mixEnvelop.setPageSize(pageSize);
        mixEnvelop.setCurrPage(page);
        return mixEnvelop;
    }
}

+ 2 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/mapping/dao/DoctorMappingDao.java

@ -16,4 +16,6 @@ public interface DoctorMappingDao extends PagingAndSortingRepository<DoctorMappi
    List<DoctorMappingDO> findByOrgCodeAndMappingCode(String orgCode,String mappingCode);
    DoctorMappingDO findByDoctor(String doctor);
    DoctorMappingDO findByIdcard(String idCard);
}

+ 3 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/mapping/dao/PatientMappingDao.java

@ -2,6 +2,7 @@ package com.yihu.jw.hospital.mapping.dao;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
@ -10,9 +11,11 @@ import org.springframework.data.repository.PagingAndSortingRepository;
public interface PatientMappingDao extends PagingAndSortingRepository<PatientMappingDO, String>, JpaSpecificationExecutor<PatientMappingDO> {
    PatientMappingDO findByIdcardAndSource(String idcard,String source);
    @Query("from PatientMappingDO t where t.mappingCode=?1 and t.source=?2")
    PatientMappingDO findByMappingCodeAndSource(String mappingCode,String source);
    PatientMappingDO findByPatient(String patient);
    PatientMappingDO findByMappingCode(String mappingCode);
    PatientMappingDO findByIdcard(String idCard);
}

+ 46 - 27
business/base-service/src/main/java/com/yihu/jw/hospital/mapping/service/PatientMappingService.java

@ -2,20 +2,21 @@ package com.yihu.jw.hospital.mapping.service;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
import com.yihu.jw.hospital.prescription.service.PrescriptionService;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
import net.sf.json.JSONArray;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
@ -24,6 +25,7 @@ import java.util.Date;
 * 互联网医院居民信息映射
 */
@Service
@Transactional
public class PatientMappingService {
    private static final Logger logger = LoggerFactory.getLogger(PatientMappingService.class);
@ -80,13 +82,16 @@ public class PatientMappingService {
    public String findYkyyPatNoByPatient(String patient,boolean demoFlag)throws Exception{
        logger.info("findYkyyPatNoByPatient:"+patient);
        BasePatientDO patientDO = basePatientDao.findById(patient);
        if(patientDO == null){
            return patient;
        }
        logger.info("patientDO:"+patientDO.toString());
        PatientMappingDO patientMappingDO = patientMappingDao.findByIdcardAndSource(patientDO.getIdcard(),"1");
        PatientMedicareCardDO patientMedicareCardDO = patientMedicareCardDao.findByTypeAndPatientCodeAndDel("A_01",patient,"1");
        if(patientMappingDO!=null){
            return patientMappingDO.getMappingCode();
        }
        com.alibaba.fastjson.JSONArray rs = ykyyEntranceService.findHisPatient(patientMedicareCardDO.getCode(),demoFlag);
        com.alibaba.fastjson.JSONArray rs = ykyyEntranceService.findHisPatientBySscAndIdcard(patientMedicareCardDO.getCode(),patientDO.getIdcard(),demoFlag);
        if(rs!=null&&rs.size()>0){
            //获取居民信息
@ -109,33 +114,37 @@ public class PatientMappingService {
        }
    }
    public String findHisPatNoByPatient(String patient)throws Exception{
    public String findHisPatNoByPatient(String patient,String cardNo)throws Exception{
        logger.info("findHisPatNoByPatient:"+patient);
        BasePatientDO patientDO = basePatientDao.findById(patient);
        logger.info("patientDO:"+patientDO.toString());
        PatientMappingDO patientMappingDO = patientMappingDao.findByIdcardAndSource(patientDO.getIdcard(),"1");
        if(patientMappingDO!=null){
            return patientMappingDO.getMappingCode();
        }
        JSONArray rs = entranceService.BS15018(patientDO.getIdcard(),null,demoFlag);
        PatientMappingDO patientMappingDO = patientMappingDao.findByIdcardAndSource(patientDO.getIdcard(),"1");
        if(rs!=null&&rs.size()>0){
            //获取居民信息
            JSONObject json = rs.getJSONObject(0);
            String mappingCode = json.getString("PAT_NO").trim();
            //存储对应映射关系
            PatientMappingDO mappingDO = new PatientMappingDO();
            mappingDO.setSource("1");
            mappingDO.setPatientName(patientDO.getName());
            mappingDO.setPatient(patientDO.getId());
            mappingDO.setMappingCode(mappingCode);
            mappingDO.setCreateTime(new Date());
            mappingDO.setIdcard(patientDO.getIdcard());
            patientMappingDao.save(mappingDO);
            return mappingCode;
            for (int i=0;i<rs.size();i++){
                //获取居民信息
                JSONObject json = rs.getJSONObject(i);
                if (cardNo.equalsIgnoreCase(json.getString("CARD_NO").trim())){
                    String mappingCode = json.getString("PAT_NO").trim();
                    if (patientMappingDO!=null){
                        patientMappingDO.setMappingCode(mappingCode);
                        patientMappingDO = patientMappingDao.save(patientMappingDO);
                    }else {
                        //存储对应映射关系
                        PatientMappingDO mappingDO = new PatientMappingDO();
                        mappingDO.setSource("1");
                        mappingDO.setPatientName(patientDO.getName());
                        mappingDO.setPatient(patientDO.getId());
                        mappingDO.setMappingCode(mappingCode);
                        mappingDO.setCreateTime(new Date());
                        mappingDO.setIdcard(patientDO.getIdcard());
                        patientMappingDO = patientMappingDao.save(mappingDO);
                    }
                }
            }
            return patientMappingDO.getMappingCode();
        }else{
            return null;
        }
@ -146,4 +155,14 @@ public class PatientMappingService {
        PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(code);
        return patientMappingDO;
    }
    public PatientMappingDO findPatientNoByPatientCodeOrIdcard(String code,String idCard){
        if (StringUtils.isNotBlank(code)){
            PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(code);
            return patientMappingDO;
        }else if (StringUtils.isNoneBlank(idCard)){
            PatientMappingDO patientMappingDO =  patientMappingDao.findByIdcard(idCard);
            return patientMappingDO;
        }
        return null;
    }
}

+ 28 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/BaseBannerDao.java

@ -0,0 +1,28 @@
package com.yihu.jw.hospital.message.dao;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import org.hibernate.annotations.SQLInsert;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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.Map;
/**
 * @author wangzhinan
 * @vsrsion 2.0
 * Created at 2020.07.08
 */
public interface BaseBannerDao extends PagingAndSortingRepository<BaseBannerDO, String>, JpaSpecificationExecutor<BaseBannerDO> {
    @Query( value = "select max(t.is_sort) AS \"zuida\" from base_banner t",nativeQuery = true)
    Integer getMaxSort();
    @Query( value = "select min(t.is_sort) AS \"zuixiao\" from base_banner t",nativeQuery = true)
    Integer getMinSort();
}

+ 28 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/BaseBannerDoctorDao.java

@ -0,0 +1,28 @@
package com.yihu.jw.hospital.message.dao;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDoctorDO;
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.Map;
/**
 * @author wangzhinan
 * @vsrsion 2.0
 * Created at 2020.07.08
 */
public interface BaseBannerDoctorDao extends PagingAndSortingRepository<BaseBannerDoctorDO, String>, JpaSpecificationExecutor<BaseBannerDoctorDO> {
    //获取医生获得锦旗总量的接口
    @Query( value = "SELECT COUNT(1) AS \"total\"  FROM base_banner_doctor a LEFT JOIN base_banner b on a.banner_id= b.id where a.doctor = ?1",nativeQuery = true)
    Integer getTotalBannerCount(String doctor);
    @Query( value = "SELECT * from base_banner_doctor t where t.doctor = ?1 and t.patient_id =?2 and t.relation_code =?3" ,nativeQuery = true)
    List<BaseBannerDoctorDO> getBanners(String doctor,String patientId,String relationCode);
    @Query("from BaseBannerDoctorDO t where t.patientId =?1 order by t.createTime desc ")
    List<BaseBannerDoctorDO> getBannersBypatients(String patientId);
    @Query("from BaseBannerDoctorDO t where t.patientId =?1 and t.doctor =?2 order by t.createTime desc ")
    public abstract List<BaseBannerDoctorDO> getBannersBypatients(String paramString1, String paramString2);
}

+ 28 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/BaseUserMessageDao.java

@ -0,0 +1,28 @@
package com.yihu.jw.hospital.message.dao;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import com.yihu.jw.entity.hospital.message.BaseUserMessageDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author wangzhinan
 * @vsrsion 2.0
 * Created at 2020.07.08
 */
public interface BaseUserMessageDao extends PagingAndSortingRepository<BaseUserMessageDO, String>, JpaSpecificationExecutor<BaseUserMessageDO> {
    @Query(value = "select count(1) AS \"all\" from base_user_message t where t.receiver = ?1 order by t.update_time desc ",nativeQuery = true)
    Integer getAllMessageTotalCount(String doctor);
    @Query(value = "select count(1) AS \"notRead\" from base_user_message t where t.receiver = ?1 and t.is_read = 0 order by t.update_time desc ",nativeQuery = true)
    Integer getMessageNotReadCount(String doctor);
    @Query(value = "select *  from base_user_message t where t.receiver = ?1 and t.is_read = 0 order by t.update_time desc",nativeQuery = true)
    List<BaseUserMessageDO> getMessageNotReadNotPage(String doctor);
    @Query("from BaseUserMessageDO p where p.receiver=?1 and p.sender=?2 order by p.createTime desc ")
    public abstract List<BaseUserMessageDO> getMessageByPatientAndDoctor(String paramString1, String paramString2);
}

+ 14 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/BaseUserMsgContentDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.hospital.message.dao;
import com.yihu.jw.entity.hospital.message.BaseUserMessageDO;
import com.yihu.jw.entity.hospital.message.BaseUserMsgContentDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseUserMsgContentDao extends PagingAndSortingRepository<BaseUserMsgContentDO, String>, JpaSpecificationExecutor<BaseUserMsgContentDO> {
    @Query(value = "select *  from base_user_msg_content t where t.base_user_msg_id = ?1 order by t.update_time desc ",nativeQuery = true)
    List<BaseUserMsgContentDO> getContentListByID(String base_user_msg_id);
}

+ 11 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/MsgContentDao.java

@ -0,0 +1,11 @@
package com.yihu.jw.hospital.message.dao;
import com.yihu.jw.entity.hospital.message.BaseUserMessageDO;
import com.yihu.jw.entity.hospital.message.BaseUserMsgContentDO;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface MsgContentDao extends JpaRepository<BaseUserMessageDO,Integer> {
    List<BaseUserMessageDO> findByRelationCode(String relationcode);
}

+ 50 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/SystemMessageDao.java

@ -1,13 +1,17 @@
package com.yihu.jw.hospital.message.dao;
import com.yihu.jw.entity.care.device.BaseSleepPlanDetail;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import org.hibernate.annotations.SQLUpdate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
@ -21,5 +25,51 @@ public interface SystemMessageDao extends PagingAndSortingRepository<SystemMessa
    @Query("from SystemMessageDO p where p.id = ?1")
    SystemMessageDO queryById(String id);
    @Modifying
    @Query("delete from SystemMessageDO a   where a.receiver = ?1 and a.relationCode = ?2 and a.type ='407'")
    int orderMessageDel(String doctor, String orderId);
    List<SystemMessageDO> queryByRelationCodeAndTypeIn(String relationCode,String[] type);
    //获取资质申请审核有效的未结束已发送的消息
    @Query("select a from SystemMessageDO a where a.type in ('401','408') and a.del='1' and a.over='1' and a.relationCode = ?1  ")
    List<SystemMessageDO> findMessageByRelationCode(String relationCode);
    @Modifying
    @Query("delete from SystemMessageDO a  where a.receiver = ?1 and a.relationCode = ?2 and a.type =?3")
    int orderMessageDelByType(String doctor, String orderId,String type);
    SystemMessageDO findByRelationCodeAndReceiver(String relationCode,String receiver);
    @Query("update SystemMessageDO a set a.isRead=0,a.over = '0' where a.id = ?1")
    @Modifying
    Integer setSpecialistById(String id);
    @Query("update SystemMessageDO a set a.isRead = 0 where a.id = ?1" )
    @Modifying
    Integer setSpecialistReadById(String id);
    @Query("update SystemMessageDO a set a.isRead = 0,a.over = '0' where a.receiver = ?1 and a.type = ?2 and (a.createTime > ?3 and a.createTime< ?4)")
    @Modifying
    void setMessageOverByType(String doctor, Integer type, Date start, Date end);
    @Query("select a from SystemMessageDO a where a.receiver=?1 and a.type=?2 and  a.del='1'")
    List<SystemMessageDO> getByReceiverAndType(String doctor,String type);
    @Query("select a from SystemMessageDO a where  a.type=?1 and  a.del='1'")
    Page<SystemMessageDO> getByType(String type, Pageable pageRequest);
    @Modifying
    @Query("update SystemMessageDO a set a.del=0 where a.id in (?1)")
    Integer delMessage(String[] ids);
    @Modifying
    @Query("DELETE FROM SystemMessageDO where type='43' and relationCode in(?1) ")
    void delMessageByRelationCode(List<String> relationCode);
    @Modifying
    @Query("update SystemMessageDO m set m.isRead=1 ,m.over=0,m.data=?3 where m.type=?1 and m.relationCode=?2 ")
    void readByTypeAndRelationCode(String type,String relationCode,String data);
}

ファイルの差分が大きいため隠しています
+ 424 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/service/BaseBannerDoctorService.java


+ 278 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/service/BaseBannerService.java

@ -0,0 +1,278 @@
package com.yihu.jw.hospital.message.service;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDoctorDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.BaseBannerDao;
import com.yihu.jw.hospital.message.dao.BaseBannerDoctorDao;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
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.StringUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class BaseBannerService extends BaseJpaService<BaseBannerDO, BaseBannerDao> {
    @Autowired
    private BaseBannerDao baseBannerDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private BaseBannerDoctorDao baseBannerDoctorDao;
    /**
     * 医生锦旗管理查询
     * @param
     * @return
     * @throws Exception
     */
   /* public List<BaseBannerDO> queryBannerByNameAndStatus(String name, String status, Integer page, Integer pageSize){
        Integer queryStatus =0;
        Integer pageNo = (page-1)*pageSize;
        Pageable pageable = new PageRequest(page,pageSize);
        if (StringUtils.isNotEmpty(status)) {
            queryStatus = Integer.valueOf(status);
            List<BaseBannerDO> result = baseBannerDao.queryByNameAndStatus(name,queryStatus,pageNo,pageSize);
            return result;
      }else {
            List<BaseBannerDO> result = baseBannerDao.queryByName(name,pageNo,pageSize);
            return result;
        }
    }*/
    public Envelop queryBannerByNameAndStatus(String name, String status, Integer page, Integer pageSize){
        Map<String,Object> params = new HashedMap();
        String sqlcount = dealSql(name,status,true);
        String sql  = dealSql(name,status,false);
        if (StringUtils.isNotEmpty(status)){
            params.put("status",status);
        }
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount,params);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,params,page,pageSize);
        for (Map<String,Object> map:list){
            String createTime= map.get("create_time").toString();
            String updateTime = map.get("update_time").toString();
            map.put("create_time",DateUtil.dateToStrLong(DateUtil.strToDateLong(createTime)));
            map.put("update_time",DateUtil.dateToStrLong(DateUtil.strToDateLong(updateTime)));
            String bannerId = map.get("id").toString();
            String sqlId = "select t.id AS \"id\" from base_banner_doctor t where t.banner_id = '"+bannerId+"'";
            List<Map<String,Object>> listID=hibenateUtils.createSQLQuery(sqlId,0,1);
            String bannerGiveId ="";
            if (listID.size()>0){
                bannerGiveId = listID.get(0).get("id").toString();
            }
            BaseBannerDoctorDO baseBannerDoctorDO = baseBannerDoctorDao.findOne(bannerGiveId);
            if (null!=baseBannerDoctorDO){
                //1不能删除
                map.put("deleteFlag",1);
            }else {
                //2可以删除
                map.put("deleteFlag",2);
            }
        }
        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, pageSize, count);
    }
    private String dealSql(String name, String status,Boolean isCount){
        StringBuffer sql = new StringBuffer();
        if (isCount) {
            sql.append("SELECT COUNT(1) AS \"total\" FROM (");
        }
        sql.append("select p.id as \"id\"," +
                "p.saas_id as \"saas_id\"," +
                "p.name as \"name\"," +
                "p.description as \"description\"," +
                "p.img as \"img\", p.is_sort as \"sort\",p.status as \"status\",p.create_time as \"create_time\",p.create_user as \"create_user\"," +
                "p.create_user_name as \"create_user_name\"," +
                "p.update_time as \"update_time\"," +
                "p.update_user as \"update_user\",p.update_user_name as \"update_user_name\" from base_banner p where 1=1");
        if(StringUtils.isNotEmpty(name)){
            sql.append(" and p.name like '%"+name+"%'");
        }if (StringUtils.isNotEmpty(status)){
            sql.append(" and p.status =:status");
        }
        sql.append(" order by  p.is_sort desc ");
        if (isCount) {
            sql.append(") t");
        }
        return sql.toString();
    }
    /**
     * 医生锦旗新增
     * @param
     * @return
     * @throws Exception
     */
    public BaseBannerDO creatBanner(BaseBannerDO baseBannerDO){
        String sql = "select max(is_sort) as sort from base_banner";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        Map<String,Object> map = list.get(0);
        int sort = 0;
        if (null!=map.get("sort")){
            if(null!=map){
                sort = Integer.valueOf(map.get("sort").toString());
            }
        }
        baseBannerDO.setSort(sort+1);
        baseBannerDO.setUpdateTime(new Date());
        baseBannerDO.setCreateTime(new Date());
        BaseBannerDO result =  baseBannerDao.save(baseBannerDO);
        return result;
    }
    /**
     * 医生锦旗更新
     * @param
     * @return
     * @throws Exception
     */
    public BaseBannerDO updateBanner(String id,String name,String img,String status,String updateUser,String updateUserName,String description){
        BaseBannerDO bannerDO = baseBannerDao.findOne(id);
        if (null == bannerDO){
            return null;
        }
        if (!StringUtil.isEmpty(name)){
            bannerDO.setName(name);
            bannerDO.setUpdateTime(new Date());
        }
        if (!StringUtil.isEmpty(img)){
            bannerDO.setImg(img);
        }
        if (!StringUtil.isEmpty(updateUser)){
            bannerDO.setUpdateUser(updateUser);
        }
        if (!StringUtil.isEmpty(updateUserName)){
            bannerDO.setUpdateUser(updateUserName);
        }
        if (!StringUtil.isEmpty(status)){
            bannerDO.setStatus(Integer.valueOf(status));
        }
        if (!StringUtil.isEmpty(description)){
            bannerDO.setDescription(description);
        }
        baseBannerDao.save(bannerDO);
        return bannerDO;
    }
    /**
     * 医生锦旗删除
     * @param
     * @return
     * @throws Exception
     */
    public Boolean deleteBanner(String id){
        BaseBannerDO bannerDO = baseBannerDao.findOne(id);
        if (null == bannerDO){
            return false;
        }
        baseBannerDao.delete(id);
        return true;
    }
    /**
     * 医生锦旗上移
     * @param
     * @return
     * @throws Exception
     */
    public BaseBannerDO upBanner(String id) throws Exception{
        BaseBannerDO bannerDO = baseBannerDao.findOne(id);
        int maxSort = baseBannerDao.getMaxSort();
        int sort = 0;
        if(null!=bannerDO){
            sort = bannerDO.getSort();
        }
        if (maxSort==sort){
            throw new Exception("不能上移");
        }
        String sql = "select t.id AS \"id\" from base_banner t where t.is_sort > "+sort+" order by t.is_sort asc ";
        System.out.println(sql);
        List<Map<String,Object>> list=hibenateUtils.createSQLQuery(sql,1,1);
        BaseBannerDO upPrevious = new BaseBannerDO();
        if (list.size()>0){
            String prviousBannerId = list.get(0).get("id").toString();
            upPrevious =baseBannerDao.findOne(prviousBannerId);
        }
        //BaseBannerDO upPrevious = baseBannerDao.upBanner(sort);
        //交换sort值
        bannerDO.setSort(upPrevious.getSort());
        upPrevious.setSort(sort);
        baseBannerDao.save(bannerDO);
        baseBannerDao.save(upPrevious);
        return bannerDO;
    }
    /**
     * 医生锦旗下移
     * @param
     * @return
     * @throws Exception
     */
    public BaseBannerDO downBanner(String id) throws Exception{
        //当前banner
        BaseBannerDO bannerDO = baseBannerDao.findOne(id);
        int minSort = baseBannerDao.getMinSort();
        int sort = 0;
        if(null!=bannerDO){
            sort = bannerDO.getSort();
        }
        if (minSort==sort){
            throw new Exception("不能下移");
        }
        String sql = " select id AS \"id\" from base_banner where is_sort < "+sort+" order by is_sort desc ";
        List<Map<String,Object>> list=hibenateUtils.createSQLQuery(sql,1,1);
        BaseBannerDO downPrevious = new BaseBannerDO();
        if (list.size()>0){
            String prviousBannerId = list.get(0).get("id").toString();
            downPrevious =baseBannerDao.findOne(prviousBannerId);
        }
        //获取的下一条banner
        //BaseBannerDO downPrevious = baseBannerDao.downBanner(sort);
        //交换sort值
        bannerDO.setSort(downPrevious.getSort());
        downPrevious.setSort(sort);
        baseBannerDao.save(bannerDO);
        baseBannerDao.save(downPrevious);
        return bannerDO;
    }
    /**
     * 锦旗开关
     * @param
     * @return
     * @throws Exception
     */
    public BaseBannerDO onOff(String id ,String status){
        BaseBannerDO bannerDO = baseBannerDao.findOne(id);
        if(null!=bannerDO){
            bannerDO.setStatus(Integer.valueOf(status));
        }
        baseBannerDao.save(bannerDO);
        return bannerDO;
    }
}

+ 612 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/service/BaseUserMsgService.java

@ -0,0 +1,612 @@
package com.yihu.jw.hospital.message.service;
import com.alibaba.fastjson.JSONObject;
import com.google.j2objc.annotations.AutoreleasePool;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.score.BaseEvaluateDO;
import com.yihu.jw.entity.base.score.BaseEvaluateScoreDO;
import com.yihu.jw.entity.base.words.BaseSensitiveDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.httplog.BaseOperateLogDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDoctorDO;
import com.yihu.jw.entity.hospital.message.BaseUserMessageDO;
import com.yihu.jw.entity.hospital.message.BaseUserMsgContentDO;
import com.yihu.jw.evaluate.score.dao.BaseEvaluateDao;
import com.yihu.jw.evaluate.score.dao.BaseEvaluateScoreDao;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.httplog.dao.BaseOperateLogDao;
import com.yihu.jw.hospital.message.dao.BaseBannerDao;
import com.yihu.jw.hospital.message.dao.BaseBannerDoctorDao;
import com.yihu.jw.hospital.message.dao.BaseUserMessageDao;
import com.yihu.jw.hospital.message.dao.BaseUserMsgContentDao;
import com.yihu.jw.hospital.prescription.dao.BaseSensitiveDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.rm.base.BaseRequestMapping;
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.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.mysql.query.URLQueryParser;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.hibernate.dialect.Ingres9Dialect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.jpa.provider.HibernateUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.swing.plaf.PanelUI;
import javax.transaction.Transactional;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class BaseUserMsgService extends BaseJpaService<BaseUserMessageDO, BaseUserMessageDao> {
    @Autowired
    private BaseUserMessageDao baseUserMessageDao;
    @Autowired
    private BaseUserMsgContentDao baseUserMsgContentDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private BaseEvaluateScoreDao baseEvaluateScoreDao;
    @Autowired
    private BaseEvaluateDao baseEvaluateDao;
    @Autowired
    private BasePatientDao basePatientDao;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private BaseBannerDoctorDao baseBannerDoctorDao;
    @Autowired
    private BaseBannerDao bannerDao;
    @Autowired
    private BaseSensitiveDao baseSensitiveDao;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private BaseBannerDoctorService baseBannerDoctorService;
    @Autowired
    private BaseDoctorHospitalDao baseDoctorHospitalDao;
    @Autowired
    private BaseOperateLogDao baseOperateLogDao;
    @Value("${wechat.id}")
    private String wxId;
    @Value("${wechat.flag}")
    private boolean flag;
    public ObjEnvelop leaveMessage(String content, String reciverId, String reciverName, String senderId, Integer type, String key, String value)
            throws IOException {
        BaseUserMessageDO baseUserMessageDO = new BaseUserMessageDO();
        ObjEnvelop objEnvelop = new ObjEnvelop();
        boolean checkTimeOut = checkGiveTimeOut(senderId, reciverId);
        if ((StringUtils.isNotBlank(key)) && (StringUtils.isNotBlank(value))) {
            if (this.baseBannerDoctorService.verifyCaptcha(key, value))
            {
                checkTimeOut = true;
            }
            else
            {
                objEnvelop.setMessage("验证码错误");
                objEnvelop.setStatus(Integer.valueOf(78));
                return objEnvelop;
            }
        }
        boolean checkTimes = checkGiveTimes(senderId, reciverId);
        if (checkTimes)
        {
            if (checkTimeOut)
            {
                BasePatientDO patientDO = this.basePatientDao.findById(senderId);
                String senderName = null;
                if (null != patientDO) {
                    senderName = patientDO.getName();
                }
                String relationCode = UUID.randomUUID().toString();
                baseUserMessageDO.setContent(content);
                baseUserMessageDO.setSender(senderId);
                baseUserMessageDO.setSenderName(senderName);
                baseUserMessageDO.setReceiver(reciverId);
                baseUserMessageDO.setReceiverName(reciverName);
                baseUserMessageDO.setRelationCode(relationCode);
                baseUserMessageDO.setRelationName("留言");
                baseUserMessageDO.setRelationType(Integer.valueOf(1));
                baseUserMessageDO.setStatus(Integer.valueOf(1));
                baseUserMessageDO.setDel(Integer.valueOf(1));
                baseUserMessageDO.setType(type);
                baseUserMessageDO.setIsRead(Integer.valueOf(0));
                this.baseUserMessageDao.save(baseUserMessageDO);
                objEnvelop.setStatus(Integer.valueOf(200));
                objEnvelop.setMessage("留言成功");
            }
            else
            {
                objEnvelop.setMessage("生成验证码");
                objEnvelop.setStatus(200);
                objEnvelop.setObj(baseBannerDoctorService.generateCaptcha());
                return objEnvelop;
            }
        }
        else
        {
            objEnvelop.setMessage("当天留言已达规定次数");
            objEnvelop.setStatus(Integer.valueOf(77));
            return objEnvelop;
        }
        return objEnvelop;
    }
    //回复留言接口
    @Transactional
    public void responseMessage(String contentId,String content, String reciverId, String senderId,Integer isDoctor) {
        BaseUserMessageDO baseUserMessageDOS = baseUserMessageDao.findOne(contentId);
        if(null!=baseUserMessageDOS&&1==isDoctor){
            baseUserMessageDOS.setStatus(2);
            baseUserMessageDOS.setIsRead(1);
        }
        baseUserMessageDao.save(baseUserMessageDOS);
        BaseUserMsgContentDO baseUserMsgContentDO =new BaseUserMsgContentDO();
        String senderName = null;
        if(1==isDoctor){
            BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(senderId);
            BasePatientDO reciver= basePatientDao.findById(reciverId);
            if (null!=reciver){
                baseUserMsgContentDO.setReceiverName(reciver.getName());
            }
            if(null!=baseDoctorDO){
                senderName = baseDoctorDO.getName();
            }
            baseUserMsgContentDO.setIsDoctor(1);
        }else {
            BasePatientDO patientDO= basePatientDao.findById(senderId);
            BaseDoctorDO reciver = baseDoctorDao.findById(reciverId);
            if(null!=reciver){
                baseUserMsgContentDO.setReceiverName(reciver.getName());
            }
            if(null!=patientDO){
                senderName = patientDO.getName();
            }
            baseUserMsgContentDO.setIsDoctor(0);
        }
        baseUserMsgContentDO.setBaseUserMsgId(contentId);
        baseUserMsgContentDO.setContent(content);
        baseUserMsgContentDO.setSender(senderId);
        baseUserMsgContentDO.setSenderName(senderName);
        baseUserMsgContentDO.setReceiver(reciverId);
        baseUserMsgContentDO.setDel(1);
        baseUserMsgContentDO.setStatus(1);
        baseUserMsgContentDao.save(baseUserMsgContentDO);
    }
    //修改留言显示
    @Transactional
    public BaseUserMessageDO updateIsShow(String id,Integer isShow) {
        BaseUserMessageDO baseUserMessageDOS = baseUserMessageDao.findOne(id);
        baseUserMessageDOS.setIsShow(isShow);
        return baseUserMessageDao.save(baseUserMessageDOS);
    }
    //评论留言展示
    public Envelop getMessage(String doctor, String showAll, String showAllType, String beginTime, String endTime,String patient, Integer page, Integer pageSize,Integer isShow) {
        StringBuffer sql = new StringBuffer();
        Map<String,Object> params = new HashedMap();
        sql.append("select t.id as \"id\" ,t.content as \"content\",t.type as \"type\"," +
                "t.sender as \"sender\",t.sender_name as \"sender_name\",t.receiver as \"receiver\"," +
                "t.receiver_name as \"receiver_name\",t.relation_type as \"relation_type\"," +
                "t.relation_code as \"relation_code\",t.relation_name as \"relation_name\",t.status as \"status\",t.is_show as \"isShow\",t.update_time as \"update_time\"");
        /*if("xm_ykyy_wx".equals(wxId)){
            flag = true;
            if (flag){
               sql.append(",date_format(t.update_time,'%Y-%m-%d %H:%i:%S' )  AS \"update_time\"");
            }else {
                sql.append(",to_char(t.update_time,'YYYY-MM-DD hh24:mi:ss')  AS \"update_time\"");
            }
        }else{
            sql.append("date_format(t.update_time,'%Y-%m-%d %H:%i:%S' )  AS \"update_time\"");
        }*/
        sql.append(" from base_user_message t where 1 = 1 and t.del = 1");
        if (StringUtils.isNotEmpty(doctor)) {
            sql.append(" and t.receiver = '" + doctor + "'");
        }
        if (StringUtils.isNotEmpty(patient)) {
            sql.append(" and t.sender = '" + patient + "'");
        }
        if (StringUtils.isNotEmpty(showAll)) {
            sql.append(" and t.status = " + showAll);
        }
        if (StringUtils.isNotEmpty(showAllType)) {
            sql.append(" and t.relation_type = " + showAllType);
        }
        if (isShow!=null) {
            sql.append(" and t.is_show = " + isShow);
        }
        if (StringUtils.isNotEmpty(beginTime)) {
            //sql.append(" and t.update_time > '" + beginTime+"'");//DateUtil.stringToDate(beginTime,"yyyy-MM-dd HH:mm:ss")
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    sql.append( " and t.update_time >= str_to_date('" + beginTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                }else {
                    sql.append(  " and t.update_time >= to_date('" + beginTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                }
            } else {
                sql.append( " AND t.update_time >='" + beginTime + " 00:00:00'");
            }
        }
        if (StringUtils.isNotEmpty(endTime)) {
            //sql.append(" and t.update_time < '" + endTime+"'");//DateUtil.stringToDate(endTime,"yyyy-MM-dd HH:mm:ss")
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    sql.append( " and t.update_time <= str_to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')");
                }else {
                    sql.append(  " and t.update_time <= to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')");
                }
            } else {
                sql.append( " AND t.update_time <='" + endTime + " 23:59:59'");
            }
        }
        sql.append(" ORDER BY t.update_time Desc");
        String sqlcount = "SELECT COUNT(1) AS \"total\" FROM ("+sql.toString()+") q";
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlcount,params);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        System.out.println(sql.toString());
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql.toString(),params,page,pageSize);
        List<Map<String, Object>> returnList = new ArrayList<>();
        for (Map<String, Object> map : list) {
            Map<String,Object> returnMap = new HashMap<>();
            String relationCode = null==map.get("relation_code")?"":map.get("relation_code").toString();
            String id =  null==map.get("id")?"":map.get("id").toString();
            String patientID = null==map.get("sender")?"":map.get("sender").toString();
            BaseUserMessageDO baseUserMsgDO =new BaseUserMessageDO();
            baseUserMsgDO.setId(id);
            if (map.get("type")!=null){
                baseUserMsgDO.setType(Integer.valueOf(map.get("type").toString()));
            }
            String reciveDoctor=null==map.get("receiver")?"":map.get("receiver").toString();
            List<BaseDoctorHospitalDO> baseDoctorHospitalDOS = baseDoctorHospitalDao.findByDoctorCode(reciveDoctor);
            if (baseDoctorHospitalDOS!=null&&baseDoctorHospitalDOS.size()>0){
                returnMap.put("deptName",baseDoctorHospitalDOS.get(0).getDeptName());
            }
            BaseDoctorDO baseDoctorDO=baseDoctorDao.findById(reciveDoctor);
            if (baseDoctorDO!=null){
                returnMap.put("doctorName",baseDoctorDO.getName());
                returnMap.put("doctorPhoto",baseDoctorDO.getPhoto());
                returnMap.put("jobtitleName",baseDoctorDO.getJobTitleName());
            }
            baseUserMsgDO.setReceiver(null==map.get("receiver")?"":map.get("receiver").toString());
            baseUserMsgDO.setReceiverName(null==map.get("receiver_name")?"":map.get("receiver_name").toString());
            baseUserMsgDO.setSender(null==map.get("sender")?"":map.get("sender").toString());
            List<BaseSensitiveDO> baseSensitiveDOS = baseSensitiveDao.getSensitiveWords();
            String content = map.get("content")==null?"":map.get("content").toString();
            for (BaseSensitiveDO sensitiveDO:baseSensitiveDOS){
                if (StringUtils.isNotBlank(content)){
                    if (content.contains(sensitiveDO.getSensitiveWord())){
                        content = content.replace(sensitiveDO.getSensitiveWord(),"****");
                    }
                }
            }
            baseUserMsgDO.setIsShow(null==map.get("isShow")?0:Integer.parseInt(map.get("isShow").toString()));
            baseUserMsgDO.setContent(content);
            baseUserMsgDO.setRelationCode(null==map.get("relation_code")?"":map.get("relation_code").toString());
            baseUserMsgDO.setRelationType(null==map.get("relation_type")?0:Integer.valueOf(map.get("relation_type").toString()));
            baseUserMsgDO.setRelationName(null==map.get("relation_name")?"":map.get("relation_name").toString());
            baseUserMsgDO.setStatus(null==map.get("status")?0:Integer.valueOf(map.get("status").toString()));
            BasePatientDO patientDO = basePatientDao.findById(null==map.get("sender")?"":map.get("sender").toString());
            List<BaseBannerDoctorDO> ba =  baseBannerDoctorDao.getBanners(baseUserMsgDO.getReceiver(),baseUserMsgDO.getSender(),baseUserMsgDO.getRelationCode());
            if(ba.size()>0){
                List<BaseBannerDO> bannerLits= new ArrayList<>();
                for (BaseBannerDoctorDO bannerDoctorDO:ba){
                    BaseBannerDO bannerDO = bannerDao.findOne(bannerDoctorDO.getBannerId());
                    bannerLits.add(bannerDO);
                    baseUserMsgDO.setBaseBannerDOS(bannerLits);
                }
            }
                //baseUserMsgDO.setBannerList(ba);
            String icon = null;
            if (null!=patientDO){
                icon = patientDO.getPhoto();
            }
            List<BaseUserMsgContentDO> contentlist=baseUserMsgContentDao.getContentListByID(id);
            if(contentlist.size()>0){
                for (BaseUserMsgContentDO dealList :contentlist){
                    if (null!=baseUserMsgDO.getType()&&baseUserMsgDO.getType()==2){
                        dealList.setSenderName(patientID==dealList.getSender()?dealList.getSenderName().substring(0,1)+"**":dealList.getSenderName());
                        dealList.setReceiverName(patientID==dealList.getReceiver()?dealList.getReceiverName().substring(0,1)+"**":dealList.getReceiverName());
                    }
                    String respongseContent = dealList.getContent();
                    for (BaseSensitiveDO sensitiveDO:baseSensitiveDOS){
                        if (StringUtils.isNotBlank(content)){
                            if (respongseContent.contains(sensitiveDO.getSensitiveWord())){
                                respongseContent = respongseContent.replace(sensitiveDO.getSensitiveWord(),"****");
                                dealList.setContent(respongseContent);
                            }
                        }
                    }
                }
            }
            baseUserMsgDO.setMsgList(contentlist);
            String updateTime = map.get("update_time").toString();
            baseUserMsgDO.setUpdateTime(DateUtil.strToDateLong(updateTime));
            //map.put("update_time",DateUtil.dateToStrLong(DateUtil.strToDateLong(updateTime)));
            List<BaseEvaluateDO> baseEvaluateDO=baseEvaluateDao.findByRelationCode(relationCode);
            BaseEvaluateScoreDO scoreList =null;
            if (baseEvaluateDO.size()>0){
                String findRC=baseEvaluateDO.get(0).getRelationCode();
                scoreList= baseEvaluateScoreDao.findOne(relationCode);
                if(null!=scoreList){
                    returnMap.put("everangScore",scoreList);
                    returnMap.put("scoreList",baseEvaluateDO);
                }
            }
            if(scoreList!=null){
                baseUserMsgDO.setSenderName(scoreList.getType()==1?map.get("sender_name").toString():map.get("sender_name").toString().substring(0,1)+"**");
            }else {
                baseUserMsgDO.setSenderName(null==map.get("sender_name")?"":map.get("sender_name").toString());
            }if(null!=baseUserMsgDO.getType()&&baseUserMsgDO.getType()==2){
                baseUserMsgDO.setSenderName(null==map.get("sender_name")?"":map.get("sender_name").toString().substring(0,1)+"**");
            }
            returnMap.put("contentList",baseUserMsgDO);
            returnMap.put("patientIcon",icon);
            returnList.add(returnMap);
        }
        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, returnList, page, pageSize, count);
    }
    //获取单条评论详细信息
    public List<Map<String,Object>> getSingle(String id){
        BaseUserMessageDO baseUserMessageDO=baseUserMessageDao.findOne(id);
        String patientId= baseUserMessageDO.getSender();
        Integer type = baseUserMessageDO.getType();
        List<BaseUserMsgContentDO> contentlist=baseUserMsgContentDao.getContentListByID(id);
        if (null!=type&&type==2){
            for (BaseUserMsgContentDO baseUserMsgContentDO:contentlist){
                baseUserMsgContentDO.setSenderName(baseUserMsgContentDO.getSender()==patientId?baseUserMsgContentDO.getSenderName().substring(0,1)+"**":baseUserMsgContentDO.getSenderName());
                baseUserMsgContentDO.setReceiverName(baseUserMsgContentDO.getReceiver()==patientId?baseUserMsgContentDO.getReceiverName().substring(0,1)+"**":baseUserMsgContentDO.getReceiverName());
            }
        }
        String relationCode= baseUserMessageDO.getRelationCode();
        List<Map<String,Object>> returnResult = new ArrayList<>();
        //List<Map<String,Object>> scoreList = this.getListByRelationCode(relationCode);
        Map<String,Object> map = new HashMap<>();
        BaseEvaluateScoreDO scoreList = new BaseEvaluateScoreDO();
        List<BaseEvaluateDO> baseEvaluateDO=baseEvaluateDao.findByRelationCode(relationCode);
        if (baseEvaluateDO.size()>0){
            String findRC=baseEvaluateDO.get(0).getRelationCode();
            scoreList= baseEvaluateScoreDao.findOne(relationCode);
            if(null!=scoreList){
                map.put("everangScore",scoreList);
                map.put("scoreList",baseEvaluateDO);
            }
        }
        map.put("scoreList",scoreList);
        map.put("sender",baseUserMessageDO.getSender());
        if (null!=type&&type==2){
            map.put("senderName",baseUserMessageDO.getSenderName().substring(0,1)+"**");
        }else {
            map.put("senderName",baseUserMessageDO.getSenderName());
        }
        map.put("content",baseUserMessageDO.getContent());
        map.put("receiver",baseUserMessageDO.getReceiver());
        map.put("receiverName",baseUserMessageDO.getReceiverName());
        map.put("relationCode",baseUserMessageDO.getRelationCode());
        map.put("relationType",baseUserMessageDO.getRelationType());
        map.put("status",baseUserMessageDO.getStatus());
        map.put("updateTime",DateUtil.dateToStrLong(baseUserMessageDO.getUpdateTime()));
        map.put("relationName",baseUserMessageDO.getRelationName());
        map.put("contentlist",contentlist);
        returnResult.add(map);
        return returnResult;
    }
    //专家咨询留言
    public void expertMessage(String content, String reciverId, String reciverName, String senderId, String senderName, String relationCode) {
        BaseUserMessageDO baseUserMessageDO = new BaseUserMessageDO();
        baseUserMessageDO.setContent(content);
        baseUserMessageDO.setSender(senderId);
        baseUserMessageDO.setSenderName(senderName);
        baseUserMessageDO.setReceiver(reciverId);
        baseUserMessageDO.setReceiverName(reciverName);
        baseUserMessageDO.setRelationCode(relationCode);
        baseUserMessageDO.setRelationName("专家咨询");
        baseUserMessageDO.setRelationType(3);
        baseUserMessageDO.setStatus(1);
        baseUserMessageDO.setDel(1);
        baseUserMessageDao.save(baseUserMessageDO);
    }
    //在线复诊留言
    public void onlineVisitMessage(String content, String reciverId, String reciverName, String senderId, String senderName, String relationCode) {
        BaseUserMessageDO baseUserMessageDO = new BaseUserMessageDO();
        baseUserMessageDO.setContent(content);
        baseUserMessageDO.setSender(senderId);
        baseUserMessageDO.setSenderName(senderName);
        baseUserMessageDO.setReceiver(reciverId);
        baseUserMessageDO.setReceiverName(reciverName);
        baseUserMessageDO.setRelationCode(relationCode);
        baseUserMessageDO.setRelationName("在线复诊");
        baseUserMessageDO.setRelationType(4);
        baseUserMessageDO.setStatus(1);
        baseUserMessageDO.setDel(1);
        baseUserMessageDao.save(baseUserMessageDO);
    }
    //评论回复展示
    public Envelop showReply(String relationCode, Integer page, Integer pageSize){
        String sql = dealSql(relationCode,false);
        String sqlCount = dealSql(relationCode,true);
        Map<String,Object> params = new HashedMap();
        if (StringUtils.isNotEmpty(relationCode)){
            params.put("relationCode",relationCode);
        }
        Long count = 0L;
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(sqlCount,params);
        if(total!=null){
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
            count = hibenateUtils.objTransformLong(total.get(0).get("total"));
        }
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,params,page,pageSize);
        for (Map<String,Object> map:list){
            String createTime= map.get("updateTime").toString();
            String updateTime = map.get("updateTime1").toString();
            map.put("updateTime",DateUtil.dateToStrLong(DateUtil.strToDateLong(createTime)));
            map.put("updateTime1",DateUtil.dateToStrLong(DateUtil.strToDateLong(updateTime)));
        }
        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, pageSize, count);
    }
    private String dealSql(String relationCode,Boolean isCount){
        StringBuffer sql = new StringBuffer();
        if (isCount) {
            sql.append("SELECT COUNT(1) AS \"total\" FROM (");
        }
        sql.append("select " +"b.id AS \"id\",b.content AS \"topContent\",b.sender_name AS \"topSenderName\" " +
                ",a.content AS \"content\",b.update_time  AS \"updateTime\", a.sender_name AS \"senderName\",a.receiver_name AS \"receiverName\",a.update_time  AS \"updateTime1\""+
                "from base_user_msg_content a left join base_user_message b" +
                "on on b.id = a.base_user_msg_id");
        sql.append(" where 1=1 ");
        if (StringUtils.isNotEmpty(relationCode)){
            sql.append(" and a.relation_code = :relationCode");
        }
        if (isCount) {
            sql.append(") t");
        }
        return sql.toString();
    }
    public boolean checkGiveTimeOut(String sender, String reciver) {
        List<BaseUserMessageDO> baseBannerDoctorDOS = this.baseUserMessageDao.getMessageByPatientAndDoctor(reciver, sender);
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = this.wlyyHospitalSysDictDao.findById("leave_message_timeout");
        if (null != baseBannerDoctorDOS&&baseBannerDoctorDOS.size()>=1)
        {
            BaseUserMessageDO lastOne = (BaseUserMessageDO)baseBannerDoctorDOS.get(0);
            Date lastDate = lastOne.getCreateTime();
            long timeOut = wlyyHospitalSysDictDO.getDictValue() != null ? Long.valueOf(wlyyHospitalSysDictDO.getDictValue()).longValue() : 5L;
            Date current = new Date();
            if (current.getTime() - lastDate.getTime() > timeOut * 1000L * 60L) {
                return true;
            }
            return false;
        }
        return true;
    }
    public boolean checkGiveTimes(String patientId, String doctorId)
    {
        boolean flag = false;
        StringBuffer sql = new StringBuffer();
        sql.append("select t.sender as \"sender\",t.receiver as \"receiver\" from base_user_message t");
        sql.append(" where 1=1 ");
        if (StringUtils.isNotBlank(patientId)) {
            sql.append(" and t.sender = '" + patientId + "'");
        }
        if (StringUtils.isNotBlank(doctorId)) {
            sql.append(" and t.receiver = '" + doctorId + "'");
        }
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String strDate = format.format(date);
        System.out.println(wxId+flag);
        if("xm_ykyy_wx".equals(wxId)){
            if (flag){
                sql.append(" and t.create_time > '" + strDate + " 00:00:00' and t.create_time<'" + strDate + " 23:59:59'");
            }else {
                sql.append(" and t.create_time > to_date('" + strDate + " 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and t.create_time< to_date('" + strDate + " 23:59:59','yyyy-mm-dd hh24:mi:ss')");
            }
        }else{
            sql.append(" and t.create_time > '" + strDate + " 00:00:00' and t.create_time<'" + strDate + " 23:59:59'");
        }
        List<Map<String, Object>> list = this.hibenateUtils.createSQLQuery(sql.toString());
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = this.wlyyHospitalSysDictDao.findById("leave_message_times");
        long countTimes = 5L;
        if (wlyyHospitalSysDictDO != null) {
            countTimes = wlyyHospitalSysDictDO.getDictValue() == null ? countTimes : Long.valueOf(wlyyHospitalSysDictDO.getDictValue()).longValue();
        }
        if (list.size() > countTimes) {
            return false;
        }
        return true;
    }
    public void deleteMessageOrMessageContent(String msgId,String isDelParent){
        if ("1".equalsIgnoreCase(isDelParent)){
            BaseUserMessageDO baseUserMessageDO = baseUserMessageDao.findOne(msgId);
            if (baseUserMessageDO!=null){
                BaseOperateLogDO baseOperateLogDO = new BaseOperateLogDO();
                JSONObject jsonObject = new JSONObject();
                baseUserMessageDO.setDel(0);
                baseUserMessageDao.save(baseUserMessageDO);
                baseOperateLogDO.setOperator(baseUserMessageDO.getSender());
                baseOperateLogDO.setIsDel("0");
                List<BaseBannerDoctorDO> ba =  baseBannerDoctorDao.getBanners(baseUserMessageDO.getReceiver(),baseUserMessageDO.getSender(),baseUserMessageDO.getRelationCode());
                if(ba!=null&&ba.size()>0){
                    jsonObject.put("banners",ba);
                    baseBannerDoctorDao.delete(ba);
                }
                List<BaseEvaluateScoreDO> scoreList= baseEvaluateScoreDao.findByRelationCode(baseUserMessageDO.getRelationCode());
                if (scoreList!=null&&scoreList.size()>0){
                    for (BaseEvaluateScoreDO baseEvaluateScoreDO:scoreList){
                        List<BaseEvaluateDO> baseEvaluateDO=baseEvaluateDao.findByRelationCode(baseEvaluateScoreDO.getId());
                        jsonObject.put(baseEvaluateScoreDO.getId(),baseEvaluateDO);
                        if (baseEvaluateDO!=null&&baseEvaluateDO.size()>0){
                            baseEvaluateDao.delete(baseEvaluateDO);
                        }
                    }
                    jsonObject.put("scoreList",scoreList);
                    baseEvaluateScoreDao.delete(scoreList);
                }
                baseOperateLogDO.setRelationCode(baseUserMessageDO.getId());
                baseOperateLogDO.setName("删除留言评价");
                baseOperateLogDO.setRelationType(jsonObject.toString());
                try {
                    baseOperateLogDao.save(baseOperateLogDO);
                }catch (Exception e){
                    e.printStackTrace();
                }
                List<BaseUserMsgContentDO> contentlist=baseUserMsgContentDao.getContentListByID(msgId);
                for (BaseUserMsgContentDO baseUserMsgContentDO:contentlist){
                    baseUserMsgContentDO.setDel(0);
                    baseUserMsgContentDao.save(baseUserMsgContentDO);
                }
            }
        }
    }
}

+ 98 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/service/SystemMessageService.java

@ -1,14 +1,30 @@
package com.yihu.jw.hospital.message.service;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.im.ConsultDo;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.utils.YkyySMSService;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author zmk
@ -21,6 +37,18 @@ public class SystemMessageService extends BaseJpaService<SystemMessageDO,SystemM
    @Autowired
    private SystemMessageDao systemMessageDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private OutpatientDao outpatientDao;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private YkyySMSService ykyySMSService;
    @Value("${wechat.id}")
    private String wechatId;
    @Autowired
    private HibenateUtils hibenateUtils;
    /**
@ -87,7 +115,77 @@ public class SystemMessageService extends BaseJpaService<SystemMessageDO,SystemM
        return systemMessageDO;
    }
    /**
     * 发送系统消息通用接口
     */
    public  SystemMessageDO commenSystemMessage(String jsonParam,String jsonContent) throws Exception{
        if (StringUtils.isNoneBlank(jsonParam)){
            SystemMessageDO systemMessageDO = objectMapper.readValue(jsonParam,SystemMessageDO.class);
            systemMessageDO.setDel("1");
            systemMessageDO.setIsRead("0");
            if (StringUtils.isNoneBlank(jsonContent)){
                JSONObject jsonObject = JSONObject.parseObject(jsonContent);
                systemMessageDO.setData(jsonObject.toJSONString());
            }
            systemMessageDao.save(systemMessageDO);
            return systemMessageDO;
        }
        return null;
    }
    public String  sendDoctorRemindSms(ConsultDo consultDo){
        String msg = "";
        if ("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
            if (consultDo!=null){
                WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(consultDo.getRelationCode());
                if (wlyyOutpatientDO!=null){
                    BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(wlyyOutpatientDO.getDoctor());
                    if (baseDoctorDO!=null){
                        ykyySMSService.sendSmsByTempcode("message_remind_paitent",wlyyOutpatientDO,null,baseDoctorDO.getMobile());
                        msg="发送成功";
                    }else{
                        msg="发送失败,医生不存在";
                    }
                }else {
                    msg="发送失败,门诊不存在";
                }
            }else {
                msg="发送失败,consult不存在";
            }
        }
        return msg;
    }
    /*private MixEnvelop findOutPatientMessage(String reciver ,Integer page ,Integer pageSize){
        String sql = "select b.id as \"id\"," +
                " b.content as \"content\"," +
                "b.saas_id as \"saasId\"," +
                "b.is_read as \"isRead\"," +
                "b.type as \"type\"," +
                "b.sender as \"sender\"," +
                "b.sender_name as \"senderName\"," +
                "b.receiver as \"receiver\"," +
                "b.receiver_name as \"receiverName\"," +
                "b.relation_type as \"relationType\"," +
                "b.relation_code as \"relationCode\"," +
                "b.relation_name as \"relationName\"," +
                "b.status as \"status\"," +
                "b.del as \"del\"," +
                "b.create_user as \"createUser\"," +
                "b.create_user_name as \"createUserName\"," +
                "b.create_time as \"createTime\"," +
                "b.update_user as \"updateUser\"," +
                "b.update_user_name as \"updateUserName\"," +
                "b.update_time as \"updateTime\" " +
                " from wlyy_outpatient t left join base_user_message b " +
                " on t.id = b.relation_code " +
                " where b.del=1 ";
        if (StringUtils.isNoneBlank(reciver)){
            sql+=" and b.reciver = '"+reciver+"'";
        }
        sql+=" and t.status = '0' order by b.create_time asc ";
        String sqlAppend = sql+" and t.status != '0' order by b.create_time desc";
        List<Map<String,Object>> listfront = hi
    }*/
}

+ 189 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/message/service/UserMsgContentService.java

@ -0,0 +1,189 @@
package com.yihu.jw.hospital.message.service;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.hospital.message.BaseUserMessageDO;
import com.yihu.jw.entity.hospital.message.BaseUserMsgContentDO;
import com.yihu.jw.hospital.message.dao.BaseUserMessageDao;
import com.yihu.jw.hospital.message.dao.BaseUserMsgContentDao;
import com.yihu.jw.hospital.message.dao.MsgContentDao;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class UserMsgContentService extends BaseJpaService<BaseUserMsgContentDO, BaseUserMsgContentDao> {
    @Autowired
    private BaseUserMsgContentDao baseUserMsgContentDao;
    @Autowired
    private BaseUserMessageDao userMessageDao;
    @Autowired
    private MsgContentDao msgContentDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private BaseBannerDoctorService bannerDoctorService;
    @Autowired
    private BaseUserMsgService baseUserMsgService;
    //获取评论
    public List getAllMessage(String relationCode){
        List<BaseUserMessageDO> list = msgContentDao.findByRelationCode(relationCode);
        for(int i=0;i<list.size();i++){
            String id = list.get(i).getId();
            List<BaseUserMsgContentDO> contentlist=baseUserMsgContentDao.getContentListByID(id);
            list.get(i).setMsgList(contentlist);
        }
        return  list;
    }
    //好评率计算
    public List<Map<String, Object>> countPoint(String doctor){
        Map<String,Object> params = new HashedMap();
        /*sqlForExpert.append("select * from wlyy_consult a left join wlyy_consult_team b" +
                " on a.id = b.consult left join base_evaluate_score c on a.relation_code = c.id   where 1=1");
        if(StringUtils.isNotEmpty(doctor)){
            sqlForExpert.append(" and b.doctor = '"+doctor+"'");
        }
        //计算专家咨询
        sqlForExpert.append(" and a.type in (1,2,3,15)");*/
        String sqlForExpert = dealSql(doctor,true);
        String countsqlForExpert = "SELECT COUNT(1) AS \"total\" FROM ("+sqlForExpert+") t";
        //专家咨询业务数总量
        Long count = 1L;
        //专家咨询业务数满意数量
        Long expertFix = 0L;
        System.out.println(countsqlForExpert);
        List<Map<String,Object>> total = hibenateUtils.createSQLQuery(countsqlForExpert,params);
        if(total!=null){
            if (!"0".equals(total.get(0).get("total").toString())) {
                count = hibenateUtils.objTransformLong(total.get(0).get("total"));
            }
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
        }
        String sqlExpertFix = sqlForExpert+" and c.score >= 80";
        String countForExpert = "SELECT COUNT(1) AS \"total\" FROM ("+sqlExpertFix+") t";
        List<Map<String,Object>> expert = hibenateUtils.createSQLQuery(countForExpert,params);
        if (expert!=null){
            expertFix = hibenateUtils.objTransformLong(expert.get(0).get("total"));
        }
        String sql =dealSql(doctor,false);
        String countsqlForOnline= "SELECT COUNT(1) AS \"total\" FROM ("+sql+") t";
        //在线复诊业务数总量
        Long countOnlineTotal = 1L;
        //在线复诊业务数满意数量
        Long onlineFix = 0L;
        List<Map<String,Object>> totalOnline = hibenateUtils.createSQLQuery(countsqlForOnline,params);
        if(totalOnline!=null){
            if (!"0".equals(totalOnline.get(0).get("total").toString())){
                countOnlineTotal = hibenateUtils.objTransformLong(totalOnline.get(0).get("total"));
            }
            //mysql 与 Oracle 聚合函数返回类型不一致,需要判断装换
        }
        String sqlOlineFix = sql+" and c.score >= 80";
        String countForFix = "SELECT COUNT(1) AS \"total\" FROM ("+sqlOlineFix+") t";
        System.out.println(countForFix
        );
        List<Map<String,Object>> onlineFixList = hibenateUtils.createSQLQuery(countForFix,params);
        if (onlineFixList!=null){
            onlineFix = hibenateUtils.objTransformLong(onlineFixList.get(0).get("total"));
        }
        float expertMY=(float) expertFix/count;
        float inlineMY = (float)onlineFix/countOnlineTotal;
        float totalConunt = (float)(expertFix+onlineFix)/(count+countOnlineTotal);
        DecimalFormat df = new DecimalFormat("0.00");
        List<Map<String,Object>> resultList= new ArrayList<>();
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("zjzx",df.format(expertMY * 100)+"%");
        resultMap.put("zxfz",df.format(inlineMY * 100)+"%");
        resultMap.put("totalCount",df.format(totalConunt * 100)+"%");
        resultMap.put("doctor",doctor);
        resultList.add(resultMap);
        return resultList;
    }
    private String dealSql(String doctor,Boolean countExpert){
        StringBuffer sqlForExpert = new StringBuffer();
        sqlForExpert.append("select b.consult AS \"consult\" ,c.id AS \"id\" from  wlyy_consult_team b \n" +
                "left join base_evaluate_score c on b.consult = c.relation_code  \n" +
                "where 1=1");
        if(StringUtils.isNotEmpty(doctor)){
            sqlForExpert.append(" and b.doctor = '"+doctor+"'");
        }
        if(countExpert){
            sqlForExpert.append(" and (b.type =1 OR b.type =15)");
        }else{
            sqlForExpert.append(" and (b.type =9 OR b.type =16)");
        }
        return sqlForExpert.toString();
    }
    //医生主页展示的医生信息
    public JSONObject showContentByDoctor(String doctor,Integer page,Integer pageSize) throws ParseException {
        //锦旗总数和各个锦旗数量
        JSONObject jsonObject = bannerDoctorService.getDoctorBanners(doctor);
        //留言总数
        int messageTotal = userMessageDao.getAllMessageTotalCount(doctor);
        //查询医生各项评价平均分
        String sqlscore = "SELECT " +
                "AVG(a.score) AS \"score\"," +
                "a.score_type AS \"score_type\" " +
                "FROM base_evaluate a,base_evaluate_score b " +
                "WHERE " +
                "a.relation_code=b.id " +
                "AND b.doctor='" + doctor + "' " +
                "GROUP BY a.score_type ORDER BY  a.score_type ASC ";
        List<Map<String, Object>> listscore = jdbcTemplate.queryForList(sqlscore);
        Double doctorScore = new Double("0");
        if (listscore != null && listscore.size() > 0) {
            for (Map<String, Object> _listscore : listscore) {
                doctorScore += Double.parseDouble(_listscore.get("score").toString());
            }
        }
        doctorScore = doctorScore / 3;
        //总评
        jsonObject.put("doctorScore", doctorScore);
        if (listscore != null && listscore.size() > 0) {
            //各项平均分
            jsonObject.put("scoreDoctor", listscore);
        } else {
            jsonObject.put("scoreDoctor", null);
        }
        Integer curPage = (page-1)*pageSize;
        String filters = "receiver="+doctor;
        String fields ="";
        String sorts = "";
        List<BaseUserMessageDO> messageList=baseUserMsgService.search(fields,filters,sorts,page,pageSize);
        //List<BaseUserMessageDO> messageList= userMessageDao.getAllMessageByDoctor(doctor,curPage,pageSize);
        if (null!=messageList){
            for (BaseUserMessageDO baseUserMessageDO:messageList){
                String id = baseUserMessageDO.getId();
                Integer type = baseUserMessageDO.getType();
                List<BaseUserMsgContentDO> contentlist=baseUserMsgContentDao.getContentListByID(id);
                if (type!=null&&2==type){
                    baseUserMessageDO.setSenderName(baseUserMessageDO.getSenderName().substring(0,1)+"**");
                    String patientId = baseUserMessageDO.getSender();
                    for (BaseUserMsgContentDO bumLsit:contentlist){
                        bumLsit.setSenderName(bumLsit.getSender()==patientId?bumLsit.getSenderName().substring(0,1)+"**":bumLsit.getSenderName());
                        bumLsit.setReceiverName(bumLsit.getReceiver()==patientId?bumLsit.getReceiverName().substring(0,1)+"**":bumLsit.getReceiverName());
                    }
                }
                baseUserMessageDO.setMsgList(contentlist);
            }
            jsonObject.put("messageList", messageList);
        }
        return jsonObject;
    }
}

+ 26 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/BaseNatAppointmentDao.java

@ -0,0 +1,26 @@
package com.yihu.jw.hospital.prescription.dao;
import com.yihu.jw.entity.hospital.prescription.BaseNatAppointmentDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
public interface BaseNatAppointmentDao extends PagingAndSortingRepository<BaseNatAppointmentDO, Integer>, JpaSpecificationExecutor<BaseNatAppointmentDO> {
    @Query("from BaseNatAppointmentDO t where t.payStatus = 0 ")
    List<BaseNatAppointmentDO> findByPayStatus();
    @Query("from BaseNatAppointmentDO t where  t.payStatus = 0 and t.isSuccess=1 and t.patientId=?1")
    List<BaseNatAppointmentDO> findPayStatusByPatientId(String patientId);
    @Query("from BaseNatAppointmentDO t where t.patientId=?1 and t.payStatus in (0,1) and t.isSuccess=1 ")
    List<BaseNatAppointmentDO> findByTasy(String patientId);
    @Query("select a from BaseNatAppointmentDO a where  a.realOrder =?1 ")
    List<BaseNatAppointmentDO> findByRealOrderList(String realOrder);
}

+ 8 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/BaseNatInspectionDao.java

@ -0,0 +1,8 @@
package com.yihu.jw.hospital.prescription.dao;
import com.yihu.jw.entity.hospital.prescription.BaseNatInspectionDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseNatInspectionDao extends PagingAndSortingRepository<BaseNatInspectionDO, Integer>, JpaSpecificationExecutor<BaseNatInspectionDO> {
}

+ 14 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/BaseNationalDrugDictDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.hospital.prescription.dao;
import com.yihu.jw.entity.hospital.prescription.BaseNationalDrugDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BaseNationalDrugDictDao extends PagingAndSortingRepository<BaseNationalDrugDictDO, Integer>, JpaSpecificationExecutor<BaseNationalDrugDictDO> {
    @Query("update BaseNationalDrugDictDO b set b.status = ?2 where b.id = ?1")
    @Modifying
    void updateStatusById(Integer id, Integer status);
}

+ 21 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/BaseSensitiveDao.java

@ -0,0 +1,21 @@
package com.yihu.jw.hospital.prescription.dao;
import com.yihu.jw.entity.base.words.BaseSensitiveDO;
import org.checkerframework.framework.qual.RequiresQualifier;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/7/6
 */
public interface BaseSensitiveDao extends PagingAndSortingRepository<BaseSensitiveDO, String>, JpaSpecificationExecutor<BaseSensitiveDO> {
    BaseSensitiveDO findBySensitiveWord(String sensitive);
    @Query(value = "select * from base_sensitive p where p.status = 1 ",nativeQuery = true)
    List<BaseSensitiveDO> getSensitiveWords();
}

+ 11 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/OauthCaConfigDao.java

@ -0,0 +1,11 @@
package com.yihu.jw.hospital.prescription.dao;
import com.yihu.jw.entity.ca.OauthCaConfigDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2019/12/25.
 */
public interface OauthCaConfigDao extends PagingAndSortingRepository<OauthCaConfigDO, String>, JpaSpecificationExecutor<OauthCaConfigDO> {
}

+ 0 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/OutpatientDao.java


この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません