commit
9cca6f6a29
@ -0,0 +1,77 @@
|
||||
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());
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
|
||||
import com.sky.result.Result;
|
||||
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.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController("userShopController")
|
||||
@RequestMapping("/user/shop")
|
||||
@Api(tags = "店铺相关接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
|
||||
public static final String KEY = "SHOP_STATUS";
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/*
|
||||
* 获取店铺营业状态
|
||||
* */
|
||||
@ApiOperation("获取店铺营业状态")
|
||||
@GetMapping("/status")
|
||||
public Result<Integer> getStatus(){
|
||||
Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
|
||||
log.info("获取店铺营业状态:{}",status == 1 ? "营业中" : "打烊中");
|
||||
return Result.success(status);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.SetmealDish;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SetmealDishMapper {
|
||||
|
||||
/*
|
||||
* 根据菜品id查询对应套餐的id
|
||||
* 这个方法用于获取与给定菜品ID列表相关的所有套餐ID。
|
||||
* @param dishIds 菜品ID列表
|
||||
* @return 返回包含相关套餐ID的列表
|
||||
*/
|
||||
List<Long> getSetmealIdsByDishIds(List<Long> dishIds);
|
||||
|
||||
/*
|
||||
* 批量插入套餐和菜品的关联数据
|
||||
* 这个方法用于将一组套餐-菜品关系批量插入数据库中。
|
||||
* @param setmealDishes 套餐-菜品关系对象列表
|
||||
*/
|
||||
void insertBatch(List<SetmealDish> setmealDishes);
|
||||
|
||||
/*
|
||||
* 根据套餐id获取相应菜品的数据
|
||||
* 这个方法用于根据套餐ID获取与之关联的所有菜品信息。
|
||||
* @param setmealId 套餐ID
|
||||
* @return 返回包含套餐中所有菜品信息的列表
|
||||
*/
|
||||
@Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
List<SetmealDish> getBySetmealId(Long setmealId);
|
||||
|
||||
/*
|
||||
* 根据多个套餐id删除对应的套餐-菜品关系
|
||||
* 这个方法用于删除与给定套餐ID列表相关的所有套餐-菜品关系。
|
||||
* @param setmealIds 套餐ID列表
|
||||
*/
|
||||
void deleteBySetmealIds(List<Long> setmealIds);
|
||||
|
||||
/*
|
||||
* 根据单个套餐id删除对应的套餐-菜品关系
|
||||
* 这个方法用于删除与指定套餐ID相关的所有套餐-菜品关系。
|
||||
* @param setmealId 套餐ID
|
||||
*/
|
||||
@Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
void deleteBySetmealId(Long setmealId);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.sky.task;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/*
|
||||
* 自定义定时任务类
|
||||
* */
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MyTask {
|
||||
|
||||
/*
|
||||
* 定时任务 每隔5秒触发一次
|
||||
* */
|
||||
// @Scheduled(cron = "0/5 * * * * ?")
|
||||
public void executeTask(){
|
||||
log.info("定时任务开始执行:{}",new Date());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.sky.task;
|
||||
|
||||
import com.sky.entity.Orders;
|
||||
import com.sky.mapper.OrderMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class OrderTask {
|
||||
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
/*
|
||||
* 处理超时订单的方法
|
||||
* */
|
||||
@Scheduled(cron = "0 * * * * ? ") //每分钟触发一次
|
||||
// @Scheduled(cron = "1/5 * * * * ?")
|
||||
public void processTimeoutOrder(){
|
||||
log.info("定时处理超时订单:{}", LocalDateTime.now());
|
||||
LocalDateTime time = LocalDateTime.now().plusMinutes(-15);
|
||||
List<Orders> orderList = orderMapper.getByStatusAndOrderTimeLT(Orders.PENDING_PAYMENT, time);
|
||||
|
||||
if(orderList != null || orderList.size() >0){
|
||||
for (Orders orders : orderList) {
|
||||
orders.setStatus(Orders.CANCELLED);
|
||||
orders.setCancelReason("订单超时,自动取消");
|
||||
orders.setCancelTime(LocalDateTime.now());
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 一直处于派送中状态的订单
|
||||
* */
|
||||
@Scheduled(cron = "0 0 1 * * ? ")//每日凌晨一点触发
|
||||
// @Scheduled(cron = "0/5 * * * * ?")
|
||||
public void processDeliveryOrder(){
|
||||
log.info("定时处理处于派送中的订单:{}",LocalDateTime.now());
|
||||
LocalDateTime time = LocalDateTime.now().plusMinutes(-60);
|
||||
List<Orders> orderList = orderMapper.getByStatusAndOrderTimeLT(Orders.DELIVERY_IN_PROGRESS, time);
|
||||
if(orderList != null || orderList.size() >0){
|
||||
for (Orders orders : orderList) {
|
||||
orders.setStatus(Orders.COMPLETED);
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.sky.task;
|
||||
|
||||
import com.sky.websocket.WebSocketServer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class WebSocketTask {
|
||||
@Autowired
|
||||
private WebSocketServer webSocketServer;
|
||||
|
||||
/**
|
||||
* 通过WebSocket每隔5秒向客户端发送消息
|
||||
*/
|
||||
// @Scheduled(cron = "0/5 * * * * ?")
|
||||
// public void sendMessageToClient() {
|
||||
// webSocketServer.sendToAllClient("这是来自服务端的消息:" + DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now()));
|
||||
// }
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.sky.test;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
* 使用POI操作excel文件
|
||||
* */
|
||||
public class POITest {
|
||||
|
||||
/*
|
||||
* 通过POI创建excel文件并且写入文件内容
|
||||
* */
|
||||
public static void write() throws IOException {
|
||||
//在内存中创建一个excel文件
|
||||
XSSFWorkbook excel = new XSSFWorkbook();
|
||||
//在excel文件中创建一个sheet页
|
||||
XSSFSheet sheet = excel.createSheet("info");
|
||||
//在sheet页中创建行对象,rownum从0开始
|
||||
XSSFRow row = sheet.createRow(1);
|
||||
//创建单元格,写入文件内容
|
||||
row.createCell(1).setCellValue("姓名");
|
||||
row.createCell(2).setCellValue("城市");
|
||||
|
||||
//创建一个新行
|
||||
row = sheet.createRow(2);
|
||||
row.createCell(1).setCellValue("aiming");
|
||||
row.createCell(2).setCellValue("北京");
|
||||
|
||||
//通过输出流将内存中的excel文件写入磁盘中
|
||||
FileOutputStream out = new FileOutputStream(new File("D:\\info.xlsx"));
|
||||
excel.write(out);
|
||||
|
||||
//关闭资源
|
||||
out.close();
|
||||
excel.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* 通过POI读入excel文件中的内容
|
||||
* */
|
||||
public static void read() throws Exception{
|
||||
FileInputStream in = new FileInputStream(new File("D:\\info.xlsx"));
|
||||
//读取磁盘上已存在的excel文件
|
||||
XSSFWorkbook excel = new XSSFWorkbook(in);
|
||||
//读取excel文件中第一个sheet页
|
||||
XSSFSheet sheet = excel.getSheetAt(0);
|
||||
|
||||
//获取sheet页中最后一行的行号
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
for(int i = 1; i <= lastRowNum; i++){
|
||||
//获取某一行
|
||||
XSSFRow row = sheet.getRow(i);
|
||||
//获得单元格对象
|
||||
String cellValue1 = row.getCell(1).getStringCellValue();
|
||||
String cellValue2 = row.getCell(2).getStringCellValue();
|
||||
System.out.println(cellValue1 + " " + cellValue2);
|
||||
}
|
||||
//关闭资源
|
||||
excel.close();
|
||||
in.close();
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
// write();
|
||||
read();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue