| | |
| | | |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.ctrl.TabMapperEntity; |
| | | import com.lf.server.entity.ctrl.UploadEntity; |
| | | import com.lf.server.entity.ctrl.KeyValueEntity; |
| | | import com.lf.server.entity.data.DirEntity; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.entity.data.VerEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.WebHelper; |
| | | import com.lf.server.service.all.BaseUploadService; |
| | | import com.lf.server.service.data.DataLoaderService; |
| | | import com.lf.server.service.data.DataUploadService; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.service.all.UploadAttachService; |
| | | import com.lf.server.service.data.UploadService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Api(tags = "数据管理\\数据上传") |
| | | @RestController |
| | | @RequestMapping("/dataLoader") |
| | | @RequestMapping("/dataUpload") |
| | | public class UploadController extends QueryController { |
| | | @Autowired |
| | | protected DataLoaderService dataLoaderService; |
| | | UploadService uploadService; |
| | | |
| | | @Autowired |
| | | protected BaseUploadService baseUploadService; |
| | | |
| | | @Autowired |
| | | protected DataUploadService dataUploadService; |
| | | |
| | | private final static List<String> EXT_LIST = new ArrayList<>(Arrays.asList(".xls", ".xlsx", ".mdb", ".zip")); |
| | | UploadAttachService uploadAttachService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询路径") |
| | | @GetMapping(value = "/selectPath") |
| | | public ResponseMsg<String> selectPath() { |
| | | try { |
| | | String pathName = baseUploadService.selectPath(); |
| | | String pathName = uploadService.selectPath(); |
| | | |
| | | return success(pathName); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | log.error(ex.getMessage(), ex); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | |
| | | @PostMapping(value = "/uploadFiles") |
| | | public ResponseMsg<Object> uploadFiles(String path, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | List<MetaFileEntity> list = baseUploadService.uploadData(null, path, req, res); |
| | | List<MetaFileEntity> 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.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 接收数组1:@RequestParam(value = "ids")List<Integer> 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 = "查询映射") |
| | | @ApiOperation(value = "上传Excel附件") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query") |
| | | @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query"), |
| | | @ApiImplicitParam(name = "ids", value = "元数据集合", dataType = "Integer", allowMultiple = true, paramType = "query") |
| | | }) |
| | | @GetMapping(value = "/selectMappers") |
| | | public ResponseMsg<List<TabMapperEntity>> selectMappers(String path) { |
| | | @ResponseBody |
| | | @PostMapping(value = "/uploadXlsAnnex") |
| | | public ResponseMsg<Object> uploadXlsAnnex(String path, Integer[] ids, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | List<TabMapperEntity> list = dataLoaderService.selectMappers(path); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("用户未登录", null); |
| | | } |
| | | if (null == ids || ids.length == 0) { |
| | | return fail("找不到元数据的ID集合"); |
| | | } |
| | | |
| | | return success(list); |
| | | List<MetaEntity> ms = metaService.selectXlsAnnex(ids, UploadAttachService.getTabs()); |
| | | if (null == ms || ms.isEmpty()) { |
| | | return fail("找不到要上传附件的元数据"); |
| | | } |
| | | |
| | | List<MetaFileEntity> list = uploadService.uploadData(null, path, false, req, res); |
| | | if (null == list || list.isEmpty()) { |
| | | return fail("没有找到上传文件", null); |
| | | } |
| | | |
| | | List<KeyValueEntity> rs = uploadAttachService.uploadXlsAnnex(ue, ms, list, path); |
| | | if (null == rs || rs.size() == 0) { |
| | | return fail("没有要更新的元数据"); |
| | | } |
| | | |
| | | return success(rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | |
| | | @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query") |
| | | }) |
| | | @GetMapping(value = "/selectFiles") |
| | | public ResponseMsg<List<MetaEntity>> selectFiles(String path) { |
| | | public ResponseMsg<List<MetaFileEntity>> selectFiles(String path) { |
| | | try { |
| | | List<MetaEntity> list = baseUploadService.selectFiles(path, EXT_LIST); |
| | | List<MetaFileEntity> list = uploadService.selectFiles(path); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询文件") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query") |
| | | }) |
| | | @GetMapping(value = "/selectFiles2") |
| | | public ResponseMsg<List<MetaEntity>> selectFiles2(String path) { |
| | | try { |
| | | List<MetaEntity> list = baseUploadService.selectFiles(path, null); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "插入文件") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "entity", value = "上传实体类", dataType = "UploadEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/insertFiles") |
| | | public ResponseMsg<Object> insertFiles(@RequestBody UploadEntity entity, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("用户未登录", null); |
| | | } |
| | | if (null == entity || null == entity.getMetaEntity()) { |
| | | return fail("元数据信息为空", null); |
| | | } |
| | | |
| | | if (null == entity.getFileEntities() || entity.getFileEntities().isEmpty()) { |
| | | return fail("没有找到上传文件", null); |
| | | } |
| | | |
| | | MetaEntity me = entity.getMetaEntity(); |
| | | me.setCreateTime(WebHelper.getCurrentTimestamp()); |
| | | // me.setBatch(StringHelper.YMDHMS_FORMAT.format(new Date(me.getCreateTime().getTime()))) |
| | | me.setCreateUser(ue.getId()); |
| | | |
| | | int rows = dataUploadService.insertFiles(me, entity.getFileEntities()); |
| | | |
| | | return success("成功", rows); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "插入文件") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "entity", value = "上传实体类", dataType = "UploadEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/insertFiles2") |
| | | public ResponseMsg<Object> insertFiles2(@RequestBody UploadEntity entity, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("用户未登录", null); |
| | | } |
| | | if (null == entity || null == entity.getMetaEntity()) { |
| | | return fail("元数据信息为空", null); |
| | | } |
| | | |
| | | if (null == entity.getFileEntities() || entity.getFileEntities().isEmpty()) { |
| | | return fail("没有找到上传文件", null); |
| | | } |
| | | |
| | | MetaEntity me = entity.getMetaEntity(); |
| | | me.setCreateTime(WebHelper.getCurrentTimestamp()); |
| | | // me.setBatch(StringHelper.YMDHMS_FORMAT.format(new Date(me.getCreateTime().getTime()))) |
| | | me.setCreateUser(ue.getId()); |
| | | |
| | | dataLoaderService.insertFiles(me, entity.getFileEntities(), entity.getTabEntities()); |
| | | |
| | | return success("成功", entity.getTabEntities()); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/deleteFiles") |
| | | public ResponseMsg<Object> deleteFiles(@RequestBody List<MetaEntity> list, HttpServletRequest req) { |
| | | public ResponseMsg<Object> deleteFiles(@RequestBody List<MetaFileEntity> list, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | |
| | | return fail("没有找到文件", null); |
| | | } |
| | | |
| | | int rows = baseUploadService.deleteFiles(list); |
| | | int rows = uploadService.deleteFiles(list); |
| | | |
| | | return success("成功", rows); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询映射") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "20230110010101"), |
| | | @ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query", example = "163"), |
| | | @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<Object> 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<MetaFileEntity> 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<Object> insertFiles(@RequestBody List<MetaFileEntity> 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 = "删除元数据") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", example = "1,2") |
| | | @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", allowMultiple = true, example = "1") |
| | | }) |
| | | @GetMapping(value = "/deleteMetas") |
| | | public ResponseMsg<Integer> deleteMetas(@RequestParam List<Integer> ids) { |
| | |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | } |