| New file |
| | |
| | | package org.springblade.common.param; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.cache.SysCache; |
| | | import org.springblade.common.utils.AuthUtils; |
| | | import org.springblade.common.utils.SpringUtils; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.modules.grid.entity.GridEntity; |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.modules.police.entity.PoliceAffairsGridEntity; |
| | | import org.springblade.modules.police.service.IPoliceAffairsGridService; |
| | | import org.springblade.modules.system.service.IRegionService; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class GridSet<T> { |
| | | |
| | | |
| | | /** |
| | | * 获取警格网格的信息 |
| | | * @param clazz 类对象 |
| | | * @param t 对象数据 |
| | | * @param lngKey 经度属性key |
| | | * @param latKey 纬度属性key |
| | | * @param gridCodeKey 网格属性key |
| | | * @param jwGirdCodeKey 警格属性key |
| | | * @param <U> |
| | | * @return |
| | | */ |
| | | public <U> GridSet invoke(Class<U> clazz, T t,String lngKey,String latKey,String gridCodeKey,String jwGirdCodeKey) { |
| | | //获取传入对象信息 |
| | | U u = clazz.cast(t); |
| | | try { |
| | | Field lngField = null; |
| | | Field latField = null; |
| | | try { |
| | | lngField = u.getClass().getDeclaredField(lngKey); |
| | | latField = u.getClass().getDeclaredField(latKey); |
| | | } catch (NoSuchFieldException e) { |
| | | lngField = u.getClass().getSuperclass().getDeclaredField(lngKey); |
| | | latField = u.getClass().getSuperclass().getDeclaredField(latKey); |
| | | } |
| | | // 获取点信息 |
| | | lngField.setAccessible(true); |
| | | latField.setAccessible(true); |
| | | String lng = lngField.get(t).toString(); |
| | | String lat = latField.get(t).toString(); |
| | | if (!Strings.isBlank(lng)) { |
| | | // 拼接点 |
| | | String point = "'POINT(" + lng +" " + lat + ")'"; |
| | | // 判断是否分析网格 |
| | | if (!Strings.isBlank(gridCodeKey)) { |
| | | // 根据位置设置网格,警格编号 |
| | | IGridService gridService = SpringUtils.getBean(IGridService.class); |
| | | Field gridCodeField = null; |
| | | try { |
| | | gridCodeField = u.getClass().getDeclaredField(gridCodeKey); |
| | | } catch (NoSuchFieldException e) { |
| | | gridCodeField = u.getClass().getSuperclass().getDeclaredField(gridCodeKey); |
| | | } |
| | | //点坐标解析网格 |
| | | List<GridEntity> gridEntityList = gridService.spatialAnalysis(point); |
| | | if (gridEntityList.size() > 0) { |
| | | GridEntity gridEntity = gridEntityList.get(0); |
| | | gridCodeField.setAccessible(true); |
| | | gridCodeField.set(t, gridEntity.getGridCode()); |
| | | } |
| | | } |
| | | // 判断是否分析警格 |
| | | if (!Strings.isBlank(jwGirdCodeKey)) { |
| | | IPoliceAffairsGridService policeAffairsGridService = SpringUtils.getBean(IPoliceAffairsGridService.class); |
| | | Field jwGridCodeField = null; |
| | | try { |
| | | jwGridCodeField = u.getClass().getDeclaredField(jwGirdCodeKey); |
| | | } catch (NoSuchFieldException e) { |
| | | jwGridCodeField = u.getClass().getSuperclass().getDeclaredField(jwGirdCodeKey); |
| | | } |
| | | //点坐标解析警格 |
| | | List<PoliceAffairsGridEntity> policeAffairsGridEntityList = policeAffairsGridService.spatialAnalysis(point); |
| | | if (policeAffairsGridEntityList.size() > 0) { |
| | | PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridEntityList.get(0); |
| | | jwGridCodeField.setAccessible(true); |
| | | jwGridCodeField.set(t, policeAffairsGridEntity.getJwGridCode()); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | | |
| | | } |