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

B2B商务平台订单总金额接口

hejq 7 лет назад
Родитель
Сommit
80adb9d3f9

+ 43 - 0
src/main/java/com/uas/platform/b2b/publicapi/controller/TradeCountController.java

@@ -0,0 +1,43 @@
+package com.uas.platform.b2b.publicapi.controller;
+
+import com.uas.platform.b2b.publicapi.model.TradeCount;
+import com.uas.platform.b2b.publicapi.service.TradeCountService;
+import com.uas.platform.core.model.PageInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Sort;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * 查询销售额接口
+ *
+ * Created by hejq on 2018-05-30.
+ */
+@RequestMapping("/public/tradecount")
+@RestController
+public class TradeCountController {
+
+    @Autowired
+    private TradeCountService tradeCountService;
+
+    /**
+     * 查询销售额统计
+     *
+     * @param tradeType 类型
+     * @param currency 币别
+     * @param fromDate 开始时间
+     * @param endDate 截止时间
+     * @return
+     */
+    @RequestMapping(method = RequestMethod.GET)
+    public List<TradeCount> findByParameters(String tradeType, String currency, String fromDate, String endDate) {
+        PageInfo pageInfo = new PageInfo();
+        pageInfo.setPageNumber(1);
+        pageInfo.setPageSize(20);
+        pageInfo.setSort(new Sort(Sort.Direction.DESC, "id"));
+        return tradeCountService.findByParameters(tradeType, currency, fromDate, endDate, pageInfo);
+    }
+}

+ 13 - 0
src/main/java/com/uas/platform/b2b/publicapi/dao/TradeCountDao.java

@@ -0,0 +1,13 @@
+package com.uas.platform.b2b.publicapi.dao;
+
+import com.uas.platform.b2b.publicapi.model.TradeCount;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+/**
+ * 销售总额数据库操作
+ *
+ * Created by hejq on 2018-05-30.
+ */
+public interface TradeCountDao extends JpaRepository<TradeCount, Long>, JpaSpecificationExecutor<TradeCount> {
+}

+ 109 - 0
src/main/java/com/uas/platform/b2b/publicapi/model/TradeCount.java

@@ -0,0 +1,109 @@
+package com.uas.platform.b2b.publicapi.model;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 销售金额统计
+ *
+ * Created by hejq on 2018-05-30.
+ */
+@Entity
+@Table(name = "trade_count")
+public class TradeCount implements Serializable {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * id
+     */
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "tr_id")
+    private Long id;
+
+    /**
+     * 单据类型
+     *  <node>
+     *      trade: 交易
+     *  </node>
+     */
+    @Column(name = "tr_type")
+    private String tradeType;
+
+    /**
+     * 币别
+     */
+    @Column(name = "tr_currency")
+    private String currency;
+
+    /**
+     * 金额
+     */
+    @Column(name = "tr_amount")
+    private BigDecimal amount;
+
+    /**
+     * 开始时间
+     */
+    @Column(name = "tr_fromdate")
+    private String fromDate;
+
+    /**
+     * 截止时间
+     */
+    @Column(name = "tr_enddate")
+    private String endDate;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getTradeType() {
+        return tradeType;
+    }
+
+    public void setTradeType(String tradeType) {
+        this.tradeType = tradeType;
+    }
+
+    public String getCurrency() {
+        return currency;
+    }
+
+    public void setCurrency(String currency) {
+        this.currency = currency;
+    }
+
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public void setAmount(BigDecimal amount) {
+        this.amount = amount;
+    }
+
+    public String getFromDate() {
+        return fromDate;
+    }
+
+    public void setFromDate(String fromDate) {
+        this.fromDate = fromDate;
+    }
+
+    public String getEndDate() {
+        return endDate;
+    }
+
+    public void setEndDate(String endDate) {
+        this.endDate = endDate;
+    }
+}

+ 2 - 0
src/main/java/com/uas/platform/b2b/publicapi/readme.md

@@ -0,0 +1,2 @@
+	#
+	/public	公共开放接口

+ 25 - 0
src/main/java/com/uas/platform/b2b/publicapi/service/TradeCountService.java

@@ -0,0 +1,25 @@
+package com.uas.platform.b2b.publicapi.service;
+
+import com.uas.platform.b2b.publicapi.model.TradeCount;
+import com.uas.platform.core.model.PageInfo;
+
+import java.util.List;
+
+/**
+ * 查询销售额接口
+ *
+ * Created by hejq on 2018-05-30.
+ */
+public interface TradeCountService {
+
+    /**
+     * 查询销售额统计
+     *
+     * @param tradeType 类型
+     * @param currency 币别
+     * @param fromDate 开始时间
+     * @param endDate 截止时间
+     * @return
+     */
+    List<TradeCount> findByParameters(String tradeType, String currency, String fromDate, String endDate, PageInfo pageInfo);
+}

+ 61 - 0
src/main/java/com/uas/platform/b2b/publicapi/service/impl/TradeCountServiceImpl.java

@@ -0,0 +1,61 @@
+package com.uas.platform.b2b.publicapi.service.impl;
+
+import com.uas.platform.b2b.publicapi.dao.TradeCountDao;
+import com.uas.platform.b2b.publicapi.model.TradeCount;
+import com.uas.platform.b2b.publicapi.service.TradeCountService;
+import com.uas.platform.core.model.PageInfo;
+import com.uas.platform.core.persistence.criteria.PredicateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import java.util.List;
+
+/**
+ * 查询销售额接口
+ *
+ * Created by hejq on 2018-05-30.
+ */
+@Service
+public class TradeCountServiceImpl implements TradeCountService {
+
+    @Autowired
+    private TradeCountDao tradeCountDao;
+
+    /**
+     * 查询销售额统计
+     *
+     * @param tradeType 类型
+     * @param currency  币别
+     * @param fromDate  开始时间
+     * @param endDate   截止时间
+     * @return
+     */
+    @Override
+    public List<TradeCount> findByParameters(String tradeType, String currency, String fromDate, String endDate, final PageInfo pageInfo) {
+        if (!StringUtils.isEmpty(fromDate)) {
+            pageInfo.expression(PredicateUtils.eq("fromDate", fromDate, true));
+        }
+        if (!StringUtils.isEmpty(endDate)) {
+            pageInfo.expression(PredicateUtils.eq("endDate", endDate, true));
+        }
+        if (!StringUtils.isEmpty(currency)) {
+            pageInfo.expression(PredicateUtils.eq("currency", currency, true));
+        }
+        if (!StringUtils.isEmpty(tradeType)) {
+            pageInfo.expression(PredicateUtils.eq("tradeType", tradeType, true));
+        }
+        return tradeCountDao.findAll(new Specification<TradeCount>() {
+            @Override
+            public Predicate toPredicate(Root<TradeCount> root, CriteriaQuery<?> query,
+                                         CriteriaBuilder builder) {
+                return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
+            }
+        });
+    }
+}