Browse Source

同步客户编号

hym 4 years ago
parent
commit
b31094be8d

+ 21 - 2
smart-city-platform/src/main/java/com/bz/smart_city/commom/util/HttpClientUtils.java

@@ -1,4 +1,5 @@
 package com.bz.smart_city.commom.util;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.http.Consts;
 import org.apache.http.HttpEntity;
@@ -19,6 +20,10 @@ import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.util.EntityUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
@@ -125,8 +130,22 @@ public class HttpClientUtils {
         post.setEntity(requestEntity);
         return execute(post);
     }
-    
- 
+
+    public static String sendApiReQuest(String path , String args){
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<>(args, headers);
+
+        RestTemplate restTemplate=new RestTemplate();
+        ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(path, formEntity,
+                String.class);
+        JSONObject info = JSONObject.parseObject(stringResponseEntity.getBody());
+        String result=null;
+        if(info.getInteger("status")==0){
+            result=info.getString("data");
+        }
+        return result;
+    }
     private static String execute(HttpUriRequest request) throws Exception {
         CloseableHttpResponse response = CLIENT.execute(request);
         if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {

+ 13 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/CustomerServiceImpl.java

@@ -1,8 +1,10 @@
 package com.bz.smart_city.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.bz.smart_city.commom.exception.ServiceException;
 import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.commom.model.ResultStatus;
+import com.bz.smart_city.commom.util.HttpClientUtils;
 import com.bz.smart_city.commom.util.TreeUtil;
 import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.dto.CustomerDto;
@@ -10,13 +12,16 @@ import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.entity.ProgramItem;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import com.bz.smart_city.entity.Customer;
 import com.bz.smart_city.dao.CustomerMapper;
@@ -29,6 +34,8 @@ public class CustomerServiceImpl implements CustomerService {
 
     @Resource
     private CustomerMapper customerMapper;
+    @Value("${sync_customer_no_url}")
+    private String syncCustomerNoUrl;
 
     @Override
     public int insert(Customer customer) {
@@ -197,6 +204,12 @@ public class CustomerServiceImpl implements CustomerService {
             generateCode(customerId);
             return;
         }
+        Customer oldCustomer = customerMapper.findById(customerId);
+        Map<String,Object> args=new HashMap<>();
+        args.put("oldNo", oldCustomer.getCustomerNo());
+        args.put("newNo", customerNo);
+        String result = HttpClientUtils.sendApiReQuest(syncCustomerNoUrl, JSONObject.toJSONString(args));
+
         log.info("Begin GenerateCode CustomerId " + customerId);
         Customer customer = new Customer();
         customer.setId(customerId);

+ 2 - 1
smart-city-platform/src/main/resources/application-dev.properties

@@ -181,4 +181,5 @@ sync.customer.wuhan.id=136
 #spring.data.mongodb.uri=mongodb://114.135.61.188:17017/meter-reading-database
 spring.data.mongodb.uri=mongodb://water:zcxk100@114.135.61.189:27071/meter-reading-database?authSource=meter-reading-database
 logging.level.org.springframework.data.mongodb.core=DEBUG
-account_userInfo_url=http://114.135.61.188:58084/api/pay/getAccountInfoByMetercode
+account_userInfo_url=http://114.135.61.188:58084/api/pay/getAccountInfoByMetercode
+sync_customer_no_url=http://114.135.61.188:58084/api/customer/synCustomer

+ 2 - 1
smart-city-platform/src/main/resources/application-sit.properties

@@ -183,4 +183,5 @@ sync.customer.wuhan.id=136
 #mongodb url
 spring.data.mongodb.uri=mongodb://114.135.61.188:17017/meter-reading-database
 logging.level.org.springframework.data.mongodb.core=DEBUG
-account_userInfo_url=http://114.135.61.188:58084/api/pay/getAccountInfoByMetercode
+account_userInfo_url=http://114.135.61.188:58084/api/pay/getAccountInfoByMetercode
+sync_customer_no_url=http://114.135.61.188:58084/api/customer/synCustomer