dddd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
5.0 KiB

4 years ago
package archiveapi
import (
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/archivesmodel"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/gin-gonic/gin"
)
//图文信息模块
type GraphicInformation struct{}
//文档列表
func (g *GraphicInformation) ArchiveFileList(c *gin.Context) {
var requestData fileList
err := c.ShouldBindJSON(&requestData)
if err != nil {
response.Result(101, err, "参数错误!请重新提交!", c)
return
}
if requestData.ParentId == 0 {
response.Result(102, err, "参数错误!请重新提交!", c)
return
}
//查询条件
whereMap := commonus.MapOut()
whereMap["g_parent"] = requestData.ParentId
//判断集团
if requestData.Group != 0 {
whereMap["g_write_group"] = requestData.Group
}
//判断分厂
if requestData.Factory != 0 {
whereMap["g_write_bfid"] = requestData.Factory
}
//判断工段
if requestData.Position != 0 {
whereMap["g_ws_id"] = requestData.Position
}
//判断班组
if requestData.Team != 0 {
whereMap["g_team"] = requestData.Team
}
//判断所属栏目
if requestData.ColumnId != 0 {
whereMap["g_parent_sun"] = requestData.ColumnId
}
if requestData.PageSize == 0 {
requestData.PageSize = 20
}
if requestData.Page <= 0 {
requestData.Page = 1
}
// psge := (requestData.Page - 1) * requestData.PageSize
appointPages := commonus.CalculatePages(requestData.Page, requestData.PageSize)
var fileList []archivesmodel.ArchiveFile
var total int64 //获取所有数据
if requestData.Title != "" {
listTitleErr := global.GVA_DB_BooImgkDate.Where(whereMap).Where("`g_title` LIKE %?% AND `g_state` IN ?", requestData.Title, []int{1, 2, 3}).Order("`g_id` DESC").Limit(requestData.PageSize).Offset(appointPages).Find(&fileList).Error
if listTitleErr != nil {
response.Result(103, listTitleErr, "数据获取失败!", c)
return
}
counrErr := global.GVA_DB_BooImgkDate.Model(&fileList).Where(whereMap).Where("`g_title` LIKE %?% AND `g_state` IN ?", requestData.Title, []int{1, 2, 3}).Count(&total).Error
if counrErr != nil {
total = 0
}
} else {
listErr := global.GVA_DB_BooImgkDate.Where(whereMap).Where("`g_state` IN ?", []int{1, 2, 3}).Order("`g_id` DESC").Limit(requestData.PageSize).Offset(appointPages).Find(&fileList).Error
if listErr != nil {
response.Result(104, listErr, "数据获取失败!", c)
return
}
counrErr := global.GVA_DB_BooImgkDate.Model(&fileList).Where(whereMap).Where("`g_state` IN ?", []int{1, 2, 3}).Count(&total).Error
if counrErr != nil {
total = 0
}
}
var fileListAry []callBackFilesList
for _, fileCont := range fileList {
var archiveTypeCont archivesmodel.ArchivesType
var fileListInfo callBackFilesList
fileListInfo.Id = fileCont.Id
fileListInfo.Title = fileCont.Title
fileListInfo.ColumnId = fileCont.ParentSun
archiveTypeCont.Id = fileCont.ParentSun
arcTypeErr := archiveTypeCont.GetArchiveTypeInfo()
// fmt.Printf("%v========>%v------->%v\n", arcTypeErr, archiveTypeCont, archiveTypeCont.Title)
if arcTypeErr == nil {
fileListInfo.ColumnTitle = archiveTypeCont.Title
} else {
fileListInfo.ColumnTitle = ""
}
reading, comment, collect, likes, tread, score := getBookArrter(fileCont.Id) //计算文章属性
fileListInfo.Reading = reading
fileListInfo.Comment = comment
fileListInfo.Collect = collect
fileListInfo.Likes = likes
fileListInfo.Tread = tread
fileListInfo.Score = score
fileListInfo.Scope = fileCont.VisitStrat
if fileCont.State == 2 {
fileListInfo.State = true
} else {
fileListInfo.State = false
}
fileListAry = append(fileListAry, fileListInfo)
}
countSum := len(fileListAry)
printData := commonus.OutPutList(total, int64(countSum), requestData.Page, requestData.PageSize, fileListAry)
// fmt.Printf("%v\n", printData)
response.Result(0, printData, "查询成功!", c)
}
//获取文档属性 global.GVA_DB_BookDate
func getBookArrter(id int64) (Reading, Comment, Collect, Likes, Tread, Score int64) {
var bookAttr archivesmodel.BookAttribute
readingErr := global.GVA_DB_BookDate.Model(&bookAttr).Where("`b_file_id` = ? AND `b_stater` = ? AND `b_type` = ?", id, 1, 1).Count(&Reading).Error
if readingErr != nil {
Reading = 0
}
collectErr := global.GVA_DB_BookDate.Model(&bookAttr).Where("`b_file_id` = ? AND `b_stater` = ? AND `b_type` = ?", id, 1, 2).Count(&Collect).Error
if collectErr != nil {
Collect = 0
}
likesErr := global.GVA_DB_BookDate.Model(&bookAttr).Where("`b_file_id` = ? AND `b_stater` = ? AND `b_type` = ?", id, 1, 3).Count(&Likes).Error
if likesErr != nil {
Likes = 0
}
treadErr := global.GVA_DB_BookDate.Model(&bookAttr).Where("`b_file_id` = ? AND `b_stater` = ? AND `b_type` = ?", id, 1, 3).Count(&Tread).Error
if treadErr != nil {
Tread = 0
}
var siscussMsg archivesmodel.DiscussMsg
commentErr := global.GVA_DB_BookDate.Model(&siscussMsg).Where("dis_file_id = ? AND dis_stater = ?", id, 2).Count(&Comment).Error
if commentErr != nil {
Comment = 0
}
return
}