提交 30e7a72d authored 作者: 黄承天's avatar 黄承天

[模型模块]新增根据processKey查询接口

上级 e3966687
......@@ -13,11 +13,13 @@ import com.tykj.workflowcore.user.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
......@@ -40,13 +42,9 @@ public class SyncDataService {
private String ip;
@Value("${sync.port}")
private Integer port = 8880;
private Integer port;
public String getUrl(){
return String.format("http://%s:%s", ip, port);
}
@Scheduled(cron = "0 0 */1 * * ?")
public void execute() {
syncKey();
......@@ -56,7 +54,8 @@ public class SyncDataService {
private void syncKey() {
log.info("开始同步秘钥信息...");
ResponseEntity<String> entity = restTemplate.postForEntity(getUrl() + "/storageKey/getKeys", null, String.class, new HashMap<>());
String url = String.format("http://%s:%s", ip, port);
ResponseEntity<String> entity = restTemplate.exchange(url + "/storageKey/getKeys", HttpMethod.POST, getEntity(), String.class, new HashMap<>());
if (nonNull(entity) && nonNull(entity.getBody())) {
try {
ResultObj<StorageKey> resultObj = new ObjectMapper().readValue(entity.getBody(), new TypeReference<ResultObj<StorageKey>>() {
......@@ -72,7 +71,8 @@ public class SyncDataService {
private void syncUser() {
log.info("开始同步用户信息...");
ResponseEntity<String> entity = restTemplate.getForEntity(getUrl() + "/user/all", String.class, new HashMap<>());
String url = String.format("http://%s:%s", ip, port);
ResponseEntity<String> entity = restTemplate.exchange(url + "/user/all", HttpMethod.GET, getEntity(), String.class, new HashMap<>());
if (nonNull(entity) && nonNull(entity.getBody())) {
try {
ResultObj<List<User>> resultObj = new ObjectMapper().readValue(entity.getBody(), new TypeReference<ResultObj<List<User>>>() {
......@@ -88,7 +88,8 @@ public class SyncDataService {
private void syncOrganization() {
log.info("开始同步组织架构信息...");
ResponseEntity<String> entity = restTemplate.getForEntity(getUrl() + "/organization/all", String.class, new HashMap<>());
String url = String.format("http://%s:%s", ip, port);
ResponseEntity<String> entity = restTemplate.exchange(url + "/organization/all", HttpMethod.GET, getEntity(), String.class, new HashMap<>());
if (nonNull(entity) && nonNull(entity.getBody())) {
try {
ResultObj<List<Organization>> resultObj = new ObjectMapper().readValue(entity.getBody(), new TypeReference<ResultObj<List<Organization>>>() {
......@@ -102,4 +103,9 @@ public class SyncDataService {
}
}
private HttpEntity getEntity() {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
return new HttpEntity<>(null, headers);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论