xmls

package com.monitor.resolve;

import java.io.File;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.monitor.entity.Fcs13;
import com.monitor.service.TimeFor;

@Service
public class ReadXmlService {

Log log = LogFactory.getLog(TimeFor.class);

@Autowired(required = false)
private JdbcTemplate jdbc;

public JdbcTemplate getJdbc() {
return jdbc;
}

public void setJdbc(JdbcTemplate jdbc) {
this.jdbc = jdbc;
}

private PreparedStatement ps=null;

Fcs13 book = new Fcs13();
public void resolve(){

refreshFileList("D:\\SAICFTEST\\INTERFACE\\SAICF_FCS\\FCS13_RFIDMONITORINFO\\");
}

private void refreshFileList(String strPath) {
String str = null;
String strctl = null;
File dir = new File(strPath);
File[] files = dir.listFiles();
String fileName = null;
String fileCtlName = null;
List list = new ArrayList();
List listctl = new ArrayList();
if (files == null)
return;
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
refreshFileList(files[i].getAbsolutePath());
} else {
String strFileName = files[i].getAbsolutePath().toLowerCase();
String strFileNamedaxie = strFileName.toUpperCase();
if(strFileName.endsWith(".xml")){
str = strFileName;
File str1 = new File(str.trim());
fileName = str1.getName();
list.add(fileName);
}
}
}
for(int j = 0;j<list.size();j++){
File f1 = new File((String) list.get(j));
try {
SAXReader reader = new SAXReader();
File f=new File("D:\\SAICFTEST\\INTERFACE\\SAICF_FCS\\FCS13_RFIDMONITORINFO\\"+f1);


Document doc = reader.read(f);
Element root=doc.getRootElement();

//取出所有的节点
List all = doc.selectNodes("//BODY/RECORD");
for(Object obj:all){
Node childNode =(Node) obj;
List rfid=childNode.selectNodes("RFID");
for(Object orfid:rfid){
Node rf=(Node)orfid;
book.setRfid(rf.getStringValue());

}

List occur_time = childNode.selectNodes("OCCUR_TIME");
for(Object ooccur_time:occur_time){
Node ot=(Node) ooccur_time;
book.setOccur_Time(ot.getStringValue());
}

List monitor_flag = childNode.selectNodes("MONITOR_FLAG");
for(Object omonitor_flag:monitor_flag){
Node mf=(Node) omonitor_flag;
book.setMonitor_Flag(mf.getStringValue());
}
try {

String xmlname = f1.getName();

String xmlnamesplit = xmlname.substring(0, 26);

String XMLNAME = xmlnamesplit.toUpperCase();


book.setFileName(XMLNAME);

String sql = "insert into IF_GROUP_FCS13(FCS13_FileName,FCS13_Rfid,FCS13_OccurTime,FCS13_MonitorFlag,FCS13_RecStatus,FCS13_RecTime) values('"+book.getFileName()+"','"+book.getRfid()+"','"+book.getOccur_Time()+"','"+book.getMonitor_Flag()+"','0',getDate())";

jdbc.execute(sql);

String sql2 = "{call sp_if_gen_fcs12ctl('"+book.getFileName()+"')}";

jdbc.execute(sql2);

} catch (Exception e) {
e.printStackTrace();
}

}

File fold = new File("D:\\SAICFTEST\\INTERFACE\\SAICF_FCS\\FCS13_RFIDMONITORINFO\\"+f1);//生成XML文件路径
String strNewPath = "D:\\SAICFTEST\\BACKUP\\SAICF_FCS\\FCS13_RFIDMONITORINFO\\";//移出XML文件路径
File fnewpath = new File(strNewPath);
if(!fnewpath.exists())
fnewpath.mkdirs();
File fnew = new File(strNewPath+fold.getName());
fold.renameTo(fnew);
} catch (Exception e) {
e.printStackTrace();
}
}

// for (int k = 0; k < files.length; k++) {
// if (files[k].isDirectory()) {
// refreshFileList(files[k].getAbsolutePath());
// } else {
// String strFileName1 = files[k].getAbsolutePath().toLowerCase();
// if(strFileName1.endsWith(".ctl")){
// strctl = strFileName1;
// File strCtl = new File(strctl.trim());
// fileCtlName = strCtl.getName();
// listctl.add(fileCtlName);
// }
// }
// }
//
// for(int m = 0;m<listctl.size();m++){
// File fctl = new File((String) listctl.get(m));
// File foldctl = new File("D:\\SAICFTEST\\INTERFACE\\SAICF_FCS\\FCS13_RFIDMONITORINFO\\"+fctl);//生成的CTL路径
// String strNewPathctl = "D:\\SAICFTEST\\BACKUP\\SAICF_FCS\\FCS13_RFIDMONITORINFO\\";//移出的CTL路径
// File fnewpathctl = new File(strNewPathctl);
// if(!fnewpathctl.exists())
// fnewpathctl.mkdirs();
// File fnewctl = new File(strNewPathctl+foldctl.getName());
// foldctl.renameTo(fnewctl);

}

}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值