Browse Source

Merge branch 'master' of huangzhanpeng/esb_huangzhanpeng into master

esb 9 years ago
parent
commit
d8446759d1

+ 5 - 5
Hos-resource/src/main/java/com/yihu/ehr/datacollect/model/DtoDictCol.java

@ -11,7 +11,7 @@ public class DtoDictCol implements java.io.Serializable {
	private String stdMetadataCode;
	private String adapterDataType;
	private String adapterDictId;
	private String stdDictId;
	private JSONArray dictList;
	public String getStdMetadataCode() {
@ -30,12 +30,12 @@ public class DtoDictCol implements java.io.Serializable {
		this.adapterDataType = adapterDataType;
	}
	public String getAdapterDictId() {
		return adapterDictId;
	public String getStdDictId() {
		return stdDictId;
	}
	public void setAdapterDictId(String adapterDictId) {
		this.adapterDictId = adapterDictId;
	public void setStdDictId(String stdDictId) {
		this.stdDictId = stdDictId;
	}
	public JSONArray getDictList() {

+ 101 - 12
Hos-resource/src/main/java/com/yihu/ehr/datacollect/service/DatacollectService.java

@ -65,6 +65,7 @@ public class DatacollectService implements IDatacollectService {
    @Resource(name = "DatacollectLogDao")
    private IDatacollectLogDao datacollectLogDao;
    MongodbHelper mongoOrigin = new MongodbHelper("origin");
    MongodbHelper mongo = new MongodbHelper();
    String dateFormat = "yyyy-MM-dd HH:mm:ss"; //默认时间字符串格式
@ -137,6 +138,81 @@ public class DatacollectService implements IDatacollectService {
        }
    }
    /**
     * 字典全转换成中文
     */
    private List<JSONObject> translateDictCN(List<JSONObject> list,JSONArray colList,String schemeVersion) throws Exception
    {
        //获取字典列表
        List<DtoDictCol> dictColList = new ArrayList<>();
        for(int i=0; i< colList.length();i++)
        {
            JSONObject col = colList.getJSONObject(i);
            String dictId = col.optString("adapterDictId");
            if(dictId!=null && dictId.length()>0)
            {
                String dictType = col.optString("adapterDataType");
                String stdMetadataCode = col.optString("stdMetadataCode");
                DtoDictCol dictCol = new DtoDictCol();
                dictCol.setStdMetadataCode(stdMetadataCode);
                dictCol.setStdDictId(dictId);
                dictCol.setAdapterDataType(dictType.length() > 0 ? dictType : "1");//默认通过code转换字典
                //获取字典数据
                List dictString = stdService.getDictByScheme(schemeVersion,dictId);
                JSONArray dictAdapterArray = new JSONArray(dictString);
                dictCol.setDictList(dictAdapterArray);
                dictColList.add(dictCol);
            }
        }
        //翻译列表
        for(JSONObject data :list)
        {
            //遍历字典字段
            for (DtoDictCol col : dictColList) {
                String colNmae = col.getStdMetadataCode();
                String oldValue = data.optString(colNmae);
                String newValue = translateDictValueCN(oldValue,col.getAdapterDataType(),col.getDictList());
                if(newValue!=null && newValue.length()>0)
                {
                    data.put(colNmae,newValue);
                }
            }
        }
        return list;
    }
    /**
     * 转译字典成中文
     * @return
     */
    private String translateDictValueCN(String oldValue,String type,JSONArray dictAdapterList) throws Exception
    {
        if(type.equals("0")) //原本就是值
        {
            return oldValue;
        }
        //遍历字典数据(编码->名称)
        for(int i=0; i< dictAdapterList.length();i++)
        {
            JSONObject dictItem = dictAdapterList.getJSONObject(i);
            if(oldValue!=null && dictItem.has("stdEntryCode")) {
                if (oldValue.equals(dictItem.getString("stdEntryCode"))) {
                    String newValue = dictItem.getString("stdEntryValue"); //名称
                    return newValue;
                }
            }
        }
        return oldValue;
    }
    /**
     * 字典转换
     * @param list
@ -159,7 +235,7 @@ public class DatacollectService implements IDatacollectService {
                String stdMetadataCode = col.optString("stdMetadataCode");
                DtoDictCol dictCol = new DtoDictCol();
                dictCol.setStdMetadataCode(stdMetadataCode);
                dictCol.setAdapterDictId(dictId);
                dictCol.setStdDictId(dictId);
                dictCol.setAdapterDataType(dictType.length()>0?dictType:"1");//默认通过code转换字典
                //获取字典数据
                List dictString = stdService.getDictByScheme(schemeVersion,dictId);
@ -214,7 +290,8 @@ public class DatacollectService implements IDatacollectService {
            }
        }
        return oldValue;
        //找不到适配字典数据则返回空
        return "";
    }
@ -274,11 +351,14 @@ public class DatacollectService implements IDatacollectService {
            }
            if(list!=null && list.size()>0)
            {
                //字典未转换前采集到原始库
                boolean b = mongoOrigin.insert(stdDatasetCode,translateDictCN(list, colList,schemeVersion));
                //字典转换
                list = translateDict(list, colList,schemeVersion);
                //采集到mongodb
                boolean b = mongo.insert(stdDatasetCode,list);
                b = mongo.insert(stdDatasetCode,list);
                if(!b)
                {
                    if(mongo.errorMessage!=null && mongo.errorMessage.length()>0)
@ -385,10 +465,11 @@ public class DatacollectService implements IDatacollectService {
                }
                strSql += strWhere;
                //总条数和最大值查询
                String sqlCount = "select count(1) as COUNT,max(" + maxKey + ") as MAX_KEYVALUE from (" + strSql+")";
                JSONObject obj = db.load(sqlCount);
                if(obj==null)
                //总条数
                String sqlCount = "select count(1) as COUNT from (" + strSql+")";
                String sqlMax = "select max(" + maxKey + ") as MAX_KEYVALUE from " + adapterTableName + strWhere;
                JSONObject objCount = db.load(sqlCount);
                if(objCount==null)
                {
                    if(db.errorMessage.length()>0)
                    {
@ -399,7 +480,7 @@ public class DatacollectService implements IDatacollectService {
                    }
                }
                else{
                    int count = obj.getInt("COUNT");
                    int count = objCount.getInt("COUNT");
                    if(count==0) //0条记录,无需采集
                    {
@ -407,8 +488,11 @@ public class DatacollectService implements IDatacollectService {
                    }
                    else
                    {
                        //获取最大值
                        JSONObject objMax = db.load(sqlMax);
                        int successCount = 0;
                        String maxKeyvalue = obj.optString("MAX_KEYVALUE");
                        String maxKeyvalue = objMax.optString("MAX_KEYVALUE");
                        //修改最大值
                        if(maxKeyvalue!=null&& maxKeyvalue.length()>0)
                        {
@ -605,9 +689,10 @@ public class DatacollectService implements IDatacollectService {
                    }
                    strSql += strWhere;
                    //总条数和最大值查询
                    String sqlCount = "select count(1) as COUNT,max(" + maxKey + ") as MAX_KEYVALUE from (" + strSql +")";
                    String sqlCount = "select count(1) as COUNT from (" + strSql+")";
                    String sqlMax = "select max(" + maxKey + ") as MAX_KEYVALUE from " + adapterTableName + strWhere;
                    //webservice获取数据//获取总条数和最大值
                    //webservice获取数据总条数
                    String strCount = WebserviceUtil.request(url,"ExcuteSQL",new Object[]{"",sqlCount});
                    List<JSONObject> dataCount = getListFromXml(strCount);
@ -618,8 +703,12 @@ public class DatacollectService implements IDatacollectService {
                            message = "0条记录,无需采集。";
                        }
                        else {
                            //webservice获取最大值
                            String strMax = WebserviceUtil.request(url,"ExcuteSQL",new Object[]{"",sqlMax});
                            List<JSONObject> dataMax = getListFromXml(strCount);
                            int successCount = 0;
                            String maxKeyvalue = dataCount.get(0).getString("MAX_KEYVALUE");
                            String maxKeyvalue = dataMax.get(0).getString("MAX_KEYVALUE");
                            //修改最大值
                            if (maxKeyvalue != null && maxKeyvalue.length() > 0) {
                                datacollectLogDao.updateJobDatasetKeyvalue(ds.getId(), maxKeyvalue);

+ 2 - 2
Hos-resource/src/main/java/com/yihu/ehr/datacollect/service/DatapushService.java

@ -103,10 +103,10 @@ public class DatapushService implements IDatapushService {
                                String val = data.optString(adapterColName);
                                String newValue =val;
                                //判断是否字典
                                if(metadata.getAdapterDictId()!=null&&metadata.getAdapterDictId()!=0)
                                if(metadata.getStdDictId()!=null&&metadata.getStdDictId()!=0)
                                {
                                    //获取字典列表
                                    List dictString = stdService.getDictByScheme(version,metadata.getAdapterDictId().toString());
                                    List dictString = stdService.getDictByScheme(version,metadata.getStdDictId().toString());
                                    JSONArray dictAdapterArray = new JSONArray(dictString);
                                    String type = "";
                                    if(metadata.getAdapterDataType()!=null)

+ 4 - 14
Hos-resource/src/main/resources/spring/applicationContext.xml

@ -36,20 +36,10 @@
    <!--Hibernate 数据库配置-->
    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <!--
        <property name="url"
                  value="jdbc:mysql://172.19.103.50:3306/healtharchive?useUnicode=true&amp;characterEncoding=UTF-8"/>
        <property name="username" value="fujian"/>
        <property name="password" value="fujian"/>
        -->
        <!--<property name="url"-->
                  <!--value="jdbc:mysql://192.168.1.220:3306/hos2_resource?useUnicode=true&amp;characterEncoding=UTF-8"/>-->
        <!--<property name="username" value="hos2"/>-->
        <!--<property name="password" value="hos2"/>-->
        <property name="url"
                  value="jdbc:mysql://localhost:3306/esb?useUnicode=true&amp;characterEncoding=UTF-8"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
        <property name="url" value="jdbc:mysql://172.19.103.71:3306/esb?useUnicode=true&amp;characterEncoding=UTF-8"/>
        <property name="username" value="hos"/>
        <property name="password" value="hos"/>
        <property name="initialSize" value="1"/>
        <property name="maxTotal" value="100"/>
        <property name="maxIdle" value="50"/>