package com.fs.app.controller;

import com.fs.app.annotation.Login;
import com.fs.common.core.domain.R;
import com.fs.his.domain.FsStoreOrder;
import com.fs.his.param.*;
import com.fs.his.service.*;
import com.fs.his.vo.FsStoreOrderItemListDVO;
import com.fs.his.vo.FsStoreOrderListDVO;
import com.fs.ybPay.service.IPayService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Api("商城订单接口")
@RestController
@RequestMapping(value="/app/storeOrder")
public class StoreOrderController extends  AppBaseController {

    @Autowired
    IPayService payService;
    @Autowired
    private IFsStoreOrderService orderService;

    @Autowired
    private IFsStoreOrderItemService orderItemService;


    @Login
    @ApiOperation("获取我的订单列表")
    @GetMapping("/getMyStoreOrderList")
    public R getMyStoreOrderList(FsStoreOrderListDParam param, HttpServletRequest request){
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        if(param.getIsDoctor()!=null&&param.getIsDoctor().equals(1)){
            param.setDoctorId(Long.parseLong(getDoctorId()));
        }
        List<FsStoreOrderListDVO> list=orderService.selectFsStoreOrderListDVO(param);
        PageInfo<FsStoreOrderListDVO> listPageInfo=new PageInfo<>(list);
        return R.ok().put("data",listPageInfo);
    }

    @Login
    @ApiOperation("获取订单")
    @GetMapping("/getStoreOrderById")
    public R getStoreOrderById(@RequestParam("orderId") Long orderId, HttpServletRequest request){
        FsStoreOrder order=orderService.selectFsStoreOrderByOrderId(orderId);
        List<FsStoreOrderItemListDVO> items=orderItemService.selectFsStoreOrderItemListDVOByOrderId(orderId);
        return R.ok().put("order",order).put("items",items);
    }




}
