工作台业务模块功能代码开发
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
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 = "工作台相关接口")
|
||||||
|
public class WorkSpaceController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WorkspaceService workspaceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作台今日数据查询
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/businessData")
|
||||||
|
@ApiOperation("工作台今日数据查询")
|
||||||
|
public Result<BusinessDataVO> businessData(){
|
||||||
|
//获得当天的开始时间
|
||||||
|
LocalDateTime begin = LocalDateTime.now().with(LocalTime.MIN);
|
||||||
|
//获得当天的结束时间
|
||||||
|
LocalDateTime end = LocalDateTime.now().with(LocalTime.MAX);
|
||||||
|
|
||||||
|
BusinessDataVO businessDataVO = workspaceService.getBusinessData(begin, end);
|
||||||
|
return Result.success(businessDataVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询订单管理数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/overviewOrders")
|
||||||
|
@ApiOperation("查询订单管理数据")
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DishMapper {
|
public interface DishMapper {
|
||||||
@@ -87,4 +88,13 @@ public interface DishMapper {
|
|||||||
*/
|
*/
|
||||||
@Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
|
@Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
|
||||||
List<Dish> getBySetmealId(Long id);
|
List<Dish> getBySetmealId(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据条件统计菜品数量
|
||||||
|
* @param map
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Integer countByMap(Map map);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SetmealMapper {
|
public interface SetmealMapper {
|
||||||
@@ -84,4 +85,14 @@ public interface SetmealMapper {
|
|||||||
*/
|
*/
|
||||||
@AutoFill(value = OperationType.UPDATE)
|
@AutoFill(value = OperationType.UPDATE)
|
||||||
void update(Setmeal setmeal);
|
void update(Setmeal setmeal);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据条件统计套餐数量
|
||||||
|
* @param map
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Integer countByMap(Map map);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
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 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据时间段统计营业数据
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
BusinessDataVO getBusinessData(LocalDateTime begin, LocalDateTime end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询订单管理数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderOverViewVO getOrderOverView();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询菜品总览
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
DishOverViewVO getDishOverView();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询套餐总览
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SetmealOverViewVO getSetmealOverView();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import com.sky.vo.OrderReportVO;
|
|||||||
import com.sky.vo.SalesTop10ReportVO;
|
import com.sky.vo.SalesTop10ReportVO;
|
||||||
import com.sky.vo.TurnoverReportVO;
|
import com.sky.vo.TurnoverReportVO;
|
||||||
import com.sky.vo.UserReportVO;
|
import com.sky.vo.UserReportVO;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -61,8 +60,8 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
|
LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
|
||||||
|
|
||||||
Map map = new HashMap();
|
Map map = new HashMap();
|
||||||
map.put("beginTime",beginTime);
|
map.put("begin",beginTime);
|
||||||
map.put("endTime",endTime);
|
map.put("end",endTime);
|
||||||
map.put("status", Orders.COMPLETED);
|
map.put("status", Orders.COMPLETED);
|
||||||
Double turnover = orderMapper.sumByMap(map);
|
Double turnover = orderMapper.sumByMap(map);
|
||||||
turnover = turnover == null ? 0.0 : turnover;
|
turnover = turnover == null ? 0.0 : turnover;
|
||||||
|
|||||||
@@ -0,0 +1,163 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据时间段统计营业数据
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BusinessDataVO getBusinessData(LocalDateTime begin, LocalDateTime end) {
|
||||||
|
/**
|
||||||
|
* 营业额:当日已完成订单的总金额
|
||||||
|
* 有效订单:当日已完成订单的数量
|
||||||
|
* 订单完成率:有效订单数 / 总订单数
|
||||||
|
* 平均客单价:营业额 / 有效订单数
|
||||||
|
* 新增用户:当日新增用户的数量
|
||||||
|
*/
|
||||||
|
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("begin",begin);
|
||||||
|
map.put("end",end);
|
||||||
|
|
||||||
|
//查询总订单数
|
||||||
|
Integer totalOrderCount = orderMapper.countByMap(map);
|
||||||
|
|
||||||
|
map.put("status", Orders.COMPLETED);
|
||||||
|
//营业额
|
||||||
|
Double turnover = orderMapper.sumByMap(map);
|
||||||
|
turnover = turnover == null? 0.0 : turnover;
|
||||||
|
|
||||||
|
//有效订单数
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//新增用户数
|
||||||
|
Integer newUsers = userMapper.countByMap(map);
|
||||||
|
|
||||||
|
return BusinessDataVO.builder()
|
||||||
|
.turnover(turnover)
|
||||||
|
.validOrderCount(validOrderCount)
|
||||||
|
.orderCompletionRate(orderCompletionRate)
|
||||||
|
.unitPrice(unitPrice)
|
||||||
|
.newUsers(newUsers)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询订单管理数据
|
||||||
|
*
|
||||||
|
* @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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,4 +65,11 @@
|
|||||||
order by create_time desc
|
order by create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<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>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -72,11 +72,11 @@
|
|||||||
<select id="sumByMap" resultType="java.lang.Double">
|
<select id="sumByMap" resultType="java.lang.Double">
|
||||||
select sum(amount) from orders
|
select sum(amount) from orders
|
||||||
<where>
|
<where>
|
||||||
<if test="beginTime != null">
|
<if test="begin != null">
|
||||||
and order_time > #{beginTime}
|
and order_time > #{begin}
|
||||||
</if>
|
</if>
|
||||||
<if test="endTime != null">
|
<if test="end != null">
|
||||||
and order_time < #{endTime}
|
and order_time < #{end}
|
||||||
</if>
|
</if>
|
||||||
<if test="status != null">
|
<if test="status != null">
|
||||||
and status = #{status}
|
and status = #{status}
|
||||||
|
|||||||
@@ -44,8 +44,6 @@
|
|||||||
order by s.create_time desc
|
order by s.create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- 修改套餐 -->
|
<!-- 修改套餐 -->
|
||||||
<update id="update" parameterType="Setmeal">
|
<update id="update" parameterType="Setmeal">
|
||||||
update setmeal
|
update setmeal
|
||||||
@@ -62,5 +60,11 @@
|
|||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<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>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user