From 49888165f5f07710b984c7c6d70463d96cf08527 Mon Sep 17 00:00:00 2001 From: tqzhang <2452618307@qq.com> Date: Tue, 7 May 2024 16:49:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20src/main/java/com/bonus/au?= =?UTF-8?q?toweb/base/DutyClock.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bonus/autoweb/base/DutyClock.java | 158 ------------------ 1 file changed, 158 deletions(-) delete mode 100644 src/main/java/com/bonus/autoweb/base/DutyClock.java diff --git a/src/main/java/com/bonus/autoweb/base/DutyClock.java b/src/main/java/com/bonus/autoweb/base/DutyClock.java deleted file mode 100644 index b79820c..0000000 --- a/src/main/java/com/bonus/autoweb/base/DutyClock.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.bonus.autoweb.base; - -import com.bonus.autoweb.DateTimeUtils; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.slf4j.LoggerFactory; -import org.slf4j.Logger; - - -/** - * 值班打卡 - */ -public class DutyClock { - private Logger log = LoggerFactory.getLogger(DutyClock.class); - - private WebDriver webDriver; - - public DutyClock(WebDriver webDriver) { - this.webDriver = webDriver; - } - - - - public void openDutyClock() throws InterruptedException { - Thread.sleep(1000*4); - //定位值班打卡并点击 - webDriver.findElement(By.id("tab-2")).click(); - log.info("定位值班打卡并点击----------"); - Thread.sleep(300); - } - - /** - * 值班打卡操作 - * - * @param classes 班次,,1早班 2晚班 - * @param type 打卡类型 1 签到 2签退 - */ - public void dutyClockOper(int classes, int type) throws InterruptedException { - openDutyClock(); -// JavascriptExecutor jsExecutor = (JavascriptExecutor) webDriver; -// boolean pageLoaded = false; -// -// do { -// pageLoaded = (Boolean) jsExecutor.executeScript("return document.readyState").equals("complete"); -// } while (!pageLoaded); - Thread.sleep(5000); - //标签位置 - String xpaht; - if (classes == 1) { - if (type == 1) { - //早班签到 - xpaht = "//*[@id=\"pane-2\"]/div/div[3]/div[1]/div[1]/div[2]/button[1]"; - } else { - //早班签退 - xpaht = "//*[@id=\"pane-2\"]/div/div[3]/div[1]/div[1]/div[2]/button[2]"; - } - } else { - if (type == 1) { - //晚班签到 - xpaht = "//*[@id=\"pane-2\"]/div/div[3]/div[2]/div[1]/div[2]/button[1]"; - } else { - //晚班签退 - xpaht = "//*[@id=\"pane-2\"]/div/div[3]/div[2]/div[1]/div[2]/button[2]"; - } - } - Thread.sleep(1000*4); - webDriver.findElement(By.xpath(xpaht)).click(); - log.info("打卡签到----------"); - Thread.sleep(1000*5); - - - //点击弹出框确认 - webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[2]/div[1]")).click(); - log.info("点击弹出框确认----------"); - Thread.sleep(800); - } - - /** - * 选择上个晚班签退 - */ - public void changeDay() throws Exception { - Thread.sleep(3000); - //判断当前日期是不是每月第一天的日期,true - boolean tf = false; - int tr = 1; - int td = 1; - String xpath; - if (!DateTimeUtils.isOneDay()) { - //不是本月第一天 - String currentDay = DateTimeUtils.getCurrentDay(); - int weekNum = DateTimeUtils.getWeekNum(currentDay); - int dayNum = DateTimeUtils.getWeekOfDate(currentDay); - /*if (dayNum == 1) { - tr = weekNum - 1; - td = 7; - } else { - tr = weekNum; - td = dayNum - 1; - }*/ - if (dayNum == 1) { - if(DateTimeUtils.getMonthOneDayIs0()){//第一天是0 - tr = weekNum; - }else{ - tr = weekNum-1; - if (weekNum == 1){ - tr = 5; - } - } - td = 7; - }else { - if(DateTimeUtils.getMonthOneDayIs0()){//第一天是0 - tr = weekNum+1; - }else{ - tr = weekNum; - } - td = dayNum - 1; - } - xpath = "//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + tr + "]" + "/td[" + td + "]"; - } else { - //点击上月按钮,切换至上月 - webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[1]/div[2]/div/button[1]")).click(); - log.info("点击上月按钮,切换至上月----------"); - Thread.sleep(300); - - //获取上月最后一天日期 - String mothDay=DateTimeUtils.getBeforeLastMonthdate(); - //判断上个月最后一天的位置 - tr = DateTimeUtils.getWeekNum(mothDay); - td = DateTimeUtils.getWeekOfDate(mothDay); - - xpath = "//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + tr + "]" + "/td[" + td + "]"; -// String dayNum = mothDay.substring(8, 10); -// WebElement spanElement = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + tr + "]" + "/td[" + td + "]/div/div/div[1]/span")); -// if (dayNum.equals(spanElement.getText())) { -// xpath = "//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + (tr + 1) + "]" + "/td[" + td + "]/div"; -// } - } - //选择前一天的日期 - webDriver.findElement(By.xpath(xpath)).click(); - log.info("选择前一天的日期----------"); - Thread.sleep(300); - openDutyClock(); - Thread.sleep(3000); - //进行晚班签退操作 - log.info("进行晚班签退操作----------"); - dutyClockOper(2,2); - - Thread.sleep(300); - - //将日期选择回当日 - webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[1]/div[2]/div/button[2]")).click(); - log.info("将日期选择回当日----------"); - Thread.sleep(300); - - } - -}