涡阳自动化小程序

This commit is contained in:
jjLv 2024-09-30 14:32:45 +08:00
parent cc9f79d6e2
commit 1c9e2a8779
8 changed files with 945 additions and 671 deletions

View File

@ -546,7 +546,7 @@ public class GetBasicData {
String type = "";
Random rand = new Random();
Set<Integer> generated = new HashSet<>();
while (generated.size() < 6) {
while (generated.size() < 3) {
Integer next = rand.nextInt(27) + 1;
// As we're adding to a set, this will automatically do a containment check
generated.add(next);
@ -813,7 +813,7 @@ public class GetBasicData {
//
// private void executePlan(String type, String company, String projectName) throws InterruptedException {
// Thread.sleep(2000);
// String checkContent = resolveGarbledCode("E:\\bns\\config\\检查计划评价.txt");
// String checkContent = resolveGarbledCode("D:\\bns\\config\\检查计划评价.txt");
// String[] checkContentArrayArray = checkContent.split("检查评价:");
//// //点击已审核按钮
//// webDriver.findElement(By.xpath("/html/body/div/div/div/div[1]/div/div/div/div[2]")).click();
@ -1186,21 +1186,21 @@ public class GetBasicData {
webDriver.findElement(By.xpath("/html/body/div[3]/div/div[2]/section/header/form/div/div[5]/div/div[2]")).click();
Thread.sleep(3000);
if("通信测试".equals(type)){
webDriver.findElement(By.xpath("/html/body/div[7]/div/div[2]/section/section/main/div/div[3]/table/tbody" +
"/tr[1]")).click();
webDriver.findElement(By.xpath("/html/body/div[7]/div/div[2]/section/main/div[1]/div[3]/table/tbody/tr[1]/td[1]/div/label")).click();
Thread.sleep(500);
webDriver.findElement(By.xpath("/html/body/div[7]/div/div[2]/section/section/main/div/div[3]/table/tbody" +
"/tr[2]")).click();
webDriver.findElement(By.xpath("/html/body/div[7]/div/div[2]/section/main/div[1]/div[3]/table/tbody/tr[2" +
"]/td[1]/div/label")).click();
Thread.sleep(1000);
webDriver.findElement(By.xpath("/html/body/div[7]/div/div[2]/section/footer/button[2]")).click();
}else {
for (int i = 1; i < 3; i++) {
webDriver.findElement(By.xpath("/html/body/div[7]/div/div[2]/section/section/main/div/div[3]/table" +
"/tbody/tr["+i+"]")).click();
webDriver.findElement(By.xpath("/html/body/div[7]/div/div[2]/section/main/div[1]/div[3]/table" +
"/tbody/tr["+i+"]/td[1]/div/label")).click();
Thread.sleep(1000);
}
Thread.sleep(3000);
webDriver.findElement(By.xpath("/html/body/div[7]/div/div[2]/section/footer[2]/button[2]")).click();
}
Thread.sleep(3000);
webDriver.findElement(By.xpath("/html/body/div[7]/div/div[2]/section/footer/button[2]")).click();
Thread.sleep(2000);
//提交
webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/section/div/button[3]")).click();

View File

@ -38,7 +38,7 @@ public class TestMain {
// testqd();
// testjjb();
// testGetData();
// testAccounters();
// testAccounters(); //值班账号
// testDailrb();
// testRCCL();
// testLog();
@ -53,7 +53,7 @@ public class TestMain {
log.error("错误信息", e);
}
}
}).start();
}).start();
}
private static void testAccounters() {
@ -91,16 +91,29 @@ public class TestMain {
//签到签退测试
private static void testqd() {
String content = GetBasicData.resolveGarbledCode("D:\\bns\\config\\account.txt");
String date = content.toString().split(";")[0].split(":")[1];
String num = content.toString().split(";")[1].split(":")[1];
if("1".equals(num)){
log.info("xgd,yj签到签退任务");
}else {
log.info("zkj,zh签到签退任务");
// String content = GetBasicData.resolveGarbledCode("D:\\bns\\config\\account.txt");
// String date = content.toString().split(";")[0].split(":")[1];
// String num = content.toString().split(";")[1].split(":")[1];
// if("1".equals(num)){
// log.info("xgd,yj签到签退任务");
// }else {
// log.info("zkj,zh签到签退任务");
// }
//// AutoWebTask autoWebTask = new AutoWebTask();
//// autoWebTask.dutyClockTask(2);
AutoWebTask autoWebTask = new AutoWebTask();
String yesterdayContent = GetBasicData.resolveGarbledCode("D:\\bns\\config\\昨日值班账号.txt");
String yesterdayLeaderSignOutPerson = yesterdayContent.toString().split("")[0].split("")[1];
String yesterdayLeaderSignOutPersonPassword = yesterdayContent.toString().split("")[1].split("")[1];
String yesterdaySignOutPerson = yesterdayContent.toString().split("")[2].split("")[1];
String yesterdaySignOutPersonPassword = yesterdayContent.toString().split("")[3].split("")[1];
try {
autoWebTask.dutySignOutTask(1,yesterdayLeaderSignOutPerson,yesterdayLeaderSignOutPersonPassword);
Thread.sleep(2000);
autoWebTask.dutySignOutTask(1,yesterdaySignOutPerson,yesterdaySignOutPersonPassword);
}catch (Exception e){
log.error("签退",e);
}
// AutoWebTask autoWebTask = new AutoWebTask();
// autoWebTask.dutyClockTask(2);
}
//交接班测试
@ -176,12 +189,13 @@ public class TestMain {
try {
//操作日志
AutoWebTask autoWebTask = new AutoWebTask();
String content = GetBasicData.resolveGarbledCode("D:\\bns\\config\\今日值班账号.txt");
String yesterdayContent = GetBasicData.resolveGarbledCode("D:\\bns\\config\\昨日值班账号.txt");
String yesterdayLeaderSignOutPerson = yesterdayContent.toString().split("")[0].split("")[1];
String yesterdayLeaderSignOutPersonPassword = yesterdayContent.toString().split("")[1].split("")[1];
// 应急值班账号
String emergencyPerson = content.toString().split("")[0].split("")[1];
String emergencyPersonPassword = content.toString().split("")[1].split("")[1];
Thread.sleep(2000);
autoWebTask.dutyAddLogsTask(2,emergencyPerson,emergencyPersonPassword);
autoWebTask.dutyAddLogsTask(1,yesterdayLeaderSignOutPerson,yesterdayLeaderSignOutPersonPassword);
count = 1;
Thread.sleep(1000);
log.info("count",count);
@ -243,13 +257,14 @@ public class TestMain {
String todaySignInLeaderPersonPassword = todayContent.toString().split("")[1].split("")[1];
String todaySignInPerson = todayContent.toString().split("")[2].split("")[1];
String todaySignInPersonPassword = todayContent.toString().split("")[3].split("")[1];
//昨日签退人员
String yesterdayLeaderSignOutPerson = yesterdayContent.toString().split("")[0].split("")[1];
String yesterdayLeaderSignOutPersonPassword = yesterdayContent.toString().split("")[1].split("")[1];
String yesterdaySignOutPerson = yesterdayContent.toString().split("")[2].split("")[1];
String yesterdaySignOutPersonPassword = yesterdayContent.toString().split("")[3].split("")[1];
if(DateTimeUtils.isEffectiveDate("17:26", "17:55")){
if(DateTimeUtils.isEffectiveDate("18:22", "18:55")){
//进行日报信息系统采集及获取工作
try {
if (logGatherCount == 0){
@ -272,7 +287,7 @@ public class TestMain {
} catch (IOException e) {
log.error("更新早上打卡人员", e);
}
}else if (DateTimeUtils.isEffectiveDate("06:00", "06:20")) {
}else if (DateTimeUtils.isEffectiveDate("06:29", "06:59")) {
//自动完成当值值班日报早报填写上报
if (dailyzao == 0) {
getTime(600);
@ -284,7 +299,7 @@ public class TestMain {
log.error("日报工作", e);
}
}
}else if (DateTimeUtils.isEffectiveDate("06:21", "06:45")) {
}else if (DateTimeUtils.isEffectiveDate("07:01", "07:29")) {
//完成值班日志填写提交晚班日志此次值班日志为总结前一天晚上的情况
if (logzao == 0) {
getTime(600);
@ -294,7 +309,7 @@ public class TestMain {
log.error("日志工作", e);
}
}
}else if (DateTimeUtils.isEffectiveDate("07:05", "07:30")) {
}else if (DateTimeUtils.isEffectiveDate("07:30", "07:59")) {
//自动完成当值值班签到值班主任值班人员都要签到
if ("error".equals(content)) {
log.error("读取打卡人员数据错误");
@ -328,7 +343,7 @@ public class TestMain {
}
}
}
}else if (DateTimeUtils.isEffectiveDate("07:35", "08:00")) {
}else if (DateTimeUtils.isEffectiveDate("08:00", "08:30")) {
if (jjbzao == 0 && jjbzao2 == 0){
getTime(600);
}
@ -416,7 +431,22 @@ public class TestMain {
}catch (Exception e) {
log.error("信息采集工作", e);
}
}else if (DateTimeUtils.isEffectiveDate("16:50", "17:20")) {
} else if (DateTimeUtils.isEffectiveDate("16:30", "17:00")) {
//进行日志信息系统采集及获取工作
try {
if (logGatherCount1 == 0){
logGatherCount1 = autoWebTask.getCaoLianData(2,emergencyPerson,emergencyPersonPassword);
}
Thread.sleep(3000);
if (dailyGatherCount1 == 0){
dailyGatherCount1= autoWebTask.getYuJingData(2,emergencyPerson,emergencyPersonPassword);
Thread.sleep(2000);
GetBasicData.getYuJingActionBasicData(2);
}
}catch (Exception e) {
log.error("信息采集工作", e);
}
} else if (DateTimeUtils.isEffectiveDate("17:01", "17:25")) {
//自动完成当值值班日报晚报填写上报
if (dailywan == 0) {
getTime(1200);

View File

@ -156,7 +156,7 @@ public class AutoMain {
Thread.sleep(10000);
//执行鼠标悬停动作-管理
Actions action = new Actions(webDriver);
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[5]/div/div/div[6]/span/span/div"));
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[6]/div/div/div[6]/span/span/div"));
action.moveToElement(wegl).build().perform();
Thread.sleep(300);
@ -201,7 +201,7 @@ public class AutoMain {
Thread.sleep(5000);
//执行鼠标悬停动作-管理
Actions action = new Actions(webDriver);
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[5]/div/div/div[2]/span/span/div"));
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[6]/div/div/div[2]/span/span/div"));
action.moveToElement(wegl).build().perform();
Thread.sleep(300);
log.info("执行鼠标悬停动作-管理");
@ -240,7 +240,7 @@ public class AutoMain {
Thread.sleep(5000);
//执行鼠标悬停动作-管理
Actions action = new Actions(webDriver);
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[5]/div/div/div[2]/span/span/div"));
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[6]/div/div/div[2]/span/span/div"));
action.moveToElement(wegl).build().perform();
Thread.sleep(300);
log.info("执行鼠标悬停动作-管理");
@ -283,7 +283,7 @@ public class AutoMain {
Thread.sleep(3000);
//执行鼠标悬停动作-管理
Actions action = new Actions(webDriver);
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[5]/div/div/div[6]/span/span/div"));
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[6]/div/div/div[6]/span/span/div"));
action.moveToElement(wegl).build().perform();
Thread.sleep(300);
@ -342,7 +342,7 @@ public class AutoMain {
Thread.sleep(5000);
//执行鼠标悬停动作-管理
Actions action = new Actions(webDriver);
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[5]/div/div/div[6]/span/span/div"));
WebElement wegl = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[6]/div/div/div[6]/span/span/div"));
action.moveToElement(wegl).build().perform();
Thread.sleep(300);

View File

@ -52,8 +52,8 @@ public class DataConfig {
/**
* 浏览器驱动地址
*/
// protected static final String drivePath = "E:\\bns\\chromedriver_win32\\geckodriver.exe";//个人本地
// protected static final String drivePath = "E:\\chromedriver_win32\\chromedriver.exe";//个人本地
// protected static final String drivePath = "D:\\bns\\chromedriver_win32\\geckodriver.exe";//个人本地
// protected static final String drivePath = "D:\\chromedriver_win32\\chromedriver.exe";//个人本地
protected static final String drivePath = "D:\\bns\\chromedriver_win32\\chromedriver.exe";//宿州客户地址

View File

@ -68,7 +68,7 @@ public class DutyDailyCheck {
//同意审核按钮点击
WebElement tyCheckBtn=webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/section/div/div[4]/div[1]/div[19]/button[4]"));
WebElement tyCheckBtn=webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/section/div/div[4]/div[1]/div[16]/button[4]"));
if(tyCheckBtn.isDisplayed()){
//存在
log.info("同意审核按钮存在-----------");

File diff suppressed because it is too large Load Diff

View File

@ -57,7 +57,7 @@ public class DutyLogIOp {
//退出当前iframe,进入到日报编辑iframe
webDriver.switchTo().defaultContent();
log.info("退出当前iframe----------");
Thread.sleep(1500);
Thread.sleep(5500);
//定位日志编辑iframe的标签
WebElement dutyEditIframe = webDriver.findElement(By.id("add-local-zbrzbz"));

View File

@ -3,10 +3,7 @@ package com.bonus.autoweb.task;
import com.bonus.autoweb.DateTimeUtils;
import com.bonus.autoweb.GetBasicData;
import com.bonus.autoweb.base.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
@ -18,8 +15,12 @@ import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 应急指挥中心打卡任务类
@ -164,39 +165,89 @@ public class AutoWebTask {
WebElement personLeaderNameEle = webDriver.findElement(By.xpath("//*[@id='pane-1']/div/div[3]/div/div/div[3" +
"]/table/tbody/tr[1]/td[2]/div/div/p[1]"));
String personLeaderName = personLeaderNameEle.getText();
log.info("今日值班人员:" + personLeaderName);
WebElement accountLeaderEle = webDriver.findElement(By.xpath("//*[@id='pane-1']/div/div[3]/div/div/div[3" +
"]/table/tbody/tr[1]/td[2]/div/div/p[2]"));
String accountLeader = accountLeaderEle.getText();
WebElement personLeaderPhoneEle = webDriver.findElement(By.xpath("//*[@id=\"pane-1\"]/div/div[3]/div/div/div[3]/table/tbody/tr[1]/td[3]/div/span"));
String personLeaderPhone = personLeaderPhoneEle.getText();
log.info("今日值班长:" + personLeaderName +";手机号:"+ personLeaderPhone);
//获取值班员账号姓名 账号名
// WebElement accountLeaderEle = webDriver.findElement(By.xpath("//*[@id='pane-1']/div/div[3]/div/div/div[3" +
// "]/table/tbody/tr[1]/td[2]/div/div/p[2]"));
// String accountLeader = accountLeaderEle.getText();
// log.info("今日值班长账号:" + accountLeader);
//获取值班员账号姓名 手机号
WebElement personNameEle = webDriver.findElement(By.xpath("//*[@id='pane-1']/div/div[3]/div/div/div[3" +
"]/table/tbody/tr[2]/td[2]/div/div/p[1]"));
String personName = personNameEle.getText();
log.info("今日值班人员:" + personName);
WebElement accountEle = webDriver.findElement(By.xpath("//*[@id='pane-1']/div/div[3]/div/div/div[3" +
"]/table/tbody/tr[2]/td[2]/div/div/p[2]"));
String account = accountEle.getText();
log.info("今日值班人员账号:" + account);
WebElement personPhoneEle = webDriver.findElement(By.xpath("//*[@id=\"pane-1\"]/div/div[3]/div/div/div[3]/table/tbody/tr[2]/td[3]/div/span"));
String personPhone = personPhoneEle.getText();
log.info("今日值班人员:" + personName +";手机号:"+ personPhone);
// WebElement accountEle = webDriver.findElement(By.xpath("//*[@id='pane-1']/div/div[3]/div/div/div[3" +
// "]/table/tbody/tr[2]/td[2]/div/div/p[2]"));
// String account = accountEle.getText();
// log.info("今日值班人员账号:" + account);
Thread.sleep(3000);
excelFile = new FileInputStream("D:\\bns\\config\\zhibanaccount.xlsx");
workbook = new XSSFWorkbook(excelFile);
Sheet datatypeSheet = workbook.getSheetAt(0);
String personLeaderPassword = "";
String personPassword = "";
String personLeaderPassword = "获取失败";
String personPassword = "获取失败";
String account = "获取失败";
String accountLeader = "获取失败";
int rowNum = 0;
for (Row row : datatypeSheet) {
String value = "";
StringBuilder lineValueBuilder = new StringBuilder();
for (Cell cell : row) {
value += cell.getStringCellValue() + "]]]";
// value += cell.getStringCellValue() + "]]]";
if (cell.getCellType() == CellType.NUMERIC) {
String phone = translateToPlainStr(String.valueOf(cell.getNumericCellValue()));
lineValueBuilder.append(phone);
} else {
lineValueBuilder.append(cell.getStringCellValue());
}
// 除了最后一个单元格每个单元格后追加分隔符
if (cell.getColumnIndex() < row.getLastCellNum() - 1) {
lineValueBuilder.append("]]]");
}
}
value = value.substring(0, value.length() - 3);
if (value.contains(account)) {
personPassword = value.split("]]]")[2];
String value = String.valueOf(lineValueBuilder);
// log.info(value);
try{
if (value.contains(personPhone)) {
personPassword = value.split("]]]")[2];
account = value.split("]]]")[1];
// matchedRecords.add(value);
// if (matchedRecords.size() == 1) {
// // 只有一个匹配的记录直接提取账号和密码信息
// String record = matchedRecords.get(0);
// personPassword = record.split("]]]")[2];
// account = record.split("]]]")[1];
// } else {
// for (String record : matchedRecords) {
// // 获取手机号或其他用于进一步判断的信息
// if (record.contains(personLeaderPhone)) {
// personPassword = record.split("]]]")[2];
// account = record.split("]]]")[1];
// }
// }
// }
}
}catch (IndexOutOfBoundsException ignored){
log.error("出现异常:"+personName+"账号内容出错,在表格的第"+rowNum+"行附近");
}
if (value.contains(accountLeader)) {
personLeaderPassword = value.split("]]]")[2];
//值班长账号密码获取
try{
if (value.contains(personLeaderPhone)) {
personLeaderPassword = value.split("]]]")[2];
accountLeader = value.split("]]]")[1];
}
}catch (IndexOutOfBoundsException ignored){
log.error("出现异常:"+personLeaderName+"账号内容出错,在表格的第"+rowNum+"行附近");
}
rowNum++;
}
AutoUtils.write("D:\\bns\\config\\今日值班账号.txt", "今日值班长账号:"+accountLeader+";密码:"+personLeaderPassword+"\n" +
"今日值班员账号:"+account+";密码:"+personPassword+"");
excelFile.close();
@ -209,6 +260,25 @@ public class AutoWebTask {
return count;
}
public String translateToPlainStr(String number) {
String regEx="^([\\+|-]?\\d+(.{0}|.\\d+))[Ee]{1}([\\+|-]?\\d+)$";
// 编译正则表达式
Pattern pattern = Pattern.compile(regEx);
// 忽略大小写的写法
// Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(number);
// 字符串是否与正则表达式相匹配
boolean rs = matcher.matches();
// 判断是否为字符串的科学计数法
if(rs){
// 科学计数法转数字
BigDecimal originValue = new BigDecimal(number);
// 数字转字符串
return originValue.toPlainString();
}
return number;
}
/**
* 交接班任务