|
@ -335,7 +335,7 @@ public class DatacollectService implements IDatacollectService {
|
|
|
if(colList!=null && colList.length()>0)
|
|
|
{
|
|
|
//拼接查询sql
|
|
|
String strSql = "Select '" + orgCode +"' as RSCOM_ORG_CODE";
|
|
|
String strSql = "Select '" + orgCode +"' as RSCOM_ORG_CODE,test";
|
|
|
for(int i=0; i< colList.length();i++)
|
|
|
{
|
|
|
JSONObject col = colList.getJSONObject(i);
|
|
@ -386,7 +386,7 @@ public class DatacollectService implements IDatacollectService {
|
|
|
|
|
|
strSql += strWhere;
|
|
|
//总条数和最大值查询
|
|
|
String sqlCount = "select count(1) as COUNT,max(" + maxKey + ") as MAX_KEYVALUE from " + adapterTableName + strWhere;
|
|
|
String sqlCount = "select count(1) as COUNT,max(" + maxKey + ") as MAX_KEYVALUE from (" + strSql+")";
|
|
|
JSONObject obj = db.load(sqlCount);
|
|
|
if(obj==null)
|
|
|
{
|
|
@ -524,7 +524,7 @@ public class DatacollectService implements IDatacollectService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 数据库表采集
|
|
|
* webservice采集
|
|
|
* @return
|
|
|
*/
|
|
|
private String collectWebservice(DtoJobDataset ds,String schemeVersion,String logId) throws Exception
|
|
@ -606,7 +606,7 @@ public class DatacollectService implements IDatacollectService {
|
|
|
}
|
|
|
strSql += strWhere;
|
|
|
//总条数和最大值查询
|
|
|
String sqlCount = "select count(1) as COUNT,max(" + maxKey + ") as MAX_KEYVALUE from " + adapterTableName + strWhere;
|
|
|
String sqlCount = "select count(1) as COUNT,max(" + maxKey + ") as MAX_KEYVALUE from (" + strSql +")";
|
|
|
|
|
|
//webservice获取数据//获取总条数和最大值
|
|
|
String strCount = WebserviceUtil.request(url,"ExcuteSQL",new Object[]{"",sqlCount});
|
|
@ -701,195 +701,7 @@ public class DatacollectService implements IDatacollectService {
|
|
|
return message;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* webservice采集(参数)
|
|
|
*//*
|
|
|
private String collectWebservice(DtoJobDataset ds,String schemeVersion,String logId) throws Exception
|
|
|
{
|
|
|
String message = "";
|
|
|
String datasetId = ds.getJobDatasetId();
|
|
|
String jobDatasetName = ds.getJobDatasetName();
|
|
|
String condition=ds.getJobDatasetCondition();
|
|
|
String key=ds.getJobDatasetKey();
|
|
|
String keytype=ds.getJobDatasetKeytype();
|
|
|
String keyvalue=ds.getJobDatasetKeyvalue();
|
|
|
String orgCode = ds.getOrgCode();
|
|
|
String config = ds.getConfig();
|
|
|
String datasourceId = ds.getDatasourceId();
|
|
|
//webservice地址
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
Map<String,String> mapConfig = objectMapper.readValue(config,Map.class);
|
|
|
if(mapConfig.containsKey("protocol") && mapConfig.containsKey("url"))
|
|
|
{
|
|
|
String url = mapConfig.get("protocol") + "://" + mapConfig.get("url");
|
|
|
//获取数据集映射
|
|
|
List datasetString = stdService.getDatasetByScheme(schemeVersion, datasetId);
|
|
|
JSONArray datasetList = new JSONArray(datasetString);
|
|
|
|
|
|
if(datasetList!=null &&datasetList.length()>0)
|
|
|
{
|
|
|
String stdTableName = datasetList.getJSONObject(0).optString("stdDatasetCode");
|
|
|
String adapterTableName = datasetList.getJSONObject(0).optString("adapterDatasetCode");
|
|
|
//获取数据集字段映射结构
|
|
|
List colString = stdService.getDatacolByScheme(schemeVersion,datasetId);
|
|
|
JSONArray colList = new JSONArray(colString);
|
|
|
|
|
|
if(colList!=null && colList.length()>0) {
|
|
|
|
|
|
Map<String,Object> params = new HashMap<>();
|
|
|
String where = "";
|
|
|
params.put("table",adapterTableName);//表名
|
|
|
String paramsStr = "";
|
|
|
//设置最大值
|
|
|
if(keyvalue!=null && keyvalue.length()>0)
|
|
|
{
|
|
|
if(condition.length()>0 && !condition.equals("[]"))
|
|
|
{
|
|
|
paramsStr = condition.substring(0,condition.length()-1) + ",{\"andOr\":\" AND \",\"field\":\""+key+"\",\"condition\":\" > \",\"value\":\""+keyvalue+"\"}]";
|
|
|
}
|
|
|
else{
|
|
|
paramsStr = "[{\"andOr\":\" AND \",\"field\":\""+key+"\",\"condition\":\" > \",\"value\":\""+keyvalue+"\"}]";
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
paramsStr = condition;
|
|
|
}
|
|
|
params.put("params",paramsStr);
|
|
|
params.put("key",key);
|
|
|
params.put("keytype",keytype);
|
|
|
|
|
|
//获取总条数和最大值
|
|
|
HttpResponse responseCount = HttpHelper.get(url,params);
|
|
|
Map<String,String> mapCount = objectMapper.readValue(responseCount.getBody(),Map.class);
|
|
|
if(responseCount.getStatusCode() == 200 && mapCount.containsKey("count"))
|
|
|
{
|
|
|
Integer count = Integer.parseInt(mapCount.get("count"));
|
|
|
if(count == 0) //0条记录,无需采集
|
|
|
{
|
|
|
message = "0条记录,无需采集。";
|
|
|
}
|
|
|
else {
|
|
|
params.remove("key");
|
|
|
params.remove("keytype");
|
|
|
int successCount = 0;
|
|
|
String maxKeyvalue = mapCount.get("maxKeyvalue");
|
|
|
int countPage = 1;
|
|
|
if(count > maxNum) //分页采集
|
|
|
{
|
|
|
countPage = count/maxNum+1;
|
|
|
}
|
|
|
for(int i=0;i<countPage;i++)
|
|
|
{
|
|
|
int rows = maxNum;
|
|
|
if(i+1==countPage){
|
|
|
rows = count-i*maxNum;
|
|
|
}
|
|
|
int start = i*maxNum; //开始行数
|
|
|
|
|
|
RsJobLogDetail detail = new RsJobLogDetail();
|
|
|
detail.setStartTime(new Date());
|
|
|
detail.setJobLogId(logId);
|
|
|
detail.setDatasourceId(datasourceId);
|
|
|
detail.setConfig(config);
|
|
|
detail.setStdDatasetCode(stdTableName);
|
|
|
detail.setJobDatasetId(datasetId);
|
|
|
detail.setJobDatasetName(ds.getJobDatasetName());
|
|
|
detail.setJobId(ds.getJobId());
|
|
|
detail.setJobSql("{table:\""+adapterTableName+"\",where:\""+where+"\",start:\""+start+"\",rows:\""+rows+"\"}");
|
|
|
detail.setJobNum(i+1);
|
|
|
detail.setJobDatasetRows(rows);
|
|
|
detail.setSchemeVersion(schemeVersion);
|
|
|
|
|
|
//分页获取数据
|
|
|
params.put("start",start);
|
|
|
params.put("rows",rows);
|
|
|
HttpResponse responseList = HttpHelper.get(url,params);
|
|
|
String msg = "";
|
|
|
if(responseList.getStatusCode() == 200) {
|
|
|
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, JSONObject.class);
|
|
|
List<JSONObject> list = objectMapper.readValue(responseList.getBody(), javaType);
|
|
|
|
|
|
if (list != null) {
|
|
|
List<JSONObject> listNew = new ArrayList<>();
|
|
|
//遍历所有数据,转译数据元代码
|
|
|
for(JSONObject obj : list)
|
|
|
{
|
|
|
JSONObject objNew = new JSONObject();
|
|
|
//转译字段名
|
|
|
for(int j=0; j< colList.length();j++)
|
|
|
{
|
|
|
JSONObject col = colList.getJSONObject(j);
|
|
|
String adapterMetadataCode = col.optString("adapterMetadataCode");
|
|
|
String stdMetadataCode = col.optString("stdMetadataCode");
|
|
|
|
|
|
if(obj.has(adapterMetadataCode))
|
|
|
{
|
|
|
objNew.put(stdMetadataCode,obj.get(adapterMetadataCode));
|
|
|
}
|
|
|
}
|
|
|
listNew.add(objNew);
|
|
|
}
|
|
|
|
|
|
msg = intoMongodb(listNew, schemeVersion, stdTableName, colList); //返回信息
|
|
|
} else {
|
|
|
msg = "查询数据为空!";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
msg = responseList.getBody();
|
|
|
if(msg.length()==0)
|
|
|
{
|
|
|
msg = "获取数据失败!";
|
|
|
}
|
|
|
}
|
|
|
if(msg.length()>0)
|
|
|
{
|
|
|
//任务日志细表异常操作
|
|
|
detail.setJobStatus("0");
|
|
|
detail.setJobContent(msg);
|
|
|
LogService.getLogger().info(msg); //文本日志
|
|
|
}
|
|
|
else{
|
|
|
detail.setJobStatus("1");
|
|
|
detail.setJobContent("采集成功!");
|
|
|
successCount += rows;
|
|
|
}
|
|
|
detail.setEndTime(new Date());
|
|
|
datacollectLogDao.saveEntity(detail);
|
|
|
}
|
|
|
|
|
|
//修改最大值
|
|
|
if(maxKeyvalue!=null&& maxKeyvalue.length()>0)
|
|
|
{
|
|
|
datacollectLogDao.updateJobDatasetKeyvalue(ds.getId(),maxKeyvalue);
|
|
|
LogService.getLogger().info("修改任务数据集最大值为"+maxKeyvalue+"。"); //文本日志
|
|
|
}
|
|
|
message = jobDatasetName + "采集成功"+successCount+"条数据,总条数"+count+"条。";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
throw new Exception(jobDatasetName + "获取总条数异常!"+responseCount.getBody());
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw new Exception(jobDatasetName + "数据集字段映射为空!");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
throw new Exception(jobDatasetName + "数据集映射为空!");
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
throw new Exception("非法webservice路径!");
|
|
|
}
|
|
|
|
|
|
LogService.getLogger().info(message);
|
|
|
return message;
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
@ -962,12 +774,18 @@ public class DatacollectService implements IDatacollectService {
|
|
|
logStr.append("/*********** 出现异常,中断采集 *******************/\n");
|
|
|
}
|
|
|
|
|
|
|
|
|
//任务主日志成功
|
|
|
log.setJobContent(logStr.toString());
|
|
|
String jobContent = logStr.toString().replace("\"", "\\\"");
|
|
|
if(jobContent.length()>4000)
|
|
|
{
|
|
|
jobContent = jobContent.substring(0,4000);
|
|
|
}
|
|
|
log.setJobContent(jobContent);
|
|
|
log.setJobEndTime(new Date());
|
|
|
log.setJobDatasetCount(count);
|
|
|
log.setJobDatasetSuccess(success);
|
|
|
LogService.getLogger().info("任务结束,"+count+"个数据集成功采集"+success+"个。");
|
|
|
LogService.getLogger().info("任务结束," + count + "个数据集成功采集" + success + "个。");
|
|
|
datacollectLogDao.updateEntity(log);
|
|
|
}
|
|
|
|
|
@ -978,7 +796,7 @@ public class DatacollectService implements IDatacollectService {
|
|
|
@Transactional
|
|
|
public ActionResult repeatJob(String id) throws Exception
|
|
|
{
|
|
|
RsJobLogDetail log = datacollectLogDao.getEntity(RsJobLogDetail.class,id);
|
|
|
RsJobLogDetail log = datacollectLogDao.getEntity(RsJobLogDetail.class, id);
|
|
|
|
|
|
if(log.getJobStatus().equals("2")) {
|
|
|
return new ActionResult(false,"数据补采中!");
|