获取主键,not exists条件增加type

version1
admin 2 years ago
parent 77240ba39a
commit edc7c3f722

@ -60,7 +60,7 @@ public interface DbDao {
@Select("select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra as extra,table_name tableName, "
+ "concat('(',if(NUMERIC_PRECISION>0,CONVERT(NUMERIC_PRECISION,CHAR),''),if(NUMERIC_SCALE>0,concat(',',CONVERT(NUMERIC_SCALE,CHAR)),''),if(CHARACTER_MAXIMUM_LENGTH>0,CONVERT(CHARACTER_MAXIMUM_LENGTH,CHAR),''),')') as width "
+ " from information_schema.columns\r\n"
+ " where lower(table_name) = lower(#{tableName}) column_key='PRI' and table_schema = (select database()) order by ordinal_position")
+ " where lower(table_name) = lower(#{tableName}) and column_key='PRI' and table_schema = (select database()) order by ordinal_position")
List<Map<String, String>> listKeyMysql(String tableName);
@Select("select cname as \"columnName\",coltype as \"dataType\",cname \"columnComment\",'' as \"columnKey\",'' as \"extra\",tname \"tableName\", "
+" '('||decode(sign(PRECISION),1,to_char(PRECISION),'')||decode(sign(SCALE),1,','||to_char(SCALE),'')||decode(sign(PRECISION),1,'',decode(sign(SCALE),1,'',to_char(width)))||')' as width "

@ -178,13 +178,17 @@ public class IdcServiceImpl implements IdcService {
String[] tn = t.split("/");
String lastUpdateTime = getUpdateTime(tn[0]);
Date nowUpdateTime = new Date();
List<Map<String, String>> keyList = dbDao.listKeyMysql(tn[0]);
String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id";
Map<String,Object> map = new HashMap<String,Object>();
String sqlWhere = "not exists (select fkId from idc_record where fkId="+tn[0]+".id)";
String sqlWhere = "not exists (select fkId from idc_record where type='"+tn[0]+"' and fkId="+tn[0]+"."+keyColumn+")";
if(!StringUtils.isEmpty(tn[1])) {
sqlWhere+=" and "+tn[1]+">=cast('"+lastUpdateTime+"' as datetime)";
} else {
map.put("isEnd", "1");
}
if(tn[0].equals("thr_order"))
logger.info("-------------------"+sqlWhere);
map.put("sqlWhere", sqlWhere);
map.put("tableName", tn[0]);
map.put("filePathColumn", tn[2]);
@ -394,10 +398,14 @@ public class IdcServiceImpl implements IdcService {
String filePathColumn = params.get("filePathColumn")!=null ? params.get("filePathColumn").toString() : "";
orderNum++;
saveIdcLog(messageType,"",tableName +">"+where,0,total);
if(tableName.equals("thr_order"))
logger.info("tableName-->"+tableName+"-->row-->"+total+"-->sqlWhere-->"+where);
if(total>0) {
success = true;
params.put("page", 0);
params.put("limit", limit);
List<Map<String, String>> keyList = dbDao.listKeyMysql(tableName);
String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id";
for(int i=0;i<Math.ceil(total/limit)+1;i++) {
params.replace("page", i *limit);
params.replace("limit",limit);
@ -414,7 +422,7 @@ public class IdcServiceImpl implements IdcService {
files[m] = list.get(m).get(filePathColumn).toString();
}
recordSql+=!StringUtils.isEmpty(recordSql) ? "," : "";
recordSql+="('"+UUID.randomUUID().toString().replaceAll("-", "")+"','"+tableName+"','"+list.get(m).get("id")+"','"+isEnd+"',now())";
recordSql+="('"+UUID.randomUUID().toString().replaceAll("-", "")+"','"+tableName+"','"+list.get(m).get(keyColumn)+"','"+isEnd+"',now())";
}
orderNum++;
@ -721,7 +729,7 @@ public class IdcServiceImpl implements IdcService {
String updateTime = "";
Map<String,Object> map = dbDao.get("select * from idc_status where id='"+id+"'");
if(map!=null&&map.get("id")!=null) {
updateTime = DateUtil.formatDate(IDCUtils.parseDate(map.get("statusTime").toString()));
updateTime = DateUtil.formatDate(IDCUtils.parseDate(map.get("statusTime").toString()),"yyyy-MM-dd HH:mm:ss");
} else {
updateTime = "2000-01-01 00:00:00";
String sql = "insert into idc_status (id,statusTime) values ('"+id+"',cast('"+updateTime+"' as datetime))";

Loading…
Cancel
Save