package com.malk.service.dingtalk.impl;

import com.malk.server.dingtalk.DDConf;
import com.malk.server.dingtalk.DDR;
import com.malk.service.dingtalk.DDClient_Personnel;
import com.malk.utils.UtilList;
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_Personnel implements DDClient_Personnel {

    /**
     * 获取花名册元数据
     */
    @Override
    public List<Map> getPersonnelMeta(String access_token, Number agentid) {
        return (List<Map>) DDR.doPost("https://oapi.dingtalk.com/topapi/smartwork/hrm/roster/meta/get", null, DDConf.initTokenParams(access_token), UtilMap.map("agentid", agentid)).getResult();
    }

    /**
     * 获取员工花名册字段信息
     *
     * @apiNote https://open.dingtalk.com/document/orgapp/intelligent-personnel-obtain-employee-roster-information
     */
    @Override
    public List<Map> getEmployeeInfos(String access_token, List<String> userIds, Number agentId, List<String> field_filter_list) {
        Map bodys = UtilMap.map("userid_list, agentid", String.join(",", userIds), agentId);
        if (UtilList.isNotEmpty(field_filter_list)) {
            bodys.put("field_filter_list", String.join(",", field_filter_list));
        }
        return (List<Map>) DDR.doPost("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/list", null, DDConf.initTokenParams(access_token), bodys).getResult();
    }
}
