|  | @ -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;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |