package com.xhpc.tradebill.controller;


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.tradebill.domain.XhpcTradebillPaymentCheckRecordDomain;
import com.xhpc.tradebill.service.PaymentBillService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/payment")
public class PaymentBillController extends BaseController {

    @Resource
    PaymentBillService paymentBillService;


    @GetMapping("/checkList/{uploadId}")
    public AjaxResult getCheckList(@RequestParam(required = false) Integer uploadId,
                                   @RequestParam(required = false) String orderNumber,
                                   @RequestParam(required = false) String userId,
                                   @RequestParam(required = false) Integer status){
        Map<String, Object> params = new HashMap<>();
        params.put("uploadId", uploadId);
        params.put("orderNumber",orderNumber);
        params.put("userId", userId);
        params.put("status", status);
        return AjaxResult.success(paymentBillService.getPaymentCheckList(params));
    }


    @GetMapping("/checkPage")
    public TableDataInfo getCheckPage(@RequestParam(required = false) Integer uploadId,
                                      @RequestParam(required = false) String orderNumber,
                                      @RequestParam(required = false) String userId,
                                      @RequestParam(required = false) Integer status){

        startPage();
        Map<String, Object> params = new HashMap<>();
        params.put("uploadId", uploadId);
        params.put("orderNumber",orderNumber);
        params.put("userId", userId);
        params.put("status", status);
        return getDataTable(paymentBillService.getPaymentCheckList(params));
    }


    @GetMapping("/statusTotal")
    public AjaxResult getStatusTotal(@RequestParam(required = false) Integer uploadId,
                                     @RequestParam(required = false) String orderNumber,
                                     @RequestParam(required = false) String userId,
                                     @RequestParam(required = false) Integer status){

        Map<String, Object> params = new HashMap<>();
        params.put("uploadId", uploadId);
        params.put("orderNumber",orderNumber);
        params.put("userId", userId);
        params.put("status", status);
        return AjaxResult.success(paymentBillService.getStatusTotal(params));
    }


    @GetMapping("/checkInfo/{id}")
    public AjaxResult getCheckInfo(@PathVariable Integer id){

        return AjaxResult.success(paymentBillService.getInfoByPk(id));
    }


    @Log(title = "人工确认支付平台对账数据", businessType = BusinessType.UPDATE)
    @PostMapping("/checkInfo")
    public AjaxResult updateCheckInfo(@RequestBody XhpcTradebillPaymentCheckRecordDomain domain){
        return AjaxResult.success(paymentBillService.updateInfoByDomain(domain));
    }


    @Log(title = "导出支付平台对账数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,
                       @RequestParam(required = false) Integer uploadId,
                       @RequestParam(required = false) String orderNumber,
                       @RequestParam(required = false) String userId,
                       @RequestParam(required = false) Integer status) throws Exception {

        Map<String, Object> params = new HashMap<>();
        params.put("uploadId", uploadId);
        params.put("orderNumber",orderNumber);
        params.put("userId", userId);
        params.put("status", status);

        paymentBillService.export(response, params);
    }

}
