dcs 2 tháng trước cách đây
mục cha
commit
fe1141923e

+ 14 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/controller/OrderInfoController.java

@@ -14,7 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping({"workarkOrderInfo"})
@@ -71,6 +73,18 @@ public class OrderInfoController {
         return Response.ok(orderInfoService.getList(orderInfo));
     }
 
+    @ApiOperation("分页查询")
+    @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.POST)
+    public Response list(@RequestBody OrderInfo orderInfo, @PathVariable int currPage, @PathVariable int pageSize) {
+        int totalCount = orderInfoService.getTotalCount(orderInfo);
+        List<OrderInfo> dataList = orderInfoService.getLimit(orderInfo, currPage, pageSize);
+        Map<String, Object> result = new HashMap<>();
+        result.put("dataList", dataList);
+        result.put("totalCount", totalCount);
+        return Response.ok(result);
+    }
+
+
     @ApiOperation("详情")
     @RequestMapping(value = "/{id}", method = RequestMethod.GET)
     public Response get(@PathVariable long id) {

+ 5 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/OrderInfoDao.java

@@ -2,6 +2,7 @@ package com.bosshand.virgo.api.workark.dao;
 
 import com.bosshand.virgo.api.workark.model.OrderInfo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -18,6 +19,10 @@ public interface OrderInfoDao {
 
     List<OrderInfo> getList(OrderInfo orderInfo);
 
+    int getTotalCount(OrderInfo orderInfo);
+
+    List<OrderInfo> getLimit(@Param("p") OrderInfo p, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
+
     OrderInfo get(long id);
 
     OrderInfo getOrderNo(String orderNo);

+ 11 - 8
virgo.api/src/main/java/com/bosshand/virgo/api/workark/service/OrderInfoService.java

@@ -56,6 +56,15 @@ public class OrderInfoService {
         return orderInfoDao.getList(orderInfo);
     }
 
+    public int getTotalCount(OrderInfo orderInfo) {
+        return orderInfoDao.getTotalCount(orderInfo);
+    }
+
+    public List<OrderInfo> getLimit(OrderInfo orderInfo, int currPage, int pageSize) {
+        int currIndex = (currPage - 1) * pageSize;
+        return orderInfoDao.getLimit(orderInfo, currIndex, pageSize);
+    }
+
     public OrderInfo get(long id){
         return orderInfoDao.get(id);
     }
@@ -65,12 +74,6 @@ public class OrderInfoService {
 
         long userId = ContextUtils.getUserContext().getUserId();
 
-        //查找已存在但未支付的订单
-        OrderInfo orderInfo = orderInfoDao.getNoPayOrderByProductId(productId, userId, OrderStatus.NOTPAY.getType());
-        if(orderInfo != null){
-            return orderInfo;
-        }
-
         //获取商品信息
         Product product = productDao.get(productId);
 
@@ -91,7 +94,7 @@ public class OrderInfoService {
         BigDecimal price = calculatePrice(productId, productCouponList);
 
         //生成订单
-        orderInfo = new OrderInfo();
+        OrderInfo orderInfo = new OrderInfo();
         orderInfo.setTitle(product.getName());
         orderInfo.setOrderNo(OrderNoUtils.getOrderNo()); //订单号
         orderInfo.setProductId(productId);
@@ -220,7 +223,7 @@ public class OrderInfoService {
         if (productCoupon.getType() == 1) {
             // 门槛
             BigDecimal threshold = productCoupon.getThreshold();
-            if (price.compareTo(threshold) >= 0) {
+            if (price.compareTo(threshold) <= 0) {
                 // 优惠金额
                 return productCoupon.getCouponAmount();
             }

+ 49 - 0
virgo.api/src/main/resources/mapper/OrderInfoMapper.xml

@@ -45,6 +45,55 @@
         </where>
     </select>
 
+    <select id="getTotalCount" parameterType="com.bosshand.virgo.api.workark.model.OrderInfo" resultType="Integer">
+        SELECT count(*) FROM workark_orderInfo
+        <where>
+            <if test="title != null">
+                and title = #{title}
+            </if>
+            <if test="orderNo != null">
+                and orderNo = #{orderNo}
+            </if>
+            <if test="userId != 0">
+                and userId = #{userId}
+            </if>
+            <if test="productId != null">
+                and productId = #{productId}
+            </if>
+            <if test="orderStatus != null">
+                and orderStatus = #{orderStatus}
+            </if>
+            <if test="paymentType != null">
+                and paymentType = #{paymentType}
+            </if>
+        </where>
+    </select>
+
+    <select id="getLimit" resultMap="result">
+        select * from workark_orderInfo
+        <where>
+            <if test="p.title != null">
+                and title = #{p.title}
+            </if>
+            <if test="p.orderNo != null">
+                and orderNo = #{p.orderNo}
+            </if>
+            <if test="p.userId != 0">
+                and userId = #{p.userId}
+            </if>
+            <if test="p.productId != null">
+                and productId = #{p.productId}
+            </if>
+            <if test="p.orderStatus != null">
+                and orderStatus = #{p.orderStatus}
+            </if>
+            <if test="p.paymentType != null">
+                and paymentType = #{p.paymentType}
+            </if>
+        </where>
+        order by createTime desc limit #{currIndex} , #{pageSize}
+    </select>
+
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         INSERT INTO workark_orderInfo (createTime, title, orderNo, userId, productId, totalFee, codeUrl, orderStatus, paymentType, productCouponIds) VALUES
                             (now(), #{title}, #{orderNo}, #{userId}, #{productId}, #{totalFee}, #{codeUrl}, #{orderStatus}, #{paymentType}, #{productCouponIds})