123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733 |
- package semantic_analysis
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- saModel "eta/eta_api/models/semantic_analysis"
- "eta/eta_api/services"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "html"
- "strconv"
- "strings"
- "time"
- )
- // SaCompareController 语义分析-文档比对
- type SaCompareController struct {
- controllers.BaseAuthController
- }
- // Save
- // @Title 保存比对
- // @Description 保存比对
- // @Param request body saModel.SaCompareSaveReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /compare/save [post]
- func (this *SaCompareController) Save() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req saModel.SaCompareSaveReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- req.Title = strings.TrimSpace(req.Title)
- if req.Title == "" {
- br.Msg = "请输入比对名称"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择比对分类"
- return
- }
- if len(req.CompareList) == 0 {
- br.Msg = "请选择比对文档"
- return
- }
- //secIds := make([]int, 0)
- for _, d := range req.CompareList {
- if d.SaDocId <= 0 {
- br.Msg = "文档ID有误"
- return
- }
- //for _, s := range d.SectionList {
- // if !utils.InArrayByInt(secIds, s.SaDocSectionId) {
- // secIds = append(secIds, s.SaDocSectionId)
- // }
- //}
- }
- // 标题去重
- existItem := new(saModel.SaCompare)
- existCond := fmt.Sprintf(` AND %s = ?`, saModel.SaCompareColumns.Title)
- existPars := make([]interface{}, 0)
- existPars = append(existPars, req.Title)
- e := existItem.GetItemByCondition(existCond, existPars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取重名标题的比对失败"
- br.ErrMsg = "获取重名标题比对失败, Err: " + e.Error()
- return
- }
- if existItem != nil && existItem.SaCompareId > 0 {
- if existItem.SaCompareId != req.SaCompareId {
- br.Msg = "标题已存在"
- return
- }
- }
- nowTime := time.Now().Local()
- compareClassifyItem := new(saModel.SaCompareClassify)
- if e := compareClassifyItem.GetItemById(req.ClassifyId); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取比对分类信息失败, Err: " + e.Error()
- return
- }
- compareItem := new(saModel.SaCompare)
- updateCols := make([]string, 0)
- if req.SaCompareId > 0 {
- // 编辑
- if e := compareItem.GetItemById(req.SaCompareId); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取比对信息失败, Err: " + e.Error()
- return
- }
- compareItem.ClassifyId = req.ClassifyId
- compareItem.ClassifyName = compareClassifyItem.ClassifyName
- compareItem.Title = req.Title
- compareItem.ModifyTime = nowTime
- updateCols = []string{
- saModel.SaCompareColumns.ClassifyId, saModel.SaCompareColumns.ClassifyName, saModel.SaCompareColumns.Title,
- saModel.SaCompareColumns.ModifyTime,
- }
- } else {
- // 新增
- compareItem.ClassifyId = req.ClassifyId
- compareItem.ClassifyName = compareClassifyItem.ClassifyName
- compareItem.Title = req.Title
- compareItem.SysAdminId = this.SysUser.AdminId
- compareItem.SysAdminName = this.SysUser.RealName
- compareItem.CreateTime = nowTime
- compareItem.ModifyTime = nowTime
- }
- // 标签匹配
- labelOB := new(saModel.SaLabel)
- labelCond := ``
- labelPars := make([]interface{}, 0)
- labelFields := []string{saModel.SaLabelColumns.SaLabelId, saModel.SaLabelColumns.LabelName}
- labelItems, e := labelOB.GetItemsByCondition(labelCond, labelPars, labelFields, "")
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取标签列表失败, Err: " + e.Error()
- return
- }
- labelMap := make(map[int]string)
- for _, l := range labelItems {
- labelMap[l.SaLabelId] = l.LabelName
- }
- // 段落和标签
- compareDocs := make([]*saModel.SaCompareDoc, 0)
- compareLabels := make([]*saModel.SaCompareLabel, 0)
- for _, v := range req.CompareList {
- compareDocs = append(compareDocs, &saModel.SaCompareDoc{
- DocId: v.SaDocId,
- })
- for _, s := range v.SectionList {
- for _, l := range s.LabelIds {
- compareLabels = append(compareLabels, &saModel.SaCompareLabel{
- DocId: v.SaDocId,
- SectionId: s.SaDocSectionId,
- LabelId: l,
- LabelName: labelMap[l],
- IsPart: s.IsPart,
- StartIndex: s.StartIndex,
- EndIndex: s.EndIndex,
- Content: html.EscapeString(s.Content),
- SysAdminId: this.SysUser.AdminId,
- SysAdminName: this.SysUser.RealName,
- CreateTime: nowTime,
- })
- }
- }
- }
- // 新增/更新比对
- if req.SaCompareId > 0 {
- if e := saModel.UpdateSaCompare(compareItem, compareDocs, compareLabels, updateCols); e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "更新比对失败, Err: " + e.Error()
- return
- }
- } else {
- if e := saModel.CreateSaCompare(compareItem, compareDocs, compareLabels); e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "新增比对失败, Err: " + e.Error()
- return
- }
- }
- // 获取表格数据
- compLabCond := fmt.Sprintf(` AND a.%s = ?`, saModel.SaCompareLabelColumns.CompareId)
- compLabPars := make([]interface{}, 0)
- compLabPars = append(compLabPars, compareItem.SaCompareId)
- compLabs, e := saModel.GetSaCompareLabelByCond(compLabCond, compLabPars)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取比对标签列表失败, ErrMsg: " + e.Error()
- return
- }
- resp, e := services.FormatCompareLabels2TableData(compLabs)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取比对表格数据失败, ErrMsg: " + e.Error()
- return
- }
- resp.SaCompareId = compareItem.SaCompareId
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // PageList
- // @Title 文档比对列表
- // @Description 文档比对列表
- // @Param Keyword query string false "关键词"
- // @Param ClassifyId query int false "分类ID"
- // @Success 200 Ret=200 获取成功
- // @router /compare/page_list [get]
- func (this *SaCompareController) PageList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyword := this.GetString("Keyword", "")
- classifyId, _ := this.GetInt("ClassifyId", 0)
- var startSize int
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- itemOB := new(saModel.SaCompare)
- cond := ``
- pars := make([]interface{}, 0)
- if keyword != "" {
- kw := "%" + keyword + "%"
- cond += fmt.Sprintf(` AND %s LIKE ?`, saModel.SaCompareColumns.Title)
- pars = append(pars, kw)
- }
- if classifyId > 0 {
- cond += fmt.Sprintf(` AND %s = ?`, saModel.SaCompareColumns.ClassifyId)
- pars = append(pars, classifyId)
- }
- total, list, e := itemOB.GetPageItemsByCondition(startSize, pageSize, cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取文档列表失败, Err: " + e.Error()
- return
- }
- respList := make([]*saModel.SaCompareItem, 0)
- for i := range list {
- v := new(saModel.SaCompareItem)
- v.SaCompareId = list[i].SaCompareId
- v.ClassifyId = list[i].ClassifyId
- v.ClassifyName = list[i].ClassifyName
- v.Title = list[i].Title
- v.ResultImg = list[i].ResultImg
- v.SysAdminId = list[i].SysAdminId
- v.SysAdminName = list[i].SysAdminName
- v.CreateTime = list[i].CreateTime.Format(utils.FormatDateTime)
- respList = append(respList, v)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := &saModel.SaComparePageListResp{
- Paging: page,
- List: respList,
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // UpdateResultImg
- // @Title 更新比对结果图片
- // @Description 更新比对结果图片
- // @Param request body saModel.SaCompareUpdateResultImgReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /compare/update_result_img [post]
- func (this *SaCompareController) UpdateResultImg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req saModel.SaCompareUpdateResultImgReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.SaCompareId <= 0 {
- br.Msg = "参数有误"
- return
- }
- if req.ResultImg == "" {
- br.Msg = "请选择结果图片"
- return
- }
- compareItem := new(saModel.SaCompare)
- if e := compareItem.GetItemById(req.SaCompareId); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取比对信息失败, Err: " + e.Error()
- return
- }
- updateCols := []string{saModel.SaCompareColumns.ResultImg, saModel.SaCompareColumns.ModifyTime}
- compareItem.ResultImg = req.ResultImg
- compareItem.ModifyTime = time.Now().Local()
- if e := compareItem.Update(updateCols); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新语义分析图片失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // Detail
- // @Title 比对详情
- // @Description 比对详情
- // @Param CompareId query int true "比对ID"
- // @Success 200 Ret=200 获取成功
- // @router /compare/detail [get]
- func (this *SaCompareController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- compareId, _ := this.GetInt("CompareId", 0)
- if compareId <= 0 {
- br.Msg = "参数有误"
- return
- }
- compareItem := new(saModel.SaCompare)
- if e := compareItem.GetItemById(compareId); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取比对信息失败, Err: " + e.Error()
- return
- }
- // 比对文档IDs
- compDocOB := new(saModel.SaCompareDoc)
- compDocCond := fmt.Sprintf(` AND %s = ?`, saModel.SaCompareDocColumns.CompareId)
- compDocPars := make([]interface{}, 0)
- compDocPars = append(compDocPars, compareItem.SaCompareId)
- compDocs, e := compDocOB.GetItemsByCondition(compDocCond, compDocPars, []string{saModel.SaCompareDocColumns.DocId}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取比对文档失败, Err: " + e.Error()
- return
- }
- compDocIds := make([]int, 0)
- for _, d := range compDocs {
- compDocIds = append(compDocIds, d.DocId)
- }
- // 比对详情
- detail := new(saModel.SaCompareDetail)
- detail.SaCompareId = compareItem.SaCompareId
- detail.ClassifyId = compareItem.ClassifyId
- detail.ClassifyName = compareItem.ClassifyName
- detail.Title = compareItem.Title
- detail.ResultImg = compareItem.ResultImg
- detail.SysAdminId = compareItem.SysAdminId
- detail.SysAdminName = compareItem.SysAdminName
- detail.CreateTime = compareItem.CreateTime.Format(utils.FormatDateTime)
- // 文档详情
- docDetail, e := services.GetSaCompareDetailByDocIds(compDocIds, compareId, this.SysUser.AdminId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取比对详情信息失败, ErrMsg: " + e.Error()
- return
- }
- detail.HeadLabel = docDetail.HeadLabel
- detail.DocList = docDetail.DocList
- detail.KeywordsList = docDetail.KeywordsList
- br.Data = detail
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // SelectDocs
- // @Title 选择比对文档
- // @Description 选择比对文档
- // @Param DocIds query string true "文档IDs"
- // @Success 200 Ret=200 获取成功
- // @router /compare/select_docs [get]
- func (this *SaCompareController) SelectDocs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- docIdStr := this.GetString("DocIds", "")
- if docIdStr == "" {
- br.Msg = "请选择文档"
- return
- }
- docIds := make([]int, 0)
- docIdArr := strings.Split(docIdStr, ",")
- if len(docIdArr) == 0 {
- br.Msg = "请选择文档"
- return
- }
- if len(docIdArr) > 10 {
- br.Msg = "最多支持选择10个文档"
- return
- }
- for i := range docIdArr {
- d, e := strconv.Atoi(docIdArr[i])
- if e != nil {
- br.Msg = "文档ID有误"
- return
- }
- docIds = append(docIds, d)
- }
- resp, e := services.GetSaCompareDetailByDocIds(docIds, 0, this.SysUser.AdminId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取选择的文档详情失败, ErrMsg: " + e.Error()
- return
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Del
- // @Title 删除语义分析
- // @Description 删除语义分析
- // @Param request body saModel.SaCompareDelReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /compare/del [post]
- func (this *SaCompareController) Del() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req saModel.SaCompareDelReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.SaCompareId <= 0 {
- br.Msg = "参数有误"
- return
- }
- // TODO:可能会有只让自己或者管理员删除的需求,目前无
- item := new(saModel.SaCompare)
- e := item.GetItemById(req.SaCompareId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "文档比对已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取语义分析比对信息失败, Err: " + e.Error()
- return
- }
- // 删除比对及相关
- if e = saModel.DelSaCompare(item.SaCompareId); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "删除语义分析比对失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // SaveKeywords
- // @Title 保存关键词
- // @Description 保存比对
- // @Param request body saModel.SaCompareSearchKeywordSaveReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /compare/save_keywords [post]
- func (this *SaCompareController) SaveKeywords() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req saModel.SaCompareSearchKeywordSaveReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.SaCompareId <= 0 {
- br.Msg = "参数异常"
- return
- }
- keywords := make([]string, 0)
- for k := range req.Keywords {
- v := strings.TrimSpace(req.Keywords[k])
- if v != "" {
- keywords = append(keywords, v)
- }
- }
- keywordOB := new(saModel.SaCompareSearchKeyword)
- if e := keywordOB.DelAndCreateSearchKeywords(req.SaCompareId, keywords); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "保存搜索关键词失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // Move
- // @Title 移动比对
- // @Description 移动比对
- // @Param request body saModel.SaCompareMoveReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /compare/move [post]
- func (this *SaCompareController) Move() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req saModel.SaCompareMoveReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.SaCompareClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- if req.SaCompareId <= 0 {
- br.Msg = "参数异常"
- return
- }
- item := new(saModel.SaCompare)
- e := item.GetItemById(req.SaCompareId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "比对已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取比对信息失败, Err: " + e.Error()
- return
- }
- // 分类
- classifyItem := new(saModel.SaCompareClassify)
- if e = classifyItem.GetItemById(req.SaCompareClassifyId); e != nil {
- br.Msg = "分类信息有误"
- br.ErrMsg = "获取比对分类信息失败, Err: " + e.Error()
- return
- }
- // CV的指标库指标的移动, 没有技术, 全是感情~
- if req.PrevSaCompareId > 0 {
- prevCompare := new(saModel.SaCompare)
- if e = prevCompare.GetItemById(req.PrevSaCompareId); e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "上一个比对已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取上一个比对信息失败, Err: " + e.Error()
- return
- }
- // 如果是在两个比对之间
- if req.NextSaCompareId > 0 {
- nextCompare := new(saModel.SaCompare)
- if e = nextCompare.GetItemById(req.NextSaCompareId); e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "下一个比对已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取下一个比对信息失败, Err: " + e.Error()
- return
- }
- // 判断上一个比对与当前比对/下一个比对的位置
- if prevCompare.Sort == item.Sort || prevCompare.Sort == nextCompare.Sort {
- _ = saModel.UpdateSaCompareSort(prevCompare.ClassifyId, prevCompare.Sort, prevCompare.SaCompareId, `sort + 2`)
- } else {
- if nextCompare.Sort-prevCompare.Sort == 1 {
- _ = saModel.UpdateSaCompareSort(prevCompare.ClassifyId, prevCompare.Sort, prevCompare.SaCompareId, `sort + 1`)
- }
- }
- }
- item.Sort = prevCompare.Sort + 1
- } else {
- firstCompare, e := saModel.GetFirstSortSaCompare(req.SaCompareClassifyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "操作失败"
- br.ErrMsg = "获取首个比对失败, Err: " + e.Error()
- return
- }
- if firstCompare != nil && firstCompare.Sort == 0 {
- _ = saModel.UpdateSaCompareSort(firstCompare.ClassifyId, 0, firstCompare.SaCompareId-1, `sort + 1`)
- }
- item.Sort = 0
- }
- // 更新
- item.ClassifyId = classifyItem.SaCompareClassifyId
- item.ClassifyName = classifyItem.ClassifyName
- item.ModifyTime = time.Now().Local()
- updateCols := []string{
- saModel.SaCompareColumns.ClassifyId, saModel.SaCompareColumns.ClassifyName, saModel.SaCompareColumns.Sort, saModel.SaCompareColumns.ModifyTime,
- }
- if e = item.Update(updateCols); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "移动比对失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // Search
- // @Title 文档对比搜索(从es获取)
- // @Description 图表模糊搜索(从es获取)
- // @Param Keyword query string true "文档对比标题"
- // @Success 200 {object} saModel.CompareListByEsResp
- // @router /compare/search [get]
- func (this *SaCompareController) Search() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyword := this.GetString("Keyword")
- var searchList []*saModel.SaCompareElastic
- var total int
- var err error
- var list []*saModel.SaCompare
- saCompare := new(saModel.SaCompare)
- existCond := fmt.Sprintf(` AND result_img != ""`)
- existPars := make([]interface{}, 0)
- if keyword != "" {
- existCond += ` AND ( title LIKE ? )`
- existPars = append(existPars, utils.GetLikeKeyword(keyword))
- }
- total, list, err = saCompare.GetPageItemsByCondition(startSize, pageSize, existCond, existPars, []string{}, "")
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- tmp := new(saModel.SaCompareElastic)
- tmp.SaCompareId = v.SaCompareId
- tmp.ResultImg = v.ResultImg
- tmp.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
- tmp.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
- tmp.SysAdminId = v.SysAdminId
- tmp.SysAdminName = v.SysAdminName
- tmp.ClassifyId = v.ClassifyId
- tmp.ClassifyName = v.ClassifyName
- tmp.Title = v.Title
- searchList = append(searchList, tmp)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := saModel.CompareListByEsResp{
- Paging: page,
- List: searchList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|