import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.DateUtil;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.dto.moment.QwMomentPlanDTO;
import com.gic.haoban.manage.api.qdto.moment.PlanClerkListQDTO;
import com.gic.haoban.manage.api.qdto.moment.PlanDataListQDTO;
import com.gic.haoban.manage.api.qdto.moment.QwMomentPlanQDTO;
import com.gic.haoban.manage.api.qdto.moment.SendResultQDTO;
import com.gic.haoban.manage.api.service.moment.QwMomentApiService;
import com.gic.haoban.manage.service.dao.mapper.moment.QwMomentPlanAttendMapper;
import com.gic.haoban.manage.service.dao.mapper.moment.QwMomentPlanMapper;
import com.gic.haoban.manage.service.entity.moment.TabQwMomentPlan;
import com.gic.haoban.manage.service.entity.moment.TabQwMomentPlanAttend;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.service.chat.GroupChatPlanService;
import com.gic.haoban.manage.service.service.content.impl.GroupMessageServiceImpl;
import com.gic.haoban.manage.service.service.moment.QwMomentPlanService;
import com.gic.wechat.api.service.qywx.QywxExternalUserService;
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.*;
import java.util.stream.Collectors;

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



    @Autowired
    private QwMomentApiService qwMomentApiService ;

    @Autowired
    private WxEnterpriseService wxEnterpriseService ;
    @Autowired
    private QywxExternalUserService qywxExternalUserService ;
    @Autowired
    private QwMomentPlanService qwMomentPlanService ;
    @Autowired
    private QwMomentPlanMapper qwMomentPlanMapper ;
    @Autowired
    private QwMomentPlanAttendMapper qwMomentPlanAttendMapper ;



    @Test
    public void ddd() {
           /* QwMomentPlanDTO dto = new QwMomentPlanDTO() ;
            dto.setPublishType(1);
            dto.setPublishTime(new Date());
            dto.setWxEnterpriseId("ca66a01b79474c40b3e7c7f93daf1a3b");
            dto.setCreatorId("fefd1c81641711e69d0818c58a146fd2");
            dto.setCreatorName("达摩管理");
            dto.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
            dto.setExecType(1);
            dto.setExpireDays(10);
            dto.setPlanClerkType(1);
            // ,"b2ef17cce11f476b996d0b27ebadf7fb"
            List<String> clerkIds = Arrays.asList("b2ef17cce11f476b996d0b27ebadf7fb","753a367d709d40a38b17ed25847d3b4b") ;
            dto.setSelectClerkIdList(clerkIds);
            this.qwMomentApiService.save(dto) ;*/

        Long planId = 772924621895778364L ;
        TabQwMomentPlan plan = this.qwMomentPlanMapper.getById(planId) ;
        this.qwMomentPlanService.sendToQiwei(plan);
    }



    @Test
    public void page() {
        QwMomentPlanQDTO qdto = new QwMomentPlanQDTO();
        qdto.setEnterpriseId("123");
        qdto.setWxEnterpriseId("123");
        qdto.setExecType(1);
        qdto.setStatusFlag(1);
        qdto.setStartTime(new Date());
        qdto.setEndTime(new Date());
        qdto.setNameParams("123");
        qdto.setPageNum(1);
        qdto.setPageSize(2);
        this.qwMomentApiService.planList(qdto) ;
    }


    @Test
    public void dataPage() {
        PlanDataListQDTO qdto = new PlanDataListQDTO();
        qdto.setPlanId(1111l);
        qdto.setPageNum(1);
        qdto.setPageSize(2);
        qdto.setStaffName("111");
        qdto.setClerkParams("2222");
        qdto.setType(1);
        this.qwMomentApiService.dataList(qdto) ;
    }



    @Test
    public void clerkPage() {
        PlanClerkListQDTO qdto = new PlanClerkListQDTO();
        qdto.setPlanId(1111l);
        qdto.setPageNum(1);
        qdto.setPageSize(2);
        qdto.setStaffName("111");
        qdto.setClerkParams("2222");
        this.qwMomentApiService.attendList(qdto) ;
    }

    @Test
    public void getmomentid() {
        String wxEnterpriseId = "ca66a01b79474c40b3e7c7f93daf1a3b";
        String jobId = "kyy1q5PYkElEGL6BISXVKkKZPD-Lpq76iGKEn8Z1nU4OBh9487Ni70dA638plHpD";
        WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
        ServiceResponse<Object> resp2 = this.qywxExternalUserService.getMomentTaskResult(qwDTO.getThirdCorpid(),
                qwDTO.getSelf3thSecret(), jobId, qwDTO.isSelf(),qwDTO.getUrlHost()) ;
        System.out.println(JSONObject.toJSONString(resp2));
    }


    @Test
    public void data() {
        Long planId = 773211358316478465L ;
      //  this.qwMomentPlanService.getQwData(planId);

        this.qwMomentPlanService.getQwPublishData(planId,null);
    }


    @Test
    public void finish() {
        SendResultQDTO q = new SendResultQDTO() ;
        q.setClerkId("2dd543ad1f2e4feab2e5a5c767197858");
        q.setWxEnterpriseId("ca66a01b79474c40b3e7c7f93daf1a3b");
        q.setStaffId("2c0d179610a04016bf8971ac0f158442");
        q.setPlanId(772845323461615680L);
        q.setSendTime(new Date(1741760727397l));
        this.qwMomentApiService.finishTask(q) ;
    }

}
