|
@ -1,10 +1,14 @@
|
|
|
package com.yihu.jw.hospital.survey.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.entity.base.user.UserDO;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientBusinessDO;
|
|
|
import com.yihu.jw.entity.hospital.survey.*;
|
|
|
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
|
|
|
import com.yihu.jw.hospital.survey.dao.*;
|
|
|
import com.yihu.jw.patient.dao.BasePatientBusinessDao;
|
|
|
import com.yihu.jw.restmodel.hospital.consult.WlyyHospitalSysDictVO;
|
|
|
import com.yihu.jw.restmodel.hospital.survey.*;
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
@ -12,12 +16,13 @@ import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
|
|
|
import com.yihu.jw.util.common.IdCardUtil;
|
|
|
import com.yihu.jw.util.common.PercentageUtil;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.util.http.HttpClientUtil;
|
|
|
import com.yihu.jw.utils.EntityUtils;
|
|
|
import com.yihu.jw.utils.StringUtil;
|
|
|
import com.yihu.jw.utils.hibernate.HibenateUtils;
|
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
@ -64,6 +69,21 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
private SurveyUserAnswerDao surveyUserAnswerDao;
|
|
|
@Autowired
|
|
|
private HibenateUtils hibenateUtils;
|
|
|
@Autowired
|
|
|
private BaseDoctorDao baseDoctorDao;
|
|
|
@Autowired
|
|
|
private BasePatientBusinessDao basePatientBusinessDao;
|
|
|
@Value("${wechat.id}")
|
|
|
private String wxId;
|
|
|
|
|
|
|
|
|
@Value("${wechat.flag}")
|
|
|
private boolean flag;
|
|
|
@Autowired
|
|
|
private HttpClientUtil HttpClientUtil;
|
|
|
|
|
|
@Value("${im.im_list_get}")
|
|
|
private String im_host;
|
|
|
/**
|
|
|
* 查询字典
|
|
|
* 1.surveyLabel;2.surveyScreenLabel
|
|
@ -283,6 +303,7 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
" t.template_comment AS templateComment, " +
|
|
|
" t.organization, " +
|
|
|
" t.creater, " +
|
|
|
" t.creater_code, " +
|
|
|
" t.create_time AS createTime, " +
|
|
|
" t.del, " +
|
|
|
" t.update_time AS updateTime" +
|
|
@ -300,7 +321,7 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
sql += " AND i.label_code ='"+label+"'";
|
|
|
}
|
|
|
if (StringUtils.isNoneBlank(creater)){
|
|
|
sql +=" AND t.creater = '"+creater+"' ";
|
|
|
sql +=" AND t.creater_code = '"+creater+"' ";
|
|
|
}
|
|
|
sql += " ORDER BY t.create_time DESC LIMIT " + (page - 1) * size + "," + size + " ";
|
|
|
|
|
@ -363,13 +384,14 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
String sqlUsed = "select t.used as \"used\" from wlyy_knowledge_article_user t where t.relation_code = '"+templateCode +"'";
|
|
|
if(StringUtils.isNotEmpty(userCode)){
|
|
|
sqlUsed += " and t.user_code = '"+userCode+"'";
|
|
|
System.out.println(sqlUsed);
|
|
|
List<Map<String,Object>> listUsed = hibenateUtils.createSQLQuery(sqlUsed);
|
|
|
if (listUsed.size()>0){
|
|
|
String used = null!=listUsed.get(0).get("used")?listUsed.get(0).get("used").toString():"0";
|
|
|
templateVO.setUsed(Integer.valueOf(used));
|
|
|
}
|
|
|
}
|
|
|
System.out.println(sqlUsed);
|
|
|
List<Map<String,Object>> listUsed = hibenateUtils.createSQLQuery(sqlUsed);
|
|
|
if (listUsed.size()>0){
|
|
|
String used = null!=listUsed.get(0).get("used")?listUsed.get(0).get("used").toString():"0";
|
|
|
templateVO.setUsed(Integer.valueOf(used));
|
|
|
}
|
|
|
|
|
|
List<WlyySurveyTemplateQuestionDO> tqDOs = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(tempId,"1");
|
|
|
if(tqDOs!=null&&tqDOs.size()>0){
|
|
|
//设置问题
|
|
@ -379,7 +401,7 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
|
|
|
//设置选项
|
|
|
for(WlyySurveyTemplateQuestionVO tq:tqVOs){
|
|
|
List<WlyySurveyTemplateOptionDO> optionDOs = surveyTemplateOptionDao.findByQuestionCodeAndDelOrderBySortAsc(tq.getId(),"1");
|
|
|
List<WlyySurveyTemplateOptionDO> optionDOs = surveyTemplateOptionDao.findByQuestionCodeAndDelOrderBySortAsc(tq.getId(),tq.getTemplateCode(),"1");
|
|
|
List<WlyySurveyTemplateOptionVO> optionVOs = new ArrayList<>();
|
|
|
convertToModels(optionDOs,optionVOs,WlyySurveyTemplateOptionVO.class);
|
|
|
tq.setOptionVOs(optionVOs);
|
|
@ -411,8 +433,8 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
public Boolean saveSurveyTemplate(String tempJson,String tempQJson,String tempOpJson,String labelJson,String labelInspJson)throws Exception{
|
|
|
|
|
|
WlyySurveyTemplateDO temp = objectMapper.readValue(tempJson,WlyySurveyTemplateDO.class);
|
|
|
String doctor = temp.getCreaterCode();
|
|
|
temp = surveyTemplateDao.save(temp);
|
|
|
|
|
|
//删除原有问题
|
|
|
List<WlyySurveyTemplateQuestionDO> questionDODels = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(temp.getId(),"1");
|
|
|
if(questionDODels!=null&&questionDODels.size()>0){
|
|
@ -615,6 +637,14 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
answerDO.setSurverUserId(surveyUserDO.getId());
|
|
|
}
|
|
|
surveyUserAnswerDao.save(answerDOs);
|
|
|
BasePatientBusinessDO basePatientBusinessDO = basePatientBusinessDao.findByDoctorPatientRelationCode(surveyUserDO.getPatient(),surveyUserDO.getSurveyTempCode(),surveyUserDO.getDoctor());
|
|
|
JSONObject object = new JSONObject();
|
|
|
if (null!=basePatientBusinessDO){
|
|
|
object.put("title",surveyUserDO.getSurveyTempTitle());
|
|
|
object.put("content",answerDOs);
|
|
|
object.put("id",surveyUserDO.getSurveyTempCode());
|
|
|
}
|
|
|
this.sendImMsg(basePatientBusinessDO.getPatient(), basePatientBusinessDO.getPatientName(), basePatientBusinessDO.getSessionId(), "36", object.toJSONString(),"1");
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@ -644,7 +674,11 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
WlyySurveyTemplateVO templateVO = convertToModel(templateDO,WlyySurveyTemplateVO.class);
|
|
|
templateVO.setLabels(findSurveyTemplateLabel(tempId));
|
|
|
templateVO.setInsplabels(findSurveyInspTemplateLabel(tempId));
|
|
|
|
|
|
BaseDoctorDO doctor = baseDoctorDao.findById(templateDO.getCreaterCode());
|
|
|
if (null!=doctor){
|
|
|
templateVO.setVisitDept(doctor.getVisitDept());
|
|
|
templateVO.setVisitDeptName(doctor.getVisitDeptName());
|
|
|
}
|
|
|
//查询所有答题过的用户,计算答题总数
|
|
|
List<WlyySurveyUserDO> surveyUsers = surveyUserDao.findBySurveyTempCodeAndStatus(templateVO.getId(),1);
|
|
|
Integer total =0;
|
|
@ -662,11 +696,11 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
|
|
|
//设置选项
|
|
|
for(WlyySurveyTemplateQuestionVO tq:tqVOs){
|
|
|
List<WlyySurveyTemplateOptionDO> optionDOs = surveyTemplateOptionDao.findByQuestionCodeAndDelOrderBySortAsc(tq.getId(),"1");
|
|
|
List<WlyySurveyTemplateOptionDO> optionDOs = surveyTemplateOptionDao.findByQuestionCodeAndDelOrderBySortAsc(tq.getId(),tq.getTemplateCode(),"1");
|
|
|
List<WlyySurveyTemplateOptionVO> optionVOs = new ArrayList<>();
|
|
|
convertToModels(optionDOs,optionVOs,WlyySurveyTemplateOptionVO.class);
|
|
|
int tpCount = 0;
|
|
|
List<WlyySurveyUserAnswerDO> answerQuestionDOs = surveyUserAnswerDao.findByTempQuestionCodeDistinctPatient(tq.getId());
|
|
|
List<WlyySurveyUserAnswerDO> answerQuestionDOs = surveyUserAnswerDao.findByTempQuestionCodeDistinctPatient(tq.getId(),tempId);
|
|
|
if(answerQuestionDOs!=null&&answerQuestionDOs.size()>0){
|
|
|
tpCount = answerQuestionDOs.size();
|
|
|
}
|
|
@ -677,7 +711,7 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
if(optionVOs!=null&&optionVOs.size()>0){
|
|
|
for(WlyySurveyTemplateOptionVO vo:optionVOs){
|
|
|
Integer answerCount =0;
|
|
|
List<WlyySurveyUserAnswerDO> answerDOs = surveyUserAnswerDao.findBytempOptionCode(vo.getId());
|
|
|
List<WlyySurveyUserAnswerDO> answerDOs = surveyUserAnswerDao.findBytempOptionCode(vo.getId(),vo.getTemplateCode());
|
|
|
if(answerDOs!=null&&answerDOs.size()>0){
|
|
|
answerCount = answerDOs.size();
|
|
|
}
|
|
@ -765,18 +799,18 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
|
|
|
/**
|
|
|
* 查询
|
|
|
* @param title
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @param
|
|
|
* @param
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop findAnswerList(String tempId,String patient,String title,Integer page,Integer size){
|
|
|
public MixEnvelop findAnswerList(String tempId,String patient,String patientName,String title,Integer page,Integer size){
|
|
|
|
|
|
String totalSql ="SELECT " +
|
|
|
" COUNT(1) AS total" +
|
|
|
" FROM " +
|
|
|
" wlyy_survey_user t " +
|
|
|
" WHERE 1=1 ";
|
|
|
" WHERE 1=1 and t.status = 1 ";
|
|
|
if(StringUtils.isNotBlank(title)){
|
|
|
totalSql += " AND t.survey_temp_title like '%"+title+"%' ";
|
|
|
}
|
|
@ -786,6 +820,9 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
if(StringUtils.isNotBlank(tempId)){
|
|
|
totalSql += " AND t.survey_temp_code = '"+tempId+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(patientName)){
|
|
|
totalSql += " AND t.patient_name like '%"+patientName+"%' ";
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
|
|
|
Long count = 0L;
|
|
@ -811,18 +848,38 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
" FROM " +
|
|
|
" wlyy_survey_user t " +
|
|
|
" JOIN base_patient p ON t.patient = p.id " +
|
|
|
" WHERE 1=1 ";
|
|
|
" WHERE 1=1 and t.status = 1 ";
|
|
|
if(StringUtils.isNotBlank(title)){
|
|
|
sql += " AND t.survey_temp_title like '%"+title+"%' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(patient)){
|
|
|
sql += " AND t.patient = '"+patient+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(patientName)){
|
|
|
sql += " AND t.patient_name like '%"+patientName+"%' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(tempId)){
|
|
|
sql += " AND t.survey_temp_code = '"+tempId+"' ";
|
|
|
}
|
|
|
sql += " ORDER BY t.create_time DESC LIMIT " + (page - 1) * size + "," + size + " ";
|
|
|
sql += " ORDER BY t.create_time DESC " ;
|
|
|
|
|
|
if ("xm_ykyy_wx".equals(wxId)) {
|
|
|
if (flag){
|
|
|
sql ="SELECT * FROM\n" +
|
|
|
"( SELECT A.*, ROWNUM RN FROM\n" +
|
|
|
" ("+sql+") A \n" +
|
|
|
" WHERE ROWNUM <= "+page*size+" ) \n" +
|
|
|
" WHERE RN >= "+((page-1)*size+1);
|
|
|
|
|
|
}else {
|
|
|
sql+="LIMIT "+ (page - 1) * size + "," + size + " ";
|
|
|
|
|
|
}
|
|
|
} else {
|
|
|
sql+="LIMIT "+ (page - 1) * size + "," + size + " ";
|
|
|
|
|
|
}
|
|
|
System.out.println(sql);
|
|
|
List<WlyySurveyUserVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyySurveyUserVO.class));
|
|
|
|
|
|
if(list!=null&&list.size()>0){
|
|
@ -833,4 +890,18 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
|
|
|
|
|
|
return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
|
|
|
}
|
|
|
|
|
|
public String sendImMsg(String from, String fromName, String sessionId, String contentType, String content, String businessType) {
|
|
|
String imAddr = im_host + "api/v2/sessions/" + sessionId + "/messages";
|
|
|
System.out.println("im地址"+imAddr);
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("sender_id", from);
|
|
|
params.put("sender_name", fromName);
|
|
|
params.put("content_type", contentType);
|
|
|
params.put("content", content);
|
|
|
params.put("session_id", sessionId);
|
|
|
params.put("business_type", businessType);
|
|
|
String response = HttpClientUtil.postBody(imAddr, params);
|
|
|
return response;
|
|
|
}
|
|
|
}
|