package com.bweb.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.model.ResponseData;
import com.hai.service.HighOilCardRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/oilCardRecord")
@Api(value = "油卡记录")
public class HighOilCardRecordController {

    private static Logger log = LoggerFactory.getLogger(HighOilCardRecordController.class);

    @Resource
    private HighOilCardRecordService oilCardRecordService;

    @RequestMapping(value = "/getOilCardRecordList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询油卡记录列表")
    public ResponseData getOilCardRecordList(@RequestParam(name = "cardNo", required = true) String cardNo,
                                             @RequestParam(name = "sourceOrderNo", required = false) String sourceOrderNo,
                                             @RequestParam(name = "type", required = false) Integer type,
                                             @RequestParam(name = "sourceType", required = false) String sourceType,
                                             @RequestParam(name = "createTimeS", required = false) Long createTimeS,
                                             @RequestParam(name = "createTimeE", required = false) Long createTimeE,
                                             @RequestParam(name = "pageNum", required = true) Integer pageNum,
                                             @RequestParam(name = "pageSize", required = true) Integer pageSize) {
        try {

            Map<String, Object> param = new HashMap<>();
            param.put("cardNo", cardNo);
            param.put("type", type);
            param.put("sourceType", sourceType);
            param.put("sourceOrderNo", sourceOrderNo);
            param.put("createTimeS", createTimeS);
            param.put("createTimeE", createTimeE);

            PageHelper.startPage(pageNum, pageSize);
            return ResponseMsgUtil.success(new PageInfo<>(oilCardRecordService.getRecordList(param)));

        } catch (Exception e) {
            log.error("HighOilCardRecordController --> getOilCardRecordList() error!", e);
            return ResponseMsgUtil.exception(e);
        }
    }

}
