蒼穹外賣-day12
課程內(nèi)容
- 工作臺
- Apache POI
- 導出運營數(shù)據(jù)Excel報表
功能實現(xiàn):工作臺、數(shù)據(jù)導出
工作臺效果圖:
數(shù)據(jù)導出效果圖:
在數(shù)據(jù)統(tǒng)計頁面點擊數(shù)據(jù)導出:生成Excel報表
1. 工作臺
1.1 需求分析和設計
1.1.1 產(chǎn)品原型
工作臺是系統(tǒng)運營的數(shù)據(jù)看板,并提供快捷操作入口,可以有效提高商家的工作效率。
工作臺展示的數(shù)據(jù):
- 今日數(shù)據(jù)
- 訂單管理
- 菜品總覽
- 套餐總覽
- 訂單信息
原型圖:
名詞解釋:
- 營業(yè)額:已完成訂單的總金額
- 有效訂單:已完成訂單的數(shù)量
- 訂單完成率:有效訂單數(shù) / 總訂單數(shù) * 100%
- 平均客單價:營業(yè)額 / 有效訂單數(shù)
- 新增用戶:新增用戶的數(shù)量
1.1.2 接口設計
通過上述原型圖分析,共包含6個接口。
接口設計:
- 今日數(shù)據(jù)接口
- 訂單管理接口
- 菜品總覽接口
- 套餐總覽接口
- 訂單搜索(已完成)
- 各個狀態(tài)的訂單數(shù)量統(tǒng)計(已完成)
1). 今日數(shù)據(jù)的接口設計
2). 訂單管理的接口設計
3). 菜品總覽的接口設計
4). 套餐總覽的接口設計
1.2 代碼導入
直接導入課程資料中的工作臺模塊功能代碼即可:
1.2.1 Controller層
添加WorkSpaceController.java
package com.sky.controller.admin;
import com.sky.result.Result;
import com.sky.service.WorkspaceService;
import com.sky.vo.BusinessDataVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.time.LocalTime;
/**
* 工作臺
*/
@RestController
@RequestMapping("/admin/workspace")
@Slf4j
@Api(tags = "工作臺相關(guān)接口")
public class WorkSpaceController {
@Autowired
private WorkspaceService workspaceService;
/**
* 工作臺今日數(shù)據(jù)查詢
* @return
*/
@GetMapping("/businessData")
@ApiOperation("工作臺今日數(shù)據(jù)查詢")
public Result<BusinessDataVO> businessData(){
//獲得當天的開始時間
LocalDateTime begin = LocalDateTime.now().with(LocalTime.MIN);
//獲得當天的結(jié)束時間
LocalDateTime end = LocalDateTime.now().with(LocalTime.MAX);
BusinessDataVO businessDataVO = workspaceService.getBusinessData(begin, end);
return Result.success(businessDataVO);
}
/**
* 查詢訂單管理數(shù)據(jù)
* @return
*/
@GetMapping("/overviewOrders")
@ApiOperation("查詢訂單管理數(shù)據(jù)")
public Result<OrderOverViewVO> orderOverView(){
return Result.success(workspaceService.getOrderOverView());
}
/**
* 查詢菜品總覽
* @return
*/
@GetMapping("/overviewDishes")
@ApiOperation("查詢菜品總覽")
public Result<DishOverViewVO> dishOverView(){
return Result.success(workspaceService.getDishOverView());
}
/**
* 查詢套餐總覽
* @return
*/
@GetMapping("/overviewSetmeals")
@ApiOperation("查詢套餐總覽")
public Result<SetmealOverViewVO> setmealOverView(){
return Result.success(workspaceService.getSetmealOverView());
}
}
1.2.2 Service層接口
添加WorkspaceService.java
package com.sky.service;
import com.sky.vo.BusinessDataVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import java.time.LocalDateTime;
public interface WorkspaceService {
/**
* 根據(jù)時間段統(tǒng)計營業(yè)數(shù)據(jù)
* @param begin
* @param end
* @return
*/
BusinessDataVO getBusinessData(LocalDateTime begin, LocalDateTime end);
/**
* 查詢訂單管理數(shù)據(jù)
* @return
*/
OrderOverViewVO getOrderOverView();
/**
* 查詢菜品總覽
* @return
*/
DishOverViewVO getDishOverView();
/**
* 查詢套餐總覽
* @return
*/
SetmealOverViewVO getSetmealOverView();
}
1.2.3 Service層實現(xiàn)類
添加WorkspaceServiceImpl.java
package com.sky.service.impl;
import com.sky.constant.StatusConstant;
import com.sky.entity.Orders;
import com.sky.mapper.DishMapper;
import com.sky.mapper.OrderMapper;
import com.sky.mapper.SetmealMapper;
import com.sky.mapper.UserMapper;
import com.sky.service.WorkspaceService;
import com.sky.vo.BusinessDataVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
@Service
@Slf4j
public class WorkspaceServiceImpl implements WorkspaceService {
@Autowired
private OrderMapper orderMapper;
@Autowired
private UserMapper userMapper;
@Autowired
private DishMapper dishMapper;
@Autowired
private SetmealMapper setmealMapper;
/**
* 根據(jù)時間段統(tǒng)計營業(yè)數(shù)據(jù)
* @param begin
* @param end
* @return
*/
public BusinessDataVO getBusinessData(LocalDateTime begin, LocalDateTime end) {
/**
* 營業(yè)額:當日已完成訂單的總金額
* 有效訂單:當日已完成訂單的數(shù)量
* 訂單完成率:有效訂單數(shù) / 總訂單數(shù)
* 平均客單價:營業(yè)額 / 有效訂單數(shù)
* 新增用戶:當日新增用戶的數(shù)量
*/
Map map = new HashMap();
map.put("begin",begin);
map.put("end",end);
//查詢總訂單數(shù)
Integer totalOrderCount = orderMapper.countByMap(map);
map.put("status", Orders.COMPLETED);
//營業(yè)額
Double turnover = orderMapper.sumByMap(map);
turnover = turnover == null? 0.0 : turnover;
//有效訂單數(shù)
Integer validOrderCount = orderMapper.countByMap(map);
Double unitPrice = 0.0;
Double orderCompletionRate = 0.0;
if(totalOrderCount != 0 && validOrderCount != 0){
//訂單完成率
orderCompletionRate = validOrderCount.doubleValue() / totalOrderCount;
//平均客單價
unitPrice = turnover / validOrderCount;
}
//新增用戶數(shù)
Integer newUsers = userMapper.countByMap(map);
return BusinessDataVO.builder()
.turnover(turnover)
.validOrderCount(validOrderCount)
.orderCompletionRate(orderCompletionRate)
.unitPrice(unitPrice)
.newUsers(newUsers)
.build();
}
/**
* 查詢訂單管理數(shù)據(jù)
*
* @return
*/
public OrderOverViewVO getOrderOverView() {
Map map = new HashMap();
map.put("begin", LocalDateTime.now().with(LocalTime.MIN));
map.put("status", Orders.TO_BE_CONFIRMED);
//待接單
Integer waitingOrders = orderMapper.countByMap(map);
//待派送
map.put("status", Orders.CONFIRMED);
Integer deliveredOrders = orderMapper.countByMap(map);
//已完成
map.put("status", Orders.COMPLETED);
Integer completedOrders = orderMapper.countByMap(map);
//已取消
map.put("status", Orders.CANCELLED);
Integer cancelledOrders = orderMapper.countByMap(map);
//全部訂單
map.put("status", null);
Integer allOrders = orderMapper.countByMap(map);
return OrderOverViewVO.builder()
.waitingOrders(waitingOrders)
.deliveredOrders(deliveredOrders)
.completedOrders(completedOrders)
.cancelledOrders(cancelledOrders)
.allOrders(allOrders)
.build();
}
/**
* 查詢菜品總覽
*
* @return
*/
public DishOverViewVO getDishOverView() {
Map map = new HashMap();
map.put("status", StatusConstant.ENABLE);
Integer sold = dishMapper.countByMap(map);
map.put("status", StatusConstant.DISABLE);
Integer discontinued = dishMapper.countByMap(map);
return DishOverViewVO.builder()
.sold(sold)
.discontinued(discontinued)
.build();
}
/**
* 查詢套餐總覽
*
* @return
*/
public SetmealOverViewVO getSetmealOverView() {
Map map = new HashMap();
map.put("status", StatusConstant.ENABLE);
Integer sold = setmealMapper.countByMap(map);
map.put("status", StatusConstant.DISABLE);
Integer discontinued = setmealMapper.countByMap(map);
return SetmealOverViewVO.builder()
.sold(sold)
.discontinued(discontinued)
.build();
}
}
1.2.4 Mapper層
在SetmealMapper中添加countByMap方法定義
/**
* 根據(jù)條件統(tǒng)計套餐數(shù)量
* @param map
* @return
*/
Integer countByMap(Map map);
在SetmealMapper.xml中添加對應SQL實現(xiàn)
<select id="countByMap" resultType="java.lang.Integer">
select count(id) from setmeal
<where>
<if test="status != null">
and status = #{status}
</if>
<if test="categoryId != null">
and category_id = #{categoryId}
</if>
</where>
</select>
在DishMapper中添加countByMap方法定義
/**
* 根據(jù)條件統(tǒng)計菜品數(shù)量
* @param map
* @return
*/
Integer countByMap(Map map);
在DishMapper.xml中添加對應SQL實現(xiàn)
<select id="countByMap" resultType="java.lang.Integer">
select count(id) from dish
<where>
<if test="status != null">
and status = #{status}
</if>
<if test="categoryId != null">
and category_id = #{categoryId}
</if>
</where>
</select>
1.3 功能測試
可以通過如下方式進行測試:
- 通過接口文檔測試
- 前后端聯(lián)調(diào)測試
接下來我們使用上述兩種方式分別測試。
1.3.1 接口文檔測試
啟動服務,訪問http://localhost:8080/doc.html,進入工作臺相關(guān)接口
注意:使用admin用戶登錄重新獲取token,在全局參數(shù)設置中添加,防止token失效。
1). 今日數(shù)據(jù)查詢
2). 菜品總覽查詢
3). 訂單管理數(shù)據(jù)查詢
4). 套餐總覽查詢
1.3.2 前后端聯(lián)調(diào)測試
啟動nginx,訪問 http://localhost,進入工作臺
進入開發(fā)者模式,分別查看今日數(shù)據(jù)、訂單管理、菜品總覽、套餐總覽
1). 今日數(shù)據(jù)查詢
2). 訂單管理數(shù)據(jù)查詢
3). 菜品總覽查詢
4). 套餐總覽查詢
1.4 代碼提交
文章來源:http://www.zghlxwxcb.cn/news/detail-697047.html
后續(xù)步驟和其它功能代碼提交一致,不再贅述。文章來源地址http://www.zghlxwxcb.cn/news/detail-697047.html
到了這里,關(guān)于蒼穹外賣 day12 Echats 營業(yè)臺數(shù)據(jù)可視化整合的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!