package com.malk.jinlun.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.kingdee.bos.webapi.entity.IdentifyInfo;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import com.malk.jinlun.config.KDWebApiConf;
import com.malk.jinlun.entity.BillQuery;
import com.malk.jinlun.service.JinlunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class JinlunServiceImpl implements JinlunService {
    @Autowired
    private KDWebApiConf kdWebApiConf;

    @Override
    public void test() throws Exception {
        K3CloudApi client = new K3CloudApi(initIden());

        List<Map> result = new ArrayList<>();
        List<Map> customerList = new ArrayList<>();

        int startRow = 0;
        int limit = 100;

        BillQuery billQuery = new BillQuery();
        billQuery.setFormId("BD_MATERIAL");
        billQuery.setFieldKeys("FNumber,FName");
        /*List<Map> filterString = new ArrayList<>();
        //修改时间为昨天到今天
        filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FModifyDate","265","1","","","0"));
//            filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FModifyDate","39","2025-03-06 00:00:00","","","0"));
        billQuery.setFilterString(filterString);*/
        billQuery.setLimit(limit);
        billQuery.setStartRow(startRow);

        String s = client.billQuery(JSONObject.toJSONString(billQuery));
        result = (List<Map>)JSONObject.parse(s);

        System.out.println("111");
    }

    private IdentifyInfo initIden(){
        //注意 1：此处不再使用参数形式传入用户名及密码等敏感信息，改为在登录配置文件中设置。
        //注意 2：必须先配置第三方系统登录授权信息后，再进行业务操作，详情参考各语言版本SDK介绍中的登录配置文件说明。
        //读取配置，初始化SDK
        IdentifyInfo iden = new IdentifyInfo();
        iden.setUserName(kdWebApiConf.getXKDApiUserName());
        iden.setAppId(kdWebApiConf.getXKDApiAppID());
        iden.setdCID(kdWebApiConf.getXKDApiAcctID());
        iden.setAppSecret(kdWebApiConf.getXKDApiAppSec());
        iden.setServerUrl(kdWebApiConf.getXKDApiServerUrl());

        return iden;
    }

}
