package com.malk.laidi.controller;

import com.alibaba.fastjson.JSON;
import com.malk.laidi.service.LDClient;
import com.malk.server.common.McR;
import com.malk.utils.UtilMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 错误抛出与拦截详见 CatchException
 */
@Slf4j
@RestController
@RequestMapping()
public class LDController {


    @Autowired
    private LDClient ldClient;

    /**
     * 同步OA出差单到氚云
     */
    @PostMapping("sync-cc")
    McR syncCC(@RequestBody Map data) {
//        String processInstanceId = "KGkpcf8qRUe26Y4Vh7ICxQ08031691566909"; //
//        String processInstanceId = "ckDghK5NSHuLYBVammK4Cg08031694687962";
        ldClient.syncCC(String.valueOf(data.get("processInstanceId")));
        return McR.success();
    }

    /**
     * 同步氚云附件到钉盘 [异步]
     */
    @PostMapping("h3yun-http")
    McR http(@RequestBody Map<String, String> data, @RequestParam String code) {
        log.info("氚云http请求, code = {}, body = {}", code, JSON.toJSONString(data));
        ldClient.syncDP(String.valueOf(data.get("attachments")), String.valueOf(data.get("projectName")), String.valueOf(data.get("typeName")));
        return McR.success(UtilMap.map("status", "是"));
    }

    /**
     * 获取钉盘&文件夹信息, spaceId, parentId [可手动创建]
     */
    @PostMapping("test")
    McR test(HttpServletRequest request) {
        ldClient.test();
        return McR.success();
    }
}
