package com.malk.kuaikeli.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.malk.kuaikeli.entity.SupplierMaterial;
import com.malk.kuaikeli.listener.SupplierMaterialDataListener;
import com.malk.server.aliwork.YDConf;
import com.malk.server.aliwork.YDParam;
import com.malk.server.common.McR;
import com.malk.service.aliwork.YDClient;
import com.malk.service.aliwork.YDService;
import com.malk.service.dingtalk.DDClient;
import com.malk.utils.UtilMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

@RestController
@RequestMapping("/test")
public class CdTestController {

    @Autowired
    private DDClient ddClient;
    @Autowired
    private YDClient ydClient;
    @Value("${server.port}")
    private String port;

    @GetMapping("/hello")
    public McR hello(){
        return McR.success("Hello "+ port);
    }

    @GetMapping("/dd")
    public McR dd(){
        return McR.success(ddClient.getAccessToken());
    }

    @PostMapping("/upload")
    public McR upload(MultipartFile file) throws IOException {
        System.out.println("2222222222222222");

        return McR.success();
    }

    @PostMapping("/test")
    public McR test(@RequestBody Map param){
        // FINST-J7666B91556KOPSCBKY425M8C73I3GCT10VULEQ1
        String id= UtilMap.getString(param,"id");
        Object obj= ydClient.queryData(YDParam.builder().searchCondition(
                JSONObject.toJSONString(UtilMap.map("textField_llkb7kd2",""))).build(), YDConf.FORM_QUERY.retrieve_id).getData();

        return McR.success();
    }
}
