package com.gyee.wisdom.report.service;


import com.gyee.wisdom.report.config.cache.CacheService;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class SeleniumService {

    @Value("${chromeDriver}")
    String chromeDriver;

    @Value("${password}")
    String password;

    @Autowired
    private CacheService cacheService;

    private final static String driver1 = "webdriver.chrome.driver";
    //本地谷歌浏览器地址  C:\Program Files\Google\Chrome\Application\chromedriver.exe
    //private final static String chromeDriver = "C:\\Users\\戴尔\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe";

    public void loginAndWrite(Map<Integer, List<String[]>> map, String departId) {
        WebDriver webDriver = null;
        try {
            //截取excel行
            List<String[]> list3 = map.get(2);
            List<String[]> listExcel = list3.subList(5,list3.size()-1);
            System.out.println("打开浏览器进行操作");
            System.setProperty(driver1,chromeDriver);
            WebDriver driver = new ChromeDriver();
            driver.manage().window().maximize();//浏览器最大化
            //超时等待30秒
            Duration duration = Duration.ofSeconds(30);
            driver.manage().timeouts().implicitlyWait(duration);
            //跳转到浏览器
            driver.get("http://10.65.17.158:7001/Liems/");
            Thread.sleep(2000);
            //操作浏览器 获取到输入框
            WebElement kk = driver.findElement(By.id("userName"));
            //然后向输入框输入selenium java
            kk.sendKeys(departId);
            Thread.sleep(1000);
            //操作浏览器 获取到输入框
            WebElement kk2 = driver.findElement(By.id("password"));
            //然后向输入框输入selenium java
            kk2.sendKeys(password);
            Thread.sleep(1000);
            WebElement btn = driver.findElement(By.id("submitBtn"));
            //对按钮进行点击操作
            btn.click();
            Thread.sleep(1000);
            Actions actions = new Actions(driver);
            WebElement btn2 = driver.findElement(By.id("topMenuDiv_0_-01100001602"));
            btn2.click();
            Thread.sleep(2000);
            WebElement btn3 = driver.findElement(By.id("tree_NodeLabel_M261"));
            btn3.click();
            Thread.sleep(2000);
            WebElement btn4 = driver.findElement(By.id("tree_NodeLabel_P1627"));
            btn4.click();
            Thread.sleep(10000);


            //填写frameL表格数据
            List<String[]> strings = map.get(1);
            strings.remove(0);
            System.out.println("开始填写Left数据");
            WebElement mainFrame2 = driver.findElement(By.id("mainFrame"));
            driver.switchTo().frame(mainFrame2);
            WebElement frameL = driver.findElement(By.id("frameL"));
            driver.switchTo().frame(frameL);
            WebElement report2 = driver.findElement(By.id("report1"));
            System.out.println("取excel的Left数据");
//            WebElement report1_D3 = report2.findElement(By.id("report1_D3"));
//            actions.doubleClick(report1_D3).sendKeys(strings.get(0)[1]).perform();
//
//            WebElement report1_D4 = report2.findElement(By.id("report1_D4"));
//            actions.doubleClick(report1_D4).sendKeys(strings.get(1)[1]).perform();

            WebElement report1_D5 = report2.findElement(By.id("report1_D5"));
            actions.doubleClick(report1_D5).sendKeys(strings.get(2)[1]).perform();

            WebElement report1_D6 = report2.findElement(By.id("report1_D6"));
            actions.doubleClick(report1_D6).sendKeys(strings.get(3)[1]).perform();

            WebElement report1_D11 = report2.findElement(By.id("report1_D11"));
            actions.doubleClick(report1_D11).sendKeys(strings.get(4)[1]).perform();

            WebElement report1_D24 = report2.findElement(By.id("report1_D24"));
            actions.doubleClick(report1_D24).sendKeys(strings.get(5)[1]).perform();

            WebElement report1_D25 = report2.findElement(By.id("report1_D25"));
            actions.doubleClick(report1_D25).sendKeys(strings.get(6)[1]).perform();

            WebElement report1_D26 = report2.findElement(By.id("report1_D26"));
            actions.doubleClick(report1_D26).sendKeys(strings.get(7)[1]).perform();

            WebElement report1_D28 = report2.findElement(By.id("report1_D28"));
            actions.doubleClick(report1_D28).sendKeys(strings.get(8)[1]).perform();

            WebElement report1_D29 = report2.findElement(By.id("report1_D29"));
            actions.doubleClick(report1_D29).sendKeys(strings.get(9)[1]).perform();

            WebElement report1_D35 = report2.findElement(By.id("report1_D35"));
            actions.doubleClick(report1_D35).sendKeys(strings.get(12)[1]).perform();

            WebElement report1_D36 = report2.findElement(By.id("report1_D36"));
            report1_D36.click();
            WebElement report1_editBox = driver.findElement(By.id("report1_editBox"));
            report1_editBox.clear();
            System.out.println(strings.get(13)[1]);
            report1_editBox.sendKeys(strings.get(13)[1]);

            WebElement report1_D43 = report2.findElement(By.id("report1_D43"));
            report1_D43.click();
            WebElement report1_editBox5 = driver.findElement(By.id("report1_editBox"));
            report1_editBox5.clear();
            report1_editBox5.sendKeys(strings.get(14)[1]);

            WebElement report1_D44 = report2.findElement(By.id("report1_D44"));
            report1_D44.click();
            WebElement report1_editBox4 = driver.findElement(By.id("report1_editBox"));
            report1_editBox4.clear();
            report1_editBox4.sendKeys(strings.get(15)[1]);
            System.out.println(strings.get(15)[1]);

            WebElement report1_D45 = report2.findElement(By.id("report1_D45"));
            actions.doubleClick(report1_D45).sendKeys(strings.get(16)[1]).perform();

            WebElement report1_D46 = report2.findElement(By.id("report1_D46"));
            actions.doubleClick(report1_D46).sendKeys(strings.get(17)[1]).perform();

            WebElement report1_D48 = report2.findElement(By.id("report1_D48"));
            report1_D48.click();
            WebElement report1_editBox6 = driver.findElement(By.id("report1_editBox"));
            report1_editBox6.clear();
            report1_editBox6.sendKeys(strings.get(18)[1]);
            actions.doubleClick(report1_D48).sendKeys(strings.get(18)[1]).perform();

            WebElement report1_D52 = report2.findElement(By.id("report1_D52"));
            report1_D52.click();
            WebElement report1_editBox2 = driver.findElement(By.id("report1_editBox"));
            report1_editBox2.clear();
            report1_editBox2.sendKeys(strings.get(19)[1]);
            System.out.println(strings.get(19)[1]);

            WebElement report1_D56 = report2.findElement(By.id("report1_D56"));
            report1_D56.click();
            WebElement report1_editBox7 = driver.findElement(By.id("report1_editBox"));
            report1_editBox7.clear();
            report1_editBox7.sendKeys(strings.get(20)[1]);

            WebElement report1_D57 = report2.findElement(By.id("report1_D57"));
            report1_D57.click();
            WebElement report1_editBox3 = driver.findElement(By.id("report1_editBox"));
            report1_editBox3.clear();
            report1_editBox3.sendKeys(strings.get(21)[1]);

            WebElement report1_D62 = report2.findElement(By.id("report1_D62"));
            report1_D62.click();
            WebElement report1_editBox8 = driver.findElement(By.id("report1_editBox"));
            report1_editBox8.clear();
            report1_editBox8.sendKeys(strings.get(22)[1]);

            WebElement report1_D79 = report2.findElement(By.id("report1_D79"));
            report1_D79.click();
            WebElement report1_textArea = driver.findElement(By.id("report1_textArea"));
            report1_textArea.clear();
            actions.doubleClick(report1_textArea).sendKeys(strings.get(23)[1]).perform();
            System.out.println("------------leftData表格数据填写完成------------------");
            // 切出iframe
            driver.switchTo().defaultContent();
            //找到frameRB
            WebElement mainFrame = driver.findElement(By.id("mainFrame"));
            driver.switchTo().frame(mainFrame);
            WebElement frameRT = driver.findElement(By.id("frameRT"));
            driver.switchTo().frame(frameRT);
            WebElement report4 = driver.findElement(By.id("report1"));

            //DataRT表格数据填写
            System.out.println("DataRT表格数据填写");
            for (int i = 4;i < listExcel.size() + 4;i++){
                WebElement report1_H = report4.findElement(By.id("report1_H"+i));
                actions.doubleClick(report1_H).sendKeys(listExcel.get(i-4)[6]).perform();

                WebElement report1_I = report4.findElement(By.id("report1_I"+i));
                actions.doubleClick(report1_I).sendKeys(listExcel.get(i-4)[7]).perform();

                // 切出iframe
                driver.switchTo().defaultContent();
                WebElement mainFrame5 = driver.findElement(By.id("mainFrame"));
                driver.switchTo().frame(mainFrame5);
                WebElement frameRT1 = driver.findElement(By.id("frameRT"));
                driver.switchTo().frame(frameRT1);
                WebElement for1 = driver.findElement(By.id("report1"));
                WebElement report1_K = for1.findElement(By.id("report1_K"+i));
                report1_K.click();
                WebElement odiv_0 = driver.findElement(By.id("odiv_0"));
                driver.switchTo().frame(odiv_0);
                int dataictonary = dataictonary(listExcel.get(i - 4)[9]);
                WebElement div1 = driver.findElement(By.xpath("//html/body/div[1]/table/tbody/tr[" + dataictonary + "]"));
                actions.moveToElement(div1).click().perform();
                // 切出iframe
                driver.switchTo().defaultContent();
                WebElement mainFrame6 = driver.findElement(By.id("mainFrame"));
                driver.switchTo().frame(mainFrame6);
                WebElement frameRT6 = driver.findElement(By.id("frameRT"));
                driver.switchTo().frame(frameRT6);
                WebElement report3 = driver.findElement(By.id("report1"));

                WebElement report1_O = report3.findElement(By.id("report1_O"+i));
                actions.doubleClick(report1_O).sendKeys(listExcel.get(i-4)[11]).perform();

                WebElement report1_R = report3.findElement(By.id("report1_R"+i));
                actions.doubleClick(report1_R).sendKeys(listExcel.get(i-4)[14]).perform();

                WebElement report1_S = report3.findElement(By.id("report1_S"+i));
                actions.doubleClick(report1_S).sendKeys(listExcel.get(i-4)[15]).perform();

                WebElement report2Element = report3.findElement(By.id("report1_T"+i));
                actions.doubleClick(report2Element).sendKeys(listExcel.get(i-4)[16]).perform();

                WebElement report1_T = report3.findElement(By.id("report1_U"+i));
                actions.doubleClick(report1_T).sendKeys(listExcel.get(i-4)[17]).perform();

                WebElement report1_V = report3.findElement(By.id("report1_V"+i));
                actions.doubleClick(report1_V).sendKeys(listExcel.get(i-4)[18]).perform();

                WebElement report1_W = report3.findElement(By.id("report1_W"+i));
                actions.doubleClick(report1_W).sendKeys(listExcel.get(i-4)[19]).perform();

                WebElement report1_AG = report3.findElement(By.id("report1_AG"+i));
                actions.doubleClick(report1_AG).sendKeys(listExcel.get(i-4)[26]).perform();

                WebElement report1_AH = report3.findElement(By.id("report1_AH"+i));
                actions.doubleClick(report1_AH).sendKeys(listExcel.get(i-4)[27]).perform();

                WebElement report1_AI = report3.findElement(By.id("report1_AI"+i));
                actions.doubleClick(report1_AI).sendKeys(listExcel.get(i-4)[28]).perform();

                WebElement report1_AR = report3.findElement(By.id("report1_AR"+i));
                actions.doubleClick(report1_AR).sendKeys(listExcel.get(i-4)[33]).perform();

                WebElement report1_AU = report3.findElement(By.id("report1_AU"+i));
                actions.doubleClick(report1_AU).sendKeys(listExcel.get(i-4)[36]).perform();

                WebElement report1_AV = report3.findElement(By.id("report1_AV"+i));
                actions.doubleClick(report1_AV).sendKeys(listExcel.get(i-4)[37]).perform();

                WebElement report1_AY = report3.findElement(By.id("report1_AY"+i));
                actions.doubleClick(report1_AY).sendKeys(listExcel.get(i-4)[38]).perform();

                WebElement report1_BB = report3.findElement(By.id("report1_BB"+i));
                actions.doubleClick(report1_BB).sendKeys(listExcel.get(i-4)[41]).perform();

                WebElement report1_BC = report3.findElement(By.id("report1_BC"+i));
                actions.doubleClick(report1_BC).sendKeys(listExcel.get(i-4)[42]).perform();

                WebElement report1_BE = report3.findElement(By.id("report1_BE"+i));
                actions.doubleClick(report1_BE).sendKeys(listExcel.get(i-4)[44]).perform();

                WebElement report1_BF = report3.findElement(By.id("report1_BF"+i));
                actions.doubleClick(report1_BF).sendKeys(listExcel.get(i-4)[45]).perform();

                WebElement report1_BG = report3.findElement(By.id("report1_BG"+i));
                actions.doubleClick(report1_BG).sendKeys(listExcel.get(i-4)[46]).perform();

                WebElement report1_BI = report3.findElement(By.id("report1_BI"+i));
                actions.doubleClick(report1_BI).sendKeys(listExcel.get(i-4)[47]).perform();

                WebElement report1_BM = report3.findElement(By.id("report1_BM"+i));
                actions.doubleClick(report1_BM).sendKeys(listExcel.get(i-4)[51]).perform();

                WebElement report1_BN = report3.findElement(By.id("report1_BN"+i));
                actions.doubleClick(report1_BN).sendKeys(listExcel.get(i-4)[52]).perform();

                WebElement report1_BQ = report3.findElement(By.id("report1_BQ"+i));
                actions.doubleClick(report1_BQ).sendKeys(listExcel.get(i-4)[54]).perform();

                WebElement report1_BR = report3.findElement(By.id("report1_BR"+i));
                actions.doubleClick(report1_BR).sendKeys(listExcel.get(i-4)[55]).perform();

                WebElement report1_BU = report3.findElement(By.id("report1_BU"+i));
                actions.doubleClick(report1_BU).sendKeys(listExcel.get(i-4)[58]).perform();


                WebElement report1_BV = report3.findElement(By.id("report1_BV"+i));
                actions.doubleClick(report1_BV).sendKeys(listExcel.get(i-4)[59]).perform();

                WebElement report1_BW = report3.findElement(By.id("report1_BW"+i));
                actions.doubleClick(report1_BW).sendKeys(listExcel.get(i-4)[60]).perform();

                WebElement report1_CA = report3.findElement(By.id("report1_CA"+i));
                actions.doubleClick(report1_CA).sendKeys(listExcel.get(i-4)[64]).perform();

                WebElement report1_CB = report3.findElement(By.id("report1_CB"+i));
                actions.doubleClick(report1_CB).sendKeys(listExcel.get(i-4)[65]).perform();

                WebElement report1_CC = report3.findElement(By.id("report1_CC"+i));
                actions.doubleClick(report1_CC).sendKeys(listExcel.get(i-4)[66]).perform();

                WebElement report1_CD = report3.findElement(By.id("report1_CD"+i));
                actions.doubleClick(report1_CD).sendKeys(listExcel.get(i-4)[67]).perform();

                WebElement report1_CE = report3.findElement(By.id("report1_CE"+i));
                actions.doubleClick(report1_CE).sendKeys(listExcel.get(i-4)[68]).perform();

                WebElement report1_CF = report3.findElement(By.id("report1_CF"+i));
                actions.doubleClick(report1_CF).sendKeys(listExcel.get(i-4)[69]).perform();

                WebElement report1_CO = report3.findElement(By.id("report1_CO"+i));
                actions.doubleClick(report1_CO).sendKeys(listExcel.get(i-4)[70]).perform();
            }
            // 切出iframe
            driver.switchTo().defaultContent();
            //填写frameRB表格数据
            System.out.println("开始填写RB数据");
            WebElement mainFrame3 = driver.findElement(By.id("mainFrame"));
            driver.switchTo().frame(mainFrame3);
            WebElement frameRB = driver.findElement(By.id("frameRB"));
            driver.switchTo().frame(frameRB);
            WebElement report1 = driver.findElement(By.id("report1"));
            //取第一个表数据
            List<String[]> list = map.get(0);
            List<String[]> listMap0 = list.stream().skip(2).collect(Collectors.toList());
            System.out.println("取excel的RB数据");
            for (int j = 4; j < listMap0.size() + 4;j++) {
                WebElement c = report1.findElement(By.id("report1_C" + j));
                actions.doubleClick(c).sendKeys(listMap0.get(j - 4)[1]).perform();
                WebElement d = report1.findElement(By.id("report1_D" + j));
                actions.doubleClick(d).sendKeys(listMap0.get(j - 4)[2]).perform();
                WebElement e = report1.findElement(By.id("report1_E" + j));
                actions.doubleClick(e).sendKeys(listMap0.get(j - 4)[3]).perform();
                WebElement f = report1.findElement(By.id("report1_F" + j));
                actions.doubleClick(f).sendKeys(listMap0.get(j - 4)[4]).perform();
            }
            // 切出iframe
            driver.switchTo().defaultContent();
            //todo: 后续添加点击日报保存按钮

            //故障报表填写
            Thread.sleep(60000);
            // 切出iframe,重新进入菜单
            driver.switchTo().defaultContent();
            WebElement btntop = driver.findElement(By.id("topMenuDiv_0_-01100001602"));
            btntop.click();
            Thread.sleep(2000);
            WebElement btntree = driver.findElement(By.id("tree_NodeLabel_M261"));
            btntree.click();
            Thread.sleep(2000);
            WebElement btntreep = driver.findElement(By.id("tree_NodeLabel_P1627"));
            btntreep.click();
            WebElement tree_NodeLabel_P1897 = driver.findElement(By.id("tree_NodeLabel_P1897"));
            tree_NodeLabel_P1897.click();
            Thread.sleep(3000);
            //拿到excel数据
            List<String[]> listFault = map.get(3);
            System.out.println("故障日报填写");
            WebElement main = driver.findElement(By.id("mainFrame"));
            driver.switchTo().frame(main);
            WebElement frameRT2 = driver.findElement(By.id("frameRT"));
            driver.switchTo().frame(frameRT2);
            //WebElement reports = driver.findElement(By.id("report1"));

            for (int i = 4;i < listFault.size() + 4;i++){
                //针对下拉框选项，iframe先切出
                driver.switchTo().defaultContent();
                WebElement mainFrame5 = driver.findElement(By.id("mainFrame"));
                driver.switchTo().frame(mainFrame5);
                WebElement frameRT1 = driver.findElement(By.id("frameRT"));
                driver.switchTo().frame(frameRT1);
                WebElement for1 = driver.findElement(By.id("report1"));
                WebElement report1_B = for1.findElement(By.id("report1_B"+i));
                report1_B.click();
                WebElement odiv_0 = driver.findElement(By.id("odiv_0"));
                driver.switchTo().frame(odiv_0);
                int s = cacheService.getSerial(listExcel.get(i - 4)[0], departId);
                WebElement div1 = driver.findElement(By.xpath("//html/body/div[1]/table/tbody/tr[" + s + "]"));
                actions.moveToElement(div1).click().perform();
                driver.switchTo().defaultContent();
                WebElement mainFrame6 = driver.findElement(By.id("mainFrame"));
                driver.switchTo().frame(mainFrame6);
                WebElement frameRT6 = driver.findElement(By.id("frameRT"));
                driver.switchTo().frame(frameRT6);
                WebElement reports = driver.findElement(By.id("report1"));

                WebElement report1_C = reports.findElement(By.id("report1_C" + i));
                actions.doubleClick(report1_C).sendKeys(listFault.get(i-4)[1]).perform();

                WebElement report1_D = reports.findElement(By.id("report1_D" + i));
                actions.doubleClick(report1_D).sendKeys(listFault.get(i-4)[2]).perform();

                WebElement report1_E = reports.findElement(By.id("report1_E" + i));
                actions.doubleClick(report1_E).sendKeys(listFault.get(i-4)[3]).perform();

                WebElement report1_F = reports.findElement(By.id("report1_F" + i));
                actions.doubleClick(report1_F).sendKeys(listFault.get(i-4)[4]).perform();

                //针对下拉框选项，iframe先切出
                driver.switchTo().defaultContent();
                WebElement mainFrame10 = driver.findElement(By.id("mainFrame"));
                driver.switchTo().frame(mainFrame10);
                WebElement frameRT10 = driver.findElement(By.id("frameRT"));
                driver.switchTo().frame(frameRT10);
                WebElement for10 = driver.findElement(By.id("report1"));
                WebElement report1_G = for10.findElement(By.id("report1_G"+i));
                report1_G.click();
                WebElement odiv_0_2 = driver.findElement(By.id("odiv_0"));
                driver.switchTo().frame(odiv_0_2);
                int s2 = faultType(listFault.get(i - 4)[5]);
                WebElement div2 = driver.findElement(By.xpath("//html/body/div[1]/table/tbody/tr[" + s2 + "]"));
                actions.moveToElement(div2).click().perform();
                driver.switchTo().defaultContent();
                WebElement mainFrame11 = driver.findElement(By.id("mainFrame"));
                driver.switchTo().frame(mainFrame11);
                WebElement frameRT11 = driver.findElement(By.id("frameRT"));
                driver.switchTo().frame(frameRT11);
                WebElement report11 = driver.findElement(By.id("report1"));

                if (!listFault.get(i-4)[6].isEmpty()){
                    WebElement report1_H = report11.findElement(By.id("report1_H" + i));
                    report1_H.click();
                    //日期控件
                    WebElement div11 = driver.findElement(By.xpath("//html/body/div[2]/div/iframe[@name='runqianCalendarIframe']"));
                    driver.switchTo().frame(div11);
                    //设置年
                    WebElement year1 = driver.findElement(By.xpath("//html/body/table/tbody/tr[1]/td/table/tbody/tr/td[2]/input"));
                    year1.clear();
                    year1.sendKeys(listFault.get(i-4)[6].substring(0,4));
                    //设置时
                    WebElement hour = driver.findElement(By.xpath("//html/body/table/tbody/tr[4]/td/div/table/tbody/tr/td[3]/input"));
                    hour.clear();
                    hour.sendKeys(listFault.get(i-4)[6].substring(11,13));
                    //设置分
                    WebElement minute = driver.findElement(By.xpath("//html/body/table/tbody/tr[4]/td/div/table/tbody/tr/td[6]/input"));
                    minute.clear();
                    minute.sendKeys(listFault.get(i-4)[6].substring(14,16));
                    //设置秒
                    WebElement second = driver.findElement(By.xpath("/html/body/table/tbody/tr[4]/td/div/table/tbody/tr/td[9]/input"));
                    second.clear();
                    second.sendKeys("0");
                    //月位置
                    WebElement month = driver.findElement(By.xpath("/html/body/table/tbody/tr[1]/td/table/tbody/tr/td[6]/span"));
                    month.click();
                    WebElement key = driver.findElement(By.xpath("/html/body/table/tbody/tr[1]/td/table/tbody/tr/td[6]/select"));
                    Select select = new Select(key);
                    select.selectByValue(listFault.get(i-4)[6].substring(5,7));
                    String day = listFault.get(i-4)[6].substring(8,10);
                    int day1 = Integer.parseInt(day) + 1;
                    WebElement key1 = driver.findElement(By.id("runqianDay"+ day1));
                    key1.click();
                }

                driver.switchTo().defaultContent();
                WebElement mainFrame12 = driver.findElement(By.id("mainFrame"));
                driver.switchTo().frame(mainFrame12);
                WebElement frameRT12 = driver.findElement(By.id("frameRT"));
                driver.switchTo().frame(frameRT12);
                WebElement report12 = driver.findElement(By.id("report1"));

                if (!listFault.get(i-4)[7].isEmpty()){
                    WebElement report1_H = report12.findElement(By.id("report1_I" + i));
                    report1_H.click();
                    //日期控件
                    WebElement div11 = driver.findElement(By.xpath("//html/body/div[2]/div/iframe[@name='runqianCalendarIframe']"));
                    driver.switchTo().frame(div11);
                    //设置年
                    WebElement year1 = driver.findElement(By.xpath("//html/body/table/tbody/tr[1]/td/table/tbody/tr/td[2]/input"));
                    year1.clear();
                    year1.sendKeys(listFault.get(i-4)[7].substring(0,4));
                    //设置时
                    WebElement hour = driver.findElement(By.xpath("//html/body/table/tbody/tr[4]/td/div/table/tbody/tr/td[3]/input"));
                    hour.clear();
                    hour.sendKeys(listFault.get(i-4)[7].substring(11,13));
                    //设置分
                    WebElement minute = driver.findElement(By.xpath("//html/body/table/tbody/tr[4]/td/div/table/tbody/tr/td[6]/input"));
                    minute.clear();
                    minute.sendKeys(listFault.get(i-4)[7].substring(14,16));
                    //设置秒
                    WebElement second = driver.findElement(By.xpath("/html/body/table/tbody/tr[4]/td/div/table/tbody/tr/td[9]/input"));
                    second.clear();
                    second.sendKeys("0");
                    //月位置
                    WebElement month = driver.findElement(By.xpath("/html/body/table/tbody/tr[1]/td/table/tbody/tr/td[6]/span"));
                    month.click();
                    WebElement key = driver.findElement(By.xpath("/html/body/table/tbody/tr[1]/td/table/tbody/tr/td[6]/select"));
                    Select select = new Select(key);
                    select.selectByValue(listFault.get(i-4)[7].substring(5,7));
                    String day = listFault.get(i-4)[7].substring(8,10);
                    int day1 = Integer.parseInt(day) + 1;
                    WebElement key1 = driver.findElement(By.id("runqianDay"+ day1));
                    key1.click();

                    // 切出iframe
                    driver.switchTo().defaultContent();
                    //todo: 后续添加点击故障日报保存按钮
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (webDriver != null) {
                webDriver.quit();
            }
        }
    }

    private int faultType(String strings) {

        //故障类型字典装换
        if(strings.equals("机舱振动故障")){
            return 2;
        }else if (strings.equals("变频器故障")){
            return 3;
        }else if (strings.equals("发电机故障")){
            return 4;
        }else if (strings.equals("齿轮箱故障")){
            return 5;
        }else if (strings.equals("箱变故障")){
            return 6;
        }else if (strings.equals("偏航系统故障")){
            return 7;
        }else if (strings.equals("液压系统故障")){
            return 8;
        }else if (strings.equals("电网故障")){
            return 9;
        }else if (strings.equals("控制柜制冷故障")){
            return 10;
        }else if (strings.equals("控制柜加热故障")){
            return 11;
        }else if (strings.equals("UPS故障")){
            return 12;
        }else if (strings.equals("FROFIBUS故障")){
            return 13;
        }else if (strings.equals("风速风向故障")){
            return 14;
        }else if (strings.equals("防雷保护故障")){
            return 15;
        }else if (strings.equals("初始化故障")){
            return 16;
        }else if (strings.equals("熔丝类故障")){
            return 17;
        }else if (strings.equals("CPU故障")){
            return 18;
        }else if (strings.equals("机舱冷却类故障")){
            return 19;
        }else if (strings.equals("故障停机类故障")){
            return 20;
        }else if (strings.equals("故障停机类故障")){
            return 21;
        }else if (strings.equals("转子位置类故障")){
            return 22;
        }else if (strings.equals("主轴类故障")){
            return 23;
        }else if (strings.equals("LUST变桨故障")){
            return 24;
        }else if (strings.equals("SSB变桨故障")){
            return 25;
        }else if (strings.equals("航灯类故障")){
            return 26;
        }else if (strings.equals("转速类故障")){
            return 27;
        }else if (strings.equals("安全链故障")){
            return 28;
        }else if (strings.equals("结冰类故障")){
            return 29;
        }else if (strings.equals("35KV电缆故障")){
            return 30;
        }else if (strings.equals("35KV集电线路故障")){
            return 31;
        }else if (strings.equals("35KV配电系统故障")){
            return 32;
        }else if (strings.equals("35KV以上输配电系统故障")){
            return 33;
        }else if (strings.equals("送出线路故障")){
            return 34;
        }
        return 1;
    }

    private int windpowerSataion(String strings) {

        //山西场站状态字段字典装换
        if(strings.equals("右玉高家堡一期")){
            return 2;
        }else if (strings.equals("大仁庄二期第一批5万")){
            return 3;
        }else if (strings.equals("虎头山三期第二批")){
            return 4;
        }else if (strings.equals("大仁庄二期第二批")){
            return 5;
        }else if (strings.equals("大仁庄一期")){
            return 6;
        }else if (strings.equals("吕梁马坊风电场")){
            return 7;
        }else if (strings.equals("阳高采凉山风电场")){
            return 8;
        }else if (strings.equals("吕梁马坊二期")){
            return 9;
        }else if (strings.equals("阳高采凉山二期")){
            return 10;
        }else if (strings.equals("虎头山三期二阶段")){
            return 11;
        }else if (strings.equals("右玉高家堡二期")){
            return 12;
        }else if (strings.equals("右玉高家堡三期")){
            return 13;
        }else if (strings.equals("虎头山一期")){
            return 14;
        }else if (strings.equals("虎头山二期")){
            return 15;
        }else if (strings.equals("右玉高家堡四期")){
            return 16;
        }else if (strings.equals("虎头山三期第一批")){
            return 17;
        }else if (strings.equals("广灵南村镇一期")){
            return 18;
        }else if (strings.equals("虎头山风电场四期")){
            return 19;
        }
        //太旗场站
        else if (strings.equals("太仆寺旗一期")){
            return 2;
        }else if (strings.equals("太仆寺旗二期")){
            return 3;
        }else if (strings.equals("太仆寺旗三期")){
            return 4;
        }
        //宁夏场站
        return 1;
    }


    public int dataictonary(String strings){
        //状态字段字典装换
        if(strings.equals("运行")){
            return 2;
        }else if (strings.equals("备用")){
            return 3;
        }else if (strings.equals("D检")){
            return 4;
        }else if (strings.equals("C检")){
            return 5;
        }else if (strings.equals("B检")){
            return 6;
        }else if (strings.equals("A检")){
            return 7;
        }else if (strings.equals("临检")){
            return 8;
        }else if (strings.equals("停用")){
            return 9;
        }
        return 1;
    }

}
