提交 084cc709 编写于 作者: zhouweidong's avatar zhouweidong

job逻辑优化

上级 126889db
......@@ -43,6 +43,7 @@ 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.util.ObjectUtils;
import org.springframework.util.DigestUtils;
import java.io.InputStream;
import java.util.*;
......@@ -55,33 +56,33 @@ import java.util.*;
@ConditionalOnProperty( name = "ibiz.enablePermissionValid", havingValue = "true")
public class PermissionSyncJob implements ApplicationRunner {
@Autowired
@Lazy
private IBZUAAFeignClient client;
@Value("${r'$'}{ibiz.systemid:${sid}}")
private String systemId;
@Value("${r'$'}{ibiz.systemname:${sname}}")
private String systemName;
@Autowired
@Lazy
private IBZUAAFeignClient client;
@Autowired
@Lazy
IBZLiteFeignClient liteFeignClient;
<#if hasWF>
@Autowired
@Lazy
private ${pub.getPKGCodeName()}.util.client.IBZWFFeignClient client2;
</#if>
<#if hasMsgTemplate>
@Autowired
@Lazy
private ${pub.getPKGCodeName()}.util.client.IBZNotifyFeignClient notifyFeignClient;
</#if>
@Autowired
@Lazy
IBZLiteFeignClient liteFeignClient;
<#if hasPredefinedCodeList>
@Autowired
@Lazy
${pub.getPKGCodeName()}.util.client.IBZDictFeignClient dictFeignClient;
......@@ -91,83 +92,97 @@ public class PermissionSyncJob implements ApplicationRunner {
public void run(ApplicationArguments args) {
try {
Thread.sleep(10000);
InputStream permission = this.getClass().getResourceAsStream("/permission/systemResource.json"); //获取当前系统所有实体资源能力
String permissionResult = IOUtils.toString(permission,"UTF-8");
JSONObject system= new JSONObject();
system.put("pssystemid",systemId);
system.put("pssystemname",systemName);
system.put("sysstructure",JSONObject.parseObject(permissionResult));
system.put("md5check",DigestUtils.md5DigestAsHex(permissionResult.getBytes()));
if(client.syncSysAuthority(system)) {
log.info("向[UAA]同步系统资源成功");
}else{
log.error("向[UAA]同步系统资源失败");
}
}
catch (Exception ex) {
log.error(String.format("向[UAA]同步系统资源失败,请检查[UAA]服务是否正常! [%s]",ex));
InputStream permission = this.getClass().getResourceAsStream("/permission/systemResource.json"); //权限资源
if (!ObjectUtils.isEmpty(permission)) {
String strPermission = IOUtils.toString(permission, "UTF-8");
JSONObject system = new JSONObject() {{
put("pssystemid", systemId);
put("pssystemid", systemName);
put("sysstructure", JSONObject.parseObject(strPermission));
put("md5check", DigestUtils.md5DigestAsHex(strPermission.getBytes()));
}};
if (uaaClient.syncSysAuthority(system)) {
log.info("向[uaa]同步系统资源成功");
} else {
log.error("向[uaa]同步系统资源失败");
}
}
} catch (Exception ex) {
log.error("向[uaa]同步系统资源失败,请检查[uaa]服务是否正常运行! {}", ex.getMessage());
}
try {
InputStream sysModel = this.getClass().getResourceAsStream("/sysmodel/${sys.codeName}.json"); //获取当前系统所有实体资源能力
String strSysModel = IOUtils.toString(sysModel,"UTF-8");
if(liteFeignClient.syncSysModel(JSONObject.parseObject(strSysModel))) {
log.info("向[lite]同步系统模型成功");
}else{
log.error("向[lite]同步系统模型失败");
InputStream model = this.getClass().getResourceAsStream("/sysmodel/${sys.codeName}.json"); //系统模型
if (!ObjectUtils.isEmpty(model)) {
String strModel = IOUtils.toString(model, "UTF-8");
if (liteClient.syncSysModel(JSONObject.parseObject(strModel))) {
log.info("向[lite]同步模型成功");
} else {
log.error("向[lite]同步模型失败");
}
}
catch (Exception ex) {
log.error(String.format("向[lite]同步系统模型失败,请检查[lite]服务是否正常! [%s]",ex));
} catch (Exception ex) {
log.error("向[lite]同步系统模型失败,请检查[lite]服务是否正常运行! {}", ex.getMessage());
}
<#if hasWF>
try{
List<Map<String,Object>> bpmnfiles = new ArrayList();
try {
List<Map<String, Object>> workflows = new ArrayList(); //工作流
<#list sys.getAllPSWorkflows() as wf>
<#if wf.getPSWFVersions()??>
<#list wf.getPSWFVersions() as wfvs>
bpmnfiles.add(new HashMap<String,Object>(){{put("${wfvs.codeName}.bpmn",IOUtils.toString(this.getClass().getResourceAsStream("/workflow/${wfvs.codeName}.bpmn"),"UTF-8"));}});
if (!ObjectUtils.isEmpty(this.getClass().getResourceAsStream("/workflow/${wfvs.codeName}.bpmn"))) {
workflows.add(new HashMap<String, Object>() {{
put("${wfvs.codeName}.bpmn", IOUtils.toString(this.getClass().getResourceAsStream("/workflow/${wfvs.codeName}.bpmn"), "UTF-8"));
}});
}
</#list>
</#if>
</#list>
if(client2.deployBpmnFile(bpmnfiles)) {
log.info("部署流程成功");
}else{
log.error("部署流程失败");
if (workflows.size() > 0) {
if (wfClient.deployBpmnFile(workflows)) {
log.info("向[wf]部署流程成功");
} else {
log.error("向[wf]部署流程失败");
}
}catch(Exception ex) {
log.error(String.format("部署流程失败,请检查[WF]服务是否正常! [%s]",ex));
}
} catch (Exception ex) {
log.error("向[wf]部署流程失败,请检查[wf]服务是否正常运行! {}", ex.getMessage());
}
</#if>
<#if hasMsgTemplate>
try {
InputStream msgTemplate = this.getClass().getResourceAsStream("/msgtempl/systemMsgTempl.json"); //获取当前系统所有实体资源能力
String strMsgTemplate = IOUtils.toString(msgTemplate,"UTF-8");
JSONObject template = new JSONObject();
template.put("template", JSONArray.parseArray(strMsgTemplate));
if(notifyFeignClient.createMsgTemplate(template)) {
log.info("推送消息模板成功");
}else{
log.error("推送消息模板失败");
}
} catch (Exception e) {
log.error("推送消息模板失败");
InputStream template = this.getClass().getResourceAsStream("/msgtempl/systemMsgTempl.json"); //消息模板
if (!ObjectUtils.isEmpty(template)) {
String strTemplate = IOUtils.toString(template, "UTF-8");
if (notifyClient.createMsgTemplate(new JSONObject() {{
put("template", JSONArray.parseArray(strTemplate));
}})) {
log.info("向[notify]同步消息模板成功");
} else {
log.error("向[notify]同步消息模板失败");
}
}
} catch (Exception ex) {
log.error("向[notify]同步消息模板失败,请检查[notify]服务是否正常运行! {}", ex.getMessage());
}
</#if>
<#if hasPredefinedCodeList>
try {
InputStream runtimeDict = this.getClass().getResourceAsStream("/sysmodel/RuntimeDict.json"); //获取当前系统所有实体资源能力
String strRuntimeDict = IOUtils.toString(runtimeDict,"UTF-8");
if(dictFeignClient.syncRuntimeDict(JSONArray.parseArray(strRuntimeDict))) {
log.info("推送系统预置代码表成功");
}else{
log.error("推送系统预置代码表失败");
}
} catch (Exception e) {
log.error("推送系统预置代码表失败");
InputStream dict = this.getClass().getResourceAsStream("/sysmodel/RuntimeDict.json"); //代码表
if (!ObjectUtils.isEmpty(dict)) {
String strDict = IOUtils.toString(dict, "UTF-8");
if (dictClient.syncRuntimeDict(JSONArray.parseArray(strDict))) {
log.info("向[dict]同步代码表成功");
} else {
log.error("向[dict]同步代码表失败");
}
}
} catch (Exception ex) {
log.error("向[dict]同步代码表失败,请检查[dict]服务是否正常运行! {}", ex.getMessage());
}
</#if>
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册