package com.malk.huagao.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.malk.huagao.service.IKdYdCustomerService;
import com.malk.huagao.service.IKdYdZpService;
import com.malk.huagao.service.YdHuaGaoService;
import com.malk.server.aliwork.YDConf;
import com.malk.server.aliwork.YDParam;
import com.malk.server.common.McR;
import com.malk.server.dingtalk.DDR_New;
import com.malk.service.aliwork.YDClient;
import com.malk.service.dingtalk.DDClient;
import com.malk.service.dingtalk.DDClient_Contacts;
import com.malk.service.dingtalk.DDClient_Workflow;
import com.malk.utils.UtilMap;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LQY
 * @since 2025-10-09
 */
@RestController
@RequestMapping("/hg")
public class KdYdCustomerController {
    @Autowired
    private IKdYdCustomerService  kdYdCustomerService;
    @Autowired
    private YdHuaGaoService ydHuaGaoService;
    @Autowired
    private IKdYdZpService kdYdZpService;
    @Autowired
    private DDClient_Contacts ddClient_contacts;
    @Autowired
    private DDClient ddClient;
@Autowired
private YDClient ydClient;
    @PostMapping("/test30")
    McR test13(@RequestBody Map data) {
        MDC.put("MDC_KEY_PID","1003");
//        Map userInfoByMobile1 = ddClient_contacts.getUserInfoById(ddClient.getAccessToken(), "yzsyzid2");
//        if (userInfoByMobile1 != null && userInfoByMobile1.containsKey("mobile")) {
//            mobile = String.valueOf(userInfoByMobile1.get("mobile"));
//        }
//        String ins = String.valueOf(data.get("formInstId"));
//
//
//        DDR_New ddrNew = ydClient.queryData(YDParam.builder()
//                .formUuid("FORM-E64114E9F2C9426E91F92886EDFFA2C08Q90")
//                .build(), YDConf.FORM_QUERY.retrieve_search_form_id);
//
//        System.out.println(ddrNew.getTotalCount());
//
//        ydClient.operateData(YDParam.builder()
//                .formUuid("FORM-E64114E9F2C9426E91F92886EDFFA2C08Q90")
//                .asynchronousExecution(true)
//                .formInstanceIdList((List<String>) ddrNew.getData())
//                .build(), YDConf.FORM_OPERATION.delete_batch);

//        DDR_New ddrNew = ydClient.queryData(YDParam.builder()
//                .formInstId("FINST-DZ966471VB228QLYJ6WXG6I7YGV631VYLW0KMBQE")
//                .build(), YDConf.FORM_QUERY.retrieve_id);
////
////        if (ddrNew == null || ddrNew.getFormData() == null) {
////            throw new RuntimeException("未找到订单信息");
////        }
////
//        Map formData1 = ddrNew.getFormData();
//        System.out.println("======"+formData1);

//        String ddje = UtilMap.getString(formData1, "numberField_mjm9k35k");
//        String dddate = UtilMap.getString(formData1, "dateField_mjm9k35j");
//
//        System.out.println(dddate);
//        System.out.println(ddje);
//        ydClient.operateData(YDParam.builder()
//                .formInstanceId(ins)
//      .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("numberField_mhirg0kz","156")))//xz04
////                .updateFormDataJson(JSONObject.toJSONString(UtilMap.map(employ,id)))//xz04
//                .useLatestVersion(true)
//                .build(), YDConf.FORM_OPERATION.update);
//        ydHuaGaoService.synckdYdMaterial();
//        ydHuaGaoService.synckdYdPayment();
//        ydHuaGaoService.synckdYdTRANSFER();
//        ydHuaGaoService.syncKdYdReceivable();
//        kdYdZpService.insertkdYdZp(data);
//        ydHuaGaoService.synckdYdOutbound();
        return McR.success();
    }
    @PostMapping("/kdYdCustomer")
    Map<String, Object> insertCustomer(@RequestBody Map map) {
        Map<String, Object> stringObjectMap = kdYdCustomerService.insertCustomer(map);
        return stringObjectMap;
    }
}
