main
			
			
		
		
							parent
							
								
									26aaad57cc
								
							
						
					
					
						commit
						166efc7f1b
					
				
									
										
											File diff suppressed because it is too large
											Load Diff
										
									
								
							
						@ -1 +1 @@ | 
				
			||||
Subproject commit e186a0d9f014c27aecbfd0775302dcb99ce89619 | 
				
			||||
Subproject commit 5fd50991814322760c7f4fb8b17a51ae8270e973 | 
				
			||||
@ -0,0 +1,32 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.library.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
 | 
				
			||||
@Slf4j | 
				
			||||
public abstract class BaseService { | 
				
			||||
    protected LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) { | 
				
			||||
        return switch (e.getCode()) { | 
				
			||||
            case NETWORK_EXCEPTION -> new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
            case COOKIE_INVALID -> new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    LibraryRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
            ); | 
				
			||||
            default -> { | 
				
			||||
                log.error("图书馆:{}代理请求异常,异常未处理", subModuleCode.name()); | 
				
			||||
                log.error("异常:", e); | 
				
			||||
                yield new LibraryRpcException( | 
				
			||||
                        LibraryRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                        subModuleCode, | 
				
			||||
                        LibraryRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
        }; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,33 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.library.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.library.BookCoverImageUrlApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class BookCoverImageUrlService extends BaseService { | 
				
			||||
    private final BookCoverImageUrlApiService service; | 
				
			||||
 | 
				
			||||
    public BookCoverImageUrlService(BookCoverImageUrlApiService service) { | 
				
			||||
        this.service = service; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getBookCoverImageUrl(String isbn) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return service.getBookCoverImageUrl(isbn); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PUBLIC_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,33 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.library.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.library.BookDetailApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class BookDetailService extends BaseService { | 
				
			||||
    private final BookDetailApiService service; | 
				
			||||
 | 
				
			||||
    public BookDetailService(BookDetailApiService service) { | 
				
			||||
        this.service = service; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getBookDetail(String bookId) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return service.getBookDetail(bookId); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PUBLIC_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,33 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.library.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.library.CurrentLoanApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class CurrentLoanService extends BaseService { | 
				
			||||
    private final CurrentLoanApiService service; | 
				
			||||
 | 
				
			||||
    public CurrentLoanService(CurrentLoanApiService service) { | 
				
			||||
        this.service = service; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCurrentLoan(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return service.getCurrentLoan(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PERSONAL_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,32 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.library.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.library.LoanHistoryApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class LoanHistoryService extends BaseService { | 
				
			||||
    private final LoanHistoryApiService service; | 
				
			||||
 | 
				
			||||
    public LoanHistoryService(LoanHistoryApiService service) { | 
				
			||||
        this.service = service; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getLoanHistory(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return service.getLoanHistory(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PERSONAL_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,32 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.library.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.library.OverdueSoonApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class OverdueSoonService extends BaseService { | 
				
			||||
    private final OverdueSoonApiService service; | 
				
			||||
 | 
				
			||||
    public OverdueSoonService(OverdueSoonApiService service) { | 
				
			||||
        this.service = service; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getOverdueSoon(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return service.getOverdueSoon(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PERSONAL_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,8 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.library.services; | 
				
			||||
 | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class ParseService { | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -1,129 +0,0 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.library.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.library.LibraryApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.mywust.network.RequestClientOption; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@Slf4j | 
				
			||||
@ApplicationScoped | 
				
			||||
public class RequestAgentService { | 
				
			||||
    private final LibraryApiService libraryApiService; | 
				
			||||
 | 
				
			||||
    public RequestAgentService(LibraryApiService libraryApiService) { | 
				
			||||
        this.libraryApiService = libraryApiService; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getBookCoverImageUrl(String isbn) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return libraryApiService.getBookCoverImageUrl(isbn); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PUBLIC_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getBookDetail(String bookId) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return libraryApiService.getBookDetail(bookId); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PUBLIC_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCurrentLoan(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return libraryApiService.getCurrentLoan(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PERSONAL_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String search(String keyword, int page, int pageSize) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return libraryApiService.search(keyword, page, pageSize); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PUBLIC_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getLoanHistory(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return libraryApiService.getLoanHistory(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PERSONAL_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getOverdueSoon(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return libraryApiService.getOverdueSoon(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PERSONAL_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) { | 
				
			||||
        return switch (e.getCode()) { | 
				
			||||
            case NETWORK_EXCEPTION -> new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
            case COOKIE_INVALID -> new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    LibraryRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
            ); | 
				
			||||
            default -> { | 
				
			||||
                log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name()); | 
				
			||||
                log.error("异常:", e); | 
				
			||||
                yield new LibraryRpcException( | 
				
			||||
                        LibraryRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                        subModuleCode, | 
				
			||||
                        LibraryRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
        }; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,32 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.library.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.library.SearchApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class SearchService extends BaseService { | 
				
			||||
    private final SearchApiService service; | 
				
			||||
 | 
				
			||||
    public SearchService(SearchApiService service) { | 
				
			||||
        this.service = service; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String search(String keyword, int page, int pageSize) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return service.search(keyword, page, pageSize); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new LibraryRpcException( | 
				
			||||
                    LibraryRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    LibraryRpcException.SubModuleCode.PUBLIC_API, | 
				
			||||
                    LibraryRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,32 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.physics.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
 | 
				
			||||
@Slf4j | 
				
			||||
public abstract class BaseService { | 
				
			||||
    protected PhysicsRpcException wrapApiException(ApiException e, PhysicsRpcException.SubModuleCode subModuleCode) { | 
				
			||||
        return switch (e.getCode()) { | 
				
			||||
            case NETWORK_EXCEPTION -> new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    PhysicsRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
            case COOKIE_INVALID -> new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    PhysicsRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
            ); | 
				
			||||
            default -> { | 
				
			||||
                log.error("物理实验:{}代理请求异常,异常未处理", subModuleCode.name()); | 
				
			||||
                log.error("异常:", e); | 
				
			||||
                yield new PhysicsRpcException( | 
				
			||||
                        PhysicsRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                        subModuleCode, | 
				
			||||
                        PhysicsRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
        }; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,57 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.physics.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser; | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsCourseApiService; | 
				
			||||
import cn.wustlinghang.mywust.data.physics.PhysicsCourse; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.mywust.network.RequestClientOption; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class CourseTableService extends BaseService { | 
				
			||||
 | 
				
			||||
    private final RequestClientOption requestClientOption; | 
				
			||||
 | 
				
			||||
    private final PhysicsCourseApiService agent; | 
				
			||||
    private final PhysicsCoursePageParser parser; | 
				
			||||
 | 
				
			||||
    public CourseTableService(RequestClientOption requestClientOption, | 
				
			||||
                              PhysicsCourseApiService agent, | 
				
			||||
                              PhysicsCoursePageParser parser) { | 
				
			||||
        this.requestClientOption = requestClientOption; | 
				
			||||
 | 
				
			||||
        this.agent = agent; | 
				
			||||
        this.parser = parser; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCourseTable(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return agent.getPage(cookie, requestClientOption); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<PhysicsCourse> parseCourseTable(String data) throws PhysicsRpcException { | 
				
			||||
        try { | 
				
			||||
            return parser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,69 +0,0 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.physics.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser; | 
				
			||||
import cn.wustlinghang.mywust.core.parser.physics.PhysicsScorePageParser; | 
				
			||||
import cn.wustlinghang.mywust.data.global.Score; | 
				
			||||
import cn.wustlinghang.mywust.data.physics.PhysicsCourse; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.util.ArrayList; | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class ParseService { | 
				
			||||
    private final PhysicsCoursePageParser coursePageParser; | 
				
			||||
    private final PhysicsScorePageParser scorePageParser; | 
				
			||||
 | 
				
			||||
    public ParseService(PhysicsCoursePageParser coursePageParser, | 
				
			||||
                        PhysicsScorePageParser scorePageParser) { | 
				
			||||
        this.coursePageParser = coursePageParser; | 
				
			||||
        this.scorePageParser = scorePageParser; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<PhysicsCourse> parseCourseTable(String data) throws PhysicsRpcException { | 
				
			||||
        try { | 
				
			||||
            return coursePageParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<Score> parseScore(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return scorePageParser.parse(data); | 
				
			||||
        } catch (PhysicsRpcException e) { | 
				
			||||
            throw e; | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.SCORE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<Score> parseAllScore(List<String> pages) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            List<Score> scores = new ArrayList<>(); | 
				
			||||
            for (String page : pages) { | 
				
			||||
                scores.addAll(scorePageParser.parse(page)); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            return scores; | 
				
			||||
        } catch (PhysicsRpcException e) { | 
				
			||||
            throw e; | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.SCORE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,91 +0,0 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.physics.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsCourseApiService; | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsScoreApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.mywust.exception.ParseException; | 
				
			||||
import cn.wustlinghang.mywust.network.RequestClientOption; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@Slf4j | 
				
			||||
@ApplicationScoped | 
				
			||||
public class RequestAgentService { | 
				
			||||
 | 
				
			||||
    private final RequestClientOption requestClientOption; | 
				
			||||
 | 
				
			||||
    private final PhysicsCourseApiService physicsCourseApiService; | 
				
			||||
    private final PhysicsScoreApiService physicsScoreApiService; | 
				
			||||
 | 
				
			||||
    public RequestAgentService(RequestClientOption requestClientOption, | 
				
			||||
                               PhysicsCourseApiService physicsCourseApiService, | 
				
			||||
                               PhysicsScoreApiService physicsScoreApiService) { | 
				
			||||
        this.requestClientOption = requestClientOption; | 
				
			||||
 | 
				
			||||
        this.physicsCourseApiService = physicsCourseApiService; | 
				
			||||
        this.physicsScoreApiService = physicsScoreApiService; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCourseTable(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return physicsCourseApiService.getPage(cookie, requestClientOption); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<String> getScore(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return physicsScoreApiService.getAllPages(cookie, requestClientOption); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.SCORE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } catch (ParseException e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.OTHER_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.SCORE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private PhysicsRpcException wrapApiException(ApiException e, PhysicsRpcException.SubModuleCode subModuleCode) { | 
				
			||||
        return switch (e.getCode()) { | 
				
			||||
            case NETWORK_EXCEPTION -> new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    PhysicsRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
            case COOKIE_INVALID -> new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    PhysicsRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
            ); | 
				
			||||
            default -> { | 
				
			||||
                log.error("物理实验:{}代理请求异常,异常未处理", subModuleCode.name()); | 
				
			||||
                log.error("异常:", e); | 
				
			||||
                yield new PhysicsRpcException( | 
				
			||||
                        PhysicsRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                        subModuleCode, | 
				
			||||
                        PhysicsRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
        }; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,87 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.physics.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.physics.PhysicsScorePageParser; | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsScoreApiService; | 
				
			||||
import cn.wustlinghang.mywust.data.global.Score; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.mywust.exception.ParseException; | 
				
			||||
import cn.wustlinghang.mywust.network.RequestClientOption; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
import java.util.ArrayList; | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class ScoreService extends BaseService { | 
				
			||||
 | 
				
			||||
    private final RequestClientOption requestClientOption; | 
				
			||||
 | 
				
			||||
    private final PhysicsScoreApiService agent; | 
				
			||||
    private final PhysicsScorePageParser parser; | 
				
			||||
 | 
				
			||||
    public ScoreService(RequestClientOption requestClientOption, | 
				
			||||
                        PhysicsScoreApiService agent, | 
				
			||||
                        PhysicsScorePageParser parser) { | 
				
			||||
        this.requestClientOption = requestClientOption; | 
				
			||||
 | 
				
			||||
        this.agent = agent; | 
				
			||||
        this.parser = parser; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<String> getScore(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return agent.getAllPages(cookie, requestClientOption); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.SCORE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } catch (ParseException e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.OTHER_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.SCORE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    public List<Score> parseScore(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return parser.parse(data); | 
				
			||||
        } catch (PhysicsRpcException e) { | 
				
			||||
            throw e; | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.SCORE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<Score> parseScore(List<String> pages) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            List<Score> scores = new ArrayList<>(); | 
				
			||||
            for (String page : pages) { | 
				
			||||
                scores.addAll(parser.parse(page)); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            return scores; | 
				
			||||
        } catch (PhysicsRpcException e) { | 
				
			||||
            throw e; | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new PhysicsRpcException( | 
				
			||||
                    PhysicsRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    PhysicsRpcException.SubModuleCode.SCORE, | 
				
			||||
                    PhysicsRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,32 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
 | 
				
			||||
@Slf4j | 
				
			||||
public abstract class BaseService { | 
				
			||||
    protected UndergradRpcException wrapApiException(ApiException e, UndergradRpcException.SubModuleCode subModuleCode) { | 
				
			||||
        return switch (e.getCode()) { | 
				
			||||
            case NETWORK_EXCEPTION -> new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
            case COOKIE_INVALID -> new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    UndergradRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
            ); | 
				
			||||
            default -> { | 
				
			||||
                log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name()); | 
				
			||||
                log.error("异常:", e); | 
				
			||||
                yield new UndergradRpcException( | 
				
			||||
                        UndergradRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                        subModuleCode, | 
				
			||||
                        UndergradRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
        }; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,58 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradCourseTableParser; | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCourseTableApiService; | 
				
			||||
import cn.wustlinghang.mywust.data.global.Course; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class CourseTableService extends BaseService { | 
				
			||||
    private final UndergradCourseTableParser courseTableParser; | 
				
			||||
    private final UndergradCourseTableApiService courseTableApiService; | 
				
			||||
 | 
				
			||||
    public CourseTableService(UndergradCourseTableParser courseTableParser, | 
				
			||||
                              UndergradCourseTableApiService courseTableApiService) { | 
				
			||||
        this.courseTableParser = courseTableParser; | 
				
			||||
        this.courseTableApiService = courseTableApiService; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCourseTable(String cookie, String term) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return courseTableApiService.getPage(term, cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.COURSE_TABLE); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<Course> parseCourseTable(String data) throws UndergradRpcException { | 
				
			||||
        try { | 
				
			||||
            if (data.contains("评教")) { | 
				
			||||
                throw new UndergradRpcException( | 
				
			||||
                        UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                        UndergradRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                        UndergradRpcException.ErrorCode.NEED_EVALUATE | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            return courseTableParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,53 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradCreditStatusParser; | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCreditStatusApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.mywust.network.RequestClientOption; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class CreditStatusService extends BaseService { | 
				
			||||
    private final UndergradCreditStatusApiService creditStatusApiService; | 
				
			||||
    private final UndergradCreditStatusParser creditStatusParser; | 
				
			||||
 | 
				
			||||
    private final RequestClientOption requestClientOption; | 
				
			||||
    public CreditStatusService(UndergradCreditStatusApiService creditStatusApiService, | 
				
			||||
                               UndergradCreditStatusParser creditStatusParser, | 
				
			||||
                               RequestClientOption requestClientOption) { | 
				
			||||
        this.creditStatusApiService = creditStatusApiService; | 
				
			||||
        this.creditStatusParser = creditStatusParser; | 
				
			||||
 | 
				
			||||
        this.requestClientOption = requestClientOption; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCreditStatus(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return creditStatusApiService.getPage(cookie, requestClientOption, false); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.CREDIT_STATUS); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.CREDIT_STATUS, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String parseCreditStatus(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return creditStatusParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.CREDIT_STATUS, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,34 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class ExamActivitiesService extends BaseService { | 
				
			||||
    private final UndergradExamDelayApiService examDelayApiService; | 
				
			||||
 | 
				
			||||
    public ExamActivitiesService(UndergradExamDelayApiService examDelayApiService) { | 
				
			||||
        this.examDelayApiService = examDelayApiService; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public UndergradExamDelayApiService.ExamActivity[] getExamActivities(String cookie, String term) | 
				
			||||
            throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return examDelayApiService.getActivities(term, cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,51 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradExamDelayParser; | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService; | 
				
			||||
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class ExamDelayApplicationService extends BaseService { | 
				
			||||
    private final UndergradExamDelayApiService examDelayApiService; | 
				
			||||
    private final UndergradExamDelayParser examDelayParser; | 
				
			||||
 | 
				
			||||
    public ExamDelayApplicationService(UndergradExamDelayApiService examDelayApiService, | 
				
			||||
                                       UndergradExamDelayParser examDelayParser) { | 
				
			||||
        this.examDelayApiService = examDelayApiService; | 
				
			||||
        this.examDelayParser = examDelayParser; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getExamDelayApplications(String cookie, String term, String activityId) | 
				
			||||
            throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return examDelayApiService.getPage(term, activityId, cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<ExamDelayApplication> parseExamDelayApplications(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return examDelayParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,132 +0,0 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.undergraduate.*; | 
				
			||||
import cn.wustlinghang.mywust.data.global.Course; | 
				
			||||
import cn.wustlinghang.mywust.data.global.Score; | 
				
			||||
import cn.wustlinghang.mywust.data.global.StudentInfo; | 
				
			||||
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; | 
				
			||||
import cn.wustlinghang.mywust.exception.ParseException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class ParseService { | 
				
			||||
    private final UndergradCourseTableParser courseTableParser; | 
				
			||||
    private final UndergradScoreParser scoreParser; | 
				
			||||
    private final UndergradStudentInfoPageParser studentInfoPageParser; | 
				
			||||
    private final UndergradTrainingPlanPageParser trainingPlanPageParser; | 
				
			||||
    private final UndergradCreditStatusParser creditStatusParser; | 
				
			||||
    private final UndergradExamDelayParser examDelayParser; | 
				
			||||
 | 
				
			||||
    public ParseService(UndergradCourseTableParser courseTableParser, | 
				
			||||
                        UndergradScoreParser scoreParser, | 
				
			||||
                        UndergradStudentInfoPageParser studentInfoPageParser, | 
				
			||||
                        UndergradTrainingPlanPageParser trainingPlanPageParser, | 
				
			||||
                        UndergradCreditStatusParser creditStatusParser, | 
				
			||||
                        UndergradExamDelayParser examDelayParser) { | 
				
			||||
 | 
				
			||||
        this.courseTableParser = courseTableParser; | 
				
			||||
        this.scoreParser = scoreParser; | 
				
			||||
        this.studentInfoPageParser = studentInfoPageParser; | 
				
			||||
        this.trainingPlanPageParser = trainingPlanPageParser; | 
				
			||||
        this.creditStatusParser = creditStatusParser; | 
				
			||||
        this.examDelayParser = examDelayParser; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<Course> parseCourseTable(String data) throws UndergradRpcException { | 
				
			||||
        try { | 
				
			||||
            if (data.contains("评教")) { | 
				
			||||
                throw new UndergradRpcException( | 
				
			||||
                        UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                        UndergradRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                        UndergradRpcException.ErrorCode.NEED_EVALUATE | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            return courseTableParser.parse(data); | 
				
			||||
 | 
				
			||||
        } catch (UndergradRpcException e) { | 
				
			||||
            throw e; | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<Score> parseScore(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            if (data.contains("评教")) { | 
				
			||||
                throw new UndergradRpcException( | 
				
			||||
                        UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                        UndergradRpcException.SubModuleCode.SCORE, | 
				
			||||
                        UndergradRpcException.ErrorCode.NEED_EVALUATE | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            return scoreParser.parse(data); | 
				
			||||
 | 
				
			||||
        } catch (UndergradRpcException e) { | 
				
			||||
            throw e; | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.SCORE, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public StudentInfo parseStudentInfo(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return studentInfoPageParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.STUDENT_INFO, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String parseTrainingPlan(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return trainingPlanPageParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.TRAINING_PLAN, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String parseCreditStatus(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return creditStatusParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.CREDIT_STATUS, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<ExamDelayApplication> parseExamDelayApplications(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return examDelayParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,166 +0,0 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.undergraduate.*; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.mywust.network.RequestClientOption; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@Slf4j | 
				
			||||
@ApplicationScoped | 
				
			||||
public class RequestAgentService { | 
				
			||||
    private final UndergradCourseTableApiService courseTableApiService; | 
				
			||||
    private final UndergradScoreApiService scoreApiService; | 
				
			||||
    private final UndergradStudentInfoApiService studentInfoApiService; | 
				
			||||
    private final UndergradTrainingPlanApiService trainingPlanApiService; | 
				
			||||
    private final UndergradCreditStatusApiService creditStatusApiService; | 
				
			||||
    private final UndergradExamDelayApiService examDelayApiService; | 
				
			||||
 | 
				
			||||
    private final RequestClientOption requestClientOption; | 
				
			||||
 | 
				
			||||
    public RequestAgentService(UndergradCourseTableApiService courseTableApiService, | 
				
			||||
                               UndergradScoreApiService scoreApiService, | 
				
			||||
                               UndergradStudentInfoApiService studentInfoApiService, | 
				
			||||
                               UndergradTrainingPlanApiService trainingPlanApiService, | 
				
			||||
                               UndergradCreditStatusApiService creditStatusApiService, | 
				
			||||
                               UndergradExamDelayApiService examDelayApiService, | 
				
			||||
                               RequestClientOption requestClientOption) { | 
				
			||||
 | 
				
			||||
        this.courseTableApiService = courseTableApiService; | 
				
			||||
        this.scoreApiService = scoreApiService; | 
				
			||||
        this.studentInfoApiService = studentInfoApiService; | 
				
			||||
        this.trainingPlanApiService = trainingPlanApiService; | 
				
			||||
        this.creditStatusApiService = creditStatusApiService; | 
				
			||||
        this.examDelayApiService = examDelayApiService; | 
				
			||||
 | 
				
			||||
        this.requestClientOption = requestClientOption; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getStudentInfoPage(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return studentInfoApiService.getPage(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.STUDENT_INFO); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.STUDENT_INFO, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCourseTable(String cookie, String term) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return courseTableApiService.getPage(term, cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.COURSE_TABLE); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.COURSE_TABLE, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getScore(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return scoreApiService.getPage(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.SCORE); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.SCORE, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getTrainingPlan(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return trainingPlanApiService.getPage(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.TRAINING_PLAN); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.TRAINING_PLAN, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getCreditStatus(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return creditStatusApiService.getPage(cookie, requestClientOption, false); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.CREDIT_STATUS); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.CREDIT_STATUS, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public UndergradExamDelayApiService.ExamActivity[] getExamActivities(String cookie, String term) | 
				
			||||
            throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return examDelayApiService.getActivities(term, cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getExamDelayApplications(String cookie, String term, String activityId) | 
				
			||||
            throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return examDelayApiService.getPage(term, activityId, cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private UndergradRpcException wrapApiException(ApiException e, UndergradRpcException.SubModuleCode subModuleCode) { | 
				
			||||
        return switch (e.getCode()) { | 
				
			||||
            case NETWORK_EXCEPTION -> new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
            case COOKIE_INVALID -> new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                    subModuleCode, | 
				
			||||
                    UndergradRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
            ); | 
				
			||||
            default -> { | 
				
			||||
                log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name()); | 
				
			||||
                log.error("异常:", e); | 
				
			||||
                yield new UndergradRpcException( | 
				
			||||
                        UndergradRpcException.TypeCode.AUTH_EXCEPTION, | 
				
			||||
                        subModuleCode, | 
				
			||||
                        UndergradRpcException.ErrorCode.COOKIE_INVALID | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
        }; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,58 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradScoreParser; | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradScoreApiService; | 
				
			||||
import cn.wustlinghang.mywust.data.global.Score; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
import java.util.List; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class ScoreService extends BaseService { | 
				
			||||
    private final UndergradScoreApiService scoreApiService; | 
				
			||||
    private final UndergradScoreParser scoreParser; | 
				
			||||
 | 
				
			||||
    public ScoreService(UndergradScoreApiService scoreApiService, | 
				
			||||
                        UndergradScoreParser scoreParser) { | 
				
			||||
        this.scoreApiService = scoreApiService; | 
				
			||||
        this.scoreParser = scoreParser; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getScore(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return scoreApiService.getPage(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.SCORE); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.SCORE, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public List<Score> parseScore(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            if (data.contains("评教")) { | 
				
			||||
                throw new UndergradRpcException( | 
				
			||||
                        UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                        UndergradRpcException.SubModuleCode.SCORE, | 
				
			||||
                        UndergradRpcException.ErrorCode.NEED_EVALUATE | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            return scoreParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.SCORE, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,49 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradStudentInfoPageParser; | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradStudentInfoApiService; | 
				
			||||
import cn.wustlinghang.mywust.data.global.StudentInfo; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class StudentInfoService extends BaseService { | 
				
			||||
    private final UndergradStudentInfoApiService studentInfoApiService; | 
				
			||||
    private final UndergradStudentInfoPageParser studentInfoPageParser; | 
				
			||||
 | 
				
			||||
    public StudentInfoService(UndergradStudentInfoApiService studentInfoApiService, | 
				
			||||
                              UndergradStudentInfoPageParser studentInfoPageParser) { | 
				
			||||
        this.studentInfoApiService = studentInfoApiService; | 
				
			||||
        this.studentInfoPageParser = studentInfoPageParser; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getStudentInfoPage(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return studentInfoApiService.getPage(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.STUDENT_INFO); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.STUDENT_INFO, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public StudentInfo parseStudentInfo(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return studentInfoPageParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.STUDENT_INFO, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,48 @@ | 
				
			||||
package cn.wustlinghang.wusthelper.internal.undergrad.services; | 
				
			||||
 | 
				
			||||
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradTrainingPlanPageParser; | 
				
			||||
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradTrainingPlanApiService; | 
				
			||||
import cn.wustlinghang.mywust.exception.ApiException; | 
				
			||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; | 
				
			||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; | 
				
			||||
import jakarta.enterprise.context.ApplicationScoped; | 
				
			||||
 | 
				
			||||
import java.io.IOException; | 
				
			||||
 | 
				
			||||
@ApplicationScoped | 
				
			||||
public class TrainingPlanService extends BaseService { | 
				
			||||
    private final UndergradTrainingPlanApiService trainingPlanApiService; | 
				
			||||
    private final UndergradTrainingPlanPageParser trainingPlanPageParser; | 
				
			||||
 | 
				
			||||
    public TrainingPlanService(UndergradTrainingPlanApiService trainingPlanApiService, | 
				
			||||
                               UndergradTrainingPlanPageParser trainingPlanPageParser) { | 
				
			||||
        this.trainingPlanApiService = trainingPlanApiService; | 
				
			||||
        this.trainingPlanPageParser = trainingPlanPageParser; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String getTrainingPlan(String cookie) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return trainingPlanApiService.getPage(cookie); | 
				
			||||
        } catch (ApiException e) { | 
				
			||||
            throw wrapApiException(e, UndergradRpcException.SubModuleCode.TRAINING_PLAN); | 
				
			||||
        } catch (IOException e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.NETWORK_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.TRAINING_PLAN, | 
				
			||||
                    UndergradRpcException.ErrorCode.NETWORK_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public String parseTrainingPlan(String data) throws RpcException { | 
				
			||||
        try { | 
				
			||||
            return trainingPlanPageParser.parse(data); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            throw new UndergradRpcException( | 
				
			||||
                    UndergradRpcException.TypeCode.PARSE_EXCEPTION, | 
				
			||||
                    UndergradRpcException.SubModuleCode.TRAINING_PLAN, | 
				
			||||
                    UndergradRpcException.ErrorCode.PARSE_ERROR | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue