package com.lf.server.controller.data.upload; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.lf.server.annotation.SysLog; import com.lf.server.entity.all.ResponseMsg; import com.lf.server.entity.all.StaticData; import com.lf.server.entity.ctrl.TabEntity; import com.lf.server.entity.data.*; import com.lf.server.entity.sys.DepEntity; import com.lf.server.entity.sys.UserEntity; import com.lf.server.helper.ClassHelper; import com.lf.server.helper.StringHelper; import com.lf.server.mapper.all.BasicMapper; import com.lf.server.service.all.BaseQueryService; import com.lf.server.service.data.*; import com.lf.server.service.sys.DepService; import com.lf.server.service.sys.TokenService; 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.GetMapping; import javax.servlet.http.HttpServletRequest; import java.util.List; /** * 查询控制器 * @author WWW */ public class QueryController extends CheckController { @Autowired protected DepService depService; @Autowired protected DirService dirService; @Autowired protected VerService verService; @Autowired protected MetaService metaService; @Autowired protected TokenService tokenService; @Autowired protected UploadService uploadService; @Autowired protected BaseQueryService baseQueryService; @Autowired DictService dictService; @SysLog() @ApiOperation(value = "根据父ID分页查询并返回记录数") @ApiImplicitParams({ @ApiImplicitParam(name = "metaid", value = "父ID", dataType = "String", paramType = "query", example = "0"), @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 = "/selectPageAndCountByPid") public ResponseMsg> selectPageAndCountByPid(Integer metaid, String name, Integer pageSize, Integer pageIndex) { try { if (pageSize < 1 || pageIndex < 1) { return fail("每页页数或分页数小于1", null); } if (null == metaid || metaid < 1) { return fail("父ID不能为空且大于1", null); } int count = metaService.selectCountByPid(metaid, name); if (count == 0) { return success(0, null); } List rs = metaService.selectPageByPid(metaid, name, pageSize, pageSize * (pageIndex - 1)); return success(count, rs); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询所有单位") @GetMapping(value = "/selectDepAll") public ResponseMsg> selectDepAll() { try { List list = depService.selectDepAll(); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询所有目录") @GetMapping(value = "/selectDirAll") public ResponseMsg> selectDirAll() { try { List list = dirService.selectDirAll(); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "根据目录ID查询版本列表") @ApiImplicitParams({ @ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query") }) @GetMapping(value = "/selectVerByDirid") public ResponseMsg> selectVerByDirid(Integer dirid) { try { if (null == dirid || dirid < 0) { dirid = 0; } List list = verService.selectByDirid(dirid); if (null == list || list.isEmpty()) { list = verService.selectByDirid(0); } return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询坐标系") @ApiImplicitParams({ @ApiImplicitParam(name = "zoning", value = "带号", dataType = "String", paramType = "query", example = "6度有带号") }) @GetMapping(value = "/selectCoords") public ResponseMsg selectCoords(String zoning) { try { List list = uploadService.selectCoords(zoning); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询项目名称") @GetMapping(value = "/selectProject") public ResponseMsg selectProject() { try { List list = uploadService.selectProject(); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询所有表") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = "点"), @ApiImplicitParam(name = "hasGeom", value = "含有Geom字段", dataType = "Boolean", paramType = "query", example = "false") }) @GetMapping(value = "/selectTabs") public ResponseMsg> selectTabs(String name, Boolean hasGeom) { try { List list = dictService.selectDictTab(name, null == hasGeom || !hasGeom ? "gid" : "geom"); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询字段信息") @ApiImplicitParams({ @ApiImplicitParam(name = "ns", value = "名称空间", dataType = "String", paramType = "query", example = "bd"), @ApiImplicitParam(name = "tab", value = "表名", dataType = "String", paramType = "query", example = "dlg25wAanp") }) @GetMapping(value = "/selectFields") public ResponseMsg> selectFields(String ns, String tab) { try { if (StringHelper.isEmpty(ns) || StringHelper.isEmpty(tab)) { return fail("名称空间和表名不能为空", null); } List list = baseQueryService.selectFields(ns, tab); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询表中数据") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "元数据ID", dataType = "Integer", paramType = "query", example = "115"), @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10") }) @GetMapping(value = "/selectDbData") public ResponseMsg selectDbData(Integer id, Integer pageIndex, Integer pageSize) { // noinspection AlibabaRemoveCommentedCode try { if (null == id || id < 0) { return fail("元数据ID不能为空或小于0", null); } MetaEntity meta = metaService.selectById(id); if (null == meta || null == meta.getTab() || !meta.getTab().contains(StaticData.POINT)) { return fail("找不到元数据信息", null); } String entity = meta.getTab().substring(meta.getTab().indexOf(".") + 1).replace("_", "").toLowerCase(); BasicMapper baseMapper = ClassHelper.getBasicMapper(entity); if (null == baseMapper) { return null; } QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("parentid", meta.getEventid()); Page page = new Page<>(pageIndex, pageSize); page.addOrder(OrderItem.desc("gid")); IPage paged = baseMapper.selectPage(page, wrapper); return success(paged.getTotal(), paged.getRecords()); } 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 = "/selectByPageForUpload") public ResponseMsg selectByPageForUpload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) { try { if (pageSize < 1 || pageIndex < 1) { return fail("每页页数或分页数小于1", null); } UserEntity ue = tokenService.getCurrentUser(req); int count = metaService.selectCountForUpload(name, ue.getId(), null); if (count == 0) { return success(0, null); } List list = metaService.selectByPageForUpload(name, ue.getId(), null, pageSize, pageSize * (pageIndex - 1)); return success(count, list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "根据元数据ID查询") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "query", example = "1") }) @GetMapping(value = "/selectMetaById") public ResponseMsg selectMetaById(int id) { try { MetaEntity entity = metaService.selectById(id); return success(entity); } catch (Exception ex) { return fail(ex, null); } } }