Commit bcc0ebf2 authored by suhuiguang's avatar suhuiguang

1.校验

parent 25b5de69
...@@ -102,6 +102,7 @@ public class ControllerAop { ...@@ -102,6 +102,7 @@ public class ControllerAop {
urls.add("^/tcm/flc-unit-info/verifyTelCode/[A-Za-z0-9]+/[A-Za-z0-9]+"); urls.add("^/tcm/flc-unit-info/verifyTelCode/[A-Za-z0-9]+/[A-Za-z0-9]+");
urls.add("^/tcm/flc-unit-info/hasExistUser/[A-Za-z0-9_-]+"); urls.add("^/tcm/flc-unit-info/hasExistUser/[A-Za-z0-9_-]+");
urls.add("/tcm/reg-unit-info/save"); urls.add("/tcm/reg-unit-info/save");
urls.add("/ymt/equipment-category/viewJgAll");
// 获取请求路径 // 获取请求路径
for (String uri : urls) { for (String uri : urls) {
Pattern p = Pattern.compile(uri); Pattern p = Pattern.compile(uri);
......
package com.yeejoin.amos.boot.module.ymt.biz.permission;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.module.ymt.biz.utils.RedisUtil;
import com.yeejoin.amos.component.feign.utils.FeignUtil;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.Bean;
import javax.annotation.Resource;
import java.util.List;
/**
* @author Administrator
*/
@Component
public class PermissionOfUser {
@Autowired
RedissonClient redissonClient;
@Autowired
RedisUtil redisUtil;
private static final String LOCK_KEY = "PERMISSION_SET_KEY";
public ReginParams getSelectedOrgInfo() {
ReginParams reginParams = new ReginParams();
String userId = RequestContext.getExeUserId();
String prefix = "REGIN_PARAM_" + userId + "_";
String reginParamKey = prefix + RequestContext.getToken();
if (redisUtil.hasKey(reginParamKey)) {
reginParams = JSON.parseObject(redisUtil.get(reginParamKey).toString(), ReginParams.class);
} else {
RLock lock = redissonClient.getLock(LOCK_KEY);
try {
lock.lock();
if (redisUtil.hasKey(reginParamKey)) {
reginParams = JSON.parseObject(redisUtil.get(reginParamKey).toString(), ReginParams.class);
} else {
this.deleteOldKey(prefix);
List<CompanyModel> companyModels = FeignUtil.remoteCall(() -> Privilege.companyClient.queryListByChild(userId));
if (companyModels != null && !companyModels.isEmpty()) {
CompanyBo companyBo = new CompanyBo();
Bean.copyExistPropertis(companyModels.get(0), companyBo);
AgencyUserModel agencyUserModel = new AgencyUserModel();
agencyUserModel.setUserId(userId);
agencyUserModel.setCompanys(companyModels);
reginParams.setCompany(companyBo);
reginParams.setUserModel(agencyUserModel);
redisUtil.set(reginParamKey,JSON.toJSONString(reginParams),24 * 60 * 60L);
}
}
} finally {
lock.unlock();
}
}
return reginParams;
}
/**
* 删除redis 里面登录过期的key
* @param prefix redis前缀
*/
private void deleteOldKey(String prefix) {
redisUtil.getAndDeletePatternKeys(prefix + "*");
}
}
...@@ -20,6 +20,7 @@ import com.yeejoin.amos.boot.module.ymt.api.service.IEquipmentCategoryService; ...@@ -20,6 +20,7 @@ import com.yeejoin.amos.boot.module.ymt.api.service.IEquipmentCategoryService;
import com.yeejoin.amos.boot.module.ymt.api.vo.EquipExportVo; import com.yeejoin.amos.boot.module.ymt.api.vo.EquipExportVo;
import com.yeejoin.amos.boot.module.ymt.biz.dao.ESEquipmentCategory; import com.yeejoin.amos.boot.module.ymt.biz.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.ymt.biz.permission.PermissionOfUser;
import com.yeejoin.amos.boot.module.ymt.biz.utils.JsonUtils; import com.yeejoin.amos.boot.module.ymt.biz.utils.JsonUtils;
import com.yeejoin.amos.boot.module.ymt.flc.api.feign.IdxFeignService; import com.yeejoin.amos.boot.module.ymt.flc.api.feign.IdxFeignService;
import com.yeejoin.amos.boot.module.ymt.flc.api.feign.PrivilegeFeginService; import com.yeejoin.amos.boot.module.ymt.flc.api.feign.PrivilegeFeginService;
...@@ -121,6 +122,11 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -121,6 +122,11 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
@Autowired @Autowired
private RedisUtils redisUtils; private RedisUtils redisUtils;
@Autowired
PermissionOfUser permissionOfUser;
//管辖机构redis缓存key //管辖机构redis缓存key
private static final String REGULATOR_UNIT_TREE = "REGULATOR_UNIT_TREE"; private static final String REGULATOR_UNIT_TREE = "REGULATOR_UNIT_TREE";
//行政区划redis缓存key //行政区划redis缓存key
...@@ -591,10 +597,8 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -591,10 +597,8 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
public List<JSONObject> getCompanyType() { public List<JSONObject> getCompanyType() {
ReginParams reginParams = permissionOfUser.getSelectedOrgInfo();
ReginParams reginParams = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
List<CompanyModel> companys = reginParams.getUserModel().getCompanys(); List<CompanyModel> companys = reginParams.getUserModel().getCompanys();
List<JSONObject> objectList = new ArrayList<>(); List<JSONObject> objectList = new ArrayList<>();
for (CompanyModel company : companys) { for (CompanyModel company : companys) {
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
...@@ -1245,7 +1249,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -1245,7 +1249,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
} }
public Page<JSONObject> queryByKeys(JSONObject map) { public Page<JSONObject> queryByKeys(JSONObject map) {
// //根据当前登录人查询 //根据当前登录人查询
if (!ValidationUtil.isEmpty(map.get(EQUSTATE))) { if (!ValidationUtil.isEmpty(map.get(EQUSTATE))) {
map.put(EQUSTATE, EquimentEnum.getCode.get(map.get(EQUSTATE).toString()).toString()); map.put(EQUSTATE, EquimentEnum.getCode.get(map.get(EQUSTATE).toString()).toString());
} }
......
...@@ -565,4 +565,12 @@ public class RedisUtil { ...@@ -565,4 +565,12 @@ public class RedisUtil {
return 0; return 0;
} }
} }
public Long getAndDeletePatternKeys(String pattern) {
Set<String> keys = redisTemplate.keys(pattern);
if (!CollectionUtils.isEmpty(keys)) {
return redisTemplate.delete(keys);
}
return null;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment