package com.moon.server.controller.data;
|
|
import com.moon.server.annotation.SysLog;
|
import com.moon.server.controller.all.BaseController;
|
import com.moon.server.entity.all.ResponseMsg;
|
import com.moon.server.entity.ctrl.PubEntity;
|
import com.moon.server.entity.data.MetaEntity;
|
import com.moon.server.entity.data.PublishEntity;
|
import com.moon.server.entity.sys.UserEntity;
|
import com.moon.server.helper.StringHelper;
|
import com.moon.server.service.all.PermsService;
|
import com.moon.server.service.data.PublishService;
|
import com.moon.server.service.data.ShuJianService;
|
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.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.List;
|
|
/**
|
* 数据发布
|
* @author WWW
|
*/
|
@Api(tags = "数据管理\\发布管理")
|
@RestController
|
@RequestMapping("/publish")
|
public class PublishController extends BaseController {
|
@Resource
|
PublishService publishService;
|
|
@Resource
|
TokenService tokenService;
|
|
@Resource
|
PermsService permsService;
|
|
@Resource
|
ShuJianService shuJianService;
|
|
@SysLog()
|
@ApiOperation(value = "分页查询元数据")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "depcode", value = "单位编码", dataType = "String", paramType = "query", example = "00"),
|
@ApiImplicitParam(name = "dircode", value = "目录编码", dataType = "String", paramType = "query", example = "01"),
|
@ApiImplicitParam(name = "verid", value = "版本ID", dataType = "Integer", paramType = "query", example = "0"),
|
@ApiImplicitParam(name = "type", value = "类别", dataType = "String", paramType = "query", example = "DOM"),
|
@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 = "/selectMetasByPage")
|
public ResponseMsg<Object> selectMetasByPage(String depcode, String dircode, Integer verid, String type, String name, Integer pageSize, Integer pageIndex) {
|
try {
|
if (pageSize < 1 || pageIndex < 1) {
|
return fail("每页页数或分页数小于1", null);
|
}
|
if (StringHelper.isEmpty(type)) {
|
return fail("数据类别为空", null);
|
}
|
|
String types = getType(type);
|
int count = publishService.selectMetasByCount(depcode, dircode, verid, types, name);
|
if (count == 0) {
|
return success(0, null);
|
}
|
|
List<MetaEntity> rs = publishService.selectMetasByPage(depcode, dircode, verid, types, name, pageSize, pageSize * (pageIndex - 1));
|
|
return success(count, rs);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
/**
|
* 获取类型
|
*/
|
private String getType(String type) throws Exception {
|
switch (type) {
|
case "DOM":
|
return "type in ('tif', 'tiff', 'img', 'jp2', 'jpg') and mata_type in (1, 3, 4, 5)";
|
case "DEM":
|
return "type in ('tif', 'tiff', 'dem') and mata_type = 2";
|
case "Vector":
|
return "type in ('shp', 'gdb') and mata_type = 6";
|
case "Model":
|
return "type in ('ifc', 'gdb') and mata_type = 7";
|
default:
|
throw new Exception("数据类型不匹配");
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "分页查询并返回记录数")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = ""),
|
@ApiImplicitParam(name = "dircode", value = "目录", dataType = "String", paramType = "query", example = ""),
|
@ApiImplicitParam(name = "type", 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 = "/selectByPageAndCount")
|
public ResponseMsg<List<PublishEntity>> selectByPageAndCount(String name, String dircode, String type, Integer pageSize, Integer pageIndex) {
|
try {
|
if (pageSize < 1 || pageIndex < 1) {
|
return fail("每页页数或分页数小于1", null);
|
}
|
type = getPubType(type);
|
|
int count = publishService.selectCount(name, dircode, type);
|
if (count == 0) {
|
return success(0, null);
|
}
|
|
List<PublishEntity> rs = publishService.selectByPage(name, dircode, type, pageSize, pageSize * (pageIndex - 1));
|
|
return success(count, rs);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
/**
|
* 获取发布类型
|
*/
|
private String getPubType(String type) throws Exception {
|
if (StringHelper.isEmpty(type)) {
|
return null;
|
}
|
|
switch (type) {
|
case "DOM":
|
return "a.type = 'DOM'";
|
case "DEM":
|
return "a.type = 'DEM'";
|
case "Vector":
|
return "a.type = 'Vector'";
|
case "Model":
|
return "a.type = 'Model'";
|
default:
|
throw new Exception("数据类型不匹配");
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "根据ID查询")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "query", example = "1")
|
})
|
@GetMapping(value = "/selectById")
|
public ResponseMsg<PublishEntity> selectById(int id) {
|
try {
|
PublishEntity entity = publishService.selectById(id);
|
|
return success(entity);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "分页查询数简的颜色表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", example = "10"),
|
@ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "int", paramType = "query", example = "1")
|
})
|
@GetMapping(value = "/selectSjColorTables")
|
public void selectSjColorTables(int pageSize, int pageIndex, HttpServletRequest req, HttpServletResponse res) {
|
pageIndex = Math.max(pageIndex, 1);
|
pageSize = Math.max(pageSize, 5);
|
|
shuJianService.selectSjColorTables(pageSize, pageIndex, req, res);
|
}
|
|
@SysLog()
|
@ApiOperation(value = "查询数简图层")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "port", value = "端口", dataType = "int", paramType = "query", example = "50001")
|
})
|
@GetMapping(value = "/selectSjLayers")
|
public void selectSjLayers(Integer port, HttpServletRequest req, HttpServletResponse res) {
|
shuJianService.selectSjLayers(port, req, res);
|
}
|
|
@SysLog()
|
@ApiOperation(value = "插入数简服务")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "entity", value = "实体类", dataType = "PubEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/insertSjService", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<Object> insertSjService(@RequestBody PubEntity entity, HttpServletRequest req, HttpServletResponse res) {
|
try {
|
if (null == entity || null == entity.getIds() || entity.getIds().isEmpty()) {
|
return fail("实体类为空或找不到元数据ID", 0);
|
}
|
if (StringHelper.isEmpty(entity.getType())) {
|
return fail("发布类别为空", null);
|
}
|
if (!ShuJianService.TYPES.contains(entity.getType())) {
|
return fail("发布类别不支持", null);
|
}
|
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (null != ue) {
|
entity.setUserId(ue.getId());
|
entity.setDepcode(ue.getDepcode());
|
}
|
entity.setDefault();
|
|
permsService.clearPermsCache();
|
Integer rows = shuJianService.insertSjService(entity);
|
|
return success(rows);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "更新数简服务")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "entity", value = "实体类", dataType = "PubEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/updateSjService", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<Object> updateSjService(@RequestBody PubEntity entity, HttpServletRequest req, HttpServletResponse res) {
|
try {
|
if (null == entity || null == entity.getPubid()) {
|
return fail("实体类为空或发布ID为空", 0);
|
}
|
if (StringHelper.isEmpty(entity.getType())) {
|
return fail("发布类别为空", null);
|
}
|
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (null != ue) {
|
entity.setUserId(ue.getId());
|
entity.setDepcode(ue.getDepcode());
|
}
|
entity.setDefault();
|
|
permsService.clearPermsCache();
|
Integer rows = shuJianService.updateSjService(entity);
|
|
return success(rows);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "删除数简服务")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", allowMultiple = true, example = "1")
|
})
|
@GetMapping(value = "/deletesSjServices")
|
public ResponseMsg<Integer> deletesSjServices(@RequestParam List<Integer> ids) {
|
try {
|
if (null == ids || ids.isEmpty()) {
|
return fail("id数组不能为空", -1);
|
}
|
|
permsService.clearPermsCache();
|
int count = shuJianService.deletesSjServices(ids);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
|
@SysLog()
|
@ApiOperation(value = "更新一条")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "entity", value = "实体类", dataType = "PublishEntity", paramType = "body")
|
})
|
@ResponseBody
|
@PostMapping(value = "/update", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<Integer> update(@RequestBody PublishEntity entity, HttpServletRequest req) {
|
try {
|
UserEntity ue = tokenService.getCurrentUser(req);
|
if (ue != null) {
|
entity.setUpdateUser(ue.getId());
|
}
|
if (StringHelper.isEmpty(entity.getGeom())) {
|
entity.setGeom("null");
|
}
|
|
permsService.clearPermsCache();
|
int count = publishService.update(entity);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
}
|