package com.sifang.modules.q7link.controller;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.q7link.openapi.model.*;
import com.sifang.modules.flowpath.dao.TraderApplyDao;
import com.sifang.modules.flowpath.entity.TraderApply;
import com.sifang.modules.q7link.entity.CrmSupplyMaterialProjectPrice;
import com.sifang.modules.sys.common.utils.IdGen;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import static com.sifang.modules.q7link.utils.Q7linkUtils.getSdkRequestConfig;
import static com.sifang.modules.q7link.utils.Q7linkUtils.openapi;

@Controller
@RequestMapping(value = "${adminPath}/sysDate")
public class QsyDateController {





    @Test
    public void queryXMJG() {
        System.out.print("开始进入项目价格成本查询");
        PostListRequest request = new PostListRequest();
        ApiParams apiParams = new ApiParams();
        apiParams.setJson("{\n" +
                "  \"objectType\":\"Vendor\",\n" +
                "  \"fields\": [\n" +
                "        \"code\",\n" +   //编码
                "        \"name\",\n" +   //名称
                "        \"srcObjectType\",\n" + //数据来源类型
                "        \"address\",\n" +   //地址
                "        \"telephone\",\n" +  //电话
                "        \"firstDealTime\",\n" +  //发展日期
                "        \"disabledTime\",\n" +  //停用日期
                "    {\n" +  //开户银行
                "      \"fieldName\": \"defaultBankAccount\",\n" +
                "      \"fields\": [\n" +
                "        \"code\",\n" +  //银行编码
                "        \"name\",\n" +  //银行名称
                "        \"accountCode\"\n" +  //银行账号
                "      ]\n" +
                "    },\n" +
                "    {\n" +  //默认地
                "      \"fieldName\": \"addressFk\",\n" +
                "      \"fields\": [\n" +
                "        \"name\",\n" +  //地址名称
                "        \"address\",\n" +  //详细地址
                "        \"contactId\"\n" +  //	联系人
                "      ]\n" +
                "    },\n" +
                "        \"currencyId\"\n" +   //	交易币种

                "  ]\n" +
                "}");
        request.sdkRequestConfig(getSdkRequestConfig(request));
        request.setApiParams(apiParams);
        PostListResult postListResult = openapi().postList(request);
        ApiResponse apiResponse = postListResult.getApiResponse();
        Map map=(Map) JSONObject.parseObject(apiResponse.getJson());
        if(map.containsKey("data")){
            if(map.get("data") != null){
                Map map1 = (Map) JSONObject.parseObject(String.valueOf(map.get("data")));
                if(map1.get("list") != null){
                    List<Map> list = JSONObject.parseArray(String.valueOf(map1.get("list")), Map.class);
                    if(CollectionUtil.isNotEmpty(list)){
                        for(Map map2:list){
                            String code=""; //编码
                            if(map2.containsKey("code")){
                                code=String.valueOf(map2.get("code"));
                            }

                            String address=""; //地址
                            if(map2.containsKey("address")){
                                address=String.valueOf(map2.get("code"));
                            }

                            String firstDealTime=""; //发展日期
                            if(map2.containsKey("firstDealTime")){
                                firstDealTime=String.valueOf(DateUtil.date(Long.valueOf(String.valueOf(map2.get("firstDealTime")))));
                            }

                            String name=""; //代理商名称
                            if(map2.containsKey("name")){
                                name=String.valueOf(map2.get("name"));
                            }

                            String telephone=""; //代理商联系电话
                            if(map2.containsKey("telephone")){
                                telephone=String.valueOf(map2.get("telephone"));
                            }
                            String accountCode="";//银行账号
                            if(map2.containsKey("defaultBankAccount")){
                                Map deMap=(Map)map2.get("defaultBankAccount");
                                if(deMap != null && deMap.containsKey("accountCode")){
                                    accountCode=String.valueOf(deMap.get("accountCode"));
                                }
                            }
                            String addressFk="";//默认地址
                            if(map2.containsKey("addressFk")){
                                Map deMap=(Map)map2.get("addressFk");
                                if(deMap != null && deMap.containsKey("address")){
                                    addressFk=String.valueOf(deMap.get("address"));
                                }
                            }

                            System.out.println("测试数据----"+map2.toString());
                            System.out.println("测试数据----"+map2.toString());

                        }
                    }
                }

            }
        }


    }

    public static void main(String[] args) {
        System.out.println(DateUtil.date(1672502400000L));
    }
}
