package com.xhpc.order.controller;

import com.xhpc.common.core.constant.HttpStatus;
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.IXhpcHistoryOrderSortingStatusService;
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/sorting")
@Api(value = "历史订单清分状态接口", tags = "历史订单清分状态接口")
public class XhpcHistoryOrderSortingStatusController extends BaseController {

    @Autowired
    private IXhpcHistoryOrderSortingStatusService iXhpcHistoryOrderSortingStatusService;


    /**
     * 修改清分状态
     * @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(HttpStatus.NOT_NULL, "历史订单信息不能为空");
        }
        String status = StringUtils.valueOf(map.get("status"));
        if (StringUtils.isEmpty(status)) {
            AjaxResult.error(HttpStatus.NOT_NULL, "状态不能为空");
        }
        String remark = StringUtils.valueOf(map.get("remark"));
        return iXhpcHistoryOrderSortingStatusService.status(historyOrderIds, Integer.parseInt(status), remark);
    }

    /**
     * 运营商用户信息
     *
     * @param userId 用户id
     * @return
     */
    @GetMapping("/operatorUser")
    @ApiOperation(value = "运营商用户信息")
    public AjaxResult operatorUser(@RequestParam Long userId) {
        return iXhpcHistoryOrderSortingStatusService.operatorUser(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 = iXhpcHistoryOrderSortingStatusService.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 iXhpcHistoryOrderSortingStatusService.info(historyOrderId);
    }
}
