| | |
| | | package com.whyc.service; |
| | | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.BattDataDTO; |
| | | import com.whyc.dto.BattTestData; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.result.RealDateDTO; |
| | |
| | | import com.whyc.pojo.BattRealdata; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.ReflectUtil; |
| | | import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.concurrent.CountDownLatch; |
| | |
| | | PageInfo pageInfo = new PageInfo(list); |
| | | return new Response().set(1,pageInfo);*/ |
| | | } |
| | | |
| | | public Response excelParse(MultipartFile file) throws IOException, InvalidFormatException { |
| | | List dataList = new LinkedList(); |
| | | Workbook workbook = null; |
| | | InputStream inputStream = file.getInputStream(); |
| | | workbook = WorkbookFactory.create(inputStream); |
| | | Sheet sheet = workbook.getSheet("数据表"); |
| | | |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | short lastCellNum = sheet.getRow(0).getLastCellNum(); |
| | | //获取单体的单元格值 |
| | | List<String> monKey = new LinkedList<>(); |
| | | for (int i = 4; i < lastCellNum-1; i++) { |
| | | monKey.add(sheet.getRow(0).getCell(i).getStringCellValue()); |
| | | } |
| | | sheet.getRow(0); |
| | | //从第2行开始 |
| | | for (int i = 1; i < lastRowNum - 1; i++) { |
| | | BattDataDTO data = new BattDataDTO(); |
| | | Map<String, Object> addProperties = new HashMap<>(); |
| | | |
| | | for (int j = 0; j < lastCellNum-1; j++) { |
| | | Cell cell = sheet.getRow(i).getCell(j); |
| | | cell.setCellType(Cell.CELL_TYPE_STRING); |
| | | String value = cell.getStringCellValue(); |
| | | if(value.equals("")){ |
| | | break; |
| | | } |
| | | switch (j){ |
| | | case 0:{data.setTime(value);}break; |
| | | case 1:{data.setTotalVol(value);}break; |
| | | case 2:{data.setTotalCurr(value);}break; |
| | | case 3:{data.setCap(value);}break; |
| | | default:{ |
| | | int index = j-4; |
| | | addProperties.put(monKey.get(index),value); |
| | | } |
| | | } |
| | | } |
| | | Object target = ReflectUtil.getTarget(data, addProperties); |
| | | dataList.add(target); |
| | | } |
| | | |
| | | return new Response().set(1,dataList); |
| | | } |
| | | |
| | | } |