Files
SGGL_HBAZ/SGGL/WebAPI/Controllers/HSSE/PdfBookController.cs
T
2026-09-11 11:14:08 +08:00

259 lines
9.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using BLL;
using System;
using System.Web.Http;
namespace WebAPI.Controllers.HSSE
{
/// <summary>
/// PDF 书籍模块接口(对应 PC 页面 HSSE/PDFDOC/PdfBookView.aspx 的完整功能:多级章节目录 + 富文本正文维护)。
/// 数据表:Sys_PdfBook / Sys_PdfChapter(目录层级 ParentChapterId+Level,正文为 UMeditor 富文本 HTML)。
/// 路由:api/PdfBook/{action},响应统一包装 Model.ResponeDatacode1正常 0异常)。
/// 鉴权:只读接口(getBooks/getChapterTree/getChapter/searchChapter)已加入权限过滤白名单,免登录;
/// 维护接口(add*/edit*/delete*/save*)需登录(请求头 token=用户/人员Id 或 FormsAuth 会话)。
/// </summary>
public class PdfBookController : ApiController
{
#region
/// <summary>获取书籍列表(含章节数,按登记时间升序)。</summary>
public Model.ResponeData getBooks()
{
var responeData = new Model.ResponeData();
try
{
responeData.data = APIPdfBookService.GetBooks();
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
/// <summary>获取某本书的多级章节目录树(嵌套 Children)。</summary>
/// <param name="bookId">书籍主键,必填。</param>
public Model.ResponeData getChapterTree(string bookId)
{
var responeData = new Model.ResponeData();
try
{
responeData.data = APIPdfBookService.GetChapterTree(bookId);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
/// <summary>获取章节正文详情(含富文本 HTML 与纯文本)。</summary>
/// <param name="chapterId">章节主键,必填。</param>
public Model.ResponeData getChapter(string chapterId)
{
var responeData = new Model.ResponeData();
try
{
var detail = APIPdfBookService.GetChapterDetail(chapterId);
if (detail == null)
{
responeData.code = 0;
responeData.message = "章节不存在或已被删除";
}
else
{
responeData.data = detail;
}
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
/// <summary>章节关键词检索(正文 HTML 先转纯文本再匹配,返回命中片段)。</summary>
[HttpPost]
public Model.ResponeData searchChapter([FromBody] SearchRequest request)
{
var responeData = new Model.ResponeData();
try
{
if (request == null)
throw new Exception("请求参数不能为空");
responeData.data = APIPdfBookService.SearchChapter(request.keyword, request.bookId);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region
/// <summary>新增书籍,返回新书籍 BookId。</summary>
[HttpPost]
public Model.ResponeData addBook([FromBody] AddBookRequest request)
{
var responeData = new Model.ResponeData();
try
{
if (request == null)
throw new Exception("请求参数不能为空");
responeData.data = new { bookId = APIPdfBookService.AddBook(request.title, request.createUser) };
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
/// <summary>新增章节(parentChapterId 为空=顶级章节),返回新章节 ChapterId。</summary>
[HttpPost]
public Model.ResponeData addChapter([FromBody] AddChapterRequest request)
{
var responeData = new Model.ResponeData();
try
{
if (request == null)
throw new Exception("请求参数不能为空");
responeData.data = new
{
chapterId = APIPdfBookService.AddChapter(request.bookId, request.parentChapterId, request.chapterTitle, request.createUser)
};
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
/// <summary>编辑章节名称。</summary>
[HttpPost]
public Model.ResponeData editChapter([FromBody] EditChapterRequest request)
{
var responeData = new Model.ResponeData();
try
{
if (request == null)
throw new Exception("请求参数不能为空");
APIPdfBookService.EditChapter(request.chapterId, request.chapterTitle);
responeData.data = true;
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
/// <summary>删除章节及其全部子章节,data 返回删除的章节总数。</summary>
[HttpPost]
public Model.ResponeData deleteChapter([FromBody] DeleteChapterRequest request)
{
var responeData = new Model.ResponeData();
try
{
if (request == null)
throw new Exception("请求参数不能为空");
responeData.data = new { deletedCount = APIPdfBookService.DeleteChapter(request.chapterId) };
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
/// <summary>保存章节正文(富文本 HTML,同页面"保存内容")。</summary>
[HttpPost]
public Model.ResponeData saveContent([FromBody] SaveContentRequest request)
{
var responeData = new Model.ResponeData();
try
{
if (request == null)
throw new Exception("请求参数不能为空");
APIPdfBookService.SaveContent(request.chapterId, request.content);
responeData.data = true;
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region
/// <summary>章节关键词检索请求。</summary>
public class SearchRequest
{
/// <summary>检索关键词,必填。</summary>
public string keyword { get; set; }
/// <summary>书籍主键;不传/为空则全库检索。</summary>
public string bookId { get; set; }
}
/// <summary>新增书籍请求。</summary>
public class AddBookRequest
{
/// <summary>书名,必填。</summary>
public string title { get; set; }
/// <summary>登记人(缺省 "api")。</summary>
public string createUser { get; set; }
}
/// <summary>新增章节请求。</summary>
public class AddChapterRequest
{
/// <summary>所属书籍主键,必填。</summary>
public string bookId { get; set; }
/// <summary>父章节主键;为空=顶级章节。</summary>
public string parentChapterId { get; set; }
/// <summary>章节名称,必填。</summary>
public string chapterTitle { get; set; }
/// <summary>登记人(预留)。</summary>
public string createUser { get; set; }
}
/// <summary>编辑章节请求。</summary>
public class EditChapterRequest
{
/// <summary>章节主键,必填。</summary>
public string chapterId { get; set; }
/// <summary>新章节名称,必填。</summary>
public string chapterTitle { get; set; }
}
/// <summary>删除章节请求。</summary>
public class DeleteChapterRequest
{
/// <summary>章节主键,必填(连同全部子章节一并删除)。</summary>
public string chapterId { get; set; }
}
/// <summary>保存章节正文请求。</summary>
public class SaveContentRequest
{
/// <summary>章节主键,必填。</summary>
public string chapterId { get; set; }
/// <summary>正文内容(UMeditor 富文本 HTML),可为空串。</summary>
public string content { get; set; }
}
#endregion
}
}