As the third part of statistics, it is mainly to share a statistical requirement.

The table structure of the initial data is as follows, in which each piece of data is the summary data that has been counted, but there is one for each platform, so we have to do another processing when the list page displays the summary data of each platform in a day.

CREATE TABLE `platform_order_sum_day` ( `id` int(11) NOT NULL AUTO_INCREMENT, 'platform' varchar(20) DEFAULT NULL COMMENT 'happen_date' date NOT NULL COMMENT 'happen_date ', 'order_num' int(11) DEFAULT NULL COMMENT 'order quantity ',' amount 'float(14,2) DEFAULT NULL COMMENT' amount ', 'create_time' datetime NOT NULL COMMENT 'create_time ',' update_time 'datetime NOT NULL COMMENT' create_time ', 'update_time' datetime NOT NULL COMMENT 'create_time ', Happen_date '(' platform', 'happendate') ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=' happen_date ';Copy the code

Combined with the need for paging on the page and the need to regenerate into a summarized table, this paging is handled directly in the code logic.

SQL > select count (*), count (*), count (*), count (*), count (*);

SELECT happen_date, SUM(order_num) AS 'sum_order_num', SUM(amount) AS 'sum_amount', SUM(shop_num) AS 'sum_shop_num', FROM platform_order_sum_day WHERE happen_date BETWEEN ? AND ? GROUP BY happen_date ORDER BY happen_date DESC;
Copy the code

SQL statement: select * from user where user = user where user = user where user = user where user = user;

SELECT platform, happen_date, order_num, amount, shop_num, puid_num FROM platform_order_sum_day WHERE happen_date BETWEEN ? and ? group by happen_date, platform order by happen_date desc; 
Copy the code

The business code here is:

// Get paging data

Page page = platformOrderSumDayDao.getPlatformOrderSumDayStatPage(happenDate, endTime, pageSize, pageNo); 
Copy the code

// Get data from different platforms for each day

List<Map<String, Object>> allList = platformOrderSumDayDao.listPlatformOrderSumDayStat(happenDate, endTime, pageSize, pageNo); 
Copy the code

// Get summary data for each day

List<Map<String, Object>> sumList = allOrderSumDao.listOrderSumDayStat(happenDate, endTime, pageSize, pageNo);
Copy the code

// Splice data into different platforms for each day

Map<String, List<Map<String, Object>>> happenMap = Maps.newHashMap(); 
Copy the code

// Put data into different platforms each day

for (Map<String, Object> map : allList) {
    String happenDateStr = DateUtil.dateToStrNoTime((Date) map.get("happen_date"));
	if (!happenMap.containsKey(happenDateStr)) {
		happenMap.put(happenDateStr, Lists.newArrayList(map));
	} else {
		happenMap.get(happenDateStr).add(map);
	}
} 
Copy the code

Multiple associated data in the table are summarized using the same map key.

The processing logic here is to summarize multiple associated data in the table using the same map key for processing. This allows you to correctly display the day-by-day, per-platform summary data by passing paging parameters and query criteria.

Today is mainly to share these, thank you!