|
@ -0,0 +1,708 @@
|
|
|
package com.yihu.wlyy.service.jimeiJkEdu;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.es.entity.HealthEduArticlePatient;
|
|
|
import com.yihu.es.entity.RoleVo;
|
|
|
import com.yihu.wlyy.config.es.ElastricSearchSave;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.app.team.AdminTeamService;
|
|
|
import com.yihu.wlyy.service.common.account.RoleService;
|
|
|
import com.yihu.wlyy.service.third.jkEduArticle.ThirdJkEduArticleService;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.yihu.wlyy.util.ElasticsearchUtil;
|
|
|
import com.yihu.wlyy.web.third.gateway.service.GcLabelService;
|
|
|
import com.yihu.wlyy.web.third.gateway.vo.DictModel;
|
|
|
import com.yihu.wlyy.web.third.gateway.vo.HealthEduArticlePatientModel;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by liuwenbin on 2017/8/12.
|
|
|
* 集美健教
|
|
|
*/
|
|
|
@Service
|
|
|
public class JMJkEduArticleService extends BaseService {
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Value("${es.type.HealthEduArticlePatient}")
|
|
|
private String esType;
|
|
|
@Value("${es.index.HealthEduArticlePatient}")
|
|
|
private String esIndex;
|
|
|
@Autowired
|
|
|
private ElasticsearchUtil elasticsearchUtil;
|
|
|
@Autowired
|
|
|
private ThirdJkEduArticleService thirdJkEduArticleService;
|
|
|
@Autowired
|
|
|
private RoleService roleService;
|
|
|
@Autowired
|
|
|
private DoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private ElastricSearchSave elastricSearchSave;
|
|
|
@Autowired
|
|
|
private GcLabelService labelService;
|
|
|
@Autowired
|
|
|
private AdminTeamService teamService;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param page
|
|
|
* @param pagesize
|
|
|
* @param sendCode
|
|
|
* @param firstLevelCategoryId 一级分类
|
|
|
* @param myArticle (条件:我的文章)
|
|
|
* @param sendType 1、医生,2、卫计委(管理员)
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public List<HealthEduArticlePatientModel> pushArticleList(int page, int pagesize, String sendCode, String firstLevelCategoryId,Integer myArticle,Integer sendType) throws Exception {
|
|
|
pagesize = page * pagesize;
|
|
|
page = (page - 1) * pagesize;
|
|
|
// if(loginType==2){
|
|
|
//
|
|
|
// String sql = "select r.code as roleCode from wlyy_user_role u " +
|
|
|
// "left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "' and LENGTH(u.role)=6";
|
|
|
// List<Map<String, Object>> resultMap = jdbcTemplate.queryForList(sql);
|
|
|
// sendCode = resultMap.size()>0?resultMap.get(0).get("roleCode").toString():sendCode;
|
|
|
// }
|
|
|
|
|
|
StringBuffer sql2 = new StringBuffer("select * from " + esType +
|
|
|
" where doctorCode='" + sendCode + "'");
|
|
|
if(sendType==1){
|
|
|
|
|
|
sql2.append(" and sendType='"+sendType+"' ");
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(firstLevelCategoryId)){
|
|
|
sql2.append("and level1Type="+firstLevelCategoryId);
|
|
|
}
|
|
|
if(myArticle==1){
|
|
|
sql2.append("and operatorId="+sendCode);
|
|
|
}
|
|
|
sql2.append(" order by createTime limit " + page + "," + pagesize);
|
|
|
List<com.yihu.es.entity.HealthEduArticlePatient> esList = elasticsearchUtil.excute(sql2.toString(), com.yihu.es.entity.HealthEduArticlePatient.class, esIndex, esType);
|
|
|
Map<String, HealthEduArticlePatientModel> result = new HashMap<>();
|
|
|
HealthEduArticlePatientModel heapm = null;
|
|
|
com.alibaba.fastjson.JSONObject article = null;
|
|
|
Doctor doctor = null;
|
|
|
for (HealthEduArticlePatient one : esList) {
|
|
|
article = thirdJkEduArticleService.getArticalById(one.getArticleId());
|
|
|
if (result.get(one.getArticleId()) != null) {
|
|
|
heapm = result.get(one.getArticleId());
|
|
|
|
|
|
} else {
|
|
|
heapm = new HealthEduArticlePatientModel();
|
|
|
}
|
|
|
heapm.setSendName(one.getSendName());
|
|
|
heapm.setSendCode(one.getDoctorCode());
|
|
|
heapm.setCreateTime(one.getCreateTime());
|
|
|
heapm.setArticleId(article.getString("articleId"));
|
|
|
heapm.setAttachedTitle(article.getString("articleTitle"));
|
|
|
heapm.setAttachedContent(article.getString("articleContent"));
|
|
|
heapm.setArticleType(article.getString("articleType"));
|
|
|
heapm.setLevel1Type(article.getString("firstLevelCategoryId"));
|
|
|
heapm.setLevel2Type(article.getString("secondLevelCategoryId"));
|
|
|
heapm.setLevel(article.getString("articlelevel"));
|
|
|
heapm.setAllCount(heapm.getAllCount() + one.getPatients().size());
|
|
|
heapm.setBrowseNumbere(Integer.valueOf(article.getString("browseNumber")));//文章浏览数
|
|
|
heapm.setCommentNumber(Integer.valueOf(article.getString("commentNumber")));//文章评论数
|
|
|
heapm.setPointNumber(Integer.valueOf(article.getString("pointNumber")));//文章点赞数
|
|
|
heapm.setArticleCover(article.getString("articleCover"));//封面
|
|
|
heapm.setComputeTime(computeTime(article.getString("insertTime")));
|
|
|
doctor = doctorDao.findByCode(one.getDoctorCode());
|
|
|
heapm.setPhoto(doctor.getPhoto());
|
|
|
heapm.setOperatorName(article.getString("operatorName"));
|
|
|
// heapm.setTime();//时间 xx小时前 2017-10-11
|
|
|
result.put(one.getArticleId(), heapm);
|
|
|
}
|
|
|
List<HealthEduArticlePatientModel> resultList = new ArrayList<>();
|
|
|
for (Map.Entry<String, HealthEduArticlePatientModel> entry : result.entrySet()) {
|
|
|
resultList.add(entry.getValue());
|
|
|
}
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
public static String computeTime(String create) {
|
|
|
Date createDate = DateUtil.strToDate(create, "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
Date nowDate = new Date();
|
|
|
//计算2个时间差
|
|
|
Long l = nowDate.getTime() - createDate.getTime();
|
|
|
|
|
|
long hour = l / (60 * 60 * 1000); //小时
|
|
|
long min = l / (60 * 1000);//分钟
|
|
|
long s = l / 1000;//秒
|
|
|
if(s<60){
|
|
|
return s+"秒前";
|
|
|
}
|
|
|
if(min<60){
|
|
|
return min+"分钟前";
|
|
|
}
|
|
|
if(hour<24){
|
|
|
return hour+"小时前";
|
|
|
}
|
|
|
return DateUtil.dateToStr(createDate,"yyyy-MM-dd");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取推送数量的总数(废弃)
|
|
|
* @param sendCode
|
|
|
* @param sendType 1、卫计委,2、医生
|
|
|
* @return
|
|
|
*/
|
|
|
public Long pushArticleListCount(String sendCode,int sendType) {
|
|
|
|
|
|
if(sendType==1){
|
|
|
String sql = "select r.code as roleCode from wlyy_user_role u " +
|
|
|
"left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "'"+ " and LENGTH(u.role)=6";;
|
|
|
|
|
|
Map<String, Object> resultMap = jdbcTemplate.queryForMap(sql);
|
|
|
sendCode = resultMap.get("roleCode").toString();
|
|
|
}
|
|
|
StringBuffer sql = new StringBuffer("select count(distinct articleId) count from " + esType +
|
|
|
" where sendCode='" + sendCode + "' ");
|
|
|
return elasticsearchUtil.excuteForLong(sql.toString(), esIndex, esType);
|
|
|
}
|
|
|
|
|
|
|
|
|
// public String fetchUserHighestAuthority(List<Map<String, Object>> resultMap){
|
|
|
// String result = "";
|
|
|
// for(Map<String, Object> one:resultMap){
|
|
|
// String role = one.get("roleCode").toString();
|
|
|
// if(role.length()==6){
|
|
|
// if("00".equals(role.substring(4))){
|
|
|
// return role;
|
|
|
// }else {
|
|
|
// result = role;
|
|
|
// }
|
|
|
// }else{
|
|
|
// if(result.length()==6){
|
|
|
//
|
|
|
// }else{
|
|
|
//
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 保存发送信息
|
|
|
*
|
|
|
* @param patientSet 患者set集和
|
|
|
* @param sendCode 发送人code、
|
|
|
* @param sendMessage 发送人携带的信息
|
|
|
* @param teamId 发送人所属团队
|
|
|
* @param articleId 文章列表
|
|
|
*/
|
|
|
@Transactional
|
|
|
public HealthEduArticlePatient saveArticle(Set<String> patientSet,
|
|
|
String sendCode,
|
|
|
// String sendName,
|
|
|
Integer sendType,
|
|
|
String sendMessage,
|
|
|
Long teamId,
|
|
|
String articleId) throws Exception {
|
|
|
|
|
|
|
|
|
String batchNo = UUID.randomUUID().toString();
|
|
|
List<Patient> patientList = new ArrayList<>();
|
|
|
|
|
|
for (String patient : patientSet) {
|
|
|
patientList.add(new Patient(patient));
|
|
|
}
|
|
|
HealthEduArticlePatient healthEduArticlePatient = new HealthEduArticlePatient();
|
|
|
//1、医生,2、卫计委(管理员)
|
|
|
//如果是卫计委得区别角色
|
|
|
Doctor doctor = doctorDao.findByCode(sendCode);
|
|
|
String sendName = doctor.getName();
|
|
|
//管理员
|
|
|
Map<String,Object> resultMap = labelService.fetchUserHighestAuthority(sendCode);
|
|
|
Integer level = (Integer)resultMap.get("level");
|
|
|
List<String> roleList = (List<String>)resultMap.get("roleList");
|
|
|
if(doctor.getLevel()==10&&sendType==2){
|
|
|
String resultSql ="";
|
|
|
String whereSql ="";
|
|
|
String temp = "";
|
|
|
for(String one :roleList){
|
|
|
temp+=",'"+one+"'";
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(temp)){
|
|
|
temp=temp.substring(1);
|
|
|
}
|
|
|
switch (level){
|
|
|
case 1:{resultSql +=" DISTINCT (province_name) as name";
|
|
|
whereSql+=" and province in ("+temp+")";break;}
|
|
|
case 2:{resultSql +=" DISTINCT (city_name) as name";
|
|
|
whereSql+=" and city in ("+temp+")";break;}
|
|
|
case 3:{resultSql +=" DISTINCT (town_name) as name";
|
|
|
whereSql+=" and town in ("+temp+")";break;}
|
|
|
case 4:{resultSql +=" DISTINCT (name) as name";
|
|
|
whereSql+=" and code in ("+temp+")";break;}
|
|
|
|
|
|
}
|
|
|
String sql = "select "+resultSql+" from dm_hospital where level=2 "+whereSql ;
|
|
|
List<Map<String, Object>> returnList = jdbcTemplate.queryForList(sql);
|
|
|
temp = "";
|
|
|
for(Map<String, Object> one :returnList){
|
|
|
temp +=","+one.get("name");
|
|
|
}
|
|
|
sendName = StringUtils.isEmpty(temp)?"":temp.substring(1);
|
|
|
}
|
|
|
List<RoleVo> roleVoLists= new ArrayList<>();
|
|
|
for(String one:roleList){
|
|
|
RoleVo roleVo = new RoleVo();
|
|
|
roleVo.setCode(one);
|
|
|
roleVoLists.add(roleVo);
|
|
|
}
|
|
|
healthEduArticlePatient.setRoleList(roleVoLists);
|
|
|
healthEduArticlePatient.setDoctorCode(sendCode);
|
|
|
healthEduArticlePatient.setSendName(sendName);
|
|
|
healthEduArticlePatient.setSendType(2);
|
|
|
healthEduArticlePatient.setAdminTeamCode(teamId);
|
|
|
|
|
|
if (doctor != null) {
|
|
|
healthEduArticlePatient.setDoctorName(doctor.getName());
|
|
|
healthEduArticlePatient.setHospital(doctor.getHospital());
|
|
|
healthEduArticlePatient.setHospitalName(doctor.getHospitalName());
|
|
|
healthEduArticlePatient.setTown(doctor.getTown());
|
|
|
healthEduArticlePatient.setTownName(doctor.getTownName());
|
|
|
healthEduArticlePatient.setSendLevel(doctor.getLevel() != null ? String.valueOf(doctor.getLevel()) : "");
|
|
|
healthEduArticlePatient.setSendPic(doctor.getPhoto());
|
|
|
healthEduArticlePatient.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
|
|
|
}
|
|
|
healthEduArticlePatient.setBatchNo(batchNo);
|
|
|
healthEduArticlePatient.setCreateTime(new Date());
|
|
|
|
|
|
|
|
|
//通过文章id 获取文章详情
|
|
|
JSONObject article = thirdJkEduArticleService.getArticalById(articleId);
|
|
|
|
|
|
healthEduArticlePatient.setArticleId(article.get("articleId") + "");
|
|
|
healthEduArticlePatient.setAttachedTitle(article.get("articleTitle") + "");
|
|
|
healthEduArticlePatient.setAttachedPic(article.get("articleCover") + "");
|
|
|
healthEduArticlePatient.setAttachedContent(article.get("articleContent") + "");
|
|
|
healthEduArticlePatient.setAttachedMessage(sendMessage);
|
|
|
healthEduArticlePatient.setArticleType(article.get("articleType") + "");
|
|
|
healthEduArticlePatient.setLevel(article.get("articlelevel") + "");
|
|
|
healthEduArticlePatient.setLevel1Type(article.get("firstLevelCategoryId") + "");
|
|
|
healthEduArticlePatient.setLevel2Type(article.get("secondLevelCategoryId") + "");
|
|
|
healthEduArticlePatient.setType("1");//文章
|
|
|
// healthEduArticlePatient.setArticleUrl(articleBaseUrl+"JkEduWeb/web/jkEdu/articleDetail.html?behavior=4&articleId="+articleId+"&userId="+);
|
|
|
healthEduArticlePatient.setPatients(patientList);
|
|
|
|
|
|
//保存到ES中
|
|
|
elastricSearchSave.save(healthEduArticlePatient, esIndex, esType);
|
|
|
return healthEduArticlePatient;
|
|
|
}
|
|
|
|
|
|
// public Map<String, Object> getUnitLabels(String userId) {
|
|
|
// String sql2 = "select r.code as roleCode from wlyy_user_role u " +
|
|
|
// "left join wlyy_role r on r.`code`=u.role where u.user='" + userId + "'";
|
|
|
// List<Map<String, Object>> resultMap = jdbcTemplate.queryForList(sql2);
|
|
|
// String whereSql = "";
|
|
|
// String role = fetchUserHighestAuthority(resultMap);
|
|
|
// String resultSql = "";
|
|
|
// if(role.length()==6){
|
|
|
//
|
|
|
// if("00".equals(role.substring(4))){
|
|
|
// resultSql +=" DISTINCT (city_name) as name";
|
|
|
// whereSql+=" and city = '"+role+"'";
|
|
|
// }else{
|
|
|
// resultSql +=" DISTINCT (town_name) as name";
|
|
|
// whereSql+=" and town = '"+role+"'";
|
|
|
// }
|
|
|
// }else{
|
|
|
// resultSql +=" DISTINCT (name) as name ";
|
|
|
// whereSql+=" and code = '"+role+"'";
|
|
|
// }
|
|
|
//
|
|
|
// String sql = "select "+resultSql+" from dm_hospital where level=2 "+whereSql ;
|
|
|
// List<Map<String, Object>> returnList = jdbcTemplate.queryForList(sql);
|
|
|
//
|
|
|
// return returnList.get(0);
|
|
|
// }
|
|
|
|
|
|
// /**
|
|
|
// * 获取用户的最高角色权限
|
|
|
// * @param resultMap
|
|
|
// * @return
|
|
|
// */
|
|
|
// public String fetchUserHighestAuthority(List<Map<String, Object>> resultMap){
|
|
|
// String result = "";
|
|
|
// String role = "";
|
|
|
// for(Map<String, Object> one:resultMap){
|
|
|
// role = one.get("roleCode").toString();
|
|
|
// if(role.length()==6){
|
|
|
// if("00".equals(role.substring(4))){//市级
|
|
|
// return role;
|
|
|
// }else {
|
|
|
// result = role;
|
|
|
// }
|
|
|
// }else{
|
|
|
// if(StringUtils.isEmpty(result)||result.length()>6){
|
|
|
// result = role;
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// return result;
|
|
|
// }
|
|
|
|
|
|
public JSONObject pushArticleConfirm(String articleId, String labelUnit, String labelSex, String labelServe, String labelDisease, String labelHealth,String userCode) throws Exception {
|
|
|
JSONObject article = thirdJkEduArticleService.getArticalById(articleId);
|
|
|
Set<String> patientSet = new HashSet<>();
|
|
|
initPatient(patientSet, labelUnit, labelSex, labelServe, labelDisease, labelHealth,userCode);
|
|
|
long num = patientSet.size();
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("num", num);
|
|
|
result.put("articleTitle", article.getString("articleTitle"));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 卫计委(管理员)推送文章初始化患者人数
|
|
|
* @param patientSet
|
|
|
* @param labelUnit
|
|
|
* @param labelSex
|
|
|
* @param labelServe
|
|
|
* @param labelDisease
|
|
|
* @param labelHealth
|
|
|
* @param userCode
|
|
|
*/
|
|
|
public void initPatient(Set<String> patientSet, String labelUnit, String labelSex, String labelServe, String labelDisease, String labelHealth,String userCode) {
|
|
|
//全选的时候前端传0,后台要去数据库再查询一次
|
|
|
// if ("0".equals(labelUnit)) {
|
|
|
// //查找全部的下属单位
|
|
|
//// String sql = "select Group_concat(code) code from dm_hospital where level=2 and town = '350211'";
|
|
|
//// labelUnit = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
// List<DictModel> dictModels = labelService.getUnitLabels(userCode);
|
|
|
// labelUnit ="";
|
|
|
// for(DictModel one:dictModels){
|
|
|
// labelUnit+=","+one.getCode();
|
|
|
// }
|
|
|
//
|
|
|
// labelUnit=labelUnit.substring(1);
|
|
|
// }
|
|
|
// if ("0".equals(labelSex)) {
|
|
|
// //查找全部的性别
|
|
|
// labelSex = "1,2";
|
|
|
// }
|
|
|
// if ("0".equals(labelServe)) {
|
|
|
// //查找全部的服务类型
|
|
|
// String sql = "select Group_concat(s.code) from wlyy_sign_dict s where s.year='2017' order by s.sort asc";
|
|
|
// labelServe = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
// }
|
|
|
// if ("0".equals(labelDisease)) {
|
|
|
// //查找全部的疾病标签
|
|
|
// String sql = "select Group_concat(s.label_code) from wlyy_sign_patient_label s where s.label_type=3 and status=1";
|
|
|
// labelDisease = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
// }
|
|
|
// if ("0".equals(labelHealth)) {
|
|
|
// //查找全部的健康情况
|
|
|
// String sql = "select Group_concat(s.label_code) from wlyy_sign_patient_label s where s.label_type=2 and status=1";
|
|
|
// labelHealth = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
// }
|
|
|
|
|
|
String tableSql = " select p.code from wlyy_sign_family w left join dm_hospital h on w.hospital=h.code ";
|
|
|
String whereSql = " where w.status>0 ";
|
|
|
|
|
|
//通过登录的角色区域权限 限制所属患者条件
|
|
|
|
|
|
Map<String,Object> resultLevel = labelService.fetchUserHighestAuthority(userCode);
|
|
|
List<String> list = (List<String>)resultLevel.get("roleList");
|
|
|
Integer level = (Integer)resultLevel.get("level");
|
|
|
StringBuilder role = new StringBuilder();
|
|
|
for(String one :list){
|
|
|
role.append(",'"+one+"'");
|
|
|
}
|
|
|
String roleSql = !StringUtils.isEmpty(role+"")?role.substring(1):"";
|
|
|
if(StringUtils.isEmpty(roleSql)){
|
|
|
|
|
|
switch (level){
|
|
|
case 1:{whereSql+=" and h.province in ("+role+")" ;break;}
|
|
|
case 2:{whereSql+=" and h.city in ("+role+")" ;break;}
|
|
|
case 3:{whereSql+=" and h.town in ("+role+")" ;break;}
|
|
|
case 4:{whereSql+=" and h.code in ("+role+")" ;break;}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!StringUtils.isEmpty(labelServe)) {
|
|
|
tableSql += " left join wlyy_sign_family_server s on w.code= s.sign_code ";
|
|
|
whereSql += " and s.server_type in (" + labelServe + " ) ";
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(labelHealth) || !StringUtils.isEmpty(labelDisease)) {
|
|
|
tableSql += " left join wlyy_sign_patient_label_info l on w.patient=l.patient ";
|
|
|
whereSql += " and l.status=1 ";
|
|
|
whereSql += " and ( ";
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(labelHealth)) {
|
|
|
whereSql += " (l.label_type = 2 AND l.label in (" + labelHealth + ")) ";
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(labelDisease)) {
|
|
|
if (!whereSql.endsWith(" and ( ")) {
|
|
|
whereSql += " or (l.label_type = 3 AND l.label in (" + labelDisease + "))) ";
|
|
|
} else {
|
|
|
whereSql += " (l.label_type = 1 AND l.label in (" + labelDisease + "))) ";
|
|
|
}
|
|
|
}
|
|
|
tableSql += " left join wlyy_patient p on p.code=w.patient ";
|
|
|
if (!StringUtils.isEmpty(labelSex)) {
|
|
|
whereSql += " and p.sex in (" + labelSex + ") ";
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(labelUnit)) {
|
|
|
whereSql += " and w.hospital in (" + labelUnit + ") ";
|
|
|
}
|
|
|
List<String> groupPatient = jdbcTemplate.queryForList(tableSql + whereSql, String.class);
|
|
|
patientSet.addAll(groupPatient);
|
|
|
}
|
|
|
|
|
|
|
|
|
/***
|
|
|
* 医生-查询推送对象
|
|
|
* @param labelType
|
|
|
* @param condition
|
|
|
* @param teamId
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONArray labelWithPushPatients(String labelType, String condition, Long teamId,String doctorCode) {
|
|
|
|
|
|
String adminTeamCodetemp = "";
|
|
|
if(teamId!=null){
|
|
|
adminTeamCodetemp+=teamId.longValue();
|
|
|
}else{
|
|
|
List<AdminTeam> teamList = teamService.getDoctorTeams(doctorCode);
|
|
|
for(AdminTeam one:teamList){
|
|
|
adminTeamCodetemp+=","+one.getId();
|
|
|
}
|
|
|
adminTeamCodetemp=adminTeamCodetemp.length()>0?adminTeamCodetemp.substring(1):"";
|
|
|
}
|
|
|
|
|
|
String[] cond = {};
|
|
|
if (!StringUtils.isEmpty(condition)) {
|
|
|
cond = condition.split(",");
|
|
|
}
|
|
|
StringBuilder whereSql = new StringBuilder();
|
|
|
String tableSql = "";
|
|
|
String sql ="";
|
|
|
for (String one : cond) {
|
|
|
if ("1".equals(one)) {//有绑定设备
|
|
|
tableSql = "LEFT JOIN wlyy_patient_device d on d.user=aa.patient and d.device_id is not null ";
|
|
|
} else if ("2".equals(one)) {//孕产妇
|
|
|
// temp.add("41");
|
|
|
whereSql.append(" and tt LIKE '%41%' ");
|
|
|
} else if ("3".equals(one)) {//65岁以上老年人
|
|
|
// temp.add("13");
|
|
|
whereSql.append(" and tt LIKE '%13%' ");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List<DictModel> returnList = null;
|
|
|
Map<String, Object> map = null;
|
|
|
JSONArray re = new JSONArray();
|
|
|
switch (labelType) {
|
|
|
case "1": {
|
|
|
sql = "select s.code code,s.name as name from wlyy_sign_dict s where s.year='2017' order by s.sort asc";
|
|
|
returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
|
|
|
for (DictModel one : returnList) {
|
|
|
|
|
|
sql = " SELECT count(DISTINCT(aa.patient)) AS num FROM " +
|
|
|
" ( SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
|
|
|
" FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l, " +
|
|
|
" wlyy_sign_family_server q WHERE w. STATUS > 0 AND l. STATUS = 1 AND w.admin_team_code in (" +adminTeamCodetemp+")"+
|
|
|
" AND w.patient = l.patient "+//AND LEFT (w.hospital, 6) = '350211' " +
|
|
|
" AND w. CODE = q.sign_code AND q.server_type = 1 ) a " +
|
|
|
" GROUP BY a.patient HAVING 1 = 1 AND tt LIKE '%1" + one.getCode() + "%' " + whereSql.toString() + ") aa " + tableSql;
|
|
|
map = jdbcTemplate.queryForMap(sql);
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("code", one.getCode());
|
|
|
obj.put("name", one.getName());
|
|
|
obj.put("num", (Long) map.get("num"));
|
|
|
re.add(obj);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
case "2": {
|
|
|
sql = "select label_code code,label_name as name from wlyy_sign_patient_label where label_type=2 and status=1";
|
|
|
returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
|
|
|
for (DictModel one : returnList) {
|
|
|
|
|
|
sql = " select count(DISTINCT(aa.patient)) as num from ( " +
|
|
|
" SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
|
|
|
" FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +//AND w.team_code=" +teamCode+
|
|
|
" WHERE w. STATUS > 0 and l.status=1 AND w.admin_team_code in ("+adminTeamCodetemp+") AND w.patient = l.patient ) a " +//AND LEFT (w.hospital, 6) = '350211' ) a " +
|
|
|
" GROUP BY a.patient HAVING tt LIKE '%2" + one.getCode() + "%' " + whereSql.toString() + ") aa " + tableSql;
|
|
|
map = jdbcTemplate.queryForMap(sql);
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("code", one.getCode());
|
|
|
obj.put("name", one.getName());
|
|
|
obj.put("num", (Long) map.get("num"));
|
|
|
re.add(obj);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
case "3": {
|
|
|
sql = "select label_code code, label_name as name from wlyy_sign_patient_label where label_type=3 and status=1";
|
|
|
returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
|
|
|
for (DictModel one : returnList) {
|
|
|
|
|
|
sql = " select count(DISTINCT(aa.patient)) as num from ( " +
|
|
|
" SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
|
|
|
" FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
|
|
|
" WHERE w. STATUS > 0 and l.status=1 AND w.admin_team_code in ("+adminTeamCodetemp+") AND w.patient = l.patient ) a " +// AND LEFT (w.hospital, 6) = '350211' ) a " +
|
|
|
" GROUP BY a.patient HAVING tt LIKE '%3" + one.getCode() + "%' " + whereSql.toString() + ") aa " + tableSql;
|
|
|
map = jdbcTemplate.queryForMap(sql);
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("code", one.getCode());
|
|
|
obj.put("name", one.getName());
|
|
|
obj.put("num", (Long) map.get("num"));
|
|
|
re.add(obj);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
case "4": {
|
|
|
sql = "select label_code code, label_name as name from wlyy_sign_patient_label where label_type=4 and status=1";
|
|
|
returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
|
|
|
for (DictModel one : returnList) {
|
|
|
|
|
|
sql = " select count(DISTINCT(aa.patient)) as num from ( " +
|
|
|
" SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
|
|
|
" FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
|
|
|
" WHERE w. STATUS > 0 and l.status=1 AND w.admin_team_code in ("+adminTeamCodetemp+") AND w.patient = l.patient ) a " +// AND LEFT (w.hospital, 6) = '350211' ) a " +
|
|
|
" GROUP BY a.patient HAVING tt LIKE '%4" + one.getCode() + "%' " + whereSql.toString() + ") aa " + tableSql;
|
|
|
map = jdbcTemplate.queryForMap(sql);
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("code", one.getCode());
|
|
|
obj.put("name", one.getName());
|
|
|
obj.put("num", (Long) map.get("num"));
|
|
|
re.add(obj);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return re;
|
|
|
}
|
|
|
|
|
|
public JSONObject pushArticleConfirm(String articleId,String labelType, String condition, String groupType,Long teamId,String doctorCode) throws Exception{
|
|
|
JSONObject article = thirdJkEduArticleService.getArticalById(articleId);
|
|
|
Set<String> patientSet = new HashSet<>();
|
|
|
initPatients(patientSet,labelType,condition,groupType,teamId,doctorCode);
|
|
|
long num = patientSet.size();
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("num", num);
|
|
|
result.put("articleTitle", article.getString("articleTitle"));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 医生推送文章初始化被推患者信息
|
|
|
* @param patientSet
|
|
|
* @param labelType
|
|
|
* @param condition
|
|
|
* @param groupType
|
|
|
* @param teamId
|
|
|
* @param doctorCode
|
|
|
*/
|
|
|
public void initPatients(Set<String> patientSet, String labelType, String condition, String groupType,Long teamId,String doctorCode) {
|
|
|
|
|
|
String adminTeamCodetemp = "";
|
|
|
if(teamId!=null){
|
|
|
adminTeamCodetemp+=teamId.longValue();
|
|
|
}else{
|
|
|
List<AdminTeam> teamList = teamService.getDoctorTeams(doctorCode);
|
|
|
for(AdminTeam one:teamList){
|
|
|
adminTeamCodetemp+=","+one.getId();
|
|
|
}
|
|
|
adminTeamCodetemp=adminTeamCodetemp.length()>0?adminTeamCodetemp.substring(1):"";
|
|
|
}
|
|
|
|
|
|
String[] cond = {};
|
|
|
String[] group = {};
|
|
|
if (!StringUtils.isEmpty(condition)) {
|
|
|
cond = condition.split(",");
|
|
|
}
|
|
|
StringBuilder whereSql = new StringBuilder();
|
|
|
String tableSql = "";
|
|
|
for (String one : cond) {
|
|
|
if ("1".equals(one)) {//有绑定设备
|
|
|
tableSql = " LEFT JOIN wlyy_patient_device d on d.user=aa.patient and d.device_id is not null ";
|
|
|
} else if ("2".equals(one)) {//孕产妇
|
|
|
whereSql.append(" and tt LIKE '%41%' ");
|
|
|
} else if ("3".equals(one)) {//65岁以上老年人
|
|
|
whereSql.append(" and tt LIKE '%13%' ");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!StringUtils.isEmpty(groupType)) {
|
|
|
group = groupType.split(",");
|
|
|
}
|
|
|
String sql = "";
|
|
|
List<String> groupPatient = null;
|
|
|
List<String> resultList = new ArrayList<>();
|
|
|
switch (labelType) {
|
|
|
case "1": {
|
|
|
for (String one : group) {
|
|
|
sql = " SELECT DISTINCT(aa.patient) FROM " +
|
|
|
" ( SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
|
|
|
" FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l, " +
|
|
|
" wlyy_sign_family_server q WHERE w. STATUS > 0 AND l. STATUS = 1 AND w.admin_team_code in (" +adminTeamCodetemp+")"+
|
|
|
" AND w.patient = l.patient " +//AND LEFT (w.hospital, 6) = '350211' " +
|
|
|
" AND w. CODE = q.sign_code AND q.server_type = 1 ) a " +
|
|
|
" GROUP BY a.patient HAVING 1 = 1 " + whereSql + " and tt LIKE '%" + labelType + one + "%' ) aa " + tableSql;
|
|
|
groupPatient = jdbcTemplate.queryForList(sql, String.class);
|
|
|
resultList.addAll(groupPatient);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
case "2": {
|
|
|
for (String one : group) {
|
|
|
sql = " select DISTINCT(aa.patient) from ( " +
|
|
|
" SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
|
|
|
" FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
|
|
|
" WHERE w. STATUS > 0 and l.status=1 AND w.admin_team_code in ("+adminTeamCodetemp+") AND w.patient = l.patient ) a " +// AND LEFT (w.hospital, 6) = '350211' ) a " +
|
|
|
" GROUP BY a.patient HAVING 1=1 " + whereSql + " and tt LIKE '%" + labelType + one + "%' ) aa " + tableSql;
|
|
|
groupPatient = jdbcTemplate.queryForList(sql, String.class);
|
|
|
resultList.addAll(groupPatient);
|
|
|
// }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
case "3": {
|
|
|
for (String one : group) {
|
|
|
sql = " select DISTINCT(aa.patient) from ( " +
|
|
|
" SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
|
|
|
" FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
|
|
|
" WHERE w. STATUS > 0 and l.status=1 AND w.admin_team_code in ("+adminTeamCodetemp+") AND w.patient = l.patient ) a " +// AND LEFT (w.hospital, 6) = '350211' ) a " +
|
|
|
" GROUP BY a.patient HAVING 1=1 " + whereSql + " and tt LIKE '%" + labelType + one + "%') aa " + tableSql;
|
|
|
groupPatient = jdbcTemplate.queryForList(sql, String.class);
|
|
|
resultList.addAll(groupPatient);
|
|
|
// }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
case "4": {
|
|
|
for (String one : group) {
|
|
|
sql = " select DISTINCT(aa.patient) from ( " +
|
|
|
" SELECT a.patient, GROUP_CONCAT( concat(a.label_type, a.label) ) tt " +
|
|
|
" FROM ( SELECT l.* FROM wlyy_sign_family w, wlyy_sign_patient_label_info l " +
|
|
|
" WHERE w. STATUS > 0 and l.status=1 AND w.admin_team_code in ("+adminTeamCodetemp+") AND w.patient = l.patient ) a " +// AND LEFT (w.hospital, 6) = '350211' ) a " +
|
|
|
" GROUP BY a.patient HAVING 1=1 " + whereSql.toString() + " and tt LIKE '%" + labelType + one + "%') aa " + tableSql;
|
|
|
groupPatient = jdbcTemplate.queryForList(sql, String.class);
|
|
|
resultList.addAll(groupPatient);
|
|
|
// }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
patientSet.addAll(resultList);
|
|
|
}
|
|
|
|
|
|
}
|