|
@ -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);
|