c84d24939eef5f90b3e87ed131559c7a14d97305.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. package org.jeecg.modules.demo.hzz.shjsgc.dfgc.controller;
  2. import java.io.File;
  3. import java.text.DateFormat;
  4. import java.util.*;
  5. import java.util.stream.Collectors;
  6. import java.io.IOException;
  7. import java.io.UnsupportedEncodingException;
  8. import java.net.URLDecoder;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import com.alibaba.fastjson.JSONObject;
  12. import io.netty.util.internal.StringUtil;
  13. import org.geotools.data.DataStore;
  14. import org.jeecg.common.api.vo.Result;
  15. import org.jeecg.common.system.query.QueryGenerator;
  16. import org.jeecg.common.util.oConvertUtils;
  17. import org.jeecg.modules.demo.hzz.shjsgc.dfgc.entity.RmDfgc;
  18. import org.jeecg.modules.demo.hzz.shjsgc.dfgc.geo.service.IRmDfgcgeoService;
  19. import org.jeecg.modules.demo.hzz.shjsgc.dfgc.service.IRmDfgcService;
  20. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  21. import com.baomidou.mybatisplus.core.metadata.IPage;
  22. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  23. import lombok.extern.slf4j.Slf4j;
  24. import org.jeecg.modules.demo.onemap.utils.Geotools;
  25. import org.jeecg.modules.demo.onemap.utils.PGDatastore;
  26. import org.jeecg.modules.demo.onemap.utils.Utility;
  27. import org.jeecg.modules.demo.onemap.utils.ZipAndRarTools;
  28. import org.jeecgframework.poi.excel.ExcelImportUtil;
  29. import org.jeecgframework.poi.excel.def.NormalExcelConstants;
  30. import org.jeecgframework.poi.excel.entity.ExportParams;
  31. import org.jeecgframework.poi.excel.entity.ImportParams;
  32. import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
  33. import org.jeecg.common.system.base.controller.JeecgController;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.beans.factory.annotation.Value;
  36. import org.springframework.web.bind.annotation.*;
  37. import org.springframework.web.multipart.MultipartFile;
  38. import org.springframework.web.multipart.MultipartHttpServletRequest;
  39. import org.springframework.web.servlet.ModelAndView;
  40. import com.alibaba.fastjson.JSON;
  41. import io.swagger.annotations.Api;
  42. import io.swagger.annotations.ApiOperation;
  43. import org.jeecg.common.aspect.annotation.AutoLog;
  44. /**
  45. * @Description: 堤防工程
  46. * @Author: jeecg-boot
  47. * @Date: 2021-11-04
  48. * @Version: V1.0
  49. */
  50. @Api(tags = "堤防工程")
  51. @RestController
  52. @RequestMapping("/hzz.shjsgc.dfgc/rmDfgc")
  53. @Slf4j
  54. public class RmDfgcController extends JeecgController<RmDfgc, IRmDfgcService> {
  55. @Autowired
  56. private IRmDfgcService rmDfgcService;
  57. @Autowired
  58. private IRmDfgcgeoService rmDfgcgeoService;
  59. private Utility utility = new Utility();
  60. @Value(value = "${jeecg.path.upload}")
  61. private String uploadpath;
  62. /**
  63. * 分页列表查询
  64. *
  65. * @param rmDfgc
  66. * @param pageNo
  67. * @param pageSize
  68. * @param req
  69. * @return
  70. */
  71. @AutoLog(value = "堤防工程-分页列表查询")
  72. @ApiOperation(value = "堤防工程-分页列表查询", notes = "堤防工程-分页列表查询")
  73. @GetMapping(value = "/list")
  74. public Result<?> queryPageList(RmDfgc rmDfgc,
  75. @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
  76. @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
  77. HttpServletRequest req) {
  78. QueryWrapper<RmDfgc> queryWrapper = QueryGenerator.initQueryWrapper(rmDfgc, req.getParameterMap());
  79. Page<RmDfgc> page = new Page<RmDfgc>(pageNo, pageSize);
  80. IPage<RmDfgc> pageList = rmDfgcService.page(page, queryWrapper);
  81. return Result.OK(pageList);
  82. }
  83. /**
  84. * 添加
  85. *
  86. * @param rmDfgc
  87. * @return
  88. */
  89. @AutoLog(value = "堤防工程-添加")
  90. @ApiOperation(value = "堤防工程-添加", notes = "堤防工程-添加")
  91. @PostMapping(value = "/add")
  92. public Result<?> add(@RequestBody RmDfgc rmDfgc) {
  93. rmDfgcService.save(rmDfgc);
  94. /**数据添加至涉河项目表中*/
  95. String id = UUID.randomUUID().toString().replace("-", "");
  96. String dfmc = rmDfgc.getDfmc();
  97. String gcjsqk = rmDfgc.getGcjsqk();
  98. String xmid = rmDfgc.getId();
  99. String dfgcgldwmc = rmDfgc.getDfgcgldwmc();
  100. String szhlmc = rmDfgc.getSzhlmc();
  101. String kgny = null;
  102. String jcny = null;
  103. if (rmDfgc.getKgny() != null && rmDfgc.getJcny() != null) {
  104. kgny = DateFormat.getDateInstance().format(rmDfgc.getKgny());
  105. jcny = DateFormat.getDateInstance().format(rmDfgc.getJcny());
  106. }
  107. /**数据矢量信息处理*/
  108. String msg = "矢量数据解析成功!";
  109. if (!StringUtil.isNullOrEmpty(rmDfgc.getGeopath())) {
  110. msg = handleGeometry(id, rmDfgc.getGeopath());
  111. rmDfgc.setFlag(1);
  112. }
  113. String geom = rmDfgcgeoService.getGeojson(id);
  114. rmDfgc.setGeoinfo(geom);
  115. rmDfgcService.saveOrUpdate(rmDfgc);
  116. rmDfgcService.insertshxm(id, dfmc, gcjsqk, xmid, "dfgc", dfgcgldwmc, kgny, jcny, szhlmc, geom);
  117. return Result.OK("添加成功!" + msg);
  118. }
  119. /**
  120. * 矢量数据处理
  121. */
  122. private String handleGeometry(String id, String geoPath) {
  123. //解压上传的zip包
  124. String warnMsg = "矢量数据解析成功!";
  125. if (StringUtil.isNullOrEmpty(id) || StringUtil.isNullOrEmpty(geoPath)) {
  126. warnMsg = "参数不全,无法处理!";
  127. return warnMsg;
  128. }
  129. String upFilePath = uploadpath + "/" + geoPath;
  130. String upFileName = upFilePath.substring(upFilePath.lastIndexOf("/") + 1);
  131. String fileNameNoExt = upFileName.substring(0, upFileName.lastIndexOf('.'));
  132. String unZipPath = uploadpath + "/shpPath/" + fileNameNoExt;
  133. try {
  134. if (geoPath.endsWith(".zip")) {
  135. ZipAndRarTools.unZip(upFilePath, unZipPath);
  136. } else if (geoPath.endsWith(".rar")) {
  137. ZipAndRarTools.unrar(upFilePath, unZipPath);
  138. } else {
  139. return "矢量数据格式不正确!";
  140. }
  141. //获取解压后的shp文件及坐标系文件的路径
  142. String shpfilepath = "";
  143. String prjFilePath = "";
  144. File file = new File(unZipPath);
  145. File[] files = file.listFiles();
  146. for (int i = 0; i < files.length; i++) {
  147. File shpFile = files[i];
  148. String fileName = shpFile.getName();
  149. if (fileName.endsWith(".shp")) {
  150. shpfilepath = unZipPath + "/" + fileName;
  151. continue;
  152. }
  153. if (fileName.endsWith(".prj")) {
  154. prjFilePath = unZipPath + "/" + fileName;
  155. continue;
  156. }
  157. }
  158. //创建数据库连接
  159. PGDatastore pgDatastore = new PGDatastore();
  160. DataStore datastore = pgDatastore.getDefeaultDatastore();
  161. Geotools geotools = new Geotools(datastore);
  162. //根据坐标系文件,判断上传的矢量是否需要转换坐标
  163. int prjType = 4490;
  164. if (StringUtil.isNullOrEmpty(prjFilePath)) {
  165. warnMsg = "上传的SHP文件没有坐标信息(*.prj),默认按照2000大地坐标处理!";
  166. } else {
  167. String prjWkt = geotools.getShpPrjWkt(prjFilePath);
  168. if (!prjWkt.contains("CGCS2000")) {
  169. warnMsg = "上传的SHP文件坐标系不是2000国家大地坐标系,无法处理!";
  170. return warnMsg;
  171. }
  172. if (prjWkt.startsWith("PROJCS")) {
  173. if (prjWkt.contains("Zone_39")) {
  174. prjType = 4527;
  175. } else if (prjWkt.contains("CM_117E")) {
  176. prjType = 4548;
  177. } else {
  178. prjType = 4490;
  179. }
  180. }
  181. }
  182. //将shp文件解析为wkt,然后根据坐标系情况,转为4490,然后更新geom
  183. String shpWkt = geotools.shp2wkt(shpfilepath);
  184. if (!StringUtil.isNullOrEmpty(shpWkt)) {
  185. if (shpWkt.startsWith("LineString")) {
  186. shpWkt = shpWkt.replace("LineString", "MULTILINESTRING");
  187. shpWkt = shpWkt.replace("(", "((");
  188. shpWkt = shpWkt.replace(")", "))");
  189. }
  190. switch (prjType) {
  191. case 4490: {
  192. rmDfgcgeoService.updDfgc3(shpWkt, id);
  193. break;
  194. }
  195. case 4527: {
  196. rmDfgcgeoService.updDfgc2(shpWkt, id);
  197. break;
  198. }
  199. case 4548: {
  200. rmDfgcgeoService.updDfgc(shpWkt, id);
  201. break;
  202. }
  203. default:
  204. break;
  205. }
  206. } else {
  207. warnMsg = "矢量数据解析异常:上传的SHP文件没有解析到空间图形信息!";
  208. return warnMsg;
  209. }
  210. } catch (IOException e) {
  211. e.printStackTrace();
  212. warnMsg = e.getMessage();
  213. return "矢量数据解析异常:" + warnMsg;
  214. } catch (Exception e) {
  215. e.printStackTrace();
  216. warnMsg = e.getMessage();
  217. return "矢量数据解析异常:" + warnMsg;
  218. }
  219. return warnMsg;
  220. }
  221. /**
  222. * 编辑
  223. *
  224. * @param rmDfgc
  225. * @return
  226. */
  227. @AutoLog(value = "堤防工程-编辑")
  228. @ApiOperation(value = "堤防工程-编辑", notes = "堤防工程-编辑")
  229. @PostMapping(value = "/edit")
  230. public Result<?> edit(@RequestBody RmDfgc rmDfgc) {
  231. String dfmc = rmDfgc.getDfmc();
  232. String gcjsqk = rmDfgc.getGcjsqk();
  233. String dfgcgldwmc = rmDfgc.getDfgcgldwmc();
  234. String id = rmDfgc.getId();
  235. String szhlmc = rmDfgc.getSzhlmc();
  236. String geoinfo = rmDfgc.getGeoinfo();
  237. String kgny = null;
  238. String jcny = null;
  239. if (rmDfgc.getKgny() != null && rmDfgc.getJcny() != null) {
  240. kgny = DateFormat.getDateInstance().format(rmDfgc.getKgny());
  241. jcny = DateFormat.getDateInstance().format(rmDfgc.getJcny());
  242. }
  243. RmDfgc oldDfgc = rmDfgcService.getById(id);
  244. String oldGeoPath = oldDfgc.getGeopath();
  245. String newGeoPath = rmDfgc.getGeopath();
  246. if (oldGeoPath != newGeoPath) {
  247. //1、删除原来上传的shp文件
  248. if (!StringUtil.isNullOrEmpty(oldGeoPath)) {
  249. delShpPath(oldGeoPath);
  250. } else {
  251. rmDfgc.setGeoinfo("");
  252. }
  253. //2、更新geom和geoinfo
  254. if (StringUtil.isNullOrEmpty(newGeoPath)) {
  255. rmDfgc.setGeoinfo("");
  256. }
  257. rmDfgcService.updateById(rmDfgc);
  258. handleGeometry(id, newGeoPath);
  259. geoinfo = rmDfgcgeoService.getGeojson(id);
  260. rmDfgc.setGeoinfo(geoinfo);
  261. rmDfgcService.saveOrUpdate(rmDfgc);
  262. } else {
  263. rmDfgcService.updateById(rmDfgc);
  264. }
  265. rmDfgcService.updateshxm(dfmc, gcjsqk, dfgcgldwmc, kgny, jcny, szhlmc, geoinfo, id);
  266. return Result.OK("编辑成功!");
  267. }
  268. /**
  269. * 根据shp上传的文件名,删除压缩文件、解压后的文件夹及文件
  270. */
  271. private void delShpPath(String shpPath) {
  272. String upFilePath = uploadpath + "/" + shpPath;
  273. if (StringUtil.isNullOrEmpty(upFilePath)) {
  274. File zipFile = new File(upFilePath);
  275. zipFile.delete();
  276. }
  277. String upFileName = upFilePath.substring(upFilePath.lastIndexOf("/") + 1);
  278. String fileNameNoExt = upFileName.substring(0, upFileName.lastIndexOf('.'));
  279. String unZipPath = uploadpath + "/shpPath/" + fileNameNoExt;
  280. File oldGeoFolder = new File(unZipPath);
  281. Utility.deleteDir(oldGeoFolder);
  282. }
  283. /**
  284. * 通过id删除
  285. *
  286. * @param id
  287. * @return
  288. */
  289. @AutoLog(value = "堤防工程-通过id删除")
  290. @ApiOperation(value = "堤防工程-通过id删除", notes = "堤防工程-通过id删除")
  291. @PostMapping(value = "/delete")
  292. public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
  293. // rmDfgcgeoService.delDfgc(rmDfgcService.getById(id).getId());
  294. rmDfgcService.deshxm(id);
  295. RmDfgc rmDfgc = rmDfgcService.getById(id);
  296. if (rmDfgc == null) {
  297. return Result.error("未找到对应数据,删除失败!");
  298. }
  299. String geoPath = rmDfgc.getGeopath();
  300. if (!StringUtil.isNullOrEmpty(geoPath)) {
  301. delShpPath(geoPath);
  302. }
  303. rmDfgcService.removeById(id);
  304. rmDfgcService.delete(id);
  305. return Result.OK("删除成功!");
  306. }
  307. /**
  308. * 批量删除
  309. *
  310. * @param ids
  311. * @return
  312. */
  313. @AutoLog(value = "堤防工程-批量删除")
  314. @ApiOperation(value = "堤防工程-批量删除", notes = "堤防工程-批量删除")
  315. @PostMapping(value = "/deleteBatch")
  316. public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
  317. // this.rmDfgcService.removeByIds(Arrays.asList(ids.split(",")));
  318. List<String> dfidList = Arrays.asList(ids.split(","));
  319. for (int i = 0; i < dfidList.size(); i++) {
  320. delete(dfidList.get(i));
  321. }
  322. return Result.OK("批量删除成功!");
  323. }
  324. /**
  325. * 通过id查询
  326. *
  327. * @param id
  328. * @return
  329. */
  330. @AutoLog(value = "堤防工程-通过id查询")
  331. @ApiOperation(value = "堤防工程-通过id查询", notes = "堤防工程-通过id查询")
  332. @GetMapping(value = "/queryById")
  333. public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
  334. RmDfgc rmDfgc = rmDfgcService.getById(id);
  335. if (rmDfgc == null) {
  336. return Result.error("未找到对应数据");
  337. }
  338. return Result.OK(rmDfgc);
  339. }
  340. @GetMapping(value = "/queryByIdInMap")
  341. public Result<?> queryByIdInMap(RmDfgc rmDfgc,
  342. @RequestParam(name = "id",required = true) String id,
  343. HttpServletRequest req){
  344. QueryWrapper<RmDfgc> queryWrapper = QueryGenerator.initQueryWrapper(rmDfgc, req.getParameterMap());
  345. queryWrapper.eq("id",id);
  346. return Result.OK(rmDfgcService.getOne(queryWrapper));
  347. }
  348. /**
  349. * 通过id查询Geometry
  350. *
  351. * @param id
  352. * @return
  353. */
  354. @AutoLog(value = "堤防工程-通过id查询Geometry")
  355. @ApiOperation(value = "堤防工程-通过id查询Geometry", notes = "堤防工程-通过id查询Geometry")
  356. @GetMapping(value = "/getGeojsonById")
  357. public Result<?> getGeojsonById(@RequestParam(name = "id", required = true) String id) {
  358. String geom = rmDfgcgeoService.getGeojson(id);
  359. JSONObject geoJson = JSONObject.parseObject(geom);
  360. return Result.OK(geoJson);
  361. }
  362. /**
  363. * 生成所有的flag为0的图形,然后地图生成标志flag设置为1
  364. * <p>
  365. * * @return
  366. */
  367. @AutoLog(value = "")
  368. @ApiOperation(value = "生成堤防工程的图形", notes = "生成堤防工程的图形")
  369. @GetMapping(value = "/genarateGeo")
  370. public Result<?> genarateGeo() {
  371. rmDfgcService.GenarateDfgcGeo();
  372. return Result.OK("生成图形成功!");
  373. }
  374. /**
  375. * 导出excel
  376. *
  377. * @param request
  378. * @param rmDfgc
  379. */
  380. @RequestMapping(value = "/exportXls")
  381. public ModelAndView exportXls(HttpServletRequest request, RmDfgc rmDfgc) {
  382. return super.exportXls(request, rmDfgc, RmDfgc.class, "堤防工程");
  383. }
  384. /**
  385. * 通过excel导入数据
  386. *
  387. * @param request
  388. * @param response
  389. * @return
  390. */
  391. @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  392. public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
  393. return super.importExcel(request, response, RmDfgc.class);
  394. }
  395. /**
  396. * 通过id查询
  397. *
  398. * @return
  399. */
  400. @AutoLog(value = "堤防工程-查询提防长度")
  401. @ApiOperation(value = "堤防工程-查询提防长度", notes = "堤防工程-查询提防长度")
  402. @GetMapping(value = "/selectdfcd")
  403. public Result<?> selectdfcd() {
  404. List<HashMap<String, String>> selectdfcd = rmDfgcService.selectdfcd();
  405. if (selectdfcd == null) {
  406. return Result.error("未找到对应数据");
  407. }
  408. return Result.OK(selectdfcd);
  409. }
  410. }