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.MemberQueryService;
import com.gic.haoban.manage.service.service.content.GroupMessageService;
import com.gic.haoban.manage.service.service.content.MaterialReportService;
import com.gic.haoban.manage.service.service.content.adaptor.MaterialDataAdaptor;
import com.gic.member.api.dto.es.MemberDataDTO;
import com.gic.search.engine.api.constant.MemberDataEnum;
import org.apache.commons.lang3.StringUtils;
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.Arrays;
import java.util.Collections;
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;
    @Autowired
    private MaterialDataAdaptor materialDataAdaptor;
    @Autowired
    private MemberQueryService memberQueryService;

    String eid = "ff8080815dacd3a2015dacd3ef5c0000";
    String wxEid = "ca66a01b79474c40b3e7c7f93daf1a3b";
    String staffId = "e608b51b267e4943b87e222a343b4f25";
//    String staffId = "fb4096b75d524c5e943c036cb4079723";
    String storeId = "ff8080816e216c04016e34294282004a";
    String clerkId = "300b60c7f8874ca2b9cc696ad6b6a480";

    @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("key", "ff8080816e216c04016e34294282004a");
//        params.put("t", 1);
//        params.put("d", "04");
        String s = params.toJSONString();
        String s1 = NoticeMessageUtil.buildMiniAppUrl(NoticeMessageTypeEnum.MATERIAL_REPORT_NOTIFY_MONTH, s);
        System.out.println("/pages/route/index?pageType=hbapp_material_report&data=".length());
        System.out.println(s1);
        System.out.println(s1.length());
    }

    @Test
    public void queryData(){
        MaterialDataAdaptor.MaterialDataResult materialDataResult = materialDataAdaptor.queryClerkReportData(eid, clerkId, storeId, MaterialReportType.MONTH.getCode(), "2023-14");
        System.out.println(JSON.toJSONString(materialDataResult));
    }

    @Test
    public void queryMemberInfo(){

//        List<MemberDataDTO> memberDataDTOS = memberQueryService.queryMemberBatch(eid, Collections.singletonList("ff8080818147efc8018148d1759903c8"), null);
//        System.out.println(JSON.toJSONString(memberDataDTOS));

        List<String> returnFields = Arrays.asList(MemberDataEnum.member_id.getCode(), MemberDataEnum.member_photoUrl.getCode());
        List<MemberDataDTO> memberDataDTOS = memberQueryService.queryMemberBatch(eid, Collections.singletonList("ff8080818147efc8018148d1759903c8"), StringUtils.join(returnFields, ","));
        System.out.println(JSON.toJSONString(memberDataDTOS));
    }

    @Autowired
    private GroupMessageService groupMessageService;
    @Test
    public void queryHasReight(){
        List<String> strings = groupMessageService.hasMaterialRightEnterprise(1);
        System.out.println(JSON.toJSONString(strings));
    }
}
