cc0c3c643d767af7536e500cfd6cda2d4a85ec29.svn-base 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. package cn.com.goldenwater.dcproj.utils;
  2. import cn.com.goldenwater.dcproj.dto.ExcelInspLevelDto;
  3. import cn.com.goldenwater.dcproj.dto.ExcelInspPblm;
  4. import cn.com.goldenwater.dcproj.dto.ExcelInspPersDto;
  5. import cn.com.goldenwater.dcproj.dto.ExcelInspRsDto;
  6. import cn.com.goldenwater.dcproj.model.*;
  7. import cn.com.goldenwater.dcproj.vo.PblmObj;
  8. import cn.com.goldenwater.dcproj.vo.RsvrObj;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.apache.poi.ss.usermodel.Row;
  11. import org.apache.poi.ss.usermodel.Sheet;
  12. import org.apache.poi.ss.usermodel.Workbook;
  13. import org.apache.poi.ss.usermodel.WorkbookFactory;
  14. import org.apache.poi.xssf.usermodel.XSSFCell;
  15. import org.apache.poi.xssf.usermodel.XSSFRow;
  16. import org.apache.poi.xssf.usermodel.XSSFSheet;
  17. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import java.io.FileInputStream;
  20. import java.io.InputStream;
  21. import java.util.*;
  22. public class LoadExcel {
  23. /**
  24. * 导入稽察数据
  25. */
  26. public static List<TacObjPblmstb> getTacExcel(String filePath, List<TacObjSubject> objSubjects) throws Exception {
  27. List<TacObjPblmstb> pblmstbs = new ArrayList<>();
  28. InputStream is = new FileInputStream(filePath);
  29. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  30. Workbook workbook = WorkbookFactory.create(is);
  31. // 读取第一章表格内容
  32. Sheet sheet = workbook.getSheetAt(0);
  33. // 定义 row、cell
  34. Row row;
  35. String cell;
  36. // 循环输出表格中的内容
  37. row = sheet.getRow(1);
  38. String spfsnlType = row.getCell(1).toString();
  39. System.out.println("所属专业--->" + spfsnlType);
  40. List<TacExcel> tacExcels = new ArrayList<>();
  41. for (int i = sheet.getFirstRowNum() + 4; i < sheet.getPhysicalNumberOfRows(); i++) {
  42. row = sheet.getRow(i);
  43. if (row == null) {
  44. continue;
  45. }
  46. int total = 12;
  47. TacExcel tacExcel = new TacExcel();
  48. for (int j = row.getFirstCellNum(); j < total; j++) {
  49. System.out.println(i + "j-->" + row.getCell(j));
  50. if (row.getCell(j) == null) {
  51. break;
  52. }
  53. cell = row.getCell(j).toString();
  54. if (j == 0) {
  55. tacExcel.setCell0(cell);
  56. }
  57. if (j == 1) {
  58. tacExcel.setCell1(cell);
  59. }
  60. if (j == 2) {
  61. tacExcel.setCell2(cell);
  62. }
  63. if (j == 3) {
  64. tacExcel.setCell3(cell);
  65. }
  66. if (j == 4) {
  67. if (StringUtils.isNotBlank(cell)) {
  68. tacExcel.setCell4("1");
  69. } else {
  70. tacExcel.setCell4("0");
  71. }
  72. if (!"√".equals(cell)) {
  73. tacExcel.setCell4Desc(cell);
  74. }
  75. }
  76. if (j == 5) {
  77. if (StringUtils.isNotBlank(cell)) {
  78. tacExcel.setCell5("1");
  79. } else {
  80. tacExcel.setCell5("0");
  81. }
  82. if (!"√".equals(cell)) {
  83. tacExcel.setCell5Desc(cell);
  84. }
  85. }
  86. if (j == 6) {
  87. if (StringUtils.isNotBlank(cell)) {
  88. tacExcel.setCell6("1");
  89. } else {
  90. tacExcel.setCell6("0");
  91. }
  92. if (!"√".equals(cell)) {
  93. tacExcel.setCell6Desc(cell);
  94. }
  95. }
  96. if (j == 7) {
  97. tacExcel.setCell7(cell);
  98. }
  99. if (j == 8) {
  100. tacExcel.setCell8(cell);
  101. }
  102. if (j == 9) {
  103. tacExcel.setCell9(cell);
  104. }
  105. if (j == 10) {
  106. tacExcel.setCell10(cell);
  107. }
  108. if (j == 11) {
  109. tacExcel.setCell11(cell);
  110. }
  111. }
  112. tacExcels.add(tacExcel);
  113. }
  114. pblmstbs = convertTacExcel(tacExcels, spfsnlType, objSubjects);
  115. return pblmstbs;
  116. }
  117. private static List<TacObjPblmstb> convertTacExcel(List<TacExcel> tacExcels, String spfsnlType, List<TacObjSubject> objSubjects) {
  118. List<TacObjPblmstb> pblmstbs = new ArrayList<>();
  119. List<TacExcel> class1Excel = new ArrayList<>();
  120. List<TacExcel> class2Excel = new ArrayList<>();
  121. List<TacExcel> class3Excel = new ArrayList<>();
  122. /**分离数据*/
  123. for (TacExcel excel : tacExcels) {
  124. if (StringUtils.isBlank(excel.getCell0())) {
  125. continue;
  126. }
  127. if (StringUtils.isBlank(excel.getCell2()) && StringUtils.isBlank(excel.getCell3())) {
  128. if (!excel.getCell0().contains(".") || excel.getCell0().contains(".0")) {
  129. if (excel.getCell0().contains(".0")) {
  130. String cell0 = excel.getCell0().substring(0, excel.getCell0().indexOf("."));
  131. excel.setCell0(cell0);
  132. }
  133. class1Excel.add(excel);
  134. } else {
  135. class2Excel.add(excel);
  136. }
  137. } else {
  138. class3Excel.add(excel);
  139. }
  140. }
  141. for (TacExcel excel : class3Excel) {
  142. TacObjPblmstb objPblmstb = new TacObjPblmstb();
  143. objPblmstb.setSpfsnlType(spfsnlType);
  144. for (TacExcel excel1 : class1Excel) {
  145. if (excel.getCell0().startsWith(excel1.getCell0() + ".")) {
  146. objPblmstb.setClass1(excel1.getCell0());
  147. objPblmstb.setClass1Name(excel1.getCell1());
  148. }
  149. }
  150. for (TacExcel excel2 : class2Excel) {
  151. if (excel.getCell0().startsWith(excel2.getCell0() + ".")) {
  152. objPblmstb.setClass2(excel2.getCell0());
  153. objPblmstb.setClass2Name(excel2.getCell1());
  154. }
  155. }
  156. objPblmstb.setCate0(excel.getCell4());
  157. objPblmstb.setCate1(excel.getCell5());
  158. objPblmstb.setCate2(excel.getCell6());
  159. objPblmstb.setCate0Desc(excel.getCell4Desc());
  160. objPblmstb.setCate1Desc(excel.getCell5Desc());
  161. objPblmstb.setCate2Desc(excel.getCell6Desc());
  162. objPblmstb.setIntm(new Date());
  163. objPblmstb.setLawContent(excel.getCell3());
  164. objPblmstb.setRelativeLaw(excel.getCell2());
  165. objPblmstb.setPblmsDesc(excel.getCell1());
  166. String subjectIds = "";
  167. if (StringUtils.isNotBlank(excel.getCell7())) {
  168. subjectIds = getSubjectId(excel.getCell7(), objSubjects);
  169. }
  170. if (StringUtils.isNotBlank(excel.getCell8())) {
  171. subjectIds += "," + getSubjectId(excel.getCell8(), objSubjects) + "";
  172. }
  173. if (StringUtils.isNotBlank(excel.getCell9())) {
  174. subjectIds += "," + getSubjectId(excel.getCell9(), objSubjects) + "";
  175. }
  176. if (StringUtils.isNotBlank(excel.getCell10())) {
  177. subjectIds += "," + getSubjectId(excel.getCell10(), objSubjects) + "";
  178. }
  179. if (subjectIds.startsWith(",")) {
  180. subjectIds = subjectIds.substring(1, subjectIds.length());
  181. }
  182. objPblmstb.setSubjectIds(subjectIds);
  183. objPblmstb.setSn(excel.getCell0());
  184. objPblmstb.setNote(excel.getCell11());
  185. pblmstbs.add(objPblmstb);
  186. }
  187. return pblmstbs;
  188. }
  189. private static String getSubjectId(String cell7, List<TacObjSubject> objSubjects) {
  190. if (StringUtils.isBlank(cell7.trim())) {
  191. return "";
  192. }
  193. cell7 = cell7.replace(" ", "");
  194. for (TacObjSubject subject : objSubjects) {
  195. if (cell7.trim().startsWith(subject.getSubName())) {
  196. return subject.getId();
  197. }
  198. if (StringUtils.isNotBlank(cell7.trim()) && subject.getSubName().contains(cell7.trim())) {
  199. return subject.getId();
  200. }
  201. }
  202. return "";
  203. }
  204. public static List<ExcelInspPblm> getExcelEmpwtrun(String filePath) throws Exception {
  205. List<ExcelInspPblm> inspPblmList = new ArrayList<>();
  206. InputStream is = new FileInputStream(filePath);
  207. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  208. XSSFWorkbook xwb = new XSSFWorkbook(is);
  209. // 读取第一章表格内容
  210. XSSFSheet sheet = xwb.getSheetAt(1);
  211. // 定义 row、cell
  212. XSSFRow row;
  213. String cell;
  214. // 循环输出表格中的内容
  215. for (int i = sheet.getFirstRowNum() + 2; i < sheet.getPhysicalNumberOfRows() - 1; i++) {
  216. row = sheet.getRow(i);
  217. ExcelInspPblm inspPblm = new ExcelInspPblm();
  218. System.out.println("数为" + i);
  219. int total = 28;
  220. for (int j = row.getFirstCellNum(); j < total; j++) {
  221. cell = String.valueOf(row.getCell(j));
  222. if (cell == null) {
  223. continue;
  224. }
  225. if (j == 0) {
  226. inspPblm.setNumber(cell);
  227. }
  228. if (j == 1) {
  229. inspPblm.setProvince(cell);
  230. }
  231. if (j == 2) {
  232. inspPblm.setArea(cell);
  233. }
  234. if (j == 3) {
  235. inspPblm.setProjectNm(cell);
  236. }
  237. //开始添加管理单位
  238. if (j == 4) {
  239. inspPblm.setFirOrg(cell);
  240. }
  241. if (j == 5) {
  242. inspPblm.setSecOrg(cell);
  243. }
  244. if (j == 6) {
  245. inspPblm.setThiOrg(cell);
  246. }
  247. if (j == 7) {
  248. inspPblm.setInspPblmDesc(cell);
  249. }
  250. if (j == 8) {
  251. inspPblm.setQualityAttachNo(cell);
  252. }
  253. if (j == 9) {
  254. inspPblm.setQualitySn(cell);
  255. }
  256. if (j == 10) {
  257. inspPblm.setHetongNo(cell);
  258. }
  259. if (j == 11) {
  260. inspPblm.setHetongSN(cell);
  261. }
  262. if (j == 12) {
  263. inspPblm.setInspCate(cell);
  264. }
  265. if (j == 13) {
  266. inspPblm.setExp1(cell);
  267. }
  268. if (j == 14) {
  269. inspPblm.setExp2(cell);
  270. }
  271. if (j == 15) {
  272. inspPblm.setExp3(cell);
  273. }
  274. if (j == 16) {
  275. inspPblm.setExp4(cell);
  276. }
  277. if (j == 17) {
  278. inspPblm.setExp5(cell);
  279. }
  280. if (j == 18) {
  281. inspPblm.setRevicon(cell);
  282. }
  283. if (j == 19) {
  284. inspPblm.setReviDetail(cell);
  285. }
  286. if (j == 20) {
  287. continue;
  288. }
  289. if (j == 21) {
  290. inspPblm.setCheckLeader(cell);
  291. }
  292. if (j == 22) {
  293. inspPblm.setCheckPerson(cell);
  294. }
  295. if (j == 23) {
  296. inspPblm.setFaxianTime(cell);
  297. }
  298. if (j == 24) {
  299. inspPblm.setRechLeader(cell);
  300. }
  301. if (j == 25) {
  302. inspPblm.setRechPerson(cell);
  303. }
  304. if (j == 26) {
  305. inspPblm.setRechTime(cell);
  306. }
  307. if (j == 27) {
  308. inspPblm.setNote(cell);
  309. }
  310. }
  311. inspPblmList.add(inspPblm);
  312. }
  313. return inspPblmList;
  314. }
  315. public static List<ExcelInspPblm> getExcelFx(String filePath) throws Exception {
  316. List<ExcelInspPblm> inspPblmList = new ArrayList<>();
  317. InputStream is = new FileInputStream(filePath);
  318. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  319. XSSFWorkbook xwb = new XSSFWorkbook(is);
  320. // 读取第一章表格内容
  321. XSSFSheet sheet = xwb.getSheetAt(2);
  322. // 定义 row、cell
  323. XSSFRow row;
  324. String cell;
  325. // 循环输出表格中的内容
  326. for (int i = sheet.getFirstRowNum() + 2; i < sheet.getPhysicalNumberOfRows() - 1; i++) {
  327. row = sheet.getRow(i);
  328. ExcelInspPblm inspPblm = new ExcelInspPblm();
  329. System.out.println("数为" + i);
  330. int total = 9;
  331. for (int j = row.getFirstCellNum(); j < total; j++) {
  332. cell = row.getCell(j).toString();
  333. cell = String.valueOf(row.getCell(j));
  334. if (cell == null) {
  335. continue;
  336. }
  337. if (j == 0) {
  338. inspPblm.setNumber(cell);
  339. }
  340. //开始添加管理单位
  341. if (j == 1) {
  342. inspPblm.setFirOrg(cell);
  343. }
  344. if (j == 2) {
  345. inspPblm.setSecOrg(cell);
  346. }
  347. if (j == 3) {
  348. inspPblm.setThiOrg(cell);
  349. }
  350. if (j == 4) {
  351. inspPblm.setExp1(cell);
  352. }
  353. if (j == 5) {
  354. inspPblm.setExp2(cell);
  355. }
  356. if (j == 6) {
  357. inspPblm.setExp3(cell);
  358. }
  359. if (j == 7) {
  360. inspPblm.setExp4(cell);
  361. }
  362. if (j == 8) {
  363. inspPblm.setExp5(cell);
  364. }
  365. }
  366. }
  367. return inspPblmList;
  368. }
  369. public static List<ExcelInspPblm> getExcel(String filePath) throws Exception {
  370. List<ExcelInspPblm> inspPblmList = new ArrayList<>();
  371. InputStream is = new FileInputStream(filePath);
  372. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  373. XSSFWorkbook xwb = new XSSFWorkbook(is);
  374. // 读取第一章表格内容
  375. XSSFSheet sheet = xwb.getSheetAt(1);
  376. // 定义 row、cell
  377. XSSFRow row;
  378. String cell;
  379. // 循环输出表格中的内容
  380. for (int i = sheet.getFirstRowNum() + 2; i < sheet.getPhysicalNumberOfRows(); i++) {
  381. row = sheet.getRow(i);
  382. ExcelInspPblm inspPblm = new ExcelInspPblm();
  383. System.out.println("数为" + i);
  384. int total = 29;
  385. for (int j = row.getFirstCellNum(); j < total; j++) {
  386. cell = row.getCell(j).toString();
  387. if (j == 0) {
  388. inspPblm.setNumber(cell);
  389. }
  390. if (j == 1) {
  391. inspPblm.setProvince(cell);
  392. }
  393. if (j == 2) {
  394. inspPblm.setArea(cell);
  395. }
  396. if (j == 3) {
  397. inspPblm.setProjectNm(cell);
  398. }
  399. if (j == 4) {
  400. inspPblm.setUnitNm(cell);
  401. }
  402. if (j == 5) {
  403. inspPblm.setMoshi(cell);
  404. }
  405. if (j == 6) {
  406. inspPblm.setOrgName(cell);
  407. }
  408. if (j == 7) {
  409. inspPblm.setNature(cell);
  410. }
  411. if (j == 8) {
  412. inspPblm.setInspPblmDesc(cell);
  413. }
  414. if (j == 9) {
  415. inspPblm.setQualityAttachNo(cell);
  416. }
  417. if (j == 10) {
  418. inspPblm.setQualitySn(cell);
  419. }
  420. if (j == 11) {
  421. inspPblm.setHetongNo(cell);
  422. }
  423. if (j == 12) {
  424. inspPblm.setHetongSN(cell);
  425. }
  426. if (j == 13) {
  427. inspPblm.setInspCate(cell);
  428. }
  429. if (j == 14) {
  430. inspPblm.setExp1(cell);
  431. }
  432. if (j == 15) {
  433. inspPblm.setExp2(cell);
  434. }
  435. if (j == 16) {
  436. inspPblm.setExp3(cell);
  437. }
  438. if (j == 17) {
  439. inspPblm.setExp4(cell);
  440. }
  441. if (j == 18) {
  442. inspPblm.setExp5(cell);
  443. }
  444. if (j == 19) {
  445. inspPblm.setRevicon(cell);
  446. }
  447. if (j == 20) {
  448. inspPblm.setReviDetail(cell);
  449. }
  450. if (j == 21) {
  451. continue;
  452. }
  453. if (j == 22) {
  454. inspPblm.setCheckLeader(cell);
  455. }
  456. if (j == 23) {
  457. inspPblm.setCheckPerson(cell);
  458. }
  459. if (j == 24) {
  460. inspPblm.setFaxianTime(cell);
  461. }
  462. if (j == 25) {
  463. inspPblm.setRechLeader(cell);
  464. }
  465. if (j == 26) {
  466. inspPblm.setRechPerson(cell);
  467. }
  468. if (j == 27) {
  469. inspPblm.setRechTime(cell);
  470. }
  471. if (j == 28) {
  472. inspPblm.setNote(cell);
  473. }
  474. }
  475. inspPblmList.add(inspPblm);
  476. }
  477. return inspPblmList;
  478. }
  479. public static List<ObjInspPblms> getValues(String type, String attach, String filePath) {
  480. try {
  481. InputStream is = new FileInputStream(filePath);
  482. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  483. XSSFWorkbook xwb = new XSSFWorkbook(is);
  484. // 读取第一章表格内容
  485. XSSFSheet sheet = xwb.getSheetAt(1);
  486. // 定义 row、cell
  487. XSSFRow row;
  488. String cell;
  489. // 循环输出表格中的内容
  490. List<ObjInspPblms> inspPblms = new ArrayList<>();
  491. String title = "";
  492. String checkPoint = "";
  493. int sort1 = 0;
  494. int sort2 = 0;
  495. for (int i = sheet.getFirstRowNum() + 4; i < sheet.getPhysicalNumberOfRows(); i++) {
  496. row = sheet.getRow(i);
  497. ObjInspPblms objInspPblms = new ObjInspPblms();
  498. int total = row.getPhysicalNumberOfCells();
  499. for (int j = row.getFirstCellNum(); j < total; j++) {
  500. cell = row.getCell(j).toString();
  501. if (j == 0) {
  502. if (cell.contains(".")) {
  503. cell = cell.substring(0, cell.length() - 2);
  504. }
  505. }
  506. if (cell.startsWith("(")) {
  507. title = cell.substring(cell.indexOf(")") + 1, cell.length());
  508. sort1++;
  509. } else {
  510. if (cell.length() == 1 && cell.contains(".")) {
  511. cell = "00" + cell;
  512. }
  513. if (cell.length() == 2 && cell.contains(".")) {
  514. cell = "0" + cell;
  515. }
  516. if (j == 0) {
  517. objInspPblms.setGuid(type + "000000000000000000000000000" + cell);
  518. objInspPblms.setPguid(type + "000000000000000000000000000000");
  519. objInspPblms.setAttach(attach);
  520. objInspPblms.setType("6");
  521. cell = row.getCell(j).toString();
  522. cell = cell.substring(0, cell.length() - 2);
  523. objInspPblms.setSn(Integer.parseInt(cell) + "");
  524. objInspPblms.setInspPblmsName(title);
  525. }
  526. if (j == 1) {
  527. if (!"".equals(cell)) {
  528. checkPoint = cell;
  529. sort2 = 0;
  530. }
  531. objInspPblms.setSort1(sort1 + "");
  532. checkPoint = checkPoint.replace("\n", "");
  533. objInspPblms.setCheckPoint(checkPoint);
  534. }
  535. if (j == 2) {
  536. objInspPblms.setPblmDesc(cell);
  537. }
  538. if ("".equals(cell)) {
  539. continue;
  540. }
  541. boolean input = true;
  542. if (j == 3) {
  543. objInspPblms.setInspPblmCate("0");
  544. String cell2 = row.getCell(2).toString();
  545. if (!"√".equals(cell)) {
  546. objInspPblms.setPblmDesc("(" + cell + ")" + cell2);
  547. } else {
  548. objInspPblms.setPblmDesc(cell2);
  549. }
  550. sort2++;
  551. objInspPblms.setSort2(sort2 + "");
  552. inspPblms.add(objInspPblms);
  553. input = false;
  554. }
  555. boolean input1 = true;
  556. if (j == 4 && input) {
  557. objInspPblms.setInspPblmCate("1");
  558. String cell2 = row.getCell(2).toString();
  559. if (!"√".equals(cell)) {
  560. objInspPblms.setPblmDesc("(" + cell + ")" + cell2);
  561. } else {
  562. objInspPblms.setPblmDesc(cell2);
  563. }
  564. sort2++;
  565. objInspPblms.setSort2(sort2 + "");
  566. inspPblms.add(copyPblms(objInspPblms, sort2));
  567. input1 = false;
  568. }
  569. boolean input2 = true;
  570. if (j == 5 && input && input1) {
  571. objInspPblms.setInspPblmCate("2");
  572. String cell2 = row.getCell(2).toString();
  573. if (!"√".equals(cell)) {
  574. objInspPblms.setPblmDesc("(" + cell + ")" + cell2);
  575. } else {
  576. objInspPblms.setPblmDesc(cell2);
  577. }
  578. sort2++;
  579. objInspPblms.setSort2(sort2 + "");
  580. inspPblms.add(copyPblms(objInspPblms, sort2));
  581. input2 = false;
  582. }
  583. if ("1".equals(attach)) {
  584. if (j == 6 && input && input1 && input2) {
  585. objInspPblms.setInspPblmCate("3");
  586. String cell2 = row.getCell(2).toString();
  587. if (!"√".equals(cell)) {
  588. objInspPblms.setPblmDesc("(" + cell + ")" + cell2);
  589. } else {
  590. objInspPblms.setPblmDesc(cell2);
  591. }
  592. sort2++;
  593. objInspPblms.setSort2(sort2 + "");
  594. inspPblms.add(copyPblms(objInspPblms, sort2));
  595. }
  596. }
  597. }
  598. }
  599. }
  600. return inspPblms;
  601. } catch (Exception e) {
  602. System.out.println("已运行xlRead() : " + e);
  603. }
  604. return null;
  605. }
  606. public static ObjInspPblms copyPblms(ObjInspPblms inspPblms, int sort2) {
  607. ObjInspPblms objInspPblms = new ObjInspPblms();
  608. objInspPblms.setCheckPoint(inspPblms.getCheckPoint());
  609. objInspPblms.setPblmDesc(inspPblms.getPblmDesc());
  610. objInspPblms.setInspPblmCate(inspPblms.getInspPblmCate());
  611. objInspPblms.setType(inspPblms.getType());
  612. objInspPblms.setSn(inspPblms.getSn());
  613. objInspPblms.setAttach(inspPblms.getAttach());
  614. objInspPblms.setSort1(inspPblms.getSort1());
  615. //
  616. objInspPblms.setSort2(sort2 + "");
  617. sort2 = sort2 + 1;
  618. objInspPblms.setInspPblmsName(inspPblms.getInspPblmsName());
  619. String end = "6" + inspPblms.getGuid().substring(inspPblms.getGuid().length() - 3);
  620. String pguid = inspPblms.getGuid().substring(0, inspPblms.getGuid().length() - 4);
  621. objInspPblms.setGuid(pguid + end);
  622. objInspPblms.setPguid(inspPblms.getPguid());
  623. return objInspPblms;
  624. }
  625. public static List<RsvrObj> getRsvrObjList(String filePath) throws Exception {
  626. List<RsvrObj> rsvrObjList = new ArrayList<>();
  627. InputStream is = new FileInputStream(filePath);
  628. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  629. XSSFWorkbook xwb = new XSSFWorkbook(is);
  630. // 读取第一章表格内容
  631. XSSFSheet sheet = xwb.getSheetAt(1);
  632. // 定义 row、cell
  633. XSSFRow row;
  634. String cell;
  635. // 循环输出表格中的内容
  636. for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
  637. row = sheet.getRow(i);
  638. RsvrObj rsvrObj = new RsvrObj();
  639. int total = row.getPhysicalNumberOfCells();
  640. for (int j = row.getFirstCellNum(); j < total; j++) {
  641. cell = row.getCell(j).toString();
  642. if (j == 1) {
  643. rsvrObj.setProvince(cell);
  644. }
  645. if (j == 2) {
  646. if (cell.contains("市辖区")) {
  647. rsvrObj.setProvince(rsvrObj.getProvince() + "");
  648. } else {
  649. if (rsvrObj.getProvince().contains("省")) {
  650. rsvrObj.setProvince(rsvrObj.getProvince());
  651. } else {
  652. rsvrObj.setProvince(rsvrObj.getProvince());
  653. }
  654. }
  655. rsvrObj.setCity(cell);
  656. }
  657. if (j == 3) {
  658. rsvrObj.setCountry(cell);
  659. }
  660. if (j == 4) {
  661. rsvrObj.setRsvrNm(cell);
  662. }
  663. if (j == 5) {
  664. rsvrObj.setGuimo(encagl(cell));
  665. }
  666. if (j == 6) {
  667. rsvrObj.setTop(cell);
  668. }
  669. if (j == 7) {
  670. rsvrObj.setPoor(isPoor(cell));
  671. }
  672. if (j == 8) {
  673. rsvrObj.setRepeat(cell);
  674. }
  675. if (j == 9) {
  676. rsvrObj.setNote(cell);
  677. }
  678. if (j == 10) {
  679. rsvrObj.setOrgNm(cell);
  680. if ("长委".equals(cell)) {
  681. rsvrObj.setOrgNm("长江委");
  682. }
  683. }
  684. }
  685. rsvrObjList.add(rsvrObj);
  686. }
  687. return rsvrObjList;
  688. }
  689. private static String isPoor(String cell) {
  690. if (StringUtils.isBlank(cell) && "否".equals(cell)) {
  691. return "2";
  692. }
  693. return "1";
  694. }
  695. private static String encagl(String desc) {
  696. if ("小Ⅱ".equals(desc)) {
  697. return "5";
  698. }
  699. if ("小Ⅰ".equals(desc)) {
  700. return "4";
  701. }
  702. return "";
  703. }
  704. public static List<PblmObj> getPblmObjList(String filePath) throws Exception {
  705. List<PblmObj> rsvrObjList = new ArrayList<>();
  706. InputStream is = new FileInputStream(filePath);
  707. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  708. XSSFWorkbook xwb = new XSSFWorkbook(is);
  709. // 读取第一章表格内容
  710. XSSFSheet sheet = xwb.getSheetAt(3);
  711. // 定义 row、cell
  712. XSSFRow row;
  713. String cell;
  714. // 循环输出表格中的内容
  715. for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
  716. row = sheet.getRow(i);
  717. PblmObj rsvrObj = new PblmObj();
  718. int total = row.getPhysicalNumberOfCells();
  719. for (int j = row.getFirstCellNum(); j < total; j++) {
  720. cell = row.getCell(j).toString();
  721. if (j == 1) {
  722. rsvrObj.setProvince(cell);
  723. }
  724. if (j == 2) {
  725. if (cell.contains("市辖区")) {
  726. rsvrObj.setProvince(rsvrObj.getProvince() + "");
  727. } else {
  728. if (rsvrObj.getProvince().contains("省")) {
  729. rsvrObj.setProvince(rsvrObj.getProvince());
  730. } else {
  731. rsvrObj.setProvince(rsvrObj.getProvince() + "");
  732. }
  733. }
  734. rsvrObj.setCity(cell);
  735. }
  736. if (j == 3) {
  737. rsvrObj.setCountry(cell);
  738. }
  739. if (j == 4) {
  740. rsvrObj.setRsvrNm(cell);
  741. }
  742. if (j == 5) {
  743. rsvrObj.setGuimo(encagl(cell));
  744. }
  745. if (j == 6) {
  746. rsvrObj.setOrgNm(cell);
  747. }
  748. if (j == 7) {
  749. rsvrObj.setPblmName(isPoor(cell));
  750. }
  751. if (j == 8) {
  752. rsvrObj.setCheckPoint(cell);
  753. }
  754. if (j == 9) {
  755. rsvrObj.setPblmDesc(cell);
  756. }
  757. if (j == 10) {
  758. rsvrObj.setPblmCate(setCate(cell));
  759. }
  760. if (j == 11) {
  761. rsvrObj.setAttach(cell);
  762. }
  763. if (j == 12) {
  764. rsvrObj.setSnNum(cell);
  765. }
  766. }
  767. rsvrObjList.add(rsvrObj);
  768. }
  769. return rsvrObjList;
  770. }
  771. public static List<ImpPblmInfo> getPblmObjListByFile(MultipartFile file) {
  772. List<ImpPblmInfo> rsvrObjList = new ArrayList<>();
  773. try {
  774. InputStream is = file.getInputStream();
  775. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  776. XSSFWorkbook xwb = new XSSFWorkbook(is);
  777. // 读取第一章表格内容
  778. XSSFSheet sheet = xwb.getSheetAt(3);
  779. // 定义 row、cell
  780. XSSFRow row;
  781. String cell = "";
  782. // 循环输出表格中的内容
  783. for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
  784. row = sheet.getRow(i);
  785. ImpPblmInfo rsvrObj = new ImpPblmInfo();
  786. int total = row.getPhysicalNumberOfCells();
  787. for (int j = row.getFirstCellNum(); j < total; j++) {
  788. if (row != null) {
  789. if (row.getCell(j) != null) {
  790. cell = row.getCell(j).toString();
  791. if (StringUtils.isNotBlank(cell)) {
  792. cell = cell.trim();
  793. }
  794. }
  795. }
  796. if (j == 0) {
  797. rsvrObj.setSn(cell);
  798. }
  799. if (j == 1) {
  800. rsvrObj.setProName(cell);
  801. }
  802. if (j == 2) {
  803. if (cell.contains("市辖区")) {
  804. rsvrObj.setProName(rsvrObj.getProName() + "");
  805. } else {
  806. if (rsvrObj.getProName().contains("省")) {
  807. rsvrObj.setProName(rsvrObj.getProName());
  808. } else {
  809. rsvrObj.setProName(rsvrObj.getProName() + "");
  810. }
  811. }
  812. rsvrObj.setCityName(cell);
  813. }
  814. if (j == 3) {
  815. rsvrObj.setCountyName(cell);
  816. }
  817. if (j == 4) {
  818. rsvrObj.setRsName(cell);
  819. }
  820. if (j == 5) {
  821. rsvrObj.setEngScal(encagl(cell));
  822. }
  823. if (j == 6) {
  824. rsvrObj.setUnit(cell);
  825. }
  826. if (j == 7) {
  827. rsvrObj.setPblmType(isPoor(cell));
  828. }
  829. if (j == 8) {
  830. rsvrObj.setPblmOption(cell);
  831. }
  832. if (j == 9) {
  833. rsvrObj.setPblmDesc(cell);
  834. }
  835. if (j == 10) {
  836. rsvrObj.setPblmLevl(setCate(cell));
  837. }
  838. if (j == 11) {
  839. rsvrObj.setAttach(cell);
  840. }
  841. if (j == 12) {
  842. rsvrObj.setPblmSn(cell);
  843. }
  844. if (j == 13) {
  845. rsvrObj.setNote(cell);
  846. }
  847. }
  848. rsvrObjList.add(rsvrObj);
  849. }
  850. } catch (Exception e) {
  851. e.printStackTrace();
  852. }
  853. return rsvrObjList;
  854. }
  855. private static String setCate(String cell) {
  856. if ("一般".equals(cell)) {
  857. return "0";
  858. }
  859. if ("较重".equals(cell)) {
  860. return "1";
  861. }
  862. if ("严重".equals(cell)) {
  863. return "2";
  864. }
  865. return "3";
  866. }
  867. public static List<ExcelInspLevelDto> getExcelLevel(String filePath) throws Exception {
  868. InputStream is = new FileInputStream(filePath);
  869. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  870. XSSFWorkbook xwb = new XSSFWorkbook(is);
  871. int sheetSize = xwb.getNumberOfSheets();
  872. int id = 0;
  873. int disLv = 1;
  874. List<ExcelInspLevelDto> list = new ArrayList<>();
  875. for (int i = 0; i < sheetSize; i++) {
  876. XSSFSheet sheet = xwb.getSheetAt(i);
  877. XSSFRow row = sheet.getRow(sheet.getFirstRowNum());
  878. Map<String, Integer> map = getIdAndDisLv(row);
  879. id = map.get("ID");
  880. disLv = map.get("DISLV");
  881. for (int j = sheet.getFirstRowNum() + 1; j < sheet.getPhysicalNumberOfRows() - 1; j++) {
  882. ExcelInspLevelDto level = new ExcelInspLevelDto();
  883. XSSFRow con = sheet.getRow(j);
  884. level.setId(con.getCell(id).toString());
  885. level.setDisPlayLevel(getCellCon(con.getCell(disLv)));
  886. list.add(level);
  887. }
  888. }
  889. return list;
  890. }
  891. private static String getCellCon(XSSFCell cell) {
  892. if (cell == null) {
  893. return "10";
  894. }
  895. if (StringUtils.isBlank(cell.toString())) {
  896. return "10";
  897. }
  898. String con = String.valueOf(cell);
  899. if (con.indexOf("级") > 0) {
  900. return con.substring(0, con.indexOf("级"));
  901. }
  902. return con;
  903. }
  904. private static Map<String, Integer> getIdAndDisLv(XSSFRow row) {
  905. Map<String, Integer> map = new HashMap<>();
  906. if ("ID".equalsIgnoreCase(String.valueOf(row.getCell(0)))) {
  907. map.put("ID", 0);
  908. map.put("DISLV", 1);
  909. } else {
  910. map.put("ID", 1);
  911. map.put("DISLV", 0);
  912. }
  913. return map;
  914. }
  915. public static List<ExcelInspPersDto> getExcelPers(String filePath) throws Exception {
  916. InputStream is = new FileInputStream(filePath);
  917. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  918. XSSFWorkbook xwb = new XSSFWorkbook(is);
  919. XSSFSheet sheet = xwb.getSheetAt(0);
  920. List<ExcelInspPersDto> list = new ArrayList<>();
  921. for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
  922. XSSFRow row = sheet.getRow(i);
  923. int total = row.getPhysicalNumberOfCells();
  924. String cell = null;
  925. ExcelInspPersDto pers = new ExcelInspPersDto();
  926. for (int j = row.getFirstCellNum(); j < total; j++) {
  927. cell = String.valueOf(row.getCell(j));
  928. if (j == 0) {
  929. pers.setId(cell);
  930. }
  931. if (j == 1) {
  932. pers.setOrgName(cell);
  933. String orgId = "041";
  934. if ("长江委".equals(cell)) {
  935. orgId = "020";
  936. } else if ("黄委".equals(cell)) {
  937. orgId = "021";
  938. } else if ("淮委".equals(cell)) {
  939. orgId = "022";
  940. } else if ("海委".equals(cell)) {
  941. orgId = "023";
  942. } else if ("珠委".equals(cell)) {
  943. orgId = "024";
  944. } else if ("松辽委".equals(cell)) {
  945. orgId = "025";
  946. } else if ("太湖局".equals(cell)) {
  947. orgId = "026";
  948. } else if ("部督查办".equals(cell)) {
  949. orgId = "027";
  950. }
  951. pers.setOrgId(orgId);
  952. }
  953. if (j == 2) {
  954. pers.setGroName(cell);
  955. }
  956. if (j == 3) {
  957. pers.setHeadman(cell);
  958. }
  959. if (j == 4) {
  960. pers.setHeadNm(cell);
  961. }
  962. if (j == 5) {
  963. pers.setMembers(cell);
  964. }
  965. if (j == 6) {
  966. pers.setMemNm(cell);
  967. }
  968. if (j == 7) {
  969. pers.setConPers(cell);
  970. }
  971. if (j == 8) {
  972. pers.setConNm(cell);
  973. }
  974. }
  975. list.add(pers);
  976. }
  977. return list;
  978. }
  979. public static List<ExcelInspPersDto> getExcelPersByFile(MultipartFile file) throws Exception {
  980. InputStream is = file.getInputStream();
  981. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  982. XSSFWorkbook xwb = new XSSFWorkbook(is);
  983. XSSFSheet sheet = xwb.getSheetAt(0);
  984. List<ExcelInspPersDto> list = new ArrayList<>();
  985. String orgName = "";
  986. String proName = "";
  987. for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
  988. XSSFRow row = sheet.getRow(i);
  989. int total = row.getPhysicalNumberOfCells();
  990. String cell = null;
  991. ExcelInspPersDto pers = new ExcelInspPersDto();
  992. for (int j = row.getFirstCellNum(); j < total; j++) {
  993. cell = String.valueOf(row.getCell(j));
  994. if (j == 0) {
  995. pers.setId(cell);
  996. }
  997. if (j == 1) {
  998. if (StringUtils.isEmpty(cell)) {
  999. cell = orgName;
  1000. } else {
  1001. orgName = cell;
  1002. }
  1003. pers.setOrgName(cell);
  1004. String orgId = "041";
  1005. if ("长江委".equals(cell)) {
  1006. orgId = "020";
  1007. } else if ("黄委".equals(cell)) {
  1008. orgId = "021";
  1009. } else if ("淮委".equals(cell)) {
  1010. orgId = "022";
  1011. } else if ("海委".equals(cell)) {
  1012. orgId = "023";
  1013. } else if ("珠委".equals(cell)) {
  1014. orgId = "024";
  1015. } else if ("松辽委".equals(cell)) {
  1016. orgId = "025";
  1017. } else if ("太湖局".equals(cell)) {
  1018. orgId = "026";
  1019. } else if ("部督查办".equals(cell)) {
  1020. orgId = "027";
  1021. } else {
  1022. orgId = "";
  1023. }
  1024. pers.setOrgId(orgId);
  1025. }
  1026. if (j == 2) {
  1027. if (StringUtils.isEmpty(cell)) {
  1028. cell = proName;
  1029. } else {
  1030. proName = cell;
  1031. }
  1032. pers.setGroName(cell);
  1033. }
  1034. if (j == 3) {
  1035. pers.setHeadman(cell);
  1036. }
  1037. if (j == 4) {
  1038. pers.setHeadNm(cell);
  1039. }
  1040. if (j == 5) {
  1041. pers.setMembers(cell);
  1042. }
  1043. if (j == 6) {
  1044. pers.setMemNm(cell);
  1045. }
  1046. if (j == 7) {
  1047. pers.setConPers(cell);
  1048. }
  1049. if (j == 8) {
  1050. pers.setConNm(cell);
  1051. }
  1052. }
  1053. list.add(pers);
  1054. }
  1055. return list;
  1056. }
  1057. public static List<ExcelInspRsDto> getRsvrObjListByFile(MultipartFile file) throws Exception {
  1058. List<ExcelInspRsDto> rsvrObjList = new ArrayList<>();
  1059. InputStream is = file.getInputStream();
  1060. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  1061. XSSFWorkbook xwb = new XSSFWorkbook(is);
  1062. // 读取第一章表格内容
  1063. XSSFSheet sheet = xwb.getSheetAt(1);
  1064. // 定义 row、cell
  1065. XSSFRow row;
  1066. String cell;
  1067. // 循环输出表格中的内容
  1068. for (int i = sheet.getFirstRowNum() + 3; i < sheet.getPhysicalNumberOfRows(); i++) {
  1069. row = sheet.getRow(i);
  1070. ExcelInspRsDto rsvrObj = new ExcelInspRsDto();
  1071. int total = row.getPhysicalNumberOfCells();
  1072. for (int j = row.getFirstCellNum(); j < total; j++) {
  1073. cell = row.getCell(j).toString();
  1074. cell = cell.trim();
  1075. if (j == 1) {
  1076. rsvrObj.setProvince(cell);
  1077. }
  1078. if (j == 2) {
  1079. if (cell.contains("市辖区")) {
  1080. rsvrObj.setProvince(rsvrObj.getProvince() + "");
  1081. } else {
  1082. if (rsvrObj.getProvince().contains("省")) {
  1083. rsvrObj.setProvince(rsvrObj.getProvince());
  1084. } else {
  1085. rsvrObj.setProvince(rsvrObj.getProvince());
  1086. }
  1087. }
  1088. rsvrObj.setCity(cell);
  1089. }
  1090. if (j == 3) {
  1091. rsvrObj.setCountry(cell);
  1092. }
  1093. if (j == 4) {
  1094. rsvrObj.setRsvrNm(cell);
  1095. }
  1096. if (j == 5) {
  1097. rsvrObj.setGuimo(encagl(cell));
  1098. }
  1099. if (j == 6) {
  1100. rsvrObj.setTop(cell);
  1101. }
  1102. if (j == 7) {
  1103. rsvrObj.setPoor(isPoor(cell));
  1104. }
  1105. if (j == 8) {
  1106. rsvrObj.setRepeat(isPoor(cell));
  1107. }
  1108. if (j == 9) {
  1109. rsvrObj.setNote(cell);
  1110. }
  1111. if (j == 10) {
  1112. rsvrObj.setOrgNm(cell);
  1113. if ("长委".equals(cell)) {
  1114. rsvrObj.setOrgNm("长江委");
  1115. }
  1116. }
  1117. }
  1118. rsvrObjList.add(rsvrObj);
  1119. }
  1120. return rsvrObjList;
  1121. }
  1122. public static List<String> findYongshuihu(String filePath) throws Exception {
  1123. InputStream is = new FileInputStream(filePath);
  1124. List<String> arrays = new ArrayList<>();
  1125. List<String> modelarrays = new ArrayList<>();
  1126. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  1127. XSSFWorkbook xwb = new XSSFWorkbook(is);
  1128. XSSFSheet sheet = xwb.getSheetAt(0);
  1129. for (int i = sheet.getFirstRowNum(); i < sheet.getPhysicalNumberOfRows(); i++) {
  1130. XSSFRow row = sheet.getRow(i);
  1131. String cell = String.valueOf(row.getCell(0));
  1132. arrays.add(cell);
  1133. }
  1134. for (String str : arrays) {
  1135. String[] stres = str.split("、");
  1136. for (int i = 0; i < stres.length; i++) {
  1137. if (StringUtils.isBlank(stres[i])) {
  1138. continue;
  1139. }
  1140. String cell = stres[i].replace("*", "");
  1141. if (cell.contains(".")) {
  1142. cell = cell.substring(cell.indexOf(".") + 1, cell.length());
  1143. }
  1144. modelarrays.add(cell);
  1145. }
  1146. }
  1147. return modelarrays;
  1148. }
  1149. public static Set<String> getTacExcelList(String absolutePath) throws Exception {
  1150. InputStream is = new FileInputStream(absolutePath);
  1151. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  1152. Workbook workbook = WorkbookFactory.create(is);
  1153. // 读取第一章表格内容
  1154. Sheet sheet = workbook.getSheetAt(0);
  1155. // 定义 row、cell
  1156. Row row;
  1157. String cell;
  1158. // 循环输出表格中的内容
  1159. row = sheet.getRow(1);
  1160. Set<String> set = new HashSet<>();
  1161. for (int i = sheet.getFirstRowNum() + 4; i < sheet.getPhysicalNumberOfRows(); i++) {
  1162. row = sheet.getRow(i);
  1163. if (row == null) {
  1164. continue;
  1165. }
  1166. int total = 12;
  1167. for (int j = row.getFirstCellNum(); j < total; j++) {
  1168. if (row.getCell(j) == null) {
  1169. break;
  1170. }
  1171. cell = row.getCell(j).toString();
  1172. if (j == 7) {
  1173. set.add(cell.trim());
  1174. }
  1175. if (j == 8) {
  1176. set.add(cell.trim());
  1177. }
  1178. if (j == 9) {
  1179. set.add(cell.trim());
  1180. }
  1181. if (j == 10) {
  1182. set.add(cell.trim());
  1183. }
  1184. }
  1185. }
  1186. return set;
  1187. }
  1188. }