import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.content.PotentialCustomerDTO;
import com.gic.haoban.manage.api.dto.qdto.content.PotentialCustomerQDTO;
import com.gic.haoban.manage.api.service.content.MallOrderStatusChangeApiService;
import com.gic.haoban.manage.api.service.content.PotentialCustomerApiService;
import com.gic.haoban.manage.service.pojo.bo.content.OrderEventMqBO;
import com.gic.haoban.manage.service.pojo.bo.content.message.InteractRecordMessageBO;
import com.gic.haoban.manage.service.service.content.PotentialCustomerService;
import com.gic.haoban.manage.service.service.content.message.InteractRecordMessageService;
import com.gic.haoban.manage.service.service.out.impl.content.MallOrderStatusChangeApiServiceImpl;
import com.sun.org.apache.bcel.internal.generic.DADD;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.UUID;

/**
 * @Author MUSI
 * @Date 2023/4/6 10:13 AM
 * @Description
 * @Version
 **/

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class InteractRecordMessageServiceTest {

    @Autowired
    InteractRecordMessageService interactRecordMessageService;
    @Autowired
    MallOrderStatusChangeApiService mallOrderStatusChangeApiService;
    @Autowired
    private PotentialCustomerApiService potentialCustomerApiService;

    String eid = "ff8080815dacd3a2015dacd3ef5c0000";
    String wxEid = "ca66a01b79474c40b3e7c7f93daf1a3b";
    String staffId = "e608b51b267e4943b87e222a343b4f25";
    String clerkId = "300b60c7f8874ca2b9cc696ad6b6a480";
    //String memberId = "ff8080818147efc8018148d1759903c8";
    String memberId = "ff80808187210d2b018721e9cc6c0036";

    String materialId = "510923843246776342";

    @Test
    public void dealRecord() {
        String runningUUid = UUID.randomUUID().toString();
        InteractRecordMessageBO interactRecordMessageBO = new InteractRecordMessageBO();
        interactRecordMessageBO.setEnterpriseId(eid);
        interactRecordMessageBO.setMaterialId(materialId);
        interactRecordMessageBO.setMemberId(memberId);
        interactRecordMessageBO.setUnionId(memberId);
        interactRecordMessageBO.setClerkId(clerkId);
        interactRecordMessageBO.setStoreId("ff8080816e216c04016e34294282004a");
        interactRecordMessageBO.setChannelSource(1);
        interactRecordMessageBO.setEventType(1);
        interactRecordMessageBO.setDurationTime(3200);
        interactRecordMessageBO.setGoodsId(runningUUid);
        interactRecordMessageBO.setLastAccessTime(new Date().getTime());
        interactRecordMessageService.dealRecord(interactRecordMessageBO);
    }


    @Test
    public void mallOrderStatusChangeTest(){
        String params  ="{\"orderNumber\":\"6230408781099580\",\"toStatus\":2,\"fromStatus\":1,\"orderId\":\"c08691af8297480db3d25ef5ef19e863\",\"enterpriseId\":\"ff8080815dacd3a2015dacd3ef5c0000\",\"mqTraceId\":\"244806167-1-1680932807.425-/gic-thirdparty/wxmall_payment_result_notice\",\"memberId\":\"ff8080818147efc8018148d1759903c8\"}";
        mallOrderStatusChangeApiService.mallOrderStatusChange(params);
    }

    @Test
    public void dealGoodsRecord(){
        String json = "{\"businessUUId\":\"IcB5ZMEvmzir1uvjgc6ohJFMmexraBak\",\"durationTime\":21990,\"enterpriseId\":\"ff8080815dacd3a2015dacd3ef5c0000\",\"eventType\":2,\"goodsId\":\"ff808081890a1b4201890a54b479001d\",\"lastAccessTime\":1692580759467,\"memberId\":\"ff80808189fd5ba6018a01ea3e070673\",\"refUrl\":\"pages/authorize/authorize\",\"unionId\":\"orXl9tyHOI4qP1QxwVcA7A3sB7zg\"}";
        InteractRecordMessageBO interactRecordMessageBO = JSONObject.parseObject(json, InteractRecordMessageBO.class);
        interactRecordMessageBO.setChannelSource(3);
        interactRecordMessageBO.setClerkId("415b123576674913b365005b81037551");
        interactRecordMessageService.dealRecord(interactRecordMessageBO);
    }

    @Test
    public void queryPotentialCustomer() {

        PotentialCustomerQDTO potentialCustomerQDTO = new PotentialCustomerQDTO();
        potentialCustomerQDTO.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
        potentialCustomerQDTO.setClerkId("415b123576674913b365005b81037551");
        potentialCustomerQDTO.setWxEnterpriseId("ca66a01b79474c40b3e7c7f93daf1a3b");
        ServiceResponse<Page<PotentialCustomerDTO>> pageServiceResponse = potentialCustomerApiService.queryPotentialCustomer(potentialCustomerQDTO);
        System.out.println(JSONObject.toJSONString(pageServiceResponse));
    }

    @Autowired
    private MallOrderStatusChangeApiServiceImpl mallOrderStatusChangeApiServiceImpl;

    @Test
    public void orderTest() {

        String json = "{\"orderNumber\":\"0230823781099580\",\"toStatus\":2,\"fromStatus\":1,\"orderId\":\"0a84ff17893046e49839fa3c3542bffa\",\"deliveryChannel\":1,\"eventTime\":1692794627733,\"enterpriseId\":\"8a809083802bbf5201804af08b0d0095\",\"businessType\":1,\"mqTraceId\":\"60157-1-1692794627.506-/gic-thirdparty/wxmall_payment_result_notice\",\"memberId\":\"8a808d838995476c0189b55f0ab807f7\"}";
        mallOrderStatusChangeApiServiceImpl.sendDelayMessage(JSONObject.parseObject(json, OrderEventMqBO.class));
    }
}
