月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-09-02 53d68348f21c33e846ba1dd9ef483468d13f3228
src/main/java/com/moon/server/controller/data/PublishController.java
@@ -9,16 +9,20 @@
import com.moon.server.entity.sys.UserEntity;
import com.moon.server.helper.StringHelper;
import com.moon.server.helper.WebHelper;
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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
/**
@@ -29,11 +33,17 @@
@RestController
@RequestMapping("/publish")
public class PublishController extends BaseController {
    @Autowired
    @Resource
    PublishService publishService;
    @Autowired
    @Resource
    TokenService tokenService;
    @Resource
    PermsService permsService;
    @Resource
    ShuJianService shuJianService;
    @SysLog()
    @ApiOperation(value = "分页查询元数据")
@@ -76,15 +86,13 @@
    private String getType(String type) throws Exception {
        switch (type) {
            case "DOM":
                return "type in ('tif', 'tiff', 'img')";
                return "type in ('tif', 'tiff', 'img', 'jp2', 'jpg') and mata_type in (1, 3, 4, 5)";
            case "DEM":
                return "type in ('tif', 'tiff')";
            case "MPT":
                return "type = 'mpt'";
            case "3DML":
                return "type = '3dml'";
            case "BIM":
                return "type in ('ifc', 'fbx', 'rvt')";
                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("数据类型不匹配");
        }
@@ -94,26 +102,51 @@
    @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, Integer pageSize, Integer pageIndex) {
    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);
            int count = publishService.selectCount(name, dircode, type);
            if (count == 0) {
                return success(0, null);
            }
            List<PublishEntity> rs = publishService.selectByPage(name, pageSize, pageSize * (pageIndex - 1));
            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 "type = 'DOM'";
            case "DEM":
                return "type = 'DEM'";
            case "Vector":
                return "type = 'Vector'";
            case "Model":
                return "type = 'Model'";
            default:
                throw new Exception("数据类型不匹配");
        }
    }
@@ -134,6 +167,20 @@
    }
    @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 = "/selectColorTables")
    public void selectColorTables(int pageSize, int pageIndex, HttpServletRequest req, HttpServletResponse res) {
        pageIndex = Math.max(pageIndex, 1);
        pageSize = Math.max(pageSize, 5);
        shuJianService.selectColorTables(pageSize, pageIndex, req, res);
    }
    @SysLog()
    @ApiOperation(value = "插入发布数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "PubEntity", paramType = "body")
@@ -151,11 +198,11 @@
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUserId(ue.getId());
                entity.setToken(WebHelper.getToken(req));
            }
            String method = getConvertMethod(entity.getType());
            long count = publishService.postForPub(entity, method, req);
            permsService.clearPermsCache();
            // String method = getConvertMethod(entity.getType())
            long count = publishService.postForPub(entity, "", req);
            return success(count);
        } catch (Exception ex) {
@@ -163,22 +210,20 @@
        }
    }
    /**
     * 获取转换方法
     */
    private String getConvertMethod(String type) throws Exception {
        switch (type) {
            case "DOM":
                return "/Convert/ToTiles";
            case "DEM":
                return "/Convert/ToTerra";
            case "MPT":
            case "3DML":
                return "/Convert/ToSG";
            case "BIM":
                return "/Convert/ToTileset";
            default:
                throw new Exception("数据类型不匹配");
    @SysLog()
    @ApiOperation(value = "发布数简服务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "PubEntity", paramType = "body")
    })
    public ResponseMsg<Object> insertShuJianService(@RequestBody PubEntity entity, HttpServletRequest req) {
        try {
            if (null == entity || null == entity.getIds() || entity.getIds().isEmpty()) {
                return fail("实体类为空或找不到元数据ID", 0);
            }
            return success(null);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
@@ -194,6 +239,13 @@
                return fail("id数组不能为空", -1);
            }
            String strs = StringHelper.join(ids, ",");
            List<PublishEntity> list = publishService.selectByIds(strs);
            if (null == list || list.isEmpty()) {
                return fail("没有找到要删除的数据", -1);
            }
            permsService.clearPermsCache();
            int count = publishService.deletes(ids, req);
            return success(count);
@@ -216,6 +268,7 @@
                entity.setUpdateUser(ue.getId());
            }
            permsService.clearPermsCache();
            int count = publishService.update(entity);
            return success(count);