package com.neusoft.smart.pos.report.controller;

import com.neusoft.smart.pos.framework.dto.ResponseData;


import com.neusoft.smart.pos.report.dto.*;

import com.neusoft.smart.pos.report.service.RecordReportToolService;
import com.neusoft.smart.pos.report.service.RecordReportService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "记录查询报表", description = "记录查询报表接口")
@RestController
@Validated
@RequestMapping(path = "/report")
public class RecordReportController {

    @Resource
    private RecordReportService recordReportService;
    @Resource
    private RecordReportToolService recordReportToolService;


    @Transactional
    @ApiOperation(value = "充值记录查询接口", notes = "充值记录查询接口")
    @GetMapping("/rechargeRecord")
//    public ResponseData<?> rechargeRecord(@RequestBody RechargeRecordRequest rechargeRecordRequest) {
//
//        return new ResponseData<>(recordReportService.queryRechargeRecord(rechargeRecordRequest));
//    }
    public ResponseData<RechargeRecordResponse> rechargeRecord(@RequestParam(value="orgName",defaultValue = "") String orgName
            , @RequestParam(value="serialNo",defaultValue = "") String serialNo
            ,@RequestParam(value="orderNumber",defaultValue = "") String orderNumber
            ,@RequestParam(value="memberName",defaultValue = "") String memberName
            ,@RequestParam(value="deviceName",defaultValue = "") String deviceName
            ,@RequestParam(value="cardNum",defaultValue = "") String cardNum
            ,@RequestParam(value="memberCardNo",defaultValue = "") String memberCardNo
            ,@RequestParam(value="payTypeName",defaultValue = "") String payTypeName
            ,@RequestParam(value="orderStatus",defaultValue = "") Integer orderStatus
            , @RequestParam(value="startTime",defaultValue = "") String startTime
            , @RequestParam(value="endTime",defaultValue = "") String endTime
            , @RequestParam(value="offset",defaultValue = "") Integer offset
            , @RequestParam(value="limit",defaultValue = "") Integer limit
            , @RequestParam(value="isPage",defaultValue = "") Boolean isPage) {



        RechargeRecordRequest rechargeRecordRequest = new RechargeRecordRequest();
        rechargeRecordRequest.setOrgGroupId(recordReportToolService.getOrgGroupId());
        rechargeRecordRequest.setOrgName(orgName);
        rechargeRecordRequest.setOrderNumber(orderNumber);
        System.out.println("orderNumber===="+rechargeRecordRequest.getOrderNumber());
        rechargeRecordRequest.setMemberName(memberName);
        rechargeRecordRequest.setDeviceName(deviceName);
        rechargeRecordRequest.setCardNum(cardNum);
        rechargeRecordRequest.setMemberCardNo(memberCardNo);
        rechargeRecordRequest.setPayTypeName(payTypeName);
                rechargeRecordRequest.setOrderStatus(orderStatus);
        rechargeRecordRequest.setSerialNo(serialNo);
//        rechargeRecordRequest.setChargeOrg("沈阳");
        rechargeRecordRequest.setStartTime(startTime);
        rechargeRecordRequest.setEndTime(endTime);
        rechargeRecordRequest.setOffset(offset);
        rechargeRecordRequest.setLimit(limit);
        rechargeRecordRequest.setIsPage(isPage);
        return new ResponseData(recordReportService.queryRechargeRecord(rechargeRecordRequest));
    }

    @Transactional
    @ApiOperation(value = "退款记录查询接口", notes = "退款记录查询接口")
    @GetMapping("/refundRecord")
    public ResponseData<RefundRecordResponse> refundRecord( @RequestParam(value="path",defaultValue = "") String path
            , @RequestParam(value="orgName",defaultValue = "") String orgName
            , @RequestParam(value="startTime",defaultValue = "") String startTime
            , @RequestParam(value="endTime",defaultValue = "") String endTime
            , @RequestParam(value="serialNo",defaultValue = "") String serialNo
            , @RequestParam(value="refundTime",defaultValue = "") String refundTime
            , @RequestParam(value="offset",defaultValue = "") Integer offset
            , @RequestParam(value="limit",defaultValue = "") Integer limit
            , @RequestParam(value="isPage",defaultValue = "") Boolean isPage) {


        RefundRecordRequest refundRecordRequest = new RefundRecordRequest();
        refundRecordRequest.setOrgGroupId(recordReportToolService.getOrgGroupId());
        refundRecordRequest.setOrgName(orgName);
        refundRecordRequest.setSerialNo(serialNo);

        refundRecordRequest.setPath(path);
        refundRecordRequest.setStartTime(startTime);
        refundRecordRequest.setEndTime(endTime);
        refundRecordRequest.setIsPage(isPage);
        refundRecordRequest.setLimit(limit);
        refundRecordRequest.setOffset(offset);
        return new ResponseData(recordReportService.queryRefundRecord(refundRecordRequest));
    }

    @Transactional
    @ApiOperation(value = "微信、支付宝消费明细查询接口", notes = "微信、支付宝消费明细查询接口")
    @GetMapping("/consumptionDetails")
    public ResponseData<ConsumptionDetailsResponse> consumptionDetails(@RequestParam(value="startTime",defaultValue = "") String startTime
           ,@RequestParam(value="endTime",defaultValue = "") String endTime
            , @RequestParam(value="serialNo",defaultValue = "") String serialNo
            , @RequestParam(value="orgName",defaultValue = "") String orgName
            , @RequestParam(value="mealTimes",defaultValue = "") String mealTimes
            , @RequestParam(value="payType",defaultValue = "") String payType
            , @RequestParam(value="offset",defaultValue = "") Integer offset
            , @RequestParam(value="limit",defaultValue = "") Integer limit
            , @RequestParam(value="isPage",defaultValue = "") Boolean isPage) {

        ConsumptionDetailsRequest consumptionDetailsRequest = new ConsumptionDetailsRequest();
        consumptionDetailsRequest.setOrgGroupId(recordReportToolService.getOrgGroupId());
        consumptionDetailsRequest.setOrgName(orgName);
        consumptionDetailsRequest.setSerialNo(serialNo);

        consumptionDetailsRequest.setMealTimes(mealTimes);
        consumptionDetailsRequest.setStartTime(startTime);
        consumptionDetailsRequest.setEndTime(endTime);
        consumptionDetailsRequest.setPayType(payType);
        consumptionDetailsRequest.setIsPage(isPage);
        consumptionDetailsRequest.setLimit(limit);
        consumptionDetailsRequest.setOffset(offset);

        return new ResponseData(recordReportService.queryConsumptionDetails(consumptionDetailsRequest));
    }

    @Transactional
    @ApiOperation(value = "营业组餐收入汇总查询接口", notes = "营业组餐收入汇总查询接口")
    @GetMapping("/businessGroup")
    public ResponseData businessGroup(@RequestParam(value="startTime",defaultValue = "") String startTime
            ,@RequestParam(value="endTime",defaultValue = "") String endTime
            , @RequestParam(value="orgName",defaultValue = "") String orgName
            ,@RequestParam(value="offset",defaultValue = "") Integer offset
            , @RequestParam(value="limit",defaultValue = "") Integer limit
            , @RequestParam(value="isPage",defaultValue = "") Boolean isPage) {
//        System.out.println("sssssss!");

        BusinessGroupRequest businessGroupRequest = new BusinessGroupRequest();

        businessGroupRequest.setOrgGroupId(recordReportToolService.getOrgGroupId());
        businessGroupRequest.setOrgName(orgName);
        businessGroupRequest.setStartTime(startTime);
        businessGroupRequest.setEndTime(endTime);
        businessGroupRequest.setIsPage(isPage);
        businessGroupRequest.setLimit(limit);
        businessGroupRequest.setOffset(offset);

       // return new ResponseData(recordReportService.queryBusinessGroup(businessGroupRequest));
        return new ResponseData(recordReportService.queryBusinessGroup(businessGroupRequest));
    }

    @Transactional
    @ApiOperation(value = "个人消费明细统计接口", notes = "个人消费明细统计接口")
    @GetMapping("/personalonsumption")
    public ResponseData personalonsumption(@RequestParam(value="startTime",defaultValue = "") String startTime
            ,@RequestParam(value="endTime",defaultValue = "") String endTime
            , @RequestParam(value="employeeNumber",defaultValue = "") String employeeNumber
            , @RequestParam(value="orgName",defaultValue = "") String orgName
            , @RequestParam(value="offset",defaultValue = "") Integer offset
            , @RequestParam(value="limit",defaultValue = "") Integer limit
            , @RequestParam(value="isPage",defaultValue = "") Boolean isPage) {


        PersonaConsumptionRequest personaConsumptionRequest1 = new PersonaConsumptionRequest();
        personaConsumptionRequest1.setOrgGroupId(recordReportToolService.getOrgGroupId());
        personaConsumptionRequest1.setOrgName(orgName);
        personaConsumptionRequest1.setEmployeeNumber(employeeNumber);
        personaConsumptionRequest1.setStartTime(startTime);
        personaConsumptionRequest1.setEndTime(endTime);
        personaConsumptionRequest1.setIsPage(isPage);
        personaConsumptionRequest1.setLimit(limit);
        personaConsumptionRequest1.setOffset(offset);
        return new ResponseData(recordReportService.queryPersonaConsumption(personaConsumptionRequest1));
    }

}
