| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246 |
- package cn.com.goldenwater.dcproj.utils;
- import cn.com.goldenwater.dcproj.dto.ExcelInspLevelDto;
- import cn.com.goldenwater.dcproj.dto.ExcelInspPblm;
- import cn.com.goldenwater.dcproj.dto.ExcelInspPersDto;
- import cn.com.goldenwater.dcproj.dto.ExcelInspRsDto;
- import cn.com.goldenwater.dcproj.model.*;
- import cn.com.goldenwater.dcproj.vo.PblmObj;
- import cn.com.goldenwater.dcproj.vo.RsvrObj;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.ss.usermodel.WorkbookFactory;
- 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.web.multipart.MultipartFile;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import java.util.*;
- public class LoadExcel {
- /**
- * 导入稽察数据
- */
- public static List<TacObjPblmstb> getTacExcel(String filePath, List<TacObjSubject> objSubjects) throws Exception {
- List<TacObjPblmstb> pblmstbs = new ArrayList<>();
- InputStream is = new FileInputStream(filePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- Workbook workbook = WorkbookFactory.create(is);
- // 读取第一章表格内容
- Sheet sheet = workbook.getSheetAt(0);
- // 定义 row、cell
- Row row;
- String cell;
- // 循环输出表格中的内容
- row = sheet.getRow(1);
- String spfsnlType = row.getCell(1).toString();
- System.out.println("所属专业--->" + spfsnlType);
- List<TacExcel> tacExcels = new ArrayList<>();
- for (int i = sheet.getFirstRowNum() + 4; i < sheet.getPhysicalNumberOfRows(); i++) {
- row = sheet.getRow(i);
- if (row == null) {
- continue;
- }
- int total = 12;
- TacExcel tacExcel = new TacExcel();
- for (int j = row.getFirstCellNum(); j < total; j++) {
- System.out.println(i + "j-->" + row.getCell(j));
- if (row.getCell(j) == null) {
- break;
- }
- cell = row.getCell(j).toString();
- if (j == 0) {
- tacExcel.setCell0(cell);
- }
- if (j == 1) {
- tacExcel.setCell1(cell);
- }
- if (j == 2) {
- tacExcel.setCell2(cell);
- }
- if (j == 3) {
- tacExcel.setCell3(cell);
- }
- if (j == 4) {
- if (StringUtils.isNotBlank(cell)) {
- tacExcel.setCell4("1");
- } else {
- tacExcel.setCell4("0");
- }
- if (!"√".equals(cell)) {
- tacExcel.setCell4Desc(cell);
- }
- }
- if (j == 5) {
- if (StringUtils.isNotBlank(cell)) {
- tacExcel.setCell5("1");
- } else {
- tacExcel.setCell5("0");
- }
- if (!"√".equals(cell)) {
- tacExcel.setCell5Desc(cell);
- }
- }
- if (j == 6) {
- if (StringUtils.isNotBlank(cell)) {
- tacExcel.setCell6("1");
- } else {
- tacExcel.setCell6("0");
- }
- if (!"√".equals(cell)) {
- tacExcel.setCell6Desc(cell);
- }
- }
- if (j == 7) {
- tacExcel.setCell7(cell);
- }
- if (j == 8) {
- tacExcel.setCell8(cell);
- }
- if (j == 9) {
- tacExcel.setCell9(cell);
- }
- if (j == 10) {
- tacExcel.setCell10(cell);
- }
- if (j == 11) {
- tacExcel.setCell11(cell);
- }
- }
- tacExcels.add(tacExcel);
- }
- pblmstbs = convertTacExcel(tacExcels, spfsnlType, objSubjects);
- return pblmstbs;
- }
- private static List<TacObjPblmstb> convertTacExcel(List<TacExcel> tacExcels, String spfsnlType, List<TacObjSubject> objSubjects) {
- List<TacObjPblmstb> pblmstbs = new ArrayList<>();
- List<TacExcel> class1Excel = new ArrayList<>();
- List<TacExcel> class2Excel = new ArrayList<>();
- List<TacExcel> class3Excel = new ArrayList<>();
- /**分离数据*/
- for (TacExcel excel : tacExcels) {
- if (StringUtils.isBlank(excel.getCell0())) {
- continue;
- }
- if (StringUtils.isBlank(excel.getCell2()) && StringUtils.isBlank(excel.getCell3())) {
- if (!excel.getCell0().contains(".") || excel.getCell0().contains(".0")) {
- if (excel.getCell0().contains(".0")) {
- String cell0 = excel.getCell0().substring(0, excel.getCell0().indexOf("."));
- excel.setCell0(cell0);
- }
- class1Excel.add(excel);
- } else {
- class2Excel.add(excel);
- }
- } else {
- class3Excel.add(excel);
- }
- }
- for (TacExcel excel : class3Excel) {
- TacObjPblmstb objPblmstb = new TacObjPblmstb();
- objPblmstb.setSpfsnlType(spfsnlType);
- for (TacExcel excel1 : class1Excel) {
- if (excel.getCell0().startsWith(excel1.getCell0() + ".")) {
- objPblmstb.setClass1(excel1.getCell0());
- objPblmstb.setClass1Name(excel1.getCell1());
- }
- }
- for (TacExcel excel2 : class2Excel) {
- if (excel.getCell0().startsWith(excel2.getCell0() + ".")) {
- objPblmstb.setClass2(excel2.getCell0());
- objPblmstb.setClass2Name(excel2.getCell1());
- }
- }
- objPblmstb.setCate0(excel.getCell4());
- objPblmstb.setCate1(excel.getCell5());
- objPblmstb.setCate2(excel.getCell6());
- objPblmstb.setCate0Desc(excel.getCell4Desc());
- objPblmstb.setCate1Desc(excel.getCell5Desc());
- objPblmstb.setCate2Desc(excel.getCell6Desc());
- objPblmstb.setIntm(new Date());
- objPblmstb.setLawContent(excel.getCell3());
- objPblmstb.setRelativeLaw(excel.getCell2());
- objPblmstb.setPblmsDesc(excel.getCell1());
- String subjectIds = "";
- if (StringUtils.isNotBlank(excel.getCell7())) {
- subjectIds = getSubjectId(excel.getCell7(), objSubjects);
- }
- if (StringUtils.isNotBlank(excel.getCell8())) {
- subjectIds += "," + getSubjectId(excel.getCell8(), objSubjects) + "";
- }
- if (StringUtils.isNotBlank(excel.getCell9())) {
- subjectIds += "," + getSubjectId(excel.getCell9(), objSubjects) + "";
- }
- if (StringUtils.isNotBlank(excel.getCell10())) {
- subjectIds += "," + getSubjectId(excel.getCell10(), objSubjects) + "";
- }
- if (subjectIds.startsWith(",")) {
- subjectIds = subjectIds.substring(1, subjectIds.length());
- }
- objPblmstb.setSubjectIds(subjectIds);
- objPblmstb.setSn(excel.getCell0());
- objPblmstb.setNote(excel.getCell11());
- pblmstbs.add(objPblmstb);
- }
- return pblmstbs;
- }
- private static String getSubjectId(String cell7, List<TacObjSubject> objSubjects) {
- if (StringUtils.isBlank(cell7.trim())) {
- return "";
- }
- cell7 = cell7.replace(" ", "");
- for (TacObjSubject subject : objSubjects) {
- if (cell7.trim().startsWith(subject.getSubName())) {
- return subject.getId();
- }
- if (StringUtils.isNotBlank(cell7.trim()) && subject.getSubName().contains(cell7.trim())) {
- return subject.getId();
- }
- }
- return "";
- }
- public static List<ExcelInspPblm> getExcelEmpwtrun(String filePath) throws Exception {
- List<ExcelInspPblm> inspPblmList = new ArrayList<>();
- InputStream is = new FileInputStream(filePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- // 读取第一章表格内容
- XSSFSheet sheet = xwb.getSheetAt(1);
- // 定义 row、cell
- XSSFRow row;
- String cell;
- // 循环输出表格中的内容
- for (int i = sheet.getFirstRowNum() + 2; i < sheet.getPhysicalNumberOfRows() - 1; i++) {
- row = sheet.getRow(i);
- ExcelInspPblm inspPblm = new ExcelInspPblm();
- System.out.println("数为" + i);
- int total = 28;
- for (int j = row.getFirstCellNum(); j < total; j++) {
- cell = String.valueOf(row.getCell(j));
- if (cell == null) {
- continue;
- }
- if (j == 0) {
- inspPblm.setNumber(cell);
- }
- if (j == 1) {
- inspPblm.setProvince(cell);
- }
- if (j == 2) {
- inspPblm.setArea(cell);
- }
- if (j == 3) {
- inspPblm.setProjectNm(cell);
- }
- //开始添加管理单位
- if (j == 4) {
- inspPblm.setFirOrg(cell);
- }
- if (j == 5) {
- inspPblm.setSecOrg(cell);
- }
- if (j == 6) {
- inspPblm.setThiOrg(cell);
- }
- if (j == 7) {
- inspPblm.setInspPblmDesc(cell);
- }
- if (j == 8) {
- inspPblm.setQualityAttachNo(cell);
- }
- if (j == 9) {
- inspPblm.setQualitySn(cell);
- }
- if (j == 10) {
- inspPblm.setHetongNo(cell);
- }
- if (j == 11) {
- inspPblm.setHetongSN(cell);
- }
- if (j == 12) {
- inspPblm.setInspCate(cell);
- }
- if (j == 13) {
- inspPblm.setExp1(cell);
- }
- if (j == 14) {
- inspPblm.setExp2(cell);
- }
- if (j == 15) {
- inspPblm.setExp3(cell);
- }
- if (j == 16) {
- inspPblm.setExp4(cell);
- }
- if (j == 17) {
- inspPblm.setExp5(cell);
- }
- if (j == 18) {
- inspPblm.setRevicon(cell);
- }
- if (j == 19) {
- inspPblm.setReviDetail(cell);
- }
- if (j == 20) {
- continue;
- }
- if (j == 21) {
- inspPblm.setCheckLeader(cell);
- }
- if (j == 22) {
- inspPblm.setCheckPerson(cell);
- }
- if (j == 23) {
- inspPblm.setFaxianTime(cell);
- }
- if (j == 24) {
- inspPblm.setRechLeader(cell);
- }
- if (j == 25) {
- inspPblm.setRechPerson(cell);
- }
- if (j == 26) {
- inspPblm.setRechTime(cell);
- }
- if (j == 27) {
- inspPblm.setNote(cell);
- }
- }
- inspPblmList.add(inspPblm);
- }
- return inspPblmList;
- }
- public static List<ExcelInspPblm> getExcelFx(String filePath) throws Exception {
- List<ExcelInspPblm> inspPblmList = new ArrayList<>();
- InputStream is = new FileInputStream(filePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- // 读取第一章表格内容
- XSSFSheet sheet = xwb.getSheetAt(2);
- // 定义 row、cell
- XSSFRow row;
- String cell;
- // 循环输出表格中的内容
- for (int i = sheet.getFirstRowNum() + 2; i < sheet.getPhysicalNumberOfRows() - 1; i++) {
- row = sheet.getRow(i);
- ExcelInspPblm inspPblm = new ExcelInspPblm();
- System.out.println("数为" + i);
- int total = 9;
- for (int j = row.getFirstCellNum(); j < total; j++) {
- cell = row.getCell(j).toString();
- cell = String.valueOf(row.getCell(j));
- if (cell == null) {
- continue;
- }
- if (j == 0) {
- inspPblm.setNumber(cell);
- }
- //开始添加管理单位
- if (j == 1) {
- inspPblm.setFirOrg(cell);
- }
- if (j == 2) {
- inspPblm.setSecOrg(cell);
- }
- if (j == 3) {
- inspPblm.setThiOrg(cell);
- }
- if (j == 4) {
- inspPblm.setExp1(cell);
- }
- if (j == 5) {
- inspPblm.setExp2(cell);
- }
- if (j == 6) {
- inspPblm.setExp3(cell);
- }
- if (j == 7) {
- inspPblm.setExp4(cell);
- }
- if (j == 8) {
- inspPblm.setExp5(cell);
- }
- }
- }
- return inspPblmList;
- }
- public static List<ExcelInspPblm> getExcel(String filePath) throws Exception {
- List<ExcelInspPblm> inspPblmList = new ArrayList<>();
- InputStream is = new FileInputStream(filePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- // 读取第一章表格内容
- XSSFSheet sheet = xwb.getSheetAt(1);
- // 定义 row、cell
- XSSFRow row;
- String cell;
- // 循环输出表格中的内容
- for (int i = sheet.getFirstRowNum() + 2; i < sheet.getPhysicalNumberOfRows(); i++) {
- row = sheet.getRow(i);
- ExcelInspPblm inspPblm = new ExcelInspPblm();
- System.out.println("数为" + i);
- int total = 29;
- for (int j = row.getFirstCellNum(); j < total; j++) {
- cell = row.getCell(j).toString();
- if (j == 0) {
- inspPblm.setNumber(cell);
- }
- if (j == 1) {
- inspPblm.setProvince(cell);
- }
- if (j == 2) {
- inspPblm.setArea(cell);
- }
- if (j == 3) {
- inspPblm.setProjectNm(cell);
- }
- if (j == 4) {
- inspPblm.setUnitNm(cell);
- }
- if (j == 5) {
- inspPblm.setMoshi(cell);
- }
- if (j == 6) {
- inspPblm.setOrgName(cell);
- }
- if (j == 7) {
- inspPblm.setNature(cell);
- }
- if (j == 8) {
- inspPblm.setInspPblmDesc(cell);
- }
- if (j == 9) {
- inspPblm.setQualityAttachNo(cell);
- }
- if (j == 10) {
- inspPblm.setQualitySn(cell);
- }
- if (j == 11) {
- inspPblm.setHetongNo(cell);
- }
- if (j == 12) {
- inspPblm.setHetongSN(cell);
- }
- if (j == 13) {
- inspPblm.setInspCate(cell);
- }
- if (j == 14) {
- inspPblm.setExp1(cell);
- }
- if (j == 15) {
- inspPblm.setExp2(cell);
- }
- if (j == 16) {
- inspPblm.setExp3(cell);
- }
- if (j == 17) {
- inspPblm.setExp4(cell);
- }
- if (j == 18) {
- inspPblm.setExp5(cell);
- }
- if (j == 19) {
- inspPblm.setRevicon(cell);
- }
- if (j == 20) {
- inspPblm.setReviDetail(cell);
- }
- if (j == 21) {
- continue;
- }
- if (j == 22) {
- inspPblm.setCheckLeader(cell);
- }
- if (j == 23) {
- inspPblm.setCheckPerson(cell);
- }
- if (j == 24) {
- inspPblm.setFaxianTime(cell);
- }
- if (j == 25) {
- inspPblm.setRechLeader(cell);
- }
- if (j == 26) {
- inspPblm.setRechPerson(cell);
- }
- if (j == 27) {
- inspPblm.setRechTime(cell);
- }
- if (j == 28) {
- inspPblm.setNote(cell);
- }
- }
- inspPblmList.add(inspPblm);
- }
- return inspPblmList;
- }
- public static List<ObjInspPblms> getValues(String type, String attach, String filePath) {
- try {
- InputStream is = new FileInputStream(filePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- // 读取第一章表格内容
- XSSFSheet sheet = xwb.getSheetAt(1);
- // 定义 row、cell
- XSSFRow row;
- String cell;
- // 循环输出表格中的内容
- List<ObjInspPblms> inspPblms = new ArrayList<>();
- String title = "";
- String checkPoint = "";
- int sort1 = 0;
- int sort2 = 0;
- for (int i = sheet.getFirstRowNum() + 4; i < sheet.getPhysicalNumberOfRows(); i++) {
- row = sheet.getRow(i);
- ObjInspPblms objInspPblms = new ObjInspPblms();
- int total = row.getPhysicalNumberOfCells();
- for (int j = row.getFirstCellNum(); j < total; j++) {
- cell = row.getCell(j).toString();
- if (j == 0) {
- if (cell.contains(".")) {
- cell = cell.substring(0, cell.length() - 2);
- }
- }
- if (cell.startsWith("(")) {
- title = cell.substring(cell.indexOf(")") + 1, cell.length());
- sort1++;
- } else {
- if (cell.length() == 1 && cell.contains(".")) {
- cell = "00" + cell;
- }
- if (cell.length() == 2 && cell.contains(".")) {
- cell = "0" + cell;
- }
- if (j == 0) {
- objInspPblms.setGuid(type + "000000000000000000000000000" + cell);
- objInspPblms.setPguid(type + "000000000000000000000000000000");
- objInspPblms.setAttach(attach);
- objInspPblms.setType("6");
- cell = row.getCell(j).toString();
- cell = cell.substring(0, cell.length() - 2);
- objInspPblms.setSn(Integer.parseInt(cell) + "");
- objInspPblms.setInspPblmsName(title);
- }
- if (j == 1) {
- if (!"".equals(cell)) {
- checkPoint = cell;
- sort2 = 0;
- }
- objInspPblms.setSort1(sort1 + "");
- checkPoint = checkPoint.replace("\n", "");
- objInspPblms.setCheckPoint(checkPoint);
- }
- if (j == 2) {
- objInspPblms.setPblmDesc(cell);
- }
- if ("".equals(cell)) {
- continue;
- }
- boolean input = true;
- if (j == 3) {
- objInspPblms.setInspPblmCate("0");
- String cell2 = row.getCell(2).toString();
- if (!"√".equals(cell)) {
- objInspPblms.setPblmDesc("(" + cell + ")" + cell2);
- } else {
- objInspPblms.setPblmDesc(cell2);
- }
- sort2++;
- objInspPblms.setSort2(sort2 + "");
- inspPblms.add(objInspPblms);
- input = false;
- }
- boolean input1 = true;
- if (j == 4 && input) {
- objInspPblms.setInspPblmCate("1");
- String cell2 = row.getCell(2).toString();
- if (!"√".equals(cell)) {
- objInspPblms.setPblmDesc("(" + cell + ")" + cell2);
- } else {
- objInspPblms.setPblmDesc(cell2);
- }
- sort2++;
- objInspPblms.setSort2(sort2 + "");
- inspPblms.add(copyPblms(objInspPblms, sort2));
- input1 = false;
- }
- boolean input2 = true;
- if (j == 5 && input && input1) {
- objInspPblms.setInspPblmCate("2");
- String cell2 = row.getCell(2).toString();
- if (!"√".equals(cell)) {
- objInspPblms.setPblmDesc("(" + cell + ")" + cell2);
- } else {
- objInspPblms.setPblmDesc(cell2);
- }
- sort2++;
- objInspPblms.setSort2(sort2 + "");
- inspPblms.add(copyPblms(objInspPblms, sort2));
- input2 = false;
- }
- if ("1".equals(attach)) {
- if (j == 6 && input && input1 && input2) {
- objInspPblms.setInspPblmCate("3");
- String cell2 = row.getCell(2).toString();
- if (!"√".equals(cell)) {
- objInspPblms.setPblmDesc("(" + cell + ")" + cell2);
- } else {
- objInspPblms.setPblmDesc(cell2);
- }
- sort2++;
- objInspPblms.setSort2(sort2 + "");
- inspPblms.add(copyPblms(objInspPblms, sort2));
- }
- }
- }
- }
- }
- return inspPblms;
- } catch (Exception e) {
- System.out.println("已运行xlRead() : " + e);
- }
- return null;
- }
- public static ObjInspPblms copyPblms(ObjInspPblms inspPblms, int sort2) {
- ObjInspPblms objInspPblms = new ObjInspPblms();
- objInspPblms.setCheckPoint(inspPblms.getCheckPoint());
- objInspPblms.setPblmDesc(inspPblms.getPblmDesc());
- objInspPblms.setInspPblmCate(inspPblms.getInspPblmCate());
- objInspPblms.setType(inspPblms.getType());
- objInspPblms.setSn(inspPblms.getSn());
- objInspPblms.setAttach(inspPblms.getAttach());
- objInspPblms.setSort1(inspPblms.getSort1());
- //
- objInspPblms.setSort2(sort2 + "");
- sort2 = sort2 + 1;
- objInspPblms.setInspPblmsName(inspPblms.getInspPblmsName());
- String end = "6" + inspPblms.getGuid().substring(inspPblms.getGuid().length() - 3);
- String pguid = inspPblms.getGuid().substring(0, inspPblms.getGuid().length() - 4);
- objInspPblms.setGuid(pguid + end);
- objInspPblms.setPguid(inspPblms.getPguid());
- return objInspPblms;
- }
- public static List<RsvrObj> getRsvrObjList(String filePath) throws Exception {
- List<RsvrObj> rsvrObjList = new ArrayList<>();
- InputStream is = new FileInputStream(filePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- // 读取第一章表格内容
- XSSFSheet sheet = xwb.getSheetAt(1);
- // 定义 row、cell
- XSSFRow row;
- String cell;
- // 循环输出表格中的内容
- for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
- row = sheet.getRow(i);
- RsvrObj rsvrObj = new RsvrObj();
- int total = row.getPhysicalNumberOfCells();
- for (int j = row.getFirstCellNum(); j < total; j++) {
- cell = row.getCell(j).toString();
- if (j == 1) {
- rsvrObj.setProvince(cell);
- }
- if (j == 2) {
- if (cell.contains("市辖区")) {
- rsvrObj.setProvince(rsvrObj.getProvince() + "");
- } else {
- if (rsvrObj.getProvince().contains("省")) {
- rsvrObj.setProvince(rsvrObj.getProvince());
- } else {
- rsvrObj.setProvince(rsvrObj.getProvince());
- }
- }
- rsvrObj.setCity(cell);
- }
- if (j == 3) {
- rsvrObj.setCountry(cell);
- }
- if (j == 4) {
- rsvrObj.setRsvrNm(cell);
- }
- if (j == 5) {
- rsvrObj.setGuimo(encagl(cell));
- }
- if (j == 6) {
- rsvrObj.setTop(cell);
- }
- if (j == 7) {
- rsvrObj.setPoor(isPoor(cell));
- }
- if (j == 8) {
- rsvrObj.setRepeat(cell);
- }
- if (j == 9) {
- rsvrObj.setNote(cell);
- }
- if (j == 10) {
- rsvrObj.setOrgNm(cell);
- if ("长委".equals(cell)) {
- rsvrObj.setOrgNm("长江委");
- }
- }
- }
- rsvrObjList.add(rsvrObj);
- }
- return rsvrObjList;
- }
- private static String isPoor(String cell) {
- if (StringUtils.isBlank(cell) && "否".equals(cell)) {
- return "2";
- }
- return "1";
- }
- private static String encagl(String desc) {
- if ("小Ⅱ".equals(desc)) {
- return "5";
- }
- if ("小Ⅰ".equals(desc)) {
- return "4";
- }
- return "";
- }
- public static List<PblmObj> getPblmObjList(String filePath) throws Exception {
- List<PblmObj> rsvrObjList = new ArrayList<>();
- InputStream is = new FileInputStream(filePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- // 读取第一章表格内容
- XSSFSheet sheet = xwb.getSheetAt(3);
- // 定义 row、cell
- XSSFRow row;
- String cell;
- // 循环输出表格中的内容
- for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
- row = sheet.getRow(i);
- PblmObj rsvrObj = new PblmObj();
- int total = row.getPhysicalNumberOfCells();
- for (int j = row.getFirstCellNum(); j < total; j++) {
- cell = row.getCell(j).toString();
- if (j == 1) {
- rsvrObj.setProvince(cell);
- }
- if (j == 2) {
- if (cell.contains("市辖区")) {
- rsvrObj.setProvince(rsvrObj.getProvince() + "");
- } else {
- if (rsvrObj.getProvince().contains("省")) {
- rsvrObj.setProvince(rsvrObj.getProvince());
- } else {
- rsvrObj.setProvince(rsvrObj.getProvince() + "");
- }
- }
- rsvrObj.setCity(cell);
- }
- if (j == 3) {
- rsvrObj.setCountry(cell);
- }
- if (j == 4) {
- rsvrObj.setRsvrNm(cell);
- }
- if (j == 5) {
- rsvrObj.setGuimo(encagl(cell));
- }
- if (j == 6) {
- rsvrObj.setOrgNm(cell);
- }
- if (j == 7) {
- rsvrObj.setPblmName(isPoor(cell));
- }
- if (j == 8) {
- rsvrObj.setCheckPoint(cell);
- }
- if (j == 9) {
- rsvrObj.setPblmDesc(cell);
- }
- if (j == 10) {
- rsvrObj.setPblmCate(setCate(cell));
- }
- if (j == 11) {
- rsvrObj.setAttach(cell);
- }
- if (j == 12) {
- rsvrObj.setSnNum(cell);
- }
- }
- rsvrObjList.add(rsvrObj);
- }
- return rsvrObjList;
- }
- public static List<ImpPblmInfo> getPblmObjListByFile(MultipartFile file) {
- List<ImpPblmInfo> rsvrObjList = new ArrayList<>();
- try {
- InputStream is = file.getInputStream();
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- // 读取第一章表格内容
- XSSFSheet sheet = xwb.getSheetAt(3);
- // 定义 row、cell
- XSSFRow row;
- String cell = "";
- // 循环输出表格中的内容
- for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
- row = sheet.getRow(i);
- ImpPblmInfo rsvrObj = new ImpPblmInfo();
- int total = row.getPhysicalNumberOfCells();
- for (int j = row.getFirstCellNum(); j < total; j++) {
- if (row != null) {
- if (row.getCell(j) != null) {
- cell = row.getCell(j).toString();
- if (StringUtils.isNotBlank(cell)) {
- cell = cell.trim();
- }
- }
- }
- if (j == 0) {
- rsvrObj.setSn(cell);
- }
- if (j == 1) {
- rsvrObj.setProName(cell);
- }
- if (j == 2) {
- if (cell.contains("市辖区")) {
- rsvrObj.setProName(rsvrObj.getProName() + "");
- } else {
- if (rsvrObj.getProName().contains("省")) {
- rsvrObj.setProName(rsvrObj.getProName());
- } else {
- rsvrObj.setProName(rsvrObj.getProName() + "");
- }
- }
- rsvrObj.setCityName(cell);
- }
- if (j == 3) {
- rsvrObj.setCountyName(cell);
- }
- if (j == 4) {
- rsvrObj.setRsName(cell);
- }
- if (j == 5) {
- rsvrObj.setEngScal(encagl(cell));
- }
- if (j == 6) {
- rsvrObj.setUnit(cell);
- }
- if (j == 7) {
- rsvrObj.setPblmType(isPoor(cell));
- }
- if (j == 8) {
- rsvrObj.setPblmOption(cell);
- }
- if (j == 9) {
- rsvrObj.setPblmDesc(cell);
- }
- if (j == 10) {
- rsvrObj.setPblmLevl(setCate(cell));
- }
- if (j == 11) {
- rsvrObj.setAttach(cell);
- }
- if (j == 12) {
- rsvrObj.setPblmSn(cell);
- }
- if (j == 13) {
- rsvrObj.setNote(cell);
- }
- }
- rsvrObjList.add(rsvrObj);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return rsvrObjList;
- }
- private static String setCate(String cell) {
- if ("一般".equals(cell)) {
- return "0";
- }
- if ("较重".equals(cell)) {
- return "1";
- }
- if ("严重".equals(cell)) {
- return "2";
- }
- return "3";
- }
- public static List<ExcelInspLevelDto> getExcelLevel(String filePath) throws Exception {
- InputStream is = new FileInputStream(filePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- int sheetSize = xwb.getNumberOfSheets();
- int id = 0;
- int disLv = 1;
- List<ExcelInspLevelDto> list = new ArrayList<>();
- for (int i = 0; i < sheetSize; i++) {
- XSSFSheet sheet = xwb.getSheetAt(i);
- XSSFRow row = sheet.getRow(sheet.getFirstRowNum());
- Map<String, Integer> map = getIdAndDisLv(row);
- id = map.get("ID");
- disLv = map.get("DISLV");
- for (int j = sheet.getFirstRowNum() + 1; j < sheet.getPhysicalNumberOfRows() - 1; j++) {
- ExcelInspLevelDto level = new ExcelInspLevelDto();
- XSSFRow con = sheet.getRow(j);
- level.setId(con.getCell(id).toString());
- level.setDisPlayLevel(getCellCon(con.getCell(disLv)));
- list.add(level);
- }
- }
- return list;
- }
- private static String getCellCon(XSSFCell cell) {
- if (cell == null) {
- return "10";
- }
- if (StringUtils.isBlank(cell.toString())) {
- return "10";
- }
- String con = String.valueOf(cell);
- if (con.indexOf("级") > 0) {
- return con.substring(0, con.indexOf("级"));
- }
- return con;
- }
- private static Map<String, Integer> getIdAndDisLv(XSSFRow row) {
- Map<String, Integer> map = new HashMap<>();
- if ("ID".equalsIgnoreCase(String.valueOf(row.getCell(0)))) {
- map.put("ID", 0);
- map.put("DISLV", 1);
- } else {
- map.put("ID", 1);
- map.put("DISLV", 0);
- }
- return map;
- }
- public static List<ExcelInspPersDto> getExcelPers(String filePath) throws Exception {
- InputStream is = new FileInputStream(filePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- XSSFSheet sheet = xwb.getSheetAt(0);
- List<ExcelInspPersDto> list = new ArrayList<>();
- for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
- XSSFRow row = sheet.getRow(i);
- int total = row.getPhysicalNumberOfCells();
- String cell = null;
- ExcelInspPersDto pers = new ExcelInspPersDto();
- for (int j = row.getFirstCellNum(); j < total; j++) {
- cell = String.valueOf(row.getCell(j));
- if (j == 0) {
- pers.setId(cell);
- }
- if (j == 1) {
- pers.setOrgName(cell);
- String orgId = "041";
- if ("长江委".equals(cell)) {
- orgId = "020";
- } else if ("黄委".equals(cell)) {
- orgId = "021";
- } else if ("淮委".equals(cell)) {
- orgId = "022";
- } else if ("海委".equals(cell)) {
- orgId = "023";
- } else if ("珠委".equals(cell)) {
- orgId = "024";
- } else if ("松辽委".equals(cell)) {
- orgId = "025";
- } else if ("太湖局".equals(cell)) {
- orgId = "026";
- } else if ("部督查办".equals(cell)) {
- orgId = "027";
- }
- pers.setOrgId(orgId);
- }
- if (j == 2) {
- pers.setGroName(cell);
- }
- if (j == 3) {
- pers.setHeadman(cell);
- }
- if (j == 4) {
- pers.setHeadNm(cell);
- }
- if (j == 5) {
- pers.setMembers(cell);
- }
- if (j == 6) {
- pers.setMemNm(cell);
- }
- if (j == 7) {
- pers.setConPers(cell);
- }
- if (j == 8) {
- pers.setConNm(cell);
- }
- }
- list.add(pers);
- }
- return list;
- }
- public static List<ExcelInspPersDto> getExcelPersByFile(MultipartFile file) throws Exception {
- InputStream is = file.getInputStream();
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- XSSFSheet sheet = xwb.getSheetAt(0);
- List<ExcelInspPersDto> list = new ArrayList<>();
- String orgName = "";
- String proName = "";
- for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
- XSSFRow row = sheet.getRow(i);
- int total = row.getPhysicalNumberOfCells();
- String cell = null;
- ExcelInspPersDto pers = new ExcelInspPersDto();
- for (int j = row.getFirstCellNum(); j < total; j++) {
- cell = String.valueOf(row.getCell(j));
- if (j == 0) {
- pers.setId(cell);
- }
- if (j == 1) {
- if (StringUtils.isEmpty(cell)) {
- cell = orgName;
- } else {
- orgName = cell;
- }
- pers.setOrgName(cell);
- String orgId = "041";
- if ("长江委".equals(cell)) {
- orgId = "020";
- } else if ("黄委".equals(cell)) {
- orgId = "021";
- } else if ("淮委".equals(cell)) {
- orgId = "022";
- } else if ("海委".equals(cell)) {
- orgId = "023";
- } else if ("珠委".equals(cell)) {
- orgId = "024";
- } else if ("松辽委".equals(cell)) {
- orgId = "025";
- } else if ("太湖局".equals(cell)) {
- orgId = "026";
- } else if ("部督查办".equals(cell)) {
- orgId = "027";
- } else {
- orgId = "";
- }
- pers.setOrgId(orgId);
- }
- if (j == 2) {
- if (StringUtils.isEmpty(cell)) {
- cell = proName;
- } else {
- proName = cell;
- }
- pers.setGroName(cell);
- }
- if (j == 3) {
- pers.setHeadman(cell);
- }
- if (j == 4) {
- pers.setHeadNm(cell);
- }
- if (j == 5) {
- pers.setMembers(cell);
- }
- if (j == 6) {
- pers.setMemNm(cell);
- }
- if (j == 7) {
- pers.setConPers(cell);
- }
- if (j == 8) {
- pers.setConNm(cell);
- }
- }
- list.add(pers);
- }
- return list;
- }
- public static List<ExcelInspRsDto> getRsvrObjListByFile(MultipartFile file) throws Exception {
- List<ExcelInspRsDto> rsvrObjList = new ArrayList<>();
- InputStream is = file.getInputStream();
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- // 读取第一章表格内容
- XSSFSheet sheet = xwb.getSheetAt(1);
- // 定义 row、cell
- XSSFRow row;
- String cell;
- // 循环输出表格中的内容
- for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
- row = sheet.getRow(i);
- ExcelInspRsDto rsvrObj = new ExcelInspRsDto();
- int total = row.getPhysicalNumberOfCells();
- for (int j = row.getFirstCellNum(); j < total; j++) {
- cell = row.getCell(j).toString();
- cell = cell.trim();
- if (j == 1) {
- rsvrObj.setProvince(cell);
- }
- if (j == 2) {
- if (cell.contains("市辖区")) {
- rsvrObj.setProvince(rsvrObj.getProvince() + "");
- } else {
- if (rsvrObj.getProvince().contains("省")) {
- rsvrObj.setProvince(rsvrObj.getProvince());
- } else {
- rsvrObj.setProvince(rsvrObj.getProvince());
- }
- }
- rsvrObj.setCity(cell);
- }
- if (j == 3) {
- rsvrObj.setCountry(cell);
- }
- if (j == 4) {
- rsvrObj.setRsvrNm(cell);
- }
- if (j == 5) {
- rsvrObj.setGuimo(encagl(cell));
- }
- if (j == 6) {
- rsvrObj.setTop(cell);
- }
- if (j == 7) {
- rsvrObj.setPoor(isPoor(cell));
- }
- if (j == 8) {
- rsvrObj.setRepeat(isPoor(cell));
- }
- if (j == 9) {
- rsvrObj.setNote(cell);
- }
- if (j == 10) {
- rsvrObj.setOrgNm(cell);
- if ("长委".equals(cell)) {
- rsvrObj.setOrgNm("长江委");
- }
- }
- }
- rsvrObjList.add(rsvrObj);
- }
- return rsvrObjList;
- }
- public static List<String> findYongshuihu(String filePath) throws Exception {
- InputStream is = new FileInputStream(filePath);
- List<String> arrays = new ArrayList<>();
- List<String> modelarrays = new ArrayList<>();
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- XSSFWorkbook xwb = new XSSFWorkbook(is);
- XSSFSheet sheet = xwb.getSheetAt(0);
- for (int i = sheet.getFirstRowNum(); i < sheet.getPhysicalNumberOfRows(); i++) {
- XSSFRow row = sheet.getRow(i);
- String cell = String.valueOf(row.getCell(0));
- arrays.add(cell);
- }
- for (String str : arrays) {
- String[] stres = str.split("、");
- for (int i = 0; i < stres.length; i++) {
- if (StringUtils.isBlank(stres[i])) {
- continue;
- }
- String cell = stres[i].replace("*", "");
- if (cell.contains(".")) {
- cell = cell.substring(cell.indexOf(".") + 1, cell.length());
- }
- modelarrays.add(cell);
- }
- }
- return modelarrays;
- }
- public static Set<String> getTacExcelList(String absolutePath) throws Exception {
- InputStream is = new FileInputStream(absolutePath);
- // 构造 XSSFWorkbook 对象,strPath 传入文件路径
- Workbook workbook = WorkbookFactory.create(is);
- // 读取第一章表格内容
- Sheet sheet = workbook.getSheetAt(0);
- // 定义 row、cell
- Row row;
- String cell;
- // 循环输出表格中的内容
- row = sheet.getRow(1);
- Set<String> set = new HashSet<>();
- for (int i = sheet.getFirstRowNum() + 4; i < sheet.getPhysicalNumberOfRows(); i++) {
- row = sheet.getRow(i);
- if (row == null) {
- continue;
- }
- int total = 12;
- for (int j = row.getFirstCellNum(); j < total; j++) {
- if (row.getCell(j) == null) {
- break;
- }
- cell = row.getCell(j).toString();
- if (j == 7) {
- set.add(cell.trim());
- }
- if (j == 8) {
- set.add(cell.trim());
- }
- if (j == 9) {
- set.add(cell.trim());
- }
- if (j == 10) {
- set.add(cell.trim());
- }
- }
- }
- return set;
- }
- }
|