Compare commits
10 Commits
689ce56914
...
48e87edac6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48e87edac6 | ||
| df4b8e9e60 | |||
| 0da38cd6da | |||
| 77ffe62c8d | |||
| b469466854 | |||
| 0232c08966 | |||
| 21bfc4430b | |||
| 01b8c0f935 | |||
| 6ab2e2a245 | |||
| 209934c668 |
@@ -0,0 +1,18 @@
|
|||||||
|
package com.sky.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket配置类,用于注册WebSocket的Bean
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class WebSocketConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ServerEndpointExporter serverEndpointExporter() {
|
||||||
|
return new ServerEndpointExporter();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sky.dto.OrdersCancelDTO;
|
||||||
|
import com.sky.dto.OrdersConfirmDTO;
|
||||||
|
import com.sky.dto.OrdersPageQueryDTO;
|
||||||
|
import com.sky.dto.OrdersRejectionDTO;
|
||||||
|
import com.sky.entity.OrderDetail;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.OrderService;
|
||||||
|
import com.sky.vo.OrderStatisticsVO;
|
||||||
|
import com.sky.vo.OrderVO;
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController("adminOrderController")
|
||||||
|
@Slf4j
|
||||||
|
@Api("订单管理接口")
|
||||||
|
@RequestMapping("/admin/order")
|
||||||
|
public class OrderController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单搜索
|
||||||
|
* @param ordersPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/conditionSearch")
|
||||||
|
@ApiOperation("订单搜索")
|
||||||
|
public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
|
||||||
|
PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 各个状态的订单数量统计
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/statistics")
|
||||||
|
@ApiOperation("各个状态的订单数量统计")
|
||||||
|
public Result<OrderStatisticsVO> statistics(){
|
||||||
|
OrderStatisticsVO orderStatisticsVO = orderService.statistics();
|
||||||
|
return Result.success(orderStatisticsVO);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单id查询订单详情
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/details/{id}")
|
||||||
|
@ApiOperation("查询订单详情")
|
||||||
|
public Result<OrderVO> details(@PathVariable Long id){
|
||||||
|
OrderVO orderVO = orderService.details(id);
|
||||||
|
return Result.success(orderVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接单
|
||||||
|
* @param ordersConfirmDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/confirm")
|
||||||
|
@ApiOperation("接单")
|
||||||
|
public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
|
||||||
|
orderService.confirm(ordersConfirmDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将待接单的订单拒单
|
||||||
|
* @param ordersRejectionDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/rejection")
|
||||||
|
@ApiOperation("拒单")
|
||||||
|
public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
|
||||||
|
orderService.rejection(ordersRejectionDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将当派送的订单 取消订单
|
||||||
|
* @param ordersCancelDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/cancel")
|
||||||
|
@ApiOperation("取消订单")
|
||||||
|
public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
|
||||||
|
orderService.cancel(ordersCancelDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 派送订单
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/delivery/{id}")
|
||||||
|
@ApiOperation("派送订单")
|
||||||
|
public Result delivery(@PathVariable Long id){
|
||||||
|
orderService.delivery(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 完成订单
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/complete/{id}")
|
||||||
|
@ApiOperation("完成订单")
|
||||||
|
public Result complete(@PathVariable Long id){
|
||||||
|
orderService.complete(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.ReportService;
|
||||||
|
import com.sky.vo.OrderReportVO;
|
||||||
|
import com.sky.vo.SalesTop10ReportVO;
|
||||||
|
import com.sky.vo.TurnoverReportVO;
|
||||||
|
import com.sky.vo.UserReportVO;
|
||||||
|
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.format.annotation.DateTimeFormat;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@RestController()
|
||||||
|
@RequestMapping("/admin/report")
|
||||||
|
@Api(tags = "数据统计相关接口")
|
||||||
|
@Slf4j
|
||||||
|
public class ReportController {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReportService reportService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 营业额统计
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/turnoverStatistics")
|
||||||
|
@ApiOperation("营业额统计")
|
||||||
|
public Result<TurnoverReportVO> turnoverStatistics(
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
|
||||||
|
log.info("营业额数据统计:{},{}", begin, end);
|
||||||
|
return Result.success(reportService.getTurnoverStatistics(begin, end));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户统计
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/userStatistics")
|
||||||
|
@ApiOperation("用户统计")
|
||||||
|
public Result<UserReportVO> userStatistics(
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
|
||||||
|
){
|
||||||
|
log.info("用户数据统计:{},{}", begin, end);
|
||||||
|
return Result.success(reportService.getUserStatistics(begin, end));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单统计
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/ordersStatistics")
|
||||||
|
@ApiOperation("订单统计")
|
||||||
|
public Result<OrderReportVO> ordersStatistics(
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
|
||||||
|
){
|
||||||
|
log.info("订单统计:{},{}", begin, end);
|
||||||
|
return Result.success(reportService.getOrdersStatistics(begin, end));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 销量排名
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/top10")
|
||||||
|
@ApiOperation("销量排名")
|
||||||
|
public Result<SalesTop10ReportVO> top10(
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
|
||||||
|
){
|
||||||
|
log.info("销量排名top10:{},{}", begin, end);
|
||||||
|
return Result.success(reportService.getSalesTop10(begin, end));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出运营数据报表
|
||||||
|
* @param response
|
||||||
|
*/
|
||||||
|
@GetMapping("/export")
|
||||||
|
@ApiOperation("导出运营数据报表")
|
||||||
|
public void export(HttpServletResponse response){
|
||||||
|
reportService.exportBusinessData(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
import com.sky.context.BaseContext;
|
||||||
|
import com.sky.entity.AddressBook;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.AddressBookService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user/addressBook")
|
||||||
|
@Api(tags = "C端地址簿接口")
|
||||||
|
public class AddressBookController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AddressBookService addressBookService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当前登录用户的所有地址信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("查询当前登录用户的所有地址信息")
|
||||||
|
public Result<List<AddressBook>> list() {
|
||||||
|
AddressBook addressBook = new AddressBook();
|
||||||
|
addressBook.setUserId(BaseContext.getCurrentId());
|
||||||
|
List<AddressBook> list = addressBookService.list(addressBook);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增地址
|
||||||
|
*
|
||||||
|
* @param addressBook
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("新增地址")
|
||||||
|
public Result save(@RequestBody AddressBook addressBook) {
|
||||||
|
addressBookService.save(addressBook);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
@ApiOperation("根据id查询地址")
|
||||||
|
public Result<AddressBook> getById(@PathVariable Long id) {
|
||||||
|
AddressBook addressBook = addressBookService.getById(id);
|
||||||
|
return Result.success(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id修改地址
|
||||||
|
*
|
||||||
|
* @param addressBook
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
@ApiOperation("根据id修改地址")
|
||||||
|
public Result update(@RequestBody AddressBook addressBook) {
|
||||||
|
addressBookService.update(addressBook);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置默认地址
|
||||||
|
*
|
||||||
|
* @param addressBook
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/default")
|
||||||
|
@ApiOperation("设置默认地址")
|
||||||
|
public Result setDefault(@RequestBody AddressBook addressBook) {
|
||||||
|
addressBookService.setDefault(addressBook);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除地址
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
@ApiOperation("根据id删除地址")
|
||||||
|
public Result deleteById(Long id) {
|
||||||
|
addressBookService.deleteById(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询默认地址
|
||||||
|
*/
|
||||||
|
@GetMapping("default")
|
||||||
|
@ApiOperation("查询默认地址")
|
||||||
|
public Result<AddressBook> getDefault() {
|
||||||
|
//SQL:select * from address_book where user_id = ? and is_default = 1
|
||||||
|
AddressBook addressBook = new AddressBook();
|
||||||
|
addressBook.setIsDefault(1);
|
||||||
|
addressBook.setUserId(BaseContext.getCurrentId());
|
||||||
|
List<AddressBook> list = addressBookService.list(addressBook);
|
||||||
|
|
||||||
|
if (list != null && list.size() == 1) {
|
||||||
|
return Result.success(list.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.error("没有查询到默认地址");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sky.dto.OrdersPaymentDTO;
|
||||||
|
import com.sky.dto.OrdersSubmitDTO;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.OrderService;
|
||||||
|
import com.sky.vo.OrderPaymentVO;
|
||||||
|
import com.sky.vo.OrderSubmitVO;
|
||||||
|
import com.sky.vo.OrderVO;
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController("userOrderController")
|
||||||
|
@RequestMapping("/user/order")
|
||||||
|
@Api(tags = "用户端订单相关接口")
|
||||||
|
@Slf4j
|
||||||
|
public class OrderController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperation("用户下单接口")
|
||||||
|
public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
|
||||||
|
log.info("用户下单,参数为{}", ordersSubmitDTO);
|
||||||
|
OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
|
||||||
|
return Result.success(orderSubmitVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单支付
|
||||||
|
*
|
||||||
|
* @param ordersPaymentDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/payment")
|
||||||
|
@ApiOperation("订单支付")
|
||||||
|
public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
|
||||||
|
log.info("订单支付:{}", ordersPaymentDTO);
|
||||||
|
OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
|
||||||
|
log.info("生成预支付交易单:{}", orderPaymentVO);
|
||||||
|
return Result.success(orderPaymentVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/historyOrders")
|
||||||
|
@ApiOperation("历史订单查询")
|
||||||
|
public Result<PageResult> page(int page, int pageSize, Integer status){
|
||||||
|
PageResult pageResult = orderService.pageQuery4User(page, pageSize, status);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询订单详情
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/orderDetail/{id}")
|
||||||
|
@ApiOperation("查询订单详情")
|
||||||
|
public Result<OrderVO> details(@PathVariable Long id){
|
||||||
|
OrderVO orderVO = orderService.details(id);
|
||||||
|
return Result.success(orderVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户取消订单
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/cancel/{id}")
|
||||||
|
@ApiOperation("取消订单")
|
||||||
|
public Result cancel(@PathVariable Long id){
|
||||||
|
orderService.userCancelById(id);
|
||||||
|
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 再来一单
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/repetition/{id}")
|
||||||
|
@ApiOperation("再来一单")
|
||||||
|
public Result repetition(@PathVariable Long id){
|
||||||
|
orderService.repetition(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户催单
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/reminder/{id}")
|
||||||
|
@ApiOperation("客户催单")
|
||||||
|
public Result reminder(@PathVariable Long id){
|
||||||
|
orderService.reminder(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,4 +44,30 @@ public class ShoppingCartController {
|
|||||||
List<ShoppingCart> list = shoppingCartService.showShoppingCart();
|
List<ShoppingCart> list = shoppingCartService.showShoppingCart();
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空购物车
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/clean")
|
||||||
|
@ApiOperation("清空购物车")
|
||||||
|
public Result clean(){
|
||||||
|
shoppingCartService.cleanShoppingCart();
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除购物车中一个商品
|
||||||
|
* @param shoppingCartDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/sub")
|
||||||
|
@ApiOperation("删除购物车中一个商品")
|
||||||
|
public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
|
||||||
|
log.info("删除购物车中一个商品,商品:{}", shoppingCartDTO);
|
||||||
|
shoppingCartService.subShoppingCart(shoppingCartDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.entity.AddressBook;
|
||||||
|
import org.apache.ibatis.annotations.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface AddressBookMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件查询
|
||||||
|
* @param addressBook
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<AddressBook> list(AddressBook addressBook);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
* @param addressBook
|
||||||
|
*/
|
||||||
|
@Insert("insert into address_book" +
|
||||||
|
" (user_id, consignee, phone, sex, province_code, province_name, city_code, city_name, district_code," +
|
||||||
|
" district_name, detail, label, is_default)" +
|
||||||
|
" values (#{userId}, #{consignee}, #{phone}, #{sex}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}," +
|
||||||
|
" #{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault})")
|
||||||
|
void insert(AddressBook addressBook);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select * from address_book where id = #{id}")
|
||||||
|
AddressBook getById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id修改
|
||||||
|
* @param addressBook
|
||||||
|
*/
|
||||||
|
void update(AddressBook addressBook);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 用户id修改 是否默认地址
|
||||||
|
* @param addressBook
|
||||||
|
*/
|
||||||
|
@Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
|
||||||
|
void updateIsDefaultByUserId(AddressBook addressBook);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除地址
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Delete("delete from address_book where id = #{id}")
|
||||||
|
void deleteById(Long id);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sky.entity.OrderDetail;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface OrderDetailMapper {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量插入订单明细数据
|
||||||
|
* @param orderDetailList
|
||||||
|
*/
|
||||||
|
void insertBatch(List<OrderDetail> orderDetailList);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单id 查询订单明细
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select * from order_detail where order_id = #{orderId}")
|
||||||
|
List<OrderDetail> getByOrderId(Long id);
|
||||||
|
}
|
||||||
99
sky-server/src/main/java/com/sky/mapper/OrderMapper.java
Normal file
99
sky-server/src/main/java/com/sky/mapper/OrderMapper.java
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.sky.dto.GoodsSalesDTO;
|
||||||
|
import com.sky.dto.OrdersPageQueryDTO;
|
||||||
|
import com.sky.entity.Orders;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface OrderMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入订单数据
|
||||||
|
* @param orders
|
||||||
|
*/
|
||||||
|
void insert(Orders orders);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单号查询订单
|
||||||
|
* @param orderNumber
|
||||||
|
*/
|
||||||
|
@Select("select * from orders where number = #{orderNumber}")
|
||||||
|
Orders getByNumber(String orderNumber);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改订单信息
|
||||||
|
* @param orders
|
||||||
|
*/
|
||||||
|
void update(Orders orders);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页条件查询 并按照下单时间排序
|
||||||
|
* @param ordersPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询订单
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select * from orders where id = #{id}")
|
||||||
|
Orders getById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据状态统计订单数量
|
||||||
|
* @param toBeConfirmed
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select count(*) from orders where status = #{status}")
|
||||||
|
Integer countStatus(Integer toBeConfirmed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单状态和下单时间查询订单
|
||||||
|
* @param status
|
||||||
|
* @param orderTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select * from orders where status = #{status} and order_time < #{orderTime}")
|
||||||
|
List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据动态条件统计营业额数据
|
||||||
|
* @param map
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
//select sum(amount) from orders where order_time < ? and order_time > ? and status = 5
|
||||||
|
Double sumByMap(Map map);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据动态条件统计订单数据
|
||||||
|
* @param map
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Integer countByMap(Map map);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间区间内的销量排名前10
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.sky.mapper;
|
|||||||
|
|
||||||
import com.sky.dto.ShoppingCartDTO;
|
import com.sky.dto.ShoppingCartDTO;
|
||||||
import com.sky.entity.ShoppingCart;
|
import com.sky.entity.ShoppingCart;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
import org.apache.ibatis.annotations.Insert;
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Update;
|
import org.apache.ibatis.annotations.Update;
|
||||||
@@ -33,4 +34,26 @@ public interface ShoppingCartMapper {
|
|||||||
+
|
+
|
||||||
"values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{amount}, #{createTime}, #{number})")
|
"values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{amount}, #{createTime}, #{number})")
|
||||||
void insert(ShoppingCart shoppingCart);
|
void insert(ShoppingCart shoppingCart);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据微信用户id删除购物车数据
|
||||||
|
* @param userId
|
||||||
|
*/
|
||||||
|
@Delete("delete from shopping_cart where user_id = #{userId}")
|
||||||
|
void deleteByUserId(Long userId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量插入购物车数据
|
||||||
|
* @param shoppingCartList
|
||||||
|
*/
|
||||||
|
void insertBatch(List<ShoppingCart> shoppingCartList);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除购物车数据
|
||||||
|
*/
|
||||||
|
@Delete("delete from shopping_cart where id = #{id}")
|
||||||
|
void deleteById(Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.sky.entity.User;
|
|||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface UserMapper {
|
public interface UserMapper {
|
||||||
/**
|
/**
|
||||||
@@ -22,4 +24,17 @@ public interface UserMapper {
|
|||||||
* @param user
|
* @param user
|
||||||
*/
|
*/
|
||||||
void insert(User user);
|
void insert(User user);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Select("select * from user where id = #{id}")
|
||||||
|
User getById(Long userId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据动态条件统计用户数量
|
||||||
|
* @param map
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Integer countByMap(Map map);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.entity.AddressBook;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface AddressBookService {
|
||||||
|
|
||||||
|
List<AddressBook> list(AddressBook addressBook);
|
||||||
|
|
||||||
|
void save(AddressBook addressBook);
|
||||||
|
|
||||||
|
AddressBook getById(Long id);
|
||||||
|
|
||||||
|
void update(AddressBook addressBook);
|
||||||
|
|
||||||
|
void setDefault(AddressBook addressBook);
|
||||||
|
|
||||||
|
void deleteById(Long id);
|
||||||
|
|
||||||
|
}
|
||||||
121
sky-server/src/main/java/com/sky/service/OrderService.java
Normal file
121
sky-server/src/main/java/com/sky/service/OrderService.java
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.*;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.vo.OrderPaymentVO;
|
||||||
|
import com.sky.vo.OrderStatisticsVO;
|
||||||
|
import com.sky.vo.OrderSubmitVO;
|
||||||
|
import com.sky.vo.OrderVO;
|
||||||
|
|
||||||
|
|
||||||
|
public interface OrderService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户下单
|
||||||
|
* @param ordersSubmitDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单支付
|
||||||
|
* @param ordersPaymentDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付成功,修改订单状态
|
||||||
|
* @param outTradeNo
|
||||||
|
*/
|
||||||
|
void paySuccess(String outTradeNo);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户订单分页查询
|
||||||
|
* @param page
|
||||||
|
* @param pageSize
|
||||||
|
* @param status
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult pageQuery4User(int page, int pageSize, Integer status);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询订单详情
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderVO details(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户取消订单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void userCancelById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 再来一单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void repetition(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单搜索
|
||||||
|
* @param ordersPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 各个状态的订单数量统计
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderStatisticsVO statistics();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接单
|
||||||
|
* @param ordersConfirmDTO
|
||||||
|
*/
|
||||||
|
void confirm(OrdersConfirmDTO ordersConfirmDTO);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拒单
|
||||||
|
* @param ordersRejectionDTO
|
||||||
|
*/
|
||||||
|
void rejection(OrdersRejectionDTO ordersRejectionDTO);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消订单
|
||||||
|
* @param ordersCancelDTO
|
||||||
|
*/
|
||||||
|
void cancel(OrdersCancelDTO ordersCancelDTO);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 派送订单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void delivery(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 完成订单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void complete(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户催单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void reminder(Long id);
|
||||||
|
}
|
||||||
55
sky-server/src/main/java/com/sky/service/ReportService.java
Normal file
55
sky-server/src/main/java/com/sky/service/ReportService.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.vo.OrderReportVO;
|
||||||
|
import com.sky.vo.SalesTop10ReportVO;
|
||||||
|
import com.sky.vo.TurnoverReportVO;
|
||||||
|
import com.sky.vo.UserReportVO;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
public interface ReportService {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*统计指定时间内的营业额数据
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
TurnoverReportVO getTurnoverStatistics(LocalDate begin, LocalDate end);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间内的用户数据
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
UserReportVO getUserStatistics(LocalDate begin, LocalDate end);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间内的订单数据
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderReportVO getOrdersStatistics(LocalDate begin, LocalDate end);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间内的销量排名前10
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SalesTop10ReportVO getSalesTop10(LocalDate begin, LocalDate end);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出运营数据报表
|
||||||
|
* @param response
|
||||||
|
*/
|
||||||
|
void exportBusinessData(HttpServletResponse response);
|
||||||
|
}
|
||||||
@@ -9,6 +9,12 @@ import java.util.List;
|
|||||||
public interface ShoppingCartService {
|
public interface ShoppingCartService {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除购物车中一个商品
|
||||||
|
* @param shoppingCartDTO
|
||||||
|
*/
|
||||||
|
void subShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加购物车
|
* 添加购物车
|
||||||
* @param shoppingCartDTO
|
* @param shoppingCartDTO
|
||||||
@@ -21,4 +27,10 @@ public interface ShoppingCartService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<ShoppingCart> showShoppingCart();
|
List<ShoppingCart> showShoppingCart();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空购物车
|
||||||
|
*/
|
||||||
|
void cleanShoppingCart();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.sky.context.BaseContext;
|
||||||
|
import com.sky.entity.AddressBook;
|
||||||
|
import com.sky.mapper.AddressBookMapper;
|
||||||
|
import com.sky.service.AddressBookService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class AddressBookServiceImpl implements AddressBookService {
|
||||||
|
@Autowired
|
||||||
|
private AddressBookMapper addressBookMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件查询
|
||||||
|
*
|
||||||
|
* @param addressBook
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<AddressBook> list(AddressBook addressBook) {
|
||||||
|
return addressBookMapper.list(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增地址
|
||||||
|
*
|
||||||
|
* @param addressBook
|
||||||
|
*/
|
||||||
|
public void save(AddressBook addressBook) {
|
||||||
|
addressBook.setUserId(BaseContext.getCurrentId());
|
||||||
|
addressBook.setIsDefault(0);
|
||||||
|
addressBookMapper.insert(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public AddressBook getById(Long id) {
|
||||||
|
AddressBook addressBook = addressBookMapper.getById(id);
|
||||||
|
return addressBook;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id修改地址
|
||||||
|
*
|
||||||
|
* @param addressBook
|
||||||
|
*/
|
||||||
|
public void update(AddressBook addressBook) {
|
||||||
|
addressBookMapper.update(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置默认地址
|
||||||
|
*
|
||||||
|
* @param addressBook
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void setDefault(AddressBook addressBook) {
|
||||||
|
//1、将当前用户的所有地址修改为非默认地址 update address_book set is_default = ? where user_id = ?
|
||||||
|
addressBook.setIsDefault(0);
|
||||||
|
addressBook.setUserId(BaseContext.getCurrentId());
|
||||||
|
addressBookMapper.updateIsDefaultByUserId(addressBook);
|
||||||
|
|
||||||
|
//2、将当前地址改为默认地址 update address_book set is_default = ? where id = ?
|
||||||
|
addressBook.setIsDefault(1);
|
||||||
|
addressBookMapper.update(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除地址
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
public void deleteById(Long id) {
|
||||||
|
addressBookMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,637 @@
|
|||||||
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.sky.constant.MessageConstant;
|
||||||
|
import com.sky.context.BaseContext;
|
||||||
|
import com.sky.dto.*;
|
||||||
|
import com.sky.entity.*;
|
||||||
|
import com.sky.exception.AddressBookBusinessException;
|
||||||
|
import com.sky.exception.OrderBusinessException;
|
||||||
|
import com.sky.exception.ShoppingCartBusinessException;
|
||||||
|
import com.sky.mapper.*;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.OrderService;
|
||||||
|
import com.sky.service.UserService;
|
||||||
|
import com.sky.utils.HttpClientUtil;
|
||||||
|
import com.sky.utils.WeChatPayUtil;
|
||||||
|
import com.sky.vo.OrderPaymentVO;
|
||||||
|
import com.sky.vo.OrderStatisticsVO;
|
||||||
|
import com.sky.vo.OrderSubmitVO;
|
||||||
|
import com.sky.vo.OrderVO;
|
||||||
|
import com.sky.websocket.WebSocketServer;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.xmlbeans.impl.xb.xmlconfig.Extensionconfig;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class OrderServiceImpl implements OrderService {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||||
|
@Autowired
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
@Autowired
|
||||||
|
private OrderDetailMapper orderDetailMapper;
|
||||||
|
@Autowired
|
||||||
|
private AddressBookMapper addressBookMapper;
|
||||||
|
@Autowired
|
||||||
|
private ShoppingCartMapper shoppingCartMapper;
|
||||||
|
@Autowired
|
||||||
|
private WeChatPayUtil weChatPayUtil;
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
@Value("${sky.shop.address}")
|
||||||
|
private String shopAddress;
|
||||||
|
@Value("${sky.baidu.ak}")
|
||||||
|
private String ak;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WebSocketServer webSocketServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户下单
|
||||||
|
* @param ordersSubmitDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO) {
|
||||||
|
|
||||||
|
//首先处理业务异常(地址簿为空 购物车数据为空)
|
||||||
|
|
||||||
|
//地址簿为空
|
||||||
|
AddressBook addressBook = addressBookMapper.getById(ordersSubmitDTO.getAddressBookId());
|
||||||
|
if(addressBook==null){
|
||||||
|
throw new AddressBookBusinessException(MessageConstant.ADDRESS_BOOK_IS_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
//检查用户的收货地址是否超出配送范围
|
||||||
|
checkOutOfRange(addressBook.getCityName() + addressBook.getDistrictName() + addressBook.getDetail());
|
||||||
|
|
||||||
|
|
||||||
|
//购物车为空
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
ShoppingCart shoppingCart = new ShoppingCart();
|
||||||
|
shoppingCart.setUserId(userId);
|
||||||
|
List<ShoppingCart> shoppingCartList = shoppingCartMapper.list(shoppingCart);
|
||||||
|
if(shoppingCartList==null || shoppingCartList.size()==0){
|
||||||
|
throw new ShoppingCartBusinessException(MessageConstant.SHOPPING_CART_IS_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
//向订单表插入一条数据
|
||||||
|
Orders orders = new Orders();
|
||||||
|
BeanUtils.copyProperties(ordersSubmitDTO,orders);
|
||||||
|
orders.setOrderTime(LocalDateTime.now());
|
||||||
|
orders.setPayStatus(Orders.UN_PAID);
|
||||||
|
orders.setStatus(Orders.PENDING_PAYMENT);
|
||||||
|
orders.setNumber(String.valueOf(System.currentTimeMillis())); //使用时间戳作为订单号
|
||||||
|
orders.setPhone(addressBook.getPhone());
|
||||||
|
orders.setConsignee(addressBook.getConsignee());
|
||||||
|
orders.setAddress(addressBook.getDetail());
|
||||||
|
orders.setUserId(userId);
|
||||||
|
|
||||||
|
orderMapper.insert(orders);
|
||||||
|
|
||||||
|
List<OrderDetail> orderDetailList = new ArrayList<>();
|
||||||
|
//向订单明细表插入多条数据
|
||||||
|
for(ShoppingCart cart:shoppingCartList){
|
||||||
|
OrderDetail orderDetail = new OrderDetail();
|
||||||
|
BeanUtils.copyProperties(cart,orderDetail);
|
||||||
|
orderDetail.setOrderId(orders.getId()); //设置当前订单明细关联的订单id
|
||||||
|
orderDetailList.add(orderDetail);
|
||||||
|
}
|
||||||
|
//批量插入
|
||||||
|
orderDetailMapper.insertBatch(orderDetailList);
|
||||||
|
|
||||||
|
//清空当前用户的购物车数据
|
||||||
|
shoppingCartMapper.deleteByUserId(userId);
|
||||||
|
|
||||||
|
//封装VO返回结果
|
||||||
|
OrderSubmitVO orderSubmitVO = OrderSubmitVO.builder()
|
||||||
|
.id(orders.getId())
|
||||||
|
.orderTime(orders.getOrderTime())
|
||||||
|
.orderNumber(orders.getNumber())
|
||||||
|
.orderAmount(orders.getAmount())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return orderSubmitVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单支付
|
||||||
|
*
|
||||||
|
* @param ordersPaymentDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception {
|
||||||
|
/*
|
||||||
|
// 当前登录用户id
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
User user = userMapper.getById(userId);
|
||||||
|
|
||||||
|
//调用微信支付接口,生成预支付交易单
|
||||||
|
JSONObject jsonObject = weChatPayUtil.pay(
|
||||||
|
ordersPaymentDTO.getOrderNumber(), //商户订单号
|
||||||
|
new BigDecimal(0.01), //支付金额,单位 元
|
||||||
|
"苍穹外卖订单", //商品描述
|
||||||
|
user.getOpenid() //微信用户的openid
|
||||||
|
);
|
||||||
|
|
||||||
|
if (jsonObject.getString("code") != null && jsonObject.getString("code").equals("ORDERPAID")) {
|
||||||
|
throw new OrderBusinessException("该订单已支付");
|
||||||
|
}
|
||||||
|
|
||||||
|
OrderPaymentVO vo = jsonObject.toJavaObject(OrderPaymentVO.class);
|
||||||
|
vo.setPackageStr(jsonObject.getString("package"));
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
log.info("跳过微信支付,支付成功");
|
||||||
|
paySuccess(ordersPaymentDTO.getOrderNumber());
|
||||||
|
|
||||||
|
return new OrderPaymentVO();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付成功,修改订单状态
|
||||||
|
*
|
||||||
|
* @param outTradeNo
|
||||||
|
*/
|
||||||
|
public void paySuccess(String outTradeNo) {
|
||||||
|
|
||||||
|
// 根据订单号查询订单
|
||||||
|
Orders ordersDB = orderMapper.getByNumber(outTradeNo);
|
||||||
|
|
||||||
|
// 根据订单id更新订单的状态、支付方式、支付状态、结账时间
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.id(ordersDB.getId())
|
||||||
|
.status(Orders.TO_BE_CONFIRMED)
|
||||||
|
.payStatus(Orders.PAID)
|
||||||
|
.checkoutTime(LocalDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
orderMapper.update(orders);
|
||||||
|
|
||||||
|
//通过websocket向客户端浏览器推送消息 type orderId content
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("type", 1); //1表示来单提醒 2表示客户催单
|
||||||
|
map.put("orderId", ordersDB.getId());
|
||||||
|
map.put("content", "订单号:" + outTradeNo);
|
||||||
|
String json = JSON.toJSONString(map);
|
||||||
|
|
||||||
|
webSocketServer.sendToAllClient(json);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户订单分页查询
|
||||||
|
* @param pageNum
|
||||||
|
* @param pageSize
|
||||||
|
* @param status
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult pageQuery4User(int pageNum, int pageSize, Integer status) {
|
||||||
|
//设置分页
|
||||||
|
PageHelper.startPage(pageNum, pageSize);
|
||||||
|
|
||||||
|
OrdersPageQueryDTO ordersPageQueryDTO = new OrdersPageQueryDTO();
|
||||||
|
ordersPageQueryDTO.setUserId(BaseContext.getCurrentId());
|
||||||
|
ordersPageQueryDTO.setStatus(status);
|
||||||
|
|
||||||
|
//分页条件查询
|
||||||
|
Page<Orders> page = orderMapper.pageQuery(ordersPageQueryDTO);
|
||||||
|
|
||||||
|
List<OrderVO> list = new ArrayList<>();
|
||||||
|
|
||||||
|
//查询出订单明细,并封装入OrderVO进行响应
|
||||||
|
if(page != null && page.getTotal() > 0){
|
||||||
|
for(Orders orders: page){
|
||||||
|
Long orderId = orders.getId(); //订单id
|
||||||
|
|
||||||
|
//查询订单明细
|
||||||
|
List<OrderDetail> orderDetails = orderDetailMapper.getByOrderId(orderId);
|
||||||
|
|
||||||
|
OrderVO orderVO = new OrderVO();
|
||||||
|
BeanUtils.copyProperties(orders,orderVO);
|
||||||
|
orderVO.setOrderDetailList(orderDetails);
|
||||||
|
|
||||||
|
list.add(orderVO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new PageResult(page.getTotal(), list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询订单详情
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public OrderVO details(Long id) {
|
||||||
|
|
||||||
|
//根据id查询订单
|
||||||
|
Orders orders = orderMapper.getById(id);
|
||||||
|
|
||||||
|
//查询该订单对应的菜品/套餐的明细
|
||||||
|
//查询该订单对应的菜品/套餐的明细
|
||||||
|
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(orders.getId());
|
||||||
|
|
||||||
|
//将该订单及其详情封装到OrderVO并返回
|
||||||
|
OrderVO orderVO = new OrderVO();
|
||||||
|
BeanUtils.copyProperties(orders,orderVO);
|
||||||
|
orderVO.setOrderDetailList(orderDetailList);
|
||||||
|
|
||||||
|
return orderVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户取消订单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void userCancelById(Long id) {
|
||||||
|
|
||||||
|
Orders ordersDB = orderMapper.getById(id);
|
||||||
|
if(ordersDB == null){
|
||||||
|
throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
//订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消
|
||||||
|
if(ordersDB.getStatus() > 2){
|
||||||
|
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
Orders orders = new Orders();
|
||||||
|
orders.setId(ordersDB.getId());
|
||||||
|
|
||||||
|
//订单处于接单状态下取消 需要进行退款
|
||||||
|
if(ordersDB.getStatus().equals(Orders.TO_BE_CONFIRMED)){
|
||||||
|
/* //调用微信支付退款接口
|
||||||
|
weChatPayUtil.refund(
|
||||||
|
ordersDB.getNumber(), //商户订单号
|
||||||
|
ordersDB.getNumber(), //商户退款单号
|
||||||
|
new BigDecimal(0.01), //退款金额 单位元
|
||||||
|
new BigDecimal(0.01)); //原订单金额*/
|
||||||
|
|
||||||
|
//支付状态修改为退款
|
||||||
|
orders.setStatus(Orders.REFUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新订单状态 取消原因 取消时间
|
||||||
|
orders.setStatus(Orders.CANCELLED);
|
||||||
|
orders.setCancelReason("用户取消");
|
||||||
|
orders.setCancelTime(LocalDateTime.now());
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 再来一单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void repetition(Long id) {
|
||||||
|
|
||||||
|
//查询当前用户id
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
|
||||||
|
//根据订单id查询当前订单详情
|
||||||
|
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(id);
|
||||||
|
|
||||||
|
//将订单详情对象转换为购物车对象
|
||||||
|
List<ShoppingCart> shoppingCartList = orderDetailList.stream().map(x ->{
|
||||||
|
ShoppingCart shoppingCart = new ShoppingCart();
|
||||||
|
|
||||||
|
//将原订单详情里面的菜品信息重新复制到购物车对象中
|
||||||
|
BeanUtils.copyProperties(x,shoppingCart, "id");
|
||||||
|
shoppingCart.setUserId(userId);
|
||||||
|
shoppingCart.setCreateTime(LocalDateTime.now());
|
||||||
|
return shoppingCart;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
//将购物车对象批量加入到数据库
|
||||||
|
shoppingCartMapper.insertBatch(shoppingCartList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单搜索
|
||||||
|
* @param ordersPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
|
||||||
|
PageHelper.startPage(ordersPageQueryDTO.getPage(), ordersPageQueryDTO.getPageSize());
|
||||||
|
Page<Orders> page = orderMapper.pageQuery(ordersPageQueryDTO);
|
||||||
|
|
||||||
|
//部分订单状态需要额外返回订单菜品信息,将Orders转换为OrderVO
|
||||||
|
List<OrderVO> orderVOList = getOrderVOList(page);
|
||||||
|
|
||||||
|
return new PageResult(page.getTotal(), orderVOList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<OrderVO> getOrderVOList(Page<Orders> page){
|
||||||
|
//需要返回订单菜品信息 自定义OrderVO响应结果
|
||||||
|
List<OrderVO> orderVOList = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Orders> orderList = page.getResult();
|
||||||
|
if(orderList != null && orderList.size() > 0){
|
||||||
|
for(Orders orders: orderList){
|
||||||
|
OrderVO orderVO = new OrderVO();
|
||||||
|
BeanUtils.copyProperties(orders,orderVO);
|
||||||
|
|
||||||
|
/* // ========== 统一拒单原因和取消原因 ==========
|
||||||
|
if (orderVO.getCancelReason() == null && orderVO.getRejectionReason() != null) {
|
||||||
|
orderVO.setCancelReason(orderVO.getRejectionReason());
|
||||||
|
}*/
|
||||||
|
String orderDishes = getOrderDishesStr(orders);
|
||||||
|
|
||||||
|
//将订单菜品信息封装到orderVO中 并添加到orderVOList
|
||||||
|
orderVO.setOrderDishes(orderDishes);
|
||||||
|
orderVOList.add(orderVO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return orderVOList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单id获取菜品信息字符串
|
||||||
|
* @param orders
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getOrderDishesStr(Orders orders){
|
||||||
|
// 查询订单菜品详情信息(订单中的菜品和数量)
|
||||||
|
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(orders.getId());
|
||||||
|
|
||||||
|
// 将每一条订单菜品信息拼接为字符串(格式:宫保鸡丁*3;)
|
||||||
|
List<String> orderDishList = orderDetailList.stream().map(x ->{
|
||||||
|
String orderDish = x.getName() + "*" + x.getNumber() + ";";
|
||||||
|
return orderDish;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 将该订单对应的所有菜品信息拼接在一起
|
||||||
|
return String.join("",orderDishList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 各个状态的订单数量统计
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public OrderStatisticsVO statistics() {
|
||||||
|
//根据状态 分别查询出待接单、待派送、派送中的订单数量
|
||||||
|
Integer toBeConfirmed = orderMapper.countStatus(Orders.TO_BE_CONFIRMED);
|
||||||
|
Integer confirmed = orderMapper.countStatus(Orders.CONFIRMED);
|
||||||
|
Integer deliveryInProgress = orderMapper.countStatus(Orders.DELIVERY_IN_PROGRESS);
|
||||||
|
|
||||||
|
//将查询出的数量封装到orderStatisticsVO中响应
|
||||||
|
OrderStatisticsVO orderStatisticsVO = new OrderStatisticsVO();
|
||||||
|
orderStatisticsVO.setConfirmed(confirmed);
|
||||||
|
orderStatisticsVO.setToBeConfirmed(toBeConfirmed);
|
||||||
|
orderStatisticsVO.setDeliveryInProgress(deliveryInProgress);
|
||||||
|
|
||||||
|
return orderStatisticsVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接单
|
||||||
|
* @param ordersConfirmDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void confirm(OrdersConfirmDTO ordersConfirmDTO) {
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.id(ordersConfirmDTO.getId())
|
||||||
|
.status(Orders.CONFIRMED)
|
||||||
|
.build();
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拒单
|
||||||
|
* @param ordersRejectionDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void rejection(OrdersRejectionDTO ordersRejectionDTO) {
|
||||||
|
//根据id查询订单
|
||||||
|
Orders ordersDB = orderMapper.getById(ordersRejectionDTO.getId());
|
||||||
|
|
||||||
|
// 订单只有存在且状态为2(待接单)才可以拒单
|
||||||
|
if(ordersDB == null || !ordersDB.getStatus().equals(Orders.TO_BE_CONFIRMED)){
|
||||||
|
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
//支付状态
|
||||||
|
Integer payStatus = ordersDB.getPayStatus();
|
||||||
|
if(payStatus == Orders.PAID){
|
||||||
|
//用户已支付 需要退款
|
||||||
|
String refund = weChatPayUtil.refund(
|
||||||
|
ordersDB.getNumber(),
|
||||||
|
ordersDB.getNumber(),
|
||||||
|
new BigDecimal(0.01),
|
||||||
|
new BigDecimal(0.01));
|
||||||
|
log.info("申请退款:{}", refund);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 拒单需要退款,根据订单id更新订单状态、拒单原因、取消时间
|
||||||
|
Orders orders = new Orders();
|
||||||
|
orders.setId(ordersDB.getId());
|
||||||
|
orders.setStatus(Orders.CANCELLED);
|
||||||
|
orders.setRejectionReason(ordersRejectionDTO.getRejectionReason());
|
||||||
|
orders.setCancelTime(LocalDateTime.now());
|
||||||
|
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商家取消订单
|
||||||
|
* @param ordersCancelDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void cancel(OrdersCancelDTO ordersCancelDTO) {
|
||||||
|
//根据id查询订单
|
||||||
|
Orders ordersDB = orderMapper.getById(ordersCancelDTO.getId());
|
||||||
|
|
||||||
|
//管理端取消订单需要退款 根据订单id更新订单状态、取消原因、取消时间
|
||||||
|
Orders orders = new Orders();
|
||||||
|
orders.setId(ordersCancelDTO.getId());
|
||||||
|
orders.setStatus(Orders.CANCELLED);
|
||||||
|
orders.setCancelReason(ordersCancelDTO.getCancelReason());
|
||||||
|
orders.setCancelTime(LocalDateTime.now());
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 派送订单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delivery(Long id) {
|
||||||
|
// 根据id查询订单
|
||||||
|
Orders ordersDB = orderMapper.getById(id);
|
||||||
|
|
||||||
|
// 校验订单是否存在,并且状态为3(待派送 已接单)
|
||||||
|
if(ordersDB == null || !ordersDB.getStatus().equals(Orders.CONFIRMED)){
|
||||||
|
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新订单状态,状态转为派送中
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.status(Orders.DELIVERY_IN_PROGRESS)
|
||||||
|
.id(ordersDB.getId())
|
||||||
|
.build();
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 完成订单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void complete(Long id) {
|
||||||
|
// 根据id查询订单
|
||||||
|
Orders ordersDB = orderMapper.getById(id);
|
||||||
|
|
||||||
|
// 校验订单是否存在,并且状态为4 派送中
|
||||||
|
if(ordersDB == null || !ordersDB.getStatus().equals(Orders.DELIVERY_IN_PROGRESS)){
|
||||||
|
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新订单状态,状态转为完成
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.status(Orders.COMPLETED)
|
||||||
|
.id(ordersDB.getId())
|
||||||
|
.deliveryTime(LocalDateTime.now())
|
||||||
|
.build();
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户催单
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void reminder(Long id) {
|
||||||
|
|
||||||
|
//根据id查询订单
|
||||||
|
Orders ordersDB = orderMapper.getById(id);
|
||||||
|
//校验订单是否存在
|
||||||
|
if(ordersDB == null){
|
||||||
|
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("type", 2); //1表示来单提醒 2表示客户催单
|
||||||
|
map.put("orderId", id);
|
||||||
|
map.put("content", ordersDB.getNumber());
|
||||||
|
|
||||||
|
//通过websocket向客户端浏览器推送消息
|
||||||
|
webSocketServer.sendToAllClient(JSON.toJSONString(map));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查客户的收货地址是否超出配送范围
|
||||||
|
* @param address
|
||||||
|
*/
|
||||||
|
private void checkOutOfRange(String address){
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("address", shopAddress);
|
||||||
|
map.put("output", "json");
|
||||||
|
map.put("ak", ak);
|
||||||
|
|
||||||
|
//获取店铺的经纬度坐标
|
||||||
|
String shopCoordinate = HttpClientUtil.doGet("https://api.map.baidu.com/geocoding/v3", map);
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(shopCoordinate);
|
||||||
|
if (!jsonObject.getString("status").equals("0")) {
|
||||||
|
throw new OrderBusinessException("店铺解析失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//数据解析
|
||||||
|
JSONObject location = jsonObject.getJSONObject("result").getJSONObject("location");
|
||||||
|
String lat = location.getString("lat");
|
||||||
|
String lng = location.getString("lng");
|
||||||
|
|
||||||
|
//店铺经纬度坐标
|
||||||
|
String shopLat = lat + "," + lng;
|
||||||
|
|
||||||
|
map.put("address", address);
|
||||||
|
|
||||||
|
//获取用户收获地址的经纬度坐标
|
||||||
|
String userCoordinate = HttpClientUtil.doGet("https://api.map.baidu.com/geocoding/v3", map);
|
||||||
|
jsonObject = JSONObject.parseObject(userCoordinate);
|
||||||
|
if (!jsonObject.getString("status").equals("0")) {
|
||||||
|
throw new OrderBusinessException("收获地址解析失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
//数据解析
|
||||||
|
location = jsonObject.getJSONObject("result").getJSONObject("location");
|
||||||
|
lat = location.getString("lat");
|
||||||
|
lng = location.getString("lng");
|
||||||
|
//用户收货地址经纬度坐标
|
||||||
|
String userLngLat = lat + "," + lng;
|
||||||
|
map.put("origin", shopLat);
|
||||||
|
map.put("destination", userLngLat);
|
||||||
|
map.put("steps_info", "0");
|
||||||
|
|
||||||
|
//路线规划
|
||||||
|
String json = HttpClientUtil.doGet("https://api.map.baidu.com/directionlite/v1/driving", map);
|
||||||
|
jsonObject = JSONObject.parseObject(json);
|
||||||
|
if (!jsonObject.getString("status").equals("0")) {
|
||||||
|
throw new OrderBusinessException("配送路线规划失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
//数据解析
|
||||||
|
JSONObject result = jsonObject.getJSONObject("result");
|
||||||
|
JSONArray jsonArray = (JSONArray) result.get("routes");
|
||||||
|
|
||||||
|
Integer distance = (Integer)((JSONObject)jsonArray.get(0)).get("distance");
|
||||||
|
//配送距离超过5000米
|
||||||
|
if(distance > 5000){
|
||||||
|
throw new OrderBusinessException("超出配送范围");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,305 @@
|
|||||||
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.sky.dto.GoodsSalesDTO;
|
||||||
|
import com.sky.entity.Orders;
|
||||||
|
import com.sky.mapper.OrderMapper;
|
||||||
|
import com.sky.mapper.UserMapper;
|
||||||
|
import com.sky.service.ReportService;
|
||||||
|
import com.sky.service.WorkspaceService;
|
||||||
|
import com.sky.vo.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class ReportServiceImpl implements ReportService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
@Autowired
|
||||||
|
private WorkspaceService workspaceService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间内的营业额数据
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TurnoverReportVO getTurnoverStatistics(LocalDate begin, LocalDate end) {
|
||||||
|
|
||||||
|
//当前集合用于存放从begin到end范围内每天的日期
|
||||||
|
List<LocalDate> dateList = new ArrayList();
|
||||||
|
dateList.add(begin);
|
||||||
|
while(!begin.equals(end)){
|
||||||
|
//日期计算 计算指定日期的后一天对应的日期
|
||||||
|
begin = begin.plusDays(1);
|
||||||
|
dateList.add(begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置营业额集合
|
||||||
|
List<Double> turnoverList = new ArrayList<>();
|
||||||
|
for(LocalDate date:dateList){
|
||||||
|
//查询date对应的营业额 状态为“已完成”的订单的金额总和
|
||||||
|
LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
|
||||||
|
LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
|
||||||
|
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("begin",beginTime);
|
||||||
|
map.put("end",endTime);
|
||||||
|
map.put("status", Orders.COMPLETED);
|
||||||
|
Double turnover = orderMapper.sumByMap(map);
|
||||||
|
turnover = turnover == null ? 0.0 : turnover;
|
||||||
|
turnoverList.add(turnover);
|
||||||
|
}
|
||||||
|
|
||||||
|
//将日期转为字符串
|
||||||
|
String join = StringUtils.join(dateList, ",");
|
||||||
|
|
||||||
|
TurnoverReportVO turnoverReportVO = TurnoverReportVO.builder()
|
||||||
|
.dateList(join)
|
||||||
|
.turnoverList(StringUtils.join(turnoverList, ","))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return turnoverReportVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间内的用户数据
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public UserReportVO getUserStatistics(LocalDate begin, LocalDate end) {
|
||||||
|
|
||||||
|
//当前集合用于存放从begin到end范围内每天的日期
|
||||||
|
List<LocalDate> dateList = new ArrayList();
|
||||||
|
dateList.add(begin);
|
||||||
|
while(!begin.equals(end)){
|
||||||
|
//日期计算 计算指定日期的后一天对应的日期
|
||||||
|
begin = begin.plusDays(1);
|
||||||
|
dateList.add(begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
//存放每天的新增用户数量 select count(id) from user where create_time < ? and create_time > ?
|
||||||
|
List<Integer> newUserList = new ArrayList<>();
|
||||||
|
//存放每天的总用户数量 select count(id) from user where create_time < ?
|
||||||
|
List<Integer> totalUserList = new ArrayList<>();
|
||||||
|
|
||||||
|
//设置用户数据集合 用户总量 新增用户
|
||||||
|
for(LocalDate date:dateList){
|
||||||
|
LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
|
||||||
|
LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
|
||||||
|
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("end", endTime);
|
||||||
|
Integer totalUser = userMapper.countByMap(map);
|
||||||
|
|
||||||
|
map.put("begin", beginTime);
|
||||||
|
Integer newUser = userMapper.countByMap(map);
|
||||||
|
|
||||||
|
totalUserList.add(totalUser);
|
||||||
|
newUserList.add(newUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
//封装结果数据
|
||||||
|
UserReportVO userReportVO = UserReportVO.builder()
|
||||||
|
.dateList(StringUtils.join(dateList, ","))
|
||||||
|
.totalUserList(StringUtils.join(totalUserList, ","))
|
||||||
|
.newUserList(StringUtils.join(newUserList, ","))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return userReportVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间内的用户数据
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public OrderReportVO getOrdersStatistics(LocalDate begin, LocalDate end) {
|
||||||
|
//当前集合用于存放从begin到end范围内每天的日期
|
||||||
|
List<LocalDate> dateList = new ArrayList();
|
||||||
|
dateList.add(begin);
|
||||||
|
while(!begin.equals(end)){
|
||||||
|
//日期计算 计算指定日期的后一天对应的日期
|
||||||
|
begin = begin.plusDays(1);
|
||||||
|
dateList.add(begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> orderCountList = new ArrayList<>();
|
||||||
|
List<Integer> validOrderCountList = new ArrayList<>();
|
||||||
|
|
||||||
|
//遍历日期集合 查询每天的有效订单数和订单总数
|
||||||
|
for(LocalDate date: dateList){
|
||||||
|
LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
|
||||||
|
LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
|
||||||
|
|
||||||
|
//查询每天的订单总数 select count(id) from orders where order_time > ? and order_time < ?
|
||||||
|
Integer orderCount = getOrderCount(beginTime, endTime, null);
|
||||||
|
orderCountList.add(orderCount);
|
||||||
|
//查询每天的有效订单数 select count(id) from orders where order_time > ? and order_time < ? and status = 5
|
||||||
|
Integer validOrderCount = getOrderCount(beginTime, endTime, Orders.COMPLETED);
|
||||||
|
validOrderCountList.add(validOrderCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
//计算时间区间内的订单总数量
|
||||||
|
Integer totalOrderCount = orderCountList.stream().reduce(Integer::sum).get();
|
||||||
|
//计算时间区间内的有效订单总数量
|
||||||
|
Integer totalValidOrderCount = validOrderCountList.stream().reduce(Integer::sum).get();
|
||||||
|
//计算订单有效率
|
||||||
|
Double orderCompletionRate = totalOrderCount ==0? 0.0: totalValidOrderCount.doubleValue() / totalOrderCount;
|
||||||
|
|
||||||
|
OrderReportVO orderReportVO = OrderReportVO.builder()
|
||||||
|
.dateList(StringUtils.join(dateList, ","))
|
||||||
|
.orderCountList(StringUtils.join(orderCountList, ","))
|
||||||
|
.validOrderCountList(StringUtils.join(validOrderCountList, ","))
|
||||||
|
.totalOrderCount(totalOrderCount)
|
||||||
|
.validOrderCount(totalValidOrderCount)
|
||||||
|
.orderCompletionRate(orderCompletionRate)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return orderReportVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据状态统计订单数量
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @param status
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Integer getOrderCount(LocalDateTime begin, LocalDateTime end, Integer status) {
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("begin", begin);
|
||||||
|
map.put("end", end);
|
||||||
|
map.put("status", status);
|
||||||
|
Integer orderCount = orderMapper.countByMap(map);
|
||||||
|
return orderCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*统计指定时间区间内的销量排名前10
|
||||||
|
* @param begin
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SalesTop10ReportVO getSalesTop10(LocalDate begin, LocalDate end) {
|
||||||
|
LocalDateTime beginTime = LocalDateTime.of(begin, LocalTime.MIN);
|
||||||
|
LocalDateTime endTime = LocalDateTime.of(end, LocalTime.MAX);
|
||||||
|
|
||||||
|
List<GoodsSalesDTO> salesTop10 = orderMapper.getSalesTop10(beginTime, endTime);
|
||||||
|
|
||||||
|
List<String> names = salesTop10.stream().map(GoodsSalesDTO::getName).collect(Collectors.toList());
|
||||||
|
String nameList = StringUtils.join(names, ",");
|
||||||
|
List<Integer> numbers = salesTop10.stream().map(GoodsSalesDTO::getNumber).collect(Collectors.toList());
|
||||||
|
String numberList = StringUtils.join(numbers, ",");
|
||||||
|
|
||||||
|
return SalesTop10ReportVO.builder()
|
||||||
|
.nameList(nameList)
|
||||||
|
.numberList(numberList)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出运营数据报表
|
||||||
|
* @param response
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void exportBusinessData(HttpServletResponse response) {
|
||||||
|
//1、查询数据库 获取营业数据 查询最近30天的数据
|
||||||
|
LocalDate dateBegin = LocalDate.now().minusDays(30);
|
||||||
|
LocalDate dateEnd = LocalDate.now().minusDays(1);
|
||||||
|
|
||||||
|
BusinessDataVO businessDataVO = workspaceService.getBusinessData(LocalDateTime.of(dateBegin, LocalTime.MIN), LocalDateTime.of(dateEnd, LocalTime.MAX));
|
||||||
|
|
||||||
|
//2、通过POI将数据写入Excel文件中
|
||||||
|
InputStream in = this.getClass().getClassLoader().getResourceAsStream("template/运营数据报表模板.xlsx");
|
||||||
|
|
||||||
|
try {
|
||||||
|
//基于模板文件创建一个新的excel文件
|
||||||
|
XSSFWorkbook excel = new XSSFWorkbook(in);
|
||||||
|
|
||||||
|
//获取表格文件的标签页
|
||||||
|
XSSFSheet sheet = excel.getSheet("Sheet1");
|
||||||
|
|
||||||
|
//填充数据--时间
|
||||||
|
sheet.getRow(1).getCell(1).setCellValue("时间" + dateBegin + "至" + dateEnd);
|
||||||
|
|
||||||
|
//获得第四行
|
||||||
|
XSSFRow row = sheet.getRow(3);
|
||||||
|
row.getCell(2).setCellValue(businessDataVO.getTurnover());
|
||||||
|
row.getCell(4).setCellValue(businessDataVO.getOrderCompletionRate());
|
||||||
|
row.getCell(6).setCellValue(businessDataVO.getNewUsers());
|
||||||
|
|
||||||
|
//获得第五行
|
||||||
|
row = sheet.getRow(4);
|
||||||
|
row.getCell(2).setCellValue(businessDataVO.getValidOrderCount());
|
||||||
|
row.getCell(4).setCellValue(businessDataVO.getUnitPrice());
|
||||||
|
|
||||||
|
//填充明细数据
|
||||||
|
for(int i = 0; i < 30; i ++){
|
||||||
|
LocalDate date = dateBegin.plusDays(i);
|
||||||
|
//查询某一天的营业数据
|
||||||
|
BusinessDataVO businessData = workspaceService.getBusinessData(LocalDateTime.of(date, LocalTime.MIN), LocalDateTime.of(date, LocalTime.MAX));
|
||||||
|
|
||||||
|
//获得某一行
|
||||||
|
row = sheet.getRow(7 + i);
|
||||||
|
row.getCell(1).setCellValue(date.toString());
|
||||||
|
row.getCell(2).setCellValue(businessData.getTurnover());
|
||||||
|
row.getCell(3).setCellValue(businessData.getValidOrderCount());
|
||||||
|
row.getCell(4).setCellValue(businessData.getOrderCompletionRate());
|
||||||
|
row.getCell(5).setCellValue(businessData.getUnitPrice());
|
||||||
|
row.getCell(6).setCellValue(businessData.getNewUsers());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//3、通过输出流将Excel文件下载到客户端浏览器
|
||||||
|
ServletOutputStream out = response.getOutputStream();
|
||||||
|
excel.write(out);
|
||||||
|
|
||||||
|
//关闭资源
|
||||||
|
out.close();
|
||||||
|
excel.close();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -30,6 +30,8 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|||||||
private SetmealMapper setmealMapper;
|
private SetmealMapper setmealMapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加购物车
|
* 添加购物车
|
||||||
* @param shoppingCartDTO
|
* @param shoppingCartDTO
|
||||||
@@ -96,4 +98,45 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|||||||
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空购物车
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void cleanShoppingCart() {
|
||||||
|
//获取当前微信用户的id
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
shoppingCartMapper.deleteByUserId(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除购物车中的商品
|
||||||
|
* @param shoppingCartDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void subShoppingCart(ShoppingCartDTO shoppingCartDTO) {
|
||||||
|
ShoppingCart shoppingCart = new ShoppingCart();
|
||||||
|
BeanUtils.copyProperties(shoppingCartDTO,shoppingCart);
|
||||||
|
|
||||||
|
//设置查询条件 查询当前用户的购物车数据
|
||||||
|
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||||
|
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||||
|
|
||||||
|
if (list != null && list.size() > 0) {
|
||||||
|
ShoppingCart cart = list.get(0);
|
||||||
|
|
||||||
|
Integer number = cart.getNumber();
|
||||||
|
if(number == 1){
|
||||||
|
//当前商品在购物车中的份数为1,直接删除当前记录
|
||||||
|
shoppingCartMapper.deleteById(shoppingCart.getId());
|
||||||
|
}else{
|
||||||
|
//当前商品在购物车中的份数不为1,修改份数即可
|
||||||
|
cart.setNumber(number-1);
|
||||||
|
shoppingCartMapper.updateNumberById(cart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
71
sky-server/src/main/java/com/sky/task/OrderTask.java
Normal file
71
sky-server/src/main/java/com/sky/task/OrderTask.java
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package com.sky.task;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sky.entity.Orders;
|
||||||
|
import com.sky.mapper.OrderMapper;
|
||||||
|
import com.sky.service.OrderService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务类 定时处理任务状态
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@EnableScheduling
|
||||||
|
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);
|
||||||
|
|
||||||
|
//select * from orders where status = ? and order_time < (当前时间 - 15分钟)
|
||||||
|
List<Orders> ordersList = orderMapper.getByStatusAndOrderTimeLT(Orders.PENDING_PAYMENT, time);
|
||||||
|
if(ordersList != null && ordersList.size()>0){
|
||||||
|
for(Orders orders : ordersList){
|
||||||
|
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> ordersList = orderMapper.getByStatusAndOrderTimeLT(Orders.DELIVERY_IN_PROGRESS, time);
|
||||||
|
if (ordersList != null && ordersList.size() > 0) {
|
||||||
|
for (Orders orders : ordersList) {
|
||||||
|
orders.setStatus(Orders.COMPLETED);
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.sky.websocket;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import javax.websocket.OnClose;
|
||||||
|
import javax.websocket.OnMessage;
|
||||||
|
import javax.websocket.OnOpen;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import javax.websocket.server.PathParam;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket服务
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@ServerEndpoint("/ws/{sid}")
|
||||||
|
public class WebSocketServer {
|
||||||
|
|
||||||
|
//存放会话对象
|
||||||
|
private static Map<String, Session> sessionMap = new HashMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接建立成功调用的方法
|
||||||
|
*/
|
||||||
|
@OnOpen
|
||||||
|
public void onOpen(Session session, @PathParam("sid") String sid) {
|
||||||
|
System.out.println("客户端:" + sid + "建立连接");
|
||||||
|
sessionMap.put(sid, session);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收到客户端消息后调用的方法
|
||||||
|
*
|
||||||
|
* @param message 客户端发送过来的消息
|
||||||
|
*/
|
||||||
|
@OnMessage
|
||||||
|
public void onMessage(String message, @PathParam("sid") String sid) {
|
||||||
|
System.out.println("收到来自客户端:" + sid + "的信息:" + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接关闭调用的方法
|
||||||
|
*
|
||||||
|
* @param sid
|
||||||
|
*/
|
||||||
|
@OnClose
|
||||||
|
public void onClose(@PathParam("sid") String sid) {
|
||||||
|
System.out.println("连接断开:" + sid);
|
||||||
|
sessionMap.remove(sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群发
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public void sendToAllClient(String message) {
|
||||||
|
Collection<Session> sessions = sessionMap.values();
|
||||||
|
for (Session session : sessions) {
|
||||||
|
try {
|
||||||
|
//服务器向客户端发送消息
|
||||||
|
session.getBasicRemote().sendText(message);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -54,3 +54,7 @@ sky:
|
|||||||
wechat:
|
wechat:
|
||||||
appid: ${sky.wechat.appid}
|
appid: ${sky.wechat.appid}
|
||||||
secret: ${sky.wechat.secret}
|
secret: ${sky.wechat.secret}
|
||||||
|
shop:
|
||||||
|
address: 山西省晋中市太古区山西农业大学
|
||||||
|
baidu:
|
||||||
|
ak: MAXYV7FMGffoKTRsrd35RXhjHTWxSEkw
|
||||||
|
|||||||
45
sky-server/src/main/resources/mapper/AddressBookMapper.xml
Normal file
45
sky-server/src/main/resources/mapper/AddressBookMapper.xml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="com.sky.mapper.AddressBookMapper">
|
||||||
|
|
||||||
|
<select id="list" parameterType="AddressBook" resultType="AddressBook">
|
||||||
|
select * from address_book
|
||||||
|
<where>
|
||||||
|
<if test="userId != null">
|
||||||
|
and user_id = #{userId}
|
||||||
|
</if>
|
||||||
|
<if test="phone != null">
|
||||||
|
and phone = #{phone}
|
||||||
|
</if>
|
||||||
|
<if test="isDefault != null">
|
||||||
|
and is_default = #{isDefault}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="update" parameterType="addressBook">
|
||||||
|
update address_book
|
||||||
|
<set>
|
||||||
|
<if test="consignee != null">
|
||||||
|
consignee = #{consignee},
|
||||||
|
</if>
|
||||||
|
<if test="sex != null">
|
||||||
|
sex = #{sex},
|
||||||
|
</if>
|
||||||
|
<if test="phone != null">
|
||||||
|
phone = #{phone},
|
||||||
|
</if>
|
||||||
|
<if test="detail != null">
|
||||||
|
detail = #{detail},
|
||||||
|
</if>
|
||||||
|
<if test="label != null">
|
||||||
|
label = #{label},
|
||||||
|
</if>
|
||||||
|
<if test="isDefault != null">
|
||||||
|
is_default = #{isDefault},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -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>
|
||||||
|
|||||||
14
sky-server/src/main/resources/mapper/OrderDetailMapper.xml
Normal file
14
sky-server/src/main/resources/mapper/OrderDetailMapper.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="com.sky.mapper.OrderDetailMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<insert id="insertBatch">
|
||||||
|
insert into order_detail (name, image, order_id, dish_id, setmeal_id, dish_flavor, number, amount)
|
||||||
|
values
|
||||||
|
<foreach collection="orderDetailList" item="od" separator=",">
|
||||||
|
(#{od.name}, #{od.image}, #{od.orderId},#{od.dishId},#{od.setmealId},#{od.dishFlavor},#{od.number}, #{od.amount})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
||||||
116
sky-server/src/main/resources/mapper/OrderMapper.xml
Normal file
116
sky-server/src/main/resources/mapper/OrderMapper.xml
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="com.sky.mapper.OrderMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into orders (number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark, phone, address, consignee, estimated_delivery_time, delivery_status, pack_amount, tableware_number, tableware_status)
|
||||||
|
values
|
||||||
|
(#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime},
|
||||||
|
#{payMethod}, #{payStatus}, #{amount}, #{remark}, #{phone}, #{address},
|
||||||
|
#{consignee}, #{estimatedDeliveryTime}, #{deliveryStatus}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.sky.entity.Orders">
|
||||||
|
update orders
|
||||||
|
<set>
|
||||||
|
<if test="cancelReason != null and cancelReason!='' ">
|
||||||
|
cancel_reason=#{cancelReason},
|
||||||
|
</if>
|
||||||
|
<if test="rejectionReason != null and rejectionReason!='' ">
|
||||||
|
rejection_reason=#{rejectionReason},
|
||||||
|
</if>
|
||||||
|
<if test="cancelTime != null">
|
||||||
|
cancel_time=#{cancelTime},
|
||||||
|
</if>
|
||||||
|
<if test="payStatus != null">
|
||||||
|
pay_status=#{payStatus},
|
||||||
|
</if>
|
||||||
|
<if test="payMethod != null">
|
||||||
|
pay_method=#{payMethod},
|
||||||
|
</if>
|
||||||
|
<if test="checkoutTime != null">
|
||||||
|
checkout_time=#{checkoutTime},
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
status = #{status},
|
||||||
|
</if>
|
||||||
|
<if test="deliveryTime != null">
|
||||||
|
delivery_time = #{deliveryTime}
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
<select id="pageQuery" resultType="com.sky.entity.Orders">
|
||||||
|
select * from orders
|
||||||
|
<where>
|
||||||
|
<if test="number != null and number != ''">
|
||||||
|
and number like concat('%', #{number}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="phone != null and phone != ''">
|
||||||
|
and phone like concat('%', #{phone}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="userId != null">
|
||||||
|
and user_id = #{userId}
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
and status = #{status}
|
||||||
|
</if>
|
||||||
|
<if test="beginTime != null">
|
||||||
|
and order_time >= #{beginTime}
|
||||||
|
</if>
|
||||||
|
<if test="endTime != null">
|
||||||
|
and order_time <= #{endTime}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by order_time desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="sumByMap" resultType="java.lang.Double">
|
||||||
|
select sum(amount) from orders
|
||||||
|
<where>
|
||||||
|
<if test="begin != null">
|
||||||
|
and order_time > #{begin}
|
||||||
|
</if>
|
||||||
|
<if test="end != null">
|
||||||
|
and order_time < #{end}
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
and status = #{status}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="countByMap" resultType="java.lang.Integer">
|
||||||
|
select count(id) from orders
|
||||||
|
<where>
|
||||||
|
<if test="begin != null">
|
||||||
|
and order_time > #{begin}
|
||||||
|
</if>
|
||||||
|
<if test="end != null">
|
||||||
|
and order_time < #{end}
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
and status = #{status}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="getSalesTop10" resultType="com.sky.dto.GoodsSalesDTO">
|
||||||
|
select od.name, sum(od.number) number from order_detail od, orders o where od.order_id = o.id and o.status = 5
|
||||||
|
<if test="begin != null">
|
||||||
|
and o.order_time > #{begin}
|
||||||
|
</if>
|
||||||
|
<if test="end != null">
|
||||||
|
and o.order_time < #{end}
|
||||||
|
</if>
|
||||||
|
group by od.name
|
||||||
|
order by number desc
|
||||||
|
limit 0, 10
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.sky.mapper.ShoppingCartMapper">
|
<mapper namespace="com.sky.mapper.ShoppingCartMapper">
|
||||||
|
|
||||||
|
|
||||||
<select id="list" resultType="com.sky.entity.ShoppingCart">
|
<select id="list" resultType="com.sky.entity.ShoppingCart">
|
||||||
select * from shopping_cart
|
select * from shopping_cart
|
||||||
<where>
|
<where>
|
||||||
@@ -21,4 +20,14 @@
|
|||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<insert id="insertBatch" parameterType="list">
|
||||||
|
insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)
|
||||||
|
values
|
||||||
|
<foreach collection="list" item="sc" separator=",">
|
||||||
|
(#{sc.name}, #{sc.image}, #{sc.userId}, #{sc.dishId}, #{sc.setmealId}, #{sc.dishFlavor}, #{sc.number}, #{sc.amount}, #{sc.createTime})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -9,4 +9,17 @@
|
|||||||
values
|
values
|
||||||
(#{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})
|
(#{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="countByMap" resultType="java.lang.Integer">
|
||||||
|
select count(id) from user
|
||||||
|
<where>
|
||||||
|
<if test="begin != null">
|
||||||
|
and create_time > #{begin}
|
||||||
|
</if>
|
||||||
|
<if test="end != null">
|
||||||
|
and create_time < #{end}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
BIN
sky-server/src/main/resources/template/运营数据报表模板.xlsx
Normal file
BIN
sky-server/src/main/resources/template/运营数据报表模板.xlsx
Normal file
Binary file not shown.
390
sql/_localhost-2026_04_22_09_59_10-dump.sql
Normal file
390
sql/_localhost-2026_04_22_09_59_10-dump.sql
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user