package com.hzya.frame.plugin.lets.plugin.base;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.hzya.frame.WebappApplication;
import com.hzya.frame.plugin.lets.constant.ProfilesActiveConstant;
import com.hzya.frame.plugin.lets.entity.BdCubasdocEntity;
import com.hzya.frame.plugin.lets.ofs.entity.ShopEntity;
import com.hzya.frame.plugin.lets.ofs.entity.SupplierEntity;
import com.hzya.frame.plugin.lets.queryvo.CustdocRequestVo;
import com.hzya.frame.plugin.lets.resultvo.ShopReturnMessageDto;
import com.hzya.frame.plugin.lets.u8cdto.CustdocEntityDto;
import com.hzya.frame.plugin.lets.util.PushDataByU8cUtil;
import com.hzya.frame.ttxofs.basics.ReturnMessageBasics;
import com.hzya.frame.ttxofs.dto.InterfaceParamByU8CApiDto;
import com.hzya.frame.ttxofs.dto.InterfaceParamDto;
import com.hzya.frame.ttxofs.dto.ofsBaseSearch.OfsShopDto;
import com.hzya.frame.ttxofs.dto.ofsBaseSearch.OfsShopReturnMessageDto;
import com.hzya.frame.ttxofs.dto.ofsBaseSearch.OfsSupplierDto;
import com.hzya.frame.ttxofs.dto.ofsBaseSearch.OfsSupplierReturnMessageDto;
import com.hzya.frame.ttxofs.service.OfsUnifiedService;
import org.checkerframework.checker.units.qual.C;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author
 * @Date 2024/8/8 9:09
 * @PackageName:com.hzya.frame.plugin.lets.plugin.base
 * @ClassName: ShopTest
 * @Description:
 */

@RunWith(SpringRunner.class)
@SpringBootTest(classes = WebappApplication.class)
public class ShopTest {

    @Autowired
    private ShopPluginInitializer shopPluginInitializer;
    @Autowired
    private SupplierPluginInitializer supplierPluginInitializer;
    @Autowired
    private OfsUnifiedService ofsUnifiedService;
    @Autowired
    private PushDataByU8cUtil pushDataByU8cUtil;

    @Autowired
    private CustdocAutoAllotPluginInitializer custdocAutoAllotPluginInitializer;


    @Test
    public void t00() {
//        shopPluginInitializer.startImplement();
//        supplierPluginInitializer.startImplement();
//
//        OfsShopDto shopEntity = new OfsShopDto();
////        shopEntity.setLastUpdated_start("2021-08-01 00:00:00");
//        shopEntity.setPageNo("1");
//        shopEntity.setClientCode("LETS");
////        Date currentDate = new Date();
////        Date startTime = DateUtil.offset(currentDate, DateField.MINUTE, -10);
////        Date endTime = DateUtil.offset(currentDate, DateField.MINUTE, -2);
////        String startTimeStr = DateUtil.format(startTime, "yyyy-MM-dd HH:mm:ss");
////        String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:ss");
////        shopEntity.setLastUpdated_start("2024-03-10 16:06:57");
////        shopEntity.setLastUpdated_end("2024-03-12 16:06:57");
////        shopEntity.setBizCode("hzz");
//        InterfaceParamByU8CApiDto interfaceParamDto = new InterfaceParamByU8CApiDto();
//        interfaceParamDto.setApi("ofs.store.search");
//        interfaceParamDto.setData(JSON.toJSONString(shopEntity));
//        OfsShopReturnMessageDto unified = null;
//        try {
//            unified = (OfsShopReturnMessageDto) ofsUnifiedService.unifiedByU8CApi(interfaceParamDto);
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//        List<OfsShopDto> data = unified.getData();
//        System.out.println("data = " + data);



//            SupplierEntity supplierEntity = new SupplierEntity();
//            supplierEntity.setPageNo("1");
//            supplierEntity.setClientCode("LETS");
//            InterfaceParamByU8CApiDto interfaceParamDto = new InterfaceParamByU8CApiDto();
//            interfaceParamDto.setApi("ofs.store.search");
//            interfaceParamDto.setData(JSON.toJSONString(supplierEntity));



//
//            System.out.println(unified);
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//

////

//        try {
//            System.out.println("开始推送");
//            //分配给所有公司
//            CustDocAssginVo custDocAssginVo = new CustDocAssginVo();
//            custDocAssginVo.setAssignallcorps("Y");
//            //客户基本档案主键
//            custDocAssginVo.setPk_cubasdoc("0001A210000000000PNV");
//            //公司主键
//            custDocAssginVo.setCustprop("2");
//            HashMap<String, Object> assginHashMap = new HashMap<>();
//            assginHashMap.put("custbasvo", custDocAssginVo);
//            String assginjsonString = JSONObject.toJSONString(assginHashMap);
//            String assignresponse = null;
//            assignresponse = pushDataByU8cUtil.pushU8CByCode(OverallConstant.getOverAllValue("custdocAssign"), assginjsonString);
//            CbdocResultVo cbdocResultVo1 = JSONObject.parseObject(assignresponse, CbdocResultVo.class);
//            System.out.println("cbdocResultVo1 = " + cbdocResultVo1);
//            //{"custbasvo":[{"custprop":"2","pk_cubasdoc":"CU785@@@000001","assignallcorps":"Y"}]}
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }


//        //生成客商管理档案
//        CustdocEntityDto parentvo = new CustdocEntityDto();
//        parentvo.setCustname("12测试客商管理档112213z案");
//        parentvo.setCustshortname("12测试客商管理档131121z案");
//        parentvo.setCustcode("test1324121ac1");
//        //地区名称：丽知商城客商？
////        parentvo.setPk_areacl("F");
//        parentvo.setPk_corp("0001");
//        CustdocRequestVo custdocRequestVo = new CustdocRequestVo();
//        custdocRequestVo.setParentvo(parentvo);
//        ArrayList<CustdocRequestVo> list = new ArrayList<>();
//        list.add(custdocRequestVo);
//        custmandocPluginInitializer.implement(list);

//        custdocAutoAllotPluginInitializer.start();

        shopPluginInitializer.startImplement("test11123");
//        supplierPluginInitializer.startImplement("test1234");
//
//                OfsShopDto shopEntity = new OfsShopDto();
////        shopEntity.setLastUpdated_start("2021-08-01 00:00:00");
//        shopEntity.setPageNo("1");
//        shopEntity.setPageSize("500");
//        shopEntity.setClientCode("LETS");
//        shopEntity.setBizCode("test1234");
////        Date currentDate = new Date();
////        Date startTime = DateUtil.offset(currentDate, DateField.MINUTE, -10);
////        Date endTime = DateUtil.offset(currentDate, DateField.MINUTE, -2);
////        String startTimeStr = DateUtil.format(startTime, "yyyy-MM-dd HH:mm:ss");
////        String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:ss");
////        shopEntity.setLastUpdated_start("2024-03-10 16:06:57");
////        shopEntity.setLastUpdated_end("2024-03-12 16:06:57");
//        InterfaceParamByU8CApiDto interfaceParamDto = new InterfaceParamByU8CApiDto();
//        interfaceParamDto.setApi("ofs.store.search");
//        interfaceParamDto.setData(JSON.toJSONString(shopEntity));
//        OfsShopReturnMessageDto unified = null;
//        try {
//            unified = (OfsShopReturnMessageDto) ofsUnifiedService.unifiedByU8CApi(interfaceParamDto);
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//        List<OfsShopDto> data = unified.getData();
//        shopPluginInitializer.startImplement();

//        OfsSupplierDto shopEntity = new OfsSupplierDto();
////        shopEntity.setLastUpdated_start("2021-08-01 00:00:00");
//        shopEntity.setPageNo("1");
//        shopEntity.setClientCode("LETS");
////        shopEntity.setCompanyCode("LETS");
////        shopEntity.setBizCode("test1234");
//        InterfaceParamByU8CApiDto interfaceParamDto = new InterfaceParamByU8CApiDto();
//        interfaceParamDto.setApi("ofs.vendor.search");
//        interfaceParamDto.setData(JSON.toJSONString(shopEntity));
//        OfsSupplierReturnMessageDto unified = null;
//        try {
//            unified = (OfsSupplierReturnMessageDto) ofsUnifiedService.unifiedByU8CApi(interfaceParamDto);
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//        List<OfsSupplierDto> data = unified.getData();
//
//        supplierPluginInitializer.implement(data);

    }
}
