2e1a50cee89b94f8502dcc7786c79cfabf4890cb.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. package cn.com.goldenwater.dcproj.service.impl;
  2. import cn.com.goldenwater.dcproj.dao.AttAdXBaseDao;
  3. import cn.com.goldenwater.dcproj.dao.AttHystBaseDao;
  4. import cn.com.goldenwater.dcproj.model.AttAdXBase;
  5. import cn.com.goldenwater.dcproj.model.AttHystBase;
  6. import cn.com.goldenwater.dcproj.param.AttAdXBaseParam;
  7. import cn.com.goldenwater.dcproj.param.AttHystBaseParam;
  8. import cn.com.goldenwater.dcproj.param.BisInspHystInfoParam;
  9. import cn.com.goldenwater.dcproj.service.AttHystBaseService;
  10. import cn.com.goldenwater.core.service.AbstractCrudService;
  11. import cn.com.goldenwater.dcproj.utils.expExcel.ExportUtil;
  12. import cn.com.goldenwater.id.util.UuidUtil;
  13. import com.github.pagehelper.PageHelper;
  14. import com.github.pagehelper.PageInfo;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.apache.poi.ss.usermodel.Cell;
  17. import org.apache.poi.ss.usermodel.Row;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import java.text.DecimalFormat;
  23. import java.util.*;
  24. /**
  25. * @author lune
  26. * @date 2021-3-2
  27. */
  28. @Service
  29. @Transactional(rollbackFor = Exception.class)
  30. public class AttHystBaseServiceImpl extends AbstractCrudService<AttHystBase, AttHystBaseParam> implements AttHystBaseService {
  31. @Autowired
  32. private AttHystBaseDao attHystBaseDao;
  33. @Autowired
  34. private AttAdXBaseDao attAdXBaseDao;
  35. public AttHystBaseServiceImpl(AttHystBaseDao attHystBaseDao) {
  36. super(attHystBaseDao);
  37. this.attHystBaseDao = attHystBaseDao;
  38. }
  39. @Override
  40. public PageInfo<AttHystBase> getListInfo(BisInspHystInfoParam p) {
  41. PageHelper.startPage(p);
  42. List<AttHystBase> list = this.attHystBaseDao.findListByParam(p);
  43. PageInfo<AttHystBase> pageInfo = new PageInfo(list);
  44. return pageInfo;
  45. }
  46. @Override
  47. public List<String> impExcelTest(MultipartFile file, AttHystBaseParam attHystBaseParam) {
  48. List<Row> rowList = ExportUtil.getRowListByFile(file);
  49. List<AttHystBase> addList = new ArrayList<>();
  50. List<AttHystBase> updateList = new ArrayList<>();
  51. if (rowList.size() > 1) {
  52. Row titleRow = rowList.get(0);//第一行标题
  53. for (int i = 1; i < rowList.size(); i++) {
  54. Row row = rowList.get(i);
  55. AttHystBase hystBaseParam = new AttHystBase();
  56. for (int j = 2; j < titleRow.getPhysicalNumberOfCells(); j++) {
  57. Cell cell = row.getCell(j);
  58. if (cell == null) {
  59. continue;
  60. }
  61. String value = cell.toString();
  62. if (StringUtils.isBlank(value)) {
  63. continue;
  64. }
  65. if (j == 2) {
  66. hystBaseParam.setHystName(value);
  67. } else if (j == 3) {
  68. hystBaseParam.setStatisCode(value);
  69. } else if (j == 5) {
  70. hystBaseParam.setAdCode(value);//存市
  71. } else if (j == 6) {
  72. hystBaseParam.setAdName(value);//存县
  73. } else if (j == 7) {
  74. hystBaseParam.setHystSite(value);//所在乡村
  75. } else if (j == 8) {
  76. hystBaseParam.setLinkMan(value);
  77. } else if (j == 9) {
  78. hystBaseParam.setLinkTel(value);
  79. } else if (j == 22) {//厂房所在河流域
  80. hystBaseParam.setRvName(value);
  81. } else if (j == 23) {//建设年月
  82. hystBaseParam.setCompDate(value);
  83. } else if (j == 24) {//所有制
  84. hystBaseParam.setOwnerType(value);
  85. } else if (j == 25) {//开发方式
  86. hystBaseParam.setExptType(value);
  87. } else if (j == 26) {//装机(kW)
  88. hystBaseParam.setInsCap(value);
  89. } else if (j == 27) {//坝高
  90. hystBaseParam.setDamHeig(value);
  91. } else if (j == 28) {//库容
  92. hystBaseParam.setTotCap(value);
  93. } else if (j == 29) {//生态流量核定值
  94. if (!value.equals("-")) {
  95. hystBaseParam.setZlgyFlow(value);
  96. }
  97. } else if (j == 30) {//水库是否注册
  98. hystBaseParam.setHystIsReg(value);
  99. } else if (j == 31) {//注册号
  100. hystBaseParam.setRegNo(value);
  101. } else if (j == 32) {//大坝是否开展安全鉴定
  102. hystBaseParam.setIsSafety(value);
  103. } else if (j == 33) {//清理整改分类
  104. hystBaseParam.setExmnType(value);
  105. } else if (j == 34) {//在建
  106. } else if (j == 35) {//厂房经度
  107. hystBaseParam.setHystLong(getFormateDouble(value));
  108. } else if (j == 36) {
  109. hystBaseParam.setHystLat(getFormateDouble(value));
  110. } else if (j == 37) {//取水经度
  111. hystBaseParam.setCenterX(getFormateDouble(value));
  112. } else if (j == 38) {
  113. hystBaseParam.setCenterY(getFormateDouble(value));
  114. }
  115. }
  116. if (StringUtils.isBlank(hystBaseParam.getId())) {
  117. hystBaseParam.setId(UuidUtil.uuid());
  118. hystBaseParam.setIntm(new Date());
  119. hystBaseParam.setUptm(new Date());
  120. addList.add(hystBaseParam);
  121. } else{
  122. updateList.add(hystBaseParam);
  123. }
  124. }
  125. }
  126. for (AttHystBase hystBaseParam : addList) {
  127. hystBaseParam.setOwnerType(getOwnerType(hystBaseParam.getOwnerType()));
  128. hystBaseParam.setExptType(getExptType(hystBaseParam.getExptType()));
  129. hystBaseParam.setHystIsReg(getShiFou(hystBaseParam.getHystIsReg()));
  130. hystBaseParam.setIsSafety(getIsSafety(hystBaseParam.getIsSafety()));
  131. hystBaseParam.setExmnType(getExmnType(hystBaseParam.getExmnType()));
  132. //处理行政区划
  133. AttAdXBaseParam attAdXBaseParam = new AttAdXBaseParam();
  134. attAdXBaseParam.setAdName(hystBaseParam.getAdName());
  135. attAdXBaseParam.setUpAdName(hystBaseParam.getAdCode());
  136. AttAdXBase by = attAdXBaseDao.getBy(attAdXBaseParam);
  137. if(by != null){
  138. hystBaseParam.setAdName(by.getAdName());
  139. hystBaseParam.setAdCode(by.getAdCode());
  140. }else{
  141. hystBaseParam.setAdCode("");
  142. }
  143. }
  144. if (addList.size() > 0) {
  145. for (AttHystBase wintBaseB : addList) {
  146. if (wintBaseB.getHystName() == null) {
  147. continue;
  148. }
  149. attHystBaseDao.insert(wintBaseB);
  150. }
  151. }
  152. if (updateList.size() > 0) {
  153. for (AttHystBase wintBaseB : updateList) {
  154. if (wintBaseB.getHystName() == null) {
  155. continue;
  156. }
  157. attHystBaseDao.update(wintBaseB);
  158. }
  159. }
  160. return null;
  161. }
  162. @Override
  163. public List<String> impExcelTestXY(MultipartFile file, AttHystBaseParam attHystBaseParam) {
  164. List<Row> rowList = ExportUtil.getRowListByFile(file);
  165. List<AttHystBase> addList = new ArrayList<>();
  166. List<AttHystBase> updateList = new ArrayList<>();
  167. if (rowList.size() > 1) {
  168. Row titleRow = rowList.get(0);//第一行标题
  169. for (int i = 1; i < rowList.size(); i++) {
  170. Row row = rowList.get(i);
  171. AttHystBase hystBaseParam = new AttHystBase();
  172. for (int j = 2; j < titleRow.getPhysicalNumberOfCells(); j++) {
  173. Cell cell = row.getCell(j);
  174. if (cell == null) {
  175. continue;
  176. }
  177. String value = cell.toString();
  178. if (StringUtils.isBlank(value)) {
  179. continue;
  180. }
  181. if (j == 2) {//名字
  182. hystBaseParam.setHystName(value);
  183. } else if (j == 3) {//统计代码
  184. hystBaseParam.setStatisCode(value);
  185. } else if(j == 33){//清理整改分类
  186. hystBaseParam.setExmnType(value);
  187. } else if (j == 35) {//厂房经度
  188. hystBaseParam.setHystLong(getFormateDouble(value));
  189. } else if (j == 36) {
  190. hystBaseParam.setHystLat(getFormateDouble(value));
  191. } else if (j == 37) {//取水经度
  192. hystBaseParam.setCenterX(getFormateDouble(value));
  193. } else if (j == 38) {
  194. hystBaseParam.setCenterY(getFormateDouble(value));
  195. }
  196. }
  197. updateList.add(hystBaseParam);
  198. }
  199. }
  200. if(updateList.size()>0){
  201. for (AttHystBase attHystBase : updateList) {
  202. //获取水电站
  203. AttHystBaseParam attParam = new AttHystBaseParam();
  204. attParam.setHystName(attHystBase.getHystName());
  205. attParam.setStatisCode(attHystBase.getStatisCode());
  206. AttHystBase by = attHystBaseDao.getBy(attParam);
  207. AttHystBase newB = new AttHystBase();
  208. if(by != null){
  209. newB.setId(by.getId());
  210. newB.setHystLong(attHystBase.getHystLong());
  211. newB.setHystLat(attHystBase.getHystLat());
  212. // by.setCenterX(attHystBase.getCenterX());
  213. // by.setCenterY(attHystBase.getCenterY());
  214. String exmnType = getExmnType(attParam.getExmnType());
  215. if(by.getExmnType()==null || !by.getExmnType().equals(exmnType)){
  216. by.setExmnType(exmnType);
  217. }
  218. addList.add(newB);
  219. }
  220. }
  221. }
  222. if(addList.size()>0){
  223. for (AttHystBase base : addList) {
  224. attHystBaseDao.update(base);
  225. }
  226. }
  227. return null;
  228. }
  229. @Override
  230. public List<String> uploadComp(MultipartFile file, AttHystBaseParam attBaseBParam) {
  231. List<Row> rowList = ExportUtil.getRowListByFile(file);
  232. List<AttHystBase> result = new ArrayList<>();
  233. if (rowList.size() > 1) {
  234. Row titleRow = rowList.get(0);//第一行标题
  235. for (int i = 1; i < rowList.size(); i++) {
  236. Row row = rowList.get(i);
  237. AttHystBase base = new AttHystBase();
  238. for (int j = 0; j < titleRow.getPhysicalNumberOfCells(); j++) {
  239. Cell cell = row.getCell(j);
  240. if (cell == null) {
  241. continue;
  242. }
  243. String value = cell.toString();
  244. if (StringUtils.isBlank(value)) {
  245. continue;
  246. }
  247. if (j == 0) {
  248. base.setHystName(value);
  249. } else if (j == 1) {
  250. if (value.equals("-")) {
  251. } else {
  252. base.setStatisCode(value);
  253. }
  254. } else if (j == 2) {
  255. base.setCompDate(value);
  256. }
  257. }
  258. result.add(base);
  259. }
  260. if (result.size() > 0) {
  261. for (AttHystBase base : result) {
  262. attHystBaseDao.updateBase(base);
  263. }
  264. }
  265. }
  266. return null;
  267. }
  268. @Override
  269. public List<String> upload(MultipartFile file, AttHystBaseParam attBaseBParam) {
  270. List<Row> rowList = ExportUtil.getRowListByFile(file);
  271. List<AttHystBase> result = new ArrayList<>();
  272. if (rowList.size() > 1) {
  273. Row titleRow = rowList.get(0);//第一行标题
  274. for (int i = 1; i < rowList.size(); i++) {
  275. Row row = rowList.get(i);
  276. AttHystBase base = new AttHystBase();
  277. for (int j = 2; j < titleRow.getPhysicalNumberOfCells(); j++) {
  278. Cell cell = row.getCell(j);
  279. if (cell == null) {
  280. continue;
  281. }
  282. String value = cell.toString();
  283. if (StringUtils.isBlank(value)) {
  284. continue;
  285. }
  286. if (j == 2) {
  287. base.setHystName(value);
  288. } else if (j == 3) {//统计代码
  289. base.setStatisCode(value);
  290. } else if (j == 4) {
  291. base.setAdName(value);
  292. } else if (j == 5) {
  293. base.setHystSite(value);
  294. } else if (j == 6) {
  295. base.setLinkMan(value);
  296. } else if (j == 7) {
  297. base.setLinkTel(value);
  298. } else if (j == 8) {
  299. base.setHystLong(Double.valueOf(value));
  300. } else if (j == 9) {
  301. base.setHystLong(Double.valueOf(value) + base.getHystLong()/60);
  302. } else if (j == 10){
  303. base.setHystLong(Double.valueOf(value) + base.getHystLong()/60);
  304. } else if (j == 11) {
  305. base.setHystLat(Double.valueOf(value));
  306. } else if (j == 12){
  307. base.setHystLat(Double.valueOf(value) + base.getHystLat()/60);
  308. } else if (j == 13) {
  309. base.setHystLat(Double.valueOf(value) + base.getHystLat()/60);
  310. } else if (j == 14) {
  311. base.setCenterX(Double.valueOf(value));
  312. } else if (j == 15) {
  313. base.setCenterX(Double.valueOf(value) + base.getCenterX()/60);
  314. } else if (j == 16){
  315. base.setCenterX(Double.valueOf(value) + base.getCenterX()/60);
  316. } else if (j == 17) {
  317. base.setCenterY(Double.valueOf(value));
  318. } else if (j == 18) {
  319. base.setCenterY(Double.valueOf(value) + base.getCenterY()/60);
  320. } else if (j == 19){
  321. base.setCenterY(Double.valueOf(value) + base.getCenterY()/60);
  322. } else if (j == 20) {
  323. base.setRvName(value);
  324. } else if (j == 21) {
  325. base.setCompDate(Double.valueOf(value).longValue()+"");
  326. } else if (j == 22) {
  327. base.setOwnerType(getOwnerType(value));
  328. } else if (j == 23) {
  329. base.setExptType(getExptType(value));
  330. } else if (j == 24) {
  331. base.setInsCap(value);
  332. } else if (j == 25) {
  333. base.setDamHeig(value);
  334. } else if (j == 26) {
  335. base.setTotCap(value);
  336. } else if (j == 27) {
  337. base.setZlgyFlow(value);
  338. } else if (j == 28) {
  339. base.setHystIsReg(getShiFou(value));
  340. } else if (j == 29) {
  341. base.setRegNo(value);
  342. } else if (j == 30) {
  343. base.setIsSafety(getIsSafety(value));
  344. } else if (j == 31) {
  345. base.setExmnType(getExmnType(value));
  346. }
  347. }
  348. if (StringUtils.isBlank(base.getHystName())) {
  349. continue;
  350. }
  351. result.add(base);
  352. }
  353. }
  354. if (result.size() >0) {
  355. Map<String,String> map = new HashMap<>();
  356. for (AttHystBase base : result) {
  357. base.setId(UuidUtil.uuid());
  358. base.setIntm(new Date());
  359. base.setUptm(new Date());
  360. if (map.containsKey(base.getAdName())) {
  361. base.setAdCode(map.get(base.getAdName()));
  362. }
  363. //处理行政区划
  364. AttAdXBaseParam attAdXBaseParam = new AttAdXBaseParam();
  365. attAdXBaseParam.setAdName(base.getAdName());
  366. List<AttAdXBase> by = attAdXBaseDao.findList(attAdXBaseParam);
  367. if(by.size() > 0) {
  368. base.setAdCode(by.get(0).getAdCode());
  369. map.put(base.getAdName(),by.get(0).getAdCode());
  370. }
  371. attHystBaseDao.insert(base);
  372. }
  373. }
  374. return null;
  375. }
  376. private Double getFormateDouble(String s){
  377. if(s ==null || s.equals("0")){
  378. return 0.0;
  379. }else {
  380. // String format1 = String.format("%.8f", s);
  381. // return Double.valueOf(format1);
  382. // DecimalFormat df = new DecimalFormat("0.00000000");
  383. // String format = df.format(s);
  384. double d = Double.valueOf(s);
  385. return (double) Math.round(d * 100000000) / 100000000;
  386. }
  387. }
  388. private String getOwnerType(String s){
  389. //(1:民营;2:集体;3:国有;4:股份制;)
  390. if(s == null){ return s;}
  391. if(s.equals("民营")){
  392. return "1";
  393. }else if(s.equals("集体")){
  394. return "2";
  395. }else if(s.equals("国有")){
  396. return "3";
  397. }else if(s.equals("股份制")){
  398. return "4";
  399. }else if(s.equals("其他")){
  400. return "5";
  401. }else if(s.equals("-")){
  402. return "";
  403. }
  404. return "6";
  405. }
  406. private String getExptType(String s){
  407. //((1:引水式;2:混合式;3:坝后式;4:河床式;5:其他-工农业渠道上;6:其他-接上一级尾水)
  408. if(s == null){ return s;}
  409. if(s.equals("引水式")){
  410. return "1";
  411. }else if(s.equals("混合式")){
  412. return "2";
  413. }else if(s.equals("坝后式") || s.equals("坝式(坝后)")){
  414. return "3";
  415. }else if(s.equals("河床式") ||s.equals("坝式(河床)")){
  416. return "4";
  417. }else if(s.equals("其他-工农业渠道上")){
  418. return "5";
  419. }else if(s.equals("其他-接上一级尾水")){
  420. return "6";
  421. }else if(s.equals("-")){
  422. return "";
  423. }
  424. return "6";
  425. }
  426. private String getShiFou(String s){
  427. if(s == null){ return s;}
  428. //(1:是;2:否;)
  429. if(s.equals("是")){
  430. return "1";
  431. }else if(s.equals("否")){
  432. return "2";
  433. }else if(s.equals("-")){
  434. return "";
  435. }
  436. return s;
  437. }
  438. private String getIsSafety(String s){
  439. if(s == null){ return s;}
  440. //(1:是;2:否;)
  441. if(s.equals("是")|| s.equals("是,二类")
  442. || s.equals("是,一类")|| s.equals("是,三类")){
  443. return "1";
  444. }else if(s.equals("否")){
  445. return "2";
  446. }else if(s.equals("-")){
  447. return "";
  448. }
  449. return "3";
  450. }
  451. private String getExmnType(String s){
  452. //1:整改类;2:立即退出类;3:其他;4:保留类5.
  453. if(s ==null || s.equals("")){
  454. return "3";
  455. }
  456. if(s.equals("整改")){
  457. return "1";
  458. }else if(s.equals("立即退出")){
  459. return "2";
  460. }else if(s.equals("")){
  461. return "3";
  462. }else if(s.equals("保留")){
  463. return "4";
  464. }else if(s.equals("限期退出")){
  465. return "5";
  466. }else if(s.equals("-")){
  467. return "";
  468. }
  469. return "6";
  470. }
  471. }