package com.malk.lilin.Controller;


import com.alibaba.fastjson.JSON;
import com.malk.lilin.Service.LiLinService;
import com.malk.server.common.McR;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
@Slf4j
@RequestMapping("/ll")
public class LiLinController {
    @Autowired
    private LiLinService liLinService;

    @GetMapping("/test")
    public McR test() {
        return McR.success();
    }

    @PostMapping("/lilinUpsert")
    public McR lilinUpsert(@RequestBody Map<String, Object> map) {
        if (Objects.nonNull(map.get("rqqj"))) {
            List<String> rqqj = (List<String>) map.get("rqqj");
            String bdbh = String.valueOf(map.get("ddbh"));
            return liLinService.lilinUpsert(rqqj, bdbh);

        }
        return McR.errorParam("实例id不能为空！");
    }

    @PostMapping("/lilinhqbank")//获取银行联行号
    public McR hqbank(@RequestBody Map<String, Object> map) throws IOException {
        log.info("lilinhqbank:{}", JSON.toJSONString(map));
        return liLinService.hqbank(map);
    }

    @PostMapping("/lilinZD")//付款制单
    public McR lilinZD(@RequestBody Map<String, Object> map) throws IOException {
        log.info("lilinZD:{}", JSON.toJSONString(map));
        return liLinService.lilinZD(map);

    }

    @PostMapping("/lilinJG")//支付结果查询
    public McR lilinJG(@RequestBody Map<String, Object> map) throws IOException {
        log.info("lilinJG:{}", JSON.toJSONString(map));
        return liLinService.lilinJG(map);

    }

    @PostMapping("/lilinLS")//查银行流水
    public McR lilinLS(@RequestBody Map<String, Object> map) throws IOException {
        log.info("lilinLS:{}", JSON.toJSONString(map));
        return liLinService.lilinLS(map);

    }

    @PostMapping("/lilinLSCF")//流水拆分
    public McR lilinLSCF(@RequestBody Map<String, Object> map) throws IOException {
        log.info("lilinLSCF:{}", JSON.toJSONString(map));
        return liLinService.lilinLSCF(map);

    }
//    @PostMapping("/lilinUpsert1")
//    public McR lilinUpsert1(@RequestBody Map<String,Object> map) {
//        if (Objects.nonNull(map.get("rqqj"))) {
//            // 获取当前日期，替换为当天的起止时间
//            LocalDate today = LocalDate.now();
//            LocalDateTime startOfDay = today.atStartOfDay();
//            LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
//
//            // 格式化为字符串，格式：yyyy-MM-dd HH:mm:ss
//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//
//            List<String> rqqj = Arrays.asList(
//                    startOfDay.format(formatter),
//                    endOfDay.format(formatter)
//            );
//
//            System.out.println("r===" + rqqj);
//
//            String bdbh = String.valueOf(map.get("bdbh"));
//            return liLinService.lilinUpsert(rqqj, bdbh);
//        }
//        if (Objects.nonNull(map.get("rqqj"))){
//            List<String> rqqj = (List<String>) map.get("rqqj");
//            System.out.println("r==="+rqqj);
////            String  bdbh = String.valueOf(map.get("ddbh"));
////            return liLinService.lilinUpsert(rqqj,bdbh);
//        }
//        return McR.errorParam("实例id不能为空！");
//    }
}
