package com.skymobi.qc.admin.action;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import com.skymobi.qc.admin.dal.CpqaMapper;
import com.skymobi.qc.admin.dal.domain.CpqaProject;
import com.skymobi.qc.admin.framework.base.BaseBO;
import com.skymobi.qc.admin.framework.util.Page;
import com.skymobi.qc.admin.framework.util.ParaMap;
public class CpqaBO extends BaseBO {
@Autowired
CpqaMapper cpqaMapper;
public List<Map<Object,Object>> getProjectList(ParaMap<String,Object> paraMap,Page page){
page.setTotalRow(cpqaMapper.getListCount());
paraMap.put("page", page);
return cpqaMapper.getProjectList(paraMap);
}
/**
* 导入数据
*/
public void importProjectData(){
String strPath = "C:\\Users\\bruce.zhang\\Desktop\\test.xlsx";
// 构造 XSSFWorkbook 对象,strPath 传入文件路径
try {
InputStream is = new FileInputStream(strPath);
XSSFWorkbook xwb = new XSSFWorkbook(is);
// 读取第一章表格内容
XSSFSheet sheet = xwb.getSheet("2011");
// 获取第一行的字段名,与数据库中的字段相匹配
HashMap<String,Integer> titleMap = new HashMap<String,Integer>();
XSSFRow title = sheet.getRow(sheet.getFirstRowNum());
for (int j = title.getFirstCellNum(); j < title.getPhysicalNumberOfCells(); j++) {
titleMap.put(title.getCell(j).toString(), j);
}
//数据
XSSFRow row;
for (int i = sheet.getFirstRowNum()+1; i < sheet.getPhysicalNumberOfRows(); i++) {
row = sheet.getRow(i);
CpqaProject cpqaProject = new CpqaProject();
cpqaProject.setApp_show_name( getCellData(row,titleMap,"中文名") );
cpqaProject.setApp_short_name( getCellData(row,titleMap,"短名称") );
cpqaProject.setSdk_version( getCellData(row,titleMap,"SDK版本号") );
cpqaProject.setApp_version( getCellIntData(row,titleMap,"版本号") );
cpqaProject.setAppid( getCellIntData(row,titleMap,"APPID") );
cpqaProject.setChannel( getCellData(row,titleMap,"通道") );
cpqaProject.setDeveloper( getCellData(row,titleMap,"开发商") );
cpqaProject.setApp_type( getCellData(row,titleMap,"类型") );
cpqaProject.setSpecial_tech( getCellData(row,titleMap,"特殊技术") );
cpqaProject.setOperate_type( getCellData(row,titleMap,"操作类型") );
cpqaProject.setPlat( getCellData(row,titleMap,"平台") );
cpqaProject.setScreen( getCellData(row,titleMap,"原始屏幕") );
cpqaProject.setAdapt_screen( getCellData(row,titleMap,"适配屏幕") );
cpqaProject.setMemory( getCellData(row,titleMap,"内存(K)") );
cpqaProject.setMemory_top( getCellIntData(row,titleMap,"实际峰值(K)") );
cpqaProject.setMrp_size( getCellData(row,titleMap,"MRP包大小(K)") );
cpqaProject.setCharge( getCellData(row,titleMap,"收费策略") );
cpqaProject.setNotice_315( getCellData(row,titleMap,"315内容") );
cpqaProject.setRelease_time( getCellDateData(row,titleMap,"发布时间") );
cpqaProject.setConfirm_user( getCellData(row,titleMap,"确认人") );
cpqaProject.setProject_type( getCellData(row,titleMap,"项目类型") );
cpqaProject.setChange_log( getCellData(row,titleMap,"版本变更内容") );
cpqaProject.setIntroduce( getCellData(row,titleMap,"简介") );
cpqaProject.setSvn( getCellData(row,titleMap,"编译包版本地址") );
cpqaProject.setSvn_time( getCellDateData(row,titleMap,"SVN上传时间") );
cpqaProject.setUsername("胡凯");
cpqaMapper.insertCpqaProject(cpqaProject);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("static-access")
private String getCellData(XSSFRow row,HashMap<String,Integer> titleMap,String title) {
XSSFCell cell = row.getCell( titleMap.get(title));
if (cell.getCellType() == cell.CELL_TYPE_NUMERIC)
return ((Double)cell.getNumericCellValue()).intValue()+"";
else
return cell.getStringCellValue();
}
private int getCellIntData(XSSFRow row,HashMap<String,Integer> titleMap,String title) {
return ((Double)row.getCell( titleMap.get(title)).getNumericCellValue()).intValue();
}
private Date getCellDateData(XSSFRow row,HashMap<String,Integer> titleMap,String title) {
return row.getCell( titleMap.get(title) ).getDateCellValue();
}
}