Skip to main content

EpisodeService

Struct EpisodeService 

Source
pub struct EpisodeService;
Expand description

话数服务

提供话数及关联数据(统计、发布)的完整业务逻辑。

Implementations§

Source§

impl EpisodeService

Source

pub async fn select_list_by_manga_id( state: &AppState, manga_id: i32, ) -> ApiResult<Vec<EpisodeSimpleListVo>>

按漫画 ID 查询话数简单列表。

返回包含文件信息的精简话数列表,用于上传页展示。 结果按 manga_episode 升序排列,仅包含未删除的话数记录。

§返回值

返回漫画下所有未删除的话数列表,按 manga_episode 排序。

§Errors
  • AppError::Database — 数据库查询失败
§Examples
use tdm_server::service::episode_service::EpisodeService;

let episodes = EpisodeService::select_list_by_manga_id(&state, manga_id).await?;
for ep in &episodes {
    println!("话数 {}: {}", ep.manga_episode, ep.manga_episode_name);
}
Source

pub async fn update_manga_episodes( state: &AppState, requests: Vec<PublishLinkRequest>, ) -> ApiResult<()>

批量更新话数发布链接。

接收一组发布链接请求,批量更新数据库中的链接字段。 更新完成后会刷新任务追踪缓存,并为每个话数触发 RSS 订阅源刷新。

§Errors
  • AppError::Database — 数据库更新失败
§Examples
let requests = vec![
    PublishLinkRequest { id: 1, publish_link: Some("https://example.com/1".into()) },
    PublishLinkRequest { id: 2, publish_link: Some("https://example.com/2".into()) },
];
EpisodeService::update_manga_episodes(&state, requests).await?;

更新单条话数的发布链接。

在写入前会检查新链接是否与其他话数冲突。更新成功后同样 会刷新任务追踪缓存和 RSS 订阅源。

§Errors
  • AppError::business("发布链接已存在喵") — 链接与其他话数冲突
  • AppError::Database — 数据库操作失败
§Examples
EpisodeService::update_publish_link(
    &state,
    42,
    Some("https://example.com/ch42".to_string()),
).await?;
Source

pub async fn page_episode( state: &AppState, page: i32, page_size: i32, manga_id: i32, ) -> ApiResult<PageBean<EpisodeListVo>>

分页查询漫画话数。

获取指定漫画下的全部话数列表,然后在内存中进行分页截取。 返回标准分页对象 PageBean,包含当前页数据、总条数和总页数。

§Errors
  • AppError::Database — 数据库查询失败
§Examples
// 查询第 1 页,每页 20 条
let page = EpisodeService::page_episode(&state, 1, 20, manga_id).await?;
println!("共 {} 条,当前页 {} 条", page.total, page.rows.len());
Source

pub async fn delete_episode(state: &AppState, id: i32) -> ApiResult<()>

删除指定话数(软删除)。

将话数标记为删除状态,同时刷新任务追踪缓存并触发 RSS 订阅源 全量刷新。注意:此操作不会立即从数据库中物理删除数据。

§Errors
  • AppError::Database — 数据库操作失败
§Examples
EpisodeService::delete_episode(&state, episode_id).await?;
Source

pub async fn add_episodes( state: &AppState, dto: EpisodeEditDto, ) -> ApiResult<()>

新增话数(对齐 Java addEpisodes)。

支持两种模式:

  • 批量模式:指定 manga_episode 起始值和 manga_episode_end 结束值, 在区间内逐条创建话数。
  • 单话模式:仅指定 manga_episode,创建一条话数记录。

创建完成后会刷新任务追踪缓存并触发 RSS 全量刷新。

§Errors
  • AppError::business("缺少漫画 ID") — DTO 中未提供 manga_id
  • AppError::business("起始话数格式不正确") — 话数序号不是有效整数
  • AppError::business("结束话数格式不正确") — 结束序号不是有效整数
  • AppError::business("该漫画单话已存在喵!") — 话数序号重复
  • AppError::business("发布链接已存在喵") — 链接与其他话数冲突
  • AppError::Database — 数据库操作失败
§Examples
// 批量创建话数 1~10
let dto = EpisodeEditDto {
    manga_id: Some(100),
    manga_episode: Some("1".into()),
    manga_episode_end: Some("10".into()),
    ..Default::default()
};
EpisodeService::add_episodes(&state, dto).await?;

// 创建单话
let dto = EpisodeEditDto {
    manga_id: Some(100),
    manga_episode: Some("11".into()),
    ..Default::default()
};
EpisodeService::add_episodes(&state, dto).await?;
Source

pub async fn get_manga_episode_by_id( state: &AppState, id: i32, ) -> ApiResult<EpisodeDetailVo>

按 ID 查询单条话数详情。

返回话数的完整信息,包括主表字段和详情字段。 如果话数已被软删除或不存在,返回业务错误。

§Errors
  • AppError::business("话数不存在喵") — 指定 ID 的话数不存在
  • AppError::Database — 数据库查询失败
§Examples
let episode = EpisodeService::get_manga_episode_by_id(&state, 42).await?;
println!("话数名称: {}", episode.manga_episode_name);
Source

pub async fn get_newest_manga_episode_by_id( state: &AppState, manga_id: i32, ) -> ApiResult<NewestEpisodeVo>

查询漫画最新话。

获取指定漫画下序号最大的话数记录。常用于展示连载漫画的 最近更新情况。

§Errors
  • AppError::business("该漫画尚无单话喵") — 漫画下没有话数记录
  • AppError::Database — 数据库查询失败
§Examples
let newest = EpisodeService::get_newest_manga_episode_by_id(&state, manga_id).await?;
println!("最新话: {}", newest.manga_episode);
Source

pub async fn update_manga_episode( state: &AppState, dto: EpisodeEditDto, ) -> ApiResult<()>

更新话数信息。

根据 DTO 中提供的字段更新话数主表。更新完成后刷新任务追踪 缓存并触发 RSS 全量刷新。

§Errors
  • AppError::Database — 数据库更新失败
§Examples
let dto = EpisodeEditDto {
    id: Some(42),
    manga_episode_name: Some("新标题".into()),
    ..Default::default()
};
EpisodeService::update_manga_episode(&state, dto).await?;
Source

pub async fn get_uploaded_submit( state: &AppState, page: i32, page_size: i32, manga_tran_name: Option<String>, username: Option<String>, ) -> ApiResult<PageBean<UploadPageVo>>

分页查询已上传稿件列表。

在数据库层面执行分页查询和计数,支持按漫画译名和用户名筛选。 返回标准分页对象 PageBean<UploadPageVo>

§Errors
  • AppError::Database — 数据库查询失败
§Examples
// 按译名筛选,查询第 1 页
let page = EpisodeService::get_uploaded_submit(
    &state, 1, 20,
    Some("进击的巨人".into()),
    None,
).await?;
Source

pub async fn get_statistics( state: &AppState, start: &str, end: &str, ) -> ApiResult<Statistics>

任意时间段统计

Source

pub async fn get_statistics_list(state: &AppState) -> ApiResult<Vec<Statistics>>

预设时间段统计列表(6 项:日/月/年 + 上期对比)

Source

pub async fn get_member_statistics( state: &AppState, start: DateTime<Utc>, end: DateTime<Utc>, ) -> ApiResult<Vec<MemberStatistics>>

组员完成统计

Source

pub async fn rollback_episode( state: &AppState, episode_id: i32, workflow_type: &str, ) -> ApiResult<()>

回退流程

Source

pub async fn upload_manga_file( state: &AppState, data: Bytes, episode_id: i32, my_name: &str, manga_id: i32, original_filename: &str, ) -> ApiResult<()>

上传话数工作文件(对齐 Java MangaFileUtils + 更新 DB 路径)

Source

pub async fn download_episode_file( state: &AppState, req: EpisodeDownloadRequest, ) -> ApiResult<(String, Bytes)>

下载话数工作文件(legacy 路径 → 规范目录 → OSS 回退)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more