| | |
| | | |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.AnaylsisId; |
| | | import com.whyc.pojo.AnaysisData; |
| | | import com.whyc.pojo.BatttestdataId; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.AnalysisUtil; |
| | | import org.apache.poi.hssf.usermodel.*; |
| | |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | |
| | | public class AnaysiService { |
| | | @Autowired(required = false) |
| | | private SubTablePageInfoService subService; |
| | | |
| | | @Autowired(required = false) |
| | | private BatttestdataInfService tinfService; |
| | | |
| | | |
| | | //预估数据 |
| | | public String createAnaysisXls(int battGroupId, int testRecordCount) { |
| | |
| | | List<AnaylsisId> list=subService.getAnaysisXls(battGroupId,testRecordCount); |
| | | return new Response().setII(1,list!=null,list,"查询预估数据"); |
| | | } |
| | | //解析xls文件到放电数据中 |
| | | public Response<Object> anaysisXlsToTdata(int battGroupId,InputStream inputStream) throws IOException, InvalidFormatException, ParseException { |
| | | Workbook workbook = null; |
| | | workbook = WorkbookFactory.create(inputStream); |
| | | inputStream.close(); |
| | | //取第一个sheet表 |
| | | Sheet sheet = workbook.getSheetAt(2); |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | Row rowTemp = sheet.getRow(0); |
| | | short lastCellNum = rowTemp.getLastCellNum(); |
| | | DataFormatter dataFormatter = new DataFormatter(Locale.US); |
| | | List<XlsToTdata> list=new ArrayList<>(); |
| | | for (int i=1;i<lastRowNum;i++){ |
| | | XlsToTdata tData=new XlsToTdata(); |
| | | Row row = sheet.getRow(i); |
| | | Cell cell0 = row.getCell(0); |
| | | String formattedValue = dataFormatter.formatCellValue(cell0); |
| | | tData.setRecordTime(ActionUtil.parseDurationDirectly(formattedValue)); |
| | | |
| | | tData.setTestTimelong(ActionUtil.convertToSeconds(formattedValue)); |
| | | |
| | | Cell cell1 = row.getCell(1); |
| | | cell1.setCellType(Cell.CELL_TYPE_NUMERIC); |
| | | tData.setGroupVol((float) cell1.getNumericCellValue()); |
| | | |
| | | Cell cell2 = row.getCell(2); |
| | | cell2.setCellType(Cell.CELL_TYPE_NUMERIC); |
| | | tData.setGroupCurr((float) cell2.getNumericCellValue()); |
| | | |
| | | Cell cell3 = row.getCell(3); |
| | | cell3.setCellType(Cell.CELL_TYPE_NUMERIC); |
| | | tData.setTestCap((float) cell3.getNumericCellValue()); |
| | | |
| | | List<Float> monVols=new ArrayList<>(); |
| | | for (int j=4;j<lastCellNum;j++){ |
| | | Cell cell = row.getCell(j); |
| | | cell.setCellType(Cell.CELL_TYPE_NUMERIC); |
| | | monVols.add((float) cell.getNumericCellValue()); |
| | | } |
| | | tData.setMonVols(monVols); |
| | | list.add(tData); |
| | | } |
| | | |
| | | //1.获取当前最大的放电信息testRecordCount |
| | | BatttestdataInf tinf=tinfService.getMaxRecord(battGroupId); |
| | | int testRecordCount=0; |
| | | if(tinf!=null) { |
| | | testRecordCount = tinf.getTestRecordCount(); |
| | | } |
| | | |
| | | |
| | | //3.将tinf补齐 |
| | | tinf=new BatttestdataInf(); |
| | | tinf.setBattGroupId(battGroupId); |
| | | tinf.setDataNew((byte) 1); |
| | | tinf.setDataAvailable((byte) 1); |
| | | tinf.setTestType(3); |
| | | tinf.setRecordTimeInterval(10); |
| | | tinf.setTestRecordCount(testRecordCount+1); |
| | | tinf.setTestRecordCountEx(testRecordCount+2); |
| | | tinf.setRecordNum(list.size()+1); |
| | | tinf.setTestStarttime(new Date()); |
| | | tinf.setRecordTime(new Date()); |
| | | tinf.setTestStarttype(3); |
| | | tinfService.insertTinf(tinf); |
| | | |
| | | //2.将数据插入电池组数据 |
| | | subService.insertAnaysisXlsToTdata(battGroupId,testRecordCount+1,list); |
| | | return new Response<>().set(1); |
| | | } |
| | | |
| | | |
| | | } |