package com.pine.admin.modules.business.controller;

import java.util.*;

import com.pine.admin.modules.base.service.ExcelPoiService;
import com.pine.common.dto.Page;
import com.pine.admin.modules.base.binder.BaseController;
import com.pine.common.dto.Result;
import com.pine.common.excelutil.ExcelPoiUtil;
import com.pine.common.exception.ApiException;
import com.pine.common.utils.DateTimeTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.pine.admin.modules.business.entity.Order;
import com.pine.admin.modules.business.service.OrderService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 订单表
 *
 * @author Pine
 * @email 771190883@qq.com
 * @date 2019-10-11 15:44:20
 */
@Api(value = "订单表接口", tags = {"订单表接口"})
@RestController
@RequestMapping("business/Order")
@CrossOrigin
public class OrderController extends BaseController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private ExcelPoiService excelPoiService;

    /**
     * <p>根据Id。</p>
     */
    @ApiOperation(value = "核销虚拟订单", notes = "核销虚拟订单")
    @PostMapping(value = "/checkWriteOffVirtual")
    public Result checkWriteOffVirtualRequest(Long orderId, String writeOffCode) {
        String s = orderService.checkWriteOffVirtualRequest(orderId, writeOffCode);
        return Result.success(true, s);
    }


    /**
     * <p>根据Id。</p>
     */
    @ApiOperation(value = "获取订单表数据", notes = "根据id来获取订单表详细信息")
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Result getOrderEntity(@PathVariable("id") String id) {

        Order data = orderService.getById(id);
        return Result.success(true, data);
    }

    /**
     * <p>分页查询。</p>
     */
    @ApiOperation(value = "分页获取订单表数据", notes = "根据条件获取")
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result page(Page page, Order record) {

        Map<String, Object> result = new HashMap<>();

        List<Order> pp = orderService.getByPage(page, record);

        result.put("page", page);
        result.put("pp", pp);
        return Result.success(true, result);
    }

    /**
     * <p>excel。</p>
     */
    @ApiOperation(value = "分页获取订单表数据", notes = "根据条件获取")
    @RequestMapping(value = "/excel", method = RequestMethod.GET)
//    @ResponseBody
    public void excel(HttpServletResponse response, HttpServletRequest request, Order order) {
        excelPoiService.orderExcelExport(request,response,order);
    }


}
