package cn.pluss.platform.controller;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.channel.MerchantAuditService;
import cn.pluss.platform.export.BillStatisticsService;
import cn.pluss.platform.mapper.MerchantRateMapper;
import cn.pluss.platform.user.impl.GeneralPushUtil;
import cn.pluss.platform.util.excel.ComplexExcelUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author Djh
 */
@Slf4j
//@RestController
@RequestMapping("test")
public class TestController {

    @Autowired
    private BillStatisticsService billStatisticsService;

    @Autowired
    private GeneralPushUtil generalPushUtil;

    @Autowired
    private MerchantRateMapper rateMapper;

    @Autowired
    private MerchantAuditService ysAuditService;

    @Autowired
    private MerchantAuditService ryxMerchantAuditService;

    @GetMapping("/export1/{merchantCode}")
    public void test1(@PathVariable("merchantCode") String merchantCode, HttpServletResponse response) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startDate = sdf.parse("2021-04-01 00:00:00");
        Date endDate = sdf.parse("2021-04-30 23:59:59");

        XSSFWorkbook workBook = billStatisticsService.createBillStatisticsSheet(null, merchantCode, startDate, endDate);
        workBook = billStatisticsService.createBillListSheet(workBook, merchantCode, startDate, endDate);
        workBook = billStatisticsService.createMemberBillStatisticsSheet(workBook, merchantCode, startDate, endDate);
        workBook = billStatisticsService.createMemberBillListSheet(workBook, merchantCode, startDate, endDate);
        workBook = billStatisticsService.createStaffBillStatisticsSheet(workBook, merchantCode, startDate, endDate);

        ComplexExcelUtil.setResponseHeader(response, "测试");
        ServletOutputStream out = response.getOutputStream();
        workBook.write(out);
    }

    @GetMapping("/ysAudit/{userId}")
    public Result<Object> test1(@PathVariable("userId") String userId) {
        ysAuditService.merchantAudit(userId, false);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/ryxResult/{orderId}")
    @ResponseBody
    public Object test3(@PathVariable("orderId") String orderId) throws Exception {
        Map<String, Object> param = new HashMap<>();
        param.put("orderId", orderId);
//        param.put("accessMerchId", "b6048439-504d-4be7-88f1-beae06391588");
        JSONObject jsonObject = ryxMerchantAuditService.merchantAuditResult(param);
        return jsonObject;
    }

    @GetMapping("/bb/czs")
    public Result<Object> test4() {
        List<String> alias = new ArrayList<>();
        alias.add("7714");
        generalPushUtil.sendAllPlatByUserIdChargeWithCoupon(alias, new BigDecimal("20"), new BigDecimal("50"));
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/bb/cz")
    public Result<Object> test5() {
        List<String> alias = new ArrayList<>();
        alias.add("7714");
        generalPushUtil.sendAllPlatByUserIdChargeWithCoupon(alias, new BigDecimal("20"), new BigDecimal("50"));
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/bb/xff")
    public Result<Object> test6() {
        List<String> alias = new ArrayList<>();
        alias.add("7714");
        generalPushUtil.sendAllPlatByUserIdConsumeWithCoupon(alias, new BigDecimal("20.12"), new BigDecimal(5));

        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/bb/xf")
    public Result<Object> test7() {
        List<String> alias = new ArrayList<>();
        alias.add("7714");
        generalPushUtil.sendAllPlatByUserIdConsumeWithCoupon(alias, new BigDecimal("20"), new BigDecimal("50"));
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/bb/zfqx")
    public Result<Object> test8() {
        List<String> alias = new ArrayList<>();
        alias.add("7714");
        generalPushUtil.sendAllPlatByAlias(alias, "订单取消支付", "订单取消支付", "3");
        return ResultGenerator.genSuccessResult();
    }
}
