| | |
| | | package com.lf.server.controller.all; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.metadata.OrderItem; |
| | |
| | | import com.lf.server.aspect.SysLog; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.helper.AesHelper; |
| | | import com.lf.server.helper.ClassHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.all.GeomBaseMapper; |
| | | import com.lf.server.service.all.BaseQueryService; |
| | | 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 java.util.List; |
| | |
| | | * @author WWW |
| | | */ |
| | | public class BaseQueryController extends BaseController { |
| | | @Autowired |
| | | BaseQueryService baseQueryService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询记录数") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgAgnp") |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgAgnp"), |
| | | @ApiImplicitParam(name = "filter", value = "过滤条件", dataType = "String", paramType = "query", example = ""), |
| | | @ApiImplicitParam(name = "wkt", value = "WKT(著名文本)", dataType = "String", paramType = "query", example = ""), |
| | | @ApiImplicitParam(name = "srid", value = "空间引用标识符", dataType = "Integer", paramType = "query", example = "4326") |
| | | }) |
| | | @GetMapping({"/selectCount"}) |
| | | public ResponseMsg<Long> selectCount(String name) { |
| | | public ResponseMsg<Long> selectCount(String name, String filter, String wkt, Integer srid) { |
| | | try { |
| | | if (StringHelper.isEmpty(name)) { |
| | | return fail("名称空间和实体名称不能为空", null); |
| | | } |
| | | |
| | | Object obj = ClassHelper.getBean(name.trim() + "Mapper"); |
| | | if (!(obj instanceof BaseMapper)) { |
| | | BaseMapper baseMapper = baseQueryService.getBaseMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | BaseMapper baseMapper = (BaseMapper) obj; |
| | | long count = baseMapper.selectCount(null); |
| | | QueryWrapper<Object> wrapper = new QueryWrapper<>(); |
| | | baseQueryService.addFilterWrapper(wrapper, filter); |
| | | baseQueryService.addGeomWrapper(baseMapper, wrapper, wkt, srid); |
| | | |
| | | long count = baseMapper.selectCount(wrapper); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | |
| | | @ApiOperation(value = "分页查询") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgAgnp"), |
| | | @ApiImplicitParam(name = "filter", value = "过滤条件", dataType = "String", paramType = "query", example = "1=1 and 2>=1"), |
| | | @ApiImplicitParam(name = "wkt", value = "WKT(著名文本)", dataType = "String", paramType = "query", example = ""), |
| | | @ApiImplicitParam(name = "srid", value = "空间引用标识符", dataType = "Integer", paramType = "query", example = "4326"), |
| | | @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1"), |
| | | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10") |
| | | }) |
| | | @GetMapping(value = "/selectByPage") |
| | | public ResponseMsg<List<Object>> selectByPage(String name, Integer pageIndex, Integer pageSize) { |
| | | public ResponseMsg<List<Object>> selectByPage(String name, String filter, String wkt, Integer srid, Integer pageIndex, Integer pageSize) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("每页页数或分页数小于1", null); |
| | | } |
| | | if (StringHelper.isEmpty(name)) { |
| | | return fail("名称空间和实体名称不能为空", null); |
| | | } |
| | | |
| | | Object obj = ClassHelper.getBean(name.trim() + "Mapper"); |
| | | if (!(obj instanceof BaseMapper)) { |
| | | BaseMapper baseMapper = baseQueryService.getBaseMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | BaseMapper baseMapper = (BaseMapper) obj; |
| | | QueryWrapper<Object> wrapper = new QueryWrapper<>(); |
| | | baseQueryService.addFilterWrapper(wrapper, filter); |
| | | baseQueryService.addGeomWrapper(baseMapper, wrapper, wkt, srid); |
| | | |
| | | Page<Object> page = new Page<>(pageIndex, pageSize); |
| | | page.addOrder(OrderItem.asc("gid")); |
| | | |
| | | IPage<Object> paged = baseMapper.selectPage(page, null); |
| | | IPage<Object> paged = baseMapper.selectPage(page, wrapper); |
| | | |
| | | return success(paged.getTotal(), paged.getRecords()); |
| | | } catch (Exception ex) { |
| | |
| | | @GetMapping(value = "/selectWktById") |
| | | public ResponseMsg<String> selectWktById(String name, Integer gid) { |
| | | try { |
| | | if (StringHelper.isEmpty(name)) { |
| | | return fail("名称空间和实体名称不能为空", null); |
| | | } |
| | | |
| | | Object obj = ClassHelper.getBean(name.trim() + "Mapper"); |
| | | if (!(obj instanceof GeomBaseMapper)) { |
| | | GeomBaseMapper baseMapper = baseQueryService.getGeoBaseMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | GeomBaseMapper baseMapper = (GeomBaseMapper) obj; |
| | | String wkt = baseMapper.selectWktById(gid); |
| | | if (!StringHelper.isEmpty(wkt)) { |
| | | wkt = AesHelper.encrypt(wkt); |