package com.moon.server.controller.show;
|
|
import com.moon.server.annotation.SysLog;
|
import com.moon.server.controller.all.BaseController;
|
import com.moon.server.entity.all.HttpStatus;
|
import com.moon.server.entity.all.ResponseMsg;
|
import com.moon.server.entity.data.DownloadEntity;
|
import com.moon.server.entity.show.ExportEntity;
|
import com.moon.server.entity.sys.UserEntity;
|
import com.moon.server.helper.StringHelper;
|
import com.moon.server.helper.WebHelper;
|
import com.moon.server.service.data.DownloadService;
|
import com.moon.server.service.show.ExportService;
|
import com.moon.server.service.sys.DownlogService;
|
import com.moon.server.service.sys.TokenService;
|
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("/export")
|
public class ExportController extends BaseController {
|
@Autowired
|
TokenService tokenService;
|
|
@Autowired
|
ExportService exportService;
|
|
@Autowired
|
DownlogService downlogService;
|
|
@Autowired
|
DownloadService downloadService;
|
|
@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 = "/selectByPage")
|
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(), "2", name);
|
if (count == 0) {
|
return success(0, null);
|
}
|
List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getId(), "2", name, pageSize, pageSize * (pageIndex - 1));
|
|
return success(count, rs);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "新建出图")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "entity", value = "在线制图实体类", dataType = "ExportEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/insertMap", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<String> insertMap(@RequestBody ExportEntity entity, HttpServletRequest req) {
|
try {
|
boolean flag = entity.getXmin() == 0 && entity.getYmin() == 0 && entity.getXmax() == 0 && entity.getYmax() == 0;
|
if (StringHelper.isEmpty(entity.getLayers()) || StringHelper.isEmpty(entity.getToken()) || flag) {
|
return fail("参数不完整");
|
}
|
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (ue == null) {
|
return fail("用户未登录");
|
}
|
|
String str = exportService.post(ue, entity);
|
if (StringHelper.isNull(str)) {
|
return fail("出图失败");
|
}
|
|
return success("出图成功", str);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "下载出图")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "guid", value = "文件GUID", dataType = "String", paramType = "query")
|
})
|
@RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
|
public void downloadFile(String guid, HttpServletRequest req, HttpServletResponse res) {
|
try {
|
if (StringHelper.isEmpty(guid)) {
|
WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "找不到文件ID", res);
|
return;
|
}
|
|
DownloadEntity de = downloadService.selectByGuid(guid);
|
if (null == de) {
|
WebHelper.writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res);
|
return;
|
}
|
|
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);
|
}
|
}
|
}
|