Sfoglia il codice sorgente

Merge branch 'dev' of wujunjie/patient-co-management into dev

chenweida 8 anni fa
parent
commit
86565df62c

+ 14 - 5
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/HealthEduArticleService.java

@ -6,9 +6,7 @@ import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import com.yihu.wlyy.repository.education.HealthEduArticleDao;
import com.yihu.wlyy.repository.education.HealthEduArticlePatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.util.Xml2ListMap;
import com.yihu.wlyy.util.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
@ -54,6 +52,7 @@ public class HealthEduArticleService extends BaseService {
        String content = null;
        String keyWord = null;
        String type = null;
        String summary = null;
        int rows = 0;
        for(Map<String,String> temp : listmap){
            code = temp.get("xml.Result.MessageId");
@ -61,6 +60,14 @@ public class HealthEduArticleService extends BaseService {
            imgUrl = temp.get("xml.Result.ImageUrlSmall");
            content = temp.get("xml.Result.MessageContent");
            keyWord = temp.get("xml.Result.MessageType");
            String str = Html2Text.Html2Text(content);
            if(str.length()>50){
            summary = str.substring(0,50).replace("\n","").replace(" ","").replace("&nbsp;","");
            }else {
                summary = str.replace("\n","").replace(" ","").replace("&nbsp;","");
            }
            switch (keyWord){
                case "1":
                    keyWord = "高血压";
@ -101,8 +108,10 @@ public class HealthEduArticleService extends BaseService {
            }
            String sql = "INSERT INTO wlyy_health_edu_article  " +
                    "VALUES(NULL,?,?,?,?,NULL,?,?)";
            rows = jdbcTemplate.update(sql,code,title,imgUrl,content,keyWord,type);
                    "VALUES(NULL,?,?,?,?,?,NULL,?,?)";
           /* String sql = "INSERT INTO wlyy_health_article  " +
                    "VALUES(NULL,?,?,?,?,?,NULL,?,?)";*/
            rows = jdbcTemplate.update(sql,code,title,summary,imgUrl,content,keyWord,type);
            rows+=rows;
        }
        return rows;

+ 42 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/Html2Text.java

@ -0,0 +1,42 @@
package com.yihu.wlyy.util;
import java.util.regex.Pattern;
/**
 * Created by Reece on 2017/3/6.
 */
public class Html2Text {
    public static String Html2Text(String inputString){
        String htmlStr = inputString; //含html标签的字符串
        String textStr ="";
        java.util.regex.Pattern p_script;
        java.util.regex.Matcher m_script;
        java.util.regex.Pattern p_style;
        java.util.regex.Matcher m_style;
        java.util.regex.Pattern p_html;
        java.util.regex.Matcher m_html;
        try{
            String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; //定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script> }
            String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; //定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style> }
            String regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
            p_script = Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
            m_script = p_script.matcher(htmlStr);
            htmlStr = m_script.replaceAll(""); //过滤script标签
            p_style = Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
            m_style = p_style.matcher(htmlStr);
            htmlStr = m_style.replaceAll(""); //过滤style标签
            p_html = Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);
            m_html = p_html.matcher(htmlStr);
            htmlStr = m_html.replaceAll(""); //过滤html标签
            textStr = htmlStr;
        }catch(Exception e){
//            Manager.log.debug("neiNewsAction","Html2Text: " + e.getMessage());
        }
        return textStr;//返回文本字符串
    }
}