package com.fgkj.fbo; import static com.fgkj.dao.BattTestData.BATT_MON_COUNT_MAX; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.dom4j.DocumentException; import com.fgkj.dao.BattTestData; import com.fgkj.dto.Com; public class CsvData { public static final int DevType_Csv = 0x45; public static final int DevType_FBR = 0x46; public boolean m_DataOk = true; public String m_BattGroupNameFull = ""; public int m_STDAH; //±ê³ÆÈÝÁ¿¡£ public int m_BattSum; //µç³Ø¸öÊý¡£ public float m_MonomerVol = 2; public int m_DevType = 0; public int m_TestType = 0; public Date m_TestTime = new Date(); public float m_GroupVol; public float m_TestCurr; public int m_MinNum = 0; public float m_MinValue = 0; public float[] MonomerVol = new float[BATT_MON_COUNT_MAX]; public float[] MonomerRes = new float[BattTestData.BATT_MON_COUNT_MAX]; public float[] MonomerSer = new float[BattTestData.BATT_MON_COUNT_MAX]; public float[] MonomerTmp = new float[BattTestData.BATT_MON_COUNT_MAX]; public float[] MonomerConn = new float[BattTestData.BATT_MON_COUNT_MAX]; public void setData(File file) { //System.out.println(111111111); m_DataOk = true; BufferedReader reader = null; try { m_TestType = BattTestData.BATTDATA_SER; m_DevType = DevType_Csv; reader = new BufferedReader(new FileReader(file)); //-------------------------------------------------------------------// //-------------------------------------------------------------------// String tmpstr = reader.readLine(); //-------------------------------------------------------------------// //-------------------------------------------------------------------// tmpstr = reader.readLine(); for(int n=0; n<4; n++) { tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length()); } if(tmpstr.contains(",")) { tmpstr = tmpstr.substring(0, tmpstr.indexOf(",")); } else if(tmpstr.contains("\r\n")) { tmpstr = tmpstr.substring(0, tmpstr.indexOf("\r\n")); } //System.out.println(tmpstr); m_BattSum = Integer.parseInt(tmpstr.trim()); //-------------------------------------------------------------------// //-------------------------------------------------------------------// tmpstr = reader.readLine(); for(int n=0; n<4; n++) { tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length()); } tmpstr = tmpstr.substring(0, tmpstr.indexOf(",")); m_MonomerVol = Float.parseFloat(tmpstr.trim()); if((m_MonomerVol>10.1) && (m_MonomerVol<20)) { m_MonomerVol = 12; } else if((m_MonomerVol>5.4) && (m_MonomerVol<7.8)) { m_MonomerVol = 6; } else if((m_MonomerVol>2.7) && (m_MonomerVol<4.0)) { m_MonomerVol = 4; } else { m_MonomerVol = 2; } //-------------------------------------------------------------------// //-------------------------------------------------------------------// tmpstr = reader.readLine(); for(int n=0; n<4; n++) { tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length()); } int month = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf("/")).trim()); tmpstr = tmpstr.substring(tmpstr.indexOf("/")+1, tmpstr.length()); int day = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf("/")).trim()); tmpstr = tmpstr.substring(tmpstr.indexOf("/")+1, tmpstr.length()); int year = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf(",")).trim()); tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length()); int hour = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf(":")).trim()); tmpstr = tmpstr.substring(tmpstr.indexOf(":")+1, tmpstr.length()); int minute = Integer.parseInt(tmpstr.substring(0, 2).trim()); tmpstr = tmpstr.substring(3, tmpstr.length()); if(tmpstr.substring(0, tmpstr.indexOf(",")).trim().equals("PM")) { hour += 12; } GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance(); gc.set(GregorianCalendar.YEAR, year); gc.set(GregorianCalendar.MONTH, month-1); gc.set(GregorianCalendar.DATE, day); gc.set(GregorianCalendar.HOUR_OF_DAY, hour); gc.set(GregorianCalendar.MINUTE, minute); gc.set(GregorianCalendar.SECOND, 0); m_TestTime = gc.getTime(); //-------------------------------------------------------------------// //-------------------------------------------------------------------// tmpstr = reader.readLine(); reader.mark(0); //-------------------------------------------------------------------// //-------------------------------------------------------------------// tmpstr = reader.readLine() + reader.readLine() + reader.readLine() + reader.readLine(); int sub_con_count = 1; if (tmpstr.contains("J1D")) { sub_con_count = 4; } else if (tmpstr.contains("J1C")) { sub_con_count = 3; } else if (tmpstr.contains("J1B")) { sub_con_count = 2; } m_BattSum /= sub_con_count; //-------------------------------------------------------------------// reader.reset(); //-------------------------------------------------------------------// m_MinValue = 900000; for(int n=0; n 1) { MonomerRes[n] = 1000 / (MonomerSer[n] / (m_MonomerVol/2)); } if(MonomerSer[n] < m_MinValue) { m_MinValue = MonomerSer[n]; m_MinNum = n+1; } } //-------------------------------------------------------------------// } catch (Exception e) { m_DataOk = false; System.err.println("Class 'CsvData' function setData(): " + e.getMessage()); } finally { try { reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void checkCsvFile(File file) { setData(file); } private String getNodeTextEx(Object ob, Element rootnode, String node_name) { String text = String.valueOf(ob); try { Element node = rootnode.element(node_name); text = node.getTextTrim(); } catch (NullPointerException e) { e.printStackTrace(); } return text; } public void checkXmlFile(File file) { m_DataOk = false; try { SAXReader reader = new SAXReader(); Document document = reader.read(file); Element rootnode = document.getRootElement(); m_TestType = BattTestData.BATTDATA_RES; m_DevType = DevType_FBR; String test_time = getNodeTextEx("1990-01-01_00:00:00", rootnode, "TEST_TIME"); if(test_time.contains("1990-01-01")) { m_DataOk = false; return; } m_TestTime = Com.get_DT_FromStr(test_time.replace("_", " ").trim(), Com.DTF_YMDhms); //String data_version = Config.getNodeTextEx("V1.0", rootnode, "VERSION"); Element sub_node = rootnode.element("BATT_PARAM"); m_BattSum = Integer.parseInt(getNodeTextEx("0", sub_node, "batt_count")); m_MonomerVol = Float.parseFloat(getNodeTextEx("0.0", sub_node, "batt_vol")); m_STDAH = Integer.parseInt(getNodeTextEx("0", sub_node, "batt_cap")); int concount_pb = Integer.parseInt(getNodeTextEx("1", sub_node, "concount_pb")); m_MinValue = 900000; for(int n=0; n childElements = rootnode.elements(); int cnt = 0; for(cnt=0; cnt 500) { m_BattSum = 500; } m_MinValue = 900000; for(int n=0; n 1) { MonomerRes[n] = 1000 / (MonomerSer[n] / (m_MonomerVol/2)); } if(MonomerSer[n] < m_MinValue) { m_MinValue = MonomerSer[n]; m_MinNum = n+1; } } } catch (IOException e) { e.printStackTrace(); } finally { if(null != fis) { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } } } }