管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-03-24 e26af85e049516e6ce2b082bc2bc90bf71643e95
src/main/java/com/lf/server/controller/data/PublishController.java
@@ -3,8 +3,12 @@
import com.lf.server.annotation.SysLog;
import com.lf.server.controller.all.BaseController;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.ctrl.PubEntity;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.data.PublishEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.WebHelper;
import com.lf.server.service.data.PublishService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -21,7 +25,7 @@
 * 数据发布
 * @author WWW
 */
@Api(tags = "运维管理\\数据发布")
@Api(tags = "数据管理\\发布管理")
@RestController
@RequestMapping("/publish")
public class PublishController extends BaseController {
@@ -32,40 +36,55 @@
    TokenService tokenService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
    @ApiOperation(value = "分页查询元数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false, example = "")
    })
    @GetMapping({"/selectCount"})
    public ResponseMsg<Integer> selectCount(String name) {
        try {
            int count = publishService.selectCount(name);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @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 = "/selectByPage")
    public ResponseMsg<List<PublishEntity>> selectByPage(String name, Integer pageSize, Integer pageIndex) {
    @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);
            }
            List<PublishEntity> rs = publishService.selectByPage(name, pageSize, pageSize * (pageIndex - 1));
            String types = getType(type);
            int count = publishService.selectMetasByCount(depcode, dircode, verid, types, name);
            if (count == 0) {
                return success(0, null);
            }
            return success(rs);
            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')";
            case "MPT":
                return "type = 'mpt'";
            case "3DML":
                return "type = '3dml'";
            case "BIM":
                return "type in ('ifc', 'fbx', 'rvt')";
            default:
                throw new Exception("数据类型不匹配");
        }
    }
@@ -97,19 +116,6 @@
    }
    @SysLog()
    @ApiOperation(value = "查询所有")
    @GetMapping(value = "/selectAll")
    public ResponseMsg<List<PublishEntity>> selectAll() {
        try {
            List<PublishEntity> list = publishService.selectAll();
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "根据ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "query", example = "1")
@@ -126,19 +132,28 @@
    }
    @SysLog()
    @ApiOperation(value = "插入一条")
    @ApiOperation(value = "插入发布数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "PublishEntity", paramType = "body")
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "PubEntity", paramType = "body")
    })
    @PostMapping(value = "/insert", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insert(@RequestBody PublishEntity entity, HttpServletRequest req) {
    @PostMapping(value = "/insertForPub", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Object> insertForPub(@RequestBody PubEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setCreateUser(ue.getId());
            if (null == entity || null == entity.getIds() || entity.getIds().isEmpty()) {
                return fail("实体类为空或找不到元数据ID", 0);
            }
            if (StringHelper.isEmpty(entity.getType())) {
                return fail("数据类别为空", null);
            }
            int count = publishService.insert(entity);
            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);
            return success(count);
        } catch (Exception ex) {
@@ -146,58 +161,36 @@
        }
    }
    @SysLog()
    @ApiOperation(value = "插入多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "PublishEntity", paramType = "body")
    })
    @PostMapping(value = "/inserts", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> inserts(@RequestBody List<PublishEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (PublishEntity entity : list) {
                    entity.setCreateUser(ue.getId());
                }
            }
            int count = publishService.inserts(list);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "删除一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/delete")
    public ResponseMsg<Integer> delete(int id) {
        try {
            int count = publishService.delete(id);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
    /**
     * 获取转换方法
     */
    private String getConvertMethod(String type) throws Exception {
        switch (type) {
            case "DOM":
                return "/Convert/ToTiles";
            case "MPT":
            case "3DML":
                return "/Convert/ToSG";
            case "BIM":
                return "/Convert/ToTileset";
            default:
                throw new Exception("数据类型不匹配");
        }
    }
    @SysLog()
    @ApiOperation(value = "删除多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", example = "1,2")
            @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", allowMultiple = true, example = "1")
    })
    @GetMapping(value = "/deletes")
    public ResponseMsg<Integer> deletes(@RequestParam List<Integer> ids) {
    public ResponseMsg<Integer> deletes(@RequestParam List<Integer> ids, HttpServletRequest req) {
        try {
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
            int count = publishService.deletes(ids);
            int count = publishService.deletes(ids, req);
            return success(count);
        } catch (Exception ex) {
@@ -220,30 +213,6 @@
            }
            int count = publishService.update(entity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "更新多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "PublishEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/updates", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updates(@RequestBody List<PublishEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (PublishEntity entity : list) {
                    entity.setUpdateUser(ue.getId());
                }
            }
            int count = publishService.updates(list);
            return success(count);
        } catch (Exception ex) {