diff --git a/adc-da-activiti/src/main/java/com/adc/da/FeignClient/workFlowFeignClient.java b/adc-da-activiti/src/main/java/com/adc/da/FeignClient/workFlowFeignClient.java index 25d62124..4f434007 100644 --- a/adc-da-activiti/src/main/java/com/adc/da/FeignClient/workFlowFeignClient.java +++ b/adc-da-activiti/src/main/java/com/adc/da/FeignClient/workFlowFeignClient.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -@FeignClient(value = "bat-wkflow") +@FeignClient(value = "bat-wkflow-zqazqazqa") public interface workFlowFeignClient { @RequestMapping(value = "/bat-wkflow/activiti_define_start_user",method = RequestMethod.GET) diff --git a/adc-da-activiti/src/main/java/com/adc/da/common/ActDefineStartMap.java b/adc-da-activiti/src/main/java/com/adc/da/common/ActDefineStartMap.java index 82c9b863..e1a55922 100644 --- a/adc-da-activiti/src/main/java/com/adc/da/common/ActDefineStartMap.java +++ b/adc-da-activiti/src/main/java/com/adc/da/common/ActDefineStartMap.java @@ -15,7 +15,8 @@ public class ActDefineStartMap { Map map = new TreeMap<>(); map.put("1","standardLibraryWkflow"); + map.put("2","standardSurveyWorkFlow"); return map.get(type); } -} +} \ No newline at end of file diff --git a/adc-da-main/src/main/java/com/adc/da/main/config/RestTemplateConfig.java b/adc-da-main/src/main/java/com/adc/da/main/config/RestTemplateConfig.java index bbfe712d..8b91a64b 100644 --- a/adc-da-main/src/main/java/com/adc/da/main/config/RestTemplateConfig.java +++ b/adc-da-main/src/main/java/com/adc/da/main/config/RestTemplateConfig.java @@ -7,6 +7,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.web.client.RestTemplate; diff --git a/adc-da-main/src/main/resources/application-dev.properties b/adc-da-main/src/main/resources/application-dev.properties index f952ebd8..a916e2e4 100644 --- a/adc-da-main/src/main/resources/application-dev.properties +++ b/adc-da-main/src/main/resources/application-dev.properties @@ -9,7 +9,7 @@ spring.datasource.password = root #============================================== # 应用设置 -spring.application.name=FotonLAWSSystem +spring.application.name=FotonLAWSSystem-zqazqazqa application.code=20200101 application.center=1 #============================================== @@ -35,11 +35,11 @@ spring.mail.port=587 # ============================================== # rabbitMQ # ============================================== -#spring.rabbitmq.host=rabbitmq-cluster-01.vs.test.geely.svc -#spring.rabbitmq.port=5672 -#spring.rabbitmq.virtual-host=uat_pcms -#spring.rabbitmq.username=uat_pcms -#spring.rabbitmq.password=VxsBLL5bJruwzXfS +spring.rabbitmq.host=rabbitmq-cluster-01.vs.test.geely.svc +spring.rabbitmq.port=5672 +spring.rabbitmq.virtual-host=uat_pcms +spring.rabbitmq.username=uat_pcms +spring.rabbitmq.password=VxsBLL5bJruwzXfS # spring.rabbitmq.publisher-confirms=true # ============================================== diff --git a/adc-da-main/src/main/resources/application.properties b/adc-da-main/src/main/resources/application.properties index 4cb8be56..6b97ffad 100644 --- a/adc-da-main/src/main/resources/application.properties +++ b/adc-da-main/src/main/resources/application.properties @@ -30,14 +30,17 @@ restPath=/api #server.servlet.context-path=/api #是否将自己注册到Eureka Server上,默认为true -eureka.client.register-with-eureka=false +eureka.client.register-with-eureka=true ##是否从Eureka Server上获取注册信息,默认为true -eureka.client.fetch-registry=false +eureka.client.fetch-registry=true + #eureka.client.service-url.defaultZone=http://10.5.116.172:8672/eureka/ #eureka.client.service-url.defaultZone=http://127.0.0.1:8671/eureka/ #eureka.client.service-url.defaultZone=http://10.5.116.172:8672/eureka/ -eureka.client.service-url.defaultZone=http://127.0.0.1:8761/eureka/ + +eureka.client.service-url.defaultZone=http://192.168.10.47:8761/eureka/ + # 请求连接的超时时间 默认的时间为 1 秒 ribbon.ConnectTimeout=500000 # 请求处理的超时时间 diff --git a/adc-da-sys/pom.xml b/adc-da-sys/pom.xml index 66956665..d199fc22 100644 --- a/adc-da-sys/pom.xml +++ b/adc-da-sys/pom.xml @@ -33,6 +33,27 @@ adc-da-base 3.0.0 + + org.apache.httpcomponents + httpclient + 4.5.2 + + + commons-codec + commons-codec + 1.10 + + + org.apache.commons + commons-lang3 + 3.4 + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + diff --git a/adc-da-sys/src/main/java/com/adc/da/sync/controller/TestSyncController.java b/adc-da-sys/src/main/java/com/adc/da/sync/controller/TestSyncController.java new file mode 100644 index 00000000..07dcc3bd --- /dev/null +++ b/adc-da-sys/src/main/java/com/adc/da/sync/controller/TestSyncController.java @@ -0,0 +1,30 @@ +package com.adc.da.sync.controller; + +import com.adc.da.sync.service.SyncUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/${restPath}/sync") +@Api(tags = "数据同步管理") +public class TestSyncController { + + @Autowired + private SyncUserService syncUserService; + + @ApiOperation(value = "福田IDM用户数据同步") + @GetMapping("/syncUser") + public void syncUser() throws Exception { + syncUserService.syncFotonUser(); + } + + @ApiOperation(value = "福田IDM组织数据同步") + @GetMapping("/syncOrg") + public void syncOrg() throws Exception { + syncUserService.syncFotonOrg(); + } +} diff --git a/adc-da-sys/src/main/java/com/adc/da/sync/service/SyncUserService.java b/adc-da-sys/src/main/java/com/adc/da/sync/service/SyncUserService.java new file mode 100644 index 00000000..defd0c5c --- /dev/null +++ b/adc-da-sys/src/main/java/com/adc/da/sync/service/SyncUserService.java @@ -0,0 +1,100 @@ +package com.adc.da.sync.service; + +import com.adc.da.sync.util.AuthUtils; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONSerializer; +import org.apache.commons.codec.binary.Base64; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +@Service("syncUserService") +@Slf4j +public class SyncUserService { + + + /** + * 同步福田IDM数据 + * @throws Exception + */ + public void syncFotonUser()throws Exception{ + String appuser = "wsuser"; + String appkey = "o1bnrph3pe6i63txm3z5l3cnka2a82pi"; + AuthUtils util = new AuthUtils(appuser, appkey, null); + + byte[] cookie = null; + do { + Map params = new HashMap(); + params.put("cookie", Base64.encodeBase64String(cookie)); + params.put("timestamp", "20141125065609Z"); + + // 用户参数 + params.put("filter", "(userid=*)"); + params.put("basedn", "ou=People,o=foton.com.cn,o=isp"); + System.out.println("RequestBody:" + params.toString()); + // 用户测试 + String rs = util.getResponseFromServer("http://172.24.224.42:82/rest/users/getUserList", params); + System.err.println(rs); + + JSONObject responseStr = (JSONObject) JSONSerializer.toJSON(rs); + + if (responseStr.containsKey("cookie")) { + try { + JSONArray entries = responseStr.getJSONArray("cookie"); + cookie = new byte[entries.size()]; + for (int i = 0; i < entries.size(); i++) { + cookie[i] = (byte) entries.getByte(i); + } + } catch (Exception e) { + if (e.getMessage().contains("is not a JSONArray")) { + cookie = null; + } + } + } + + } while (cookie != null); + } + + + + public void syncFotonOrg()throws Exception{ + String appuser = "wsuser"; + String appkey = "o1bnrph3pe6i63txm3z5l3cnka2a82pi"; + AuthUtils util = new AuthUtils(appuser, appkey, null); + + byte[] cookie = null; + do { + Map params = new HashMap(); + params.put("cookie", Base64.encodeBase64String(cookie)); + params.put("timestamp", "20141125065609Z"); + + // 组织参数 + params.put("filter", "(orgNumber=*)"); + params.put("basedn", "ou=Organizations,o=foton.com.cn,o=isp"); + // 组织测试 + String rs = util.getResponseFromServer("http://172.24.224.42:82/rest/orgs/getOrgList", params); + System.err.println(rs); + + + JSONObject responseStr = (JSONObject) JSONSerializer.toJSON(rs); + + if (responseStr.containsKey("cookie")) { + try { + JSONArray entries = responseStr.getJSONArray("cookie"); + cookie = new byte[entries.size()]; + for (int i = 0; i < entries.size(); i++) { + cookie[i] = (byte) entries.getByte(i); + } + } catch (Exception e) { + if (e.getMessage().contains("is not a JSONArray")) { + cookie = null; + } + } + } + + } while (cookie != null); + } +} diff --git a/adc-da-sys/src/main/java/com/adc/da/sync/util/AuthUtils.java b/adc-da-sys/src/main/java/com/adc/da/sync/util/AuthUtils.java new file mode 100644 index 00000000..3a085b1f --- /dev/null +++ b/adc-da-sys/src/main/java/com/adc/da/sync/util/AuthUtils.java @@ -0,0 +1,78 @@ +package com.adc.da.sync.util; + +import net.sf.json.JSONObject; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.utils.HttpClientUtils; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.ContentType; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Map; + +public class AuthUtils { + + private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss'Z'"); + + private final String appuser; + private final String appkey; + private final String appinfo; + + public AuthUtils(String appuser, String appkey, String appinfo) { + this.appuser = appuser; + this.appkey = appkey; + this.appinfo = appinfo; + } + + public String getResponseFromServer(String url, Map params) throws Exception { + HttpPost httpPost = new HttpPost(url); + createSignHeader(httpPost, params); + JSONObject object = JSONObject.fromObject(params); + httpPost.setEntity(new ByteArrayEntity(object.toString().getBytes(), ContentType.APPLICATION_JSON)); + return execute(httpPost); + } + + private String execute(HttpUriRequest request) throws Exception { + CloseableHttpClient client = null; + CloseableHttpResponse resp = null; + try { + client = HttpClientBuilder.create().build(); + resp = client.execute(request); + return EntityUtils.toString(resp.getEntity()); + } finally { + HttpClientUtils.closeQuietly(resp); + HttpClientUtils.closeQuietly(client); + } + } + + private void createSignHeader(HttpUriRequest request, Map params) throws Exception { + request.addHeader("appuser", appuser); + + String randomcode = RandomStringUtils.random(10, true, true); + request.addHeader("randomcode", randomcode); + + Calendar now = Calendar.getInstance(); + String timestamp = sdf.format(now.getTime()); + request.addHeader("timestamp", timestamp); + + String data = StringUtils.join(appuser, randomcode, timestamp); + String encodekey = DigestUtils.sha256Hex(StringUtils.join(data, "{", appkey, "}")); + request.addHeader("encodekey", encodekey); + + JSONObject object = JSONObject.fromObject(params); + String paramData = StringUtils.join(object.toString(), "&", appkey); + String signature = DigestUtils.md5Hex(paramData); + request.addHeader("sign", signature); + + request.addHeader("appinfo", appinfo); + request.addHeader("Content-Type", "application/json"); + } +} diff --git a/adc-da-sys/src/main/resources/mybatis/mapper/sys/UserEOMapper.xml b/adc-da-sys/src/main/resources/mybatis/mapper/sys/UserEOMapper.xml index 2ef62938..8220853c 100644 --- a/adc-da-sys/src/main/resources/mybatis/mapper/sys/UserEOMapper.xml +++ b/adc-da-sys/src/main/resources/mybatis/mapper/sys/UserEOMapper.xml @@ -421,7 +421,7 @@ - select from TS_USER u