123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- package com.sinosoft.gps.bgd_mxb.DAO;
- import java.io.FileInputStream;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import org.apache.poi.hssf.usermodel.HSSFCell;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.xssf.usermodel.XSSFCell;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import com.formaction.vo.Msg;
- import com.persistence.service.assitant.generator.IdentityGenerator;
- import com.sinosoft.common.util.DateUtil;
- import com.sinosoft.em.alert.duty.records.dao.EcmDutyDao;
- import com.sinosoft.em.alert.duty.records.vo.EcmDutyDetail;
- import com.sinosoft.gps.bgd_mxb.vo.BGDBaoBiao;
- import com.sinosoft.gps.bgd_mxb.vo.BGDmingxi;
- import com.sinosoft.gps.bgd_mxb.vo.ECMGPSLIST;
- import com.sinosoft.gps.bgd_mxb.vo.ECMGPSLIST2;
- import com.sinosoft.lz.system.department.Department;
- import com.sinosoft.lz.system.department.DepartmentDao;
- public class ListExcel {
- // public Msg readExcel(String filePath,String oper_name, String oper_dept) {
- public Msg readExcel(String filePath,String writer, String write_dept,String taskId/*,String taskName,String taskTime*/) {
- Msg msg=new Msg();
- try {
-
- String excelType = filePath.substring(filePath.lastIndexOf(".") + 1);
-
- ECMGPSLIST_Dao listDao = new ECMGPSLIST_Dao();
-
- /******************通过任务id读取保供电范围的单位名称**************************/
- List<String[]> bgdCorpList = listDao.getBGDCorpByTaskId(taskId);
- String bgdArea = bgdCorpList.get(0)[0];
- String[] bgdAreaArr = null;
- if(bgdArea.contains(",")){
- bgdAreaArr = bgdArea.split(",");
- }
- /******************通过任务id读取保供电范围的单位名称**************************/
-
- // Read the Excel 2003-2007
- if (excelType != null && !"".equalsIgnoreCase(excelType)
- && !"xlsx".equalsIgnoreCase(excelType)) {
- // 创建对Excel工作簿文件的引用
- HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath));
- //只读一页
- HSSFSheet childSheet = workbook.getSheetAt(0);
-
- //************************检查是否匹配模版*****************************
- childSheet.getRow(1).getCell(0).setCellType(Cell.CELL_TYPE_STRING);
- String dw=childSheet.getRow(1).getCell(0).getStringCellValue(); // 单位
-
- childSheet.getRow(1).getCell(1).setCellType(Cell.CELL_TYPE_STRING);
- String checkInput_men = childSheet.getRow(1).getCell(1).getStringCellValue(); //投入人员(人次)
-
- childSheet.getRow(1).getCell(2).setCellType(Cell.CELL_TYPE_STRING);
- String checkInput_car = childSheet.getRow(1).getCell(2).getStringCellValue(); //投入车辆(台次)
-
- childSheet.getRow(1).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
- String fdc = childSheet.getRow(1).getCell(3).getStringCellValue(); //投入应急发电车(台)
-
- childSheet.getRow(1).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
- String fdj = childSheet.getRow(1).getCell(4).getStringCellValue(); //投入应急发电机(台)
-
- childSheet.getRow(1).getCell(5).setCellType(Cell.CELL_TYPE_STRING);
- String xinghao = childSheet.getRow(1).getCell(5).getStringCellValue(); //型号
-
- childSheet.getRow(1).getCell(6).setCellType(Cell.CELL_TYPE_STRING);
- String rongliang = childSheet.getRow(1).getCell(6).getStringCellValue(); //容量
-
- childSheet.getRow(1).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
- String changjia = childSheet.getRow(1).getCell(7).getStringCellValue(); //厂家
-
- childSheet.getRow(1).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
- String qtzhuagnbei = childSheet.getRow(1).getCell(8).getStringCellValue(); //其他应急装备
-
-
- if(!"单位".equals(dw) || !"投入人员(人次)".equals(checkInput_men) || !"投入车辆(车次)".equals(checkInput_car) || !"投入应急发电车(台)".equals(fdc) || !"投入应急发电机(台)".equals(fdj)
- || !"型号".equals(xinghao) || !"容量".equals(rongliang) || !"厂家".equals(changjia) || !"其他应急装备".equals(qtzhuagnbei)) {
- msg.setSucsess("false");
- msg.setInfo("22");//模版不匹配
- workbook.close();
- return msg;
- }
-
-
- List<BGDmingxi> gpsList2 = new ArrayList<BGDmingxi>();
- int rowCnt = childSheet.getLastRowNum();
- System.out.println("rowCnt"+ rowCnt);
- for (int r = 2; r <= rowCnt; r++) {// 循环该 子sheet row
- // EcmDutyDetail detail = new EcmDutyDetail();
- BGDmingxi list2 = new BGDmingxi();
- list2.setINPUT_NAME(writer);//填报人
- list2.setINPUT_DEPT(write_dept);//填报单位
- list2.setFD_OBJECTID(IdentityGenerator.getIdentityGenerator().gerenalIdentity(613));//主键
- /*list2.setFD_TASK(taskId);//任务id
- list2.setFD_TASK_NAME(taskName);//任务名称
- list2.setBGD_RW_TIME(taskTime);//任务时间
- */
- childSheet.getRow(r).getCell(0).setCellType(Cell.CELL_TYPE_STRING);
- list2.setBGD_DW(childSheet.getRow(r).getCell(0).getStringCellValue());//单位
- if(!checkBGDArea(childSheet.getRow(r).getCell(0).getStringCellValue(), bgdAreaArr)){
- msg.setSucsess("false1");
- msg.setInfo(r+"_"+1);
- workbook.close();
- return msg;
- }
- childSheet.getRow(r).getCell(1).setCellType(Cell.CELL_TYPE_STRING);
- list2.setMAN_COUNT(childSheet.getRow(r).getCell(1).getStringCellValue());//人次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(1).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+2);
- workbook.close();
- return msg;
- }
- childSheet.getRow(r).getCell(2).setCellType(Cell.CELL_TYPE_STRING);
- list2.setCAR_COUNT(childSheet.getRow(r).getCell(2).getStringCellValue());//车次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(2).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+3);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
- list2.setBGD_FDC(childSheet.getRow(r).getCell(3).getStringCellValue());//发电车
- if(!checkDataType(3 , childSheet.getRow(r).getCell(3).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+4);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
- list2.setBGD_FDJ(childSheet.getRow(r).getCell(4).getStringCellValue());//发电机
- if(!checkDataType(3 , childSheet.getRow(r).getCell(4).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+5);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(5).setCellType(Cell.CELL_TYPE_STRING);
- list2.setXINGHAO( childSheet.getRow(r).getCell(5).getStringCellValue()); //型号
-
- childSheet.getRow(r).getCell(6).setCellType(Cell.CELL_TYPE_STRING);
- list2.setRONGLIANG(childSheet.getRow(r).getCell(6).getStringCellValue()); //容量
-
- childSheet.getRow(r).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
- list2.setCHANJIA(childSheet.getRow(r).getCell(7).getStringCellValue()); //厂家
-
- childSheet.getRow(r).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
- list2.setQTZHUNGBEI(childSheet.getRow(r).getCell(8).getStringCellValue()); //其他应急装备
-
- gpsList2.add(list2);
-
- }
- workbook.close();
- // EcmDutyDao dao = new EcmDutyDao();
- if(listDao.saveBGDmingxi(gpsList2,taskId)){
- msg.setSucsess("true");
- }
- // }
-
- } else { // Read the Excel 2010
- XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(filePath));
- // for (int i = 0; i < workbook.getNumberOfSheets(); i++) {// 循环sheet
- // System.out.println("==========开始第 " + i
- // + " 个sheet============");
- XSSFSheet childSheet = workbook.getSheetAt(0);
- // EcmEmDuty duty = new EcmEmDuty();
- ECMGPSLIST list1 = new ECMGPSLIST();
-
- //************************检查是否匹配模版*****************************
- childSheet.getRow(1).getCell(0).setCellType(Cell.CELL_TYPE_STRING);
- String dw=childSheet.getRow(1).getCell(0).getStringCellValue(); // 单位
-
- childSheet.getRow(1).getCell(1).setCellType(Cell.CELL_TYPE_STRING);
- String checkInput_men = childSheet.getRow(1).getCell(1).getStringCellValue(); //投入人员(人次)
-
- childSheet.getRow(1).getCell(2).setCellType(Cell.CELL_TYPE_STRING);
- String checkInput_car = childSheet.getRow(1).getCell(2).getStringCellValue(); //投入车辆(台次)
-
- childSheet.getRow(1).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
- String fdc = childSheet.getRow(1).getCell(3).getStringCellValue(); //投入应急发电车(台)
-
- childSheet.getRow(1).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
- String fdj = childSheet.getRow(1).getCell(4).getStringCellValue(); //投入应急发电机(台)
-
- childSheet.getRow(1).getCell(5).setCellType(Cell.CELL_TYPE_STRING);
- String xinghao = childSheet.getRow(1).getCell(5).getStringCellValue(); //型号
-
- childSheet.getRow(1).getCell(6).setCellType(Cell.CELL_TYPE_STRING);
- String rongliang = childSheet.getRow(1).getCell(6).getStringCellValue(); //容量
-
- childSheet.getRow(1).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
- String changjia = childSheet.getRow(1).getCell(7).getStringCellValue(); //厂家
-
- childSheet.getRow(1).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
- String qtzhuagnbei = childSheet.getRow(1).getCell(8).getStringCellValue(); //其他应急装备
-
-
- if(!"单位".equals(dw) || !"投入人员(人次)".equals(checkInput_men) || !"投入车辆(车次)".equals(checkInput_car) || !"投入应急发电车(台)".equals(fdc) || !"投入应急发电机(台)".equals(fdj)
- || !"型号".equals(xinghao) || !"容量".equals(rongliang) || !"厂家".equals(changjia) || !"其他应急装备".equals(qtzhuagnbei)) {
- msg.setSucsess("false");
- msg.setInfo("22");
- workbook.close();
- return msg;
- }
-
- List<BGDmingxi> gsplist2 = new ArrayList<BGDmingxi>();
- for (int r = 2; r < childSheet.getPhysicalNumberOfRows(); r++) {// 循环该 子sheet row
- XSSFCell cel = childSheet.getRow(r).getCell(0);
- if(cel==null){
- continue;
- }
- // EcmDutyDetail detail = new EcmDutyDetail();
- BGDmingxi list2 = new BGDmingxi();
- list2.setINPUT_NAME(writer);//填报人
- list2.setINPUT_DEPT(write_dept);//填报单位
- list2.setFD_OBJECTID(IdentityGenerator.getIdentityGenerator().gerenalIdentity(613));//主键
- childSheet.getRow(r).getCell(0).setCellType(Cell.CELL_TYPE_STRING);
- list2.setBGD_DW(childSheet.getRow(r).getCell(0).getStringCellValue());//单位
- if(!checkBGDArea(childSheet.getRow(r).getCell(1).getStringCellValue(), bgdAreaArr)){
- msg.setSucsess("false1");
- msg.setInfo(r+"_"+1);
- workbook.close();
- return msg;
- }
- childSheet.getRow(r).getCell(1).setCellType(Cell.CELL_TYPE_STRING);
- list2.setMAN_COUNT(childSheet.getRow(r).getCell(1).getStringCellValue());//人次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(1).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+2);
- workbook.close();
- return msg;
- }
- childSheet.getRow(r).getCell(2).setCellType(Cell.CELL_TYPE_STRING);
- list2.setCAR_COUNT(childSheet.getRow(r).getCell(2).getStringCellValue());//车次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(2).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+3);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
- list2.setBGD_FDC(childSheet.getRow(r).getCell(3).getStringCellValue());//发电车
- if(!checkDataType(3 , childSheet.getRow(r).getCell(3).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+4);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
- list2.setBGD_FDJ(childSheet.getRow(r).getCell(4).getStringCellValue());//发电机
- if(!checkDataType(3 , childSheet.getRow(r).getCell(4).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+5);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(5).setCellType(Cell.CELL_TYPE_STRING);
- list2.setXINGHAO( childSheet.getRow(r).getCell(5).getStringCellValue()); //型号
-
- childSheet.getRow(r).getCell(6).setCellType(Cell.CELL_TYPE_STRING);
- list2.setRONGLIANG(childSheet.getRow(r).getCell(6).getStringCellValue()); //容量
-
- childSheet.getRow(r).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
- list2.setCHANJIA(childSheet.getRow(r).getCell(7).getStringCellValue()); //厂家
-
- childSheet.getRow(r).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
- list2.setQTZHUNGBEI(childSheet.getRow(r).getCell(8).getStringCellValue()); //其他应急装备
-
- gsplist2.add(list2);
- }
- workbook.close();
- // EcmDutyDao dao = new EcmDutyDao();
-
- if(listDao.saveBGDmingxi(gsplist2,taskId)){
- msg.setSucsess("true");
- }
- }
-
- //}
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage());
- }
-
- return msg;
- }
-
-
- public Msg readTaskBaoBiaoExcel(String filePath,String writer,String userId,String corpName, String write_dept,String taskId) {
- Msg msg=new Msg();
- try {
-
- String excelType = filePath.substring(filePath.lastIndexOf(".") + 1);
-
- ECMGPSLIST_Dao listDao = new ECMGPSLIST_Dao();
-
- /******************通过任务id读取任务编号**************************/
- List<String[]> bgdCorpList = listDao.getBGDNumByTaskId(taskId);
- String bgdNum = bgdCorpList.get(0)[0];
- String bgdName = bgdCorpList.get(0)[1];
-
- /******************通过任务id读取任务编号**************************/
-
- // Read the Excel 2003-2007
- if (excelType != null && !"".equalsIgnoreCase(excelType)
- && !"xlsx".equalsIgnoreCase(excelType)) {
- // 创建对Excel工作簿文件的引用
- HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath));
- //只读一页
- HSSFSheet childSheet = workbook.getSheetAt(0);
-
- //************************检查是否匹配模版*****************************
-
- childSheet.getRow(3).getCell(2).setCellType(Cell.CELL_TYPE_STRING);
- String fdcdr = childSheet.getRow(3).getCell(2).getStringCellValue(); //发电车单日最大用量/台
-
- childSheet.getRow(3).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
- String fdczl = childSheet.getRow(3).getCell(3).getStringCellValue(); //发电车投入总量/台次
-
- childSheet.getRow(3).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
- String fdjdr = childSheet.getRow(3).getCell(4).getStringCellValue(); ////发电机单日最大用量/台
-
- childSheet.getRow(3).getCell(5).setCellType(Cell.CELL_TYPE_STRING);
- String fdjzll = childSheet.getRow(3).getCell(5).getStringCellValue(); //发电机投入总量/台次
-
- childSheet.getRow(2).getCell(6).setCellType(Cell.CELL_TYPE_STRING);
- String cheliang = childSheet.getRow(2).getCell(6).getStringCellValue(); //车辆/辆次
-
- childSheet.getRow(2).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
- String zbzh = childSheet.getRow(2).getCell(7).getStringCellValue(); //值班指挥管理人员/人日
-
- childSheet.getRow(2).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
- String bdwbz = childSheet.getRow(2).getCell(8).getStringCellValue(); //本单位班组人员/人日
-
- childSheet.getRow(2).getCell(9).setCellType(Cell.CELL_TYPE_STRING);
- String abry = childSheet.getRow(2).getCell(9).getStringCellValue(); //安保人员/人日
-
- childSheet.getRow(2).getCell(10).setCellType(Cell.CELL_TYPE_STRING);
- String wwsc = childSheet.getRow(2).getCell(10).getStringCellValue(); //外委生产人员/人日
-
-
- /* if(!"单日最大用量/台".equals(fdcdr) || !"投入总量/台次".equals(fdczl)
- || !"单日最大用量/台".equals(fdjdr) || !"投入总量/台次".equals(fdjzll) || !"车辆/辆次".equals(cheliang) ||
- !"值班指挥管理人员/人日".equals(zbzh) || !"本单位班组人员/人日".equals(bdwbz) || !"安保人员/人日".equals(abry)
- || !"外委生产人员/人日".equals(wwsc)) {
- msg.setSucsess("false");
- msg.setInfo("22");//模版不匹配
- workbook.close();
- return msg;
- }*/
-
-
- List<BGDBaoBiao> gpsList2 = new ArrayList<BGDBaoBiao>();
- int rowCnt = childSheet.getLastRowNum();
- System.out.println("rowCnt"+ rowCnt);
- for (int r = 4; r < rowCnt; r++) {// 循环该 子sheet row
- String cel = childSheet.getRow(r).getCell(2).getStringCellValue();
- if(cel==null || "".equals(cel)){
- continue;
- }
-
- // EcmDutyDetail detail = new EcmDutyDetail();
- BGDBaoBiao list2 = new BGDBaoBiao();
- list2.setINPUT_NAME_ID(userId);
- list2.setINPUT_TIME(writer);
- list2.setINPUT_UNIT_ID(write_dept);
- list2.setINPUT_UNIT_NAME(corpName);
- list2.setGPS_TASK_NUMBER(bgdNum); //保供电任务编号
-
- list2.setFD_OBJECTID(IdentityGenerator.getIdentityGenerator().gerenalIdentity(620));//主键
- /*list2.setFD_TASK(taskId);//任务id
- list2.setFD_TASK_NAME(taskName);//任务名称
- list2.setBGD_RW_TIME(taskTime);//任务时间
- */
-
- childSheet.getRow(r).getCell(2).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_FDC_DAY(childSheet.getRow(r).getCell(2).getStringCellValue()); //发电车单日最大用量/台
- if(!checkDataType(3 , childSheet.getRow(r).getCell(2).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+3);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK__FDC_TOTAL(childSheet.getRow(r).getCell(3).getStringCellValue());//发电车投入总量/台次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(3).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+4);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_FDJ_DAY(childSheet.getRow(r).getCell(4).getStringCellValue());//发电机单日最大用量/台
- if(!checkDataType(3 , childSheet.getRow(r).getCell(4).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+5);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(5).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_FDJ_TOTAL( childSheet.getRow(r).getCell(5).getStringCellValue()); //发电机投入总量/台次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(5).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+6);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(6).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_CAR(childSheet.getRow(r).getCell(6).getStringCellValue()); //车辆/辆次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(6).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+7);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_ZBZHGLRY(childSheet.getRow(r).getCell(7).getStringCellValue()); //值班指挥管理人员/人日
- if(!checkDataType(3 , childSheet.getRow(r).getCell(7).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+8);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_BDWBZRY(childSheet.getRow(r).getCell(8).getStringCellValue()); //本单位班组人员/人日
- if(!checkDataType(3 , childSheet.getRow(r).getCell(8).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+9);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(9).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_ABRY( childSheet.getRow(r).getCell(9).getStringCellValue()); //安保人员/人日
- if(!checkDataType(3 , childSheet.getRow(r).getCell(9).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+10);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(10).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_WWSCRY( childSheet.getRow(r).getCell(10).getStringCellValue()); //外委生产人员/人日
- if(!checkDataType(3 , childSheet.getRow(r).getCell(10).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+11);
- workbook.close();
- return msg;
- }
-
-
- gpsList2.add(list2);
-
- }
- workbook.close();
- // EcmDutyDao dao = new EcmDutyDao();
- if(listDao.saveBGDBaoBiao(gpsList2,taskId,bgdNum,bgdName)){
- msg.setSucsess("true");
- }
- // }
-
- } else { // Read the Excel 2010
- XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(filePath));
- // for (int i = 0; i < workbook.getNumberOfSheets(); i++) {// 循环sheet
- // System.out.println("==========开始第 " + i
- // + " 个sheet============");
- XSSFSheet childSheet = workbook.getSheetAt(0);
- // EcmEmDuty duty = new EcmEmDuty();
- ECMGPSLIST list1 = new ECMGPSLIST();
-
- //************************检查是否匹配模版*****************************
- childSheet.getRow(1).getCell(1).setCellType(Cell.CELL_TYPE_STRING);
- String taskNum=childSheet.getRow(1).getCell(1).getStringCellValue(); //保供电任务编号
-
- childSheet.getRow(3).getCell(2).setCellType(Cell.CELL_TYPE_STRING);
- String fdcdr = childSheet.getRow(3).getCell(2).getStringCellValue(); //发电车单日最大用量/台
-
- childSheet.getRow(3).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
- String fdczl = childSheet.getRow(3).getCell(3).getStringCellValue(); //发电车投入总量/台次
-
- childSheet.getRow(3).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
- String fdjdr = childSheet.getRow(3).getCell(4).getStringCellValue(); ////发电机单日最大用量/台
-
- childSheet.getRow(3).getCell(5).setCellType(Cell.CELL_TYPE_STRING);
- String fdjzll = childSheet.getRow(3).getCell(5).getStringCellValue(); //发电机投入总量/台次
-
- childSheet.getRow(2).getCell(6).setCellType(Cell.CELL_TYPE_STRING);
- String cheliang = childSheet.getRow(2).getCell(6).getStringCellValue(); //车辆/辆次
-
- childSheet.getRow(2).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
- String zbzh = childSheet.getRow(2).getCell(7).getStringCellValue(); //值班指挥管理人员/人日
-
- childSheet.getRow(2).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
- String bdwbz = childSheet.getRow(2).getCell(8).getStringCellValue(); //本单位班组人员/人日
-
- childSheet.getRow(2).getCell(9).setCellType(Cell.CELL_TYPE_STRING);
- String abry = childSheet.getRow(2).getCell(9).getStringCellValue(); //安保人员/人日
-
- childSheet.getRow(2).getCell(10).setCellType(Cell.CELL_TYPE_STRING);
- String wwsc = childSheet.getRow(2).getCell(10).getStringCellValue(); //外委生产人员/人日
-
-
- /*
- if(!"保供电任务编号".equals(taskNum) || !"单日最大用量/台".equals(fdcdr) || !"投入总量/台次".equals(fdczl)
- || !"单日最大用量/台".equals(fdjdr) || !"投入总量/台次".equals(fdjzll) || !"车辆/辆次".equals(cheliang) ||
- !"值班指挥管理人员/人日".equals(zbzh) || !"本单位班组人员/人日".equals(bdwbz) || !"安保人员/人日".equals(abry)
- || !"外委生产人员/人日".equals(wwsc)) {
- msg.setSucsess("false");
- msg.setInfo("22");
- workbook.close();
- return msg;
- }*/
-
- List<BGDBaoBiao> gsplist2 = new ArrayList<BGDBaoBiao>();
- for (int r = 4; r < childSheet.getPhysicalNumberOfRows(); r++) {// 循环该 子sheet row
- String cel = childSheet.getRow(r).getCell(1).getStringCellValue();
- if(cel==null || "".equals(cel)){
- continue;
- }
- // EcmDutyDetail detail = new EcmDutyDetail();
- BGDBaoBiao list2 = new BGDBaoBiao();
- list2.setINPUT_NAME_ID(userId);
- list2.setINPUT_TIME(writer);
- list2.setINPUT_UNIT_ID(write_dept);
- list2.setINPUT_UNIT_NAME(corpName);
-
- list2.setFD_OBJECTID(IdentityGenerator.getIdentityGenerator().gerenalIdentity(620));//主键
- /*list2.setFD_TASK(taskId);//任务id
- list2.setFD_TASK_NAME(taskName);//任务名称
- list2.setBGD_RW_TIME(taskTime);//任务时间
- */
- childSheet.getRow(r).getCell(1).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_NUMBER(childSheet.getRow(r).getCell(1).getStringCellValue()); //保供电任务编号
- if(!checkBGDNum(childSheet.getRow(r).getCell(1).getStringCellValue(), bgdNum)){
- msg.setSucsess("false2");
- msg.setInfo(r+"_"+2);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(2).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_FDC_DAY(childSheet.getRow(r).getCell(2).getStringCellValue()); //发电车单日最大用量/台
- if(!checkDataType(3 , childSheet.getRow(r).getCell(2).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+3);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK__FDC_TOTAL(childSheet.getRow(r).getCell(3).getStringCellValue());//发电车投入总量/台次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(3).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+4);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_FDJ_DAY(childSheet.getRow(r).getCell(4).getStringCellValue());//发电机单日最大用量/台
- if(!checkDataType(3 , childSheet.getRow(r).getCell(4).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+5);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(5).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_FDJ_TOTAL( childSheet.getRow(r).getCell(5).getStringCellValue()); //发电机投入总量/台次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(5).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+6);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(6).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_CAR(childSheet.getRow(r).getCell(6).getStringCellValue()); //车辆/辆次
- if(!checkDataType(3 , childSheet.getRow(r).getCell(6).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+7);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_ZBZHGLRY(childSheet.getRow(r).getCell(7).getStringCellValue()); //值班指挥管理人员/人日
- if(!checkDataType(3 , childSheet.getRow(r).getCell(7).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+8);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_BDWBZRY(childSheet.getRow(r).getCell(8).getStringCellValue()); //本单位班组人员/人日
- if(!checkDataType(3 , childSheet.getRow(r).getCell(8).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+9);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(9).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_ABRY( childSheet.getRow(r).getCell(9).getStringCellValue()); //安保人员/人日
- if(!checkDataType(3 , childSheet.getRow(r).getCell(9).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+10);
- workbook.close();
- return msg;
- }
-
- childSheet.getRow(r).getCell(10).setCellType(Cell.CELL_TYPE_STRING);
- list2.setGPS_TASK_WWSCRY( childSheet.getRow(r).getCell(10).getStringCellValue()); //外委生产人员/人日
- if(!checkDataType(3 , childSheet.getRow(r).getCell(10).getStringCellValue())){
- msg.setSucsess("false");
- msg.setInfo(r+"_"+11);
- workbook.close();
- return msg;
- }
-
-
- gsplist2.add(list2);
-
- }
- workbook.close();
- // EcmDutyDao dao = new EcmDutyDao();
- if(listDao.saveBGDBaoBiao(gsplist2,taskId,bgdNum,bgdName)){
- msg.setSucsess("true");
- }
- }
-
- //}
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage());
- }
-
- return msg;
- }
-
-
-
-
- private boolean checkBGDNum(String stringCellValue, String bgdNum) {
- boolean flag = false;
- if(bgdNum!=null && bgdNum.equals(stringCellValue)){
- flag = true;
- }
- return flag;
- }
- /***
- * 检查单位是否在保供电范围之内
- * @param corp
- * @param corps
- * @return
- */
- private boolean checkBGDArea(String corp,String[] corps){
- boolean flag = false;
- for (int i = 0; i < corps.length; i++) {
- if(corp.equals(corps[i])){
- flag = true;
- break;
- }
- }
- return flag;
- }
-
- /***
- * 验证数据类型是否符合正则
- * 0:时间格式2016-03-10 11:11年月日时分
- * 1:手机号码
- * 2:人名(中文汉字或英文?)
- 、 * @param i
- * @param value
- */
- private boolean checkDataType(int i, String value1) {
- System.out.println("====================================");
- String el = "";
- if(i==0){//0:验证 时间格式2016-03-10 11:11年月日时分
- el = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])"
- + "|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|"
- + "([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))"
- + "[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))"
- + "|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))\\s{1}[0-5]{1}[0-9]{1}\\:[0-5]{1}[0-9]{1}$";
- }else if(i==1){//1:手机号码
- el = "^[1]{1}[0-9]{10}$";
- }else if(i==2){//2:人名(中文汉字或英文)
- el = "^[A-Za-z\u4e00-\u9fa5]+$";
- }else if(i==3){//五位以内数字
- el = "^[0-9]{1,5}$";
- }
- Pattern pat = Pattern.compile(el);
- Matcher mat = pat.matcher(value1);
- boolean dataType = mat.matches();
- return dataType;
- }
-
- }
|