123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- package v1
- import (
- "github.com/druidcaesa/gotool"
- "strconv"
- "strings"
- "time"
- "ulink-admin/frame"
- "ulink-admin/modules/doc/models/model"
- "ulink-admin/modules/doc/models/req"
- "ulink-admin/modules/doc/service"
- "ulink-admin/pkg/excels"
- "ulink-admin/pkg/file"
- "ulink-admin/pkg/page"
- "ulink-admin/pkg/resp"
- )
- type DocArticleApi struct {
- docArticleService service.DocArticleService
- }
- // List 查询文章分页数据
- // @Summary 分页查询文章数据接口
- // @Description 分页查询文章数据接口
- // @Tags 文章相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param object query req.DocArticleQuery false "查询参数"
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=page.Page{list=model.DocArticle},msg=string} "分页获取文章列表,返回包括列表,总数,页码,每页数量"
- // @Router /docarticle/list [get]
- func (a DocArticleApi) List(c *frame.Context) {
- query := req.DocArticleQuery{}
- if c.Bind(&query) != nil {
- resp.ParamError(c)
- return
- }
- list, i := a.docArticleService.FindList(query)
- resp.OK(c, page.Page{
- List: list,
- Total: i,
- Size: query.PageSize,
- })
- }
- // List 查询文章所有数据
- // @Summary 查询全部数据文章数据接口
- // @Description 查询全部数据文章数据接口
- // @Tags 文章相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=model.DocArticle,msg=string} "分页获取文章列表,返回包括列表,总数,页码,每页数量"
- // @Router /docarticle/listAll [get]
- func (a DocArticleApi) ListAll(c *frame.Context) {
- list := a.docArticleService.FindAll()
- resp.OK(c, list)
- }
- // Get 根据文章Id获取详细信息
- // @Summary 文章详情查询接口
- // @Description 文章详情查询接口
- // @Tags 文章相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param id path int true "id" id
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=model.DocArticle,msg=string} "返回文章详情查询"
- // @Router /docarticle [get]
- func (a DocArticleApi) Get(c *frame.Context) {
- param := c.Param("id")
- id, _ := strconv.ParseInt(param, 10, 64)
- resp.OK(c, a.docArticleService.GetDocArticleById(id))
- }
- // Add 新增文章
- // @Summary 新增文章接口
- // @Description 新增文章接口
- // @Tags 文章相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param data body model.DocArticle true "文章实体对象"
- // @Success 200 {object} resp.Response{msg=string} "操作状态"
- // @Router /docarticle/add [post]
- func (a DocArticleApi) Add(c *frame.Context) {
- docArticle := model.DocArticle{}
- if err := c.Bind(&docArticle); err != nil {
- resp.ParamError(c, map[string]string{"error": err.Error()})
- return
- }
- docArticle.CreateBy = admin.GetUserInfo(c).UserName
- docArticle.CreateTime = time.Now()
- docArticle.UpdateBy = admin.GetUserInfo(c).UserName
- docArticle.UpdateTime = time.Now()
- if a.docArticleService.Insert(&docArticle) {
- resp.OK(c)
- } else {
- resp.Error(c)
- }
- }
- // Edit 修改文章数据接口
- // @Summary 修改文章接口
- // @Description 新增文章接口
- // @Tags 文章相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param data body model.DocArticle true "文章实体对象"
- // @Success 200 {object} resp.Response{msg=string} "操作状态"
- // @Router /docarticle/edit [put]
- func (a DocArticleApi) Edit(c *frame.Context) {
- docArticle := model.DocArticle{}
- if c.Bind(&docArticle) != nil {
- resp.ParamError(c)
- return
- }
- docArticle.UpdateBy = admin.GetUserInfo(c).UserName
- docArticle.UpdateTime = time.Now()
- if a.docArticleService.Update(&docArticle) {
- resp.OK(c)
- } else {
- resp.Error(c)
- }
- }
- // Delete 删除文章数据
- // @Summary 删除文章接口
- // @Description 删除文章接口
- // @Tags 文章相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param id path int true "id" id
- // @Success 200 {object} resp.Response{msg=string} "操作状态"
- // @Router /docarticle [delete]
- func (a DocArticleApi) Delete(c *frame.Context) {
- //获取docArticleId
- param := c.Param("id")
- list := make([]int64, 0)
- if gotool.StrUtils.HasNotEmpty(param) {
- strs := strings.Split(param, ",")
- for _, str := range strs {
- id, _ := strconv.ParseInt(str, 10, 64)
- list = append(list, id)
- }
- }
- //判断是否可以删除
- if a.docArticleService.Delete(list) {
- resp.OK(c)
- } else {
- resp.Error(c)
- }
- }
- // Export 导出excel
- func (a DocArticleApi) Export(c *frame.Context) {
- query := req.DocArticleQuery{}
- if c.Bind(&query) != nil {
- resp.ParamError(c)
- return
- }
- list, _ := a.docArticleService.FindList(query)
- excelList := make([]interface{}, 0)
- for _, docArticle := range *list {
- excelList = append(excelList, docArticle)
- }
- _, files := excels.ExportExcel(excelList, "文章数据表")
- file.DownloadExcel(c, files)
- }
|