123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- package org.jeecg.modules.demo.hzz.hhhj.gsp.controller;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.jeecg.common.api.vo.Result;
- import org.jeecg.common.aspect.annotation.AutoLog;
- import org.jeecg.common.system.base.controller.JeecgController;
- import org.jeecg.common.system.query.QueryGenerator;
- import org.jeecg.modules.demo.hzz.hhhj.gsp.entity.RmBulletinBoard;
- import org.jeecg.modules.demo.hzz.hhhj.gsp.geo.service.IRmGgpgeoService;
- import org.jeecg.modules.demo.hzz.hhhj.gsp.service.IRmBulletinBoardService;
- import org.jeecg.modules.demo.hzz.shjsgc.bzgc.entity.RmBzgc;
- import org.jeecgframework.poi.excel.ExcelImportUtil;
- import org.jeecgframework.poi.excel.entity.ImportParams;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.multipart.MultipartHttpServletRequest;
- import org.springframework.web.servlet.ModelAndView;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.text.DateFormat;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- /**
- * @Description: 公告牌信息表
- * @Author: jeecg-boot
- * @Date: 2021-09-29
- * @Version: V1.0
- */
- @Api(tags = "公告牌信息表")
- @RestController
- @RequestMapping("/hzz.hhhj.gsp/rmBulletinBoard")
- @Slf4j
- public class RmBulletinBoardController extends JeecgController<RmBulletinBoard, IRmBulletinBoardService> {
- @Autowired
- private IRmBulletinBoardService rmBulletinBoardService;
- @Autowired
- private IRmGgpgeoService rmGgpgeoService;
- /**
- * 分页列表查询
- *
- * @param rmBulletinBoard
- * @param pageNo
- * @param pageSize
- * @param req
- * @return
- */
- @AutoLog(value = "公告牌信息表-分页列表查询")
- @ApiOperation(value = "公告牌信息表-分页列表查询", notes = "公告牌信息表-分页列表查询")
- @GetMapping(value = "/list")
- public Result<?> queryPageList(RmBulletinBoard rmBulletinBoard,
- @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
- @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
- HttpServletRequest req) {
- QueryWrapper<RmBulletinBoard> queryWrapper = QueryGenerator.initQueryWrapper(rmBulletinBoard, req.getParameterMap());
- Page<RmBulletinBoard> page = new Page<RmBulletinBoard>(pageNo, pageSize);
- IPage<RmBulletinBoard> pageList = rmBulletinBoardService.page(page, queryWrapper);
- return Result.OK(pageList);
- }
- /**
- * 添加
- *
- * @param rmBulletinBoard
- * @return
- */
- @AutoLog(value = "公告牌信息表-添加")
- @ApiOperation(value = "公告牌信息表-添加", notes = "公告牌信息表-添加")
- @PostMapping(value = "/add")
- public Result<?> add(@RequestBody RmBulletinBoard rmBulletinBoard) {
- rmBulletinBoardService.save(rmBulletinBoard);
- generateGeom(rmBulletinBoard);
- String geoinfo = rmGgpgeoService.getGeojson(rmBulletinBoard.getId());
- rmBulletinBoard.setGeoinfo(geoinfo);
- rmBulletinBoard.setFlag(1);
- rmBulletinBoardService.saveOrUpdate(rmBulletinBoard);
- return Result.OK("添加成功!");
- }
- /**
- * 创建空间图形
- */
- private void generateGeom(RmBulletinBoard rmBulletinBoard){
- Double hzb = rmBulletinBoard.getHzb();
- Double zzb = rmBulletinBoard.getZzb();
- String id = rmBulletinBoard.getId();
- String gspbm = rmBulletinBoard.getGspbm();
- if(hzb>39000000 || zzb>39000000){
- if(hzb>zzb){
- rmGgpgeoService.addGsp2("POINT("+hzb+" "+zzb+")",id,gspbm);
- }else{
- rmGgpgeoService.addGsp2("POINT("+zzb+" "+hzb+")",id,gspbm);
- }
- }else if(hzb>180 || zzb>180){
- if(hzb<zzb){
- rmGgpgeoService.addGsp("POINT("+hzb+" "+zzb+")",id,gspbm);
- }else{
- rmGgpgeoService.addGsp("POINT("+zzb+" "+hzb+")",id,gspbm);
- }
- }else{
- if(hzb>zzb){
- rmGgpgeoService.addGsp3("POINT("+hzb+" "+zzb+")",id,gspbm);
- }else{
- rmGgpgeoService.addGsp3("POINT("+zzb+" "+hzb+")",id,gspbm);
- }
- }
- }
- /**
- * 编辑
- *
- * @param rmBulletinBoard
- * @return
- */
- @AutoLog(value = "公告牌信息表-编辑")
- @ApiOperation(value = "公告牌信息表-编辑", notes = "公告牌信息表-编辑")
- @PostMapping(value = "/edit")
- public Result<?> edit(@RequestBody RmBulletinBoard rmBulletinBoard) {
- //1、更新属性
- rmBulletinBoardService.updateById(rmBulletinBoard);
- //2、更新geom
- updateGeom(rmBulletinBoard);
- //3、更新geoinfo
- String geoinfo = rmGgpgeoService.getGeojson(rmBulletinBoard.getId());
- rmBulletinBoard.setGeoinfo(geoinfo);
- rmBulletinBoardService.saveOrUpdate(rmBulletinBoard);
- return Result.OK("编辑成功!");
- }
- /**
- * 更新空间图形
- */
- private void updateGeom(RmBulletinBoard rmBulletinBoard){
- Double hzb = rmBulletinBoard.getHzb();
- Double zzb = rmBulletinBoard.getZzb();
- String id = rmBulletinBoard.getId();
- String gspbm = rmBulletinBoard.getGspbm();
- if(hzb>39000000 || zzb>39000000){
- if(hzb>zzb){
- rmGgpgeoService.updGsp2("POINT("+hzb+" "+zzb+")",id,gspbm);
- }else{
- rmGgpgeoService.updGsp2("POINT("+zzb+" "+hzb+")",id,gspbm);
- }
- }else if(hzb>180 || zzb>180){
- if(hzb<zzb){
- rmGgpgeoService.updGsp("POINT("+hzb+" "+zzb+")",id,gspbm);
- }else{
- rmGgpgeoService.updGsp("POINT("+zzb+" "+hzb+")",id,gspbm);
- }
- }else{
- if(hzb>zzb){
- rmGgpgeoService.updGsp3("POINT("+hzb+" "+zzb+")",id,gspbm);
- }else{
- rmGgpgeoService.updGsp3("POINT("+zzb+" "+hzb+")",id,gspbm);
- }
- }
- }
- /**
- * 通过id删除
- *
- * @param id
- * @return
- */
- @AutoLog(value = "公告牌信息表-通过id删除")
- @ApiOperation(value = "公告牌信息表-通过id删除", notes = "公告牌信息表-通过id删除")
- @PostMapping(value = "/delete")
- // @RequiresPermissions("rmBulletinBoard:delete")
- public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
- rmBulletinBoardService.removeById(id);
- rmGgpgeoService.delGsp(id);
- return Result.OK("删除成功!");
- }
- /**
- * 批量删除
- *
- * @param ids
- * @return
- */
- @AutoLog(value = "公告牌信息表-批量删除")
- @ApiOperation(value = "公告牌信息表-批量删除", notes = "公告牌信息表-批量删除")
- @PostMapping(value = "/deleteBatch")
- public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
- this.rmBulletinBoardService.removeByIds(Arrays.asList(ids.split(",")));
- List<String> gspIds = Arrays.asList(ids.split(","));
- for(int i=0;i<gspIds.size();i++){
- rmGgpgeoService.delGsp(gspIds.get(i));
- }
- return Result.OK("批量删除成功!");
- }
- /**
- * 通过id查询
- *
- * @param id
- * @return
- */
- @AutoLog(value = "公告牌信息表-通过id查询")
- @ApiOperation(value = "公告牌信息表-通过id查询", notes = "公告牌信息表-通过id查询")
- @GetMapping(value = "/queryById")
- public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
- RmBulletinBoard rmBulletinBoard = rmBulletinBoardService.getById(id);
- if (rmBulletinBoard == null) {
- return Result.error("未找到对应数据");
- }
- return Result.OK(rmBulletinBoard);
- }
- /**
- * 通过关联id查询
- *
- * @param relId
- * @return
- */
- @AutoLog(value = "公告牌信息表-通过关联id查询")
- @ApiOperation(value = "公告牌信息表-通过关联id查询", notes = "公告牌信息表-通过关联id查询")
- @GetMapping(value = "/queryByRelId")
- public Result<?> queryByRelId(@RequestParam(name = "relId", required = true) String relId) {
- QueryWrapper<RmBulletinBoard> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("gspbm",relId);
- RmBulletinBoard rmBulletinBoard = rmBulletinBoardService.getOne(queryWrapper);
- if (rmBulletinBoard == null) {
- return Result.error("未找到对应数据");
- }
- return Result.OK(rmBulletinBoard);
- }
- /**
- * 生成所有的flag为0的图形,然后地图生成标志flag设置为1
- * <p>
- * * @return
- */
- @AutoLog(value = "生成公告牌的图形")
- @ApiOperation(value = "生成公告牌的图形", notes = "生成公告牌的图形")
- @GetMapping(value = "/genarateGeo")
- public Result<?> genarateGeo() {
- rmBulletinBoardService.GenarateGspGeo();
- return Result.OK("生成图形成功!");
- }
- /**
- * 导出excel
- *
- * @param request
- * @param rmBulletinBoard
- */
- @RequestMapping(value = "/exportXls")
- public ModelAndView exportXls(HttpServletRequest request, RmBulletinBoard rmBulletinBoard) {
- return super.exportXls(request, rmBulletinBoard, RmBulletinBoard.class, "公告牌信息表");
- }
- /**
- * 通过excel导入数据
- *
- * @param request
- * @param response
- * @return
- */
- @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
- public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
- for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
- MultipartFile file = entity.getValue();// 获取上传文件对象
- ImportParams params = new ImportParams();
- params.setTitleRows(2);
- params.setHeadRows(1);
- params.setNeedSave(true);
- try {
- List<RmBulletinBoard> list = ExcelImportUtil.importExcel(file.getInputStream(), RmBulletinBoard.class, params);
- long start = System.currentTimeMillis();
- rmBulletinBoardService.saveBatch(list);
- for (RmBulletinBoard page : list) {
- // rmBulletinBoardService.save(page);
- if(page.getHzb()!=null &&page.getZzb()!=null){
- generateGeom(page);
- String geoinfo = rmGgpgeoService.getGeojson(page.getId());
- page.setGeoinfo(geoinfo);
- page.setFlag(1);
- }
- rmBulletinBoardService.saveOrUpdate(page);
- }
- return Result.ok("文件导入成功!数据行数:" + list.size());
- } catch (Exception e) {
- log.error(e.getMessage(),e);
- return Result.error("文件导入失败:"+e.getMessage());
- } finally {
- try {
- file.getInputStream().close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return Result.error("文件导入失败!");
- }
- }
|