whycrzg
2021-02-23 351b9a53cb9ecebdf8f79db0117f540d9c42c2a4
src/main/java/com/fgkj/services/ResDataUploadService.java
@@ -1,32 +1,33 @@
package com.fgkj.services;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Battresdata_inf;
import com.fgkj.dto.DLG_Progress;
import com.fgkj.dto.User_inf;
import com.fgkj.fbo.CsvData;
import com.fgkj.mapper.impl.BattInfMapper;
import com.fgkj.mapper.impl.Battresdata_infMapper;
import com.fgkj.mapper.impl.ResDataUploadMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpSession;
import com.fgkj.mapper.BaseDAO;
import com.fgkj.mapper.BaseDAOFactory;
import com.fgkj.mapper.impl.Battresdata_infDAOImpl;
import com.fgkj.mapper.impl.ResDataUploadImpl;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Battresdata_inf;
import com.fgkj.dto.DLG_Progress;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.User_inf;
import com.fgkj.fbo.CsvData;
import javax.annotation.Resource;
@Service
public class ResDataUploadService extends Thread{
   private ServiceModel model;
   /*ServiceModel model = new ServiceModel();
   private User_inf uinf;
   private int bg_id;
   private String[][] tableRowData;
   private File[] file;
   private HttpSession session;
   private DLG_Progress progress;
   // private HttpSession session;
   // private DLG_Progress progress;
   
   
   public ResDataUploadService(
@@ -45,9 +46,78 @@
      progress.setTableData(tableRowData);
      progress.setTotal(file.length);
      session.setAttribute("Resprogress", progress);
   }*/
   @Resource
   private ResDataUploadMapper mapper;
   @Resource
   private BattInfMapper battInfMapper;
   @Resource
   private Battresdata_infMapper battResDataInfMapper;
   public void uploadResFile(User_inf uinf, int bg_id, String[][] tableRowData, File[] file, HttpSession session) {
      DLG_Progress progress=new DLG_Progress(true,false);
      progress.setTableData(tableRowData);
      progress.setTotal(file.length);
      session.setAttribute("Resprogress", progress);
      Thread thread = new Thread() {
         @Override
         public void run() {
            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++;
               CsvData res_data = new CsvData();
               File f = file[n];
               if (tableRowData[n][1].toUpperCase().endsWith(".CSV")) {
                  res_data.checkCsvFile(f);
               } else if (tableRowData[n][1].toUpperCase().endsWith(".FGXLS")) {
                  res_data.checkFgxlsFile(f);
               } else if (tableRowData[n][1].toUpperCase().endsWith(".XML")) {
                  res_data.checkXmlFile(f);
               }
               int bg_id = Integer.parseInt((String) tableRowData[n][0]);
//         if(!FileisUpload(bg_id,res_data)){
//            continue;
//         }
               //System.out.println("正在上传");
               boolean res = mapper.uploadResData(uinf, bg_id, res_data,
                     tableRowData[n], progress.isJudge());
               if (true == res) {
                  System.out.println(f.getName());
                  tableRowData[n][4] = "true";
                  tableRowData[n][5] = "100";
                  progress.setUploadOkcount(progress.getUploadOkcount() + 1);
               }
            }
            for (File fl : file) {
               if (fl.exists()) {
                  fl.delete();
               }
            }
            progress.setCompleteed(true);
            progress.setJudge(false);
         }
      };
      thread.start();
   }
   
   public void run(){
   /*public void run(){
      for(int n=0; n<tableRowData.length; n++)
      {   
         if(false == progress.isJudge())
@@ -98,19 +168,18 @@
      
      progress.setCompleteed(true);
      progress.setJudge(false);
   }
   }*/
   
   //判断当前文件能否上传
   
   /**
    * 
    * @param bg_id   电池组名
    * @param CsvData csv_data   上传数据
    * @param  csv_data   上传数据
    * @return   true :能上传                 false:不能上传
    */
   public boolean FileisUpload(int bg_id,CsvData csv_data) {
      BaseDAO dao = BaseDAOFactory.getBaseDAO(BaseDAO.BATTINF);
      BaseDAO daoAgain = BaseDAOFactory.getBaseDAO(BaseDAO.BATTRESDATA_INF);
      Calendar mcld = Calendar.getInstance();
      mcld.setTime(csv_data.m_TestTime);
      
@@ -131,13 +200,13 @@
      int mon_count=0;
      float mon_vol=0f;
      if(0 == data_reason_type) {
         List<BattInf> listB=dao.serchByCondition(binf);
         List<BattInf> listB=battInfMapper.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<Battresdata_inf> listR=((Battresdata_infDAOImpl)daoAgain).serchTest_record_count(rinf);
         List<Battresdata_inf> listR=battResDataInfMapper.serchTest_record_count(rinf);
         if(listR!=null&&listR.size()>0){
            int test_record_count = listR.get(0).getTest_record_count();
            data_reason_type = 1;