Просмотр исходного кода

Merge remote-tracking branch 'origin/feature-hejq-201844' into feature-hejq-201844

shenjunjie 7 лет назад
Родитель
Сommit
3719b05919
29 измененных файлов с 2654 добавлено и 495 удалено
  1. 8 0
      db/ddl.sql
  2. 9 0
      src/main/java/com/uas/platform/b2b/dao/EnterpriseDao.java
  3. 12 0
      src/main/java/com/uas/platform/b2b/erp/model/VendorInfo.java
  4. 14 0
      src/main/java/com/uas/platform/b2b/model/Vendor.java
  5. 145 0
      src/main/java/com/uas/platform/b2b/openapi/controller/UsoftController.java
  6. 39 0
      src/main/java/com/uas/platform/b2b/openapi/dao/UsoftWhitelistDao.java
  7. 49 0
      src/main/java/com/uas/platform/b2b/openapi/model/Product.java
  8. 112 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftAccept.java
  9. 110 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftAcceptItem.java
  10. 204 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftHistoryTradingData.java
  11. 47 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftInterval.java
  12. 57 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftIntervalItem.java
  13. 102 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftOrder.java
  14. 91 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftOrderItem.java
  15. 99 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftRunningEfficient.java
  16. 122 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftTrading.java
  17. 167 0
      src/main/java/com/uas/platform/b2b/openapi/model/UsoftWhitelist.java
  18. 8 0
      src/main/java/com/uas/platform/b2b/openapi/service/TradingDataService.java
  19. 102 0
      src/main/java/com/uas/platform/b2b/openapi/service/UsoftService.java
  20. 207 205
      src/main/java/com/uas/platform/b2b/openapi/service/impl/TradingDataServiceImpl.java
  21. 641 0
      src/main/java/com/uas/platform/b2b/openapi/service/impl/UsoftServiceImpl.java
  22. 7 1
      src/main/java/com/uas/platform/b2b/openapi/support/NumFormat.java
  23. 19 1
      src/main/java/com/uas/platform/b2b/service/impl/ErpProdIODetailServiceImpl.java
  24. 51 4
      src/main/java/com/uas/platform/b2b/service/impl/PurchaseApCheckServiceImpl.java
  25. 82 0
      src/main/java/com/uas/platform/b2b/task/ApCheckTask.java
  26. 1 1
      src/main/resources/ptest/jdbc.properties
  27. 128 124
      src/main/webapp/WEB-INF/spring/webmvc.xml
  28. 21 0
      src/test/java/com/uas/platform/b2b/purc/ApCheckCountTest.java
  29. 0 159
      src/test/java/com/uas/platform/b2b/purc/PurchaseNoticeSearchTest.java

+ 8 - 0
db/ddl.sql

@@ -5,4 +5,12 @@
 -- author: suntg
 -- content: 内容备注xxx
 
+-- date: 2018-12-12 17:51
+-- author: hejq
+-- content: 供应商关系表增加字段,需要对账金额,次更新时间,
+-- 采用字符串是因为需要分币别统计处理
+  alter table `purc$vendors`
+  add column todo_apchek_count VARCHAR(100) default '' comment '需要对账金额',
+  add column update_time datetime comment '上一次更新时间';
+
 

+ 9 - 0
src/main/java/com/uas/platform/b2b/dao/EnterpriseDao.java

@@ -11,6 +11,7 @@ import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
 import javax.persistence.QueryHint;
+import java.sql.Date;
 import java.util.List;
 
 /**
@@ -116,4 +117,12 @@ public interface EnterpriseDao extends JpaSpecificationExecutor<Enterprise>,JpaR
 	 */
 	@Query("from Enterprise e where e.enName = :name")
 	List<Enterprise> findByName(@Param("name") String name);
+
+	/**
+	 * 查找符合条件的企业uu
+	 * @param date
+	 * @return
+	 */
+	@Query(value = "select distinct e.uu from Enterprise e where e.enDate <= :date")
+	List<Long> findEnuu(@Param("date") Date date);
 }

+ 12 - 0
src/main/java/com/uas/platform/b2b/erp/model/VendorInfo.java

@@ -26,6 +26,11 @@ public class VendorInfo {
 	 */
 	private Short apcheck;
 
+    /**
+     * 供应商关系表id
+     */
+	private Long id;
+
 	public Long getVenduu() {
 		return venduu;
 	}
@@ -50,4 +55,11 @@ public class VendorInfo {
 		this.apcheck = apcheck;
 	}
 
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
 }

+ 14 - 0
src/main/java/com/uas/platform/b2b/model/Vendor.java

@@ -172,6 +172,12 @@ public class Vendor implements Serializable {
 	@Column(name = "ve_erpstatus")
 	private Integer erpstatus;
 
+    /**
+     * 应收金额数据
+     */
+	@Column(name = "todo_apchek_count")
+    private String totalCountString;
+
     /**
      * 最近一次对账时间
      */
@@ -421,6 +427,14 @@ public class Vendor implements Serializable {
         this.totalCount = totalCount;
     }
 
+    public String getTotalCountString() {
+        return totalCountString;
+    }
+
+    public void setTotalCountString(String totalCountString) {
+        this.totalCountString = totalCountString;
+    }
+
     public InquiryVendorInfo covert() {
 		InquiryVendorInfo info = new InquiryVendorInfo();
 		info.setB2b_id(this.id);

+ 145 - 0
src/main/java/com/uas/platform/b2b/openapi/controller/UsoftController.java

@@ -0,0 +1,145 @@
+package com.uas.platform.b2b.openapi.controller;
+
+import com.uas.platform.b2b.openapi.model.*;
+import com.uas.platform.b2b.openapi.service.UsoftService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @Author: huj
+ * @Date: Created in 10:55 2018/11/08.
+ */
+@RestController
+@RequestMapping("/openapi/usoft")
+public class UsoftController {
+
+    @Autowired
+    UsoftService usoftService;
+
+    /**
+     * 根据卖方uu获取订单数据
+     * @param enUU
+     *      卖方uu
+     * @param startTime
+     *      起始时间
+     * @param endTime
+     *      截止时间
+     * @return
+     */
+    @RequestMapping(value = "/order", method = RequestMethod.GET)
+    public List<UsoftOrder> getUsoftOrders(@RequestParam(required = true) Long enUU, Long startTime, Long endTime) {
+        return usoftService.getUsoftOrders(enUU, startTime, endTime);
+    }
+
+    /**
+     * 根据订单获取订单明细
+     * @param orderIds
+     *      订单id
+     * @return
+     */
+    @RequestMapping(value = "/order/item/batch", method = RequestMethod.GET)
+    public List<UsoftOrderItem> getUsoftOrderItemsBatch(String orderIds) {
+        return usoftService.getUsoftOrderItemsBatch(orderIds);
+    }
+
+    /**
+     * 根据订单获取订单明细
+     * @param orderId
+     *      订单id
+     * @return
+     */
+    @RequestMapping(value = "/order/item", method = RequestMethod.GET)
+    public List<UsoftOrderItem> getUsoftOrderItems(Long orderId) {
+        return usoftService.getUsoftOrderItems(orderId);
+    }
+
+    /**
+     * 根据卖方uu获取验收单数据
+     * @param enUU
+     *      卖方uu
+     * @param startTime
+     *      起始时间
+     * @param endTime
+     *      截止时间
+     * @return
+     */
+    @RequestMapping(value = "/accept", method = RequestMethod.GET)
+    public List<UsoftAccept> getUsoftAccepts(Long enUU, Long startTime, Long endTime) {
+        return usoftService.getUsoftAccepts(enUU, startTime, endTime);
+    }
+
+    /**
+     * 根据验收单id获取验收明细
+     * @param acceptId
+     *      验收单id
+     * @return
+     */
+    @RequestMapping(value = "/accept/item", method = RequestMethod.GET)
+    public List<UsoftAcceptItem> getUsoftAcceptItems(Long acceptId) {
+        return usoftService.getUsoftAcceptItems(acceptId);
+    }
+
+    /**
+     * 根据验收单id获取验收明细
+     * @param acceptIds
+     *      验收单id字符串
+     * @return
+     */
+    @RequestMapping(value = "/accept/item/batch", method = RequestMethod.GET)
+    public List<UsoftAcceptItem> getUsoftAcceptItemsBatch(String acceptIds) {
+        return usoftService.getUsoftAcceptItemsBatch(acceptIds);
+    }
+
+    /**
+     * 获取白名单用户数据
+     *
+     * @return
+     */
+    @RequestMapping(value = "/whitelist", method = RequestMethod.GET)
+    public List<UsoftWhitelist> getUsoftWhitelists() {
+        return usoftService.getUsoftWhitelists();
+    }
+
+    /**
+     * 获取所有用户历史交易数据
+     * @return
+     */
+    @RequestMapping(value = "/summary/history/trading", method = RequestMethod.GET)
+    public UsoftHistoryTradingData getUsoftHistoryTradingDate() {
+        return usoftService.getUsoftHistoryTradingData();
+    }
+
+    /**
+     * 获取所有用户运营效率分析一览表
+     * @return
+     */
+    @RequestMapping(value = "/summary/running/efficient", method = RequestMethod.GET)
+    public UsoftRunningEfficient getUsoftRunningEfficient() {
+        return usoftService.getUsoftRunningEfficient();
+    }
+
+    /**
+     * 获取所有用户分布区间数据
+     * @return
+     */
+    @RequestMapping(value = "/summary/interval", method = RequestMethod.GET)
+    public UsoftInterval getUsoftInterval() {
+        return usoftService.getUsoftInterval();
+    }
+
+    /**
+     * 获取所有用户近三年交易数据
+     */
+    @RequestMapping(value = "/summary/trading", method = RequestMethod.GET)
+    public List<UsoftTrading> getUsoftTradings() {
+        return usoftService.getUsoftTradings();
+    }
+
+    @Scheduled(cron = "0 0 23 * * ? ")
+    public void whitelistTask() {
+        usoftService.initUsoftWhitelists();
+    }
+}

+ 39 - 0
src/main/java/com/uas/platform/b2b/openapi/dao/UsoftWhitelistDao.java

@@ -0,0 +1,39 @@
+package com.uas.platform.b2b.openapi.dao;
+
+import com.uas.platform.b2b.openapi.model.UsoftWhitelist;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.stereotype.Repository;
+
+import java.util.Set;
+
+/**
+ * @Author: huj
+ * @Date: Created in 15:46 2018/11/12.
+ */
+@Repository
+public interface UsoftWhitelistDao extends JpaSpecificationExecutor<UsoftWhitelist>, JpaRepository<UsoftWhitelist, Long> {
+
+
+    /**
+     * 查询已存在在白名单的企业uu
+     * @return
+     */
+    @Query(value = "SELECT DISTINCT u.enUU from UsoftWhitelist u")
+    Set<Long> findAllEnuu();
+
+    /**
+     * 按企业uu查找白名单企业
+     * @param enUU
+     * @return
+     */
+    UsoftWhitelist findByEnUU(Long enUU);
+
+    /**
+     * 查找白名单数
+     * @return
+     */
+    @Query(nativeQuery = true, value = "select count(1) from  usofwhitelist")
+    Integer countAll();
+}

+ 49 - 0
src/main/java/com/uas/platform/b2b/openapi/model/Product.java

@@ -0,0 +1,49 @@
+package com.uas.platform.b2b.openapi.model;
+
+/**
+ * @Author: huj
+ * @Date: Created in 14:37 2018/11/09.
+ */
+public class Product {
+
+    private String title;
+
+    private String code;
+
+    private String cmpcode;
+
+    private String spec;
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getCmpcode() {
+        return cmpcode;
+    }
+
+    public void setCmpcode(String cmpcode) {
+        this.cmpcode = cmpcode;
+    }
+
+    public String getSpec() {
+        return spec;
+    }
+
+    public void setSpec(String spec) {
+        this.spec = spec;
+    }
+
+}

+ 112 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftAccept.java

@@ -0,0 +1,112 @@
+package com.uas.platform.b2b.openapi.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import com.uas.platform.b2b.openapi.support.NumFormat;
+
+/**
+ * @Author: huj
+ * @Date: Created in 10:13 2018/11/08.
+ */
+public class UsoftAccept {
+
+    private Long id;
+
+    private String code;
+
+    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
+    private String acceptTime;
+
+    private String custName;
+
+    private String receivename;
+
+    private String sendCode;
+
+    private String payments;
+
+    private String currency;
+
+    private Double amount;
+
+    private String remark;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getAcceptTime() {
+        return acceptTime;
+    }
+
+    public void setAcceptTime(String acceptTime) {
+        this.acceptTime = acceptTime;
+    }
+
+    public String getCustName() {
+        return custName;
+    }
+
+    public void setCustName(String custName) {
+        this.custName = custName;
+    }
+
+    public String getReceivename() {
+        return receivename;
+    }
+
+    public void setReceivename(String receivename) {
+        this.receivename = receivename;
+    }
+
+    public String getSendCode() {
+        return sendCode;
+    }
+
+    public void setSendCode(String sendCode) {
+        this.sendCode = sendCode;
+    }
+
+    public String getPayments() {
+        return payments;
+    }
+
+    public void setPayments(String payments) {
+        this.payments = payments;
+    }
+
+    public String getCurrency() {
+        return currency;
+    }
+
+    public void setCurrency(String currency) {
+        this.currency = currency;
+    }
+
+    public Double getAmount() {
+        return NumFormat.getTwo(amount);
+    }
+
+    public void setAmount(Double amount) {
+        this.amount = amount;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+}

+ 110 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftAcceptItem.java

@@ -0,0 +1,110 @@
+package com.uas.platform.b2b.openapi.model;
+
+import com.uas.platform.b2b.openapi.support.NumFormat;
+
+/**
+ * @Author: huj
+ * @Date: Created in 10:13 2018/11/08.
+ */
+public class UsoftAcceptItem {
+
+    private Long id;
+
+    private String orderCode;
+
+    private Product product;
+
+    private String brand;
+
+    private Double price;
+
+    private String unit;
+
+    private Double checkqty;
+
+    private Double amount;
+
+    private String batchCode;
+
+    private Long acceptId;
+
+    public Long getAcceptId() {
+        return acceptId;
+    }
+
+    public void setAcceptId(Long acceptId) {
+        this.acceptId = acceptId;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getOrderCode() {
+        return orderCode;
+    }
+
+    public void setOrderCode(String orderCode) {
+        this.orderCode = orderCode;
+    }
+
+    public Product getProduct() {
+        return product;
+    }
+
+    public void setProduct(Product product) {
+        this.product = product;
+    }
+
+    public String getBrand() {
+        return brand;
+    }
+
+    public void setBrand(String brand) {
+        this.brand = brand;
+    }
+
+    public Double getPrice() {
+        return price;
+    }
+
+    public void setPrice(Double price) {
+        this.price = price;
+    }
+
+    public String getUnit() {
+        return unit;
+    }
+
+    public void setUnit(String unit) {
+        this.unit = unit;
+    }
+
+    public Double getCheckqty() {
+        return checkqty;
+    }
+
+    public void setCheckqty(Double checkqty) {
+        this.checkqty = checkqty;
+    }
+
+    public Double getAmount() {
+        return NumFormat.getTwo(amount);
+    }
+
+    public void setAmount(Double amount) {
+        this.amount = amount;
+    }
+
+    public String getBatchCode() {
+        return batchCode;
+    }
+
+    public void setBatchCode(String batchCode) {
+        this.batchCode = batchCode;
+    }
+}

+ 204 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftHistoryTradingData.java

@@ -0,0 +1,204 @@
+package com.uas.platform.b2b.openapi.model;
+
+import com.uas.platform.b2b.openapi.support.NumFormat;
+
+/**
+ * 所有用户历史交易数据一览表
+ * @Author: huj
+ * @Date: Created in 11:21 2018/11/08.
+ */
+public class UsoftHistoryTradingData {
+
+    /**
+     * 全部用户数量(家)
+     */
+    private Integer totalQty;
+    /**
+     * 有交易额用户数量(家)
+     */
+    private Integer havingTradingQty;
+    /**
+     * 白名单用户数量(家)
+     */
+    private Integer whitelistQty;
+    /**
+     * 历史交易时间(年)
+     */
+    private Double historyTradingHours;
+    /**
+     * 累计订单笔数(笔)
+     */
+    private Double historyOrderNum;
+    /**
+     * 累计订单金额(元)
+     */
+    private Double historyOrderAmount;
+    /**
+     * 累计验收金额(元)
+     */
+    private Double historyAcceptAmount;
+    /**
+     * 累计验退金额(元)
+     */
+    private Double historyReturnAmount;
+    /**
+     * 累计对账金额(元)
+     */
+    private Double historyApcheckAmount;
+    /**
+     * 累计发票金额(元)
+     */
+    private Double historyApbillAmount;
+    /**
+     * 平均单笔订单金额(元)
+     * 等于累计订单金额/累计订单笔数
+     */
+    private Double avgOrderAmount;
+    /**
+     * 平均单笔对账金额(元)
+     * 等于累计对账金额/累计对账笔数
+     */
+    private Double avgApcheckAmount;
+    /**
+     * 平均单笔发票金额(元)
+     * 等于累计发票金额/累计发票笔数
+     */
+    private Double avgApbillAmount;
+    /**
+     * 平均单个用户金额(元)
+     * 等于累计订单金额/全部用户数量
+     */
+    private Double avgUserAmount;
+
+    public Integer getTotalQty() {
+        return totalQty;
+    }
+
+    public void setTotalQty(Integer totalQty) {
+        this.totalQty = totalQty;
+    }
+
+    public Integer getHavingTradingQty() {
+        return havingTradingQty;
+    }
+
+    public void setHavingTradingQty(Integer havingTradingQty) {
+        this.havingTradingQty = havingTradingQty;
+    }
+
+    public Integer getWhitelistQty() {
+        return whitelistQty;
+    }
+
+    public void setWhitelistQty(Integer whitelistQty) {
+        this.whitelistQty = whitelistQty;
+    }
+
+    public Double getHistoryTradingHours() {
+        return NumFormat.getOne(historyTradingHours);
+    }
+
+    public void setHistoryTradingHours(Double historyTradingHours) {
+        this.historyTradingHours = historyTradingHours;
+    }
+
+    public Double getHistoryOrderNum() {
+        return historyOrderNum;
+    }
+
+    public void setHistoryOrderNum(Double historyOrderNum) {
+        this.historyOrderNum = historyOrderNum;
+    }
+
+    public Double getHistoryOrderAmount() {
+        return NumFormat.getTwo(historyOrderAmount);
+    }
+
+    public void setHistoryOrderAmount(Double historyOrderAmount) {
+        this.historyOrderAmount = historyOrderAmount;
+    }
+
+    public Double getHistoryAcceptAmount() {
+        return NumFormat.getTwo(historyAcceptAmount);
+    }
+
+    public void setHistoryAcceptAmount(Double historyAcceptAmount) {
+        this.historyAcceptAmount = historyAcceptAmount;
+    }
+
+    public Double getHistoryReturnAmount() {
+        return NumFormat.getTwo(historyReturnAmount);
+    }
+
+    public void setHistoryReturnAmount(Double historyReturnAmount) {
+        this.historyReturnAmount = historyReturnAmount;
+    }
+
+    public Double getHistoryApcheckAmount() {
+        return NumFormat.getTwo(historyApcheckAmount);
+    }
+
+    public void setHistoryApcheckAmount(Double historyApcheckAmount) {
+        this.historyApcheckAmount = historyApcheckAmount;
+    }
+
+    public Double getHistoryApbillAmount() {
+        return NumFormat.getTwo(historyApbillAmount);
+    }
+
+    public void setHistoryApbillAmount(Double historyApbillAmount) {
+        this.historyApbillAmount = historyApbillAmount;
+    }
+
+    public Double getAvgOrderAmount() {
+        return NumFormat.getTwo(avgOrderAmount);
+    }
+
+    public void setAvgOrderAmount(Double avgOrderAmount) {
+        this.avgOrderAmount = avgOrderAmount;
+    }
+
+    public Double getAvgApcheckAmount() {
+        return NumFormat.getTwo(avgApcheckAmount);
+    }
+
+    public void setAvgApcheckAmount(Double avgApcheckAmount) {
+        this.avgApcheckAmount = avgApcheckAmount;
+    }
+
+    public Double getAvgApbillAmount() {
+        return NumFormat.getTwo(avgApbillAmount);
+    }
+
+    public void setAvgApbillAmount(Double avgApbillAmount) {
+        this.avgApbillAmount = avgApbillAmount;
+    }
+
+    public Double getAvgUserAmount() {
+        return NumFormat.getTwo(avgUserAmount);
+    }
+
+    public void setAvgUserAmount(Double avgUserAmount) {
+        this.avgUserAmount = avgUserAmount;
+    }
+
+    public UsoftHistoryTradingData(Integer totalQty, Integer havingTradingQty, Integer whitelistQty,
+                                   Double historyTradingHours, Double historyOrderNum, Double historyOrderAmount,
+                                   Double historyAcceptAmount, Double historyReturnAmount, Double historyApcheckNum,
+                                   Double historyApcheckAmount, Double historyApbillNum, Double historyApbillAmount) {
+        this.totalQty = totalQty;
+        this.havingTradingQty = havingTradingQty;
+        this.whitelistQty = whitelistQty;
+        this.historyTradingHours = historyTradingHours;
+        this.historyOrderNum = historyOrderNum;
+        this.historyOrderAmount = historyOrderAmount;
+        this.historyAcceptAmount = historyAcceptAmount;
+        this.historyReturnAmount = historyReturnAmount;
+        this.historyApcheckAmount = historyApcheckAmount;
+        this.historyApbillAmount = historyApbillAmount;
+        this.avgOrderAmount = historyOrderNum == null ? 0 : historyOrderAmount/historyOrderNum;
+        this.avgApcheckAmount = historyApcheckNum == null ? 0 : historyApcheckAmount/historyApcheckNum;
+        this.avgApbillAmount = historyApbillNum == null ? 0 : historyApbillAmount/historyApbillNum;
+        this.avgUserAmount = totalQty == null ? 0 : historyOrderAmount/totalQty;
+    }
+}

+ 47 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftInterval.java

@@ -0,0 +1,47 @@
+package com.uas.platform.b2b.openapi.model;
+
+import java.util.Set;
+
+/**
+ * 用户分布区间
+ * @Author: huj
+ * @Date: Created in 11:45 2018/11/08.
+ */
+public class UsoftInterval {
+
+    private Set<UsoftIntervalItem> tradingTime;
+
+    private Set<UsoftIntervalItem> orderAmount;
+
+    private Set<UsoftIntervalItem> orderNum;
+
+    public Set<UsoftIntervalItem> getTradingTime() {
+        return tradingTime;
+    }
+
+    public void setTradingTime(Set<UsoftIntervalItem> tradingTime) {
+        this.tradingTime = tradingTime;
+    }
+
+    public Set<UsoftIntervalItem> getOrderAmount() {
+        return orderAmount;
+    }
+
+    public void setOrderAmount(Set<UsoftIntervalItem> orderAmount) {
+        this.orderAmount = orderAmount;
+    }
+
+    public Set<UsoftIntervalItem> getOrderNum() {
+        return orderNum;
+    }
+
+    public void setOrderNum(Set<UsoftIntervalItem> orderNum) {
+        this.orderNum = orderNum;
+    }
+
+    public UsoftInterval(Set<UsoftIntervalItem> tradingTime, Set<UsoftIntervalItem> orderAmount, Set<UsoftIntervalItem> orderNum) {
+        this.tradingTime = tradingTime;
+        this.orderAmount = orderAmount;
+        this.orderNum = orderNum;
+    }
+}

+ 57 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftIntervalItem.java

@@ -0,0 +1,57 @@
+package com.uas.platform.b2b.openapi.model;
+
+import com.uas.platform.b2b.openapi.support.NumFormat;
+
+/**
+ * @Author: huj
+ * @Date: Created in 11:47 2018/11/08.
+ */
+public class UsoftIntervalItem {
+
+    private String name;
+
+    private Double num;
+
+    private Double percent;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Double getNum() {
+        return num;
+    }
+
+    public void setNum(Double num) {
+        this.num = num;
+    }
+
+    public Double getPercent() {
+        return NumFormat.getTwo(percent);
+    }
+
+    public void setPercent(Double percent) {
+        this.percent = percent;
+    }
+
+    public UsoftIntervalItem(String name, Double num, Double total) {
+        this.name = name;
+        this.num = num;
+        this.percent = num/total;
+    }
+
+
+    @Override
+    public int hashCode() {
+        return super.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
+}

+ 102 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftOrder.java

@@ -0,0 +1,102 @@
+package com.uas.platform.b2b.openapi.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import com.uas.platform.b2b.openapi.support.NumFormat;
+
+/**
+ * @Author: huj
+ * @Date: Created in 09:56 2018/11/08.
+ */
+public class UsoftOrder {
+
+    private Long id;
+
+    private String code;
+
+    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
+    private String orderTime;
+
+    private String custName;
+
+    private String currency;
+
+    private Double amount;
+
+    private String payments;
+
+    private String address;
+
+    private String remark;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getOrderTime() {
+        return orderTime;
+    }
+
+    public void setOrderTime(String orderTime) {
+        this.orderTime = orderTime;
+    }
+
+    public String getCustName() {
+        return custName;
+    }
+
+    public void setCustName(String custName) {
+        this.custName = custName;
+    }
+
+    public String getCurrency() {
+        return currency;
+    }
+
+    public void setCurrency(String currency) {
+        this.currency = currency;
+    }
+
+    public Double getAmount() {
+        return NumFormat.getTwo(amount);
+    }
+
+    public void setAmount(Double amount) {
+        this.amount = amount;
+    }
+
+    public String getPayments() {
+        return payments;
+    }
+
+    public void setPayments(String payments) {
+        this.payments = payments;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+}

+ 91 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftOrderItem.java

@@ -0,0 +1,91 @@
+package com.uas.platform.b2b.openapi.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+
+/**
+ * @Author: huj
+ * @Date: Created in 10:04 2018/11/08.
+ */
+public class UsoftOrderItem {
+
+    private Long id;
+
+    private Product product;
+
+    private Double price;
+
+    private Float rate;
+
+    private Double quantity;
+
+    private String unit;
+
+    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
+    private String delivery;
+
+    private Long orderId;
+
+    public Long getOrderId() {
+        return orderId;
+    }
+
+    public void setOrderId(Long orderId) {
+        this.orderId = orderId;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Product getProduct() {
+        return product;
+    }
+
+    public void setProduct(Product product) {
+        this.product = product;
+    }
+
+    public Double getPrice() {
+        return price;
+    }
+
+    public void setPrice(Double price) {
+        this.price = price;
+    }
+
+    public Float getRate() {
+        return rate;
+    }
+
+    public void setRate(Float rate) {
+        this.rate = rate;
+    }
+
+    public Double getQuantity() {
+        return quantity;
+    }
+
+    public void setQuantity(Double quantity) {
+        this.quantity = quantity;
+    }
+
+    public String getUnit() {
+        return unit;
+    }
+
+    public void setUnit(String unit) {
+        this.unit = unit;
+    }
+
+    public String getDelivery() {
+        return delivery;
+    }
+
+    public void setDelivery(String delivery) {
+        this.delivery = delivery;
+    }
+}

+ 99 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftRunningEfficient.java

@@ -0,0 +1,99 @@
+package com.uas.platform.b2b.openapi.model;
+
+import com.uas.platform.b2b.openapi.support.NumFormat;
+
+/**
+ * 所有用户运营效率分析一览表
+ * @Author: huj
+ * @Date: Created in 11:34 2018/11/08.
+ */
+public class UsoftRunningEfficient {
+
+    /**
+     * 历史退货率(%)
+     * 等于累计验退金额/累计验收金额*100%
+     */
+    private Double historyReturnPCT;
+    /**
+     * 有效订单率(%)
+     * 等于累计验收金额/累计订单金额*100%
+     */
+    private Double effectiveOrderPCT;
+    /**
+     * 历史对账率(%)
+     * 等于累计对账金额/累计订单金额*100%
+     */
+    private Double historyApcheckPCT;
+    /**
+     * 历史开票率(%)
+     * 等于累计开票金额/累计订单金额*100%
+     */
+    private Double historyApbillPCT;
+    /**
+     * 活跃用户率(%)
+     * 等于有交易额用户数量/全部用户数量*100%
+     */
+    private Double activeUserPCT;
+    /**
+     * 准入用户率(%)
+     * 等于白名单用户数量/有交易额用户数量*100%
+     */
+    private Double realUserPCT;
+
+    public Double getHistoryReturnPCT() {
+        return NumFormat.getPercent(historyReturnPCT);
+    }
+
+    public void setHistoryReturnPCT(Double historyReturnPCT) {
+        this.historyReturnPCT = historyReturnPCT;
+    }
+
+    public Double getEffectiveOrderPCT() {
+        return NumFormat.getPercent(effectiveOrderPCT);
+    }
+
+    public void setEffectiveOrderPCT(Double effectiveOrderPCT) {
+        this.effectiveOrderPCT = effectiveOrderPCT;
+    }
+
+    public Double getHistoryApcheckPCT() {
+        return NumFormat.getPercent(historyApcheckPCT);
+    }
+
+    public void setHistoryApcheckPCT(Double historyApcheckPCT) {
+        this.historyApcheckPCT = historyApcheckPCT;
+    }
+
+    public Double getHistoryApbillPCT() {
+        return NumFormat.getPercent(historyApbillPCT);
+    }
+
+    public void setHistoryApbillPCT(Double historyApbillPCT) {
+        this.historyApbillPCT = historyApbillPCT;
+    }
+
+    public Double getActiveUserPCT() {
+        return NumFormat.getPercent(activeUserPCT);
+    }
+
+    public void setActiveUserPCT(Double activeUserPCT) {
+        this.activeUserPCT = activeUserPCT;
+    }
+
+    public Double getRealUserPCT() {
+        return NumFormat.getPercent(realUserPCT);
+    }
+
+    public void setRealUserPCT(Double realUserPCT) {
+        this.realUserPCT = realUserPCT;
+    }
+
+    public UsoftRunningEfficient(UsoftHistoryTradingData data) {
+        this.historyReturnPCT = data.getHistoryReturnAmount()/data.getHistoryAcceptAmount();
+        this.effectiveOrderPCT = data.getHistoryAcceptAmount()/data.getHistoryOrderAmount();
+        this.historyApcheckPCT = data.getHistoryApcheckAmount()/data.getHistoryOrderAmount();
+        this.historyApbillPCT = data.getHistoryApbillAmount()/data.getHistoryOrderAmount();
+        this.activeUserPCT = (double) data.getHavingTradingQty()/data.getTotalQty();
+        this.realUserPCT = (double) data.getWhitelistQty()/data.getHavingTradingQty();
+    }
+}

+ 122 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftTrading.java

@@ -0,0 +1,122 @@
+package com.uas.platform.b2b.openapi.model;
+
+import com.uas.platform.b2b.openapi.support.NumFormat;
+
+/**
+ * 近3年优软云平台交易数据一览表
+ * @Author: huj
+ * @Date: Created in 11:58 2018/11/08.
+ */
+public class UsoftTrading {
+
+    /**
+     * 科目
+     */
+    private String name;
+    /**
+     * 前两年
+     */
+    private Double lastTwoYearNum;
+    /**
+     * 前一年
+     */
+    private Double lastYearNum;
+    /**
+     * 当年
+     */
+    private Double thisYearNum;
+    /**
+     * 合计
+     */
+    private Double total;
+    /**
+     * 平均
+     */
+    private Double avg;
+    /**
+     * 前一年增持绿
+     */
+    private Double lastYearPCT;
+    /**
+     * 当年增长绿
+     */
+    private Double thisYearPCT;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Double getLastTwoYearNum() {
+        return NumFormat.getTwo(lastTwoYearNum);
+    }
+
+    public void setLastTwoYearNum(Double lastTwoYearNum) {
+        this.lastTwoYearNum = lastTwoYearNum;
+    }
+
+    public Double getLastYearNum() {
+        return NumFormat.getTwo(lastYearNum);
+    }
+
+    public void setLastYearNum(Double lastYearNum) {
+        this.lastYearNum = lastYearNum;
+    }
+
+    public Double getThisYearNum() {
+        return NumFormat.getTwo(thisYearNum);
+    }
+
+    public void setThisYearNum(Double thisYearNum) {
+        this.thisYearNum = thisYearNum;
+    }
+
+    public Double getTotal() {
+        return NumFormat.getTwo(total);
+    }
+
+    public void setTotal(Double total) {
+        this.total = total;
+    }
+
+    public Double getAvg() {
+        return NumFormat.getTwo(avg);
+    }
+
+    public void setAvg(Double avg) {
+        this.avg = avg;
+    }
+
+    public Double getLastYearPCT() {
+        return lastYearPCT;
+    }
+
+    public void setLastYearPCT(Double lastYearPCT) {
+        this.lastYearPCT = lastYearPCT;
+    }
+
+    public Double getThisYearPCT() {
+        return thisYearPCT;
+    }
+
+    public void setThisYearPCT(Double thisYearPCT) {
+        this.thisYearPCT = thisYearPCT;
+    }
+
+    public UsoftTrading(String name, Double lastTwoYearNum, Double lastYearNum, Double thisYearNum) {
+        lastTwoYearNum = lastTwoYearNum == null ? 0.0 : lastTwoYearNum;
+        lastYearNum = lastYearNum == null ? 0.0 : lastYearNum;
+        thisYearNum = thisYearNum == null ? 0.0 : thisYearNum;
+        this.name = name;
+        this.lastTwoYearNum = lastTwoYearNum;
+        this.lastYearNum = lastYearNum;
+        this.thisYearNum = thisYearNum;
+        this.total = lastTwoYearNum + lastYearNum + thisYearNum;
+        this.avg = total / 3;
+        this.lastYearPCT = NumFormat.getIncrease(lastTwoYearNum, lastYearNum);
+        this.thisYearPCT = NumFormat.getIncrease(lastYearNum,thisYearNum);
+    }
+}

+ 167 - 0
src/main/java/com/uas/platform/b2b/openapi/model/UsoftWhitelist.java

@@ -0,0 +1,167 @@
+package com.uas.platform.b2b.openapi.model;
+
+import javax.persistence.*;
+
+/**
+ * 白名单用户数据
+ * @Author: huj
+ * @Date: Created in 11:03 2018/11/08.
+ */
+@Entity
+@Table(name = "usofwhitelist", indexes = {@Index(name = "unique_enuu", columnList = "u_enuu", unique = true)})
+public class UsoftWhitelist {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "u_id")
+    private Long id;
+
+    /**
+     * 企业uu
+     */
+    @Column(name = "u_enuu")
+    private Long enUU;
+
+    /**
+     * 企业name
+     */
+    @Column(name = "u_enname")
+    private String enName;
+
+    /**
+     * 企业地址
+     */
+    @Column(name = "u_address")
+    private String address;
+
+    /**
+     * 历史交易时间
+     */
+    @Column(name = "u_history_tradinghours")
+    private Double historyTradingHours;
+
+    /**
+     * 历史交易笔数
+     */
+    @Column(name = "u_history_order_num")
+    private Double historyOrderNum;
+
+    /**
+     * 历史订单总额
+     */
+    @Column(name = "u_history_order_amount")
+    private Double historyOrderAmount;
+
+    /**
+     * 前1年订单笔数(笔)
+     */
+    @Column(name = "u_lastyear_order_num")
+    private Double lastYearOrderNum;
+
+    /**
+     * 前1年订单总额(元)
+     */
+    @Column(name = "u_lastyear_order_amount")
+    private Double lastYearOrderAmount;
+
+    /**
+     * 当年订单笔数(笔)
+     */
+    @Column(name = "u_thisyear_order_num")
+    private Double thisYearOrderNum;
+
+    /**
+     * 当年订单总额
+     */
+    @Column(name = "u_thisyear_order_amount")
+    private Double thisYearOrderAmount;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getEnUU() {
+        return enUU;
+    }
+
+    public void setEnUU(Long enUU) {
+        this.enUU = enUU;
+    }
+
+    public String getEnName() {
+        return enName;
+    }
+
+    public void setEnName(String enName) {
+        this.enName = enName;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public Double getHistoryTradingHours() {
+        return historyTradingHours;
+    }
+
+    public void setHistoryTradingHours(Double historyTradingHours) {
+        this.historyTradingHours = historyTradingHours;
+    }
+
+    public Double getHistoryOrderNum() {
+        return historyOrderNum;
+    }
+
+    public void setHistoryOrderNum(Double historyOrderNum) {
+        this.historyOrderNum = historyOrderNum;
+    }
+
+    public Double getHistoryOrderAmount() {
+        return historyOrderAmount;
+    }
+
+    public void setHistoryOrderAmount(Double historyOrderAmount) {
+        this.historyOrderAmount = historyOrderAmount;
+    }
+
+    public Double getLastYearOrderNum() {
+        return lastYearOrderNum;
+    }
+
+    public void setLastYearOrderNum(Double lastYearOrderNum) {
+        this.lastYearOrderNum = lastYearOrderNum;
+    }
+
+    public Double getLastYearOrderAmount() {
+        return lastYearOrderAmount;
+    }
+
+    public void setLastYearOrderAmount(Double lastYearOrderAmount) {
+        this.lastYearOrderAmount = lastYearOrderAmount;
+    }
+
+    public Double getThisYearOrderNum() {
+        return thisYearOrderNum;
+    }
+
+    public void setThisYearOrderNum(Double thisYearOrderNum) {
+        this.thisYearOrderNum = thisYearOrderNum;
+    }
+
+    public Double getThisYearOrderAmount() {
+        return thisYearOrderAmount;
+    }
+
+    public void setThisYearOrderAmount(Double thisYearOrderAmount) {
+        this.thisYearOrderAmount = thisYearOrderAmount;
+    }
+
+}

+ 8 - 0
src/main/java/com/uas/platform/b2b/openapi/service/TradingDataService.java

@@ -35,4 +35,12 @@ public interface TradingDataService {
      * @return
      */
     ModelMap getRecentOfMonth(Long enUU);
+
+    /**
+     * 交易时间
+     * @param enUU 卖方uu
+     * @param custUU 客户uu
+     * @return 交易时间
+     */
+    Double getTimeSum(Long enUU, Long custUU);
 }

+ 102 - 0
src/main/java/com/uas/platform/b2b/openapi/service/UsoftService.java

@@ -0,0 +1,102 @@
+package com.uas.platform.b2b.openapi.service;
+
+import com.uas.platform.b2b.openapi.model.*;
+
+import java.util.List;
+
+/**
+ * @Author: huj
+ * @Date: Created in 10:36 2018/11/08.
+ */
+public interface UsoftService {
+
+    /**
+     * 根据卖方uu获取订单数据
+     * @param enUU
+     *      卖方uu
+     * @param startTime
+     *      起始时间
+     * @param endTime
+     *      截止时间
+     * @return
+     */
+    List<UsoftOrder> getUsoftOrders(Long enUU, Long startTime, Long endTime);
+
+    /**
+     * 根据订单获取订单明细
+     * @param orderId
+     *      订单id
+     * @return
+     */
+    List<UsoftOrderItem> getUsoftOrderItems(Long orderId);
+
+    /**
+     * 根据订单获取订单明细(批量)
+     * @param orderIds
+     *      订单id
+     * @return
+     */
+    List<UsoftOrderItem> getUsoftOrderItemsBatch(String orderIds);
+
+    /**
+     * 根据卖方uu获取验收单数据
+     * @param enUU
+     *      卖方uu
+     * @param startTime
+     *      起始时间
+     * @param endTime
+     *      截止时间
+     * @return
+     */
+    List<UsoftAccept> getUsoftAccepts(Long enUU, Long startTime, Long endTime);
+
+    /**
+     * 根据验收单id获取验收明细
+     * @param acceptId
+     *      验收单id
+     * @return
+     */
+    List<UsoftAcceptItem> getUsoftAcceptItems(Long acceptId);
+
+    /**
+     * 根据验收单id获取验收明细
+     * @param acceptIds
+     *      验收单id字符串
+     * @return
+     */
+    List<UsoftAcceptItem> getUsoftAcceptItemsBatch(String acceptIds);
+
+    /**
+     * 获取白名单用户数据
+     * @return
+     */
+    List<UsoftWhitelist> getUsoftWhitelists();
+
+    /**
+     * 获取所有用户历史交易数据
+     * @return
+     */
+    UsoftHistoryTradingData getUsoftHistoryTradingData();
+
+    /**
+     * 获取所有用户运营效率分析一览表
+     * @return
+     */
+    UsoftRunningEfficient getUsoftRunningEfficient();
+
+    /**
+     * 获取所有用户分布区间数据
+     * @return
+     */
+    UsoftInterval getUsoftInterval();
+
+    /**
+     * 获取所有用户近三年交易数据
+     */
+    List<UsoftTrading> getUsoftTradings();
+
+    /**
+     * 定时任务初始化or更新白名单企业
+     */
+    void initUsoftWhitelists();
+}

+ 207 - 205
src/main/java/com/uas/platform/b2b/openapi/service/impl/TradingDataServiceImpl.java

@@ -45,7 +45,8 @@ public class TradingDataServiceImpl implements TradingDataService {
         // 获取累计发票金额
         Double apBillSum = getApBillSum(enUU);
         // 获取历史退货率
-        Double historyReturn = NumFormat.getPercent(returnSum / getOrderSum(enUU));
+        Double orderSum = getOrderSum(enUU);
+        Double historyReturn = NumFormat.getPercent(orderSum == 0.0 ? 0.0 : returnSum / orderSum);
         map.put("timeSum", timeSum);
         map.put("acceptSum", acceptSum);
         map.put("returnSum", returnSum);
@@ -70,13 +71,13 @@ public class TradingDataServiceImpl implements TradingDataService {
                 if (StringUtils.isEmpty(acceptSum) || acceptSum == 0.0) {
                     custTrading.setAcceptPercent(0.00);
                 } else {
-                    custTrading.setAcceptPercent(NumFormat.getPercent((acceptSum - returnSum) / sum));
+                    custTrading.setAcceptPercent(NumFormat.getPercent(sum == 0.0 ? 0.0 : (acceptSum - returnSum) / sum));
                 }
                 Integer acceptNum = getAcceptNum(enUU, custTrading.getCustUU());
                 Integer realNum = acceptNum - getReturnNum(enUU, custTrading.getCustUU());
                 custTrading.setRealNum(realNum);
                 if (0 != acceptNum) {
-                    custTrading.setNumPercent(NumFormat.getPercent((double) realNum / sumNum));
+                    custTrading.setNumPercent(NumFormat.getPercent(sumNum == 0 ? 0 : (double) realNum / sumNum));
                 }
                 custTrading.setTimeSum(NumFormat.getOne(getTimeSum(enUU, custTrading.getCustUU())));
             }
@@ -90,93 +91,93 @@ public class TradingDataServiceImpl implements TradingDataService {
         ModelMap map = new ModelMap();
         List<RecentOfYear> years = new ArrayList<>();
         // 有交易额客户数量
-        RecentOfYear ofYear1 = new RecentOfYear("有交易额客户数量");
-        ofYear1.setTwoYear((double) getAcceptCust(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
-        ofYear1.setOneYear((double) getAcceptCust(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
-        ofYear1.setThisYear((double) getAcceptCust(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
-        ofYear1.setOneYearNum(NumFormat.getIncrease(ofYear1.getTwoYear(), ofYear1.getOneYear()));
-        ofYear1.setThisYearNum(NumFormat.getIncrease(ofYear1.getOneYear(), ofYear1.getThisYear()));
-        years.add(ofYear1);
+        RecentOfYear havingTradingQty = new RecentOfYear("有交易额客户数量");
+        havingTradingQty.setTwoYear((double) getAcceptCust(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
+        havingTradingQty.setOneYear((double) getAcceptCust(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        havingTradingQty.setThisYear((double) getAcceptCust(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
+        havingTradingQty.setOneYearNum(NumFormat.getIncrease(havingTradingQty.getTwoYear(), havingTradingQty.getOneYear()));
+        havingTradingQty.setThisYearNum(NumFormat.getIncrease(havingTradingQty.getOneYear(), havingTradingQty.getThisYear()));
+        years.add(havingTradingQty);
         // 验收金额
-        RecentOfYear ofYear2 = new RecentOfYear("验收金额");
-        ofYear2.setTwoYear(getAcceptSumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
-        ofYear2.setOneYear(getAcceptSumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
-        ofYear2.setThisYear(getAcceptSumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
-        ofYear2.setOneYearNum(NumFormat.getIncrease(ofYear2.getTwoYear(), ofYear2.getOneYear()));
-        ofYear2.setThisYearNum(NumFormat.getIncrease(ofYear2.getOneYear(), ofYear2.getThisYear()));
-        years.add(ofYear2);
+        RecentOfYear acceptAmount = new RecentOfYear("验收金额");
+        acceptAmount.setTwoYear(getAcceptSumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
+        acceptAmount.setOneYear(getAcceptSumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        acceptAmount.setThisYear(getAcceptSumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
+        acceptAmount.setOneYearNum(NumFormat.getIncrease(acceptAmount.getTwoYear(), acceptAmount.getOneYear()));
+        acceptAmount.setThisYearNum(NumFormat.getIncrease(acceptAmount.getOneYear(), acceptAmount.getThisYear()));
+        years.add(acceptAmount);
         // 验收笔数
-        RecentOfYear ofYear3 = new RecentOfYear("验收笔数");
-        ofYear3.setTwoYear((double) getAcceptNumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
-        ofYear3.setOneYear((double) getAcceptNumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
-        ofYear3.setThisYear((double) getAcceptNumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
-        ofYear3.setOneYearNum(NumFormat.getIncrease(ofYear3.getTwoYear(), ofYear3.getOneYear()));
-        ofYear3.setThisYearNum(NumFormat.getIncrease(ofYear3.getOneYear(), ofYear3.getThisYear()));
-        years.add(ofYear3);
+        RecentOfYear acceptNum = new RecentOfYear("验收笔数");
+        acceptNum.setTwoYear((double) getAcceptNumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
+        acceptNum.setOneYear((double) getAcceptNumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        acceptNum.setThisYear((double) getAcceptNumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
+        acceptNum.setOneYearNum(NumFormat.getIncrease(acceptNum.getTwoYear(), acceptNum.getOneYear()));
+        acceptNum.setThisYearNum(NumFormat.getIncrease(acceptNum.getOneYear(), acceptNum.getThisYear()));
+        years.add(acceptNum);
         // 验退金额
-        RecentOfYear ofYear4 = new RecentOfYear("验退金额");
-        ofYear4.setTwoYear(getReturnSumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
-        ofYear4.setOneYear(getReturnSumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
-        ofYear4.setThisYear(getReturnSumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
-        ofYear4.setOneYearNum(NumFormat.getIncrease(ofYear4.getTwoYear(), ofYear4.getOneYear()));
-        ofYear4.setThisYearNum(NumFormat.getIncrease(ofYear4.getOneYear(), ofYear4.getThisYear()));
-        years.add(ofYear4);
+        RecentOfYear returnAmount = new RecentOfYear("验退金额");
+        returnAmount.setTwoYear(getReturnSumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
+        returnAmount.setOneYear(getReturnSumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        returnAmount.setThisYear(getReturnSumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
+        returnAmount.setOneYearNum(NumFormat.getIncrease(returnAmount.getTwoYear(), returnAmount.getOneYear()));
+        returnAmount.setThisYearNum(NumFormat.getIncrease(returnAmount.getOneYear(), returnAmount.getThisYear()));
+        years.add(returnAmount);
         // 验退笔数
-        RecentOfYear ofYear5 = new RecentOfYear("验退笔数");
-        ofYear5.setTwoYear((double) getReturnNumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
-        ofYear5.setOneYear((double) getReturnNumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
-        ofYear5.setThisYear((double) getReturnNumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
-        ofYear5.setOneYearNum(NumFormat.getIncrease(ofYear5.getTwoYear(), ofYear5.getOneYear()));
-        ofYear5.setThisYearNum(NumFormat.getIncrease(ofYear5.getOneYear(), ofYear5.getThisYear()));
-        years.add(ofYear5);
+        RecentOfYear returnNum = new RecentOfYear("验退笔数");
+        returnNum.setTwoYear((double) getReturnNumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
+        returnNum.setOneYear((double) getReturnNumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        returnNum.setThisYear((double) getReturnNumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
+        returnNum.setOneYearNum(NumFormat.getIncrease(returnNum.getTwoYear(), returnNum.getOneYear()));
+        returnNum.setThisYearNum(NumFormat.getIncrease(returnNum.getOneYear(), returnNum.getThisYear()));
+        years.add(returnNum);
         // 实收金额
-        RecentOfYear ofYear6 = new RecentOfYear("实收金额");
-        ofYear6.setTwoYear(ofYear2.getTwoYear() - ofYear4.getTwoYear());
-        ofYear6.setOneYear(ofYear2.getOneYear() - ofYear4.getOneYear());
-        ofYear6.setThisYear(ofYear2.getThisYear() - ofYear4.getThisYear());
-        ofYear6.setOneYearNum(NumFormat.getIncrease(ofYear6.getTwoYear(), ofYear6.getOneYear()));
-        ofYear6.setThisYearNum(NumFormat.getIncrease(ofYear6.getOneYear(), ofYear6.getThisYear()));
-        years.add(ofYear6);
+        RecentOfYear realAmount = new RecentOfYear("实收金额");
+        realAmount.setTwoYear(acceptAmount.getTwoYear() - returnAmount.getTwoYear());
+        realAmount.setOneYear(acceptAmount.getOneYear() - returnAmount.getOneYear());
+        realAmount.setThisYear(acceptAmount.getThisYear() - returnAmount.getThisYear());
+        realAmount.setOneYearNum(NumFormat.getIncrease(realAmount.getTwoYear(), realAmount.getOneYear()));
+        realAmount.setThisYearNum(NumFormat.getIncrease(realAmount.getOneYear(), realAmount.getThisYear()));
+        years.add(realAmount);
         // 实收笔数
-        RecentOfYear ofYear7 = new RecentOfYear("实收笔数");
-        ofYear7.setTwoYear(ofYear3.getTwoYear() - ofYear5.getTwoYear());
-        ofYear7.setOneYear(ofYear3.getOneYear() - ofYear5.getOneYear());
-        ofYear7.setThisYear(ofYear3.getThisYear() - ofYear5.getThisYear());
-        ofYear7.setOneYearNum(NumFormat.getIncrease(ofYear7.getTwoYear(), ofYear7.getOneYear()));
-        ofYear7.setThisYearNum(NumFormat.getIncrease(ofYear7.getOneYear(), ofYear7.getThisYear()));
-        years.add(ofYear7);
+        RecentOfYear realNum = new RecentOfYear("实收笔数");
+        realNum.setTwoYear(acceptNum.getTwoYear() - returnNum.getTwoYear());
+        realNum.setOneYear(acceptNum.getOneYear() - returnNum.getOneYear());
+        realNum.setThisYear(acceptNum.getThisYear() - returnNum.getThisYear());
+        realNum.setOneYearNum(NumFormat.getIncrease(realNum.getTwoYear(), realNum.getOneYear()));
+        realNum.setThisYearNum(NumFormat.getIncrease(realNum.getOneYear(), realNum.getThisYear()));
+        years.add(realNum);
         // 对账金额
-        RecentOfYear ofYear8 = new RecentOfYear("对账金额");
-        ofYear8.setTwoYear(getApCheckSumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
-        ofYear8.setOneYear(getApCheckSumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
-        ofYear8.setThisYear(getApCheckSumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
-        ofYear8.setOneYearNum(NumFormat.getIncrease(ofYear8.getTwoYear(), ofYear8.getOneYear()));
-        ofYear8.setThisYearNum(NumFormat.getIncrease(ofYear8.getOneYear(), ofYear8.getThisYear()));
-        years.add(ofYear8);
+        RecentOfYear apcheckAmount = new RecentOfYear("对账金额");
+        apcheckAmount.setTwoYear(getApCheckSumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
+        apcheckAmount.setOneYear(getApCheckSumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        apcheckAmount.setThisYear(getApCheckSumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
+        apcheckAmount.setOneYearNum(NumFormat.getIncrease(apcheckAmount.getTwoYear(), apcheckAmount.getOneYear()));
+        apcheckAmount.setThisYearNum(NumFormat.getIncrease(apcheckAmount.getOneYear(), apcheckAmount.getThisYear()));
+        years.add(apcheckAmount);
         // 对账笔数
-        RecentOfYear ofYear9 = new RecentOfYear("对账笔数");
-        ofYear9.setTwoYear(getApCheckNumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
-        ofYear9.setOneYear(getApCheckNumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
-        ofYear9.setThisYear(getApCheckNumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
-        ofYear9.setOneYearNum(NumFormat.getIncrease(ofYear9.getTwoYear(), ofYear9.getOneYear()));
-        ofYear9.setThisYearNum(NumFormat.getIncrease(ofYear9.getOneYear(), ofYear9.getThisYear()));
-        years.add(ofYear9);
+        RecentOfYear apcheckNum = new RecentOfYear("对账笔数");
+        apcheckNum.setTwoYear(getApCheckNumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
+        apcheckNum.setOneYear(getApCheckNumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        apcheckNum.setThisYear(getApCheckNumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
+        apcheckNum.setOneYearNum(NumFormat.getIncrease(apcheckNum.getTwoYear(), apcheckNum.getOneYear()));
+        apcheckNum.setThisYearNum(NumFormat.getIncrease(apcheckNum.getOneYear(), apcheckNum.getThisYear()));
+        years.add(apcheckNum);
         // 开票金额
-        RecentOfYear ofYear10 = new RecentOfYear("开票金额");
-        ofYear10.setTwoYear(getApBillSumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
-        ofYear10.setOneYear(getApBillSumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
-        ofYear10.setThisYear(getApBillSumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
-        ofYear10.setOneYearNum(NumFormat.getIncrease(ofYear10.getTwoYear(), ofYear10.getOneYear()));
-        ofYear10.setThisYearNum(NumFormat.getIncrease(ofYear10.getOneYear(), ofYear10.getThisYear()));
-        years.add(ofYear10);
+        RecentOfYear apbillAmount = new RecentOfYear("开票金额");
+        apbillAmount.setTwoYear(getApBillSumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
+        apbillAmount.setOneYear(getApBillSumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        apbillAmount.setThisYear(getApBillSumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
+        apbillAmount.setOneYearNum(NumFormat.getIncrease(apbillAmount.getTwoYear(), apbillAmount.getOneYear()));
+        apbillAmount.setThisYearNum(NumFormat.getIncrease(apbillAmount.getOneYear(), apbillAmount.getThisYear()));
+        years.add(apbillAmount);
         // 开票笔数
-        RecentOfYear ofYear11 = new RecentOfYear("开票笔数");
-        ofYear11.setTwoYear(getApBillNumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
-        ofYear11.setOneYear(getApBillNumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
-        ofYear11.setThisYear(getApBillNumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
-        ofYear11.setOneYearNum(NumFormat.getIncrease(ofYear11.getTwoYear(), ofYear11.getOneYear()));
-        ofYear11.setThisYearNum(NumFormat.getIncrease(ofYear11.getOneYear(), ofYear11.getThisYear()));
-        years.add(ofYear11);
+        RecentOfYear apbillNum = new RecentOfYear("开票笔数");
+        apbillNum.setTwoYear(getApBillNumTime(enUU, NumFormat.getTwoYear(), NumFormat.getOneYear()));
+        apbillNum.setOneYear(getApBillNumTime(enUU, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        apbillNum.setThisYear(getApBillNumTime(enUU, NumFormat.getThisYear(), NumFormat.getNow()));
+        apbillNum.setOneYearNum(NumFormat.getIncrease(apbillNum.getTwoYear(), apbillNum.getOneYear()));
+        apbillNum.setThisYearNum(NumFormat.getIncrease(apbillNum.getOneYear(), apbillNum.getThisYear()));
+        years.add(apbillNum);
         map.put("data", years);
         return map;
     }
@@ -191,145 +192,119 @@ public class TradingDataServiceImpl implements TradingDataService {
         Date now = NumFormat.getNowM();
         List<RecentOfMonth> months = new ArrayList<>();
         // 有交易额客户数量
-        RecentOfMonth ofMonth1 = new RecentOfMonth("有交易额客户数量");
-        ofMonth1.setFourMonth((double) getAcceptCust(enUU, four, three));
-        ofMonth1.setThreeMonth((double) getAcceptCust(enUU, three, two));
-        ofMonth1.setTwoMonth((double) getAcceptCust(enUU, two, one));
-        ofMonth1.setOneMonth((double) getAcceptCust(enUU, one, now));
-        ofMonth1.setThreeMonthNum(NumFormat.getIncrease(ofMonth1.getFourMonth(), ofMonth1.getThreeMonth()));
-        ofMonth1.setTwoMonthNum(NumFormat.getIncrease(ofMonth1.getThreeMonth(), ofMonth1.getTwoMonth()));
-        ofMonth1.setOneMonthNum(NumFormat.getIncrease(ofMonth1.getTwoMonth(), ofMonth1.getOneMonth()));
-        months.add(ofMonth1);
+        RecentOfMonth havingTradingQty = new RecentOfMonth("有交易额客户数量");
+        havingTradingQty.setFourMonth((double) getAcceptCust(enUU, four, three));
+        havingTradingQty.setThreeMonth((double) getAcceptCust(enUU, three, two));
+        havingTradingQty.setTwoMonth((double) getAcceptCust(enUU, two, one));
+        havingTradingQty.setOneMonth((double) getAcceptCust(enUU, one, now));
+        havingTradingQty.setThreeMonthNum(NumFormat.getIncrease(havingTradingQty.getFourMonth(), havingTradingQty.getThreeMonth()));
+        havingTradingQty.setTwoMonthNum(NumFormat.getIncrease(havingTradingQty.getThreeMonth(), havingTradingQty.getTwoMonth()));
+        havingTradingQty.setOneMonthNum(NumFormat.getIncrease(havingTradingQty.getTwoMonth(), havingTradingQty.getOneMonth()));
+        months.add(havingTradingQty);
         // 验收金额
-        RecentOfMonth ofMonth2 = new RecentOfMonth("验收金额");
-        ofMonth2.setFourMonth(getAcceptSumTime(enUU, four, three));
-        ofMonth2.setThreeMonth(getAcceptSumTime(enUU, three, two));
-        ofMonth2.setTwoMonth(getAcceptSumTime(enUU, two, one));
-        ofMonth2.setOneMonth(getAcceptSumTime(enUU, one, now));
-        ofMonth2.setThreeMonthNum(NumFormat.getIncrease(ofMonth2.getFourMonth(), ofMonth2.getThreeMonth()));
-        ofMonth2.setTwoMonthNum(NumFormat.getIncrease(ofMonth2.getThreeMonth(), ofMonth2.getTwoMonth()));
-        ofMonth2.setOneMonthNum(NumFormat.getIncrease(ofMonth2.getTwoMonth(), ofMonth2.getOneMonth()));
-        months.add(ofMonth2);
+        RecentOfMonth aceptAmount = new RecentOfMonth("验收金额");
+        aceptAmount.setFourMonth(getAcceptSumTime(enUU, four, three));
+        aceptAmount.setThreeMonth(getAcceptSumTime(enUU, three, two));
+        aceptAmount.setTwoMonth(getAcceptSumTime(enUU, two, one));
+        aceptAmount.setOneMonth(getAcceptSumTime(enUU, one, now));
+        aceptAmount.setThreeMonthNum(NumFormat.getIncrease(aceptAmount.getFourMonth(), aceptAmount.getThreeMonth()));
+        aceptAmount.setTwoMonthNum(NumFormat.getIncrease(aceptAmount.getThreeMonth(), aceptAmount.getTwoMonth()));
+        aceptAmount.setOneMonthNum(NumFormat.getIncrease(aceptAmount.getTwoMonth(), aceptAmount.getOneMonth()));
+        months.add(aceptAmount);
         // 验收笔数
-        RecentOfMonth ofMonth3 = new RecentOfMonth("验收笔数");
-        ofMonth3.setFourMonth((double) getAcceptNumTime(enUU, four, three));
-        ofMonth3.setThreeMonth((double) getAcceptNumTime(enUU, three, two));
-        ofMonth3.setTwoMonth((double) getAcceptNumTime(enUU, two, one));
-        ofMonth3.setOneMonth((double) getAcceptNumTime(enUU, one, now));
-        ofMonth3.setThreeMonthNum(NumFormat.getIncrease(ofMonth3.getFourMonth(), ofMonth3.getThreeMonth()));
-        ofMonth3.setTwoMonthNum(NumFormat.getIncrease(ofMonth3.getThreeMonth(), ofMonth3.getTwoMonth()));
-        ofMonth3.setOneMonthNum(NumFormat.getIncrease(ofMonth3.getTwoMonth(), ofMonth3.getOneMonth()));
-        months.add(ofMonth3);
+        RecentOfMonth aceptNum = new RecentOfMonth("验收笔数");
+        aceptNum.setFourMonth((double) getAcceptNumTime(enUU, four, three));
+        aceptNum.setThreeMonth((double) getAcceptNumTime(enUU, three, two));
+        aceptNum.setTwoMonth((double) getAcceptNumTime(enUU, two, one));
+        aceptNum.setOneMonth((double) getAcceptNumTime(enUU, one, now));
+        aceptNum.setThreeMonthNum(NumFormat.getIncrease(aceptNum.getFourMonth(), aceptNum.getThreeMonth()));
+        aceptNum.setTwoMonthNum(NumFormat.getIncrease(aceptNum.getThreeMonth(), aceptNum.getTwoMonth()));
+        aceptNum.setOneMonthNum(NumFormat.getIncrease(aceptNum.getTwoMonth(), aceptNum.getOneMonth()));
+        months.add(aceptNum);
         // 验退金额
-        RecentOfMonth ofMonth4 = new RecentOfMonth("验退金额");
-        ofMonth4.setFourMonth(getReturnSumTime(enUU, four, three));
-        ofMonth4.setThreeMonth(getReturnSumTime(enUU, three, two));
-        ofMonth4.setTwoMonth(getReturnSumTime(enUU, two, one));
-        ofMonth4.setOneMonth(getReturnSumTime(enUU, one, now));
-        ofMonth4.setThreeMonthNum(NumFormat.getIncrease(ofMonth4.getFourMonth(), ofMonth4.getThreeMonth()));
-        ofMonth4.setTwoMonthNum(NumFormat.getIncrease(ofMonth4.getThreeMonth(), ofMonth4.getTwoMonth()));
-        ofMonth4.setOneMonthNum(NumFormat.getIncrease(ofMonth4.getTwoMonth(), ofMonth4.getOneMonth()));
-        months.add(ofMonth4);
+        RecentOfMonth returnAmount = new RecentOfMonth("验退金额");
+        returnAmount.setFourMonth(getReturnSumTime(enUU, four, three));
+        returnAmount.setThreeMonth(getReturnSumTime(enUU, three, two));
+        returnAmount.setTwoMonth(getReturnSumTime(enUU, two, one));
+        returnAmount.setOneMonth(getReturnSumTime(enUU, one, now));
+        returnAmount.setThreeMonthNum(NumFormat.getIncrease(returnAmount.getFourMonth(), returnAmount.getThreeMonth()));
+        returnAmount.setTwoMonthNum(NumFormat.getIncrease(returnAmount.getThreeMonth(), returnAmount.getTwoMonth()));
+        returnAmount.setOneMonthNum(NumFormat.getIncrease(returnAmount.getTwoMonth(), returnAmount.getOneMonth()));
+        months.add(returnAmount);
         // 验退笔数
-        RecentOfMonth ofMonth5 = new RecentOfMonth("验退笔数");
-        ofMonth5.setFourMonth((double) getReturnNumTime(enUU, four, three));
-        ofMonth5.setThreeMonth((double) getReturnNumTime(enUU, three, two));
-        ofMonth5.setTwoMonth((double) getReturnNumTime(enUU, two, one));
-        ofMonth5.setOneMonth((double) getReturnNumTime(enUU, one, now));
-        ofMonth5.setThreeMonthNum(NumFormat.getIncrease(ofMonth5.getFourMonth(), ofMonth5.getThreeMonth()));
-        ofMonth5.setTwoMonthNum(NumFormat.getIncrease(ofMonth5.getThreeMonth(), ofMonth5.getTwoMonth()));
-        ofMonth5.setOneMonthNum(NumFormat.getIncrease(ofMonth5.getTwoMonth(), ofMonth5.getOneMonth()));
-        months.add(ofMonth5);
+        RecentOfMonth returnNum = new RecentOfMonth("验退笔数");
+        returnNum.setFourMonth((double) getReturnNumTime(enUU, four, three));
+        returnNum.setThreeMonth((double) getReturnNumTime(enUU, three, two));
+        returnNum.setTwoMonth((double) getReturnNumTime(enUU, two, one));
+        returnNum.setOneMonth((double) getReturnNumTime(enUU, one, now));
+        returnNum.setThreeMonthNum(NumFormat.getIncrease(returnNum.getFourMonth(), returnNum.getThreeMonth()));
+        returnNum.setTwoMonthNum(NumFormat.getIncrease(returnNum.getThreeMonth(), returnNum.getTwoMonth()));
+        returnNum.setOneMonthNum(NumFormat.getIncrease(returnNum.getTwoMonth(), returnNum.getOneMonth()));
+        months.add(returnNum);
         // 实收金额
-        RecentOfMonth ofMonth6 = new RecentOfMonth("实收金额");
-        ofMonth6.setFourMonth(ofMonth2.getFourMonth() - ofMonth4.getFourMonth());
-        ofMonth6.setThreeMonth(ofMonth2.getThreeMonth() - ofMonth4.getThreeMonth());
-        ofMonth6.setTwoMonth(ofMonth2.getTwoMonth() - ofMonth4.getTwoMonth());
-        ofMonth6.setOneMonth(ofMonth2.getOneMonth() - ofMonth4.getOneMonth());
-        ofMonth6.setThreeMonthNum(NumFormat.getIncrease(ofMonth6.getFourMonth(), ofMonth6.getThreeMonth()));
-        ofMonth6.setTwoMonthNum(NumFormat.getIncrease(ofMonth6.getThreeMonth(), ofMonth6.getTwoMonth()));
-        ofMonth6.setOneMonthNum(NumFormat.getIncrease(ofMonth6.getTwoMonth(), ofMonth6.getOneMonth()));
-        months.add(ofMonth6);
+        RecentOfMonth realAmount = new RecentOfMonth("实收金额");
+        realAmount.setFourMonth(aceptAmount.getFourMonth() - returnAmount.getFourMonth());
+        realAmount.setThreeMonth(aceptAmount.getThreeMonth() - returnAmount.getThreeMonth());
+        realAmount.setTwoMonth(aceptAmount.getTwoMonth() - returnAmount.getTwoMonth());
+        realAmount.setOneMonth(aceptAmount.getOneMonth() - returnAmount.getOneMonth());
+        realAmount.setThreeMonthNum(NumFormat.getIncrease(realAmount.getFourMonth(), realAmount.getThreeMonth()));
+        realAmount.setTwoMonthNum(NumFormat.getIncrease(realAmount.getThreeMonth(), realAmount.getTwoMonth()));
+        realAmount.setOneMonthNum(NumFormat.getIncrease(realAmount.getTwoMonth(), realAmount.getOneMonth()));
+        months.add(realAmount);
         // 实收笔数
-        RecentOfMonth ofMonth7 = new RecentOfMonth("实收笔数");
-        ofMonth7.setFourMonth(ofMonth3.getFourMonth() - ofMonth5.getFourMonth());
-        ofMonth7.setThreeMonth(ofMonth3.getThreeMonth() - ofMonth5.getThreeMonth());
-        ofMonth7.setTwoMonth(ofMonth3.getTwoMonth() - ofMonth5.getTwoMonth());
-        ofMonth7.setOneMonth(ofMonth3.getOneMonth() - ofMonth5.getOneMonth());
-        ofMonth7.setThreeMonthNum(NumFormat.getIncrease(ofMonth7.getFourMonth(), ofMonth7.getThreeMonth()));
-        ofMonth7.setTwoMonthNum(NumFormat.getIncrease(ofMonth7.getThreeMonth(), ofMonth7.getTwoMonth()));
-        ofMonth7.setOneMonthNum(NumFormat.getIncrease(ofMonth7.getTwoMonth(), ofMonth7.getOneMonth()));
-        months.add(ofMonth7);
+        RecentOfMonth realNum = new RecentOfMonth("实收笔数");
+        realNum.setFourMonth(aceptNum.getFourMonth() - returnNum.getFourMonth());
+        realNum.setThreeMonth(aceptNum.getThreeMonth() - returnNum.getThreeMonth());
+        realNum.setTwoMonth(aceptNum.getTwoMonth() - returnNum.getTwoMonth());
+        realNum.setOneMonth(aceptNum.getOneMonth() - returnNum.getOneMonth());
+        realNum.setThreeMonthNum(NumFormat.getIncrease(realNum.getFourMonth(), realNum.getThreeMonth()));
+        realNum.setTwoMonthNum(NumFormat.getIncrease(realNum.getThreeMonth(), realNum.getTwoMonth()));
+        realNum.setOneMonthNum(NumFormat.getIncrease(realNum.getTwoMonth(), realNum.getOneMonth()));
+        months.add(realNum);
         // 对账金额
-        RecentOfMonth ofMonth8 = new RecentOfMonth("对账金额");
-        ofMonth8.setFourMonth(getApCheckSumTime(enUU, four, three));
-        ofMonth8.setThreeMonth(getApCheckSumTime(enUU, three, two));
-        ofMonth8.setTwoMonth(getApCheckSumTime(enUU, two, one));
-        ofMonth8.setOneMonth(getApCheckSumTime(enUU, one, now));
-        ofMonth8.setThreeMonthNum(NumFormat.getIncrease(ofMonth8.getFourMonth(), ofMonth8.getThreeMonth()));
-        ofMonth8.setTwoMonthNum(NumFormat.getIncrease(ofMonth8.getThreeMonth(), ofMonth8.getTwoMonth()));
-        ofMonth8.setOneMonthNum(NumFormat.getIncrease(ofMonth8.getTwoMonth(), ofMonth8.getOneMonth()));
-        months.add(ofMonth8);
+        RecentOfMonth apcheckAmount = new RecentOfMonth("对账金额");
+        apcheckAmount.setFourMonth(getApCheckSumTime(enUU, four, three));
+        apcheckAmount.setThreeMonth(getApCheckSumTime(enUU, three, two));
+        apcheckAmount.setTwoMonth(getApCheckSumTime(enUU, two, one));
+        apcheckAmount.setOneMonth(getApCheckSumTime(enUU, one, now));
+        apcheckAmount.setThreeMonthNum(NumFormat.getIncrease(apcheckAmount.getFourMonth(), apcheckAmount.getThreeMonth()));
+        apcheckAmount.setTwoMonthNum(NumFormat.getIncrease(apcheckAmount.getThreeMonth(), apcheckAmount.getTwoMonth()));
+        apcheckAmount.setOneMonthNum(NumFormat.getIncrease(apcheckAmount.getTwoMonth(), apcheckAmount.getOneMonth()));
+        months.add(apcheckAmount);
         // 对账笔数
-        RecentOfMonth ofMonth9 = new RecentOfMonth("对账笔数");
-        ofMonth9.setFourMonth(getApCheckNumTime(enUU, four, three));
-        ofMonth9.setThreeMonth(getApCheckNumTime(enUU, three, two));
-        ofMonth9.setTwoMonth(getApCheckNumTime(enUU, two, one));
-        ofMonth9.setOneMonth(getApCheckNumTime(enUU, one, now));
-        ofMonth9.setThreeMonthNum(NumFormat.getIncrease(ofMonth9.getFourMonth(), ofMonth9.getThreeMonth()));
-        ofMonth9.setTwoMonthNum(NumFormat.getIncrease(ofMonth9.getThreeMonth(), ofMonth9.getTwoMonth()));
-        ofMonth9.setOneMonthNum(NumFormat.getIncrease(ofMonth9.getTwoMonth(), ofMonth9.getOneMonth()));
-        months.add(ofMonth9);
+        RecentOfMonth apcheckNum = new RecentOfMonth("对账笔数");
+        apcheckNum.setFourMonth(getApCheckNumTime(enUU, four, three));
+        apcheckNum.setThreeMonth(getApCheckNumTime(enUU, three, two));
+        apcheckNum.setTwoMonth(getApCheckNumTime(enUU, two, one));
+        apcheckNum.setOneMonth(getApCheckNumTime(enUU, one, now));
+        apcheckNum.setThreeMonthNum(NumFormat.getIncrease(apcheckNum.getFourMonth(), apcheckNum.getThreeMonth()));
+        apcheckNum.setTwoMonthNum(NumFormat.getIncrease(apcheckNum.getThreeMonth(), apcheckNum.getTwoMonth()));
+        apcheckNum.setOneMonthNum(NumFormat.getIncrease(apcheckNum.getTwoMonth(), apcheckNum.getOneMonth()));
+        months.add(apcheckNum);
         // 开票金额
-        RecentOfMonth ofMonth10 = new RecentOfMonth("开票金额");
-        ofMonth10.setFourMonth(getApBillSumTime(enUU, four, three));
-        ofMonth10.setThreeMonth(getApBillSumTime(enUU, three, two));
-        ofMonth10.setTwoMonth(getApBillSumTime(enUU, two, one));
-        ofMonth10.setOneMonth(getApBillSumTime(enUU, one, now));
-        ofMonth10.setThreeMonthNum(NumFormat.getIncrease(ofMonth10.getFourMonth(), ofMonth10.getThreeMonth()));
-        ofMonth10.setTwoMonthNum(NumFormat.getIncrease(ofMonth10.getThreeMonth(), ofMonth10.getTwoMonth()));
-        ofMonth10.setOneMonthNum(NumFormat.getIncrease(ofMonth10.getTwoMonth(), ofMonth10.getOneMonth()));
-        months.add(ofMonth10);
+        RecentOfMonth apbillAmount = new RecentOfMonth("开票金额");
+        apbillAmount.setFourMonth(getApBillSumTime(enUU, four, three));
+        apbillAmount.setThreeMonth(getApBillSumTime(enUU, three, two));
+        apbillAmount.setTwoMonth(getApBillSumTime(enUU, two, one));
+        apbillAmount.setOneMonth(getApBillSumTime(enUU, one, now));
+        apbillAmount.setThreeMonthNum(NumFormat.getIncrease(apbillAmount.getFourMonth(), apbillAmount.getThreeMonth()));
+        apbillAmount.setTwoMonthNum(NumFormat.getIncrease(apbillAmount.getThreeMonth(), apbillAmount.getTwoMonth()));
+        apbillAmount.setOneMonthNum(NumFormat.getIncrease(apbillAmount.getTwoMonth(), apbillAmount.getOneMonth()));
+        months.add(apbillAmount);
         // 开票笔数
-        RecentOfMonth ofMonth11 = new RecentOfMonth("开票笔数");
-        ofMonth11.setFourMonth(getApBillNumTime(enUU, four, three));
-        ofMonth11.setThreeMonth(getApBillNumTime(enUU, three, two));
-        ofMonth11.setTwoMonth(getApBillNumTime(enUU, two, one));
-        ofMonth11.setOneMonth(getApBillNumTime(enUU, one, now));
-        ofMonth11.setThreeMonthNum(NumFormat.getIncrease(ofMonth11.getFourMonth(), ofMonth11.getThreeMonth()));
-        ofMonth11.setTwoMonthNum(NumFormat.getIncrease(ofMonth11.getThreeMonth(), ofMonth11.getTwoMonth()));
-        ofMonth11.setOneMonthNum(NumFormat.getIncrease(ofMonth11.getTwoMonth(), ofMonth11.getOneMonth()));
-        months.add(ofMonth11);
+        RecentOfMonth apbillNum = new RecentOfMonth("开票笔数");
+        apbillNum.setFourMonth(getApBillNumTime(enUU, four, three));
+        apbillNum.setThreeMonth(getApBillNumTime(enUU, three, two));
+        apbillNum.setTwoMonth(getApBillNumTime(enUU, two, one));
+        apbillNum.setOneMonth(getApBillNumTime(enUU, one, now));
+        apbillNum.setThreeMonthNum(NumFormat.getIncrease(apbillNum.getFourMonth(), apbillNum.getThreeMonth()));
+        apbillNum.setTwoMonthNum(NumFormat.getIncrease(apbillNum.getThreeMonth(), apbillNum.getTwoMonth()));
+        apbillNum.setOneMonthNum(NumFormat.getIncrease(apbillNum.getTwoMonth(), apbillNum.getOneMonth()));
+        months.add(apbillNum);
         map.put("data", months);
         return map;
     }
 
-    /**
-     * 交易时间
-     * @param enUU 卖方uu
-     * @param custUU 客户uu
-     * @return 交易时间
-     */
-    private Double getTimeSum(Long enUU, Long custUU) {
-        StringBuffer last = new StringBuffer("SELECT ifnull((SELECT pu_date from purc$orders "
-                + "WHERE pu_venduu = " + enUU + " and pu_date is not null ");
-        if (!StringUtils.isEmpty(custUU)) {
-            last.append("and pu_enuu = " + custUU + "");
-        }
-        last.append(" ORDER BY pu_date desc limit 1),now()) pu_date");
-        StringBuffer first = new StringBuffer("SELECT ifnull((SELECT pu_date from purc$orders "
-                + "WHERE pu_venduu = " + enUU + " and pu_date is not null ");
-        if (!StringUtils.isEmpty(custUU)) {
-            first.append("and pu_enuu = " + custUU + "");
-        }
-        first.append(" ORDER BY pu_date asc limit 1),now()) pu_date");
-        Date lastTime = commonDao.queryForObject(last.toString(), Date.class);
-        Date firstTime = commonDao.queryForObject(first.toString(), Date.class);
-        StringBuffer result = new StringBuffer("SELECT TIMESTAMPDIFF(MONTH,'" + firstTime + "','" + lastTime + "')");
-        Double resultTime = commonDao.queryForObject(result.toString(), Double.class) / TimeStauts.TYEAR.value();
-        return NumFormat.getOne(resultTime);
-    }
-
     /**
      * 验收金额
      * @param enUU 卖方uu
@@ -587,4 +562,31 @@ public class TradingDataServiceImpl implements TradingDataService {
         Double result = commonDao.queryForObject(sql.toString(), Double.class);
         return NumFormat.getTwo(result);
     }
+
+    /**
+     * 交易时间
+     * @param enUU 卖方uu
+     * @param custUU 客户uu
+     * @return 交易时间
+     */
+    @Override
+    public Double getTimeSum(Long enUU, Long custUU) {
+        StringBuffer last = new StringBuffer("SELECT ifnull((SELECT pu_date from purc$orders "
+                + "WHERE pu_venduu = " + enUU + " and pu_date is not null ");
+        if (!StringUtils.isEmpty(custUU)) {
+            last.append("and pu_enuu = " + custUU + "");
+        }
+        last.append(" ORDER BY pu_date desc limit 1),now()) pu_date");
+        StringBuffer first = new StringBuffer("SELECT ifnull((SELECT pu_date from purc$orders "
+                + "WHERE pu_venduu = " + enUU + " and pu_date is not null ");
+        if (!StringUtils.isEmpty(custUU)) {
+            first.append("and pu_enuu = " + custUU + "");
+        }
+        first.append(" ORDER BY pu_date asc limit 1),now()) pu_date");
+        Date lastTime = commonDao.queryForObject(last.toString(), Date.class);
+        Date firstTime = commonDao.queryForObject(first.toString(), Date.class);
+        StringBuffer result = new StringBuffer("SELECT TIMESTAMPDIFF(MONTH,'" + firstTime + "','" + lastTime + "')");
+        Double resultTime = commonDao.queryForObject(result.toString(), Double.class) / TimeStauts.TYEAR.value();
+        return NumFormat.getOne(resultTime);
+    }
 }

+ 641 - 0
src/main/java/com/uas/platform/b2b/openapi/service/impl/UsoftServiceImpl.java

@@ -0,0 +1,641 @@
+package com.uas.platform.b2b.openapi.service.impl;
+
+import com.uas.platform.b2b.dao.CommonDao;
+import com.uas.platform.b2b.dao.EnterpriseDao;
+import com.uas.platform.b2b.model.Enterprise;
+import com.uas.platform.b2b.openapi.dao.UsoftWhitelistDao;
+import com.uas.platform.b2b.openapi.model.*;
+import com.uas.platform.b2b.openapi.service.TradingDataService;
+import com.uas.platform.b2b.openapi.service.UsoftService;
+import com.uas.platform.b2b.openapi.support.ErpRate;
+import com.uas.platform.b2b.openapi.support.NumFormat;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.sql.Date;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @Author: huj
+ * @Date: Created in 10:37 2018/11/08.
+ */
+@Service
+public class UsoftServiceImpl implements UsoftService {
+
+    @Autowired
+    CommonDao commonDao;
+
+    @Autowired
+    UsoftWhitelistDao whitelistDao;
+
+    @Autowired
+    TradingDataService tradingDataService;
+
+    @Autowired
+    EnterpriseDao enterpriseDao;
+
+    /**
+     * 根据卖方uu获取订单数据
+     *
+     * @param enUU      卖方uu
+     * @param startTime 起始时间
+     * @param endTime   截止时间
+     * @return
+     */
+    @Override
+    public List<UsoftOrder> getUsoftOrders(Long enUU, Long startTime, Long endTime) {
+        String sql = "select pu_id id,pu_code code,pu_date orderTime,en_name custName,pu_currency currency,pu_payments "
+                + "payments,pu_shipaddress address,ifnull(pu_remark,'') remark,(case pu_currency when 'RMB' then "
+                + "sum(pd_price * pd_qty) "
+                + "when 'USD' then sum(pd_price * pd_qty) * " + ErpRate.USD_RATE + " when 'HKD' then sum(pd_price * pd_qty) "
+                + "* " + ErpRate.HKD_RATE + " end) amount from purc$orders LEFT JOIN sec$enterprises  on pu_enuu = en_uu "
+                + "LEFT JOIN purc$orderitems ON pu_id = pd_puid where pu_venduu = " + enUU + " and pu_date >= '" + new Date(startTime)
+                + "' and pu_date <='" + new Date(endTime) + "' group by pu_id order by pu_date desc";
+
+        return commonDao.query(sql, UsoftOrder.class);
+    }
+
+    /**
+     * 根据订单获取订单明细
+     *
+     * @param orderId 订单id
+     * @return
+     */
+    @Override
+    public List<UsoftOrderItem> getUsoftOrderItems(Long orderId) {
+        String sql = "SELECT pd_id id,pd_price price,pd_taxrate rate,pd_qty quantity,pr_unit unit,"
+                + "pd_delivery  delivery from purc$orderitems WHERE pd_puid = " + orderId;
+        List<UsoftOrderItem> orderItems = commonDao.query(sql, UsoftOrderItem.class);
+        if (!CollectionUtils.isEmpty(orderItems)) {
+            orderItems.forEach( orderItem -> {
+                Product product = commonDao.queryBean("select pr_code code,pr_title title,pr_cmpcode cmpcode,"
+                        + "pr_spec spec from purc$orderitems WHERE pd_id = " + orderItem.getId(), Product.class);
+                orderItem.setProduct(product);
+            });
+        }
+        return orderItems;
+    }
+
+    /**
+     * 根据订单获取订单明细(批量)
+     *
+     * @param orderIds 订单id
+     * @return
+     */
+    @Override
+    public List<UsoftOrderItem> getUsoftOrderItemsBatch(String orderIds) {
+        String sql = "SELECT pd_id id,pd_price price,pd_taxrate rate,pd_qty quantity,pr_unit unit,pd_puid orderId,"
+                + "pd_delivery  delivery from purc$orderitems WHERE pd_puid in (" + orderIds + ")";
+        List<UsoftOrderItem> orderItems = commonDao.query(sql, UsoftOrderItem.class);
+        if (!CollectionUtils.isEmpty(orderItems)) {
+            orderItems.forEach( orderItem -> {
+                Product product = commonDao.queryBean("select pr_code code,pr_title title,pr_cmpcode cmpcode,"
+                        + "pr_spec spec from purc$orderitems WHERE pd_id = " + orderItem.getId(), Product.class);
+                orderItem.setProduct(product);
+            });
+        }
+        return orderItems;
+    }
+
+    /**
+     * 根据卖方uu获取验收单数据
+     *
+     * @param enUU      卖方uu
+     * @param startTime 起始时间
+     * @param endTime   截止时间
+     * @return
+     */
+    @Override
+    public List<UsoftAccept> getUsoftAccepts(Long enUU, Long startTime, Long endTime) {
+        String sql = "SELECT pa_id id,pa_code code,pa_date acceptTime,en_name custName,pa_receivename receivename,ifnull(pa_sendcode,'') "
+                + "sendCode,pa_payments payments,pa_currency currency,ifnull(pa_remark,'') remark,(CASE pa_currency WHEN 'RMB' THEN SUM"
+                + "(pai_qty*pai_orderprice) WHEN 'USD' THEN SUM(pai_qty*pai_orderprice) * 6.85 WHEN 'HKD' THEN SUM"
+                + "(pai_qty*pai_orderprice) * 0.87 END) amount from purc$accept LEFT JOIN sec$enterprises on pa_enuu = en_uu "
+                + "LEFT JOIN purc$acceptitem on pai_paid=pa_id where pa_venduu = " + enUU +" and pa_date >= '" + new Date(startTime)
+                + "' and pa_date <='" + new Date(endTime) + "' GROUP BY pa_id order by pa_date desc";
+        return commonDao.query(sql, UsoftAccept.class);
+    }
+
+    /**
+     * 根据验收单id获取验收明细
+     *
+     * @param acceptId 验收单id
+     * @return
+     */
+    @Override
+    public List<UsoftAcceptItem> getUsoftAcceptItems(Long acceptId) {
+        String sql = "SELECT pai_id id,pu_code orderCode,a.pr_brand brand,a.pr_unit unit,pai_orderprice price,"
+                + "(case pa_currency when 'RMB' then pai_qty * pai_orderprice when 'USD' then pai_qty * pai_orderprice * "
+                + ErpRate.USD_RATE + " when 'HKD' then pai_qty * pai_orderprice * " + ErpRate.HKD_RATE
+                + " end) amount,pai_qty checkqty,pai_batchcode batchCode from purc$acceptitem a "
+                + "LEFT JOIN purc$orderitems on pai_pdid = pd_id LEFT JOIN purc$orders on pd_puid = pu_id LEFT JOIN purc$accept"
+                + " on pai_paid = pa_id where pai_paid = " + acceptId;
+        List<UsoftAcceptItem> acceptItems = commonDao.query(sql, UsoftAcceptItem.class);
+        if (!CollectionUtils.isEmpty(acceptItems)) {
+            acceptItems.forEach( acceptItem -> {
+                Product product = commonDao.queryBean("select pr_code code,pr_title title,pr_cmpcode cmpcode,"
+                        + "pr_spec spec from purc$acceptitem WHERE pai_id = " + acceptItem.getId(), Product.class);
+                acceptItem.setProduct(product);
+            });
+        }
+        return acceptItems;
+    }
+
+    /**
+     * 根据验收单id获取验收明细
+     *
+     * @param acceptIds 验收单id字符串
+     * @return
+     */
+    @Override
+    public List<UsoftAcceptItem> getUsoftAcceptItemsBatch(String acceptIds) {
+        String sql = "SELECT pai_id id,pu_code orderCode,a.pr_brand brand,a.pr_unit unit,pai_orderprice price, pai_paid acceptId,"
+                + "(case pa_currency when 'RMB' then pai_qty * pai_orderprice when 'USD' then pai_qty * pai_orderprice * "
+                + ErpRate.USD_RATE + " when 'HKD' then pai_qty * pai_orderprice * " + ErpRate.HKD_RATE
+                + " end) amount,pai_qty checkqty,pai_batchcode batchCode from purc$acceptitem a "
+                + "LEFT JOIN purc$orderitems on pai_pdid = pd_id LEFT JOIN purc$orders on pd_puid = pu_id LEFT JOIN purc$accept"
+                + " on pai_paid = pa_id where pai_paid in (" + acceptIds + ")";
+        List<UsoftAcceptItem> acceptItems = commonDao.query(sql, UsoftAcceptItem.class);
+        if (!CollectionUtils.isEmpty(acceptItems)) {
+            acceptItems.forEach( acceptItem -> {
+                Product product = commonDao.queryBean("select pr_code code,pr_title title,pr_cmpcode cmpcode,"
+                        + "pr_spec spec from purc$acceptitem WHERE pai_id = " + acceptItem.getId(), Product.class);
+                acceptItem.setProduct(product);
+            });
+        }
+        return acceptItems;
+    }
+
+    /**
+     * 获取白名单用户数据
+     *
+     * @return
+     */
+    @Override
+    public List<UsoftWhitelist> getUsoftWhitelists() {
+        return whitelistDao.findAll();
+    }
+
+    /**
+     * 定时任务初始化白名单企业
+     */
+    @Transactional(rollbackFor = RuntimeException.class)
+    @Override
+    public void initUsoftWhitelists() {
+        List<Long> enuus = enterpriseDao.findEnuu(NumFormat.getsixM());
+        List<Long> realEnuus = new ArrayList<>();
+        // 查找符合条件的企业uu
+        if (!CollectionUtils.isEmpty(enuus)) {
+            enuus.forEach(enuu -> {
+                Double orderNum = orderNum(enuu, null, null);
+                Double orderAmount = orderAmount(enuu, null, null);
+                if (orderNum >= 5.0 && orderAmount >= 1000000.0) {
+                    realEnuus.add(enuu);
+                }
+            });
+        }
+        // 更新或新增白名单企业
+        List<UsoftWhitelist> all = new ArrayList<>();
+        Set<Long> whitelistEnuus = whitelistDao.findAllEnuu();
+        if (!CollectionUtils.isEmpty(realEnuus)) {
+            realEnuus.forEach( enuu -> {
+                // 存在则更新
+                if (whitelistEnuus.contains(enuu)) {
+                    UsoftWhitelist usoftWhitelist = whitelistDao.findByEnUU(enuu);
+                    // 更新白名单企业数据
+                    updateWhitelist(usoftWhitelist, enuu);
+                    all.add(usoftWhitelist);
+                } else {
+                    UsoftWhitelist usoftWhitelist = new UsoftWhitelist();
+                    usoftWhitelist.setEnUU(enuu);
+                    Enterprise enterprise = enterpriseDao.findEnterpriseByUu(enuu);
+                    usoftWhitelist.setEnName(enterprise.getEnName());
+                    usoftWhitelist.setAddress(enterprise.getEnAddress());
+                    updateWhitelist(usoftWhitelist, enuu);
+                    all.add(usoftWhitelist);
+                }
+            });
+            whitelistDao.save(all);
+        }
+    }
+
+    /**
+     * 更新白名单属性
+     * @param usoftWhitelist
+     */
+    private void updateWhitelist(UsoftWhitelist usoftWhitelist, Long enuu) {
+        usoftWhitelist.setHistoryTradingHours(tradingDataService.getTimeSum(enuu, null));
+        usoftWhitelist.setHistoryOrderAmount(orderAmount(enuu, null, null));
+        usoftWhitelist.setLastYearOrderAmount(orderAmount(enuu, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        usoftWhitelist.setThisYearOrderAmount(orderAmount(enuu, NumFormat.getThisYear(), NumFormat.getNow()));
+        usoftWhitelist.setHistoryOrderNum(orderNum(enuu, null, null));
+        usoftWhitelist.setLastYearOrderNum(orderNum(enuu, NumFormat.getOneYear(), NumFormat.getThisYear()));
+        usoftWhitelist.setThisYearOrderNum(orderNum(enuu, NumFormat.getThisYear(), NumFormat.getNow()));
+    }
+
+    /**
+     * 订单笔数
+     * @param vendUU
+     * @return
+     */
+    private Double orderNum(Long vendUU, Date start, Date end) {
+        StringBuilder sql = new StringBuilder("select count(1) from purc$orders where pu_venduu = "  + vendUU);
+        if (!StringUtils.isEmpty(vendUU) && !StringUtils.isEmpty(end)) {
+            sql.append(" and pu_date >='" + start + "' and pu_date < '" + end + "'");
+        }
+        return commonDao.queryForObject(sql.toString(), Double.class);
+    }
+
+    /**
+     * 订单金额
+     * @param vendUU
+     * @return
+     */
+    private Double orderAmount(Long vendUU, Date start, Date end) {
+        StringBuffer sql = new StringBuffer("SELECT sum(case currency when 'RMB' then a.amount when 'USD' "
+                + "then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE + " end) result "
+                + "FROM (SELECT sum(pd_price*pd_qty) amount,pu_currency currency FROM purc$orders LEFT JOIN purc$orderitems "
+                + "on pu_id=pd_puid where pu_venduu = " + vendUU );
+        if (!StringUtils.isEmpty(start) && !StringUtils.isEmpty(end)) {
+            sql.append(" and pu_date >='" + start + "' and pu_date < '" + end + "'");
+        }
+        sql.append(" GROUP BY pu_currency) a");
+        Double result = commonDao.queryForObject(sql.toString(), Double.class);
+        return result;
+    }
+
+    /**
+     * 获取所有用户历史交易数据
+     *
+     * @return
+     */
+    @Override
+    public UsoftHistoryTradingData getUsoftHistoryTradingData() {
+        // 全部用户数量(家)
+        Integer totalQty = commonDao.queryForObject("select count(1) from sec$enterprises", Integer.class);
+        // 有交易额用户数量(家)
+        Integer havingTradingQty = commonDao.queryForObject("select COUNT(DISTINCT pu_venduu) from purc$orders", Integer.class);
+        // 白名单用户数量(家)
+        Integer whitelistQty = whitelistDao.countAll();
+        // 历史交易时间(年)
+        Date startTime =  commonDao.queryForObject("select min(pu_date) from purc$orders WHERE pu_date is not null ", Date.class);
+        Date endTime =  new Date(new java.util.Date().getTime());
+        Double historyTradingHours = commonDao.queryForObject("SELECT TIMESTAMPDIFF(MONTH,'" + startTime + "','" + endTime + "')", Double.class)/12;
+        // 累计订单笔数(笔)
+        Double historyOrderNum = commonDao.queryForObject("select COUNT(1) from purc$orders", Double.class);
+        // 累计订单金额(元)
+        Double historyOrderAmount = commonDao.queryForObject("SELECT sum(case currency when 'RMB' then a.amount "
+                + "when 'USD' then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE + " end) "
+                + "result FROM (SELECT sum(pd_price*pd_qty) amount,pu_currency currency FROM purc$orders LEFT JOIN purc$orderitems "
+                + "on pu_id=pd_puid  GROUP BY pu_currency) a", Double.class);
+        // 累计验收金额(元)
+        Double historyAcceptAmount = commonDao.queryForObject("SELECT sum(case currency when 'RMB' then a.amount " +
+                "when 'USD' then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE
+                + " end) result FROM (SELECT SUM(pai_qty*pai_orderprice) amount,pa_currency currency FROM purc$accept "
+                + " LEFT JOIN purc$acceptitem on pai_paid=pa_id GROUP BY pa_currency) a", Double.class);
+        // 累计验退金额(元)
+        Double historyReturnAmount = commonDao.queryForObject("SELECT sum(case currency when 'RMB' then a.amount "
+                + "when 'USD' then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE
+                + " end)  result FROM (SELECT SUM(pri_qty*pri_orderprice) amount,pr_currency currency FROM purc$return  "
+                + "LEFT JOIN purc$returnitem on pri_prid=pr_id GROUP BY pr_currency) a", Double.class);
+        // 累计对账笔数
+        Double historyApcheckNum = commonDao.queryForObject("select count(1) from purc$apcheck where "
+                + "pa_checkstatus = '已确认'", Double.class);
+        // 累计对账金额(元)
+        Double historyApcheckAmount = commonDao.queryForObject("SELECT sum(case currency when 'RMB' then a.amount " +
+                "when 'USD' then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE
+                + " end) result FROM (select sum(pa_checkamount) amount,pa_currency currency from purc$apcheck where "
+                + "pa_checkstatus = '已确认' GROUP BY pa_currency) a", Double.class);
+        // 累计发票笔数
+        Double historyApbillNum = commonDao.queryForObject("select count(1) from purc$apbill", Double.class);
+        // 累计发票金额(元)
+        Double historyApbillAmount = commonDao.queryForObject("SELECT sum(case currency when 'RMB' then a.amount "
+                + "when 'USD' then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE
+                + " end) result FROM (SELECT SUM(pab_paymount) amount,pab_currency currency FROM purc$apbill "
+                + "GROUP BY pab_currency) a", Double.class);
+        UsoftHistoryTradingData data = new UsoftHistoryTradingData(totalQty, havingTradingQty, whitelistQty,
+                historyTradingHours, historyOrderNum, historyOrderAmount, historyAcceptAmount, historyReturnAmount,
+                historyApcheckNum, historyApcheckAmount, historyApbillNum, historyApbillAmount);
+        return data;
+    }
+
+    /**
+     * 获取所有用户运营效率分析一览表
+     *
+     * @return
+     */
+    @Override
+    public UsoftRunningEfficient getUsoftRunningEfficient() {
+        UsoftHistoryTradingData data = getUsoftHistoryTradingData();
+        UsoftRunningEfficient runningEfficient = new UsoftRunningEfficient(data);
+        return runningEfficient;
+    }
+
+    /**
+     * 获取所有用户分布区间数据
+     *
+     * @return
+     */
+    @Override
+    public UsoftInterval getUsoftInterval() {
+        Double havingTradingQty = commonDao.queryForObject("SELECT COUNT(1) from (SELECT pu_venduu,"
+                + "TIMESTAMPDIFF(MONTH,min(pu_date),Max(pu_date)) mouth from purc$orders GROUP BY pu_venduu) a ", Double.class);
+        Double total = commonDao.queryForObject("select count(1) from sec$enterprises", Double.class);
+        Set<UsoftIntervalItem> tradingTime = new HashSet<>(7);
+        tradingTime.add(getTradingTime("4年(含)以上", 48, null, total, "moreThan"));
+        tradingTime.add(getTradingTime("3年(含)- 4年", 36, 48, total, "inter"));
+        tradingTime.add(getTradingTime("2年(含)- 3年", 24, 36, total, "inter"));
+        tradingTime.add(getTradingTime("1年(含)- 2年", 12, 24, total, "inter"));
+        tradingTime.add(getTradingTime("6个月(含)- 1年", 6, 12, total, "inter"));
+        tradingTime.add(getTradingTime("3个月(含)- 6个月", 3, 6, total, "inter"));
+        tradingTime.add(getTradingTime("3个月以下", null, 3, total, "lessThan"));
+        Set<UsoftIntervalItem> orderAmount = new HashSet<>(7);
+        orderAmount.add(getOrderAmount("5000万(含)以上", 50000000, null, total, "moreThan"));
+        orderAmount.add(getOrderAmount("3000万(含)- 5000万", 30000000, 50000000, total, "inter"));
+        orderAmount.add(getOrderAmount("1000万(含)- 3000万", 10000000, 30000000, total, "inter"));
+        orderAmount.add(getOrderAmount("500万(含)- 1000万", 5000000, 10000000, total, "inter"));
+        orderAmount.add(getOrderAmount("100万(含)- 500万", 1000000, 5000000, total, "inter"));
+        orderAmount.add(getOrderAmount("0-100万", null, 1000000, total, "lessThan"));
+        orderAmount.add(new UsoftIntervalItem("0",total - havingTradingQty, total));
+        Set<UsoftIntervalItem> orderNum = new HashSet<>(7);
+        orderNum.add(getOrderNum("2000笔(含)以上", 2000, null, total, "moreThan"));
+        orderNum.add(getOrderNum("1000笔(含)- 2000笔", 1000, 2000, total, "inter"));
+        orderNum.add(getOrderNum("500笔(含)- 1000笔", 500, 1000, total, "inter"));
+        orderNum.add(getOrderNum("200笔(含)- 500笔", 200, 500, total, "inter"));
+        orderNum.add(getOrderNum("50笔(含)- 200笔", 50, 200, total, "inter"));
+        orderNum.add(getOrderNum("0-50笔", null, 50, total, "lessThan"));
+        orderNum.add(new UsoftIntervalItem("0",total - havingTradingQty, total));
+        UsoftInterval usoftInterval = new UsoftInterval(tradingTime, orderAmount, orderNum);
+        return usoftInterval;
+    }
+
+    /**
+     * 用户分布区间交易时间
+     * @param name
+     * @param start
+     * @param end
+     * @param total
+     * @return
+     */
+    private UsoftIntervalItem getTradingTime(String name, Integer start, Integer end, Double total, String type) {
+        StringBuilder sql = new StringBuilder("SELECT COUNT(1) from (SELECT pu_venduu,TIMESTAMPDIFF(MONTH,min(pu_date)," +
+                "Max(pu_date)) mouth from purc$orders GROUP BY pu_venduu) a ");
+        if ("moreThan".equals(type)) {
+            sql.append(" where a.mouth >= " + start);
+        }
+        if ("inter".equals(type)) {
+            sql.append("where a.mouth < " + end + " and a.mouth >= " + start);
+        }
+        if ("lessThan".equals(type)) {
+            sql.append(" where a.mouth < " + end);
+        }
+        UsoftIntervalItem usoftIntervalItem = new UsoftIntervalItem(name, commonDao.queryForObject(sql.toString(),
+                Double.class), total);
+        return usoftIntervalItem;
+    }
+
+    /**
+     * 用户分布区间订单总额
+     * @param name
+     * @param start
+     * @param end
+     * @param total
+     * @param type
+     * @return
+     */
+    private UsoftIntervalItem getOrderAmount(String name, Integer start, Integer end, Double total, String type) {
+        StringBuilder sql = new StringBuilder("SELECT COUNT(1) from (SELECT venduu,sum(case currency when 'RMB' then "
+                + "a.amount when 'USD' then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE
+                + " end) result FROM (SELECT pu_venduu venduu,sum(pd_price*pd_qty) amount,pu_currency currency "
+                + "FROM purc$orders LEFT JOIN purc$orderitems on pu_id=pd_puid GROUP BY pu_venduu,pu_currency) a "
+                + "GROUP BY venduu) r  ");
+        if ("moreThan".equals(type)) {
+            sql.append(" where r.result  >= " + start);
+        }
+        if ("inter".equals(type)) {
+            sql.append("where r.result < " + end + " and r.result >= " + start);
+        }
+        if ("lessThan".equals(type)) {
+            sql.append(" where r.result < " + end);
+        }
+        UsoftIntervalItem usoftIntervalItem = new UsoftIntervalItem(name, commonDao.queryForObject(sql.toString(),
+                Double.class), total);
+        return usoftIntervalItem;
+    }
+
+    /**
+     * 用户分布区间订单笔数
+     * @param name
+     * @param start
+     * @param end
+     * @param total
+     * @param type
+     * @return
+     */
+    private UsoftIntervalItem getOrderNum(String name, Integer start, Integer end, Double total, String type) {
+        StringBuilder sql = new StringBuilder("select COUNT(1) from (SELECT COUNT(1) count,pu_venduu from purc$orders "
+                +"GROUP BY pu_venduu) a ");
+        if ("moreThan".equals(type)) {
+            sql.append("where count >= " + start);
+        }
+        if ("inter".equals(type)) {
+            sql.append("where count  < " + end + " and count >= " + start);
+        }
+        if ("lessThan".equals(type)) {
+            sql.append(" where count < " + end);
+        }
+        UsoftIntervalItem usoftIntervalItem = new UsoftIntervalItem(name, commonDao.queryForObject(sql.toString(),
+                Double.class), total);
+        return usoftIntervalItem;
+    }
+
+    /**
+     * 获取所有用户近三年交易数据
+     */
+    @Override
+    public List<UsoftTrading> getUsoftTradings() {
+        Date twoYear = NumFormat.getTwoYear();
+        Date oneYear = NumFormat.getOneYear();
+        Date thisYear = NumFormat.getThisYear();
+        Date now = NumFormat.getNow();
+        List<UsoftTrading> tradings = new ArrayList<>(10);
+        UsoftTrading totalQty = new UsoftTrading( "全部用户数量", getTotalQty(twoYear, oneYear),
+                getTotalQty(oneYear, thisYear), getTotalQty(thisYear, now));
+        tradings.add(totalQty);
+        Double acceptAmountTwoYear = getAcceptAmount(twoYear, oneYear);
+        Double acceptAmountOneYear = getAcceptAmount(oneYear, thisYear);
+        Double acceptAmountThisYear = getAcceptAmount(thisYear, now);
+        Double havingTradingQtyTwoYear = getHavingTradingQty(twoYear, oneYear);
+        Double havingTradingQtyOneYear = getHavingTradingQty(oneYear, thisYear);
+        Double havingTradingQtyThisYear = getHavingTradingQty(thisYear, now);
+        Double returnAmountTwoYear = getReturnAmount(twoYear, oneYear);
+        Double returnAmountOneYear = getReturnAmount(oneYear, thisYear);
+        Double returnAmountThisYear = getReturnAmount(thisYear, now);
+        UsoftTrading havingTradingQty = new UsoftTrading("有交易额客户数量", getHavingTradingQty(twoYear, oneYear),
+                getHavingTradingQty(oneYear, thisYear), getHavingTradingQty(thisYear, now));
+        tradings.add(havingTradingQty);
+        UsoftTrading avgUser = new UsoftTrading("平均单个用户验收金额",
+                acceptAmountTwoYear/havingTradingQtyTwoYear,
+                acceptAmountOneYear/havingTradingQtyOneYear,
+                acceptAmountThisYear/havingTradingQtyThisYear);
+        tradings.add(avgUser);
+        tradings.add(havingTradingQty);
+        UsoftTrading orderAmount = new UsoftTrading("订单金额", getOrderAmount(twoYear, oneYear),
+                getOrderAmount(oneYear, thisYear), getOrderAmount(thisYear, now));
+        tradings.add(orderAmount);
+        UsoftTrading orderNum = new UsoftTrading("订单笔数", getOrderNum(twoYear, oneYear),
+                getOrderNum(oneYear, thisYear), getOrderNum(thisYear, now));
+        tradings.add(orderNum);
+        UsoftTrading acceptAmount = new UsoftTrading("验收金额", acceptAmountTwoYear, acceptAmountOneYear,
+                acceptAmountThisYear);
+        tradings.add(acceptAmount);
+        UsoftTrading returnAmount = new UsoftTrading("验退金额", returnAmountTwoYear, returnAmountOneYear,
+                returnAmountThisYear);
+        tradings.add(returnAmount);
+        UsoftTrading realAmount = new UsoftTrading("实收金额", acceptAmountTwoYear -
+                returnAmountTwoYear, acceptAmountOneYear - returnAmountOneYear,
+                acceptAmountThisYear - returnAmountThisYear);
+        tradings.add(realAmount);
+        UsoftTrading apcheckAmount = new UsoftTrading("对账金额", getApcheckAmount(twoYear, oneYear),
+                getApcheckAmount(oneYear, thisYear), getApcheckAmount(thisYear, now));
+        tradings.add(apcheckAmount);
+        UsoftTrading apbillAount = new UsoftTrading("开票金额", getApbillAmount(twoYear, oneYear),
+                getApbillAmount(oneYear, thisYear), getApbillAmount(thisYear, now));
+        tradings.add(apbillAount);
+        return tradings;
+    }
+
+    /**
+     * 全部用户数量
+     * @param start
+     *      起始时间
+     * @param end
+     *      截止时间
+     * @return
+     */
+    private Double getTotalQty(Date start, Date end) {
+        StringBuilder sql = new StringBuilder("SELECT COUNT(1) from sec$enterprises WHERE en_time >= ' " + start
+                + " ' and en_time < ' " +  end +"'");
+        Double total = commonDao.queryForObject(sql.toString(), Double.class);
+        return total;
+    }
+
+    /**
+     * 有交易额客户
+     * @param start
+     *      起始时间
+     * @param end
+     *      截止时间
+     * @return
+     */
+    private Double getHavingTradingQty(Date start, Date end) {
+        StringBuilder sql = new StringBuilder("select COUNT(DISTINCT pu_venduu) from purc$orders WHERE pu_date >= ' " + start
+                + " ' and pu_date < ' " +  end +"'");
+        return commonDao.queryForObject(sql.toString(), Double.class);
+    }
+
+    /**
+     * 订单笔数
+     * @param start
+     *      起始时间
+     * @param end
+     *      截止时间
+     * @return
+     */
+    private Double getOrderNum(Date start, Date end) {
+        StringBuilder sql = new StringBuilder("select COUNT(1) from purc$orders WHERE pu_date >= ' " + start
+                + " ' and pu_date < ' " +  end +"'");
+        return commonDao.queryForObject(sql.toString(), Double.class);
+    }
+
+    /**
+     * 订单金额
+     * @param start
+     *      起始时间
+     * @param end
+     *      截止时间
+     * @return
+     */
+    private Double getOrderAmount(Date start, Date end) {
+        StringBuilder sql = new StringBuilder("SELECT sum(case currency when 'RMB' then a.amount when 'USD' then "
+                + "a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE + " end) "
+                + "result FROM (SELECT sum(pd_price*pd_qty) amount,pu_currency currency FROM purc$orders LEFT JOIN "
+                + "purc$orderitems on pu_id=pd_puid WHERE pu_date >= ' " + start  + " ' and pu_date < ' " +  end
+                + "' GROUP BY pu_currency) a");
+        return commonDao.queryForObject(sql.toString(), Double.class);
+    }
+
+    /**
+     * 验收金额
+     * @param start
+     *      起始时间
+     * @param end
+     *      截止时间
+     * @return
+     */
+    private Double getAcceptAmount(Date start, Date end) {
+        StringBuilder sql = new StringBuilder("SELECT sum(case currency when 'RMB' then a.amount when 'USD' then " +
+                "a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE  + " end) "
+                + "result FROM (SELECT SUM(pai_qty*pai_orderprice) amount,pa_currency currency FROM purc$accept "
+                + " LEFT JOIN purc$acceptitem on pai_paid=pa_id where pa_date >= ' " + start  + " ' and pa_date < ' "
+                +  end + "' GROUP BY pa_currency) a");
+        return commonDao.queryForObject(sql.toString(), Double.class);
+    }
+
+    /**
+     * 验退金额
+     * @param start
+     *      起始时间
+     * @param end
+     *      截止时间
+     * @return
+     */
+    private Double getReturnAmount(Date start, Date end) {
+        StringBuilder sql = new StringBuilder("SELECT sum(case currency when 'RMB' then a.amount "
+                + "when 'USD' then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE
+                + " end)  result FROM (SELECT SUM(pri_qty*pri_orderprice) amount,pr_currency currency FROM purc$return"
+                + " LEFT JOIN purc$returnitem on pri_prid=pr_id where pr_date >= ' " + start  + " ' and pr_date < ' "
+                +  end + "' GROUP BY pr_currency) a");
+        return commonDao.queryForObject(sql.toString(), Double.class);
+    }
+
+    /**
+     * 对账金额
+     * @param start
+     *      起始时间
+     * @param end
+     *      截止时间
+     * @return
+     */
+    private Double getApcheckAmount(Date start, Date end) {
+        StringBuilder sql = new StringBuilder("SELECT sum(case currency when 'RMB' then a.amount " +
+                "when 'USD' then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE
+                + " end) result FROM (select sum(pa_checkamount) amount,pa_currency currency from purc$apcheck where "
+                + "pa_checkstatus = '已确认' and pa_recorddate >= ' " + start  + " ' and pa_recorddate < ' "
+                +  end + "' GROUP BY pa_currency) a");
+        return commonDao.queryForObject(sql.toString(), Double.class);
+    }
+
+    /**
+     * 开票金额
+     * @param start
+     *      起始时间
+     * @param end
+     *      截止时间
+     * @return
+     */
+    private Double getApbillAmount(Date start, Date end) {
+        StringBuilder sql = new StringBuilder("SELECT sum(case currency when 'RMB' then a.amount "
+                + "when 'USD' then a.amount * " + ErpRate.USD_RATE + " when 'HKD' then a.amount * " + ErpRate.HKD_RATE
+                + " end) result FROM (SELECT SUM(pab_paymount) amount,pab_currency currency FROM purc$apbill where  "
+                + " pab_date >= ' " + start  + " ' and pab_date < ' "  +  end + "'" + "GROUP BY pab_currency) a");
+        return commonDao.queryForObject(sql.toString(), Double.class);
+    }
+
+}

+ 7 - 1
src/main/java/com/uas/platform/b2b/openapi/support/NumFormat.java

@@ -3,7 +3,6 @@ package com.uas.platform.b2b.openapi.support;
 import org.springframework.util.StringUtils;
 
 import java.text.DecimalFormat;
-import java.text.NumberFormat;
 import java.util.Calendar;
 import java.util.Date;
 
@@ -86,6 +85,13 @@ public class NumFormat {
         return 0.0;
     }
 
+    public static java.sql.Date getsixM() {
+        Calendar ca = Calendar.getInstance();
+        ca.setTime(getDayStartMon());
+        ca.add(Calendar.MONTH, -6);
+        return new java.sql.Date(ca.getTime().getTime());
+    }
+
     public static java.sql.Date getThreeM() {
         Calendar ca = Calendar.getInstance();
         ca.setTime(getDayStartMon());

+ 19 - 1
src/main/java/com/uas/platform/b2b/service/impl/ErpProdIODetailServiceImpl.java

@@ -1,15 +1,21 @@
 package com.uas.platform.b2b.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.uas.platform.b2b.core.util.DateFormatUtils;
 import com.uas.platform.b2b.core.util.DateUtils;
+import com.uas.platform.b2b.core.util.ThreadUtils;
 import com.uas.platform.b2b.dao.CommonDao;
+import com.uas.platform.b2b.dao.VendorDao;
 import com.uas.platform.b2b.model.ApcheckKeyWord;
 import com.uas.platform.b2b.model.ErpProdIODetail;
 import com.uas.platform.b2b.model.ErpProdIo;
+import com.uas.platform.b2b.model.Vendor;
 import com.uas.platform.b2b.publicapi.model.TradeCount;
 import com.uas.platform.b2b.service.ErpProdIODetailService;
 import com.uas.platform.b2b.service.PurchaseApCheckService;
+import com.uas.platform.b2b.support.CollectionUtil;
 import com.uas.platform.b2b.support.SystemSession;
+import com.uas.platform.b2b.task.ApCheckTask;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import org.apache.axis.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -36,6 +42,9 @@ public class ErpProdIODetailServiceImpl implements ErpProdIODetailService {
 	@Autowired
     private PurchaseApCheckService apCheckService;
 
+	@Autowired
+    private VendorDao vendorDao;
+
 	@Override
 	public ErpProdIo findXlsApChecks(List<Long> filter, ApcheckKeyWord keyword, Long fromDate, Long endDate, String checkDate) {
 		Long enUU = SystemSession.getUser().getEnterprise().getUu();
@@ -101,7 +110,16 @@ public class ErpProdIODetailServiceImpl implements ErpProdIODetailService {
         erpProdIo.setDetails(details);
         // 应收总额
         List<TradeCount> totalTrades = apCheckService.getDueTrade(enUU, keyword.getCustomerUU());
-        erpProdIo.setTotalCount(totalTrades);
+        List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(keyword.getCustomerUU(), enUU);
+        if (!CollectionUtil.isEmpty(totalTrades)) {
+            erpProdIo.setTotalCount(totalTrades);
+            if (!CollectionUtil.isEmpty(vendors)) {
+                String tradeString = JSON.toJSONString(totalTrades);
+                ThreadUtils.task(()
+                    -> commonDao.getJdbcTemplate().update(String.format(ApCheckTask.UPDATE_COUNT_SQL, tradeString, vendors.get(0).getId()))
+                );
+            }
+        }
         // 本月应收
         List<TradeCount> thisMonthTrades = apCheckService.getThisMonthTrade(enUU, keyword.getCustomerUU(), checkDate, fromDate, endDate);
         erpProdIo.setThisMonthCount(thisMonthTrades);

+ 51 - 4
src/main/java/com/uas/platform/b2b/service/impl/PurchaseApCheckServiceImpl.java

@@ -1,8 +1,10 @@
 package com.uas.platform.b2b.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.uas.platform.b2b.core.util.ContextUtils;
 import com.uas.platform.b2b.core.util.DateFormatUtils;
 import com.uas.platform.b2b.core.util.DateUtils;
+import com.uas.platform.b2b.core.util.StringUtil;
 import com.uas.platform.b2b.core.util.ThreadUtils;
 import com.uas.platform.b2b.dao.CommonDao;
 import com.uas.platform.b2b.dao.EnterpriseDao;
@@ -10,6 +12,7 @@ import com.uas.platform.b2b.dao.PurchaseApCheckDao;
 import com.uas.platform.b2b.dao.PurchaseApCheckDoneDao;
 import com.uas.platform.b2b.dao.PurchaseApCheckItemDao;
 import com.uas.platform.b2b.dao.PurchaseApCheckTodoDao;
+import com.uas.platform.b2b.dao.VendorDao;
 import com.uas.platform.b2b.event.PurchaseApCheckReplyReleaseEvent;
 import com.uas.platform.b2b.model.Enterprise;
 import com.uas.platform.b2b.model.OrderRedDotAll;
@@ -28,6 +31,7 @@ import com.uas.platform.b2b.service.OrderRedDotService;
 import com.uas.platform.b2b.service.PurchaseApCheckService;
 import com.uas.platform.b2b.service.UserService;
 import com.uas.platform.b2b.service.VendorService;
+import com.uas.platform.b2b.support.SPageUtils;
 import com.uas.platform.b2b.support.SystemSession;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.model.Constant;
@@ -35,12 +39,14 @@ import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.PageParams;
 import com.uas.platform.core.model.Status;
 import com.uas.platform.core.persistence.criteria.PredicateUtils;
+import com.uas.ps.core.util.StringUtils;
 import com.uas.search.b2b.model.MultiValue;
 import com.uas.search.b2b.model.SPage;
 import com.uas.search.b2b.model.Sort;
 import com.uas.search.b2b.util.SearchConstants;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -95,6 +101,9 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
 	@Autowired
     private UserService userService;
 
+	@Autowired
+    private VendorDao vendorDao;
+
     /**
      * RMB
      */
@@ -512,15 +521,16 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
      */
     @Override
     public SPage<Vendor> getCustomerInfo(PageParams params, String keyword, String checkDate, Long fromDate, Long endDate) {
-        SPage<Vendor> vendorSPage = searchCustomerInfo(params, keyword);
+        SPage<Vendor> vendorSPage = findCustomerByPage(params, keyword);
         final Long enUU = SystemSession.getUser().getEnterprise().getUu();
         if (!CollectionUtils.isEmpty(vendorSPage.getContent())) {
             vendorSPage.getContent().stream().filter(customer -> null != customer.getApcheck() && customer.getApcheck() == 1)
                 .forEach(customer -> {
                     Long customerUU = customer.getMyEnUU();
-                    // 应收总额
-                    List<TradeCount> totalTrades = getDueTrade(enUU, customerUU);
-                    customer.setTotalCount(totalTrades);
+                    if (!StringUtils.isEmpty(customer.getTotalCountString())) {
+                        List<TradeCount> tradeCounts = JSON.parseArray(customer.getTotalCountString(), TradeCount.class);
+                        customer.setTotalCount(tradeCounts);
+                    }
                     // 本月应收
                     List<TradeCount> thisMonthTrades = getThisMonthTrade(enUU, customerUU, checkDate, fromDate, endDate);
                     customer.setThisMonthCount(thisMonthTrades);
@@ -529,6 +539,43 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
         return vendorSPage;
     }
 
+    /**
+     * 通过分页信息查询客户信息
+     *
+     * @param params 分页参数
+     * @param keyword 搜索关键词
+     * @return 搜索结果
+     */
+    private SPage<Vendor> findCustomerByPage(PageParams params, String keyword) {
+        // 只使用前端的页码和分页大小,防止排序信息注入
+        SearchFilter filter = userService.distribute();
+        if (filter != null && filter.getDistribute() == null) {
+            return new SPage<>();
+        }
+        PageInfo pageInfo = new PageInfo(params.getPage(), params.getCount());
+        org.springframework.data.domain.Sort sort = new org.springframework.data.domain.Sort( org.springframework.data.domain.Sort.Direction.DESC, "totalCountString");
+        pageInfo.setSort(sort);
+        /*
+         * 过滤条件
+         * 1、 当前企业为供应商
+         * 2、 客户已分配
+         * 3、 开启B2B对账
+         * 4、 需要对账价格不为空
+         */
+        pageInfo.filter("vendEnUU", SystemSession.getUser().getEnterprise().getUu());
+        pageInfo.filter("apcheck", Constant.YES);
+        pageInfo.expression(PredicateUtils.ne("totalCountString", "", true));
+        if (filter != null) {
+            pageInfo.expression(PredicateUtils.in("myEnUU", filter.getDistribute(), true));
+        }
+        if (!StringUtils.isEmpty(keyword)) {
+            pageInfo.expression(PredicateUtils.like("myEnterprise.enName", keyword, true));
+        }
+        Page<Vendor> vendors = vendorDao.findAll((Root<Vendor> root, CriteriaQuery<?> query, CriteriaBuilder builder) ->
+            query.where(pageInfo.getPredicates(root, query, builder)).getRestriction(), pageInfo);
+        return SPageUtils.covertSPage(vendors);
+    }
+
     /**
      * 获取指定月份应收金额
      *

+ 82 - 0
src/main/java/com/uas/platform/b2b/task/ApCheckTask.java

@@ -0,0 +1,82 @@
+package com.uas.platform.b2b.task;
+
+import com.alibaba.fastjson.JSON;
+import com.uas.platform.b2b.dao.CommonDao;
+import com.uas.platform.b2b.dao.CommunalLogDao;
+import com.uas.platform.b2b.erp.model.VendorInfo;
+import com.uas.platform.b2b.model.CommunalLog;
+import com.uas.platform.b2b.publicapi.model.TradeCount;
+import com.uas.platform.b2b.service.PurchaseApCheckService;
+import com.uas.platform.b2b.support.CollectionUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * 对账数据维护任务
+ *
+ * @author hejq
+ * @date 2018-12-12 17:55
+ */
+@Component
+public class ApCheckTask {
+
+    /**
+     * 查询待更新处理数据的供应商客户关系
+     */
+    private static final String TODO_CUSTOMER_SQL = "select ve_id id,ve_myenuu custuu,ve_vendenuu venduu from `purc$vendors` where ve_apcheck = 1 and coalesce(update_time, '') < current_date() limit 500";
+
+    /**
+     * 更新对账金额语句
+     */
+    public static final String UPDATE_COUNT_SQL = "update purc$vendors set todo_apchek_count = '%s', update_time = now() where ve_id = %d";
+
+    @Autowired
+    private CommonDao commonDao;
+
+    @Autowired
+    private PurchaseApCheckService apCheckService;
+
+    @Autowired
+    private CommunalLogDao communalLogDao;
+
+    /**
+     * 每天凌晨0点到2点开始执行
+     * 更新总对账和待对账的数据
+     */
+    @Scheduled(cron = "0 0/5 0,1,2 * * ? ")
+    public void updateCount() {
+        List<VendorInfo> vendorList = commonDao.query(TODO_CUSTOMER_SQL, VendorInfo.class);
+        if (!CollectionUtil.isEmpty(vendorList)) {
+            final int[] size = {0};
+            vendorList.forEach(vendorInfo -> {
+                List<TradeCount> tradeCounts = apCheckService.getDueTrade(vendorInfo.getVenduu(), vendorInfo.getCustuu());
+                String tradeString;
+                if (!CollectionUtil.isEmpty(tradeCounts)) {
+                    tradeString = JSON.toJSONString(tradeCounts);
+                } else {
+                    tradeString = "";
+                }
+                try {
+                    String sql = String.format(UPDATE_COUNT_SQL, tradeString, vendorInfo.getId());
+                    commonDao.getJdbcTemplate().update(sql);
+                    size[0]++;
+                } catch (RuntimeException e) {
+                    CommunalLog log = new CommunalLog();
+                    log.setTitle("更新客户关系表对账数据--更新失败");
+                    log.setMessage("id: " + vendorInfo.getId());
+                    log.setTime(System.currentTimeMillis());
+                    communalLogDao.save(log);
+                }
+            });
+            CommunalLog log = new CommunalLog();
+            log.setTitle("更新客户关系表对账数据");
+            log.setMessage("最小id: " + vendorList.get(0).getId() + ";数量: " + size[0]);
+            log.setTime(System.currentTimeMillis());
+            communalLogDao.save(log);
+        }
+    }
+
+}

+ 1 - 1
src/main/resources/ptest/jdbc.properties

@@ -1,6 +1,6 @@
 #mysql info
 jdbc.driverClassName=com.mysql.jdbc.Driver
-jdbc.url=jdbc:mysql://192.168.100.3:3306:3306/b2b_mysql_test?characterEncoding=UTF-8&allowMultiQueries=true&rewriteBatchedStatements=true
+jdbc.url=jdbc:mysql://192.168.100.3:3306/b2b_mysql_test?characterEncoding=UTF-8&allowMultiQueries=true&rewriteBatchedStatements=true
 jdbc.username=sa
 jdbc.password=select111***
 jdbc.initialSize=5

+ 128 - 124
src/main/webapp/WEB-INF/spring/webmvc.xml

@@ -1,125 +1,129 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
-	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
-	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
-
-	<!-- 开启@AspectJ AOP代理 -->
-	<aop:aspectj-autoproxy />
-
-	<bean id="lazyPropertyFilter" class="com.uas.platform.b2b.core.serializer.LazyPropertyFilter"></bean>
-
-	<bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig">
-		<property name="serializerFeatures">
-			<list>
-				<value>DisableCircularReferenceDetect</value>
-			</list>
-		</property>
-		<property name="serializeFilters">
-			<list>
-				<ref bean="lazyPropertyFilter"/>
-			</list>
-		</property>
-	</bean>
-
-	<mvc:annotation-driven>
-		<mvc:message-converters register-defaults="true">
-			<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
-			<bean id="fastJsonHttpMessageConverter"
-				class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
-				<property name="supportedMediaTypes">
-					<list>
-						<value>application/json;charset=UTF-8</value>
-					</list>
-				</property>
-				<property name="fastJsonConfig" ref="fastJsonConfig" />
-			</bean>
-		</mvc:message-converters>
-	</mvc:annotation-driven>
-
-	<mvc:default-servlet-handler />
-
-	<mvc:resources mapping="/static/**" location="/resources/" />
-
-	<context:component-scan base-package="com.uas.platform" />
-
-	<bean
-		class="org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver">
-		<constructor-arg>
-			<bean
-				class="org.springframework.web.servlet.view.InternalResourceViewResolver">
-				<property name="prefix" value="/WEB-INF/views/" />
-				<property name="suffix" value=".html" />
-				<property name="contentType" value="text/html;charset=UTF-8" />
-			</bean>
-		</constructor-arg>
-		<property name="normalPrefix" value="normal/" />
-		<property name="mobilePrefix" value="mobile/" />
-		<property name="tabletPrefix" value="mobile/" />
-	</bean>
-
-	<mvc:view-controller path="/" view-name="index" />
-	<mvc:view-controller path="/index" view-name="index" />
-	<mvc:view-controller path="/storage" view-name="storage" />
-	<mvc:view-controller path="/public" view-name="public" />
-	<mvc:view-controller path="/serve" view-name="serve" />
-	<mvc:view-controller path="/changeAdmin" view-name="/changeAdmin" />
-	<mvc:view-controller path="/public/app" view-name="client" />
-	<mvc:view-controller path="/authen" view-name="authen" />
-	<mvc:view-controller path="/login/proxy" view-name="proxyLogin" />
-	<mvc:view-controller path="/logout/proxy" view-name="proxyLogout" />
-	<mvc:interceptors>
-		<mvc:interceptor>
-			<mvc:mapping path="/**"></mvc:mapping>
-			<bean class="com.uas.platform.b2b.filter.DataSourceInterceptor"></bean>
-		</mvc:interceptor>
-		<!-- SSO过滤 -->
-		<mvc:interceptor>
-			<mvc:mapping path="/**"></mvc:mapping>
-			<mvc:exclude-mapping path="/WEB-INF/**" />
-			<mvc:exclude-mapping path="/**/static/**" />
-			<mvc:exclude-mapping path="/login/**" />
-			<mvc:exclude-mapping path="/logout/**" />
-			<mvc:exclude-mapping path="/file/**" />
-			<mvc:exclude-mapping path="/public/**" />
-			<mvc:exclude-mapping path="/erp/**" />
-			<mvc:exclude-mapping path="/manage/**" />
-			<mvc:exclude-mapping path="/openapi/**" />
-			<mvc:exclude-mapping path="/serve/**" />
-			<mvc:exclude-mapping path="/changeAdmin/**" />
-			<mvc:exclude-mapping path="/authen/**" />
-			<mvc:exclude-mapping path="/mobile/**" />
-			<mvc:exclude-mapping path="/erp/listen" />
-			<bean class="com.uas.platform.b2b.filter.SSOInterceptor"></bean>
-		</mvc:interceptor>
-		<!-- 对所有的请求拦截,将Session中的User信息设置进SystemSession -->
-		<mvc:interceptor>
-			<mvc:mapping path="/**"></mvc:mapping>
-			<bean class="com.uas.platform.b2b.filter.SystemSessionInterceptor"></bean>
-		</mvc:interceptor>
-		<!-- 采用统一私钥签名、认证 -->
-		<mvc:interceptor>
-			<mvc:mapping path="/manage/user"></mvc:mapping>
-			<bean class="com.uas.platform.b2b.filter.SignatureInterceptor"></bean>
-		</mvc:interceptor>
-		<!-- 针对具体UAS用户,采用独立私钥签名、认证 -->
-		<mvc:interceptor>
-			<mvc:mapping path="/erp/**"></mvc:mapping>
-			<mvc:exclude-mapping path="/erp/listen" />
-			<bean class="com.uas.platform.b2b.filter.AccessSignatureInterceptor"></bean>
-		</mvc:interceptor>
-		<!-- 针对开放接口第三方,采用access_token认证 -->
-		<mvc:interceptor>
-			<mvc:mapping path="/openapi/**"></mvc:mapping>
-			<mvc:exclude-mapping path="/openapi/access_token" />
-			<mvc:exclude-mapping path="/openapi/webpage" />
-			<mvc:exclude-mapping path="/mobile/**"/>
-			<bean class="com.uas.platform.b2b.filter.AccessTokenInterceptor"></bean>
-		</mvc:interceptor>
-		<!-- 移动端,通过企业UU、用户手机号认证 -->
-		<mvc:interceptor>
-			<mvc:mapping path="/mobile/**"></mvc:mapping>
-			<bean class="com.uas.platform.b2b.filter.AppAccessInterceptor"></bean>
-		</mvc:interceptor>
-	</mvc:interceptors>
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
+	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+	<!-- 开启@AspectJ AOP代理 -->
+	<aop:aspectj-autoproxy />
+
+	<bean id="lazyPropertyFilter" class="com.uas.platform.b2b.core.serializer.LazyPropertyFilter"></bean>
+
+	<bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig">
+		<property name="serializerFeatures">
+			<list>
+				<value>DisableCircularReferenceDetect</value>
+			</list>
+		</property>
+		<property name="serializeFilters">
+			<list>
+				<ref bean="lazyPropertyFilter"/>
+			</list>
+		</property>
+	</bean>
+
+	<mvc:annotation-driven>
+		<mvc:message-converters register-defaults="true">
+			<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
+			<bean id="fastJsonHttpMessageConverter"
+				class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
+				<property name="supportedMediaTypes">
+					<list>
+						<value>application/json;charset=UTF-8</value>
+					</list>
+				</property>
+				<property name="fastJsonConfig" ref="fastJsonConfig" />
+			</bean>
+		</mvc:message-converters>
+	</mvc:annotation-driven>
+
+	<mvc:default-servlet-handler />
+
+	<mvc:resources mapping="/static/**" location="/resources/" />
+
+	<context:component-scan base-package="com.uas.platform" />
+
+	<bean
+		class="org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver">
+		<constructor-arg>
+			<bean
+				class="org.springframework.web.servlet.view.InternalResourceViewResolver">
+				<property name="prefix" value="/WEB-INF/views/" />
+				<property name="suffix" value=".html" />
+				<property name="contentType" value="text/html;charset=UTF-8" />
+			</bean>
+		</constructor-arg>
+		<property name="normalPrefix" value="normal/" />
+		<property name="mobilePrefix" value="mobile/" />
+		<property name="tabletPrefix" value="mobile/" />
+	</bean>
+
+	<mvc:view-controller path="/" view-name="index" />
+	<mvc:view-controller path="/index" view-name="index" />
+	<mvc:view-controller path="/storage" view-name="storage" />
+	<mvc:view-controller path="/public" view-name="public" />
+	<mvc:view-controller path="/serve" view-name="serve" />
+	<mvc:view-controller path="/changeAdmin" view-name="/changeAdmin" />
+	<mvc:view-controller path="/public/app" view-name="client" />
+	<mvc:view-controller path="/authen" view-name="authen" />
+	<mvc:view-controller path="/login/proxy" view-name="proxyLogin" />
+	<mvc:view-controller path="/logout/proxy" view-name="proxyLogout" />
+	<mvc:interceptors>
+		<mvc:interceptor>
+			<mvc:mapping path="/**"></mvc:mapping>
+			<bean class="com.uas.platform.b2b.filter.DataSourceInterceptor"></bean>
+		</mvc:interceptor>
+		<!-- SSO过滤 -->
+		<mvc:interceptor>
+			<mvc:mapping path="/**"></mvc:mapping>
+			<mvc:exclude-mapping path="/WEB-INF/**" />
+			<mvc:exclude-mapping path="/**/static/**" />
+			<mvc:exclude-mapping path="/login/**" />
+			<mvc:exclude-mapping path="/logout/**" />
+			<mvc:exclude-mapping path="/file/**" />
+			<mvc:exclude-mapping path="/public/**" />
+			<mvc:exclude-mapping path="/erp/**" />
+			<mvc:exclude-mapping path="/manage/**" />
+			<mvc:exclude-mapping path="/openapi/**" />
+			<mvc:exclude-mapping path="/serve/**" />
+			<mvc:exclude-mapping path="/changeAdmin/**" />
+			<mvc:exclude-mapping path="/authen/**" />
+			<mvc:exclude-mapping path="/mobile/**" />
+			<mvc:exclude-mapping path="/openapi/api/trade/**" />
+			<mvc:exclude-mapping path="/openapi/usoft/**" />
+			<mvc:exclude-mapping path="/erp/listen" />
+			<bean class="com.uas.platform.b2b.filter.SSOInterceptor"></bean>
+		</mvc:interceptor>
+		<!-- 对所有的请求拦截,将Session中的User信息设置进SystemSession -->
+		<mvc:interceptor>
+			<mvc:mapping path="/**"></mvc:mapping>
+			<bean class="com.uas.platform.b2b.filter.SystemSessionInterceptor"></bean>
+		</mvc:interceptor>
+		<!-- 采用统一私钥签名、认证 -->
+		<mvc:interceptor>
+			<mvc:mapping path="/manage/user"></mvc:mapping>
+			<bean class="com.uas.platform.b2b.filter.SignatureInterceptor"></bean>
+		</mvc:interceptor>
+		<!-- 针对具体UAS用户,采用独立私钥签名、认证 -->
+		<mvc:interceptor>
+			<mvc:mapping path="/erp/**"></mvc:mapping>
+			<mvc:exclude-mapping path="/erp/listen" />
+			<bean class="com.uas.platform.b2b.filter.AccessSignatureInterceptor"></bean>
+		</mvc:interceptor>
+		<!-- 针对开放接口第三方,采用access_token认证 -->
+		<mvc:interceptor>
+			<mvc:mapping path="/openapi/**"></mvc:mapping>
+			<mvc:exclude-mapping path="/openapi/access_token" />
+			<mvc:exclude-mapping path="/openapi/webpage" />
+			<mvc:exclude-mapping path="/mobile/**"/>
+			<mvc:exclude-mapping path="/openapi/api/trade/**" />
+			<mvc:exclude-mapping path="/openapi/usoft/**" />
+			<bean class="com.uas.platform.b2b.filter.AccessTokenInterceptor"></bean>
+		</mvc:interceptor>
+		<!-- 移动端,通过企业UU、用户手机号认证 -->
+		<mvc:interceptor>
+			<mvc:mapping path="/mobile/**"></mvc:mapping>
+			<bean class="com.uas.platform.b2b.filter.AppAccessInterceptor"></bean>
+		</mvc:interceptor>
+	</mvc:interceptors>
 </beans>

+ 21 - 0
src/test/java/com/uas/platform/b2b/purc/ApCheckCountTest.java

@@ -0,0 +1,21 @@
+package com.uas.platform.b2b.purc;
+
+import com.uas.platform.b2b.BaseJunitTest;
+import com.uas.platform.b2b.task.ApCheckTask;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author hejq
+ * @date 2018-12-13 8:44
+ */
+public class ApCheckCountTest extends BaseJunitTest {
+
+    @Autowired
+    ApCheckTask task;
+
+    @Test
+    public void testCountTask() {
+        task.updateCount();
+    }
+}

+ 0 - 159
src/test/java/com/uas/platform/b2b/purc/PurchaseNoticeSearchTest.java

@@ -1,159 +0,0 @@
-package com.uas.platform.b2b.purc;
-
-import com.uas.platform.b2b.dao.PurchaseNoticeDao;
-import com.uas.platform.b2b.dao.PurchaseOrderDao;
-import com.uas.platform.core.util.HttpUtil;
-import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.xmlbeans.impl.xb.xsdschema.Public;
-import org.hibernate.annotations.Check;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-
-public class PurchaseNoticeSearchTest {
-
-    @Autowired
-    PurchaseNoticeDao purchaseNoticeDao;
-
-    @Autowired
-    PurchaseOrderDao purchaseOrderDao;
-
-    /**
-     * 查出索引没有创建的
-     * @throws Exception
-     */
-    @Test
-    public void checkAndUpdateAA() throws Exception {
-        List<Long> ids = new ArrayList<>();
-        for (Long i=1228788L;i<=1229289L;i++) {
-            ids.add(i);
-        }
-        List<Long> list = checkAll("purc$notice",ids);
-        if (!StringUtils.isEmpty(list)) {
-            for (Long id : list) {
-                update("purc$notice",id);
-            }
-        }
-
-
-    }
-
-    @Test
-    public void update() throws Exception {
-        Long[] ids = {1133714L,1133715L,1133716L,1133717L,1133718L,1133719L,1133720L,1133721L,1133722L,1133723L,1133724L,1133725L};
-        List<Long> list = checkAll("PURC$INQUIRYITEMS",Arrays.asList(ids));
-        if (CollectionUtils.isEmpty(list)){
-            System.out.println("无不存在索引");
-        } else {
-            list.forEach(id-> System.out.println(id));
-        }
-
-    }
-
-    private List<Long> checkAll(String tableName,List<Long> ids) throws Exception{
-        List<Long> list = new ArrayList<>();
-        for (Long id :ids) {
-            String searchInfoUrl = "http://10.10.100.179:8081/search/object";// ?tableName=PURC$NOTICE&id=
-            String infoUrl = searchInfoUrl + "?tableName=" + tableName + "&id=";
-            HttpUtil.Response response = HttpUtil.sendGetRequest(infoUrl + id, null);
-            if (StringUtils.isEmpty(response.getResponseText())) {
-                list.add(id);
-            }
-        }
-        return list;
-    }
-
-    /**
-     * 重建
-     * @param tableName
-     * @param id
-     * @return
-     * @throws Exception
-     */
-    private boolean update(String tableName, Long id) throws Exception {
-        String searchUpdateUrl = "http://10.10.100.179:8081/index/maintain";// ?tableName=PURC$NOTICE&methodType=update&dataId=
-        String url = searchUpdateUrl + "?tableName=" + tableName + "&methodType=update&dataId=";
-
-        HttpRequestBase request = new HttpRequestBase() {
-            @Override
-            public String getMethod() {
-                return "GET";
-            }
-        };
-        request.addHeader("Authorization", "Basic YWRtaW46c2VsZWN0MTExKioq");
-
-        request.setURI(URI.create(url + id));
-        HttpUtil.Response response = HttpUtil.sendHttpUriRequest(request);
-        System.out.println(id + " " + response.getResponseText());
-        return true;
-    }
-
-    /**
-     * 检查,如果不存在重建
-     * @param tableName
-     * @param id
-     * @return
-     * @throws Exception
-     */
-    private boolean checkAndUpdate(String tableName, Long id) throws Exception {
-        String searchInfoUrl = "http://10.10.100.179:8081/search/object";// ?tableName=PURC$NOTICE&id=
-        String infoUrl = searchInfoUrl + "?tableName=" + tableName + "&id=";
-
-        HttpUtil.Response response = HttpUtil.sendGetRequest(infoUrl + id, null);
-        if (StringUtils.isEmpty(response.getResponseText())) {
-            return update(tableName, id);
-        }
-        return false;
-    }
-
-    @Test
-    public void test() throws Exception{
-        update("purc$orders",13832582L);
-    }
-
-    public void checkIndex() throws Exception{
-        Date date = new Date();
-        List<Long> idsNotice = purchaseNoticeDao.findByDate(date);
-        List<Long> idsOrders = purchaseOrderDao.findByDate(date);
-        if (!CollectionUtils.isEmpty(idsNotice)) {
-            checkAndUpateAll("purc$notice",idsNotice);
-        }
-        if (!CollectionUtils.isEmpty(idsOrders)) {
-            checkAndUpateAll("purc$orders",idsOrders);
-        }
-
-    }
-
-    private void checkAndUpateAll(String tableName,List<Long> ids) throws Exception{
-        List<Long> noExistIds = new ArrayList<>();
-        for (Long id :ids) {
-            String searchInfoUrl = "http://10.10.100.179:8081/search/object?tableName=" + tableName + "&id=";
-            HttpUtil.Response response = HttpUtil.sendGetRequest(searchInfoUrl + id, null);
-            if (StringUtils.isEmpty(response.getResponseText())) {
-                noExistIds.add(id);
-            }
-        }
-        if (!CollectionUtils.isEmpty(noExistIds)) {
-            for (Long noExistId : noExistIds) {
-                String searchUpdateUrl ="http://10.10.100.179:8081/index/maintain?tableName=" + tableName + "&methodType=update&dataId=";
-                HttpRequestBase request = new HttpRequestBase() {
-                    @Override
-                    public String getMethod() {
-                        return "GET";
-                    }
-                };
-                request.addHeader("Authorization", "Basic YWRtaW46c2VsZWN0MTExKioq");
-                request.setURI(URI.create(searchUpdateUrl + noExistId));
-                HttpUtil.Response response = HttpUtil.sendHttpUriRequest(request);
-                System.out.println(noExistId + " " + response.getResponseText());
-            }
-        }
-    }
-}