package com.trade.service;

import com.trade.common.utils.file.ASopUtil;
import com.trade.service.contract.dto.ContractGenInputItem;
import com.trade.service.contract.dto.ContractSignInfo;
import com.trade.service.contract.dto.ContractSignInput;
import com.trade.service.contract.entity.ESignFlow;
import com.trade.service.contract.queue.MessageSender;
import com.trade.service.contract.service.ContractService;
import com.trade.service.contract.service.ContractTemplateRepository;
import com.trade.service.contract.service.ESignFlowService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
public class ContractServiceTests {
    @Resource
    ContractService contractService;
    @Resource
    private ContractTemplateRepository contractTemplateRepository;
    @Resource
    private MessageSender messageSender;
    @Resource
    private ESignFlowService esignFlowService;


    @Test
    public void contractMapTest(){
        System.out.println(contractTemplateRepository.getContractTemplates().get("123"));
    }

    @Test
    public void contractGenerateTest(){
        // 生成合同
        ContractGenInputItem item = new ContractGenInputItem();
        item.setTemplateCode("123");
        Map<String, Object> params = new HashMap<>();
        params.put("name","张三");
        item.setParams(params);
        item.setContractName("测试合同");
        System.out.println(contractService.generateSingleContract(item, null));
    }

    @Test
    public void contractSignTest(){
        ContractSignInput input = new ContractSignInput();
        input.setSignPlatform(1);
        contractService.signContract(input);
    }

    @Test
    public void convert2PDFTest(){
        String docFile = "C:/Users/dawn7/Desktop/123.docx";
        ASopUtil.doc2pdf(docFile,"C:/Users/dawn7/Desktop/123.pdf");
    }

    @Test
    public void messageTest(){
        String message = "测试消息";
        messageSender.sendESignCallbackMessage(message);
    }

    @Test
    public void eSignFlowAddTest() {
        ESignFlow esignFlow = ESignFlow.builder().bizSysId("A101").flowId("666666")
                .scene("测试场景").expiredTime(LocalDateTime.now()).status(0).build();
        esignFlowService.add(esignFlow);
    }

    @Test
    public void eSignFlowQueryTest() {
        System.out.println( esignFlowService.getByFlowId("666666").getId());
    }


}
