Browse Source

Merge branch 'dev' of ssh://10.10.100.21/source/saas-platform into dev

zhuth 7 years ago
parent
commit
7cb5bddec7

+ 4 - 0
applications/commons/commons-server/pom.xml

@@ -104,6 +104,10 @@
             <groupId>com.google.zxing</groupId>
             <artifactId>javase</artifactId>
         </dependency>
+      <dependency>
+        <groupId>com.usoftchina.saas</groupId>
+        <artifactId>mall-api</artifactId>
+      </dependency>
     </dependencies>
 
     <build>

+ 20 - 1
applications/commons/commons-server/src/main/java/com/usoftchina/saas/commons/service/impl/ConfigsServiceImpl.java

@@ -2,6 +2,8 @@ package com.usoftchina.saas.commons.service.impl;
 
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.usoftchina.saas.account.api.CompanyApi;
+import com.usoftchina.saas.account.dto.CompanyDTO;
 import com.usoftchina.saas.commons.cache.ConfigsCache;
 import com.usoftchina.saas.commons.dto.DocBaseDTO;
 import com.usoftchina.saas.commons.dto.ListReqDTO;
@@ -13,8 +15,11 @@ import com.usoftchina.saas.context.BaseContextHolder;
 import com.usoftchina.saas.document.api.CurrencyApi;
 import com.usoftchina.saas.document.dto.CurrencyDTO;
 import com.usoftchina.saas.exception.BizException;
+import com.usoftchina.saas.inquiry.api.EnConfigApi;
+import com.usoftchina.saas.inquiry.po.enConfig.AddOrUpdateEnterpriseRequest;
 import com.usoftchina.saas.page.PageDefault;
 import com.usoftchina.saas.page.PageRequest;
+import com.usoftchina.saas.utils.http.HttpUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
@@ -35,7 +40,10 @@ public class ConfigsServiceImpl implements ConfigsService{
     private MessageLogService messageLogService;
     @Autowired
     private CurrencyApi currencyApi;
-
+    @Autowired
+    private EnConfigApi enConfigApi;
+    @Autowired
+    private CompanyApi companyApi;
 
     @Override
     public PageInfo getListData(@PageDefault(size = 10) PageRequest page, ListReqDTO req) {
@@ -113,6 +121,17 @@ public class ConfigsServiceImpl implements ConfigsService{
                 currencyApi.setStandard(currencyDTO);
             } else if("enableB2B".equals(con.getCode())){
                 int count = configsMapper.selectByCodeAndCompanyId(con.getCode(), BaseContextHolder.getCompanyId());
+                //将企业信息同步给B2B,用于平台开启数据传输
+                if ("1".equals(con.getData())){
+                    CompanyDTO companyDTO = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData();
+                    enConfigApi.addOrUpdateEnterprise(new AddOrUpdateEnterpriseRequest(
+                            companyDTO.getUu(),
+                            companyDTO.getName(),
+                            true,
+                            true,
+                            companyDTO.getAccessKey()
+                    ));
+                }
                 if (count == 0){
                     //不存在,则插入
                     Configs configs = new Configs();

+ 8 - 1
applications/commons/commons-server/src/main/resources/application.yml

@@ -76,4 +76,11 @@ auth:
   public-key: auth/pub.key
 ribbon:
   ReadTimeout: 5000
-  ConnectTimeout: 5000
+  ConnectTimeout: 5000
+b2b:
+  baseUrl:
+    inquiry: https://test-inquiry.uuzcc.cn
+    Component: https://test-mall.uuzcc.cn
+    product: http://test-product.uuzcc.cn
+    common: http://test-b2b.uuzcc.cn
+    post: https://test-b2b-post.uuzcc.cn

+ 8 - 1
applications/commons/commons-server/src/main/resources/config/application-docker-prod.yml

@@ -20,4 +20,11 @@ spring:
     host: 10.10.100.173
     port: 6379
 logging:
-  destination: 10.10.100.160:5000
+  destination: 10.10.100.160:5000
+b2b:
+  baseUrl:
+    inquiry: https://api-inquiry.usoftchina.com
+    Component: https://mall.usoftchina.com
+    product: http://api-product.usoftchina.com
+    common: https://b2b-api.usoftchina.com
+    post: https://b2b-post.usoftchina.com

+ 2 - 2
applications/document/document-api/src/main/java/com/usoftchina/saas/document/api/ProductApi.java

@@ -46,13 +46,13 @@ public interface ProductApi {
      * @param code
      * @return
      */
-    @GetMapping("/getByProdCode")
+    @GetMapping("/product/getByProdCode")
     Result<ProductDTO> getByProdCode(@RequestParam("code") String code);
 
     /**
      * 上传至B2B平台
      * @return
      */
-    @PostMapping("/b2b/upload")
+    @PostMapping("/product/b2b/upload")
     Result uploadToB2B();
 }

+ 44 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/VendorServiceImpl.java

@@ -3,6 +3,8 @@ package com.usoftchina.saas.document.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.usoftchina.saas.account.api.CompanyApi;
+import com.usoftchina.saas.account.dto.CompanyDTO;
 import com.usoftchina.saas.base.Result;
 import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
 import com.usoftchina.saas.commons.api.MaxnumberService;
@@ -29,8 +31,14 @@ import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.page.PageRequest;
 import com.usoftchina.saas.utils.CollectionUtils;
 import com.usoftchina.saas.utils.DateUtils;
+import com.usoftchina.saas.utils.JsonUtils;
 import com.usoftchina.saas.utils.RegexpUtils;
+import com.usoftchina.saas.utils.http.HttpUtil;
+import com.usoftchina.saas.utils.http.HttpUtil.Response;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
@@ -59,6 +67,12 @@ public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendo
     private DataImportMapper dataImportMapper;
     @Autowired
     private VendorkindService vendorkindService;
+    @Autowired
+    private CompanyApi companyApi;
+    @Value("${b2b.baseUrl.common}")
+    private String b2bUrl;
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(VendorServiceImpl.class);
 
     @Override
     public PageInfo<VendorDTO> getVendorsByCondition(PageRequest page, ListReqDTO listReqDTO) {
@@ -236,6 +250,15 @@ public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendo
                 main.setVe_beginprepayamount(vendortpl.getVe_beginprepayamount());
             }
 
+            //启用B2B对账
+            if (StringUtils.isEmpty(oldVendor.getVe_uu()) && !StringUtils.isEmpty(main.getVe_uu())){
+                try {
+                    enableApCheck(main.getVe_uu());
+                } catch (Exception e) {
+                    LOGGER.info("请求B2B对账启用接口失败!, time={}", DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
+                }
+            }
+
             getMapper().updateByPrimaryKeySelective(main);
             if (items.size() > 0) {
                 List<Vendorcontact> updateItems = new ArrayList<Vendorcontact>();
@@ -312,6 +335,27 @@ public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendo
         return generateMsgObj(main.getId(), ve_code);
     }
 
+    /**
+     * 启用B2B对账
+     * @param ve_uu
+     * @throws Exception
+     */
+    private void enableApCheck(String ve_uu) throws Exception {
+        CompanyDTO companyDTO = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData();
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("venduu", ve_uu);
+        map.put("custuu", companyDTO.getUu());
+        map.put("apcheck", 1);
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("data", JsonUtils.toJsonString(map));
+        Response response = HttpUtil.sendPostRequest(b2bUrl + "/erp/vendor/apcheck?access_id=" + companyDTO.getUu(), params, true, companyDTO.getAccessKey());
+        if (response.getStatusCode() == 200){
+            LOGGER.info("供应商UU={},启用B2B对账成功!", ve_uu);
+        }else {
+            LOGGER.info("供应商UU={},启用B2B对账失败!,原因={}", ve_uu, response.getResponseText());
+        }
+    }
+
     /**
      * 删除主从表数据
      * @param id

+ 25 - 2
applications/purchase/purchase-server/src/main/java/com/usoftchina/saas/purchase/service/impl/PurchaseServiceImpl.java

@@ -1,8 +1,10 @@
 package com.usoftchina.saas.purchase.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.netflix.discovery.converters.Auto;
+import com.rabbitmq.tools.json.JSONUtil;
 import com.usoftchina.saas.account.dto.CompanyDTO;
 import com.usoftchina.saas.commons.cache.ConfigsCache;
 import com.usoftchina.saas.document.api.AddressApi;
@@ -54,6 +56,7 @@ import com.usoftchina.saas.transfers.dto.MessageInfo;
 import com.usoftchina.saas.utils.BeanMapper;
 import com.usoftchina.saas.utils.CollectionUtils;
 import com.usoftchina.saas.utils.JsonUtils;
+import feign.Response;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -61,6 +64,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
 
+import java.io.IOException;
+import java.io.Reader;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.CountDownLatch;
@@ -895,10 +900,28 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
     public void DealInquiry(InquiryDealReqDTO inquiryDealReqDTO) {
         Long enUU = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData().getUu();
         Long userUU = accountApi.getAccountById(BaseContextHolder.getUserId()).getData().getUu();
+        Response response = null;
         if (inquiryDealReqDTO.getStatus() == 1){
-            inquiryApi.adoptQuote(inquiryDealReqDTO.getId(), inquiryDealReqDTO.getStatus(), enUU, userUU);
+            response = inquiryApi.adoptQuote(inquiryDealReqDTO.getId(), inquiryDealReqDTO.getStatus(), enUU, userUU);
         }else{
-            inquiryApi.refuseQuote(inquiryDealReqDTO.getId(), inquiryDealReqDTO.getStatus(), enUU, userUU, inquiryDealReqDTO.getRefusereason());
+            response = inquiryApi.refuseQuote(inquiryDealReqDTO.getId(), inquiryDealReqDTO.getStatus(), enUU, userUU, inquiryDealReqDTO.getRefusereason());
+        }
+        if (response.status() == 500){
+            try {
+                Reader reader = response.body().asReader();
+                int size = response.body().length();
+                char[] ch = new char[size];
+                int temp = 0, len = 0;
+                while ((temp = reader.read()) != -1){
+                    ch[len] = (char) temp;
+                    len++;
+                }
+                reader.close();
+                JSONObject jsonObject = JSONObject.parseObject(new String(ch));
+                throw new BizException(79320, jsonObject.getString("message"));
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
     }
 

+ 4 - 3
applications/transfers/mall-api/src/main/java/com/usoftchina/saas/inquiry/api/InquiryApi.java

@@ -3,6 +3,7 @@ package com.usoftchina.saas.inquiry.api;
 import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.exception.ExceptionCode;
 import com.usoftchina.saas.inquiry.po.inquiry.*;
+import feign.Response;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.stereotype.Component;
 import org.springframework.ui.ModelMap;
@@ -115,7 +116,7 @@ public interface InquiryApi {
      * @param useruu    用户uu
      */
     @PostMapping("/buyer/adopt")
-    void adoptQuote(@RequestParam("id") Long id, @RequestParam("status") Short status,
+    Response adoptQuote(@RequestParam("id") Long id, @RequestParam("status") Short status,
                     @RequestParam("enuu") Long enuu, @RequestParam("useruu") Long useruu);
 
     /**
@@ -127,6 +128,6 @@ public interface InquiryApi {
      * @param refusereason  拒绝理由
      */
     @PostMapping("/buyer/refuse")
-    void refuseQuote(@RequestParam("id") Long id, @RequestParam("status") Short status, @RequestParam("enuu") Long enuu,
-                     @RequestParam("useruu") Long useruu, @RequestParam("refusereason") String refusereason);
+    Response refuseQuote(@RequestParam("id") Long id, @RequestParam("status") Short status, @RequestParam("enuu") Long enuu,
+                         @RequestParam("useruu") Long useruu, @RequestParam("refusereason") String refusereason);
 }

+ 11 - 0
applications/transfers/mall-api/src/main/java/com/usoftchina/saas/inquiry/po/enConfig/AddOrUpdateEnterpriseRequest.java

@@ -67,4 +67,15 @@ public class AddOrUpdateEnterpriseRequest {
     public void setAccessSecret(String accessSecret) {
         this.accessSecret = accessSecret;
     }
+
+    public AddOrUpdateEnterpriseRequest(Long enuu, String name, boolean saas, boolean saasPost, String accessSecret) {
+        this.enuu = enuu;
+        this.name = name;
+        this.saas = saas;
+        this.saasPost = saasPost;
+        this.accessSecret = accessSecret;
+    }
+
+    public AddOrUpdateEnterpriseRequest() {
+    }
 }

+ 27 - 0
applications/transfers/mall-api/src/main/java/com/usoftchina/saas/inquiry/po/inquiry/InquiryResult.java

@@ -0,0 +1,27 @@
+package com.usoftchina.saas.inquiry.po.inquiry;
+
+/**
+ * @Author chenwei
+ * @Date 2019/01/24
+ */
+public class InquiryResult {
+
+    private Boolean success;
+    private String message;
+
+    public Boolean getSuccess() {
+        return success;
+    }
+
+    public void setSuccess(Boolean success) {
+        this.success = success;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+}

+ 34 - 2
applications/transfers/mall-api/src/test/java/com/usoftchina/saas/inquiry/test/InquiryApiTest.java

@@ -3,6 +3,7 @@ package com.usoftchina.saas.inquiry.test;
 import com.usoftchina.saas.inquiry.api.InquiryApi;
 import com.usoftchina.saas.inquiry.po.inquiry.*;
 import com.usoftchina.saas.utils.JsonUtils;
+import feign.Response;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -13,6 +14,7 @@ import org.springframework.test.context.junit4.SpringRunner;
 import org.springframework.ui.ModelMap;
 
 import javax.naming.directory.InvalidSearchFilterException;
+import java.io.*;
 import java.util.*;
 
 /**
@@ -159,7 +161,37 @@ public class InquiryApiTest {
     }
 
     @Test
-    public void testH_refuseQuote(){
-        inquiryApi.refuseQuote(0L, new Short("1"), enUU, userUU, "reason");
+    public void testH_refuseQuote() throws IOException {
+        Response response = inquiryApi.refuseQuote(83950L, new Short("0"), 10050689L, 1000027286L, "测试");
+        if (response.status() == 500){
+            //读取内容方式1
+            InputStream in = response.body().asInputStream();
+            char[] bytes = new char[in.available()];
+            InputStreamReader reader = new InputStreamReader(in);
+            int length = reader.read(bytes);
+            System.out.println("result:" + new String(bytes, 0, length));
+            reader.close();
+            in.close();
+            //读取内容方式2
+            Reader reader2 = response.body().asReader();
+            int size = response.body().length();
+            char[] ch = new char[size];
+            int temp = 0, len = 0;
+            while ((temp = reader2.read()) != -1){
+                ch[len] = (char) temp;
+                len++;
+            }
+            reader2.close();
+            System.out.println("result2: ==========" + new String(ch));
+            //方式3
+            BufferedReader bufferedReader = new BufferedReader(response.body().asReader());
+            StringBuilder sb = new StringBuilder();
+            String line = null;
+            while (bufferedReader.readLine() != null ){
+                sb.append(line);
+            }
+            bufferedReader.close();
+            System.out.println("result3: " + sb);
+        }
     }
 }