Forráskód Böngészése

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

LAPTOP-KB9HII50\70708 1 éve
szülő
commit
9394751f94
20 módosított fájl, 3591 hozzáadás és 1969 törlés
  1. 5 0
      business/base-service/pom.xml
  2. 642 611
      business/base-service/src/main/java/com/yihu/jw/article/service/KnowledgeArticleDictService.java
  3. 32 7
      business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintService.java
  4. 571 193
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/DsyyPrescriptionService.java
  5. 78 110
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java
  6. 894 518
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/DsyyEntranceService.java
  7. 1 1
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/EntranceService.java
  8. 377 76
      business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java
  9. 55 42
      business/base-service/src/main/java/com/yihu/jw/order/pay/ylz/YlzPayService.java
  10. 1 1
      business/base-service/src/main/java/com/yihu/jw/utils/dsyyUtil/ServiceLocator.java
  11. 10 0
      business/base-service/src/main/java/com/yihu/jw/utils/dsyyUtil/ZyXmyytRequestServiceu.java
  12. 26 1
      common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java
  13. 12 0
      server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java
  14. 1 1
      server/svr-authentication/src/main/java/com/yihu/jw/security/service/DsyyService.java
  15. 326 2
      svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/controller/DsyyController.java
  16. 8 4
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/complaint/BaseComplaintEndPoint.java
  17. 13 3
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/patient/PatientNoLoginEndPoint.java
  18. 113 0
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/DsyyPrescriptionCotroller.java
  19. 34 27
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java
  20. 392 372
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/service/consult/KnowledgeArticleService.java

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

@ -188,6 +188,11 @@
            <version>${version.commons-io}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>5.7.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.kaptcha</groupId>
            <artifactId>kaptcha</artifactId>

+ 642 - 611
business/base-service/src/main/java/com/yihu/jw/article/service/KnowledgeArticleDictService.java

@ -28,6 +28,7 @@ import com.yihu.jw.utils.EntityUtils;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import java.util.Date;
@ -37,636 +38,666 @@ import java.util.UUID;
/**
 * 健康文章业务层代码
 *
 * @author huangwenjie
 * @date 2019/9/10 13:54
 */
@Service
public class KnowledgeArticleDictService extends BaseJpaService<KnowledgeArticleDictDO, KnowledgeArticleDictDao> {
	
	@Autowired
	private KnowledgeArticleDictDao knowledgeArticleDictDao;
	@Autowired
	private BaseMenuDictDao baseMenuDictDao;
	
	@Autowired
	private KnowledgeArticleDeptDao knowledgeArticleDeptDao;
	@Autowired
	private WlyyHospitalSysDictDao hospitalSysDictDao;
	@Autowired
	private BasePatientBusinessDao patientBusinessDao;
	@Autowired
	private KnowledgeArticleUserDao knowledgeArticleUserDao;
	@Autowired
	private BaseDoctorHospitalDao doctorHospitalDao;
	@Autowired
	private BaseDoctorDao doctorDao;
	@Autowired
	private SurveyUserDao surveyUserDao;
	@Autowired
	private SurveyTemplateDao surveyTemplateDao;
	@Autowired
    @Autowired
    private KnowledgeArticleDictDao knowledgeArticleDictDao;
    @Autowired
    private BaseMenuDictDao baseMenuDictDao;
    @Autowired
    private KnowledgeArticleDeptDao knowledgeArticleDeptDao;
    @Autowired
    private WlyyHospitalSysDictDao hospitalSysDictDao;
    @Autowired
    private BasePatientBusinessDao patientBusinessDao;
    @Autowired
    private KnowledgeArticleUserDao knowledgeArticleUserDao;
    @Autowired
    private BaseDoctorHospitalDao doctorHospitalDao;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private SurveyUserDao surveyUserDao;
    @Autowired
    private SurveyTemplateDao surveyTemplateDao;
    @Autowired
    private HibenateUtils hibenateUtils;
	@Autowired
	private UserDao userDao;
	@Autowired
	private BasePatientDao patientDao;
	@Autowired
	private KnowledgeArticleDoctorDao knowledgeArticleDoctorDao;
	//查询文章列表
	public List<Map<String,Object>> findArticleList(String first,String second,Integer type ,String key,Integer page ,Integer pageSize){
		String sql ="select b.id as \"id\", " +
				" b.title as \"title\"," +
				" b.intro as \"intro\"," +
				" b.category_first as \"categoryFirst\"," +
				" b.category_first_name as \"categoryFirstName\"," +
				" b.category_second as \"category_second\"," +
				" b.category_second_name as \"categorySecondName\"," +
				" b.create_user as \"createUser\"," +
				" b.status as \"status\"," +
				" b.used as \"used\"," +
				" b.create_user_name as \"createUserName\"," +
				" b.create_time as \"createTime\"," +
				" b.check_time as \"checkTime\"," +
				" b.release_status as \"releaseStatus\"," +
				" t.menu_id as \"menuId\"," +
				" t.parent_id as \"parentId\"," +
				" t.menu_name as \"menuName\"  " +
				" from wlyy_knowledge_article_menu t left join wlyy_knowledge_article_dict b" +
				" on t.article_id=b.id left join base_menu_dict c " +
				" on c.id= t.menu_id where t.del=1 and b.type="+type;
		if (StringUtils.isNotBlank(first)){
			sql+=" and t.category_first ='"+first+"'";
		}
		if (StringUtils.isNotBlank(second)){
			sql+=" and t.category_second ='"+second+"'";
		}
		if (StringUtils.isNotBlank(key)){
			sql+=" and (t.title like '%"+first+"&' or t.intro like '%"+key+"%' or t.content like '%"+key+"%')";
		}
		List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
		for (Map<String,Object> map:list){
			if (!"0".equalsIgnoreCase(map.get("parentId").toString())){
				BaseMenuDictDO baseMenuDictDO = baseMenuDictDao.findById(map.get("parentId").toString()).orElse(null);;
				if (baseMenuDictDO!=null){
					map.put("parentName",baseMenuDictDO.getName());
				}
			}else {
				map.put("parentName",map.get("menuName").toString());
			}
		}
		return list;
	}
	public boolean delArticle(String id){
		String str[]= id.split(",");
		for (int i=0;i<str.length;i++){
			KnowledgeArticleDictDO knowledgeArticleDictDO = findByIdAndDel(str[i]);
			if (knowledgeArticleDictDO!=null){
				knowledgeArticleDictDO.setDel(0);
				knowledgeArticleDictDao.save(knowledgeArticleDictDO);
			}
		}
		return true;
	}
	public KnowledgeArticleDictDO findById(String id){
		return knowledgeArticleDictDao.findById(id).orElse(null);
	}
	public KnowledgeArticleDictDO findByIdAndDel(String id){
		return knowledgeArticleDictDao.findByIdAndDel(id);
	}
	/**
	 * 更新/保存健康文章
	 * @param jsonData
	 * @return
	 * @throws Exception
	 */
	public KnowledgeArticleDictDO saveArticle(String jsonData,Integer type) throws  Exception {
		KnowledgeArticleDictDO knowledgeArticleDO = EntityUtils.jsonToEntity(jsonData, KnowledgeArticleDictDO.class);
		WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("articleNeedCheck").orElse(null);;
		Boolean articleNeedCheck= true;
		if (wlyyHospitalSysDictDO!=null){
			if (!wlyyHospitalSysDictDO.getDictValue().equalsIgnoreCase("1")){
				articleNeedCheck=false;
			}
		}
		if (StringUtils.isBlank(knowledgeArticleDO.getId()) ) {
			// 新增
			knowledgeArticleDO.setId(UUID.randomUUID().toString().replace("-", ""));
			knowledgeArticleDO.setCreateTime(new Date());
			knowledgeArticleDO.setStatus(0);
			knowledgeArticleDO.setReleaseStatus(0);
			knowledgeArticleDO.setDel(1);
			knowledgeArticleDO.setType(type);
			knowledgeArticleDO.setFabulous(0);
			knowledgeArticleDO.setReadCount(0);
			knowledgeArticleDO.setUsed(0);
			knowledgeArticleDO.setCollection(0);
			knowledgeArticleDO.setIsUsed(0);
			if(knowledgeArticleDO.getReleaseTime()==null){
				knowledgeArticleDO.setReleaseTime(new Date());
			}
			if(type==1){
				BaseDoctorDO userDO = doctorDao.findById(knowledgeArticleDO.getCreateUser()).orElse(null);;
				if (userDO!=null){
					knowledgeArticleDO.setCreateUserName(userDO.getName());
				}
			}else {
				BaseDoctorDO userDO = doctorDao.findById(knowledgeArticleDO.getCreateUser()).orElse(null);;
				if (userDO!=null){
					knowledgeArticleDO.setCreateUserName(userDO.getName());
				}
			}
			if (!articleNeedCheck){
				knowledgeArticleDO.setStatus(1);
				knowledgeArticleDO.setReleaseStatus(1);
			}
			knowledgeArticleDO = knowledgeArticleDictDao.save(knowledgeArticleDO);
			return knowledgeArticleDO;
		} else {
			KnowledgeArticleDictDO one = findById(knowledgeArticleDO.getId());
			one.setTitle(knowledgeArticleDO.getTitle());
			one.setContent(knowledgeArticleDO.getContent());
			one.setImage(knowledgeArticleDO.getImage());
			one.setIntro(knowledgeArticleDO.getIntro());
			one.setUpdateTime(new Date());
			one.setCategoryFirst(knowledgeArticleDO.getCategoryFirst());
			one.setCategoryFirstName(knowledgeArticleDO.getCategoryFirstName());
			one.setCategorySecond(knowledgeArticleDO.getCategorySecond());
			one.setCategorySecondName(knowledgeArticleDO.getCategorySecondName());
			one.setReleaseTime(knowledgeArticleDO.getReleaseTime());
			if(knowledgeArticleDO.getReleaseTime()==null){
				knowledgeArticleDO.setReleaseTime(new Date());
			}
			one.setStatus(0);
			one.setPuplishType(knowledgeArticleDO.getPuplishType());
			one.setPuplishTypeName(knowledgeArticleDO.getPuplishTypeName());
			one.setSource(knowledgeArticleDO.getSource());
			one.setUrl(knowledgeArticleDO.getUrl());
			one.setVedioUrl(knowledgeArticleDO.getVedioUrl());
			one.setRecommendDoctor(knowledgeArticleDO.getRecommendDoctor());
			one.setRecommendDoctorName(knowledgeArticleDO.getRecommendDoctorName());
			if (!articleNeedCheck){
				one.setStatus(1);
				one.setReleaseStatus(1);
			}
			knowledgeArticleDictDao.save(one);
			return  one;
		}
	}
	/**
	 * 获取doctorId获取医生发布的文章统计数据
	 * @param doctorId
	 * @return
	 */
	public JSONObject findArticleStaticsByDoctorId(String doctorId){
		String eulogySql = " select * from base_knowledge_article_doctor kad where kad.type=2 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='"+doctorId+"') ";
		List<Map<String,Object>> mapList = jdbcTemplate.queryForList(eulogySql);//点赞数量
		String startDate = DateUtil.getNextDay(new Date(),-7)+" 00:00:00";
		String endDate = DateUtil.getStringDateShort()+" 23:59:59";
		String dateCondition = " and kad.create_time >='"+startDate+"' and kad.create_time <='"+endDate+"' ";
		String eulogy7Sql = " select * from base_knowledge_article_doctor kad where kad.type=2 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='"+doctorId+"') "+dateCondition;
		List<Map<String,Object>> map7List = jdbcTemplate.queryForList(eulogy7Sql);//7日点赞数量
		//收藏数量
		String collectSql = " select * from base_knowledge_article_doctor kad where kad.type=3 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='"+doctorId+"') ";
		List<Map<String,Object>> collectList = jdbcTemplate.queryForList(collectSql);//收藏数量
		String collect7Sql = " select * from base_knowledge_article_doctor kad where kad.type=3 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='"+doctorId+"') "+dateCondition;
		List<Map<String,Object>> collect7List = jdbcTemplate.queryForList(collect7Sql);//7日收藏数量
		//评论数量
		String commentSql = " select * from base_knowledge_article_doctor kad where kad.type=1 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='"+doctorId+"') ";
		List<Map<String,Object>> commentList = jdbcTemplate.queryForList(commentSql);//评论数量
		String comment7Sql = " select * from base_knowledge_article_doctor kad where kad.type=1 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='"+doctorId+"') "+dateCondition;
		List<Map<String,Object>> comment7List = jdbcTemplate.queryForList(comment7Sql);//7日评论数量
		JSONObject object = new JSONObject();
		object.put("eulogyTotal",mapList.size());//点赞数量
		object.put("eulogy7Total",map7List.size());//7日新增点赞数量
		object.put("collectTotal",collectList.size());//收藏数量
		object.put("collect7Total",collect7List.size());//7日新增收藏数量
		object.put("commentTotal",commentList.size());//评论数量
		object.put("comment7Total",comment7List.size());//7日新增评论数量
		return object;
	}
	
	//审核/退回文章
	public KnowledgeArticleDictDO reviewArticle(String articleId,Integer status,String reason) throws Exception{
		KnowledgeArticleDictDO knowledgeArticleDO = findById(articleId);
		if (null == knowledgeArticleDO) {
			throw new Exception("该文章不存在");
		} else {
			knowledgeArticleDO.setStatus(status);
			knowledgeArticleDO.setCheckTime(new Date());
			if(StringUtils.isNotBlank(reason)){
				knowledgeArticleDO.setCancelReason(reason);
			}
			knowledgeArticleDO.setReleaseStatus(status);
			knowledgeArticleDictDao.save(knowledgeArticleDO);
			return  knowledgeArticleDO;
		}
	}
	
	/**
	 * 保存文章科室关系
	 * @param articleId
	 * @param sdJsons
	 * @return
	 * @throws Exception
	 */
	public Boolean saveArticleDept(String articleId,String sdJsons)throws Exception{
		
		//删除之前关系
		List<KnowledgeArticleDeptDO> list = knowledgeArticleDeptDao.findByArticleId(articleId);
		if(list!=null&&list.size()>0){
			knowledgeArticleDeptDao.deleteAll(list);
		}
		
		if(org.apache.commons.lang3.StringUtils.isNotBlank(sdJsons)){
			List<KnowledgeArticleDeptDO> _list = EntityUtils.jsonToList(sdJsons,KnowledgeArticleDeptDO.class);
			if(_list!=null&&_list.size()>0){
				knowledgeArticleDeptDao.saveAll(_list);
			}
		}
		return true;
	}
	/**
	 * 查询文章下科室
	 * @param articleId
	 * @return
	 */
	public List<Map<String,Object>> findDeptByArticle(String articleId)throws Exception{
		String sql ="SELECT " +
				" d.article_id AS \"articleId\"," +
				" d.dept as \"dept\", " +
				" d.dept_name AS \"deptName\" " +
				" FROM " +
				" wlyy_knowledge_article t " +
				" JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
				" WHERE " +
				" t.id = '"+articleId+"'";
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
		return list;
	}
	
	/**
	 * 查询文章下科室
	 * @param articleId
	 * @return
	 */
	public List<Map<String,Object>> findDeptByArticle2(String articleId)throws Exception{
		String sql ="SELECT " +
				" d.article_id AS \"articleId\"," +
				" d.dept as \"dept\", " +
				" d.dept_name AS \"deptName\" " +
				" FROM " +
				" wlyy_knowledge_article_dict t " +
				" JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
				" WHERE " +
				" t.id = '"+articleId+"'";
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
		return list;
	}
	/**
	 * 查询部门下的文章
	 * @param dept
	 * @return
	 */
	public List<Map<String,Object>> findArticleByDept2(String dept)throws Exception{
		String sql = "SELECT " +
				" t.id as \"id\", " +
				" t.title as \"title\", " +
				" t.create_time AS \"create_time\" ," +
				" t.image AS \"image\" " +
				" FROM " +
				" wlyy_knowledge_article_dict t " +
				" JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
				" WHERE " +
				" d.dept = '"+dept+"'";
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
		return list;
	}
	
	/**
	 * 查询部门下的文章
	 * @param dept
	 * @return
	 */
	public List<Map<String,Object>> findArticleByDept(String dept)throws Exception{
		String sql = "SELECT " +
				" t.id as \"id\", " +
				" t.title as \"title\", " +
				" t.create_time AS \"create_time\" ," +
				" t.image AS \"image\" " +
				" FROM " +
				" wlyy_knowledge_article t " +
				" JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
				" WHERE " +
				" d.dept = '"+dept+"'";
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
		return list;
	}
	
	/**
	 * 设置部门发送文章
	 * @param dept
	 * @param sdJsons
	 * @return
	 */
	public Boolean saveDeptArticle(String dept, String sdJsons) throws Exception{
		
		//删除之前关系
		List<KnowledgeArticleDeptDO> dels = knowledgeArticleDeptDao.findByDept(dept);
		if(dels!=null&&dels.size()>0){
			knowledgeArticleDeptDao.deleteAll(dels);
		}
		
		if(org.apache.commons.lang3.StringUtils.isNotBlank(sdJsons)){
			List<KnowledgeArticleDeptDO> list = EntityUtils.jsonToList(sdJsons,KnowledgeArticleDeptDO.class);
			if(list!=null&&list.size()>0){
				knowledgeArticleDeptDao.saveAll(list);
			}
		}
		return true;
	}
	public KnowledgeArticleDictDO releaseArticle(String articleId,Integer releaseStatus ){
		String ids[] = articleId.split(",");
		KnowledgeArticleDictDO knowledgeArticleDictDO = new KnowledgeArticleDictDO();
		for (int i=0;i<ids.length;i++){
			knowledgeArticleDictDO = findByIdAndDel(ids[i]);
			if (null!=knowledgeArticleDictDO){
				knowledgeArticleDictDO.setReleaseStatus(releaseStatus);
				knowledgeArticleDictDao.save(knowledgeArticleDictDO);
			}
		}
		return knowledgeArticleDictDO;
	}
	/**
	 *	患者接收问卷/文章
	 * @param businessDOS
	 * @return
	 */
	public List<BasePatientBusinessDO> sendBusinessToPatient(List<BasePatientBusinessDO> businessDOS) throws Exception {
		if (businessDOS!=null&&businessDOS.size()!=0){
			for (BasePatientBusinessDO patientBusinessDO:businessDOS){
				BasePatientBusinessDO basePatientBusinessDO = patientBusinessDao.findByPatientAndRelationCodeAndDel(patientBusinessDO.getPatient(),patientBusinessDO.getRelationCode());
				if (basePatientBusinessDO != null) {
					throw new Exception("已发送过!");
				}
				patientBusinessDO.setCreateTime(new Date());
				patientBusinessDO.setUpdateTime(new Date());
				patientBusinessDO.setCreateUser(patientBusinessDO.getDoctor());
				patientBusinessDO.setUpdateUser(patientBusinessDO.getDoctor());
				patientBusinessDO.setCreateUserName(patientBusinessDO.getDoctorName());
				patientBusinessDO.setUpdateUserName(patientBusinessDO.getUpdateUserName());
				patientBusinessDO.setCollection(0);
				patientBusinessDO.setDel(1);
				patientBusinessDO = patientBusinessDao.save(patientBusinessDO);
					if (patientBusinessDO.getRelationType()==1){
						KnowledgeArticleDictDO knowledgeArticleDO = findByIdAndDel(patientBusinessDO.getRelationCode());
					System.out.println("content:"+JSON.toJSONString(knowledgeArticleDO));
					JSONObject object = new JSONObject();
					object.put("id",knowledgeArticleDO.getId());
					object.put("title",knowledgeArticleDO.getTitle());
					object.put("content",knowledgeArticleDO.getIntro());
					object.put("img",knowledgeArticleDO.getImage());
				}else {
					WlyySurveyUserDO wlyySurveyUserDO = new WlyySurveyUserDO();
					String doctor = patientBusinessDO.getDoctor();
					BaseDoctorDO doctorDO = doctorDao.findById(doctor).orElse(null);;
					wlyySurveyUserDO.setDept(doctorDO.getVisitDept());
					wlyySurveyUserDO.setDeptName(doctorDO.getVisitDeptName());
					wlyySurveyUserDO.setDoctor(doctor);
					wlyySurveyUserDO.setDoctorName(doctorDO.getName());
					wlyySurveyUserDO.setStatus(0);
					wlyySurveyUserDO.setPatient(patientBusinessDO.getPatient());
					wlyySurveyUserDO.setPatientName(patientBusinessDO.getPatientName());
					wlyySurveyUserDO.setSurveyTempCode(patientBusinessDO.getRelationCode());
					wlyySurveyUserDO.setSurveyTempTitle(patientBusinessDO.getRelationName());
					wlyySurveyUserDO.setCreateTime(new Date());
					wlyySurveyUserDO.setEndTime(new Date());
					wlyySurveyUserDO = surveyUserDao.save(wlyySurveyUserDO);
					JSONObject object = new JSONObject();
					WlyySurveyTemplateDO wlyySurveyTemplateDO = surveyTemplateDao.findById(wlyySurveyUserDO.getSurveyTempCode()).orElse(null);;
					if (null!=wlyySurveyTemplateDO){
						object.put("title",wlyySurveyTemplateDO.getTitle());
						object.put("content",wlyySurveyTemplateDO.getTemplateComment());
						object.put("id",wlyySurveyTemplateDO.getId());
					}
				}
			}
		}
		return businessDOS;
	}
	/**
	 * 设置为1常用或者0不常用
	 * @param id
	 * @param used
	 * @return
	 */
	public KnowledgeArticleDictDO setUsed(String id,Integer used,String doctor){
		KnowledgeArticleDictDO knowledgeArticleDO = findByIdAndDel(id);
		BaseDoctorDO doctorDO = doctorDao.findById(doctor).orElse(null);;
		KnowledgeArticleUserDO knowledgeArticleUserDO =knowledgeArticleUserDao.findByrelationCodeAndUserAndDel(id,doctor);
		if (knowledgeArticleUserDO==null){
			knowledgeArticleUserDO = new KnowledgeArticleUserDO();
			knowledgeArticleUserDO.setRelationCode(id);
			knowledgeArticleUserDO.setRelationName(knowledgeArticleDO.getTitle());
			knowledgeArticleUserDO.setRelationType(1);
			knowledgeArticleUserDO.setDel(1);
			knowledgeArticleUserDO.setUser(doctor);
			if (doctorDO!=null){
				knowledgeArticleUserDO.setUserName(doctorDO.getName());
				knowledgeArticleUserDO.setCreateUserName(doctorDO.getName());
			}
			knowledgeArticleUserDO.setCreateTime(new Date());
			knowledgeArticleUserDO.setUpdateTime(new Date());
			knowledgeArticleUserDO.setCreateUser(doctor);
			knowledgeArticleUserDO.setUpdateUser(doctor);
			knowledgeArticleUserDO.setUsed(used);
			knowledgeArticleUserDO = knowledgeArticleUserDao.save(knowledgeArticleUserDO);
		}
        if (knowledgeArticleDO!=null){
            if (knowledgeArticleDO.getUsed()!=null){
            	if (used==1){
					knowledgeArticleUserDO.setUsed(1);
					knowledgeArticleDO.setUsed(knowledgeArticleDO.getUsed()+1);
				}else if (used==0){
            		knowledgeArticleUserDO.setUsed(0);
            		knowledgeArticleDO.setUsed(knowledgeArticleDO.getUsed()-1);
				}
			}else {
				if (used==1){
					knowledgeArticleDO.setUsed(1);
				}else if (used==0){
					knowledgeArticleDO.setUsed(0);
				}
			}
    @Autowired
    private UserDao userDao;
    @Autowired
    private BasePatientDao patientDao;
    @Autowired
    private KnowledgeArticleDoctorDao knowledgeArticleDoctorDao;
    //查询文章列表
    public List<Map<String, Object>> findArticleList(String first, String second, Integer type, String key, Integer page, Integer pageSize) {
        String sql = "select b.id as \"id\", " +
                " b.title as \"title\"," +
                " b.intro as \"intro\"," +
                " b.category_first as \"categoryFirst\"," +
                " b.category_first_name as \"categoryFirstName\"," +
                " b.category_second as \"category_second\"," +
                " b.category_second_name as \"categorySecondName\"," +
                " b.create_user as \"createUser\"," +
                " b.status as \"status\"," +
                " b.used as \"used\"," +
                " b.create_user_name as \"createUserName\"," +
                " b.create_time as \"createTime\"," +
                " b.check_time as \"checkTime\"," +
                " b.release_status as \"releaseStatus\"," +
                " t.menu_id as \"menuId\"," +
                " t.parent_id as \"parentId\"," +
                " t.menu_name as \"menuName\"  " +
                " from wlyy_knowledge_article_menu t left join wlyy_knowledge_article_dict b" +
                " on t.article_id=b.id left join base_menu_dict c " +
                " on c.id= t.menu_id where t.del=1 and b.type=" + type;
        if (StringUtils.isNotBlank(first)) {
            sql += " and t.category_first ='" + first + "'";
        }
        if (StringUtils.isNotBlank(second)) {
            sql += " and t.category_second ='" + second + "'";
        }
        if (StringUtils.isNotBlank(key)) {
            sql += " and (t.title like '%" + first + "&' or t.intro like '%" + key + "%' or t.content like '%" + key + "%')";
        }
        List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, page, pageSize);
        for (Map<String, Object> map : list) {
            if (!"0".equalsIgnoreCase(map.get("parentId").toString())) {
                BaseMenuDictDO baseMenuDictDO = baseMenuDictDao.findById(map.get("parentId").toString()).orElse(null);
                ;
                if (baseMenuDictDO != null) {
                    map.put("parentName", baseMenuDictDO.getName());
                }
            } else {
                map.put("parentName", map.get("menuName").toString());
            }
        }
        return list;
    }
    public boolean delArticle(String id) {
        String str[] = id.split(",");
        for (int i = 0; i < str.length; i++) {
            KnowledgeArticleDictDO knowledgeArticleDictDO = findByIdAndDel(str[i]);
            if (knowledgeArticleDictDO != null) {
                knowledgeArticleDictDO.setDel(0);
                knowledgeArticleDictDao.save(knowledgeArticleDictDO);
            }
        }
        return true;
    }
    public KnowledgeArticleDictDO findById(String id) {
        return knowledgeArticleDictDao.findById(id).orElse(null);
    }
    public KnowledgeArticleDictDO findByIdAndDel(String id) {
        return knowledgeArticleDictDao.findByIdAndDel(id);
    }
    /**
     * 更新/保存健康文章
     *
     * @param jsonData
     * @return
     * @throws Exception
     */
    public KnowledgeArticleDictDO saveArticle(String jsonData, Integer type) throws Exception {
        KnowledgeArticleDictDO knowledgeArticleDO = EntityUtils.jsonToEntity(jsonData, KnowledgeArticleDictDO.class);
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("articleNeedCheck").orElse(null);
        ;
        Boolean articleNeedCheck = true;
        if (wlyyHospitalSysDictDO != null) {
            if (!wlyyHospitalSysDictDO.getDictValue().equalsIgnoreCase("1")) {
                articleNeedCheck = false;
            }
        }
        if (StringUtils.isBlank(knowledgeArticleDO.getId())) {
            // 新增
            knowledgeArticleDO.setId(UUID.randomUUID().toString().replace("-", ""));
            knowledgeArticleDO.setCreateTime(new Date());
            knowledgeArticleDO.setStatus(0);
            knowledgeArticleDO.setReleaseStatus(0);
            knowledgeArticleDO.setDel(1);
            knowledgeArticleDO.setType(type);
            knowledgeArticleDO.setFabulous(0);
            knowledgeArticleDO.setReadCount(0);
            knowledgeArticleDO.setUsed(0);
            knowledgeArticleDO.setCollection(0);
            knowledgeArticleDO.setIsUsed(0);
            if (knowledgeArticleDO.getReleaseTime() == null) {
                knowledgeArticleDO.setReleaseTime(new Date());
            }
            if (type == 1) {
                BaseDoctorDO userDO = doctorDao.findById(knowledgeArticleDO.getCreateUser()).orElse(null);
                ;
                if (userDO != null) {
                    knowledgeArticleDO.setCreateUserName(userDO.getName());
                }
            } else {
                BaseDoctorDO userDO = doctorDao.findById(knowledgeArticleDO.getCreateUser()).orElse(null);
                ;
                if (userDO != null) {
                    knowledgeArticleDO.setCreateUserName(userDO.getName());
                }
            }
            if (!articleNeedCheck) {
                knowledgeArticleDO.setStatus(1);
                knowledgeArticleDO.setReleaseStatus(1);
            }
            knowledgeArticleDO = knowledgeArticleDictDao.save(knowledgeArticleDO);
            return knowledgeArticleDO;
        } else {
            KnowledgeArticleDictDO one = findById(knowledgeArticleDO.getId());
            one.setTitle(knowledgeArticleDO.getTitle());
            one.setContent(knowledgeArticleDO.getContent());
            one.setImage(knowledgeArticleDO.getImage());
            one.setIntro(knowledgeArticleDO.getIntro());
            one.setUpdateTime(new Date());
            one.setCategoryFirst(knowledgeArticleDO.getCategoryFirst());
            one.setCategoryFirstName(knowledgeArticleDO.getCategoryFirstName());
            one.setCategorySecond(knowledgeArticleDO.getCategorySecond());
            one.setCategorySecondName(knowledgeArticleDO.getCategorySecondName());
            one.setReleaseTime(knowledgeArticleDO.getReleaseTime());
            if (knowledgeArticleDO.getReleaseTime() == null) {
                knowledgeArticleDO.setReleaseTime(new Date());
            }
            one.setStatus(0);
            one.setPuplishType(knowledgeArticleDO.getPuplishType());
            one.setPuplishTypeName(knowledgeArticleDO.getPuplishTypeName());
            one.setSource(knowledgeArticleDO.getSource());
            one.setUrl(knowledgeArticleDO.getUrl());
            one.setVedioUrl(knowledgeArticleDO.getVedioUrl());
            one.setRecommendDoctor(knowledgeArticleDO.getRecommendDoctor());
            one.setRecommendDoctorName(knowledgeArticleDO.getRecommendDoctorName());
            if (!articleNeedCheck) {
                one.setStatus(1);
                one.setReleaseStatus(1);
            }
            knowledgeArticleDictDao.save(one);
            return one;
        }
    }
    /**
     * 获取doctorId获取医生发布的文章统计数据
     *
     * @param doctorId
     * @return
     */
    public JSONObject findArticleStaticsByDoctorId(String doctorId) {
        String eulogySql = " select * from base_knowledge_article_doctor kad where kad.type=2 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='" + doctorId + "') ";
        List<Map<String, Object>> mapList = jdbcTemplate.queryForList(eulogySql);//点赞数量
        String startDate = DateUtil.getNextDay(new Date(), -7) + " 00:00:00";
        String endDate = DateUtil.getStringDateShort() + " 23:59:59";
        String dateCondition = " and kad.create_time >='" + startDate + "' and kad.create_time <='" + endDate + "' ";
        String eulogy7Sql = " select * from base_knowledge_article_doctor kad where kad.type=2 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='" + doctorId + "') " + dateCondition;
        List<Map<String, Object>> map7List = jdbcTemplate.queryForList(eulogy7Sql);//7日点赞数量
        //收藏数量
        String collectSql = " select * from base_knowledge_article_doctor kad where kad.type=3 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='" + doctorId + "') ";
        List<Map<String, Object>> collectList = jdbcTemplate.queryForList(collectSql);//收藏数量
        String collect7Sql = " select * from base_knowledge_article_doctor kad where kad.type=3 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='" + doctorId + "') " + dateCondition;
        List<Map<String, Object>> collect7List = jdbcTemplate.queryForList(collect7Sql);//7日收藏数量
        //评论数量
        String commentSql = " select * from base_knowledge_article_doctor kad where kad.type=1 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='" + doctorId + "') ";
        List<Map<String, Object>> commentList = jdbcTemplate.queryForList(commentSql);//评论数量
        String comment7Sql = " select * from base_knowledge_article_doctor kad where kad.type=1 and kad.relation_code in (select ad.id from wlyy_knowledge_article_dict ad where ad.create_user ='" + doctorId + "') " + dateCondition;
        List<Map<String, Object>> comment7List = jdbcTemplate.queryForList(comment7Sql);//7日评论数量
        JSONObject object = new JSONObject();
        object.put("eulogyTotal", mapList.size());//点赞数量
        object.put("eulogy7Total", map7List.size());//7日新增点赞数量
        object.put("collectTotal", collectList.size());//收藏数量
        object.put("collect7Total", collect7List.size());//7日新增收藏数量
        object.put("commentTotal", commentList.size());//评论数量
        object.put("comment7Total", comment7List.size());//7日新增评论数量
        return object;
    }
    //审核/退回文章
    public KnowledgeArticleDictDO reviewArticle(String articleId, Integer status, String reason) throws Exception {
        KnowledgeArticleDictDO knowledgeArticleDO = findById(articleId);
        if (null == knowledgeArticleDO) {
            throw new Exception("该文章不存在");
        } else {
            knowledgeArticleDO.setStatus(status);
            knowledgeArticleDO.setCheckTime(new Date());
            if (StringUtils.isNotBlank(reason)) {
                knowledgeArticleDO.setCancelReason(reason);
            }
            knowledgeArticleDO.setReleaseStatus(status);
            knowledgeArticleDictDao.save(knowledgeArticleDO);
            return knowledgeArticleDO;
        }
    }
    /**
     * 保存文章科室关系
     *
     * @param articleId
     * @param sdJsons
     * @return
     * @throws Exception
     */
    public Boolean saveArticleDept(String articleId, String sdJsons) throws Exception {
        //删除之前关系
        List<KnowledgeArticleDeptDO> list = knowledgeArticleDeptDao.findByArticleId(articleId);
        if (list != null && list.size() > 0) {
            knowledgeArticleDeptDao.deleteAll(list);
        }
        if (org.apache.commons.lang3.StringUtils.isNotBlank(sdJsons)) {
            List<KnowledgeArticleDeptDO> _list = EntityUtils.jsonToList(sdJsons, KnowledgeArticleDeptDO.class);
            if (_list != null && _list.size() > 0) {
                knowledgeArticleDeptDao.saveAll(_list);
            }
        }
        return true;
    }
    /**
     * 查询文章下科室
     *
     * @param articleId
     * @return
     */
    public List<Map<String, Object>> findDeptByArticle(String articleId) throws Exception {
        String sql = "SELECT " +
                " d.article_id AS \"articleId\"," +
                " d.dept as \"dept\", " +
                " d.dept_name AS \"deptName\" " +
                " FROM " +
                " wlyy_knowledge_article t " +
                " JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
                " WHERE " +
                " t.id = '" + articleId + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    /**
     * 查询文章下科室
     *
     * @param articleId
     * @return
     */
    public List<Map<String, Object>> findDeptByArticle2(String articleId) throws Exception {
        String sql = "SELECT " +
                " d.article_id AS \"articleId\"," +
                " d.dept as \"dept\", " +
                " d.dept_name AS \"deptName\" " +
                " FROM " +
                " wlyy_knowledge_article_dict t " +
                " JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
                " WHERE " +
                " t.id = '" + articleId + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    /**
     * 查询部门下的文章
     *
     * @param dept
     * @return
     */
    public List<Map<String, Object>> findArticleByDept2(String dept) throws Exception {
        String sql = "SELECT " +
                " t.id as \"id\", " +
                " t.title as \"title\", " +
                " t.create_time AS \"create_time\" ," +
                " t.image AS \"image\" " +
                " FROM " +
                " wlyy_knowledge_article_dict t " +
                " JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
                " WHERE " +
                " d.dept = '" + dept + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    /**
     * 查询部门下的文章
     *
     * @param dept
     * @return
     */
    public List<Map<String, Object>> findArticleByDept(String dept) throws Exception {
        String sql = "SELECT " +
                " t.id as \"id\", " +
                " t.title as \"title\", " +
                " t.create_time AS \"create_time\" ," +
                " t.image AS \"image\" " +
                " FROM " +
                " wlyy_knowledge_article t " +
                " JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
                " WHERE " +
                " d.dept = '" + dept + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    /**
     * 设置部门发送文章
     *
     * @param dept
     * @param sdJsons
     * @return
     */
    public Boolean saveDeptArticle(String dept, String sdJsons) throws Exception {
        //删除之前关系
        List<KnowledgeArticleDeptDO> dels = knowledgeArticleDeptDao.findByDept(dept);
        if (dels != null && dels.size() > 0) {
            knowledgeArticleDeptDao.deleteAll(dels);
        }
        if (org.apache.commons.lang3.StringUtils.isNotBlank(sdJsons)) {
            List<KnowledgeArticleDeptDO> list = EntityUtils.jsonToList(sdJsons, KnowledgeArticleDeptDO.class);
            if (list != null && list.size() > 0) {
                knowledgeArticleDeptDao.saveAll(list);
            }
        }
        return true;
    }
    public KnowledgeArticleDictDO releaseArticle(String articleId, Integer releaseStatus) {
        String ids[] = articleId.split(",");
        KnowledgeArticleDictDO knowledgeArticleDictDO = new KnowledgeArticleDictDO();
        for (int i = 0; i < ids.length; i++) {
            knowledgeArticleDictDO = findByIdAndDel(ids[i]);
            if (null != knowledgeArticleDictDO) {
                knowledgeArticleDictDO.setReleaseStatus(releaseStatus);
                knowledgeArticleDictDao.save(knowledgeArticleDictDO);
            }
        }
        return knowledgeArticleDictDO;
    }
    /**
     * 患者接收问卷/文章
     *
     * @param businessDOS
     * @return
     */
    public List<BasePatientBusinessDO> sendBusinessToPatient(List<BasePatientBusinessDO> businessDOS) throws Exception {
        if (businessDOS != null && businessDOS.size() != 0) {
            for (BasePatientBusinessDO patientBusinessDO : businessDOS) {
//				BasePatientBusinessDO basePatientBusinessDO = patientBusinessDao.findByPatientAndRelationCodeAndDel(patientBusinessDO.getPatient(),patientBusinessDO.getRelationCode());
//				if (basePatientBusinessDO != null) {
//					//这边要改成能发多次
//					throw new Exception("已发送过!");
//				}
                String sql = "select * from base_patient_business a " +
                        "where a.del=1 and a.patient='" + patientBusinessDO.getPatient() + "' and a.relation_code='" + patientBusinessDO.getRelationCode() + "'";
                List<BasePatientBusinessDO> basePatientBusinessDOList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BasePatientBusinessDO.class));
                if (!basePatientBusinessDOList.isEmpty()) {
                    System.out.println("已经发送过==>" + basePatientBusinessDOList.size() + "次");
                }
                patientBusinessDO.setCreateTime(new Date());
                patientBusinessDO.setUpdateTime(new Date());
                patientBusinessDO.setCreateUser(patientBusinessDO.getDoctor());
                patientBusinessDO.setUpdateUser(patientBusinessDO.getDoctor());
                patientBusinessDO.setCreateUserName(patientBusinessDO.getDoctorName());
                patientBusinessDO.setUpdateUserName(patientBusinessDO.getUpdateUserName());
                patientBusinessDO.setCollection(0);
                patientBusinessDO.setDel(1);
                patientBusinessDO = patientBusinessDao.save(patientBusinessDO);
                if (patientBusinessDO.getRelationType() == 1) {
                    KnowledgeArticleDictDO knowledgeArticleDO = findByIdAndDel(patientBusinessDO.getRelationCode());
                    System.out.println("content:" + JSON.toJSONString(knowledgeArticleDO));
                    JSONObject object = new JSONObject();
                    object.put("id", knowledgeArticleDO.getId());
                    object.put("title", knowledgeArticleDO.getTitle());
                    object.put("content", knowledgeArticleDO.getIntro());
                    object.put("img", knowledgeArticleDO.getImage());
                } else {
                    WlyySurveyUserDO wlyySurveyUserDO = new WlyySurveyUserDO();
                    String doctor = patientBusinessDO.getDoctor();
                    BaseDoctorDO doctorDO = doctorDao.findById(doctor).orElse(null);
                    ;
                    wlyySurveyUserDO.setDept(doctorDO.getVisitDept());
                    wlyySurveyUserDO.setDeptName(doctorDO.getVisitDeptName());
                    wlyySurveyUserDO.setDoctor(doctor);
                    wlyySurveyUserDO.setDoctorName(doctorDO.getName());
                    wlyySurveyUserDO.setStatus(0);
                    wlyySurveyUserDO.setPatient(patientBusinessDO.getPatient());
                    wlyySurveyUserDO.setPatientName(patientBusinessDO.getPatientName());
                    wlyySurveyUserDO.setSurveyTempCode(patientBusinessDO.getRelationCode());
                    wlyySurveyUserDO.setSurveyTempTitle(patientBusinessDO.getRelationName());
                    wlyySurveyUserDO.setCreateTime(new Date());
                    wlyySurveyUserDO.setEndTime(new Date());
                    wlyySurveyUserDO = surveyUserDao.save(wlyySurveyUserDO);
                    JSONObject object = new JSONObject();
                    WlyySurveyTemplateDO wlyySurveyTemplateDO = surveyTemplateDao.findById(wlyySurveyUserDO.getSurveyTempCode()).orElse(null);
                    ;
                    if (null != wlyySurveyTemplateDO) {
                        object.put("title", wlyySurveyTemplateDO.getTitle());
                        object.put("content", wlyySurveyTemplateDO.getTemplateComment());
                        object.put("id", wlyySurveyTemplateDO.getId());
                    }
                }
            }
        }
        return businessDOS;
    }
    /**
     * 设置为1常用或者0不常用
     *
     * @param id
     * @param used
     * @return
     */
    public KnowledgeArticleDictDO setUsed(String id, Integer used, String doctor) {
        KnowledgeArticleDictDO knowledgeArticleDO = findByIdAndDel(id);
        BaseDoctorDO doctorDO = doctorDao.findById(doctor).orElse(null);
        ;
        KnowledgeArticleUserDO knowledgeArticleUserDO = knowledgeArticleUserDao.findByrelationCodeAndUserAndDel(id, doctor);
        if (knowledgeArticleUserDO == null) {
            knowledgeArticleUserDO = new KnowledgeArticleUserDO();
            knowledgeArticleUserDO.setRelationCode(id);
            knowledgeArticleUserDO.setRelationName(knowledgeArticleDO.getTitle());
            knowledgeArticleUserDO.setRelationType(1);
            knowledgeArticleUserDO.setDel(1);
            knowledgeArticleUserDO.setUser(doctor);
            if (doctorDO != null) {
                knowledgeArticleUserDO.setUserName(doctorDO.getName());
                knowledgeArticleUserDO.setCreateUserName(doctorDO.getName());
            }
            knowledgeArticleUserDO.setCreateTime(new Date());
            knowledgeArticleUserDO.setUpdateTime(new Date());
            knowledgeArticleUserDO.setCreateUser(doctor);
            knowledgeArticleUserDO.setUpdateUser(doctor);
            knowledgeArticleUserDO.setUsed(used);
            knowledgeArticleUserDO = knowledgeArticleUserDao.save(knowledgeArticleUserDO);
        }
        if (knowledgeArticleDO != null) {
            if (knowledgeArticleDO.getUsed() != null) {
                if (used == 1) {
                    knowledgeArticleUserDO.setUsed(1);
                    knowledgeArticleDO.setUsed(knowledgeArticleDO.getUsed() + 1);
                } else if (used == 0) {
                    knowledgeArticleUserDO.setUsed(0);
                    knowledgeArticleDO.setUsed(knowledgeArticleDO.getUsed() - 1);
                }
            } else {
                if (used == 1) {
                    knowledgeArticleDO.setUsed(1);
                } else if (used == 0) {
                    knowledgeArticleDO.setUsed(0);
                }
            }
        }
		knowledgeArticleUserDO.setRelationName(knowledgeArticleDO.getTitle());
        knowledgeArticleUserDO.setRelationName(knowledgeArticleDO.getTitle());
        knowledgeArticleUserDao.save(knowledgeArticleUserDO);
		return knowledgeArticleDictDao.save(knowledgeArticleDO);
	}
	public KnowledgeArticleDictDO selectById(String id){
		return findByIdAndDel(id);
	}
	//根据分类查询文章
	public MixEnvelop findArticleByCategoryAndName(String categoryFirst, String categorySecond, String keyWords, Integer page, Integer pageSize){
		MixEnvelop objEnvelop = new MixEnvelop();
		String sql = "select t.id as \"id\",t.title as \"title\",t.read_count as \"readCount\"," +
				"t.collection as \"collection\",t.fabulous as \"fabulous\",t.is_share as \"share\"," +
        return knowledgeArticleDictDao.save(knowledgeArticleDO);
    }
    public KnowledgeArticleDictDO selectById(String id) {
        return findByIdAndDel(id);
    }
    //根据分类查询文章
    public MixEnvelop findArticleByCategoryAndName(String categoryFirst, String categorySecond, String keyWords, Integer page, Integer pageSize) {
        MixEnvelop objEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\",t.title as \"title\",t.read_count as \"readCount\"," +
                "t.collection as \"collection\",t.fabulous as \"fabulous\",t.is_share as \"share\"," +
                " t.intro as \"intro\",t.category_first_name as \"categoryFirstName\"," +
                " t.category_second_name as \"categorySecondName\" ," +
                "t.content as \"content\",t.image as \"image\",t.create_user_name as \"createUserName\",c.job_title_name as \"jobTitleName\"," +
                "b.dept_name as \"deptName\",b.org_name as \"hospitalName\"," +
				"t.create_time as \"createTime\" " +
				" from wlyy_knowledge_article t left join wlyy_knowledge_article_dept a " +
                "t.create_time as \"createTime\" " +
                " from wlyy_knowledge_article t left join wlyy_knowledge_article_dept a " +
                " on a.article_id = t.id left join base_doctor_hospital b on b.doctor_code = t.create_user" +
				" left join base_doctor c on c.id = t.create_user where 1=1 and t.del = 1 and t.status = 1";
		if (StringUtils.isNotBlank(categoryFirst)){
		    sql+=" and t.category_first = '"+categoryFirst+"'";
                " left join base_doctor c on c.id = t.create_user where 1=1 and t.del = 1 and t.status = 1";
        if (StringUtils.isNotBlank(categoryFirst)) {
            sql += " and t.category_first = '" + categoryFirst + "'";
        }
		if (StringUtils.isNotBlank(categorySecond)){
			sql+=" and t.category_second ='"+categorySecond+"'";
		}
        if (StringUtils.isNotBlank(keyWords)){
            sql+=" and (t.create_user_name like '%"+keyWords+"%' or t.title like '%"+keyWords+"%' or t.content like '%"+keyWords+"%' or a.dept_name like '%"+keyWords+"%' )";
        if (StringUtils.isNotBlank(categorySecond)) {
            sql += " and t.category_second ='" + categorySecond + "'";
        }
		sql+=" group by t.id ,t.title ,t.intro,t.category_first_name ,t.category_second_name ,c.job_title_name," +
				"t.read_count,t.collection,t.fabulous,t.is_share,t.content ,t.image ,t.create_user_name ,b.dept_name ,b.org_name,t.create_time " +
				" order by t.create_time desc";
        List<Map<String,Object>> result = hibenateUtils.createSQLQuery(sql,page,pageSize);
        List<Map<String,Object>> countList = hibenateUtils.createSQLQuery(sql);
        if (StringUtils.isNotBlank(keyWords)) {
            sql += " and (t.create_user_name like '%" + keyWords + "%' or t.title like '%" + keyWords + "%' or t.content like '%" + keyWords + "%' or a.dept_name like '%" + keyWords + "%' )";
        }
        sql += " group by t.id ,t.title ,t.intro,t.category_first_name ,t.category_second_name ,c.job_title_name," +
                "t.read_count,t.collection,t.fabulous,t.is_share,t.content ,t.image ,t.create_user_name ,b.dept_name ,b.org_name,t.create_time " +
                " order by t.create_time desc";
        List<Map<String, Object>> result = hibenateUtils.createSQLQuery(sql, page, pageSize);
        List<Map<String, Object>> countList = hibenateUtils.createSQLQuery(sql);
        objEnvelop.setObj(result);
        objEnvelop.setTotalCount(countList.size());
        objEnvelop.setPageSize(pageSize);
        objEnvelop.setCurrPage(page);
        return objEnvelop;
	}
	//根据分类查询文章
	public MixEnvelop findArticleByCategoryAndName2(String categoryFirst, String categorySecond, String keyWords, Integer page, Integer pageSize){
		MixEnvelop objEnvelop = new MixEnvelop();
		String sql = "select t.id as \"id\",t.title as \"title\",t.read_count as \"readCount\"," +
				"t.collection as \"collection\",t.fabulous as \"fabulous\",t.is_share as \"share\"," +
				" t.intro as \"intro\",t.category_first_name as \"categoryFirstName\"," +
				" t.category_second_name as \"categorySecondName\" ," +
				"t.content as \"content\",t.image as \"image\",t.create_user_name as \"createUserName\",c.job_title_name as \"jobTitleName\"," +
				"b.dept_name as \"deptName\",b.org_name as \"hospitalName\"," +
				"t.create_time as \"createTime\" " +
				" from wlyy_knowledge_article_dict t left join wlyy_knowledge_article_dept a " +
				" on a.article_id = t.id left join base_doctor_hospital b on b.doctor_code = t.create_user" +
				" left join base_doctor c on c.id = t.create_user where 1=1 and t.del = 1 and t.status = 1";
		if (StringUtils.isNotBlank(categoryFirst)){
			sql+=" and t.category_first = '"+categoryFirst+"'";
		}
		if (StringUtils.isNotBlank(categorySecond)){
			sql+=" and t.category_second ='"+categorySecond+"'";
		}
		if (StringUtils.isNotBlank(keyWords)){
			sql+=" and (t.create_user_name like '%"+keyWords+"%' or t.title like '%"+keyWords+"%' or t.content like '%"+keyWords+"%' or a.dept_name like '%"+keyWords+"%' )";
		}
		sql+=" group by t.id ,t.title ,t.intro,t.category_first_name ,t.category_second_name ,c.job_title_name," +
				"t.read_count,t.collection,t.fabulous,t.is_share,t.content ,t.image ,t.create_user_name ,b.dept_name ,b.org_name,t.create_time " +
				" order by t.create_time desc";
		List<Map<String,Object>> result = hibenateUtils.createSQLQuery(sql,page,pageSize);
		List<Map<String,Object>> countList = hibenateUtils.createSQLQuery(sql);
		objEnvelop.setObj(result);
		objEnvelop.setTotalCount(countList.size());
		objEnvelop.setPageSize(pageSize);
		objEnvelop.setCurrPage(page);
		return objEnvelop;
	}
	//查询患者收藏的文章列表
	public JSONObject findPatientFavorite2(String patient,Integer page,Integer pageSize){
		String sql = "select t.id as \"id\",t.user_code as \"user\",t.user_name as \"userName\"," +
				"t.relation_code as \"relationCode\"," +
				"t.relation_type as \"relationType\"," +
				"t.relation_name as \"relationName\"," +
				"t.is_read as \"isRead\",t.fabulous as \"fabulous\"," +
				"t.is_share as \"share\"," +
				"t.collection as \"collection\",t.used as \"used\",t.del as \"del\"";
		sql+=" from wlyy_knowledge_article_user t left join wlyy_knowledge_article_dict a" +
				" on t.relation_code = a.id where 1=1 and a.del=1 and a.collection=1 ";
		if (StringUtils.isNotEmpty(patient)){
			sql+=" and t.user_code = '"+patient+"'";
		}
		List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
		if(list!=null&&list.size()>0){
			for (Map<String,Object> map:list){
				String relationCode = map.get("relationCode").toString();
				String type =  map.get("relationType").toString();
				if ("1".equalsIgnoreCase(type)){
					KnowledgeArticleDictDO knowledgeArticleDO = this.selectById(relationCode);
					if (knowledgeArticleDO!=null){
						List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(knowledgeArticleDO.getCreateUser());
						if (doctorHospitalDOS!=null&&doctorHospitalDOS.size()!=0){
							knowledgeArticleDO.setDeptName(doctorHospitalDOS.get(0).getDeptName());
							knowledgeArticleDO.setHospitalName(doctorHospitalDOS.get(0).getOrgName());
						}
					}
					map.put("KnowledgeArticleUserDO",knowledgeArticleDO);
				}
			}
		}
		List<Map<String,Object>> listCount = hibenateUtils.createSQLQuery(sql);
		JSONObject result = new JSONObject();
		result.put("total",listCount.size());
		result.put("detailModelList",list);
		return result;
	}
	//查询患者收藏的文章列表
	public JSONObject findPatientFavorite(String patient,Integer page,Integer pageSize){
		String sql = "select t.id as \"id\",t.user_code as \"user\",t.user_name as \"userName\"," +
				"t.relation_code as \"relationCode\"," +
				"t.relation_type as \"relationType\"," +
				"t.relation_name as \"relationName\"," +
				"t.is_read as \"isRead\",t.fabulous as \"fabulous\"," +
				"t.is_share as \"share\"," +
				"t.collection as \"collection\",t.used as \"used\",t.del as \"del\"";
		sql+=" from wlyy_knowledge_article_user t left join wlyy_knowledge_article a" +
				" on t.relation_code = a.id where 1=1 and a.del=1 and a.collection=1 ";
		if (StringUtils.isNotEmpty(patient)){
			sql+=" and t.user_code = '"+patient+"'";
		}
		List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
		if(list!=null&&list.size()>0){
			for (Map<String,Object> map:list){
				String relationCode = map.get("relationCode").toString();
				String type =  map.get("relationType").toString();
				if ("1".equalsIgnoreCase(type)){
					KnowledgeArticleDictDO knowledgeArticleDO = this.selectById(relationCode);
					if (knowledgeArticleDO!=null){
						List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(knowledgeArticleDO.getCreateUser());
						if (doctorHospitalDOS!=null&&doctorHospitalDOS.size()!=0){
							knowledgeArticleDO.setDeptName(doctorHospitalDOS.get(0).getDeptName());
							knowledgeArticleDO.setHospitalName(doctorHospitalDOS.get(0).getOrgName());
						}
					}
					map.put("KnowledgeArticleUserDO",knowledgeArticleDO);
				}
			}
		}
		List<Map<String,Object>> listCount = hibenateUtils.createSQLQuery(sql);
		JSONObject result = new JSONObject();
		result.put("total",listCount.size());
		result.put("detailModelList",list);
		return result;
	}
    }
    //根据分类查询文章
    public MixEnvelop findArticleByCategoryAndName2(String categoryFirst, String categorySecond, String keyWords, Integer page, Integer pageSize) {
        MixEnvelop objEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\",t.title as \"title\",t.read_count as \"readCount\"," +
                "t.collection as \"collection\",t.fabulous as \"fabulous\",t.is_share as \"share\"," +
                " t.intro as \"intro\",t.category_first_name as \"categoryFirstName\"," +
                " t.category_second_name as \"categorySecondName\" ," +
                "t.content as \"content\",t.image as \"image\",t.create_user_name as \"createUserName\",c.job_title_name as \"jobTitleName\"," +
                "b.dept_name as \"deptName\",b.org_name as \"hospitalName\"," +
                "t.create_time as \"createTime\" " +
                " from wlyy_knowledge_article_dict t left join wlyy_knowledge_article_dept a " +
                " on a.article_id = t.id left join base_doctor_hospital b on b.doctor_code = t.create_user" +
                " left join base_doctor c on c.id = t.create_user where 1=1 and t.del = 1 and t.status = 1";
        if (StringUtils.isNotBlank(categoryFirst)) {
            sql += " and t.category_first = '" + categoryFirst + "'";
        }
        if (StringUtils.isNotBlank(categorySecond)) {
            sql += " and t.category_second ='" + categorySecond + "'";
        }
        if (StringUtils.isNotBlank(keyWords)) {
            sql += " and (t.create_user_name like '%" + keyWords + "%' or t.title like '%" + keyWords + "%' or t.content like '%" + keyWords + "%' or a.dept_name like '%" + keyWords + "%' )";
        }
        sql += " group by t.id ,t.title ,t.intro,t.category_first_name ,t.category_second_name ,c.job_title_name," +
                "t.read_count,t.collection,t.fabulous,t.is_share,t.content ,t.image ,t.create_user_name ,b.dept_name ,b.org_name,t.create_time " +
                " order by t.create_time desc";
        List<Map<String, Object>> result = hibenateUtils.createSQLQuery(sql, page, pageSize);
        List<Map<String, Object>> countList = hibenateUtils.createSQLQuery(sql);
        objEnvelop.setObj(result);
        objEnvelop.setTotalCount(countList.size());
        objEnvelop.setPageSize(pageSize);
        objEnvelop.setCurrPage(page);
        return objEnvelop;
    }
    //查询患者收藏的文章列表
    public JSONObject findPatientFavorite2(String patient, Integer page, Integer pageSize) {
        String sql = "select t.id as \"id\",t.user_code as \"user\",t.user_name as \"userName\"," +
                "t.relation_code as \"relationCode\"," +
                "t.relation_type as \"relationType\"," +
                "t.relation_name as \"relationName\"," +
                "t.is_read as \"isRead\",t.fabulous as \"fabulous\"," +
                "t.is_share as \"share\"," +
                "t.collection as \"collection\",t.used as \"used\",t.del as \"del\"";
        sql += " from wlyy_knowledge_article_user t left join wlyy_knowledge_article_dict a" +
                " on t.relation_code = a.id where 1=1 and a.del=1 and a.collection=1 ";
        if (StringUtils.isNotEmpty(patient)) {
            sql += " and t.user_code = '" + patient + "'";
        }
        List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, page, pageSize);
        if (list != null && list.size() > 0) {
            for (Map<String, Object> map : list) {
                String relationCode = map.get("relationCode").toString();
                String type = map.get("relationType").toString();
                if ("1".equalsIgnoreCase(type)) {
                    KnowledgeArticleDictDO knowledgeArticleDO = this.selectById(relationCode);
                    if (knowledgeArticleDO != null) {
                        List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(knowledgeArticleDO.getCreateUser());
                        if (doctorHospitalDOS != null && doctorHospitalDOS.size() != 0) {
                            knowledgeArticleDO.setDeptName(doctorHospitalDOS.get(0).getDeptName());
                            knowledgeArticleDO.setHospitalName(doctorHospitalDOS.get(0).getOrgName());
                        }
                    }
                    map.put("KnowledgeArticleUserDO", knowledgeArticleDO);
                }
            }
        }
        List<Map<String, Object>> listCount = hibenateUtils.createSQLQuery(sql);
        JSONObject result = new JSONObject();
        result.put("total", listCount.size());
        result.put("detailModelList", list);
        return result;
    }
    //查询患者收藏的文章列表
    public JSONObject findPatientFavorite(String patient, Integer page, Integer pageSize) {
        String sql = "select t.id as \"id\",t.user_code as \"user\",t.user_name as \"userName\"," +
                "t.relation_code as \"relationCode\"," +
                "t.relation_type as \"relationType\"," +
                "t.relation_name as \"relationName\"," +
                "t.is_read as \"isRead\",t.fabulous as \"fabulous\"," +
                "t.is_share as \"share\"," +
                "t.collection as \"collection\",t.used as \"used\",t.del as \"del\"";
        sql += " from wlyy_knowledge_article_user t left join wlyy_knowledge_article a" +
                " on t.relation_code = a.id where 1=1 and a.del=1 and a.collection=1 ";
        if (StringUtils.isNotEmpty(patient)) {
            sql += " and t.user_code = '" + patient + "'";
        }
        List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, page, pageSize);
        if (list != null && list.size() > 0) {
            for (Map<String, Object> map : list) {
                String relationCode = map.get("relationCode").toString();
                String type = map.get("relationType").toString();
                if ("1".equalsIgnoreCase(type)) {
                    KnowledgeArticleDictDO knowledgeArticleDO = this.selectById(relationCode);
                    if (knowledgeArticleDO != null) {
                        List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(knowledgeArticleDO.getCreateUser());
                        if (doctorHospitalDOS != null && doctorHospitalDOS.size() != 0) {
                            knowledgeArticleDO.setDeptName(doctorHospitalDOS.get(0).getDeptName());
                            knowledgeArticleDO.setHospitalName(doctorHospitalDOS.get(0).getOrgName());
                        }
                    }
                    map.put("KnowledgeArticleUserDO", knowledgeArticleDO);
                }
            }
        }
        List<Map<String, Object>> listCount = hibenateUtils.createSQLQuery(sql);
        JSONObject result = new JSONObject();
        result.put("total", listCount.size());
        result.put("detailModelList", list);
        return result;
    }
}

+ 32 - 7
business/base-service/src/main/java/com/yihu/jw/complaint/BaseComplaintService.java

@ -234,6 +234,7 @@ public class BaseComplaintService {
                " t.create_time as \"createTime\"," +
                " t.update_time as \"updateTime\"," +
                " d.photo as \"photo\"," +
                " t.complaint_id as \"complaintId\"," +
                " group_concat(b.name)  as \"name\" " +
                " from base_complaint_doctor t " +
                " INNER join base_complaint_dict b on t.complaint_id=b.id " +
@ -440,7 +441,7 @@ public class BaseComplaintService {
    //查询投诉列表
    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) {
                                        String startTime, String endTime, Integer page, Integer pageSize, String pcAdmin) {
        MixEnvelop mixEnvelop = new MixEnvelop();
        Boolean queryAll = false;
        if ("admin".equalsIgnoreCase(role)) {
@ -480,8 +481,14 @@ public class BaseComplaintService {
                " 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' ";
        //排除撤销的
        sql += " and t.status<>'-1' ";
        if (StringUtils.isBlank(pcAdmin)) {
            //排除撤销的
            sql += " and t.status<>'-1' ";
        } else {
            System.out.println("pc管理员不用排除撤销的");
        }
        if (StringUtils.isNoneBlank(status) && "3".equalsIgnoreCase(status)) {
            sql += " and  g.status='3' ";
        }/*else if (StringUtils.isNoneBlank(status)&&"1".equalsIgnoreCase(status)){
@ -728,7 +735,7 @@ public class BaseComplaintService {
    /*
     * 查询投诉数量*/
    public Map<String, Object> findComplaintCount(String doctor, String role) {
    public Map<String, Object> findComplaintCount(String doctor, String role, String pcAdmin) {
//        BaseComplaintDoctorDO baseComplaintDoctorDO = baseComplaintDoctorDao.findbyDoctorAndDel(doctor);
        String sql = " SELECT t.complaint_id from base_complaint_doctor t where t.is_del='1' and t.doctor='" + doctor + "'";
@ -754,19 +761,34 @@ public class BaseComplaintService {
            }
            if (!queryAll) {
//                if ("808080eb7a194099017a1943fa820004".equalsIgnoreCase(baseComplaintDoctorDO.getComplaintId())) {
                if (flag) {
                    complaints = getCountByStatus(doctor, "0", role);
                    recieve = getCountByStatus(doctor, "1", role);
                    deal = getCountByStatus(doctor, "2", role);
                    passto = getCountByPassto(doctor);
                    total = getCountByStatus(doctor, "", role);
                    //撤销
                    cacel = getCountByStatus(doctor, "-1", role);
                    if (StringUtils.isNotBlank(pcAdmin)) {
                        System.out.println("是pc管理员");
                    } else {
                        total = total - cacel;
                    }
                } else {
                    complaints = getCountByStatus(doctor, "0", role);
                    recieve = getCountByStatus(doctor, "1", role);
                    deal = getCountByStatus(doctor, "2", role);
                    passto = getCountByPassto(doctor);
                    total = getCountByStatus(doctor, "", role);
                    //撤销
                    cacel = getCountByStatus(doctor, "-1", role);
                    if (StringUtils.isNotBlank(pcAdmin)) {
                        System.out.println("是pc管理员");
                    } else {
                        total = total - cacel;
                    }
                }
                //cacel=baseComplaintDao.getCountByStatusAndComplaintId("-1",baseComplaintDoctorDO.getComplaintId());
            } else {
@ -774,9 +796,12 @@ public class BaseComplaintService {
                recieve = baseComplaintDao.getCountByStatus("1");
                deal = baseComplaintDao.getCountByStatus("2");
                cacel = baseComplaintDao.getCountByStatus("-1");
                total = complaints + recieve + deal + cacel;
                total = complaints + recieve + deal;
                if (StringUtils.isNotBlank(pcAdmin)) {
                    //是管理员加上撤销的
                    total = +cacel;
                }
            }
        }
        Map map = new HashMap();
        map.put("complaints", complaints);

+ 571 - 193
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/DsyyPrescriptionService.java

@ -14,6 +14,7 @@ import com.yihu.jw.entity.hospital.healthCare.YlzMedicalRelationDO;
import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.hospital.prescription.*;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.hospital.healthCare.YlzMedicailIcdDao;
@ -87,6 +88,8 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
    //请求内网服务
    public static String entranceUrl = "http://192.168.101.2:10024/dsyy/";
    private final static String updateUrl="http://192.168.101.2:10023/dsyy/updateBySql";
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
@ -283,14 +286,15 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        return prescriptionVOList;
    }
        /**
         * 通过身份证获取卡号
         *
         *
         * @param patient
         * @return
         * @throws Exception
         */
    /**
     * 通过身份证获取卡号
     *
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public JSONArray findCardNo(String patient,boolean demoFlag) throws Exception {
        BasePatientDO patientDO = patientDao.getOne(patient);
        if (patientDO==null){
@ -310,7 +314,7 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
            rs.add(jsonObject);
            return rs;
        }
        patientMedicareCardDao.deleteByPatientId(patient);
        deleteCard(patient);
        JSONArray array = dsyyEntranceService.findCardNo(patientDO.getIdcard());
        for (int i=0;i<array.size();i++){
            JSONObject object = array.getJSONObject(i);
@ -335,6 +339,10 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        return array;
    }
    public void deleteCard(String patient){
        patientMedicareCardDao.deleteByPatientId(patient);
    }
    /**
     * 获取诊断
     *
@ -385,7 +393,7 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
     *
     * @return
     */
    public JSONObject register(String doctor,String dept,String sickId,String clinicclass,String courierflag) throws Exception {
    public JSONObject register(String doctor,String dept,String sickId,String clinicclass,String courierflag,String flag) throws Exception {
        String url = entranceUrl +"registered";
        JSONObject object = new JSONObject();
        Map<String,Object> params = new HashedMap();
@ -394,6 +402,7 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        params.put("sickId",sickId);
        params.put("clinicclass",clinicclass);
        params.put("courierflag",courierflag);
        params.put("flag",flag);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
@ -782,6 +791,146 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        return object;
    }
    /**
     * 回调his预缴金充值
     *
     * @param orderNo
     * @throws Exception
     */
    public JSONObject rechargeHis(String orderNo) throws Exception {
        JSONObject jsonObject1 = new JSONObject();
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(orderNo);
        if (businessOrderDO.getUploadStatus()==null||businessOrderDO.getStatus()==0){
            String cardNo = "";
             if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("1")){
                WlyyOutpatientDO outpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                cardNo = outpatientDO.getCardNo();
            }else if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("2")){
                WlyyOutpatientDO outpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                cardNo = outpatientDO.getCardNo();
            }else if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("3")){
                WlyyOutpatientDO outpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                cardNo = outpatientDO.getCardNo();
            }else if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("6")){
                YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                cardNo=ylzMedicalRelationDO.getCardNo();
            }
            String depositType = "HL";
            String channelType="11";
            String amount=businessOrderDO.getPayPrice()+"";
            String outChargeNo=businessOrderDO.getOrderNo();
            String extra="";
            String notes="预缴金充值";
            String traceNo=businessOrderDO.getTraceNo();
            logger.info("发起预缴金充值接口开始======");
            JSONObject jsonObject = startRechargeToHospital("01",cardNo,depositType,channelType,amount,outChargeNo,extra,notes,traceNo,"");
            logger.info("发起预缴金充值接口结束======");
            //response:{"message":"请求成功","status":200,"obj":"{\"function_name\":\"start_recharge\",\"retCode\":\"99\",\"retMsg\":\"系统中已经存在交易流水号[HLWYY1710423577816808100]\"}"}
            if (jsonObject.getString("status").equalsIgnoreCase("200")){
                JSONObject res = jsonObject.getJSONObject("obj");
                if (!res.getString("retCode").equalsIgnoreCase("99")){
                    logger.info("确认预缴金充值接口开始======");
                    jsonObject1 = rechargeToHospital("01",cardNo,depositType,channelType,amount,outChargeNo,extra,notes,traceNo,"");
                    logger.info("确认预缴金充值接口结束======");
                    businessOrderDO.setUploadStatus(1);
                    businessOrderDao.save(businessOrderDO);
                }
            }
        }
        return jsonObject1;
    }
    /**
     *
     * 发起充值接口
     *
     * @param cardType 卡类型 01
     * @param cardNo 卡号 不为空
     * @param depositType 充值类型
     * @param channelType 渠道 CASH-现金 POS-pos机 ONE_CREDIT-信用就医 L-移动支付
     * @param amount 充值金额
     * @param outChargeNo 交易日志号
     * @param extra 备用参数
     * @param notes 备注说明
     * @param traceNo 平台唯一交易跟踪号
     * @param status 传空
     * @return
     * @throws Exception
     */
    public JSONObject startRechargeToHospital(String cardType,String cardNo,String depositType,String channelType,String amount,String outChargeNo,
                                                     String extra,String notes,String traceNo,String status) throws Exception {
        String url = entranceUrl +"startRecharge";
        JSONObject object = new JSONObject();
        Map<String,Object> params = new HashedMap();
        params.put("operatorId","HLWYY");
        params.put("operatorName","互联网医院");
        params.put("termNo","");
        params.put("cardType",cardType);
        params.put("cardNo",cardNo);
        params.put("accountType","01");
        params.put("depositType",depositType);
        params.put("channelType",channelType);
        params.put("amount",amount);
        params.put("outChargeNo",outChargeNo);
        params.put("extra",extra);
        params.put("notes",notes);
        params.put("traceNo",traceNo);
        params.put("status",status);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        return rs;
    }
    /**
     *
     * 充值确认接口
     *
     * @param cardType 卡类型 01
     * @param cardNo 卡号 不为空
     * @param depositType 充值类型
     * @param channelType 渠道 CASH-现金 POS-pos机 ONE_CREDIT-信用就医 L-移动支付
     * @param amount 充值金额
     * @param outChargeNo 交易日志号
     * @param extra 备用参数
     * @param notes 备注说明
     * @param traceNo 平台唯一交易跟踪号
     * @param status 传空
     * @return
     * @throws Exception
     */
    public JSONObject rechargeToHospital(String cardType,String cardNo,String depositType,String channelType,String amount,String outChargeNo,
                                              String extra,String notes,String traceNo,String status) throws Exception {
        String url = entranceUrl +"recharge";
        JSONObject object = new JSONObject();
        Map<String,Object> params = new HashedMap();
        params.put("operatorId","HLWYY");
        params.put("operatorName","互联网医院");
        params.put("termNo","");
        params.put("cardType",cardType);
        params.put("cardNo",cardNo);
        params.put("accountType","01");
        params.put("depositType",depositType);
        params.put("channelType",channelType);
        params.put("amount",amount);
        params.put("outChargeNo",outChargeNo);
        params.put("extra",extra);
        params.put("notes",notes);
        params.put("traceNo",traceNo);
        params.put("status",status);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        return rs;
    }
    /**
     * 互联网医院通知院内摆药
     *
@ -840,154 +989,312 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
    }
    /**
     * 数据哈希计算接口
     *
     * @param contentJson
     * 获取医生签名图片
     * @param doctor
     * @return
     */
    public JSONObject getSignPicture(String doctor){
        try {
            BaseDoctorDO doctorDO = baseDoctorDao.findByIdAndDel(doctor);
            if (doctorDO==null){
                throw new Exception("医生信息不存在!");
            }
            JSONObject response = synDoctorSearch(doctorDO.getIdcard());
            JSONObject object = new JSONObject();
            if (response!=null){
                JSONObject data = response.getJSONObject("data");
                object.put("code","1000");
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("image",data.getString("stamp"));
                object.put("data",jsonObject);
            }
            logger.info("医生签名图片 getSignPicture :"+response.toJSONString());
            return object;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 处方签名
     * @param prescriptionId
     * @return
     * @throws Exception
     */
    public JSONObject computeDigestForAlg(String contentJson) throws Exception {
        String url = entranceUrl +"computeDigestForAlg";
        JSONObject object = new JSONObject();
    public String SOF_SignDataWithExtraInfo(String prescriptionId) throws Exception {
        String url = entranceUrl +"SOF_SignDataWithExtraInfo";
        String result = "";
        Map<String,Object> params = new HashedMap();
        params.put("content",contentJson);
        params.put("prescriptionId",prescriptionId);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        Integer status = rs.getInteger("status");
        if (status==200){
            object = rs.getJSONObject("obj");
            result = rs.getString("obj");
        }
        return object;
        return result;
    }
    /**
     * 数据签名接口
     * @param templateId 模板ID签名数据摘要数据类型
     * @param urId 签名流水ID
     * @param patientName 患者姓名
     * @param patientAge 患者年龄
     * @param patientSex 患者性别
     * @param patientCardType  证件类型
     * @param recipeTime 开具时间
     * @param hashValue Hash原文(从签名指纹接口结果中得到的)
     * @param hashType Hash算法(从签名指纹接口结果中得到的)
     * 病历签名
     * @param prescriptionId
     * @return
     * @throws Exception
     */
    public JSONObject synRecipeInfo(String templateId,String urId,String patientName,String patientAge,
                                    String patientSex,String patientCardType,String recipeTime,
                                    String hashValue,String hashType,String openId,String patientCard) throws Exception {
        String url = entranceUrl +"synRecipeInfo";
        JSONObject object = new JSONObject();
    public String SOF_SignDataWithExtraInfoEmr(String prescriptionId) throws Exception {
        String url = entranceUrl +"SOF_SignDataWithExtraInfoEmr";
        String result = "";
        Map<String,Object> params = new HashedMap();
        params.put("templateId",templateId);
        params.put("urId",urId);
        params.put("patientName",patientName);
        params.put("patientAge",patientAge);
        params.put("patientSex",patientSex);
        params.put("patientCardType",patientCardType);
        params.put("recipeTime",recipeTime);
        params.put("hashValue",hashValue);
        params.put("hashType",hashType);
        params.put("openId",openId);
        params.put("patientCard",patientCard);
        params.put("prescriptionId",prescriptionId);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        Integer status = rs.getInteger("status");
        if (status==200){
            object = rs.getJSONObject("obj");
            result = rs.getString("obj");
        }
        return object;
        return result;
    }
    /**
     * 处方签名
     * @param prescriptionDO
     * 查询ca用户信息
     * @param idcard
     * @return
     * @throws Exception
     */
    public String SOF_SignDataWithExtraInfo(WlyyPrescriptionDO prescriptionDO) throws Exception {
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(prescriptionDO.getOutpatientId()).orElse(null);
        List<WlyyPrescriptionInfoDO> infoDOS = prescriptionInfoDao.findByPrescriptionId(prescriptionDO.getId(), 1);
        List<WlyyPrescriptionDiagnosisDO> diagnosisDOS = prescriptionDiagnosisDao.findByPrescriptionId(prescriptionDO.getId(),1);
    public JSONObject synDoctorSearch(String idcard) throws Exception {
        String url = entranceUrl +"synDoctorSearch";
        JSONObject object = new JSONObject();
        String baseSign="";
        object.put("infos",infoDOS);
        object.put("registerSn",outpatientDO.getRegisterNo());
        object.put("diagnosiss",diagnosisDOS);
        JSONObject jsonObject = computeDigestForAlg(object.toJSONString());
        String hashValue = null;
        String hashType = null;
        if (jsonObject.getString("status").equalsIgnoreCase("0")){
            JSONObject data = jsonObject.getJSONObject("data");
            hashValue= data.getString("hashValue");
            hashType = data.getString("hashType");
        Map<String,Object> params = new HashedMap();
        params.put("userIdcardNum",idcard);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        Integer status = rs.getInteger("status");
        if (status==200){
            object = rs.getJSONObject("message");
        }
        return object;
    }
        BasePatientDO patientDO = patientDao.findById(outpatientDO.getPatient()).orElse(null);
        BaseDoctorDO doctorDO = doctorDao.findByIdAndDel(outpatientDO.getDoctor());
        if (patientDO!=null&&doctorDO!=null){
            String patientName = patientDO.getName();
            Integer patientAge = IdCardUtil.getAgeForIdcard(patientDO.getIdcard());
            String patientSex = IdCardUtil.getSexForIdcard(patientDO.getIdcard());
            String recipeTime = DateUtil.dateToStrLong(prescriptionDO.getCreateTime());
            String openId = doctorDO.getOpenid();
            String idcard = patientDO.getIdcard();
            if (hashType!=null&&hashValue!=null){
                JSONObject object1 = synRecipeInfo("hash_004",getCode(),patientName,patientAge.toString(),patientSex,"SF",recipeTime,hashValue,hashType,openId,idcard);
                if (object1.getString("status").equalsIgnoreCase("0")){
                    logger.info("西药处方签名成功"+object1);
                    JSONObject jsonObject1 = JSONObject.parseObject(object1.getString("data"));
                    if (jsonObject1!=null){
                        baseSign=jsonObject1.getString("stamp");
                    }
    /**
     * 电子病历保存
     * @param prescriptionId
     * @return
     * @throws Exception
     */
    public String dzblSave(String prescriptionId) throws Exception {
        String url = entranceUrl +"dzblSave";
        String result = "";
        Map<String,Object> params = new HashedMap();
        params.put("prescriptionId",prescriptionId);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        Integer status = rs.getInteger("status");
        if (status==200){
            if (StringUtils.isNoneBlank(rs.getString("obj"))){
                JSONObject jsonObject = JSONObject.parseObject(rs.getString("obj"));
                if (jsonObject.getString("RESULT_CODE").equalsIgnoreCase("true")){
                    logger.info("病历保存成功"+rs.toJSONString());
                }
            }
            result = rs.getString("obj");
        }
        return baseSign;
        logger.info("病历保存日志=="+rs.toJSONString());
        return result;
    }
    /**
     * 病历签名
     * @param prescriptionDO
     * 查询病历文书
     *
     * @param patientId
     * @param eventNo
     * @return
     * @throws Exception
     */
    public void SOF_SignDataWithExtraInfoEmr(WlyyPrescriptionDO prescriptionDO) throws Exception {
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(prescriptionDO.getOutpatientId()).orElse(null);
        WlyyPrescriptionEmrDO prescriptionEmrDO = prescriptionEmrDao.findEmrByPrescriptionId(prescriptionDO.getId());
        JSONObject object = new JSONObject();
        object.put("emr",prescriptionEmrDO);
        object.put("registerSn",outpatientDO.getRegisterNo());
        object.put("doctorName",outpatientDO.getDoctorName());
        object.put("patientName",outpatientDO.getPatientName());
        JSONObject jsonObject = computeDigestForAlg(object.toJSONString());
        String hashValue = null;
        String hashType = null;
        if (jsonObject.getString("status").equalsIgnoreCase("0")){
            JSONObject data = jsonObject.getJSONObject("data");
            hashValue= data.getString("hashValue");
            hashType = data.getString("hashType");
    public JSONArray selectHistoryEmrFromEntrance(String patientId,String eventNo) throws Exception {
       JSONArray array =dsyyEntranceService.selectHistoryEmrFromEntrance(patientId,eventNo);
       JSONArray jsonArray = new JSONArray();
       for (int i=0;i<array.size();i++){
           JSONObject object = array.getJSONObject(i);
           String PATIENT = object.getString("PATIENT");
           String OPID = object.getString("OPID");
           String res = selectHistoryEmrRecordJcpt(PATIENT,OPID);
           if (StringUtils.isNoneBlank(res)){
               jsonArray.add(object);
           }
       }
        return jsonArray;
    }
    /**
     * 查询历次就诊门诊病历文书集成平台
     * @param patientId 病人id
     * @param eventNo 就诊次数
     * @return
     */
    public String selectHistoryEmrRecordJcpt(String patientId,String eventNo) throws Exception {
        String url = entranceUrl +"selectEmrInfoIdJcpt";
        String object = "";
        Map<String,Object> params = new HashedMap();
        params.put("patientId",patientId);
        params.put("visitNo",eventNo);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        Integer status = rs.getInteger("status");
        if (status==200){
            object = rs.getString("obj");
        }
        return object;
    }
        BasePatientDO patientDO = patientDao.findById(outpatientDO.getPatient()).orElse(null);
        BaseDoctorDO doctorDO = doctorDao.findByIdAndDel(outpatientDO.getDoctor());
        if (patientDO!=null&&doctorDO!=null){
            String patientName = patientDO.getName();
            Integer patientAge = IdCardUtil.getAgeForIdcard(patientDO.getIdcard());
            String patientSex = IdCardUtil.getSexForIdcard(patientDO.getIdcard());
            String recipeTime = DateUtil.dateToStrLong(prescriptionDO.getCreateTime());
            String openId = doctorDO.getOpenid();
            String idcard = patientDO.getIdcard();
            if (hashType!=null&&hashValue!=null){
                JSONObject object1 = synRecipeInfo("hash_002",getCode(),patientName,patientAge.toString(),patientSex,"SF",recipeTime,hashValue,hashType,openId,idcard);
                if (object1.getString("status").equalsIgnoreCase("0")){
                    logger.info("门诊病历签名成功"+object1);
                }
            }
    /**
     * 查询历次就诊门诊病历文书
     * @param patientId 病人id
     * @param eventNo 就诊次数
     * @return
     */
    public String selectHistoryEmrRecord(String patientId,String eventNo) throws Exception {
        String url = entranceUrl +"selectEmrInfoId";
        String object = "";
        Map<String,Object> params = new HashedMap();
        params.put("patientId",patientId);
        params.put("visitNo",eventNo);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        Integer status = rs.getInteger("status");
        if (status==200){
            object = rs.getString("detailModelList");
        }
        return object;
    }
    //=====================合理用药内网调用接口=======================
    /**
     * 合理用药审核
     *
     *
     * @param outpatient
     * @param prescriptionOnly
     * @param payType
     * @param doctor
     * @param patient
     * @param diagnosisDOS
     * @param infos
     * @return
     * @throws Exception
     */
    public String dsyyCheckInfo(String outpatient,String prescriptionOnly,String payType,String doctor,String patient,String diagnosisDOS, String infos) throws Exception {
        String url = entranceUrl +"dsyyCheckInfo";
        String jsonObject = "";
        Map<String,Object> params = new HashedMap();
        params.put("outpatient",outpatient);
        params.put("prescriptionOnly",prescriptionOnly);
        params.put("payType",payType);
        params.put("doctor",doctor);
        params.put("patient",patient);
        params.put("diagnosisDOS",diagnosisDOS);
        params.put("infos",infos);
        logger.info("params=="+params);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        if(rs.getInteger("status")==200){
            jsonObject = rs.getString("message");
        }
        return jsonObject;
    }
    /**
     * 处方在医生站系统成功保存后调用
     *
     *
     * @param outpatient
     * @param prescriptionOnly
     * @param payType
     * @param doctor
     * @param patient
     * @param diagnosisDOS
     * @param infos
     * @return
     * @throws Exception
     */
    public String dsyySaveCheckInfo(String outpatient,String prescriptionOnly,String payType,String doctor,String patient,String diagnosisDOS, String infos) throws Exception {
        String url = entranceUrl +"dsyySaveCheckInfo";
        String jsonObject = "";
        Map<String,Object> params = new HashedMap();
        params.put("outpatient",outpatient);
        params.put("prescriptionOnly",prescriptionOnly);
        params.put("payType",payType);
        params.put("doctor",doctor);
        params.put("patient",patient);
        params.put("diagnosisDOS",diagnosisDOS);
        params.put("infos",infos);
        logger.info("params=="+params);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        if(rs.getInteger("status")==200){
            jsonObject = rs.getString("message");
        }
        return jsonObject;
    }
    /**
     * 处方保存成功后,发送给审方系统进行人工审方
     *
     *
     * @param outpatient
     * @param prescriptionOnly
     * @param payType
     * @param doctor
     * @param patient
     * @param diagnosisDOS
     * @param infos
     * @return
     * @throws Exception
     */
    public String dsyyValidCheckInfo(String outpatient,String prescriptionOnly,String payType,String doctor,String patient,String diagnosisDOS, String infos) throws Exception {
        String url = entranceUrl +"dsyyValidCheckInfo";
        String jsonObject = "";
        Map<String,Object> params = new HashedMap();
        params.put("outpatient",outpatient);
        params.put("prescriptionOnly",prescriptionOnly);
        params.put("payType",payType);
        params.put("doctor",doctor);
        params.put("patient",patient);
        params.put("diagnosisDOS",diagnosisDOS);
        params.put("infos",infos);
        logger.info("params=="+params);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        if(rs.getInteger("status")==200){
            jsonObject = rs.getString("message");
        }
        return jsonObject;
    }
    //========================调用内网服务结束===================
@ -1000,7 +1307,7 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
     * @return
     */
    public JSONObject registerOutPatient(String outPatientId, String doctor){
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(outPatientId).orElse(null);
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(outPatientId).get();
        List<WlyyPrescriptionExpressageDO> expressageDOS =prescriptionExpressageDao.findByOutpatientId(outPatientId);
        DoctorMappingDO doctorMappingDO = doctorMappingDao.findByDoctor(doctor);
        BaseDoctorDO doctorDO = baseDoctorDao.findByIdAndDel(doctor);
@ -1061,7 +1368,13 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        }
        JSONObject res = null;
        try {
            res = register(doctorFlag,outpatientDO.getDept(),patientMappingDO.getMappingCode(),chargeType,courierflag);
            String flag = "";
            if (!StringUtils.isNoneBlank(outpatientDO.getMedicalState())) {
                flag = "0";
            }else {
                flag = outpatientDO.getMedicalState();
            }
            res = register(doctorFlag,outpatientDO.getDept(),patientMappingDO.getMappingCode(),chargeType,courierflag,flag);
        } catch (Exception e) {
            e.printStackTrace();
        }
@ -1206,20 +1519,18 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        if (expressageDO!=null){
            if (expressageDO.getOneselfPickupFlg()==0){
                Object result=getSFExpressInfoNew(registerNo,realorder,"");
                logger.info("顺丰下单完成信息=="+result.toString());
                String re = result.toString();
                if (re!=null){
                    JSONObject object = JSONObject.parseObject(re);
                    if (object.getString("code").equalsIgnoreCase("SUCCESS"));
                    JSONArray jsonArray = object.getJSONArray("result");
                    JSONObject jsonObject = jsonArray.getJSONObject(0);
                    String sfOrder = jsonObject.getString("mainMailNo");
                    String sfOrder = object.getString("mainMailNo");
                    String address = expressageDO.getProvinceName()+expressageDO.getCityName()+expressageDO.getTownName()+expressageDO.getStreetName()+expressageDO.getAddress();
                    String phone = expressageDO.getMobile();
                    String remark = expressageDO.getRemark();
                    String cardNo = outpatientDO.getCardNo();
                    String isExpress = "是";
                    String isExpress = "1";
                    if (expressageDO.getOneselfPickupFlg()==1){
                        isExpress = "否";
                        isExpress = "0";
                    }
                    return  sendDispensingToHisToHospital(registerNo,cardNo,isExpress,sfOrder,address,phone,remark);
                }else {
@ -1277,20 +1588,6 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
                            //处方已下单成功
                            System.out.println("获取顺丰物流面单信息:4");
                        } else {
                            //如果该处方的快递单号未生成,则继续下单
                            //根据业务订单号判断是否已经下单成功
                            //--2020.05.20--顺丰V2.0接口已不提供查询接口,直接单下单--START
//                    boolean go_on = sfexpressService.sfOrderSearchService(sfexpress_obj);
//
//                    //如果该业务订单号未下单成功过,则重新下单
//                    if(go_on){
//                        //请求顺丰接口下单,成功下单后,返回快递单号
//                        sfexpress_obj = sfexpressService.postSFOrderService(sfexpress_obj);
//                        //保存快递单号和增加处方物流记录为配送
//                        sfexpressService.updatePrescriptionExpressage(sfexpress_obj);
//                    }
                            //--2020.05.20--顺丰V2.0接口已不提供查询接口,直接单下单--END
                            //请求顺丰接口下单,成功下单后,返回快递单号
                            sfexpress_obj = sfexpressService.postSFOrderService(sfexpress_obj);
                            System.out.println("获取顺丰物流面单信息:5");
@ -1305,35 +1602,6 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
                            com.alibaba.fastjson.JSONObject object = sfexpressService.postSFOrderQueryService(sfexpress_obj);
                            System.out.println("获取顺丰物流面单信息7-1"+object.toJSONString());
                            System.out.println("获取顺丰物流面单信息:7");
                            /* com.alibaba.fastjson.JSONObject sfJsonObject = new com.alibaba.fastjson.JSONObject();*/
                    /*sfJsonObject.put("mailno", sfexpress_obj.getMailno());
                    sfJsonObject.put("mailtype", "标准快递");
                    sfJsonObject.put("destcode", object.getString("destRouteLabel"));
                    if (wxId.equalsIgnoreCase("xm_zsyy_wx")) {
                        sfJsonObject.put("j_name", "厦门大学附属中山医院");
                        sfJsonObject.put("j_phone", "4003008888");
                        sfJsonObject.put("j_townName", "思明区");
                        sfJsonObject.put("j_address", "湖滨南路201-209号");
                    } else if (wxId.equalsIgnoreCase("xm_ykyy_wx")) {
                        sfJsonObject.put("j_name", "厦门大学附属中山医院");
                        sfJsonObject.put("j_phone", "4003008888");
                        sfJsonObject.put("j_townName", "思明区");
                        sfJsonObject.put("j_address", "湖滨南路201-209号");
                    }
                    sfJsonObject.put("j_provinceName", "福建省");
                    sfJsonObject.put("j_cityName", "厦门市");
                    sfJsonObject.put("d_name", sfexpress_obj.getName());
                    sfJsonObject.put("d_provinceName", sfexpress_obj.getProvinceName());
                    sfJsonObject.put("d_cityName", sfexpress_obj.getCityName());
                    sfJsonObject.put("d_townName", sfexpress_obj.getTownName());
                    sfJsonObject.put("d_address", sfexpress_obj.getAddress());
                    sfJsonObject.put("d_phone", sfexpress_obj.getMobile());
                    sfJsonObject.put("express_type", 11);
                    sfJsonObject.put("pay_method", 2);
                    sfJsonObject.put("receive_time", "");
                    sfJsonObject.put("dispensaryType", 2);*/
                            result = object;
                            System.out.println("获取顺丰物流面单信息:8");
                        }
@ -1373,7 +1641,7 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        //请求his获取待结算存储
        Map<String,Object> params = new HashedMap();
        String url =entranceUrl +"getSettlement";
        params.put("cardType","cardType");
        params.put("cardType",cardType);
        params.put("cardNo",cardno);
        params.put("hismzlsh",outpatientDO.getRegisterNo());
        params.put("operatorId","HLWYY");
@ -1387,6 +1655,9 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        JSONObject resObj = new JSONObject();
        if (resStatus==200){
            resObj = rs3.getJSONObject("obj");
            if (resObj.getString("retCode").equalsIgnoreCase("99")){
                throw  new Exception(resObj.getString("retMsg"));
            }
        }
        //获取his结算基本信息表
        String basicSql ="select * from SST_JSDP_JBXX_GJYB where CARD_NO ='"+cardno+"'";
@ -1568,8 +1839,20 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
    }
    public String updateUrl(String sql) throws Exception {
        Map<String,Object> params = new HashedMap();
        params.put("sql",sql);
        logger.info("sql语句:"+sql);
        HttpResponse response = HttpUtils.doGet(updateUrl,params);
        String content = response.getContent();
        logger.info("response:"+content);
        return content;
    }
    /**
     * 确认医保结算
     * 确认his结算
     *
     *
     * @param outpatientId
     * @return
@ -1599,36 +1882,129 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
                outChargeNo = businessOrderDO.getTraceNo();
                orderNo = businessOrderDO.getOrderNo();
            }
            if (ylzMedicalRelationDO.getMedicalState()==null||(ylzMedicalRelationDO.getMedicalState()!=null&&ylzMedicalRelationDO.getMedicalState()==0)){
            if (ylzMedicalRelationDO.getMedicalState()==null||(ylzMedicalRelationDO.getMedicalState()!=null&&ylzMedicalRelationDO.getMedicalState()==0)){
                String sql = "update SST_JSDP_JBXX_GJYB\n" +
                        "   set SETL_ID           = '', \n" +
                        "       ACCT_PAY          = '0',\n" +
                        "       PSN_CASH_PAY      = '"+ylzMedicalRelationDO.getPersonCash()+"',\n" +
                        "       FUND_PAY_SUMAMT   = '0',\n" +
                        "       CVLSERV_PAY       = '0',\n" +
                        "       PSN_PART_AMT      = '0',\n" +
                        "       HIFMI_PAY         = '0',\n" +
                        "       MEDFEE_SUMAMT     = '"+ylzMedicalRelationDO.getBcwkje()+"',\n" +
                        "       SETL_TIME         = '0',\n" +
                        "       BALC              = '0',\n" +
                        "       ACCT_MULAID_PAY   = '0',\n" +
                        "       HIFOB_PAY         = '0',\n" +
                        "       MDTRT_ID          = '',\n" +
                        "       HIFP_PAY          = '0',\n" +
                        "       MAF_PAY           = '',\n" +
                        "       OTH_PAY           = '0',\n" +
                        "       HIFES_PAY         = '0',\n" +
                        "       OUTCHARGENO       = '"+orderNo+"',\n" +
                        "       PSN_CERT_TYPE     = '0',\n" +
                        "       NATY              = '0',\n" +
                        "       BRDY              = '0',\n" +
                        "       CVLSERV_FLAG      = '0',\n" +
                        "       ACT_PAY_DEDC      = '0',\n" +
                        "       PSN_TYPE          = '0',\n" +
                        "       HOSP_PART_AMT     = '0',\n" +
                        "       CLR_OPTINS        = '0',\n" +
                        "       CLR_WAY           = '0',\n" +
                        "       CLR_TYPE          = '0',\n" +
                        "       POOL_PROP_SELFPAY = '0',\n" +
                        "       INSUPLC_ADMDVS    = '',\n" +
                        "       INSUTYPE          = '',\n" +
                        "       PSN_NO            = '',\n" +
                        "       CHANNEL_TYPE      = '',\n" +
                        "       ACSIGN_TYPE       = 'null',\n" +
                        "       MDTRT_CERT_TYPE   = '03',\n" +
                        "       CVL_ACCT_PAY      = '0',\n" +
                        "       CVL_ACCT_BALC     = '0',\n" +
                        "       HL_ACCT_PAY       = '0',\n" +
                        "       HL_ACCT_BALC      = '0',\n" +
                        "       FM_ACCT_BALC      = '0',\n" +
                        "       PUR_ACCT_PAY      = '0'\n" +
                        " where 1 = 1\n" +
                        "   and LOG_NO = '"+ylzMedicalRelationDO.getLogNo()+"'";
                //结算更新
                System.out.println("sql=="+sql);
                String res = updateUrl(sql);
            }else {
                String sql = "update SST_JSDP_JBXX_GJYB\n" +
                        "   set SETL_ID      = '"+ylzMedicalRelationDO.getBillSerial()+"',\n" +
                        "       PSN_CASH_PAY      = '"+ylzMedicalRelationDO.getPersonCash()+"',\n" +
                        "       MEDFEE_SUMAMT     = '"+ylzMedicalRelationDO.getBcwkje()+"',\n" +
                        "       HIFOB_PAY         = '0',\n" +
                        "       OUTCHARGENO       = '"+orderNo+"',\n" +
                        "       BRDY              = '0',\n" +
                        "       CVLSERV_FLAG      = '0',\n" +
                        "       HOSP_PART_AMT     = '0',\n" +
                        "       POOL_PROP_SELFPAY = '0',\n" +
                        "       INSUPLC_ADMDVS    = '"+ylzMedicalRelationDO.getAdministrativeArea()+"',\n" +
                        "       INSUTYPE          = '"+ylzMedicalRelationDO.getInsuranceType()+"',\n" +
                        "       PSN_NO            = '',\n" +
                        "       CHANNEL_TYPE      = '',\n" +
                        "       ACSIGN_TYPE       = 'null',\n" +
                        "       MDTRT_CERT_TYPE   = '03',\n" +
                        "       CVL_ACCT_PAY      = '0',\n" +
                        "       CVL_ACCT_BALC     = '0',\n" +
                        "       HL_ACCT_PAY       = '0',\n" +
                        "       HL_ACCT_BALC      = '0',\n" +
                        "       FM_ACCT_BALC      = '0',\n" +
                        "       PUR_ACCT_PAY      = '0',\n" +
                        "       CHRG_BCHNO      = '"+ylzMedicalRelationDO.getBillSerial()+"',\n" +
                        "       MDTRT_ID      = '"+ylzMedicalRelationDO.getInsuranceSerial()+"',\n" +
                        "       PSN_CERT_TYPE      = '"+ylzMedicalRelationDO.getCertType()+"',\n" +
                        "       NATY      = '"+ylzMedicalRelationDO.getCertType()+"',\n" +
                        "       PSN_TYPE      = '"+ylzMedicalRelationDO.getTreatmentType()+"',\n" +
                        "       RYDYMC      = '"+ylzMedicalRelationDO.getTreatmentTypeName()+"',\n" +
                        "       YBDYZT      = '"+(StringUtils.isNoneBlank(ylzMedicalRelationDO.getTreatmentStatus())?ylzMedicalRelationDO.getTreatmentStatus():0)+"',\n" +
                        "       YBDYMC      = '"+(StringUtils.isNoneBlank(ylzMedicalRelationDO.getTreatmentStatusName())?ylzMedicalRelationDO.getTreatmentStatusName():"")+"',\n" +
                        "       YDJYLX      = '"+ylzMedicalRelationDO.getAllopatryType()+"',\n" +
                        "       YDLXMC      = '"+ylzMedicalRelationDO.getAllopatryTypeName()+"',\n" +
                        "       ACT_PAY_DEDC = '"+ylzMedicalRelationDO.getPayStandard()+"',\n" +
                        "       HIFP_PAY      = '"+ylzMedicalRelationDO.getTcjjPay()+"',\n" +
                        "       CVLSERV_PAY = '"+ylzMedicalRelationDO.getGwyPay()+"',\n" +
                        "       HIFES_PAY      = '"+ylzMedicalRelationDO.getEnterpriseSupplement()+"',\n" +
                        "       HIFMI_PAY      = '"+ylzMedicalRelationDO.getSbjjPay()+"',\n" +
                        "       MAF_PAY      = '"+ylzMedicalRelationDO.getYljzPay()+"',\n" +
                        "       OTH_PAY      = '"+ylzMedicalRelationDO.getOtherPay()+"',\n" +
                        "       PSN_PART_AMT      = '"+ylzMedicalRelationDO.getPersonCash()+"',\n" +
                        "       ACCT_PAY      = '"+ylzMedicalRelationDO.getPersonAccount()+"',\n" +
                        "       BALC      = '"+ylzMedicalRelationDO.getAccountBalance()+"',\n" +
                        "       ACCT_MULAID_PAY = '"+ylzMedicalRelationDO.getJtgjPay()+"',\n" +
                        "       CLR_WAY = '"+(StringUtils.isNoneBlank(ylzMedicalRelationDO.getClrWay())?ylzMedicalRelationDO.getClrWay():0)+"',\n" +
                        "       CLR_OPTINS = '"+(StringUtils.isNoneBlank(ylzMedicalRelationDO.getClrOptins())?ylzMedicalRelationDO.getClrOptins():0)+"',\n" +
                        "       CLR_TYPE = '"+(StringUtils.isNoneBlank(ylzMedicalRelationDO.getClrType())?ylzMedicalRelationDO.getClrType():0)+"',\n" +
                        "       FUND_PAY_SUMAMT = '"+ylzMedicalRelationDO.getMedicalPrice()+"',\n" +
                        "       SETL_TIME = '"+DateUtil.dateToStrShort(ylzMedicalRelationDO.getPayDate())+"',\n" +
                        "       OUTYBSFJSON = '"+ylzMedicalRelationDO.getOutJson()+"'\n" +
                        " where 1 = 1\n" +
                        "   and LOG_NO = '"+ylzMedicalRelationDO.getLogNo()+"'";
                //结算更新
                System.out.println("sql=="+sql);
                String res = updateUrl(sql);
                logger.info("结算成功更新日志:"+res);
            }
            Map<String,Object> params = new HashedMap();
            String url ="" +"comfirmSettleMent";
            params.put("mct","03");
            params.put("mcn",ylzMedicalRelationDO.getCardNo());
            params.put("xtgzh0",ylzMedicalRelationDO.getLogNo());
            HttpResponse response = HttpUtils.doGet(url,params);
            System.out.println("response=="+response.getContent());
            String res = response.getContent();
            if (!StringUtils.isNoneBlank(outChargeNo)){
                outChargeNo=ylzMedicalRelationDO.getHisBillSerial();
            }
            String operatorId = "HLWYY";
            String operatorName = "互联网医院";
            String termNo = "DSYYHLWYY";
            JSONObject rsObj = confirmPayGjybToHospital(ylzMedicalRelationDO.getCardNo(),ylzMedicalRelationDO.getLogNo(),depositAmount,outChargeNo, operatorId,operatorName,termNo);
            logger.info("");
            boolean flag = true;
            if (StringUtils.isNoneBlank(res)){
                JSONObject jsonObject = JSONObject.parseObject(res);
                String status = jsonObject.getString("status");
                if (status.equalsIgnoreCase("200")){
                    JSONObject obj = jsonObject.getJSONObject("obj");
                    String rs = obj.getString("rs");
                    JSONObject rsObj = JSONObject.parseObject(rs);
                    String retCode = rsObj.getString("retCode");
                    if (retCode.equalsIgnoreCase("99")){
                        flag=false;
                        throw new Exception(rsObj.getString("retMsg"));
                    }
                }else {
                    flag = false;
            if (rsObj!=null){
                String retCode = rsObj.getString("retCode");
                if (retCode.equalsIgnoreCase("99")){
                    flag=false;
                    throw new Exception(rsObj.getString("retMsg"));
                }
            }else {
                flag=false;
            }
            if (flag){
                ylzMedicalRelationDO.setState(1);
@ -1665,7 +2041,7 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
                }
                try {
                    logger.info("=================电子发票开具开始=================");
               /*     dsyyEntranceService.OutpatientInvoicing(ylzMedicalRelationDO.getHisBillSerial(),"lb");*/
                   /* hcyyEntranceService.OutpatientInvoicing(ylzMedicalRelationDO.getHisBillSerial(),"lb");*/
                    logger.info("=================电子发票开具结束=================");
                }catch (Exception e){
                    e.printStackTrace();
@ -1680,4 +2056,6 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
            throw new Exception(e.getMessage());
        }
    }
}

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

@ -346,6 +346,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    private ServiceItemPlanDao serviceItemPlanDao;
    @Autowired
    private WlyyBusinessService wlyyBusinessService;
    @Autowired
    private DsyyEntranceService dsyyEntranceService;
    public static String entranceUrl = "http://172.16.100.240:10023/xzzx/";
@ -10451,113 +10453,56 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                    e.printStackTrace();
                }
            }else if (wxId.equalsIgnoreCase("xm_dsyy_wx")){
                try {
                    if (prescriptionDiagnosisDOS!=null&&prescriptionDiagnosisDOS.size()!=0){
                        String diagnosisName = prescriptionDiagnosisDOS.get(0).getName();
                        String diagnosisCode = prescriptionDiagnosisDOS.get(0).getCode();
                        //同步诊断
                        com.alibaba.fastjson.JSONObject jsonObject2 = dsyyPrescriptionService.saveDiagnosis(outpatientDO.getRegisterNo(),diagnosisName,diagnosisCode);
                        logger.info("上传诊断返回参数"+jsonObject2);
                        //{"msg":"交易成功","code":"0","data":{"PresDetail":{"PresNo":"16151365"}},"success":"True"}
                        if (jsonObject2!=null){
                            if (jsonObject2.getString("returnCode").equalsIgnoreCase("0")){
                                String HISTradeNo = jsonObject2.getString("HISTradeNo");
                                logger.info("上传诊断成功"+jsonObject2);
                            }else {
                                throw new Exception(jsonObject2.getString("msg"));
                            }
                        }
                    }
                    //同步处方
                    String applyDoctor = doctorMappingDO.getDoctorName()+"/"+doctorMappingDO.getMappingCode();
                    com.alibaba.fastjson.JSONObject object = dsyyPrescriptionService.savePrescriptionToHospital("0",outpatientDO.getCardNo(),outpatientDO.getRegisterNo(),outpatientDO.getDept(),applyDoctor,"50105",infoDOS);
                    logger.info("成功上传处方"+object);
                if (prescriptionDiagnosisDOS!=null&&prescriptionDiagnosisDOS.size()!=0){
                    String diagnosisName = prescriptionDiagnosisDOS.get(0).getName();
                    String diagnosisCode = prescriptionDiagnosisDOS.get(0).getCode();
                    //同步诊断
                    com.alibaba.fastjson.JSONObject jsonObject2 = dsyyPrescriptionService.saveDiagnosis(outpatientDO.getRegisterNo(),diagnosisName,diagnosisCode);
                    logger.info("上传诊断返回参数"+jsonObject2);
                    //{"msg":"交易成功","code":"0","data":{"PresDetail":{"PresNo":"16151365"}},"success":"True"}
                    if (object!=null){
                        if (object.getString("returnCode").equalsIgnoreCase("0")){
                            com.alibaba.fastjson.JSONObject jsonObject = object.getJSONObject("data");
                            com.alibaba.fastjson.JSONObject jsonObject1 = jsonObject.getJSONObject("PresDetail");
                            String realOrder = jsonObject1.getString("PresNo");
                            wlyyPrescriptionDO.setAdmNo(outpatientDO.getAdmNo());
                            wlyyPrescriptionDO.setSerialNo(outpatientDO.getAdmNo());
                            wlyyPrescriptionDO.setRealOrder(realOrder);
                    if (jsonObject2!=null){
                        if (jsonObject2.getString("returnCode").equalsIgnoreCase("0")){
                            String HISTradeNo = jsonObject2.getString("HISTradeNo");
                            logger.info("上传诊断成功"+jsonObject2);
                        }else {
                            throw new Exception(object.getString("msg"));
                            throw new Exception(jsonObject2.getString("msg"));
                        }
                    }
                    logger.info("进入处方签名");
                   /* try {
                        String baseSign=dsyyPrescriptionService.SOF_SignDataWithExtraInfo(wlyyPrescriptionDO);
                    }catch (Exception e){
                        e.printStackTrace();
                    }*/
                /*    logger.info("进入处方签名");
                    //电子病例签名
                    String baseSign=hcyyEntranceService.initiateDataSign(wlyyPrescriptionDO.getId(),2,ip);
                    //同步电子病历
                    WlyyPrescriptionEmrDO prescriptionEmrDO = prescriptionEmrDao.findEmrByPrescriptionId(prescriptionId);
                    try {
                        if (prescriptionEmrDO != null) {
                            logger.info("电子病历同步");
                            hcyyPrescriptionService.saveEmrToEntrance(prescriptionId,baseSign);
                            logger.info("电子病历同步");
                            logger.info("电子病历签名");
                            hcyyEntranceService.initiateDataSign(wlyyPrescriptionDO.getId(),1,ip);
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }*/
                    try {
                        if (object!=null){
                            if (object.getString("code").equalsIgnoreCase("0")){
                                //  * @param applyDepaName @param applyDoctorName
                                WlyyPrescriptionDO prescriptionDO = prescriptionDao.findById(prescriptionId).orElse(null);
                                String patientCode = outpatientDO.getConsumer();
                                String realerOrder = prescriptionDO.getRealOrder();
                                String recipeTime = DateUtil.dateToStr(prescriptionDO.getCreateTime(), "yyyyMMddHHmmss");
                                List<BaseDoctorHospitalDO> doctorHospitalDOS = baseDoctorHospitalDao.findByDoctorCode(prescriptionDO.getDoctor());
                                String applyDepaName = null;
                                if (doctorHospitalDOS != null && doctorHospitalDOS.size() != 0) {
                                    applyDepaName = doctorHospitalDOS.get(0).getDeptName();
                                }
                                String voucherNo = outpatientDO.getRegisterNo();
                                String applyDoctorName = prescriptionDO.getDoctorName();
                                BasePatientDO patientDO = basePatientDao.findById(patientCode).orElse(null);
                                String userName = null;
                                String idcard = null;
                                if (patientDO != null) {
                                    userName = patientDO.getName();
                                    idcard = patientDO.getIdcard();
                                }
                                PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patientCode);
                                String userNo = null;
                                if (patientMappingDO != null) {
                                    userNo = patientMappingDO.getMappingCode();
                                }
                                String cardNo = null;
                                if (StringUtils.isNoneBlank(outpatientDO.getCardNo())) {
                                    cardNo = outpatientDO.getCardNo();
                                }
                                logger.info("cardNo:" + cardNo);
                               /* JSONObject jsonObject =entranceService.BS15054(patientMappingDO.getMappingCode(),prescriptionDO.getRealOrder(),demoFlag);
                                net.sf.json.JSONObject res = jsonObject.getJSONObject("resquest");
                                logger.info("获取待结算数据 res: " + res.toString());
                                String rsCode = res.getString("@RESULT");
                                String free= 0+"";
                                if ("0".equals(rsCode)) {
                                    free = res.getString("@total_charge");
                                }*/
                                /*ylzPayService.msgPush("01", cardNo, "01", patientDO.getMobile(), "00", userNo, userName, idcard, voucherNo, applyDepaName, applyDoctorName, recipeTime, "", "","WX_PUB");
                                 */}
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                }
                //同步处方
                String applyDoctor = doctorMappingDO.getDoctorName()+"/"+doctorMappingDO.getMappingCode();
                com.alibaba.fastjson.JSONObject object = dsyyPrescriptionService.savePrescriptionToHospital("0",outpatientDO.getCardNo(),outpatientDO.getRegisterNo(),outpatientDO.getDept(),applyDoctor,"50105",infoDOS);
                logger.info("成功上传处方"+object);
                //{"msg":"交易成功","code":"0","data":{"PresDetail":{"PresNo":"16151365"}},"success":"True"}
                if (object!=null){
                    if (object.getString("returnCode").equalsIgnoreCase("0")){
                        com.alibaba.fastjson.JSONObject jsonObject = object.getJSONObject("data");
                        com.alibaba.fastjson.JSONObject jsonObject1 = jsonObject.getJSONObject("PresDetail");
                        String realOrder = jsonObject1.getString("PresNo");
                        wlyyPrescriptionDO.setAdmNo(outpatientDO.getAdmNo());
                        wlyyPrescriptionDO.setSerialNo(outpatientDO.getAdmNo());
                        wlyyPrescriptionDO.setRealOrder(realOrder);
                    }else {
                        throw new Exception(object.getString("msg"));
                    }
                } catch (Exception e) {
                }
                logger.info("进入处方签名开始");
                try {
                    String baseSign=dsyyPrescriptionService.SOF_SignDataWithExtraInfo(wlyyPrescriptionDO.getId());
                    logger.info("进入处方签名结束"+baseSign);
                }catch (Exception e){
                    e.printStackTrace();
                }
                //电子病例签名
                String baseSign=dsyyPrescriptionService.SOF_SignDataWithExtraInfoEmr(wlyyPrescriptionDO.getId());
                try {
                    logger.info("ca签名后病历保存开始“"+baseSign);
                    String res= dsyyPrescriptionService.dzblSave(wlyyPrescriptionDO.getId());
                    logger.info("ca签名后病历保存结束“"+res);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
            prescriptionLogService.addPrescriptionLog(prescriptionId, 20, 2, operate, operateName, reason, new Date());
            wlyyPrescriptionDO.setCheckStatus(2);
@ -11986,7 +11931,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    }
    //作废处方
    public String disablePrescription(String prescriptionId) throws  Exception{
        WlyyPrescriptionDO prescriptionDO = prescriptionDao.findById(prescriptionId).orElse(null);
        WlyyPrescriptionDO prescriptionDO = prescriptionDao.findById(prescriptionId).get();
        if (null!=prescriptionDO){
            String hisId = prescriptionDO.getHisId();
            if("xm_xzzx_wx".equalsIgnoreCase(wechatId)){
@ -11997,8 +11942,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                        xzzxEntranceService.deletePrescriptionToEntrance(prescriptionDO.getRealOrder());
                    }
                }
            }
            if("xm_zsyy_wx".equalsIgnoreCase(wechatId)){
            }else if("xm_zsyy_wx".equalsIgnoreCase(wechatId)){
                /*prescriptionDao.updateCheckStatus(prescriptionId,2,reason,20);*/
                logger.info("作废处方开始" + prescriptionDO.getCheckStatus());
                WlyyHttpLogDO wlyyHttpLogDO = new WlyyHttpLogDO();
@ -12051,6 +11995,20 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                    wlyyPrescriptionDO.setCheckReason("已作废");
                    prescriptionDao.save(wlyyPrescriptionDO);
                }
            }else if("xm_dsyy_wx".equalsIgnoreCase(wechatId)){
                logger.info("第三医院删除处方");
                WlyyOutpatientDO outpatientDO = outpatientDao.findById(prescriptionDO.getOutpatientId()).get();
                DoctorMappingDO doctorMappingDO = doctorMappingDao.findByDoctor(outpatientDO.getDoctor());
                if (StringUtils.isNotBlank(prescriptionDO.getRealOrder())){
                    String applyDoctor = doctorMappingDO.getDoctorName()+"/"+doctorMappingDO.getMappingCode();
                    dsyyPrescriptionService.delHisPrescriptionByHisNo("0",outpatientDO.getCardNo(),outpatientDO.getRegisterNo(),outpatientDO.getDept(),applyDoctor,"50105",prescriptionDO.getRealOrder());
                }
                prescriptionDO.setStatus(-4);
                prescriptionDO.setDisableTime(new Date());
                prescriptionDO.setCheckStatus(5);
                prescriptionDO.setCheckReason("已作废");
                prescriptionDao.save(prescriptionDO);
                return "已作废";
            }
            prescriptionDO.setStatus(-4);
            prescriptionDO.setDisableTime(new Date());
@ -14631,12 +14589,13 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     */
    public com.alibaba.fastjson.JSONObject getSettlementInfo(String outpatientId,Integer flag) throws Exception {
        logger.info("获取患者待结算信息开始!");
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(outpatientId).orElse(null);
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(outpatientId).get();
        if(outpatientDO==null){
            throw new Exception("门诊信息为空");
        }
        WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("ylzConfigOrgCode").get();
        logger.info("获取待结算开始!");
        if (wechatId.equalsIgnoreCase("xm_dsyy_wx")) {
            logger.info("获取待结算开始!=====");
            com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
            logger.info("获取患者待结算信息开始!");
            YlzMedicalRelationDO ylzMedicalRelationDO = new YlzMedicalRelationDO();
@ -14680,7 +14639,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                }
            }
            if (ylzMedicalRelationDO != null && ylzMedicalRelationDO.getStatus() == 1) {
                com.alibaba.fastjson.JSONObject object2 = hcyyPrescriptionService.selectCardInfo(outpatientDO.getCardNo());
                com.alibaba.fastjson.JSONObject object2 = dsyyEntranceService.selectCardInfo(outpatientDO.getCardNo());
                Double cardFee = object2.getDouble("ZHYE");
                //医保已结算直接返回数据
                List<YlzMedicalMxDO> mxDOList = ylzMedicailMxDao.findByMedicalId(ylzMedicalRelationDO.getId());
@ -14800,11 +14759,20 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            throw new Exception("门诊信息为空");
        }
        if (StringUtils.isNoneBlank(code)){
            logger.info("医保结算结果获取start!");
            result = healthCareService.getSettlementResult(code);
            logger.info("医保结算结果获取end!");
            if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                logger.info("医保结算结果获取start!");
                result = healthCareService.getSettlementResult(code);
                logger.info("医保结算结果获取end!");
                com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(result);
            }else {
                logger.info("医保结算结果获取start!");
                result = healthCareNewService.getSettlementResult(code);
                logger.info("医保结算结果获取end!");
                com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(result);
            }
        }/*else{
        }
        /*else{
            logger.info("医保结算页面start!");
            String registerNo = outpatientDO.getRegisterNo();
            result = healthCareService.getSettlementResultUrl(registerNo);

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 894 - 518
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/DsyyEntranceService.java


+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/EntranceService.java

@ -1653,7 +1653,7 @@ public class EntranceService {
    }
    public String ylzRefund(String outPatientId,boolean sys) throws Exception {
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(outPatientId).orElse(null);
        WlyyOutpatientDO outpatientDO = outpatientDao.findById(outPatientId).get();
        if (outpatientDO == null) {
            throw new Exception("门诊信息表为空");
        }

+ 377 - 76
business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java

@ -7,6 +7,7 @@ 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.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
import com.yihu.jw.entity.base.wx.WxPayLogDO;
import com.yihu.jw.entity.base.wx.WxWechatDO;
@ -15,6 +16,8 @@ import com.yihu.jw.entity.hospital.dict.WlyyChargeDictDO;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalRelationDO;
import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.hospital.prescription.*;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
@ -24,8 +27,10 @@ import com.yihu.jw.hospital.healthCare.YlzMedicailRelationDao;
import com.yihu.jw.hospital.httplog.dao.WlyyHttpLogDao;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.hospital.prescription.dao.*;
import com.yihu.jw.hospital.prescription.service.DsyyPrescriptionService;
import com.yihu.jw.hospital.prescription.service.PrescriptionLogService;
import com.yihu.jw.hospital.prescription.service.PrescriptionService;
import com.yihu.jw.hospital.prescription.service.entrance.DsyyEntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
@ -36,6 +41,8 @@ import com.yihu.jw.order.dao.ConsultOrderDao;
import com.yihu.jw.order.pay.wx.WeChatConfig;
import com.yihu.jw.order.pay.ylz.YlzPayService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionInfoVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.sms.dao.BaseSmsTemplateDao;
@ -80,6 +87,7 @@ import java.util.*;
 * 业务订单
 */
@Service
@Transactional
public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,BusinessOrderDao> {
    private Logger logger = LoggerFactory.getLogger(BusinessOrderService.class);
@ -150,6 +158,11 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
    private HttpClientUtil httpClientUtil;
    @Autowired
    private YlzMedicailRelationDao ylzMedicailRelationDao;
    @Autowired
    private DsyyPrescriptionService dsyyPrescriptionService;
    @Autowired
    private DsyyEntranceService dsyyEntranceService;
    /**
@ -173,7 +186,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        List<BusinessOrderDO> businessOrderDOS = new ArrayList<>();
        if (wlyyPrescriptionDOS!=null&&wlyyPrescriptionDOS.size()!=0){
            WlyyPrescriptionDO wlyyPrescriptionDO = wlyyPrescriptionDOS.get(0);
            WlyyOutpatientDO outpatientDO = outpatientDao.findById(wlyyPrescriptionDO.getOutpatientId()).orElse(null);
            WlyyOutpatientDO outpatientDO = outpatientDao.findById(wlyyPrescriptionDO.getOutpatientId()).get();
            BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(wlyyPrescriptionDO.getId());
            if (businessOrderDO==null) {
                businessOrderDO = new BusinessOrderDO();
@ -211,7 +224,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                JSONArray array = new JSONArray();
                List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS = prescriptionInfoDao.findByPrescriptionId(code, 1);
                if (wechatId.equalsIgnoreCase("xm_ykyy_wx")){
                    WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKTCONTROL").orElse(null);
                    WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKTCONTROL").get();
                    for (WlyyPrescriptionInfoDO prescriptionInfoDO : wlyyPrescriptionInfoDOS) {
                        JSONObject object = new JSONObject();
                        //{"commodityName":"","commodityPrice":"","DrugUnit":"","MedicineDoctor":""}
@ -240,7 +253,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                        object.put("MedicineDoctor", yktDoctor);
                        array.add(object);
                    }
                    BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).orElse(null);
                    BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).get();
                    String userId = null;
                    if (patientDO != null) {
                        userId = patientDO.getUserId();
@ -323,10 +336,10 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        }
        businessOrderDO = businessOrderDao.save(businessOrderDO);
        String patient = businessOrderDO.getPatient();
        BasePatientDO basePatientDO = patientDao.findById(patient).orElse(null);
        BasePatientDO basePatientDO = patientDao.findById(patient).get();
        String orderNo = businessOrderDO.getOrderNo();
        String patientId = "";
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKTCONTROL").orElse(null);
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKTCONTROL").get();
        if (StringUtils.isNoneBlank(basePatientDO.getYktId())){
            patientId = basePatientDO.getYktId();
        }else {
@ -422,7 +435,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            throw new Exception("can't find wechat:the wxId is "+wechatId);
        }
        String patient = businessOrderDO.getPatient();
        BasePatientDO basePatientDO = patientDao.findById(patient).orElse(null);
        BasePatientDO basePatientDO = patientDao.findById(patient).get();
        String orderNo = businessOrderDO.getOrderNo();
        String patientId = basePatientDO.getYktId();
        String orderAmout = businessOrderDO.getPayPrice()/100+"";
@ -449,7 +462,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                doctorId="hlwyymrys001";
            }
        }
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKTCONTROL").orElse(null);
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKTCONTROL").get();
        if (null != hospitalSysDictDO && "0".equalsIgnoreCase(hospitalSysDictDO.getDictValue())) {
        } else {
@ -482,7 +495,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
     */
    @Transactional(rollbackFor = Exception.class)
    public String refund(Map<String,String> par,String appKey) throws Exception {
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("REFUND").orElse(null);
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("REFUND").get();
        if(StringUtils.isNoneBlank(hospitalSysDictDO.getImgUrl())){
            //公网域名必须为https
            par.put("notify_url",hospitalSysDictDO.getImgUrl());
@ -515,7 +528,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        WxWechatDO wxWechatDO = wechatDao.findByIdAndStatus(wechatId);
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode);
        if (NumberUtils.isDigits(relationCode) ){
            BaseNatAppointmentDO baseNatAppointmentDO = baseNatAppointmentDao.findById(Integer.valueOf(relationCode)).orElse(null);
            BaseNatAppointmentDO baseNatAppointmentDO = baseNatAppointmentDao.findById(Integer.valueOf(relationCode)).get();
            if (baseNatAppointmentDO!=null&&"-1".equalsIgnoreCase(baseNatAppointmentDO.getIsSuccess())){
                throw new Exception("订单已取消");
            }
@ -523,7 +536,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                throw new Exception("订单已支付");
            }
        }
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(relationCode).orElse(null);
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(relationCode).get();
        if (wlyyOutpatientDO!=null){
            if ("-1".equalsIgnoreCase(wlyyOutpatientDO.getStatus())){
                throw new Exception("订单已取消");
@ -919,8 +932,8 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            //更改业务状态,做日志保存等操作
            BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(seqNo);
            businessOrderDO.setPayTime(DateUtil.strToDate(timeEnd,DateUtil.YYYY_MM_DD_HH_MM_SS));
            WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKTCONTROL").orElse(null);
            WlyyHospitalSysDictDO changeMethod = hospitalSysDictDao.findById("consultPay").orElse(null);
            WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKTCONTROL").get();
            WlyyHospitalSysDictDO changeMethod = hospitalSysDictDao.findById("consultPay").get();
            String changeflag="0";
            String type="";
            if(null!=changeMethod){
@ -929,11 +942,11 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            if (businessOrderDO!=null){
                if (businessOrderDO.getOrderCategory().equalsIgnoreCase("1")){
                    if ("0".equalsIgnoreCase(changeflag)){
                        ConsultDo consultDo = consultOrderDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                        ConsultDo consultDo = consultOrderDao.findById(businessOrderDO.getRelationCode()).get();
                        consultDo.setPayStatus(1);
                        consultOrderDao.save(consultDo);
                    }else {
                        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                        wlyyOutpatientDO.setPayStatus(1);
                        outpatientDao.save(wlyyOutpatientDO);
                        prescriptionService.wxTempalteJPush("outpatient_remind",wlyyOutpatientDO,null,"","","","");
@ -948,7 +961,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                    }
                }else if (businessOrderDO.getOrderCategory().equalsIgnoreCase("2")||businessOrderDO.getOrderCategory().equalsIgnoreCase("3")){
                    WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                    WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                    wlyyOutpatientDO.setPayStatus(1);
                    outpatientDao.save(wlyyOutpatientDO);
                    if (StringUtils.isNoneBlank(wlyyOutpatientDO.getDoctor())){
@ -1008,7 +1021,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                                                " where "+condition+" t.CFSB ='"+wlyyPrescriptionDO.getRealOrder()+"'";
                                        ykyyEntranceService.updateHisStatus(updatesql);
                                        logger.info("自取写入更新his");
                                        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(wlyyPrescriptionDO.getOutpatientId()).orElse(null);
                                        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(wlyyPrescriptionDO.getOutpatientId()).get();
                                        ykyySMSService.sendSmsByTempcode("oneself_pick",wlyyOutpatientDO,wlyyPrescriptionDO,"");
                                    }else {
@ -1064,7 +1077,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                }else if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("6")){
                    String price = Integer.parseInt(totalFee)/100+"";
                    BaseNatAppointmentDO baseNatAppointmentDO = baseNatAppointmentDao.findById(Integer.parseInt(businessOrderDO.getRelationCode())).orElse(null);
                    BaseNatAppointmentDO baseNatAppointmentDO = baseNatAppointmentDao.findById(Integer.parseInt(businessOrderDO.getRelationCode())).get();
                    baseNatAppointmentDO.setPayStatus("1");
                    baseNatAppointmentDao.save(baseNatAppointmentDO);
@ -1113,7 +1126,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
    public String sendDataToYkt(String orderNo){
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(orderNo);
        String patient = businessOrderDO.getPatient();
        BasePatientDO basePatientDO = patientDao.findById(patient).orElse(null);
        BasePatientDO basePatientDO = patientDao.findById(patient).get();
        String patientId = basePatientDO.getYktId();
        String orderAmout = businessOrderDO.getPayPrice()/100+"";
        String description = businessOrderDO.getDescription();
@ -1226,10 +1239,10 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        if(wxWechatDO==null){
            throw new Exception("can't find wechat:the wxId is "+wechatId);
        }
        WlyyHospitalSysDictDO hospitalSysDictDO =hospitalSysDictDao.findById("YLZ_NOTIFY_URL").orElse(null);
        WlyyHospitalSysDictDO hospitalSysDictDO =hospitalSysDictDao.findById("YLZ_NOTIFY_URL").get();
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(code);
        if (businessOrderDO!=null){
            BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).orElse(null);
            BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).get();
            String idcard = "";
            String ssc = "";
            if (patientDO!=null){
@ -1287,10 +1300,10 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        if(wxWechatDO==null){
            throw new Exception("can't find wechat:the wxId is "+wechatId);
        }
        WlyyHospitalSysDictDO hospitalSysDictDO =hospitalSysDictDao.findById("YLZ_NOTIFY_URL").orElse(null);
        WlyyHospitalSysDictDO hospitalSysDictDO =hospitalSysDictDao.findById("YLZ_NOTIFY_URL").get();
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(code);
        if (businessOrderDO!=null){
            BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).orElse(null);
            BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).get();
            String idcard = "";
            String ssc = "";
            if (patientDO!=null){
@ -1337,7 +1350,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        return businessOrderDO;
    }
    public BusinessOrderDO selectStatusById(Integer id){
        BusinessOrderDO businessOrderDO = businessOrderDao.findById(id).orElse(null);
        BusinessOrderDO businessOrderDO = businessOrderDao.findById(id).get();
        return businessOrderDO;
    }
@ -1372,7 +1385,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        if (businessOrderDO==null){
            throw new Exception("this orderId not exit");
        }
        BasePatientDO patientDO = patientDao.findById(patient).orElse(null);
        BasePatientDO patientDO = patientDao.findById(patient).get();
        if (patientDO==null){
            throw new Exception("this patient not exit");
        }
@ -1394,7 +1407,19 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        orderRefundDO.setPatientName(patientDO.getName());
        orderRefundDO.setRefundDesc(description);
        orderRefundDO = orderRefundDao.save(orderRefundDO);
        String map = ylzPayService.refund(patientDO.getIdcard(),"123456",patientDO.getName(),"01",patientDO.getIdcard(),"01",orderRefundDO.getRefundPrice().toString(),"1",orderRefundDO.getOrderNo(),orderRefundDO.getOutRefundNo(),patientDO.getIdcard());
        String operatorId = "";
        String operatorName = "";
        if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
            operatorId = "123456";
            operatorName =businessOrderDO.getPatientName();
        }else if(wechatId.equalsIgnoreCase("xm_xzzx_wx")){
            operatorId = "hlwyy";
            operatorName = "互联网医院";
        }else if(wechatId.equalsIgnoreCase("xm_hcyy_wx")){
            operatorId = "hlwyy";
            operatorName = "互联网医院";
        }
        String map = ylzPayService.refund(patientDO.getIdcard(),operatorId,operatorName,"01",patientDO.getIdcard(),"01",orderRefundDO.getRefundPrice().toString(),"1",orderRefundDO.getOrderNo(),orderRefundDO.getOutRefundNo(),patientDO.getIdcard());
        JSONObject object = JSONObject.parseObject(map);
        if (object.get("respCode").toString().equalsIgnoreCase("000000")){
            orderRefundDO.setStatus(2);
@ -1412,14 +1437,55 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
    /**
     * 易联众查询交易订单
     *
     * @param orderNo
     * @param tradeType
     * @return
     */
    public JSONObject tradeQuery(String orderNo,String tradeType){
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(orderNo);
        String response = ylzPayService.tradeQuery(null,null,businessOrderDO.getPatientName(),orderNo,tradeType,businessOrderDO.getRematk());
    public JSONObject tradeQuery(String relationCode,String tradeType) throws Exception {
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode);
        String operatorId = "";
        String operatorName = "";
        if(wechatId.equalsIgnoreCase("xm_dsyy_wx")){
            operatorId = "HLWCS";
            operatorName = "互联网医院";
        }
        String response = ylzPayService.tradeQuery(operatorId,operatorName,businessOrderDO.getOrderNo(),tradeType,businessOrderDO.getRematk());
        JSONObject object = JSONObject.parseObject(response);
        if (object.getString("respCode").equalsIgnoreCase("000000")){
            JSONObject param = object.getJSONObject("param");
            if (param.getString("result").equalsIgnoreCase("succ")){
                if(wechatId.equalsIgnoreCase("xm_dsyy_wx")){
                    logger.info("his充值开始");
                    dsyyPrescriptionService.rechargeHis(businessOrderDO.getOrderNo());
                    logger.info("his充值结束");
                }
                if (businessOrderDO.getStatus()!=1){
                    if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("1")){
                        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                        wlyyOutpatientDO.setPayStatus(1);
                        WlyyOutpatientDO outpatientDO = outpatientDao.save(wlyyOutpatientDO);
                    }else if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("2")){
                        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                        wlyyOutpatientDO.setPayStatus(1);
                        WlyyOutpatientDO outpatientDO = outpatientDao.save(wlyyOutpatientDO);
                    }else if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("3")){
                        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                        wlyyOutpatientDO.setPayStatus(1);
                        WlyyOutpatientDO outpatientDO = outpatientDao.save(wlyyOutpatientDO);
                    }else if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("6")){
                        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findById(businessOrderDO.getRelationCode()).get();
                        if (wechatId.equalsIgnoreCase("xm_dsyy_wx")){
                            dsyyPrescriptionService.confirmSettlement(ylzMedicalRelationDO.getRelationCode());
                        }
                    }
                }
                businessOrderDO.setUpdateTime(new Date());
                businessOrderDO.setStatus(1);
                businessOrderDO.setPayTime(new Date());
                businessOrderDao.save(businessOrderDO);
            }
        }
        return object;
    }
@ -1436,23 +1502,23 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            throw new Exception("查不到订单!");
        }
        String newPayFlag = "0";
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("consultPay").orElse(null);
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("consultPay").get();
        if (null!=wlyyHospitalSysDictDO){
            newPayFlag = wlyyHospitalSysDictDO.getDictValue();
        }
        if (businessOrderDO.getOrderCategory().equalsIgnoreCase("1")){
            if ("0".equalsIgnoreCase(newPayFlag)){
                ConsultDo consultDo = consultOrderDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                ConsultDo consultDo = consultOrderDao.findById(businessOrderDO.getRelationCode()).get();
                consultDo.setPayStatus(2);
                consultOrderDao.save(consultDo);
            }else {
                WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                wlyyOutpatientDO.setPayStatus(2);
                outpatientDao.save(wlyyOutpatientDO);
            }
        }else if (businessOrderDO.getOrderCategory().equalsIgnoreCase("2")||businessOrderDO.getOrderCategory().equalsIgnoreCase("3")){
            WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).orElse(null);
            WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
            wlyyOutpatientDO.setPayStatus(2);
            outpatientDao.save(wlyyOutpatientDO);
        }
@ -1468,11 +1534,12 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
     * @param orderNo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public BusinessOrderDO updatePayStatus(String orderNo) throws Exception {
        logger.info("入参:"+orderNo);
        String baseUrl = prescriptionService.findDomainUrlInDict();
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(orderNo);
        WlyyHospitalSysDictDO changeMethod = hospitalSysDictDao.findById("consultPay").orElse(null);
        WlyyHospitalSysDictDO changeMethod = hospitalSysDictDao.findById("consultPay").get();
        String changeflag="0";
        if(null!=changeMethod){
            changeflag = changeMethod.getDictValue();
@ -1482,16 +1549,16 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        }
        if (businessOrderDO.getOrderCategory().equalsIgnoreCase("1")&&businessOrderDO.getStatus()==0){
            if ("0".equalsIgnoreCase(changeflag)){
                ConsultDo consultDo = consultOrderDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                ConsultDo consultDo = consultOrderDao.findById(businessOrderDO.getRelationCode()).get();
                consultDo.setPayStatus(1);
                consultOrderDao.save(consultDo);
            }else {
                WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.getOne(businessOrderDO.getRelationCode());
                WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                wlyyOutpatientDO.setPayStatus(1);
                WlyyOutpatientDO outpatientDO = outpatientDao.save(wlyyOutpatientDO);
                //发送企业模板消息给医生
                BasePatientDO patientDO = new BasePatientDO();
                patientDO = patientDao.findById(outpatientDO.getPatient()).orElse(null);
                patientDO = patientDao.findById(outpatientDO.getPatient()).get();
                String msg = "";
                String name=outpatientDO.getPatientName();
                String sex = "";
@ -1539,7 +1606,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            }
        }else if (businessOrderDO.getOrderCategory().equalsIgnoreCase("2")||businessOrderDO.getOrderCategory().equalsIgnoreCase("3")||businessOrderDO.getOrderCategory().equalsIgnoreCase("5")){
           WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).orElse(null);
           WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
           wlyyOutpatientDO.setPayStatus(1);
           WlyyOutpatientDO outpatientDO = outpatientDao.save(wlyyOutpatientDO);
           try {
@ -1553,7 +1620,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
           if (businessOrderDO.getStatus()!=null&&businessOrderDO.getStatus()==0){
               //发送企业模板消息给医生
               BasePatientDO patientDO = new BasePatientDO();
               patientDO = patientDao.findById(outpatientDO.getPatient()).orElse(null);
               patientDO = patientDao.findById(outpatientDO.getPatient()).get();
               String msg = "";
               String name=outpatientDO.getPatientName();
               String sex = "";
@ -1620,6 +1687,216 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        return businessOrderDO;
    }
    /**
     * 预交金处方支付
     * @param code
     * @param depositType
     * @param wechatId
     * @return
     * @throws Exception
     */
    public String ylzRechargePreDs(String code,String depositType,String wechatId,String cardType,String cardNo,boolean demoFlag,String appletCode) throws Exception {
        try {
            String response = null;
            WxWechatDO wxWechatDO = wechatDao.findById(wechatId).get();
            if(wxWechatDO==null){
                throw new Exception("can't find wechat:the wxId is "+wechatId);
            }
            WlyyHospitalSysDictDO hospitalSysDictDO =hospitalSysDictDao.findById("YLZ_NOTIFY_URL").get();
            WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(code).get();
            YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(code);
            BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(ylzMedicalRelationDO.getId());
            BigDecimal b1 = new BigDecimal(ylzMedicalRelationDO.getBcwkje());//总金额
            BigDecimal b2 = new BigDecimal(ylzMedicalRelationDO.getPersonAccount());//个人账户
            BigDecimal b3 = new BigDecimal(ylzMedicalRelationDO.getMedicalPrice());//医保总金额
            Double fee = b1.subtract(b2).subtract(b3).doubleValue();
            if (businessOrderDO!=null){
                BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).get();
                String idcard = "";
                if (patientDO!=null){
                    idcard = patientDO.getIdcard();
                }
                logger.info("开始1"+idcard);
                String openId = "";
                JSONObject object1 = dsyyEntranceService.selectCardInfo(cardNo);
                Double cardFee = object1.getDouble("ZHYE");
                BigDecimal b = new BigDecimal(String.valueOf(cardFee));
                BigDecimal c = new BigDecimal(String.valueOf(fee));
                if (b.compareTo(c) == 1){
                    return "无需线上支付";
                }
                BigDecimal balance = c.subtract(b);
                if (balance.doubleValue()<=0){
                    return "无需线上支付";
                }
                businessOrderDO.setPayPrice(balance.doubleValue());
                businessOrderDO.setPayType(4);
                businessOrderDO.setHistoryOrder(businessOrderDO.getOrderNo());
                businessOrderDO.setOrderNo("HLWYY"+System.currentTimeMillis()+(int)(Math.random()*900)+100);
                businessOrderDO.setDepositType(depositType);
                businessOrderDao.save(businessOrderDO);
                if (StringUtils.isNotBlank(appletCode)){
                    logger.info("appletCode不为空"+appletCode);
                    Map<String,Object> objectMap = checkApplets(appletCode,wxWechatDO.getApplets(),wxWechatDO.getAppletsSecret());
                    if (objectMap!=null){
                        openId = objectMap.get("openid").toString();
                        logger.info("appletCode"+appletCode);
                        logger.info("openid"+openId);
                    }
                }else {
                    logger.info("appletCode为空"+appletCode);
                    List<BasePatientWechatDo> patientWechatDo = patientWechatDao.findByWechatIdAndPatientId(wechatId,businessOrderDO.getPatient());
                    if (patientWechatDo!=null&&patientWechatDo.size()!=0){
                        openId = patientWechatDo.get(0).getOpenid();
                    }
                }
                String price = businessOrderDO.getPayPrice().toString();
                String notifyUrl = hospitalSysDictDO.getDictCode();
                String operatorId =null;
                String operatorName = null;
                if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                    operatorId = "123456";
                    operatorName =businessOrderDO.getPatientName();
                }else if(wechatId.equalsIgnoreCase("xm_xzzx_wx")){
                    operatorId = "hlwyy";
                    operatorName = "互联网医院";
                }else if(wechatId.equalsIgnoreCase("xm_hcyy_wx")){
                    operatorId = "hlwyy";
                    operatorName = "互联网医院";
                }
                response = ylzPayService.recharge(operatorId,operatorName,cardType,"01",cardNo,idcard,depositType,price,businessOrderDO.getOrderNo(),openId,patientDO.getName(),notifyUrl);
                if (depositType.equalsIgnoreCase("WX_QR")){
                    JSONObject object = JSONObject.parseObject(response);
                    if (object!=null){
                        JSONObject jsonObject = object.getJSONObject("param");
                        if (object.getString("respCode").equalsIgnoreCase("000000")){
                            InputStream qrcode = QrcodeUtil.createQrcode(jsonObject.getString("qrcode"),300,"jpg");
                            ByteToInputStream byteToInputStream = new ByteToInputStream();
                            String QRCodeImg = byteToInputStream.getBase64FromInputStream(qrcode);
                            jsonObject.put("qrcodeUrl","data:image/png;base64,"+ QRCodeImg);
                            String traceNo = jsonObject.getString("traceNo");
                            businessOrderDO.setTraceNo(traceNo);
                            businessOrderDao.save(businessOrderDO);
                        }
                        response = object.toJSONString();
                    }
                }else {
                    JSONObject object = JSONObject.parseObject(response);
                    if (object!=null){
                        JSONObject jsonObject = object.getJSONObject("param");
                        if (object.getString("respCode").equalsIgnoreCase("000000")){
                            String traceNo = jsonObject.getString("traceNo");
                            businessOrderDO.setTraceNo(traceNo);
                            businessOrderDao.save(businessOrderDO);
                        }
                    }
                }
            }else {
                businessOrderDO = new BusinessOrderDO();
                BasePatientDO patientDO = patientDao.findById(wlyyOutpatientDO.getPatient()).get();
                String idcard = "";
                if (patientDO!=null){
                    idcard = patientDO.getIdcard();
                }
                logger.info("开始2"+idcard);
                String openId = "";
                JSONObject object1 = dsyyEntranceService.selectCardInfo(cardNo);
                Double cardFee = object1.getDouble("ZHYE");
                BigDecimal b = new BigDecimal(String.valueOf(cardFee));
                BigDecimal c = new BigDecimal(String.valueOf(fee));
                if (b.compareTo(c) == 1){
                    return "无需线上支付";
                }
                BigDecimal balance = c.subtract(b);
                if (balance.doubleValue()<=0){
                    return "无需线上支付";
                }
                businessOrderDO.setPayPrice(balance.doubleValue());
                businessOrderDO.setPayType(4);
                businessOrderDO.setOrderNo("HLWYY"+System.currentTimeMillis()+(int)(Math.random()*900)+100);
                businessOrderDO.setDepositType(depositType);
                businessOrderDO.setRelationCode(ylzMedicalRelationDO.getId());
                businessOrderDO.setRelationName("费用结算");
                businessOrderDO.setPatientName(patientDO.getName());
                businessOrderDO.setPatient(patientDO.getId());
                businessOrderDO.setDoctor(wlyyOutpatientDO.getDoctor());
                businessOrderDO.setOrderCategory("6");
                businessOrderDO.setOrderType(6);
                businessOrderDO.setStatus(0);
                businessOrderDO.setDescription("费用结算");
                businessOrderDO.setCreateTime(new Date());
                businessOrderDO.setUpdateTime(new Date());
                businessOrderDao.save(businessOrderDO);
                if (StringUtils.isNotBlank(appletCode)){
                    logger.info("appletCode不为空"+appletCode);
                    Map<String,Object> objectMap = checkApplets(appletCode,wxWechatDO.getApplets(),wxWechatDO.getAppletsSecret());
                    if (objectMap!=null){
                        openId = objectMap.get("openid").toString();
                        logger.info("appletCode"+appletCode);
                        logger.info("openid"+openId);
                    }
                }else {
                    logger.info("appletCode为空"+appletCode);
                    List<BasePatientWechatDo> patientWechatDo = patientWechatDao.findByWechatIdAndPatientId(wechatId,businessOrderDO.getPatient());
                    if (patientWechatDo!=null&&patientWechatDo.size()!=0){
                        openId = patientWechatDo.get(0).getOpenid();
                    }
                }
                String price = businessOrderDO.getPayPrice().toString();
                String notifyUrl = hospitalSysDictDO.getDictCode();
                String operatorId =null;
                String operatorName = null;
                if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){
                    operatorId = "123456";
                    operatorName =businessOrderDO.getPatientName();
                }else if(wechatId.equalsIgnoreCase("xm_xzzx_wx")){
                    operatorId = "hlwyy";
                    operatorName = "互联网医院";
                }else if(wechatId.equalsIgnoreCase("xm_hcyy_wx")){
                    operatorId = "hlwyy";
                    operatorName = "互联网医院";
                }
                response = ylzPayService.recharge(operatorId,operatorName,cardType,"01",cardNo,idcard,depositType,price,businessOrderDO.getOrderNo(),openId,patientDO.getName(),notifyUrl);
                if (depositType.equalsIgnoreCase("WX_QR")){
                    JSONObject object = JSONObject.parseObject(response);
                    if (object!=null){
                        JSONObject jsonObject = object.getJSONObject("param");
                        if (object.getString("respCode").equalsIgnoreCase("000000")){
                            InputStream qrcode = QrcodeUtil.createQrcode(jsonObject.getString("qrcode"),300,"jpg");
                            ByteToInputStream byteToInputStream = new ByteToInputStream();
                            String QRCodeImg = byteToInputStream.getBase64FromInputStream(qrcode);
                            jsonObject.put("qrcodeUrl","data:image/png;base64,"+ QRCodeImg);
                            String traceNo = jsonObject.getString("traceNo");
                            businessOrderDO.setTraceNo(traceNo);
                            businessOrderDao.save(businessOrderDO);
                        }
                        response = object.toJSONString();
                    }
                }else {
                    JSONObject object = JSONObject.parseObject(response);
                    if (object!=null){
                        JSONObject jsonObject = object.getJSONObject("param");
                        if (object.getString("respCode").equalsIgnoreCase("000000")){
                            String traceNo = jsonObject.getString("traceNo");
                            businessOrderDO.setTraceNo(traceNo);
                            businessOrderDao.save(businessOrderDO);
                        }
                    }
                }
            }
            return response;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
    /**
     *无需支付
@ -1631,7 +1908,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        logger.info("进入无需支付");
        String baseUrl = prescriptionService.findDomainUrlInDict();
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode);
        WlyyHospitalSysDictDO changeMethod = hospitalSysDictDao.findById("consultPay").orElse(null);
        WlyyHospitalSysDictDO changeMethod = hospitalSysDictDao.findById("consultPay").get();
        String changeflag="0";
        if(null!=changeMethod){
            changeflag = changeMethod.getDictValue();
@ -1641,17 +1918,17 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        }
        if (businessOrderDO.getOrderCategory().equalsIgnoreCase("1")&&0==businessOrderDO.getStatus()){
            if ("0".equalsIgnoreCase(changeflag)){
                ConsultDo consultDo = consultOrderDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                ConsultDo consultDo = consultOrderDao.findById(businessOrderDO.getRelationCode()).get();
                consultDo.setPayStatus(1);
                consultOrderDao.save(consultDo);
            }else {
                WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
                wlyyOutpatientDO.setPayStatus(1);
                WlyyOutpatientDO outpatientDO = outpatientDao.save(wlyyOutpatientDO);
                if (businessOrderDO.getStatus()!=null&&businessOrderDO.getStatus()==0){
                    //发送企业模板消息给医生
                    BasePatientDO patientDO = new BasePatientDO();
                    patientDO = patientDao.findById(outpatientDO.getPatient()).orElse(null);
                    patientDO = patientDao.findById(outpatientDO.getPatient()).get();
                    String msg = "";
                    String name=outpatientDO.getPatientName();
                    String sex = "";
@ -1693,13 +1970,13 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                }
            }
        }else if (businessOrderDO.getOrderCategory().equalsIgnoreCase("2")||businessOrderDO.getOrderCategory().equalsIgnoreCase("3")||businessOrderDO.getOrderCategory().equalsIgnoreCase("5")&&0==businessOrderDO.getStatus()){
            WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).orElse(null);
            WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()).get();
            wlyyOutpatientDO.setPayStatus(1);
            WlyyOutpatientDO outpatientDO = outpatientDao.save(wlyyOutpatientDO);
            if (businessOrderDO.getStatus()!=null&&businessOrderDO.getStatus()==0){
                //发送企业模板消息给医生
                BasePatientDO patientDO = new BasePatientDO();
                patientDO = patientDao.findById(outpatientDO.getPatient()).orElse(null);
                patientDO = patientDao.findById(outpatientDO.getPatient()).get();
                String msg = "";
                String name=outpatientDO.getPatientName();
                String sex = "";
@ -1764,7 +2041,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
    public JSONObject selectOrderTime(String relationCode){
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("PAY_TIME").orElse(null);
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("PAY_TIME").get();
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode);
        if (businessOrderDO!=null){
            Date createDate = businessOrderDO.getCreateTime();
@ -1788,7 +2065,6 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
    }
    /**
     * 预交金支付
     * @param code
@ -1797,17 +2073,17 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
     * @return
     * @throws Exception
     */
    public String ylzRechargeJson(String code,String depositType,String wechatId,String cardType,String cardNo,boolean demoFlag) throws Exception {
    public String ylzRechargeJson(String code,String depositType,String wechatId,String cardType,String cardNo,boolean demoFlag,String appletCode) throws Exception {
        String response = null;
        WxWechatDO wxWechatDO = wechatDao.findByIdAndStatus(wechatId);
        if(wxWechatDO==null){
            throw new Exception("can't find wechat:the wxId is "+wechatId);
        }
        WlyyHospitalSysDictDO hospitalSysDictDO =hospitalSysDictDao.findById("YLZ_NOTIFY_URL").orElse(null);
        WlyyHospitalSysDictDO hospitalSysDictDO =hospitalSysDictDao.findById("YLZ_NOTIFY_URL").get();
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(code);
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(code).orElse(null);
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(code).get();
        if (businessOrderDO!=null){
            BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).orElse(null);
            BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).get();
            String idcard = "";
            if (patientDO!=null){
                idcard = patientDO.getIdcard();
@ -1818,7 +2094,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            if (StringUtils.isNoneBlank(businessOrderDO.getDoctor())){
                BaseDoctorDO doctorDO = doctorDao.findByIdAndDel(businessOrderDO.getDoctor());
                String fee = null;
                if (wechatId.equalsIgnoreCase("xm_zsyy_wx")||wechatId.equalsIgnoreCase("xm_xzzx_wx")||wechatId.equalsIgnoreCase("xm_hcyy_wx")){
                if (wechatId.equalsIgnoreCase("xm_zsyy_wx")||wechatId.equalsIgnoreCase("xm_xzzx_wx")||wechatId.equalsIgnoreCase("xm_hcyy_wx")||wechatId.equalsIgnoreCase("xm_dsyy_wx")){
                    if (wlyyOutpatientDO!=null){
                        if ("1".equalsIgnoreCase(wlyyOutpatientDO.getOutpatientType())&&"1".equalsIgnoreCase(wlyyOutpatientDO.getType())){
                            WlyyChargeDictDO chargeDictDO = chargeDictDao.findByChargeTypeAndDeptTypeCode(doctorDO.getTwfzChargeType(),"6");
@ -1853,11 +2129,11 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                }
                doctorFee= Double.parseDouble(fee);
            }else {
                WlyyHospitalSysDictDO wlyyHospitalSysDictDO =hospitalSysDictDao.findById("WX_MONEY").orElse(null);
                WlyyHospitalSysDictDO wlyyHospitalSysDictDO =hospitalSysDictDao.findById("WX_MONEY").get();
                doctorFee = Double.parseDouble(wlyyHospitalSysDictDO.getDictValue());
            }
            WlyyHospitalSysDictDO wlyyHospitalSysDictDO =hospitalSysDictDao.findById("YLZ_YE").orElse(null);
            WlyyHospitalSysDictDO wlyyHospitalSysDictDO =hospitalSysDictDao.findById("YLZ_YE").get();
            if (wlyyHospitalSysDictDO!=null&&wlyyHospitalSysDictDO.getDictValue().equalsIgnoreCase("0")){
                businessOrderDO.setPayPrice(doctorFee);
            }else {
@ -1882,10 +2158,20 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            businessOrderDO.setOrderNo("HLWYY"+System.currentTimeMillis()+(int)(Math.random()*900)+100);
            businessOrderDO.setDepositType(depositType);
            businessOrderDao.save(businessOrderDO);
            List<BasePatientWechatDo> patientWechatDos = patientWechatDao.findByWechatIdAndPatientId(wechatId,businessOrderDO.getPatient());
            if (patientWechatDos!=null&&patientWechatDos.size()!=0){
                BasePatientWechatDo patientWechatDo = patientWechatDos.get(0);
                openId = patientWechatDo.getOpenid();
            if (StringUtils.isNotBlank(appletCode)){
                logger.info("appletCode不为空"+appletCode);
                Map<String,Object> objectMap = checkApplets(appletCode,wxWechatDO.getApplets(),wxWechatDO.getAppletsSecret());
                if (objectMap!=null){
                    openId = objectMap.get("openid").toString();
                    logger.info("appletCode"+appletCode);
                    logger.info("openid"+openId);
                }
            }else {
                logger.info("appletCode为空"+appletCode);
                List<BasePatientWechatDo> patientWechatDo = patientWechatDao.findByWechatIdAndPatientId(wechatId,businessOrderDO.getPatient());
                if (patientWechatDo!=null&&patientWechatDo.size()!=0){
                    openId = patientWechatDo.get(0).getOpenid();
                }
            }
            String price = businessOrderDO.getPayPrice().toString();
            String notifyUrl = hospitalSysDictDO.getDictCode();
@ -1900,6 +2186,9 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            }else if(wechatId.equalsIgnoreCase("xm_hcyy_wx")){
                operatorId = "hlwyy";
                operatorName = "互联网医院";
            }else if(wechatId.equalsIgnoreCase("xm_dsyy_wx")){
                operatorId = "HLWCS";
                operatorName = "互联网医院";
            }
            response = ylzPayService.recharge(operatorId,operatorName,cardType,"01",cardNo,idcard,depositType,price,businessOrderDO.getOrderNo(),openId,patientDO.getName(),notifyUrl);
            if (depositType.equalsIgnoreCase("WX_QR")){
@ -1950,8 +2239,8 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        if(wxWechatDO==null){
            throw new Exception("can't find wechat:the wxId is "+wechatId);
        }
        WlyyHospitalSysDictDO hospitalSysDictDO =hospitalSysDictDao.findById("YLZ_NOTIFY_URL").orElse(null);
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(code).orElse(null);
        WlyyHospitalSysDictDO hospitalSysDictDO =hospitalSysDictDao.findById("YLZ_NOTIFY_URL").get();
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(code).get();
        YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findByOutpatient(code);
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(ylzMedicalRelationDO.getId());
        BigDecimal b1 = new BigDecimal(ylzMedicalRelationDO.getBcwkje());//总金额
@ -1960,7 +2249,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        Double fee = b1.subtract(b2).subtract(b3).doubleValue();
        if (businessOrderDO!=null){
            BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).orElse(null);
            BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()).get();
            String idcard = "";
            if (patientDO!=null){
                idcard = patientDO.getIdcard();
@ -2006,6 +2295,9 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            }else if(wechatId.equalsIgnoreCase("xm_hcyy_wx")){
                operatorId = "hlwyy";
                operatorName = "互联网医院";
            }else if(wechatId.equalsIgnoreCase("xm_dsyy_wx")){
                operatorId = "HLWCS";
                operatorName = "互联网医院";
            }
            response = ylzPayService.recharge(operatorId,operatorName,cardType,"01",cardNo,idcard,depositType,price,businessOrderDO.getOrderNo(),openId,patientDO.getName(),notifyUrl);
            if (depositType.equalsIgnoreCase("WX_QR")){
@ -2037,7 +2329,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            }
        }else {
            businessOrderDO = new BusinessOrderDO();
            BasePatientDO patientDO = patientDao.findById(wlyyOutpatientDO.getPatient()).orElse(null);
            BasePatientDO patientDO = patientDao.findById(wlyyOutpatientDO.getPatient()).get();
            String idcard = "";
            if (patientDO!=null){
                idcard = patientDO.getIdcard();
@ -2066,10 +2358,16 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            businessOrderDO.setCreateTime(new Date());
            businessOrderDO.setUpdateTime(new Date());
            businessOrderDao.save(businessOrderDO);
            List<BasePatientWechatDo> patientWechatDos = patientWechatDao.findByWechatIdAndPatientId(wechatId,businessOrderDO.getPatient());
            if (patientWechatDos!=null&&patientWechatDos.size()!=0){
                BasePatientWechatDo patientWechatDo = patientWechatDos.get(0);
                openId = patientWechatDo.getOpenid();
            if(depositType.equalsIgnoreCase("WX_MIN")){
                openId = patientDO.getOpenid();
            }else {
                List<BasePatientWechatDo> patientWechatDos = patientWechatDao.findByWechatIdAndPatientId(wechatId,wlyyOutpatientDO.getConsumer());
                if (patientWechatDos!=null&&patientWechatDos.size()!=0){
                    BasePatientWechatDo patientWechatDo = patientWechatDos.get(0);
                    openId = patientWechatDo.getOpenid();
                }else {
                    throw new Exception("请关注“第三医院”公众号,点击互联网医院-在线诊室进行结算!");
                }
            }
            String price = businessOrderDO.getPayPrice().toString();
            String notifyUrl = hospitalSysDictDO.getDictCode();
@ -2084,6 +2382,9 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
            }else if(wechatId.equalsIgnoreCase("xm_hcyy_wx")){
                operatorId = "hlwyy";
                operatorName = "互联网医院";
            }else if(wechatId.equalsIgnoreCase("xm_dsyy_wx")){
                operatorId = "HLWCS";
                operatorName = "互联网医院";
            }
            response = ylzPayService.recharge(operatorId,operatorName,cardType,"01",cardNo,idcard,depositType,price,businessOrderDO.getOrderNo(),openId,patientDO.getName(),notifyUrl);
            if (depositType.equalsIgnoreCase("WX_QR")){
@ -2156,14 +2457,14 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
     */
    public String yktAppPayJson(String relationCode) throws UnknownHostException {
        String serverIp = getServerIp();
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKT_NOTIFY_URL").orElse(null);
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YKT_NOTIFY_URL").get();
        String url = hospitalSysDictDO.getDictCode();
        String notifyUrl =url;
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode);
        businessOrderDO.setPayType(5);
        businessOrderDao.save(businessOrderDO);
        String totalFee =(int)(businessOrderDO.getPayPrice()*100)+"";
        WlyyHospitalSysDictDO hospitalSysD2ictDO = hospitalSysDictDao.findById("YKTCONTROL").orElse(null);
        WlyyHospitalSysDictDO hospitalSysD2ictDO = hospitalSysDictDao.findById("YKTCONTROL").get();
        if (null != hospitalSysD2ictDO && "0".equalsIgnoreCase(hospitalSysD2ictDO.getDictValue())) {
            return null;
        } else {
@ -2260,13 +2561,13 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                    logger.info("price"+prie);
                    map.put("payPrice",prie);
                }if (orderCategoryFlag.equalsIgnoreCase("1")||orderCategoryFlag.equalsIgnoreCase("2")||orderCategoryFlag.equalsIgnoreCase("3")){
                    WlyyOutpatientDO outpatientDO = outpatientDao.findById(relationCode).orElse(null);
                    WlyyOutpatientDO outpatientDO = outpatientDao.findById(relationCode).get();
                    map.put("doctorName",outpatientDO.getDoctorName());
                    map.put("consumerName",outpatientDO.getConsumerName());
                    map.put("patientName",outpatientDO.getPatientName());
                }else if (orderCategoryFlag.equalsIgnoreCase("4")){
                    WlyyPrescriptionDO prescriptionDO = prescriptionDao.findById(relationCode).orElse(null);
                    WlyyOutpatientDO outpatientDO = outpatientDao.findById(prescriptionDO.getOutpatientId()).orElse(null);
                    WlyyPrescriptionDO prescriptionDO = prescriptionDao.findById(relationCode).get();
                    WlyyOutpatientDO outpatientDO = outpatientDao.findById(prescriptionDO.getOutpatientId()).get();
                    map.put("doctorName",outpatientDO.getDoctorName());
                    map.put("consumerName",outpatientDO.getConsumerName());
                    map.put("patientName",outpatientDO.getPatientName());
@ -2383,7 +2684,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                    map.put("payPrice",prie);
                }
                if (orderCategoryFlag.equalsIgnoreCase("1")||orderCategoryFlag.equalsIgnoreCase("2")||orderCategoryFlag.equalsIgnoreCase("3")){
                    WlyyOutpatientDO outpatientDO = outpatientDao.findById(relationCode).orElse(null);
                    WlyyOutpatientDO outpatientDO = outpatientDao.findById(relationCode).get();
                    if (outpatientDO!=null){
                        map.put("doctorName",outpatientDO.getDoctorName());
                        map.put("consumerName",outpatientDO.getPatientName());
@ -2393,8 +2694,8 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                    }
                }else if (orderCategoryFlag.equalsIgnoreCase("4")){
                    WlyyPrescriptionDO prescriptionDO = prescriptionDao.findById(relationCode).orElse(null);
                    WlyyOutpatientDO outpatientDO = outpatientDao.findById(prescriptionDO.getOutpatientId()).orElse(null);
                    WlyyPrescriptionDO prescriptionDO = prescriptionDao.findById(relationCode).get();
                    WlyyOutpatientDO outpatientDO = outpatientDao.findById(prescriptionDO.getOutpatientId()).get();
                    if (outpatientDO!=null){
                        map.put("doctorName",outpatientDO.getDoctorName());
                        map.put("consumerName",outpatientDO.getPatientName());
@ -2445,7 +2746,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
    ,String geetestValidate,String geetestSeccode) throws Exception {
        String isNeedGeet= "0";//1需要 0不需要
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO1= hospitalSysDictDao.findById("isCardNeedGeet").orElse(null);
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO1= hospitalSysDictDao.findById("isCardNeedGeet").get();
        if (wlyyHospitalSysDictDO1!=null){
            isNeedGeet=wlyyHospitalSysDictDO1.getDictValue();
        }
@ -2455,7 +2756,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                throw new  Exception("验证失败");
            }
        }
        BasePatientDO patientDO = patientDao.findById(patientId).orElse(null);
        BasePatientDO patientDO = patientDao.findById(patientId).get();
        BusinessOrderDO businessOrderDO = new BusinessOrderDO();
        businessOrderDO.setPatient(patientId);
        businessOrderDO.setPatientName(patientDO.getName());

+ 55 - 42
business/base-service/src/main/java/com/yihu/jw/order/pay/ylz/YlzPayService.java

@ -194,47 +194,7 @@ public class YlzPayService {
    }
    public String tradeQuery(String termNo,String operatorId,String operatorName,String outTradeNo,String tradeType,String notes){
        String object  = null;
        Boolean isSuccess = true;
        String error = null;
        OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("ylz_pay_config").orElse(null);
        if(oauthYlzConfigDO==null){
            return "未找到支付配置文件";
        }
        String appId = oauthYlzConfigDO.getAppId();
        String appSecret = oauthYlzConfigDO.getAppKey();
        String onepayUrl = oauthYlzConfigDO.getUrl();
        String signType=oauthYlzConfigDO.getSignType();
        String encryptType = oauthYlzConfigDO.getEncType();
        HisOnepayClient onepayClient = new HisOnepayClient(onepayUrl, appId, appSecret, signType, encryptType);
        TradeQueryParams param = new TradeQueryParams();
        try {
            param.setTermNo("123456");
            param.setOperatorId("123456");
            param.setOperatorName(operatorName);
            param.setTradeType(tradeType);
            param.setOutTradeNo(outTradeNo);
            param.setNotes(notes);
            ResponseParams<TradeQueryResult> response = onepayClient.tradeQuery(param);
            if (response.getRespCode().equals("000000")){
                object = JSON.toJSONString(response);
            }else {
                isSuccess = false;
                object = JSON.toJSONString(response);
                error = "请求失败,返回结果:" + response.getRespCode() + "," + response.getRespMsg();
            }
        } catch (Exception e) {
            e.printStackTrace();
            isSuccess = false;
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            error = sw.toString();
        }
        logService.saveHttpLog(isSuccess, "hop.trade.tradeQuery", "互联网医院查询订单", "POST", null,JSON.toJSONString(param), object, error,logService.onepayType);
        return object;
    }
    /**
@ -400,7 +360,7 @@ public class YlzPayService {
        RechargeParams param = new RechargeParams();
        String error = null;
        try {
            OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("ylz_pay_config").orElse(null);
            OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("ylz_pay_config").get();
            if(oauthYlzConfigDO==null){
                return "未找到支付配置文件";
            }
@ -541,6 +501,58 @@ public class YlzPayService {
        return jsonObject;
    }
    /**
     * 查询是否支付成功
     * @param termNo
     * @param operatorId
     * @param operatorName
     * @param outTradeNo
     * @param tradeType
     * @param notes
     * @return
     */
    public String tradeQuery(String operatorId,String operatorName,String outTradeNo,String tradeType,String notes){
        String object  = null;
        Boolean isSuccess = true;
        String error = null;
        OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("ylz_pay_config").orElse(null);
        if(oauthYlzConfigDO==null){
            return "未找到支付配置文件";
        }
        String appId = oauthYlzConfigDO.getAppId();
        String appSecret = oauthYlzConfigDO.getAppKey();
        String onepayUrl = oauthYlzConfigDO.getUrl();
        String signType=oauthYlzConfigDO.getSignType();
        String encryptType = oauthYlzConfigDO.getEncType();
        HisOnepayClient onepayClient = new HisOnepayClient(onepayUrl, appId, appSecret, signType, encryptType);
        TradeQueryParams param = new TradeQueryParams();
        try {
            param.setTermNo("");
            param.setOperatorId(operatorId);
            param.setOperatorName(operatorName);
            param.setTradeType(tradeType);
            param.setOutTradeNo(outTradeNo);
            param.setNotes(notes);
            ResponseParams<TradeQueryResult> response = onepayClient.tradeQuery(param);
            if (response.getRespCode().equals("000000")){
                object = JSON.toJSONString(response);
            }else {
                isSuccess = false;
                object = JSON.toJSONString(response);
                error = "请求失败,返回结果:" + response.getRespCode() + "," + response.getRespMsg();
            }
        } catch (Exception e) {
            e.printStackTrace();
            isSuccess = false;
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            error = sw.toString();
        }
        logService.saveHttpLog(isSuccess, "hop.trade.tradeQuery", "互联网医院查询订单", "POST", null,JSON.toJSONString(param), object, error,logService.onepayType);
        return object;
    }
    /**
     * 预交金查询余额
@ -592,6 +604,7 @@ public class YlzPayService {
        return jsonObject;
    }
//============================================预交金充值 end======================================================

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/utils/dsyyUtil/ServiceLocator.java

@ -22,7 +22,7 @@ public class ServiceLocator extends org.apache.axis.client.Service implements Se
    }
    // Use to get a proxy class for ServiceSoap
    private String ServiceSoap_address = "http://10.95.8.41/csp/jhip/JHIPLIB.SOAP.BS.Service.cls";
    private String ServiceSoap_address = "http://10.95.8.41:80/csp/jhip/JHIPLIB.SOAP.BS.Service.cls?CfgItem=JH1224%E4%BA%92%E8%81%94%E7%BD%91%E4%BF%9D%E5%AD%98%E7%97%85%E5%8E%86%E6%8E%A5%E5%8F%A3BS";
    public String getServiceSoapAddress() {
        return ServiceSoap_address;

+ 10 - 0
business/base-service/src/main/java/com/yihu/jw/utils/dsyyUtil/ZyXmyytRequestServiceu.java

@ -0,0 +1,10 @@
package com.yihu.jw.utils.dsyyUtil;
import com.sun.jna.Library;
import com.sun.jna.Native;
public interface ZyXmyytRequestServiceu extends Library {
	ZyXmyytRequestServiceu mydll = Native.load("ZyXmyytRequestServiceu.dll",ZyXmyytRequestServiceu.class);
	int CallYYTServerService(String ServerInfo,String RegMsg,String strAnsMsg,String ErrInfo);
 }

+ 26 - 1
common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java

@ -425,10 +425,35 @@ public class HttpClientUtil {
        return ret;
    }
    public  String postBodyText(String url, String params) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("text/plain; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.TEXT_PLAIN_VALUE.toString());
        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params, headers);
        String ret = restTemplate.postForObject(url, formEntity, String.class);
        return ret;
    }
    public  String postHeadBodyText(String url, String params) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("text/plain; charset=GBK");
        headers.setContentType(type);
        headers.add("grant_type","client_credentials");
        headers.add("client_id","HLW");
        headers.add("client_secret","123456");
        headers.add("Accept", MediaType.TEXT_PLAIN_VALUE.toString());
        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params, headers);
        String ret = restTemplate.postForObject(url, formEntity, String.class);
        return ret;
    }
    public  static String postBodyStatic(String url, com.alibaba.fastjson.JSONObject params) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        MediaType type = MediaType.parseMediaType("application/json; charset=GBK");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params.toString(), headers);

+ 12 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java

@ -336,6 +336,8 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        //图形验证码验证
        String key = parameters.get("key");
        String text = parameters.get("text");
        String appletCode = parameters.get("appletCode");
        logger.info("appletCode"+appletCode);
        if (org.apache.commons.lang3.StringUtils.isNotBlank(key) && org.apache.commons.lang3.StringUtils.isNotBlank(text)) {
            if (!verifyCaptcha(key, text)) {
                System.out.println("");
@ -517,6 +519,16 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        baseLoginLogService.save(baseLoginLogDO);
        logger.info("login:登录进入10");
     /*   WxWechatDO wxWechatDO = wechatDao.findById(wechatId).get();
        String appletOpenid = null;
        if (!StringUtils.isEmpty(appletCode)){
            Map<String,Object> objectMap = checkApplets(appletCode,wxWechatDO.getApplets(),wxWechatDO.getAppletsSecret());
            if (objectMap!=null){
                appletOpenid = objectMap.get("openid").toString();
                userDetailsService.updateOpenId(appletOpenid, wlyyUserSimple.getId());
            }
        }*/
        //个推 clientId
        String clientId = parameters.get("getuiClientId");
        String getuiClientType = parameters.get("getuiClientType");

+ 1 - 1
server/svr-authentication/src/main/java/com/yihu/jw/security/service/DsyyService.java

@ -91,7 +91,7 @@ public class DsyyService {
     */
    public JSONObject getTokeninfo(String requestId){
        try {
            String url = entranceUrl+"tokeninfo";
            String url = entranceUrl+"tokeninfo?requestId="+requestId;
            String response = httpClientUtil.get(url,"utf-8");
            logger.info("验证二维码 getQueryQRCode :"+response);
            JSONObject object = JSONObject.parseObject(response);

+ 326 - 2
svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/controller/DsyyController.java

@ -2,8 +2,10 @@ package com.yihu.jw.entrance.controller;
import com.alibaba.fastjson.JSONArray;
import com.yihu.jw.entity.hospital.prescription.WlyyInspectionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDiagnosisDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
import com.yihu.jw.hospital.prescription.service.entrance.DsyyEntranceService;
import com.yihu.jw.order.pay.ylz.YlzPayService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
@ -29,6 +31,8 @@ public class DsyyController extends EnvelopRestEndpoint {
    @Autowired
    private DsyyEntranceService dsyyEntranceService;
    @Autowired
    private YlzPayService ylzPayService;
    @GetMapping(value = "/createSQLQuery")
    @ApiOperation(value = "视图统一查询")
@ -61,8 +65,10 @@ public class DsyyController extends EnvelopRestEndpoint {
                                 @ApiParam(name = "clinicclass", value = "挂号类别(必填)", required = false)
                                        @RequestParam(value = "clinicclass",required = false)String clinicclass,
                                 @ApiParam(name = "courierflag", value = "courierflag", required = false)
                                        @RequestParam(value = "courierflag",required = false)String courierflag) throws Exception {
        return success("请求成功",dsyyEntranceService.registered( doctor,dept,sickId,clinicclass,courierflag));
                                     @RequestParam(value = "courierflag",required = false)String courierflag,
                                 @ApiParam(name = "flag", value = "flag", required = false)
                                     @RequestParam(value = "flag",required = false)String flag) throws Exception {
        return success("请求成功",dsyyEntranceService.registered( doctor,dept,sickId,clinicclass,courierflag,flag));
    }
    @PostMapping(value = "/refundConsultation")
@ -310,6 +316,94 @@ public class DsyyController extends EnvelopRestEndpoint {
    }
    /**
     * 发起充值接口
     *
     * @param operatorId 操作人代码
     * @param operatorName 操作人姓名
     * @param termNo 终端编号
     * @param cardType 卡类型 01
     * @param cardNo 卡号 不为空
     * @param accountType 充值类型 01门诊 02住院
     * @param depositType 充值类型
     * @param channelType 渠道 CASH-现金 POS-pos机 ONE_CREDIT-信用就医 L-移动支付
     * @param amount 充值金额
     * @param outChargeNo 交易日志号
     * @param extra 备用参数
     * @param notes 备注说明
     * @param traceNo 平台唯一交易跟踪号
     * @param status 传空
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/startRecharge")
    @ApiOperation(value = "发起充值接口")
    public ObjEnvelop startRecharge(@ApiParam(name = "operatorId", value = "操作者id", required = false)
                                         @RequestParam(value = "operatorId",required = false)String operatorId,
                                         @ApiParam(name = "operatorName", value = "操作者姓名", required = false)
                                         @RequestParam(value = "operatorName",required = false)String operatorName,
                                         @ApiParam(name = "termNo", value = "终端编号", required = false)
                                         @RequestParam(value = "termNo",required = false)String termNo,
                                         @ApiParam(name = "cardType", value = "卡类型 01", required = false)
                                         @RequestParam(value = "cardType",required = false)String cardType,
                                         @ApiParam(name = "cardNo", value = "卡号", required = false)
                                         @RequestParam(value = "cardNo",required = false)String cardNo,
                                         @ApiParam(name = "accountType", value = "充值类型 01门诊 02住院", required = false)
                                         @RequestParam(value = "accountType",required = false)String accountType,
                                         @ApiParam(name = "depositType", value = "充值类型", required = false)
                                         @RequestParam(value = "depositType",required = false)String depositType,
                                         @ApiParam(name = "channelType", value = "渠道 CASH-现金 POS-pos机 ONE_CREDIT-信用就医 L-移动支付", required = false)
                                         @RequestParam(value = "channelType",required = false)String channelType,
                                         @ApiParam(name = "amount", value = "充值金额", required = false)
                                         @RequestParam(value = "amount",required = false)String amount,
                                         @ApiParam(name = "outChargeNo", value = "交易日志号", required = false)
                                             @RequestParam(value = "outChargeNo",required = false)String outChargeNo,
                                         @ApiParam(name = "extra", value = "备用参数", required = false)
                                             @RequestParam(value = "extra",required = false)String extra,
                                         @ApiParam(name = "notes", value = "备注说明", required = false)
                                             @RequestParam(value = "notes",required = false)String notes,
                                         @ApiParam(name = "traceNo", value = "平台唯一交易跟踪号", required = false)
                                             @RequestParam(value = "traceNo",required = false)String traceNo,
                                         @ApiParam(name = "status", value = "传空", required = false)
                                             @RequestParam(value = "status",required = false)String status) throws Exception {
        return success("请求成功",dsyyEntranceService.startRecharge(operatorId ,operatorName,termNo,cardType,cardNo,accountType,
                depositType,channelType,amount,outChargeNo,extra,notes,traceNo,status));
    }
    @PostMapping(value = "/recharge")
    @ApiOperation(value = "充值确认接口")
    public ObjEnvelop recharge(@ApiParam(name = "operatorId", value = "操作者id", required = false)
                                    @RequestParam(value = "operatorId",required = false)String operatorId,
                                    @ApiParam(name = "operatorName", value = "操作者姓名", required = false)
                                    @RequestParam(value = "operatorName",required = false)String operatorName,
                                    @ApiParam(name = "termNo", value = "终端编号", required = false)
                                    @RequestParam(value = "termNo",required = false)String termNo,
                                    @ApiParam(name = "cardType", value = "卡类型 01", required = false)
                                    @RequestParam(value = "cardType",required = false)String cardType,
                                    @ApiParam(name = "cardNo", value = "卡号", required = false)
                                    @RequestParam(value = "cardNo",required = false)String cardNo,
                                    @ApiParam(name = "accountType", value = "充值类型 01门诊 02住院", required = false)
                                    @RequestParam(value = "accountType",required = false)String accountType,
                                    @ApiParam(name = "depositType", value = "充值类型", required = false)
                                    @RequestParam(value = "depositType",required = false)String depositType,
                                    @ApiParam(name = "channelType", value = "渠道 CASH-现金 POS-pos机 ONE_CREDIT-信用就医 L-移动支付", required = false)
                                    @RequestParam(value = "channelType",required = false)String channelType,
                                    @ApiParam(name = "amount", value = "充值金额", required = false)
                                    @RequestParam(value = "amount",required = false)String amount,
                                    @ApiParam(name = "outChargeNo", value = "交易日志号", required = false)
                                    @RequestParam(value = "outChargeNo",required = false)String outChargeNo,
                                    @ApiParam(name = "extra", value = "备用参数", required = false)
                                    @RequestParam(value = "extra",required = false)String extra,
                                    @ApiParam(name = "notes", value = "备注说明", required = false)
                                    @RequestParam(value = "notes",required = false)String notes,
                                    @ApiParam(name = "traceNo", value = "平台唯一交易跟踪号", required = false)
                                    @RequestParam(value = "traceNo",required = false)String traceNo,
                                    @ApiParam(name = "status", value = "传空", required = false)
                                    @RequestParam(value = "status",required = false)String status) throws Exception {
        return success("请求成功",dsyyEntranceService.recharge(operatorId ,operatorName,termNo,cardType,cardNo,accountType,
                depositType,channelType,amount,outChargeNo,extra,notes,traceNo,status));
    }
    @PostMapping(value = "/sendDispensingToHis")
    @ApiOperation(value = "互联网医院通知院内摆药")
    public ObjEnvelop buildAccount(@ApiParam(name = "hISTradeNo", value = "必填,挂号流水号", required = false)
@ -343,6 +437,28 @@ public class DsyyController extends EnvelopRestEndpoint {
        return success(dsyyEntranceService.tokeninfo(requestId));
    }
    /**
     *
     * @param openId 用户开放标识
     * @param phone 用户手机号
     * @param userIdcardNum 证件号
     * @param employeeNumber 员工号
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/synDoctorSearch")
    @ApiOperation(value = "同步医师结果查询接口")
    public Envelop synDoctorSearch( @ApiParam(name = "openId", value = "用户开放标识", required = false)
                              @RequestParam(value = "openId",required = false)String openId,
                                    @ApiParam(name = "phone", value = "用户手机号", required = false)
                                    @RequestParam(value = "phone",required = false)String phone,
                                    @ApiParam(name = "userIdcardNum", value = "证件号", required = false)
                                    @RequestParam(value = "userIdcardNum",required = false)String userIdcardNum,
                                    @ApiParam(name = "employeeNumber", value = "员工号", required = false)
                                    @RequestParam(value = "employeeNumber",required = false)String employeeNumber) throws Exception {
        return success(dsyyEntranceService.synDoctorSearch(openId,phone,userIdcardNum,employeeNumber));
    }
    @PostMapping(value = "/computeDigestForAlg")
    @ApiOperation(value = "数据哈希计算接口")
    public Envelop computeDigestForAlg(@ApiParam(name = "content", value = "内容", required = false)
@ -434,6 +550,46 @@ public class DsyyController extends EnvelopRestEndpoint {
        return Envelop.getError("发送失败");
    }
    @PostMapping(value = "/dzblSave")
    @ApiOperation(value = "电子病历保存")
    public ObjEnvelop dzblSave(@ApiParam(name = "prescriptionId", value = "处方id", required = false)
                               @RequestParam(value = "prescriptionId",required = false)String prescriptionId) throws Exception {
        return success("请求成功",dsyyEntranceService.dzblSave(prescriptionId));
    }
    @PostMapping(value = "/selectEmrInfoId")
    @ApiOperation(value = "病历查询")
    public ListEnvelop selectEmrInfoId(@ApiParam(name = "patientId", value = "患者id", required = false)
                               @RequestParam(value = "patientId",required = false)String patientId,
                                               @ApiParam(name = "visitNo", value = "就诊次数", required = false)
                                     @RequestParam(value = "visitNo",required = false)String visitNo) throws Exception {
        return success("请求成功",dsyyEntranceService.selectEmrInfoIdAndVisitNo(patientId,visitNo));
    }
    @PostMapping(value = "/selectEmrInfoIdJcpt")
    @ApiOperation(value = "病历查询-webservice")
    public ObjEnvelop<String> selectEmrInfoIdJcpt(@ApiParam(name = "patientId", value = "患者id", required = false)
                                       @RequestParam(value = "patientId",required = false)String patientId,
                                                  @ApiParam(name = "visitNo", value = "就诊次数", required = false)
                                       @RequestParam(value = "visitNo",required = false)String visitNo) throws Exception {
        return success("请求成功",dsyyEntranceService.selectEmrInfoId(patientId,visitNo));
    }
    @PostMapping(value = "/SOF_SignDataWithExtraInfo")
    @ApiOperation(value = "处方签名")
    public ObjEnvelop SOF_SignDataWithExtraInfo(@ApiParam(name = "prescriptionId", value = "处方id", required = false)
                               @RequestParam(value = "prescriptionId",required = false)String prescriptionId) throws Exception {
        return success("请求成功",dsyyEntranceService.SOF_SignDataWithExtraInfo(prescriptionId));
    }
    @PostMapping(value = "/SOF_SignDataWithExtraInfoEmr")
    @ApiOperation(value = "病历签名")
    public ObjEnvelop SOF_SignDataWithExtraInfoEmr(@ApiParam(name = "prescriptionId", value = "处方id", required = false)
                                                @RequestParam(value = "prescriptionId",required = false)String prescriptionId) throws Exception {
        return success("请求成功",dsyyEntranceService.SOF_SignDataWithExtraInfoEmr(prescriptionId));
    }
    @GetMapping(value = "/queryDzfp")
    @ApiOperation(value = "电子发票查询")
    public Envelop queryDzfp(@ApiParam(name = "id", value = "结算id", required = false)
@ -460,4 +616,172 @@ public class DsyyController extends EnvelopRestEndpoint {
    }
    @GetMapping(value = "/recharge")
    @ApiOperation(value = "七十三医院调用")
    public Envelop recharge(@ApiParam(name = "operatorId", value = "operatorId", required = false)
                            @RequestParam(value = "operatorId",required = false)String operatorId,
                            @ApiParam(name = "operatorName", value = "operatorName", required = false)
                            @RequestParam(value = "operatorName",required = false)String operatorName,
                            @ApiParam(name = "cardType", value = "cardType", required = false)
                            @RequestParam(value = "cardType",required = false)String cardType,
                            @ApiParam(name = "accountType", value = "accountType", required = false)
                                @RequestParam(value = "accountType",required = false)String accountType,
                            @ApiParam(name = "cardNo", value = "cardNo", required = false)
                                @RequestParam(value = "cardNo",required = false)String cardNo,
                            @ApiParam(name = "idNo", value = "idNo", required = false)
                                @RequestParam(value = "idNo",required = false)String idNo,
                            @ApiParam(name = "depositType", value = "depositType", required = false)
                                @RequestParam(value = "depositType",required = false)String depositType,
                            @ApiParam(name = "amount", value = "amount", required = false)
                                @RequestParam(value = "amount",required = false)String amount,
                            @ApiParam(name = "outChargeNo", value = "outChargeNo", required = false)
                                @RequestParam(value = "outChargeNo",required = false)String outChargeNo,
                            @ApiParam(name = "openId", value = "openId", required = false)
                                @RequestParam(value = "openId",required = false)String openId,
                            @ApiParam(name = "userName", value = "userName", required = false)
                                @RequestParam(value = "userName",required = false)String userName,
                            @ApiParam(name = "notifyUrl", value = "notifyUrl", required = false)
                                @RequestParam(value = "notifyUrl",required = false)String notifyUrl) throws Exception {
        try {
            return success(ylzPayService.recharge(operatorId,operatorName,cardType,accountType,cardNo,idNo,depositType,amount,outChargeNo,openId,userName,notifyUrl));
        }catch (Exception e){
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = "/updateBySql")
    @ApiOperation(value = "更新语句")
    public ObjEnvelop updateBySql(@ApiParam(name = "sql", value = "sql语句", required = true)
                                  @RequestParam(value = "sql",required = true)String sql){
        ObjEnvelop envelop = new ObjEnvelop();
        dsyyEntranceService.updateBySql(sql);
        return success(envelop);
    }
    /**
     * 合理用药审核
     * @param patient 病人id
     * @param doctor 医生id
     * @param diagnosisDOS 诊断json
     * @param infos  药品json
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/dsyyCheckInfo")
    @ApiOperation(value = "合理用药审核")
    public Envelop dsyyCheckInfo(
            @ApiParam(name = "outpatient", value = "就诊表id")
            @RequestParam(value = "outpatient", defaultValue = "") String outpatient,
            @ApiParam(name = "prescriptionOnly", value = "处方唯一标识")
            @RequestParam(value = "prescriptionOnly", defaultValue = "") String prescriptionOnly,
            @ApiParam(name = "payType", value = "付款方式0自费;1医保")
            @RequestParam(value = "payType", defaultValue = "") String payType,
            @ApiParam(name = "doctor", value = "医生id")
            @RequestParam(value = "doctor", defaultValue = "") String doctor,
            @ApiParam(name = "patient", value = "病人id")
            @RequestParam(value = "patient", defaultValue = "") String patient,
            @ApiParam(name = "diagnosisDOS", value = "诊断json")
            @RequestParam(value = "diagnosisDOS", defaultValue = "") String diagnosisDOS,
            @ApiParam(name = "infos", value = "药品json")
            @RequestParam(value = "infos", defaultValue = "") String infos) throws Exception {
        JSONArray druginfos = JSONArray.parseArray(infos);
        List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS = new ArrayList<>();
        for (int i = 0; i < druginfos.size(); i++) {
            WlyyPrescriptionInfoDO wlyyPrescriptionInfo = toEntity(druginfos.get(i).toString(), WlyyPrescriptionInfoDO.class);
            wlyyPrescriptionInfoDOS.add(wlyyPrescriptionInfo);
        }
        JSONArray diagnosis = JSONArray.parseArray(diagnosisDOS);
        List<WlyyPrescriptionDiagnosisDO> wlyyPrescriptionDiagnosisDOS = new ArrayList<>();
        for (int i = 0; i < diagnosis.size(); i++) {
            WlyyPrescriptionDiagnosisDO wlyyPrescriptionDiagnosisDO = toEntity(diagnosis.get(i).toString(), WlyyPrescriptionDiagnosisDO.class);
            wlyyPrescriptionDiagnosisDOS.add(wlyyPrescriptionDiagnosisDO);
        }
        return success(dsyyEntranceService.checkPrescriptions(outpatient,prescriptionOnly,payType,patient,doctor,wlyyPrescriptionInfoDOS,wlyyPrescriptionDiagnosisDOS));
    }
    /**
     * 处方在医生站系统成功保存后调用
     * @param patient 病人id
     * @param doctor 医生id
     * @param diagnosisDOS 诊断json
     * @param infos  药品json
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/dsyySaveCheckInfo")
    @ApiOperation(value = "处方在医生站系统成功保存后调用")
    public Envelop dsyySaveCheckInfo(
            @ApiParam(name = "outpatient", value = "就诊表id")
            @RequestParam(value = "outpatient", defaultValue = "") String outpatient,
            @ApiParam(name = "prescriptionOnly", value = "处方唯一标识")
            @RequestParam(value = "prescriptionOnly", defaultValue = "") String prescriptionOnly,
            @ApiParam(name = "payType", value = "付款方式0自费;1医保")
            @RequestParam(value = "payType", defaultValue = "") String payType,
            @ApiParam(name = "doctor", value = "医生id")
            @RequestParam(value = "doctor", defaultValue = "") String doctor,
            @ApiParam(name = "patient", value = "病人id")
            @RequestParam(value = "patient", defaultValue = "") String patient,
            @ApiParam(name = "diagnosisDOS", value = "诊断json")
            @RequestParam(value = "diagnosisDOS", defaultValue = "") String diagnosisDOS,
            @ApiParam(name = "infos", value = "药品json")
            @RequestParam(value = "infos", defaultValue = "") String infos) throws Exception {
        JSONArray druginfos = JSONArray.parseArray(infos);
        List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS = new ArrayList<>();
        for (int i = 0; i < druginfos.size(); i++) {
            WlyyPrescriptionInfoDO wlyyPrescriptionInfo = toEntity(druginfos.get(i).toString(), WlyyPrescriptionInfoDO.class);
            wlyyPrescriptionInfoDOS.add(wlyyPrescriptionInfo);
        }
        JSONArray diagnosis = JSONArray.parseArray(diagnosisDOS);
        List<WlyyPrescriptionDiagnosisDO> wlyyPrescriptionDiagnosisDOS = new ArrayList<>();
        for (int i = 0; i < diagnosis.size(); i++) {
            WlyyPrescriptionDiagnosisDO wlyyPrescriptionDiagnosisDO = toEntity(diagnosis.get(i).toString(), WlyyPrescriptionDiagnosisDO.class);
            wlyyPrescriptionDiagnosisDOS.add(wlyyPrescriptionDiagnosisDO);
        }
        return success(dsyyEntranceService.saveCheck(outpatient,prescriptionOnly,payType,patient,doctor,wlyyPrescriptionInfoDOS,wlyyPrescriptionDiagnosisDOS));
    }
    /**
     * 处方保存成功后,发送给审方系统进行人工审方
     * @param patient 病人id
     * @param doctor 医生id
     * @param diagnosisDOS 诊断json
     * @param infos  药品json
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/dsyyValidCheckInfo")
    @ApiOperation(value = "人工审方")
    public Envelop dsyyValidCheckInfo(
            @ApiParam(name = "outpatient", value = "就诊表id")
            @RequestParam(value = "outpatient", defaultValue = "") String outpatient,
            @ApiParam(name = "prescriptionOnly", value = "处方唯一标识")
            @RequestParam(value = "prescriptionOnly", defaultValue = "") String prescriptionOnly,
            @ApiParam(name = "payType", value = "付款方式0自费;1医保")
            @RequestParam(value = "payType", defaultValue = "") String payType,
            @ApiParam(name = "doctor", value = "医生id")
            @RequestParam(value = "doctor", defaultValue = "") String doctor,
            @ApiParam(name = "patient", value = "病人id")
            @RequestParam(value = "patient", defaultValue = "") String patient,
            @ApiParam(name = "diagnosisDOS", value = "诊断json")
            @RequestParam(value = "diagnosisDOS", defaultValue = "") String diagnosisDOS,
            @ApiParam(name = "infos", value = "药品json")
            @RequestParam(value = "infos", defaultValue = "") String infos) throws Exception {
        JSONArray druginfos = JSONArray.parseArray(infos);
        List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS = new ArrayList<>();
        for (int i = 0; i < druginfos.size(); i++) {
            WlyyPrescriptionInfoDO wlyyPrescriptionInfo = toEntity(druginfos.get(i).toString(), WlyyPrescriptionInfoDO.class);
            wlyyPrescriptionInfoDOS.add(wlyyPrescriptionInfo);
        }
        JSONArray diagnosis = JSONArray.parseArray(diagnosisDOS);
        List<WlyyPrescriptionDiagnosisDO> wlyyPrescriptionDiagnosisDOS = new ArrayList<>();
        for (int i = 0; i < diagnosis.size(); i++) {
            WlyyPrescriptionDiagnosisDO wlyyPrescriptionDiagnosisDO = toEntity(diagnosis.get(i).toString(), WlyyPrescriptionDiagnosisDO.class);
            wlyyPrescriptionDiagnosisDOS.add(wlyyPrescriptionDiagnosisDO);
        }
        return success(dsyyEntranceService.validCheck(outpatient,prescriptionOnly,payType,patient,doctor,wlyyPrescriptionInfoDOS,wlyyPrescriptionDiagnosisDOS));
    }
}

+ 8 - 4
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/complaint/BaseComplaintEndPoint.java

@ -280,14 +280,15 @@ public class BaseComplaintEndPoint extends EnvelopRestEndpoint {
            @ApiParam(name = "endTime", value = "endTime", required = false) @RequestParam(value = "endTime", required = false) String endTime,
            @ApiParam(name = "page", value = "page", required = false) @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(name = "pageSize", value = "pageSize", required = false) @RequestParam(value = "pageSize", required = false) Integer pageSize,
            @ApiParam(name = "startTime", value = "startTime", required = false) @RequestParam(value = "startTime", required = false) String startTime
            @ApiParam(name = "startTime", value = "startTime", required = false) @RequestParam(value = "startTime", required = false) String startTime,
            @ApiParam(name = "pcAdmin", value = "pcAdmin", required = false) @RequestParam(value = "pcAdmin", required = false) String pcAdmin
    ) throws Exception {
        try {
            if (!StringUtils.isNotBlank(doctor)) {
                doctor = getUID();
            }
            return success(baseComplaintService.findComplaintList(role, doctor, status, patientName, patientId, keyWord, complaintId,
                    startTime, endTime, page, pageSize));
                    startTime, endTime, page, pageSize,pcAdmin));
        } catch (Exception e) {
            return failedException(e);
        }
@ -345,9 +346,12 @@ public class BaseComplaintEndPoint extends EnvelopRestEndpoint {
    @ApiOperation(value = "查询投诉建议数量", notes = "查询投诉建议单挑")
    public Envelop findComplaintCount(
            @ApiParam(name = "doctor", value = "doctor", required = false) @RequestParam(value = "doctor", required = false) String doctor,
            @ApiParam(name = "role", value = "role", required = false) @RequestParam(value = "role", required = false) String role) throws Exception {
            @ApiParam(name = "role", value = "role", required = false) @RequestParam(value = "role", required = false) String role,
            @ApiParam(name = "pcAdmin", value = "pc管理员传值", required = false) @RequestParam(value = "pcAdmin", required = false) String pcAdmin
    ) throws Exception {
        try {
            return success(baseComplaintService.findComplaintCount(doctor, role));
            return success(baseComplaintService.findComplaintCount(doctor, role,pcAdmin));
        } catch (Exception e) {
            return failedException(e);
        }

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

@ -267,6 +267,9 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
    @Autowired
    private DictHospitalDeptDao dictHospitalDeptDao;
    @Autowired
    private DsyyPrescriptionService dsyyPrescriptionService;
    @GetMapping(value = "orgInfo")
    @ApiOperation(value = "机构详情", notes = "机构详情")
@ -737,7 +740,8 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
            if (!isDecrypt) {
                response.getWriter().write("DECRYPT FAILURE");
            } else {
                boolean isVerify = client.verifyResponseSign(decryptRes);
//                boolean isVerify = client.verifyResponseSign(decryptRes);
                boolean isVerify = true;
                logger.info("验签结果:{}", isVerify);
                if (!isVerify) {
                    response.getWriter().write("FAILURE");
@ -748,6 +752,11 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
                    String traceNo = param.getString("outChargeNo");
                    //im处方发消息
                    BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(traceNo);
                    if(wxId.equalsIgnoreCase("xm_dsyy_wx")){
                        logger.info("his充值开始");
                        dsyyPrescriptionService.rechargeHis(businessOrderDO.getOrderNo());
                        logger.info("his充值结束");
                    }
                    if (businessOrderDO.getStatus()!=1){
                        if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("4")){
                            WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findById(businessOrderDO.getRelationCode()).orElse(null);
@ -781,7 +790,9 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
                            hospitalSystemMessageService.sendImMessage(systemMessageDO);
                        }else if (businessOrderDO!=null&&businessOrderDO.getOrderCategory().equalsIgnoreCase("6")){
                            YlzMedicalRelationDO ylzMedicalRelationDO = ylzMedicailRelationDao.findById(businessOrderDO.getRelationCode()).orElse(null);
                            prescriptionService.confirmSettlementService(ylzMedicalRelationDO.getRelationCode());
                            if (wxId.equalsIgnoreCase("xm_dsyy_wx")){
                                dsyyPrescriptionService.confirmSettlement(ylzMedicalRelationDO.getRelationCode());
                            }
                        }
                    }
                    businessOrderService.updatePayStatus(traceNo);
@ -897,7 +908,6 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
        return appId;
    }
    @PostMapping(value= BaseHospitalRequestMapping.Prescription.findWorkTimeRule)
    @ApiOperation(value = "查询排班规则")
    public ObjEnvelop findWorkTimeRule(@ApiParam(name = "hospital", value = "医院code")

+ 113 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/DsyyPrescriptionCotroller.java

@ -6,6 +6,7 @@ import com.yihu.jw.entity.hospital.prescription.*;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDiagnosisDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionInfoDao;
import com.yihu.jw.hospital.prescription.service.DsyyPrescriptionService;
import com.yihu.jw.hospital.prescription.service.HcyyPrescriptionService;
import com.yihu.jw.hospital.prescription.service.entrance.DsyyEntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.HcyyEntranceService;
@ -47,6 +48,8 @@ public class DsyyPrescriptionCotroller extends EnvelopRestEndpoint {
    private ImService imService;
    @Autowired
    private DsyyEntranceService dsyyEntranceService;
    @Autowired
    private DsyyPrescriptionService dsyyPrescriptionService;
    @GetMapping(value = "/updateDept")
@ -63,7 +66,117 @@ public class DsyyPrescriptionCotroller extends EnvelopRestEndpoint {
        return ObjEnvelop.getSuccess("ok",dsyyEntranceService.updateDoctor(idcard));
    }
    @GetMapping(value= "rechargeHis")
    @ApiOperation(value = "回调his预缴金充值")
    public ObjEnvelop rechargeHis(@ApiParam(name = "orderNo", value = "订单编码")
                                  @RequestParam(value = "orderNo",required = true)String orderNo) throws Exception {
        return success(dsyyPrescriptionService.rechargeHis(orderNo));
    }
    /**
     * 合理用药审核
     * @param patient 病人id
     * @param doctor 医生id
     * @param diagnosisDOS 诊断json
     * @param infos  药品json
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/dsyyCheckInfo")
    @ApiOperation(value = "合理用药审核")
    public Envelop dsyyCheckInfo(
            @ApiParam(name = "outpatient", value = "就诊表id")
            @RequestParam(value = "outpatient", defaultValue = "") String outpatient,
            @ApiParam(name = "prescriptionOnly", value = "处方唯一标识")
            @RequestParam(value = "prescriptionOnly", defaultValue = "") String prescriptionOnly,
            @ApiParam(name = "payType", value = "付款方式0自费;1医保")
            @RequestParam(value = "payType", defaultValue = "") String payType,
            @ApiParam(name = "doctor", value = "医生id")
            @RequestParam(value = "doctor", defaultValue = "") String doctor,
            @ApiParam(name = "patient", value = "病人id")
            @RequestParam(value = "patient", defaultValue = "") String patient,
            @ApiParam(name = "diagnosisDOS", value = "诊断json")
            @RequestParam(value = "diagnosisDOS", defaultValue = "") String diagnosisDOS,
            @ApiParam(name = "infos", value = "药品json")
            @RequestParam(value = "infos", defaultValue = "") String infos) throws Exception {
        return success(dsyyPrescriptionService.dsyyCheckInfo(outpatient,prescriptionOnly,payType,doctor,patient,diagnosisDOS,infos));
    }
    /**
     * 处方在医生站系统成功保存后调用
     * @param patient 病人id
     * @param doctor 医生id
     * @param diagnosisDOS 诊断json
     * @param infos  药品json
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/dsyySaveCheckInfo")
    @ApiOperation(value = "处方在医生站系统成功保存后调用")
    public Envelop dsyySaveCheckInfo(
            @ApiParam(name = "outpatient", value = "就诊表id")
            @RequestParam(value = "outpatient", defaultValue = "") String outpatient,
            @ApiParam(name = "prescriptionOnly", value = "处方唯一标识")
            @RequestParam(value = "prescriptionOnly", defaultValue = "") String prescriptionOnly,
            @ApiParam(name = "payType", value = "付款方式0自费;1医保")
            @RequestParam(value = "payType", defaultValue = "") String payType,
            @ApiParam(name = "doctor", value = "医生id")
            @RequestParam(value = "doctor", defaultValue = "") String doctor,
            @ApiParam(name = "patient", value = "病人id")
            @RequestParam(value = "patient", defaultValue = "") String patient,
            @ApiParam(name = "diagnosisDOS", value = "诊断json")
            @RequestParam(value = "diagnosisDOS", defaultValue = "") String diagnosisDOS,
            @ApiParam(name = "infos", value = "药品json")
            @RequestParam(value = "infos", defaultValue = "") String infos) throws Exception {
        return success(dsyyPrescriptionService.dsyySaveCheckInfo(outpatient,prescriptionOnly,payType,doctor,patient,diagnosisDOS,infos));
    }
    /**
     * 处方保存成功后,发送给审方系统进行人工审方
     * @param patient 病人id
     * @param doctor 医生id
     * @param diagnosisDOS 诊断json
     * @param infos  药品json
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/dsyyValidCheckInfo")
    @ApiOperation(value = "人工审方")
    public Envelop dsyyValidCheckInfo(
            @ApiParam(name = "outpatient", value = "就诊表id")
            @RequestParam(value = "outpatient", defaultValue = "") String outpatient,
            @ApiParam(name = "prescriptionOnly", value = "处方唯一标识")
            @RequestParam(value = "prescriptionOnly", defaultValue = "") String prescriptionOnly,
            @ApiParam(name = "payType", value = "付款方式0自费;1医保")
            @RequestParam(value = "payType", defaultValue = "") String payType,
            @ApiParam(name = "doctor", value = "医生id")
            @RequestParam(value = "doctor", defaultValue = "") String doctor,
            @ApiParam(name = "patient", value = "病人id")
            @RequestParam(value = "patient", defaultValue = "") String patient,
            @ApiParam(name = "diagnosisDOS", value = "诊断json")
            @RequestParam(value = "diagnosisDOS", defaultValue = "") String diagnosisDOS,
            @ApiParam(name = "infos", value = "药品json")
            @RequestParam(value = "infos", defaultValue = "") String infos) throws Exception {
        return success(dsyyPrescriptionService.dsyyValidCheckInfo(outpatient,prescriptionOnly,payType,doctor,patient,diagnosisDOS,infos));
    }
    /**
     * 处方保存成功后,发送给审方系统进行人工审方
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/sfToHis")
    @ApiOperation(value = "物流通知his摆药")
    public Envelop sfToHis(
            @ApiParam(name = "outpatientId", value = "就诊表id")
            @RequestParam(value = "outpatientId", defaultValue = "") String outpatientId,
            @ApiParam(name = "realorder", value = "处方号")
            @RequestParam(value = "realorder", defaultValue = "") String realorder) throws Exception {
        return success(dsyyPrescriptionService.sfToHis(outpatientId,realorder));
    }
}

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

@ -385,12 +385,9 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
                                           @ApiParam(name = "prescriptionId", value = "处方ID")
                                           @RequestParam(value = "prescriptionId", required = false) String prescriptionId) throws Exception {
        try {
            com.alibaba.fastjson.JSONObject obj = prescriptionService.findReOutpatientInfo(outpatientId, prescriptionId, wxId);
            return success(obj);
        } catch (Exception e) {
            return failedObjEnvelopException(e);
        }
        com.alibaba.fastjson.JSONObject obj = prescriptionService.findReOutpatientInfo(outpatientId, prescriptionId, wxId);
        return success(obj);
    }
    @GetMapping(value = BaseHospitalRequestMapping.Prescription.findPrescriptionInfo)
@ -1852,6 +1849,8 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
            return success(ykyyService.getSignPicture(doctor));
        }else if (wxId.equalsIgnoreCase("xm_hcyy_wx")){
            return success(hcyyEntranceService.getSignPicture(doctor));
        }else if (wxId.equalsIgnoreCase("xm_dsyy_wx")){
            return success(dsyyPrescriptionService.getSignPicture(doctor));
        }else {
            return success("功能尚未开通","500");
        }
@ -2153,12 +2152,10 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "cardType", value = "cardType", required = true)
            @RequestParam(required = true) String cardType,
            @ApiParam(name = "cardNo", value = "cardNo", required = true)
            @RequestParam(required = true) String cardNo) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok", businessOrderService.ylzRechargeJson(relationCode, depositType, wxId, cardType, cardNo, demoFlag));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
            @RequestParam(required = true) String cardNo,
            @ApiParam(name = "appletCode", value = "appletCode", required = false)
            @RequestParam(required = false) String appletCode) throws Exception {
        return ObjEnvelop.getSuccess("ok", businessOrderService.ylzRechargeJson(relationCode, depositType, wxId, cardType, cardNo, demoFlag,appletCode));
    }
    /**
@ -2178,9 +2175,16 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "cardType", value = "cardType", required = true)
            @RequestParam(required = true) String cardType,
            @ApiParam(name = "cardNo", value = "cardNo", required = true)
            @RequestParam(required = true) String cardNo) throws Exception {
            @RequestParam(required = true) String cardNo,
            @ApiParam(name = "appletCode", value = "appletCode", required = false)
            @RequestParam(required = false) String appletCode) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok", businessOrderService.ylzRechargePre(relationCode, depositType, wxId, cardType, cardNo, demoFlag));
            if (wxId.equalsIgnoreCase("xm_dsyy_wx")){
                return ObjEnvelop.getSuccess("ok", businessOrderService.ylzRechargePreDs(relationCode, depositType, wxId, cardType, cardNo, demoFlag,appletCode));
            }else {
                return ObjEnvelop.getSuccess("ok", businessOrderService.ylzRechargePre(relationCode, depositType, wxId, cardType, cardNo, demoFlag));
            }
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
@ -2329,12 +2333,12 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value = BaseHospitalRequestMapping.Prescription.tradeQuery)
    @ApiOperation("易联众统一订单查询")
    public ObjEnvelop tradeQuery(
            @ApiParam(name = "tradeType", value = "tradeType", required = true)
            @ApiParam(name = "tradeType", value = "交易hop.trade.recharge退款hop.trade.refund", required = true)
            @RequestParam(required = true) String tradeType,
            @ApiParam(name = "orderNo", value = "orderNo", required = true)
            @RequestParam(required = true) String orderNo) throws Exception {
            @ApiParam(name = "relationCode", value = "relationCode", required = true)
            @RequestParam(required = true) String relationCode) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok", businessOrderService.tradeQuery(orderNo, tradeType));
            return ObjEnvelop.getSuccess("ok", businessOrderService.tradeQuery(relationCode, tradeType));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
@ -2429,13 +2433,8 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "prescriptionId", value = "prescriptionId", required = true)
            @RequestParam(required = true) String prescriptionId,HttpServletRequest request) throws Exception {
        WlyyPrescriptionCheckDO wlyyPrescriptionCheckDO = null;
        wlyyPrescriptionCheckDO = prescriptionService.saveCheck(operate, operateName, reason, status, prescriptionId, wxId,getIpAddress(request));
        try {
            wlyyPrescriptionCheckDO = prescriptionService.saveCheck(operate, operateName, reason, status, prescriptionId, wxId,getIpAddress(request));
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionService.findPrescriptionDo(prescriptionId);
            WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(wlyyPrescriptionDO.getOutpatientId()).orElse(null);
            if (status == 1) {
@ -2474,7 +2473,6 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
            System.out.println("发送诊断消息失败:" + e.getMessage());
//            e.printStackTrace();
        }
        return ObjEnvelop.getSuccess("ok", wlyyPrescriptionCheckDO);
    }
@ -2701,6 +2699,8 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
                return ObjEnvelop.getSuccess("ok", xzzxEntranceService.selectHistoryEmrFromEntrance(patient, null));
            } else if (wxId.equalsIgnoreCase("xm_hcyy_wx")) {
                return ObjEnvelop.getSuccess("ok", hcyyPrescriptionService.selectHistoryEmrFromEntrance(patient, null));
            }  else if (wxId.equalsIgnoreCase("xm_dsyy_wx")) {
                return ObjEnvelop.getSuccess("ok", dsyyPrescriptionService.selectHistoryEmrFromEntrance(patient, null));
            } else {
                return ObjEnvelop.getSuccess("ok", prescriptionService.outpatient(patient, doctorId));
            }
@ -2735,7 +2735,9 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
                return ObjEnvelop.getSuccess("ok", xzzxEntranceService.selectBrowseSingleEMR(opid));
            }else if (wxId.equalsIgnoreCase("xm_hcyy_wx")) {
                return ObjEnvelop.getSuccess("ok", hcyyPrescriptionService.selectBrowseSingleEMR(opid));
            }  else {
            } else if (wxId.equalsIgnoreCase("xm_dsyy_wx")) {
                return ObjEnvelop.getSuccess("ok", dsyyPrescriptionService.selectHistoryEmrRecord(opid,recSn));
            } else {
                return ObjEnvelop.getSuccess("ok", prescriptionService.getPatInfoDataXml(opid, recSn));
            }
        } catch (Exception e) {
@ -3703,7 +3705,12 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "outpatientId", value = "outpatientId")
            @RequestParam(value = "outpatientId", required = false) String outpatientId) throws Exception {
        try {
            return success("操作成功", prescriptionService.confirmSettlementService(outpatientId));
            if (wxId.equalsIgnoreCase("xm_dsyy_wx")){
                return success("操作成功", dsyyPrescriptionService.confirmSettlement(outpatientId));
            }else {
                return success("操作成功", prescriptionService.confirmSettlementService(outpatientId));
            }
        } catch (Exception e) {
            return Envelop.getError(e.getMessage());
        }

+ 392 - 372
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/service/consult/KnowledgeArticleService.java

@ -29,6 +29,7 @@ import com.yihu.jw.utils.EntityUtils;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import java.util.Date;
@ -38,409 +39,428 @@ import java.util.UUID;
/**
 * 健康文章业务层代码
 *
 * @author huangwenjie
 * @date 2019/9/10 13:54
 */
@Service
public class KnowledgeArticleService extends BaseJpaService<KnowledgeArticleDO, KnowledgeArticleDao> {
	
	@Autowired
	private KnowledgeArticleDao knowledgeArticleDao;
	@Autowired
	private KnowledgeArticleDictDao knowledgeArticleDictDao;
	@Autowired
	private KnowledgeArticleDeptDao knowledgeArticleDeptDao;
	@Autowired
	private WlyyHospitalSysDictDao hospitalSysDictDao;
	@Autowired
	private BasePatientBusinessDao patientBusinessDao;
	@Autowired
	private KnowledgeArticleUserDao knowledgeArticleUserDao;
	@Autowired
	private BaseDoctorHospitalDao doctorHospitalDao;
	@Autowired
	private BaseDoctorDao doctorDao;
	@Autowired
	private ImUtil imUtil;
	@Autowired
	private SurveyUserDao surveyUserDao;
	@Autowired
	private SurveyTemplateDao surveyTemplateDao;
	@Autowired
    @Autowired
    private KnowledgeArticleDao knowledgeArticleDao;
    @Autowired
    private KnowledgeArticleDictDao knowledgeArticleDictDao;
    @Autowired
    private KnowledgeArticleDeptDao knowledgeArticleDeptDao;
    @Autowired
    private WlyyHospitalSysDictDao hospitalSysDictDao;
    @Autowired
    private BasePatientBusinessDao patientBusinessDao;
    @Autowired
    private KnowledgeArticleUserDao knowledgeArticleUserDao;
    @Autowired
    private BaseDoctorHospitalDao doctorHospitalDao;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private ImUtil imUtil;
    @Autowired
    private SurveyUserDao surveyUserDao;
    @Autowired
    private SurveyTemplateDao surveyTemplateDao;
    @Autowired
    private HibenateUtils hibenateUtils;
	@Autowired
	private BasePatientDao patientDao;
	
	/**
	 * 删除,支持批量
	 * @param id
	 */
	public boolean delArticle(String id){
		String[] split = id.split(",|,");
		String ids = StringUtils.join(split, ",");
		String sql = "update wlyy_knowledge_article a set a.del = 0 where a.id in(" + ids + ")";
		String sqlUser = "update wlyy_knowledge_article_user a set a.del = 0 where a.relation_code in(" + ids + ")";
		String sqlBussiness = "update base_patient_business a set a.del = 0 where a.relation_code in(" + ids + ")";
		int update = jdbcTemplate.update(sql);
		int updateUser = jdbcTemplate.update(sqlUser);
		int updateBussiness  = jdbcTemplate.update(sqlBussiness);
		if (update > 0||updateUser>0||updateBussiness>0) {
			return true;
		}
		return false;
	}
	
	/**
	 * 更新/保存健康文章
	 * @param jsonData
	 * @return
	 * @throws Exception
	 */
	public KnowledgeArticleDO saveArticle(String jsonData) throws  Exception {
		WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("EXAMINE").orElse(null);
		KnowledgeArticleDO knowledgeArticleDO = EntityUtils.jsonToEntity(jsonData, KnowledgeArticleDO.class);
		if (null == knowledgeArticleDO.getId()) {
			// 新增
			knowledgeArticleDO.setId(UUID.randomUUID().toString().replace("-", ""));
			knowledgeArticleDO.setCreateTime(new Date());
    @Autowired
    private BasePatientDao patientDao;
    /**
     * 删除,支持批量
     *
     * @param id
     */
    public boolean delArticle(String id) {
        String[] split = id.split(",|,");
        String ids = StringUtils.join(split, ",");
        String sql = "update wlyy_knowledge_article a set a.del = 0 where a.id in(" + ids + ")";
        String sqlUser = "update wlyy_knowledge_article_user a set a.del = 0 where a.relation_code in(" + ids + ")";
        String sqlBussiness = "update base_patient_business a set a.del = 0 where a.relation_code in(" + ids + ")";
        int update = jdbcTemplate.update(sql);
        int updateUser = jdbcTemplate.update(sqlUser);
        int updateBussiness = jdbcTemplate.update(sqlBussiness);
        if (update > 0 || updateUser > 0 || updateBussiness > 0) {
            return true;
        }
        return false;
    }
    /**
     * 更新/保存健康文章
     *
     * @param jsonData
     * @return
     * @throws Exception
     */
    public KnowledgeArticleDO saveArticle(String jsonData) throws Exception {
        WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("EXAMINE").orElse(null);
        KnowledgeArticleDO knowledgeArticleDO = EntityUtils.jsonToEntity(jsonData, KnowledgeArticleDO.class);
        if (null == knowledgeArticleDO.getId()) {
            // 新增
            knowledgeArticleDO.setId(UUID.randomUUID().toString().replace("-", ""));
            knowledgeArticleDO.setCreateTime(new Date());
//			knowledgeArticleDO.setSource("客服");
			knowledgeArticleDO.setDel(1);
			if (wlyyHospitalSysDictDO!=null&&wlyyHospitalSysDictDO.getDictValue().equalsIgnoreCase("0")){
				knowledgeArticleDO.setStatus(1);
			}
			knowledgeArticleDO = knowledgeArticleDao.save(knowledgeArticleDO);
			return knowledgeArticleDO;
		} else {
			KnowledgeArticleDO one = knowledgeArticleDao.findById(knowledgeArticleDO.getId()).orElse(null);
			one.setTitle(knowledgeArticleDO.getTitle());
			one.setContent(knowledgeArticleDO.getContent());
			one.setImage(knowledgeArticleDO.getImage());
			one.setUpdateTime(new Date());
			if (wlyyHospitalSysDictDO!=null&&wlyyHospitalSysDictDO.getDictValue().equalsIgnoreCase("0")){
				one.setStatus(1);
			}
			knowledgeArticleDao.save(one);
			return  one;
		}
	}
            knowledgeArticleDO.setDel(1);
            if (wlyyHospitalSysDictDO != null && wlyyHospitalSysDictDO.getDictValue().equalsIgnoreCase("0")) {
                knowledgeArticleDO.setStatus(1);
            }
            knowledgeArticleDO = knowledgeArticleDao.save(knowledgeArticleDO);
            return knowledgeArticleDO;
        } else {
            KnowledgeArticleDO one = knowledgeArticleDao.findById(knowledgeArticleDO.getId()).orElse(null);
            one.setTitle(knowledgeArticleDO.getTitle());
            one.setContent(knowledgeArticleDO.getContent());
            one.setImage(knowledgeArticleDO.getImage());
            one.setUpdateTime(new Date());
            if (wlyyHospitalSysDictDO != null && wlyyHospitalSysDictDO.getDictValue().equalsIgnoreCase("0")) {
                one.setStatus(1);
            }
            knowledgeArticleDao.save(one);
            return one;
        }
    }
    /**
     * 更新/保存健康文章
     *
     * @return
     * @throws Exception
     */
    public KnowledgeArticleDO updateIsShow(String id, Integer isShow) throws Exception {
	/**
	 * 更新/保存健康文章
	 * @return
	 * @throws Exception
	 */
	public KnowledgeArticleDO updateIsShow(String id,Integer isShow) throws  Exception {
        KnowledgeArticleDO one = knowledgeArticleDao.findById(id).orElse(null);
        one.setIsShow(isShow);
        one.setUpdateTime(new Date());
        knowledgeArticleDao.save(one);
        return one;
		KnowledgeArticleDO one = knowledgeArticleDao.findById(id).orElse(null);
		one.setIsShow(isShow);
		one.setUpdateTime(new Date());
		knowledgeArticleDao.save(one);
		return  one;
    }
	}
	
	//审核/退回文章
	public KnowledgeArticleDO reviewArticle(String articleId,Integer status,String reason) throws Exception{
		
		KnowledgeArticleDO knowledgeArticleDO = knowledgeArticleDao.findById(articleId).orElse(null);
		if (null == knowledgeArticleDO) {
			throw new Exception("该文章不存在");
		} else {
			knowledgeArticleDO.setStatus(status);
			knowledgeArticleDO.setUpdateTime(new Date());
			if(StringUtils.isNotBlank(reason)){
				knowledgeArticleDO.setCancelReason(reason);
			}
			knowledgeArticleDao.save(knowledgeArticleDO);
			return  knowledgeArticleDO;
		}
	}
	
	/**
	 * 保存文章科室关系
	 * @param articleId
	 * @param sdJsons
	 * @return
	 * @throws Exception
	 */
	public Boolean saveArticleDept(String articleId,String sdJsons)throws Exception{
		
		//删除之前关系
		List<KnowledgeArticleDeptDO> list = knowledgeArticleDeptDao.findByArticleId(articleId);
		if(list!=null&&list.size()>0){
			knowledgeArticleDeptDao.deleteAll(list);
		}
		
		if(org.apache.commons.lang3.StringUtils.isNotBlank(sdJsons)){
			List<KnowledgeArticleDeptDO> _list = EntityUtils.jsonToList(sdJsons,KnowledgeArticleDeptDO.class);
			if(_list!=null&&_list.size()>0){
				knowledgeArticleDeptDao.saveAll(_list);
			}
		}
		return true;
	}
	
	/**
	 * 查询文章下科室
	 * @param articleId
	 * @return
	 */
	public List<Map<String,Object>> findDeptByArticle(String articleId)throws Exception{
		String sql ="SELECT " +
				" d.article_id AS articleId," +
				" d.dept, " +
				" d.dept_name AS deptName " +
				" FROM " +
				" wlyy_knowledge_article t " +
				" JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
				" WHERE " +
				" t.id = '"+articleId+"'";
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
		return list;
	}
	
	/**
	 * 查询部门下的文章
	 * @param dept
	 * @return
	 */
	public List<Map<String,Object>> findArticleByDept(String dept)throws Exception{
		String sql = "SELECT " +
				" t.id as \"id\", " +
				" t.title as \"title\", " +
				" t.create_time AS \"create_time\" ," +
				" t.image AS \"image\" " +
				" FROM " +
				" wlyy_knowledge_article t " +
				" JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
				" WHERE " +
				" d.dept = '"+dept+"'";
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
		return list;
	}
	
	/**
	 * 设置部门发送文章
	 * @param dept
	 * @param sdJsons
	 * @return
	 */
	public Boolean saveDeptArticle(String dept, String sdJsons) throws Exception{
		
		//删除之前关系
		List<KnowledgeArticleDeptDO> dels = knowledgeArticleDeptDao.findByDept(dept);
		if(dels!=null&&dels.size()>0){
			knowledgeArticleDeptDao.deleteAll(dels);
		}
		
		if(org.apache.commons.lang3.StringUtils.isNotBlank(sdJsons)){
			List<KnowledgeArticleDeptDO> list = EntityUtils.jsonToList(sdJsons,KnowledgeArticleDeptDO.class);
			if(list!=null&&list.size()>0){
				knowledgeArticleDeptDao.saveAll(list);
			}
		}
		return true;
	}
    //审核/退回文章
    public KnowledgeArticleDO reviewArticle(String articleId, Integer status, String reason) throws Exception {
	/**
	 *	患者接收问卷/文章
	 * @param businessDOS
	 * @return
	 */
	public List<BasePatientBusinessDO> sendBusinessToPatient(List<BasePatientBusinessDO> businessDOS) throws Exception {
		if (businessDOS!=null&&businessDOS.size()!=0){
			for (BasePatientBusinessDO patientBusinessDO:businessDOS){
				BasePatientBusinessDO basePatientBusinessDO = patientBusinessDao.findByPatientAndRelationCodeAndDel(patientBusinessDO.getPatient(),patientBusinessDO.getRelationCode());
				if (basePatientBusinessDO != null) {
					throw new Exception("已发送过!");
				}
				patientBusinessDO.setCreateTime(new Date());
				patientBusinessDO.setUpdateTime(new Date());
				patientBusinessDO.setCreateUser(patientBusinessDO.getDoctor());
				patientBusinessDO.setUpdateUser(patientBusinessDO.getDoctor());
				patientBusinessDO.setCreateUserName(patientBusinessDO.getDoctorName());
				patientBusinessDO.setUpdateUserName(patientBusinessDO.getUpdateUserName());
				patientBusinessDO.setCollection(0);
				patientBusinessDO.setDel(1);
				patientBusinessDO = patientBusinessDao.save(patientBusinessDO);
				if (patientBusinessDO.getRelationType()==1){
					KnowledgeArticleDO knowledgeArticleDO = knowledgeArticleDao.findByIdAndDel(patientBusinessDO.getRelationCode());
					JSONObject object = new JSONObject();
					if(knowledgeArticleDO==null){
						KnowledgeArticleDictDO knowledgeArticleDictDO = knowledgeArticleDictDao.findByIdAndDel(patientBusinessDO.getRelationCode());
						object.put("id",knowledgeArticleDictDO.getId());
						object.put("title",knowledgeArticleDictDO.getTitle());
						object.put("content",knowledgeArticleDictDO.getIntro());
						object.put("img",knowledgeArticleDictDO.getImage());
						object.put("type",knowledgeArticleDictDO.getType());
					}else {
						object.put("id",knowledgeArticleDO.getId());
						object.put("title",knowledgeArticleDO.getTitle());
						object.put("content",knowledgeArticleDO.getIntro());
						object.put("img",knowledgeArticleDO.getImage());
					}
					imUtil.sendImMsg(patientBusinessDO.getDoctor(), patientBusinessDO.getDoctorName(), patientBusinessDO.getSessionId(), "4", object.toJSONString(),"1",null);
				}else {
					WlyySurveyUserDO wlyySurveyUserDO = new WlyySurveyUserDO();
					String doctor = patientBusinessDO.getDoctor();
					BaseDoctorDO doctorDO = doctorDao.findById(doctor).orElse(null);
					wlyySurveyUserDO.setDept(doctorDO.getVisitDept());
					wlyySurveyUserDO.setDeptName(doctorDO.getVisitDeptName());
					wlyySurveyUserDO.setDoctor(doctor);
					wlyySurveyUserDO.setDoctorName(doctorDO.getName());
					wlyySurveyUserDO.setStatus(0);
					wlyySurveyUserDO.setPatient(patientBusinessDO.getPatient());
					wlyySurveyUserDO.setPatientName(patientBusinessDO.getPatientName());
					wlyySurveyUserDO.setSurveyTempCode(patientBusinessDO.getRelationCode());
					wlyySurveyUserDO.setSurveyTempTitle(patientBusinessDO.getRelationName());
					wlyySurveyUserDO.setCreateTime(new Date());
					wlyySurveyUserDO.setEndTime(new Date());
					wlyySurveyUserDO = surveyUserDao.save(wlyySurveyUserDO);
					JSONObject object = new JSONObject();
					WlyySurveyTemplateDO wlyySurveyTemplateDO = surveyTemplateDao.findById(wlyySurveyUserDO.getSurveyTempCode()).orElse(null);
					if (null!=wlyySurveyTemplateDO){
						object.put("title",wlyySurveyTemplateDO.getTitle());
						object.put("content",wlyySurveyTemplateDO.getTemplateComment());
						object.put("doctor",patientBusinessDO.getDoctor());
						object.put("doctorName",patientBusinessDO.getDoctorName());
						object.put("id",wlyySurveyTemplateDO.getId());
					}
					imUtil.sendImMsg(patientBusinessDO.getDoctor(), patientBusinessDO.getDoctorName(), patientBusinessDO.getSessionId(), "17", object.toJSONString(),"1",null);
				}
        KnowledgeArticleDO knowledgeArticleDO = knowledgeArticleDao.findById(articleId).orElse(null);
        if (null == knowledgeArticleDO) {
            throw new Exception("该文章不存在");
        } else {
            knowledgeArticleDO.setStatus(status);
            knowledgeArticleDO.setUpdateTime(new Date());
            if (StringUtils.isNotBlank(reason)) {
                knowledgeArticleDO.setCancelReason(reason);
            }
            knowledgeArticleDao.save(knowledgeArticleDO);
            return knowledgeArticleDO;
        }
    }
			}
		}
		return businessDOS;
	}
    /**
     * 保存文章科室关系
     *
     * @param articleId
     * @param sdJsons
     * @return
     * @throws Exception
     */
    public Boolean saveArticleDept(String articleId, String sdJsons) throws Exception {
        //删除之前关系
        List<KnowledgeArticleDeptDO> list = knowledgeArticleDeptDao.findByArticleId(articleId);
        if (list != null && list.size() > 0) {
            knowledgeArticleDeptDao.deleteAll(list);
        }
        if (org.apache.commons.lang3.StringUtils.isNotBlank(sdJsons)) {
            List<KnowledgeArticleDeptDO> _list = EntityUtils.jsonToList(sdJsons, KnowledgeArticleDeptDO.class);
            if (_list != null && _list.size() > 0) {
                knowledgeArticleDeptDao.saveAll(_list);
            }
        }
        return true;
    }
    /**
     * 查询文章下科室
     *
     * @param articleId
     * @return
     */
    public List<Map<String, Object>> findDeptByArticle(String articleId) throws Exception {
        String sql = "SELECT " +
                " d.article_id AS articleId," +
                " d.dept, " +
                " d.dept_name AS deptName " +
                " FROM " +
                " wlyy_knowledge_article t " +
                " JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
                " WHERE " +
                " t.id = '" + articleId + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    /**
     * 查询部门下的文章
     *
     * @param dept
     * @return
     */
    public List<Map<String, Object>> findArticleByDept(String dept) throws Exception {
        String sql = "SELECT " +
                " t.id as \"id\", " +
                " t.title as \"title\", " +
                " t.create_time AS \"create_time\" ," +
                " t.image AS \"image\" " +
                " FROM " +
                " wlyy_knowledge_article t " +
                " JOIN wlyy_knowledge_article_dept d ON t.id = d.article_id " +
                " WHERE " +
                " d.dept = '" + dept + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    /**
     * 设置部门发送文章
     *
     * @param dept
     * @param sdJsons
     * @return
     */
    public Boolean saveDeptArticle(String dept, String sdJsons) throws Exception {
        //删除之前关系
        List<KnowledgeArticleDeptDO> dels = knowledgeArticleDeptDao.findByDept(dept);
        if (dels != null && dels.size() > 0) {
            knowledgeArticleDeptDao.deleteAll(dels);
        }
	/**
	 * 设置为1常用或者0不常用
	 * @param id
	 * @param used
	 * @return
	 */
	public KnowledgeArticleDO setUsed(String id,Integer used,String doctor){
		KnowledgeArticleDO knowledgeArticleDO = knowledgeArticleDao.findByIdAndDel(id);
		BaseDoctorDO doctorDO = doctorDao.findById(doctor).orElse(null);
		KnowledgeArticleUserDO knowledgeArticleUserDO =knowledgeArticleUserDao.findByrelationCodeAndUserAndDel(id,doctor);
		if (knowledgeArticleUserDO==null){
			knowledgeArticleUserDO = new KnowledgeArticleUserDO();
			knowledgeArticleUserDO.setRelationCode(id);
			knowledgeArticleUserDO.setRelationName(knowledgeArticleDO.getTitle());
			knowledgeArticleUserDO.setRelationType(1);
			knowledgeArticleUserDO.setDel(1);
			knowledgeArticleUserDO.setUser(doctor);
			if (doctorDO!=null){
				knowledgeArticleUserDO.setUserName(doctorDO.getName());
				knowledgeArticleUserDO.setCreateUserName(doctorDO.getName());
			}
			knowledgeArticleUserDO.setCreateTime(new Date());
			knowledgeArticleUserDO.setUpdateTime(new Date());
			knowledgeArticleUserDO.setCreateUser(doctor);
			knowledgeArticleUserDO.setUpdateUser(doctor);
			knowledgeArticleUserDO.setUsed(used);
			knowledgeArticleUserDO = knowledgeArticleUserDao.save(knowledgeArticleUserDO);
		}
        if (knowledgeArticleDO!=null){
            if (knowledgeArticleDO.getUsed()!=null){
            	if (used==1){
					knowledgeArticleUserDO.setUsed(1);
					knowledgeArticleDO.setUsed(knowledgeArticleDO.getUsed()+1);
				}else if (used==0){
            		knowledgeArticleUserDO.setUsed(0);
            		knowledgeArticleDO.setUsed(knowledgeArticleDO.getUsed()-1);
				}
			}else {
				if (used==1){
					knowledgeArticleDO.setUsed(1);
				}else if (used==0){
					knowledgeArticleDO.setUsed(0);
				}
			}
        if (org.apache.commons.lang3.StringUtils.isNotBlank(sdJsons)) {
            List<KnowledgeArticleDeptDO> list = EntityUtils.jsonToList(sdJsons, KnowledgeArticleDeptDO.class);
            if (list != null && list.size() > 0) {
                knowledgeArticleDeptDao.saveAll(list);
            }
        }
		knowledgeArticleUserDO.setRelationName(knowledgeArticleDO.getTitle());
        return true;
    }
    /**
     * 患者接收问卷/文章
     *
     * @param businessDOS
     * @return
     */
    public List<BasePatientBusinessDO> sendBusinessToPatient(List<BasePatientBusinessDO> businessDOS) throws Exception {
        if (businessDOS != null && businessDOS.size() != 0) {
            for (BasePatientBusinessDO patientBusinessDO : businessDOS) {
//                BasePatientBusinessDO basePatientBusinessDO = patientBusinessDao.findByPatientAndRelationCodeAndDel(patientBusinessDO.getPatient(), patientBusinessDO.getRelationCode());
                //这边要改成能发多次
//                if (basePatientBusinessDO != null) {
//                    throw new Exception("已发送过!");
//                }
                String sql = "select * from base_patient_business a " +
                        "where a.del=1 and a.patient='" + patientBusinessDO.getPatient() + "' and a.relation_code='" + patientBusinessDO.getRelationCode() + "'";
                List<BasePatientBusinessDO> basePatientBusinessDOList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BasePatientBusinessDO.class));
                if (!basePatientBusinessDOList.isEmpty()) {
                    System.out.println("已经发送过==>" + basePatientBusinessDOList.size() + "次");
                }
                patientBusinessDO.setCreateTime(new Date());
                patientBusinessDO.setUpdateTime(new Date());
                patientBusinessDO.setCreateUser(patientBusinessDO.getDoctor());
                patientBusinessDO.setUpdateUser(patientBusinessDO.getDoctor());
                patientBusinessDO.setCreateUserName(patientBusinessDO.getDoctorName());
                patientBusinessDO.setUpdateUserName(patientBusinessDO.getUpdateUserName());
                patientBusinessDO.setCollection(0);
                patientBusinessDO.setDel(1);
                patientBusinessDO = patientBusinessDao.save(patientBusinessDO);
                if (patientBusinessDO.getRelationType() == 1) {
                    KnowledgeArticleDO knowledgeArticleDO = knowledgeArticleDao.findByIdAndDel(patientBusinessDO.getRelationCode());
                    JSONObject object = new JSONObject();
                    if (knowledgeArticleDO == null) {
                        KnowledgeArticleDictDO knowledgeArticleDictDO = knowledgeArticleDictDao.findByIdAndDel(patientBusinessDO.getRelationCode());
                        object.put("id", knowledgeArticleDictDO.getId());
                        object.put("title", knowledgeArticleDictDO.getTitle());
                        object.put("content", knowledgeArticleDictDO.getIntro());
                        object.put("img", knowledgeArticleDictDO.getImage());
                        object.put("type", knowledgeArticleDictDO.getType());
                    } else {
                        object.put("id", knowledgeArticleDO.getId());
                        object.put("title", knowledgeArticleDO.getTitle());
                        object.put("content", knowledgeArticleDO.getIntro());
                        object.put("img", knowledgeArticleDO.getImage());
                    }
                    imUtil.sendImMsg(patientBusinessDO.getDoctor(), patientBusinessDO.getDoctorName(), patientBusinessDO.getSessionId(), "4", object.toJSONString(), "1", null);
                } else {
                    WlyySurveyUserDO wlyySurveyUserDO = new WlyySurveyUserDO();
                    String doctor = patientBusinessDO.getDoctor();
                    BaseDoctorDO doctorDO = doctorDao.findById(doctor).orElse(null);
                    wlyySurveyUserDO.setDept(doctorDO.getVisitDept());
                    wlyySurveyUserDO.setDeptName(doctorDO.getVisitDeptName());
                    wlyySurveyUserDO.setDoctor(doctor);
                    wlyySurveyUserDO.setDoctorName(doctorDO.getName());
                    wlyySurveyUserDO.setStatus(0);
                    wlyySurveyUserDO.setPatient(patientBusinessDO.getPatient());
                    wlyySurveyUserDO.setPatientName(patientBusinessDO.getPatientName());
                    wlyySurveyUserDO.setSurveyTempCode(patientBusinessDO.getRelationCode());
                    wlyySurveyUserDO.setSurveyTempTitle(patientBusinessDO.getRelationName());
                    wlyySurveyUserDO.setCreateTime(new Date());
                    wlyySurveyUserDO.setEndTime(new Date());
                    wlyySurveyUserDO = surveyUserDao.save(wlyySurveyUserDO);
                    JSONObject object = new JSONObject();
                    WlyySurveyTemplateDO wlyySurveyTemplateDO = surveyTemplateDao.findById(wlyySurveyUserDO.getSurveyTempCode()).orElse(null);
                    if (null != wlyySurveyTemplateDO) {
                        object.put("title", wlyySurveyTemplateDO.getTitle());
                        object.put("content", wlyySurveyTemplateDO.getTemplateComment());
                        object.put("doctor", patientBusinessDO.getDoctor());
                        object.put("doctorName", patientBusinessDO.getDoctorName());
                        object.put("id", wlyySurveyTemplateDO.getId());
                    }
                    imUtil.sendImMsg(patientBusinessDO.getDoctor(), patientBusinessDO.getDoctorName(), patientBusinessDO.getSessionId(), "17", object.toJSONString(), "1", null);
                }
            }
        }
        return businessDOS;
    }
    /**
     * 设置为1常用或者0不常用
     *
     * @param id
     * @param used
     * @return
     */
    public KnowledgeArticleDO setUsed(String id, Integer used, String doctor) {
        KnowledgeArticleDO knowledgeArticleDO = knowledgeArticleDao.findByIdAndDel(id);
        BaseDoctorDO doctorDO = doctorDao.findById(doctor).orElse(null);
        KnowledgeArticleUserDO knowledgeArticleUserDO = knowledgeArticleUserDao.findByrelationCodeAndUserAndDel(id, doctor);
        if (knowledgeArticleUserDO == null) {
            knowledgeArticleUserDO = new KnowledgeArticleUserDO();
            knowledgeArticleUserDO.setRelationCode(id);
            knowledgeArticleUserDO.setRelationName(knowledgeArticleDO.getTitle());
            knowledgeArticleUserDO.setRelationType(1);
            knowledgeArticleUserDO.setDel(1);
            knowledgeArticleUserDO.setUser(doctor);
            if (doctorDO != null) {
                knowledgeArticleUserDO.setUserName(doctorDO.getName());
                knowledgeArticleUserDO.setCreateUserName(doctorDO.getName());
            }
            knowledgeArticleUserDO.setCreateTime(new Date());
            knowledgeArticleUserDO.setUpdateTime(new Date());
            knowledgeArticleUserDO.setCreateUser(doctor);
            knowledgeArticleUserDO.setUpdateUser(doctor);
            knowledgeArticleUserDO.setUsed(used);
            knowledgeArticleUserDO = knowledgeArticleUserDao.save(knowledgeArticleUserDO);
        }
        if (knowledgeArticleDO != null) {
            if (knowledgeArticleDO.getUsed() != null) {
                if (used == 1) {
                    knowledgeArticleUserDO.setUsed(1);
                    knowledgeArticleDO.setUsed(knowledgeArticleDO.getUsed() + 1);
                } else if (used == 0) {
                    knowledgeArticleUserDO.setUsed(0);
                    knowledgeArticleDO.setUsed(knowledgeArticleDO.getUsed() - 1);
                }
            } else {
                if (used == 1) {
                    knowledgeArticleDO.setUsed(1);
                } else if (used == 0) {
                    knowledgeArticleDO.setUsed(0);
                }
            }
        }
        knowledgeArticleUserDO.setRelationName(knowledgeArticleDO.getTitle());
        knowledgeArticleUserDao.save(knowledgeArticleUserDO);
		return knowledgeArticleDao.save(knowledgeArticleDO);
	}
        return knowledgeArticleDao.save(knowledgeArticleDO);
    }
	public KnowledgeArticleDO selectById(String id){
		return knowledgeArticleDao.findByIdAndDel(id);
	}
	//根据分类查询文章
	public MixEnvelop findArticleByCategoryAndName(String categoryFirst, String categorySecond, String keyWords, Integer page, Integer pageSize){
		MixEnvelop objEnvelop = new MixEnvelop();
		String sql = "select t.id as \"id\",t.title as \"title\",t.read_count as \"readCount\"," +
				"t.collection as \"collection\",t.fabulous as \"fabulous\",t.is_share as \"share\"," +
    public KnowledgeArticleDO selectById(String id) {
        return knowledgeArticleDao.findByIdAndDel(id);
    }
    //根据分类查询文章
    public MixEnvelop findArticleByCategoryAndName(String categoryFirst, String categorySecond, String keyWords, Integer page, Integer pageSize) {
        MixEnvelop objEnvelop = new MixEnvelop();
        String sql = "select t.id as \"id\",t.title as \"title\",t.read_count as \"readCount\"," +
                "t.collection as \"collection\",t.fabulous as \"fabulous\",t.is_share as \"share\"," +
                " t.intro as \"intro\",t.category_first_name as \"categoryFirstName\"," +
                " t.category_second_name as \"categorySecondName\" ," +
                "t.content as \"content\",t.image as \"image\",t.create_user_name as \"createUserName\",c.job_title_name as \"jobTitleName\"," +
                "b.dept_name as \"deptName\",b.org_name as \"hospitalName\"," +
				"t.create_time as \"createTime\" " +
				" from wlyy_knowledge_article t left join wlyy_knowledge_article_dept a " +
                "t.create_time as \"createTime\" " +
                " from wlyy_knowledge_article t left join wlyy_knowledge_article_dept a " +
                " on a.article_id = t.id left join base_doctor_hospital b on b.doctor_code = t.create_user" +
				" left join base_doctor c on c.id = t.create_user where 1=1 and t.del = 1 and t.status = 1";
		if (StringUtils.isNotBlank(categoryFirst)){
		    sql+=" and t.category_first = '"+categoryFirst+"'";
                " left join base_doctor c on c.id = t.create_user where 1=1 and t.del = 1 and t.status = 1";
        if (StringUtils.isNotBlank(categoryFirst)) {
            sql += " and t.category_first = '" + categoryFirst + "'";
        }
        if (StringUtils.isNotBlank(categorySecond)) {
            sql += " and t.category_second ='" + categorySecond + "'";
        }
		if (StringUtils.isNotBlank(categorySecond)){
			sql+=" and t.category_second ='"+categorySecond+"'";
		}
        if (StringUtils.isNotBlank(keyWords)){
            sql+=" and (t.create_user_name like '%"+keyWords+"%' or t.title like '%"+keyWords+"%' or t.content like '%"+keyWords+"%' or a.dept_name like '%"+keyWords+"%' )";
        if (StringUtils.isNotBlank(keyWords)) {
            sql += " and (t.create_user_name like '%" + keyWords + "%' or t.title like '%" + keyWords + "%' or t.content like '%" + keyWords + "%' or a.dept_name like '%" + keyWords + "%' )";
        }
		sql+=" group by t.id ,t.title ,t.intro,t.category_first_name ,t.category_second_name ,c.job_title_name," +
				"t.read_count,t.collection,t.fabulous,t.is_share,t.content ,t.image ,t.create_user_name ,b.dept_name ,b.org_name,t.create_time " +
				" order by t.create_time desc";
        List<Map<String,Object>> result = hibenateUtils.createSQLQuery(sql,page,pageSize);
        List<Map<String,Object>> countList = hibenateUtils.createSQLQuery(sql);
        sql += " group by t.id ,t.title ,t.intro,t.category_first_name ,t.category_second_name ,c.job_title_name," +
                "t.read_count,t.collection,t.fabulous,t.is_share,t.content ,t.image ,t.create_user_name ,b.dept_name ,b.org_name,t.create_time " +
                " order by t.create_time desc";
        List<Map<String, Object>> result = hibenateUtils.createSQLQuery(sql, page, pageSize);
        List<Map<String, Object>> countList = hibenateUtils.createSQLQuery(sql);
        objEnvelop.setObj(result);
        objEnvelop.setTotalCount(countList.size());
        objEnvelop.setPageSize(pageSize);
        objEnvelop.setCurrPage(page);
        return objEnvelop;
	}
	//查询患者收藏的文章列表
	public JSONObject findPatientFavorite(String patient,Integer page,Integer pageSize){
		String sql = "select t.id as \"id\",t.user_code as \"user\",t.user_name as \"userName\"," +
				"t.relation_code as \"relationCode\"," +
				"t.relation_type as \"relationType\"," +
				"t.relation_name as \"relationName\"," +
				"t.is_read as \"isRead\",t.fabulous as \"fabulous\"," +
				"t.is_share as \"share\"," +
				"t.collection as \"collection\",t.used as \"used\",t.del as \"del\"";
		sql+=" from wlyy_knowledge_article_user t left join wlyy_knowledge_article a" +
				" on t.relation_code = a.id where 1=1 and a.del=1 and a.collection=1 ";
		if (StringUtils.isNotEmpty(patient)){
			sql+=" and t.user_code = '"+patient+"'";
		}
		List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
		if(list!=null&&list.size()>0){
			for (Map<String,Object> map:list){
				String relationCode = map.get("relationCode").toString();
				String type =  map.get("relationType").toString();
				if ("1".equalsIgnoreCase(type)){
					KnowledgeArticleDO knowledgeArticleDO = this.selectById(relationCode);
					if (knowledgeArticleDO!=null){
						List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(knowledgeArticleDO.getCreateUser());
						if (doctorHospitalDOS!=null&&doctorHospitalDOS.size()!=0){
							knowledgeArticleDO.setDeptName(doctorHospitalDOS.get(0).getDeptName());
							knowledgeArticleDO.setHospitalName(doctorHospitalDOS.get(0).getOrgName());
						}
					}
					map.put("KnowledgeArticleUserDO",knowledgeArticleDO);
				}
			}
		}
		List<Map<String,Object>> listCount = hibenateUtils.createSQLQuery(sql);
		JSONObject result = new JSONObject();
		result.put("total",listCount.size());
		result.put("detailModelList",list);
		return result;
	}
    }
    //查询患者收藏的文章列表
    public JSONObject findPatientFavorite(String patient, Integer page, Integer pageSize) {
        String sql = "select t.id as \"id\",t.user_code as \"user\",t.user_name as \"userName\"," +
                "t.relation_code as \"relationCode\"," +
                "t.relation_type as \"relationType\"," +
                "t.relation_name as \"relationName\"," +
                "t.is_read as \"isRead\",t.fabulous as \"fabulous\"," +
                "t.is_share as \"share\"," +
                "t.collection as \"collection\",t.used as \"used\",t.del as \"del\"";
        sql += " from wlyy_knowledge_article_user t left join wlyy_knowledge_article a" +
                " on t.relation_code = a.id where 1=1 and a.del=1 and a.collection=1 ";
        if (StringUtils.isNotEmpty(patient)) {
            sql += " and t.user_code = '" + patient + "'";
        }
        List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, page, pageSize);
        if (list != null && list.size() > 0) {
            for (Map<String, Object> map : list) {
                String relationCode = map.get("relationCode").toString();
                String type = map.get("relationType").toString();
                if ("1".equalsIgnoreCase(type)) {
                    KnowledgeArticleDO knowledgeArticleDO = this.selectById(relationCode);
                    if (knowledgeArticleDO != null) {
                        List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(knowledgeArticleDO.getCreateUser());
                        if (doctorHospitalDOS != null && doctorHospitalDOS.size() != 0) {
                            knowledgeArticleDO.setDeptName(doctorHospitalDOS.get(0).getDeptName());
                            knowledgeArticleDO.setHospitalName(doctorHospitalDOS.get(0).getOrgName());
                        }
                    }
                    map.put("KnowledgeArticleUserDO", knowledgeArticleDO);
                }
            }
        }
        List<Map<String, Object>> listCount = hibenateUtils.createSQLQuery(sql);
        JSONObject result = new JSONObject();
        result.put("total", listCount.size());
        result.put("detailModelList", list);
        return result;
    }
}