package com.jkcredit.invoice;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.alibaba.fastjson.JSONObject;
import com.jkcredit.invoice.model.entity.SearchInvoiceResult;
import com.jkcredit.invoice.util.PlateCheckUtil;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: sunzhaoning
 * @create: 2019-07-10 16:45
 * @version: V1.0
 **/

public class PlateNumberTest {

    public static void test() {

        String pathname = "/Users/sunzhaoning/ftp/1";

        try {
            File filename = new File(pathname);
            InputStreamReader reader = new InputStreamReader(new FileInputStream(filename));
            BufferedReader br = new BufferedReader(reader);
            String line;
            int i = 0;
            while ((line = br.readLine()) != null) {
               boolean is = PlateCheckUtil.isPlateNumber(line);
               if(!is){
                   System.out.println(line);
               }
            }
            reader.close();
            br.close();
        } catch (
                IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void fe_map() throws Exception {
        SearchInvoiceResult searchInvoiceResult = new SearchInvoiceResult();
        searchInvoiceResult.setWaybillNum("1234567856432");
        SearchInvoiceResult searchInvoiceResult1 = new SearchInvoiceResult();
        searchInvoiceResult1.setWaybillNum("asfasfsghgfdssfdg");
        List<SearchInvoiceResult> list = new ArrayList<>();
        list.add(searchInvoiceResult);
        list.add(searchInvoiceResult1);
        TemplateExportParams params = new TemplateExportParams(
                "/Users/sunzhaoning/Downloads/发票列表.xls");
        Map<String, Object> map = new HashMap<>();
        map.put("amount", "2014-12-25");
        map.put("taxAmount", 2000000.00);
        map.put("count", "贰佰万");
        map.put("money", "执笔潜行科技有限公司");

        List<Map<String, String>> listMap = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Map<String, String> lm = new HashMap<>();
            lm.put("invoiceNum", list.get(i).getInvoiceNum());
            lm.put("invoiceCode", list.get(i).getInvoiceCode());
            lm.put("invoiceMakeTime", list.get(i).getInvoiceMakeTime());
            lm.put("invoiceUrl", list.get(i).getInvoiceUrl());
            lm.put("enStation", list.get(i).getEnStation());
            lm.put("exStation", list.get(i).getExStation());
            lm.put("exTime", list.get(i).getExTime());
            lm.put("fee", list.get(i).getFee().toString());
            lm.put("totalTaxAmount", list.get(i).getTotalTaxAmount().toString());
            lm.put("plateNum", list.get(i).getPlateNum());
            lm.put("waybillNum", list.get(i).getWaybillNum());
            lm.put("waybillStartTime",list.get(i).getWaybillStartTime());
            lm.put("waybillEndTime", list.get(i).getWaybillEndTime());
            lm.put("totalAmount",list.get(i).getTotalTaxAmount().toString());
            lm.put("taxRate", String.valueOf(list.get(i).getTaxRate()));
            lm.put("amount", list.get(i).getAmount().toString());
            lm.put("sellerName", list.get(i).getSellerName());
            lm.put("sellerTaxpayerCode", list.get(i).getSellerTaxpayerCode());
            lm.put("transactionId", list.get(i).getTransactionId());

            listMap.add(lm);
        }
        map.put("maplist", listMap);

        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        File savefile = new File("/Users/sunzhaoning/Downloads/");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream("/Users/sunzhaoning/Downloads/专项支出用款申请书_map.xls");
        workbook.write(fos);
        fos.close();
    }

    public static void main(String[] args) {
        test();
    }
}
