85edf6b61b426f2c170f97858a763c8057a2056a.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. package org.jeecg.modules.demo.hzz.hhhj.gsp.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import io.swagger.annotations.Api;
  6. import io.swagger.annotations.ApiOperation;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.jeecg.common.api.vo.Result;
  9. import org.jeecg.common.aspect.annotation.AutoLog;
  10. import org.jeecg.common.system.base.controller.JeecgController;
  11. import org.jeecg.common.system.query.QueryGenerator;
  12. import org.jeecg.modules.demo.hzz.hhhj.gsp.entity.RmBulletinBoard;
  13. import org.jeecg.modules.demo.hzz.hhhj.gsp.geo.service.IRmGgpgeoService;
  14. import org.jeecg.modules.demo.hzz.hhhj.gsp.service.IRmBulletinBoardService;
  15. import org.jeecg.modules.demo.hzz.shjsgc.bzgc.entity.RmBzgc;
  16. import org.jeecgframework.poi.excel.ExcelImportUtil;
  17. import org.jeecgframework.poi.excel.entity.ImportParams;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.*;
  20. import org.springframework.web.multipart.MultipartFile;
  21. import org.springframework.web.multipart.MultipartHttpServletRequest;
  22. import org.springframework.web.servlet.ModelAndView;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import java.io.IOException;
  26. import java.text.DateFormat;
  27. import java.util.Arrays;
  28. import java.util.List;
  29. import java.util.Map;
  30. import java.util.UUID;
  31. /**
  32. * @Description: 公告牌信息表
  33. * @Author: jeecg-boot
  34. * @Date: 2021-09-29
  35. * @Version: V1.0
  36. */
  37. @Api(tags = "公告牌信息表")
  38. @RestController
  39. @RequestMapping("/hzz.hhhj.gsp/rmBulletinBoard")
  40. @Slf4j
  41. public class RmBulletinBoardController extends JeecgController<RmBulletinBoard, IRmBulletinBoardService> {
  42. @Autowired
  43. private IRmBulletinBoardService rmBulletinBoardService;
  44. @Autowired
  45. private IRmGgpgeoService rmGgpgeoService;
  46. /**
  47. * 分页列表查询
  48. *
  49. * @param rmBulletinBoard
  50. * @param pageNo
  51. * @param pageSize
  52. * @param req
  53. * @return
  54. */
  55. @AutoLog(value = "公告牌信息表-分页列表查询")
  56. @ApiOperation(value = "公告牌信息表-分页列表查询", notes = "公告牌信息表-分页列表查询")
  57. @GetMapping(value = "/list")
  58. public Result<?> queryPageList(RmBulletinBoard rmBulletinBoard,
  59. @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
  60. @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
  61. HttpServletRequest req) {
  62. QueryWrapper<RmBulletinBoard> queryWrapper = QueryGenerator.initQueryWrapper(rmBulletinBoard, req.getParameterMap());
  63. Page<RmBulletinBoard> page = new Page<RmBulletinBoard>(pageNo, pageSize);
  64. IPage<RmBulletinBoard> pageList = rmBulletinBoardService.page(page, queryWrapper);
  65. return Result.OK(pageList);
  66. }
  67. /**
  68. * 添加
  69. *
  70. * @param rmBulletinBoard
  71. * @return
  72. */
  73. @AutoLog(value = "公告牌信息表-添加")
  74. @ApiOperation(value = "公告牌信息表-添加", notes = "公告牌信息表-添加")
  75. @PostMapping(value = "/add")
  76. public Result<?> add(@RequestBody RmBulletinBoard rmBulletinBoard) {
  77. rmBulletinBoardService.save(rmBulletinBoard);
  78. generateGeom(rmBulletinBoard);
  79. String geoinfo = rmGgpgeoService.getGeojson(rmBulletinBoard.getId());
  80. rmBulletinBoard.setGeoinfo(geoinfo);
  81. rmBulletinBoard.setFlag(1);
  82. rmBulletinBoardService.saveOrUpdate(rmBulletinBoard);
  83. return Result.OK("添加成功!");
  84. }
  85. /**
  86. * 创建空间图形
  87. */
  88. private void generateGeom(RmBulletinBoard rmBulletinBoard){
  89. Double hzb = rmBulletinBoard.getHzb();
  90. Double zzb = rmBulletinBoard.getZzb();
  91. String id = rmBulletinBoard.getId();
  92. String gspbm = rmBulletinBoard.getGspbm();
  93. if(hzb>39000000 || zzb>39000000){
  94. if(hzb>zzb){
  95. rmGgpgeoService.addGsp2("POINT("+hzb+" "+zzb+")",id,gspbm);
  96. }else{
  97. rmGgpgeoService.addGsp2("POINT("+zzb+" "+hzb+")",id,gspbm);
  98. }
  99. }else if(hzb>180 || zzb>180){
  100. if(hzb<zzb){
  101. rmGgpgeoService.addGsp("POINT("+hzb+" "+zzb+")",id,gspbm);
  102. }else{
  103. rmGgpgeoService.addGsp("POINT("+zzb+" "+hzb+")",id,gspbm);
  104. }
  105. }else{
  106. if(hzb>zzb){
  107. rmGgpgeoService.addGsp3("POINT("+hzb+" "+zzb+")",id,gspbm);
  108. }else{
  109. rmGgpgeoService.addGsp3("POINT("+zzb+" "+hzb+")",id,gspbm);
  110. }
  111. }
  112. }
  113. /**
  114. * 编辑
  115. *
  116. * @param rmBulletinBoard
  117. * @return
  118. */
  119. @AutoLog(value = "公告牌信息表-编辑")
  120. @ApiOperation(value = "公告牌信息表-编辑", notes = "公告牌信息表-编辑")
  121. @PostMapping(value = "/edit")
  122. public Result<?> edit(@RequestBody RmBulletinBoard rmBulletinBoard) {
  123. //1、更新属性
  124. rmBulletinBoardService.updateById(rmBulletinBoard);
  125. //2、更新geom
  126. updateGeom(rmBulletinBoard);
  127. //3、更新geoinfo
  128. String geoinfo = rmGgpgeoService.getGeojson(rmBulletinBoard.getId());
  129. rmBulletinBoard.setGeoinfo(geoinfo);
  130. rmBulletinBoardService.saveOrUpdate(rmBulletinBoard);
  131. return Result.OK("编辑成功!");
  132. }
  133. /**
  134. * 更新空间图形
  135. */
  136. private void updateGeom(RmBulletinBoard rmBulletinBoard){
  137. Double hzb = rmBulletinBoard.getHzb();
  138. Double zzb = rmBulletinBoard.getZzb();
  139. String id = rmBulletinBoard.getId();
  140. String gspbm = rmBulletinBoard.getGspbm();
  141. if(hzb>39000000 || zzb>39000000){
  142. if(hzb>zzb){
  143. rmGgpgeoService.updGsp2("POINT("+hzb+" "+zzb+")",id,gspbm);
  144. }else{
  145. rmGgpgeoService.updGsp2("POINT("+zzb+" "+hzb+")",id,gspbm);
  146. }
  147. }else if(hzb>180 || zzb>180){
  148. if(hzb<zzb){
  149. rmGgpgeoService.updGsp("POINT("+hzb+" "+zzb+")",id,gspbm);
  150. }else{
  151. rmGgpgeoService.updGsp("POINT("+zzb+" "+hzb+")",id,gspbm);
  152. }
  153. }else{
  154. if(hzb>zzb){
  155. rmGgpgeoService.updGsp3("POINT("+hzb+" "+zzb+")",id,gspbm);
  156. }else{
  157. rmGgpgeoService.updGsp3("POINT("+zzb+" "+hzb+")",id,gspbm);
  158. }
  159. }
  160. }
  161. /**
  162. * 通过id删除
  163. *
  164. * @param id
  165. * @return
  166. */
  167. @AutoLog(value = "公告牌信息表-通过id删除")
  168. @ApiOperation(value = "公告牌信息表-通过id删除", notes = "公告牌信息表-通过id删除")
  169. @PostMapping(value = "/delete")
  170. // @RequiresPermissions("rmBulletinBoard:delete")
  171. public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
  172. rmBulletinBoardService.removeById(id);
  173. rmGgpgeoService.delGsp(id);
  174. return Result.OK("删除成功!");
  175. }
  176. /**
  177. * 批量删除
  178. *
  179. * @param ids
  180. * @return
  181. */
  182. @AutoLog(value = "公告牌信息表-批量删除")
  183. @ApiOperation(value = "公告牌信息表-批量删除", notes = "公告牌信息表-批量删除")
  184. @PostMapping(value = "/deleteBatch")
  185. public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
  186. this.rmBulletinBoardService.removeByIds(Arrays.asList(ids.split(",")));
  187. List<String> gspIds = Arrays.asList(ids.split(","));
  188. for(int i=0;i<gspIds.size();i++){
  189. rmGgpgeoService.delGsp(gspIds.get(i));
  190. }
  191. return Result.OK("批量删除成功!");
  192. }
  193. /**
  194. * 通过id查询
  195. *
  196. * @param id
  197. * @return
  198. */
  199. @AutoLog(value = "公告牌信息表-通过id查询")
  200. @ApiOperation(value = "公告牌信息表-通过id查询", notes = "公告牌信息表-通过id查询")
  201. @GetMapping(value = "/queryById")
  202. public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
  203. RmBulletinBoard rmBulletinBoard = rmBulletinBoardService.getById(id);
  204. if (rmBulletinBoard == null) {
  205. return Result.error("未找到对应数据");
  206. }
  207. return Result.OK(rmBulletinBoard);
  208. }
  209. /**
  210. * 通过关联id查询
  211. *
  212. * @param relId
  213. * @return
  214. */
  215. @AutoLog(value = "公告牌信息表-通过关联id查询")
  216. @ApiOperation(value = "公告牌信息表-通过关联id查询", notes = "公告牌信息表-通过关联id查询")
  217. @GetMapping(value = "/queryByRelId")
  218. public Result<?> queryByRelId(@RequestParam(name = "relId", required = true) String relId) {
  219. QueryWrapper<RmBulletinBoard> queryWrapper = new QueryWrapper<>();
  220. queryWrapper.eq("gspbm",relId);
  221. RmBulletinBoard rmBulletinBoard = rmBulletinBoardService.getOne(queryWrapper);
  222. if (rmBulletinBoard == null) {
  223. return Result.error("未找到对应数据");
  224. }
  225. return Result.OK(rmBulletinBoard);
  226. }
  227. /**
  228. * 生成所有的flag为0的图形,然后地图生成标志flag设置为1
  229. * <p>
  230. * * @return
  231. */
  232. @AutoLog(value = "生成公告牌的图形")
  233. @ApiOperation(value = "生成公告牌的图形", notes = "生成公告牌的图形")
  234. @GetMapping(value = "/genarateGeo")
  235. public Result<?> genarateGeo() {
  236. rmBulletinBoardService.GenarateGspGeo();
  237. return Result.OK("生成图形成功!");
  238. }
  239. /**
  240. * 导出excel
  241. *
  242. * @param request
  243. * @param rmBulletinBoard
  244. */
  245. @RequestMapping(value = "/exportXls")
  246. public ModelAndView exportXls(HttpServletRequest request, RmBulletinBoard rmBulletinBoard) {
  247. return super.exportXls(request, rmBulletinBoard, RmBulletinBoard.class, "公告牌信息表");
  248. }
  249. /**
  250. * 通过excel导入数据
  251. *
  252. * @param request
  253. * @param response
  254. * @return
  255. */
  256. @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  257. public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
  258. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  259. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  260. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  261. MultipartFile file = entity.getValue();// 获取上传文件对象
  262. ImportParams params = new ImportParams();
  263. params.setTitleRows(2);
  264. params.setHeadRows(1);
  265. params.setNeedSave(true);
  266. try {
  267. List<RmBulletinBoard> list = ExcelImportUtil.importExcel(file.getInputStream(), RmBulletinBoard.class, params);
  268. long start = System.currentTimeMillis();
  269. rmBulletinBoardService.saveBatch(list);
  270. for (RmBulletinBoard page : list) {
  271. // rmBulletinBoardService.save(page);
  272. if(page.getHzb()!=null &&page.getZzb()!=null){
  273. generateGeom(page);
  274. String geoinfo = rmGgpgeoService.getGeojson(page.getId());
  275. page.setGeoinfo(geoinfo);
  276. page.setFlag(1);
  277. }
  278. rmBulletinBoardService.saveOrUpdate(page);
  279. }
  280. return Result.ok("文件导入成功!数据行数:" + list.size());
  281. } catch (Exception e) {
  282. log.error(e.getMessage(),e);
  283. return Result.error("文件导入失败:"+e.getMessage());
  284. } finally {
  285. try {
  286. file.getInputStream().close();
  287. } catch (IOException e) {
  288. e.printStackTrace();
  289. }
  290. }
  291. }
  292. return Result.error("文件导入失败!");
  293. }
  294. }