package com.malk.service.dingtalk.impl;

import cn.hutool.core.util.ObjectUtil;
import com.malk.server.dingtalk.DDConf;
import com.malk.server.dingtalk.DDR;
import com.malk.service.dingtalk.DDClient_Report;
import com.malk.utils.UtilMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class DDImplClient_Report implements DDClient_Report {

    /**
     * 获取用户发出的日志列表
     *
     * @apiNote https://open.dingtalk.com/document/orgapp/query-logs-sent-by-an-employee
     */
    @Override
    public List<Map> reportList(String access_token, long start_time, long end_time, Map extInfo) {
        Map body = UtilMap.map("start_time, end_time, size", start_time, end_time, 20);
        if (ObjectUtil.isNotNull(extInfo)) {
            body.putAll(extInfo);
        }
        if (!body.containsKey("cursor")) {
            body.put("cursor", 0);
        }
        Map result = (Map) DDR.doPost("https://oapi.dingtalk.com/topapi/report/list", null, DDConf.initTokenParams(access_token), body).getResult();
        return (List<Map>) result.get("data_list");
    }
}
