|
@ -0,0 +1,327 @@
|
|
|
package com.yihu.jw.hospital.survey.service;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
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.restmodel.hospital.consult.WlyyHospitalSysDictVO;
|
|
|
import com.yihu.jw.restmodel.hospital.survey.*;
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
|
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
|
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by Trick on 2019/9/6.
|
|
|
*/
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQuestionDao> {
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyHospitalSysDictDao sysDictDao;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
@Autowired
|
|
|
private SurveyQuestionDao surveyQuestionDao;
|
|
|
@Autowired
|
|
|
private SurveyQuestionsOptionDao surveyQuestionsOptionDao;
|
|
|
@Autowired
|
|
|
private SurveyTemplateDao surveyTemplateDao;
|
|
|
@Autowired
|
|
|
private SurveyTemplateQuestionDao surveyTemplateQuestionDao;
|
|
|
@Autowired
|
|
|
private SurveyTemplateOptionDao surveyTemplateOptionDao;
|
|
|
/**
|
|
|
* 查询字典
|
|
|
* 1.surveyLabel;2.surveyScreenLabel
|
|
|
* @param name
|
|
|
* @return
|
|
|
*/
|
|
|
public List<WlyyHospitalSysDictVO> getSurveyLabel(String name){
|
|
|
List<WlyyHospitalSysDictVO> list = new ArrayList<>();
|
|
|
return convertToModels(sysDictDao.findByDictName(name),list,WlyyHospitalSysDictVO.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询问题
|
|
|
* @param title
|
|
|
* @param questionType
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop findSurveyQuestion(String title,Integer questionType,Integer page,Integer size)throws Exception{
|
|
|
|
|
|
//计算总数
|
|
|
String totalSql ="SELECT" +
|
|
|
" COUNT(1) AS total" +
|
|
|
" FROM" +
|
|
|
" wlyy_survey_question q " +
|
|
|
" WHERE q.del = '1' ";
|
|
|
if(StringUtils.isNotBlank(title)){
|
|
|
totalSql+=" AND q.title like '%"+title+"%'";
|
|
|
}
|
|
|
if(questionType!=null){
|
|
|
totalSql+=" AND q.question_type ="+questionType;
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
|
|
|
Long count = 0L;
|
|
|
if (rstotal != null && rstotal.size() > 0) {
|
|
|
count = (Long) rstotal.get(0).get("total");
|
|
|
}
|
|
|
|
|
|
//计算总数
|
|
|
String sql ="SELECT " +
|
|
|
" q.id AS id, " +
|
|
|
" q.title AS title, " +
|
|
|
" q.question_comment AS questionComment, " +
|
|
|
" q.question_type AS questionType, " +
|
|
|
" q.is_required AS isRequired, " +
|
|
|
" q.min_num AS minNum, " +
|
|
|
" q.max_num AS maxNum, " +
|
|
|
" q.del, " +
|
|
|
" q.create_time AS createTime, " +
|
|
|
" q.update_time AS updateTime " +
|
|
|
" FROM " +
|
|
|
" wlyy_survey_question q " +
|
|
|
" WHERE q.del = '1' ";
|
|
|
|
|
|
if(StringUtils.isNotBlank(title)){
|
|
|
sql+=" AND q.title like '%"+title+"%'";
|
|
|
}
|
|
|
if(questionType!=null){
|
|
|
sql+=" AND q.question_type ="+questionType;
|
|
|
}
|
|
|
sql += " ORDER BY o.create_time DESC LIMIT " + (page - 1) * size + "," + size + " ";
|
|
|
|
|
|
List<WlyySurveyQuestionVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyySurveyQuestionVO.class));
|
|
|
|
|
|
if(list!=null&&list.size()>0){
|
|
|
for(WlyySurveyQuestionVO sq:list){
|
|
|
List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(sq.getId(),"1");
|
|
|
if(optionDOs!=null&&optionDOs.size()>0){
|
|
|
List<WlyySurveyQuestionsOptionVO> optionVOs = new ArrayList<>();
|
|
|
sq.setOptionVOs(convertToModels(optionDOs,optionVOs,WlyySurveyQuestionsOptionVO.class));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询问题单条
|
|
|
* @param surveyId
|
|
|
* @return
|
|
|
*/
|
|
|
public WlyySurveyQuestionVO findBySurveyId(String surveyId){
|
|
|
WlyySurveyQuestionDO sq = surveyQuestionDao.findOne(surveyId);
|
|
|
WlyySurveyQuestionVO surveyQuestionVO = convertToModel(sq,WlyySurveyQuestionVO.class);
|
|
|
List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(sq.getId(),"1");
|
|
|
if(optionDOs!=null&&optionDOs.size()>0){
|
|
|
List<WlyySurveyQuestionsOptionVO> optionVOs = new ArrayList<>();
|
|
|
surveyQuestionVO.setOptionVOs(convertToModels(optionDOs,optionVOs,WlyySurveyQuestionsOptionVO.class));
|
|
|
}
|
|
|
return surveyQuestionVO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存问题
|
|
|
* @param sqOptionJson
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Boolean saveSurveyQuestion(String sqjsons,String sqOptionJson)throws Exception{
|
|
|
|
|
|
//保存问题
|
|
|
List<WlyySurveyQuestionDO> surveys = (List<WlyySurveyQuestionDO>) com.alibaba.fastjson.JSONArray.parseArray(sqjsons, WlyySurveyQuestionDO.class);
|
|
|
surveyQuestionDao.save(surveys);
|
|
|
|
|
|
if(surveys!=null&&surveys.size()>0){
|
|
|
for(WlyySurveyQuestionDO sq:surveys){
|
|
|
List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(sq.getId(),"1");
|
|
|
if(optionDOs!=null&&optionDOs.size()>0){
|
|
|
surveyQuestionsOptionDao.delete(optionDOs);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(sqOptionJson)){
|
|
|
List<WlyySurveyQuestionsOptionDO> options = (List<WlyySurveyQuestionsOptionDO>) com.alibaba.fastjson.JSONArray.parseArray(sqOptionJson, WlyySurveyQuestionsOptionDO.class);
|
|
|
surveyQuestionsOptionDao.save(options);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 单个编辑问题
|
|
|
* @param sqjson
|
|
|
* @param sqOptionJson
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Boolean updataSurveyQuestion(String sqjson,String sqOptionJson) throws Exception{
|
|
|
WlyySurveyQuestionDO sq = objectMapper.readValue(sqjson,WlyySurveyQuestionDO.class);
|
|
|
surveyQuestionDao.save(sq);
|
|
|
|
|
|
List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(sq.getId(),"1");
|
|
|
if(optionDOs!=null&&optionDOs.size()>0){
|
|
|
surveyQuestionsOptionDao.delete(optionDOs);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(sqOptionJson)){
|
|
|
List<WlyySurveyQuestionsOptionDO> options = (List<WlyySurveyQuestionsOptionDO>) com.alibaba.fastjson.JSONArray.parseArray(sqOptionJson, WlyySurveyQuestionsOptionDO.class);
|
|
|
surveyQuestionsOptionDao.save(options);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除问题
|
|
|
* @param ids
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean delSurveyQuestion(String ids){
|
|
|
|
|
|
String sids[] =ids.split(",");
|
|
|
if(sids!=null&&ids.length()>0){
|
|
|
for(String id:sids){
|
|
|
WlyySurveyQuestionDO del = surveyQuestionDao.findOne(id);
|
|
|
if(del!=null){
|
|
|
surveyQuestionDao.delete(del);
|
|
|
}
|
|
|
List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(id,"1");
|
|
|
if(optionDOs!=null&&optionDOs.size()>0){
|
|
|
surveyQuestionsOptionDao.delete(optionDOs);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//=====================问卷模板=====================================
|
|
|
|
|
|
/**
|
|
|
* 查询模板列表
|
|
|
* @param title
|
|
|
* @param label
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop findSurveyTemplate(String title,String label,Integer page,Integer size){
|
|
|
|
|
|
String totalSql ="SELECT " +
|
|
|
" COUNT(1) AS total" +
|
|
|
" FROM " +
|
|
|
" wlyy_survey_template t ";
|
|
|
if(StringUtils.isNotBlank(label)){
|
|
|
totalSql+=" JOIN wlyy_survey_label_info i OM t.id = i.survey_temp_code";
|
|
|
}
|
|
|
totalSql += " WHERE " +
|
|
|
" t.del = '1'";
|
|
|
if(StringUtils.isNotBlank(title)){
|
|
|
totalSql += " t.title like '%"+title+"%' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(label)){
|
|
|
totalSql += " i.label_code ='"+label+"'";
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
|
|
|
Long count = 0L;
|
|
|
if (rstotal != null && rstotal.size() > 0) {
|
|
|
count = (Long) rstotal.get(0).get("total");
|
|
|
}
|
|
|
|
|
|
|
|
|
String sql = "SELECT " +
|
|
|
" t.id, " +
|
|
|
" t.title, " +
|
|
|
" t.template_comment AS templateComment, " +
|
|
|
" t.organization, " +
|
|
|
" t.creater, " +
|
|
|
" t.create_time AS createTime, " +
|
|
|
" t.del, " +
|
|
|
" t.update_time AS updateTime" +
|
|
|
" FROM " +
|
|
|
" wlyy_survey_template t ";
|
|
|
if(StringUtils.isNotBlank(label)){
|
|
|
sql += " JOIN wlyy_survey_label_info i OM t.id = i.survey_temp_code";
|
|
|
}
|
|
|
sql += " WHERE " +
|
|
|
" t.del = '1'";
|
|
|
if(StringUtils.isNotBlank(title)){
|
|
|
sql += " t.title like '%"+title+"%' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(label)){
|
|
|
sql += " i.label_code ='"+label+"'";
|
|
|
}
|
|
|
sql += " ORDER BY o.create_time DESC LIMIT " + (page - 1) * size + "," + size + " ";
|
|
|
|
|
|
List<WlyySurveyTemplateVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyySurveyTemplateVO.class));
|
|
|
|
|
|
if(list!=null&&list.size()>0){
|
|
|
//设置标签
|
|
|
for(WlyySurveyTemplateVO templateVO : list){
|
|
|
templateVO.setLabels(findSurveyTemplateLabel(templateVO.getId()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取问卷模板详情
|
|
|
* @param tempId
|
|
|
* @return
|
|
|
*/
|
|
|
public WlyySurveyTemplateVO findSurveyTemplateById(String tempId){
|
|
|
WlyySurveyTemplateDO templateDO = surveyTemplateDao.findOne(tempId);
|
|
|
WlyySurveyTemplateVO templateVO = convertToModel(templateDO,WlyySurveyTemplateVO.class);
|
|
|
templateVO.setLabels(findSurveyTemplateLabel(tempId));
|
|
|
|
|
|
List<WlyySurveyTemplateQuestionDO> tqDOs = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(tempId,"1");
|
|
|
if(tqDOs!=null&&tqDOs.size()>0){
|
|
|
//设置问题
|
|
|
List<WlyySurveyTemplateQuestionVO> tqVOs = new ArrayList<>();
|
|
|
convertToModels(tqDOs,tqVOs,WlyySurveyTemplateQuestionVO.class);
|
|
|
templateVO.setTemplateQuestionVOs(tqVOs);
|
|
|
|
|
|
//设置选项
|
|
|
for(WlyySurveyTemplateQuestionVO tq:tqVOs){
|
|
|
List<WlyySurveyTemplateOptionDO> optionDOs = surveyTemplateOptionDao.findByTemplateQuestionCodeAndDelOrderBySortAsc(tq.getId(),"1");
|
|
|
List<WlyySurveyTemplateOptionVO> optionVOs = new ArrayList<>();
|
|
|
convertToModels(optionDOs,optionVOs,WlyySurveyTemplateOptionVO.class);
|
|
|
tq.setTemplateOptionVOs(optionVOs);
|
|
|
}
|
|
|
}
|
|
|
return templateVO;
|
|
|
}
|
|
|
|
|
|
public List<Map<String,Object>> findSurveyTemplateLabel(String tempId){
|
|
|
String sql ="SELECT " +
|
|
|
" i.label_code AS labelCode, " +
|
|
|
" i.label_name AS labelName " +
|
|
|
" FROM " +
|
|
|
" wlyy_survey_label_info i " +
|
|
|
" WHERE " +
|
|
|
" i.survey_temp_code = '"+tempId+"'";
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
// public Boolean saveSurveyTemplate(){
|
|
|
//
|
|
|
// }
|
|
|
}
|