Commit a7a49398 authored by zhangsen's avatar zhangsen

API 权限-》接口优化

parent 6078eab7
package com.yeejoin.amos.fas.core.util;
/**
* @description:
* @author: tw
* @createDate: 2021/6/22
* redis key
*/
public class RedisKey {
/**根据动态表单code获取动态表单列表*/
public static final String FORM_CODE = "form_code_";
/**根据字典code获取数据字典列表*/
public static final String DATA_DICTIONARY_CODE= "data_dictionary_code_";
/**根据字典code获取数据字典列表*/
public static final String DATA_DICTIONARY_CODE_XIN= "data_dictionary_code_xin_";
/**根据id获取消防人员基本信息*/
public static final String FIREFIGHTERS_ID="firefighters_id_";
/**根据id获取消防人员列表基本信息*/
public static final String FIREFIGHTERS_LIST_ID="firefighters_id_list_";
/**根据消防人员id查询岗位学历信息工作经历*/
public static final String EDUCATION_POST_EXPERIENCE_FIREFIGHTERS_ID="education_post_experience_firefighters_id_";
/**根据合同信id 查询合同信息*/
public static final String CONTRACT_ID="contract_id_";
/**根据思想状况信息id 查询思想信息*/
public static final String THOUGHT_ID="thought_id_";
/**根据警情id查询警情详情记录*/
public static final String ALERTCALLED_ID="alertcalled_id_";
/**特种设备根据警情id查询警情详情记录*/
public static final String TZS_ALERTCALLED_ID="tzs_alertcalled_id_";
/**联通CTI token */
public static final String CTI_TOKEN = "cti_token";
/**微信公众平台 token */
public static final String WECHAT_TOKEN = "wechat_token";
/**微信公众平台 token */
public static final String WECHAT_JS_TOKEN = "wechat_js_token";
/**警情联系人*/
public static final String CONTACT_USER = "contact_user";
/**联通CTIuser token */
public static final String CTI_USER_TOKEN = "cti_user_token";
/** 企业用户注册前缀 */
public static final String FLC_USER_TEL = "flc_tel_";
/** 驼峰转下划线(简单写法,效率低于 ) */
public static String humpToLine(String str) {
return str.replaceAll("[A-Z]", "_$0").toLowerCase();
}
/**
* 用户新缓存前缀
*/
public static final String REGION_REDIS_PREFIX = "biz_";
/**
* 创建区域key
* @param token 权限
* @return String
*/
public static String buildReginKey(String userId, String token) {
return REGION_REDIS_PREFIX + userId + "_" + token;
}
/**
* 模糊重新区域key
* @param token 权限
* @return String
*/
public static String buildPatternKey(String token) {
return REGION_REDIS_PREFIX + "*" + "_" + token;
}
/**
* 判断str1中包含str2的个数
* @param str1
* @param str2
* @return counter
*/
public static int countStr(String str1, String str2) {
int counter=0;
if (str1.indexOf(str2) == -1) {
return 0;
} else if (str1.indexOf(str2) != -1) {
counter++;
countStr(str1.substring(str1.indexOf(str2) +
str2.length()), str2);
return counter;
}
return 0;
}
}
...@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -716,7 +717,16 @@ public class RiskSourceController extends BaseController { ...@@ -716,7 +717,16 @@ public class RiskSourceController extends BaseController {
@ApiOperation(httpMethod = "GET", value = "初始化預案水資源", notes = "初始化預案水資源") @ApiOperation(httpMethod = "GET", value = "初始化預案水資源", notes = "初始化預案水資源")
@RequestMapping(value = "/contingency/water", produces = "application/json;charset=UTF-8", method = RequestMethod.GET) @RequestMapping(value = "/contingency/water", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
public CommonResponse queryContingencyWater() { public CommonResponse queryContingencyWater() {
return CommonResponseUtil.success(riskSourceService.queryContingencyWater()); String bizOrgCode = null;
ReginParams reginParams = getSelectedOrgInfo();
ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
if (!ValidationUtil.isEmpty(personIdentity)) {
bizOrgCode = personIdentity.getBizOrgCode();
}
if (StringUtils.isEmpty(bizOrgCode)) {
return CommonResponseUtil.success(null);
}
return CommonResponseUtil.success(riskSourceService.queryContingencyWater(bizOrgCode));
} }
/** /**
......
...@@ -94,7 +94,7 @@ public interface RiskSourceMapper extends BaseMapper { ...@@ -94,7 +94,7 @@ public interface RiskSourceMapper extends BaseMapper {
List<RiskSourceTreeResponse> getCheckPointRiskSource(); List<RiskSourceTreeResponse> getCheckPointRiskSource();
List<FormInstanceVo> queryContingencyWater(); List<FormInstanceVo> queryContingencyWater(@Param("bizOrgCode") String bizOrgCode);
List<Map> queryFmeaByPointId(@Param("pointId") Long pointId); List<Map> queryFmeaByPointId(@Param("pointId") Long pointId);
......
package com.yeejoin.amos.fas.business.feign;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
/**
* @author DELL
*/
@FeignClient(name = "${jcs.fegin.name}", path = "jcs", configuration = {FeignConfiguration.class})
public interface JcsFeign {
/**
* 查询用户单位信息
*
* @param id 用户id
* @return ResponseModel<ReginParams.PersonIdentity>
*/
@GetMapping(value = "/org-person/getUser/{id}")
FeignClientResult selectById(@PathVariable String id);
}
\ No newline at end of file
...@@ -1407,8 +1407,8 @@ public class RiskSourceServiceImpl implements IRiskSourceService { ...@@ -1407,8 +1407,8 @@ public class RiskSourceServiceImpl implements IRiskSourceService {
// } // }
@Override @Override
public List<FormInstanceVo> queryContingencyWater() { public List<FormInstanceVo> queryContingencyWater(String bizOrgCode) {
List<FormInstanceVo> list = riskSourceMapper.queryContingencyWater(); List<FormInstanceVo> list = riskSourceMapper.queryContingencyWater(bizOrgCode);
for (FormInstanceVo map : list) { for (FormInstanceVo map : list) {
String iotCode = ""; String iotCode = "";
String maxlevel = ""; String maxlevel = "";
...@@ -1420,7 +1420,10 @@ public class RiskSourceServiceImpl implements IRiskSourceService { ...@@ -1420,7 +1420,10 @@ public class RiskSourceServiceImpl implements IRiskSourceService {
if (!ObjectUtils.isEmpty(map.getIotCode())) { if (!ObjectUtils.isEmpty(map.getIotCode())) {
iotCode = map.getIotCode(); iotCode = map.getIotCode();
} }
Object value = redisTemplate.opsForValue().get("WaterLevel:Value:" + iotCode); Object value = null;
if (StringUtil.isNotEmpty(iotCode)) {
value = redisTemplate.opsForValue().get("WaterLevel:Value:" + iotCode);
}
if (StringUtil.isNotEmpty(value)) { if (StringUtil.isNotEmpty(value)) {
maxlevel = value.toString(); maxlevel = value.toString();
volume = map.getVolume() != null && StringUtil.isNumeric(map.getVolume()) ? String.format("%.2f", (Double.valueOf(map.getVolume()))) : String.format("%.2f", Double.valueOf(value.toString()) * area); volume = map.getVolume() != null && StringUtil.isNumeric(map.getVolume()) ? String.format("%.2f", (Double.valueOf(map.getVolume()))) : String.format("%.2f", Double.valueOf(value.toString()) * area);
......
...@@ -151,7 +151,7 @@ public interface IRiskSourceService { ...@@ -151,7 +151,7 @@ public interface IRiskSourceService {
void queryContingencyDeviceStatus(ContingencyDeviceStatus contingencyDeviceStatus); void queryContingencyDeviceStatus(ContingencyDeviceStatus contingencyDeviceStatus);
List<FormInstanceVo> queryContingencyWater(); List<FormInstanceVo> queryContingencyWater(String bizOrgCode);
List<Map> queryFmeaByPointId(Long pointId); List<Map> queryFmeaByPointId(Long pointId);
......
...@@ -4,6 +4,7 @@ package com.yeejoin.amos.fas.business.vo; ...@@ -4,6 +4,7 @@ package com.yeejoin.amos.fas.business.vo;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
...@@ -14,13 +15,33 @@ public class ReginParams implements Serializable { ...@@ -14,13 +15,33 @@ public class ReginParams implements Serializable {
private CompanyBo company; private CompanyBo company;
private RoleBo role; private RoleBo role;
private DepartmentBo department; private DepartmentBo department;
@Deprecated
private String token; private String token;
private AgencyUserModel userModel; private AgencyUserModel userModel;
private PersonIdentity personIdentity;
@Data
public static class PersonIdentity implements Serializable {
private String identityType;
private String personSeq;
private String personName;
private String companyId;
private String companyName;
private String bizOrgCode;
private String companyBizOrgCode;
}
public PersonIdentity getPersonIdentity() {
return personIdentity;
}
public void setPersonIdentity(PersonIdentity personIdentity) {
this.personIdentity = personIdentity;
}
@Deprecated
public String getToken() { public String getToken() {
return token; return token;
} }
@Deprecated
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
} }
......
...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.component.feign.config.InnerInvokException; import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.config.TokenOperation; import com.yeejoin.amos.component.feign.config.TokenOperation;
import com.yeejoin.amos.component.feign.model.FeignClientResult; import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.fas.business.feign.JcsFeign;
import com.yeejoin.amos.fas.business.feign.RemoteSecurityService; import com.yeejoin.amos.fas.business.feign.RemoteSecurityService;
import com.yeejoin.amos.fas.business.vo.CompanyBo; import com.yeejoin.amos.fas.business.vo.CompanyBo;
import com.yeejoin.amos.fas.business.vo.DepartmentBo; import com.yeejoin.amos.fas.business.vo.DepartmentBo;
...@@ -24,12 +25,14 @@ import org.slf4j.Logger; ...@@ -24,12 +25,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.Bean;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
...@@ -48,6 +51,8 @@ public class PermissionAspect { ...@@ -48,6 +51,8 @@ public class PermissionAspect {
@Autowired @Autowired
private RemoteSecurityService remoteSecurityService; private RemoteSecurityService remoteSecurityService;
@Autowired
private JcsFeign jcsFeign;
// 前置通知,在方法执行之前 // 前置通知,在方法执行之前
@Before(value = "@annotation(Permission)") @Before(value = "@annotation(Permission)")
...@@ -83,6 +88,14 @@ public class PermissionAspect { ...@@ -83,6 +88,14 @@ public class PermissionAspect {
userId = userModel.getUserId(); userId = userModel.getUserId();
ReginParams reginParams = JSON.parseObject(redisTemplate.opsForValue().get(buildKey(userModel.getUserId(), token)), ReginParams.class); ReginParams reginParams = JSON.parseObject(redisTemplate.opsForValue().get(buildKey(userModel.getUserId(), token)), ReginParams.class);
if(reginParams == null && userModel.getCompanys().size() > 0){ if(reginParams == null && userModel.getCompanys().size() > 0){
if (userId != null) {
FeignClientResult responseModel = jcsFeign.selectById(userId);
if (ObjectUtils.isEmpty(responseModel.getResult()) || responseModel.getStatus() != HttpStatus.OK.value()) {
throw new RuntimeException(responseModel.getDevMessage());
}
ReginParams.PersonIdentity personIdentity = (ReginParams.PersonIdentity) Bean.mapToBean((Map<String, Object>) responseModel.getResult(), ReginParams.PersonIdentity.class);
regionParam.setPersonIdentity(personIdentity);
}
CompanyModel companyModel = userModel.getCompanys().get(0); CompanyModel companyModel = userModel.getCompanys().get(0);
List<DepartmentModel> deptList = remoteSecurityService.getDepartmentTreeByCompanyId(token, product, appKey, companyModel.getSequenceNbr().toString()); List<DepartmentModel> deptList = remoteSecurityService.getDepartmentTreeByCompanyId(token, product, appKey, companyModel.getSequenceNbr().toString());
CompanyBo companyBo = convertCompanyModelToBo(companyModel); CompanyBo companyBo = convertCompanyModelToBo(companyModel);
......
...@@ -111,4 +111,6 @@ outSystem.user.password=a1234560 ...@@ -111,4 +111,6 @@ outSystem.user.password=a1234560
privilege.fegin.name=AMOS-API-PRIVILEGE privilege.fegin.name=AMOS-API-PRIVILEGE
#预案指标配置 #预案指标配置
plan.index =ONL_OilDischargeDeviceOilPillowDischargeOpen,CAFS_CAFSFireGunEquipmentValveStatus,DCCP_DCCPStreamTransformerCharged,WSS_DelugeValve_Start,ONL_OilDischargeDeviceOilyPillowDischargeOpen plan.index =ONL_OilDischargeDeviceOilPillowDischargeOpen,CAFS_CAFSFireGunEquipmentValveStatus,DCCP_DCCPStreamTransformerCharged,WSS_DelugeValve_Start,ONL_OilDischargeDeviceOilyPillowDischargeOpen
\ No newline at end of file #JCS服务fegin调用
jcs.fegin.name=JCS
\ No newline at end of file
...@@ -719,6 +719,9 @@ ...@@ -719,6 +719,9 @@
r.resource_type IN ( 'pool', 'industryPool' ) r.resource_type IN ( 'pool', 'industryPool' )
AND r.is_delete = 1 AND r.is_delete = 1
AND ou.`code` IS NOT NULL AND ou.`code` IS NOT NULL
<if test="bizOrgCode != null and bizOrgCode != ''">
AND r.biz_org_code like concat (#{bizOrgCode},'%')
</if>
GROUP BY GROUP BY
r.sequence_nbr r.sequence_nbr
</select> </select>
......
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