开源共享

master
王兵 4 months ago
parent a4c59e9ba5
commit a2a9e1c60e

2
.gitignore vendored

@ -21,3 +21,5 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.idea/

@ -0,0 +1,47 @@
## 禅道java版sdk工具包
基于禅道开源版18.1封装的java版sdk工具包对于高版本的是否兼容还需要测试
### 功能描述
利用禅道开放的第三方应用接口封装的java版sdk工具包可通过java代码的方式创建项目、执行、任务等常用接口。
大部分接口是直接使用的禅道开放的接口,小部分接口是通过模拟浏览器的方式实现的。
### 免责声明
SDK源码编写完成后仅简单应用了项目、执行、任务的创建、开始、关闭等功能未进行大规模测试。
此仓库的源码是从项目上剥离出来的源码,使用时请备份数据,并进行严格测试,确保安全后再上线使用。
### 开发环境
jdk 8+
### 构建工具
Maven 3+
### 编译命令
```
mvn package
```
如果编译报错可以尝试更换maven版本或使用最新maven版本
### 使用说明
#### 引用方式
1. 直接引入jar包
2. 引入源码
#### 创建凭证
使用禅道管理员账号登录,依次找到左侧菜单栏【后台】-【二次开发】-【应用】-【添加应用】
得到代号+密钥就是接入凭证
#### 创建管理账号
创建一个专门的管理账号拥有管理员权限。例如我创建的是pms账号
#### 使用方法
参考 ClientTest.java
##### 版本说明
###### v0.0.1-SNAPSHOT
1. 项目的创建、删除、修改、开始、激活、关闭
2. 执行的创建、删除、开始、激活、关闭
3. 任务的创建、删除、开始、激活、关闭、完成
4. 用户的获取
### 联系方式
E-Mailwangbing@wbsite.xyz

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tzcmcc.zentao.sdk</groupId>
<artifactId>zentao-java-sdk</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>zentao-java-sdk</name>
<description>zentao-java-sdk</description>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.test.skip>true</maven.test.skip>
</properties>
<repositories>
<!-- 将中央仓库地址指向阿里云聚合仓库,提高下载速度 -->
<repository>
<id>aliyun</id>
<name>Aliyun Repository</name>
<layout>default</layout>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>
<pluginRepositories>
<!-- 将插件的仓库指向阿里云聚合仓库解决低版本maven下载插件异常或提高下载速度 -->
<pluginRepository>
<id>aliyun</id>
<name>Aliyun Repository</name>
<url>https://maven.aliyun.com/repository/public</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<dependencies>
<!-- 糊涂工具包含常用API避免重复造轮子 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.0.M2</version>
</dependency>
<!-- html解析工具 -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- 项目名称 -->
<finalName>${project.artifactId}-${project.version}</finalName>
<!-- 默认的主代码目录 -->
<sourceDirectory>src/main/java</sourceDirectory>
<!-- 默认的测试代码目录 -->
<testSourceDirectory>src/test/java</testSourceDirectory>
</build>
</project>

@ -0,0 +1,15 @@
package xyz.wbsite.zentao.sdk;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class Constant {
public final static String SUCCESS_KEY = "success";
public final static String LOGIN_OVERTIME = "登录已超时";
}

@ -0,0 +1,105 @@
package xyz.wbsite.zentao.sdk;
import xyz.wbsite.zentao.sdk.user.ent.ZtUser;
import xyz.wbsite.zentao.sdk.user.req.ZtUserListAllRequest;
import xyz.wbsite.zentao.sdk.user.rsp.ZtUserListAllResponse;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
*
* <p>
* 18.1
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZentaoClient {
/**
*
*/
private static Map<String, ZentaoInstance> cache = new ConcurrentHashMap<>();
/**
*
*/
private final ZentaoInstance managerInstance;
/**
*
*/
private final String serviceUrl;
/**
* code
*/
private final String serviceCode;
/**
* key
*/
private final String serviceKey;
/**
*
*
* @param serviceUrl
* @param serviceCode code
* @param serviceKey key
* @param managerAccount
*/
public ZentaoClient(String serviceUrl, String serviceCode, String serviceKey, String managerAccount) {
this.serviceUrl = serviceUrl;
this.serviceCode = serviceCode;
this.serviceKey = serviceKey;
this.managerInstance = new ZentaoInstance(this, managerAccount);
}
/**
*
* <p>
* managerAccount
*/
public List<ZtUser> listAllUser() {
ZtUserListAllResponse ztUserListAllResponse = managerInstance.getZtUserService().listAll(new ZtUserListAllRequest());
if (!ztUserListAllResponse.isSuccess()) {
throw new IllegalArgumentException(ztUserListAllResponse.getMessage());
}
return ztUserListAllResponse.getResult();
}
/**
*
*/
public ZentaoInstance loginAs(String account) {
if (cache.containsKey(account)) {
return cache.get(account);
}
cache.put(account, new ZentaoInstance(this, account));
return cache.get(account);
}
/**
*
*/
public ZentaoInstance loginAsPms() {
return managerInstance;
}
public String getServiceUrl() {
return serviceUrl;
}
public String getServiceCode() {
return serviceCode;
}
public String getServiceKey() {
return serviceKey;
}
}

@ -0,0 +1,165 @@
package xyz.wbsite.zentao.sdk;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.http.HttpUtil;
import cn.hutool.log.StaticLog;
import xyz.wbsite.zentao.sdk.execution.ZtExecutionService;
import xyz.wbsite.zentao.sdk.project.ZtProjectService;
import xyz.wbsite.zentao.sdk.task.ZtTaskService;
import xyz.wbsite.zentao.sdk.user.ZtUserService;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZentaoInstance {
/**
*
*/
private ZentaoClient client;
/**
*
*/
private String account;
/**
*
*/
private String zentaosid;
private static final int DEFAULT_CONNECT_TIMEOUT = 3 * 1000;
private static final int DEFAULT_READ_TIMEOUT = 10 * 1000;
private final ZtProjectService ztProjectService = new ZtProjectService(this);
private final ZtExecutionService ztExecutionService = new ZtExecutionService(this);
private final ZtTaskService ztTaskService = new ZtTaskService(this);
private final ZtUserService ztUserService = new ZtUserService(this);
public ZentaoInstance(ZentaoClient client, String account) {
this.client = client;
this.account = account;
}
public ZtProjectService getZtProjectService() {
return ztProjectService;
}
public ZtExecutionService getZtExecutionService() {
return ztExecutionService;
}
public ZtTaskService getZtTaskService() {
return ztTaskService;
}
public ZtUserService getZtUserService() {
return ztUserService;
}
private boolean login(String account) {
String time = String.valueOf(System.currentTimeMillis() / 1000);
String token = SecureUtil.md5(client.getServiceCode() + client.getServiceKey() + time);
String url = StrUtil.format(client.getServiceUrl() + "/api.php?m=user&f=apilogin&account={}&code={}&time={}&token={}", account, client.getServiceCode(), time, token);
HttpRequest request = HttpUtil.createGet(url);
HttpResponse response = request.execute();
if (HttpStatus.HTTP_OK != response.getStatus()) {
System.err.println("请求失败");
return false;
} else {
this.zentaosid = response.getCookieValue("zentaosid");
StaticLog.info("禅道登录凭证:{}", this.zentaosid);
}
return true;
}
/**
*
*
* @return
*/
public synchronized boolean checkStatus() {
try {
HttpRequest httpRequest = createTestUrl();
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
return false;
}
String body = execute.body();
String string = Convert.unicodeToStr(body);
if (!StrUtil.contains(string, Constant.LOGIN_OVERTIME)) {
return true;
}
} catch (Exception ignored) {
}
// 登录状态异常后尝试登录
return login(account);
}
public HttpRequest createTestUrl() {
String fullUrl = client.getServiceUrl();
HttpRequest request = HttpUtil.createGet(fullUrl);
setDefault(request, fullUrl);
request.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
request.header("Upgrade-Insecure-Requests", "1");
return request;
}
public HttpRequest createGet(String url) {
checkStatus();
String fullUrl = client.getServiceUrl() + url;
HttpRequest request = HttpUtil.createGet(fullUrl);
setDefault(request, fullUrl);
return request;
}
public HttpRequest createGetForHtml(String url) {
checkStatus();
String fullUrl = client.getServiceUrl() + url;
HttpRequest request = HttpUtil.createGet(fullUrl);
setDefault(request, fullUrl);
request.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
request.header("Upgrade-Insecure-Requests", "1");
return request;
}
public HttpRequest createPost(String url) {
checkStatus();
String fullUrl = client.getServiceUrl() + url;
HttpRequest request = HttpUtil.createPost(fullUrl);
setDefault(request, fullUrl);
return request;
}
public HttpRequest createPostForHtml(String url) {
checkStatus();
String fullUrl = client.getServiceUrl() + url;
HttpRequest request = HttpUtil.createPost(fullUrl);
setDefault(request, fullUrl);
request.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
request.header("Upgrade-Insecure-Requests", "1");
return request;
}
public void setDefault(HttpRequest request, String url) {
request.setConnectionTimeout(DEFAULT_CONNECT_TIMEOUT);
request.setReadTimeout(DEFAULT_READ_TIMEOUT);
request.header("Accept", "application/json, text/javascript, */*; q=0.01");
request.header("Accept-Encoding", "gzip, deflate");
request.header("Accept-Language", "zh-CN,zh;q=0.9");
request.header("Connection", "keep-alive");
request.header("Host", client.getServiceUrl().replaceAll("http[s]?://", ""));
request.header("Origin", client.getServiceUrl());
request.header("Referer", url);
request.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36");
request.header("X-Requested-With", "XMLHttpRequest");
request.cookie("zentaosid=" + this.zentaosid);
}
}

@ -0,0 +1,407 @@
package xyz.wbsite.zentao.sdk.execution;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.StaticLog;
import xyz.wbsite.zentao.sdk.Constant;
import xyz.wbsite.zentao.sdk.ZentaoInstance;
import xyz.wbsite.zentao.sdk.execution.ent.ZtExecution;
import xyz.wbsite.zentao.sdk.execution.req.ZtExecutionActivateRequest;
import xyz.wbsite.zentao.sdk.execution.req.ZtExecutionCloseRequest;
import xyz.wbsite.zentao.sdk.execution.req.ZtExecutionCreateRequest;
import xyz.wbsite.zentao.sdk.execution.req.ZtExecutionDeleteRequest;
import xyz.wbsite.zentao.sdk.execution.req.ZtExecutionStartRequest;
import xyz.wbsite.zentao.sdk.execution.rsp.ZtExecutionActivateResponse;
import xyz.wbsite.zentao.sdk.execution.rsp.ZtExecutionCloseResponse;
import xyz.wbsite.zentao.sdk.execution.rsp.ZtExecutionCreateResponse;
import xyz.wbsite.zentao.sdk.execution.rsp.ZtExecutionDeleteResponse;
import xyz.wbsite.zentao.sdk.execution.rsp.ZtExecutionGetResponse;
import xyz.wbsite.zentao.sdk.execution.rsp.ZtExecutionStartResponse;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
* /
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionService {
private ZentaoInstance zentaoInstance;
public ZtExecutionService(ZentaoInstance zentaoInstance) {
this.zentaoInstance = zentaoInstance;
}
/**
*
*/
public ZtExecutionCreateResponse create(ZtExecutionCreateRequest projectCreateRequest) {
ZtExecutionCreateResponse response = new ZtExecutionCreateResponse();
try {
String url = StrUtil.format("/execution-create-{}-0-0-productID=0,branchID=0.json", projectCreateRequest.getProject());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("project", projectCreateRequest.getProject());
httpRequest.form("name", projectCreateRequest.getName());
httpRequest.form("code", projectCreateRequest.getCode());
httpRequest.form("begin", projectCreateRequest.getBegin());
httpRequest.form("end", projectCreateRequest.getEnd());
httpRequest.form("delta", projectCreateRequest.getDelta());
httpRequest.form("days", projectCreateRequest.getDays());
httpRequest.form("lifetime", projectCreateRequest.getLifetime());
httpRequest.form("status", "wait");
httpRequest.form("plans[][]", "");
httpRequest.form("team", projectCreateRequest.getTeam());
httpRequest.form("teams", projectCreateRequest.getTeams());
httpRequest.form("PO", projectCreateRequest.getPo());
httpRequest.form("QD", projectCreateRequest.getQd());
httpRequest.form("PM", projectCreateRequest.getPm());
httpRequest.form("RD", projectCreateRequest.getRd());
for (String teamMember : projectCreateRequest.getTeamMembers()) {
httpRequest.form("teamMembers[]", teamMember);
}
httpRequest.form("desc", projectCreateRequest.getDesc());
httpRequest.form("acl", projectCreateRequest.getAcl());
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
// 返回 {"result":"success","message":"保存成功","id":"366"}
StaticLog.info(body);
if (body.contains(Constant.SUCCESS_KEY)) {
JSONObject entries = JSONUtil.parseObj(body);
response.setId(Convert.toInt(entries.get("id")));
response.setSuccess(true);
response.setMessage("请求成功");
return response;
}
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtExecutionStartResponse start(ZtExecutionStartRequest projectStartRequest) {
ZtExecutionStartResponse response = new ZtExecutionStartResponse();
try {
String url = StrUtil.format("/execution-start-{}.json", projectStartRequest.getExecutionId());
StaticLog.info(url);
HttpRequest request = zentaoInstance.createPost(url);
request.form("status", "doing");
request.form("realBegan", projectStartRequest.getRealBegan());
request.form("comment", projectStartRequest.getComment());
request.form("uid", RandomUtil.randomString(13));
HttpResponse execute = request.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
// 返回的是html
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtExecutionCloseResponse close(ZtExecutionCloseRequest projectCloseRequest) {
ZtExecutionCloseResponse response = new ZtExecutionCloseResponse();
try {
String url = StrUtil.format("/execution-close-{}.html", projectCloseRequest.getExecutionId());
StaticLog.info(url);
HttpRequest request = zentaoInstance.createPost(url);
request.form("status", "closed");
request.form("realEnd", projectCloseRequest.getRealEnd());
request.form("comment", projectCloseRequest.getComment());
request.form("uid", RandomUtil.randomString(13));
HttpResponse execute = request.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
StaticLog.info(Convert.unicodeToStr(body));
// 返回的是html
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (Exception e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtExecutionActivateResponse activate(ZtExecutionActivateRequest projectActivateRequest) {
ZtExecutionActivateResponse response = new ZtExecutionActivateResponse();
try {
String url = StrUtil.format("/execution-close-{}.html", projectActivateRequest.getExecutionId());
StaticLog.info(url);
HttpRequest request = zentaoInstance.createPost(url);
request.form("begin", projectActivateRequest.getBegin());
request.form("end", projectActivateRequest.getEnd());
request.form("readjustTime", projectActivateRequest.getReadjustTime());
request.form("status", "doing");
request.form("comment", projectActivateRequest.getComment());
request.form("uid", RandomUtil.randomString(13));
HttpResponse execute = request.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
StaticLog.info(Convert.unicodeToStr(body));
// 返回的是html
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (Exception e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtExecutionDeleteResponse delete(ZtExecutionDeleteRequest projectDeleteRequest) {
ZtExecutionDeleteResponse response = new ZtExecutionDeleteResponse();
try {
String url = StrUtil.format("/execution-delete-{}.html", projectDeleteRequest.getExecutionId());
StaticLog.info(url);
HttpRequest request = zentaoInstance.createPost(url);
HttpResponse execute = request.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
StaticLog.info(Convert.unicodeToStr(body));
// 返回的是html
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (Exception e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
* <p>
* session
*/
private boolean setQuery(int projectId, String fieldName, String fieldValue) {
try {
String url = StrUtil.format("/search-buildQuery.html");
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("fieldname", "");
httpRequest.form("fieldid", "");
httpRequest.form("fieldstatus", "0");
httpRequest.form("fieldproject", "0");
httpRequest.form("fieldPM", "");
httpRequest.form("fieldopenedBy", "");
httpRequest.form("fieldopenedDate", "");
httpRequest.form("fieldbegin", "");
httpRequest.form("fieldend", "");
httpRequest.form("fieldrealBegan", "");
httpRequest.form("fieldrealEnd", "");
httpRequest.form("fieldclosedBy", "");
httpRequest.form("fieldlastEditedDate", "");
httpRequest.form("fieldclosedDate", "");
httpRequest.form("fieldteamCount", "");
httpRequest.form("andOr1", "AND");
httpRequest.form("field1", fieldName);
httpRequest.form("operator1", "=");
httpRequest.form("value1", fieldValue);
httpRequest.form("andOr2", "and");
httpRequest.form("field2", "id");
httpRequest.form("operator2", "=");
httpRequest.form("value2", "");
httpRequest.form("andOr3", "and");
httpRequest.form("field3", "status");
httpRequest.form("operator3", "=");
httpRequest.form("value3", "0");
httpRequest.form("groupAndOr", "and");
httpRequest.form("andOr4", "AND");
httpRequest.form("field4", "project");
httpRequest.form("operator4", "=");
httpRequest.form("value4", projectId);
httpRequest.form("andOr5", "and");
httpRequest.form("field5", "PM");
httpRequest.form("operator5", "=");
httpRequest.form("value5", "");
httpRequest.form("andOr6", "and");
httpRequest.form("field6", "openedBy");
httpRequest.form("operator6", "=");
httpRequest.form("value6", "");
httpRequest.form("module", "execution");
httpRequest.form("actionURL", "/execution-all-bySearch-order_asc-0-myQueryID.html");
httpRequest.form("groupItems", "3");
httpRequest.form("formType", "lite");
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
return false;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
return execute.getStatus() == HttpStatus.HTTP_OK;
} catch (Exception e) {
StaticLog.error(e);
}
return false;
}
/**
*
*/
public ZtExecutionGetResponse getByName(int projectId, String name) {
ZtExecutionGetResponse response = new ZtExecutionGetResponse();
try {
boolean setQuery = setQuery(projectId, "name", name);
if (!setQuery) {
response.setSuccess(false);
response.setMessage("设置查询参数失败");
return response;
}
HttpRequest httpRequest = zentaoInstance.createGetForHtml("/execution-all-bySearch-order_asc-0-myQueryID.html");
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
Document parse = Jsoup.parse(body);
Elements trs = parse.select(".main-table .sortable tr");
if (trs.size() == 1) {
Element tr = trs.get(0);
ZtExecution ztExecution = new ZtExecution();
ztExecution.setId(Convert.toInt(tr.select(".c-id").text()));
ztExecution.setName(tr.select(".c-name").attr("title"));
ztExecution.setCode(tr.select(".c-code").attr("title"));
ztExecution.setProjectId(projectId);
ztExecution.setProjectName(tr.select(".c-project").attr("title"));
ztExecution.setPm(tr.select(".c-PM").text());
ztExecution.setStatus(tr.select(".c-status").text());
ztExecution.setProgress(tr.select(".c-progress").text());
ztExecution.setBegin(tr.select(".c-begin").text());
ztExecution.setEnd(tr.select(".c-end").text());
ztExecution.setEstimate(tr.select(".c-estimate").text());
ztExecution.setConsumed(tr.select(".c-consumed").text());
ztExecution.setLeft(tr.select(".c-left").text());
response.setSuccess(true);
response.setMessage("请求成功");
response.setResult(ztExecution);
return response;
}
StaticLog.info(body);
response.setMessage("无数据");
return response;
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtExecutionGetResponse getByCode(int projectId, String code) {
ZtExecutionGetResponse response = new ZtExecutionGetResponse();
try {
boolean setQuery = setQuery(projectId, "code", code);
if (!setQuery) {
response.setSuccess(false);
response.setMessage("设置查询参数失败");
return response;
}
HttpRequest httpRequest = zentaoInstance.createGetForHtml("/execution-all-bySearch-order_asc-0-myQueryID.html");
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
Document parse = Jsoup.parse(body);
Elements trs = parse.select(".main-table .sortable tr");
if (trs.size() == 1) {
Element tr = trs.get(0);
ZtExecution ztExecution = new ZtExecution();
ztExecution.setId(Convert.toInt(tr.select(".c-id").text()));
ztExecution.setName(tr.select(".c-name").attr("title"));
ztExecution.setCode(tr.select(".c-code").attr("title"));
ztExecution.setProjectId(projectId);
ztExecution.setProjectName(tr.select(".c-project").attr("title"));
ztExecution.setPm(tr.select(".c-PM").text());
ztExecution.setStatus(tr.select(".c-status").text());
ztExecution.setProgress(tr.select(".c-progress").text());
ztExecution.setBegin(tr.select(".c-begin").text());
ztExecution.setEnd(tr.select(".c-end").text());
ztExecution.setEstimate(tr.select(".c-estimate").text());
ztExecution.setConsumed(tr.select(".c-consumed").text());
ztExecution.setLeft(tr.select(".c-left").text());
response.setSuccess(true);
response.setMessage("请求成功");
response.setResult(ztExecution);
return response;
}
StaticLog.info(body);
response.setMessage("无数据");
return response;
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
}

@ -0,0 +1,168 @@
package xyz.wbsite.zentao.sdk.execution.ent;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecution {
/**
* ID
*/
private int id;
/**
*
*/
private String name;
/**
*
*/
private String code;
/**
* ID
*/
private int projectId;
/**
*
*/
private String projectName;
/**
*
*/
private String pm;
/**
*
*/
private String status;
/**
*
*/
private String progress;
/**
*
*/
private String begin;
/**
*
*/
private String end;
/**
*
*/
private String estimate;
/**
*
*/
private String consumed;
/**
*
*/
private String left;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getPm() {
return pm;
}
public void setPm(String pm) {
this.pm = pm;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getProgress() {
return progress;
}
public void setProgress(String progress) {
this.progress = progress;
}
public String getBegin() {
return begin;
}
public void setBegin(String begin) {
this.begin = begin;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public String getEstimate() {
return estimate;
}
public void setEstimate(String estimate) {
this.estimate = estimate;
}
public String getConsumed() {
return consumed;
}
public void setConsumed(String consumed) {
this.consumed = consumed;
}
public String getLeft() {
return left;
}
public void setLeft(String left) {
this.left = left;
}
}

@ -0,0 +1,64 @@
package xyz.wbsite.zentao.sdk.execution.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionActivateRequest {
private int executionId;
private String begin;
private String end;
/**
* 0/1
*/
private String readjustTime;
private String comment;
public int getExecutionId() {
return executionId;
}
public void setExecutionId(int executionId) {
this.executionId = executionId;
}
public String getBegin() {
return begin;
}
public void setBegin(String begin) {
this.begin = begin;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public String getReadjustTime() {
return readjustTime;
}
public void setReadjustTime(String readjustTime) {
this.readjustTime = readjustTime;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

@ -0,0 +1,41 @@
package xyz.wbsite.zentao.sdk.execution.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionCloseRequest {
private int executionId;
private String comment;
private String realEnd;
public int getExecutionId() {
return executionId;
}
public void setExecutionId(int executionId) {
this.executionId = executionId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getRealEnd() {
return realEnd;
}
public void setRealEnd(String realEnd) {
this.realEnd = realEnd;
}
}

@ -0,0 +1,222 @@
package xyz.wbsite.zentao.sdk.execution.req;
import java.util.List;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionCreateRequest {
private int project;
private String name;
private String code;
/**
* 2023-11-09
*/
private String begin;
/**
* 2024-11-07
*/
private String end;
/**
*
*/
private int delta;
/**
*
*/
private int days;
/**
* short/long/ops
*/
private String lifetime;
/**
*
*/
private String team;
/**
*
* zt_projectid
*/
private int teams;
/**
*
*/
private String po;
/**
*
*/
private String qd;
/**
*
*/
private String pm;
/**
*
*/
private String rd;
/**
*
*/
private List<String> teamMembers;
/**
*
*/
private String desc;
/**
* 访private/open
*/
private String acl;
/**
* extend/reset
*/
private String auth;
public int getProject() {
return project;
}
public void setProject(int project) {
this.project = project;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getBegin() {
return begin;
}
public void setBegin(String begin) {
this.begin = begin;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public int getDelta() {
return delta;
}
public void setDelta(int delta) {
this.delta = delta;
}
public int getDays() {
return days;
}
public void setDays(int days) {
this.days = days;
}
public String getLifetime() {
return lifetime;
}
public void setLifetime(String lifetime) {
this.lifetime = lifetime;
}
public String getTeam() {
return team;
}
public void setTeam(String team) {
this.team = team;
}
public int getTeams() {
return teams;
}
public void setTeams(int teams) {
this.teams = teams;
}
public String getPo() {
return po;
}
public void setPo(String po) {
this.po = po;
}
public String getQd() {
return qd;
}
public void setQd(String qd) {
this.qd = qd;
}
public String getPm() {
return pm;
}
public void setPm(String pm) {
this.pm = pm;
}
public String getRd() {
return rd;
}
public void setRd(String rd) {
this.rd = rd;
}
public List<String> getTeamMembers() {
return teamMembers;
}
public void setTeamMembers(List<String> teamMembers) {
this.teamMembers = teamMembers;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getAcl() {
return acl;
}
public void setAcl(String acl) {
this.acl = acl;
}
public String getAuth() {
return auth;
}
public void setAuth(String auth) {
this.auth = auth;
}
}

@ -0,0 +1,21 @@
package xyz.wbsite.zentao.sdk.execution.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionDeleteRequest {
private int executionId;
public int getExecutionId() {
return executionId;
}
public void setExecutionId(int executionId) {
this.executionId = executionId;
}
}

@ -0,0 +1,41 @@
package xyz.wbsite.zentao.sdk.execution.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionStartRequest {
private int executionId;
private String comment;
private String realBegan;
public int getExecutionId() {
return executionId;
}
public void setExecutionId(int executionId) {
this.executionId = executionId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getRealBegan() {
return realBegan;
}
public void setRealBegan(String realBegan) {
this.realBegan = realBegan;
}
}

@ -0,0 +1,36 @@
package xyz.wbsite.zentao.sdk.execution.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionActivateResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,36 @@
package xyz.wbsite.zentao.sdk.execution.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionCloseResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,48 @@
package xyz.wbsite.zentao.sdk.execution.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionCreateResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
* id
*/
private int id;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

@ -0,0 +1,36 @@
package xyz.wbsite.zentao.sdk.execution.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionDeleteResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,50 @@
package xyz.wbsite.zentao.sdk.execution.rsp;
import xyz.wbsite.zentao.sdk.execution.ent.ZtExecution;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionGetResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
*
*/
private ZtExecution result;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public ZtExecution getResult() {
return result;
}
public void setResult(ZtExecution result) {
this.result = result;
}
}

@ -0,0 +1,36 @@
package xyz.wbsite.zentao.sdk.execution.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtExecutionStartResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,443 @@
package xyz.wbsite.zentao.sdk.project;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.StaticLog;
import xyz.wbsite.zentao.sdk.Constant;
import xyz.wbsite.zentao.sdk.ZentaoInstance;
import xyz.wbsite.zentao.sdk.project.ent.ZtProject;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectActivateRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectCloseRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectCreateRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectDeleteRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectEditRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectStartRequest;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectActivateResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectCloseResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectCreateResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectDeleteResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectEditResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectGetResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectStartResponse;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectService {
private ZentaoInstance zentaoInstance;
public ZtProjectService(ZentaoInstance zentaoInstance) {
this.zentaoInstance = zentaoInstance;
}
/**
*
*/
public ZtProjectCreateResponse create(ZtProjectCreateRequest request) {
ZtProjectCreateResponse response = new ZtProjectCreateResponse();
try {
String url = StrUtil.format("/project-create-{}-0-0-productID=0,branchID=0.json", request.getModel());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.contentType("application/x-www-form-urlencoded; charset=UTF-8");
httpRequest.form("parent", request.getParent());
httpRequest.form("name", request.getName());
httpRequest.form("code", request.getCode());
httpRequest.form("multiple", request.getMultiple());
httpRequest.form("hasProduct", request.getHasProduct());
httpRequest.form("PM", request.getPm());
httpRequest.form("budget", NumberUtil.decimalFormat("#.00", Convert.toDouble(request.getBudget(), 0D)));
httpRequest.form("budgetUnit", request.getBudgetUnit());
httpRequest.form("begin", request.getBegin());
httpRequest.form("end", request.getEnd());
httpRequest.form("days", request.getDays());
httpRequest.form("products[0]", request.getProducts());
httpRequest.form("productName", request.getProductName());
httpRequest.form("desc", request.getDesc());
httpRequest.form("acl", request.getAcl());
httpRequest.form("auth", request.getAuth());
httpRequest.form("model", request.getModel());
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
//{"result":"success","message":"保存成功","id":"355"}
StaticLog.info(body);
if (body.contains(Constant.SUCCESS_KEY)) {
JSONObject entries = JSONUtil.parseObj(body);
response.setId(Convert.toInt(entries.get("id")));
response.setSuccess(true);
response.setMessage("请求成功");
return response;
}
} catch (HttpException e) {
throw new RuntimeException(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtProjectEditResponse edit(ZtProjectEditRequest request) {
ZtProjectEditResponse response = new ZtProjectEditResponse();
try {
String url = StrUtil.format("/project-edit-{}-view.json", request.getId());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPostForHtml(url);
httpRequest.form("parent", request.getParent());
httpRequest.form("name", request.getName());
httpRequest.form("code", request.getCode());
httpRequest.form("PM", request.getPm());
httpRequest.form("budget", NumberUtil.decimalFormat("#.00", Convert.toDouble(request.getBudget(), 0D)));
httpRequest.form("budgetUnit", request.getBudgetUnit());
httpRequest.form("future", request);
httpRequest.form("begin", request.getBegin());
httpRequest.form("end", request.getEnd());
httpRequest.form("days", request.getDays());
httpRequest.form("desc", request.getDesc());
httpRequest.form("acl", request.getAcl());
httpRequest.form("auth", request.getAuth());
httpRequest.form("model", request.getModel());
httpRequest.form("delta", request.getDelta());
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
//{"result":"success","message":"保存成功","locate":"/project-view-363.json"}
StaticLog.info(body);
if (body.contains(Constant.SUCCESS_KEY)) {
response.setSuccess(true);
response.setMessage("请求成功");
return response;
}
} catch (Exception e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtProjectStartResponse start(ZtProjectStartRequest request) {
ZtProjectStartResponse response = new ZtProjectStartResponse();
try {
String url = StrUtil.format("/project-start-{}.html", request.getProjectId());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("status", "doing");
httpRequest.form("realBegan", request.getRealBegan());
httpRequest.form("comment", request.getComment());
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (Exception e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtProjectCloseResponse close(ZtProjectCloseRequest request) {
ZtProjectCloseResponse response = new ZtProjectCloseResponse();
try {
String url = StrUtil.format("/project-close-{}.html", request.getProjectId());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("status", "closed");
httpRequest.form("realEnd", request.getRealEnd());
httpRequest.form("comment", request.getComment());
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (Exception e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtProjectActivateResponse activate(ZtProjectActivateRequest request) {
ZtProjectActivateResponse response = new ZtProjectActivateResponse();
try {
String url = StrUtil.format("/project-close-{}.html", request.getProjectId());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("begin", request.getBegin());
httpRequest.form("end", request.getEnd());
httpRequest.form("readjustTime", request.getReadjustTime());
httpRequest.form("status", "doing");
httpRequest.form("comment", request.getComment());
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (Exception e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtProjectDeleteResponse delete(ZtProjectDeleteRequest request) {
ZtProjectDeleteResponse response = new ZtProjectDeleteResponse();
try {
String url = StrUtil.format("/project-delete-{}-yes-browse.html", request.getProjectId());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (Exception e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
* <p>
* session
*/
private boolean setQuery(String fieldName, String fieldValue) {
try {
String url = StrUtil.format("/search-buildQuery.html");
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("fieldname", "");
httpRequest.form("fieldcode", "");
httpRequest.form("fieldid", "");
httpRequest.form("fieldmodel", "");
httpRequest.form("fieldhasProduct", "");
httpRequest.form("fieldparent", "0");
httpRequest.form("fieldstatus", "");
httpRequest.form("fielddesc", "");
httpRequest.form("fieldPM", "");
httpRequest.form("fieldopenedDate", "");
httpRequest.form("fieldbegin", "");
httpRequest.form("fieldend", "");
httpRequest.form("fieldrealBegan", "");
httpRequest.form("fieldrealEnd", "");
httpRequest.form("fieldopenedBy", "");
httpRequest.form("fieldclosedBy", "");
httpRequest.form("fieldlastEditedDate", "");
httpRequest.form("fieldclosedDate", "");
httpRequest.form("andOr1", "AND");
httpRequest.form("field1", fieldName);
httpRequest.form("operator1", "=");
httpRequest.form("value1", fieldValue);
httpRequest.form("andOr2", "and");
httpRequest.form("field2", "code");
httpRequest.form("operator2", "=");
httpRequest.form("value2", "");
httpRequest.form("andOr3", "and");
httpRequest.form("field3", "id");
httpRequest.form("operator3", "=");
httpRequest.form("value3", "");
httpRequest.form("groupAndOr", "and");
httpRequest.form("andOr4", "AND");
httpRequest.form("field4", "model");
httpRequest.form("operator4", "=");
httpRequest.form("value4", "");
httpRequest.form("andOr5", "and");
httpRequest.form("field5", "hasProduct");
httpRequest.form("operator5", "=");
httpRequest.form("value5", "");
httpRequest.form("andOr6", "and");
httpRequest.form("field6", "parent");
httpRequest.form("operator6", "=");
httpRequest.form("value6", 0);
httpRequest.form("module", "project");
httpRequest.form("actionURL", "/project-browse-0-bySearch-myQueryID.html");
httpRequest.form("groupItems", "3");
httpRequest.form("formType", "lite");
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
return false;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
return execute.getStatus() == HttpStatus.HTTP_OK;
} catch (Exception e) {
StaticLog.error(e);
}
return false;
}
/**
*
*/
public ZtProjectGetResponse getByName(String name) {
ZtProjectGetResponse response = new ZtProjectGetResponse();
try {
boolean setQuery = setQuery("name", name);
if (!setQuery) {
response.setSuccess(false);
response.setMessage("设置查询参数失败");
return response;
}
HttpRequest httpRequest = zentaoInstance.createGetForHtml("/project-browse-0-bySearch-myQueryID.html");
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
Document parse = Jsoup.parse(body);
Elements trs = parse.select(".main-table .sortable tr");
if (trs.size() == 1) {
Element tr = trs.get(0);
ZtProject ztProject = new ZtProject();
ztProject.setId(Convert.toInt(tr.select(".c-id").text()));
ztProject.setName(tr.select(".c-name").attr("title"));
ztProject.setStatus(tr.select(".c-status").text());
ztProject.setPm(tr.select(".c-PM").text());
ztProject.setBudget(tr.select(".c-budget").text());
ztProject.setBegin(tr.select(".c-begin").text());
ztProject.setEnd(tr.select(".c-end").text());
ztProject.setProgress(tr.select(".c-progress").text());
response.setSuccess(true);
response.setMessage("请求成功");
response.setResult(ztProject);
return response;
}
StaticLog.info(body);
response.setMessage("无数据");
return response;
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtProjectGetResponse getByCode(String code) {
ZtProjectGetResponse response = new ZtProjectGetResponse();
try {
boolean setQuery = setQuery("code", code);
if (!setQuery) {
response.setSuccess(false);
response.setMessage("设置查询参数失败");
return response;
}
HttpRequest httpRequest = zentaoInstance.createGetForHtml("/project-browse-0-bySearch-myQueryID.html");
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
Document parse = Jsoup.parse(body);
Elements trs = parse.select(".main-table .sortable tr");
if (trs.size() == 1) {
Element tr = trs.get(0);
ZtProject ztProject = new ZtProject();
ztProject.setId(Convert.toInt(tr.select(".c-id").text()));
ztProject.setName(tr.select(".c-name").attr("title"));
ztProject.setStatus(tr.select(".c-status").text());
ztProject.setPm(tr.select(".c-PM").text());
ztProject.setBudget(tr.select(".c-budget").text());
ztProject.setBegin(tr.select(".c-begin").text());
ztProject.setEnd(tr.select(".c-end").text());
ztProject.setProgress(tr.select(".c-progress").text());
response.setSuccess(true);
response.setMessage("请求成功");
response.setResult(ztProject);
return response;
}
StaticLog.info(body);
response.setMessage("无数据");
return response;
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
}

@ -0,0 +1,108 @@
package xyz.wbsite.zentao.sdk.project.ent;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProject {
/**
* ID
*/
private int id;
/**
*
*/
private String name;
/**
*
*/
private String status;
/**
*
*/
private String pm;
/**
*
*/
private String budget;
/**
*
*/
private String begin;
/**
*
*/
private String end;
/**
*
*/
private String progress;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getPm() {
return pm;
}
public void setPm(String pm) {
this.pm = pm;
}
public String getBudget() {
return budget;
}
public void setBudget(String budget) {
this.budget = budget;
}
public String getBegin() {
return begin;
}
public void setBegin(String begin) {
this.begin = begin;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public String getProgress() {
return progress;
}
public void setProgress(String progress) {
this.progress = progress;
}
}

@ -0,0 +1,65 @@
package xyz.wbsite.zentao.sdk.project.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectActivateRequest {
private int projectId;
private String begin;
private String end;
/**
* 0/1
*/
private String readjustTime;
private String comment;
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
public String getBegin() {
return begin;
}
public void setBegin(String begin) {
this.begin = begin;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public String getReadjustTime() {
return readjustTime;
}
public void setReadjustTime(String readjustTime) {
this.readjustTime = readjustTime;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

@ -0,0 +1,41 @@
package xyz.wbsite.zentao.sdk.project.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectCloseRequest {
private int projectId;
private String comment;
private String realEnd;
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getRealEnd() {
return realEnd;
}
public void setRealEnd(String realEnd) {
this.realEnd = realEnd;
}
}

@ -0,0 +1,229 @@
package xyz.wbsite.zentao.sdk.project.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectCreateRequest {
/**
*
*/
private String parent;
/**
*
*/
private String name;
/**
*
*/
private String code;
/**
* 0:1:
*/
private String multiple;
/**
* 0:1:
*/
private String hasProduct;
/**
*
*/
private String pm;
/**
*
*/
private String budget;
/**
* CNY
*/
private String budgetUnit;
/**
* 1
*/
private String future;
/**
* yyyy-MM-dd
*/
private String begin;
/**
* yyyy-MM-dd
*/
private String end;
/**
*
*/
private int days;
/**
*
*/
private String products;
/**
*
*/
private String productName;
/**
*
*/
private String desc;
/**
* 访private/open
*/
private String acl;
/**
* extend/reset
*/
private String auth;
/**
* scrum/waterfall/kanban
*/
private String model;
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMultiple() {
return multiple;
}
public void setMultiple(String multiple) {
this.multiple = multiple;
}
public String getHasProduct() {
return hasProduct;
}
public void setHasProduct(String hasProduct) {
this.hasProduct = hasProduct;
}
public String getPm() {
return pm;
}
public void setPm(String pm) {
this.pm = pm;
}
public String getBudget() {
return budget;
}
public void setBudget(String budget) {
this.budget = budget;
}
public String getBudgetUnit() {
return budgetUnit;
}
public void setBudgetUnit(String budgetUnit) {
this.budgetUnit = budgetUnit;
}
public String getFuture() {
return future;
}
public void setFuture(String future) {
this.future = future;
}
public String getBegin() {
return begin;
}
public void setBegin(String begin) {
this.begin = begin;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public int getDays() {
return days;
}
public void setDays(int days) {
this.days = days;
}
public String getProducts() {
return products;
}
public void setProducts(String products) {
this.products = products;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getAcl() {
return acl;
}
public void setAcl(String acl) {
this.acl = acl;
}
public String getAuth() {
return auth;
}
public void setAuth(String auth) {
this.auth = auth;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
}

@ -0,0 +1,21 @@
package xyz.wbsite.zentao.sdk.project.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectDeleteRequest {
private int projectId;
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
}

@ -0,0 +1,205 @@
package xyz.wbsite.zentao.sdk.project.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectEditRequest {
/**
* ID
*/
private int id;
/**
* ID
*/
private String parent;
/**
*
*/
private String name;
/**
*
*/
private String code;
/**
*
*/
private String pm;
/**
* 1
*/
private String future;
/**
*
*/
private String budget;
/**
* CNY
*/
private String budgetUnit;
/**
* yyyy-MM-dd
*/
private String begin;
/**
* yyyy-MM-dd
*/
private String end;
/**
*
*/
private int days;
/**
* delta
*/
private int delta;
/**
*
*/
private String desc;
/**
* 访private/open
*/
private String acl;
/**
* extend/reset
*/
private String auth;
/**
* scrum/waterfall/kanban
*/
private String model;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPm() {
return pm;
}
public void setPm(String pm) {
this.pm = pm;
}
public String getBudget() {
return budget;
}
public void setBudget(String budget) {
this.budget = budget;
}
public String getBudgetUnit() {
return budgetUnit;
}
public void setBudgetUnit(String budgetUnit) {
this.budgetUnit = budgetUnit;
}
public String getBegin() {
return begin;
}
public void setBegin(String begin) {
this.begin = begin;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public int getDays() {
return days;
}
public void setDays(int days) {
this.days = days;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getAcl() {
return acl;
}
public void setAcl(String acl) {
this.acl = acl;
}
public String getAuth() {
return auth;
}
public void setAuth(String auth) {
this.auth = auth;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getDelta() {
return delta;
}
public void setDelta(int delta) {
this.delta = delta;
}
public String getFuture() {
return future;
}
public void setFuture(String future) {
this.future = future;
}
}

@ -0,0 +1,41 @@
package xyz.wbsite.zentao.sdk.project.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectStartRequest {
private int projectId;
private String comment;
private String realBegan;
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getRealBegan() {
return realBegan;
}
public void setRealBegan(String realBegan) {
this.realBegan = realBegan;
}
}

@ -0,0 +1,36 @@
package xyz.wbsite.zentao.sdk.project.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectActivateResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,36 @@
package xyz.wbsite.zentao.sdk.project.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectCloseResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,50 @@
package xyz.wbsite.zentao.sdk.project.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectCreateResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
*
* id
*/
private int id;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

@ -0,0 +1,36 @@
package xyz.wbsite.zentao.sdk.project.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectDeleteResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,36 @@
package xyz.wbsite.zentao.sdk.project.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectEditResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,48 @@
package xyz.wbsite.zentao.sdk.project.rsp;
import xyz.wbsite.zentao.sdk.project.ent.ZtProject;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectGetResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
private ZtProject result;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public ZtProject getResult() {
return result;
}
public void setResult(ZtProject result) {
this.result = result;
}
}

@ -0,0 +1,49 @@
package xyz.wbsite.zentao.sdk.project.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtProjectStartResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
* id
*/
private int id;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

@ -0,0 +1,450 @@
package xyz.wbsite.zentao.sdk.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.StaticLog;
import xyz.wbsite.zentao.sdk.Constant;
import xyz.wbsite.zentao.sdk.ZentaoInstance;
import xyz.wbsite.zentao.sdk.task.ent.ZtTask;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskCloseRequest;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskCreateRequest;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskDeleteRequest;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskFinishRequest;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskStartRequest;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskCloseResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskCreateResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskDeleteResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskFinishResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskGetResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskStartResponse;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskService {
private ZentaoInstance zentaoInstance;
public ZtTaskService(ZentaoInstance zentaoInstance) {
this.zentaoInstance = zentaoInstance;
}
/**
*
*/
public ZtTaskCreateResponse create(ZtTaskCreateRequest ztTaskCreateRequest) {
ZtTaskCreateResponse response = new ZtTaskCreateResponse();
try {
String url = StrUtil.format("/task-create-{}-0-0.json", ztTaskCreateRequest.getExecution());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("execution", ztTaskCreateRequest.getExecution());
httpRequest.form("type", ztTaskCreateRequest.getType());
httpRequest.form("module", ztTaskCreateRequest.getModule());
httpRequest.form("assignedTo[]", StrUtil.join(",", ztTaskCreateRequest.getAssignedTo()));
httpRequest.form("teamMember", ztTaskCreateRequest.getTeamMember());
httpRequest.form("multiple", ztTaskCreateRequest.getMultiple());
httpRequest.form("mode", ztTaskCreateRequest.getMode());
httpRequest.form("status", "wait");
httpRequest.form("story", ztTaskCreateRequest.getStory());
httpRequest.form("color", ztTaskCreateRequest.getColor());
httpRequest.form("name", ztTaskCreateRequest.getName());
httpRequest.form("storyEstimate", ztTaskCreateRequest.getStoryEstimate());
httpRequest.form("storyDesc", ztTaskCreateRequest.getStoryDesc());
httpRequest.form("storyPri", ztTaskCreateRequest.getStoryPri());
httpRequest.form("pri", ztTaskCreateRequest.getPri());
httpRequest.form("estimate", ztTaskCreateRequest.getEstimate());
httpRequest.form("desc", ztTaskCreateRequest.getDesc());
httpRequest.form("estStarted", ztTaskCreateRequest.getEstStarted());
httpRequest.form("deadline", ztTaskCreateRequest.getDeadline());
httpRequest.form("after", "toTaskList");
httpRequest.form("team[]", "");
httpRequest.form("teamSource[]", "");
httpRequest.form("teamEstimate[]", "");
if (CollUtil.isNotEmpty(ztTaskCreateRequest.getMailtos())) {
for (String mailto : ztTaskCreateRequest.getMailtos()) {
httpRequest.form("mailto[]", mailto);
}
}
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
// {"result":"success","message":"保存成功","id":"1891"}
if (body.contains(Constant.SUCCESS_KEY)) {
JSONObject entries = JSONUtil.parseObj(body);
response.setId(Convert.toInt(entries.get("id")));
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} else {
response.setSuccess(false);
response.setMessage(JSONUtil.parseObj(body).getStr("message"));
return response;
}
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtTaskStartResponse start(ZtTaskStartRequest projectStartRequest) {
ZtTaskStartResponse response = new ZtTaskStartResponse();
try {
String url = StrUtil.format("/task-start-{}.html", projectStartRequest.getTaskId());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("assignedTo", projectStartRequest.getAssignedTo());
httpRequest.form("realStarted", projectStartRequest.getRealStarted());
httpRequest.form("consumed", projectStartRequest.getConsumed());
httpRequest.form("left", projectStartRequest.getLeft());
httpRequest.form("status", "doing");
httpRequest.form("comment", projectStartRequest.getComment());
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
// 返回html
StaticLog.info(body);
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtTaskFinishResponse finish(ZtTaskFinishRequest ztTaskFinishRequest) {
ZtTaskFinishResponse response = new ZtTaskFinishResponse();
try {
String url = StrUtil.format("/task-finish-{}.html", ztTaskFinishRequest.getTaskId());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("currentConsumed", ztTaskFinishRequest.getCurrentConsumed());
httpRequest.form("consumed", ztTaskFinishRequest.getConsumed());
httpRequest.form("assignedTo", ztTaskFinishRequest.getAssignedTo());
httpRequest.form("realStarted", ztTaskFinishRequest.getRealStarted());
httpRequest.form("finishedDate", ztTaskFinishRequest.getFinishedDate());
httpRequest.form("status", "done");
httpRequest.form("comment", ztTaskFinishRequest.getComment());
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
if (body.contains(Constant.SUCCESS_KEY)) {
JSONObject entries = JSONUtil.parseObj(body);
response.setId(Convert.toInt(entries.get("id")));
response.setSuccess(true);
response.setMessage("请求成功");
return response;
}
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtTaskCloseResponse close(ZtTaskCloseRequest projectCloseRequest) {
ZtTaskCloseResponse response = new ZtTaskCloseResponse();
try {
String url = StrUtil.format("/task-close-{}.html", projectCloseRequest.getTaskId());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("status", "closed");
httpRequest.form("comment", projectCloseRequest.getComment());
httpRequest.form("uid", RandomUtil.randomString(13));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
if (body.contains(Constant.SUCCESS_KEY)) {
JSONObject entries = JSONUtil.parseObj(body);
response.setId(Convert.toInt(entries.get("id")));
response.setSuccess(true);
response.setMessage("请求成功");
return response;
}
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*/
public ZtTaskDeleteResponse delete(ZtTaskDeleteRequest projectDeleteRequest) {
ZtTaskDeleteResponse response = new ZtTaskDeleteResponse();
try {
String url = StrUtil.format("/task-delete-{}.html", projectDeleteRequest.getTaskId());
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
* <p>
* session
*/
private boolean setQuery(int executionId, String fieldName, String fieldValue) {
try {
String url = StrUtil.format("/search-buildQuery.html");
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createPost(url);
httpRequest.form("fieldname", "");
httpRequest.form("fieldstatus", "");
httpRequest.form("fielddesc", "");
httpRequest.form("fieldassignedTo", "");
httpRequest.form("fieldpri", 0);
httpRequest.form("fieldexecution", "");
httpRequest.form("fieldmodule", "ZERO");
httpRequest.form("fieldestimate", "");
httpRequest.form("fieldleft", "");
httpRequest.form("fieldconsumed", "");
httpRequest.form("fieldtype", "");
httpRequest.form("fieldfromBug", "");
httpRequest.form("fieldclosedReason", "");
httpRequest.form("fieldopenedBy", "");
httpRequest.form("fieldfinishedBy", "");
httpRequest.form("fieldclosedBy", "");
httpRequest.form("fieldcanceledBy", "");
httpRequest.form("fieldlastEditedBy", "");
httpRequest.form("fieldmailto", "");
httpRequest.form("fieldopenedDate", "");
httpRequest.form("fielddeadline", "");
httpRequest.form("fieldestStarted", "");
httpRequest.form("fieldrealStarted", "");
httpRequest.form("fieldassignedDate", "");
httpRequest.form("fieldfinishedDate", "");
httpRequest.form("fieldclosedDate", "");
httpRequest.form("fieldcanceledDate", "");
httpRequest.form("fieldlastEditedDate", "");
httpRequest.form("fieldactivatedDate", "");
httpRequest.form("fieldid", "");
httpRequest.form("andOr1", "AND");
httpRequest.form("field1", fieldName);
httpRequest.form("operator1", "=");
httpRequest.form("value1", fieldValue);
httpRequest.form("andOr2", "and");
httpRequest.form("field2", "id");
httpRequest.form("operator2", "=");
httpRequest.form("value2", "");
httpRequest.form("andOr3", "and");
httpRequest.form("field3", "status");
httpRequest.form("operator3", "=");
httpRequest.form("value3", "");
httpRequest.form("groupAndOr", "and");
httpRequest.form("andOr4", "AND");
httpRequest.form("field4", "desc");
httpRequest.form("operator4", "include");
httpRequest.form("value4", "");
httpRequest.form("andOr5", "and");
httpRequest.form("field5", "assignedTo");
httpRequest.form("operator5", "=");
httpRequest.form("value5", "");
httpRequest.form("andOr6", "and");
httpRequest.form("field6", "pri");
httpRequest.form("operator6", "=");
httpRequest.form("value6", 0);
httpRequest.form("module", "task");
httpRequest.form("actionURL", StrUtil.format("/execution-task-{}-bySearch-myQueryID.html", executionId));
httpRequest.form("groupItems", "3");
httpRequest.form("formType", "lite");
StaticLog.info(JSONUtil.toJsonStr(httpRequest.form()));
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
return false;
}
String body = Convert.unicodeToStr(execute.body());
StaticLog.info(body);
return execute.getStatus() == HttpStatus.HTTP_OK;
} catch (Exception e) {
StaticLog.error(e);
}
return false;
}
/**
*
*
* @param executionId ID
* @param taskId ID
* @return
*/
public ZtTaskGetResponse getById(int executionId, int taskId) {
ZtTaskGetResponse response = new ZtTaskGetResponse();
try {
boolean setQuery = setQuery(executionId, "id", String.valueOf(taskId));
if (!setQuery) {
response.setSuccess(false);
response.setMessage("设置查询参数失败");
return response;
}
String url = StrUtil.format("/execution-task-{}-bySearch-myQueryID.html", executionId);
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createGetForHtml(url);
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
Document parse = Jsoup.parse(body);
Elements trs = parse.select("#taskList tbody tr");
if (trs.size() == 1) {
Element tr = trs.get(0);
ZtTask ztTask = new ZtTask();
ztTask.setId(Convert.toInt(tr.select(".c-id").text()));
ztTask.setName(tr.select(".c-name").attr("title"));
ztTask.setStatus(tr.select(".c-status").text());
ztTask.setPri(tr.select(".c-pri").text());
ztTask.setAssignedTo(tr.select(".c-assignedTo").text());
ztTask.setStatus(tr.select(".c-status").text());
ztTask.setFinishedBy(tr.select(".c-finishedBy").text());
ztTask.setProgress(tr.select("c-deadline").text());
ztTask.setProgress(tr.select("c-estimate").text());
ztTask.setProgress(tr.select("c-consumed").text());
ztTask.setProgress(tr.select("c-left").text());
ztTask.setProgress(tr.select("c-progress").text());
response.setSuccess(true);
response.setMessage("请求成功");
response.setResult(ztTask);
return response;
}
StaticLog.info(body);
response.setMessage("无数据");
return response;
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
/**
*
*
* @param executionId ID
* @param name
* @return
*/
public ZtTaskGetResponse getByName(int executionId, String name) {
ZtTaskGetResponse response = new ZtTaskGetResponse();
try {
boolean setQuery = setQuery(executionId, "name", name);
if (!setQuery) {
response.setSuccess(false);
response.setMessage("设置查询参数失败");
return response;
}
String url = StrUtil.format("/execution-task-{}-bySearch-myQueryID.html", executionId);
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createGetForHtml(url);
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
Document parse = Jsoup.parse(body);
Elements trs = parse.select("#taskList tbody tr");
if (trs.size() == 1) {
Element tr = trs.get(0);
ZtTask ztTask = new ZtTask();
ztTask.setId(Convert.toInt(tr.select(".c-id").text()));
ztTask.setName(tr.select(".c-name").attr("title"));
ztTask.setStatus(tr.select(".c-status").text());
ztTask.setPri(tr.select(".c-pri").text());
ztTask.setAssignedTo(tr.select(".c-assignedTo").text());
ztTask.setStatus(tr.select(".c-status").text());
ztTask.setFinishedBy(tr.select(".c-finishedBy").text());
ztTask.setProgress(tr.select("c-deadline").text());
ztTask.setProgress(tr.select("c-estimate").text());
ztTask.setProgress(tr.select("c-consumed").text());
ztTask.setProgress(tr.select("c-left").text());
ztTask.setProgress(tr.select("c-progress").text());
response.setSuccess(true);
response.setMessage("请求成功");
response.setResult(ztTask);
return response;
}
StaticLog.info(body);
response.setMessage("无数据");
return response;
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
}

@ -0,0 +1,144 @@
package xyz.wbsite.zentao.sdk.task.ent;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTask {
/**
* ID
*/
private int id;
/**
*
*/
private String name;
/**
*
*/
private String pri;
/**
*
*/
private String assignedTo;
/**
*
*/
private String status;
/**
*
*/
private String finishedBy;
/**
*
*/
private String deadline;
/**
*
*/
private String estimate;
/**
*
*/
private String consumed;
/**
*
*/
private String left;
/**
*
*/
private String progress;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPri() {
return pri;
}
public void setPri(String pri) {
this.pri = pri;
}
public String getAssignedTo() {
return assignedTo;
}
public void setAssignedTo(String assignedTo) {
this.assignedTo = assignedTo;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getFinishedBy() {
return finishedBy;
}
public void setFinishedBy(String finishedBy) {
this.finishedBy = finishedBy;
}
public String getDeadline() {
return deadline;
}
public void setDeadline(String deadline) {
this.deadline = deadline;
}
public String getEstimate() {
return estimate;
}
public void setEstimate(String estimate) {
this.estimate = estimate;
}
public String getConsumed() {
return consumed;
}
public void setConsumed(String consumed) {
this.consumed = consumed;
}
public String getLeft() {
return left;
}
public void setLeft(String left) {
this.left = left;
}
public String getProgress() {
return progress;
}
public void setProgress(String progress) {
this.progress = progress;
}
}

@ -0,0 +1,72 @@
package xyz.wbsite.zentao.sdk.task.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskActivateRequest {
/**
* id
*/
private int executionId;
/**
*
*/
private String begin;
/**
*
*/
private String end;
/**
* 0/1
*/
private boolean readjustTime;
/**
*
*/
private String comment;
public int getExecutionId() {
return executionId;
}
public void setExecutionId(int executionId) {
this.executionId = executionId;
}
public String getBegin() {
return begin;
}
public void setBegin(String begin) {
this.begin = begin;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public boolean isReadjustTime() {
return readjustTime;
}
public void setReadjustTime(boolean readjustTime) {
this.readjustTime = readjustTime;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

@ -0,0 +1,31 @@
package xyz.wbsite.zentao.sdk.task.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskCloseRequest {
private int taskId;
private String comment;
public int getTaskId() {
return taskId;
}
public void setTaskId(int taskId) {
this.taskId = taskId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

@ -0,0 +1,238 @@
package xyz.wbsite.zentao.sdk.task.req;
import java.util.List;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskCreateRequest {
/**
* ID
*/
private int execution;
/**
* devel/design/request/test/study/discuss/ui/affair/misc
*/
private String type;
/**
* ID,0
*/
private String module;
/**
*
*/
private List<String> assignedTo;
/**
*
*/
private String teamMember;
/**
* 1
*/
private String multiple;
/**
* linear/multi
*/
private String mode;
/**
*
*/
private String story;
private String storyEstimate;
private String storyDesc;
private String storyPri;
/**
*
*/
private String color;
/**
*
*/
private String name;
/**
* 1-4
*/
private String pri;
/**
* ()
*/
private String estimate;
/**
*
*/
private String desc;
/**
* yyyy-MM-dd
*/
private String estStarted;
/**
* yyyy-MM-dd
*/
private String deadline;
/**
*
*/
private List<String> mailtos;
public int getExecution() {
return execution;
}
public void setExecution(int execution) {
this.execution = execution;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
public List<String> getAssignedTo() {
return assignedTo;
}
public void setAssignedTo(List<String> assignedTo) {
this.assignedTo = assignedTo;
}
public String getTeamMember() {
return teamMember;
}
public void setTeamMember(String teamMember) {
this.teamMember = teamMember;
}
public String getMultiple() {
return multiple;
}
public void setMultiple(String multiple) {
this.multiple = multiple;
}
public String getMode() {
return mode;
}
public void setMode(String mode) {
this.mode = mode;
}
public String getStory() {
return story;
}
public void setStory(String story) {
this.story = story;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStoryEstimate() {
return storyEstimate;
}
public void setStoryEstimate(String storyEstimate) {
this.storyEstimate = storyEstimate;
}
public String getStoryDesc() {
return storyDesc;
}
public void setStoryDesc(String storyDesc) {
this.storyDesc = storyDesc;
}
public String getStoryPri() {
return storyPri;
}
public void setStoryPri(String storyPri) {
this.storyPri = storyPri;
}
public String getPri() {
return pri;
}
public void setPri(String pri) {
this.pri = pri;
}
public String getEstimate() {
return estimate;
}
public void setEstimate(String estimate) {
this.estimate = estimate;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getEstStarted() {
return estStarted;
}
public void setEstStarted(String estStarted) {
this.estStarted = estStarted;
}
public String getDeadline() {
return deadline;
}
public void setDeadline(String deadline) {
this.deadline = deadline;
}
public List<String> getMailtos() {
return mailtos;
}
public void setMailtos(List<String> mailtos) {
this.mailtos = mailtos;
}
}

@ -0,0 +1,21 @@
package xyz.wbsite.zentao.sdk.task.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskDeleteRequest {
private int taskId;
public int getTaskId() {
return taskId;
}
public void setTaskId(int taskId) {
this.taskId = taskId;
}
}

@ -0,0 +1,95 @@
package xyz.wbsite.zentao.sdk.task.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskFinishRequest {
/**
* ID
*/
private int taskId;
/**
*
*/
private int currentConsumed;
/**
*
*/
private String consumed;
/**
*
*/
private String assignedTo;
/**
*
*/
private String realStarted;
/**
*
*/
private String finishedDate;
/**
*
*/
private String comment;
public int getTaskId() {
return taskId;
}
public void setTaskId(int taskId) {
this.taskId = taskId;
}
public int getCurrentConsumed() {
return currentConsumed;
}
public void setCurrentConsumed(int currentConsumed) {
this.currentConsumed = currentConsumed;
}
public String getConsumed() {
return consumed;
}
public void setConsumed(String consumed) {
this.consumed = consumed;
}
public String getAssignedTo() {
return assignedTo;
}
public void setAssignedTo(String assignedTo) {
this.assignedTo = assignedTo;
}
public String getRealStarted() {
return realStarted;
}
public void setRealStarted(String realStarted) {
this.realStarted = realStarted;
}
public String getFinishedDate() {
return finishedDate;
}
public void setFinishedDate(String finishedDate) {
this.finishedDate = finishedDate;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

@ -0,0 +1,83 @@
package xyz.wbsite.zentao.sdk.task.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskStartRequest {
/**
* ID
*/
private int taskId;
/**
*
*/
private String assignedTo;
/**
* 2023-11-10 10:09:26
*/
private String realStarted;
/**
* ()
*/
private String consumed;
/**
* ()
*/
private String left;
/**
*
*/
private String comment;
public int getTaskId() {
return taskId;
}
public void setTaskId(int taskId) {
this.taskId = taskId;
}
public String getAssignedTo() {
return assignedTo;
}
public void setAssignedTo(String assignedTo) {
this.assignedTo = assignedTo;
}
public String getRealStarted() {
return realStarted;
}
public void setRealStarted(String realStarted) {
this.realStarted = realStarted;
}
public String getConsumed() {
return consumed;
}
public void setConsumed(String consumed) {
this.consumed = consumed;
}
public String getLeft() {
return left;
}
public void setLeft(String left) {
this.left = left;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

@ -0,0 +1,48 @@
package xyz.wbsite.zentao.sdk.task.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskActivateResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
* ID
*/
private int id;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

@ -0,0 +1,48 @@
package xyz.wbsite.zentao.sdk.task.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskCloseResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
* ID
*/
private int id;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

@ -0,0 +1,47 @@
package xyz.wbsite.zentao.sdk.task.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskCreateResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
* ID
*/
private int id;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

@ -0,0 +1,36 @@
package xyz.wbsite.zentao.sdk.task.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskDeleteResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,48 @@
package xyz.wbsite.zentao.sdk.task.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskFinishResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
* ID
*/
private int id;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

@ -0,0 +1,50 @@
package xyz.wbsite.zentao.sdk.task.rsp;
import xyz.wbsite.zentao.sdk.task.ent.ZtTask;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskGetResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
*
*/
private ZtTask result;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public ZtTask getResult() {
return result;
}
public void setResult(ZtTask result) {
this.result = result;
}
}

@ -0,0 +1,48 @@
package xyz.wbsite.zentao.sdk.task.rsp;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtTaskStartResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
/**
* ID
*/
private int id;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

@ -0,0 +1,86 @@
package xyz.wbsite.zentao.sdk.user;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.log.StaticLog;
import xyz.wbsite.zentao.sdk.ZentaoInstance;
import xyz.wbsite.zentao.sdk.user.ent.ZtUser;
import xyz.wbsite.zentao.sdk.user.req.ZtUserListAllRequest;
import xyz.wbsite.zentao.sdk.user.rsp.ZtUserListAllResponse;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.ArrayList;
import java.util.List;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtUserService {
private ZentaoInstance zentaoInstance;
public ZtUserService(ZentaoInstance client) {
this.zentaoInstance = client;
}
public ZtUserListAllResponse listAll(ZtUserListAllRequest request) {
ZtUserListAllResponse response = new ZtUserListAllResponse();
try {
List<ZtUser> result = new ArrayList<>();
int currentPage = 1;
while (true) {
String url = StrUtil.format("/company-browse-inside-0-bydept-id-32-2000-{}.html", currentPage);
StaticLog.info(url);
HttpRequest httpRequest = zentaoInstance.createGetForHtml(url);
HttpResponse execute = httpRequest.execute();
if (HttpStatus.HTTP_OK != execute.getStatus()) {
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
String body = execute.body();
Document parse = Jsoup.parse(body);
Elements trs = parse.select(".main-table #userList tbody tr");
for (Element tr : trs) {
ZtUser ztUser = new ZtUser();
ztUser.setId(Convert.toInt(tr.select(".c-id").text()));
ztUser.setName(tr.child(1).attr("title"));
ztUser.setAccount(tr.child(2).text());
ztUser.setPosition(tr.child(3).text());
ztUser.setEmail(tr.child(4).text());
ztUser.setSex(tr.child(5).text());
ztUser.setPhone(tr.child(6).text());
ztUser.setQq(tr.child(7).text());
ztUser.setLastLoginDate(tr.child(8).text());
ztUser.setAccessTimes(Convert.toInt(tr.child(9).text(), 0));
result.add(ztUser);
}
if (trs.size() < 2000) {
break;
}
// 继续获取下一页数据
currentPage++;
}
response.setResult(result);
response.setSuccess(true);
response.setMessage("请求成功");
return response;
} catch (HttpException e) {
StaticLog.error(e);
}
response.setSuccess(false);
response.setMessage("请求失败");
return response;
}
}

@ -0,0 +1,144 @@
package xyz.wbsite.zentao.sdk.user.ent;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtUser {
/**
* ID
*/
private int id;
/**
*
*/
private String name;
/**
*
*/
private String account;
/**
*
*/
private String position;
/**
*
*/
private String email;
/**
*
*/
private String sex;
/**
*
*/
private String mobile;
/**
*
*/
private String phone;
/**
* QQ
*/
private String qq;
/**
*
*/
private String lastLoginDate;
/**
*
*/
private int accessTimes;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getQq() {
return qq;
}
public void setQq(String qq) {
this.qq = qq;
}
public String getLastLoginDate() {
return lastLoginDate;
}
public void setLastLoginDate(String lastLoginDate) {
this.lastLoginDate = lastLoginDate;
}
public int getAccessTimes() {
return accessTimes;
}
public void setAccessTimes(int accessTimes) {
this.accessTimes = accessTimes;
}
}

@ -0,0 +1,12 @@
package xyz.wbsite.zentao.sdk.user.req;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtUserListAllRequest {
}

@ -0,0 +1,50 @@
package xyz.wbsite.zentao.sdk.user.rsp;
import xyz.wbsite.zentao.sdk.user.ent.ZtUser;
import java.util.List;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ZtUserListAllResponse {
/**
*
*/
private boolean success;
/**
*
*/
private String message;
private List<ZtUser> result;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<ZtUser> getResult() {
return result;
}
public void setResult(List<ZtUser> result) {
this.result = result;
}
}

@ -0,0 +1,218 @@
package xyz.wbsite.zentao.sdk;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import xyz.wbsite.zentao.sdk.execution.req.ZtExecutionCreateRequest;
import xyz.wbsite.zentao.sdk.execution.req.ZtExecutionStartRequest;
import xyz.wbsite.zentao.sdk.execution.rsp.ZtExecutionCreateResponse;
import xyz.wbsite.zentao.sdk.execution.rsp.ZtExecutionStartResponse;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectActivateRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectCloseRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectCreateRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectDeleteRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectEditRequest;
import xyz.wbsite.zentao.sdk.project.req.ZtProjectStartRequest;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectActivateResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectCloseResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectCreateResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectDeleteResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectEditResponse;
import xyz.wbsite.zentao.sdk.project.rsp.ZtProjectStartResponse;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskCloseRequest;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskCreateRequest;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskDeleteRequest;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskFinishRequest;
import xyz.wbsite.zentao.sdk.task.req.ZtTaskStartRequest;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskCloseResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskCreateResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskDeleteResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskFinishResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskGetResponse;
import xyz.wbsite.zentao.sdk.task.rsp.ZtTaskStartResponse;
import org.junit.Test;
import java.util.Collections;
/**
*
* <p>
* 18.1
*
* @since 1.8
*/
public class ClientTest {
@Test
public void test() {
// 初始化客户端
ZentaoClient client = new ZentaoClient("http://127.0.0.1:80", "******", "********************************", "pms");
ZentaoInstance instance = client.loginAsPms();
// 创建项目
ZtProjectCreateRequest ztProjectCreateRequest = new ZtProjectCreateRequest();
ztProjectCreateRequest.setParent("0");
ztProjectCreateRequest.setName("测试项目");
ztProjectCreateRequest.setCode("测试项目");
ztProjectCreateRequest.setMultiple("1");
ztProjectCreateRequest.setHasProduct("0");
ztProjectCreateRequest.setPm("");
ztProjectCreateRequest.setBudget("1000");
ztProjectCreateRequest.setBudgetUnit("CNY");
ztProjectCreateRequest.setBegin(DateUtil.date().toString("yyyy-MM-dd"));
ztProjectCreateRequest.setEnd(DateUtil.date().offset(DateField.DAY_OF_MONTH, 27).toString("yyyy-MM-dd"));
ztProjectCreateRequest.setDays(21);
ztProjectCreateRequest.setProducts("0");
ztProjectCreateRequest.setProductName("");
ztProjectCreateRequest.setDesc("");
ztProjectCreateRequest.setAcl("open");
ztProjectCreateRequest.setAuth("extend");
ztProjectCreateRequest.setModel("scrum");
ZtProjectCreateResponse createProjectResponse = instance.getZtProjectService().create(ztProjectCreateRequest);
System.out.println(JSONUtil.toJsonPrettyStr(createProjectResponse));
// 编辑项目
ZtProjectEditRequest ztProjectEditRequest = new ZtProjectEditRequest();
ztProjectEditRequest.setId(createProjectResponse.getId());
ztProjectEditRequest.setParent("0");
ztProjectEditRequest.setName("测试项目");
ztProjectEditRequest.setCode("测试项目");
ztProjectEditRequest.setPm("");
ztProjectEditRequest.setBudget("1000");
ztProjectEditRequest.setBudgetUnit("CNY");
ztProjectEditRequest.setBegin(DateUtil.date().toString("yyyy-MM-dd"));
ztProjectEditRequest.setEnd(DateUtil.date().offset(DateField.DAY_OF_MONTH, 27).toString("yyyy-MM-dd"));
ztProjectEditRequest.setDays(21);
ztProjectEditRequest.setDesc("");
ztProjectEditRequest.setAcl("open");
ztProjectEditRequest.setAuth("extend");
ztProjectEditRequest.setModel("scrum");
ZtProjectEditResponse ztProjectEditResponse = instance.getZtProjectService().edit(ztProjectEditRequest);
System.out.println(JSONUtil.toJsonPrettyStr(ztProjectEditResponse));
// 开始项目
ZtProjectStartRequest ztProjectStartRequest = new ZtProjectStartRequest();
ztProjectStartRequest.setProjectId(createProjectResponse.getId());
ztProjectStartRequest.setComment("");
ztProjectStartRequest.setRealBegan(DateUtil.today());
ZtProjectStartResponse startProjectResponse = instance.getZtProjectService().start(ztProjectStartRequest);
System.out.println(JSONUtil.toJsonPrettyStr(startProjectResponse));
// 创建执行模块1
{
ZtExecutionCreateRequest ztExecutionCreateRequest = new ZtExecutionCreateRequest();
ztExecutionCreateRequest.setProject(createProjectResponse.getId());
ztExecutionCreateRequest.setName("测试项目-模块1");
ztExecutionCreateRequest.setCode("测试项目-模块1");
ztExecutionCreateRequest.setBegin(DateUtil.date().toString("yyyy-MM-dd"));
ztExecutionCreateRequest.setEnd(DateUtil.date().offset(DateField.DAY_OF_MONTH, 6).toString("yyyy-MM-dd"));
ztExecutionCreateRequest.setDelta(7);
ztExecutionCreateRequest.setDays(5);
ztExecutionCreateRequest.setLifetime("short");
ztExecutionCreateRequest.setTeam("");
ztExecutionCreateRequest.setTeams(createProjectResponse.getId());
ztExecutionCreateRequest.setPo("");
ztExecutionCreateRequest.setQd("");
ztExecutionCreateRequest.setPm("");
ztExecutionCreateRequest.setRd("");
ztExecutionCreateRequest.setTeamMembers(CollUtil.newArrayList(""));
ztExecutionCreateRequest.setDesc("");
ztExecutionCreateRequest.setAcl("open");
ztExecutionCreateRequest.setAuth("extend");
ZtExecutionCreateResponse ztExecutionCreateResponse = instance.getZtExecutionService().create(ztExecutionCreateRequest);
System.out.println(JSONUtil.toJsonPrettyStr(ztExecutionCreateResponse));
// 开始执行模块1
ZtExecutionStartRequest ztExecutionStartRequest = new ZtExecutionStartRequest();
ztExecutionStartRequest.setExecutionId(ztExecutionCreateResponse.getId());
ztExecutionStartRequest.setComment("");
ztExecutionStartRequest.setRealBegan(DateUtil.today());
ZtExecutionStartResponse ztExecutionStartResponse = instance.getZtExecutionService().start(ztExecutionStartRequest);
System.out.println(JSONUtil.toJsonPrettyStr(ztExecutionStartResponse));
{
// 创建测试任务1
ZtTaskCreateRequest ztTaskCreateRequest = new ZtTaskCreateRequest();
ztTaskCreateRequest.setExecution(ztExecutionCreateResponse.getId());
ztTaskCreateRequest.setType("devel");
ztTaskCreateRequest.setModule("0");
ztTaskCreateRequest.setAssignedTo(Collections.emptyList());
ztTaskCreateRequest.setTeamMember("");
ztTaskCreateRequest.setMultiple("");
ztTaskCreateRequest.setMode("");
ztTaskCreateRequest.setStory("");
ztTaskCreateRequest.setStoryEstimate("");
ztTaskCreateRequest.setStoryDesc("");
ztTaskCreateRequest.setStoryPri("");
ztTaskCreateRequest.setColor("#ff0000");
ztTaskCreateRequest.setName("测试任务1");
ztTaskCreateRequest.setPri("1");
ztTaskCreateRequest.setEstimate("1");
ztTaskCreateRequest.setDesc("任务描述");
ztTaskCreateRequest.setEstStarted(DateUtil.date().toString("yyyy-MM-dd"));
ztTaskCreateRequest.setDeadline(DateUtil.date().toString("yyyy-MM-dd"));
ztTaskCreateRequest.setMailtos(Collections.emptyList());
ZtTaskCreateResponse ztTaskCreateResponse = instance.getZtTaskService().create(ztTaskCreateRequest);
System.out.println(JSONUtil.toJsonPrettyStr(ztTaskCreateResponse));
ZtTaskGetResponse ztTaskGetResponse = instance.getZtTaskService().getByName(ztExecutionCreateResponse.getId(), "测试任务1");
// 开始任务
ZtTaskStartRequest ztTaskStartRequest = new ZtTaskStartRequest();
ztTaskStartRequest.setTaskId(ztTaskGetResponse.getResult().getId());
ztTaskStartRequest.setAssignedTo("");
ztTaskStartRequest.setRealStarted(DateUtil.date().toString("yyyy-MM-dd HH:mm:ss"));
ztTaskStartRequest.setConsumed(ztTaskGetResponse.getResult().getConsumed());
ztTaskStartRequest.setLeft(ztTaskGetResponse.getResult().getLeft());
ztTaskStartRequest.setComment("备注");
ZtTaskStartResponse ztTaskStartResponse = instance.getZtTaskService().start(ztTaskStartRequest);
System.out.println(JSONUtil.toJsonPrettyStr(ztTaskStartResponse));
// 完成任务
ZtTaskFinishRequest ztTaskFinishRequest = new ZtTaskFinishRequest();
ztTaskFinishRequest.setTaskId(ztTaskGetResponse.getResult().getId());
ztTaskFinishRequest.setAssignedTo("");
ztTaskFinishRequest.setRealStarted(DateUtil.date().toString("yyyy-MM-dd HH:mm:ss"));
ztTaskFinishRequest.setConsumed(ztTaskGetResponse.getResult().getConsumed());
ztTaskFinishRequest.setComment("备注");
ZtTaskFinishResponse ztTaskFinishResponse = instance.getZtTaskService().finish(ztTaskFinishRequest);
System.out.println(JSONUtil.toJsonPrettyStr(ztTaskFinishResponse));
// 关闭任务
ZtTaskCloseRequest ztTaskCloseRequest = new ZtTaskCloseRequest();
ztTaskCloseRequest.setTaskId(ztTaskCreateResponse.getId());
ztTaskCloseRequest.setComment("备注");
ZtTaskCloseResponse ztTaskCloseResponse = instance.getZtTaskService().close(ztTaskCloseRequest);
System.out.println(JSONUtil.toJsonPrettyStr(ztTaskCloseResponse));
// 删除任务
ZtTaskDeleteRequest ztTaskDeleteRequest = new ZtTaskDeleteRequest();
ztTaskDeleteRequest.setTaskId(ztTaskCreateResponse.getId());
ZtTaskDeleteResponse ztTaskDeleteResponse = instance.getZtTaskService().delete(ztTaskDeleteRequest);
System.out.println(JSONUtil.toJsonPrettyStr(ztTaskDeleteResponse));
}
}
// 关闭项目
ZtProjectCloseRequest ztProjectCloseRequest = new ZtProjectCloseRequest();
ztProjectCloseRequest.setProjectId(createProjectResponse.getId());
ztProjectCloseRequest.setComment("");
ztProjectCloseRequest.setRealEnd(DateUtil.today());
ZtProjectCloseResponse closeProjectResponse = instance.getZtProjectService().close(ztProjectCloseRequest);
System.out.println(JSONUtil.toJsonPrettyStr(closeProjectResponse));
// 激活项目
ZtProjectActivateRequest ztProjectActivateRequest = new ZtProjectActivateRequest();
ztProjectActivateRequest.setProjectId(createProjectResponse.getId());
ztProjectActivateRequest.setComment("");
ztProjectActivateRequest.setBegin(DateUtil.today());
ZtProjectActivateResponse activateProjectResponse = instance.getZtProjectService().activate(ztProjectActivateRequest);
System.out.println(JSONUtil.toJsonPrettyStr(activateProjectResponse));
// 删除项目
ZtProjectDeleteRequest ztProjectDeleteRequest = new ZtProjectDeleteRequest();
ztProjectDeleteRequest.setProjectId(createProjectResponse.getId());
ZtProjectDeleteResponse ztProjectDeleteResponse = instance.getZtProjectService().delete(ztProjectDeleteRequest);
System.out.println(JSONUtil.toJsonPrettyStr(ztProjectDeleteResponse));
}
}
Loading…
Cancel
Save

Powered by TurnKey Linux.