Commit 86d2d5e0083bc34d2a99694464ee4f02eec2224a

Authored by Jiang
1 parent 9e0e540a

解决后台订单列表分页的问题

b2c-orders-commons/src/main/java/com/b2c/orders/domain/common/Page.java 0 → 100644
  1 +/*
  2 + * Copyright (c) 2014 www.diligrp.com All rights reserved.
  3 + * 本软件源代码版权归----所有,未经许可不得任意复制与传播.
  4 + */
  5 +package com.b2c.orders.domain.common;
  6 +
  7 +import java.io.Serializable;
  8 +import java.util.ArrayList;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * 分页对象
  13 + * @author dev-center
  14 + * @since 2014-05-15
  15 + * @param <T> 实体
  16 + */
  17 +public class Page<T> implements Serializable {
  18 + //初始化size
  19 + private final static int INIT_SIZE = 10;
  20 + private int pageSize = INIT_SIZE;
  21 + private int totalCount;
  22 + private int currentPage;
  23 + private List<T> data = new ArrayList<>();
  24 +
  25 + public Page() {
  26 + // 默认构造器
  27 + }
  28 +
  29 + public Page(int currentPage) {
  30 + this.currentPage = currentPage;
  31 + }
  32 +
  33 + public Page(int currentPage, int pageSize) {
  34 + this.currentPage = currentPage;
  35 + this.pageSize = pageSize;
  36 + }
  37 +
  38 + /**
  39 + * 获取开始索引
  40 + * @return
  41 + */
  42 + public int getStartIndex() {
  43 + return (getCurrentPage() - 1) * this.pageSize;
  44 + }
  45 +
  46 + /**
  47 + * 获取结束索引
  48 + * @return
  49 + */
  50 + public int getEndIndex() {
  51 + return getCurrentPage() * this.pageSize;
  52 + }
  53 +
  54 + /**
  55 + * 是否第一页
  56 + * @return
  57 + */
  58 + public boolean isFirstPage() {
  59 + return getCurrentPage() <= 1;
  60 + }
  61 +
  62 + /**
  63 + * 是否末页
  64 + * @return
  65 + */
  66 + public boolean isLastPage() {
  67 + return getCurrentPage() >= getPageCount();
  68 + }
  69 +
  70 + /**
  71 + * 获取下一页页码
  72 + * @return
  73 + */
  74 + public int getNextPage() {
  75 + if (isLastPage()) {
  76 + return getCurrentPage();
  77 + }
  78 + return getCurrentPage() + 1;
  79 + }
  80 +
  81 + /**
  82 + * 获取上一页页码
  83 + * @return
  84 + */
  85 + public int getPreviousPage() {
  86 + if (isFirstPage()) {
  87 + return 1;
  88 + }
  89 + return getCurrentPage() - 1;
  90 + }
  91 +
  92 + /**
  93 + * 获取当前页页码
  94 + * @return
  95 + */
  96 + public int getCurrentPage() {
  97 + if (currentPage == 0) {
  98 + currentPage = 1;
  99 + }
  100 + return currentPage;
  101 + }
  102 +
  103 + /**
  104 + * 取得总页数
  105 + * @return
  106 + */
  107 + public int getPageCount() {
  108 + if (totalCount % pageSize == 0) {
  109 + return totalCount / pageSize;
  110 + } else {
  111 + return totalCount / pageSize + 1;
  112 + }
  113 + }
  114 +
  115 + /**
  116 + * 取总记录数.
  117 + * @return
  118 + */
  119 + public int getTotalCount() {
  120 + return this.totalCount;
  121 + }
  122 +
  123 + /**
  124 + * 设置当前页
  125 + * @param currentPage
  126 + */
  127 + public void setCurrentPage(int currentPage) {
  128 + this.currentPage = currentPage;
  129 + }
  130 +
  131 + /**
  132 + * 获取每页数据容量.
  133 + * @return
  134 + */
  135 + public int getPageSize() {
  136 + return pageSize;
  137 + }
  138 +
  139 + public void setPageSize(int pageSize) {
  140 + this.pageSize = pageSize;
  141 + }
  142 + /**
  143 + * 该页是否有下一页.
  144 + * @return
  145 + */
  146 + public boolean hasNextPage() {
  147 + return getCurrentPage() < getPageCount();
  148 + }
  149 +
  150 + /**
  151 + * 该页是否有上一页.
  152 + * @return
  153 + */
  154 + public boolean hasPreviousPage() {
  155 + return getCurrentPage() > 1;
  156 + }
  157 +
  158 + /**
  159 + * 获取数据集
  160 + * @return
  161 + */
  162 + public List<T> getResult() {
  163 + return data;
  164 + }
  165 +
  166 + /**
  167 + * 设置数据集
  168 + * @param data
  169 + */
  170 + public void setResult(List<T> data) {
  171 + this.data = data;
  172 + }
  173 +
  174 + /**
  175 + * 设置总记录条数
  176 + * @param totalCount
  177 + */
  178 + public void setTotalCount(int totalCount) {
  179 + this.totalCount = totalCount;
  180 + }
  181 + //==============扩展字段===============//
  182 + private String unit = "条";//单位
  183 + private String extInfo;//扩展信息
  184 + public void setUnit(String unit) {
  185 + this.unit = unit;
  186 + }
  187 + public String getUnit() {
  188 + return unit;
  189 + }
  190 + public void setExtInfo(String extInfo) {
  191 + this.extInfo = extInfo;
  192 + }
  193 + public String getExtInfo() {
  194 + return extInfo;
  195 + }
  196 +}
... ...
b2c-orders-dao/src/main/java/com/b2c/orders/dao/utils/Query.java
... ... @@ -6,7 +6,7 @@ public class Query extends BaseQuery {
6 6  
7 7 @Override
8 8 public Integer getCurrPage() {
9   - if (super.getCurrPage() == null || super.getCurrPage() < 0) {
  9 + if (super.getCurrPage() == null || super.getCurrPage() <= 0) {
10 10 this.setCurrPage(1);
11 11 }
12 12 return super.getCurrPage();
... ... @@ -14,7 +14,17 @@ public class Query extends BaseQuery {
14 14  
15 15 @Override
16 16 public int getStartRow() {
17   - return (this.getCurrPage() - 1) * this.getPageSize();
  17 + int currentPage = this.getCurrPage();
  18 + int startRow = (currentPage - 1) * this.getPageSize();
  19 + return startRow;
  20 + }
  21 +
  22 + public Integer getCurrentPage() {
  23 + return this.getCurrPage();
  24 + }
  25 +
  26 + public void setCurrentPage(Integer currentPage) {
  27 + this.setCurrPage(currentPage);
18 28 }
19 29  
20 30 }
... ...
b2c-orders-dao/src/main/resources/product.json deleted 100644 → 0
1   -{
2   - "code" : 200,
3   - "result" : "成功",
4   - "data" : {
5   - "1bKvCngjj0w" : {
6   - "pid" : 8000000487,
7   - "name" : "name",
8   - "cid" : 272,
9   - "userDefined" : 123,
10   - "salesNum" : 0,
11   - "productionAddr" : "日本",
12   - "productionAddrId" : -20,
13   - "localityAddr" : "山东潍坊市寿光市",
14   - "localityId" : 1370810,
15   - "countryAreaId" : -20,
16   - "publishedLocationID" : 11,
17   - "saleType" : "10",
18   - "quotationType" : 2,
19   - "sellerID" : 998,
20   - "vendorId" : 998,
21   - "prepareTime" : 4,
22   - "foreignPid" : null,
23   - "status" : 3,
24   - "saleUnit" : "公斤",
25   - "storeUnit" : 38,
26   - "defaultPic" : "http://img8.dili7.com/images/i1/67.jpeg",
27   - "minPrice" : 1000,
28   - "maxPrice" : 1100,
29   - "indate" : 15,
30   - "onSaleTime" : 1429858403000,
31   - "publishMode" : 2,
32   - "dropsTime" : 1431154403000,
33   - "publishSettime" : 1431154403000,
34   - "minNum" : 12,
35   - "stockNum" : 1111,
36   - "skus" : [{
37   - "sku" : "2t3oocXHY7",
38   - "decodeSku" : "1bKvCngjj0w",
39   - "remark" : "",
40   - "pid" : 8000000487,
41   - "stockNum" : 1111,
42   - "minNum" : 0,
43   - "price" : 20,
44   - "version" : 1,
45   - "sales" : 0,
46   - "status" : 3,
47   - "attributesMap" : {
48   - "品种" : "毛粉"
49   - }
50   - }],
51   - "productQuotation" : [{
52   - "id" : 962,
53   - "price" : 1100,
54   - "minPurchaseScope" : 12,
55   - "maxPurchaseScope" : 13
56   - }],
57   - "pictures" : ["http://img8.dili7.com/images/i1/67.jpeg",
58   - "http://img9.dili7.com/images/i1/eb.jpg"],
59   - "ctime" : 1429858403000,
60   - "utime" : 1429858403000
61   - }
62   - }
63   -}
64 0 \ No newline at end of file
b2c-orders-dao/src/main/resources/sqlmap-config.xml
... ... @@ -12,7 +12,7 @@
12 12 <setting name="aggressiveLazyLoading" value="false" />
13 13 <!-- 查询时,关闭关联对象即时加载以提高性能 -->
14 14 <setting name="lazyLoadingEnabled" value="true" />
15   - <!-- <setting name="logImpl" value="STDOUT_LOGGING" /> -->
  15 + <setting name="logImpl" value="STDOUT_LOGGING" />
16 16 </settings>
17 17  
18 18 <!-- 全局别名设置,在映射文件中只需写别名,而不必写出整个类路径 -->
... ...
b2c-orders-dao/src/main/resources/sqlmap/OrderMapper.xml
... ... @@ -276,7 +276,7 @@
276 276 ]]>
277 277 </update>
278 278  
279   - <select id="countByCondition" parameterType="Query" resultType="Integer">
  279 + <select id="countByCondition" parameterType="Query" resultType="int">
280 280 SELECT count(1) FROM t_order t1
281 281 <include refid="joinOrderItem" />
282 282 where 1=1
... ...
b2c-orders-domain/pom.xml
... ... @@ -50,5 +50,9 @@
50 50 </exclusion>
51 51 </exclusions>
52 52 </dependency>
  53 + <dependency>
  54 + <groupId>junit</groupId>
  55 + <artifactId>junit</artifactId>
  56 + </dependency>
53 57 </dependencies>
54 58 </project>
55 59 \ No newline at end of file
... ...
b2c-orders-manager/src/main/java/com/b2c/orders/manager/OrderManager.java
... ... @@ -9,12 +9,12 @@ import com.b2c.orders.commons.exceptions.SellerException;
9 9 import com.b2c.orders.commons.exceptions.ShopBuyerException;
10 10 import com.b2c.orders.commons.exceptions.ShopException;
11 11 import com.b2c.orders.domain.Order;
  12 +import com.b2c.orders.domain.common.Page;
12 13 import com.b2c.orders.domain.vo.OrderVo;
13 14 import com.b2c.orders.enums.PayType;
14 15 import com.b2c.orders.enums.UserType;
15 16 import com.b2c.orders.service.rpc.exception.DtmsRPCException;
16 17 import com.diligrp.website.util.dao.BaseQuery;
17   -import com.diligrp.website.util.web.PageTemplate;
18 18  
19 19 public interface OrderManager {
20 20 /**
... ... @@ -174,5 +174,5 @@ public interface OrderManager {
174 174 */
175 175 void remove(UserType userType, Long orderId) throws OrderRepositoryException, OrderException;
176 176  
177   - PageTemplate list(BaseQuery query, UserType userType);
  177 + Page<Order> list(BaseQuery query, UserType userType);
178 178 }
... ...
b2c-orders-manager/src/main/java/com/b2c/orders/manager/impl/OrderManagerBean.java
... ... @@ -33,6 +33,7 @@ import com.b2c.orders.dao.OrderLogDao;
33 33 import com.b2c.orders.domain.Order;
34 34 import com.b2c.orders.domain.OrderItem;
35 35 import com.b2c.orders.domain.OrderLog;
  36 +import com.b2c.orders.domain.common.Page;
36 37 import com.b2c.orders.domain.rpc.Buyer;
37 38 import com.b2c.orders.domain.rpc.Product;
38 39 import com.b2c.orders.domain.rpc.Seller;
... ... @@ -551,7 +552,7 @@ public class OrderManagerBean implements OrderManager {
551 552 }
552 553  
553 554 @Override
554   - public PageTemplate list(BaseQuery query, UserType userType) {
  555 + public Page<Order> list(BaseQuery query, UserType userType) {
555 556 if (UserType.BUYER.equals(userType)) {
556 557 query.addParam("buyerDelete", Boolean.valueOf(false).toString());
557 558 } else if (UserType.SELLER.equals(userType)) {
... ... @@ -563,6 +564,11 @@ public class OrderManagerBean implements OrderManager {
563 564 }
564 565 List<Order> list = this.orderDao.listByCondition(query);
565 566 Integer count = this.orderDao.countByCondition(query);
566   - return PageTemplate.create(query, count, list);
  567 + Page<Order> page = new Page<>();
  568 + page.setCurrentPage(query.getCurrPage());
  569 + page.setPageSize(query.getPageSize());
  570 + page.setResult(list);
  571 + page.setTotalCount(count);
  572 + return page;
567 573 }
568 574 }
... ...
b2c-orders-service/src/main/java/com/b2c/orders/service/OrderService.java
... ... @@ -9,12 +9,12 @@ import com.b2c.orders.commons.exceptions.SellerException;
9 9 import com.b2c.orders.commons.exceptions.ShopBuyerException;
10 10 import com.b2c.orders.commons.exceptions.ShopException;
11 11 import com.b2c.orders.domain.Order;
  12 +import com.b2c.orders.domain.common.Page;
12 13 import com.b2c.orders.domain.vo.OrderVo;
13 14 import com.b2c.orders.enums.PayType;
14 15 import com.b2c.orders.enums.UserType;
15 16 import com.b2c.orders.service.rpc.exception.DtmsRPCException;
16 17 import com.diligrp.website.util.dao.BaseQuery;
17   -import com.diligrp.website.util.web.PageTemplate;
18 18  
19 19 public interface OrderService {
20 20  
... ... @@ -171,7 +171,7 @@ public interface OrderService {
171 171 * TODO
172 172 * @return 含分页信息的结果集
173 173 */
174   - PageTemplate list(BaseQuery query, UserType userType);
  174 + Page<Order> list(BaseQuery query, UserType userType);
175 175  
176 176 /**
177 177 * 删除订单
... ...
b2c-orders-service/src/main/java/com/b2c/orders/service/impl/OrderServiceBean.java
... ... @@ -16,6 +16,7 @@ import com.b2c.orders.commons.exceptions.SellerException;
16 16 import com.b2c.orders.commons.exceptions.ShopBuyerException;
17 17 import com.b2c.orders.commons.exceptions.ShopException;
18 18 import com.b2c.orders.domain.Order;
  19 +import com.b2c.orders.domain.common.Page;
19 20 import com.b2c.orders.domain.vo.OrderVo;
20 21 import com.b2c.orders.enums.PayType;
21 22 import com.b2c.orders.enums.UserType;
... ... @@ -23,7 +24,6 @@ import com.b2c.orders.manager.OrderManager;
23 24 import com.b2c.orders.service.OrderService;
24 25 import com.b2c.orders.service.rpc.exception.DtmsRPCException;
25 26 import com.diligrp.website.util.dao.BaseQuery;
26   -import com.diligrp.website.util.web.PageTemplate;
27 27  
28 28 @Service
29 29 @Transactional(propagation = Propagation.REQUIRED, rollbackFor = ApplicationException.class)
... ... @@ -108,7 +108,7 @@ public class OrderServiceBean implements OrderService {
108 108  
109 109 @Transactional(propagation = Propagation.SUPPORTS)
110 110 @Override
111   - public PageTemplate list(BaseQuery query, UserType userType) {
  111 + public Page<Order> list(BaseQuery query, UserType userType) {
112 112 return this.orderManager.list(query, userType);
113 113 }
114 114  
... ...
b2c-orders-web/src/main/java/com/b2c/orders/web/controller/OrderController.java
1 1 package com.b2c.orders.web.controller;
2 2  
  3 +import java.util.Enumeration;
3 4 import java.util.HashMap;
4 5 import java.util.List;
5 6 import java.util.Map;
6 7  
  8 +import javax.servlet.http.HttpServletRequest;
  9 +
7 10 import org.springframework.beans.factory.annotation.Autowired;
8 11 import org.springframework.stereotype.Controller;
9 12 import org.springframework.web.bind.annotation.RequestMapping;
... ... @@ -11,16 +14,16 @@ import org.springframework.web.bind.annotation.RequestMethod;
11 14 import org.springframework.web.bind.annotation.RequestParam;
12 15 import org.springframework.web.servlet.ModelAndView;
13 16  
  17 +import com.b2c.orders.dao.utils.Query;
14 18 import com.b2c.orders.domain.Order;
15 19 import com.b2c.orders.domain.OrderLog;
  20 +import com.b2c.orders.domain.common.Page;
16 21 import com.b2c.orders.enums.OrderStatus;
17 22 import com.b2c.orders.enums.PayType;
18 23 import com.b2c.orders.enums.UserType;
19 24 import com.b2c.orders.service.OrderLogService;
20 25 import com.b2c.orders.service.OrderService;
21 26 import com.b2c.orders.web.common.VelocitySupport;
22   -import com.diligrp.website.util.dao.BaseQuery;
23   -import com.diligrp.website.util.web.PageTemplate;
24 27  
25 28 @Controller
26 29 public class OrderController extends VelocitySupport {
... ... @@ -36,10 +39,10 @@ public class OrderController extends VelocitySupport {
36 39 }
37 40  
38 41 @RequestMapping(value = "/list", method = RequestMethod.GET)
39   - public ModelAndView list(BaseQuery query) {
40   - PageTemplate pt = this.orderService.list(query, UserType.SYSTEM);
41   - return this.toVM("list", pt).addObject("query", query).addObject("orderStatusMap",
42   - OrderStatus.getInitMaps()).addObject("payTypes", PayType.values());
  42 + public ModelAndView list(Query query, HttpServletRequest request) {
  43 + Page<Order> pt = this.orderService.list(query, UserType.SYSTEM);
  44 + return this.toVM("list", pt).addObject("query", query).addObject("orderStatusMap", OrderStatus.getInitMaps())
  45 + .addObject("payTypes", PayType.values());
43 46 }
44 47  
45 48 @RequestMapping(value = "/detail", method = RequestMethod.GET)
... ...
b2c-orders-web/src/main/java/com/b2c/orders/web/restful/OrderRestController.java
... ... @@ -53,6 +53,7 @@ import com.b2c.orders.domain.client.dto.response.OrderDetailResponseDto;
53 53 import com.b2c.orders.domain.client.dto.response.OrderItemResponseDto;
54 54 import com.b2c.orders.domain.client.dto.response.OrderListResponseDto;
55 55 import com.b2c.orders.domain.client.dto.response.SubmitOrderResponseDto;
  56 +import com.b2c.orders.domain.common.Page;
56 57 import com.b2c.orders.domain.rpc.Buyer;
57 58 import com.b2c.orders.domain.rpc.Product;
58 59 import com.b2c.orders.domain.rpc.Seller;
... ... @@ -67,7 +68,6 @@ import com.diligrp.titan.sdk.TitanClient;
67 68 import com.diligrp.titan.sdk.output.BaseOutput;
68 69 import com.diligrp.titan.sdk.service.ProductService;
69 70 import com.diligrp.website.util.dao.BaseQuery;
70   -import com.diligrp.website.util.web.PageTemplate;
71 71  
72 72 import io.swagger.annotations.Api;
73 73 import io.swagger.annotations.ApiOperation;
... ... @@ -396,14 +396,14 @@ public class OrderRestController {
396 396 @RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
397 397 public ApiPageDataResponse<OrderListResponseDto> list(OrderListRequestDto request) {
398 398 BaseQuery query = this.buildQuery(request);
399   - PageTemplate page = this.orderService.list(query, UserType.get(request.getUserType()));
  399 + Page<Order> page = this.orderService.list(query, UserType.get(request.getUserType()));
400 400 ApiPageDataResponse<OrderListResponseDto> pageResponse = new ApiPageDataResponse<>();
401   - pageResponse.setCurrentPage(page.getCurrPage());
  401 + pageResponse.setCurrentPage(page.getCurrentPage());
402 402 pageResponse.setPageSize(page.getPageSize());
403   - pageResponse.setTotalPage(page.getTotalPage());
404   - pageResponse.setTotalSize(page.getTotalSize());
  403 + pageResponse.setTotalPage(page.getTotalCount());
  404 + pageResponse.setTotalSize(page.getPageSize());
405 405 @SuppressWarnings("unchecked")
406   - List<Order> orderList = (List<Order>) page.getList();
  406 + List<Order> orderList = page.getResult();
407 407 if (!CollectionUtils.isEmpty(orderList)) {
408 408 List<OrderListResponseDto> orderDtoList = new ArrayList<>(orderList.size());
409 409 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
... ...
b2c-orders-web/src/main/webapp/WEB-INF/vm/common/macro.vm
... ... @@ -3,22 +3,22 @@
3 3  
4 4 ##分页
5 5 #macro(showPage $page)
6   -<input type="hidden" name="currentPage" id="currentPage" value="${page.currPage}"/>
  6 +<input type="hidden" name="currentPage" id="currentPage" value="${page.currentPage}"/>
7 7 #if($page != "")
8 8 <div>
9 9 <ul class="pagination pull-right" style="margin:0px;">
10 10 <li class="prev #if($page.isFirstPage())disabled#end" title="前一页">
11   - #set ( $tmpCurr = $page.currPage - 1 )
  11 + #set ( $tmpCurr = $page.currentPage - 1 )
12 12 <a href="#if($page.isFirstPage())javascript:void(0)#else javascript:XUI.form.page(${tmpCurr},globalValidator)#end">
13 13 <i class="icon-double-angle-left"></i>
14 14 </a>
15 15 </li>
16   - #foreach($index in $!{webUtils.pageSplit($page.currPage,$page.pageCount,6)})
  16 + #foreach($index in $!{webUtils.pageSplit($page.currentPage,$page.pageCount,6)})
17 17 #set( $i = $index )
18   - <li #if($index == ($page.currPage)) class="active" #end><a href="javascript:XUI.form.page($i,globalValidator)">$index</a></li>
  18 + <li #if($index == ($page.currentPage)) class="active" #end><a href="javascript:XUI.form.page($i,globalValidator)">$index</a></li>
19 19 #end
20 20 <li class="next #if($page.isLastPage())disabled#end" title="后一页">
21   - #set ( $tmpCurr = $page.currPage + 1 )
  21 + #set ( $tmpCurr = $page.currentPage + 1 )
22 22 <a href="#if($page.isLastPage())javascript:void(0)#else javascript:XUI.form.page(${tmpCurr},globalValidator)#end">
23 23 <i class="icon-double-angle-right"></i>
24 24 </a>
... ... @@ -69,7 +69,7 @@
69 69 #end
70 70 </select>
71 71 #set($currentPage=${page.currPage}+1)
72   - 查询出<strong>${page.list.size()}</strong>条数据,共<strong>${page.totalPage}</strong>页,当前第<strong>${currentPage}</strong>页
  72 + 查询出<strong>${page.totalCount}</strong>条数据,共<strong>${page.pageCount}</strong>页,当前第<strong>${page.currentPage}</strong>页
73 73 </span>
74 74 </div>
75 75 #end
... ...
b2c-orders-web/src/main/webapp/WEB-INF/vm/list.vm
... ... @@ -71,7 +71,7 @@
71 71 </tr>
72 72 </thead>
73 73 <tbody>
74   - #foreach(${item} in ${model.list})
  74 + #foreach(${item} in ${model.result})
75 75 <tr>
76 76 <td class="textC">
77 77 #if($!{detailRight})
... ...