Commit 857eb218 authored by suhuiguang's avatar suhuiguang

1.权限接口

parent d453edfd
package com.yeejoin.amos.maintenance.business.feign;
import feign.codec.Encoder;
import feign.codec.ErrorDecoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -22,4 +23,9 @@ public class FeignConfiguration {
public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {
return new FeignBasicAuthRequestInterceptor();
}
@Bean
public FeignErrorDecoder errorDecoder(){
return new FeignErrorDecoder();
}
}
package com.yeejoin.amos.maintenance.business.feign;
import feign.Response;
import feign.Util;
import feign.codec.ErrorDecoder;
import java.io.IOException;
/**
* @author DELL
*/
public class FeignErrorDecoder implements ErrorDecoder {
@Override
public Exception decode(String s, Response response) {
String msg = null;
try {
msg = Util.toString(response.body().asReader());
} catch (IOException e) {
e.printStackTrace();
}
throw new RuntimeException(msg);
}
}
package com.yeejoin.amos.maintenance.business.feign;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
/**
* @author DELL
*/
@FeignClient(name = "${jcs.fegin.name}",configuration = FeignConfiguration.class)
public interface JCSFeignClient {
/**
* 查询用户单位信息
* @param userId 用户id
* @return ResponseModel<ReginParams.PersonIdentity>
*/
@GetMapping(value = "jcs/org-usr/{userId}/userUnit")
ResponseModel<ReginParams.PersonIdentity> getUserUnit(@PathVariable String userId);
}
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.maintenance.business.feign.JCSFeignClient;
import com.yeejoin.amos.maintenance.exception.PermissionException;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
......@@ -14,6 +15,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ResponseBody;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
/**
* @author DELL
......@@ -26,31 +28,23 @@ public class PersonIdentifyAspect {
@Autowired
RedisUtils redisUtils;
@Autowired
JCSFeignClient jcsFeignClient;
@Before(value = "@annotation(com.yeejoin.amos.maintenance.core.framework.PersonIdentify) && @annotation(permission)")
public void personIdentity(JoinPoint joinPoint, PersonIdentify permission) throws PermissionException {
ReginParams reginParam = JSON.parseObject(redisUtils.get(buildKey(RequestContext.getToken())).toString(), ReginParams.class);
if (permission.isNeedIdentity() && reginParam != null) {
//调用jcs,进行人员身份判断,是维保公司人员还是业主单位人员
// JSONObject result = new JSONObject();
// String identityType = result.get("identityType").toString();
// String personSeq = result.get("personSeq").toString();
// String personName = result.get("personName").toString();
// String companyId = result.get("companyId").toString();
// String companyName = result.get("companyName").toString();
String identityType = "1";
String personSeq = "1421016571081420802";
String personName = "SHG";
String companyId = "1420727427956502529";
String companyName ="机电公司";
ReginParams.PersonIdentity personIdentity = new ReginParams.PersonIdentity();
personIdentity.setIdentityType(identityType);
personIdentity.setPersonSeq(personSeq);
personIdentity.setPersonName(personName);
personIdentity.setCompanyId(companyId);
personIdentity.setCompanyName(companyName);
reginParam.setPersonIdentity(new ReginParams.PersonIdentity());
String userId = reginParam.getUserModel().getUserId();
ResponseModel<ReginParams.PersonIdentity> responseModel = jcsFeignClient.getUserUnit(userId);
if (responseModel != null) {
ReginParams.PersonIdentity personIdentity = responseModel.getResult();
reginParam.setPersonIdentity(personIdentity);
redisUtils.set(buildKey(RequestContext.getToken()), JSONObject.toJSONString(reginParam));
} else {
throw new RuntimeException("用户信息校验失败");
}
}
}
......
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