import java.io.File;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class XMLReader {
public static void reader(String readPath, JDBCConnector front, JDBCConnector rest){
//readPath = "F:/knowledgeExport";
File dir = new File(readPath);
File[] files = dir.listFiles();
for(int j=0;j<files.length;j++){
System.out.println((files[j].isDirectory()?"目录:":"文件:")+files[j].getName());
try {
//File f = new File("c:/work/project/xml/aaron.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(files[j]);
//NodeList nl = doc.getElementsByTagName("root");
String tableName = doc.getElementsByTagName("table_name").item(0).getFirstChild().getNodeValue();
//System.out.println("system_id:"+ doc.getElementsByTagName("system_id").item(0).getFirstChild().getNodeValue());
System.out.println("table_name:"+ doc.getElementsByTagName("table_name").item(0).getFirstChild().getNodeValue());
//NodeList dl = doc.getElementsByTagName("datalist");
//System.out.println("dl:"+dl.getLength());
NodeList data = doc.getElementsByTagName("data");
System.out.println("data-num:"+data.getLength());
if("info_source_ general".equals(tableName)){
//信源表不让改字段 暂时导入无法做 先放着
}else if("class_content".equals(tableName)){//classType=0
yqpt_knowledge_class(doc, data, 0, front, rest);
}else if("class_person".equals(tableName)){//classType=1
yqpt_knowledge_class(doc, data, 1, front, rest);
}else if("class_organ".equals(tableName)){//classType=2
yqpt_knowledge_class(doc, data, 2, front, rest);
}else if("class_expert".equals(tableName)){//classType=6
yqpt_knowledge_class(doc, data, 6, front, rest);
}else if("class_word".equals(tableName)){
yqpt_knowledge_words(doc, data, front, rest);
}else if("personage_personage".equals(tableName)){
yqpt_knowledge_personage(doc, data, front, rest);
}else if("personage_organ".equals(tableName)){
yqpt_knowledge_organ(doc, data, front, rest);
}else if("personage_expert".equals(tableName)){
yqpt_knowledge_professor(doc, data, front, rest);
}else if("date_service_work".equals(tableName)){//业务工作时间库
knowledge_service_time(doc, data, front, rest);
}else if("date_time_node".equals(tableName)){//重要时间节点 历史事件
yqpt_knowledge_event(doc, data, front, rest);
}else if("region_name".equals(tableName)){
yqpt_knowledge_region(doc, data, front, rest);
}else if("sentiment_word".equals(tableName)){
yqpt_knowledge_sentiment_word(doc, data, front, rest);
}else{
}
/* for (int i = 0; i < data.getLength(); i++) {
System.out.println("system_id:"+ doc.getElementsByTagName("system_id").item(i).getFirstChild().getNodeValue());
System.out.println("table_name:"+ doc.getElementsByTagName("table_name").item(i).getFirstChild().getNodeValue());
}*/
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* <p>table knowledge_service_time</p>
* <p>业务工作时间库数据导入</p>
* <p>返回</p>
* @author Lingdong
* @since 2014-5-27 下午02:26:30
* @param doc
* @param data
* @param front
* @param rest
*/
public static void knowledge_service_time(Document doc, NodeList data, JDBCConnector front, JDBCConnector rest){
//data_id,date,cycle,intro,range,prompt_start,source,u_time,u_user,u_type
//id,work_date,cycle,cycle_unit,describ,prompt_range,range_names,prompt_start,prompt_start_unit,state,source,create_time,create_user,modify_time,modify_user,u_type,system_id
for (int i = 0; i < data.getLength(); i++) {
String id = doc.getElementsByTagName("data_id").item(i).getFirstChild().getNodeValue();
String date = doc.getElementsByTagName("date").item(i).getFirstChild().getNodeValue();
String cycle = doc.getElementsByTagName("cycle").item(i).getFirstChild().getNodeValue();
String intro = doc.getElementsByTagName("intro").item(i).getFirstChild().getNodeValue();
String range = doc.getElementsByTagName("range").item(i).getFirstChild().getNodeValue();
String prompt_start = doc.getElementsByTagName("prompt_start").item(i).getFirstChild().getNodeValue();
String source = "";
if(doc.getElementsByTagName("source").item(i).hasChildNodes()){//判断节点是否为空
source = doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
}
String uTime = "null";
if(doc.getElementsByTagName("u_time").item(i).hasChildNodes()){//判断节点是否为空
uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
}
String userName = "null";
if(doc.getElementsByTagName("u_user").item(i).hasChildNodes()){//判断节点是否为空
userName = doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
}
String uType = doc.getElementsByTagName("u_type").item(i).getFirstChild().getNodeValue();
if("null".equals(uTime)||XString.isNullOrEmpty(uTime)){
uTime = DateUtil.getNowTime4String();//时间为空则用当前时间
}
String inserFrontSql = " INSERT INTO knowledge_service_time select null, '" + date + "','" + cycle
+ "','','" + uTime + "', id, '" + uTime + "', id, " + id + " from user where name='" + userName + "' ";
if("null".equals(userName)||XString.isNullOrEmpty(userName)){
inserFrontSql = " INSERT INTO knowledge_service_time values (null, '" + date + "','" + cycle
+ "','','" + uTime + "', null, '" + uTime + "', null, " + id + ") ";
}
String sql = "";
if("1".equals(uType)){//添加操作
//根据system_id先删除一下要导入的数据 防止重复
sql = " delete from knowledge_service_time where system_id=" + id;
front.updateBySql(sql);
sql = inserFrontSql;
front.updateBySql(sql);
}else if("2".equals(uType)){//修改操作
sql = " update knowledge_service_time set work_date='" + date + "',cycle='" + cycle
+ "', modify_time='"
+ uTime + "', modify_user=(select id from user where name='" + userName + "') where system_id=" + id;
front.updateBySql(sql);
}else{//删除操作
sql = " delete from knowledge_service_time where system_id=" + id;
front.updateBySql(sql);
}
}
}
/**
* <p>table yqpt_knowledge_professor knowledge_professor</p>
* <p>专家库数据导入</p>
* <p>返回</p>
* @author Lingdong
* @since 2014-5-26 下午03:56:26
* @param doc
* @param data
* @param front
* @param rest
*/
public static void yqpt_knowledge_professor(Document doc, NodeList data, JDBCConnector front, JDBCConnector rest){
//data_id,expert_name,class_id,organ,nationality,duty,research_field,viewpoint,blog,weibo,user_id,source,u_time,u_user,u_type
//id,name,class_id,class_names,organ,nationality,job,main_research,viewpoint,board_id,blog,weibo,state,source,create_time,flag,u_type,system_id
for (int i = 0; i < data.getLength(); i++) {
String id = doc.getElementsByTagName("data_id").item(i).getFirstChild().getNodeValue();
String expert_name = doc.getElementsByTagName("expert_name").item(i).getFirstChild().getNodeValue();
String class_id = doc.getElementsByTagName("class_id").item(i).getFirstChild().getNodeValue();
if(!XString.isNullOrEmpty(class_id)){//如果不为空 转换成YQ系统中需要的格式
class_id = "[" + class_id.replace(";", "],[") + "]";
}
String nationality = doc.getElementsByTagName("nationality").item(i).getFirstChild().getNodeValue();
String organ = "";
String duty = "";
String research_field = "";
String viewpoint = "";
String blog = "";
String weibo = "";
String user_id = "";
if(doc.getElementsByTagName("organ").item(i).hasChildNodes()){//判断节点是否为空
organ = doc.getElementsByTagName("organ").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("duty").item(i).hasChildNodes()){//判断节点是否为空
duty = doc.getElementsByTagName("duty").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("research_field").item(i).hasChildNodes()){//判断节点是否为空
research_field = doc.getElementsByTagName("research_field").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("viewpoint").item(i).hasChildNodes()){//判断节点是否为空
viewpoint = doc.getElementsByTagName("viewpoint").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("blog").item(i).hasChildNodes()){//判断节点是否为空
blog = doc.getElementsByTagName("blog").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("weibo").item(i).hasChildNodes()){//判断节点是否为空
weibo = doc.getElementsByTagName("weibo").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("user_id").item(i).hasChildNodes()){//判断节点是否为空
user_id = doc.getElementsByTagName("user_id").item(i).getFirstChild().getNodeValue();
}
String source = "";
if(doc.getElementsByTagName("source").item(i).hasChildNodes()){//判断节点是否为空
source = doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
}
String uTime = "null";
if(doc.getElementsByTagName("u_time").item(i).hasChildNodes()){//判断节点是否为空
uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
}
String userName = "null";
if(doc.getElementsByTagName("u_user").item(i).hasChildNodes()){//判断节点是否为空
userName = doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
}
String uType = doc.getElementsByTagName("u_type").item(i).getFirstChild().getNodeValue();
if("null".equals(uTime)||XString.isNullOrEmpty(uTime)){
uTime = DateUtil.getNowTime4String();//时间为空则用当前时间
}
String inserFrontSql = " INSERT INTO knowledge_professor select :id:, '" + expert_name + "','" + class_id
+ "',''," + user_id + ",'" + uTime + "', id, '" + uTime + "', id, " + id + " from user where name='" + userName + "' ";
if("null".equals(userName)||XString.isNullOrEmpty(userName)){
inserFrontSql = " INSERT INTO knowledge_professor values (:id:, '" + expert_name + "','" + class_id
+ "',''," + user_id + ",'" + uTime + "', null, '" + uTime + "', null, " + id + ") ";
}
String sql = "";
if("1".equals(uType)){//添加操作
//根据system_id先删除一下要导入的数据 防止重复
sql = " delete from yqpt_knowledge_professor where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_professor where system_id=" + id;
front.updateBySql(sql);
sql = " INSERT INTO yqpt_knowledge_professor VALUES(null, '" + expert_name + "','" + class_id + "','','"
+ organ + "','" + nationality + "','" + duty + "','" + research_field + "','" + viewpoint + "'," + user_id
+ ", '" + blog + "','" + weibo + "',0,'" + source + "','" + uTime + "',null,1," + id + ") ";
rest.updateBySql(sql);
int lastid = rest.findLastInsertId();//获取最后插入的id 入前台库表 id要rest和front同步
sql = inserFrontSql.replace(":id:", lastid+"");//替换为具体id
front.updateBySql(sql);
//data_id,expert_name,class_id,organ,nationality,duty,research_field,viewpoint,blog,weibo,user_id,source,u_time,u_user,u_type
//id,name,class_id,class_names,organ,nationality,job,main_research,viewpoint,board_id,blog,weibo,state,source,create_time,flag,u_type,system_id
}else if("2".equals(uType)){//修改操作
sql = " update yqpt_knowledge_professor set name='" + expert_name + "',class_id='" + class_id
+ "',organ='" + organ + "',job='" + duty + "',viewpoint='" + viewpoint
+ "',blog='" + blog + "',nationality='" + nationality + "',weibo='" + weibo
+ "',main_research='" + research_field + "',state=0, u_type=1,source='"
+ source + "' where system_id=" + id;
rest.updateBySql(sql);
sql = " update knowledge_professor set name='" + expert_name + "',class_id='" + class_id
+ "',board_id=" + user_id + ", modify_time='"
+ uTime + "', modify_user=(select id from user where name='" + userName + "') where system_id=" + id;
front.updateBySql(sql);
}else{//删除操作
sql = " delete from yqpt_knowledge_professor where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_professor where system_id=" + id;
front.updateBySql(sql);
}
}
}
/**
* <p>table yqpt_knowledge_organ knowledge_organ</p>
* <p>机构库数据导入</p>
* <p>返回</p>
* @author Lingdong
* @since 2014-5-26 下午02:47:32
* @param doc
* @param data
* @param front
* @param rest
*/
public static void yqpt_knowledge_organ(Document doc, NodeList data, JDBCConnector front, JDBCConnector rest){
//data_id,name,class_id,site_name,site_url,viewpoint,main_research,intro,nationality,importance,activity,source,u_time,u_user,u_type
for (int i = 0; i < data.getLength(); i++) {
String id = doc.getElementsByTagName("data_id").item(i).getFirstChild().getNodeValue();
String name = doc.getElementsByTagName("name").item(i).getFirstChild().getNodeValue();
String class_id = doc.getElementsByTagName("class_id").item(i).getFirstChild().getNodeValue();
if(!XString.isNullOrEmpty(class_id)){//如果不为空 转换成YQ系统中需要的格式
class_id = "[" + class_id.replace(";", "],[") + "]";
}
String site_name = "";
String site_url = "";
String viewpoint = "";
String main_research = "";
String intro = "";
if(doc.getElementsByTagName("site_name").item(i).hasChildNodes()){//判断节点是否为空
site_name = doc.getElementsByTagName("site_name").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("site_url").item(i).hasChildNodes()){//判断节点是否为空
site_url = doc.getElementsByTagName("site_url").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("viewpoint").item(i).hasChildNodes()){//判断节点是否为空
viewpoint = doc.getElementsByTagName("viewpoint").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("main_research").item(i).hasChildNodes()){//判断节点是否为空
main_research = doc.getElementsByTagName("main_research").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("intro").item(i).hasChildNodes()){//判断节点是否为空
intro = doc.getElementsByTagName("intro").item(i).getFirstChild().getNodeValue();
}
String nationality = doc.getElementsByTagName("nationality").item(i).getFirstChild().getNodeValue();
String importance = doc.getElementsByTagName("importance").item(i).getFirstChild().getNodeValue();
String activity = doc.getElementsByTagName("activity").item(i).getFirstChild().getNodeValue();
String source = "";
if(doc.getElementsByTagName("source").item(i).hasChildNodes()){//判断节点是否为空
source = doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
}
String uTime = "null";
if(doc.getElementsByTagName("u_time").item(i).hasChildNodes()){//判断节点是否为空
uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
}
String userName = "null";
if(doc.getElementsByTagName("u_user").item(i).hasChildNodes()){//判断节点是否为空
userName = doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
}
String uType = doc.getElementsByTagName("u_type").item(i).getFirstChild().getNodeValue();
if("null".equals(uTime)||XString.isNullOrEmpty(uTime)){
uTime = DateUtil.getNowTime4String();//时间为空则用当前时间
}
String inserFrontSql = " INSERT INTO knowledge_organ select :id:, '" + name + "','" + class_id + "','"
+ uTime + "', id, '" + uTime + "', id, " + id + " from user where name='" + userName + "' ";
if("null".equals(userName)||XString.isNullOrEmpty(userName)){
inserFrontSql = " INSERT INTO knowledge_organ values (:id:, '" + name + "','" + class_id + "','"
+ uTime + "', null, '" + uTime + "', null, " + id + ") ";
}
String sql = "";
if("1".equals(uType)){//添加操作
//根据system_id先删除一下要导入的数据 防止重复
sql = " delete from yqpt_knowledge_organ where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_organ where system_id=" + id;
front.updateBySql(sql);
sql = " INSERT INTO yqpt_knowledge_organ VALUES(null, '" + name + "','" + class_id + "','','"
+ intro + "','" + nationality + "','','" + main_research + "','" + viewpoint + "','" + site_name
+ "','" + site_url
+ "'," + importance + "," + activity + ",null,1,'" + source + "','" + uTime + "',1," + id + ") ";
rest.updateBySql(sql);
int lastid = rest.findLastInsertId();//获取最后插入的id 入前台库表 id要rest和front同步
sql = inserFrontSql.replace(":id:", lastid+"");//替换为具体id
front.updateBySql(sql);
}else if("2".equals(uType)){//修改操作
sql = " update yqpt_knowledge_organ set name='" + name + "',class_id='" + class_id
+ "',site_name='" + site_name + "',site_url='" + site_url + "',viewpoint='" + viewpoint
+ "',intro='" + intro + "',nationality='" + nationality + "',importance_degree=" + importance
+ ",active_degree=" + activity + ",main_research='" + main_research + "',state=0, u_type=1,source='"
+ source + "' where system_id=" + id;
rest.updateBySql(sql);
sql = " update knowledge_organ set name='" + name + "',class_ids='" + class_id + "', modify_time='"
+ uTime + "', modify_user=(select id from user where name='" + userName + "') where system_id=" + id;
front.updateBySql(sql);
}else{//删除操作
sql = " delete from yqpt_knowledge_organ where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_organ where system_id=" + id;
front.updateBySql(sql);
}
}
}
/**
* <p>table yqpt_knowledge_personage knowledge_personage</p>
* <p>人物库数据导入</p>
* <p>返回</p>
* @author Lingdong
* @since 2014-5-26 下午01:56:54
* @param doc
* @param data
* @param front
* @param rest
*/
public static void yqpt_knowledge_personage(Document doc, NodeList data, JDBCConnector front, JDBCConnector rest){
//data_id,name,class_id,site_name,site_url,job,intro,nationality,importance,activity,source,u_time,u_user,u_type
for (int i = 0; i < data.getLength(); i++) {
String id = doc.getElementsByTagName("data_id").item(i).getFirstChild().getNodeValue();
String name = doc.getElementsByTagName("name").item(i).getFirstChild().getNodeValue();
String class_id = doc.getElementsByTagName("class_id").item(i).getFirstChild().getNodeValue();
if(!XString.isNullOrEmpty(class_id)){//如果不为空 转换成YQ系统中需要的格式
class_id = "[" + class_id.replace(";", "],[") + "]";
}
String site_name = "";
String site_url = "";
String job = "";
String intro = "";
if(doc.getElementsByTagName("site_name").item(i).hasChildNodes()){//判断节点是否为空
site_name = doc.getElementsByTagName("site_name").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("site_url").item(i).hasChildNodes()){//判断节点是否为空
site_url = doc.getElementsByTagName("site_url").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("job").item(i).hasChildNodes()){//判断节点是否为空
job = doc.getElementsByTagName("job").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("intro").item(i).hasChildNodes()){//判断节点是否为空
intro = doc.getElementsByTagName("intro").item(i).getFirstChild().getNodeValue();
}
String nationality = doc.getElementsByTagName("nationality").item(i).getFirstChild().getNodeValue();
String importance = doc.getElementsByTagName("importance").item(i).getFirstChild().getNodeValue();
String activity = doc.getElementsByTagName("activity").item(i).getFirstChild().getNodeValue();
String source = "";
if(doc.getElementsByTagName("source").item(i).hasChildNodes()){//判断节点是否为空
source = doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
}
String uTime = "null";
if(doc.getElementsByTagName("u_time").item(i).hasChildNodes()){//判断节点是否为空
uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
}
String userName = "null";
if(doc.getElementsByTagName("u_user").item(i).hasChildNodes()){//判断节点是否为空
userName = doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
}
String uType = doc.getElementsByTagName("u_type").item(i).getFirstChild().getNodeValue();
if("null".equals(uTime)||XString.isNullOrEmpty(uTime)){
uTime = DateUtil.getNowTime4String();//时间为空则用当前时间
}
String inserFrontSql = " INSERT INTO knowledge_personage select :id:, '" + name + "','" + class_id + "','"
+ uTime + "', id, '" + uTime + "', id, " + id + " from user where name='" + userName + "' ";
if("null".equals(userName)||XString.isNullOrEmpty(userName)){
inserFrontSql = " INSERT INTO knowledge_personage values (:id:, '" + name + "','" + class_id + "','"
+ uTime + "', null, '" + uTime + "', null, " + id + ") ";
}
String sql = "";
if("1".equals(uType)){//添加操作
//根据system_id先删除一下要导入的数据 防止重复
sql = " delete from yqpt_knowledge_personage where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_personage where system_id=" + id;
front.updateBySql(sql);
sql = " INSERT INTO yqpt_knowledge_personage VALUES(null, '" + class_id + "','', '" + name + "','"
+ site_name + "','" + site_url + "','" + job + "','" + intro + "','" + nationality
+ "'," + importance + "," + activity + ",0,'" + source + "','" + uTime + "',1," + id + ") ";
rest.updateBySql(sql);
int lastid = rest.findLastInsertId();//获取最后插入的id 入前台库表 id要rest和front同步
sql = inserFrontSql.replace(":id:", lastid+"");//替换为具体id
front.updateBySql(sql);
}else if("2".equals(uType)){//修改操作
sql = " update yqpt_knowledge_personage set person_name='" + name + "',class_ids='" + class_id
+ "',site_name='" + site_name + "',site_url='" + site_url + "',job='" + job
+ "',intro='" + intro + "',nationality='" + nationality + "',import_degree=" + importance
+ ",active_degree=" + activity + ",state=0, u_type=1,source='"
+ source + "' where system_id=" + id;
rest.updateBySql(sql);
sql = " update knowledge_personage set person_name='" + name + "',class_ids='" + class_id + "', modify_time='"
+ uTime + "', modify_user=(select id from user where name='" + userName + "') where system_id=" + id;
front.updateBySql(sql);
}else{//删除操作
sql = " delete from yqpt_knowledge_personage where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_personage where system_id=" + id;
front.updateBySql(sql);
}
}
}
/**
* <p>table yqpt_knowledge_sentiment_word</p>
* <p>情感词库数据导入</p>
* <p>返回</p>
* @author Lingdong
* @since 2014-5-26 上午11:12:18
* @param doc
* @param data
* @param front
* @param rest
*/
public static void yqpt_knowledge_sentiment_word(Document doc, NodeList data, JDBCConnector front, JDBCConnector rest){
//data_id,word,word_prop,frequency,source,u_time,u_user,u_type,
for (int i = 0; i < data.getLength(); i++) {
String id = doc.getElementsByTagName("data_id").item(i).getFirstChild().getNodeValue();
String word = doc.getElementsByTagName("word").item(i).getFirstChild().getNodeValue();
String word_prop = doc.getElementsByTagName("word_prop").item(i).getFirstChild().getNodeValue();
String frequency = doc.getElementsByTagName("frequency").item(i).getFirstChild().getNodeValue();
String uType = doc.getElementsByTagName("u_type").item(i).getFirstChild().getNodeValue();
String source = "";
if(doc.getElementsByTagName("source").item(i).hasChildNodes()){//判断节点是否为空
source = doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
}
String uTime = "null";
if(doc.getElementsByTagName("u_time").item(i).hasChildNodes()){//判断节点是否为空
uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
}
/*String userName = "null";
if(doc.getElementsByTagName("u_user").item(i).hasChildNodes()){//判断节点是否为空
userName = doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
}*/
if("null".equals(uTime)||XString.isNullOrEmpty(uTime)){
uTime = DateUtil.getNowTime4String();//时间为空则用当前时间
}
String sql = "";
if("1".equals(uType)){//添加操作
//根据system_id先删除一下要导入的数据 防止重复
sql = " delete from yqpt_knowledge_sentiment_word where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from yqpt_knowledge_sentiment_word where system_id=" + id + " or word='" + word + "' ";
rest.updateBySql(sql);
sql = " INSERT INTO yqpt_knowledge_sentiment_word VALUES(null, '" + word + "', '" + word_prop
+ "'," + frequency + ",1,'" + source + "','" + uTime + "',1," + id + ") ";
rest.updateBySql(sql);
}else if("2".equals(uType)){//修改操作
sql = " update yqpt_knowledge_sentiment_word set word='" + word + "',word_prop='" + word_prop
+ "',frequency=" + frequency + ",source='"
+ source + "', u_type=1 where system_id=" + id;
rest.updateBySql(sql);
}else{//删除操作
sql = " delete from yqpt_knowledge_sentiment_word where system_id=" + id;
rest.updateBySql(sql);
}
}
}
/**
* <p>table yqpt_knowledge_region knowledge_region</p>
* <p>地名库 数据导入</p>
* <p>返回</p>
* @author Lingdong
* @since 2014-5-23 下午04:17:58
* @param doc
* @param data
* @param front
* @param rest
*/
public static void yqpt_knowledge_region(Document doc, NodeList data, JDBCConnector front, JDBCConnector rest){
for (int i = 0; i < data.getLength(); i++) {
String id = doc.getElementsByTagName("data_id").item(i).getFirstChild().getNodeValue();
String name = doc.getElementsByTagName("name").item(i).getFirstChild().getNodeValue();
String province = doc.getElementsByTagName("province").item(i).getFirstChild().getNodeValue();
String country = doc.getElementsByTagName("country").item(i).getFirstChild().getNodeValue();
String frequency = doc.getElementsByTagName("frequency").item(i).getFirstChild().getNodeValue();
String source = "";
if(doc.getElementsByTagName("source").item(i).hasChildNodes()){//判断节点是否为空
source = doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
}
String uTime = "null";
if(doc.getElementsByTagName("u_time").item(i).hasChildNodes()){//判断节点是否为空
uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
}
String userName = "null";
if(doc.getElementsByTagName("u_user").item(i).hasChildNodes()){//判断节点是否为空
userName = doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
}
String uType = doc.getElementsByTagName("u_type").item(i).getFirstChild().getNodeValue();
if("null".equals(uTime)||XString.isNullOrEmpty(uTime)){
uTime = DateUtil.getNowTime4String();//时间为空则用当前时间
}
String inserFrontSql = " INSERT INTO knowledge_region select :id:, '" + name + "',0,'" + uTime
+ "', id, '" + uTime + "', id, " + id + " from user where name='" + userName + "' ";
if("null".equals(userName)||XString.isNullOrEmpty(userName)){
inserFrontSql = " INSERT INTO knowledge_words values (:id:, '" + name + "',0,'"
+ uTime + "', null, '" + uTime + "', null, " + id + ") ";
}
String sql = "";
if("1".equals(uType)){//添加操作 根据system_id或name先删除一下要导入的数据 防止重复
sql = " delete from yqpt_knowledge_region where system_id=" + id + " or name='" + name + "' ";
rest.updateBySql(sql);
sql = " delete from knowledge_region where name='" + name + "' ";
front.updateBySql(sql);
sql = " INSERT INTO yqpt_knowledge_region VALUES(null, '" + name + "', '" + province
+ "','" + country + "'," + frequency + ",0,'" + source + "',0,'" + uTime + "',1," + id + ") ";
rest.updateBySql(sql);
int lastid = rest.findLastInsertId();//获取最后插入的id 入前台库表 id要rest和front同步
sql = inserFrontSql.replace(":id:", lastid+"");//替换为具体id
front.updateBySql(sql);
}else if("2".equals(uType)){//修改操作
sql = " update yqpt_knowledge_region set name='" + name + "',province='" + province
+ "',country='" + country + "',frequency=" + frequency + ",source='"
+ source + "', u_type=1 where system_id=" + id;
rest.updateBySql(sql);
sql = " update knowledge_region set name='" + name + "', modify_time='" + uTime
+ "', modify_user=(select id from user where name='" + userName + "') where system_id=" + id;
front.updateBySql(sql);
}else{//删除操作
sql = " delete from yqpt_knowledge_region where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_region where system_id=" + id;
front.updateBySql(sql);
}
}
}
/**
* <p>yqpt_knowledge_class表导入 (分类体系的几个表,以classType区分)</p>
* <p>返回</p>
* @author Lingdong
* @since 2014-5-22 上午09:40:23
* @param doc
* @param data
* @param classType
* @param front
* @param rest
*/
public static void yqpt_knowledge_class(Document doc, NodeList data, Integer classType, JDBCConnector front, JDBCConnector rest){
for (int i = 0; i < data.getLength(); i++) {
String id = doc.getElementsByTagName("data_id").item(i).getFirstChild().getNodeValue();
String name = doc.getElementsByTagName("name").item(i).getFirstChild().getNodeValue();
//doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
String uType = doc.getElementsByTagName("u_type").item(i).getFirstChild().getNodeValue();
//doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
String uTime = "null";
if(doc.getElementsByTagName("u_time").item(i).hasChildNodes()){//判断节点是否为空
uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
}
if("null".equals(uTime)||XString.isNullOrEmpty(uTime)){
uTime = DateUtil.getNowTime4String();
}
String level = "1";
String parent_id = "0";
if(classType==0){
level = doc.getElementsByTagName("level").item(i).getFirstChild().getNodeValue();
parent_id = doc.getElementsByTagName("parent_id").item(i).getFirstChild().getNodeValue();
}
if("1".equals(uType)){
//根据system_id先删除一下要导入的数据 防止重复
String sql = " delete from yqpt_knowledge_class where system_id=" + id;
rest.updateBySql(sql);
sql = " INSERT INTO yqpt_knowledge_class VALUES(null, '" + name + "', " + level + ", "
+ parent_id + ", " + classType + ", 1, '" + uTime + "'," + id + ") ";
rest.updateBySql(sql);
}else if("2".equals(uType)){
String sql = " update yqpt_knowledge_class set name='" + name + "',level=" + level
+ ",parent_id=" + parent_id + " where system_id=" + id;
rest.updateBySql(sql);
}else{
String sql = " delete from yqpt_knowledge_class where system_id=" + id;
rest.updateBySql(sql);
}
}
}
/**
* <p>table yqpt_knowledge_words knowledge_words</p>
* <p>内容分类词库导入</p>
* <p>返回</p>
* @author Lingdong
* @since 2014-5-22 上午11:03:20
* @param doc
* @param data
* @param front
* @param rest
*/
public static void yqpt_knowledge_words(Document doc, NodeList data, JDBCConnector front, JDBCConnector rest){
for (int i = 0; i < data.getLength(); i++) {
String id = doc.getElementsByTagName("data_id").item(i).getFirstChild().getNodeValue();
String word = doc.getElementsByTagName("word").item(i).getFirstChild().getNodeValue();
String word_prop = doc.getElementsByTagName("word_prop").item(i).getFirstChild().getNodeValue();
String class_id = doc.getElementsByTagName("class_id").item(i).getFirstChild().getNodeValue();
//doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
String uType = doc.getElementsByTagName("u_type").item(i).getFirstChild().getNodeValue();
String uTime = "null";
if(doc.getElementsByTagName("u_time").item(i).hasChildNodes()){//判断节点是否为空
uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
}
String userName = "null";
if(doc.getElementsByTagName("u_user").item(i).hasChildNodes()){//判断节点是否为空
userName = doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
}
if("null".equals(uTime)||XString.isNullOrEmpty(uTime)){
uTime = DateUtil.getNowTime4String();
}
String inserFrontSql = " INSERT INTO knowledge_words select :id:, '" + word + "','" + uTime
+ "', id, '" + uTime + "', id," + id + " from user where name='" + userName + "' ";
if("null".equals(userName)||XString.isNullOrEmpty(userName)){
inserFrontSql = " INSERT INTO knowledge_words values (:id:, '" + word + "','"
+ uTime + "', null, '" + uTime + "', null," + id + ") ";
}
String sql = "";
if("1".equals(uType)){
//根据system_id先删除一下要导入的数据 防止重复
sql = " delete from yqpt_knowledge_words where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_words where system_id=" + id;
front.updateBySql(sql);
sql = " INSERT INTO yqpt_knowledge_words VALUES(null, '" + word + "', '" + word_prop
+ "',null, null, " + class_id + ", 1, '" + uTime + "'," + id + ") ";
rest.updateBySql(sql);
int lastid = rest.findLastInsertId();//获取最后插入的id 入前台库表 id要rest和front同步
sql = inserFrontSql.replace(":id:", lastid+"");//替换为具体id
front.updateBySql(sql);
}else if("2".equals(uType)){
sql = " update yqpt_knowledge_words set word='" + word + "',word_prop=" + word_prop
+ ",level3_class=" + class_id + " where system_id=" + id;
rest.updateBySql(sql);
sql = " update knowledge_words set word='" + word + "', modify_time='" + uTime
+ "', modify_user=(select id from user where name='" + userName + "') where system_id=" + id;
front.updateBySql(sql);
}else{
sql = " delete from yqpt_knowledge_words where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_words where system_id=" + id;
front.updateBySql(sql);
}
}
}
/**
* <p>table yqpt_knowledge_event knowledge_event</p>
* <p>重要时间节点库 历史事件</p>
* <p>返回</p>
* @author Lingdong
* @since 2014-5-22 下午04:03:19
* @param doc
* @param data
* @param front
* @param rest
*/
public static void yqpt_knowledge_event(Document doc, NodeList data, JDBCConnector front, JDBCConnector rest){
for (int i = 0; i < data.getLength(); i++) {
String id = doc.getElementsByTagName("data_id").item(i).getFirstChild().getNodeValue();
String date = doc.getElementsByTagName("date").item(i).getFirstChild().getNodeValue();
String cycle = doc.getElementsByTagName("cycle").item(i).getFirstChild().getNodeValue();
String class_id = doc.getElementsByTagName("class_id").item(i).getFirstChild().getNodeValue();
String name = doc.getElementsByTagName("name").item(i).getFirstChild().getNodeValue();
String intro = doc.getElementsByTagName("intro").item(i).getFirstChild().getNodeValue();
String prompt_start = doc.getElementsByTagName("prompt_start").item(i).getFirstChild().getNodeValue();
String prompt_end = doc.getElementsByTagName("prompt_end").item(i).getFirstChild().getNodeValue();
//String source = doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
String uType = doc.getElementsByTagName("u_type").item(i).getFirstChild().getNodeValue();
//String uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
//String userName = doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
String source = "";
if(doc.getElementsByTagName("source").item(i).hasChildNodes()){//判断节点是否为空
source = doc.getElementsByTagName("source").item(i).getFirstChild().getNodeValue();
}
String uTime = "null";
if(doc.getElementsByTagName("u_time").item(i).hasChildNodes()){//判断节点是否为空
uTime = doc.getElementsByTagName("u_time").item(i).getFirstChild().getNodeValue();
}
String userName = "null";
if(doc.getElementsByTagName("u_user").item(i).hasChildNodes()){//判断节点是否为空
userName = doc.getElementsByTagName("u_user").item(i).getFirstChild().getNodeValue();
}
if("null".equals(uTime)||XString.isNullOrEmpty(uTime)){
uTime = DateUtil.getNowTime4String();
}
String inserFrontSql = " INSERT INTO knowledge_event select :id:, '" + name + "'," + date + "," + class_id
+ ",'" + uTime + "', id, '" + uTime + "', id," + id + " from user where name='" + userName + "' ";
if("null".equals(userName)||XString.isNullOrEmpty(userName)){
inserFrontSql = " INSERT INTO knowledge_event values (:id:, '" + name + "'," + date + "," + class_id
+ ",'" + uTime + "', null, '" + uTime + "', null," + id + ") ";
}
String sql = "";
if("1".equals(uType)){
//根据system_id先删除一下要导入的数据 防止重复
sql = " delete from yqpt_knowledge_event where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_event where system_id=" + id;
front.updateBySql(sql);
sql = " INSERT INTO yqpt_knowledge_event VALUES(null, " + date + ", " + cycle + "," + class_id
+ ",'" + name + "','" + intro + "', " + prompt_start + "," + prompt_end + ",1, '" + source + "','" + uTime + "'," + id + ") ";
rest.updateBySql(sql);
int lastid = rest.findLastInsertId();//获取最后插入的id 入前台库表 id要rest和front同步
sql = inserFrontSql.replace(":id:", lastid+"");//替换为具体id
front.updateBySql(sql);
}else if("2".equals(uType)){
sql = " update yqpt_knowledge_event set date=" + date + ",cycle=" + cycle +",class_id=" + class_id
+ ",name='" + name + "',intro='" + intro + "',prompt_start=" + prompt_start + ",prompt_end=" + prompt_end
+ ",source='" + source + "' where system_id=" + id;
rest.updateBySql(sql);
sql = " update knowledge_event set name='" + name + "',date=" + date + " , class_id=" + class_id + " , modify_time='" + uTime
+ "', modify_user=(select id from user where name='" + userName + "') where system_id=" + id;
front.updateBySql(sql);
}else{
sql = " delete from yqpt_knowledge_event where system_id=" + id;
rest.updateBySql(sql);
sql = " delete from knowledge_event where system_id=" + id;
front.updateBySql(sql);
}
}
}
public static void main(String[] args) {
reader("",null,null);
}
}
分享到:
相关推荐
然后,调用`parse()`方法读取XML文件并将其解析为`Document`对象。 - JAXB解析:如果XML文件与Java对象模型有明确的一对一关系,JAXB提供了一种更便捷的方法。使用`Unmarshaller`可以从XML文件中创建Java对象,而`...
标题 "java 读取Ftp指定位置的文件解析并入库" 涉及到的是使用Java编程语言通过FTP(File Transfer Protocol)协议从远程服务器上下载文件,然后对下载的文件进行解析,并将解析得到的数据存储到数据库中。...
Java读取XML文件内容过程解析 Java读取XML文件内容过程解析是Java编程语言中的一种常见操作。本文将通过示例代码详细介绍Java读取XML文件内容的过程,帮助读者更好地理解和掌握这项技术。 首先,需要引入dom4j库,...
Java的XML解析是Java开发中一个重要的组成部分,它允许程序读取、操作和生成XML文档。XML(eXtensible Markup Language)是一种用于标记数据的结构化语言,广泛应用于配置文件、数据交换、Web服务等领域。在Java中,...
在本场景中,我们将探讨如何使用Java Swing技术读取RAW格式的图片文件并将其显示在用户界面上。 首先,理解RAW文件的基本概念是至关重要的。RAW文件包含了相机传感器捕获的原始光数据,这些数据未经色彩校正、白...
在Java中,JAXP(Java API for XML Processing)是用于处理XML的标准接口,它提供了DOM和SAX的实现。Xerces是Apache组织提供的高性能XML解析器,被广泛应用于各种项目中,包括Tomcat服务器。而JDK1.4及以后的版本,...
本文将重点讨论如何通过Java处理XML格式的报文日志文件,并将其入库。 XML(Extensible Markup Language)是一种结构化数据表示语言,广泛应用于数据交换和存储。XML文件中的数据以键值对或节点树的形式存在,易于...
1. **XML解析**:首先,XML2Java库会读取XML文件,利用Java内置的DOM(Document Object Model)或SAX(Simple API for XML)解析器解析XML文档,构建出XML数据的内存表示。 2. **模式识别**:解析过程中,XML2Java...
以下是一个关于如何在Java中读取XML文件内容的详细步骤和源代码解析。 1. **引入库** 在Java中,我们通常使用JAXB(Java Architecture for XML Binding)或DOM(Document Object Model)来处理XML文件。DOM是Java ...
1. **Java I/O流**:在读写文件时,Java的I/O流扮演着核心角色。`java.io`包提供了多种类,如`FileInputStream`用于读取文件,`FileOutputStream`用于写入文件。在处理docx到PDF转换时,你需要先读取docx文件的内容...
在Java编程语言中,DOM(Document Object Model)是一种解析XML文档的标准方法,它将XML文件转换为一个可操作的对象树。DOM4J是Java社区中广泛使用的DOM解析库,提供了丰富的API来处理XML文档。这篇博客文章(链接已...
"Dom4j写XML和读取XML的工具类,非常好用" 这个标题表明我们要讨论的是一个使用Dom4j库来处理XML文档的Java工具类。Dom4j是一个非常流行的Java库,它提供了XML的解析、创建、修改以及查询功能,使得在Java中操作XML...
在本项目中,你可能需要了解如何使用Java的DOM、SAX或StAX等解析器来读取、解析XML文件,提取所需数据,然后将这些数据与MQ传递的信息相结合,进行后续的入库操作。 接下来,我们谈谈Hibernate,这是一个强大的对象...
`BeanReader`会读取Java对象,并将其转化为XML文档。 6. **高级用法**:Betwixt还支持定制化XML元素和属性的处理,如类型转换、处理数组和集合、处理嵌套对象等。这可以通过实现`IntrospectionContext`接口并提供...
1. **导入库**:使用DOM解析XML时,我们需要导入javax.xml.parsers和org.w3c.dom相关的库。例如: ```java import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; ...
GDATAXML库为开发者提供了方便的API,可以高效地读取、写入和操作XML文档,极大地简化了XML解析过程。 **核心功能与特性** 1. **XML解析**:GDATAXML能够解析XML文档,将其转换为对象模型,方便开发者通过对象的...
1. **导入库**:将提供的jar包(如Spire.Doc for Java)引入到你的Java项目中,确保已经正确配置了依赖。 2. **读取Word文档**:使用库提供的API打开并加载Word文档,例如`Document doc = new Document("path_to_...
该项目是一款基于Java语言的文件变化监控与读取入库至Access数据库的设计源码,包含32个文件,其中包括25个Java源文件、2个Markdown文档、2个XML配置文件、1个Git忽略文件、1个属性文件以及1个YAML文件。该系统旨在...
Java命令行交互输入库JLine是开发者在编写需要接收用户命令行输入的Java程序时,常用的工具库。它提供了一套完整的解决方案,包括历史记录、自动补全、多路复用器等功能,极大地提升了用户与Java命令行应用程序的...