提交 84b9d1fb 编写于 作者: sq3536's avatar sq3536

系统资源同步

上级 2d979d41
...@@ -7,14 +7,13 @@ import ${pub.getPKGCodeName()}.util.security.AuthenticationUser; ...@@ -7,14 +7,13 @@ import ${pub.getPKGCodeName()}.util.security.AuthenticationUser;
import ${pub.getPKGCodeName()}.util.security.AuthorizationLogin; import ${pub.getPKGCodeName()}.util.security.AuthorizationLogin;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.util.Map;
@Component @Component
public class IBZUAAFallback implements IBZUAAFeignClient { public class IBZUAAFallback implements IBZUAAFeignClient {
@Override @Override
public JSONObject pushSystemPermissionData(Map<String, Object> systemPermissionData, String systemId) { public boolean pushSystemPermissionData(String systemid,JSONObject systemPermissionData) {
return null; return false;
} }
@Override @Override
......
...@@ -8,19 +8,18 @@ import ${pub.getPKGCodeName()}.util.security.AuthorizationLogin; ...@@ -8,19 +8,18 @@ import ${pub.getPKGCodeName()}.util.security.AuthorizationLogin;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.util.Map;
@FeignClient(value = "ibzuaa-api",fallback = IBZUAAFallback.class) @FeignClient(value = "ibzuaa-api",fallback = IBZUAAFallback.class)
public interface IBZUAAFeignClient public interface IBZUAAFeignClient
{ {
/** /**
* 推送系统权限数据到uaa * 推送系统权限数据到uaa
* @param systemid
* @param systemPermissionData * @param systemPermissionData
* @param systemId
* @return * @return
*/ */
@PostMapping("/uaa/permission/save") @PostMapping("/syspssystems/{systemid}/permissiondata")
JSONObject pushSystemPermissionData(@RequestBody Map<String, Object> systemPermissionData, @RequestParam("systemid") String systemId); boolean pushSystemPermissionData(@PathVariable("systemid") String systemid,@RequestBody JSONObject systemPermissionData);
/** /**
* 用户登录 * 用户登录
......
...@@ -4,60 +4,50 @@ TARGET=PSSYSTEM ...@@ -4,60 +4,50 @@ TARGET=PSSYSTEM
<#assign sid = sys.getName()/> <#assign sid = sys.getName()/>
package ${pub.getPKGCodeName()}.util.job; package ${pub.getPKGCodeName()}.util.job;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import ${pub.getPKGCodeName()}.util.client.IBZUAAFeignClient; import ${pub.getPKGCodeName()}.util.client.IBZUAAFeignClient;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.io.IOException;
/** /**
* 权限:向uaa同步当前系统菜单、权限资源任务类 * 权限:向uaa同步当前系统菜单、权限资源任务类
*/ */
//@Component //开启此类需要保证Main中开启了feign EnableFeignClients @Slf4j
@Component
@ConditionalOnProperty( name = "ibiz.enablePermissionValid", havingValue = "true")
public class PermissionSyncJob implements ApplicationRunner { public class PermissionSyncJob implements ApplicationRunner {
private Log log = LogFactory.getLog(PermissionSyncJob.class);
@Autowired @Autowired
@Lazy
private IBZUAAFeignClient client; private IBZUAAFeignClient client;
@Value("${r'${ibiz.enablePermissionValid:false}'}")
boolean enablePermissionValid; //是否开启权限校验
@Value("${r'$'}{ibiz.systemid:${sid}}") @Value("${r'$'}{ibiz.systemid:${sid}}")
private String systemId; private String systemId;
@Override @Override
public void run(ApplicationArguments args) { public void run(ApplicationArguments args) {
if(enablePermissionValid){
try { try {
Thread.sleep(10000);
InputStream permission= this.getClass().getResourceAsStream("/permission/systemResource.json"); //获取当前系统所有实体资源能力 InputStream permission= this.getClass().getResourceAsStream("/permission/systemResource.json"); //获取当前系统所有实体资源能力
String permissionResult = IOUtils.toString(permission,"UTF-8"); String permissionResult = IOUtils.toString(permission,"UTF-8");
JSONObject jsonNodePermission = JSONObject.parseObject(permissionResult); if(client.pushSystemPermissionData(systemId,JSONObject.parseObject(permissionResult))){
Map<String,Object> map=new HashMap<>();
map.put("permission",jsonNodePermission);
JSONObject syncResult=client.pushSystemPermissionData(map,systemId);
if(syncResult.getInteger("code")==1){
log.info("向[UAA]同步系统资源成功"); log.info("向[UAA]同步系统资源成功");
}else{ }else{
log.info(String.format("向[UAA]同步系统资源失败,失败原因为[%s]",syncResult.getString("msg"))); log.info(String.format("向[UAA]同步系统资源失败"));
} }
} }
catch (Exception ex) { catch (Exception ex) {
log.error(String.format("向[UAA]同步系统资源失败,请检查[UAA]服务是否正常! [%s]",ex)); log.error(String.format("向[UAA]同步系统资源失败,请检查[UAA]服务是否正常! [%s]",ex));
} }
} }
}
} }
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册