parent
71264e9ac3
commit
ac79a9142e
@ -0,0 +1,40 @@ |
||||
package cn.linghang.mywust.core.request.factory.library.request; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.StringJoiner; |
||||
|
||||
@Data |
||||
public class SearchRequest { |
||||
private final List<Object> filterFieldList = new ArrayList<>(); |
||||
private final String collapseField = "groupId"; |
||||
private final String sortType = "desc"; |
||||
private final String indexName = "idx.opac"; |
||||
private final String sortField = "relevance"; |
||||
|
||||
private final List<QueryFieldListItem> queryFieldList = new ArrayList<>(1); |
||||
|
||||
private int pageSize; |
||||
private int page; |
||||
|
||||
public SearchRequest(String keyWord, int pageSize, int page) { |
||||
this.pageSize = pageSize; |
||||
this.page = page; |
||||
this.queryFieldList.add(new QueryFieldListItem(keyWord)); |
||||
} |
||||
|
||||
@Data |
||||
public static class QueryFieldListItem { |
||||
private final String field = "all"; |
||||
private final String operator = "*"; |
||||
private final int logic = 0; |
||||
|
||||
private final List<String> values = new ArrayList<>(1); |
||||
|
||||
public QueryFieldListItem(String keyWord) { |
||||
values.add(keyWord); |
||||
} |
||||
} |
||||
} |
@ -1,30 +0,0 @@ |
||||
package cn.linghang.mywust.core.request.factory.library.response; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class BaseInfo { |
||||
|
||||
@JsonProperty("map") |
||||
private Map map; |
||||
|
||||
@JsonProperty("empty") |
||||
private boolean empty; |
||||
|
||||
public void setMap(Map map) { |
||||
this.map = map; |
||||
} |
||||
|
||||
public Map getMap() { |
||||
return map; |
||||
} |
||||
|
||||
public void setEmpty(boolean empty) { |
||||
this.empty = empty; |
||||
} |
||||
|
||||
public boolean isEmpty() { |
||||
return empty; |
||||
} |
||||
} |
@ -1,30 +0,0 @@ |
||||
package cn.linghang.mywust.core.request.factory.library.response; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class DetailInfo { |
||||
|
||||
@JsonProperty("map") |
||||
private Map map; |
||||
|
||||
@JsonProperty("empty") |
||||
private boolean empty; |
||||
|
||||
public void setMap(Map map) { |
||||
this.map = map; |
||||
} |
||||
|
||||
public Map getMap() { |
||||
return map; |
||||
} |
||||
|
||||
public void setEmpty(boolean empty) { |
||||
this.empty = empty; |
||||
} |
||||
|
||||
public boolean isEmpty() { |
||||
return empty; |
||||
} |
||||
} |
@ -1,30 +0,0 @@ |
||||
package cn.linghang.mywust.core.request.factory.library.response; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class ExtraInfo { |
||||
|
||||
@JsonProperty("map") |
||||
private Map map; |
||||
|
||||
@JsonProperty("empty") |
||||
private boolean empty; |
||||
|
||||
public void setMap(Map map) { |
||||
this.map = map; |
||||
} |
||||
|
||||
public Map getMap() { |
||||
return map; |
||||
} |
||||
|
||||
public void setEmpty(boolean empty) { |
||||
this.empty = empty; |
||||
} |
||||
|
||||
public boolean isEmpty() { |
||||
return empty; |
||||
} |
||||
} |
@ -1,49 +0,0 @@ |
||||
package cn.linghang.mywust.core.request.factory.library.response; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class LoanResultItem { |
||||
@JsonProperty("bibId") |
||||
private String bookId; |
||||
|
||||
@JsonProperty("bibAttrs") |
||||
private BookAttribute bookAttribute; |
||||
|
||||
@JsonProperty("returnDate") |
||||
private String returnDate; |
||||
|
||||
@JsonProperty("loanDate") |
||||
private String loanDate; |
||||
|
||||
@JsonProperty("location") |
||||
private String location; |
||||
|
||||
@JsonProperty("barCode") |
||||
private String barCode; |
||||
|
||||
@Data |
||||
public static class BookAttribute { |
||||
@JsonProperty("pub_year") |
||||
private String publishYear; |
||||
|
||||
@JsonProperty("author") |
||||
private String author; |
||||
|
||||
@JsonProperty("callno") |
||||
private String callNumber; |
||||
|
||||
@JsonProperty("isbn") |
||||
private String isbn; |
||||
|
||||
@JsonProperty("classno") |
||||
private String classNumber; |
||||
|
||||
@JsonProperty("publisher") |
||||
private String publisher; |
||||
|
||||
@JsonProperty("title") |
||||
private String title; |
||||
} |
||||
} |
@ -1,64 +0,0 @@ |
||||
package cn.linghang.mywust.core.request.factory.library.response; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class Map<S, S1> { |
||||
@JsonProperty("baseInfo") |
||||
private BaseInfo baseInfo; |
||||
|
||||
@JsonProperty("detailInfo") |
||||
private DetailInfo detailInfo; |
||||
|
||||
@JsonProperty("extraInfo") |
||||
private ExtraInfo extraInfo; |
||||
|
||||
@JsonProperty("score") |
||||
private int score; |
||||
|
||||
@JsonProperty("_clickCount") |
||||
private int clickCount; |
||||
|
||||
@JsonProperty("collected") |
||||
private boolean collected; |
||||
|
||||
@JsonProperty("出版发行项") |
||||
private String publisher; |
||||
|
||||
@JsonProperty("个人责任者") |
||||
private String author; |
||||
|
||||
@JsonProperty("提要文摘附注") |
||||
private String describe; |
||||
|
||||
@JsonProperty("ISBN及定价") |
||||
private String isbn; |
||||
|
||||
@JsonProperty("载体形态项") |
||||
private String size; |
||||
|
||||
@JsonProperty("学科主题") |
||||
private String category; |
||||
|
||||
@JsonProperty("使用对象附注") |
||||
private String reader; |
||||
|
||||
@JsonProperty("责任者附注") |
||||
private String authorDescribe; |
||||
|
||||
@JsonProperty("中图法分类号") |
||||
private String clcNumber; |
||||
|
||||
@JsonProperty("著录信息附注") |
||||
private String publishNotes; |
||||
|
||||
@JsonProperty("丛编项") |
||||
private String series; |
||||
|
||||
@JsonProperty("题名/责任者") |
||||
private String fullTitle; |
||||
|
||||
@JsonProperty("title") |
||||
private String title; |
||||
} |
@ -1,17 +0,0 @@ |
||||
package cn.linghang.mywust.core.request.factory.library.response; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
||||
public class Response{ |
||||
|
||||
@JsonProperty("map") |
||||
private Map map; |
||||
|
||||
public void setMap(Map map){ |
||||
this.map = map; |
||||
} |
||||
|
||||
public Map getMap(){ |
||||
return map; |
||||
} |
||||
} |
@ -1,150 +0,0 @@ |
||||
package cn.linghang.mywust.core.request.factory.library.response; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class SearchResultItem { |
||||
/** |
||||
* 图书id |
||||
*/ |
||||
@JsonProperty("bibId") |
||||
private String bookId; |
||||
|
||||
/** |
||||
* 作者 |
||||
*/ |
||||
@JsonProperty("author") |
||||
private String author; |
||||
|
||||
/** |
||||
* 索书号 |
||||
*/ |
||||
@JsonProperty("callno") |
||||
private List<String> callNumber; |
||||
|
||||
/** |
||||
* doc类型 |
||||
*/ |
||||
@JsonProperty("docType") |
||||
private String docType; |
||||
|
||||
/** |
||||
* 分组id |
||||
*/ |
||||
@JsonProperty("groupId") |
||||
private String groupId; |
||||
|
||||
/** |
||||
* ISBN号 |
||||
*/ |
||||
@JsonProperty("isbn") |
||||
private String isbn; |
||||
|
||||
@JsonProperty("bibNo") |
||||
private String bibNo; |
||||
|
||||
/** |
||||
* 标题 |
||||
*/ |
||||
@JsonProperty("title") |
||||
private String title; |
||||
|
||||
/** |
||||
* 图书总数 |
||||
*/ |
||||
@JsonProperty("itemCount") |
||||
private int itemCount; |
||||
|
||||
/** |
||||
* 可借数 |
||||
*/ |
||||
@JsonProperty("circCount") |
||||
private int circCount; |
||||
|
||||
/** |
||||
* 出版年 |
||||
*/ |
||||
@JsonProperty("pub_year") |
||||
private String publishYear; |
||||
|
||||
/** |
||||
* 分类号 |
||||
*/ |
||||
@JsonProperty("classno") |
||||
private String classNumber; |
||||
|
||||
/** |
||||
* 出版商 |
||||
*/ |
||||
@JsonProperty("publisher") |
||||
private String publisher; |
||||
|
||||
/** |
||||
* 馆藏信息,原始数据为json字符串 |
||||
*/ |
||||
@JsonProperty("holdings") |
||||
private String collectionInfo; |
||||
|
||||
/** |
||||
* 馆藏信息 |
||||
*/ |
||||
@Data |
||||
public static class CollectionInfo { |
||||
/** |
||||
* 索书号 |
||||
*/ |
||||
@JsonProperty("callNo") |
||||
private String callNumber; |
||||
|
||||
/** |
||||
* 馆藏总数 |
||||
*/ |
||||
@JsonProperty("itemsCount") |
||||
private int itemsCount; |
||||
|
||||
/** |
||||
* 图书条码 |
||||
*/ |
||||
@JsonProperty("barCode") |
||||
private String barCode; |
||||
|
||||
/** |
||||
* 可借状态 |
||||
*/ |
||||
@JsonProperty("circStatus") |
||||
private int circStatus; |
||||
|
||||
/** |
||||
* 书籍分卷信息 |
||||
*/ |
||||
@JsonProperty("vol") |
||||
private String vol; |
||||
|
||||
/** |
||||
* 图书可借状态 |
||||
*/ |
||||
@JsonProperty("itemsAvailable") |
||||
private int itemsAvailable; |
||||
|
||||
/** |
||||
* 所属馆藏地 |
||||
*/ |
||||
@JsonProperty("location") |
||||
private String location; |
||||
|
||||
/** |
||||
* 捐赠者id |
||||
*/ |
||||
@JsonProperty("donatorId") |
||||
private Object donatorId; |
||||
|
||||
/** |
||||
* 状态信息 |
||||
*/ |
||||
@JsonProperty("status") |
||||
private String status; |
||||
} |
||||
} |
@ -1,56 +0,0 @@ |
||||
package cn.linghang.mywust.core.request.factory.undergrade; |
||||
|
||||
import cn.linghang.mywust.network.entitys.FormBodyBuilder; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* <p>课表请求参数生成</p> |
||||
* <p>由于请求参数生成部分过于庞大和丑陋,不适合放在总的Factory,因此单独拎出来了</p> |
||||
* |
||||
* @author lensfrex |
||||
* @create 2022-10-27 10:17 |
||||
*/ |
||||
public class CourseTableRequestParamFactory { |
||||
// 课表请求的谜之参数,貌似是固定的
|
||||
// 其实都可以靠解析html中id为Form1的表单获得(input和select两种所有元素的值),这样可以防止系统作妖改掉这些值
|
||||
// 但为了快速起见,免去重复解析,直接使用也是没有什么大问题的,估计在很长的一段时间内这部分都是不会改的
|
||||
protected static final Map<String, String> COURSE_TABLE_MAGIC_QUERY_PARAMS = generateMagicQueryParam(); |
||||
|
||||
private static final String MAGIC_PARAM_PREFIX_0 = "7DF471C4FF954CFA9C691580B8214B36-"; |
||||
private static final String MAGIC_PARAM_PREFIX_1 = "EEBED1036A7B4991BF01CBFD47908031-"; |
||||
private static final String MAGIC_PARAM_PREFIX_2 = "711BA240F1B0462C9359E3CC28D57EBE-"; |
||||
private static final String MAGIC_PARAM_PREFIX_3 = "2A9E45FD425B477AB74272EF70478E1A-"; |
||||
private static final String MAGIC_PARAM_PREFIX_4 = "91826EDF3A594498A9F761D685EEAE96-"; |
||||
private static final String MAGIC_PARAM_PREFIX_5 = "ACC171586F9245B09C86C589102423B4-"; |
||||
|
||||
private static Map<String, String> generateMagicQueryParam() { |
||||
FormBodyBuilder formBodyBuilder = new FormBodyBuilder(true); |
||||
for (int i = 0; i < 6; i++) { |
||||
formBodyBuilder |
||||
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_0 + i + "-1") |
||||
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_1 + i + "-1") |
||||
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_2 + i + "-1") |
||||
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_3 + i + "-1") |
||||
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_4 + i + "-1") |
||||
.add("jx0415zbdiv_1", MAGIC_PARAM_PREFIX_5 + i + "-1") |
||||
|
||||
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_0 + i + "-2") |
||||
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_1 + i + "-2") |
||||
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_2 + i + "-2") |
||||
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_3 + i + "-2") |
||||
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_4 + i + "-2") |
||||
.add("jx0415zbdiv_2", MAGIC_PARAM_PREFIX_5 + i + "-2"); |
||||
} |
||||
|
||||
formBodyBuilder |
||||
.add("jx0404id", "") |
||||
.add("cj0701id", "") |
||||
.add("zc", "") |
||||
.add("demo", "") |
||||
.add("sfFD", "1") |
||||
.add("kbjcmsid", "9486203B90F3E3CBE0532914A8C03BE2"); |
||||
|
||||
return formBodyBuilder.build(); |
||||
} |
||||
} |
@ -0,0 +1,66 @@ |
||||
package cn.linghang.mywust.core.request.service.library; |
||||
|
||||
import cn.linghang.mywust.core.exception.ApiException; |
||||
import cn.linghang.mywust.core.request.factory.library.LibraryRequestFactory; |
||||
import cn.linghang.mywust.network.Requester; |
||||
import cn.linghang.mywust.network.entitys.HttpRequest; |
||||
import cn.linghang.mywust.network.entitys.HttpResponse; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* 图书馆相关接口,由于返回的数据都是json,特别好解析,所以这里的数据获取到了之后可以直接拿来用,自己来解析 |
||||
*/ |
||||
public class LibraryApiService extends LibraryApiServiceBase { |
||||
public LibraryApiService(Requester requester) { |
||||
super(requester); |
||||
} |
||||
|
||||
public String search(String keyword, int page, int pageSize) throws ApiException, IOException { |
||||
HttpRequest request = LibraryRequestFactory.bookSearchRequest(keyword, page, pageSize); |
||||
HttpResponse response = requester.post(request); |
||||
checkResponse(response); |
||||
|
||||
return request.getStringData(); |
||||
} |
||||
|
||||
public String getBookDetail(String bookId) throws ApiException, IOException { |
||||
HttpRequest request = LibraryRequestFactory.bookInfoRequest(bookId); |
||||
HttpResponse response = requester.post(request); |
||||
checkResponse(response); |
||||
|
||||
return request.getStringData(); |
||||
} |
||||
|
||||
public String getBookCoverImageUrl(String isbn) throws ApiException, IOException { |
||||
HttpRequest request = LibraryRequestFactory.bookCoverImageUrlRequest(isbn); |
||||
HttpResponse response = requester.post(request); |
||||
checkResponse(response); |
||||
|
||||
return request.getStringData(); |
||||
} |
||||
|
||||
public String getOverdueSoon(String cookie) throws ApiException, IOException { |
||||
HttpRequest request = LibraryRequestFactory.overdueSoonRequest(cookie); |
||||
HttpResponse response = requester.post(request); |
||||
checkResponse(response); |
||||
|
||||
return request.getStringData(); |
||||
} |
||||
|
||||
public String getCurrentLoan(String cookie) throws ApiException, IOException { |
||||
HttpRequest request = LibraryRequestFactory.currentLoanRequest(cookie); |
||||
HttpResponse response = requester.post(request); |
||||
checkResponse(response); |
||||
|
||||
return request.getStringData(); |
||||
} |
||||
|
||||
public String getLoanHistory(String cookie) throws ApiException, IOException { |
||||
HttpRequest request = LibraryRequestFactory.loanHistoryRequest(cookie); |
||||
HttpResponse response = requester.post(request); |
||||
checkResponse(response); |
||||
|
||||
return request.getStringData(); |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
package cn.linghang.mywust.core.request.service.library; |
||||
|
||||
import cn.linghang.mywust.core.exception.ApiException; |
||||
import cn.linghang.mywust.network.Requester; |
||||
import cn.linghang.mywust.network.entitys.HttpResponse; |
||||
|
||||
public abstract class LibraryApiServiceBase { |
||||
protected final Requester requester; |
||||
|
||||
public LibraryApiServiceBase(Requester requester) { |
||||
this.requester = requester; |
||||
} |
||||
|
||||
public void checkResponse(HttpResponse response) throws ApiException { |
||||
// 检查响应是否正确
|
||||
if (response.getStatusCode() != 200) { |
||||
throw new ApiException(ApiException.Code.COOKIE_INVALID); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue