Browse Source

bug修改

suqinyi 11 months ago
parent
commit
c1b479b55e

+ 317 - 287
business/base-service/src/main/java/com/yihu/jw/hospital/survey/service/SurveyService.java

@ -8,6 +8,7 @@ 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.mysql.query.BaseJpaService;
import com.yihu.jw.patient.dao.BasePatientBusinessDao;
import com.yihu.jw.restmodel.hospital.consult.WlyyHospitalSysDictVO;
import com.yihu.jw.restmodel.hospital.survey.*;
@ -19,7 +20,6 @@ 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.hibernate.HibenateUtils;
import com.yihu.jw.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -81,42 +81,45 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    @Value("${im.im_list_get}")
    private String im_host;
    /**
     * 查询字典
     * 1.surveyLabel;2.surveyScreenLabel
     *
     * @param name
     * @return
     */
    public List<WlyyHospitalSysDictVO> findSurveyLabel(String name){
    public List<WlyyHospitalSysDictVO> findSurveyLabel(String name) {
        List<WlyyHospitalSysDictVO> list = new ArrayList<>();
        return convertToModels(sysDictDao.findByDictName(name),list,WlyyHospitalSysDictVO.class);
        return convertToModels(sysDictDao.findByDictName(name), list, WlyyHospitalSysDictVO.class);
    }
    /**
     * 查询问题
     *
     * @param title
     * @param questionType
     * @param page
     * @param size
     * @return
     */
    public MixEnvelop findSurveyQuestion(String title,String creater, Integer questionType,Integer page,Integer size)throws Exception{
    public MixEnvelop findSurveyQuestion(String title, String creater, Integer questionType, Integer page, Integer size) throws Exception {
        //计算总数
        String totalSql ="SELECT" +
        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 (StringUtils.isNotBlank(title)) {
            totalSql += " AND q.title like '%" + title + "%'";
        }
        if(questionType!=null){
            totalSql+=" AND q.question_type ="+questionType;
        if (questionType != null) {
            totalSql += " AND q.question_type =" + questionType;
        }
        if (StringUtils.isNoneBlank(creater)){
            totalSql+=" AND q.creater ='"+creater+"' ";
        if (StringUtils.isNoneBlank(creater)) {
            totalSql += " AND q.creater ='" + creater + "' ";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -126,7 +129,7 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
        }
        //计算总数
        String sql ="SELECT " +
        String sql = "SELECT " +
                " q.id AS \"id\", " +
                " q.title AS \"title\", " +
                " q.question_comment AS \"questionComment\", " +
@ -141,41 +144,41 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                " wlyy_survey_question q " +
                " WHERE q.del = '1' ";
        if(StringUtils.isNotBlank(title)){
            sql+=" AND q.title like '%"+title+"%'";
        if (StringUtils.isNotBlank(title)) {
            sql += " AND q.title like '%" + title + "%'";
        }
        if(questionType!=null){
            sql+=" AND q.question_type ="+questionType;
        if (questionType != null) {
            sql += " AND q.question_type =" + questionType;
        }
        if (StringUtils.isNoneBlank(creater)){
            sql+=" AND q.creater ='"+creater+"' ";
        if (StringUtils.isNoneBlank(creater)) {
            sql += " AND q.creater ='" + creater + "' ";
        }
        sql += " ORDER BY q.create_time DESC  ";
        if ("xm_ykyy_wx".equals(wxId)) {
            if (!flag){
                sql ="SELECT * FROM\n" +
            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);
                        "    (" + 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 + " ";
            }
        } else {
            sql+="LIMIT "+ (page - 1) * size + "," + size + " ";
            sql += "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){
        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));
                    sq.setOptionVOs(convertToModels(optionDOs, optionVOs, WlyySurveyQuestionsOptionVO.class));
                }
            }
        }
@ -185,44 +188,46 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 查询问题单条
     *
     * @param surveyId
     * @return
     */
    public WlyySurveyQuestionVO findBySurveyId(String surveyId){
    public WlyySurveyQuestionVO findBySurveyId(String surveyId) {
        WlyySurveyQuestionDO sq = surveyQuestionDao.findById(surveyId).orElse(null);
        WlyySurveyQuestionVO surveyQuestionVO = convertToModel(sq,WlyySurveyQuestionVO.class);
        List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(sq.getId(),"1");
        if(optionDOs!=null&&optionDOs.size()>0){
        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));
            surveyQuestionVO.setOptionVOs(convertToModels(optionDOs, optionVOs, WlyySurveyQuestionsOptionVO.class));
        }
        return surveyQuestionVO;
    }
    /**
     * 保存问题
     *
     * @param sqOptionJson
     * @return
     * @throws Exception
     */
    public Boolean saveSurveyQuestion(String sqjsons,String sqOptionJson)throws Exception{
    public Boolean saveSurveyQuestion(String sqjsons, String sqOptionJson) throws Exception {
        //保存问题
        List<WlyySurveyQuestionDO> surveys = EntityUtils.jsonToList(sqjsons, WlyySurveyQuestionDO.class);
        for (WlyySurveyQuestionDO wlyySurveyQuestionDO:surveys){
        for (WlyySurveyQuestionDO wlyySurveyQuestionDO : surveys) {
            wlyySurveyQuestionDO.setCreateTime(new Date());
            wlyySurveyQuestionDO.setUpdateTime(new Date());
        }
        surveyQuestionDao.saveAll(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){
        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.deleteAll(optionDOs);
                }
                if(StringUtils.isNotBlank(sqOptionJson)){
                if (StringUtils.isNotBlank(sqOptionJson)) {
                    List<WlyySurveyQuestionsOptionDO> options = EntityUtils.jsonToList(sqOptionJson, WlyySurveyQuestionsOptionDO.class);
                    surveyQuestionsOptionDao.saveAll(options);
                }
@ -233,21 +238,22 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 单个编辑问题
     *
     * @param sqjson
     * @param sqOptionJson
     * @return
     * @throws Exception
     */
    public Boolean updataSurveyQuestion(String sqjson,String sqOptionJson) throws Exception{
        WlyySurveyQuestionDO sq = objectMapper.readValue(sqjson,WlyySurveyQuestionDO.class);
    public Boolean updataSurveyQuestion(String sqjson, String sqOptionJson) throws Exception {
        WlyySurveyQuestionDO sq = objectMapper.readValue(sqjson, WlyySurveyQuestionDO.class);
        sq.setUpdateTime(new Date());
        surveyQuestionDao.save(sq);
        List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(sq.getId(),"1");
        if(optionDOs!=null&&optionDOs.size()>0){
        List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(sq.getId(), "1");
        if (optionDOs != null && optionDOs.size() > 0) {
            surveyQuestionsOptionDao.deleteAll(optionDOs);
        }
        if(StringUtils.isNotBlank(sqOptionJson)){
        if (StringUtils.isNotBlank(sqOptionJson)) {
            List<WlyySurveyQuestionsOptionDO> options = EntityUtils.jsonToList(sqOptionJson, WlyySurveyQuestionsOptionDO.class);
            surveyQuestionsOptionDao.saveAll(options);
        }
@ -256,20 +262,21 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 删除问题
     *
     * @param ids
     * @return
     */
    public Boolean delSurveyQuestion(String ids){
    public Boolean delSurveyQuestion(String ids) {
        String sids[] =ids.split(",");
        if(sids!=null&&ids.length()>0){
            for(String id:sids){
        String sids[] = ids.split(",");
        if (sids != null && ids.length() > 0) {
            for (String id : sids) {
                WlyySurveyQuestionDO del = surveyQuestionDao.findById(id).orElse(null);
                if(del!=null){
                if (del != null) {
                    surveyQuestionDao.delete(del);
                }
                List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(id,"1");
                if(optionDOs!=null&&optionDOs.size()>0){
                List<WlyySurveyQuestionsOptionDO> optionDOs = surveyQuestionsOptionDao.findByQuestionCodeAndDelOrderBySortAsc(id, "1");
                if (optionDOs != null && optionDOs.size() > 0) {
                    surveyQuestionsOptionDao.deleteAll(optionDOs);
                }
            }
@ -280,32 +287,33 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    //=====================问卷模板=====================================
    /**
     *  查询模板列表
     * 查询模板列表
     *
     * @param title
     * @param label
     * @param page
     * @param size
     * @return
     */
    public MixEnvelop findSurveyTemplate(String title,String creater,String label,Integer page,Integer size){
    public MixEnvelop findSurveyTemplate(String title, String creater, String label, Integer page, Integer size) {
        String totalSql ="SELECT " +
        String totalSql = "SELECT " +
                " COUNT(1) AS \"total\"" +
                " FROM " +
                " wlyy_survey_template t ";
        if(StringUtils.isNotBlank(label)){
            totalSql+=" JOIN wlyy_survey_label_info i ON t.id = i.survey_temp_code";
        if (StringUtils.isNotBlank(label)) {
            totalSql += " JOIN wlyy_survey_label_info i ON t.id = i.survey_temp_code";
        }
        totalSql += " WHERE " +
                    " t.del = '1'";
        if(StringUtils.isNotBlank(title)){
            totalSql += " AND t.title like '%"+title+"%' ";
                " t.del = '1'";
        if (StringUtils.isNotBlank(title)) {
            totalSql += " AND t.title like '%" + title + "%' ";
        }
        if(StringUtils.isNotBlank(label)){
            totalSql += " AND i.label_code ='"+label+"'";
        if (StringUtils.isNotBlank(label)) {
            totalSql += " AND i.label_code ='" + label + "'";
        }
        if (StringUtils.isNoneBlank(creater)){
            totalSql +=" AND  t.creater_code = '"+creater+"' ";
        if (StringUtils.isNoneBlank(creater)) {
            totalSql += " AND  t.creater_code = '" + creater + "' ";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -327,67 +335,67 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                " t.update_time AS \"updateTime\"" +
                " FROM " +
                " wlyy_survey_template t ";
        if(StringUtils.isNotBlank(label)){
        if (StringUtils.isNotBlank(label)) {
            sql += " JOIN wlyy_survey_label_info i ON t.id = i.survey_temp_code";
        }
            sql += " WHERE " +
                   " t.del = '1'";
        if(StringUtils.isNotBlank(title)){
            sql += " AND t.title like '%"+title+"%' ";
        sql += " WHERE " +
                " t.del = '1'";
        if (StringUtils.isNotBlank(title)) {
            sql += " AND t.title like '%" + title + "%' ";
        }
        if(StringUtils.isNotBlank(label)){
            sql += " AND  i.label_code ='"+label+"'";
        if (StringUtils.isNotBlank(label)) {
            sql += " AND  i.label_code ='" + label + "'";
        }
        if (StringUtils.isNoneBlank(creater)){
            sql +=" AND  t.creater_code = '"+creater+"' ";
        if (StringUtils.isNoneBlank(creater)) {
            sql += " AND  t.creater_code = '" + creater + "' ";
        }
        sql += " ORDER BY t.create_time DESC  ";
        if ("xm_ykyy_wx".equals(wxId)) {
            if (!flag){
                sql ="SELECT * FROM\n" +
            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);
                        "    (" + sql + ") A \n" +
                        "    WHERE ROWNUM <= " + page * size + " ) \n" +
                        "       WHERE RN >= " + ((page - 1) * size + 1);
                System.out.println(sql);
            }else {
                sql+="LIMIT "+ (page - 1) * size + "," + size + " ";
            } else {
                sql += "LIMIT " + (page - 1) * size + "," + size + " ";
            }
        } else {
            sql+="LIMIT "+ (page - 1) * size + "," + size + " ";
            sql += "LIMIT " + (page - 1) * size + "," + size + " ";
        }
        List<WlyySurveyTemplateVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyySurveyTemplateVO.class));
        if(list!=null&&list.size()>0){
        if (list != null && list.size() > 0) {
            //设置标签
            for(WlyySurveyTemplateVO templateVO : list){
            for (WlyySurveyTemplateVO templateVO : list) {
                String templateCode = templateVO.getId();
                String sqlUsed = "select t.used as \"used\" from wlyy_knowledge_article_user t where t.relation_code = '"+templateCode +"'";
                if(StringUtils.isNotEmpty(creater)){
                    sqlUsed += " and t.user_code = '"+creater+"'";
                String sqlUsed = "select t.used as \"used\" from wlyy_knowledge_article_user t where t.relation_code = '" + templateCode + "'";
                if (StringUtils.isNotEmpty(creater)) {
                    sqlUsed += " and t.user_code = '" + creater + "'";
                }
                List<Map<String,Object>> listUsed = hibenateUtils.createSQLQuery(sqlUsed);
                for (Map<String,Object> map:listUsed){
                List<Map<String, Object>> listUsed = hibenateUtils.createSQLQuery(sqlUsed);
                for (Map<String, Object> map : listUsed) {
                    Integer in = null;
                    if (listUsed.size()>0){
                        if (null!=listUsed.get(0)){
                    if (listUsed.size() > 0) {
                        if (null != listUsed.get(0)) {
                            Object object = map.get("used");
                            if(object!=null){
                                if(object instanceof Integer){
                                    in = (Integer)object;
                                }else if(object instanceof String){
                                    in = Integer.parseInt((String)object);
                                }else if(object instanceof Double){
                                    in = (int)((double)object);
                                }else if(object instanceof Float){
                                    in = (int)((float)object);
                                }else if(object instanceof BigDecimal){
                                    in = ((BigDecimal)object).intValue();
                                }else if(object instanceof Long){
                                    in = ((Long)object).intValue();
                            if (object != null) {
                                if (object instanceof Integer) {
                                    in = (Integer) object;
                                } else if (object instanceof String) {
                                    in = Integer.parseInt((String) object);
                                } else if (object instanceof Double) {
                                    in = (int) ((double) object);
                                } else if (object instanceof Float) {
                                    in = (int) ((float) object);
                                } else if (object instanceof BigDecimal) {
                                    in = ((BigDecimal) object).intValue();
                                } else if (object instanceof Long) {
                                    in = ((Long) object).intValue();
                                }
                            }
                        }
@ -396,7 +404,6 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                }
                templateVO.setLabels(findSurveyTemplateLabel(templateVO.getId()));
            }
        }
@ -406,38 +413,39 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 获取问卷模板详情
     *
     * @param tempId
     * @return
     */
    public WlyySurveyTemplateVO findSurveyTemplateById(String tempId,String userCode ){
    public WlyySurveyTemplateVO findSurveyTemplateById(String tempId, String userCode) {
        WlyySurveyTemplateDO templateDO = surveyTemplateDao.findById(tempId).orElse(null);
        WlyySurveyTemplateVO templateVO = convertToModel(templateDO,WlyySurveyTemplateVO.class);
        WlyySurveyTemplateVO templateVO = convertToModel(templateDO, WlyySurveyTemplateVO.class);
        templateVO.setLabels(findSurveyTemplateLabel(tempId));
        templateVO.setInsplabels(findSurveyInspTemplateLabel(tempId));
        String templateCode = templateDO.getId();
        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+"'";
        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";
            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){
        List<WlyySurveyTemplateQuestionDO> tqDOs = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(tempId, "1");
        if (tqDOs != null && tqDOs.size() > 0) {
            //设置问题
            List<WlyySurveyTemplateQuestionVO> tqVOs = new ArrayList<>();
            convertToModels(tqDOs,tqVOs,WlyySurveyTemplateQuestionVO.class);
            convertToModels(tqDOs, tqVOs, WlyySurveyTemplateQuestionVO.class);
            //设置选项
            for(WlyySurveyTemplateQuestionVO tq:tqVOs){
                List<WlyySurveyTemplateOptionDO> optionDOs  = surveyTemplateOptionDao.findByQuestionCodeAndDelOrderBySortAsc(tq.getCode(),tq.getTemplateCode(),"1");
            for (WlyySurveyTemplateQuestionVO tq : tqVOs) {
                List<WlyySurveyTemplateOptionDO> optionDOs = surveyTemplateOptionDao.findByQuestionCodeAndDelOrderBySortAsc(tq.getCode(), tq.getTemplateCode(), "1");
                List<WlyySurveyTemplateOptionVO> optionVOs = new ArrayList<>();
                convertToModels(optionDOs,optionVOs,WlyySurveyTemplateOptionVO.class);
                for (WlyySurveyTemplateOptionVO optionVO:optionVOs){
                convertToModels(optionDOs, optionVOs, WlyySurveyTemplateOptionVO.class);
                for (WlyySurveyTemplateOptionVO optionVO : optionVOs) {
                    optionVO.setId(optionVO.getCode());
                }
                tq.setOptionVOs(optionVOs);
@ -448,32 +456,33 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
        return templateVO;
    }
    public List<WlyySurveyLabelInfoVO> findSurveyTemplateLabel(String tempId){
    public List<WlyySurveyLabelInfoVO> findSurveyTemplateLabel(String tempId) {
        List<WlyySurveyLabelInfoDO> list = surveyLabelInfoDao.findBySurveyTempCode(tempId);
        List<WlyySurveyLabelInfoVO> rs = new ArrayList<>();
        return convertToModels(list,rs,WlyySurveyLabelInfoVO.class);
        return convertToModels(list, rs, WlyySurveyLabelInfoVO.class);
    }
    public List<WlyySurveyInspLabelInfoVO> findSurveyInspTemplateLabel(String tempId){
    public List<WlyySurveyInspLabelInfoVO> findSurveyInspTemplateLabel(String tempId) {
        List<WlyySurveyInspLabelInfoDO> list = surveyInspLabelInfoDao.findBySurveyTempCode(tempId);
        List<WlyySurveyInspLabelInfoVO> rs = new ArrayList<>();
        return convertToModels(list,rs,WlyySurveyInspLabelInfoVO.class);
        return convertToModels(list, rs, WlyySurveyInspLabelInfoVO.class);
    }
    /**
     * 保存,更新模板
     *
     * @param tempJson
     * @param tempQJson
     * @param tempOpJson
     * @return
     * @throws Exception
     */
    public Boolean saveSurveyTemplate(String tempJson,String tempQJson,String tempOpJson,String labelJson,String labelInspJson)throws Exception{
    public Boolean saveSurveyTemplate(String tempJson, String tempQJson, String tempOpJson, String labelJson, String labelInspJson) throws Exception {
        WlyySurveyTemplateDO temp = objectMapper.readValue(tempJson,WlyySurveyTemplateDO.class);
        if (StringUtils.isNotEmpty(temp.getId())){
        WlyySurveyTemplateDO temp = objectMapper.readValue(tempJson, WlyySurveyTemplateDO.class);
        if (StringUtils.isNotEmpty(temp.getId())) {
            WlyySurveyTemplateDO templateDO = surveyTemplateDao.findById(temp.getId()).orElse(null);
            if(null!=templateDO){
            if (null != templateDO) {
                temp.setCreater(templateDO.getCreater());
                temp.setCreaterCode(templateDO.getCreaterCode());
                temp.setUpdateTime(new Date());
@ -483,14 +492,14 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
        temp.setUpdateTime(new Date());
        temp = surveyTemplateDao.save(temp);
        //删除原有问题
        List<WlyySurveyTemplateQuestionDO> questionDODels = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(temp.getId(),"1");
        if(questionDODels!=null&&questionDODels.size()>0){
        List<WlyySurveyTemplateQuestionDO> questionDODels = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(temp.getId(), "1");
        if (questionDODels != null && questionDODels.size() > 0) {
            surveyTemplateQuestionDao.deleteAll(questionDODels);
        }
        //新增问题
        if(StringUtils.isNotBlank(tempQJson)){
        if (StringUtils.isNotBlank(tempQJson)) {
            List<WlyySurveyTemplateQuestionDO> questions = EntityUtils.jsonToList(tempQJson, WlyySurveyTemplateQuestionDO.class);
            for (WlyySurveyTemplateQuestionDO wlyySurveyTemplateQuestionDO:questions){
            for (WlyySurveyTemplateQuestionDO wlyySurveyTemplateQuestionDO : questions) {
                wlyySurveyTemplateQuestionDO.setTemplateCode(temp.getId());
                wlyySurveyTemplateQuestionDO.setCode(wlyySurveyTemplateQuestionDO.getId());
                wlyySurveyTemplateQuestionDO.setId(UUID.randomUUID().toString());
@ -502,18 +511,18 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
        }
        //删除原有问题选项
        List<WlyySurveyTemplateOptionDO> optionDODels = surveyTemplateOptionDao.findByTemplateCodeAndDelOrderBySortAsc(temp.getId(),"1");
        if(optionDODels!=null&&optionDODels.size()>0){
        List<WlyySurveyTemplateOptionDO> optionDODels = surveyTemplateOptionDao.findByTemplateCodeAndDelOrderBySortAsc(temp.getId(), "1");
        if (optionDODels != null && optionDODels.size() > 0) {
            surveyTemplateOptionDao.deleteAll(optionDODels);
        }
        //保存新问题选项
        if(StringUtils.isNotBlank(tempOpJson)){
        if (StringUtils.isNotBlank(tempOpJson)) {
            List<WlyySurveyTemplateOptionDO> options = EntityUtils.jsonToList(tempOpJson, WlyySurveyTemplateOptionDO.class);
            for (WlyySurveyTemplateOptionDO wlyySurveyTemplateOptionDO:options){
            for (WlyySurveyTemplateOptionDO wlyySurveyTemplateOptionDO : options) {
                wlyySurveyTemplateOptionDO.setTemplateCode(temp.getId());
                wlyySurveyTemplateOptionDO.setCode(wlyySurveyTemplateOptionDO.getId());
                wlyySurveyTemplateOptionDO.setId(UUID.randomUUID()+"");
                wlyySurveyTemplateOptionDO.setId(UUID.randomUUID() + "");
            }
            surveyTemplateOptionDao.saveAll(options);
@ -521,21 +530,21 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
        //保存标签
        List<WlyySurveyLabelInfoDO> labelDels = surveyLabelInfoDao.findBySurveyTempCode(temp.getId());
        if(labelDels!=null&&labelDels.size()>0){
        if (labelDels != null && labelDels.size() > 0) {
            surveyLabelInfoDao.deleteAll(labelDels);
        }
        if(StringUtils.isNotBlank(labelJson)){
        if (StringUtils.isNotBlank(labelJson)) {
            List<WlyySurveyLabelInfoDO> labels = EntityUtils.jsonToList(labelJson, WlyySurveyLabelInfoDO.class);
            surveyLabelInfoDao.saveAll(labels);
        }
        //删除检查标签
        List<WlyySurveyInspLabelInfoDO> labelInspDels = surveyInspLabelInfoDao.findBySurveyTempCode(temp.getId());
        if(labelDels!=null&&labelDels.size()>0){
        if (labelDels != null && labelDels.size() > 0) {
            surveyInspLabelInfoDao.deleteAll(labelInspDels);
        }
        //保存检查标签
        if(StringUtils.isNotBlank(labelInspJson)){
        if (StringUtils.isNotBlank(labelInspJson)) {
            List<WlyySurveyInspLabelInfoDO> labels = EntityUtils.jsonToList(labelInspJson, WlyySurveyInspLabelInfoDO.class);
            surveyInspLabelInfoDao.saveAll(labels);
        }
@ -545,20 +554,21 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 删除
     *
     * @param tempId
     * @return
     */
    public Boolean delSurveyTemplate(String tempId){
    public Boolean delSurveyTemplate(String tempId) {
        WlyySurveyTemplateDO temp = surveyTemplateDao.getOne(tempId);
        if(temp!=null){
        if (temp != null) {
            //删除原有问题
            List<WlyySurveyTemplateQuestionDO> questionDODels = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(temp.getId(),"1");
            if(questionDODels!=null&&questionDODels.size()>0){
            List<WlyySurveyTemplateQuestionDO> questionDODels = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(temp.getId(), "1");
            if (questionDODels != null && questionDODels.size() > 0) {
                surveyTemplateQuestionDao.deleteAll(questionDODels);
            }
            //删除原有问题选项
            List<WlyySurveyTemplateOptionDO> optionDODels = surveyTemplateOptionDao.findByTemplateCodeAndDelOrderBySortAsc(temp.getId(),"1");
            if(optionDODels!=null&&optionDODels.size()>0){
            List<WlyySurveyTemplateOptionDO> optionDODels = surveyTemplateOptionDao.findByTemplateCodeAndDelOrderBySortAsc(temp.getId(), "1");
            if (optionDODels != null && optionDODels.size() > 0) {
                surveyTemplateOptionDao.deleteAll(optionDODels);
            }
            surveyTemplateDao.delete(temp);
@ -570,22 +580,23 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 保存问卷科室关系
     *
     * @param tempId
     * @param sdJsons
     * @return
     * @throws Exception
     */
    public Boolean saveSurveyDept(String tempId,String sdJsons)throws Exception{
    public Boolean saveSurveyDept(String tempId, String sdJsons) throws Exception {
        //删除之前关系
        List<WlyySurveyDeptDO> dels = surveyDeptDao.findBySurveyTempCode(tempId);
        if(dels!=null&&dels.size()>0){
        if (dels != null && dels.size() > 0) {
            surveyDeptDao.deleteAll(dels);
        }
        if(StringUtils.isNotBlank(sdJsons)){
            List<WlyySurveyDeptDO> list = EntityUtils.jsonToList(sdJsons,WlyySurveyDeptDO.class);
            if(list!=null&&list.size()>0){
        if (StringUtils.isNotBlank(sdJsons)) {
            List<WlyySurveyDeptDO> list = EntityUtils.jsonToList(sdJsons, WlyySurveyDeptDO.class);
            if (list != null && list.size() > 0) {
                surveyDeptDao.saveAll(list);
            }
        }
@ -594,22 +605,23 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 保存部门问卷关系
     *
     * @param dept
     * @param sdJsons
     * @return
     * @throws Exception
     */
    public Boolean saveDeptSurvey(String dept,String sdJsons)throws Exception{
    public Boolean saveDeptSurvey(String dept, String sdJsons) throws Exception {
        //删除之前关系
        List<WlyySurveyDeptDO> dels = surveyDeptDao.findByDept(dept);
        if(dels!=null&&dels.size()>0){
        if (dels != null && dels.size() > 0) {
            surveyDeptDao.deleteAll(dels);
        }
        if(StringUtils.isNotBlank(sdJsons)){
            List<WlyySurveyDeptDO> list = EntityUtils.jsonToList(sdJsons,WlyySurveyDeptDO.class);
            if(list!=null&&list.size()>0){
        if (StringUtils.isNotBlank(sdJsons)) {
            List<WlyySurveyDeptDO> list = EntityUtils.jsonToList(sdJsons, WlyySurveyDeptDO.class);
            if (list != null && list.size() > 0) {
                surveyDeptDao.saveAll(list);
            }
        }
@ -618,10 +630,11 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 查询科室下问卷列表
     *
     * @param dept
     * @return
     */
    public List<Map<String,Object>> findSurveyByDept(String dept){
    public List<Map<String, Object>> findSurveyByDept(String dept) {
        String sql = "SELECT " +
                " t.id as \"id\", " +
                " t.title as \"title\", " +
@ -630,22 +643,22 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                " wlyy_survey_template t " +
                " JOIN wlyy_survey_dept d ON t.id = d.survey_temp_code " +
                " WHERE " +
                " d.dept = '"+dept+"'";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
                " d.dept = '" + dept + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    public List<Map<String,Object>> findSurveyByDeptAndPatient(String dept,String patient) {
        List<Map<String,Object>> result = findSurveyByDept(dept);
        if(result!=null&&result.size()>0){
            for(Map<String,Object> map:result){
                String tempId = (String)map.get("id");
                List<WlyySurveyUserDO> list = surveyUserDao.findBySurvey(tempId,patient);
                if(list!=null&&list.size()>0){
                    map.put("isAnswer",true);
                }else{
                    map.put("isAnswer",false);
    public List<Map<String, Object>> findSurveyByDeptAndPatient(String dept, String patient) {
        List<Map<String, Object>> result = findSurveyByDept(dept);
        if (result != null && result.size() > 0) {
            for (Map<String, Object> map : result) {
                String tempId = (String) map.get("id");
                List<WlyySurveyUserDO> list = surveyUserDao.findBySurvey(tempId, patient);
                if (list != null && list.size() > 0) {
                    map.put("isAnswer", true);
                } else {
                    map.put("isAnswer", false);
                }
            }
        }
@ -653,12 +666,13 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    }
    /**
    * 查询问卷下科室
    * @param tempId
    * @return
    */
    public List<Map<String,Object>> findDeptBySurvey(String tempId){
        String sql ="SELECT " +
     * 查询问卷下科室
     *
     * @param tempId
     * @return
     */
    public List<Map<String, Object>> findDeptBySurvey(String tempId) {
        String sql = "SELECT " +
                " d.survey_temp_code AS \"surveyTempCode\"," +
                " d.dept AS \"dept\", " +
                " d.dept_name AS \"deptName\" " +
@ -666,36 +680,35 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                " wlyy_survey_template t " +
                " JOIN wlyy_survey_dept d ON t.id = d.survey_temp_code " +
                " WHERE " +
                " t.id = '"+tempId+"'";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
                " t.id = '" + tempId + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    /**
     *
     * @param suJson
     * @param suaJsons
     * @return
     * @throws Exception
     */
    public Boolean saveSurveyAnswer(String suJson,String suaJsons)throws Exception{
    public Boolean saveSurveyAnswer(String suJson, String suaJsons) throws Exception {
        WlyySurveyUserDO surveyUserDO = objectMapper.readValue(suJson,WlyySurveyUserDO.class);
        surveyUserDO.setFixDate(DateUtil.dateToStr(new Date(),"yyyy-MM-dd"));
        WlyySurveyUserDO surveyUserDO = objectMapper.readValue(suJson, WlyySurveyUserDO.class);
        surveyUserDO.setFixDate(DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        surveyUserDO.setId(UUID.randomUUID().toString());
        surveyUserDO = surveyUserDao.save(surveyUserDO);
        //删除问题答案
        List<WlyySurveyUserAnswerDO> dels = surveyUserAnswerDao.findBySurverUserId(surveyUserDO.getId());
        if(dels!=null&&dels.size()>0){
        if (dels != null && dels.size() > 0) {
            surveyUserAnswerDao.deleteAll(dels);
        }
        //保存答案
        if(StringUtils.isNotBlank(suaJsons)){
            List<WlyySurveyUserAnswerDO> answerDOs = EntityUtils.jsonToList(suaJsons,WlyySurveyUserAnswerDO.class);
            for(WlyySurveyUserAnswerDO answerDO : answerDOs){
        if (StringUtils.isNotBlank(suaJsons)) {
            List<WlyySurveyUserAnswerDO> answerDOs = EntityUtils.jsonToList(suaJsons, WlyySurveyUserAnswerDO.class);
            for (WlyySurveyUserAnswerDO answerDO : answerDOs) {
                answerDO.setSurverUserId(surveyUserDO.getId());
                answerDO.setCreateTime(new Date());
                /*WlyySurveyTemplateOptionDO surveyTemplateOptionDO = surveyTemplateOptionDao.getOne(answerDO.getTempOptionCode());
@ -703,26 +716,40 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                answerDO.setTempOptionCode(surveyTemplateOptionDO.getCode());*/
            }
            surveyUserAnswerDao.saveAll(answerDOs);
            BasePatientBusinessDO basePatientBusinessDO = basePatientBusinessDao.findByDoctorPatientRelationCode(surveyUserDO.getPatient(),surveyUserDO.getSurveyTempCode(),surveyUserDO.getDoctor());
            String sql = " select * from base_patient_business a " +
                    " where a.del=1 " +
                    " and a.patient='" + surveyUserDO.getPatient() + "' " +
                    " and a.relationCode='" + surveyUserDO.getSurveyTempCode() + "' " +
                    " and a.doctor = '" + surveyUserDO.getDoctor() + "' order by create_time desc";
            List<BasePatientBusinessDO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(BasePatientBusinessDO.class));
            BasePatientBusinessDO basePatientBusinessDO = null;
            if (!list.isEmpty()) {
                basePatientBusinessDO = list.get(0);
            }
//            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());
            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");
            this.sendImMsg(basePatientBusinessDO.getPatient(), basePatientBusinessDO.getPatientName(), basePatientBusinessDO.getSessionId(), "36", object.toJSONString(), "1");
        }
        return true;
    }
    public List<WlyySurveyUserAnswerDO> findAnswerBySurveyTempCode(String surverUserId,String patient,String tempId){
    public List<WlyySurveyUserAnswerDO> findAnswerBySurveyTempCode(String surverUserId, String patient, String tempId) {
        List<WlyySurveyUserAnswerDO> list = null;
        if(StringUtils.isNotBlank(surverUserId)){
        if (StringUtils.isNotBlank(surverUserId)) {
            list = surveyUserAnswerDao.findBySurverUserId(surverUserId);
        }else{
            List<WlyySurveyUserDO> surveys = surveyUserDao.findBySurvey(tempId,patient);
        } else {
            List<WlyySurveyUserDO> surveys = surveyUserDao.findBySurvey(tempId, patient);
            System.out.println(surveys);
            if(surveys!=null&&surveys.size()>0){
            if (surveys != null && surveys.size() > 0) {
                WlyySurveyUserDO wlyySurveyUserDO = surveys.get(0);
                System.out.println(wlyySurveyUserDO);
                list = surveyUserAnswerDao.findBySurverUserId(wlyySurveyUserDO.getId());
@ -733,56 +760,57 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 查询问题情况
     *
     * @param tempId
     * @return
     */
    public WlyySurveyTemplateVO findSurveyTemplateResult(String tempId) {
        WlyySurveyTemplateDO templateDO = surveyTemplateDao.getOne(tempId);
        WlyySurveyTemplateVO templateVO = convertToModel(templateDO,WlyySurveyTemplateVO.class);
        WlyySurveyTemplateVO templateVO = convertToModel(templateDO, WlyySurveyTemplateVO.class);
        templateVO.setLabels(findSurveyTemplateLabel(tempId));
        templateVO.setInsplabels(findSurveyInspTemplateLabel(tempId));
        BaseDoctorDO doctor = baseDoctorDao.findByIdAndDel(templateDO.getCreaterCode());
        if (null!=doctor){
        if (null != doctor) {
            templateVO.setVisitDept(doctor.getVisitDept());
            templateVO.setVisitDeptName(doctor.getVisitDeptName());
        }
        //查询所有答题过的用户,计算答题总数
        List<WlyySurveyUserDO> surveyUsers = surveyUserDao.findBySurveyTempCodeAndStatus(tempId,1);
        Integer total =0;
        if(surveyUsers!=null&&surveyUsers.size()>0){
        List<WlyySurveyUserDO> surveyUsers = surveyUserDao.findBySurveyTempCodeAndStatus(tempId, 1);
        Integer total = 0;
        if (surveyUsers != null && surveyUsers.size() > 0) {
            total = surveyUsers.size();
        }
        templateVO.setAnswerCount(total);
        List<WlyySurveyTemplateQuestionDO> tqDOs = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(tempId,"1");
        if(tqDOs!=null&&tqDOs.size()>0){
        List<WlyySurveyTemplateQuestionDO> tqDOs = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(tempId, "1");
        if (tqDOs != null && tqDOs.size() > 0) {
            //设置问题
            List<WlyySurveyTemplateQuestionVO> tqVOs = new ArrayList<>();
            convertToModels(tqDOs,tqVOs,WlyySurveyTemplateQuestionVO.class);
            convertToModels(tqDOs, tqVOs, WlyySurveyTemplateQuestionVO.class);
            //设置选项
            for(WlyySurveyTemplateQuestionVO tq:tqVOs){
                List<WlyySurveyTemplateOptionDO> optionDOs  = surveyTemplateOptionDao.findByQuestionCodeAndDelOrderBySortAsc(tq.getCode(),tq.getTemplateCode(),"1");
            for (WlyySurveyTemplateQuestionVO tq : tqVOs) {
                List<WlyySurveyTemplateOptionDO> optionDOs = surveyTemplateOptionDao.findByQuestionCodeAndDelOrderBySortAsc(tq.getCode(), tq.getTemplateCode(), "1");
                List<WlyySurveyTemplateOptionVO> optionVOs = new ArrayList<>();
                convertToModels(optionDOs,optionVOs,WlyySurveyTemplateOptionVO.class);
                convertToModels(optionDOs, optionVOs, WlyySurveyTemplateOptionVO.class);
                int tpCount = 0;
                List<WlyySurveyUserAnswerDO> answerQuestionDOs = surveyUserAnswerDao.findByTempQuestionCodeDistinctPatient(tq.getCode(),tempId);
                if(answerQuestionDOs!=null&&answerQuestionDOs.size()>0){
                List<WlyySurveyUserAnswerDO> answerQuestionDOs = surveyUserAnswerDao.findByTempQuestionCodeDistinctPatient(tq.getCode(), tempId);
                if (answerQuestionDOs != null && answerQuestionDOs.size() > 0) {
                    tpCount = answerQuestionDOs.size();
                }
                tq.setTqCount(tpCount);
                /**
                 * 统计每个选项选择的百分比
                 */
                if(optionVOs!=null&&optionVOs.size()>0){
                    for(WlyySurveyTemplateOptionVO vo:optionVOs){
                        Integer answerCount =0;
                        List<WlyySurveyUserAnswerDO> answerDOs = surveyUserAnswerDao.findBytempOptionCode(vo.getCode(),vo.getTemplateCode());
                        if(answerDOs!=null&&answerDOs.size()>0){
                if (optionVOs != null && optionVOs.size() > 0) {
                    for (WlyySurveyTemplateOptionVO vo : optionVOs) {
                        Integer answerCount = 0;
                        List<WlyySurveyUserAnswerDO> answerDOs = surveyUserAnswerDao.findBytempOptionCode(vo.getCode(), vo.getTemplateCode());
                        if (answerDOs != null && answerDOs.size() > 0) {
                            answerCount = answerDOs.size();
                        }
                        vo.setPercentage(PercentageUtil.bs(answerCount,total)+"%");
                        vo.setPercentage(PercentageUtil.bs(answerCount, total) + "%");
                        vo.setOptCount(answerCount);
                        vo.setId(vo.getCode());
                    }
@ -797,6 +825,7 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 综合查询问题答案
     *
     * @param comment
     * @param content
     * @param tempQuestionCode
@ -805,27 +834,27 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
     * @param size
     * @return
     */
    public MixEnvelop findQuestionInfoList(String comment, String tempId,String content, String tempQuestionCode,String tempOptionCode,Integer page,Integer size){
    public MixEnvelop findQuestionInfoList(String comment, String tempId, String content, String tempQuestionCode, String tempOptionCode, Integer page, Integer size) {
        String totalSql ="SELECT " +
        String totalSql = "SELECT " +
                " COUNT(1) AS \"total\"" +
                " FROM " +
                " wlyy_survey_user_answer t " +
                " WHERE 1=1";
        if(StringUtils.isNotBlank(comment)){
            totalSql += " AND t.comment like '%"+comment+"%' ";
        if (StringUtils.isNotBlank(comment)) {
            totalSql += " AND t.comment like '%" + comment + "%' ";
        }
        if(StringUtils.isNotBlank(content)){
            totalSql += " AND t.content  like '%"+content+"%'";
        if (StringUtils.isNotBlank(content)) {
            totalSql += " AND t.content  like '%" + content + "%'";
        }
        if(StringUtils.isNotBlank(tempQuestionCode)){
            totalSql += " AND t.temp_question_code ='"+tempQuestionCode+"'";
        if (StringUtils.isNotBlank(tempQuestionCode)) {
            totalSql += " AND t.temp_question_code ='" + tempQuestionCode + "'";
        }
        if(StringUtils.isNotBlank(tempOptionCode)){
            totalSql += " AND t.temp_option_code ='"+tempOptionCode+"'";
        if (StringUtils.isNotBlank(tempOptionCode)) {
            totalSql += " AND t.temp_option_code ='" + tempOptionCode + "'";
        }
        if(StringUtils.isNotBlank(tempId)){
            totalSql += " AND t.survey_temp_code ='"+tempId+"'";
        if (StringUtils.isNotBlank(tempId)) {
            totalSql += " AND t.survey_temp_code ='" + tempId + "'";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -850,36 +879,36 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                " FROM " +
                " wlyy_survey_user_answer t " +
                " WHERE 1=1";
        if(StringUtils.isNotBlank(comment)){
            sql += " AND t.user_comment like '%"+comment+"%' ";
        if (StringUtils.isNotBlank(comment)) {
            sql += " AND t.user_comment like '%" + comment + "%' ";
        }
        if(StringUtils.isNotBlank(content)){
            sql += " AND t.user_content  like '%"+content+"%'";
        if (StringUtils.isNotBlank(content)) {
            sql += " AND t.user_content  like '%" + content + "%'";
        }
        if(StringUtils.isNotBlank(tempQuestionCode)){
            sql += " AND t.temp_question_code ='"+tempQuestionCode+"'";
        if (StringUtils.isNotBlank(tempQuestionCode)) {
            sql += " AND t.temp_question_code ='" + tempQuestionCode + "'";
        }
        if(StringUtils.isNotBlank(tempOptionCode)){
            sql += " AND t.temp_option_code ='"+tempOptionCode+"'";
        if (StringUtils.isNotBlank(tempOptionCode)) {
            sql += " AND t.temp_option_code ='" + tempOptionCode + "'";
        }
        if(StringUtils.isNotBlank(tempId)){
            sql += " AND t.survey_temp_code ='"+tempId+"'";
        if (StringUtils.isNotBlank(tempId)) {
            sql += " AND t.survey_temp_code ='" + tempId + "'";
        }
        sql += " ORDER BY t.create_time DESC  ";
        if ("xm_ykyy_wx".equals(wxId)) {
            if (!flag){
                sql ="SELECT * FROM\n" +
            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);
                        "    (" + 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 + " ";
            }
        } else {
            sql+="LIMIT "+ (page - 1) * size + "," + size + " ";
            sql += "LIMIT " + (page - 1) * size + "," + size + " ";
        }
        List<WlyySurveyUserAnswerDO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyySurveyUserAnswerDO.class));
@ -889,35 +918,36 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 查询
     *
     * @param
     * @param
     * @param
     * @return
     */
    public MixEnvelop findAnswerList(String tempId,String patient,String patientName,String title,Integer page,Integer size,String startTime,String endTime){
    public MixEnvelop findAnswerList(String tempId, String patient, String patientName, String title, Integer page, Integer size, String startTime, String endTime) {
        String totalSql ="SELECT " +
        String totalSql = "SELECT " +
                " COUNT(1) AS \"total\"" +
                " FROM " +
                " wlyy_survey_user t " +
                " WHERE 1=1 and t.status = 1 ";
        if(StringUtils.isNotBlank(title)){
            totalSql += " AND t.survey_temp_title like '%"+title+"%' ";
        if (StringUtils.isNotBlank(title)) {
            totalSql += " AND t.survey_temp_title like '%" + title + "%' ";
        }
        if(StringUtils.isNotBlank(patient)){
            totalSql += " AND t.patient = '"+patient+"' ";
        if (StringUtils.isNotBlank(patient)) {
            totalSql += " AND t.patient = '" + patient + "' ";
        }
        if(StringUtils.isNotBlank(tempId)){
            totalSql += " AND t.survey_temp_code = '"+tempId+"' ";
        if (StringUtils.isNotBlank(tempId)) {
            totalSql += " AND t.survey_temp_code = '" + tempId + "' ";
        }
        if(StringUtils.isNotBlank(patientName)){
            totalSql += " AND t.patient_name like  '%"+patientName+"%' ";
        if (StringUtils.isNotBlank(patientName)) {
            totalSql += " AND t.patient_name like  '%" + patientName + "%' ";
        }
        if(StringUtils.isNotBlank(startTime)){
            totalSql += " AND t.create_time >=  '"+startTime+" 00:00:00' ";
        if (StringUtils.isNotBlank(startTime)) {
            totalSql += " AND t.create_time >=  '" + startTime + " 00:00:00' ";
        }
        if(StringUtils.isNotBlank(endTime)){
            totalSql += " AND t.create_time <=  '"+endTime+" 23:59:59' ";
        if (StringUtils.isNotBlank(endTime)) {
            totalSql += " AND t.create_time <=  '" + endTime + " 23:59:59' ";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -945,47 +975,47 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                " wlyy_survey_user t " +
                " JOIN base_patient p ON t.patient = p.id " +
                " WHERE 1=1 and t.status = 1 ";
        if(StringUtils.isNotBlank(title)){
            sql += " AND t.survey_temp_title like '%"+title+"%' ";
        if (StringUtils.isNotBlank(title)) {
            sql += " AND t.survey_temp_title like '%" + title + "%' ";
        }
        if(StringUtils.isNotBlank(patient)){
            sql += " AND t.patient = '"+patient+"' ";
        if (StringUtils.isNotBlank(patient)) {
            sql += " AND t.patient = '" + patient + "' ";
        }
        if(StringUtils.isNotBlank(patientName)){
            sql += " AND t.patient_name like  '%"+patientName+"%' ";
        if (StringUtils.isNotBlank(patientName)) {
            sql += " AND t.patient_name like  '%" + patientName + "%' ";
        }
        if(StringUtils.isNotBlank(tempId)){
            sql += " AND t.survey_temp_code = '"+tempId+"' ";
        if (StringUtils.isNotBlank(tempId)) {
            sql += " AND t.survey_temp_code = '" + tempId + "' ";
        }
        if(StringUtils.isNotBlank(startTime)){
            sql += " AND t.create_time >=  '"+startTime+" 00:00:00' ";
        if (StringUtils.isNotBlank(startTime)) {
            sql += " AND t.create_time >=  '" + startTime + " 00:00:00' ";
        }
        if(StringUtils.isNotBlank(endTime)){
            sql += " AND t.create_time <=  '"+endTime+" 23:59:59' ";
        if (StringUtils.isNotBlank(endTime)) {
            sql += " AND t.create_time <=  '" + endTime + " 23:59:59' ";
        }
        sql += " ORDER BY t.create_time DESC " ;
        sql += " ORDER BY t.create_time DESC ";
        if ("xm_ykyy_wx".equals(wxId)) {
            if (!flag){
                sql ="SELECT * FROM\n" +
            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);
                        "    (" + 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 + " ";
            }
        } else {
            sql+="LIMIT "+ (page - 1) * size + "," + size + " ";
            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){
            for(WlyySurveyUserVO vo :list){
        if (list != null && list.size() > 0) {
            for (WlyySurveyUserVO vo : list) {
                vo.setAge(IdCardUtil.getAgeForIdcard(vo.getIdcard()));
            }
        }
@ -995,7 +1025,7 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    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);
        System.out.println("im地址" + imAddr);
        JSONObject params = new JSONObject();
        params.put("sender_id", from);
        params.put("sender_name", fromName);

+ 88 - 88
business/im-service/src/main/java/com/yihu/jw/im/service/ImService.java

@ -180,15 +180,15 @@ public class ImService {
    public static String im_host;
//    @Value("${im-service.im_service_url}")
    //    @Value("${im-service.im_service_url}")
    @Value("${im.im_list_get}")
    public void setIm_host(String im_host) {
        ImService.im_host = im_host;
    }
    public String getSender(){
    public String getSender() {
        WlyyHospitalSysDictDO dictDO = hospitalSysDictDao.findById("customer").orElse(null);
        if(dictDO==null){
        if (dictDO == null) {
            dictDO = new WlyyHospitalSysDictDO();
            dictDO.setDictCode("customer");
            dictDO.setDictValue("客服");
@ -197,9 +197,9 @@ public class ImService {
    }
    //是否加入客服
    public boolean isAddCustomer(String type){
        List<WlyyHospitalSysDictDO> dos = hospitalSysDictDao.findByDictNameAndDictCode("customer_type",type);
        if(dos.size()>0){
    public boolean isAddCustomer(String type) {
        List<WlyyHospitalSysDictDO> dos = hospitalSysDictDao.findByDictNameAndDictCode("customer_type", type);
        if (dos.size() > 0) {
            return true;
        }
        return false;
@ -292,9 +292,9 @@ public class ImService {
        sql += " ORDER BY a.czrq desc ";
        logger.info("sql=" + sql);
        List<Map<String, Object>> result = hibenateUtils.createSQLQuery(sql, page, pagesize);
        for (Map<String, Object> map:result){
            map.put("patientAge",IdCardUtil.getAgeForIdcard(map.get("patientIdcard")+""));
            map.put("doctorAge",IdCardUtil.getAgeForIdcard(map.get("doctorIdcard")+""));
        for (Map<String, Object> map : result) {
            map.put("patientAge", IdCardUtil.getAgeForIdcard(map.get("patientIdcard") + ""));
            map.put("doctorAge", IdCardUtil.getAgeForIdcard(map.get("doctorIdcard") + ""));
        }
        /*result = jdbcTemplate.query(sql, new BeanPropertyRowMapper(ConsultVO.class));*/
        return result;
@ -366,17 +366,17 @@ public class ImService {
        return consultCode;
    }
    public List<ConsultTeamDo> getUnfinishedConsult3(String patient, String doctor,int type) {
        return consultTeamDao.findUnfinishedConsultType(patient,doctor,type);
    public List<ConsultTeamDo> getUnfinishedConsult3(String patient, String doctor, int type) {
        return consultTeamDao.findUnfinishedConsultType(patient, doctor, type);
    }
    public String getUnfinishedConsult(String patient, String doctor,int type) {
    public String getUnfinishedConsult(String patient, String doctor, int type) {
        String totalSql = "SELECT a.consult as \"consultCode\" " +
                "FROM wlyy_consult_team a " +
                "WHERE a.patient= '" + patient + "' " +
                "AND a.doctor='" + doctor + "' " +
                "AND a.del='1' " +
                "AND a.type=" +type+
                "AND a.type=" + type +
                " AND a.status=0";
        List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(totalSql);
        String consultCode = null;
@ -693,7 +693,7 @@ public class ImService {
            }
        }
        robotService.reply(consultModel.getType()+"",content,consult,type);
        robotService.reply(consultModel.getType() + "", content, consult, type);
        return failed;
    }
@ -903,11 +903,11 @@ public class ImService {
            } else {
                throw new Exception("获取ACCESSTOKEN失败");
            }
        }else if("xm_xzzx_wx".equals(wxId)){
        } else if ("xm_xzzx_wx".equals(wxId)) {
            accessToken = xzzxEntranceService.getXzToken();
        }else if ("xm_hcyy_wx".equals(wechat_appid)) { //海沧医院
                accessToken = hcyyEntranceService.getHcToken();
        }else if("xm_dsyy_wx".equals(wechat_appid)){//第三医院
        } else if ("xm_hcyy_wx".equals(wechat_appid)) { //海沧医院
            accessToken = hcyyEntranceService.getHcToken();
        } else if ("xm_dsyy_wx".equals(wechat_appid)) {//第三医院
            accessToken = wxAccessTokenService.getWxAppletsAccessTokenById(wechat_appid).getAccessToken();
        } else {
            accessToken = wxAccessTokenService.getWxAccessTokenById(wechat_appid).getAccessToken();
@ -1005,7 +1005,7 @@ public class ImService {
     * @return
     * @throws Exception
     */
    public JSONObject addTeamConsult(ConsultTeamDo ct, String patient, String doctor, String source,String relationCode) throws Exception {
    public JSONObject addTeamConsult(ConsultTeamDo ct, String patient, String doctor, String source, String relationCode) throws Exception {
        JSONObject re = new JSONObject();
        boolean boo = StringUtils.isEmpty(getUnfinishedConsult(patient, doctor));
        logger.info("boo" + boo);
@ -1017,22 +1017,22 @@ public class ImService {
            }
        }
        if (!flag) {
            if(ct.getType()==28){
                if (!StringUtils.isEmpty(getUnfinishedConsult(patient, doctor,ct.getType()))) {
            if (ct.getType() == 28) {
                if (!StringUtils.isEmpty(getUnfinishedConsult(patient, doctor, ct.getType()))) {
                    throw new RuntimeException("居民还有未结束的康复咨询!");
                }
            }else {
            } else {
                if (!StringUtils.isEmpty(getUnfinishedConsult(patient, doctor))) {//判断是否有未结束的咨询移到同步方法中
                    throw new RuntimeException("居民还有未结束的专家咨询!");
                }
            }
        }
        String title = "专家咨询";
        if(ct.getType()==28){
        if (ct.getType() == 28) {
            title = "康复咨询";
            ServiceItemPlanDO serviceItemPlanDO = serviceItemPlanDao.findById(relationCode).orElse(null);
            if(serviceItemPlanDO!=null){
                if(!StringUtils.isEmpty(serviceItemPlanDO.getRelationCode())){
            if (serviceItemPlanDO != null) {
                if (!StringUtils.isEmpty(serviceItemPlanDO.getRelationCode())) {
                    throw new RuntimeException("该计划已发起过咨询,请选择其他计划发起!");
                }
                serviceItemPlanDO.setRelationCode(ct.getConsult());
@ -1077,7 +1077,7 @@ public class ImService {
        ct.setDoctorName(baseDoctorDO.getName());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("title", tempPatient.getName() + "申请"+title);
        jsonObject.put("title", tempPatient.getName() + "申请" + title);
        jsonObject.put("content", ct.getSymptoms());
        jsonObject.put("age", DateUtil.getAgeForIdcard(tempPatient.getIdcard()));
        jsonObject.put("sex", tempPatient.getSex());
@ -1304,7 +1304,7 @@ public class ImService {
                        consultTitle = "家医咨询";
                    }
                }else if("4".equals(wlyyOutpatientDO.getOutpatientType())){
                } else if ("4".equals(wlyyOutpatientDO.getOutpatientType())) {
                    //康复咨询
                    users.put(patient, 0);
                    ct.setType(28);
@ -1381,7 +1381,7 @@ public class ImService {
                    } else {
                        obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_GENERAL_EXPERT);
                    }
                }else if("4".equals(wlyyOutpatientDO.getOutpatientType())){
                } else if ("4".equals(wlyyOutpatientDO.getOutpatientType())) {
                    messages = imUtil.getCreateTopicMessage(patient, p.getName(), consult.getTitle(), content, consult.getImages(), doctorCode);
                    //5、(im创建咨询) 续方咨询的sessionid为居民code+就诊code+28(图文,视频,图文+视频)
                    sessionId = patient + "_" + outpatientCode + "_" + ct.getType();
@ -1507,7 +1507,7 @@ public class ImService {
        JSONObject jsonObject = new JSONObject();
        if ("3".equals(wlyyOutpatientDO.getOutpatientType())) {
            jsonObject.put("title", p.getName() + "申请咨询");
        } else if("4".equals(wlyyOutpatientDO.getOutpatientType())){
        } else if ("4".equals(wlyyOutpatientDO.getOutpatientType())) {
            jsonObject.put("title", p.getName() + "申请康复咨询");
        } else {
            jsonObject.put("title", p.getName() + "申请复诊");
@ -1553,7 +1553,7 @@ public class ImService {
                consultTitle = "家医咨询";
            }
        }else if("4".equals(wlyyOutpatientDO.getOutpatientType())){
        } else if ("4".equals(wlyyOutpatientDO.getOutpatientType())) {
            users.put(patient, 0);
            ct.setType(28);
            consultTitle = "申请康复咨询";
@ -1629,7 +1629,7 @@ public class ImService {
            } else {
                obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_GENERAL_EXPERT);
            }
        }else if("4".equals(wlyyOutpatientDO.getOutpatientType())){
        } else if ("4".equals(wlyyOutpatientDO.getOutpatientType())) {
            messages = imUtil.getCreateTopicMessage(patient, p.getName(), consult.getTitle(), content, consult.getImages(), doctorCode);
            //5、(im创建咨询) 续方咨询的sessionid为居民code+就诊code+28(图文,视频,图文+视频)
            sessionId = patient + "_" + outpatientCode + "_" + ct.getType();
@ -1681,7 +1681,7 @@ public class ImService {
        addLogs(ct);
        JSONObject result = imUtil.getSingleSessionInfo(sessionId, doctorCode);
        //发送外层SOCKET消息 在线复诊
        if ("1".equals(wlyyOutpatientDO.getOutpatientType()) || "3".equals(wlyyOutpatientDO.getOutpatientType())|| "4".equals(wlyyOutpatientDO.getOutpatientType())) {
        if ("1".equals(wlyyOutpatientDO.getOutpatientType()) || "3".equals(wlyyOutpatientDO.getOutpatientType()) || "4".equals(wlyyOutpatientDO.getOutpatientType())) {
            System.out.println("发送外层SOCKET消息:在线复诊");
            JSONObject object = new JSONObject();
            object.put("socket_sms_type", 5);
@ -1720,7 +1720,7 @@ public class ImService {
            msgStr = msgStr + "  已开始复诊";
        } else if ("2".equals(wlyyOutpatientDO.getOutpatientType())) {
            msgStr = msgStr + "  已开始协同门诊";
        } else if("4".equals(wlyyOutpatientDO.getOutpatientType())){
        } else if ("4".equals(wlyyOutpatientDO.getOutpatientType())) {
            msgStr = msgStr + "  已开始康复咨询";
        } else {
            msgStr = msgStr + "  已开始专家咨询";
@ -1820,13 +1820,13 @@ public class ImService {
                outpatientDao.save(wlyyOutpatientDO);
                //结束康复执行计划
                if(org.apache.commons.lang3.StringUtils.isNotBlank(wlyyOutpatientDO.getPlanId())){
                if (org.apache.commons.lang3.StringUtils.isNotBlank(wlyyOutpatientDO.getPlanId())) {
                    ServiceItemPlanDO serviceItemPlanDO = serviceItemPlanDao.findById(wlyyOutpatientDO.getPlanId()).orElse(null);
                    if(serviceItemPlanDO!=null){
                    if (serviceItemPlanDO != null) {
                        serviceItemPlanDO.setStatus("1");
                        serviceItemPlanDO.setCompleteTime(DateUtil.getStringDate());
                        serviceItemPlanDao.save(serviceItemPlanDO);
                        updPlanStatus(serviceItemPlanDO.getPlanId(),serviceItemPlanDO.getPlanDetailId());
                        updPlanStatus(serviceItemPlanDO.getPlanId(), serviceItemPlanDO.getPlanDetailId());
                    }
                }
            }
@ -2027,8 +2027,8 @@ public class ImService {
        net.sf.json.JSONObject data = new net.sf.json.JSONObject();
        data.put("name", patient.getName());
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(consultTeam.getRelationCode()).orElse(null);
        if (wlyyOutpatientDO!=null){
            data.put("consumerName",wlyyOutpatientDO.getConsumerName());
        if (wlyyOutpatientDO != null) {
            data.put("consumerName", wlyyOutpatientDO.getConsumerName());
        }
        data.put("age", IdCardUtil.getAgeForIdcard(patient.getIdcard()));
        data.put("gender", StringUtils.isEmpty(patient.getSex()) ? null : patient.getSex().toString());
@ -2106,14 +2106,14 @@ public class ImService {
     */
    public JSONObject getConsultInfoAndPatientInfo(String consult, String patientCode) {
        JSONObject result = new JSONObject();
        if(!StringUtils.isEmpty(consult)){
        if (!StringUtils.isEmpty(consult)) {
            ConsultDo consultDo = consultDao.findById(consult).orElse(null);
            if (StringUtils.isEmpty(patientCode)) {
                patientCode = consultDo.getPatient();
            }
            result.put("consultDo", consultDo);
        }else {
        } else {
            result.put("consultDo", null);
        }
        BasePatientDO basePatientDO = null;
@ -3207,32 +3207,32 @@ public class ImService {
    }
    //发送在线候诊室消息
    public void sendConstomerImg(String patientCode,String outpatientId,String outpatientType,String doctorCode){
    public void sendConstomerImg(String patientCode, String outpatientId, String outpatientType, String doctorCode) {
        try {
            //808080eb8223c9e50182249cd6ff0000_guidance_26
            String session_id26 = patientCode +"_guidance_26";
            String session_id27 = patientCode +"_guidance_27";
            String session_id26 = patientCode + "_guidance_26";
            String session_id27 = patientCode + "_guidance_27";
            BaseDoctorDO doctorDO = baseDoctorDao.findByIdAndDel(doctorCode);
            String msg = "您好,"+doctorDO.getName()+"医生已接诊,请您及时进入诊室与您的医生沟通。医生将会与您详细讨论病情,并为您提供专业的治疗建议。我们将竭诚为您服务,为您的健康保驾护航。";
            String msg = "您好," + doctorDO.getName() + "医生已接诊,请您及时进入诊室与您的医生沟通。医生将会与您详细讨论病情,并为您提供专业的治疗建议。我们将竭诚为您服务,为您的健康保驾护航。";
            JSONObject json = new JSONObject();
            json.put("outpatientId",outpatientId);
            json.put("outpatientType",outpatientType);
            json.put("msg",msg);
            json.put("outpatientId", outpatientId);
            json.put("outpatientType", outpatientType);
            json.put("msg", msg);
            WlyyHospitalSysDictDO dictDO = hospitalSysDictDao.findById("customer").orElse(null);
            String sender_id = "customer";
            String sender_name = "客服";
            if(dictDO!=null){
            if (dictDO != null) {
                sender_id = dictDO.getDictCode();
                sender_name = dictDO.getDictValue();
            }
            if(imUtil.sessionIsExist(session_id26)){
            if (imUtil.sessionIsExist(session_id26)) {
                imUtil.sendImMsg(sender_id, sender_name, session_id26, "51", json.toJSONString(), "1", null);
            }
            if(imUtil.sessionIsExist(session_id27)){
            if (imUtil.sessionIsExist(session_id27)) {
                imUtil.sendImMsg(sender_id, sender_name, session_id27, "51", json.toJSONString(), "1", null);
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
@ -3271,11 +3271,12 @@ public class ImService {
                int age = DateUtil.getAgeForIdcard(basePatientDO.getIdcard());
                patientAge = "" + age;
            }
            if(isAddCustomer(type)){
            if (isAddCustomer(type)) {
                //加入客服
                participants.put(getSender(), 0);
            }
            JSONObject sessionJson = imUtil.createSession(participants, sessionType, basePatientDO.getName() + " " + patientSex + " " + patientAge, session_id);
            System.out.println("sessionJson==>" + JSON.toJSONString(sessionJson));
            if (sessionJson.getInteger("status") == -1) {
                throw new RuntimeException(sessionJson.getString("message"));
            } else {
@ -3303,7 +3304,7 @@ public class ImService {
     * @return
     */
    public String patientGuaidenceAppend(String sender_id, String sender_name, String session_id, String content_type, String content, String business_type, String extend) throws Exception {
        logger.info("导诊推送im="+content);
        logger.info("导诊推送im=" + content);
        return imUtil.sendImMsg(sender_id, sender_name, session_id, content_type, content, "1", extend);
    }
@ -4141,13 +4142,13 @@ public class ImService {
        boolean flag = false;
        //发送导诊结束消息
        String systemType = "1";
        if (sessionId.endsWith("_26")){
        if (sessionId.endsWith("_26")) {
            systemType = "2";
        }else if (sessionId.endsWith("_27")){
        } else if (sessionId.endsWith("_27")) {
            systemType = "3";
        }
        BaseSystemDialogSetting endSetting =  dialogSettingDao.findBySystemTypeAndFunctionType(systemType,"5",1);
        if(endSetting!=null){
        BaseSystemDialogSetting endSetting = dialogSettingDao.findBySystemTypeAndFunctionType(systemType, "5", 1);
        if (endSetting != null) {
            String content = endSetting.getContent();
            BaseDoctorDO doctorDO = baseDoctorDao.findByIdAndDel(participants);
            imUtil.sendImMsg(participants, doctorDO.getName(), sessionId, "1", content, "1", null);
@ -4258,9 +4259,9 @@ public class ImService {
        }
        if (org.apache.commons.lang.StringUtils.isNotBlank(doctor)) {
            if("28".equals(type)){
                sql += " AND (op.doctor='" + doctor + "' or op.plan_doctor='"+doctor+"')";
            }else {
            if ("28".equals(type)) {
                sql += " AND (op.doctor='" + doctor + "' or op.plan_doctor='" + doctor + "')";
            } else {
                sql += " AND op.doctor='" + doctor + "' ";
            }
@ -4317,9 +4318,9 @@ public class ImService {
                sql += " AND op.outpatient_type = 2";
            } else if (type.equalsIgnoreCase("28")) {
                sql += " AND op.outpatient_type = 4";
            } else if(type.equalsIgnoreCase("29")){
            } else if (type.equalsIgnoreCase("29")) {
                sql += " AND op.outpatient_type = 1 and  oh.id is not null ";
            }else {
            } else {
                sql += " AND op.type in (1,2,3) ";
            }
        }
@ -4502,32 +4503,32 @@ public class ImService {
    }
    public MixEnvelop recordByDoctor(String doctor, String id,String type, Integer status,String title, String start_time, String end_time, String patient) { //
    public MixEnvelop recordByDoctor(String doctor, String id, String type, Integer status, String title, String start_time, String end_time, String patient) { //
        String sql = "";
        sql ="SELECT\n" +
                        "\ta.patient_name AS \"pname\",\n" +
                        "\ta.doctor_name AS \"dname\",\n" +
                        "\ta.dept_name AS \"dept\",\n" +
                        "\ta.outpatient_type AS \"type\",\n" +
                        "\ta.create_time AS \"ctime\",\n" +
                        "\ta.register_date AS \"rtime\",\n" +
                        "\ta.end_time AS \"etime\",\n" +
                        "\ta.description AS \"des\",\n" +
                        "\tb. STATUS AS \"pay\",\n" +
                        "\ta. STATUS AS \"STATUS\"\n" +
                        "FROM\n" +
                        "\twlyy_outpatient a\n" +
                        "LEFT JOIN wlyy_prescription b ON a.id = b.outpatient_id\n" +
                        "LEFT JOIN wlyy_consult c ON c.relation_code = a.id\n" +
                        "LEFT JOIN wlyy_consult_team d ON c.id = d.consult\n" +
                        "LEFT JOIN base_patient e ON a.patient = e.id\n" +
                        "WHERE\n" +
                        "\t1 = 1 ";
        if (status == null){
        }else if (status == 1) {
        sql = "SELECT\n" +
                "\ta.patient_name AS \"pname\",\n" +
                "\ta.doctor_name AS \"dname\",\n" +
                "\ta.dept_name AS \"dept\",\n" +
                "\ta.outpatient_type AS \"type\",\n" +
                "\ta.create_time AS \"ctime\",\n" +
                "\ta.register_date AS \"rtime\",\n" +
                "\ta.end_time AS \"etime\",\n" +
                "\ta.description AS \"des\",\n" +
                "\tb. STATUS AS \"pay\",\n" +
                "\ta. STATUS AS \"STATUS\"\n" +
                "FROM\n" +
                "\twlyy_outpatient a\n" +
                "LEFT JOIN wlyy_prescription b ON a.id = b.outpatient_id\n" +
                "LEFT JOIN wlyy_consult c ON c.relation_code = a.id\n" +
                "LEFT JOIN wlyy_consult_team d ON c.id = d.consult\n" +
                "LEFT JOIN base_patient e ON a.patient = e.id\n" +
                "WHERE\n" +
                "\t1 = 1 ";
        if (status == null) {
        } else if (status == 1) {
            sql += " and a.status = 0 and a.pay_status =1 ";
        } else if (status == 0) {
@ -4992,5 +4993,4 @@ public class ImService {
    }
}

+ 189 - 184
business/im-service/src/main/java/com/yihu/jw/im/service/RobotService.java

@ -40,7 +40,7 @@ public class RobotService {
    @Autowired
    private BaseKnowledgeQuestionDao knowledgeQuestionDao;
    @Autowired
    private  BaseKnowledgeFlowConfigurationRelationDao knowledgeFlowConfigurationRelationDao;
    private BaseKnowledgeFlowConfigurationRelationDao knowledgeFlowConfigurationRelationDao;
    @Autowired
    private BaseKnowledgeQuestionsDao knowledgeQuestionsDao;
    @Autowired
@ -57,34 +57,35 @@ public class RobotService {
    /**
     * 发送卡片
     *
     * @param session_id
     * @param type 会话类型
     * @param cardType 1 常见问题 2科室医生 3 症状描述
     * @param type       会话类型
     * @param cardType   1 常见问题 2科室医生 3 症状描述
     */
    public void sendCard(String session_id,String type,String cardType){
        if("1".equals(cardType)){
    public void sendCard(String session_id, String type, String cardType) {
        if ("1".equals(cardType)) {
            //1常见问题
            List<BaseKnowledgeQuestion> questionList = knowledgeQuestionDao.findTopList(DateUtil.getStringDate(),5);
            List<BaseKnowledgeQuestion> questionList = knowledgeQuestionDao.findTopList(DateUtil.getStringDate(), 5);
            JSONArray jsonArray = new JSONArray();
            for (BaseKnowledgeQuestion question:questionList){
            for (BaseKnowledgeQuestion question : questionList) {
                JSONObject json = new JSONObject();
                json.put("id",question.getId());
                json.put("questionName",question.getQuestionName());
                json.put("id", question.getId());
                json.put("questionName", question.getQuestionName());
                jsonArray.add(jsonArray);
            }
            JSONObject result = new JSONObject();
            result.put("content",jsonArray);
            result.put("content_type",ImUtil.ContentType.KnowCommonQuestion);
            result.put("session_id",session_id);
            result.put("content", jsonArray);
            result.put("content_type", ImUtil.ContentType.KnowCommonQuestion);
            result.put("session_id", session_id);
            sendReply(result);
            return;
        }
    }
    //获取发送者
    public WlyyHospitalSysDictDO getSender(){
    public WlyyHospitalSysDictDO getSender() {
        WlyyHospitalSysDictDO dictDO = hospitalSysDictDao.findById("customer").orElse(null);
        if(dictDO==null){
        if (dictDO == null) {
            dictDO = new WlyyHospitalSysDictDO();
            dictDO.setDictCode("customer");
            dictDO.setDictValue("客服");
@ -93,399 +94,403 @@ public class RobotService {
    }
    //发送回复消息
    public void sendReply(JSONObject json){
    public void sendReply(JSONObject json) {
        try {
            WlyyHospitalSysDictDO dictDO = getSender();
            imService.patientGuaidenceAppend(dictDO.getDictCode(),dictDO.getDictValue(),json.getString("session_id"),
                    json.getString("content_type"),json.getString("content"),"1",null);
        }catch (Exception e){
            imService.patientGuaidenceAppend(dictDO.getDictCode(), dictDO.getDictValue(), json.getString("session_id"),
                    json.getString("content_type"), json.getString("content"), "1", null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        json = null;
    }
    public void sendReplyMap(Map<String,JSONObject> map){
    public void sendReplyMap(Map<String, JSONObject> map) {
        try {
            WlyyHospitalSysDictDO dictDO = getSender();
            for (JSONObject json:map.values()){
                imService.patientGuaidenceAppend(dictDO.getDictCode(),dictDO.getDictValue(),json.getString("session_id"),
                        json.getString("content_type"),json.getString("content"),"1",null);
            for (JSONObject json : map.values()) {
                String s = imService.patientGuaidenceAppend(dictDO.getDictCode(), dictDO.getDictValue(), json.getString("session_id"),
                        json.getString("content_type"), json.getString("content"), "1", null);
                System.out.println("结果==>" + s);
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
        map = null;
    }
    //智能导诊助手回复
    public Map<String,JSONObject> robotReply(String session_id,String type,String content){
        Map<String,JSONObject> map = new HashMap<>();
    public Map<String, JSONObject> robotReply(String session_id, String type, String content) {
        Map<String, JSONObject> map = new HashMap<>();
        try {
            List<BaseSystemDialogSetting> settingList = dialogSettingDao.selectBySystemTypeAndFlag(sessionTypeToType(type),1);
            if(settingList.size()==0){
            List<BaseSystemDialogSetting> settingList = dialogSettingDao.selectBySystemTypeAndFlag(sessionTypeToType(type), 1);
            if (settingList.size() == 0) {
                //未配置自动回复内容
                return map;
            }
            Map<String,BaseSystemDialogSetting> mapSetting = settingList.stream().collect(Collectors.toMap(BaseSystemDialogSetting::getFunctionType, v -> v,(o1,o2)->o1));
            Map<String, BaseSystemDialogSetting> mapSetting = settingList.stream().collect(Collectors.toMap(BaseSystemDialogSetting::getFunctionType, v -> v, (o1, o2) -> o1));
            //欢迎语
            welcome(session_id,mapSetting,map);
            welcome(session_id, mapSetting, map);
            //自动匹配回复文字内容
//            replyContent(session_id,type,content,mapSetting,map);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }
    public void reply(String sessionType,String content,String consult,Integer contentType){
        if(contentType==1||contentType==3001){
    public void reply(String sessionType, String content, String consult, Integer contentType) {
        if (contentType == 1 || contentType == 3001) {
            //常见问题
            replyContent(sessionType,content,consult,contentType);
            replyContent(sessionType, content, consult, contentType);
            return;
        }
        if(contentType==3006){
        if (contentType == 3006) {
            //回复疾病
            replyDisease(sessionType,content,null,consult,contentType+"");
            replyDisease(sessionType, content, null, consult, contentType + "");
            return;
        }
    }
    //回复疾病
    public void replyDisease(String sessionType,String content,String sessionId,String consult,String contentType){
    public void replyDisease(String sessionType, String content, String sessionId, String consult, String contentType) {
        try {
            JSONObject jsonObject = JSON.parseObject(content);
            String id = jsonObject.getString("id");
            JSONArray jsonArray = baseKnowledgeDictService.findDeptById(id);
            WlyyHospitalSysDictDO dictDO = getSender();
            if(StringUtils.isNotEmpty(consult)){
                imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, ImUtil.ContentType.KnowSymptomsDiseaseA.getValue(), jsonArray.toJSONString(),null);
            }else {
                imService.patientGuaidenceAppend(dictDO.getDictCode(),dictDO.getDictValue(),sessionId,
                        ImUtil.ContentType.KnowSymptomsDiseaseA.getValue(),jsonArray.toJSONString(),"1",null);
            if (StringUtils.isNotEmpty(consult)) {
                imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, ImUtil.ContentType.KnowSymptomsDiseaseA.getValue(), jsonArray.toJSONString(), null);
            } else {
                imService.patientGuaidenceAppend(dictDO.getDictCode(), dictDO.getDictValue(), sessionId,
                        ImUtil.ContentType.KnowSymptomsDiseaseA.getValue(), jsonArray.toJSONString(), "1", null);
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     *
     * @param sessionType 会话类型
     * @param content 消息内容
     * @param consult 咨询code
     * @param content     消息内容
     * @param consult     咨询code
     * @param contentType 消息类型 文本1 问题集3002
     */
    //普通咨询常见问题匹配
    public void replyContent(String sessionType,String content,String consult,Integer contentType){
    public void replyContent(String sessionType, String content, String consult, Integer contentType) {
        try {
            WlyyHospitalSysDictDO dictDO = getSender();
            if (contentType==3003){
                String contentTypes = ImUtil.ContentType.KnowCommonDict+"";
                String contentMsg = selectByContentType(contentTypes,content).toJSONString();
                imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, contentTypes, contentMsg,null);
            if (contentType == 3003) {
                String contentTypes = ImUtil.ContentType.KnowCommonDict + "";
                String contentMsg = selectByContentType(contentTypes, content).toJSONString();
                imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, contentTypes, contentMsg, null);
            }
            BaseSystemDialogSetting setting = dialogSettingDao.findBySystemTypeAndFunctionType(sessionTypeToType(sessionType),"7",1);
            if(setting==null){
            BaseSystemDialogSetting setting = dialogSettingDao.findBySystemTypeAndFunctionType(sessionTypeToType(sessionType), "7", 1);
            if (setting == null) {
                return;
            }
            //查找相似问题
            BaseKnowledgeQuestion question = new BaseKnowledgeQuestion();
            if (contentType==1){
            if (contentType == 1) {
                question = findQuestionLikeName(content);
            }else if ((contentType+"").equalsIgnoreCase(ImUtil.ContentType.KnowCommonQuestions+"")){
            } else if ((contentType + "").equalsIgnoreCase(ImUtil.ContentType.KnowCommonQuestions + "")) {
                question = knowledgeQuestionDao.findById(content).get();
            }
            if(question!=null&&StringUtils.isNotBlank(question.getAnswer())){
            if (question != null && StringUtils.isNotBlank(question.getAnswer())) {
                //匹配到相关问题后先推送答案
                String answer = question.getAnswer();
                imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, "1", answer,null);
                imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, "1", answer, null);
                //匹配问题是否关联其他配置;
                if (question.getFlag()==null){
                if (question.getFlag() == null) {
                    List<BaseKnowledgeFlowConfigurationRelation> flowConfigurationRelations = findFlowConfigurationRelationLikeName(content);
                    if (flowConfigurationRelations!=null&&flowConfigurationRelations.size()!=0){
                    if (flowConfigurationRelations != null && flowConfigurationRelations.size() != 0) {
                        BaseKnowledgeFlowConfigurationRelation flowConfigurationRelation = flowConfigurationRelations.get(0);
                        String contentTypes = "1";
                        String contentMsg = "";
                        if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("2")){
                            contentTypes = ImUtil.ContentType.KnowCommonDict+"";
                            contentMsg = selectByContentType(contentTypes,flowConfigurationRelation.getRelationCode()).toJSONString();
                        }else  if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("3")){
                            contentTypes = ImUtil.ContentType.KnowCommonQuestions+"";
                            contentMsg = selectByContentType(contentTypes,flowConfigurationRelation.getRelationCode()).toJSONString();
                        if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("2")) {
                            contentTypes = ImUtil.ContentType.KnowCommonDict + "";
                            contentMsg = selectByContentType(contentTypes, flowConfigurationRelation.getRelationCode()).toJSONString();
                        } else if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("3")) {
                            contentTypes = ImUtil.ContentType.KnowCommonQuestions + "";
                            contentMsg = selectByContentType(contentTypes, flowConfigurationRelation.getRelationCode()).toJSONString();
                        }
                        imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, contentTypes, contentMsg,null);
                        imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, contentTypes, contentMsg, null);
                    }
                }
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     *
     * @param sessionId 会话id
     * @param type 咨询类型
     * @param content 内容
     * @param contentType 消息类型
     * @param businessType  业务类型
     * @param extend 扩展
     * 导诊咨询常见问题匹配
     * @param sessionId    会话id
     * @param type         咨询类型
     * @param content      内容
     * @param contentType  消息类型
     * @param businessType 业务类型
     * @param extend       扩展
     *                     导诊咨询常见问题匹配
     */
    public void replyGuaidenceContent(String sessionId,String type,String content,String contentType,String businessType, String extend){
    public void replyGuaidenceContent(String sessionId, String type, String content, String contentType, String businessType, String extend) {
        try {
            if(contentType.equals(ImUtil.ContentType.KnowSymptomsDiseaseQ.getValue())){
            if (contentType.equals(ImUtil.ContentType.KnowSymptomsDiseaseQ.getValue())) {
                //回复疾病
                replyDisease(type,content,sessionId,null,contentType);
                replyDisease(type, content, sessionId, null, contentType);
                return;
            }
            WlyyHospitalSysDictDO dictDO = getSender();
            if (contentType.equalsIgnoreCase("3003")){
            if (contentType.equalsIgnoreCase("3003")) {
                String contentTypes = ImUtil.ContentType.KnowCommonDict.getValue();
                String contentMsg = selectByContentType(contentTypes,content).toJSONString();
                imService.patientGuaidenceAppend(dictDO.getDictCode(),dictDO.getDictValue(),sessionId,
                        contentTypes+"", contentMsg, "1",null);
                String contentMsg = selectByContentType(contentTypes, content).toJSONString();
                imService.patientGuaidenceAppend(dictDO.getDictCode(), dictDO.getDictValue(), sessionId,
                        contentTypes + "", contentMsg, "1", null);
            }
            String systemType = sessionTypeToType(type);
            BaseSystemDialogSetting setting = dialogSettingDao.findBySystemTypeAndFunctionType(systemType,"7",1);
            if(setting==null){
            BaseSystemDialogSetting setting = dialogSettingDao.findBySystemTypeAndFunctionType(systemType, "7", 1);
            if (setting == null) {
                return;
            }
            Boolean re = imUtil.sessionIsExist(sessionId);
            if(re){
            if (re) {
                //查找相似问题
                BaseKnowledgeQuestion question = new BaseKnowledgeQuestion();
                if (contentType.equalsIgnoreCase("1")){
                if (contentType.equalsIgnoreCase("1")) {
                    question = findQuestionLikeName(content);
                }else if ((contentType+"").equalsIgnoreCase(ImUtil.ContentType.KnowCommonQuestions.getValue()+"")){
                } else if ((contentType + "").equalsIgnoreCase(ImUtil.ContentType.KnowCommonQuestions.getValue() + "")) {
                    question = knowledgeQuestionDao.findById(content).orElse(null);
                }
                if(question!=null&&StringUtils.isNotBlank(question.getAnswer())){
                if (question != null && StringUtils.isNotBlank(question.getAnswer())) {
                    //匹配到相关问题后先推送答案
                    String answer = question.getAnswer();
                    imService.patientGuaidenceAppend(dictDO.getDictCode(),dictDO.getDictValue(),sessionId,
                            contentType+"", answer, "1",null);
                    imService.patientGuaidenceAppend(dictDO.getDictCode(), dictDO.getDictValue(), sessionId,
                            contentType + "", answer, "1", null);
                    //匹配问题是否关联其他配置;
                    if (question.getFlag()==null){
                    if (question.getFlag() == null) {
                        List<BaseKnowledgeFlowConfigurationRelation> flowConfigurationRelations = findFlowConfigurationRelationLikeName(content);
                        if (flowConfigurationRelations!=null&&flowConfigurationRelations.size()!=0){
                        if (flowConfigurationRelations != null && flowConfigurationRelations.size() != 0) {
                            BaseKnowledgeFlowConfigurationRelation flowConfigurationRelation = flowConfigurationRelations.get(0);
                            String contentTypes = "1";
                            String contentMsg = "";
                            if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("2")){
                                contentTypes = ImUtil.ContentType.KnowCommonDict+"";
                                contentMsg = selectByContentType(contentTypes,flowConfigurationRelation.getRelationCode()).toJSONString();
                            }else  if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("3")){
                                contentTypes = ImUtil.ContentType.KnowCommonQuestions+"";
                                contentMsg = selectByContentType(contentTypes,flowConfigurationRelation.getRelationCode()).toJSONString();
                            if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("2")) {
                                contentTypes = ImUtil.ContentType.KnowCommonDict + "";
                                contentMsg = selectByContentType(contentTypes, flowConfigurationRelation.getRelationCode()).toJSONString();
                            } else if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("3")) {
                                contentTypes = ImUtil.ContentType.KnowCommonQuestions + "";
                                contentMsg = selectByContentType(contentTypes, flowConfigurationRelation.getRelationCode()).toJSONString();
                            }
                            imService.patientGuaidenceAppend(dictDO.getDictCode(),dictDO.getDictValue(),sessionId,
                                    contentTypes+"", contentMsg, "1",null);
                            imService.patientGuaidenceAppend(dictDO.getDictCode(), dictDO.getDictValue(), sessionId,
                                    contentTypes + "", contentMsg, "1", null);
                        }
                    }
                }
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public JSONObject selectByContentType(String contentType,String id){
    public JSONObject selectByContentType(String contentType, String id) {
        JSONObject object = new JSONObject();
        if (contentType.equalsIgnoreCase(ImUtil.ContentType.KnowCommonDict+"")){
        if (contentType.equalsIgnoreCase(ImUtil.ContentType.KnowCommonDict + "")) {
            BaseKnowledgeDict dict = knowledgeDictDao.findById(id).get();
            BaseKnowledgeDictRelation dictRelation  = knowledgeDictRelationDao.selectByDictId(id);
            if (dictRelation!=null){
            BaseKnowledgeDictRelation dictRelation = knowledgeDictRelationDao.selectByDictId(id);
            if (dictRelation != null) {
                String dept = dictRelation.getDept();
            }
            List<DictHospitalDeptDO> deptDOList = findDeptList(id);
            object.put("content",deptDOList);
            object.put("contentType",contentType);
            object.put("content", deptDOList);
            object.put("contentType", contentType);
        }else if (contentType.equalsIgnoreCase(ImUtil.ContentType.KnowCommonQuestions+"")){
        } else if (contentType.equalsIgnoreCase(ImUtil.ContentType.KnowCommonQuestions + "")) {
            BaseKnowledgeQuestions questions = knowledgeQuestionsDao.findById(id).get();
            List<BaseKnowledgeQuestionsRelation> questionsRelations = knowledgeQuestionsRelationDao.selectByQuestionsId(questions.getId());
            object.put("content",questionsRelations);
            object.put("contentType",contentType);
            object.put("content", questionsRelations);
            object.put("contentType", contentType);
        }
        return object;
    }
    public void replyContent(String session_id,String type,String content,Map<String,BaseSystemDialogSetting> mapSetting,Map<String,JSONObject> map){
    public void replyContent(String session_id, String type, String content, Map<String, BaseSystemDialogSetting> mapSetting, Map<String, JSONObject> map) {
        try {
            BaseSystemDialogSetting setting = null;
            if(mapSetting==null){
                setting = dialogSettingDao.findBySystemTypeAndFunctionType(sessionTypeToType(type),"7",1);
            }else {
            if (mapSetting == null) {
                setting = dialogSettingDao.findBySystemTypeAndFunctionType(sessionTypeToType(type), "7", 1);
            } else {
                setting = mapSetting.get("7");
            }
            if(setting==null){
            if (setting == null) {
                return;
            }
            //查找相似问题
            BaseKnowledgeQuestion question = findQuestionLikeName(content);
            if(question!=null){
            if (question != null) {
                String answer = question.getAnswer();
                JSONObject result = new JSONObject();
                result.put("content",answer);
                result.put("content_type","1");
                result.put("session_id",session_id);
                map.put("7",result);
                result.put("content", answer);
                result.put("content_type", "1");
                result.put("session_id", session_id);
                map.put("7", result);
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void welcome(String session_id,Map<String,BaseSystemDialogSetting> mapSetting,Map<String,JSONObject> map){
    public void welcome(String session_id, Map<String, BaseSystemDialogSetting> mapSetting, Map<String, JSONObject> map) {
        try {
            Integer sessionStatus = imUtil.sessionStatus(session_id);
            if(sessionStatus==null||sessionStatus==1){
            if (sessionStatus == null || sessionStatus == 1) {
                //系统客服tip
                JSONObject tip = new JSONObject();
                tip.put("content","1");
                tip.put("content_type",ImUtil.ContentType.KnowCommonCustomer.getValue());
                tip.put("session_id",session_id);
                map.put("0",tip);
                tip.put("content", "1");
                tip.put("content_type", ImUtil.ContentType.KnowCommonCustomer.getValue());
                tip.put("session_id", session_id);
                map.put("0", tip);
                //欢迎语
                BaseSystemDialogSetting welcomeSetting = mapSetting.get("1");
                if(welcomeSetting!=null&&StringUtils.isNotBlank(welcomeSetting.getContent())){
                if (welcomeSetting != null && StringUtils.isNotBlank(welcomeSetting.getContent())) {
                    String welcomeContent = welcomeSetting.getContent();
                    JSONObject result = new JSONObject();
                    result.put("content",welcomeContent);
                    result.put("content_type","1");
                    result.put("session_id",session_id);
                    map.put("1",result);
                    result.put("content", welcomeContent);
                    result.put("content_type", "1");
                    result.put("session_id", session_id);
                    map.put("1", result);
                }
                //欢迎消息关联问题
                BaseSystemDialogSetting welcomeQueSetting = mapSetting.get("2");
                if(welcomeQueSetting!=null){
                if (welcomeQueSetting != null) {
                    Integer relaitonCodeType = welcomeQueSetting.getRelaitonCodeType();//1常见问题2字典中心3问题集
                    relaitonCodeType = relaitonCodeType==null?-1:relaitonCodeType;
                    relaitonCodeType = relaitonCodeType == null ? -1 : relaitonCodeType;
                    String relationCode = welcomeQueSetting.getRelationCode();//relationType2对应业务code,多个逗号隔开
                    if(StringUtils.isNotBlank(relationCode)){
                    if (StringUtils.isNotBlank(relationCode)) {
                        return;
                    }
                    relationCode = relationCode.replace(",","','");
                    if(relaitonCodeType==1){
                    relationCode = relationCode.replace(",", "','");
                    if (relaitonCodeType == 1) {
                        //1常见问题
                        JSONObject result = new JSONObject();
                        result.put("content",relationCode);
                        result.put("content_type",ImUtil.ContentType.KnowCommonQuestion.getValue());
                        result.put("session_id",session_id);
                        map.put("2",result);
                    }else if(relaitonCodeType==2){
                        result.put("content", relationCode);
                        result.put("content_type", ImUtil.ContentType.KnowCommonQuestion.getValue());
                        result.put("session_id", session_id);
                        map.put("2", result);
                    } else if (relaitonCodeType == 2) {
                        JSONObject result = new JSONObject();
                        result.put("content",relationCode);
                        result.put("content_type",ImUtil.ContentType.KnowCommonDict.getValue());
                        result.put("session_id",session_id);
                        map.put("2",result);
                    }else if(relaitonCodeType==3){
                        result.put("content", relationCode);
                        result.put("content_type", ImUtil.ContentType.KnowCommonDict.getValue());
                        result.put("session_id", session_id);
                        map.put("2", result);
                    } else if (relaitonCodeType == 3) {
                        JSONObject result = new JSONObject();
                        result.put("content",relationCode);
                        result.put("content_type",ImUtil.ContentType.KnowCommonQuestions.getValue());
                        result.put("session_id",session_id);
                        map.put("2",result);
                        result.put("content", relationCode);
                        result.put("content_type", ImUtil.ContentType.KnowCommonQuestions.getValue());
                        result.put("session_id", session_id);
                        map.put("2", result);
                    }
                }
            }
            if(sessionStatus==1){
            System.out.println("sessionStatus==>" + sessionStatus);
            if (sessionStatus == 1) {
                //结束的会话开启
                imUtil.updateSessionStatus(session_id,"0");
                System.out.println("开启结束的会话");
                imUtil.updateSessionStatus(session_id, "0");
            } else {
                System.out.println("没有开启结束的会话");
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //查找常见问题
    public BaseKnowledgeQuestion findQuestionLikeName(String content){
        if(!StringUtils.isNotEmpty(content)){
    public BaseKnowledgeQuestion findQuestionLikeName(String content) {
        if (!StringUtils.isNotEmpty(content)) {
            return null;
        }
        String sql = "select p.* from base_knowledge_question p where p.status = 1 and p.del=1 and  " +
                " (p.time=1 or (p.time=2 and p.date<'"+DateUtil.getStringDate()+"')) " +
                " and (p.question_name like '%"+content+"%' or p.similar_question_name like '"+content+"')  order by sort limit 1";
        List<BaseKnowledgeQuestion> questionList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseKnowledgeQuestion.class));
        if(questionList.size()>0){
                " (p.time=1 or (p.time=2 and p.date<'" + DateUtil.getStringDate() + "')) " +
                " and (p.question_name like '%" + content + "%' or p.similar_question_name like '" + content + "')  order by sort limit 1";
        List<BaseKnowledgeQuestion> questionList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BaseKnowledgeQuestion.class));
        if (questionList.size() > 0) {
            return questionList.get(0);
        }
        return null;
    }
    //查找常见问题关联配置
    public List<BaseKnowledgeFlowConfigurationRelation> findFlowConfigurationRelationLikeName(String content){
        if(!StringUtils.isNotEmpty(content)){
    public List<BaseKnowledgeFlowConfigurationRelation> findFlowConfigurationRelationLikeName(String content) {
        if (!StringUtils.isNotEmpty(content)) {
            return null;
        }
        String sql = "select p.* from base_knowledge_flow_configuration_relation p where " +
                "  p.relation_name like '%"+content+"%'  order by sort asc ";
        List<BaseKnowledgeFlowConfigurationRelation> flowConfigurationRelations = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseKnowledgeFlowConfigurationRelation.class));
                "  p.relation_name like '%" + content + "%'  order by sort asc ";
        List<BaseKnowledgeFlowConfigurationRelation> flowConfigurationRelations = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BaseKnowledgeFlowConfigurationRelation.class));
        return flowConfigurationRelations;
    }
    public List<BaseKnowledgeQuestions> findTopQuestionsList(Integer limit,String ids){
        String sql = "select p.* from base_knowledge_questions p where p.status = 1 and p.del=1 and p.id in ('"+ids+"')" +
                "(p.time=1 or (p.time=2 and p.date<'"+DateUtil.getStringDate()+"'))  order by sort limit "+limit;
        List<BaseKnowledgeQuestions> questionList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseKnowledgeQuestions.class));
    public List<BaseKnowledgeQuestions> findTopQuestionsList(Integer limit, String ids) {
        String sql = "select p.* from base_knowledge_questions p where p.status = 1 and p.del=1 and p.id in ('" + ids + "')" +
                "(p.time=1 or (p.time=2 and p.date<'" + DateUtil.getStringDate() + "'))  order by sort limit " + limit;
        List<BaseKnowledgeQuestions> questionList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BaseKnowledgeQuestions.class));
        return questionList;
    }
    public List<BaseKnowledgeQuestion> findTopQuestionList(Integer limit,String ids){
        String sql = "select p.* from base_knowledge_question p where p.status = 1 and p.del=1 and p.id in ('"+ids+"')" +
                "(p.time=1 or (p.time=2 and p.date<'"+DateUtil.getStringDate()+"'))  order by sort limit "+limit;
        List<BaseKnowledgeQuestion> questionList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseKnowledgeQuestion.class));
    public List<BaseKnowledgeQuestion> findTopQuestionList(Integer limit, String ids) {
        String sql = "select p.* from base_knowledge_question p where p.status = 1 and p.del=1 and p.id in ('" + ids + "')" +
                "(p.time=1 or (p.time=2 and p.date<'" + DateUtil.getStringDate() + "'))  order by sort limit " + limit;
        List<BaseKnowledgeQuestion> questionList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BaseKnowledgeQuestion.class));
        return questionList;
    }
    /**
     * 查询相关字典
     *
     * @param limit
     * @param ids
     * @return
     */
    public List<BaseKnowledgeDict> findTopDictList(Integer limit,String ids){
        String sql = "select p.* from base_knowledge_dict p where p.del=1 and p.id in ('"+ids+"') order by sort limit "+limit;
        List<BaseKnowledgeDict> dictList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseKnowledgeDict.class));
    public List<BaseKnowledgeDict> findTopDictList(Integer limit, String ids) {
        String sql = "select p.* from base_knowledge_dict p where p.del=1 and p.id in ('" + ids + "') order by sort limit " + limit;
        List<BaseKnowledgeDict> dictList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BaseKnowledgeDict.class));
        return dictList;
    }
    /**
     * 根据业务不一样转换相关的会话类型
     *
     * @param type
     * @return
     */
    //会话类型转类型
    public String sessionTypeToType(String type){
        if(!StringUtils.isNotEmpty(type)){
    public String sessionTypeToType(String type) {
        if (!StringUtils.isNotEmpty(type)) {
            return type;
        }
        if("18".equalsIgnoreCase(type)){
        if ("18".equalsIgnoreCase(type)) {
            return "1";
        }
        if("26".equalsIgnoreCase(type)){
        if ("26".equalsIgnoreCase(type)) {
            return "2";
        }
        if("27".equalsIgnoreCase(type)){
        if ("27".equalsIgnoreCase(type)) {
            return "3";
        }
        if("1".equalsIgnoreCase(type)||"5".equalsIgnoreCase(type)||"9".equalsIgnoreCase(type)||"12".equalsIgnoreCase(type)||"15".equalsIgnoreCase(type)||"16".equalsIgnoreCase(type)){
        if ("1".equalsIgnoreCase(type) || "5".equalsIgnoreCase(type) || "9".equalsIgnoreCase(type) || "12".equalsIgnoreCase(type) || "15".equalsIgnoreCase(type) || "16".equalsIgnoreCase(type)) {
            return "4";
        }
        return type;
    }
    public List<DictHospitalDeptDO> findDeptList(String ids){
        String sql = "select p.* from dict_hospital_dept p where p.consult_dept_flag=1 and p.code in ('"+ids+"') ";
        List<DictHospitalDeptDO> deptDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(DictHospitalDeptDO.class));
    public List<DictHospitalDeptDO> findDeptList(String ids) {
        String sql = "select p.* from dict_hospital_dept p where p.consult_dept_flag=1 and p.code in ('" + ids + "') ";
        List<DictHospitalDeptDO> deptDOList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DictHospitalDeptDO.class));
        return deptDOList;
    }
}

+ 6 - 7
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/consult/PatientConsultEndpoint.java

@ -1,5 +1,6 @@
package com.yihu.jw.hospital.endpoint.consult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
@ -877,18 +878,16 @@ public class PatientConsultEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value = "robotWelcome")
    @ApiOperation(value = "居民导诊欢迎语", notes = "居民导诊欢迎语")
    public Envelop robotWelcome(
            @ApiParam(name = "sender_id", value = "居民id", defaultValue = "")
            @RequestParam(value = "sender_id", required = true) String sender_id,
            @ApiParam(name = "session_id", value = "session_id", defaultValue = "")
            @RequestParam(value = "session_id", required = false) String session_id,
            @ApiParam(name = "type", value = "咨询type", defaultValue = "")
            @RequestParam(value = "type", required = false) String type
            @ApiParam(name = "sender_id", value = "居民id", defaultValue = "") @RequestParam(value = "sender_id", required = true) String sender_id,
            @ApiParam(name = "session_id", value = "session_id", defaultValue = "") @RequestParam(value = "session_id", required = false) String session_id,
            @ApiParam(name = "type", value = "咨询type", defaultValue = "") @RequestParam(value = "type", required = false) String type
    ) {
        try {
            System.out.println("sender_id[居民id]==>" + sender_id + "   session_id==>" + session_id);
            Map<String, JSONObject> map = robotService.robotReply(session_id, type, null);
            imService.getPatientGuaidenceConsult(sender_id, session_id, type);
            robotService.sendReplyMap(map);
            return Envelop.getSuccess("success");
            return Envelop.getSuccess(JSON.toJSONString(map));
        } catch (Exception e) {
            return failedException(e);
        }