Task.class
package com.rdmwork;
/**
* @author: zhaoxu
* @description:
*/
public class Task {
String taskId;
String viewState;
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getViewState() {
return viewState;
}
public void setViewState(String viewState) {
this.viewState = viewState;
}
@Override
public String toString() {
return "Task{" +
"taskId='" + taskId + '\'' +
", viewState='" + viewState + '\'' +
'}';
}
}
RdmWork.class
package com.rdmwork;
import com.alibaba.fastjson.JSONObject;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author: zhaoxu
* @description:
*/
public class RdmWork {
final static String headerAgent = "User-Agent";
final static String headerAgentArg = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36";
static Pattern pattern = Pattern.compile("\"[^\"]*");
public static void main(String[] args) throws IOException {
String begin_date = "2020-11-27";
String end_date = "2020-11-27";
String username_rdm = "账号";
String password_rdm = "密码";
String username_supcon = "账号";
String password_supcon = "密码";
//登录门户获取工作日
loginSUPCON("", username_supcon, password_supcon);
ArrayList workDayList = getWorkDays(begin_date, end_date);
ArrayList sortWorkDays = sortStrings(workDayList.iterator());
//登录RDM
loginRDM("http://rdm.rd.supcon.com:2000/j_security_check", username_rdm, password_rdm);
ArrayList<Task> tasks = findTasks();
Task taskId = tasks.get(0);
submit(taskId, sortWorkDays);
}
public static ArrayList sortStrings(Iterator iterator) {
String[] workDays = new String[100];
ArrayList sortWorkDays = new ArrayList();
int size = 0;
while (iterator.hasNext()) {
String[] node = iterator.next().toString().split("=");
workDays[size] = node[0];
size++;
}
for (int i = 0; i < size; i++) {
for (int j = i + 1; j < size; j++) {
String[] numI = workDays[i].split("-");
String[] numJ = workDays[j].split("-");
//按照31进制进行排序
Integer sumI = Integer.parseInt(numI[0]) * 29791 + Integer.parseInt(numI[1]) * 961 + Integer.parseInt(numI[2]) * 31;
Integer sumJ = Integer.parseInt(numJ[0]) * 29791 + Integer.parseInt(numJ[1]) * 961 + Integer.parseInt(numJ[2]) * 31;
if (sumI <= sumJ) {
String temp = workDays[j];
workDays[j] = workDays[i];
workDays[i] = temp;
}
}
sortWorkDays.add(workDays[i]);
}
return sortWorkDays;
}
public static void loginRDM(String url, String username, String password) throws IOException {
Base64.Encoder encoder = Base64.getEncoder();
String pwd = encoder.encodeToString(password.getBytes(StandardCharsets.UTF_8));
String form = "isExpires=1&sessionIndex=''&j_username=" + username + "&j_showcode=N&j_validatecode=''&BROWSER_VERSION=1&REMOTE_LANGUAGE=undefined" +
"&j_password=" + pwd;
CookieManager manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
CookieHandler.setDefault(manager);
String post = post(url, form);
}
public static ArrayList getWorkDays(String begin_date, String end_date) throws IOException {
String dayType = getJson("https://ehr.supcon.com/RedseaPlatform/KqCount.mc?method=geRenPaibanByMonth&type=2&year="
+ begin_date.split("-")[0] + "&month=" + begin_date.split("-")[1]);
JSONObject dayJson = JSONObject.parseObject(dayType);
HashMap<String, String> dayWork = new HashMap<>();
String caleHtml = dayJson.get("caleHtml").toString();
String split = caleHtml.split("日 一 二 三 四 五 六 ")[1];
for (int i = 0; i < split.split(" ").length; i = i + 2) {
dayWork.put(begin_date.split("-")[0] + "-" + begin_date.split("-")[1] + "-" + split.split(" ")[i], split.split(" ")[i + 1]);
}
String dayType1 = getJson("https://ehr.supcon.com/RedseaPlatform/KqCount.mc?method=geRenPaibanByMonth&type=2&year="
+ end_date.split("-")[0] + "&month=" + end_date.split("-")[1]);
JSONObject dayJson1 = JSONObject.parseObject(dayType1);
String caleHtml1 = dayJson1.get("caleHtml").toString();
String split1 = caleHtml1.split("日 一 二 三 四 五 六 ")[1];
for (int i = 0; i < split1.split(" ").length; i = i + 2) {
dayWork.put(end_date.split("-")[0] + "-" + end_date.split("-")[1] + "-" + split1.split(" ")[i], split1.split(" ")[i + 1]);
}
Iterator iterator = dayWork.entrySet().iterator();
ArrayList arrayList = new ArrayList();
String[] numBegin = begin_date.split("-");
String[] numEnd = end_date.split("-");
//按照31进制选择
Integer sumBegin = Integer.parseInt(numBegin[0]) * 29791 + Integer.parseInt(numBegin[1]) * 961 + Integer.parseInt(numBegin[2]) * 31;
Integer sumEnd = Integer.parseInt(numEnd[0]) * 29791 + Integer.parseInt(numEnd[1]) * 961 + Integer.parseInt(numEnd[2]) * 31;
while (iterator.hasNext()) {
String[] node = iterator.next().toString().split("=");
String[] nodeDate = node[0].split("-");
Integer sunN = Integer.parseInt(nodeDate[0]) * 29791 + Integer.parseInt(nodeDate[1]) * 961 + Integer.parseInt(nodeDate[2]) * 31;
if (node[1].equals("正常") && sunN >= sumBegin && sunN <= sumEnd) {
arrayList.add(node[0]);
}
}
return arrayList;
}
private static String getJson(String url) throws IOException {
Document doc = Jsoup.connect(url)
.ignoreContentType(true)
.get();
return doc.select("body").text();
}
public static String loginSUPCON(String url, String username, String password) throws IOException {
final String loginURL = "https://portal.supcon.com/cas-web/login?service=https%3A%2F%2Fehr.supcon.com%2FRedseaPlatform%2F";
String form = "portal_username=" + username + "&password=" + password + "<=xxx&_eventId=submit&username=" + username;
final String headerAgent = "User-Agent";
final String headerAgentArg = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36";
String code = "";
byte[] buffer;
String all = "";
int length;
String lt = "";
try {
CookieManager manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
CookieHandler.setDefault(manager);
HttpURLConnection httpURLConnection = (HttpURLConnection) (new URL(loginURL).openConnection());
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty(headerAgent, headerAgentArg);
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
buffer = new byte[1024];
while ((length = inputStream.read(buffer)) != -1) {
all = all + new String(buffer, 0, length, "UTF-8");
}
httpURLConnection.disconnect();
// 通过第一次打开的页面获取lt
lt = all.split("<input type=\"hidden\" name=\"lt\" value=\"")[1].split("\" />")[0];
all = null;
httpURLConnection = (HttpURLConnection) (new URL(loginURL).openConnection());
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty(headerAgent, headerAgentArg);
httpURLConnection.setDoOutput(true);
httpURLConnection.connect();
httpURLConnection.getOutputStream().write(form.replace("xxx", lt).getBytes("UTF-8"));
InputStream input = httpURLConnection.getInputStream();
String login = "";
while ((length = input.read(buffer)) != -1) {
login += (new String(buffer, 0, length, "UTF-8"));
}
try {
if (login.split("<title>SUPCON – ")[0] != "" && login.split("<title>SUPCON – ")[1].split("</title>")[0].equals("中控统一登录平台")) {
code = "false";
}
} catch (ArrayIndexOutOfBoundsException e) {
code = "true";
}
httpURLConnection.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
}
return code;
}
public static void submit(Task task, ArrayList<String> sortWorkDays) throws IOException {
Scanner in = new Scanner(System.in);
int rate = 20;
String operate_remark = "";
for (int i = sortWorkDays.size() - 1; i >= 0; i--) {
System.out.println(sortWorkDays.get(i) + "这天你干了啥:");
operate_remark = in.next();
if (rate > 100) {
rate = 20;
}
Map data = new HashMap<>();
data.put("AJAXREQUEST", "j_id_jsp_872742270_0");
data.put("taskForm", "taskForm");
data.put("report_action_date", sortWorkDays.get(i));
data.put("report_rate", String.valueOf(rate));
data.put("report_in_work", "7.5");
data.put("report_end_date", "");
data.put("report_remain_work", "0");
data.put("operate_remark", operate_remark);
data.put("report_question", "");
data.put("objectId", task.taskId);
data.put("taskId", task.taskId);
data.put("workflowType", "TSK");
data.put("action", "1");
data.put("ueditor_image_urls", "");
data.put("milestoneDate", "");
data.put("formerDate", "");
data.put("report_id", getReportId(task.taskId, sortWorkDays.get(i)));
data.put("javax.faces.ViewState", task.getViewState());
data.put("taskForm:save", "taskForm:save");
String s = postMap("http://rdm.rd.supcon.com:2000/pages/task/entity.jsf", data);
rate += 20;
}
}
public static String findViewState() throws IOException {
String s = get("http://rdm.rd.supcon.com:2000/pages/task/list/myTask.jsf", "");
return s.split("id=\"javax.faces.ViewState\" value=\"")[1].split("\" />")[0];
}
public static String get(String url, String params) throws IOException {
String response = "";
HttpURLConnection httpURLConnection = (HttpURLConnection) (new URL(url).openConnection());
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty(headerAgent, headerAgentArg);
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
byte[] buffer;
int length;
buffer = new byte[1024];
while ((length = inputStream.read(buffer)) != -1) {
response = response + new String(buffer, 0, length, "UTF-8");
}
httpURLConnection.disconnect();
}
return response;
}
public static String post(String url, String params) throws IOException {
String response = "";
HttpURLConnection httpURLConnection = (HttpURLConnection) (new URL(url).openConnection());
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty(headerAgent, headerAgentArg);
httpURLConnection.setDoOutput(true);
httpURLConnection.connect();
httpURLConnection.getOutputStream().write(params.getBytes("UTF-8"));
httpURLConnection.getInputStream();
InputStream inputStream = httpURLConnection.getInputStream();
byte[] buffer;
int length;
buffer = new byte[1024];
while ((length = inputStream.read(buffer)) != -1) {
response = response + new String(buffer, 0, length, "UTF-8");
}
httpURLConnection.disconnect();
return response;
}
public static String postMap(String url, Map<String, String> data) throws IOException {
Connection connect = Jsoup.connect(url);
connect.data(data);
Document post = connect.post();
return post.toString();
}
public static String getReportId(String taskId, String date) throws IOException {
String param = "callCount=1&page=/pages/task/entity.jsf?taskId=" + taskId + "&action=1&planRight=&date=&httpSessionId=E82B2DA430911A0643163E9B861475F5&scriptSessionId" +
"=750F49C3DA1731E1EF25170F88D6526D264&" +
"c0-scriptName=jtaskEntityBean&c0-methodName=dynGetReport&c0-id=0&c0-param0=string:" + taskId + "&c0-param1=null:null&batchId=0&";
String s = post("http://rdm.rd.supcon.com:2000/dwr/call/plaincall/jtaskEntityBean.dynGetReport.dwr", param);
Matcher matcher = pattern.matcher(s);
if (matcher.find()) {
}
return matcher.group().split("\"")[1];
}
static ArrayList<Task> findTasks() throws IOException {
Map data = new HashMap<>();
data.put("AJAXREQUEST", "j_id_jsp_772476017_0");
data.put("operate", "operate");
data.put("page", "1");
data.put("cate", "22");
data.put("type", "TSK");
data.put("module", "TSK");
data.put("planId", "");
data.put("refreshType", "1");
data.put("isInit", "");
data.put("nodeId", "value=\"");
data.put("projectIds", "");
data.put("taskName", "");
data.put("emptySearch", "");
data.put("baseSearch", "");
data.put("hasPlanOwner", "N");
data.put("showFCTask", "N");
data.put("condition", "");
data.put("isOwner", "");
data.put("light", "");
data.put("pjtTask", "");
data.put("userId", "");
data.put("objectId", "");
data.put("filterIds", "");
data.put("operate:_path", "");
data.put("operate:_fileName", "");
data.put("operate:_fileContentType", "");
data.put("javax.faces.ViewState", findViewState());
data.put("operate:refreshFull", "operate:refreshFull");
String s = postMap("http://rdm.rd.supcon.com:2000/pages/task/list/myTask.jsf", data);
String[] split = s.split("<tr class=\"body-row\" id=\"");
ArrayList<Task> taskList = new ArrayList<Task>();
for (int i = 1; i < split.length; i++) {
Task task = new Task();
task.setTaskId(split[i].split("\" status")[0]);
String viewState = getViewState(task.getTaskId()).split("id=\"javax.faces.ViewState\" value=\"")[1].split("\" /></span>")[0];
task.setViewState(viewState);
taskList.add(task);
}
return taskList;
}
public static String getViewState(String id) throws IOException {
return get("http://rdm.rd.supcon.com:2000/pages/task/entity.jsf?taskId=" + id + "&action=1&planRight=&date=", "");
}
}