package com.fgkj.services;
|
|
import java.io.File;
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Vector;
|
|
import javax.servlet.http.HttpSession;
|
|
import com.fgkj.actions.ActionUtil;
|
import com.fgkj.dao.BaseDAO;
|
import com.fgkj.dao.BaseDAOFactory;
|
import com.fgkj.dao.impl.Batttestdata_infDAOImpl;
|
import com.fgkj.dao.impl.FboDataUploadImpl;
|
import com.fgkj.dto.BattInf;
|
import com.fgkj.dto.Batttestdata_inf;
|
import com.fgkj.dto.Com;
|
import com.fgkj.dto.DLG_Progress;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.dto.User_inf;
|
import com.fgkj.fbo.FboData;
|
import com.fgkj.fbo.FboDataInf;
|
import com.fgkj.fbo.IdcData;
|
|
public class FboDataUploadService extends Thread{
|
private ServiceModel model;
|
private User_inf uinf;
|
private int bg_id;
|
private String[][] tableRowData;
|
private File[] file;
|
private HttpSession session;
|
private DLG_Progress progress;
|
|
public FboDataUploadService() {
|
model = new ServiceModel();
|
progress=new DLG_Progress(true,false);
|
}
|
|
public FboDataUploadService(
|
User_inf uinf,
|
int bg_id,
|
String[][] tableRowData,
|
File[] file,
|
HttpSession session) {
|
this.model = new ServiceModel();
|
this.uinf = uinf;
|
this.bg_id = bg_id;
|
this.tableRowData=tableRowData;
|
this.file=file;
|
this.session=session;
|
progress=new DLG_Progress(true,false);
|
progress.setTableData(tableRowData);
|
progress.setTotal(file.length);
|
session.setAttribute("progress", progress);
|
}
|
|
public void run(){
|
//System.out.println("开启线程");
|
//System.out.println(progress);
|
for(int n=0; n<tableRowData.length; n++)
|
{
|
if(false == progress.isJudge())
|
{
|
break;
|
}
|
|
if("false".equals(tableRowData[n][2])) //是否能上传
|
{
|
continue;
|
}
|
if("true".equals(tableRowData[n][4])) //是否已上传
|
{
|
continue;
|
}
|
|
//m_UploadCount++;
|
FboDataInf data_inf = new FboDataInf();
|
ArrayList<FboData> al_fbo_data = new ArrayList<FboData>();
|
|
File f=file[n];
|
if(tableRowData[n][1].toUpperCase().endsWith(".FBO")) {
|
FboData.checkFboFile(f, data_inf, al_fbo_data);
|
} else if(tableRowData[n][1].toUpperCase().endsWith(".IDC")) {
|
IdcData.checkIdcFile(f, data_inf, al_fbo_data);
|
}
|
int bg_id = Integer.parseInt((String) tableRowData[n][0]);
|
//判断文件是否存在
|
// boolean flag=FileisUpload(bg_id, data_inf);
|
// if(!flag){
|
// continue;
|
// }
|
|
Boolean bl=new FboDataUploadImpl().uploadFboData(uinf, bg_id, data_inf, al_fbo_data, tableRowData[n], progress.isJudge());
|
if(true == bl){
|
//System.out.println(bg_id+"\t"+bl);
|
tableRowData[n][4]="true";
|
progress.setUploadOkcount(progress.getUploadOkcount()+1);
|
}
|
|
}
|
for(File fl:file){
|
if(fl.exists()){
|
fl.delete();
|
}
|
}
|
progress.setCompleteed(true);
|
progress.setJudge(false);
|
}
|
//判断当前文件能否上传
|
/**
|
*
|
* @param bg_id 电池组名
|
* @param data_inf 上传数据
|
* @return true :能上传 false:不能上传
|
*/
|
public boolean FileisUpload(int bg_id,FboDataInf data_inf) {
|
BaseDAO dao = BaseDAOFactory.getBaseDAO(BaseDAO.BATTINF);
|
BaseDAO daoAgain = BaseDAOFactory.getBaseDAO(BaseDAO.BATTTESTDATA_INF);
|
Calendar mcld = Calendar.getInstance();
|
mcld.set(Calendar.YEAR, 2000 + data_inf.TestStartTime.year);
|
mcld.set(Calendar.MONTH, data_inf.TestStartTime.month);
|
mcld.set(Calendar.DATE, data_inf.TestStartTime.day);
|
mcld.set(Calendar.HOUR_OF_DAY, data_inf.TestStartTime.hour);
|
mcld.set(Calendar.MINUTE, data_inf.TestStartTime.minute);
|
mcld.set(Calendar.SECOND, data_inf.TestStartTime.second);
|
|
Date test_starttime = mcld.getTime();
|
//System.out.println("test_starttime: " + test_starttime);
|
boolean data_ok = true;
|
int data_reason_type = 0;
|
|
BattInf binf = new BattInf();
|
Batttestdata_inf tdata = new Batttestdata_inf();
|
binf.setBattGroupId(bg_id);
|
tdata.setBattGroupId(bg_id);
|
tdata.setTest_starttime(test_starttime);
|
float batt_cap = 0f;
|
int mon_count = 0;
|
float mon_vol = 0f;
|
List<BattInf> listB = dao.serchByCondition(binf);
|
if (listB != null && listB.size() > 0) {
|
batt_cap = listB.get(0).getMonCapStd();
|
mon_count = listB.get(0).getMonCount();
|
mon_vol = listB.get(0).getMonVolStd();
|
}
|
|
List<Batttestdata_inf> listT = ((Batttestdata_infDAOImpl)daoAgain)
|
.serchTest_record_count(tdata);
|
if (listT != null && listT.size() > 0) {
|
// int test_record_count = listT.get(0).getTest_record_count();
|
data_reason_type = 1;
|
}
|
|
if (0 == data_reason_type) {
|
if (batt_cap != data_inf.STDCap) {
|
data_reason_type = 2;
|
} else if (mon_count != data_inf.BattSum) {
|
data_reason_type = 3;
|
} else if (mon_vol != data_inf.MonomerVol) {
|
data_reason_type = 4;
|
}
|
}
|
|
if (data_reason_type > 0) {
|
data_ok = false;
|
}
|
return data_ok;
|
}
|
|
public void stopUpload(){
|
progress.setJudge(false);
|
}
|
|
public String[][] getTableRowData() {
|
return tableRowData;
|
}
|
|
public void setTableRowData(String[][] tableRowData) {
|
this.tableRowData = tableRowData;
|
}
|
}
|