32bb17e69090b90809d15e944a21b36aea803eab.svn-base 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  1. package cn.com.goldenwater.dcproj.controller.importex;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.dao.*;
  5. import cn.com.goldenwater.dcproj.model.*;
  6. import cn.com.goldenwater.dcproj.param.AttAdXBaseParam;
  7. import cn.com.goldenwater.dcproj.param.AttWintBaseBParam;
  8. import cn.com.goldenwater.id.util.UuidUtil;
  9. import org.apache.commons.lang.math.NumberUtils;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  12. import org.apache.poi.ooxml.POIXMLDocument;
  13. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  14. import org.apache.poi.openxml4j.opc.OPCPackage;
  15. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  16. import org.apache.poi.ss.usermodel.*;
  17. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RequestMethod;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import java.io.*;
  23. import java.util.*;
  24. import java.util.regex.Pattern;
  25. /**
  26. * 取水excel读取准备入库
  27. */
  28. @RestController
  29. @RequestMapping(value = "/qs")
  30. public class QsReadExcelController extends BaseController {
  31. @Autowired
  32. private AttWintBaseBDao wintBaseBDao;
  33. @Autowired
  34. private AttWiuBaseDao wiuBaseDao;
  35. @Autowired
  36. private AttWiuIntPlDao wiuIntPlDao;
  37. @Autowired
  38. private AttWiuMeasDwtDao measDwtDao;
  39. @Autowired
  40. private AttWiuWatConsDao wiuWatConsDao;
  41. @Autowired
  42. private AttWiuWatLicDao wiuWatLicDao;
  43. @Autowired
  44. private AttAdXBaseDao attAdXBaseDao;
  45. //统计读取excel文件的个数
  46. public static int countDealExcelNum = 0;
  47. //统计是否有多用户公用取水口的情况
  48. public static int countIsHasSheet3 = 0;
  49. //用list存一下发生空指针时的坐标
  50. public static List<String> zbs = new ArrayList<>();
  51. public static List<String> NullList = new ArrayList<>();
  52. public static List<String> qushuikou = new ArrayList<>();
  53. //存一下文件名
  54. public static String doDealIngFileName = "";
  55. //存一下是多用户的文件名
  56. public static List<String> dyhFileNames = new ArrayList<>();
  57. //非长江流域的
  58. // public static String originalPath = "C:\\Users\\81229\\Desktop\\全国重点监管取水口汇总20190725\\全国重点监管取水口--初始台账\\珠江委审批全国重点监管取水口初始台账"; //非多用户
  59. // public static String originalPath = "C:\\Users\\81229\\Desktop\\全国重点监管取水口汇总20190725\\全国重点监管取水口--初始台账\\湖南"; //非多用户 贵州,一级区名称不同于其他excel这里没值
  60. // public static String originalPath = "C:\\Users\\81229\\Desktop\\全国重点监管取水口汇总20190725\\全国重点监管取水口--初始台账\\河北省"; //非多用户 海委,虽然写了多用户取水,但是没填其他sheet
  61. // public static String originalPath = "C:\\Users\\81229\\Desktop\\全国重点监管取水口汇总20190725\\全国重点监管取水口--初始台账\\江苏省"; //黑龙江,有多用户的情况,34,77,78,79,89
  62. // public static String originalPath = "C:\\Users\\81229\\Desktop\\全国重点监管取水口汇总20190725\\全国重点监管取水口--初始台账\\内蒙古自治区"; //黑龙江,有多用户的情况,34,77,78,79,89
  63. // public static String originalPath = "C:\\Users\\81229\\Desktop\\全国重点监管取水口汇总20190725"; //黑龙江,有多用户的情况,34,77,78,79,89
  64. public static String originalPath = "D:\\home\\全国重点监管取水口汇总20190903复核后更新"; //黑龙江,有多用户的情况,34,77,78,79,89
  65. // public static String originalPath = "D:\\home\\无法解析"; //黑龙江,有多用户的情况,34,77,78,79,89
  66. // public static String originalPath = "C:\\Users\\81229\\Desktop\\全国重点监管取水口汇总2019072777\\全国重点监管取水口--初始台账"; //黑龙江,有多用户的情况,34,77,78,79,89
  67. static Pattern pattern = Pattern.compile("([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])");
  68. @RequestMapping(value = "/index", method = RequestMethod.GET)
  69. public BaseResponse index() throws Exception {
  70. //加载数据库链接
  71. //循环读取,处理文件夹的情况
  72. readFileAndGetDataByCycle(originalPath);
  73. System.out.println("发生空指针异常时的坐标有:" + Arrays.toString(zbs.toArray()));
  74. System.out.println("异常文件" + Arrays.toString(NullList.toArray()));
  75. System.out.println("名字为空--" + Arrays.toString(qushuikou.toArray()));
  76. return buildSuccessResponse();
  77. }
  78. /**
  79. * 根据路径读取excel并获取数据
  80. */
  81. private void readFileAndGetDataByCycle(String originalPath) throws Exception {
  82. //根据path读取文件
  83. File file = new File(originalPath);
  84. //递归处理文件
  85. dealFile(file);
  86. }
  87. /**
  88. * 循环处理file
  89. *
  90. * @param file
  91. */
  92. private void dealFile(File file) throws Exception {
  93. //先判断file是否是文件
  94. if (file.isDirectory()) {
  95. File[] files = file.listFiles();
  96. if (null != files && 0 < files.length) {
  97. for (File f : files) {
  98. //递归处理
  99. dealFile(f);
  100. }
  101. }
  102. } else {
  103. countDealExcelNum++;
  104. //是excel,处理数据
  105. Workbook wb = readExcel(file);
  106. if (wb == null) {
  107. return;
  108. }
  109. doDealIngFileName = file.getName();
  110. //暂时是输出一句话
  111. // dealDataAndToConsole(wb);
  112. System.out.println("当前处理文件--->" + doDealIngFileName);
  113. //处理wb,也就是excel
  114. if (file.getName().contains("对应名录") || !file.getName().contains("名录")) {
  115. Map<String, String> map = dealDataAndSaveInMap(wb);
  116. System.out.println("处理的文件名是 :" + file.getName());
  117. int qskcstzb = wb.getSheetIndex("取水口初始台账表");
  118. System.out.println("获取数据的sheet的索引是:" + wb.getSheetIndex("取水口初始台账表"));
  119. System.out.println("处理的excel文件个数 :" + countDealExcelNum);
  120. System.out.println("是否有多用户公用取水口的情况 :" + countIsHasSheet3);
  121. System.out.println("多用户取水的文件名 :" + Arrays.toString(dyhFileNames.toArray()));
  122. //插入数据库
  123. ArrayList<String> params1 = new ArrayList<>();
  124. ArrayList<String> params2 = new ArrayList<>();
  125. ArrayList<String> params3 = new ArrayList<>();
  126. ArrayList<String> params4 = new ArrayList<>(); //对应多取水户2
  127. ArrayList<String> params5 = new ArrayList<>(); //对应多取水户2
  128. ArrayList<String> params6 = new ArrayList<>(); //对应多取水户3
  129. ArrayList<String> params7 = new ArrayList<>(); //对应多取水户3
  130. ArrayList<String> params8 = new ArrayList<>(); //对应多取水户4
  131. ArrayList<String> params9 = new ArrayList<>(); //对应多取水户4
  132. ArrayList<String> params10 = new ArrayList<>(); //对应多取水户5
  133. ArrayList<String> params11 = new ArrayList<>(); //对应多取水户5
  134. String idA = UUID.randomUUID().toString().replace("-", "");
  135. String idB = UUID.randomUUID().toString().replace("-", "");
  136. String idC = UUID.randomUUID().toString().replace("-", "");
  137. String id4 = UUID.randomUUID().toString().replace("-", ""); //多用户2 上半部分
  138. String id5 = UUID.randomUUID().toString().replace("-", ""); //多用户2 下半部分
  139. String id6 = UUID.randomUUID().toString().replace("-", ""); //多用户3 上半部分
  140. String id7 = UUID.randomUUID().toString().replace("-", ""); //多用户3 下半部分
  141. String id8 = UUID.randomUUID().toString().replace("-", ""); //多用户4 上半部分
  142. String id9 = UUID.randomUUID().toString().replace("-", ""); //多用户4 下半部分
  143. String id10 = UUID.randomUUID().toString().replace("-", ""); //多用户5 上半部分
  144. String id11 = UUID.randomUUID().toString().replace("-", ""); //多用户5 下半部分
  145. params1.add(idA);
  146. params1.add(file.getName());
  147. params2.add(idB);
  148. params2.add(file.getName());
  149. params3.add(idC);
  150. params3.add(file.getName());
  151. params4.add(id4);
  152. params4.add(file.getName());
  153. params5.add(id5);
  154. params5.add(file.getName());
  155. params6.add(id6);
  156. params6.add(file.getName());
  157. params7.add(id7);
  158. params7.add(file.getName());
  159. params8.add(id8);
  160. params8.add(file.getName());
  161. params9.add(id9);
  162. params9.add(file.getName());
  163. params10.add(id10);
  164. params10.add(file.getName());
  165. params11.add(id11);
  166. params11.add(file.getName());
  167. //遍历map 输出值
  168. int index = 0;
  169. for (Map.Entry<String, String> entry : map.entrySet()) {
  170. index++;
  171. System.out.print(entry.getKey() + "=" + entry.getValue() + "\t");
  172. //System.out.println(entry.getKey() + "=" + entry.getValue());
  173. if (22 > params1.size()) {
  174. params1.add(entry.getValue());
  175. }
  176. //组织234部分的数据
  177. if (21 <= index && 55 >= index) {
  178. params2.add(entry.getValue());
  179. }
  180. //组织5部分
  181. if (56 <= index && 81 >= index) {
  182. params3.add(entry.getValue());
  183. }
  184. //多用户2 上半部分
  185. if (82 <= index && 116 >= index) {
  186. params4.add(entry.getValue());
  187. }
  188. //多用户2 下半部分
  189. if (117 <= index && 142 >= index) {
  190. params5.add(entry.getValue());
  191. }
  192. //多用户3 上半部分
  193. if (143 <= index && 177 >= index) {
  194. params6.add(entry.getValue());
  195. }
  196. //多用户3 下半部分
  197. if (178 <= index && 203 >= index) {
  198. params7.add(entry.getValue());
  199. }
  200. //多用户4 上半部分
  201. if (204 <= index && 238 >= index) {
  202. params8.add(entry.getValue());
  203. }
  204. //多用户4 下半部分
  205. if (239 <= index && 264 >= index) {
  206. params9.add(entry.getValue());
  207. }
  208. //多用户5 上半部分
  209. if (265 <= index && 299 >= index) {
  210. params10.add(entry.getValue());
  211. }
  212. //多用户5 下半部分
  213. if (300 <= index && 325 >= index) {
  214. params11.add(entry.getValue());
  215. }
  216. }
  217. params2.add(idA);
  218. params3.add(idB);
  219. params4.add(idA); //多用户2上半部分
  220. params5.add(id4); //多用户2下半部分
  221. params6.add(idA); //多用户3上半部分
  222. params7.add(id6); //多用户3上半部分
  223. params8.add(idA); //多用户4上半部分
  224. params9.add(id8); //多用户4上半部分
  225. params10.add(idA); //多用户5上半部分
  226. params11.add(id10); //多用户5上半部分
  227. //System.out.println("取水口下半部分表的参数:" + params2);
  228. //System.out.println("参数2的参数长度:" + params2.size());
  229. // 取水口基本情况表--ATT_WINT_BASE_B
  230. // 取用水户基础信息表--ATT_WIU_BASE
  231. // 取水户计量及取用水情况--ATT_WIU_MEAS_DWT
  232. // 取水户实际取水量--ATT_WIU_WAT_CONS
  233. // 取水许可审批情况--ATT_WIU_WAT_LIC
  234. // 取水户取水计划情况--ATT_WIU_INT_PL
  235. String wintCode = "";
  236. String wintId = params1.get(0);
  237. if (params1.size() > 0) {
  238. // template.update(sql1.toString(),params1.toArray()); //表a
  239. //包含取水口基本情况
  240. AttWintBaseB wintBaseB = new AttWintBaseB();
  241. wintBaseB.setId(params1.get(0));
  242. try {
  243. wintBaseB.setWintName(params1.get(2));
  244. } catch (Exception e) {
  245. System.out.println("读取失败问文件" + doDealIngFileName);
  246. NullList.add(doDealIngFileName);
  247. return;
  248. }
  249. AttWintBaseBParam wintBaseBParam = new AttWintBaseBParam();
  250. wintBaseBParam.setWintName(params1.get(2));
  251. List<AttWintBaseB> wintBaseB1 = wintBaseBDao.findList(wintBaseBParam);
  252. if (wintBaseB1 != null && !wintBaseB1.isEmpty()) {
  253. return;
  254. }
  255. wintBaseB.setAdName(params1.get(3) + "-" + params1.get(4) + "-" + params1.get(5));
  256. AttAdXBaseParam xBaseParam = new AttAdXBaseParam();
  257. List<AttAdXBase> attAdXBaseList = null;
  258. if (StringUtils.isNotBlank(params1.get(5))) {
  259. String xian = params1.get(5);
  260. if (xian.contains("(")) {
  261. xian = xian.replace("(", "").replace(")", "");
  262. }
  263. if (xian.length() > 3) {
  264. xian = xian.substring(0, 3);
  265. }
  266. xBaseParam.setAdName(xian);
  267. attAdXBaseList = attAdXBaseDao.findList(xBaseParam);
  268. }
  269. AttAdXBase attAdXBase = null;
  270. if (attAdXBaseList == null || attAdXBaseList.size() == 0 || attAdXBaseList.size() > 1) {
  271. String xian = params1.get(4);
  272. if (xian.contains("(")) {
  273. xian = xian.replace("(", "").replace(")", "");
  274. }
  275. xBaseParam.setAdName(xian);
  276. attAdXBaseList = attAdXBaseDao.findList(xBaseParam);
  277. if (attAdXBaseList == null || attAdXBaseList.isEmpty()) {
  278. if (StringUtils.isNotBlank(params1.get(5))) {
  279. xian = params1.get(5).substring(0, 2);
  280. } else {
  281. xian = params1.get(4).substring(0, params1.get(4).indexOf("市"));
  282. }
  283. xBaseParam.setAdName(xian);
  284. attAdXBaseList = attAdXBaseDao.findList(xBaseParam);
  285. if (attAdXBaseList != null && attAdXBaseList.size() == 1) {
  286. attAdXBase = attAdXBaseList.get(0);
  287. }
  288. for (AttAdXBase xBase : attAdXBaseList) {
  289. if (xBase.getAdFullName().contains(params1.get(3))) {
  290. attAdXBase = xBase;
  291. }
  292. }
  293. if (attAdXBase == null && attAdXBaseList != null) {
  294. attAdXBase = attAdXBaseList.get(0);
  295. }
  296. } else {
  297. attAdXBase = attAdXBaseList.get(0);
  298. }
  299. } else {
  300. attAdXBase = attAdXBaseList.get(0);
  301. }
  302. wintBaseB.setAdCode(attAdXBase.getAdCode());
  303. wintBaseB.setCharDepNm(params1.get(11));
  304. wintBaseB.setCharDepPers(params1.get(12));
  305. wintBaseB.setCharDepTel(params1.get(13));
  306. if (!"填写".equals(params1.get(20))) {
  307. if (params1.get(20).contains("(")) {
  308. String desyQ = params1.get(20).substring(0, params1.get(20).indexOf("("));
  309. wintBaseB.setDesDayQ(Double.parseDouble(desyQ));
  310. } else {
  311. if (params1.get(20).contains("×")) {
  312. String[] arrays = params1.get(20).split("×");
  313. double desq = Double.parseDouble(arrays[0]) * Integer.parseInt(arrays[1]);
  314. wintBaseB.setDesDayQ(desq);
  315. } else {
  316. if (StringUtils.isNotBlank(params1.get(20)) && !"填写".equals(params1.get(20))) {
  317. if (params1.get(20).contains("万")) {
  318. String desc = params1.get(20).substring(0, params1.get(20).length() - 1);
  319. wintBaseB.setDesDayQ(Double.parseDouble(desc));
  320. } else {
  321. if (isNumeric(params1.get(20))) {
  322. wintBaseB.setDesDayQ(Double.parseDouble(params1.get(20)));
  323. }
  324. }
  325. }
  326. }
  327. }
  328. }
  329. wintBaseB.setInTm(new Date());
  330. if (params1.get(21).contains("万")) {
  331. String desc = params1.get(21).substring(0, params1.get(21).indexOf("万"));
  332. wintBaseB.setDesYearQ(Double.parseDouble(desc));
  333. } else {
  334. if (StringUtils.isNotBlank(params1.get(21)) && !"填写".equals(params1.get(21))) {
  335. if (params1.get(21).contains("-")) {
  336. String[] arrays = params1.get(21).split("-");
  337. wintBaseB.setDesYearQ(Double.parseDouble(arrays[0]));
  338. } else {
  339. if (isNumeric(params1.get(21))) {
  340. wintBaseB.setDesYearQ(Double.parseDouble(params1.get(21)));
  341. }
  342. }
  343. }
  344. }
  345. wintBaseB.setLocWrz1rdName(params1.get(9));
  346. if (StringUtils.isNotBlank(params1.get(19)) && params1.get(19).contains("(")) {
  347. String desyQ = params1.get(19).replace("m³/s", "");
  348. desyQ = desyQ.substring(0, desyQ.indexOf("("));
  349. wintBaseB.setDesQ(Double.parseDouble(desyQ));
  350. } else {
  351. if (StringUtils.isNotBlank(params1.get(19)) && params1.get(19).contains("设计")) {
  352. String desc = params1.get(19).replace("设计", "");
  353. if (desc.contains("(")) {
  354. desc = desc.substring(0, desc.indexOf("("));
  355. wintBaseB.setDesQ(Double.parseDouble(desc));
  356. }
  357. } else if (StringUtils.isNotBlank(params1.get(19)) && !"填写".equals(params1.get(19))) {
  358. if (isNumeric(params1.get(19))) {
  359. wintBaseB.setDesQ(Double.parseDouble(params1.get(19)));
  360. }
  361. }
  362. }
  363. wintBaseB.setLocWrz2rdName("");
  364. wintBaseB.setLocWrz3rdName("");
  365. wintBaseB.setUpTm(new Date());
  366. wintBaseB.setWainIntName(params1.get(14));
  367. wintBaseB.setWainIntType(getType(params1.get(15)));
  368. if (StringUtils.isNotBlank(params1.get(8)) && !"填写".equals(params1.get(8)) && !"/".equals(params1.get(8))) {
  369. wintBaseB.setWainLat(DuFenMiaoToLat(params1.get(8)));
  370. }
  371. if (StringUtils.isNotBlank(params1.get(7)) && !"填写".equals(params1.get(7)) && !"/".equals(params1.get(7))) {
  372. wintBaseB.setWainLong(DuFenMiaoToLon(params1.get(7)));
  373. }
  374. if ("单一用户取水口".equals(params1.get(10))) {
  375. wintBaseB.setWainType(1 + "");
  376. } else {
  377. wintBaseB.setWainType(2 + "");
  378. }
  379. //1:河道内的水库;2:湖泊;3:河流;4:跨省引调水工程;9:其他
  380. wintBaseB.setWainWasoName(params1.get(18));
  381. wintBaseB.setWainWasoType(getWasoType(params1.get(16)));
  382. wintBaseB.setWintPos(params1.get(6));
  383. System.out.println(params1);
  384. String time = (System.currentTimeMillis() + "");
  385. time = time.substring(time.length() - 4, time.length());
  386. wintCode = attAdXBase.getAdCode() + time + "";
  387. wintBaseB.setWintCode(wintCode);
  388. wintBaseBDao.insert(wintBaseB);
  389. }
  390. if (params2.size() > 3) {
  391. //包含取水用户信息到计量到收费审核
  392. addUsers(params1, params2, wintId);
  393. }
  394. if (params3.size() > 3) {
  395. //取水计划
  396. addPlan(params2, params3);
  397. System.out.println(params3);
  398. }
  399. if (params4.size() > 3) {
  400. // template.update(sql2.toString(),params4.toArray()); //表b
  401. addUsers(params1, params4, wintId);
  402. }
  403. if (params5.size() > 3) {
  404. // template.update(sql3.toString(),params5.toArray()); //表c
  405. addPlan(params2, params5);
  406. }
  407. if (params6.size() > 3) {
  408. // template.update(sql2.toString(),params6.toArray()); //表b
  409. addUsers(params1, params6, wintId);
  410. }
  411. if (params7.size() > 3) {
  412. // template.update(sql3.toString(),params7.toArray()); //表c
  413. addPlan(params2, params7);
  414. }
  415. if (params8.size() > 3) {
  416. // template.update(sql2.toString(),params8.toArray()); //表b
  417. addUsers(params1, params8, wintId);
  418. }
  419. if (params9.size() > 3) {
  420. // template.update(sql3.toString(),params9.toArray()); //表c
  421. addPlan(params2, params9);
  422. }
  423. if (params10.size() > 3) {
  424. // template.update(sql2.toString(),params10.toArray()); //表b
  425. addUsers(params1, params10, wintId);
  426. }
  427. if (params11.size() > 3) {
  428. // template.update(sql3.toString(),params11.toArray()); //表c
  429. addPlan(params2, params11);
  430. }
  431. }
  432. }
  433. }
  434. private void addPlan(ArrayList<String> params2, ArrayList<String> params3) {
  435. AttWiuIntPl wiuIntPl = new AttWiuIntPl();
  436. AttWiuIntPl wiuIntPl2 = new AttWiuIntPl();
  437. wiuIntPl.setId(UuidUtil.uuid());
  438. wiuIntPl.setWiuId(params2.get(0));
  439. wiuIntPl.setYr("2019");
  440. wiuIntPl.setYrTp("1");
  441. wiuIntPl2.setId(UuidUtil.uuid());
  442. wiuIntPl2.setWiuId(params2.get(0));
  443. wiuIntPl2.setYr("2019");
  444. wiuIntPl2.setYrTp("2");
  445. if (StringUtils.isNotBlank(params3.get(2)) && isNumeric(params3.get(2))) {
  446. wiuIntPl.setYrWw(Double.parseDouble(params3.get(2)));
  447. }
  448. if (StringUtils.isNotBlank(params3.get(3)) && isNumeric(params3.get(3))) {
  449. wiuIntPl.setJanWw(Double.parseDouble(params3.get(3)));
  450. }
  451. if (StringUtils.isNotBlank(params3.get(4)) && isNumeric(params3.get(4))) {
  452. wiuIntPl.setFebWw(Double.parseDouble(params3.get(4)));
  453. }
  454. if (StringUtils.isNotBlank(params3.get(5)) && isNumeric(params3.get(5))) {
  455. wiuIntPl.setMarWw(Double.parseDouble(params3.get(5)));
  456. }
  457. if (StringUtils.isNotBlank(params3.get(6)) && isNumeric(params3.get(6))) {
  458. wiuIntPl.setAprWw(Double.parseDouble(params3.get(6)));
  459. }
  460. if (StringUtils.isNotBlank(params3.get(7)) && isNumeric(params3.get(7))) {
  461. wiuIntPl.setMayWw(Double.parseDouble(params3.get(7)));
  462. }
  463. if (StringUtils.isNotBlank(params3.get(8)) && isNumeric(params3.get(8))) {
  464. wiuIntPl.setJunWw(Double.parseDouble(params3.get(8)));
  465. }
  466. if (StringUtils.isNotBlank(params3.get(9)) && isNumeric(params3.get(9))) {
  467. wiuIntPl.setJulWw(Double.parseDouble(params3.get(9)));
  468. }
  469. if (StringUtils.isNotBlank(params3.get(10)) && isNumeric(params3.get(10))) {
  470. wiuIntPl.setAugWw(Double.parseDouble(params3.get(10)));
  471. }
  472. if (StringUtils.isNotBlank(params3.get(11)) && isNumeric(params3.get(11))) {
  473. wiuIntPl.setSepWw(Double.parseDouble(params3.get(11)));
  474. }
  475. if (StringUtils.isNotBlank(params3.get(12)) && isNumeric(params3.get(12))) {
  476. wiuIntPl.setOctWw(Double.parseDouble(params3.get(12)));
  477. }
  478. if (StringUtils.isNotBlank(params3.get(13)) && isNumeric(params3.get(13))) {
  479. wiuIntPl.setNovWw(Double.parseDouble(params3.get(13)));
  480. }
  481. if (StringUtils.isNotBlank(params3.get(14)) && isNumeric(params3.get(14))) {
  482. wiuIntPl.setDecWw(Double.parseDouble(params3.get(14)));
  483. }
  484. //------------------
  485. if (StringUtils.isNotBlank(params3.get(15)) && isNumeric(params3.get(15))) {
  486. wiuIntPl2.setYrWw(Double.parseDouble(params3.get(15)));
  487. }
  488. if (StringUtils.isNotBlank(params3.get(16)) && isNumeric(params3.get(16))) {
  489. wiuIntPl2.setJanWw(Double.parseDouble(params3.get(16)));
  490. }
  491. if (StringUtils.isNotBlank(params3.get(17)) && isNumeric(params3.get(17))) {
  492. wiuIntPl2.setFebWw(Double.parseDouble(params3.get(17)));
  493. }
  494. if (StringUtils.isNotBlank(params3.get(18)) && isNumeric(params3.get(18))) {
  495. wiuIntPl2.setMarWw(Double.parseDouble(params3.get(18)));
  496. }
  497. if (StringUtils.isNotBlank(params3.get(19)) && isNumeric(params3.get(19))) {
  498. wiuIntPl2.setAprWw(Double.parseDouble(params3.get(19)));
  499. }
  500. if (StringUtils.isNotBlank(params3.get(20)) && isNumeric(params3.get(20))) {
  501. wiuIntPl2.setMayWw(Double.parseDouble(params3.get(20)));
  502. }
  503. if (StringUtils.isNotBlank(params3.get(21)) && isNumeric(params3.get(21))) {
  504. wiuIntPl2.setJunWw(Double.parseDouble(params3.get(21)));
  505. }
  506. if (StringUtils.isNotBlank(params3.get(22)) && isNumeric(params3.get(22))) {
  507. wiuIntPl2.setJulWw(Double.parseDouble(params3.get(22)));
  508. }
  509. if (StringUtils.isNotBlank(params3.get(23)) && isNumeric(params3.get(23))) {
  510. wiuIntPl2.setAugWw(Double.parseDouble(params3.get(23)));
  511. }
  512. if (StringUtils.isNotBlank(params3.get(24)) && isNumeric(params3.get(24))) {
  513. wiuIntPl2.setSepWw(Double.parseDouble(params3.get(24)));
  514. }
  515. if (StringUtils.isNotBlank(params3.get(25)) && isNumeric(params3.get(25))) {
  516. wiuIntPl2.setOctWw(Double.parseDouble(params3.get(25)));
  517. }
  518. if (StringUtils.isNotBlank(params3.get(26)) && isNumeric(params3.get(26))) {
  519. wiuIntPl2.setNovWw(Double.parseDouble(params3.get(26)));
  520. }
  521. if (StringUtils.isNotBlank(params3.get(27)) && isNumeric(params3.get(27))) {
  522. wiuIntPl2.setDecWw(Double.parseDouble(params3.get(27)));
  523. }
  524. wiuIntPl.setInTm(new Date());
  525. wiuIntPl2.setInTm(new Date());
  526. wiuIntPl2.setUpTm(new Date());
  527. wiuIntPl.setUpTm(new Date());
  528. if (!"填写".equals(params3.get(2)) && !"".equals(params3.get(2))) {
  529. wiuIntPlDao.insert(wiuIntPl);
  530. }
  531. if (!"填写".equals(params3.get(15)) && !"".equals(params3.get(15))) {
  532. wiuIntPlDao.insert(wiuIntPl2);
  533. }
  534. }
  535. private void addUsers(ArrayList<String> params1, ArrayList<String> params2, String wintCode) {
  536. AttWiuBase wiuBase = new AttWiuBase();
  537. wiuBase.setId(params2.get(0));
  538. wiuBase.setWiuName(params2.get(2));
  539. if ("填写".equals(params2.get(2)) || "".equals(params2.get(2))) {
  540. return;
  541. }
  542. wiuBase.setCodeVal(params2.get(8));
  543. // wiuBase.setGdX();
  544. // wiuBase.setGdY();
  545. if (params2.get(8).length() == 18) {
  546. wiuBase.setCodeType("2");
  547. } else {
  548. wiuBase.setCodeType("1");
  549. }
  550. if ("法定代表人".equals(params1.get(3))) {
  551. wiuBase.setIdtType("1");
  552. } else {
  553. wiuBase.setIdtType("2");
  554. }
  555. wiuBase.setWiuNat(getIdtType(params2.get(5)));
  556. wiuBase.setInTm(new Date());
  557. wiuBase.setUpTm(new Date());
  558. wiuBase.setName(params2.get(4));
  559. // wiuBase.setObjId();
  560. wiuBase.setState("2");
  561. wiuBase.setWintCode(params1.get(0));
  562. wiuBase.setWintName(params2.get(2));
  563. wiuBase.setWintPos(params1.get(6));
  564. wiuBase.setWiuContact(params2.get(9));
  565. wiuBase.setWiuContactTel(params2.get(10));
  566. wiuBase.setWiuNatName(params2.get(5));
  567. if (StringUtils.isNotBlank(params1.get(8)) && !"填写".equals(params1.get(8)) && !"/".equals(params1.get(7))) {
  568. wiuBase.setWiuLat(DuFenMiaoToLat(params1.get(8)));
  569. }
  570. if (StringUtils.isNotBlank(params1.get(7)) && !"填写".equals(params1.get(7)) && !"/".equals(params1.get(7))) {
  571. wiuBase.setWiuLong(DuFenMiaoToLon(params1.get(7)));
  572. }
  573. AttWiuMeasDwt wiuMeasDwt = new AttWiuMeasDwt();
  574. wiuMeasDwt.setInTm(new Date());
  575. wiuMeasDwt.setUpTm(new Date());
  576. wiuMeasDwt.setId(UuidUtil.uuid());
  577. wiuMeasDwt.setWainUse1(getWainUseType(params2.get(15)));
  578. wiuMeasDwt.setWainUse2(getWainUseType(params2.get(16)));
  579. wiuMeasDwt.setWainUse3(getWainUseType(params2.get(17)));
  580. wiuMeasDwt.setWainUse4(getWainUseType(params2.get(18)));
  581. wiuMeasDwt.setWainUse5(getWainUseType(params2.get(19)));
  582. wiuMeasDwt.setWiuId(wiuBase.getId());
  583. if ("全部接入".equals(params2.get(14))) {
  584. wiuMeasDwt.setWiuIsAtlonwms("1");
  585. } else {
  586. wiuMeasDwt.setWiuIsAtlonwms("2");
  587. }
  588. if ("能".equals(params2.get(13))) {
  589. wiuMeasDwt.setWiustRunCond("1");
  590. } else {
  591. wiuMeasDwt.setWiustRunCond("2");
  592. }
  593. wiuMeasDwt.setWwCond(getComd(params2.get(11)));
  594. wiuMeasDwt.setWiustTp(getWiustTp(params2.get(12)));
  595. //TODO
  596. AttWiuWatCons wiuWatCons16 = new AttWiuWatCons();
  597. AttWiuWatCons wiuWatCons17 = new AttWiuWatCons();
  598. AttWiuWatCons wiuWatCons18 = new AttWiuWatCons();
  599. if ("计量".equals(params2.get(27))) {
  600. wiuWatCons16.setDataType("1");//1:自然年;2:调度年
  601. } else {
  602. wiuWatCons16.setDataType("2");//1:自然年;2:调度年
  603. }
  604. wiuWatCons16.setId(UuidUtil.uuid());
  605. wiuWatCons16.setInTm(new Date());
  606. wiuWatCons16.setUpTm(new Date());
  607. if (StringUtils.isNotBlank(params2.get(24)) && params2.get(24).contains("万")) {
  608. String dun = params2.get(24).substring(0, params2.get(24).indexOf("万"));
  609. wiuWatCons16.setWatCons(Double.parseDouble(dun));
  610. } else {
  611. if (StringUtils.isNotBlank(params2.get(24)) && isNumeric(params2.get(24))) {
  612. wiuWatCons16.setWatCons(Double.parseDouble(params2.get(24)));
  613. }
  614. }
  615. wiuWatCons16.setWiuId(wiuBase.getId());
  616. wiuWatCons16.setYear("2016");
  617. wiuWatCons16.setYearType("1");
  618. //------------------------------
  619. if ("计量".equals(params2.get(28))) {
  620. wiuWatCons17.setDataType("1");//1:自然年;2:调度年
  621. } else {
  622. wiuWatCons17.setDataType("2");//1:自然年;2:调度年
  623. }
  624. wiuWatCons17.setId(UuidUtil.uuid());
  625. wiuWatCons17.setInTm(new Date());
  626. wiuWatCons17.setUpTm(new Date());
  627. if (StringUtils.isNotBlank(params2.get(25)) && params2.get(25).contains("万")) {
  628. String dun = params2.get(25).substring(0, params2.get(25).indexOf("万"));
  629. wiuWatCons17.setWatCons(Double.parseDouble(dun));
  630. } else {
  631. if (StringUtils.isNotBlank(params2.get(25)) && isNumeric(params2.get(25))) {
  632. wiuWatCons17.setWatCons(Double.parseDouble(params2.get(25)));
  633. }
  634. }
  635. wiuWatCons17.setWiuId(wiuBase.getId());
  636. wiuWatCons17.setYear("2017");
  637. wiuWatCons17.setYearType("1");
  638. //------------------------------
  639. if ("计量".equals(params2.get(28))) {
  640. wiuWatCons18.setDataType("1");//1:自然年;2:调度年
  641. } else {
  642. wiuWatCons18.setDataType("2");//1:自然年;2:调度年
  643. }
  644. wiuWatCons18.setId(UuidUtil.uuid());
  645. wiuWatCons18.setInTm(new Date());
  646. wiuWatCons18.setUpTm(new Date());
  647. if (StringUtils.isNotBlank(params2.get(26)) && params2.get(26).contains("万")) {
  648. String dun = params2.get(26).substring(0, params2.get(26).indexOf("万"));
  649. wiuWatCons18.setWatCons(Double.parseDouble(dun));
  650. } else {
  651. if (StringUtils.isNotBlank(params2.get(26)) && isNumeric(params2.get(26))) {
  652. wiuWatCons18.setWatCons(Double.parseDouble(params2.get(26)));
  653. }
  654. }
  655. wiuWatCons18.setWiuId(wiuBase.getId());
  656. wiuWatCons18.setYear("2018");
  657. wiuWatCons18.setYearType("1");
  658. AttWiuWatLic wiuWatLic = new AttWiuWatLic();
  659. wiuWatLic.setId(UuidUtil.uuid());
  660. wiuWatLic.setReplSn(params2.get(31));
  661. wiuWatLic.setApprOrg(params2.get(32));
  662. if (StringUtils.isNotBlank(params2.get(35)) && isNumeric(params2.get(35))) {
  663. wiuWatLic.setApprWw(Double.parseDouble(params2.get(35)));
  664. }
  665. wiuWatLic.setInTm(new Date());
  666. wiuWatLic.setUpTm(new Date());
  667. if ("填写".equals(params2.get(30))) {
  668. wiuWatLic.setQsxkspqklx("2");
  669. } else {
  670. wiuWatLic.setQsxkspqklx("1");
  671. wiuWatLic.setWatLicCode(params2.get(30));
  672. }
  673. if (!"填写".equals(params2.get(36)) || !"".equals(params2.get(36))) {
  674. wiuWatLic.setQsxkspqklx("3");
  675. wiuWatLic.setFtafawdp(params2.get(36));
  676. }
  677. wiuWatLic.setReplSn(params2.get(35));
  678. //1:已申领取水许可证;2:已办理取水许可但未申领取水许可证;3:未办理取水许可
  679. wiuWatLic.setWrpNm(params2.get(33));
  680. // wiuWatLic.setWiuDl();
  681. // wiuWatLic.setWiuBd(params2.get(32));
  682. wiuWatLic.setWiuId(wiuBase.getId());
  683. if (StringUtils.isNotBlank(params2.get(34)) && isNumeric(params2.get(34))) {
  684. if (isNumeric(params2.get(34))) {
  685. wiuWatLic.setWiuWw(Double.parseDouble(params2.get(34)));
  686. }
  687. }
  688. System.out.println(params2);
  689. wiuBase.setWintCode(params2.get(3));
  690. wiuBase.setWiuCode(wintCode);
  691. wiuBaseDao.insert(wiuBase);
  692. wiuWatCons16.setWiuId(wiuBase.getId());
  693. wiuWatConsDao.insert(wiuWatCons16);
  694. wiuWatCons17.setWiuId(wiuBase.getId());
  695. wiuWatConsDao.insert(wiuWatCons17);
  696. wiuWatCons18.setWiuId(wiuBase.getId());
  697. wiuWatConsDao.insert(wiuWatCons18);
  698. if (StringUtils.isNotBlank(wiuWatLic.getWatLicCode())) {
  699. wiuWatLic.setQsxkspqklx("1");
  700. }
  701. wiuWatLicDao.insert(wiuWatLic);
  702. measDwtDao.insert(wiuMeasDwt);
  703. }
  704. public static boolean isNumeric(String str) {
  705. return pattern.matcher(str).matches();
  706. }
  707. private String getWainUseType(String s) {
  708. //1:城镇供水(自来水);2:生活用水(自备);3:火(核)电直流冷却用水;4:火(核)电循环冷却用水;5:非火(核)电用水;
  709. // 6:农业用水;7:人工生态环境补水;8:水资源配置调度取水;9:其他用水
  710. if ("空".equals(s)) {
  711. return "";
  712. }
  713. if ("城镇供水(自来水)".equals(s)) {
  714. return "1";
  715. }
  716. if ("生活用水(自备)".equals(s)) {
  717. return "2";
  718. }
  719. if ("火(核)电直流冷却用水".equals(s)) {
  720. return "3";
  721. }
  722. if ("火(核)电循环冷却用水".equals(s)) {
  723. return "4";
  724. }
  725. if ("非火(核)电用水".equals(s)) {
  726. return "5";
  727. }
  728. if ("农业用水".equals(s)) {
  729. return "6";
  730. }
  731. if ("人工生态环境补水".equals(s)) {
  732. return "7";
  733. }
  734. if ("水资源配置调度取水".equals(s)) {
  735. return "8";
  736. }
  737. return "9";
  738. }
  739. private String getWiustTp(String s) {
  740. //1:超声波流量计;2:电磁流量计;3:水表;4:水位计;5:水尺;9:其他
  741. if ("超声波流量计".equals(s)) {
  742. return "1";
  743. }
  744. if ("电磁流量计".equals(s)) {
  745. return "2";
  746. }
  747. if ("水表".equals(s)) {
  748. return "3";
  749. }
  750. if ("水位计".equals(s)) {
  751. return "4";
  752. }
  753. if ("水尺".equals(s)) {
  754. return "5";
  755. }
  756. return "9";
  757. }
  758. private String getComd(String s) {
  759. //1:全部计量;2:部分计量;3:无计量
  760. if ("全部计量".equals(s)) {
  761. return "1";
  762. }
  763. if ("部分计量".equals(s)) {
  764. return "2";
  765. }
  766. return "3";
  767. }
  768. private String getIdtType(String s) {
  769. //1:法人;2:其他组织;3:法人的分支机构;4:自然人
  770. if ("法人".equals(s)) {
  771. return "1";
  772. }
  773. if ("其他组织".equals(s)) {
  774. return "2";
  775. }
  776. if ("法人的分支机构".equals(s)) {
  777. return "3";
  778. }
  779. return "4";
  780. }
  781. public static double DuFenMiaoToLat(String latlng) {
  782. latlng = latlng.trim().replace("填写", "");
  783. if (latlng.contains("、")) {
  784. latlng = latlng.substring(0, latlng.indexOf("、"));
  785. }
  786. latlng = latlng.replace("东经", "").replace("北纬:", "").replace("东经:", "").replace("。", "°").replace("N", "")
  787. .replace("E", "").replace("北纬", "").replace("\"", "").replace("゜", "°").replace(" ", "").replace("º", "°")
  788. .replace("´", "′").replace("’", "′").replace("'", "′")
  789. .replace("'", "′").replace("度", "°").replace("分", "′");
  790. if (latlng.contains("(")) {
  791. latlng = latlng.substring(latlng.indexOf("(") + 1, latlng.indexOf(")"));
  792. }
  793. if (!latlng.contains("′") && latlng.contains("°")) {
  794. return Double.parseDouble(latlng.substring(0, latlng.length() - 1));
  795. }
  796. if (isNumeric(latlng)) {
  797. return Double.parseDouble(latlng);
  798. }
  799. if (latlng.endsWith("′")) {
  800. latlng = latlng + "00秒";
  801. }
  802. latlng = latlng.replace("'", "′");
  803. double du = Double.parseDouble(latlng.substring(0, latlng.indexOf("°")));
  804. double fen = Double.parseDouble(latlng.substring(latlng.indexOf("°") + 1, latlng.indexOf("′")));
  805. double miao = Double.parseDouble(latlng.substring(latlng.indexOf("′") + 1, latlng.length() - 1));
  806. if (du < 0) {
  807. return -(Math.abs(du) + (fen + (miao / 60)) / 60);
  808. }
  809. return du + (fen + (miao / 60)) / 60;
  810. }
  811. public static double DuFenMiaoToLon(String latlng) {//"
  812. latlng = latlng.trim().replace("填写", "");
  813. if (latlng.contains("、")) {
  814. latlng = latlng.substring(0, latlng.indexOf("、"));
  815. }
  816. latlng = latlng.replace("东经", "").replace("北纬:", "").replace("'", "′").replace("东经:", "").replace("北纬", "").replace("。", "°").replace("N", "").replace("E", "").replace("\"", "").replace(" ", "").replace("゜", "°").replace("º", "°")
  817. .replace("´", "′").replace("'", "′").replace("’", "′").replace("度", "°").replace("分", "′");
  818. ;
  819. if (latlng.contains("(")) {
  820. latlng = latlng.substring(latlng.indexOf("(") + 1, latlng.indexOf(")"));
  821. }
  822. if (!latlng.contains("′") && latlng.contains("°")) {
  823. return Double.parseDouble(latlng.substring(0, latlng.length() - 1));
  824. }
  825. if (isNumeric(latlng)) {
  826. return Double.parseDouble(latlng);
  827. }
  828. if (latlng.endsWith("′")) {
  829. latlng = latlng + "00分";
  830. }
  831. latlng = latlng.replace("'", "′");
  832. double du = Double.parseDouble(latlng.substring(0, latlng.indexOf("°")));
  833. double fen = Double.parseDouble(latlng.substring(latlng.indexOf("°") + 1, latlng.indexOf("′")));
  834. double miao = Double.parseDouble(latlng.substring(latlng.indexOf("′") + 1, latlng.length() - 1));
  835. if (du < 0) {
  836. return -(Math.abs(du) + (fen + (miao / 60)) / 60);
  837. }
  838. return du + (fen + (miao / 60)) / 60;
  839. }
  840. private static String getWasoType(String s) {
  841. //1:河道内的水库;2:湖泊;3:河流;4:跨省引调水工程;9:其他
  842. if ("河道内的水库".equals(s)) {
  843. return "1";
  844. }
  845. if ("湖泊".equals(s)) {
  846. return "2";
  847. }
  848. if ("河流".equals(s)) {
  849. return "3";
  850. }
  851. if ("跨省引调水工程".equals(s)) {
  852. return "4";
  853. }
  854. return "9";
  855. }
  856. private static String getType(String s) {
  857. //1:渠道;2:人工河道;3:虹吸管;4:泵站;5:闸;6:从江河湖泊饮水的水库;7:其他;
  858. if ("渠道".equals(s)) {
  859. return "1";
  860. }
  861. if ("人工河道".equals(s)) {
  862. return "2";
  863. }
  864. if ("虹吸管".equals(s)) {
  865. return "3";
  866. }
  867. if ("泵站".equals(s)) {
  868. return "4";
  869. }
  870. if ("闸".equals(s)) {
  871. return "5";
  872. }
  873. if ("从江河湖泊饮水的水库".equals(s)) {
  874. return "6";
  875. }
  876. return "7";
  877. }
  878. /**
  879. * 处理数据并将数据存进map集合
  880. */
  881. private static Map<String, String> dealDataAndSaveInMap(Workbook wb) {
  882. //Sheet sheet = wb.getSheetAt(1);
  883. //确定下改处理哪个sheet是要读取数据的,暂时试试通过名字
  884. //Sheet sheet = wb.getSheet("取水口初始台账表");
  885. //主业务sheet
  886. Sheet sheet = null;
  887. Iterator<Sheet> sheetIterator = wb.sheetIterator();
  888. while (sheetIterator.hasNext()) {
  889. Sheet next = sheetIterator.next();
  890. if (null != next.getRow(8) && null != getStringValByZb(next, "C8") && getStringValByZb(next, "C8").contains("取水口类型") && null != getStringValByZb(next, "D4")) {
  891. if (!"填写".equalsIgnoreCase(getStringValByZb(next, "D4"))) {
  892. sheet = next;
  893. } else {
  894. qushuikou.add(doDealIngFileName);
  895. }
  896. }
  897. //明确多用户情况
  898. if (null != getStringValByZb(next, "B2") && getStringValByZb(next, "B2").contains("多用户公用取水口初始台账表") && !"填表说明".equalsIgnoreCase(next.getSheetName()) && null != next.getRow(5) && null != getStringValByZb(next, "C5") && "取水户名称".equalsIgnoreCase(getStringValByZb(next, "C5")) && null != getStringValByZb(next, "D5") && !"".equalsIgnoreCase(getStringValByZb(next, "D5").trim()) && !"填写".equalsIgnoreCase(getStringValByZb(next, "D5"))) {
  899. System.out.println("看看sheet的名字和作为比较的值:" + next.getSheetName() + "@" + getStringValByZb(next, "D5") + "依据是坐标取出的值是 :" + getStringValByZb(next, "C5") + "看看c8是啥:" + getStringValByZb(next, "C8"));
  900. countIsHasSheet3++;
  901. dyhFileNames.add(doDealIngFileName);
  902. }
  903. }
  904. if (null == sheet) {
  905. System.out.println("发生异常的文件是 :" + doDealIngFileName);
  906. LinkedHashMap<String, String> tempMap = new LinkedHashMap<>();
  907. //tempMap.put("张三",111);
  908. return tempMap;
  909. }
  910. LinkedHashMap<String, String> map = new LinkedHashMap<>();
  911. map.put("v1", getStringValByZb(sheet, "D4"));
  912. map.put("v2", getStringValByZb(sheet, "D5"));
  913. map.put("v3", getStringValByZb(sheet, "F5"));
  914. map.put("v4", getStringValByZb(sheet, "H5"));
  915. map.put("v5", getStringValByZb(sheet, "D6"));
  916. map.put("v6", getStringValByZb(sheet, "G6"));
  917. map.put("v7", getStringValByZb(sheet, "I6"));
  918. map.put("v8", getStringValByZb(sheet, "E7"));
  919. map.put("v9", getStringValByZb(sheet, "E8")); //这是确定是否读取sheet2的标准 如果值为 多用户公用取水口,则需要读后面的sheet
  920. //判断上面的值,以确定是否有多用户公用取水口
  921. // if ("多用户公用取水口".equalsIgnoreCase(getStringValByZb(sheet, "E8"))) {
  922. // countIsHasSheet3++;
  923. // dyhFileNames.add(doDealIngFileName);
  924. // }
  925. map.put("v10", getStringValByZb(sheet, "D9"));
  926. map.put("v11", getStringValByZb(sheet, "G9")); //可能发生空指针的两处
  927. map.put("v12", getStringValByZb(sheet, "I9")); //可能发生空指针的两处
  928. map.put("v13", getStringValByZb(sheet, "D10"));
  929. map.put("v14", getStringValByZb(sheet, "E11"));
  930. map.put("v15", getStringValByZb(sheet, "E12"));
  931. map.put("v16", getStringValByZb(sheet, "I12"));
  932. //map.put("v16", "取水水源为其他时,在此处填写具体水源名称".equalsIgnoreCase(getStringValByZb(sheet, "I12")) ? null : getStringValByZb(sheet, "I12"));
  933. map.put("v17", getStringValByZb(sheet, "D13"));
  934. map.put("v18", getStringValByZb(sheet, "E14"));
  935. map.put("v19", getStringValByZb(sheet, "G14"));
  936. map.put("v20", getStringValByZb(sheet, "I14"));
  937. //以上是取水口相关信息
  938. //以下是取水口下面的234信息
  939. map.put("v21", getStringValByZb(sheet, "D17"));
  940. map.put("v22", getStringValByZb(sheet, "G17"));
  941. map.put("v23", getStringValByZb(sheet, "I17"));
  942. map.put("v24", getStringValByZb(sheet, "F18"));
  943. map.put("v25", getStringValByZb(sheet, "G18"));
  944. map.put("v26", getStringValByZb(sheet, "F19"));
  945. map.put("v27", getStringValByZb(sheet, "G19"));
  946. map.put("v28", getStringValByZb(sheet, "D20"));
  947. map.put("v29", getStringValByZb(sheet, "G20"));
  948. map.put("v30", getStringValByZb(sheet, "E24"));
  949. map.put("v31", getStringValByZb(sheet, "H24"));
  950. map.put("v32", getStringValByZb(sheet, "E25"));
  951. map.put("v33", getStringValByZb(sheet, "H25"));
  952. map.put("v34", getStringValByZb(sheet, "D27"));
  953. //map.put("v35", "空".equalsIgnoreCase(getStringValByZb(sheet, "F27")) ? null : getStringValByZb(sheet, "F27"));
  954. //map.put("v36", "空".equalsIgnoreCase(getStringValByZb(sheet, "H27")) ? null : getStringValByZb(sheet, "H27"));
  955. map.put("v35", getStringValByZb(sheet, "F27"));
  956. map.put("v36", getStringValByZb(sheet, "H27"));
  957. // map.put("v37", "空".equalsIgnoreCase(getStringValByZb(sheet, "D28")) ? null : getStringValByZb(sheet, "D28"));
  958. // map.put("v38", "空".equalsIgnoreCase(getStringValByZb(sheet, "F28")) ? null : getStringValByZb(sheet, "F28"));
  959. // map.put("v39", "空".equalsIgnoreCase(getStringValByZb(sheet, "H28")) ? null : getStringValByZb(sheet, "H28"));
  960. // map.put("v40", "空".equalsIgnoreCase(getStringValByZb(sheet, "D29")) ? null : getStringValByZb(sheet, "D29"));
  961. // map.put("v41", "空".equalsIgnoreCase(getStringValByZb(sheet, "F29")) ? null : getStringValByZb(sheet, "F29"));
  962. // map.put("v42", "空".equalsIgnoreCase(getStringValByZb(sheet, "H29")) ? null : getStringValByZb(sheet, "H29"));
  963. map.put("v37", getStringValByZb(sheet, "D28"));
  964. map.put("v38", getStringValByZb(sheet, "F28"));
  965. map.put("v39", getStringValByZb(sheet, "H28"));
  966. map.put("v40", getStringValByZb(sheet, "D29"));
  967. map.put("v41", getStringValByZb(sheet, "F29"));
  968. map.put("v42", getStringValByZb(sheet, "H29"));
  969. map.put("v43", getStringValByZb(sheet, "E30"));
  970. map.put("v44", getStringValByZb(sheet, "G30"));
  971. map.put("v45", getStringValByZb(sheet, "I30"));
  972. map.put("v46", getStringValByZb(sheet, "E31"));
  973. map.put("v47", getStringValByZb(sheet, "G31"));
  974. map.put("v48", getStringValByZb(sheet, "I31"));
  975. map.put("v49", getStringValByZb(sheet, "E36"));
  976. map.put("v50", getStringValByZb(sheet, "E40"));
  977. map.put("v51", getStringValByZb(sheet, "G40"));
  978. map.put("v52", getStringValByZb(sheet, "E41"));
  979. map.put("v53", getStringValByZb(sheet, "E42"));
  980. map.put("v54", getStringValByZb(sheet, "E43"));
  981. map.put("v55", getStringValByZb(sheet, "E44"));
  982. //取水口页234信息
  983. //取水口页5部分
  984. map.put("v56", getStringValByZb(sheet, "E48"));
  985. map.put("v57", getStringValByZb(sheet, "D50"));
  986. map.put("v58", getStringValByZb(sheet, "E50"));
  987. map.put("v59", getStringValByZb(sheet, "F50"));
  988. map.put("v60", getStringValByZb(sheet, "G50"));
  989. map.put("v61", getStringValByZb(sheet, "H50"));
  990. map.put("v62", getStringValByZb(sheet, "I50"));
  991. map.put("v63", getStringValByZb(sheet, "D52"));
  992. map.put("v64", getStringValByZb(sheet, "E52"));
  993. map.put("v65", getStringValByZb(sheet, "F52"));
  994. map.put("v66", getStringValByZb(sheet, "G52"));
  995. map.put("v67", getStringValByZb(sheet, "H52"));
  996. map.put("v68", getStringValByZb(sheet, "I52"));
  997. map.put("v69", getStringValByZb(sheet, "E53"));
  998. map.put("v70", getStringValByZb(sheet, "D55"));
  999. map.put("v71", getStringValByZb(sheet, "E55"));
  1000. map.put("v72", getStringValByZb(sheet, "F55"));
  1001. map.put("v73", getStringValByZb(sheet, "G55"));
  1002. map.put("v74", getStringValByZb(sheet, "H55"));
  1003. map.put("v75", getStringValByZb(sheet, "I55"));
  1004. map.put("v76", getStringValByZb(sheet, "D57"));
  1005. map.put("v77", getStringValByZb(sheet, "E57"));
  1006. map.put("v78", getStringValByZb(sheet, "F57"));
  1007. map.put("v79", getStringValByZb(sheet, "G57"));
  1008. map.put("v80", getStringValByZb(sheet, "H57"));
  1009. map.put("v81", getStringValByZb(sheet, "I57"));
  1010. //取水口页5部分
  1011. //读取多用户那些sheet
  1012. Map<String, String> dyhMap = readDyhSheet(wb);
  1013. for (Map.Entry<String, String> entry : dyhMap.entrySet()) {
  1014. map.put(entry.getKey(), entry.getValue());
  1015. //System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
  1016. }
  1017. return map;
  1018. }
  1019. /**
  1020. * 读取多用户sheet
  1021. *
  1022. * @param wb
  1023. * @return
  1024. */
  1025. private static Map<String, String> readDyhSheet(Workbook wb) {
  1026. LinkedHashMap<String, String> dyhMap = new LinkedHashMap<>();
  1027. Sheet sheet2 = wb.getSheet("多用户公用取水口初始台账表2");
  1028. if (null != sheet2) {
  1029. dyhMap = readDyh2(dyhMap, sheet2);
  1030. }
  1031. Sheet sheet3 = wb.getSheet("多用户公用取水口初始台账表3");
  1032. if (null != sheet3) {
  1033. dyhMap = readDyh3(dyhMap, sheet3);
  1034. }
  1035. Sheet sheet4 = wb.getSheet("多用户公用取水口初始台账表4");
  1036. if (null != sheet4) {
  1037. dyhMap = readDyh4(dyhMap, sheet4);
  1038. }
  1039. Sheet sheet5 = wb.getSheet("多用户公用取水口初始台账表5");
  1040. if (null != sheet5) {
  1041. dyhMap = readDyh5(dyhMap, sheet5);
  1042. }
  1043. return dyhMap;
  1044. }
  1045. /**
  1046. * 读取第一个多用户sheet页
  1047. *
  1048. * @param dyhMap
  1049. * @param sheet2
  1050. * @return
  1051. */
  1052. private static LinkedHashMap<String, String> readDyh5(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
  1053. String str = "d5";
  1054. dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
  1055. dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
  1056. dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
  1057. dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
  1058. dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
  1059. dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
  1060. dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
  1061. dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
  1062. dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
  1063. dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
  1064. dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
  1065. dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
  1066. dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
  1067. dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
  1068. dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
  1069. dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
  1070. dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
  1071. dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
  1072. dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
  1073. dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
  1074. dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
  1075. dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
  1076. dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
  1077. dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
  1078. dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
  1079. dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
  1080. dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
  1081. dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
  1082. dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
  1083. dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
  1084. dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
  1085. dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
  1086. dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
  1087. dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
  1088. dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
  1089. dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
  1090. dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
  1091. dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
  1092. dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
  1093. dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
  1094. dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
  1095. dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
  1096. dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
  1097. dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
  1098. dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
  1099. dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
  1100. dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
  1101. dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
  1102. dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
  1103. dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
  1104. dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
  1105. dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
  1106. dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
  1107. dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
  1108. dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
  1109. dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
  1110. dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
  1111. dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
  1112. dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
  1113. dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
  1114. dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
  1115. return dyhMap;
  1116. }
  1117. /**
  1118. * 读取第一个多用户sheet页
  1119. *
  1120. * @param dyhMap
  1121. * @param sheet2
  1122. * @return
  1123. */
  1124. private static LinkedHashMap<String, String> readDyh4(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
  1125. String str = "d4";
  1126. dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
  1127. dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
  1128. dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
  1129. dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
  1130. dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
  1131. dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
  1132. dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
  1133. dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
  1134. dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
  1135. dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
  1136. dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
  1137. dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
  1138. dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
  1139. dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
  1140. dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
  1141. dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
  1142. dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
  1143. dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
  1144. dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
  1145. dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
  1146. dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
  1147. dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
  1148. dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
  1149. dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
  1150. dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
  1151. dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
  1152. dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
  1153. dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
  1154. dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
  1155. dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
  1156. dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
  1157. dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
  1158. dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
  1159. dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
  1160. dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
  1161. dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
  1162. dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
  1163. dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
  1164. dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
  1165. dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
  1166. dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
  1167. dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
  1168. dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
  1169. dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
  1170. dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
  1171. dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
  1172. dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
  1173. dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
  1174. dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
  1175. dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
  1176. dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
  1177. dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
  1178. dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
  1179. dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
  1180. dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
  1181. dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
  1182. dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
  1183. dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
  1184. dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
  1185. dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
  1186. dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
  1187. return dyhMap;
  1188. }
  1189. /**
  1190. * 读取第一个多用户sheet页
  1191. *
  1192. * @param dyhMap
  1193. * @param sheet2
  1194. * @return
  1195. */
  1196. private static LinkedHashMap<String, String> readDyh3(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
  1197. String str = "d3";
  1198. dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
  1199. dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
  1200. dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
  1201. dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
  1202. dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
  1203. dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
  1204. dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
  1205. dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
  1206. dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
  1207. dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
  1208. dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
  1209. dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
  1210. dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
  1211. dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
  1212. dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
  1213. dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
  1214. dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
  1215. dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
  1216. dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
  1217. dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
  1218. dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
  1219. dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
  1220. dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
  1221. dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
  1222. dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
  1223. dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
  1224. dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
  1225. dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
  1226. dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
  1227. dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
  1228. dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
  1229. dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
  1230. dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
  1231. dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
  1232. dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
  1233. dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
  1234. dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
  1235. dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
  1236. dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
  1237. dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
  1238. dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
  1239. dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
  1240. dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
  1241. dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
  1242. dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
  1243. dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
  1244. dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
  1245. dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
  1246. dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
  1247. dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
  1248. dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
  1249. dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
  1250. dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
  1251. dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
  1252. dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
  1253. dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
  1254. dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
  1255. dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
  1256. dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
  1257. dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
  1258. dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
  1259. return dyhMap;
  1260. }
  1261. /**
  1262. * 读取第一个多用户sheet页
  1263. *
  1264. * @param dyhMap
  1265. * @param sheet2
  1266. * @return
  1267. */
  1268. private static LinkedHashMap<String, String> readDyh2(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
  1269. String str = "d2";
  1270. dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
  1271. dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
  1272. dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
  1273. dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
  1274. dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
  1275. dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
  1276. dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
  1277. dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
  1278. dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
  1279. dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
  1280. dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
  1281. dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
  1282. dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
  1283. dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
  1284. dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
  1285. dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
  1286. dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
  1287. dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
  1288. dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
  1289. dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
  1290. dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
  1291. dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
  1292. dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
  1293. dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
  1294. dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
  1295. dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
  1296. dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
  1297. dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
  1298. dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
  1299. dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
  1300. dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
  1301. dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
  1302. dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
  1303. dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
  1304. dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
  1305. dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
  1306. dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
  1307. dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
  1308. dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
  1309. dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
  1310. dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
  1311. dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
  1312. dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
  1313. dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
  1314. dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
  1315. dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
  1316. dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
  1317. dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
  1318. dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
  1319. dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
  1320. dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
  1321. dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
  1322. dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
  1323. dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
  1324. dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
  1325. dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
  1326. dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
  1327. dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
  1328. dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
  1329. dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
  1330. dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
  1331. return dyhMap;
  1332. }
  1333. /**
  1334. * 处理excel,并输出下数据看看
  1335. *
  1336. * @param wb
  1337. */
  1338. private static void dealDataAndToConsole(Workbook wb) {
  1339. Sheet sheet = wb.getSheetAt(1);
  1340. StringBuilder sb = new StringBuilder();
  1341. sb.append("输出的参数内容是:\n");
  1342. //Iterator<Row> iterator = sheetAt.iterator();
  1343. // sheet.getRow(2).getCell(2).setCellType(CellType.STRING);
  1344. // String v1 = sheet.getRow(2).getCell(2).getStringCellValue();
  1345. //sheet.getRow(3).getCell(3).setCellType(CellType.STRING);
  1346. //String v1 = sheet.getRow(3).getCell(3).getStringCellValue();
  1347. String v1 = getStringCellValByZb(sheet, "D4").getStringCellValue();
  1348. sb.append("取水口名称是:" + v1 + "\n");
  1349. // sheet.getRow(4).getCell(3).setCellType(CellType.STRING);
  1350. // String v2 = sheet.getRow(4).getCell(3).getStringCellValue();
  1351. String v2 = getStringCellValByZb(sheet, "D5").getStringCellValue();
  1352. sb.append("取水口所在行政区:" + v2 + "\n");
  1353. // sheet.getRow(4).getCell(5).setCellType(CellType.STRING);
  1354. // String v3 = sheet.getRow(4).getCell(5).getStringCellValue();
  1355. String v3 = getStringCellValByZb(sheet, "F5").getStringCellValue();
  1356. sb.append("取水口所在行政区:" + v3 + "\n");
  1357. // sheet.getRow(3).getCell(6).setCellType(CellType.STRING);
  1358. // String v4 = sheet.getRow(3).getCell(6).getStringCellValue();
  1359. String v4 = getStringCellValByZb(sheet, "H5").getStringCellValue();
  1360. sb.append("取水口所在行政区:" + v4 + "\n");
  1361. // sheet.getRow(4).getCell(2).setCellType(CellType.STRING);
  1362. // String v5 = sheet.getRow(4).getCell(2).getStringCellValue();
  1363. String v5 = getStringCellValByZb(sheet, "D6").getStringCellValue();
  1364. sb.append("取水口具体地点:" + v5 + "\n");
  1365. // sheet.getRow(4).getCell(5).setCellType(CellType.STRING);
  1366. // String v6 = sheet.getRow(4).getCell(5).getStringCellValue();
  1367. String v6 = getStringCellValByZb(sheet, "G6").getStringCellValue();
  1368. sb.append("经纬度坐标东经:" + v6 + "\n");
  1369. // sheet.getRow(4).getCell(7).setCellType(CellType.STRING);
  1370. // String v7 = sheet.getRow(4).getCell(7).getStringCellValue();
  1371. String v7 = getStringCellValByZb(sheet, "I6").getStringCellValue();
  1372. sb.append("经纬度坐标北纬:" + v7 + "\n");
  1373. // sheet.getRow(5).getCell(3).setCellType(CellType.STRING);
  1374. // String v8 = sheet.getRow(5).getCell(3).getStringCellValue();
  1375. String v8 = getStringCellValByZb(sheet, "E7").getStringCellValue();
  1376. sb.append("一级区名称:" + v8 + "\n");
  1377. // sheet.getRow(6).getCell(3).setCellType(CellType.STRING);
  1378. // String v9 = sheet.getRow(6).getCell(3).getStringCellValue();
  1379. String v9 = getStringCellValByZb(sheet, "E8").getStringCellValue();
  1380. sb.append("取水口类型:" + v9 + "\n");
  1381. System.out.println(sb.toString());
  1382. }
  1383. /**
  1384. * 根据坐标获取cell的string类型的值
  1385. *
  1386. * @param sheet
  1387. * @param xy
  1388. * @return
  1389. */
  1390. private static String getStringValByZb(Sheet sheet, String xy) {
  1391. Cell cell = getStringCellValByZb(sheet, xy);
  1392. if (null == cell) {
  1393. return null;
  1394. }
  1395. // if ("填写".equalsIgnoreCase(cell.getStringCellValue())) {
  1396. // return null;
  1397. // }
  1398. return dealCellType(cell);
  1399. //return cell.getStringCellValue();
  1400. }
  1401. /**
  1402. * 根据坐标获取要读取的设置成string的单元格
  1403. *
  1404. * @param sheet
  1405. * @param xy
  1406. * @return
  1407. */
  1408. private static Cell getStringCellValByZb(Sheet sheet, String xy) {
  1409. if (null == sheet) {
  1410. zbs.add(doDealIngFileName + "!" + xy);
  1411. return null;
  1412. }
  1413. char[] chars = xy.toCharArray();
  1414. String lie = String.valueOf(chars[0]);
  1415. //处理下D11这种多数值的情况
  1416. int row = 0;
  1417. if (2 >= chars.length) {
  1418. row = NumberUtils.toInt(String.valueOf(chars[1]));
  1419. } else {
  1420. String rowStr = "";
  1421. for (int i = 1; i < chars.length; i++) {
  1422. rowStr += String.valueOf(chars[i]);
  1423. }
  1424. row = NumberUtils.toInt(String.valueOf(rowStr));
  1425. }
  1426. int lieNum = 0;
  1427. switch (lie.toUpperCase()) {
  1428. case "A":
  1429. lieNum = 0;
  1430. break;
  1431. case "B":
  1432. lieNum = 1;
  1433. break;
  1434. case "C":
  1435. lieNum = 2;
  1436. break;
  1437. case "D":
  1438. lieNum = 3;
  1439. break;
  1440. case "E":
  1441. lieNum = 4;
  1442. break;
  1443. case "F":
  1444. lieNum = 5;
  1445. break;
  1446. case "G":
  1447. lieNum = 6;
  1448. break;
  1449. case "H":
  1450. lieNum = 7;
  1451. break;
  1452. case "I":
  1453. lieNum = 8;
  1454. break;
  1455. case "J":
  1456. lieNum = 9;
  1457. break;
  1458. case "K":
  1459. lieNum = 10;
  1460. break;
  1461. case "L":
  1462. lieNum = 11;
  1463. break;
  1464. case "M":
  1465. lieNum = 12;
  1466. break;
  1467. case "N":
  1468. lieNum = 13;
  1469. break;
  1470. case "O":
  1471. lieNum = 14;
  1472. break;
  1473. }
  1474. Row row1 = sheet.getRow(row - 1);
  1475. // CellStyle cellStyle;
  1476. // String extString = doDealIngFileName.substring(doDealIngFileName.lastIndexOf("."));
  1477. // if (".xls".equals(extString)) {
  1478. // cellStyle = new HSSFCellStyle();
  1479. // } else if (".xlsx".equals(extString)) {
  1480. // wb = new XSSFWorkbook(is);
  1481. // }
  1482. //row1.setRowStyle(HSSFCellStyle.class);
  1483. if (null == row1) {
  1484. zbs.add(doDealIngFileName + "@" + xy);
  1485. return null;
  1486. }
  1487. if (null == sheet.getRow(row - 1).getCell(lieNum)) {
  1488. return null;
  1489. } else {
  1490. return sheet.getRow(row - 1).getCell(lieNum);
  1491. // sheet.getRow(row - 1).getCell(lieNum).setCellType(CellType.STRING);
  1492. // sheet.getRow(row - 1).getCell(lieNum).setCellType(1);
  1493. // return sheet.getRow(row - 1).getCell(lieNum);
  1494. }
  1495. }
  1496. /**
  1497. * 细节处理下cell
  1498. *
  1499. * @param cell
  1500. */
  1501. private static String dealCellType(Cell cell) {
  1502. if (cell.getCellType() == CellType.NUMERIC) {
  1503. String tempStr = cell.toString();
  1504. if (getScientific(tempStr)) {
  1505. cell.setCellType(CellType.STRING);
  1506. return cell.getStringCellValue().trim();
  1507. }
  1508. if (!tempStr.startsWith("0") && tempStr.endsWith("0") && tempStr.indexOf(".") != -1) {
  1509. cell.setCellType(CellType.STRING);
  1510. return cell.getStringCellValue().trim();
  1511. }
  1512. return cell.toString().trim();
  1513. // return String.valueOf(cell.getNumericCellValue());
  1514. } else {
  1515. cell.setCellType(CellType.STRING);
  1516. return cell.getStringCellValue().trim();
  1517. }
  1518. }
  1519. /**
  1520. * 正则判断是否为科学计数法
  1521. *
  1522. * @param input
  1523. * @return
  1524. */
  1525. public static boolean getScientific(String input) {
  1526. String regx = "^((-?\\d+.?\\d*)[Ee]{1}(-?\\d+))$";//科学计数法正则表达式
  1527. Pattern pattern = Pattern.compile(regx);
  1528. return pattern.matcher(input).matches();
  1529. }
  1530. /**
  1531. * 将文件读取成excel
  1532. *
  1533. * @param file
  1534. * @return
  1535. */
  1536. private static Workbook readExcel(File file) throws Exception {
  1537. //System.out.println("file.getPath()获取到的路径是这样的: " + file.getPath());
  1538. if (file.getName().startsWith("~$")) {
  1539. System.out.println("特殊文件--》" + file.getPath());
  1540. return null;
  1541. }
  1542. Workbook wb = readExcel(file.getPath());
  1543. return wb;
  1544. }
  1545. /**
  1546. * 读excel
  1547. *
  1548. * @param path
  1549. * @return
  1550. * @throws IOException
  1551. */
  1552. private static Workbook readExcel(String path) throws Exception {
  1553. String extString = path.substring(path.lastIndexOf("."));
  1554. InputStream is = new FileInputStream(path);
  1555. Workbook wb = null;
  1556. if (".xls".equals(extString)) {
  1557. wb = new HSSFWorkbook(is);
  1558. } else if (".xlsx".equals(extString)) {
  1559. // wb = create(is);
  1560. wb = new XSSFWorkbook(is);
  1561. }
  1562. return wb;
  1563. }
  1564. public static Workbook create(InputStream in) throws
  1565. IOException, InvalidFormatException {
  1566. return WorkbookFactory.create(in);
  1567. // poi版本升级后,下面老方法已不可用
  1568. // if (!in.markSupported()) {
  1569. // in = new PushbackInputStream(in, 8);
  1570. // }
  1571. // if (POIFSFileSystem.hasPOIFSHeader(in)) {
  1572. // return new HSSFWorkbook(in);
  1573. // }
  1574. // if (POIXMLDocument.hasOOXMLHeader(in)) {
  1575. // return new XSSFWorkbook(OPCPackage.open(in));
  1576. // }
  1577. // throw new IllegalArgumentException("你的excel版本目前poi解析不了");
  1578. }
  1579. }