Commit a33a093b by zhangkb

2020年第二季度基础项数据exel导入方法

parent 4e7a9752
package com.keymobile.indicators.api.hytobacco; package com.keymobile.indicators.api.hytobacco;
import java.io.InputStream;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.keymobile.indicators.service.hytobacco.IndicatorsValueService; import com.keymobile.indicators.service.hytobacco.IndicatorsValueService;
...@@ -21,6 +23,16 @@ public class IndicatorsValueCtrl { ...@@ -21,6 +23,16 @@ public class IndicatorsValueCtrl {
@Autowired @Autowired
private IndicatorsValueService indicatorsValueService; private IndicatorsValueService indicatorsValueService;
@ApiOperation(value = "导入2020年2季度数据", notes = "导入2020年2季度数据")
@PostMapping(value = "/importIndiData")
public void importIndiData(@RequestParam("file") MultipartFile file) throws Exception{
try (InputStream is = file.getInputStream()){
indicatorsValueService.importIndicatordData(is);
}catch(Exception e) {
e.printStackTrace();
}
}
@ApiOperation(value = "填充excel file1数据", notes = "填充excel file1数据") @ApiOperation(value = "填充excel file1数据", notes = "填充excel file1数据")
@PostMapping(value = "/fillExcelFileOne") @PostMapping(value = "/fillExcelFileOne")
public void fillExcelFileOne(@RequestBody List<String> indIds,@RequestParam int date, public void fillExcelFileOne(@RequestBody List<String> indIds,@RequestParam int date,
......
...@@ -2,6 +2,7 @@ package com.keymobile.indicators.service.hytobacco; ...@@ -2,6 +2,7 @@ package com.keymobile.indicators.service.hytobacco;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
...@@ -14,6 +15,8 @@ import java.util.Map.Entry; ...@@ -14,6 +15,8 @@ import java.util.Map.Entry;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
...@@ -42,6 +45,88 @@ public class IndicatorsValueService { ...@@ -42,6 +45,88 @@ public class IndicatorsValueService {
@Autowired @Autowired
private DriveIndCalResultDefMapper driveIndCalResultDefMapper; private DriveIndCalResultDefMapper driveIndCalResultDefMapper;
//导入2020年第二季度基础项数据
public void importIndicatordData(InputStream is) throws Exception{
//定义行信息
Map<String,Integer> excelRowInfo = new HashMap<>();
excelRowInfo.put("430000122",2);excelRowInfo.put("430000123",3);excelRowInfo.put("430000125",4);
excelRowInfo.put("430000124",5);excelRowInfo.put("430000128",6);excelRowInfo.put("430000129",7);
excelRowInfo.put("430000087",9);excelRowInfo.put("430000101",10);excelRowInfo.put("430000096",11);
excelRowInfo.put("430000097",12);excelRowInfo.put("430000089",13);excelRowInfo.put("430000094",14);
excelRowInfo.put("430000095",15);excelRowInfo.put("430000091",16);excelRowInfo.put("430000121",17);
excelRowInfo.put("430000093",18);excelRowInfo.put("430000092",19);excelRowInfo.put("430000120",20);
excelRowInfo.put("430000139",43);excelRowInfo.put("430000140",44);excelRowInfo.put("430000141",45);
excelRowInfo.put("430000147",46);excelRowInfo.put("430000148",47);excelRowInfo.put("430000149",48);
excelRowInfo.put("430000150",49);
excelRowInfo.put("430000156",51);
excelRowInfo.put("430000157",58);excelRowInfo.put("430000160",59);excelRowInfo.put("430000161",60);
excelRowInfo.put("430000158",61);excelRowInfo.put("430000159",62);excelRowInfo.put("430000162",63);
excelRowInfo.put("430000164",65);
excelRowInfo.put("430000165",67);
excelRowInfo.put("430000167",69);
//列信息
Map<String,Integer> excelCellInfo = new HashMap<>();
excelCellInfo.put("43", 4);excelCellInfo.put("4301", 6);excelCellInfo.put("4302", 8);
excelCellInfo.put("4303", 10);excelCellInfo.put("4304", 12);excelCellInfo.put("4305", 14);
excelCellInfo.put("4306", 16);excelCellInfo.put("4307", 18);excelCellInfo.put("4308", 20);
excelCellInfo.put("4309", 22);excelCellInfo.put("4310", 24);excelCellInfo.put("4311", 26);
excelCellInfo.put("4312", 28);excelCellInfo.put("4313", 30);excelCellInfo.put("4331", 32);
//对象映射
Map<String,String> compareObjInfo = new HashMap<>();
compareObjInfo.put("43", "全省");compareObjInfo.put("4301", "长沙市");compareObjInfo.put("4302", "株洲市");
compareObjInfo.put("4303", "湘潭市");compareObjInfo.put("4304", "衡阳市");compareObjInfo.put("4305", "邵阳市");
compareObjInfo.put("4306", "岳阳市");compareObjInfo.put("4307", "常德市");compareObjInfo.put("4308", "张家界");
compareObjInfo.put("4309", "益阳市");compareObjInfo.put("4310", "郴州市");compareObjInfo.put("4311", "永州市");
compareObjInfo.put("4312", "怀化市");compareObjInfo.put("4313", "娄底市");compareObjInfo.put("4331", "湘西州");
List<IndicatorsData> datas = new ArrayList<>();
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
for (Sheet xssfSheet : xssfWorkbook) {
for(Map.Entry<String, Integer> rowMap : excelRowInfo.entrySet()) {
Row xssfRow = xssfSheet.getRow(rowMap.getValue());
for(Map.Entry<String, Integer> cellMap : excelCellInfo.entrySet()) {
IndicatorsData currentData = new IndicatorsData();
IndicatorsData sameData = new IndicatorsData();
currentData.setIndId(rowMap.getKey());
currentData.setIndDesc(xssfRow.getCell(1).getStringCellValue());
currentData.setType("1");
currentData.setBatchNo("B10000110");
currentData.setDataType("double");
currentData.setUnit(xssfRow.getCell(2).getStringCellValue());
currentData.setDim1(cellMap.getKey());
currentData.setDim1Desc(compareObjInfo.get(cellMap.getKey()));
currentData.setDim2(202006);
currentData.setValue(String.valueOf(xssfRow.getCell(cellMap.getValue()).getNumericCellValue()));
datas.add(currentData);
sameData.setIndId(rowMap.getKey());
sameData.setIndDesc(xssfRow.getCell(1).getStringCellValue());
sameData.setType("1");
sameData.setBatchNo("B10000110");
sameData.setDataType("double");
sameData.setUnit(xssfRow.getCell(2).getStringCellValue());
sameData.setDim1(cellMap.getKey());
sameData.setDim1Desc(compareObjInfo.get(cellMap.getKey()));
sameData.setDim2(201906);
sameData.setValue(String.valueOf(xssfRow.getCell(cellMap.getValue()+1).getNumericCellValue()));
datas.add(sameData);
}
}
}
indicatorsDataMapper.batchCreateIndData(datas);
System.out.println("导入基础项完成");
}
public void fillExcelXianScore(List<String> indIds,int date, public void fillExcelXianScore(List<String> indIds,int date,
String compareObjString,int groupNum,int type) throws Exception{ String compareObjString,int groupNum,int type) throws Exception{
String filePath = "D://indicatorsFile/file10.xlsx"; String filePath = "D://indicatorsFile/file10.xlsx";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment