123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/system"
- "eta/eta_api/services/data"
- etaTrialService "eta/eta_api/services/eta_trial"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- )
- // CCFClassify
- // @Title CCF化纤分类
- // @Description CCF化纤分类接口
- // @Success 200 {object} data_manage.BaseFromCCFClassifyItem
- // @router /ccf/classify [get]
- func (this *EdbInfoController) CCFClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- classifies, e := data_manage.GetBaseFromCCFClassify()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取CCF化纤分类失败, Err: " + e.Error()
- return
- }
- classifyOb := new(data_manage.BaseFromCCFClassify)
- resp := make([]*data_manage.BaseFromCCFClassifyItem, 0)
- parentMap := make(map[int][]*data_manage.BaseFromCCFClassifyItem)
- for _, v := range classifies {
- t := classifyOb.Format2Item(v)
- if v.ParentId == 0 {
- resp = append(resp, t)
- }
- if v.ParentId > 0 {
- if parentMap[v.ParentId] == nil {
- parentMap[v.ParentId] = make([]*data_manage.BaseFromCCFClassifyItem, 0)
- }
- parentMap[v.ParentId] = append(parentMap[v.ParentId], t)
- }
- }
- for _, v := range resp {
- v.Child = parentMap[v.ClassifyId]
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // CCFIndexData
- // @Title 获取CCF化纤数据
- // @Description 获取CCF化纤接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query string true "分类id"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /ccf/index/data [get]
- func (this *EdbInfoController) CCFIndexData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- 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 = utils.StartIndex(currentIndex, pageSize)
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- return
- }
- // 增加频度请求入参
- frequency := this.GetString("Frequency")
- // 获取指标
- var condition string
- var pars []interface{}
- if classifyId >= 0 {
- condition += ` AND classify_id=? `
- pars = append(pars, classifyId)
- }
- if frequency != "" {
- condition += ` AND frequency=? `
- pars = append(pars, frequency)
- }
- indexes, err := data_manage.GetCCFIndex(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- indexCodes := make([]string, 0)
- for _, v := range indexes {
- indexCodes = append(indexCodes, v.IndexCode)
- }
- /*indexCounts, e := data_manage.GetCCFIndexDataCountGroup(indexCodes)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标数据总量失败, Err:" + err.Error()
- return
- }
- countMap := make(map[string]int)
- for _, v := range indexCounts {
- countMap[v.IndexCode] = v.Count
- }*/
- edbInfoMap := make(map[string]*data_manage.EdbInfo)
- dataMap := make(map[string][]*data_manage.BaseFromCCFData)
- total := 0
- if len(indexCodes) > 0 {
- edbInfoList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_CCF, indexCodes)
- if err != nil {
- br.Msg = "获取数据源失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- for _, v := range edbInfoList {
- edbInfoMap[v.EdbCode] = v
- }
- // 首先对分类下的指标按照日期进行分页,再针对日期,进行排序
- dataTimes, err := data_manage.GetCCFIndexDataTimePageByCodes(indexCodes, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据日期信息失败,Err:" + err.Error()
- return
- }
- if len(dataTimes) > 0 {
- startDate := dataTimes[len(dataTimes)-1]
- endDate := dataTimes[0]
- // 把截止日往后加1天
- endDateT, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
- endDate = endDateT.AddDate(0, 0, 1).Format(utils.FormatDate)
- dataList, e := data_manage.GetCCFIndexDataByDataTime(indexCodes, startDate, endDate)
- if e != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + e.Error()
- return
- }
- //将数据按照指标进行分类
- for _, v := range dataList {
- dataMap[v.IndexCode] = append(dataMap[v.IndexCode], v)
- }
- }
- total, err = data_manage.GetCCFIndexDataTimePageCount(indexCodes)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resultList := make([]*data_manage.BaseFromCCFIndexList, 0)
- for _, v := range indexes {
- product := new(data_manage.BaseFromCCFIndexList)
- product.BaseFromCcfIndexId = v.BaseFromCcfIndexId
- product.ClassifyId = v.ClassifyId
- product.Unit = v.Unit
- product.IndexCode = v.IndexCode
- product.IndexName = v.IndexName
- product.Frequency = v.Frequency
- product.CreateTime = v.CreateTime
- product.ModifyTime = v.ModifyTime
- if edb, ok := edbInfoMap[v.IndexCode]; ok {
- product.EdbInfoId = edb.EdbInfoId
- product.EdbExist = 1
- }
- /*total := countMap[v.IndexCode]
- page := paging.GetPaging(currentIndex, pageSize, total)
- dataList, e := data_manage.GetCCFIndexData(v.IndexCode, startSize, pageSize)
- if e != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + e.Error()
- return
- }*/
- dataListTmp, ok := dataMap[v.IndexCode]
- if !ok {
- dataListTmp = make([]*data_manage.BaseFromCCFData, 0)
- }
- product.DataList = dataListTmp
- product.Paging = page
- resultList = append(resultList, product)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resultList
- }
- // CCFSearchList
- // @Title CCF模糊搜索
- // @Description CCF模糊搜索
- // @Param Keyword query string ture "关键字搜索"
- // @Success 200 {object} data_manage.BaseFromCCFIndexSearchItem
- // @router /ccf/search_list [get]
- func (this *EdbInfoController) CCFSearchList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- list := make([]*data_manage.BaseFromCCFIndexSearchItem, 0)
- var err error
- // 关键字
- keyword := this.GetString("Keyword")
- if keyword != "" {
- keyWordArr := strings.Split(keyword, " ")
- if len(keyWordArr) > 0 {
- condition := ""
- for _, v := range keyWordArr {
- condition += ` AND CONCAT(index_name,index_code) LIKE '%` + v + `%'`
- }
- list, err = data_manage.GetCCFItemList(condition)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- }
- } else {
- list, err = data_manage.GetCCFItemList("")
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // CCFSingleData
- // @Title 获取CCF数据
- // @Description 获取CCF单条数据接口
- // @Param IndexCode query string true "指标唯一编码"
- // @Success 200 {object} models.BaseResponse
- // @router /ccf/single_data [get]
- func (this *EdbInfoController) CCFSingleData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- indexCode := this.GetString("IndexCode")
- indexInfo, err := data_manage.GetBaseFromCCFIndexByIndexCode(indexCode)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- dataTmpList, err := data_manage.GetCCFIndexDataByCode(indexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- var ret data_manage.CCFSingleDataResp
- var dataList []*data_manage.CCFSingleData
- ret.ClassifyId = indexInfo.ClassifyId
- ret.BaseFromCcfIndexId = indexInfo.BaseFromCcfIndexId
- ret.IndexCode = indexInfo.IndexCode
- ret.IndexName = indexInfo.IndexName
- ret.Frequency = indexInfo.Frequency
- ret.CreateTime = indexInfo.CreateTime.Format(utils.FormatDateTime)
- ret.ModifyTime = indexInfo.ModifyTime.Format(utils.FormatDateTime)
- ret.Unit = indexInfo.Unit
- for _, v := range dataTmpList {
- tmp := &data_manage.CCFSingleData{
- Value: v.Value,
- DataTime: v.DataTime,
- }
- dataList = append(dataList, tmp)
- }
- ret.Data = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // ExportCCFList
- // @Title 导出CCF数据
- // @Description 导出CCF数据
- // @Param IndexName query string false "名称关键词"
- // @Param IndexCode query string false "指标唯一编码"
- // @Param ClassifyId query string true "分类"
- // @Success 200 导出成功
- // @router /ccf/export [get]
- func (this *EdbInfoController) ExportCCFList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- indexCode := this.GetString("IndexCode") //指标唯一编码
- classifyId, _ := this.GetInt("ClassifyId")
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downFile := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- var pars []interface{}
- condition := ""
- if classifyId > 0 {
- //获取指标
- condition += " AND classify_id=?"
- pars = append(pars, classifyId)
- }
- if indexCode != "" {
- //获取指标
- condition += " AND index_code=?"
- pars = append(pars, indexCode)
- }
- indexList, err := data_manage.GetCCFIndex(condition, pars)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(indexList) <= 0 {
- fmt.Println("indexList 为空")
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- return
- }
- //sheetNew := new(xlsx.Sheet)
- //sheetNew, err = xlsxFile.AddSheet("CCF化纤")
- //sheetNew.SetColWidth()
- //获取指标数据
- /*windRow := sheetNew.AddRow()
- secNameRow := sheetNew.AddRow()
- indexCodeRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()*/
- //获取分类下指标最大数据量
- var dataMax int
- //setRowIndex := 6
- codeList := make([]string, 0)
- frequenciesMap := make(map[string][]*data_manage.BaseFromCCFIndexList)
- for _, v := range indexList {
- codeList = append(codeList, v.IndexCode)
- frequenciesMap[v.Frequency] = append(frequenciesMap[v.Frequency], v)
- }
- dataListMap := make(map[string][]*data_manage.BaseFromCCFData)
- if len(indexList) > 0 {
- allDataList, e := data_manage.GetCCFIndexDataByCodes(codeList)
- if e != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + e.Error()
- return
- }
- for _, v := range allDataList {
- dataListMap[v.IndexCode] = append(dataListMap[v.IndexCode], v)
- }
- for _, v := range dataListMap {
- if len(v) > dataMax {
- dataMax = len(v)
- }
- }
- }
- // 按照频率分组排序
- frequencies := []string{
- "日度", "周度", "旬度", "月度", "季度", "半年度", "年度",
- }
- for _, frequency := range frequencies {
- //获取指标
- indexCodeList, ok := frequenciesMap[frequency]
- if !ok {
- continue
- }
- if len(indexCodeList) <= 0 {
- fmt.Printf("sheet:%s, 不存在指标", frequency)
- return
- }
- var sheetName string
- switch frequency {
- case "日度":
- sheetName = "日度(Daily)"
- case "周度":
- sheetName = "周度(Weekly)"
- case "旬度":
- sheetName = "旬度(ten-day)"
- case "月度":
- sheetName = "月度(Monthly)"
- case "季度":
- sheetName = "季度(Quarterly)"
- case "半年度":
- sheetName = "半年度(Semi-annual)"
- case "年度":
- sheetName = "年度(Annual)"
- default:
- sheetName = "其他数据"
- }
- sheetNew, err := xlsxFile.AddSheet(sheetName)
- if err != nil {
- fmt.Println("新增Sheet失败", err.Error())
- return
- }
- secNameRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- var indexIdList []int
- for _, idx := range frequenciesMap[frequency] {
- indexIdList = append(indexIdList, idx.BaseFromCcfIndexId)
- }
- dataTimeList, err := data_manage.GetCCFDataDataTimeByIndexId(indexIdList)
- if err != nil {
- br.Msg = "下载失败"
- br.ErrMsg = "获取数据时间失败,Err:" + err.Error()
- fmt.Println("获取数据时间失败", err.Error())
- return
- }
- // 添加excel左侧指标日期
- setRowIndex := 4
- for rk, dv := range dataTimeList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- }
- for k, icl := range indexCodeList {
- // 获取数据
- dataList, ok := dataListMap[icl.IndexCode]
- if !ok {
- continue
- }
- if k == 0 {
- secNameRow.AddCell().SetValue("指标名称/Metric Name")
- frequencyRow.AddCell().SetValue("频度/Frequency")
- unitRow.AddCell().SetValue("单位/Unit")
- lastModifyDateRow.AddCell().SetValue("更新时间/Update Time")
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- }
- if len(dataList) == 0 {
- continue
- }
- secNameRow.AddCell().SetValue(icl.IndexName)
- frequencyRow.AddCell().SetValue(icl.Frequency)
- unitRow.AddCell().SetValue(icl.Unit)
- timeDate, err := time.Parse(utils.FormatDateTime, dataList[0].ModifyTime)
- if err != nil {
- continue
- }
- lastModifyDateRow.AddCell().SetValue(timeDate.Format(utils.FormatDate))
- dataInfoMap := make(map[string]*data_manage.BaseFromCCFData)
- for _, v := range dataList {
- dataInfoMap[v.DataTime] = v
- }
- for rk, dtv := range dataTimeList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDateCell := row.AddCell()
- tmpData, ok := dataInfoMap[dtv]
- if ok {
- displayDateCell.SetValue(tmpData.Value)
- }
- }
- }
- }
- /*for k, sv := range indexList {
- //获取数据
- dataList, ok := dataListMap[sv.IndexCode]
- if !ok {
- continue
- }
- if len(dataList) > 0 {
- windRow.AddCell().SetValue("CCF化纤")
- secNameRow.AddCell().SetValue("指标名称")
- indexCodeRow.AddCell().SetValue("指标ID")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- secNameRow.AddCell().SetValue(sv.IndexName)
- indexCodeRow.AddCell().SetValue(sv.IndexCode)
- frequencyRow.AddCell().SetValue(sv.Frequency)
- unitRow.AddCell().SetValue(sv.Unit)
- lastModifyDateRow.AddCell().SetValue(sv.ModifyTime)
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- indexCodeRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- minCol := k * 3
- sheetNew.SetColWidth(minCol, minCol, 15)
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := setRowIndex + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetValue(dv.Value)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- }*/
- err = xlsxFile.Save(downFile)
- if err != nil {
- //有指标无数据时先导出一遍空表
- sheet, err := xlsxFile.AddSheet("无数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("")
- err = xlsxFile.Save(downFile)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- }
- fileName := `CCF化纤信息`
- //if len(indexList) > 0 {
- // fileName = indexList[0].IndexName
- //}
- fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
- this.Ctx.Output.Download(downFile, fileName)
- defer func() {
- os.Remove(downFile)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
- // CCFStockClassify
- // @Title CCF化纤信息-装置分类
- // @Description CCF化纤信息-装置分类
- // @Success 200 {object} data_manage.CCFStockClassify
- // @router /ccf/stock/classify [get]
- func (this *EdbInfoController) CCFStockClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- classifyOb := new(data_manage.CCFStockClassify)
- items, e := classifyOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "ccf_stock_classify_id ASC")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取CCF化纤分类列表失败, Err: " + e.Error()
- return
- }
- resp := make([]*data_manage.CCFStockClassifyItem, 0)
- for _, v := range items {
- resp = append(resp, v.Format2Item())
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CCFStockTable
- // @Title CCF化纤信息-装置表格详情
- // @Description CCF化纤信息-装置表格详情
- // @Param ClassifyId query int true "分类ID"
- // @Param TableDate query string false "表格日期"
- // @Success 200 {object} data_manage.CCFStockExcel
- // @router /ccf/stock/table [get]
- func (this *EdbInfoController) CCFStockTable() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- classifyId, _ := this.GetInt("ClassifyId", 0)
- tableDate := this.GetString("TableDate")
- if tableDate != "" {
- _, e := time.ParseInLocation(utils.FormatDate, tableDate, time.Local)
- if e != nil {
- br.Msg = "日期格式有误"
- return
- }
- }
- excelOb := new(data_manage.CCFStockExcel)
- cond := ``
- pars := make([]interface{}, 0)
- if classifyId > 0 {
- cond += fmt.Sprintf(` AND %s = ?`, excelOb.Cols().ClassifyId)
- pars = append(pars, classifyId)
- }
- if tableDate != "" {
- cond += fmt.Sprintf(` AND %s = ?`, excelOb.Cols().ExcelDate)
- pars = append(pars, tableDate)
- }
- // 若无tableDate默认取最近的有数据的表格
- item, e := excelOb.GetItemByCondition(cond, pars, fmt.Sprintf("%s DESC", excelOb.Cols().ExcelDate))
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Ret = 200
- br.Success = true
- br.Msg = "该日期暂无数据"
- br.Data = data_manage.CCFStockExcel{}
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取CCF化纤装置表格失败, Err: " + e.Error()
- return
- }
- resp := item.Format2Item()
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CCFIndexBatchSearch
- // @Title CCF化纤信息指标查询
- // @Description CCF化纤信息指标查询
- // @Param ClassifyIds query string true "分类id, 多个分类用英文"
- // @Param Keyword query string true "关键词, 指标ID/指标名称"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /ccf/batch_search [get]
- func (this *EdbInfoController) CCFIndexBatchSearch() {
- 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
- }
- classifyIdStr := this.GetString("ClassifyIds")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- resp := data_manage.BaseFromCCFIndexSearchList{}
- total := 0
- page := paging.GetPaging(currentIndex, pageSize, total)
- var list = make([]*data_manage.BaseFromCCFIndexList, 0)
- var condition string
- var pars []interface{}
- classifyIds := strings.Split(classifyIdStr, ",")
- if len(classifyIds) > 0 && classifyIds[0] != `` {
- condition += " AND classify_id IN (" + utils.GetOrmInReplace(len(classifyIds)) + " ) "
- pars = append(pars, classifyIds)
- }
- keyword := this.GetString("Keyword")
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- frequencies := this.GetString("Frequencies")
- if frequencies != "" {
- frequencyList := strings.Split(frequencies, ",")
- condition += " AND frequency IN (" + utils.GetOrmInReplace(len(frequencyList)) + " ) "
- pars = append(pars, frequencyList)
- }
- condition += ` AND index_code not in (SELECT edb_code FROM edb_info WHERE source=?) `
- pars = append(pars, utils.DATA_SOURCE_CCF)
- list, err := data_manage.GetCCFIndexPage(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- // 获取最新值
- endTimeList := make([]string, 0)
- endValMap := make(map[int]string)
- indexIds := make([]int, 0)
- for _, v := range list {
- endTimeList = append(endTimeList, v.EndDate)
- indexIds = append(indexIds, v.BaseFromCcfIndexId)
- }
- if len(indexIds) > 0 {
- dataTmpList, e := data_manage.GetCCFIndexDataByIndexIdAndDataTime(indexIds, endTimeList)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标最新值失败,Err:" + e.Error()
- return
- }
- for _, v := range dataTmpList {
- endValMap[v.BaseFromCcfIndexId] = v.Value
- }
- }
- for _, v := range list {
- if val, ok := endValMap[v.BaseFromCcfIndexId]; ok {
- v.EndValue = val
- }
- }
- total, err = data_manage.GetCCFIndexPageCount(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CCFIndexBatchAdd
- // @Title CCF化纤信息批量新增
- // @Description CCF化纤信息批量新增
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /ccf/batch_add [post]
- func (this *EdbInfoController) CCFIndexBatchAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_BATCH_ADD_CCF_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- _ = utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req []*data_manage.AddEdbInfoReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if len(req) == 0 {
- br.Msg = "请选择指标"
- return
- }
- if len(req) > 30 {
- br.Msg = "批量添加指标数量不得超过30个"
- return
- }
- for _, v := range req {
- v.EdbCode = strings.TrimSpace(v.EdbCode)
- if v.EdbCode == "" {
- br.Msg = "指标ID不可为空"
- return
- }
- v.EdbName = strings.TrimSpace(v.EdbName)
- if v.EdbName == "" {
- br.Msg = "请输入指标名称"
- return
- }
- v.Frequency = strings.TrimSpace(v.Frequency)
- if v.Frequency == "" {
- br.Msg = "请选择频度"
- return
- }
- v.Unit = strings.TrimSpace(v.Unit)
- if v.Unit == "" {
- br.Msg = "请输入单位"
- return
- }
- if v.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- }
- // 限定同一时间最多批量新增30个指标
- for _, v := range req {
- var r data_manage.CCFIndexSource2EdbReq
- r.EdbCode = v.EdbCode
- r.EdbName = v.EdbName
- r.Frequency = v.Frequency
- r.Unit = v.Unit
- r.ClassifyId = v.ClassifyId
- r.AdminId = sysUser.AdminId
- r.AdminRealName = sysUser.RealName
- edbInfo, e, errMsg, skip := data.CCFIndexSource2Edb(r, this.Lang)
- if e != nil {
- br.Msg = "操作失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = e.Error()
- return
- }
- if skip {
- continue
- }
- // 试用平台更新用户累计新增指标数
- if utils.BusinessCode == utils.BusinessCodeSandbox {
- go func() {
- adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- if e != nil {
- tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
- utils.FileLog.Info(tips)
- return
- }
- if adminItem.DepartmentName != "ETA试用客户" {
- return
- }
- var ur etaTrialService.EtaTrialUserReq
- ur.Mobile = adminItem.Mobile
- _, _ = etaTrialService.UpdateUserIndexNum(ur)
- }()
- }
- // 新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- }
- br.Msg = "操作成功"
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- }
- // CCFIndexNameCheck
- // @Title 加入指标库的重名检测
- // @Description 加入指标库的重名检测
- // @Param ClassifyIds query string true "分类id, 多个分类用英文"
- // @Param Keyword query string true "关键词, 指标ID/指标名称"
- // @Success 200 {object} NameCheckResult
- // @router /ccf/edb_info/name_check [post]
- func (this *EdbInfoController) CCFIndexNameCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- 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 []*data_manage.NameCheckEdbInfoReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if len(req) == 0 {
- br.Msg = "请选择指标"
- return
- }
- codeMaxT := 30
- codeLen := len(req)
- if codeLen > codeMaxT {
- br.Msg = "批量添加指标数量不得超过30个"
- return
- }
- indexNames := make([]string, 0)
- resp := make([]*data_manage.EdbNameCheckResult, 0)
- for _, v := range req {
- v.EdbCode = strings.TrimSpace(v.EdbCode)
- if v.EdbCode == "" {
- br.Msg = "指标ID不可为空"
- return
- }
- v.EdbName = strings.TrimSpace(v.EdbName)
- if v.EdbName == "" {
- br.Msg = "请输入指标名称"
- return
- }
- indexNames = append(indexNames, v.EdbName)
- resp = append(resp, &data_manage.EdbNameCheckResult{
- EdbCode: v.EdbCode,
- EdbName: v.EdbName,
- })
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(v.EdbCode, utils.DATA_SOURCE_CCF, 0, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) <= 0 {
- respItem, err := data.AddEdbData(utils.DATA_SOURCE_CCF, v.EdbCode, v.Frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + v.EdbCode
- return
- }
- }
- }
- // 重名校验
- edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
- return
- }
- nameExists := make(map[string]bool)
- for _, v := range edbList {
- nameExists[v.EdbName] = true
- }
- if len(nameExists) > 0 {
- for _, v := range resp {
- v.Exist = nameExists[v.EdbName]
- }
- }
- br.Data = resp
- br.Msg = "校验成功"
- br.Ret = 200
- br.Success = true
- }
- // CCFAddCheck
- // @Title 加入指标库指标Id检测
- // @Description 加入指标库指标Id检测
- // @Param request body request.BatchAddCheckReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /ccf/edb_info/add_check [post]
- func (c *EdbInfoController) CCFAddCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.BatchAddCheckReq
- if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- codeMaxT := 30
- codeLen := len(req.IndexCodes)
- // 获取指标库已有指标
- existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_CCF)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取自有数据已添加的指标失败, Err: " + e.Error()
- return
- }
- existMap := make(map[string]*data_manage.EdbInfo)
- for _, v := range existsEdb {
- existMap[v.EdbCode] = v
- }
- if codeLen == 0 {
- br.Msg = "请选择指标"
- return
- }
- if codeLen > codeMaxT {
- br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMaxT)
- return
- }
- // 查询选中的指标
- cond := fmt.Sprintf(` AND index_code IN (%s)`, utils.GetOrmInReplace(codeLen))
- pars := make([]interface{}, 0)
- pars = append(pars, req.IndexCodes)
- list, err := data_manage.GetCCFIndex(cond, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(list) > codeMaxT {
- br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMaxT)
- return
- }
- resp := make([]*data_manage.BaseFromCCFIndexList, 0)
- for _, v := range list {
- if edb, ok := existMap[v.IndexCode]; ok {
- v.EdbInfoId = edb.EdbInfoId
- // todo 验证下面三个字段的用处
- //v.EdbClassifyId = edb.ClassifyId
- //v.EdbUniqueCode = edb.UniqueCode
- v.EdbExist = 1
- }
- resp = append(resp, v)
- }
- br.Data = resp
- br.Msg = "校验成功"
- br.Ret = 200
- br.Success = true
- }
- // CCFEdbInfoAdd
- // @Title 新增指标接口
- // @Description 新增指标接口
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /ccf/edb_info/add [post]
- func (this *EdbInfoController) CCFEdbInfoAdd() {
- 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
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req data_manage.AddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- req.EdbCode = strings.Trim(req.EdbCode, " ")
- if req.EdbCode == "" {
- br.Msg = "指标ID不能为空"
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if req.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if req.Unit == "" {
- br.Msg = "单位不能为空"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- count, err := data_manage.GetCCFIndexDataCount(req.EdbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if count == 0 {
- br.Msg = "指标不存在"
- }
- // 指标入库
- edbInfo, err, errMsg, isSendEmail := data.EdbInfoAdd(utils.DATA_SOURCE_CCF, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, req.StartDate, req.EndDate, sysUser.AdminId, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- // 试用平台更新用户累计新增指标数
- adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取系统用户数据失败,Err:" + e.Error()
- return
- }
- if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
- go func() {
- var r etaTrialService.EtaTrialUserReq
- r.Mobile = adminItem.Mobile
- _, _ = etaTrialService.UpdateUserIndexNum(r)
- }()
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- // 更新es
- go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
- resp := new(data_manage.AddEdbInfoResp)
- resp.EdbInfoId = edbInfo.EdbInfoId
- resp.UniqueCode = edbInfo.UniqueCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // GetFrequency
- // @Title CCF化纤信息数据频度
- // @Description CCF化纤信息数据频度接口
- // @Param ClassifyId query string true "分类Id"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /ccf/frequency [get]
- func (this *EdbInfoController) GetCCFFrequency() {
- 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
- }
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- return
- }
- frequencyList, err := data_manage.GetCCFFrequencyByClassifyId(classifyId)
- if err != nil {
- br.Msg = "获取频度失败"
- br.ErrMsg = "获取频度失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = frequencyList
- }
- // BatchAddEdbCheck
- // @Title 新增校验
- // @Description 新增校验
- // @Param request body data_manage.BatchManualEdbReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /ccf/batch/add/check [post]
- func (c *EdbInfoController) BatchAddEdbCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- // 最大批量添加的数量
- codeMaxT := 31
- var req data_manage.BatchCheckCCFEdbReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,Err:" + err.Error()
- return
- }
- req.Keyword = strings.TrimSpace(req.Keyword)
- classifyIdStr := req.ClassifyIds
- var list = make([]*data_manage.BaseFromCCFIndexList, 0)
- var condition string
- var pars []interface{}
- if req.ListAll {
- classifyIds := strings.Split(classifyIdStr, ",")
- if len(classifyIds) > 0 && classifyIds[0] != `` {
- condition += " AND classify_id IN (" + utils.GetOrmInReplace(len(classifyIds)) + " ) "
- pars = append(pars, classifyIds)
- }
- keyword := req.Keyword
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- frequencies := req.Frequencies
- if frequencies != "" {
- frequencyList := strings.Split(frequencies, ",")
- condition += " AND frequency IN (" + utils.GetOrmInReplace(len(frequencyList)) + " ) "
- pars = append(pars, frequencyList)
- }
- codes := req.TradeCodeList
- codeList := make([]string, 0)
- if codes != "" {
- codeList = strings.Split(codes, ",")
- }
- if len(codeList) > 0 {
- condition += ` AND index_code not in (` + utils.GetOrmInReplace(len(codeList)) + `) `
- pars = append(pars, codeList)
- }
- } else {
- codes := req.TradeCodeList
- codeList := make([]string, 0)
- if codes != "" {
- codeList = strings.Split(codes, ",")
- }
- if len(codeList) <= 0 {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- return
- }
- // 指标
- condition += ` AND index_code in (` + utils.GetOrmInReplace(len(codeList)) + `) `
- pars = append(pars, codeList)
- }
- condition += ` AND index_code not in (SELECT edb_code FROM edb_info WHERE source=?) `
- pars = append(pars, utils.DATA_SOURCE_CCF)
- list, err = data_manage.GetCCFIndexPage(condition, pars, 0, codeMaxT)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if len(list) >= codeMaxT {
- br.Msg = "批量添加指标数量不得超过30个"
- return
- }
- br.Data = list
- br.Msg = "校验成功"
- br.Ret = 200
- br.Success = true
- }
|