import com.alibaba.fastjson.JSON;
import com.gic.commons.util.DateUtil;
import com.gic.haoban.manage.api.dto.content.log.TriggerCustomerDetailLogDTO;
import com.gic.haoban.manage.api.enums.content.ClerkShareMaterialType;
import com.gic.haoban.manage.api.enums.content.ShareBizType;
import com.gic.haoban.manage.api.enums.content.TriggerCustomerChannelType;
import com.gic.haoban.manage.api.service.content.task.QywxGroupMsgTaskApiService;
import com.gic.haoban.manage.service.pojo.bo.content.ClerkShareLogBO;
import com.gic.haoban.manage.service.pojo.bo.content.GroupMessageInfoBo;
import com.gic.haoban.manage.service.service.content.ClerkShareLogService;
import com.gic.haoban.manage.service.service.content.GroupMessageService;
import com.squareup.moshi.Json;
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;

/**
 * @Author MUSI
 * @Date 2023/3/20 8:57 PM
 * @Description
 * @Version
 **/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class GroupMessageServiceTest {
    @Autowired
    private GroupMessageService groupMessageService;
    @Autowired
    private ClerkShareLogService clerkShareLogService;
    @Autowired
    private QywxGroupMsgTaskApiService qywxGroupMsgTaskApiService;
    String eid = "ff8080815dacd3a2015dacd3ef5c0000";

    String wxEid = "ca66a01b79474c40b3e7c7f93daf1a3b";

    @Test
    public void shareLogTest() {
        ClerkShareLogBO clerkShareLogBO = new ClerkShareLogBO();
        clerkShareLogBO.setEnterpriseId(eid);
        clerkShareLogBO.setWxEnterpriseId(wxEid);
        clerkShareLogBO.setClerkId("fbc508e395f846ef9005852c420e1c4f");
        clerkShareLogBO.setStaffId("e608b51b267e4943b87e222a343b4f25");
        clerkShareLogBO.setShareType(ClerkShareMaterialType.SHARE_PYQ.getCode());
        clerkShareLogBO.setBizId(eid);
        clerkShareLogBO.setBizType(ShareBizType.MATERIAL.getCode());
        clerkShareLogService.saveClerkShareLog(clerkShareLogBO);
    }

    @Test
    public void shareWithPyq() {
        TriggerCustomerDetailLogDTO customerDetailLog = new TriggerCustomerDetailLogDTO();
        customerDetailLog.setEnterpriseId(eid);
        customerDetailLog.setShareType(TriggerCustomerChannelType.PYQ.getCode());
        TriggerCustomerDetailLogDTO.SharePYQ sharePYQ = new TriggerCustomerDetailLogDTO.SharePYQ();
        sharePYQ.setShareLogId(511216759709786113L);
        customerDetailLog.setSharePYQ(sharePYQ);
        qywxGroupMsgTaskApiService.handlerTriggerCustomerDetailLog(JSON.toJSONString(customerDetailLog));
    }

    @Test
    public void groupMessageTest() {
        Date currentTime = new Date();
        GroupMessageInfoBo groupMessageInfoBo = new GroupMessageInfoBo();
        groupMessageInfoBo.setEnterpriseId(eid);
        groupMessageInfoBo.setStartTime(DateUtil.addNumForMinute(currentTime, -100));
        groupMessageInfoBo.setEndTime(currentTime);
        groupMessageService.handlerGroupMessage(groupMessageInfoBo);
    }
}
