package com.lf.server.controller.data.upload;
|
|
import com.lf.server.annotation.SysLog;
|
import com.lf.server.entity.all.ResponseMsg;
|
import com.lf.server.entity.all.StaticData;
|
import com.lf.server.entity.data.DirEntity;
|
import com.lf.server.entity.data.MetaFileEntity;
|
import com.lf.server.entity.sys.UserEntity;
|
import com.lf.server.helper.StringHelper;
|
import com.lf.server.service.data.UploadService;
|
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.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.List;
|
|
/**
|
* 数据入库
|
* @author WWW
|
*/
|
@Api(tags = "数据管理\\数据上传")
|
@RestController
|
@RequestMapping("/dataUpload")
|
public class UploadController extends QueryController {
|
@Autowired
|
UploadService uploadService;
|
|
@SysLog()
|
@ApiOperation(value = "查询路径")
|
@GetMapping(value = "/selectPath")
|
public ResponseMsg<String> selectPath() {
|
try {
|
String pathName = uploadService.selectPath();
|
|
return success(pathName);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "上传文件")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query")
|
})
|
@ResponseBody
|
@PostMapping(value = "/uploadFiles")
|
public ResponseMsg<Object> uploadFiles(String path, HttpServletRequest req, HttpServletResponse res) {
|
try {
|
List<MetaFileEntity> list = uploadService.uploadData(null, path, req, res);
|
if (null == list || list.isEmpty()) {
|
return fail("没有找到上传文件", null);
|
}
|
|
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 = "/selectFiles")
|
public ResponseMsg<List<MetaFileEntity>> selectFiles(String path) {
|
try {
|
List<MetaFileEntity> list = uploadService.selectFiles(path, StaticData.ALL_EXTENSION);
|
|
return success(list);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "删除文件")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "list", value = "实体类集合", dataType = "MetaEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/deleteFiles")
|
public ResponseMsg<Object> deleteFiles(@RequestBody List<MetaFileEntity> 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.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "查询映射")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "20230109010101"),
|
@ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query", example = "1"),
|
@ApiImplicitParam(name = "epsgCode", value = "坐标编码", dataType = "String", paramType = "query", example = "EPSG:4490")
|
})
|
@GetMapping(value = "/selectMappers")
|
public ResponseMsg<Object> selectMappers(String path, Integer dirid, String epsgCode) {
|
try {
|
if (StringHelper.isEmpty(path) || StringHelper.isEmpty(epsgCode) || null == dirid) {
|
return fail("路径、目录ID和坐标编码不能为空");
|
}
|
if (1 > uploadService.selectCount4Coord(epsgCode)) {
|
return fail("坐标编码" + epsgCode + "不存在");
|
}
|
DirEntity dir = dirService.selectDir(dirid);
|
if (null == dir) {
|
return fail("目录ID=" + dirid + "不存在");
|
}
|
|
List<MetaFileEntity> metas = uploadService.selectFiles(path, StaticData.ALL_EXTENSION);
|
if (null == metas || metas.isEmpty()) {
|
return fail("目录" + path + "下查无文件");
|
}
|
|
List<MetaFileEntity> list = uploadService.selectMappers(metas, dir, epsgCode);
|
|
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 = uploadService.insertFiles(me, entity.getFileEntities())
|
|
return success("成功", 0);
|
} 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());
|
|
// uploadService.insertFiles(me, entity.getFileEntities(), entity.getTabEntities())
|
|
return success("成功", entity.getTabEntities());
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}*/
|
|
@SysLog()
|
@ApiOperation(value = "删除元数据")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", example = "1,2")
|
})
|
@GetMapping(value = "/deleteMetas")
|
public ResponseMsg<Integer> deleteMetas(@RequestParam List<Integer> 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.getMessage(), -1);
|
}
|
}
|
}
|