发货接口测试成功,然后接着完成订单测试说空指针异常,URL测试地址是对的
package com.hw.springbootmall.controller; import com.github.pagehelper.PageInfo; import com.hw.springbootmall.common.ApiResponseObj; import com.hw.springbootmall.exception.MallExeception; import com.hw.springbootmall.service.OrderService; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; /** * @Author: Aiver * @Date: 2023/02/12~~12:19 * @Description:订单后台管理 */ @RestController //下面有完结订单,管理员和用户都可以完结订单。管理员和用户也可以访问,所以注释了这个admin的校验拦截,加在下面需要拦截验证管理员身份登陆 //@RequestMapping("/admin/order") public class OrderAdminController { @Autowired OrderService orderService; @ApiOperation(value = "管理员订单列表") @GetMapping("/admin/order/listOrderForAdmin") public ApiResponseObj listOrderForAdmin(@RequestParam Integer pageNum ,@RequestParam Integer pageSize){ PageInfo pageInfo = orderService.listForAdmin(pageNum, pageSize); return ApiResponseObj.success(pageInfo); } @ApiOperation(value = "管理员订单发货") @PostMapping("/admin/order/adminDeliveredOrder") public ApiResponseObj adminDeliveredOrder(@RequestParam String orderNo) throws MallExeception { orderService.deliver(orderNo); //业务逻辑就是修改订单状态,0是已取消订单,10未付款,20已付款,30已发货,40交易完成 return ApiResponseObj.success(); } /** * 管理员和用户都可以完结订单 * @param orderNo * @return * @throws MallExeception */ @ApiOperation(value = "管理员或者订单交易完成") @PostMapping("/orderFinish") public ApiResponseObj orderFinish(@RequestParam String orderNo) throws MallExeception { orderService.finish(orderNo); //业务逻辑就是修改订单状态,0是已取消订单,10未付款,20已付款,30已发货,40交易完成 return ApiResponseObj.success(); } }
//发货 @Override public void deliver(String orderNo) throws MallExeception { Order order = orderMapper.selectByOrderNo(orderNo); //查不到订单,报错 if (order == null) { throw new MallExeception(ExceptionEnum.ORDER_NOT_EXIT); } if (order.getOrderStatus() == Quantity.OrderStatusEnum.PAID.getCode()) { //如果订单状态是已支付,那么就发货并修改为发挥状态码 order.setOrderStatus(Quantity.OrderStatusEnum.DELIVERED.getCode()); order.setDeliveryTime(new Date()); orderMapper.updateByPrimaryKeySelective(order); } else { throw new MallExeception(ExceptionEnum.WRONG_ORDER_STATUS); } } @Override public void finish(String orderNo) throws MallExeception { Order order = orderMapper.selectByOrderNo(orderNo); //查不到订单,报错 if (order == null) { throw new MallExeception(ExceptionEnum.ORDER_NOT_EXIT); } //如果是普通用户,就要校验订单的所属 boolean isAdmin = userService.isAdmin(UserFilter.user); boolean orderBelongToUser = order.getUserId().equals(UserFilter.user.getId()); if (!isAdmin && !orderBelongToUser) { //普通用户而且也不属于他自己的订单 throw new MallExeception(ExceptionEnum.NOT_YOUR_ORDER); } //发货后可以完结订单 if (order.getOrderStatus() == Quantity.OrderStatusEnum.DELIVERED.getCode()) { order.setOrderStatus(Quantity.OrderStatusEnum.FINISHED.getCode()); order.setEndTime(new Date()); orderMapper.updateByPrimaryKeySelective(order); } else { throw new MallExeception(ExceptionEnum.WRONG_ORDER_STATUS); } }
只有这一行报错
[02:12 13:18:41.455] [ERROR] [com.hw.springbootmall.exception.GlobalExceptionHandler] - 系统异常来的java.lang.NullPointerException
相关截图:
12
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星