package com.moon.server.controller.show; import com.moon.server.annotation.SysLog; import com.moon.server.controller.all.BaseQueryController; import com.moon.server.entity.all.HttpStatus; import com.moon.server.entity.all.ResponseMsg; import com.moon.server.entity.all.StaticData; import com.moon.server.entity.ctrl.DownloadTileEntity; import com.moon.server.entity.ctrl.ShpRecordEntity; import com.moon.server.entity.data.DownloadEntity; import com.moon.server.entity.data.MetaFileEntity; import com.moon.server.entity.data.PublishEntity; import com.moon.server.entity.sys.UserEntity; import com.moon.server.helper.AesHelper; import com.moon.server.helper.StringHelper; import com.moon.server.helper.WebHelper; import com.moon.server.service.all.BaseUploadService; import com.moon.server.service.data.DownloadService; import com.moon.server.service.data.PublishService; import com.moon.server.service.show.InquiryService; import com.moon.server.service.sys.TokenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; @Api(tags = "综合展示\\查询") @RestController @SuppressWarnings("ALL") @RequestMapping("/inquiry") public class InquiryController extends BaseQueryController { @Autowired TokenService tokenService; @Autowired BaseUploadService baseUploadService; @Autowired InquiryService inquiryService; @Resource PublishService publishService; @SysLog() @ApiOperation(value = "上传Shp文件读取第一条记录的WKT") @ResponseBody @PostMapping(value = "/uploadShp") public ResponseMsg uploadShp(HttpServletRequest req, HttpServletResponse res) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue == null) { return fail("用户未登录", null); } List list = baseUploadService.uploadData(null, null, false, req, res); if (list == null || list.size() < StaticData.I4) { return fail("没有找到已上传的数据或不完整", null); } ShpRecordEntity sr = inquiryService.readShpFirstRecord(list); if (sr != null && !StringHelper.isEmpty(sr.getWkt())) { sr.setWkt(AesHelper.encrypt(sr.getWkt())); } return success(sr); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "下载瓦片") @ApiImplicitParams({ @ApiImplicitParam(name = "dt", value = "下载瓦片实体类", dataType = "DownloadTileEntity", paramType = "body") }) @ResponseBody @PostMapping(value = "/downloadTiles") public ResponseMsg downloadTiles(@RequestBody DownloadTileEntity dt, HttpServletRequest req, HttpServletResponse res) { try { if (null == dt || null == dt.getPubid() || StringHelper.isEmpty(dt.getPwd())) { return fail("发布ID和密码不能为空"); } String err = dt.verifyCoords(); if (null != err) { return fail(err); } if (!DownloadService.decryptPwd(dt)) { return fail("密码解密失败", null); } PublishEntity pub = publishService.selectById(dt.getPubid()); if (null == pub) { return fail("发布数据不存在"); } UserEntity ue = tokenService.getCurrentUser(req); String guid = inquiryService.zipTiles(dt, pub, ue); if (null == guid) { return fail("没有瓦片需要打包下载"); } return success(guid); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "下载文件") @ApiImplicitParams({ @ApiImplicitParam(name = "guid", value = "文件GUID", dataType = "String", paramType = "query") }) @ResponseBody @GetMapping(value = "/downloadFile") public void downloadFile(String guid, HttpServletRequest req, HttpServletResponse res) { try { DownloadEntity de = downloadService.selectByGuid(guid); if (null == de) { WebHelper.writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res); return; } UserEntity ue = tokenService.getCurrentUser(req); downlogService.updateInfos(ue, de, req); String filePath = downloadService.getDownloadFilePath(de); WebHelper.download(filePath, de.getName(), res); } catch (Exception ex) { WebHelper.writeInfo(HttpStatus.ERROR, ex.getMessage(), res); } } }