import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.UniqueIdUtils;
import com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum;
import com.gic.haoban.manage.api.enums.content.MaterialReportType;
import com.gic.haoban.manage.api.service.content.task.QywxGroupMsgTaskApiService;
import com.gic.haoban.manage.api.util.notify.NoticeMessageUtil;
import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanInteractRecordMapper;
import com.gic.haoban.manage.service.entity.content.TabHaobanInteractRecord;
import com.gic.haoban.manage.service.service.content.MaterialReportService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

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

/**
 * @Author MUSI
 * @Date 2023/3/25 12:04 AM
 * @Description
 * @Version
 **/

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

    public MaterialReportServiceTest(){

    }
    @Autowired
    private MaterialReportService materialReportService;
    @Autowired
    private QywxGroupMsgTaskApiService qywxGroupMsgTaskApiService;
    @Autowired
    private TabHaobanInteractRecordMapper interactRecordMapper;

    String eid = "ff8080815dacd3a2015dacd3ef5c0000";
    String wxEid = "ca66a01b79474c40b3e7c7f93daf1a3b";
    String staffId = "e608b51b267e4943b87e222a343b4f25";

    @Test
    public void handlerMaterialWeekReportTest() {
        System.setProperty("gic.module.name", "haoban-manage3-service");
        materialReportService.handlerMaterialReport(eid, staffId, MaterialReportType.WEEK.getCode());
        materialReportService.handlerMaterialReport(eid, staffId, MaterialReportType.MONTH.getCode());
    }

    @Test
    public void weekReport(){
        qywxGroupMsgTaskApiService.handlerMaterialMonthReport("");
        qywxGroupMsgTaskApiService.handlerMaterialWeekReport("");
    }

    @Test
    public void shardingTest(){
        TabHaobanInteractRecord temp = new TabHaobanInteractRecord();
        temp.setId(UniqueIdUtils.uniqueLong());
        temp.setEnterpriseId(eid);
        temp.setClerkId(staffId);
        temp.setMemberId(staffId);
        temp.setUnionId(staffId);
        temp.setTraceId(staffId);
        temp.setBizType(1);
        temp.setStoreId(staffId);
        temp.setChannelSource(1);
        temp.setEventType(1);
        temp.setDurationTime(111);
        temp.setTimes(1);
        temp.setDeleteFlag(0);
        temp.setCreateTime(new Date());
        temp.setUpdateTime(new Date());
        temp.setBizId(UniqueIdUtils.uniqueLong()+"");
//        int insert = interactRecordMapper.insert(temp);
        List<TabHaobanInteractRecord> tabHaobanInteractRecords = interactRecordMapper.queryAllByLimit(temp);
        System.out.println(JSON.toJSONString(tabHaobanInteractRecords));
    }

    @Test
    public void urlTest(){
        JSONObject params = new JSONObject();
        //params.put("clerkId", "300b60c7f8874ca2b9cc696ad6b6a480");
        params.put("s", "ff8080816e216c04016e34294282004a");
        params.put("t", 1);
        String s = params.toJSONString();
        String s1 = NoticeMessageUtil.buildMiniAppUrl(NoticeMessageTypeEnum.MATERIAL_REPORT_NOTIFY, s);
        System.out.println("/pages/route/index?pageType=hbapp_material_report&data=".length());
        System.out.println(s1);
        System.out.println(s1.length());
    }
}
