package com.terra.system.controller.show;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.terra.system.annotation.SysLog;
|
import com.terra.system.controller.all.BaseQueryController;
|
import com.terra.system.entity.all.HttpStatus;
|
import com.terra.system.entity.all.ResponseMsg;
|
import com.terra.system.entity.all.StaticData;
|
import com.terra.system.entity.ctrl.DownloadReqEntity;
|
import com.terra.system.entity.data.DownloadEntity;
|
import com.terra.system.entity.data.MetaEntity;
|
import com.terra.system.entity.data.VerEntity;
|
import com.terra.system.entity.sys.UserEntity;
|
import com.terra.system.helper.*;
|
import com.terra.system.mapper.all.BasicMapper;
|
import com.terra.system.service.all.BaseQueryService;
|
import com.terra.system.service.data.DownloadService;
|
import com.terra.system.service.data.MetaService;
|
import com.terra.system.service.data.VerService;
|
import com.terra.system.service.show.DataLibService;
|
import com.terra.system.service.sys.TokenService;
|
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.io.File;
|
import java.net.URLDecoder;
|
import java.nio.charset.StandardCharsets;
|
import java.util.List;
|
|
/**
|
* 资料馆
|
* @author WWW
|
*/
|
@Api(tags = "综合展示\\资料馆")
|
@RestController
|
@RequestMapping("/dataLib")
|
public class DataLibController extends BaseQueryController {
|
@Resource
|
MetaService metaService;
|
|
@Resource
|
TokenService tokenService;
|
|
@Resource
|
DataLibService dataLibService;
|
|
@Resource
|
BaseQueryService baseQueryService;
|
|
@Resource
|
VerService verService;
|
|
@SysLog()
|
@ApiOperation(value = "根据目录ID查询版本列表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query")
|
})
|
@GetMapping(value = "/selectVerByDirid")
|
public ResponseMsg<List<VerEntity>> selectVerByDirid(Integer dirid) {
|
try {
|
if (null == dirid || dirid < 0) {
|
dirid = 0;
|
}
|
|
List<VerEntity> list = verService.selectByDirid(dirid);
|
if (null == list || list.isEmpty()) {
|
list = verService.selectByDirid(0);
|
}
|
|
return success(list);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "分页查询元数据")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "depcode", value = "单位编码", dataType = "String", paramType = "query", example = "00"),
|
@ApiImplicitParam(name = "types", value = "资料类别", dataType = "String", paramType = "query", example = "基础测绘,基础地灾,基础勘察,合规数据,管理数据,测绘(ESV),勘察(EGE),地灾(EGD),洞库(EGD)"),
|
@ApiImplicitParam(name = "dirs", value = "项目编码", dataType = "String", paramType = "query", example = ""),
|
@ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = ""),
|
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
|
@ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
|
})
|
@GetMapping(value = "/selectMetasForPage")
|
public ResponseMsg<Object> selectMetasForPage(String depcode, String types, String dirs, String name, Integer pageSize, Integer pageIndex) {
|
try {
|
if (pageSize < 1 || pageIndex < 1) {
|
return fail("每页页数或分页数小于1", null);
|
}
|
// dirs = DataLibService.copeCodes(dirs, "dircode")
|
dirs = dataLibService.getDirsByTypes(types, dirs, "dircode");
|
|
int count = metaService.selectMetasForCount(depcode, dirs, name);
|
if (count == 0) {
|
return success(0, null);
|
}
|
|
List<MetaEntity> rs = metaService.selectMetasForPage(depcode, dirs, name, pageSize, pageSize * (pageIndex - 1));
|
|
return success(count, rs);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "查询表中数据")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "元数据ID", dataType = "Integer", paramType = "query", example = "115"),
|
@ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1"),
|
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10")
|
})
|
@GetMapping(value = "/selectDbData")
|
public ResponseMsg<Object> selectDbData(Integer id, Integer pageIndex, Integer pageSize) {
|
// noinspection AlibabaRemoveCommentedCode
|
try {
|
if (null == id || id < 0) {
|
return fail("元数据ID不能为空或小于0", null);
|
}
|
|
MetaEntity meta = metaService.selectById(id);
|
if (null == meta || null == meta.getTab() || !meta.getTab().contains(StaticData.POINT)) {
|
return fail("找不到元数据信息", null);
|
}
|
|
String entity = meta.getTab().substring(meta.getTab().indexOf(".") + 1).replace("_", "").toLowerCase();
|
BasicMapper baseMapper = ClassHelper.getBasicMapper(entity);
|
if (null == baseMapper) {
|
return null;
|
}
|
|
QueryWrapper wrapper = new QueryWrapper();
|
wrapper.eq("parentid", meta.getEventid());
|
|
Page<Object> page = new Page<>(pageIndex, pageSize);
|
page.addOrder(OrderItem.desc("gid"));
|
IPage<Object> paged = baseMapper.selectPage(page, wrapper);
|
|
return success(paged.getTotal(), paged.getRecords());
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "请求元数据下载")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "dr", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/downloadReq")
|
public ResponseMsg<Object> downloadReq(@RequestBody DownloadReqEntity dr, HttpServletRequest req, HttpServletResponse res) {
|
try {
|
if (null == dr || StringHelper.isEmpty(dr.getPwd())) {
|
return fail("密码不能为空");
|
}
|
if (null == dr.getIds() || dr.getIds().isEmpty()) {
|
return fail("请选择要下载的文件ID");
|
}
|
if (!DownloadService.decryptPwd(dr)) {
|
return fail("密码解密失败", null);
|
}
|
if (StringHelper.isPwdInvalid(dr.getPwd())) {
|
return fail("密码不符合要求");
|
}
|
|
UserEntity ue = tokenService.getCurrentUser(req);
|
String guid = metaService.downloadMeteReq(ue, dr);
|
|
return success(guid);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "查询下载文件")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "guid", value = "文件GUID", dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "pwd", value = "密码", dataType = "String", paramType = "query")
|
})
|
@GetMapping(value = "/selectDownloadFile")
|
public ResponseMsg<Boolean> selectDownloadFile(String guid, String pwd) {
|
try {
|
if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) {
|
return fail("文件ID和密码不能为空", null);
|
}
|
if (!pwd.endsWith(StaticData.EQ)) {
|
pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name());
|
}
|
|
String password = DownloadService.decryptPwd(pwd);
|
if (null == password) {
|
return fail("密码解密失败", null);
|
}
|
|
DownloadEntity de = downloadService.selectByGuid(guid);
|
if (null == de) {
|
return fail("文件不存在", null);
|
}
|
if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) {
|
return fail("密码不正确", null);
|
}
|
|
String filePath = downloadService.getDownloadFilePath(de);
|
File file = new File(filePath);
|
|
return success(file.exists());
|
} catch (Exception ex) {
|
return fail(ex, false);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "下载文件")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "guid", value = "文件GUID", dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "pwd", value = "密码", dataType = "String", paramType = "query")
|
})
|
@ResponseBody
|
@GetMapping(value = "/downloadFile")
|
@SuppressWarnings("AlibabaRemoveCommentedCode")
|
public void downloadFile(String guid, String pwd, HttpServletRequest req, HttpServletResponse res) {
|
try {
|
/*if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) {
|
WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "文件ID和密码不能为空", res);
|
}
|
if (!pwd.endsWith(StaticData.EQ)) {
|
pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name());
|
}
|
|
String password = DownloadService.decryptPwd(pwd);
|
if (null == password) {
|
WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "密码解密失败", res);
|
}*/
|
|
DownloadEntity de = downloadService.selectByGuid(guid);
|
if (null == de) {
|
WebHelper.writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res);
|
return;
|
}
|
/*if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) {
|
WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "密码不正确", res);
|
}*/
|
|
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);
|
}
|
}
|
}
|