Przeglądaj źródła

添加feign服务

wangchangsheng 2 lat temu
rodzic
commit
7784371686

+ 5 - 0
ims-service/ims-eval/pom.xml

@@ -55,6 +55,11 @@
             <artifactId>apm-toolkit-logback-1.x</artifactId>
             <version>8.5.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.netflix.feign</groupId>
+            <artifactId>feign-jackson</artifactId>
+            <version>8.18.0</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

+ 23 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/config/ImaConfig.java

@@ -0,0 +1,23 @@
+package com.ims.eval.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "iam")
+public class ImaConfig {
+
+	/**网关网址 **/
+	private String gatewayUrl;
+
+
+	public String getGatewayUrl() {
+		return gatewayUrl;
+	}
+
+	public void setGatewayUrl(String gatewayUrl) {
+		this.gatewayUrl = gatewayUrl;
+	}
+}

+ 35 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/controller/UserController.java

@@ -1,8 +1,10 @@
 package com.ims.eval.controller;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.ims.eval.entity.dto.result.R;
 import com.ims.eval.entity.Myuser;
+import com.ims.eval.feign.RemoteServiceBuilder;
 import com.ims.eval.service.IUserService;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +28,39 @@ public class UserController {
 	@Autowired
 	private IUserService userService;
 
+	@Autowired
+	private RemoteServiceBuilder remoteServiceBuilder;
+
+	/**
+	 * 查询所有数据
+
+	 * @return
+	 */
+	//@ImsPreAuth("eval:organizationEvaluationRule:view")
+	@GetMapping(value = "getSysUser")
+	public JSONObject getSysUser(
+		@RequestParam(value = "code", required = false) String code) {
+		JSONObject json = remoteServiceBuilder.getGatewayUrl().getSysUser(code);
+		return json;
+	}
+
+
+	/**
+	 * 查询所有数据
+
+	 * @return
+	 */
+	//@ImsPreAuth("eval:organizationEvaluationRule:view")
+	@GetMapping(value = "getCodeByToken")
+	public JSONObject getCodeByToken(
+		@RequestParam(value = "token", required = false) String token) {
+		JSONObject json = remoteServiceBuilder.getGatewayUrl().getCodeByToken(token);
+		return json;
+	}
+
+
+
+
 
 	//@ImsPreAuth("eval:dataDictionary:edit")
 	@PostMapping(value = "/save")

+ 32 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/feign/IGatewayUrlService.java

@@ -0,0 +1,32 @@
+package com.ims.eval.feign;
+
+import com.alibaba.fastjson.JSONObject;
+import feign.Headers;
+import feign.Param;
+import feign.RequestLine;
+
+/**
+ * 访问远程接口服务
+ */
+public interface IGatewayUrlService {
+
+
+	/**
+	 * 通过登录code获取用户
+	 * @param code
+	 * @return
+	 */
+	@Headers({"Content-Type: application/json", "Accept: application/json"})
+	@RequestLine("POST /ims-idms/sysuser/getSysUser?code={code}")
+	JSONObject getSysUser(@Param(value = "code") String code);
+
+
+	/**
+	 * 通过token获取业务code
+	 * @param token
+	 * @return
+	 */
+	@Headers({"Content-Type: application/json", "Accept: application/json"})
+	@RequestLine("POST /ims-idms/usersession/getCodeByToken?token={token}")
+	JSONObject getCodeByToken(@Param(value = "token") String token);
+}

+ 31 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/feign/RemoteServiceBuilder.java

@@ -0,0 +1,31 @@
+package com.ims.eval.feign;
+
+import com.ims.eval.config.ImaConfig;
+import feign.Feign;
+import feign.Request;
+import feign.Retryer;
+import feign.jackson.JacksonDecoder;
+import feign.jackson.JacksonEncoder;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class RemoteServiceBuilder {
+
+	@Autowired
+	private ImaConfig imaConfig;
+
+	@Bean
+	public IGatewayUrlService getGatewayUrl() {
+		return Feign.builder()
+			.encoder(new JacksonEncoder())
+			.decoder(new JacksonDecoder())
+			.options(new Request.Options(5000, 600000))
+			.retryer(new Retryer.Default(10000, 10000, 3))
+			.target(IGatewayUrlService.class, imaConfig.getGatewayUrl());
+	}
+
+}

+ 30 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/IUserService.java

@@ -1,5 +1,6 @@
 package com.ims.eval.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.ims.eval.entity.Myuser;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -17,4 +18,33 @@ public interface IUserService extends IService<Myuser> {
 
 	List<Myuser> listAll(String id, String orgId,String unitId);
 
+
+	/**
+	 * 通过用户名密码查询一个用户
+	 * @param username
+	 * @return
+	 */
+	Myuser getUser(String username);
+
+
+	/**
+	 * 更新用户
+	 * @param user
+	 * @return
+	 */
+	void updateUser(Myuser user);
+
+	/**
+	 * 通过code获取user
+	 * @param code
+	 * @return
+	 */
+	JSONObject getSysUser(String code);
+	/**
+	 * 通过token获取code
+	 * @param token
+	 * @return
+	 */
+	JSONObject getCodeByToken(String token);
+
 }

+ 34 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/UserServiceImpl.java

@@ -1,12 +1,14 @@
 package com.ims.eval.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ims.common.utils.StringUtils;
 import com.ims.eval.entity.Myuser;
 import com.ims.eval.dao.UserMapper;
-import com.ims.eval.entity.PersonnelEvaluationRule;
+import com.ims.eval.feign.RemoteServiceBuilder;
 import com.ims.eval.service.IUserService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -22,6 +24,9 @@ import java.util.List;
 @Service
 public class UserServiceImpl extends ServiceImpl<UserMapper, Myuser> implements IUserService {
 
+	@Autowired
+	private RemoteServiceBuilder remoteServiceBuilder;
+
 	@Override
 	public List<Myuser> listAll(String id, String orgId,String unitId) {
 
@@ -43,4 +48,32 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, Myuser> implements
 
 		return list;
 	}
+
+	@Override
+	public Myuser getUser(String username) {
+		QueryWrapper<Myuser> qw = new QueryWrapper<>();
+		qw.lambda().eq(Myuser::getLoginName,username);
+		List<Myuser> list = baseMapper.selectList(qw);
+		if(list.size()<=0){
+			return null;
+		}
+		return list.get(0);
+	}
+
+	@Override
+	public void updateUser(Myuser user) {
+		super.saveOrUpdate(user);
+	}
+
+	@Override
+	public JSONObject getSysUser(String code) {
+		JSONObject json = remoteServiceBuilder.getGatewayUrl().getSysUser(code);
+		return json;
+	}
+
+	@Override
+	public JSONObject getCodeByToken(String token) {
+		JSONObject json = remoteServiceBuilder.getGatewayUrl().getCodeByToken(token);
+		return json;
+	}
 }

+ 4 - 0
ims-service/ims-eval/src/main/resources/application.yml

@@ -14,3 +14,7 @@ spring:
       httpclient:
         connect-timeout: 1000
         response-timeout: 5s
+
+
+iam:
+  gateway-url: http://10.65.78.23:18600/