package com.terra.system.controller.data.upload; import com.terra.system.annotation.SysLog; import com.terra.system.entity.all.ResponseMsg; import com.terra.system.entity.ctrl.KeyValueEntity; import com.terra.system.entity.data.DirEntity; import com.terra.system.entity.data.MetaEntity; import com.terra.system.entity.data.MetaFileEntity; import com.terra.system.entity.data.VerEntity; import com.terra.system.entity.sys.UserEntity; import com.terra.system.helper.StringHelper; import com.terra.system.service.all.UploadAttachService; import com.terra.system.service.data.UploadService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import javax.annotation.Resource; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; /** * 数据入库 * @author WWW */ @Api(tags = "数据管理\\数据上传") @RestController @RequestMapping("/dataUpload") public class UploadController extends QueryController { @Resource UploadService uploadService; @Resource UploadAttachService uploadAttachService; @SysLog() @ApiOperation(value = "查询路径") @GetMapping(value = "/selectPath") public ResponseMsg selectPath() { try { String pathName = uploadService.selectPath(); return success(pathName); } catch (Exception ex) { log.error(ex.getMessage(), ex); return fail(ex, null); } } @SysLog() @ApiOperation(value = "上传文件") @ApiImplicitParams({ @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query") }) @ResponseBody @PostMapping(value = "/uploadFiles") public ResponseMsg uploadFiles(String path, HttpServletRequest req, HttpServletResponse res) { try { List list = uploadService.uploadData(null, path, false, req, res); if (null == list || list.isEmpty()) { return fail("没有找到上传文件", null); } uploadService.copePath(list); return success(list); } catch (Exception ex) { return fail(ex, null); } } /** * 接收数组1:@RequestParam(value = "ids")List ids * &ids=1209&ids=1180&ids=1387 * 接收数据2:Integer[] ids * formData.append("ids", 1209); formData.append("ids", 1180); formData.append("ids", 1387); */ @SysLog() @ApiOperation(value = "上传Excel附件") @ApiImplicitParams({ @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query"), @ApiImplicitParam(name = "ids", value = "元数据集合", dataType = "Integer", allowMultiple = true, paramType = "query") }) @ResponseBody @PostMapping(value = "/uploadXlsAnnex") public ResponseMsg uploadXlsAnnex(String path, Integer[] ids, HttpServletRequest req, HttpServletResponse res) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue == null) { return fail("用户未登录", null); } if (null == ids || ids.length == 0) { return fail("找不到元数据的ID集合"); } List ms = metaService.selectXlsAnnex(ids, UploadAttachService.getTabs()); if (null == ms || ms.isEmpty()) { return fail("找不到要上传附件的元数据"); } List list = uploadService.uploadData(null, path, false, req, res); if (null == list || list.isEmpty()) { return fail("没有找到上传文件", null); } List rs = uploadAttachService.uploadXlsAnnex(ue, ms, list, path); if (null == rs || rs.size() == 0) { return fail("没有要更新的元数据"); } return success(rs); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询文件") @ApiImplicitParams({ @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query") }) @GetMapping(value = "/selectFiles") public ResponseMsg> selectFiles(String path) { try { List list = uploadService.selectFiles(path, false); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "删除文件") @ApiImplicitParams({ @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "MetaEntity", paramType = "body") }) @ResponseBody @PostMapping(value = "/deleteFiles") public ResponseMsg deleteFiles(@RequestBody List list, HttpServletRequest req) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue == null) { return fail("用户未登录", null); } if (null == list || list.isEmpty()) { return fail("没有找到文件", null); } int rows = uploadService.deleteFiles(list); return success("成功", rows); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询映射") @ApiImplicitParams({ @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "20230722"), @ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query", example = "1"), @ApiImplicitParam(name = "verid", value = "版本ID", dataType = "Integer", paramType = "query", example = "0"), @ApiImplicitParam(name = "epsgCode", value = "坐标编码", dataType = "String", paramType = "query", example = "EPSG:4490") }) @GetMapping(value = "/selectMappers") public ResponseMsg selectMappers(String path, Integer dirid, Integer verid, String epsgCode, HttpServletRequest req) { try { if (StringHelper.isEmpty(path) || StringHelper.isEmpty(epsgCode) || null == dirid || null == verid) { return fail("路径、目录ID、版本ID和坐标编码不能为空"); } if (1 > uploadService.selectCount4Coord(epsgCode)) { return fail("坐标编码" + epsgCode + "不存在"); } DirEntity dir = dirService.selectDir(dirid); if (null == dir) { return fail("目录ID=" + dirid + "不存在"); } VerEntity ver = verService.selectVersion(verid); if (null == ver) { return fail("版本ID=" + verid + "不存在"); } UserEntity ue = tokenService.getCurrentUser(req); List list = uploadService.selectMappers(ue, path, dir, ver, epsgCode); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "插入文件") @ApiImplicitParams({ @ApiImplicitParam(name = "list", value = "元数据文件集合", dataType = "MetaFileEntity", paramType = "body") }) @ResponseBody @PostMapping(value = "/insertFiles") public ResponseMsg insertFiles(@RequestBody List list, HttpServletRequest req) { try { UserEntity ue = tokenService.getCurrentUser(req); if (null == ue) { return fail("用户未登录", null); } if (null == list || list.isEmpty()) { return fail("元数据文件集合为空", null); } uploadService.insertFiles(ue, list, req); return success("成功", list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "插入KML文件") @ApiImplicitParams({ @ApiImplicitParam(name = "list", value = "元数据文件集合", dataType = "MetaFileEntity", paramType = "body") }) @ResponseBody @PostMapping(value = "/insertKml") public ResponseMsg insertKml(@RequestBody List list, HttpServletRequest req){ try { UserEntity ue = tokenService.getCurrentUser(req); if (null == ue) { return fail("用户未登录", null); } if (null == list || list.isEmpty()) { return fail("元数据文件集合为空", null); } uploadService.insertKml(ue, list); return success("成功", list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "删除元数据") @ApiImplicitParams({ @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", allowMultiple = true, example = "1") }) @GetMapping(value = "/deleteMetas") public ResponseMsg deleteMetas(@RequestParam List ids) { try { if (ids == null || ids.isEmpty()) { return fail("id数组不能为空", -1); } int count = metaService.deletes(ids); return success(count); } catch (Exception ex) { return fail(ex, -1); } } }