package com.xhpc.activity.controller;

import com.xhpc.activity.service.XhpcWorkHistoryOrderService;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author yuyang
 * @date 2022/8/5 9:32
 */
@RestController
@RequestMapping("/workHistoryOrder")
public class XhpcWorkHistoryOrderController extends BaseController {

    @Resource
    XhpcWorkHistoryOrderService xhpcWorkHistoryOrderService;

    /**
     * 历史异常订单
     * @return
     */
    @GetMapping("/getListPage")
    public TableDataInfo getListPage(String tenantId, Long chargingStationId, Long chargingPileId, Long terminalId, String phone, String transactionNumber, String chargingStationName, Long operatorId, Integer source, String beginStartTime, String beginEndTime,Integer type,
                                     String affiliationOrganization, String evcsOrderNo, String plateNum, Integer internetId, String internetSerialNumber, String terminalName, String vinCode, String overStartTime, String overEndTime, Long personnelId, Integer confirmResult,String stopReasonEvcs)

    {
        Map<String, Object> params = new HashMap<>();
        params.put("tenantId",tenantId);
        params.put("chargingStationId",chargingStationId);
        params.put("chargingPileId", chargingPileId);
        params.put("terminalId", terminalId);
        params.put("phone", phone);
        params.put("transactionNumber", transactionNumber);
        params.put("chargingStationName", chargingStationName);
        params.put("operatorId", operatorId);
        params.put("source", source);
        params.put("beginStartTime", beginStartTime);
        params.put("beginEndTime", beginEndTime);
        params.put("type", type);
        params.put("affiliationOrganization", affiliationOrganization);
        params.put("evcsOrderNo", evcsOrderNo);
        params.put("plateNum", plateNum);
        params.put("internetId", internetId);
        params.put("internetSerialNumber", internetSerialNumber);
        params.put("terminalName", terminalName);
        params.put("vinCode", vinCode);
        params.put("overStartTime", overStartTime);
        params.put("overEndTime", overEndTime);
        params.put("personnelId", personnelId);
        params.put("confirmResult", confirmResult);
        params.put("stopReasonEvcs", stopReasonEvcs);

        List<Map<String, Object>> listPage = xhpcWorkHistoryOrderService.getListPage(params);
        return getDataTable(listPage);
    }

    /**
     * 历史订单导出
     * @throws IOException 文件创建异常
     */
    @PostMapping("/export")
    public void getExport(HttpServletResponse response,String tenantId, Long chargingStationId, Long chargingPileId, Long terminalId, String phone, String transactionNumber,String chargingStationName, Long operatorId, Integer source, String beginStartTime, String beginEndTime,Integer type,
                          String affiliationOrganization, String evcsOrderNo, String plateNum, Integer internetId, String internetSerialNumber, String terminalName, String vinCode, String overStartTime, String overEndTime, Long personnelId, Integer confirmResult,String stopReasonEvcs) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("tenantId",tenantId);
        params.put("chargingStationId",chargingStationId);
        params.put("chargingPileId", chargingPileId);
        params.put("terminalId", terminalId);
        params.put("phone", phone);
        params.put("transactionNumber", transactionNumber);
        params.put("chargingStationName", chargingStationName);
        params.put("operatorId", operatorId);
        params.put("source", source);
        params.put("beginStartTime", beginStartTime);
        params.put("beginEndTime", beginEndTime);
        params.put("type", type);
        params.put("affiliationOrganization", affiliationOrganization);
        params.put("evcsOrderNo", evcsOrderNo);
        params.put("plateNum", plateNum);
        params.put("internetId", internetId);
        params.put("internetSerialNumber", internetSerialNumber);
        params.put("terminalName", terminalName);
        params.put("vinCode", vinCode);
        params.put("overStartTime", overStartTime);
        params.put("overEndTime", overEndTime);
        params.put("personnelId", personnelId);
        params.put("confirmResult", confirmResult);
        params.put("stopReasonEvcs", stopReasonEvcs);
        xhpcWorkHistoryOrderService.export(response,params);
    }


}
