package com.xhpc.order.controller;

import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.order.service.IXhpcHistoryOrderReconciliationStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order/reconciliation")
@Api(value = "历史订单对账状态接口", tags = "历史订单对账状态接口")
public class XhpcHistoryOrderReconciliationStatusController extends BaseController {

    @Autowired
    private IXhpcHistoryOrderReconciliationStatusService iXhpcHistoryOrderReconciliationStatusService;

    /**
     * 修改对账状态
     * @return
     */
    @Log(title = "对账-修改对账状态", businessType = BusinessType.UPDATE)
    @PostMapping("/status")
    @ApiOperation(value = "修改对账状态")
    public AjaxResult status(@RequestBody Map<String, Object> map) {
        String historyOrderIds = StringUtils.valueOf(map.get("historyOrderIds"));
        if (StringUtils.isEmpty(historyOrderIds)) {
            AjaxResult.error("历史订单信息不能为空");
        }
        String status = StringUtils.valueOf(map.get("status"));
        if (StringUtils.isEmpty(status)) {
            AjaxResult.error("状态不能为空");
        }
        String remark = StringUtils.valueOf(map.get("remark"));
        return iXhpcHistoryOrderReconciliationStatusService.status(historyOrderIds, Integer.parseInt(status), remark);
    }

    /**
     * 流量用户信息
     *
     * @param userId 用户id
     * @return
     */
    @GetMapping("/internetUser")
    @ApiOperation(value = "流量用户信息")
    public AjaxResult internetUser(@RequestParam Long userId) {
        return iXhpcHistoryOrderReconciliationStatusService.internetUser(userId);
    }

    /**
     * 流量用户对账分页列表
     *
     * @param userId              用户id
     * @param serialNumber        订单编号
     * @param createTimeStart     创建开始时间
     * @param createTimeEnd       创建结束时间
     * @param chargingStationName 电站名称
     * @param status              状态
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "流量用户对账分页列表")
    public TableDataInfo page(@RequestParam Long userId, String serialNumber, String createTimeStart, String createTimeEnd, String chargingStationName, String status) {
        List<Map<String, Object>> list = iXhpcHistoryOrderReconciliationStatusService.page(userId, serialNumber, createTimeStart, createTimeEnd, chargingStationName, status);
        return getDataTable(list);
    }

    /**
     * 清分详情
     *
     * @param historyOrderId 历史订单id
     * @return
     */
    @GetMapping("/info")
    @ApiOperation(value = "清分详情")
    public AjaxResult info(@RequestParam Long historyOrderId) {
        return iXhpcHistoryOrderReconciliationStatusService.info(historyOrderId);
    }
}
