增加单独生成任务方法

version1
chengqf 2 years ago
parent cf184ed2af
commit eb624a63f6

@ -72,6 +72,13 @@ public class IdcController {
return idcService.receive(request, content, files);
}
@RequestMapping(value = "/spssync/common/once")
@ResponseBody
public BaseResponse once(HttpServletRequest request,@RequestBody Map<String, Object> params) {
//
boolean isUpload = params.get("isUpload")!=null && params.get("isUpload").equals("1") ? true : false ;
return idcService.onceSync( params.get("tableName").toString(), isUpload);
}
//@Log("数据同步测试")
@RequestMapping(value = "/spssync/common/test")
public BaseResponse test(HttpServletRequest request, @RequestBody Map<String, Object> params) {

@ -36,4 +36,6 @@ public interface IdcService {
void asyncSpsTask();
void downloadFile(String fileName,HttpServletResponse response) ;
BaseResponse onceSync(String tableName,boolean isUpload);
}

@ -223,8 +223,34 @@ public class IdcServiceImpl implements IdcService {
}
}
private void syncData(String t, boolean isUpload, String syncIp) {
/*单独表调用tableName可只传表名如传完整参数按SYNCS_TABLES格式*/
@Override
public BaseResponse onceSync(String tableName,boolean isUpload) {
String tnames = tableName.contains("/") ? tableName : "//"+tableName+"///////";
String[] ts = tnames.split("/");
String ip="";
Map<String, Object> map = dbDao.get("select * from sync_data_set limit 1");
if(isUpload) {
if (!(map.get("syncIp") != null && !StringUtils.isEmpty(map.get("syncIp").toString()))) {
logger.error("中继服务地址未配置");
return ResultVOUtils.error(9999, "中继服务地址未配置");
}
ip = map.get("syncIp").toString();
}
if(!StringUtils.isEmpty(ts[0])) {
if(!(map!=null&&map.get(ts[0])!=null&&map.get(ts[0]).equals("1")))
return ResultVOUtils.error(9999, "当前不允许生成");
}
if(syncData(tnames,isUpload,ip))
return ResultVOUtils.success();
return ResultVOUtils.error(9999, "系统错误");
}
private boolean syncData(String t, boolean isUpload, String syncIp) {
boolean sync = true;
boolean result = false;
try {
String[] tnames = t.split("/");
String lastUpdateTime = getUpdateTime(tnames[2] + "." + tnames[0]);
@ -235,8 +261,15 @@ public class IdcServiceImpl implements IdcService {
String keyColumn = keyList != null && keyList.size() > 0 ? keyList.get(0).get("columnName").toString() : "id";
Map<String, Object> map = new HashMap<String, Object>();
String sqlWhere = "";
if (!StringUtils.isEmpty(tnames[6])) {
sqlWhere += " " + tnames[6] + ">= cast('" + lastUpdateTime + "' as datetime)";// and date_add(cast('"+DateUtil.formatDate(nowUpdateTime, "yyyy-MM-dd HH:mm:ss")+"' as datetime),INTERVAL 1 day)";
String updateTimeColumn = tnames[6];
if(StringUtils.isEmpty(updateTimeColumn)) {
Map<String,Object> tMap = dbDao.get("select column_name columnName from information_schema.columns where column_name='updateTime' and lower(table_name) = lower('"+tnames[0]+"') and table_schema = (select database()) limit 1");
updateTimeColumn = tMap !=null ? "updateTime" : "";
}
if (!StringUtils.isEmpty(updateTimeColumn)) {
sqlWhere += " " + updateTimeColumn + ">= cast('" + lastUpdateTime + "' as datetime)";// and date_add(cast('"+DateUtil.formatDate(nowUpdateTime, "yyyy-MM-dd HH:mm:ss")+"' as datetime),INTERVAL 1 day)";
sqlWhere += " and not exists (select fkId from idc_record where type='" + tnames[2] + "' and fkId=" + tnames[2] + "." + keyColumn + " and createTime>date_sub(now(),interval 15 MINUTE))";
} else {
sqlWhere = "not exists (select fkId from idc_record where type='" + tnames[2] + "' and fkId=" + tnames[2] + "." + keyColumn + ")";
@ -264,11 +297,16 @@ public class IdcServiceImpl implements IdcService {
sync = nextTimePoint.before(nowUpdateTime);
}
if (sync) {
if (syncMasterData(map, isUpload, syncIp)) {
result = syncMasterData(map, isUpload, syncIp);
if (result) {
setUpdateTime(tnames[2] + "." + tnames[0], DateUtil.formatDate(nowUpdateTime, "yyyy-MM-dd HH:mm:ss"));
}
}
//}
} catch (Exception ex) {
}
return result;
}
@ -507,11 +545,13 @@ public class IdcServiceImpl implements IdcService {
int childNum = -1;
/*子表*/
String[] syncTables = TableUtils.syncTables();
for (String str : syncTables) {
if (str.contains("/" + tableKey + "/")) {
childNum++;
childs[childNum] = str;
}
if(!StringUtils.isEmpty(tableKey)) {
for (String str : syncTables) {
if (str.contains("/" + tableKey + "/")) {
childNum++;
childs[childNum] = str;
}
}
}
Map<String, String> table = dbDao.getMysql(tableName);
if (!(table != null && table.get("tableName") != null))

Loading…
Cancel
Save