import java.util.Arrays;
import java.util.List;

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 com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.EnterpriseDetailDTO;
import com.gic.haoban.manage.api.dto.hm.HmGroupDTO;
import com.gic.haoban.manage.api.dto.hm.HmGroupQueryDTO;
import com.gic.haoban.manage.api.dto.hm.HmPageDTO;
import com.gic.haoban.manage.api.dto.hm.HmPageRelationDTO;
import com.gic.haoban.manage.api.dto.hm.HmWelcomeRelationDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmPageRelationQDTO;
import com.gic.haoban.manage.api.dto.welcome.qdto.QueryWelcomeRelationQDTO;
import com.gic.haoban.manage.api.enums.hm.HmWelcomeReferType;
import com.gic.haoban.manage.api.service.WxEnterpriseApiService;
import com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService;
import com.gic.haoban.manage.api.service.hm.HmGroupApiService;
import com.gic.haoban.manage.api.service.hm.HmPageApiService;
import com.gic.haoban.manage.api.service.hm.HmQrcodeApiService;
import com.gic.haoban.manage.api.service.hm.HmWelcomeRelationApiService;
import com.gic.haoban.manage.service.pojo.bo.hm.HmWelcomeRelationBO;
import com.gic.haoban.manage.service.service.ExternalClerkRelatedService;
import com.gic.haoban.manage.service.service.hm.WelcomeRelationService;
import com.gic.redis.data.util.RedisUtil;

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

    @Autowired
    private HmPageApiService pageService;

    @Autowired
    private WxEnterpriseRelatedApiService enterpriseRelatedApiService;

    @Autowired
    private HmGroupApiService groupService;

    @Autowired
    private HmWelcomeRelationApiService welcomeRelationApiService;
    @Autowired
    private WxEnterpriseApiService wxEnterpriseApiService ;
    @Autowired
    private ExternalClerkRelatedService externalClerkRelatedService ;

    @Test
    public void test(){
         String key = "haoban_fresh_wx_friend" + "20221004" + "dc4c06fd6ff94cb8be6a8beef639f873";
         System.out.println(RedisUtil.getCache(key));
         RedisUtil.delCache(key);
         
     //  this.externalClerkRelatedService.repairExternalUserId("218a8a6c2ca14e28a1053f541be0e49d,ca66a01b79474c40b3e7c7f93daf1a3b");
     //   this.wxEnterpriseApiService.stopHaoban("ff80808182c3a46b0182c3a4ea7d0000");
        
     /*   HmPageQDTO pageQDTO = new HmPageQDTO();
        pageQDTO.setPageSearchText("MB01419872763172380673");
        ServiceResponse<Page<HmPageDTO>> pageServiceResponse = pageService.queryPageList(pageQDTO);*/
    }


    @Test
    public void entriprise(){
        ServiceResponse<EnterpriseDetailDTO> enterpriseDetailDTOServiceResponse = enterpriseRelatedApiService.queryEnterpriseDetail("ca66a01b79474c40b3e7c7f93daf1a3b", "ff8080815dacd3a2015dacd3ef5c0000");
        System.out.println(JSON.toJSONString(enterpriseDetailDTOServiceResponse));
    }

    @Test
    public void queryPageList(){
        HmPageRelationQDTO pageRelationQDTO = new HmPageRelationQDTO();
        pageRelationQDTO.setPageId(418460224953786370L);
        pageRelationQDTO.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
        ServiceResponse<Page<HmPageRelationDTO>> pageServiceResponse = pageService.queryPageRelation(pageRelationQDTO);
        System.out.println(JSON.toJSONString(pageServiceResponse));
    }

    @Test
    public void deletePage(){
        HmPageDTO pageDTO = new HmPageDTO();
        pageDTO.setPageId(418460224953786370L);
        ServiceResponse<Boolean> booleanServiceResponse = pageService.deleteHmPage(pageDTO);
        System.out.println(JSON.toJSONString(booleanServiceResponse));
    }

    @Test
    public void groupList(){
        HmGroupQueryDTO groupQueryDTO = new HmGroupQueryDTO();
        //groupQueryDTO.setGroupName("默认");
        groupQueryDTO.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
        groupQueryDTO.setClerkId("b7279937120a433b9d96ae3c9abedb04");
        ServiceResponse<Page<HmGroupDTO>> pageServiceResponse = groupService.queryHmGroupSettingList(groupQueryDTO);
        System.out.println(JSON.toJSONString(pageServiceResponse));
    }


    @Autowired
    private WelcomeRelationService welcomeRelationService;

    @Test
    public void saveWelcomeRelation(){
        HmWelcomeRelationBO welcomeRelationBo = new HmWelcomeRelationBO();
        welcomeRelationBo.setEnterpriseId("1231321312312");
        welcomeRelationBo.setWxEnterpriseId("31312312312");
        welcomeRelationBo.setReferId("313131");
        welcomeRelationBo.setReferCode("HM1312312312");
        welcomeRelationBo.setReferName("活码名称");
        welcomeRelationBo.setType(HmWelcomeReferType.HM.getCode());
        welcomeRelationService.saveHmWelcomeRelation(welcomeRelationBo);
    }


    @Test
    public void updateWelcomeRelationTest(){
        HmWelcomeRelationBO welcomeRelationBo = new HmWelcomeRelationBO();
        welcomeRelationBo.setEnterpriseId("1231321312312");
        welcomeRelationBo.setWxEnterpriseId("31312312312");
        welcomeRelationBo.setReferId("313131");
        welcomeRelationBo.setReferCode("HM1312312dada");
        welcomeRelationBo.setReferName("活码名称");
        welcomeRelationBo.setType(HmWelcomeReferType.HM.getCode());
        welcomeRelationService.updateWelcomeRelation(welcomeRelationBo);
    }


    @Autowired
    private HmQrcodeApiService qrcodeApiService;


    @Test
    public void batchUpdateQrcode(){
        List<Long> ids = Arrays.asList(418494104339988481L, 418494104339988482L);
        long grouoId = 420219621589671937L;
        ServiceResponse<Boolean> booleanServiceResponse = qrcodeApiService.batchUpdateHmQrcodeGroup(ids, grouoId);
        System.out.println(JSON.toJSONString(booleanServiceResponse));
    }

    @Test
    public void welcomeTest(){
        QueryWelcomeRelationQDTO qdto = new QueryWelcomeRelationQDTO();
        qdto.setWelcomeId("7f12bdab4fb543e8977f96e30fc8eddb");
        //qdto.setSearchContent("测试");
        ServiceResponse<Page<HmWelcomeRelationDTO>> serviceResponse = welcomeRelationApiService.queryWelcomeRelation(qdto);
        System.out.println(JSON.toJSONString(serviceResponse));
    }

    @Test
    public void groupNameCheckTest(){
        ServiceResponse<List<HmGroupDTO>> ms = groupService.queryGroupListByName("", "ff8080815dacd3a2015dacd3ef5c0000", "测试006");
        System.out.println(JSON.toJSONString(ms));
    }

}
