package com.xhpc.log.controller;

import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.enums.StationDeviceEnum;
import com.xhpc.log.service.OrderLogService;
import lombok.extern.java.Log;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


/**
 * 订单报文日志
 */
@RestController
@RequestMapping("/log/order/")
public class OrderLogController extends BaseController {

    @Resource
    OrderLogService orderLogService;

    @GetMapping("/getPage")
    public TableDataInfo getOrderPage(@RequestParam(required = false) String tenantId,
                @RequestParam(required = false) Integer number){

        startPage();
        Map<String, Object> params = new HashMap<>();
        params.put("operatorId", SecurityUtils.getUserId());
        params.put("number", number);
        params.put("tenantId", tenantId);
        return getDataTable(orderLogService.getOrderPage(params));
    }


    @GetMapping("/detail")
    public TableDataInfo getOrderDetailPage(@RequestParam("orderId") String orderId){
        startPage();
        return getDataTable(orderLogService.getOrderDetailPage(orderId));
    }


    @PostMapping("/export")
    public void export(HttpServletResponse response,
                       @RequestParam(required = false) String orderId,
                       @RequestParam(required = false) String tenantId,
                       @RequestParam(required = false) Integer number,
                       @RequestParam(required = false) String serialNumber) throws Exception {

        Map<String, Object> params = new HashMap<>();
        params.put("operatorId", SecurityUtils.getUserId());
        params.put("number", number);
        params.put("serialNumber", serialNumber);
        params.put("tenantId", tenantId);
        params.put("orderId", orderId);
        orderLogService.export(response, params);
    }

}
