| | |
| | | import com.lf.server.helper.ClassHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.all.GeomBaseMapper; |
| | | import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | |
| | | * @param wrapper |
| | | * @param filter |
| | | */ |
| | | public void addFilterWrapper(QueryWrapper<Object> wrapper, String filter) { |
| | | public void addFilterWrapper(QueryWrapper wrapper, String filter) { |
| | | if (StringHelper.isEmpty(filter)) { |
| | | return; |
| | | } |
| | | |
| | | String[] strs = filter.trim().split(" (?i)and "); |
| | | for (String str : strs) { |
| | | int start = str.indexOf(" "); |
| | | if (start == -1) { |
| | | continue; |
| | | } |
| | | int end = str.indexOf(" ", start + 1); |
| | | if (end == -1) { |
| | | continue; |
| | | } |
| | | |
| | | String field = str.substring(0, start).trim(); |
| | | String express = str.substring(start + 1, end).trim().toLowerCase(); |
| | | String value = str.substring(end + 1).trim(); |
| | | |
| | | addWrapper(wrapper, field, express, getObjectVal(value)); |
| | | } |
| | | } |
| | | |
| | | private Object getObjectVal(String value) { |
| | | if (StringHelper.isInteger(value)) { |
| | | return Long.parseLong(value); |
| | | } |
| | | |
| | | if (StringHelper.isNumeric(value)) { |
| | | return Double.parseDouble(value); |
| | | } |
| | | |
| | | return value; |
| | | } |
| | | |
| | | private void addWrapper(QueryWrapper wrapper, String field, String express, Object value) { |
| | | switch (express) { |
| | | case "like": |
| | | wrapper.like(field, value); |
| | | break; |
| | | case ">": |
| | | wrapper.gt(field, value); |
| | | break; |
| | | case ">=": |
| | | wrapper.ge(field, value); |
| | | break; |
| | | case "<>": |
| | | wrapper.ne(field, value); |
| | | break; |
| | | case "=": |
| | | wrapper.eq(field, value); |
| | | break; |
| | | case "<": |
| | | wrapper.lt(field, value); |
| | | break; |
| | | case "<=": |
| | | wrapper.le(field, value); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | |
| | | * @param srid 空间引用标识符 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public void addGeomWrapper(BaseMapper baseMapper, QueryWrapper<Object> wrapper, String wkt, Integer srid) throws Exception { |
| | | public void addGeomWrapper(BaseMapper baseMapper, QueryWrapper wrapper, String wkt, Integer srid) throws Exception { |
| | | if (baseMapper instanceof GeomBaseMapper && !StringHelper.isEmpty(wkt) && srid != null) { |
| | | wkt = AesHelper.decrypt(wkt); |
| | | wrapper.apply(String.format("ST_Intersects(geom, ST_PolygonFromText('%s', %d))", wkt, srid)); |