RtuImportTask.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. /**
  2. * Copyright
  3. * All right reserved.
  4. * 项目名称:
  5. * 创建日期:2022/5/22
  6. */
  7. package org.springblade.task;
  8. import com.alibaba.excel.EasyExcel;
  9. import com.alibaba.excel.context.AnalysisContext;
  10. import com.alibaba.excel.read.builder.ExcelReaderBuilder;
  11. import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder;
  12. import com.alibaba.excel.read.listener.ReadListener;
  13. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  14. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springblade.common.cache.DictBizCache;
  17. import org.springblade.core.excel.listener.DataListener;
  18. import org.springblade.core.excel.util.ExcelUtil;
  19. import org.springblade.core.oss.model.BladeFile;
  20. import org.springblade.core.tool.utils.ConcurrentDateFormat;
  21. import org.springblade.core.tool.utils.Func;
  22. import org.springblade.modules.baseinfo.rtu.entity.RtuInfoEntity;
  23. import org.springblade.modules.baseinfo.rtu.service.IRtuBaseInfoService;
  24. import org.springblade.modules.manage.entity.RtuImportRecordDetailEntity;
  25. import org.springblade.modules.manage.entity.RtuImportRecordEntity;
  26. import org.springblade.modules.manage.entity.RtuInfoTableDataEntity;
  27. import org.springblade.modules.manage.service.IRtuImportRecordDetailService;
  28. import org.springblade.modules.manage.service.IRtuImportRecordService;
  29. import org.springblade.modules.system.entity.DictBiz;
  30. import java.io.BufferedInputStream;
  31. import java.io.InputStream;
  32. import java.net.HttpURLConnection;
  33. import java.net.URL;
  34. import java.util.*;
  35. import java.util.concurrent.Callable;
  36. /***
  37. * Date:2022/5/22
  38. * Title: 河道水位抽取
  39. * Description:
  40. * @author swp
  41. * @version 1.0
  42. * Remark:认为有必要的其他信息
  43. */
  44. @Slf4j
  45. public class RtuImportTask implements Callable<Integer> {
  46. private BladeFile bladeFile;
  47. private RtuImportRecordEntity recordEntity;
  48. private IRtuBaseInfoService rtuBaseInfoService;
  49. private IRtuImportRecordService rtuImportRecordService;
  50. private IRtuImportRecordDetailService rtuImportRecordDetailService;
  51. public RtuImportTask(BladeFile bladeFile, RtuImportRecordEntity recordEntity, IRtuBaseInfoService rtuBaseInfoService, IRtuImportRecordService rtuImportRecordService, IRtuImportRecordDetailService rtuImportRecordDetailService) {
  52. this.bladeFile = bladeFile;
  53. this.recordEntity = recordEntity;
  54. this.rtuBaseInfoService = rtuBaseInfoService;
  55. this.rtuImportRecordService = rtuImportRecordService;
  56. this.rtuImportRecordDetailService = rtuImportRecordDetailService;
  57. }
  58. @Override
  59. public Integer call() {
  60. try {
  61. log.info("RTU导入任务开始执行*********************");
  62. URL url = new URL(bladeFile.getLink());
  63. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  64. //设置超时间为3秒
  65. conn.setConnectTimeout(3 * 1000);
  66. //防止屏蔽程序抓取而返回403错误
  67. conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
  68. //处理百分比
  69. // float recordSize = 0;
  70. // float processCount = 0;
  71. //得到输入流
  72. InputStream inputStream = conn.getInputStream();
  73. String fileName = bladeFile.getOriginalName();
  74. // LambdaQueryWrapper<RtuInfoEntity> statusWwrapper = Wrappers.<RtuInfoEntity>query().lambda();
  75. // statusWwrapper.eq(RtuInfoEntity::getIsDeleted, 0);
  76. // List<RtuInfoEntity> rtuList = rtuBaseInfoService.list(statusWwrapper);
  77. // Map<String, Integer> rtuStatus = new HashMap<>(rtuList.size());
  78. // for (RtuInfoEntity entity : rtuList) {
  79. // rtuStatus.put(entity.getRtuCode(), 0);
  80. // }
  81. if(!fileName.endsWith("xlsx")){
  82. recordEntity.setImportStatus(2L);
  83. rtuImportRecordService.saveOrUpdate(recordEntity);
  84. return 0;
  85. }
  86. DataListener<RtuInfoTableDataEntity> dataListener = new DataListener<>();
  87. InputStream inputStreambuff = new BufferedInputStream(inputStream);
  88. ExcelReaderBuilder builder = EasyExcel.read(inputStreambuff, RtuInfoTableDataEntity.class, dataListener);
  89. ((ExcelReaderSheetBuilder)builder.sheet(0).headRowNumber(3)).doRead();
  90. List<RtuInfoTableDataEntity> list= dataListener.getDataList();
  91. if (null != list && list.size()>0){
  92. for (RtuInfoTableDataEntity entity:list){
  93. log.info(entity.getRtuCode());
  94. }
  95. }
  96. //List<NoticeExcel> list = ExcelUtil.read(inputStream, 0, RtuInfoTableDataEntity.class);
  97. // List<RtuInfoTableDataEntity> list = new LinkedList<>();
  98. if (fileName.endsWith("xlsx")) {
  99. EasyExcel.read(inputStream, RtuInfoTableDataEntity.class, new ReadListener() {
  100. @Override
  101. public void invoke(Object o, AnalysisContext analysisContext) {
  102. RtuInfoTableDataEntity dataEntity = (RtuInfoTableDataEntity) o;
  103. list.add(dataEntity);
  104. }
  105. @Override
  106. public void doAfterAllAnalysed(AnalysisContext analysisContext) {
  107. boolean dataErrorCheck = false;
  108. for (int i = 2; i < list.size(); i++) {
  109. RtuInfoTableDataEntity dataEntity = list.get(i);
  110. if (null != dataEntity.getCity()) {
  111. String city = dataEntity.getCity().trim();
  112. if (city.length() == 0) {
  113. dataErrorCheck = true;
  114. break;
  115. }
  116. } else {
  117. dataErrorCheck = true;
  118. break;
  119. }
  120. if (null != dataEntity.getDist()) {
  121. String dist = dataEntity.getDist().trim();
  122. if (dist.length() == 0) {
  123. dataErrorCheck = true;
  124. break;
  125. }
  126. } else {
  127. dataErrorCheck = true;
  128. break;
  129. }
  130. if (null != dataEntity.getRtuCode()) {
  131. String rtuCode = dataEntity.getRtuCode().trim();
  132. if (rtuCode.length() > 0) {
  133. if (!isLetterDigit(rtuCode)) {
  134. dataErrorCheck = true;
  135. break;
  136. }
  137. } else {
  138. dataErrorCheck = true;
  139. break;
  140. }
  141. } else {
  142. dataErrorCheck = true;
  143. break;
  144. }
  145. if (null != dataEntity.getRtuName()) {
  146. String rtuName = dataEntity.getRtuName().trim();
  147. if (rtuName.length() == 0) {
  148. dataErrorCheck = true;
  149. break;
  150. }
  151. } else {
  152. dataErrorCheck = true;
  153. break;
  154. }
  155. if (null != dataEntity.getRtuKind()) {
  156. String rtuKind = dataEntity.getRtuKind().trim();
  157. if (rtuKind.length() == 0) {
  158. dataErrorCheck = true;
  159. break;
  160. }
  161. } else {
  162. dataErrorCheck = true;
  163. break;
  164. }
  165. if (null != dataEntity.getManageCompany()) {
  166. String company = dataEntity.getManageCompany().trim();
  167. if (company.length() == 0) {
  168. dataErrorCheck = true;
  169. break;
  170. }
  171. } else {
  172. dataErrorCheck = true;
  173. break;
  174. }
  175. }
  176. if (dataErrorCheck) {
  177. recordEntity.setImportStatus(2L);
  178. rtuImportRecordService.saveOrUpdate(recordEntity);
  179. } else {
  180. for (int i = 2; i < list.size(); i++) {
  181. RtuInfoTableDataEntity dataEntity = list.get(i);
  182. String rtuCode = dataEntity.getRtuCode().trim();
  183. RtuInfoEntity rtuInfoEntity = new RtuInfoEntity();
  184. rtuInfoEntity.setRtuCode(rtuCode);
  185. if (null != dataEntity.getCity()) {
  186. rtuInfoEntity.setAdCity(dataEntity.getCity().trim());
  187. }
  188. if (null != dataEntity.getDist()) {
  189. rtuInfoEntity.setAdDist(dataEntity.getDist().trim());
  190. }
  191. if (null != dataEntity.getRtuName()) {
  192. rtuInfoEntity.setRtuName(dataEntity.getRtuName().trim());
  193. }
  194. if (null != dataEntity.getRtuKind()) {
  195. rtuInfoEntity.setIsRain(0);
  196. rtuInfoEntity.setIsRiver(0);
  197. rtuInfoEntity.setIsRes(0);
  198. rtuInfoEntity.setIsGround(0);
  199. String kinds = dataEntity.getRtuKind().trim();
  200. if (kinds.length() > 0) {
  201. List<DictBiz> bizs = DictBizCache.getList("rtu_kind");
  202. String kindList = "";
  203. if (kinds.contains("水位")) {
  204. rtuInfoEntity.setIsRes(1);
  205. rtuInfoEntity.setIsRiver(1);
  206. for (DictBiz biz : bizs) {
  207. if (biz.getDictKey().equals("river")) {
  208. if (kindList.length() > 0) {
  209. kindList += ",";
  210. }
  211. kindList += Long.toString(biz.getId());
  212. } else if (biz.getDictKey().equals("rsvr")) {
  213. if (kindList.length() > 0) {
  214. kindList += ",";
  215. }
  216. kindList += Long.toString(biz.getId());
  217. }
  218. }
  219. rtuInfoEntity.setRtuKinds(kindList);
  220. }
  221. if (kinds.contains("雨量")) {
  222. rtuInfoEntity.setIsRain(1);
  223. for (DictBiz biz : bizs) {
  224. if (biz.getDictKey().equals("rain")) {
  225. if (kindList.length() > 0) {
  226. kindList += ",";
  227. }
  228. kindList += Long.toString(biz.getId());
  229. break;
  230. }
  231. }
  232. }
  233. if (kinds.contains("墒情")) {
  234. rtuInfoEntity.setIsGround(1);
  235. for (DictBiz biz : bizs) {
  236. if (biz.getDictKey().equals("ground")) {
  237. if (kindList.length() > 0) {
  238. kindList += ",";
  239. }
  240. kindList += Long.toString(biz.getId());
  241. break;
  242. }
  243. }
  244. }
  245. if (kinds.contains("视频")) {
  246. rtuInfoEntity.setIsVideo(1);
  247. // for (DictBiz biz : bizs) {
  248. // if (biz.getDictKey().equals("ground")) {
  249. // if (kindList.length() > 0) {
  250. // kindList += ",";
  251. // }
  252. // kindList += Long.toString(biz.getId());
  253. // break;
  254. // }
  255. // }
  256. }
  257. rtuInfoEntity.setRtuKinds(kindList);
  258. }
  259. }
  260. if (null != dataEntity.getLocationDesc()) {
  261. rtuInfoEntity.setLocationDesc(dataEntity.getLocationDesc().trim());
  262. }
  263. if (null != dataEntity.getLng()) {
  264. ArrayList<String> textArr = new ArrayList<>();
  265. textArr.add("");
  266. String location = dataEntity.getLng().trim();
  267. for (int l = 0; l < location.length(); l++) {
  268. String subtext = location.substring(l, l + 1);
  269. if (Func.isNumeric(subtext)) {
  270. String str = textArr.get(textArr.size() - 1);
  271. str += subtext;
  272. textArr.set(textArr.size() - 1, str);
  273. } else {
  274. textArr.add("");
  275. }
  276. }
  277. ArrayList<String> tmp = new ArrayList<>();
  278. for (String text : textArr) {
  279. if (text.length() > 0) {
  280. tmp.add(text);
  281. }
  282. }
  283. if (tmp.size() >= 4) {
  284. //度分秒,秒有小数点
  285. String v = tmp.get(2) + "." + tmp.get(3);
  286. double lat = Double.parseDouble(v);
  287. lat = lat / 60.0;
  288. v = tmp.get(1);
  289. lat = (Double.parseDouble(v) + lat) / 60.0;
  290. v = tmp.get(0);
  291. lat = Double.parseDouble(v) + lat;
  292. rtuInfoEntity.setLng(String.format("%.06f", lat));
  293. } else if (tmp.size() == 3) {
  294. //度分秒
  295. String v = tmp.get(2);
  296. double lat = Double.parseDouble(v);
  297. lat = lat / 60.0;
  298. v = tmp.get(1);
  299. lat = (Double.parseDouble(v) + lat) / 60.0;
  300. v = tmp.get(0);
  301. lat = Double.parseDouble(v) + lat;
  302. rtuInfoEntity.setLng(String.format("%.06f", lat));
  303. } else if (tmp.size() == 2) {
  304. //度
  305. String v = tmp.get(0) + "." + tmp.get(1);
  306. double lat = Double.parseDouble(v);
  307. rtuInfoEntity.setLng(String.format("%.06f", lat));
  308. }
  309. }
  310. if (null != dataEntity.getLat()) {
  311. ArrayList<String> textArr = new ArrayList<>();
  312. textArr.add("");
  313. String location = dataEntity.getLat().trim();
  314. for (int l = 0; l < location.length(); l++) {
  315. String subtext = location.substring(l, l + 1);
  316. if (Func.isNumeric(subtext)) {
  317. String str = textArr.get(textArr.size() - 1);
  318. str += subtext;
  319. textArr.set(textArr.size() - 1, str);
  320. } else {
  321. textArr.add("");
  322. }
  323. }
  324. ArrayList<String> tmp = new ArrayList<>();
  325. for (String text : textArr) {
  326. if (text.length() > 0) {
  327. tmp.add(text);
  328. }
  329. }
  330. if (tmp.size() >= 4) {
  331. //度分秒,秒有小数点
  332. String v = tmp.get(2) + "." + tmp.get(3);
  333. double lat = Double.parseDouble(v);
  334. lat = lat / 60.0;
  335. v = tmp.get(1);
  336. lat = (Double.parseDouble(v) + lat) / 60.0;
  337. v = tmp.get(0);
  338. lat = Double.parseDouble(v) + lat;
  339. rtuInfoEntity.setLat(String.format("%.06f", lat));
  340. } else if (tmp.size() == 3) {
  341. //度分秒
  342. String v = tmp.get(2);
  343. double lat = Double.parseDouble(v);
  344. lat = lat / 60.0;
  345. v = tmp.get(1);
  346. lat = (Double.parseDouble(v) + lat) / 60.0;
  347. v = tmp.get(0);
  348. lat = Double.parseDouble(v) + lat;
  349. rtuInfoEntity.setLat(String.format("%.06f", lat));
  350. } else if (tmp.size() == 2) {
  351. //度
  352. String v = tmp.get(0) + "." + tmp.get(1);
  353. double lat = Double.parseDouble(v);
  354. rtuInfoEntity.setLat(String.format("%.06f", lat));
  355. }
  356. }
  357. if (null != dataEntity.getManageCompany()) {
  358. rtuInfoEntity.setManageCompany(dataEntity.getManageCompany().trim());
  359. }
  360. if (null != dataEntity.getRtuBrand()) {
  361. rtuInfoEntity.setRtuBrand(dataEntity.getRtuBrand().trim());
  362. }
  363. if (null != dataEntity.getRtuModel()) {
  364. rtuInfoEntity.setRtuModel(dataEntity.getRtuModel().trim());
  365. }
  366. if (null != dataEntity.getRtuReplaceDate()) {
  367. ArrayList<String> textArr = new ArrayList<>();
  368. textArr.add("");
  369. String replaceDate = dataEntity.getRtuReplaceDate().trim();
  370. for (int l = 0; l < replaceDate.length(); l++) {
  371. String subtext = replaceDate.substring(l, l + 1);
  372. if (Func.isNumeric(subtext)) {
  373. String str = textArr.get(textArr.size() - 1);
  374. str += subtext;
  375. textArr.set(textArr.size() - 1, str);
  376. } else {
  377. textArr.add("");
  378. }
  379. }
  380. ArrayList<String> tmp = new ArrayList<>();
  381. for (String text : textArr) {
  382. if (text.length() > 0) {
  383. tmp.add(text);
  384. }
  385. }
  386. if (tmp.size() >= 3) {
  387. String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
  388. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  389. rtuInfoEntity.setRtuReplaceDate(dt);
  390. } else if (tmp.size() == 2) {
  391. String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
  392. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  393. rtuInfoEntity.setRtuReplaceDate(dt);
  394. }
  395. }
  396. if (null != dataEntity.getToSheng()) {
  397. if (dataEntity.getToSheng().trim().equals("是")) {
  398. rtuInfoEntity.setDatagramToSheng(1);
  399. } else {
  400. rtuInfoEntity.setDatagramToSheng(0);
  401. }
  402. } else {
  403. rtuInfoEntity.setDatagramToSheng(0);
  404. }
  405. if (null != dataEntity.getToShi()) {
  406. if (dataEntity.getToShi().trim().equals("是")) {
  407. rtuInfoEntity.setDatagramToShi(1);
  408. } else {
  409. rtuInfoEntity.setDatagramToShi(0);
  410. }
  411. } else {
  412. rtuInfoEntity.setDatagramToShi(0);
  413. }
  414. if (null != dataEntity.getToQu()) {
  415. if (dataEntity.getToQu().trim().equals("是")) {
  416. rtuInfoEntity.setDatagramToQu(1);
  417. } else {
  418. rtuInfoEntity.setDatagramToQu(0);
  419. }
  420. } else {
  421. rtuInfoEntity.setDatagramToQu(0);
  422. }
  423. if (null != dataEntity.getRainSensorBrand()) {
  424. rtuInfoEntity.setRainSensorBrand(dataEntity.getRainSensorBrand().trim());
  425. }
  426. if (null != dataEntity.getRainSensorModel()) {
  427. rtuInfoEntity.setRainSensorModel(dataEntity.getRainSensorModel().trim());
  428. }
  429. if (null != dataEntity.getRainSensorReplaceDate()) {
  430. ArrayList<String> textArr = new ArrayList<>();
  431. textArr.add("");
  432. String replaceDate = dataEntity.getRainSensorReplaceDate().trim();
  433. for (int l = 0; l < replaceDate.length(); l++) {
  434. String subtext = replaceDate.substring(l, l + 1);
  435. if (Func.isNumeric(subtext)) {
  436. String str = textArr.get(textArr.size() - 1);
  437. str += subtext;
  438. textArr.set(textArr.size() - 1, str);
  439. } else {
  440. textArr.add("");
  441. }
  442. }
  443. ArrayList<String> tmp = new ArrayList<>();
  444. for (String text : textArr) {
  445. if (text.length() > 0) {
  446. tmp.add(text);
  447. }
  448. }
  449. if (tmp.size() >= 3) {
  450. String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
  451. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  452. rtuInfoEntity.setRainSensorReplaceDate(dt);
  453. } else if (tmp.size() == 2) {
  454. String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
  455. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  456. rtuInfoEntity.setRainSensorReplaceDate(dt);
  457. }
  458. }
  459. if (null != dataEntity.getWaterSensorType()) {
  460. List<DictBiz> bizs = DictBizCache.getList("water_level_sensor_type");
  461. for (DictBiz biz : bizs) {
  462. if (dataEntity.getWaterSensorType().trim().contains(biz.getDictValue())) {
  463. rtuInfoEntity.setWaterSensorType(biz.getId());
  464. break;
  465. }
  466. }
  467. }
  468. if (null != dataEntity.getWaterSensorBrand()) {
  469. rtuInfoEntity.setWaterSensorBrand(dataEntity.getWaterSensorBrand().trim());
  470. }
  471. if (null != dataEntity.getWaterSensorModel()) {
  472. rtuInfoEntity.setWaterSensorModel(dataEntity.getWaterSensorModel().trim());
  473. }
  474. if (null != dataEntity.getWaterSensorReplaceDate()) {
  475. ArrayList<String> textArr = new ArrayList<>();
  476. textArr.add("");
  477. String replaceDate = dataEntity.getWaterSensorReplaceDate().trim();
  478. for (int l = 0; l < replaceDate.length(); l++) {
  479. String subtext = replaceDate.substring(l, l + 1);
  480. if (Func.isNumeric(subtext)) {
  481. String str = textArr.get(textArr.size() - 1);
  482. str += subtext;
  483. textArr.set(textArr.size() - 1, str);
  484. } else {
  485. textArr.add("");
  486. }
  487. }
  488. ArrayList<String> tmp = new ArrayList<>();
  489. for (String text : textArr) {
  490. if (text.length() > 0) {
  491. tmp.add(text);
  492. }
  493. }
  494. if (tmp.size() >= 3) {
  495. String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
  496. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  497. rtuInfoEntity.setWaterSensorReplaceDate(dt);
  498. } else if (tmp.size() == 2) {
  499. String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
  500. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  501. rtuInfoEntity.setWaterSensorReplaceDate(dt);
  502. }
  503. }
  504. if (null != dataEntity.getGroundSensorType()) {
  505. List<DictBiz> bizs = DictBizCache.getList("ground_water_sensor_type");
  506. for (DictBiz biz : bizs) {
  507. if (dataEntity.getGroundSensorType().trim().contains(biz.getDictValue())) {
  508. rtuInfoEntity.setGroundSensorType(biz.getId());
  509. break;
  510. }
  511. }
  512. }
  513. if (null != dataEntity.getGroundSensorBrand()) {
  514. rtuInfoEntity.setGroundSensorBrand(dataEntity.getGroundSensorBrand().trim());
  515. }
  516. if (null != dataEntity.getGroundSensorModel()) {
  517. rtuInfoEntity.setGroundSensorModel(dataEntity.getGroundSensorModel().trim());
  518. }
  519. if (null != dataEntity.getGroundSensorReplaceDate()) {
  520. ArrayList<String> textArr = new ArrayList<>();
  521. textArr.add("");
  522. String replaceDate = dataEntity.getGroundSensorReplaceDate().trim();
  523. for (int l = 0; l < replaceDate.length(); l++) {
  524. String subtext = replaceDate.substring(l, l + 1);
  525. if (Func.isNumeric(subtext)) {
  526. String str = textArr.get(textArr.size() - 1);
  527. str += subtext;
  528. textArr.set(textArr.size() - 1, str);
  529. } else {
  530. textArr.add("");
  531. }
  532. }
  533. ArrayList<String> tmp = new ArrayList<>();
  534. for (String text : textArr) {
  535. if (text.length() > 0) {
  536. tmp.add(text);
  537. }
  538. }
  539. if (tmp.size() >= 3) {
  540. String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
  541. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  542. rtuInfoEntity.setGroundSensorReplaceDate(dt);
  543. } else if (tmp.size() == 2) {
  544. String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
  545. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  546. rtuInfoEntity.setGroundSensorReplaceDate(dt);
  547. }
  548. }
  549. if (null != dataEntity.getBatteryModel()) {
  550. rtuInfoEntity.setBatteryModel(dataEntity.getBatteryModel().trim());
  551. }
  552. if (null != dataEntity.getBatteryReplaceDate()) {
  553. ArrayList<String> textArr = new ArrayList<>();
  554. textArr.add("");
  555. String replaceDate = dataEntity.getBatteryReplaceDate().trim();
  556. for (int l = 0; l < replaceDate.length(); l++) {
  557. String subtext = replaceDate.substring(l, l + 1);
  558. if (Func.isNumeric(subtext)) {
  559. String str = textArr.get(textArr.size() - 1);
  560. str += subtext;
  561. textArr.set(textArr.size() - 1, str);
  562. } else {
  563. textArr.add("");
  564. }
  565. }
  566. ArrayList<String> tmp = new ArrayList<>();
  567. for (String text : textArr) {
  568. if (text.length() > 0) {
  569. tmp.add(text);
  570. }
  571. }
  572. if (tmp.size() >= 3) {
  573. String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
  574. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  575. rtuInfoEntity.setBatteryReplaceDate(dt);
  576. } else if (tmp.size() == 2) {
  577. String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
  578. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  579. rtuInfoEntity.setBatteryReplaceDate(dt);
  580. }
  581. }
  582. if (null != dataEntity.getSunModel()) {
  583. rtuInfoEntity.setSunPowerModel(dataEntity.getSunModel().trim());
  584. }
  585. if (null != dataEntity.getSimId()) {
  586. rtuInfoEntity.setNetworkSimId(dataEntity.getSimId().trim());
  587. }
  588. if (null != dataEntity.getSimPay()) {
  589. rtuInfoEntity.setNetworkPayer(dataEntity.getSimPay().trim());
  590. }
  591. if (null != dataEntity.getSimOverdate()) {
  592. ArrayList<String> textArr = new ArrayList<>();
  593. textArr.add("");
  594. String replaceDate = dataEntity.getSimOverdate().trim();
  595. for (int l = 0; l < replaceDate.length(); l++) {
  596. String subtext = replaceDate.substring(l, l + 1);
  597. if (Func.isNumeric(subtext)) {
  598. String str = textArr.get(textArr.size() - 1);
  599. str += subtext;
  600. textArr.set(textArr.size() - 1, str);
  601. } else {
  602. textArr.add("");
  603. }
  604. }
  605. ArrayList<String> tmp = new ArrayList<>();
  606. for (String text : textArr) {
  607. if (text.length() > 0) {
  608. tmp.add(text);
  609. }
  610. }
  611. if (tmp.size() >= 3) {
  612. String v = tmp.get(0) + "-" + tmp.get(1) + "-" + tmp.get(2);
  613. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  614. rtuInfoEntity.setNetworkPayEndDate(dt);
  615. } else if (tmp.size() == 2) {
  616. String v = tmp.get(0) + "-" + tmp.get(1) + "-01";
  617. Date dt = Func.parse(v, ConcurrentDateFormat.of("yyyy-MM-dd"));
  618. rtuInfoEntity.setNetworkPayEndDate(dt);
  619. }
  620. }
  621. if (null != dataEntity.getSatellite()) {
  622. if (dataEntity.getSatellite().trim().equals("是")) {
  623. rtuInfoEntity.setIsSatellite(1);
  624. } else {
  625. rtuInfoEntity.setIsSatellite(0);
  626. }
  627. } else {
  628. rtuInfoEntity.setIsSatellite(0);
  629. }
  630. if (null != dataEntity.getSatelliteModel()) {
  631. List<DictBiz> bizs = DictBizCache.getList("satellite_model");
  632. for (DictBiz biz : bizs) {
  633. if (dataEntity.getSatelliteModel().trim().contains(biz.getDictValue())) {
  634. rtuInfoEntity.setSatelliteModel(biz.getId());
  635. break;
  636. }
  637. }
  638. }
  639. if (null != dataEntity.getRemark()) {
  640. rtuInfoEntity.setRemark(dataEntity.getRemark().trim());
  641. }
  642. //查找行政区划
  643. RtuInfoEntity adcd= rtuBaseInfoService.getAdcd(rtuInfoEntity);
  644. if (adcd!= null){
  645. rtuInfoEntity.setAdName(adcd.getAdName());
  646. rtuInfoEntity.setAdCode(adcd.getAdCode());
  647. }
  648. System.out.println("save record********************");
  649. if (recordEntity.getSaveType() == 0) {
  650. //新增
  651. RtuInfoEntity entity = rtuBaseInfoService.rtuInfoByRtuCode(rtuInfoEntity.getRtuCode());
  652. if (null == entity) {
  653. // System.out.println("save ********************");
  654. // System.out.println(JSON.toJSON(rtuInfoEntity).toString());
  655. rtuBaseInfoService.save(rtuInfoEntity);
  656. RtuImportRecordDetailEntity detailEntity = new RtuImportRecordDetailEntity();
  657. detailEntity.setRecordId(recordEntity.getId());
  658. detailEntity.setRtuCode(rtuInfoEntity.getRtuCode());
  659. detailEntity.setRtuName(rtuInfoEntity.getRtuName());
  660. detailEntity.setSaveType(0);
  661. rtuImportRecordDetailService.save(detailEntity);
  662. }
  663. } else if (recordEntity.getSaveType() == 1) {
  664. //覆盖
  665. RtuInfoEntity entity = rtuBaseInfoService.rtuInfoByRtuCode(rtuInfoEntity.getRtuCode());
  666. if (null != entity) {
  667. //更新列
  668. entity.setRtuName(rtuInfoEntity.getRtuName());
  669. entity.setAdCity(rtuInfoEntity.getAdCity());
  670. entity.setAdDist(rtuInfoEntity.getAdDist());
  671. entity.setRtuKinds(rtuInfoEntity.getRtuKinds());
  672. entity.setLocationDesc(rtuInfoEntity.getLocationDesc());
  673. entity.setLng(rtuInfoEntity.getLng());
  674. entity.setLat(rtuInfoEntity.getLat());
  675. entity.setManageCompany(rtuInfoEntity.getManageCompany());
  676. entity.setRtuBrand(rtuInfoEntity.getRtuBrand());
  677. entity.setRtuModel(rtuInfoEntity.getRtuModel());
  678. entity.setRtuReplaceDate(rtuInfoEntity.getRtuReplaceDate());
  679. entity.setDatagramToQu(rtuInfoEntity.getDatagramToQu());
  680. entity.setDatagramToShi(rtuInfoEntity.getDatagramToShi());
  681. entity.setDatagramToSheng(rtuInfoEntity.getDatagramToSheng());
  682. entity.setRainSensorBrand(rtuInfoEntity.getRainSensorBrand());
  683. entity.setRainSensorModel(rtuInfoEntity.getRainSensorModel());
  684. entity.setRainSensorReplaceDate(rtuInfoEntity.getRainSensorReplaceDate());
  685. entity.setWaterSensorBrand(rtuInfoEntity.getWaterSensorBrand());
  686. entity.setWaterSensorModel(rtuInfoEntity.getWaterSensorModel());
  687. entity.setWaterSensorReplaceDate(rtuInfoEntity.getWaterSensorReplaceDate());
  688. entity.setWaterSensorType(rtuInfoEntity.getWaterSensorType());
  689. entity.setGroundSensorBrand(rtuInfoEntity.getGroundSensorBrand());
  690. entity.setGroundSensorModel(rtuInfoEntity.getGroundSensorModel());
  691. entity.setGroundSensorReplaceDate(rtuInfoEntity.getGroundSensorReplaceDate());
  692. entity.setGroundSensorType(rtuInfoEntity.getGroundSensorType());
  693. entity.setBatteryModel(rtuInfoEntity.getBatteryModel());
  694. entity.setBatteryReplaceDate(rtuInfoEntity.getBatteryReplaceDate());
  695. entity.setSunPowerModel(rtuInfoEntity.getSunPowerModel());
  696. entity.setNetworkSimId(rtuInfoEntity.getNetworkSimId());
  697. entity.setNetworkPayer(rtuInfoEntity.getNetworkPayer());
  698. entity.setNetworkPayEndDate(rtuInfoEntity.getNetworkPayEndDate());
  699. entity.setSatelliteModel(rtuInfoEntity.getSatelliteModel());
  700. entity.setIsSatellite(rtuInfoEntity.getIsSatellite());
  701. entity.setRemark(rtuInfoEntity.getRemark());
  702. entity.setAdCode(rtuInfoEntity.getAdCode());
  703. entity.setAdName(rtuInfoEntity.getAdName());
  704. entity.setUpdateTime(new Date());
  705. rtuBaseInfoService.updateById(entity);
  706. RtuImportRecordDetailEntity detailEntity = new RtuImportRecordDetailEntity();
  707. detailEntity.setRecordId(recordEntity.getId());
  708. detailEntity.setRtuCode(rtuInfoEntity.getRtuCode());
  709. detailEntity.setRtuName(rtuInfoEntity.getRtuName());
  710. // System.out.println("update ********************");
  711. // System.out.println(JSON.toJSON(rtuInfoEntity).toString());
  712. detailEntity.setSaveType(1);
  713. rtuImportRecordDetailService.save(detailEntity);
  714. }
  715. } else if (recordEntity.getSaveType() == 2) {
  716. //新增或修改
  717. RtuImportRecordDetailEntity detailEntity = new RtuImportRecordDetailEntity();
  718. detailEntity.setRecordId(recordEntity.getId());
  719. detailEntity.setRtuCode(rtuInfoEntity.getRtuCode());
  720. detailEntity.setRtuName(rtuInfoEntity.getRtuName());
  721. RtuInfoEntity entity = rtuBaseInfoService.rtuInfoByRtuCode(rtuInfoEntity.getRtuCode());
  722. if (null != entity) {
  723. detailEntity.setSaveType(1);
  724. entity.setUpdateTime(new Date());
  725. //更新列
  726. entity.setRtuName(rtuInfoEntity.getRtuName());
  727. entity.setAdCity(rtuInfoEntity.getAdCity());
  728. entity.setAdDist(rtuInfoEntity.getAdDist());
  729. entity.setRtuKinds(rtuInfoEntity.getRtuKinds());
  730. entity.setLocationDesc(rtuInfoEntity.getLocationDesc());
  731. entity.setLng(rtuInfoEntity.getLng());
  732. entity.setLat(rtuInfoEntity.getLat());
  733. entity.setManageCompany(rtuInfoEntity.getManageCompany());
  734. entity.setRtuBrand(rtuInfoEntity.getRtuBrand());
  735. entity.setRtuModel(rtuInfoEntity.getRtuModel());
  736. entity.setRtuReplaceDate(rtuInfoEntity.getRtuReplaceDate());
  737. entity.setDatagramToQu(rtuInfoEntity.getDatagramToQu());
  738. entity.setDatagramToShi(rtuInfoEntity.getDatagramToShi());
  739. entity.setDatagramToSheng(rtuInfoEntity.getDatagramToSheng());
  740. entity.setRainSensorBrand(rtuInfoEntity.getRainSensorBrand());
  741. entity.setRainSensorModel(rtuInfoEntity.getRainSensorModel());
  742. entity.setRainSensorReplaceDate(rtuInfoEntity.getRainSensorReplaceDate());
  743. entity.setWaterSensorBrand(rtuInfoEntity.getWaterSensorBrand());
  744. entity.setWaterSensorModel(rtuInfoEntity.getWaterSensorModel());
  745. entity.setWaterSensorReplaceDate(rtuInfoEntity.getWaterSensorReplaceDate());
  746. entity.setWaterSensorType(rtuInfoEntity.getWaterSensorType());
  747. entity.setGroundSensorBrand(rtuInfoEntity.getGroundSensorBrand());
  748. entity.setGroundSensorModel(rtuInfoEntity.getGroundSensorModel());
  749. entity.setGroundSensorReplaceDate(rtuInfoEntity.getGroundSensorReplaceDate());
  750. entity.setGroundSensorType(rtuInfoEntity.getGroundSensorType());
  751. entity.setBatteryModel(rtuInfoEntity.getBatteryModel());
  752. entity.setBatteryReplaceDate(rtuInfoEntity.getBatteryReplaceDate());
  753. entity.setSunPowerModel(rtuInfoEntity.getSunPowerModel());
  754. entity.setNetworkSimId(rtuInfoEntity.getNetworkSimId());
  755. entity.setNetworkPayer(rtuInfoEntity.getNetworkPayer());
  756. entity.setNetworkPayEndDate(rtuInfoEntity.getNetworkPayEndDate());
  757. entity.setSatelliteModel(rtuInfoEntity.getSatelliteModel());
  758. entity.setIsSatellite(rtuInfoEntity.getIsSatellite());
  759. entity.setRemark(rtuInfoEntity.getRemark());
  760. entity.setAdCode(rtuInfoEntity.getAdCode());
  761. entity.setAdName(rtuInfoEntity.getAdName());
  762. rtuBaseInfoService.updateById(entity);
  763. }else{
  764. rtuBaseInfoService.save(rtuInfoEntity);
  765. detailEntity.setSaveType(0);
  766. }
  767. rtuImportRecordDetailService.save(detailEntity);
  768. }
  769. }
  770. recordEntity.setImportStatus(1L);
  771. rtuImportRecordService.saveOrUpdate(recordEntity);
  772. }
  773. // Set<String> rtuCodes = rtuStatus.keySet();
  774. // for (String key : rtuCodes) {
  775. // Integer status = rtuStatus.get(key);
  776. // if (status == 0) {
  777. // LambdaQueryWrapper<RtuInfoEntity> wrapper = Wrappers.<RtuInfoEntity>query().lambda();
  778. // wrapper.eq(RtuInfoEntity::getIsDeleted, 0);
  779. // wrapper.eq(RtuInfoEntity::getRtuCode, key);
  780. // RtuInfoEntity entity = rtuBaseInfoService.getOne(wrapper);
  781. // if (null != entity) {
  782. // System.out.println("remove ********************");
  783. // System.out.println(JSON.toJSON(entity).toString());
  784. //
  785. // rtuBaseInfoService.removeById(entity.getId());
  786. // RtuImportRecordDetailEntity detailEntity = new RtuImportRecordDetailEntity();
  787. // detailEntity.setRecordId(recordEntity.getId());
  788. // detailEntity.setRtuCode(entity.getRtuCode());
  789. // detailEntity.setRtuName(entity.getRtuName());
  790. // detailEntity.setSaveType(2);
  791. // rtuImportRecordDetailService.save(detailEntity);
  792. // }
  793. // }
  794. // }
  795. }
  796. }).sheet().doRead();
  797. } else {
  798. recordEntity.setImportStatus(2L);
  799. rtuImportRecordService.saveOrUpdate(recordEntity);
  800. }
  801. } catch (Exception e) {
  802. e.printStackTrace();
  803. log.error("RTU导入任务异常 {}", e.getMessage());
  804. try {
  805. recordEntity.setImportStatus(2L);
  806. rtuImportRecordService.saveOrUpdate(recordEntity);
  807. } catch (Exception e1) {
  808. e1.printStackTrace();
  809. }
  810. }
  811. return 0;
  812. }
  813. private static boolean isLetterDigit(String str) {
  814. String regex = "^[a-z0-9A-Z]+$";
  815. return str.matches(regex);
  816. }
  817. private Double tranformPos(String lng) {
  818. lng = lng
  819. .trim()
  820. .replace("g", "");
  821. if (lng.indexOf("o") >= 0 || lng.indexOf("°") >= 0 || lng.indexOf("°") >= 0 || lng.indexOf("°") >= 0) {
  822. lng = lng
  823. .trim()
  824. .replace("o", ":")
  825. .replace("°", ":")
  826. .replace("°", ":")
  827. .replace("°", ":")
  828. .replace("′", ":")
  829. .replace("'", ":")
  830. .replace("\"", "")
  831. .replace("″", "")
  832. .replace(".", ":");
  833. String[] lntArr = lng.split(":");
  834. Double result = 0D;
  835. if (lntArr.length == 1) {
  836. String[] lntArr2 = new String[3];
  837. lntArr2[0] = lntArr[0];
  838. lntArr2[1] = "0";
  839. lntArr2[2] = "0";
  840. lntArr = lntArr2;
  841. } else if (lntArr.length == 2) {
  842. String[] lntArr2 = new String[3];
  843. lntArr2[0] = lntArr[0];
  844. lntArr2[1] = lntArr[1];
  845. lntArr2[2] = "0";
  846. lntArr = lntArr2;
  847. }
  848. for (int i = lntArr.length; i > 0; i--) {
  849. String str = lntArr[i - 1];
  850. if (null != str) {
  851. str = str.trim();
  852. if (null != str && str.length() > 0) {
  853. double v = Double.parseDouble(str);
  854. if (i == 1) {
  855. result = v + result;
  856. } else {
  857. result = (result + v) / 60;
  858. }
  859. } else {
  860. double v = 0.0;
  861. if (i == 1) {
  862. result = v + result;
  863. } else {
  864. result = (result + v) / 60;
  865. }
  866. }
  867. } else {
  868. double v = 0.0;
  869. if (i == 1) {
  870. result = v + result;
  871. } else {
  872. result = (result + v) / 60;
  873. }
  874. }
  875. }
  876. return result;
  877. } else {
  878. String lng2 = lng;
  879. lng2 = lng2
  880. .trim()
  881. .replace(".", ":");
  882. String[] vs = lng2.split(":");
  883. if (vs.length > 1) {
  884. lng = lng
  885. .trim()
  886. .replace("o", ":")
  887. .replace("°", ":")
  888. .replace("°", ":")
  889. .replace("°", ":")
  890. .replace("′", ":")
  891. .replace("'", ":")
  892. .replace("\"", "")
  893. .replace("″", "")
  894. .replace(".", ":");
  895. String[] lntArr = lng.split(":");
  896. Double result = 0D;
  897. if (lntArr.length == 1) {
  898. String[] lntArr2 = new String[3];
  899. lntArr2[0] = lntArr[0];
  900. lntArr2[1] = "0";
  901. lntArr2[2] = "0";
  902. lntArr = lntArr2;
  903. } else if (lntArr.length == 2) {
  904. String[] lntArr2 = new String[3];
  905. lntArr2[0] = lntArr[0];
  906. lntArr2[1] = lntArr[1];
  907. lntArr2[2] = "0";
  908. lntArr = lntArr2;
  909. }
  910. for (int i = lntArr.length; i > 0; i--) {
  911. String str = lntArr[i - 1];
  912. if (null != str) {
  913. str = str.trim();
  914. if (null != str && str.length() > 0) {
  915. double v = Double.parseDouble(str);
  916. if (i == 1) {
  917. result = v + result;
  918. } else {
  919. result = (result + v) / 60;
  920. }
  921. } else {
  922. double v = 0.0;
  923. if (i == 1) {
  924. result = v + result;
  925. } else {
  926. result = (result + v) / 60;
  927. }
  928. }
  929. } else {
  930. double v = 0.0;
  931. if (i == 1) {
  932. result = v + result;
  933. } else {
  934. result = (result + v) / 60;
  935. }
  936. }
  937. }
  938. return result;
  939. } else {
  940. double v = Double.parseDouble(lng);
  941. return v;
  942. }
  943. }
  944. }
  945. }