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

job逻辑优化

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