| | |
| | | package org.springblade.common.param; |
| | | |
| | | import lombok.Data; |
| | | 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.core.tool.utils.StringUtil; |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | 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; |
| | | |
| | | import static org.springblade.core.secure.utils.AuthUtil.getUserRole; |
| | | |
| | | import java.util.Map; |
| | | @Data |
| | | public class CommonParamSet<T> { |
| | | /** |
| | | * 区域编号集合 |
| | |
| | | * 是否为超级管理员 |
| | | */ |
| | | private Integer isAdministrator; |
| | | |
| | | /** |
| | | * 社区编号 |
| | | */ |
| | | private String communityCode; |
| | | /** |
| | | * 网格编号集合 |
| | | */ |
| | | private List<String> gridCodeList = new ArrayList<>(); |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private String str = null; |
| | | |
| | | public List<String> getRegionChildCodesList() { |
| | | return regionChildCodesList; |
| | |
| | | return gridCodeList; |
| | | } |
| | | |
| | | public String getStr() { |
| | | return str; |
| | | } |
| | | |
| | | public String getCommunityCode() { |
| | | return communityCode; |
| | | } |
| | | |
| | | public <U> CommonParamSet invoke(Class<U> clazz, T t) { |
| | | //获取传入对象信息 |
| | | U u = clazz.cast(t); |
| | |
| | | // 获取请求头中的角色别名 |
| | | String roleName = SpringUtils.getRequestParam("roleName"); |
| | | // 获取请求头中的社区编号 |
| | | String communityCode = SpringUtils.getRequestParam("communityCode"); |
| | | communityCode = SpringUtils.getRequestParam("communityCode"); |
| | | if (!Strings.isBlank(communityCode)) { |
| | | // 校验社区编号是否合规 |
| | | if (null != SpringUtils.getBean(IRegionService.class).getById(communityCode)) { |
| | |
| | | } |
| | | |
| | | if (isAdministrator == 2) { |
| | | if (!Strings.isBlank(communityCode)) { |
| | | if (Strings.isNotBlank(communityCode)) { |
| | | // 请求头带了后直接使用过滤 |
| | | regionChildCodesList.add(communityCode); |
| | | }else { |
| | |
| | | regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId(), communityCode); |
| | | // 民警角色 |
| | | if (!Strings.isBlank(roleName) && roleName.equals("mj")) { |
| | | regionChildCodesList = SysCache.getPoliceRegionChildCodesByDeptId(AuthUtil.getDeptId(),communityCode); |
| | | regionChildCodesList = SysCache.getGridRegionChildCodesByDeptId(AuthUtil.getDeptId(),communityCode,roleName); |
| | | } |
| | | } |
| | | // 获取网格编号集合 |
| | |
| | | roleNameField.set(t, roleName); |
| | | // 网格员角色 |
| | | if (roleName.equals("wgy")) { |
| | | gridCodeList = SpringUtil.getBean(IGridService.class).getGridListByUserId(AuthUtil.getUserId()); |
| | | gridCodeList = SysCache.getGridRegionChildCodesByDeptId(AuthUtil.getDeptId(),communityCode,roleName); |
| | | } |
| | | } |
| | | // 特定账号设置 |
| | |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * 设置对应的属性值 |
| | | * @param clazz |
| | | * @param t |
| | | * @param list 字段属性集合 |
| | | * @param pre 字段拼接 |
| | | * @return |
| | | */ |
| | | public <U> CommonParamSet setFieldValue(Class<U> clazz, T t,List<String> list,String pre) { |
| | | //获取传入对象信息 |
| | | U u = clazz.cast(t); |
| | | try { |
| | | StringBuilder builder = new StringBuilder(pre); |
| | | for (String fieldName : list) { |
| | | if (!fieldName.equals("tableName")) { |
| | | if (fieldName.equals("tableId")) { |
| | | fieldName = "id"; |
| | | } |
| | | Field field = u.getClass().getDeclaredField(fieldName); |
| | | field.setAccessible(true); |
| | | builder.append(field.get(t).toString()).append(","); |
| | | } |
| | | } |
| | | String toString = builder.toString(); |
| | | str = toString.substring(0,toString.length()-1); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * 设置对应的属性值 |
| | | * @param clazz |
| | | * @param t |
| | | * @param list 字段属性集合 |
| | | * @param map |
| | | * @return |
| | | */ |
| | | public <U> CommonParamSet setFieldValueByMap(Class<U> clazz, T t, List<String> list, Map<String,Object> map) { |
| | | //获取传入对象信息 |
| | | U u = clazz.cast(t); |
| | | try { |
| | | for (String fieldName : list) { |
| | | if (!fieldName.equals("tableName")){ |
| | | if (fieldName.equals("tableId")){ |
| | | fieldName = "id"; |
| | | } |
| | | Field field = u.getClass().getDeclaredField(fieldName); |
| | | field.setAccessible(true); |
| | | String value = field.get(t).toString(); |
| | | if (fieldName.equals("id")){ |
| | | fieldName = "tableId"; |
| | | } |
| | | map.put(fieldName,value); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | | |
| | | } |