1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672 |
- package ai
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/ai_summary"
- "eta_gn/eta_api/models/aimod"
- "eta_gn/eta_api/models/sandbox"
- saModel "eta_gn/eta_api/models/semantic_analysis"
- aiSummaryService "eta_gn/eta_api/services/ai_summary"
- "eta_gn/eta_api/services/aiser"
- "eta_gn/eta_api/utils"
- "fmt"
- "strconv"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // AiSummaryClassifyItems
- // @Title 获取所有ai纪要分类接口
- // @Description 获取所有ai纪要分类接口
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartClassifyListResp
- // @router /summary/classify/list [get]
- func (this *AiController) AiSummaryClassifyItems() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- resp := new(ai_summary.AiSummaryClassifyListResp)
- aiSummaryClassifyId, _ := this.GetInt("AiSummaryClassifyId")
- isShowMe, _ := this.GetBool("IsShowMe")
- if isShowMe {
- errMsg, err := aiSummaryService.GetAiSummaryClassifyListForMe(*this.SysUser, resp, aiSummaryClassifyId)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- fmt.Println("source my classify")
- return
- }
- rootList, err := ai_summary.GetAiSummaryClassifyAndInfoByParentId(aiSummaryClassifyId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- for k := range rootList {
- rootList[k].UniqueCode = strconv.Itoa(rootList[k].AiSummaryClassifyId) + "_" + strconv.Itoa(rootList[k].AiSummaryId)
- }
- classifyAll, err := ai_summary.GetAiSummaryClassifyAndInfoByParentId(aiSummaryClassifyId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- for k := range classifyAll {
- classifyAll[k].UniqueCode = strconv.Itoa(classifyAll[k].AiSummaryClassifyId) + "_" + strconv.Itoa(classifyAll[k].AiSummaryId)
- }
- nodeAll := make([]*ai_summary.AiSummaryClassifyItems, 0)
- for k := range rootList {
- rootNode := rootList[k]
- aiSummaryService.AiSummaryClassifyItemsMakeTreeV2(this.SysUser, classifyAll, rootNode)
- nodeAll = append(nodeAll, rootNode)
- }
- resp.AllNodes = nodeAll
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 新增ai纪要分类
- // @Description 新增ai纪要分类接口
- // @Param request body data_manage.AddChartClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /summary/classify/add [post]
- func (this *AiController) AddAiSummaryClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ai_summary.AddAiSummaryClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- if req.ParentId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- count, err := ai_summary.GetAiSummaryClassifyCount(req.ClassifyName, req.ParentId)
- if err != nil {
- br.Msg = "判断名称是否已存在失败"
- br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "分类名称已存在,请重新输入"
- br.IsSendEmail = false
- return
- }
- //获取该层级下最大的排序数
- maxSort, err := ai_summary.GetAiSummaryClassifyMaxSort(req.ParentId)
- classify := new(ai_summary.AiSummaryClassify)
- classify.ParentId = req.ParentId
- classify.ClassifyName = req.ClassifyName
- classify.HasData = 0
- classify.CreateTime = time.Now()
- classify.ModifyTime = time.Now()
- classify.SysUserId = this.SysUser.AdminId
- classify.SysUserRealName = this.SysUser.RealName
- classify.Level = req.Level + 1
- classify.Sort = maxSort + 1
- _, err = ai_summary.AddAiSummaryClassify(classify)
- if err != nil {
- br.Msg = "保存分类失败"
- br.ErrMsg = "保存分类失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- }
- // @Title 修改ai纪要分类
- // @Description 修改ai纪要分类接口
- // @Param request body data_manage.EditChartClassifyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /summary/classify/edit [post]
- func (this *AiController) EditAiSummaryClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ai_summary.EditAiSummaryClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- if req.AiSummaryClassifyId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err = ai_summary.EditSandboxClassify(req.AiSummaryClassifyId, req.ClassifyName)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 删除纪要分类检测接口
- // @Description 删除纪要分类检测接口
- // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
- // @Success 200 Ret=200 检测成功
- // @router /summary/classify/delete/check [post]
- func (this *AiController) DeleteSandboxClassifyCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ai_summary.AiSummaryClassifyDeleteCheckReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.AiSummaryClassifyId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- var deleteStatus int
- var tipsMsg string
- //删除分类
- if req.AiSummaryClassifyId > 0 {
- //判断分类下,是否含有纪要
- count, err := ai_summary.GetAiSummaryInfoCountByClassifyId(req.AiSummaryClassifyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- deleteStatus = 1
- tipsMsg = "该分类下关联沙盘不可删除"
- }
- }
- if deleteStatus != 1 {
- classifyCount, err := ai_summary.GetAiSummaryInfoCountByClassifyId(req.AiSummaryClassifyId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "删除失败"
- br.ErrMsg = "分类下是否含有沙盘失败,Err:" + err.Error()
- return
- }
- if classifyCount > 0 {
- deleteStatus = 2
- tipsMsg = "确认删除当前目录及包含的子目录吗"
- }
- }
- if deleteStatus == 0 {
- tipsMsg = "可删除,进行删除操作"
- }
- resp := new(sandbox.SandboxClassifyDeleteCheckResp)
- resp.DeleteStatus = deleteStatus
- resp.TipsMsg = tipsMsg
- br.Ret = 200
- br.Msg = "检测成功"
- br.Success = true
- br.Data = resp
- }
- // @Title 删除纪要分类/纪要
- // @Description 删除纪要分类/纪要接口
- // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /summary/classify/delete [post]
- func (this *AiController) DeleteAiSummaryClassify() {
- 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
- }
- var req ai_summary.DeleteAiSummaryClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.AiSummaryClassifyId < 0 && req.AiSummaryId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- //删除分类
- if req.AiSummaryClassifyId > 0 && req.AiSummaryId == 0 {
- //判断是否含有纪要
- childIds := make([]int, 0)
- classifyAll, err := ai_summary.GetAiSummaryClassifyAll()
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAllMap := make(map[int]*ai_summary.AiSummaryClassifyItems)
- for _, v := range classifyAll {
- classifyAllMap[v.AiSummaryClassifyId] = v
- }
- aiSummaryService.GetSummaryClassifyChildIds(req.AiSummaryClassifyId, classifyAllMap, &childIds)
- condition := ``
- pars := make([]interface{}, 0)
- if len(childIds) > 0 {
- ids := utils.IntArr2joinString(childIds, ",")
- condition = ` AND classify_id IN (` + ids + `) `
- } else {
- condition = ` AND classify_id = ? `
- pars = append(pars, req.AiSummaryClassifyId)
- }
- count, err := ai_summary.GetSummaryCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "查询失败"
- br.ErrMsg = "判断分类下是否有纪要失败,Err:" + err.Error()
- return
- }
- //count, err := ai_summary.GetAiSummaryInfoCountByClassifyId(req.AiSummaryClassifyId)
- //if err != nil && !utils.IsErrNoRow(err) {
- // br.Msg = "删除失败"
- // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
- // return
- //}
- if count > 0 {
- br.Msg = "该目录下存在纪要,不可删除"
- br.IsSendEmail = false
- return
- }
- childIds = append(childIds, req.AiSummaryClassifyId)
- err = ai_summary.DeleteAiSummaryClassifyByIds(childIds)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- }
- //删除纪要
- if req.AiSummaryId > 0 {
- summaryInfo, err := ai_summary.GetAiSummaryById(req.AiSummaryId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "纪要已删除,请刷新页面"
- br.ErrMsg = "指标不存在,Err:" + err.Error()
- return
- } else {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
- return
- }
- }
- if summaryInfo == nil {
- br.Msg = "纪要已删除,请刷新页面"
- return
- }
- if summaryInfo.SysUserId != sysUser.AdminId {
- br.Msg = "仅纪要创建人可以删除"
- return
- }
- err = ai_summary.DelAiSummaryById(req.AiSummaryId)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- }
- br.Ret = 200
- br.Msg = "删除成功"
- br.Success = true
- br.IsAddLog = true
- }
- // AiSummaryClassifyMove
- // @Title 纪要分类移动接口
- // @Description 纪要分类移动接口
- // @Success 200 {object} data_manage.MoveChartClassifyReq
- // @router /summary/classify/move [post]
- func (this *AiController) AiSummaryClassifyMove() {
- 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
- }
- var req ai_summary.MoveAiSummaryClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.AiSummaryClassifyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "分类id小于等于0"
- return
- }
- //判断分类是否存在
- aiSummaryClassifyInfo, err := ai_summary.GetAiSummaryClassifyById(req.AiSummaryClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- updateCol := make([]string, 0)
- // 判断移动的是分类还是沙盘
- if req.AiSummaryId > 0 {
- //判断分类是否存在
- count, _ := ai_summary.GetAiSummaryClassifyCountById(req.AiSummaryClassifyId)
- if count <= 0 {
- br.Msg = "分类已被删除,不可移动,请刷新页面"
- return
- }
- aiSummaryInfo, err := ai_summary.GetAiSummaryById(req.AiSummaryId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
- return
- }
- //如果改变了分类,那么移动该图表数据
- // 11/22 ETA逻辑优化去除名称重复限制
- if aiSummaryInfo.ClassifyId != req.ParentClassifyId {
- ////查询需要修改的分类下是否存在同一个图表名称
- //tmpSandboxInfo, tmpErr := sandbox.GetSandboxByClassifyIdAndName(req.ParentClassifyId, aiSummaryInfo.Name)
- //if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
- // br.Msg = "移动失败"
- // br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
- // return
- //}
- //if tmpSandboxInfo != nil {
- // br.Msg = "移动失败,同一个分类下沙盘名称不允许重复"
- // br.ErrMsg = "移动失败,同一个分类下沙盘名称不允许重复"
- // return
- //}
- err = ai_summary.MoveAiSummary(req.AiSummaryId, req.ParentClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- }
- //移动排序
- updateCol := make([]string, 0)
- //如果有传入 上一个兄弟节点分类id
- if req.PrevId > 0 {
- if req.PrevType == 1 {
- //上一个兄弟节点
- prevClassify, err := ai_summary.GetAiSummaryClassifyById(req.PrevId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextId > 0 {
- if req.NextType == 1 {
- //上一个节点是分类 下一个节点是分类的情况
- //下一个兄弟节点
- nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
- if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == aiSummaryClassifyInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
- } else {
- //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
- if nextClassify.Sort-prevClassify.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
- }
- }
- } else {
- //上一个节点是分类 下一个节点是沙盘的情况
- //下一个兄弟节点
- nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
- if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == aiSummaryInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
- } else {
- //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
- if nextChartInfo.Sort-prevClassify.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.AiSummaryClassifyId, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
- }
- }
- }
- }
- aiSummaryInfo.Sort = prevClassify.Sort + 1
- aiSummaryInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- prevAiSumary, err := ai_summary.GetAiSummaryById(req.PrevId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextId > 0 {
- if req.NextType == 1 {
- //上一个节点是沙盘 下一个节点是分类的情况
- //下一个兄弟节点
- nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
- if prevAiSumary.Sort == nextClassify.Sort || prevAiSumary.Sort == aiSummaryClassifyInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
- } else {
- //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
- if nextClassify.Sort-prevAiSumary.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
- }
- }
- } else {
- //上一个节点是沙盘 下一个节点是沙盘的情况
- //下一个兄弟节点
- nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
- if prevAiSumary.Sort == nextChartInfo.Sort || prevAiSumary.Sort == aiSummaryInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
- } else {
- //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
- if nextChartInfo.Sort-prevAiSumary.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
- }
- }
- }
- }
- aiSummaryInfo.Sort = prevAiSumary.Sort + 1
- aiSummaryInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- } else {
- // prevId为0,也就是沙盘移到最前端
- firstClassify, err := ai_summary.GetFirstAiSummaryByClassifyId(req.AiSummaryClassifyId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "移动失败"
- br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
- return
- }
- //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
- if firstClassify != nil && firstClassify.ClassifyId > 0 && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = ai_summary.UpdateAiSummarySortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.AiSummaryId-1, updateSortStr)
- }
- aiSummaryInfo.Sort = 0 //那就是排在第一位
- aiSummaryInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- //更新
- if len(updateCol) > 0 {
- err = aiSummaryInfo.Update(updateCol)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- } else {
- //移动的是分类
- //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
- if aiSummaryClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
- parentChartClassifyInfo, err := ai_summary.GetAiSummaryClassifyById(req.ParentClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
- return
- }
- aiSummaryClassifyInfo.ParentId = parentChartClassifyInfo.AiSummaryClassifyId
- aiSummaryClassifyInfo.Level = parentChartClassifyInfo.Level + 1
- aiSummaryClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
- } else if aiSummaryClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
- //改为一级分类
- aiSummaryClassifyInfo.ParentId = req.ParentClassifyId
- aiSummaryClassifyInfo.Level = 1
- aiSummaryClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
- }
- //如果有传入 上一个兄弟节点分类id
- if req.PrevId > 0 {
- if req.PrevType == 1 {
- //上一个节点是分类
- //上一个兄弟节点
- prevClassify, err := ai_summary.GetAiSummaryClassifyById(req.PrevId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextId > 0 {
- if req.NextType == 1 {
- //上一个节点是分类 下一个节点是分类的情况
- //下一个兄弟节点
- nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
- if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == aiSummaryClassifyInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
- } else {
- //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
- if nextClassify.Sort-prevClassify.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
- }
- }
- } else {
- //上一个节点是分类 下一个节点是沙盘的情况
- //下一个兄弟节点
- nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟(分类)与下一个兄弟(沙盘)的排序权重是一致的,那么需要将下一个兄弟(沙盘)(以及下个兄弟(沙盘)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
- if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == aiSummaryClassifyInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, prevClassify.AiSummaryClassifyId, prevClassify.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
- } else {
- //如果下一个兄弟(沙盘)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
- if nextChartInfo.Sort-prevClassify.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.AiSummaryClassifyId, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevClassify.AiSummaryClassifyId, prevClassify.Sort, 0, updateSortStr)
- }
- }
- }
- }
- aiSummaryClassifyInfo.Sort = prevClassify.Sort + 1
- aiSummaryClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- //上一个节点是沙盘
- prevAiSumary, err := ai_summary.GetAiSummaryById(req.PrevId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextId > 0 {
- if req.NextType == 1 {
- //上一个节点是沙盘 下一个节点是分类的情况
- //下一个兄弟节点
- nextClassify, err := ai_summary.GetAiSummaryClassifyById(req.NextId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
- if prevAiSumary.Sort == nextClassify.Sort || prevAiSumary.Sort == aiSummaryClassifyInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
- } else {
- //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
- if nextClassify.Sort-prevAiSumary.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
- }
- }
- } else {
- //上一个节点是沙盘 下一个节点是沙盘的情况
- //下一个兄弟节点
- nextChartInfo, err := ai_summary.GetAiSummaryById(req.NextId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟(沙盘)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(沙盘)的排序权重+1
- if prevAiSumary.Sort == nextChartInfo.Sort || prevAiSumary.Sort == aiSummaryClassifyInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
- } else {
- //如果下一个兄弟(分类)的排序权重正好是上个兄弟(沙盘)节点的下一层,那么需要再加一层了
- if nextChartInfo.Sort-prevAiSumary.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(prevAiSumary.ClassifyId, 0, prevAiSumary.Sort, updateSortStr)
- _ = ai_summary.UpdateAiSummarySortByClassifyId(prevAiSumary.ClassifyId, prevAiSumary.Sort, prevAiSumary.AiSummaryId, updateSortStr)
- }
- }
- }
- }
- aiSummaryClassifyInfo.Sort = prevAiSumary.Sort + 1
- aiSummaryClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- } else {
- firstClassify, err := ai_summary.GetFirstAiSummaryClassifyByParentId(aiSummaryClassifyInfo.ParentId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "移动失败"
- br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
- return
- }
- //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
- if firstClassify != nil && firstClassify.AiSummaryClassifyId > 0 && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = ai_summary.UpdateAiSummaryClassifySortByParentId(firstClassify.ParentId, firstClassify.AiSummaryClassifyId-1, 0, updateSortStr)
- }
- aiSummaryClassifyInfo.Sort = 0 //那就是排在第一位
- aiSummaryClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- //更新
- if len(updateCol) > 0 {
- err = aiSummaryClassifyInfo.Update(updateCol)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- }
- // @Title Ai纪要列表接口
- // @Description Ai纪要列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param AiSummaryClassifyId query int true "分类id"
- // @Param KeyWord query string true "搜索关键词"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /summary/list [get]
- func (this *AiController) AiSummaryList() {
- 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
- }
- aiSummaryClassifyId, _ := this.GetInt("AiSummaryClassifyId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- classifyAll, err := ai_summary.GetAiSummaryClassifyAll()
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAllMap := make(map[int]*ai_summary.AiSummaryClassifyItems)
- for _, v := range classifyAll {
- classifyAllMap[v.AiSummaryClassifyId] = v
- }
- var condition string
- var pars []interface{}
- if aiSummaryClassifyId > 0 {
- sandboxClassifyIds, err := ai_summary.GetAiSummaryClassify(aiSummaryClassifyId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
- return
- }
- condition += " AND ai_summary_classify_id IN(" + sandboxClassifyIds + ") "
- //pars = append(pars, chartClassifyId)
- }
- if keyWord != "" {
- condition += ` AND ( title LIKE '%` + keyWord + `%' )`
- }
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- if isShowMe {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- //获取图表信息
- list, err := ai_summary.GetAiSummaryListByCondition(condition, pars, startSize, pageSize)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取纪要信息失败"
- br.ErrMsg = "获取纪要信息失败,Err:" + err.Error()
- return
- }
- for i, v := range list {
- parentIds := make([]int, 0)
- aiSummaryService.GetSummaryParentIds(v.ClassifyId, classifyAllMap, &parentIds)
- ids := utils.IntArr2joinString(parentIds, ",")
- //ids, err := ai_summary.GetAiSummaryAllParentByClassifyId(v.ClassifyId)
- //if err != nil {
- // br.Msg = "获取父级信息错误!"
- // br.ErrMsg = "获取父级信息错误,Err:" + err.Error()
- // return
- //}
- list[i].ParentIds = ids
- }
- resp := new(ai_summary.AiSummaryListResp)
- if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
- items := make([]*ai_summary.AiSummaryItems, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- dataCount, err := ai_summary.GetAiSummaryListCountByCondition(condition, pars)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title Ai纪要详情接口
- // @Description Ai纪要详情接口
- // @Param AiSummaryId query int true "详情id"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /summary/detail [get]
- func (this *AiController) AiSummaryDetail() {
- 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
- }
- aiSummaryId, _ := this.GetInt("AiSummaryId")
- detail, err := ai_summary.GetAiSummaryItemById(aiSummaryId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取沙盘信息失败"
- br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
- return
- }
- resp := ai_summary.AiSummaryDetailResp{
- AiSummaryItems: detail,
- }
- if detail.SaDocId > 0 {
- item := new(saModel.SaDoc)
- e := item.GetItemById(detail.SaDocId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- br.Msg = "文档已被删除, 请刷新页面"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取文档信息失败, Err: " + e.Error()
- return
- }
- resp.SaDocTitle = item.Title
- resp.SaDocClassifyId = item.ClassifyId
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 新增ai纪要
- // @Description 新增ai纪要接口
- // @Param request body data_manage.AddChartClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /summary/add [post]
- func (this *AiController) AddAiSummary() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ai_summary.AddAiSummaryReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Title == "" {
- br.Msg = "请输入名称"
- br.IsSendEmail = false
- return
- }
- if req.SummaryContent == "" {
- br.Msg = "纪要内容为空"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyId < 0 {
- br.Msg = "分类id错误"
- br.IsSendEmail = false
- return
- }
- //获取该层级下最大的排序数
- maxSort, err := ai_summary.GetAiSummaryMaxSort(req.ClassifyId)
- summary := &ai_summary.AiSummary{
- SaDocId: req.SaDocId,
- OriginContent: req.OriginContent,
- SummaryContent: req.SummaryContent,
- ClassifyId: req.ClassifyId,
- SysUserId: this.SysUser.AdminId,
- SysUserRealName: this.SysUser.RealName,
- Title: req.Title,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- OpenaiFileName: req.OpenaiFileName,
- OpenaiFilePath: req.OpenaiFilePath,
- OriginTitle: req.OriginTitle,
- Sort: maxSort + 1,
- }
- id, err := ai_summary.AddAiSummary(summary)
- if err != nil {
- br.Msg = "保存分类失败"
- br.ErrMsg = "保存分类失败,Err:" + err.Error()
- return
- }
- classify, err := ai_summary.GetAiSummaryClassifyById(req.ClassifyId)
- if err != nil {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- resp := ai_summary.AiSummaryAddResp{
- AiSummaryId: int(id),
- UniqueCode: strconv.Itoa(req.ClassifyId) + "_" + strconv.Itoa(int(id)),
- ParentId: classify.ParentId,
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.Data = resp
- }
- // @Title 生成ai纪要
- // @Description 生成ai纪要接口
- // @Param request body data_manage.AddChartClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /summary/generate [post]
- func (this *AiController) GenerateAiSummary() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req ai_summary.GenerateAiSummaryReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.Prompt, err = aiser.FormatAskContent(req.Prompt)
- if err != nil {
- br.Msg = "提示词错误"
- br.ErrMsg = "提示词错误,FormatAskContent,Err:" + err.Error()
- return
- }
- if req.Prompt == "" {
- br.Msg = "请输入提示词"
- br.IsSendEmail = false
- return
- }
- req.OriginContent, err = aiser.FormatAskContent(req.OriginContent)
- if err != nil {
- br.Msg = "文档内容错误"
- br.ErrMsg = "文档内容错误,FormatAskContent,Err:" + err.Error()
- return
- }
- if req.OriginContent == "" && len(req.OpenaiFileId) == 0 && req.SaDocId <= 0 {
- br.Msg = "请选择文档或输入内容"
- br.IsSendEmail = false
- return
- }
- if req.SaDocId > 0 {
- // 获取段落
- sectionOB := new(saModel.SaDocSection)
- sectionCond := fmt.Sprintf(` AND %s = ?`, saModel.SaDocSectionColumns.DocId)
- sectionPars := make([]interface{}, 0)
- sectionPars = append(sectionPars, req.SaDocId)
- sectionList, e := sectionOB.GetItemsByCondition(sectionCond, sectionPars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取段落信息失败, Err: " + e.Error()
- return
- }
- secIds := make([]int, 0)
- for _, s := range sectionList {
- secIds = append(secIds, s.SaDocSectionId)
- }
- for _, v := range sectionList {
- req.OriginContent += v.Content + "<br>"
- }
- }
- if utils.Re == nil {
- key := "CACHE_CHAT_" + strconv.Itoa(this.SysUser.AdminId)
- cacheVal, err := utils.Rc.RedisInt(key)
- fmt.Println("RedisString:", cacheVal, "err:", err)
- if err != nil && (err.Error() != "redigo: nil returned" && err.Error() != "redis: nil") {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- putVal := 0
- if cacheVal <= 0 {
- putVal = utils.AiChatLimit
- } else {
- putVal = cacheVal - 1
- }
- if putVal <= 0 {
- br.Msg = "您今日" + strconv.Itoa(utils.AiChatLimit) + "次问答已达上限,请明天再来!"
- br.ErrMsg = "您今日" + strconv.Itoa(utils.AiChatLimit) + "次问答已达上限,请明天再来!"
- return
- }
- lastSecond := utils.GetTodayLastSecond()
- utils.Rc.Put(key, putVal, lastSecond)
- }
- resp := new(aimod.ChatResp)
- if req.OriginContent != "" {
- // 直接提问的方式
- //根据提问,获取信息
- ask := req.Prompt + req.OriginContent
- var answer string
- //answerArr := []string{
- // "周度数据显示,成品油现货市场价格跟随原油下跌,但近期相对抗跌,裂解价差走扩。批零价差方面汽油收窄,柴油走扩",
- // "出口利润在原油下跌海外成品油矛盾更大的情况下汽柴油出口窗口完全关闭",
- // "汽油需求在经历五一假期的一段高峰后将回归平稳,总体没有明显矛盾,后期我们担心更多的还是柴油。"}
- //获取主题下的所有信息
- //AiChatTopicId
- //获取主题下的所有信息
- //AiChatTopicId
- historyList, err := aimod.GetAiChatList(req.AiChatTopicId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取主题历史数据失败!"
- br.ErrMsg = "获取主题历史数据失败,Err:" + err.Error()
- return
- }
- historyChatList := make([]aimod.HistoryChat, 0)
- for _, v := range historyList {
- historyChat := new(aimod.HistoryChat)
- historyChat.Ask = v.Ask
- historyChat.Answer = v.Answer
- historyChatList = append(historyChatList, *historyChat)
- }
- answer, err = aiser.ChatAutoMsg(ask, historyChatList, req.Model)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,ChatAutoMsg,Err:" + err.Error()
- return
- }
- resp.Ask = ask
- resp.Answer = answer
- resp.Model = req.Model
- if req.AiChatTopicId <= 0 { //新增
- name, err := aiser.QueryAskContent(ask)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,QueryAskContent,Err:" + err.Error()
- return
- }
- topic := new(aimod.AiChatTopic)
- topic.TopicName = name
- topic.SysUserId = this.SysUser.AdminId
- topic.SysUserRealName = this.SysUser.RealName
- topic.CreateTime = time.Now()
- topic.ModifyTime = time.Now()
- topicId, err := aimod.AddAiChatTopic(topic)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "生成话题失败,Err:" + err.Error()
- return
- }
- resp.AiChatTopicId = int(topicId)
- chatItem := new(aimod.AiChat)
- chatItem.AiChatTopicId = resp.AiChatTopicId
- chatItem.Ask = ask
- chatItem.AskUuid = utils.MD5(ask)
- chatItem.Answer = answer
- chatItem.Model = EnabledModelsForMap[req.Model]
- chatItem.SysUserId = this.SysUser.AdminId
- chatItem.SysUserRealName = this.SysUser.RealName
- chatItem.CreateTime = time.Now()
- chatItem.ModifyTime = time.Now()
- _, err = aimod.AddAiChat(chatItem)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
- return
- }
- } else {
- resp.AiChatTopicId = req.AiChatTopicId
- chatItem := new(aimod.AiChat)
- chatItem.AiChatTopicId = resp.AiChatTopicId
- chatItem.Ask = ask
- chatItem.AskUuid = utils.MD5(ask)
- chatItem.Answer = answer
- chatItem.Model = EnabledModelsForMap[req.Model]
- chatItem.SysUserId = this.SysUser.AdminId
- chatItem.SysUserRealName = this.SysUser.RealName
- chatItem.CreateTime = time.Now()
- chatItem.ModifyTime = time.Now()
- _, err = aimod.AddAiChat(chatItem)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
- return
- }
- }
- } else if len(req.OpenaiFileId) > 0 {
- // 走文件上传的方式
- //根据提问,获取信息
- ask := req.Prompt
- askUuid := utils.MD5(ask)
- var assistantId, threadId string
- if req.AiChatTopicId > 0 {
- aiChatTopicObj := new(aimod.AiChatTopic)
- aiChatTopicObj.AiChatTopicId = req.AiChatTopicId
- topic, err := aiChatTopicObj.GetAiChatTopicById()
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,主题不存在,Err:" + err.Error()
- return
- }
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,GetAiChatTopicById,Err:" + err.Error()
- return
- }
- assistantId = topic.AssistantId
- threadId = topic.ThreadId
- }
- var answer string
- //获取主题下的所有信息
- //AiChatTopicId
- //historyList, err := aimod.GetAiChatList(req.AiChatTopicId)
- //if err != nil && !utils.IsErrNoRow(err) {
- // br.Msg = "获取主题历史数据失败!"
- // br.ErrMsg = "获取主题历史数据失败,Err:" + err.Error()
- // return
- //}
- frList := make([]aimod.HistoryChat, 0)
- tmpFileIdList := make([]string, 0)
- tmpFileIdList = append(tmpFileIdList, req.OpenaiFileId...)
- //// 历史消息
- //for _, v := range historyList {
- // if v.OpenaiFileId != "" {
- // tmpFileIdList = append(tmpFileIdList, v.OpenaiFileId)
- // } else {
- // historyFr := new(aimod.HistoryChat)
- // historyFr.Ask = v.Ask
- // historyFr.Answer = v.Answer
- // historyFr.OpenaiFileId = tmpFileIdList
- // frList = append(frList, *historyFr)
- // tmpFileIdList = []string{}
- // }
- //}
- // 当前的消息
- {
- frItem := new(aimod.HistoryChat)
- frItem.Ask = ask
- frItem.Answer = ""
- frItem.OpenaiFileId = tmpFileIdList
- frList = append(frList, *frItem)
- }
- fileRetrieveResp, err := aiser.FileRetrieve(assistantId, threadId, req.Model, frList, req.OpenaiFileId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,FileRetrieve,Err:" + err.Error()
- return
- }
- if fileRetrieveResp != nil {
- if fileRetrieveResp.Ret == 200 {
- assistantId = fileRetrieveResp.Data.AssistantId
- threadId = fileRetrieveResp.Data.ThreadId
- answer = fileRetrieveResp.Data.Answer
- } else {
- br.Msg = "获取数据失败!"
- br.ErrMsg = fileRetrieveResp.Msg
- return
- }
- }
- if req.AiChatTopicId <= 0 { //新增
- name, err := aiser.QueryAskContent(ask)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,QueryAskContent,Err:" + err.Error()
- return
- }
- topic := new(aimod.AiChatTopic)
- topic.TopicName = name
- topic.SysUserId = this.SysUser.AdminId
- topic.SysUserRealName = this.SysUser.RealName
- topic.CreateTime = time.Now()
- topic.ModifyTime = time.Now()
- topic.AssistantId = assistantId
- topic.ThreadId = threadId
- topicId, err := aimod.AddAiChatTopic(topic)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "生成话题失败,Err:" + err.Error()
- return
- }
- chatItem := new(aimod.AiChat)
- chatItem.AiChatTopicId = int(topicId)
- chatItem.Ask = ask
- chatItem.AskUuid = utils.MD5(ask)
- chatItem.Answer = answer
- chatItem.Model = EnabledModelsForMap[req.Model]
- chatItem.SysUserId = this.SysUser.AdminId
- chatItem.SysUserRealName = this.SysUser.RealName
- chatItem.CreateTime = time.Now()
- chatItem.ModifyTime = time.Now()
- _, err = aimod.AddAiChat(chatItem)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
- return
- }
- req.AiChatTopicId = int(topicId)
- } else {
- chatItem := new(aimod.AiChat)
- chatItem.AiChatTopicId = req.AiChatTopicId
- chatItem.Ask = ask
- chatItem.AskUuid = askUuid
- chatItem.Answer = answer
- chatItem.Model = EnabledModelsForMap[req.Model]
- chatItem.SysUserId = this.SysUser.AdminId
- chatItem.SysUserRealName = this.SysUser.RealName
- chatItem.CreateTime = time.Now()
- chatItem.ModifyTime = time.Now()
- _, err = aimod.AddAiChat(chatItem)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
- return
- }
- //更新 assistantId,threadId
- aiChatTopicObj := new(aimod.AiChatTopic)
- //updateParams := make(map[string]interface{})
- //updateParams["assistant_id"] = assistantId
- //updateParams["thread_id"] = threadId
- //updateParams["modify_time"] = time.Now()
- //
- //whereParam := make(map[string]interface{})
- //whereParam["ai_chat_topic_id"] = req.AiChatTopicId
- err = aiChatTopicObj.UpdateAssistantAndThreadId(assistantId, threadId, req.AiChatTopicId)
- if err != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "修改助手标识失败,Err:" + err.Error()
- return
- }
- }
- resp.Model = aimod.ModelViewMap[req.Model]
- resp.AiChatTopicId = req.AiChatTopicId
- resp.Ask = ask
- resp.Answer = answer
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- //// @Title 文件上传
- //// @Description 文件上传接口
- //// @Param File query file true "文件"
- //// @Param AiChatTopicId query int true "主题id"
- //// @Success 200 {object} models.ResourceResp
- //// @router /file/upload [post]
- //func (this *AiFileController) FileUpload2() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- //
- // f, h, err := this.GetFile("File")
- // if err != nil {
- // br.Msg = "获取资源信息失败"
- // br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
- // return
- // }
- // model := this.GetString("Model")
- //
- // aiChatTopicId, _ := this.GetInt("AiChatTopicId")
- //
- // uploadFileName := h.Filename //上传的文件名
- // ext := path.Ext(h.Filename)
- // dateDir := time.Now().Format("20060102")
- // uploadDir := utils.STATIC_DIR + "ai/" + dateDir
- // err = os.MkdirAll(uploadDir, utils.DIR_MOD)
- // if err != nil {
- // br.Msg = "存储目录创建失败"
- // br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
- // return
- // }
- // randStr := utils.GetRandStringNoSpecialChar(28)
- // fileName := randStr + ext
- // fpath := uploadDir + "/" + fileName
- // defer f.Close() //关闭上传文件
- // err = this.SaveToFile("File", fpath)
- // if err != nil {
- // br.Msg = "文件上传失败"
- // br.ErrMsg = "文件上传失败,Err:" + err.Error()
- // return
- // }
- // resourceUrl := ``
- // ossClient := services.NewOssClient()
- // if ossClient == nil {
- // br.Msg = "上传失败"
- // br.ErrMsg = "初始化OSS服务失败"
- // return
- // }
- // resourceUrl, err = ossClient.UploadFile(fileName, fpath, "")
- // if err != nil {
- // br.Msg = "文件上传失败"
- // br.ErrMsg = "文件上传失败,Err:" + err.Error()
- // return
- // }
- //
- // defer func() {
- // os.Remove(fpath)
- // }()
- //
- // item := new(models.Resource)
- // item.ResourceUrl = resourceUrl
- // item.ResourceType = 1
- // item.CreateTime = time.Now()
- // newId, err := models.AddResource(item)
- // if err != nil {
- // br.Msg = "资源上传失败"
- // br.ErrMsg = "资源上传失败,Err:" + err.Error()
- // return
- // }
- // //调用AI接口,上传文件
- // resp := models.ResourceResp{
- // Id: newId,
- // ResourceUrl: resourceUrl,
- // ResourceName: uploadFileName,
- // }
- // uploadResult, err := aiser.OpenAiFileUpload(resourceUrl, uploadFileName, model)
- // if err != nil {
- // br.Msg = "文件上传失败"
- // br.ErrMsg = "文件上传失败,Err:" + err.Error()
- // return
- // }
- //
- // var assistantId, threadId string
- // if aiChatTopicId > 0 {
- // aiChatTopicObj := new(aimod.AiChatTopic)
- // aiChatTopicObj.AiChatTopicId = aiChatTopicId
- // topic, err := aiChatTopicObj.GetAiChatTopicById()
- // if err != nil {
- // if utils.IsErrNoRow(err) {
- // br.Msg = "获取数据失败!"
- // br.ErrMsg = "获取数据失败,主题不存在,Err:" + err.Error()
- // return
- // }
- // br.Msg = "获取数据失败!"
- // br.ErrMsg = "获取数据失败,GetAiChatTopicById,Err:" + err.Error()
- // return
- // }
- // assistantId = topic.AssistantId
- // threadId = topic.ThreadId
- // }
- //
- // if aiChatTopicId <= 0 { //新增
- // topic := new(aimod.AiChatTopic)
- // var filenameWithSuffix string
- // filenameWithSuffix = path.Base(uploadFileName)
- // var fileSuffix string
- // fileSuffix = path.Ext(filenameWithSuffix)
- // var filenameOnly string
- // filenameOnly = strings.TrimSuffix(filenameWithSuffix, fileSuffix)
- // topic.TopicName = filenameOnly
- // topic.SysUserId = this.SysUser.AdminId
- // topic.SysUserRealName = this.SysUser.RealName
- // topic.CreateTime = time.Now()
- // topic.ModifyTime = time.Now()
- // topic.AssistantId = assistantId
- // topic.ThreadId = threadId
- // topicId, err := aimod.AddAiChatTopic(topic)
- // if err != nil {
- // br.Msg = "获取数据失败!"
- // br.ErrMsg = "生成话题失败,Err:" + err.Error()
- // return
- // }
- // aiChatTopicId = int(topicId)
- // chatItem := new(aimod.AiChat)
- // chatItem.AiChatTopicId = aiChatTopicId
- // chatItem.Ask = uploadFileName
- // chatItem.AskUuid = utils.MD5(uploadFileName)
- // chatItem.Model = EnabledModelsForMap[model]
- // chatItem.SysUserId = this.SysUser.AdminId
- // chatItem.SysUserRealName = this.SysUser.RealName
- // if uploadResult != nil && uploadResult.Data != nil {
- // chatItem.OpenaiFileId = uploadResult.Data.ID
- // chatItem.OpenaiFileName = uploadFileName
- // }
- // chatItem.OpenaiFilePath = resourceUrl
- // chatItem.CreateTime = time.Now()
- // chatItem.ModifyTime = time.Now()
- // _, err = aimod.AddAiChat(chatItem)
- // if err != nil {
- // br.Msg = "获取数据失败!"
- // br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
- // return
- // }
- // } else {
- // chatItem := new(aimod.AiChat)
- // chatItem.AiChatTopicId = aiChatTopicId
- // chatItem.Ask = uploadFileName
- // chatItem.AskUuid = utils.MD5(fileName)
- // chatItem.Model = EnabledModelsForMap[model]
- // chatItem.SysUserId = this.SysUser.AdminId
- // chatItem.SysUserRealName = this.SysUser.RealName
- // if uploadResult != nil && uploadResult.Data != nil {
- // chatItem.OpenaiFileId = uploadResult.Data.ID
- // chatItem.OpenaiFileName = uploadFileName
- // }
- // chatItem.OpenaiFilePath = resourceUrl
- // chatItem.CreateTime = time.Now()
- // chatItem.ModifyTime = time.Now()
- // _, err = aimod.AddAiChat(chatItem)
- // if err != nil {
- // br.Msg = "获取数据失败!"
- // br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
- // return
- // }
- // }
- //
- // if uploadResult != nil && uploadResult.Data != nil && uploadResult.Data.ID != "" {
- // uploadObj := new(aimod.FileUploadRecord)
- // uploadObj.AdminId = this.SysUser.AdminId
- // uploadObj.FileUrl = resourceUrl
- // uploadObj.FileName = uploadFileName
- // uploadObj.OpenaiFileId = uploadResult.Data.ID
- // uploadObj.OpenaiFileName = uploadResult.Data.FileName
- // uploadObj.OpenaiObject = uploadResult.Data.Object
- // uploadObj.OpenaiStatus = uploadResult.Data.Status
- // uploadObj.OpenaiPurpose = uploadResult.Data.Purpose
- // uploadObj.OpenaiStatusDetails = uploadResult.Data.StatusDetails
- // uploadObj.OpenaiCreatedAt = uploadResult.Data.CreatedAt
- // uploadObj.CreateTime = time.Now()
- // uploadObj.ModifyTime = time.Now()
- // _, err = uploadObj.AddFileUploadRecord()
- // if err != nil {
- // br.Msg = "上传失败"
- // br.ErrMsg = "上传失败,Err:" + err.Error()
- // return
- // }
- // resp.OpenaiFileId = uploadObj.OpenaiFileId
- // }
- // resp.AiChatTopicId = aiChatTopicId
- // br.Msg = "上传成功"
- // br.Ret = 200
- // br.Success = true
- // br.Data = resp
- // return
- //}
- // AiSummaryClassifyList
- // @Title 获取所有纪要分类接口-不包含沙盘
- // @Description 获取所有纪要分类接口-不包含沙盘
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartClassifyListResp
- // @router /summary/classifyList [get]
- func (this *AiController) AiSummaryClassifyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- resp := new(ai_summary.AiSummaryClassifyListResp)
- rootList, err := ai_summary.GetAiSummaryClassifyByParentId(0)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := ai_summary.GetAiSummaryClassifyAll()
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- nodeAll := make([]*ai_summary.AiSummaryClassifyItems, 0)
- for k := range rootList {
- rootNode := rootList[k]
- aiSummaryService.AiSummaryClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
- nodeAll = append(nodeAll, rootNode)
- }
- resp.AllNodes = nodeAll
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|