package com.tax.file.test;

import com.alibaba.fastjson.JSONObject;
import com.tax.file.constants.FileConstants;
import com.tax.file.model.FIncomeInvoice;
import com.tax.file.utils.NationUtil;
import com.tax.file.utils.income.IncomeFileExcelUtil;
import com.yxcheng.token.utils.DateUtils;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class TestNation {

    @Before
    public void init(){
        NationUtil.setUrl("http://39.106.193.77:8880/fpcxService/QxrzServlet.do");
        FileConstants.isDebug = "1";
        FileConstants.nationFilePath = "/Users/wenhao/tmp/123455";
    }

    @Test
    public void testIncomeFileUpload() throws IOException {
        FIncomeInvoice entity = new FIncomeInvoice();
        entity.setTaxno("12344");
        entity.setToken("1~3~2~~1~0~0~1~0~0~1~c897f24c-4ef0-4ce9-8420-a77028b05ed2@@12344@@03");
        entity.setFilePath("/Users/wenhao/FPRZ_EMPEY_EXCEL.xls");
        entity.setZoneCode("9999");
        JSONObject jsonObject = NationUtil.incomeFileUpload(entity);
        System.out.println(jsonObject);
    }


    @Test
    public void testIncomeFileUpload2() throws Exception {
        String path = "/Users/wenhao/tmp/123455/20200525/9999/14/4/abccd.xls";
        List<FIncomeInvoice> list = new ArrayList<>();
        FIncomeInvoice entity = new FIncomeInvoice();
        entity.setInvKind("041001800104");
        entity.setInvNum("86504132");
        entity.setInvDate(DateUtils.getSearchDate("2019-12-12"));
        entity.setIsIncome("1");
        entity.setIncomeMonth("202001");
        list.add(entity);

        IncomeFileExcelUtil.generateExcel(list,path);

        FIncomeInvoice query = new FIncomeInvoice();
        query.setTaxno("12344");
        query.setToken("1~3~2~~1~0~0~1~0~0~1~4c376a8b-367e-4e71-8cc4-f1f0e18004d2@@12344@@03");
        query.setFilePath(path);
        query.setZoneCode("9999");
        JSONObject jsonObject = NationUtil.incomeFileUpload(query);
        System.out.println(jsonObject);
    }


    @Test
    public void testIncomeResultQuery() throws IOException {
        FIncomeInvoice entity = new FIncomeInvoice();
        entity.setTaxno("12344");
        entity.setToken("1~3~2~~1~0~0~1~0~0~1~78da03f8-5fea-48bb-8628-a30a59c1611c@@12344@@03");
        entity.setZoneCode("9999");
        Date applyDateBegin = DateUtils.getPreFirstDay(new Date(),9);
        entity.setApplyDateBegin(applyDateBegin);
        entity.setApplyDateEnd(new Date());

        JSONObject jsonObject = NationUtil.incomeResultQuery(entity);
        System.out.println(jsonObject);
    }


    @Test
    public void testIncomeSingleQuery() throws IOException {
        FIncomeInvoice entity = new FIncomeInvoice();
        entity.setTaxno("12344");
        entity.setToken("1~3~2~~1~0~0~1~0~0~1~9562c5b4-f96d-40cb-a190-e9481373dfb1@@12344@@03");
        entity.setZoneCode("9999");
        entity.setInvKind("041001800104");
        entity.setInvNum("86504132");

        JSONObject jsonObject = NationUtil.incomeSingleQuery(entity);
        System.out.println(jsonObject);
    }


    @Test
    public void testIncomeFileDown() throws Exception {
        FIncomeInvoice entity = new FIncomeInvoice();
        entity.setTaxno("12344");
        entity.setToken("1~3~2~~1~0~0~1~0~0~1~9461ddf0-3a1e-4622-a755-f1fd794f8f5a@@12344@@03");
        entity.setZoneCode("9999");
        entity.setFileId("171aaf92a59testnode77452");

        JSONObject jsonObject = NationUtil.incomeFileDown(entity);
        System.out.println(jsonObject);
        String filePath = NationUtil.downFile(jsonObject, entity);
        System.out.println(filePath);

    }
}
