文章目录
-
- 概要
- 整体架构流程
- 技术细节
- 小结
概要
完成订单是电子商务、外卖平台、在线零售等多个行业中的一项重要业务流程。这项功能允许商家或平台将订单状态更新为“已完成”,表明订单已经成功交付给客户。
需求分析以及接口设计
技术细节
1.Controller层:
@ApiOperation("完成订单")
@PutMapping("/complete/{id}")
public Result complete(@PathVariable Long id){
log.info("完成订单,订单id:{}",id);
orderService.complete(id);
return Result.success();
}
2.Service层:
@Override
public void complete(Long id) {
//只有派送中的订单能进行"已完成"
Orders ordersDB = orderMapper.getById(id);
Integer status = ordersDB.getStatus();
if(status == null || !status.equals(Orders.DELIVERY_IN_PROGRESS)){
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
}
Orders orders = new Orders();
orders.setId(id);
orders.setStatus(Orders.COMPLETED);
orderMapper.update(orders);
}
3.Mapper层:
<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>