package com.terra.system.controller.show;
|
|
import com.terra.system.annotation.SysLog;
|
import com.terra.system.controller.all.BaseController;
|
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.data.DownloadEntity;
|
import com.terra.system.entity.show.PipelineEntity;
|
import com.terra.system.entity.sys.UserEntity;
|
import com.terra.system.helper.Md5Helper;
|
import com.terra.system.helper.StringHelper;
|
import com.terra.system.helper.WebHelper;
|
import com.terra.system.service.data.DownloadService;
|
import com.terra.system.service.show.PipelineService;
|
import com.terra.system.service.sys.DownlogService;
|
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.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 管道分析
|
* @author WWW
|
*/
|
@Api(tags = "综合展示\\管道分析")
|
@RestController
|
@RequestMapping("/pipeline")
|
public class PipelineController extends BaseController {
|
@Resource
|
TokenService tokenService;
|
|
@Resource
|
DownlogService downlogService;
|
|
@Resource
|
DownloadService downloadService;
|
|
@Resource
|
PipelineService pipelineService;
|
|
@SysLog()
|
@ApiOperation(value = "查询管段")
|
@GetMapping(value = "/selectSegNames")
|
public ResponseMsg<Object> selectSegNames() {
|
try {
|
List<PipelineEntity> rs = pipelineService.selectSegNames();
|
|
return success(rs);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "查询管线分析")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pe", value = "管道分析实体类", dataType = "PipelineEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/selectPipeAnalysis")
|
public ResponseMsg<Object> selectPipeAnalysis(@RequestBody PipelineEntity pe) {
|
try {
|
if (null == pe.getGid() || pe.getGid() < 1) {
|
return fail("请输入管段ID");
|
}
|
if (null == pe.getTabs() || 0 == pe.getTabs().size()) {
|
return fail("请输入表名");
|
}
|
if (!checkTabs(pe.getTabs())) {
|
return fail("存在非法表名");
|
}
|
|
Map<String, Object> map = new HashMap<>(4);
|
for (String tab : pe.getTabs()) {
|
List<PipelineEntity> rs = pipelineService.selectPipeAnalysis(tab, pe.getGid());
|
map.put(tab, rs);
|
}
|
|
return success(map);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "请求管道分析结果下载")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pe", value = "管道分析实体类", dataType = "PipelineEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/downloadReq")
|
public ResponseMsg<Object> downloadReq(@RequestBody PipelineEntity pe, HttpServletRequest req) {
|
try {
|
if (null == pe || StringHelper.isEmpty(pe.getPwd())) {
|
return fail("密码不能为空");
|
}
|
if (null == pe.getTabs() || 0 == pe.getTabs().size()) {
|
return fail("请输入表名");
|
}
|
if (!checkTabs(pe.getTabs())) {
|
return fail("存在非法表名");
|
}
|
if (!DownloadService.decryptPwd(pe)) {
|
return fail("密码解密失败", null);
|
}
|
if (StringHelper.isPwdInvalid(pe.getPwd())) {
|
return fail("密码不符合要求");
|
}
|
|
Map<String, List<PipelineEntity>> map = new HashMap<>(4);
|
for (String tab : pe.getTabs()) {
|
List<PipelineEntity> rs = pipelineService.selectPipeAnalysis(tab, pe.getGid());
|
if (null != rs && rs.size() > 0) {
|
map.put(tab, rs);
|
}
|
}
|
if (map.size() == 0) {
|
return fail("查无数据");
|
}
|
|
UserEntity ue = tokenService.getCurrentUser(req);
|
String guid = pipelineService.createZipFile(ue, map, pe.getPwd());
|
|
return success(guid);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "分页查询下载文件")
|
@ApiImplicitParams({
|
@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 = "/selectPageCountForDownload")
|
public ResponseMsg<List<DownloadEntity>> selectPageCountForDownload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) {
|
try {
|
if (pageSize < 1 || pageIndex < 1) {
|
return fail("每页页数或分页数小于1", null);
|
}
|
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (ue == null) {
|
return fail("用户未登录", null);
|
}
|
|
int count = downloadService.selectCountForUser(ue.getId(), "5", name);
|
if (count == 0) {
|
return success(0, null);
|
}
|
List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getId(), "5", name, pageSize, pageSize * (pageIndex - 1));
|
|
return success(count, rs);
|
} 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")
|
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);
|
}
|
}
|
|
/**
|
* 检查表名
|
*/
|
private boolean checkTabs(List<String> tabs) {
|
for (String tab : tabs) {
|
if (!StaticData.PIPE_ANALYSIS_TABS.contains(tab)) {
|
return false;
|
}
|
}
|
|
return true;
|
}
|
}
|