package com.jkcredit.invoice.controller.interserver;

import cn.com.taiji.sdk.model.comm.protocol.tts.trade.service.CardTradeModel;
import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
import com.jkcredit.invoice.service.lowerservice.SelfCarServiceL;
import com.jkcredit.invoice.service.lowerservice.vo.*;
import com.jkcredit.invoice.util.RespR;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "自有车下游接口")
@RestController
@RequestMapping(value = {"/selfCarService"})
public class SelfCarServiceController {
    @Autowired
    SelfCarServiceL selfCarService;
    /**
     * @param tradeRequestVo
     * @return
     */
    @PostMapping("/getTradeList")
    @ApiOperation(value="获取交易Id列表", notes="获取交易Id列表")
    public RespR getTradeList(@RequestBody TradeRequestVo tradeRequestVo){
        if(tradeRequestVo.getTradeStatus() ==null){
            tradeRequestVo.setTradeStatus(1);
            RespR<List<CardTradeModel>> respRbefore = selfCarService.getTradeList(tradeRequestVo);
            tradeRequestVo.setTradeStatus(2);
            RespR<List<CardTradeModel>> respRUnder = selfCarService.getTradeList(tradeRequestVo);
            tradeRequestVo.setTradeStatus(3);
            RespR<List<CardTradeModel>> respRAfter = selfCarService.getTradeList(tradeRequestVo);
            //合并展示
            List<CardTradeModel> cardTradeModels = new ArrayList<>();
            if(respRbefore.getCode() == 0){
                cardTradeModels.addAll(respRbefore.getData());
            }
            if(respRUnder.getCode() == 0){
                cardTradeModels.addAll(respRUnder.getData());
            }
            if(respRAfter.getCode() == 0){
                cardTradeModels.addAll(respRAfter.getData());
            }
            return new RespR(cardTradeModels);
        }
        //合并展示

        return selfCarService.getTradeList(tradeRequestVo);
    }

    /**
     * @param invoiceApplVo
     * @return
     */
    @PostMapping("/applInvoice")
    @ApiOperation(value="开票申请", notes="开票申请")
    public RespR applInvoice(@RequestBody InvoiceApplVo invoiceApplVo){
        return selfCarService.applInvoice(invoiceApplVo);
    }

    /**
     * @param selfCarDueQueryVo
     * @return
     */
    @PostMapping("/getSelfCarInvoicesByTime")
    @ApiOperation(value="已开发票查询", notes="已开发票查询")
    public RespR getSelfCarInvoicesByTime(@RequestBody SelfCarDueQueryVo selfCarDueQueryVo){
        return selfCarService.getSelfCarInvoicesByTime(selfCarDueQueryVo,null);
    }
    /**
     * @param invoicePackageVo
     * @return
     */
    @PostMapping("/getSelfCarInvoicePackage")
    @ApiOperation(value="发票打包下载", notes="发票打包下载")
    public RespR getSelfCarInvoicePackage(@RequestBody InvoicePackageVo invoicePackageVo){
        return selfCarService.getInvoicePackge(invoicePackageVo);
    }
    /**
     * @param ApplQueryInvVo
     * @return
     */
    @PostMapping("/getSelfCarInvoicesByAppl")
    @ApiOperation(value="按申请id查询发票", notes="按申请id查询发票")
    public RespR getSelfCarInvoicesByAppl(@RequestBody ApplQueryInvVo ApplQueryInvVo){
        return selfCarService.getSelfCarInvoicesByApplyIds(ApplQueryInvVo);
    }
    /**
     * @param etcQueryVo
     * @return
     */
    @PostMapping("/customerETCQuery")
    @ApiOperation(value="", notes="ETC绑定列表查询")
    public RespR customerETCQuery(@RequestBody EtcQueryVo etcQueryVo){
        return selfCarService.getEtcInfo(etcQueryVo);
    }



    /**
     * @param etcBindVo
     * @return
     */
    @PostMapping("/queryEtcInfo")
    @ApiOperation(value="", notes="备案ETC查询")
    public RespR customerQueryEtcInfo(@RequestBody EtcBindVo etcBindVo){
        return selfCarService.queryEtcInfo(etcBindVo);
    }

    /**
     * @param etcBindVo
     * @return
     */
    @PostMapping("/customerETCRec")
    @ApiOperation(value="", notes="ETC备案")
    public RespR customerETCRec(@RequestBody EtcBindVo etcBindVo){
        return selfCarService.customerEtcRec(etcBindVo);
    }


    /**
     * @param etcValidVo
     * @return
     */
    @PostMapping("/customerETCRecValid")
    @ApiOperation(value="", notes="ETC备案验证")
    public RespR customerETCRecValid(@RequestBody EtcValidVo etcValidVo){
        return selfCarService.customerEtcRecValid(etcValidVo);
    }

    /**
     * @param customerCarRecs
     * @return
     */
    @PostMapping("/customerCarUnRec")
    @ApiOperation(value="", notes="etc解绑")
    public RespR customerCarUnRec(@RequestBody List<CustomerCarRec> customerCarRecs){
        return selfCarService.customerCarUnRec(customerCarRecs);
    }
}
