用户端:

查询历史订单
 查询订单详情
 取消订单
 再来一单
管理端:
 分页条件查询
This commit is contained in:
2024-12-28 20:36:18 +08:00
parent 28cb22928f
commit f68ed79b7f
11 changed files with 241 additions and 3 deletions

View File

@@ -115,6 +115,11 @@
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>6.1.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>

View File

@@ -0,0 +1,28 @@
package com.sky.controller.admin;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import io.swagger.annotations.Api;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/admin/order")
@Api(tags = "Order-Controller")
@Slf4j
public class OrderController {
@Autowired
private OrderService orderService;
@GetMapping("/conditionSearch")
public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
PageResult pageResult = orderService.pageQuery(ordersPageQueryDTO);
return Result.success(pageResult);
}
}

View File

@@ -1,11 +1,14 @@
package com.sky.controller.user; package com.sky.controller.user;
import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPaymentDTO; import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO; import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result; import com.sky.result.Result;
import com.sky.service.OrderService; import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO; import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO; import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -42,4 +45,32 @@ public class OrderController {
log.info("生成预支付交易单:{}", orderPaymentVO); log.info("生成预支付交易单:{}", orderPaymentVO);
return Result.success(orderPaymentVO); return Result.success(orderPaymentVO);
} }
@GetMapping("/historyOrders")
public Result<PageResult> historyOrders(Integer page, Integer pageSize, Integer status) {
log.info("查询历史订单");
PageResult pageResult = orderService.getHistoryOrders(page, pageSize, status);
return Result.success(pageResult);
}
@GetMapping("/orderDetail/{id}")
public Result<OrderVO> orderDetail(@PathVariable Long id) {
log.info("check order detail: {}", id);
OrderVO orderVO = orderService.getOrderDetailById(id);
return Result.success(orderVO);
}
@PutMapping("/cancel/{id}")
public Result cancel(@PathVariable Long id) {
log.info("cancel order: {}", id);
orderService.cancel(id);
return Result.success();
}
@PostMapping("/repetition/{id}")
public Result repetition(@PathVariable Long id) {
log.info("repetition order: {}", id);
orderService.repetition(id);
return Result.success();
}
} }

View File

@@ -13,4 +13,6 @@ public interface OrderDetailMapper {
* @param orderDetails * @param orderDetails
*/ */
void insertBatch(List<OrderDetail> orderDetails); void insertBatch(List<OrderDetail> orderDetails);
List<OrderDetail> getByOrderId(Long orderId);
} }

View File

@@ -1,11 +1,14 @@
package com.sky.mapper; package com.sky.mapper;
import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders; import com.sky.entity.Orders;
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 org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
@Mapper @Mapper
public interface OrderMapper { public interface OrderMapper {
@@ -29,4 +32,9 @@ public interface OrderMapper {
@Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}") @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id); void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);
Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
@Select("select * from orders where id = #{id}")
Orders getById(Long id);
} }

View File

@@ -58,4 +58,10 @@ public interface ShoppingCartMapper {
*/ */
@Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}") @Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
void deleteByUserId(Long userId); void deleteByUserId(Long userId);
/**
* insert all the shopping cart data
* @param shoppingCartList
*/
void insertBatch(List<ShoppingCart> shoppingCartList);
} }

View File

@@ -1,9 +1,13 @@
package com.sky.service; package com.sky.service;
import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO; import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO; import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.vo.OrderPaymentVO; import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO; import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@@ -29,4 +33,39 @@ public interface OrderService {
*/ */
void paySuccess(String outTradeNo); void paySuccess(String outTradeNo);
/**
* 获取历史订单
* (page query for user)
* @param page
* @param pageSize
* @param status
* @return
*/
PageResult getHistoryOrders(Integer page, Integer pageSize, Integer status);
/**
* get order detail by order id
* @param id
* @return
*/
OrderVO getOrderDetailById(Long id);
/**
* cancel order
* @param id
*/
void cancel(Long id);
/**
* repeat order by order id
* @param id
*/
void repetition(Long id);
/**
* page query for admin
* @param ordersPageQueryDTO
* @return
*/
PageResult pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
} }

View File

@@ -1,28 +1,32 @@
package com.sky.service.impl; package com.sky.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.constant.MessageConstant; import com.sky.constant.MessageConstant;
import com.sky.context.BaseContext; import com.sky.context.BaseContext;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO; import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO; import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.*; import com.sky.entity.*;
import com.sky.exception.AddressBookBusinessException; import com.sky.exception.AddressBookBusinessException;
import com.sky.exception.OrderBusinessException;
import com.sky.exception.ShoppingCartBusinessException; import com.sky.exception.ShoppingCartBusinessException;
import com.sky.mapper.*; import com.sky.mapper.*;
import com.sky.result.PageResult;
import com.sky.service.OrderService; import com.sky.service.OrderService;
import com.sky.utils.WeChatPayUtil; import com.sky.utils.WeChatPayUtil;
import com.sky.vo.OrderPaymentVO; import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO; import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
@Service @Service
@@ -69,6 +73,7 @@ public class OrderServiceImpl implements OrderService {
orders.setNumber(userId + "-" + System.currentTimeMillis()); orders.setNumber(userId + "-" + System.currentTimeMillis());
orders.setPhone(addressBook.getPhone()); orders.setPhone(addressBook.getPhone());
orders.setUserName(addressBook.getConsignee()); orders.setUserName(addressBook.getConsignee());
orders.setConsignee(addressBook.getConsignee());
orders.setAddress(addressBook.getDetail()); orders.setAddress(addressBook.getDetail());
orderMapper.insert(orders); orderMapper.insert(orders);
@@ -120,7 +125,7 @@ public class OrderServiceImpl implements OrderService {
}*/ }*/
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("code","ORDERPAID"); jsonObject.put("code", "ORDERPAID");
OrderPaymentVO vo = jsonObject.toJavaObject(OrderPaymentVO.class); OrderPaymentVO vo = jsonObject.toJavaObject(OrderPaymentVO.class);
vo.setPackageStr(jsonObject.getString("package")); vo.setPackageStr(jsonObject.getString("package"));
@@ -164,4 +169,83 @@ public class OrderServiceImpl implements OrderService {
orderMapper.update(orders); orderMapper.update(orders);
} }
@Override
public PageResult getHistoryOrders(Integer page, Integer pageSize, Integer status) {
Long userId = BaseContext.getCurrentId();
PageHelper.startPage(page,pageSize);
OrdersPageQueryDTO ordersPageQueryDTO = new OrdersPageQueryDTO();
ordersPageQueryDTO.setUserId(userId);
ordersPageQueryDTO.setStatus(status);
Page<Orders> ordersPage = orderMapper.pageQuery(ordersPageQueryDTO);
List<OrderVO> list = new ArrayList<>();
if (ordersPage != null && ordersPage.getTotal() > 0) {
for (Orders order : ordersPage) {
List<OrderDetail> orderDetails = orderDetailMapper.getByOrderId(order.getId());
OrderVO orderVO = new OrderVO();
orderVO.setOrderDetailList(orderDetails);
BeanUtils.copyProperties(order, orderVO);
list.add(orderVO);
}
}
return new PageResult(list.size(),list);
}
@Override
public OrderVO getOrderDetailById(Long id) {
OrderVO orderVO = new OrderVO();
Orders orders = orderMapper.getById(id);
BeanUtils.copyProperties(orders, orderVO);
orderVO.setOrderDetailList(orderDetailMapper.getByOrderId(orderVO.getId()));
return orderVO;
}
@Override
public void cancel(Long id) {
Orders orders = new Orders();
orders.setId(id);
orders.setStatus(Orders.CANCELLED);
orders.setCancelTime(LocalDateTime.now());
orderMapper.update(orders);
}
@Override
public void repetition(Long id) {
//get information of order detail
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(id);
//construct shopping cart
List<ShoppingCart> shoppingCartList = new ArrayList<>();
for (OrderDetail orderDetail : orderDetailList) {
ShoppingCart shoppingCart = new ShoppingCart();
shoppingCart.setName(orderDetail.getName());
shoppingCart.setImage(orderDetail.getImage());
shoppingCart.setUserId(BaseContext.getCurrentId());
shoppingCart.setDishId(orderDetail.getDishId());
shoppingCart.setSetmealId(orderDetail.getSetmealId());
shoppingCart.setDishFlavor(orderDetail.getDishFlavor());
shoppingCart.setNumber(orderDetail.getNumber());
shoppingCart.setAmount(orderDetail.getAmount());
shoppingCart.setCreateTime(LocalDateTime.now());
shoppingCartList.add(shoppingCart);
}
shoppingCartMapper.insertBatch(shoppingCartList);
}
@Override
public PageResult pageQuery(OrdersPageQueryDTO ordersPageQueryDTO) {
PageHelper.startPage(ordersPageQueryDTO.getPage(),ordersPageQueryDTO.getPageSize());
Page<Orders> ordersPage = orderMapper.pageQuery(ordersPageQueryDTO);
List<OrderVO> list = new ArrayList<>();
for (Orders orders : ordersPage) {
OrderVO orderVO = new OrderVO();
BeanUtils.copyProperties(orders, orderVO);
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(orders.getId());
String orderDishes = Arrays.toString(orderDetailList.toArray());
orderDishes = orderDishes.substring(1, orderDishes.length() - 1);
orderVO.setOrderDishes(orderDishes);
list.add(orderVO);
}
return new PageResult(list.size(),list);
}
} }

View File

@@ -11,4 +11,7 @@
(#{orderDetail.name},#{orderDetail.image},#{orderDetail.orderId},#{orderDetail.dishId},#{orderDetail.setmealId},#{orderDetail.dishFlavor},#{orderDetail.number},#{orderDetail.amount}) (#{orderDetail.name},#{orderDetail.image},#{orderDetail.orderId},#{orderDetail.dishId},#{orderDetail.setmealId},#{orderDetail.dishFlavor},#{orderDetail.number},#{orderDetail.amount})
</foreach> </foreach>
</insert> </insert>
<select id="getByOrderId" resultType="com.sky.entity.OrderDetail">
select * from sky_take_out.order_detail where order_id = #{orderId}
</select>
</mapper> </mapper>

View File

@@ -44,4 +44,29 @@
</set> </set>
where id = #{id} where id = #{id}
</update> </update>
<select id="pageQuery" resultType="com.sky.entity.Orders">
select * from orders
<where>
<if test="number != null">
and number like concat('%',#{number},'%')
</if>
<if test="phone != null">
and phone like concat('%',#{number},'%')
</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 &lt;= #{endTime}
</if>
<if test="userId != null">
and user_id = #{userId}
</if>
</where>
order by order_time desc
</select>
</mapper> </mapper>

View File

@@ -3,6 +3,13 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"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">
<insert id="insertBatch">
insert into sky_take_out.shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number,
amount, create_time) values
<foreach collection="shoppingCartList" item="s" separator=",">
(#{s.name},#{s.image},#{s.userId},#{s.dishId},#{s.setmealId},#{s.dishFlavor},#{s.number},#{s.amount},#{s.createTime})
</foreach>
</insert>
<delete id="delete"> <delete id="delete">
delete from sky_take_out.shopping_cart delete from sky_take_out.shopping_cart
<where> <where>