列名加饭引号,防止因关键字报错

version1
chengqf 2 years ago
parent eb624a63f6
commit d75721fbed

@ -70,7 +70,7 @@ public class IdcServiceImpl implements IdcService {
@Value("${API_SECRET}") @Value("${API_SECRET}")
private String apiSecret; private String apiSecret;
private int orderNum = 0; private int orderNum = 0;
@Resource @Resource
@ -94,47 +94,50 @@ public class IdcServiceImpl implements IdcService {
return ResultVOUtils.success(list); return ResultVOUtils.success(list);
} }
/*下载任务*/ /*下载任务*/
@Override @Override
public BaseResponse download(HttpServletRequest request, Map<String, Object> params) { public BaseResponse download(HttpServletRequest request, Map<String, Object> params) {
return statusFile(params,"basic_export_status"); return statusFile(params, "basic_export_status");
} }
@Override @Override
public BaseResponse uploadStatus(HttpServletRequest request, Map<String, Object> params) { public BaseResponse uploadStatus(HttpServletRequest request, Map<String, Object> params) {
return statusFile(params,"basic_upload_status"); return statusFile(params, "basic_upload_status");
} }
@Override @Override
public BaseResponse downloadStatus(HttpServletRequest request, Map<String, Object> params) { public BaseResponse downloadStatus(HttpServletRequest request, Map<String, Object> params) {
return statusFile(params,"basic_download_status"); return statusFile(params, "basic_download_status");
} }
private BaseResponse statusFile(Map<String,Object> params,String tableName) {
String id = ""; private BaseResponse statusFile(Map<String, Object> params, String tableName) {
if (params.containsKey("taskId") && params.get("taskId") != null) { String id = "";
id = params.get("taskId").toString(); if (params.containsKey("taskId") && params.get("taskId") != null) {
} else { id = params.get("taskId").toString();
id = params.get("id").toString(); } else {
} id = params.get("id").toString();
}
Map<String, Object> map = map = dbDao.get("select * from " + tableName + " where id='" + id + "'");
Map<String, Object> map = map = dbDao.get("select * from " + tableName + " where id='" + id + "'");
if (map == null)
return ResultVOUtils.error(9000, "下载任务不存在"); if (map == null)
if (!(map.get("cacheFilePath") != null && FileUtils.isFileExist(map.get("cacheFilePath").toString()))) return ResultVOUtils.error(9000, "下载任务不存在" + tableName);
return ResultVOUtils.error(9000, "下载文件不存在"); if (!(map.get("cacheFilePath") != null && FileUtils.isFileExist(map.get("cacheFilePath").toString())))
String json = FileUtils.readFileAll(map.get("cacheFilePath").toString()); return ResultVOUtils.error(9000, "下载文件不存在-" + tableName);
String json = FileUtils.readFileAll(map.get("cacheFilePath").toString());
JSONObject object = JSON.parseObject(json);
if (object == null) JSONObject object = JSON.parseObject(json);
return ResultVOUtils.error(9000, "任务下载失败"); if (object == null)
if (object != null && object.getInteger("code") != null) { return ResultVOUtils.error(9000, "任务下载失败");
BaseResponse response = JSON.parseObject(json, BaseResponse.class); if (object != null && object.getInteger("code") != null) {
return response; BaseResponse response = JSON.parseObject(json, BaseResponse.class);
} return response;
}
return ResultVOUtils.success(object);
return ResultVOUtils.success(object);
} }
/*UDI系统上传自助平台*/ /*UDI系统上传自助平台*/
@Override @Override
@ -197,7 +200,7 @@ public class IdcServiceImpl implements IdcService {
} }
} }
private void asyncDataTask(boolean isUpload) { private void asyncDataTask(boolean isUpload) {
initTable(); initTable();
Map<String, Object> map = dbDao.get("select * from sync_data_set limit 1"); Map<String, Object> map = dbDao.get("select * from sync_data_set limit 1");
@ -211,8 +214,7 @@ public class IdcServiceImpl implements IdcService {
String[] syncTables = TableUtils.syncTables(); String[] syncTables = TableUtils.syncTables();
for (int i = 0; i < syncTables.length; i++) { for (int i = 0; i < syncTables.length; i++) {
String[] tnames = syncTables[i].split("/"); String[] tnames = syncTables[i].split("/");
boolean sync = ((tnames[0]==null||StringUtils.isEmpty(tnames[0])||(tnames[0]!=null&&tnames[0].equals("null")))&& boolean sync = StringUtils.isEmpty(tnames[0]) ||
(tnames[1]==null||StringUtils.isEmpty(tnames[1])||(tnames[1]!=null&&tnames[1].equals("null"))))||
(!StringUtils.isEmpty(tnames[0]) && map != null && map.get(tnames[0]) != null && map.get(tnames[0]).toString().equals("1")); (!StringUtils.isEmpty(tnames[0]) && map != null && map.get(tnames[0]) != null && map.get(tnames[0]).toString().equals("1"));
saveIdcLog("---", "", map.get(tnames[0]) + syncTables[i], 0, 0); saveIdcLog("---", "", map.get(tnames[0]) + syncTables[i], 0, 0);
if (sync) { if (sync) {
@ -223,51 +225,51 @@ public class IdcServiceImpl implements IdcService {
} }
} }
/*单独表调用tableName可只传表名如传完整参数按SYNCS_TABLES格式*/ /*单独表调用tableName可只传表名如传完整参数按SYNCS_TABLES格式*/
@Override @Override
public BaseResponse onceSync(String tableName,boolean isUpload) { public BaseResponse onceSync(String tableName, boolean isUpload) {
String tnames = tableName.contains("/") ? tableName : "//"+tableName+"///////"; String tnames = tableName.contains("/") ? tableName : "//" + tableName + "///////";
String[] ts = tnames.split("/"); String[] ts = tnames.split("/");
String ip=""; String ip = "";
Map<String, Object> map = dbDao.get("select * from sync_data_set limit 1"); Map<String, Object> map = dbDao.get("select * from sync_data_set limit 1");
if(isUpload) { if (isUpload) {
if (!(map.get("syncIp") != null && !StringUtils.isEmpty(map.get("syncIp").toString()))) { if (!(map.get("syncIp") != null && !StringUtils.isEmpty(map.get("syncIp").toString()))) {
logger.error("中继服务地址未配置"); logger.error("中继服务地址未配置");
return ResultVOUtils.error(9999, "中继服务地址未配置"); return ResultVOUtils.error(9999, "中继服务地址未配置");
} }
ip = map.get("syncIp").toString(); ip = map.get("syncIp").toString();
} }
if(!StringUtils.isEmpty(ts[0])) { if (!StringUtils.isEmpty(ts[0])) {
if(!(map!=null&&map.get(ts[0])!=null&&map.get(ts[0]).equals("1"))) if (!(map != null && map.get(ts[0]) != null && map.get(ts[0]).equals("1")))
return ResultVOUtils.error(9999, "当前不允许生成"); return ResultVOUtils.error(9999, "当前不允许生成");
} }
if(syncData(tnames,isUpload,ip)) if (syncData(tnames, isUpload, ip))
return ResultVOUtils.success(); return ResultVOUtils.success();
return ResultVOUtils.error(9999, "系统错误"); return ResultVOUtils.error(9999, "系统错误");
} }
private boolean syncData(String t, boolean isUpload, String syncIp) { private boolean syncData(String t, boolean isUpload, String syncIp) {
boolean sync = true; boolean sync = true;
boolean result = false; boolean result = false;
try { try {
String[] tnames = t.split("/"); String[] tnames = t.split("/");
String lastUpdateTime = getUpdateTime(tnames[2] + "." + tnames[0]); String lastUpdateTime = getUpdateTime(tnames[2] + "." + tnames[0]);
Date nowUpdateTime = new Date(); Date nowUpdateTime = new Date();
//if (!StringUtils.isEmpty(tnames[0])) { // if (!StringUtils.isEmpty(tnames[0])) {
List<Map<String, String>> keyList = dbDao.listKeyMysql(tnames[2]); List<Map<String, String>> keyList = dbDao.listKeyMysql(tnames[2]);
String keyColumn = keyList != null && keyList.size() > 0 ? keyList.get(0).get("columnName").toString() : "id"; String keyColumn = keyList != null && keyList.size() > 0 ? keyList.get(0).get("columnName").toString() : "id";
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
String sqlWhere = ""; String sqlWhere = "";
String updateTimeColumn = tnames[6]; String updateTimeColumn = tnames[6];
if(StringUtils.isEmpty(updateTimeColumn)) { 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"); 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" : ""; updateTimeColumn = tMap != null ? "updateTime" : "";
} }
if (!StringUtils.isEmpty(updateTimeColumn)) { 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 += " " + 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))"; 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))";
@ -297,14 +299,14 @@ public class IdcServiceImpl implements IdcService {
sync = nextTimePoint.before(nowUpdateTime); sync = nextTimePoint.before(nowUpdateTime);
} }
if (sync) { if (sync) {
result = syncMasterData(map, isUpload, syncIp); result = syncMasterData(map, isUpload, syncIp);
if (result) { if (result) {
setUpdateTime(tnames[2] + "." + tnames[0], DateUtil.formatDate(nowUpdateTime, "yyyy-MM-dd HH:mm:ss")); setUpdateTime(tnames[2] + "." + tnames[0], DateUtil.formatDate(nowUpdateTime, "yyyy-MM-dd HH:mm:ss"));
} }
} }
//} //}
} catch (Exception ex) { } catch (Exception ex) {
} }
return result; return result;
} }
@ -359,7 +361,6 @@ public class IdcServiceImpl implements IdcService {
return result; return result;
} }
public BaseResponse downlaodSuccess(HttpServletRequest request, Map<String, Object> params) { public BaseResponse downlaodSuccess(HttpServletRequest request, Map<String, Object> params) {
String sql = "update basic_export_status set receiveStatus='1',endTime=now() where id='" + params.get("taskId") + "'"; String sql = "update basic_export_status set receiveStatus='1',endTime=now() where id='" + params.get("taskId") + "'";
@ -367,17 +368,19 @@ public class IdcServiceImpl implements IdcService {
return ResultVOUtils.success(); return ResultVOUtils.success();
} }
@Override @Override
public BaseResponse receiveJson(HttpServletRequest request,Map<String, Object> params) { public BaseResponse receiveJson(HttpServletRequest request, Map<String, Object> params) {
return ResultVOUtils.success(); return ResultVOUtils.success();
} }
@Override @Override
public BaseResponse uploadFile(HttpServletRequest request, public BaseResponse uploadFile(HttpServletRequest request,
String content,MultipartFile[] files) { String content, MultipartFile[] files) {
return ResultVOUtils.success(); return ResultVOUtils.success();
} }
/****/ /****/
@Override @Override
public BaseResponse receive(HttpServletRequest request, public BaseResponse receive(HttpServletRequest request,
@ -545,13 +548,13 @@ public class IdcServiceImpl implements IdcService {
int childNum = -1; int childNum = -1;
/*子表*/ /*子表*/
String[] syncTables = TableUtils.syncTables(); String[] syncTables = TableUtils.syncTables();
if(!StringUtils.isEmpty(tableKey)) { if (!StringUtils.isEmpty(tableKey)) {
for (String str : syncTables) { for (String str : syncTables) {
if (str.contains("/" + tableKey + "/")) { if (str.contains("/" + tableKey + "/")) {
childNum++; childNum++;
childs[childNum] = str; childs[childNum] = str;
} }
} }
} }
Map<String, String> table = dbDao.getMysql(tableName); Map<String, String> table = dbDao.getMysql(tableName);
if (!(table != null && table.get("tableName") != null)) if (!(table != null && table.get("tableName") != null))
@ -605,7 +608,7 @@ public class IdcServiceImpl implements IdcService {
String fileNames = list.get(m).get(filePathColumn).toString(); String fileNames = list.get(m).get(filePathColumn).toString();
String[] str = fileNames.split(","); String[] str = fileNames.split(",");
for (int r = 0; r < str.length; r++) { for (int r = 0; r < str.length; r++) {
if (!StringUtils.isEmpty(str[r])&&FileUtils.isFileExist(filePath + filePathSlash + "register/file/image2/" + str[r])) if (!StringUtils.isEmpty(str[r]) && FileUtils.isFileExist(filePath + filePathSlash + "register/file/image2/" + str[r]))
files.add(filePath + filePathSlash + "register/file/image2/" + str[r]); files.add(filePath + filePathSlash + "register/file/image2/" + str[r]);
} }
} }
@ -628,8 +631,8 @@ public class IdcServiceImpl implements IdcService {
if (childList.get(i).get(chidTnames[7]) != null) { if (childList.get(i).get(chidTnames[7]) != null) {
String[] str = childList.get(i).get(chidTnames[7]).toString().split(","); String[] str = childList.get(i).get(chidTnames[7]).toString().split(",");
for (int s = 0; s < str.length; s++) { for (int s = 0; s < str.length; s++) {
if (!StringUtils.isEmpty(str[s])&&FileUtils.isFileExist(filePath + filePathSlash + "register/file/image2/" + str[s])) if (!StringUtils.isEmpty(str[s]) && FileUtils.isFileExist(filePath + filePathSlash + "register/file/image2/" + str[s]))
files.add(filePath + filePathSlash + "register/file/image2/" + str[s]); files.add(filePath + filePathSlash + "register/file/image2/" + str[s]);
} }
} }
} }
@ -682,7 +685,8 @@ public class IdcServiceImpl implements IdcService {
} }
/*增加同步任务状态*/ /*增加同步任务状态*/
private void syncAddTaskStatus(Map<String, Object> json, int scheduleType, boolean success, Date startTime, boolean isEnd) { private void syncAddTaskStatus(Map<String, Object> json, int scheduleType, boolean success, Date startTime,
boolean isEnd) {
try { try {
String content = JSON.toJSONString(json); String content = JSON.toJSONString(json);
String datePath = DateUtil.formatDate(new Date(), "yyyy-MM-dd"); String datePath = DateUtil.formatDate(new Date(), "yyyy-MM-dd");
@ -725,7 +729,8 @@ public class IdcServiceImpl implements IdcService {
} }
private boolean analyMiddle(String host, JSONObject jsonObject, MultipartFile[] files, boolean isUpload, boolean isToDB) { private boolean analyMiddle(String host, JSONObject jsonObject, MultipartFile[] files, boolean isUpload,
boolean isToDB) {
if (jsonObject.get("data") != null) { if (jsonObject.get("data") != null) {
String tableName = ""; String tableName = "";
String uniqueColumn = ""; String uniqueColumn = "";
@ -788,9 +793,11 @@ public class IdcServiceImpl implements IdcService {
/*解析到数据库*/ /*解析到数据库*/
/*按表名解析数据到数据库,子表暂未处理*/ /*按表名解析数据到数据库,子表暂未处理*/
private boolean analyToDB(String host, String tableName, String uniqueColumn, String filePathColumn, List<Map<String, Object>> list, boolean isUpload) { private boolean analyToDB(String host, String tableName, String uniqueColumn, String
filePathColumn, List<Map<String, Object>> list, boolean isUpload) {
String tName = DBAUtils.tableRealName(tableName);
String tName = DBAUtils.tableRealName(tableName);
String sql = "replace " + tName + "("; String sql = "replace " + tName + "(";
String del = "delete from " + tName + " where "; String del = "delete from " + tName + " where ";
String upd = "update " + tName + " set "; String upd = "update " + tName + " set ";
@ -804,7 +811,7 @@ public class IdcServiceImpl implements IdcService {
if (col > 0) if (col > 0)
sql += ","; sql += ",";
columnList.get(i).put("attrName", columnList.get(i).get("columnName")); columnList.get(i).put("attrName", columnList.get(i).get("columnName"));
sql += columnList.get(i).get("columnName").toString(); sql += "`"+columnList.get(i).get("columnName").toString()+"`";
col++; col++;
if (uniqueColumn != null && columnList.get(i).get("columnKey") != null && ("," + uniqueColumn + ",").contains("," + columnList.get(i).get("columnName") + ",")) { if (uniqueColumn != null && columnList.get(i).get("columnKey") != null && ("," + uniqueColumn + ",").contains("," + columnList.get(i).get("columnName") + ",")) {
keyColumn[key] = columnList.get(i).get("columnName").toString(); keyColumn[key] = columnList.get(i).get("columnName").toString();
@ -1075,7 +1082,8 @@ public class IdcServiceImpl implements IdcService {
} }
/*由表名获取数据*/ /*由表名获取数据*/
private Map<String, Object> getData(String messageType, String tableName, Map<String, Object> params, Map<String, Object> whereParams) { private Map<String, Object> getData(String messageType, String
tableName, Map<String, Object> params, Map<String, Object> whereParams) {
List<Map<String, Object>> list = getList(tableName, whereParams); List<Map<String, Object>> list = getList(tableName, whereParams);
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("messageId", CustomUtil.getId()); map.put("messageId", CustomUtil.getId());
@ -1092,7 +1100,8 @@ public class IdcServiceImpl implements IdcService {
} }
private SystemParamConfigEntity getSystemParamConfig(String paramKey, String paramName, String defaultValue, String paramExplain) { private SystemParamConfigEntity getSystemParamConfig(String paramKey, String paramName, String
defaultValue, String paramExplain) {
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(paramKey); SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(paramKey);
if (systemParamConfigEntity == null || (systemParamConfigEntity != null && StringUtils.isEmpty(systemParamConfigEntity.getParamKey()))) { if (systemParamConfigEntity == null || (systemParamConfigEntity != null && StringUtils.isEmpty(systemParamConfigEntity.getParamKey()))) {
systemParamConfigEntity = new SystemParamConfigEntity(); systemParamConfigEntity = new SystemParamConfigEntity();
@ -1194,13 +1203,13 @@ public class IdcServiceImpl implements IdcService {
alterTable("idc_log", "create table idc_log (id varchar(36),orderNum int,taskId varchar(60),type varchar(60),content varchar(2000),offset int,total int,createTime datetime,PRIMARY KEY (id))"); alterTable("idc_log", "create table idc_log (id varchar(36),orderNum int,taskId varchar(60),type varchar(60),content varchar(2000),offset int,total int,createTime datetime,PRIMARY KEY (id))");
dbDao.delete("delete from idc_record where createTime<date_sub(now(),interval 2 day) and isEnd='0'"); dbDao.delete("delete from idc_record where createTime<date_sub(now(),interval 2 day) and isEnd='0'");
try { try {
executeSql("alter table basic_export_status add column cacheFilePath varchar(255)"); executeSql("alter table basic_export_status add column cacheFilePath varchar(255)");
executeSql("alter table basic_upload_status add column cacheFilePath varchar(255)"); executeSql("alter table basic_upload_status add column cacheFilePath varchar(255)");
executeSql("alter table idc_status modify column id varchar(100)"); executeSql("alter table idc_status modify column id varchar(100)");
executeSql("delete from idc_log where createTime<date_sub(now(),interval 3 day)"); executeSql("delete from idc_log where createTime<date_sub(now(),interval 3 day)");
executeSql("alter table basic_export_status add column msg varchar(255)"); executeSql("alter table basic_export_status add column msg varchar(255)");
executeSql("alter table basic_upload_status add column msg varchar(255)"); executeSql("alter table basic_upload_status add column msg varchar(255)");
executeSql("alter table basic_download_status add column msg varchar(255)"); executeSql("alter table basic_download_status add column msg varchar(255)");
} catch (Exception e) { } catch (Exception e) {
} }
@ -1209,19 +1218,19 @@ public class IdcServiceImpl implements IdcService {
private void alterTable(String tableName, String sql) { private void alterTable(String tableName, String sql) {
Map<String, String> map = dbDao.getMysql(tableName); Map<String, String> map = dbDao.getMysql(tableName);
if (!(map != null && map.get("tableName") != null)) { if (!(map != null && map.get("tableName") != null)) {
executeSql(sql); executeSql(sql);
} }
} }
private void executeSql(String sql) { private void executeSql(String sql) {
try { try {
jdbcTemplate.execute(sql); jdbcTemplate.execute(sql);
} catch (Exception e) { } catch (Exception e) {
} }
} }
} }
Loading…
Cancel
Save