ccf_data.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/system"
  7. "eta/eta_api/services/data"
  8. etaTrialService "eta/eta_api/services/eta_trial"
  9. "eta/eta_api/utils"
  10. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. "github.com/tealeg/xlsx"
  13. "os"
  14. "path/filepath"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // CCFClassify
  20. // @Title CCF化纤分类
  21. // @Description CCF化纤分类接口
  22. // @Success 200 {object} data_manage.BaseFromCCFClassifyItem
  23. // @router /ccf/classify [get]
  24. func (this *EdbInfoController) CCFClassify() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. if br.ErrMsg == "" {
  28. br.IsSendEmail = false
  29. }
  30. this.Data["json"] = br
  31. this.ServeJSON()
  32. }()
  33. sysUser := this.SysUser
  34. if sysUser == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,SysUser Is Empty"
  37. br.Ret = 408
  38. return
  39. }
  40. classifies, e := data_manage.GetBaseFromCCFClassify()
  41. if e != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取CCF化纤分类失败, Err: " + e.Error()
  44. return
  45. }
  46. classifyOb := new(data_manage.BaseFromCCFClassify)
  47. resp := make([]*data_manage.BaseFromCCFClassifyItem, 0)
  48. parentMap := make(map[int][]*data_manage.BaseFromCCFClassifyItem)
  49. for _, v := range classifies {
  50. t := classifyOb.Format2Item(v)
  51. if v.ParentId == 0 {
  52. resp = append(resp, t)
  53. }
  54. if v.ParentId > 0 {
  55. if parentMap[v.ParentId] == nil {
  56. parentMap[v.ParentId] = make([]*data_manage.BaseFromCCFClassifyItem, 0)
  57. }
  58. parentMap[v.ParentId] = append(parentMap[v.ParentId], t)
  59. }
  60. }
  61. for _, v := range resp {
  62. v.Child = parentMap[v.ClassifyId]
  63. }
  64. br.Data = resp
  65. br.Ret = 200
  66. br.Success = true
  67. br.Msg = "获取成功"
  68. }
  69. // CCFIndexData
  70. // @Title 获取CCF化纤数据
  71. // @Description 获取CCF化纤接口
  72. // @Param PageSize query int true "每页数据条数"
  73. // @Param CurrentIndex query int true "当前页页码,从1开始"
  74. // @Param ClassifyId query string true "分类id"
  75. // @Success 200 {object} data_manage.LzFrequency
  76. // @router /ccf/index/data [get]
  77. func (this *EdbInfoController) CCFIndexData() {
  78. br := new(models.BaseResponse).Init()
  79. defer func() {
  80. if br.ErrMsg == "" {
  81. br.IsSendEmail = false
  82. }
  83. this.Data["json"] = br
  84. this.ServeJSON()
  85. }()
  86. sysUser := this.SysUser
  87. if sysUser == nil {
  88. br.Msg = "请登录"
  89. br.ErrMsg = "请登录,SysUser Is Empty"
  90. br.Ret = 408
  91. return
  92. }
  93. pageSize, _ := this.GetInt("PageSize")
  94. currentIndex, _ := this.GetInt("CurrentIndex")
  95. var startSize int
  96. if pageSize <= 0 {
  97. pageSize = utils.PageSize20
  98. }
  99. if currentIndex <= 0 {
  100. currentIndex = 1
  101. }
  102. startSize = utils.StartIndex(currentIndex, pageSize)
  103. classifyId, _ := this.GetInt("ClassifyId")
  104. if classifyId < 0 {
  105. br.Msg = "请选择分类"
  106. br.ErrMsg = "请选择分类"
  107. return
  108. }
  109. // 增加频度请求入参
  110. frequency := this.GetString("Frequency")
  111. // 获取指标
  112. var condition string
  113. var pars []interface{}
  114. if classifyId >= 0 {
  115. condition += ` AND classify_id=? `
  116. pars = append(pars, classifyId)
  117. }
  118. if frequency != "" {
  119. condition += ` AND frequency=? `
  120. pars = append(pars, frequency)
  121. }
  122. indexes, err := data_manage.GetCCFIndex(condition, pars)
  123. if err != nil {
  124. br.Msg = "获取数据失败"
  125. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  126. return
  127. }
  128. indexCodes := make([]string, 0)
  129. for _, v := range indexes {
  130. indexCodes = append(indexCodes, v.IndexCode)
  131. }
  132. /*indexCounts, e := data_manage.GetCCFIndexDataCountGroup(indexCodes)
  133. if e != nil {
  134. br.Msg = "获取失败"
  135. br.ErrMsg = "获取指标数据总量失败, Err:" + err.Error()
  136. return
  137. }
  138. countMap := make(map[string]int)
  139. for _, v := range indexCounts {
  140. countMap[v.IndexCode] = v.Count
  141. }*/
  142. edbInfoMap := make(map[string]*data_manage.EdbInfo)
  143. dataMap := make(map[string][]*data_manage.BaseFromCCFData)
  144. total := 0
  145. if len(indexCodes) > 0 {
  146. edbInfoList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_CCF, indexCodes)
  147. if err != nil {
  148. br.Msg = "获取数据源失败"
  149. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  150. return
  151. }
  152. for _, v := range edbInfoList {
  153. edbInfoMap[v.EdbCode] = v
  154. }
  155. // 首先对分类下的指标按照日期进行分页,再针对日期,进行排序
  156. dataTimes, err := data_manage.GetCCFIndexDataTimePageByCodes(indexCodes, startSize, pageSize)
  157. if err != nil {
  158. br.Msg = "获取数据失败"
  159. br.ErrMsg = "获取指标数据日期信息失败,Err:" + err.Error()
  160. return
  161. }
  162. if len(dataTimes) > 0 {
  163. startDate := dataTimes[len(dataTimes)-1]
  164. endDate := dataTimes[0]
  165. // 把截止日往后加1天
  166. endDateT, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  167. endDate = endDateT.AddDate(0, 0, 1).Format(utils.FormatDate)
  168. dataList, e := data_manage.GetCCFIndexDataByDataTime(indexCodes, startDate, endDate)
  169. if e != nil {
  170. br.Msg = "获取数据失败"
  171. br.ErrMsg = "获取指标数据失败,Err:" + e.Error()
  172. return
  173. }
  174. //将数据按照指标进行分类
  175. for _, v := range dataList {
  176. dataMap[v.IndexCode] = append(dataMap[v.IndexCode], v)
  177. }
  178. }
  179. total, err = data_manage.GetCCFIndexDataTimePageCount(indexCodes)
  180. if err != nil {
  181. br.Msg = "获取数据失败"
  182. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  183. return
  184. }
  185. }
  186. page := paging.GetPaging(currentIndex, pageSize, total)
  187. resultList := make([]*data_manage.BaseFromCCFIndexList, 0)
  188. for _, v := range indexes {
  189. product := new(data_manage.BaseFromCCFIndexList)
  190. product.BaseFromCcfIndexId = v.BaseFromCcfIndexId
  191. product.ClassifyId = v.ClassifyId
  192. product.Unit = v.Unit
  193. product.IndexCode = v.IndexCode
  194. product.IndexName = v.IndexName
  195. product.Frequency = v.Frequency
  196. product.CreateTime = v.CreateTime
  197. product.ModifyTime = v.ModifyTime
  198. if edb, ok := edbInfoMap[v.IndexCode]; ok {
  199. product.EdbInfoId = edb.EdbInfoId
  200. product.EdbExist = 1
  201. }
  202. /*total := countMap[v.IndexCode]
  203. page := paging.GetPaging(currentIndex, pageSize, total)
  204. dataList, e := data_manage.GetCCFIndexData(v.IndexCode, startSize, pageSize)
  205. if e != nil {
  206. br.Msg = "获取数据失败"
  207. br.ErrMsg = "获取指标数据失败,Err:" + e.Error()
  208. return
  209. }*/
  210. dataListTmp, ok := dataMap[v.IndexCode]
  211. if !ok {
  212. dataListTmp = make([]*data_manage.BaseFromCCFData, 0)
  213. }
  214. product.DataList = dataListTmp
  215. product.Paging = page
  216. resultList = append(resultList, product)
  217. }
  218. br.Ret = 200
  219. br.Success = true
  220. br.Msg = "获取成功"
  221. br.Data = resultList
  222. }
  223. // CCFSearchList
  224. // @Title CCF模糊搜索
  225. // @Description CCF模糊搜索
  226. // @Param Keyword query string ture "关键字搜索"
  227. // @Success 200 {object} data_manage.BaseFromCCFIndexSearchItem
  228. // @router /ccf/search_list [get]
  229. func (this *EdbInfoController) CCFSearchList() {
  230. br := new(models.BaseResponse).Init()
  231. defer func() {
  232. if br.ErrMsg == "" {
  233. br.IsSendEmail = false
  234. }
  235. this.Data["json"] = br
  236. this.ServeJSON()
  237. }()
  238. sysUser := this.SysUser
  239. if sysUser == nil {
  240. br.Msg = "请登录"
  241. br.ErrMsg = "请登录,SysUser Is Empty"
  242. br.Ret = 408
  243. return
  244. }
  245. list := make([]*data_manage.BaseFromCCFIndexSearchItem, 0)
  246. var err error
  247. // 关键字
  248. keyword := this.GetString("Keyword")
  249. if keyword != "" {
  250. keyWordArr := strings.Split(keyword, " ")
  251. if len(keyWordArr) > 0 {
  252. condition := ""
  253. for _, v := range keyWordArr {
  254. condition += ` AND CONCAT(index_name,index_code) LIKE '%` + v + `%'`
  255. }
  256. list, err = data_manage.GetCCFItemList(condition)
  257. if err != nil {
  258. br.ErrMsg = "获取失败,Err:" + err.Error()
  259. br.Msg = "获取失败"
  260. return
  261. }
  262. }
  263. } else {
  264. list, err = data_manage.GetCCFItemList("")
  265. if err != nil {
  266. br.ErrMsg = "获取失败,Err:" + err.Error()
  267. br.Msg = "获取失败"
  268. return
  269. }
  270. }
  271. br.Ret = 200
  272. br.Success = true
  273. br.Msg = "获取成功"
  274. br.Data = list
  275. }
  276. // CCFSingleData
  277. // @Title 获取CCF数据
  278. // @Description 获取CCF单条数据接口
  279. // @Param IndexCode query string true "指标唯一编码"
  280. // @Success 200 {object} models.BaseResponse
  281. // @router /ccf/single_data [get]
  282. func (this *EdbInfoController) CCFSingleData() {
  283. br := new(models.BaseResponse).Init()
  284. defer func() {
  285. if br.ErrMsg == "" {
  286. br.IsSendEmail = false
  287. }
  288. this.Data["json"] = br
  289. this.ServeJSON()
  290. }()
  291. sysUser := this.SysUser
  292. if sysUser == nil {
  293. br.Msg = "请登录"
  294. br.ErrMsg = "请登录,SysUser Is Empty"
  295. br.Ret = 408
  296. return
  297. }
  298. indexCode := this.GetString("IndexCode")
  299. indexInfo, err := data_manage.GetBaseFromCCFIndexByIndexCode(indexCode)
  300. if err != nil {
  301. br.Msg = "获取指标信息失败"
  302. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  303. return
  304. }
  305. dataTmpList, err := data_manage.GetCCFIndexDataByCode(indexCode)
  306. if err != nil {
  307. br.Msg = "获取数据失败"
  308. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  309. return
  310. }
  311. var ret data_manage.CCFSingleDataResp
  312. var dataList []*data_manage.CCFSingleData
  313. ret.ClassifyId = indexInfo.ClassifyId
  314. ret.BaseFromCcfIndexId = indexInfo.BaseFromCcfIndexId
  315. ret.IndexCode = indexInfo.IndexCode
  316. ret.IndexName = indexInfo.IndexName
  317. ret.Frequency = indexInfo.Frequency
  318. ret.CreateTime = indexInfo.CreateTime.Format(utils.FormatDateTime)
  319. ret.ModifyTime = indexInfo.ModifyTime.Format(utils.FormatDateTime)
  320. ret.Unit = indexInfo.Unit
  321. for _, v := range dataTmpList {
  322. tmp := &data_manage.CCFSingleData{
  323. Value: v.Value,
  324. DataTime: v.DataTime,
  325. }
  326. dataList = append(dataList, tmp)
  327. }
  328. ret.Data = dataList
  329. br.Ret = 200
  330. br.Success = true
  331. br.Msg = "获取成功"
  332. br.Data = ret
  333. }
  334. // ExportCCFList
  335. // @Title 导出CCF数据
  336. // @Description 导出CCF数据
  337. // @Param IndexName query string false "名称关键词"
  338. // @Param IndexCode query string false "指标唯一编码"
  339. // @Param ClassifyId query string true "分类"
  340. // @Success 200 导出成功
  341. // @router /ccf/export [get]
  342. func (this *EdbInfoController) ExportCCFList() {
  343. br := new(models.BaseResponse).Init()
  344. defer func() {
  345. if br.ErrMsg == "" {
  346. br.IsSendEmail = false
  347. }
  348. this.Data["json"] = br
  349. this.ServeJSON()
  350. }()
  351. sysUser := this.SysUser
  352. if sysUser == nil {
  353. br.Msg = "请重新登录"
  354. return
  355. }
  356. indexCode := this.GetString("IndexCode") //指标唯一编码
  357. classifyId, _ := this.GetInt("ClassifyId")
  358. dir, _ := os.Executable()
  359. exPath := filepath.Dir(dir)
  360. downFile := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  361. xlsxFile := xlsx.NewFile()
  362. var pars []interface{}
  363. condition := ""
  364. if classifyId > 0 {
  365. //获取指标
  366. condition += " AND classify_id=?"
  367. pars = append(pars, classifyId)
  368. }
  369. if indexCode != "" {
  370. //获取指标
  371. condition += " AND index_code=?"
  372. pars = append(pars, indexCode)
  373. }
  374. indexList, err := data_manage.GetCCFIndex(condition, pars)
  375. if err != nil {
  376. fmt.Println("获取数据失败,Err:" + err.Error())
  377. return
  378. }
  379. if len(indexList) <= 0 {
  380. fmt.Println("indexList 为空")
  381. br.Ret = 200
  382. br.Success = true
  383. br.Msg = "success"
  384. return
  385. }
  386. //sheetNew := new(xlsx.Sheet)
  387. //sheetNew, err = xlsxFile.AddSheet("CCF化纤")
  388. //sheetNew.SetColWidth()
  389. //获取指标数据
  390. /*windRow := sheetNew.AddRow()
  391. secNameRow := sheetNew.AddRow()
  392. indexCodeRow := sheetNew.AddRow()
  393. frequencyRow := sheetNew.AddRow()
  394. unitRow := sheetNew.AddRow()
  395. lastModifyDateRow := sheetNew.AddRow()*/
  396. //获取分类下指标最大数据量
  397. var dataMax int
  398. //setRowIndex := 6
  399. codeList := make([]string, 0)
  400. frequenciesMap := make(map[string][]*data_manage.BaseFromCCFIndexList)
  401. for _, v := range indexList {
  402. codeList = append(codeList, v.IndexCode)
  403. frequenciesMap[v.Frequency] = append(frequenciesMap[v.Frequency], v)
  404. }
  405. dataListMap := make(map[string][]*data_manage.BaseFromCCFData)
  406. if len(indexList) > 0 {
  407. allDataList, e := data_manage.GetCCFIndexDataByCodes(codeList)
  408. if e != nil {
  409. br.Msg = "获取数据失败"
  410. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  411. return
  412. }
  413. for _, v := range allDataList {
  414. dataListMap[v.IndexCode] = append(dataListMap[v.IndexCode], v)
  415. }
  416. for _, v := range dataListMap {
  417. if len(v) > dataMax {
  418. dataMax = len(v)
  419. }
  420. }
  421. }
  422. // 按照频率分组排序
  423. frequencies := []string{
  424. "日度", "周度", "旬度", "月度", "季度", "半年度", "年度",
  425. }
  426. for _, frequency := range frequencies {
  427. //获取指标
  428. indexCodeList, ok := frequenciesMap[frequency]
  429. if !ok {
  430. continue
  431. }
  432. if len(indexCodeList) <= 0 {
  433. fmt.Printf("sheet:%s, 不存在指标", frequency)
  434. return
  435. }
  436. var sheetName string
  437. switch frequency {
  438. case "日度":
  439. sheetName = "日度(Daily)"
  440. case "周度":
  441. sheetName = "周度(Weekly)"
  442. case "旬度":
  443. sheetName = "旬度(ten-day)"
  444. case "月度":
  445. sheetName = "月度(Monthly)"
  446. case "季度":
  447. sheetName = "季度(Quarterly)"
  448. case "半年度":
  449. sheetName = "半年度(Semi-annual)"
  450. case "年度":
  451. sheetName = "年度(Annual)"
  452. default:
  453. sheetName = "其他数据"
  454. }
  455. sheetNew, err := xlsxFile.AddSheet(sheetName)
  456. if err != nil {
  457. fmt.Println("新增Sheet失败", err.Error())
  458. return
  459. }
  460. secNameRow := sheetNew.AddRow()
  461. frequencyRow := sheetNew.AddRow()
  462. unitRow := sheetNew.AddRow()
  463. lastModifyDateRow := sheetNew.AddRow()
  464. var indexIdList []int
  465. for _, idx := range frequenciesMap[frequency] {
  466. indexIdList = append(indexIdList, idx.BaseFromCcfIndexId)
  467. }
  468. dataTimeList, err := data_manage.GetCCFDataDataTimeByIndexId(indexIdList)
  469. if err != nil {
  470. br.Msg = "下载失败"
  471. br.ErrMsg = "获取数据时间失败,Err:" + err.Error()
  472. fmt.Println("获取数据时间失败", err.Error())
  473. return
  474. }
  475. // 添加excel左侧指标日期
  476. setRowIndex := 4
  477. for rk, dv := range dataTimeList {
  478. rowIndex := setRowIndex + rk
  479. row := sheetNew.Row(rowIndex)
  480. displayDate, _ := time.Parse(utils.FormatDate, dv)
  481. displayDateCell := row.AddCell()
  482. style := new(xlsx.Style)
  483. style.ApplyAlignment = true
  484. style.Alignment.WrapText = true
  485. displayDateCell.SetStyle(style)
  486. displayDateCell.SetDate(displayDate)
  487. }
  488. for k, icl := range indexCodeList {
  489. // 获取数据
  490. dataList, ok := dataListMap[icl.IndexCode]
  491. if !ok {
  492. continue
  493. }
  494. if k == 0 {
  495. secNameRow.AddCell().SetValue("指标名称/Metric Name")
  496. frequencyRow.AddCell().SetValue("频度/Frequency")
  497. unitRow.AddCell().SetValue("单位/Unit")
  498. lastModifyDateRow.AddCell().SetValue("更新时间/Update Time")
  499. min := k * 3
  500. sheetNew.SetColWidth(min, min, 15)
  501. }
  502. if len(dataList) == 0 {
  503. continue
  504. }
  505. secNameRow.AddCell().SetValue(icl.IndexName)
  506. frequencyRow.AddCell().SetValue(icl.Frequency)
  507. unitRow.AddCell().SetValue(icl.Unit)
  508. timeDate, err := time.Parse(utils.FormatDateTime, dataList[0].ModifyTime)
  509. if err != nil {
  510. continue
  511. }
  512. lastModifyDateRow.AddCell().SetValue(timeDate.Format(utils.FormatDate))
  513. dataInfoMap := make(map[string]*data_manage.BaseFromCCFData)
  514. for _, v := range dataList {
  515. dataInfoMap[v.DataTime] = v
  516. }
  517. for rk, dtv := range dataTimeList {
  518. rowIndex := setRowIndex + rk
  519. row := sheetNew.Row(rowIndex)
  520. displayDateCell := row.AddCell()
  521. tmpData, ok := dataInfoMap[dtv]
  522. if ok {
  523. displayDateCell.SetValue(tmpData.Value)
  524. }
  525. }
  526. }
  527. }
  528. /*for k, sv := range indexList {
  529. //获取数据
  530. dataList, ok := dataListMap[sv.IndexCode]
  531. if !ok {
  532. continue
  533. }
  534. if len(dataList) > 0 {
  535. windRow.AddCell().SetValue("CCF化纤")
  536. secNameRow.AddCell().SetValue("指标名称")
  537. indexCodeRow.AddCell().SetValue("指标ID")
  538. frequencyRow.AddCell().SetValue("频率")
  539. unitRow.AddCell().SetValue("单位")
  540. lastModifyDateRow.AddCell().SetValue("更新时间")
  541. secNameRow.AddCell().SetValue(sv.IndexName)
  542. indexCodeRow.AddCell().SetValue(sv.IndexCode)
  543. frequencyRow.AddCell().SetValue(sv.Frequency)
  544. unitRow.AddCell().SetValue(sv.Unit)
  545. lastModifyDateRow.AddCell().SetValue(sv.ModifyTime)
  546. windRow.AddCell()
  547. windRow.AddCell()
  548. secNameRow.AddCell()
  549. indexCodeRow.AddCell()
  550. frequencyRow.AddCell()
  551. unitRow.AddCell()
  552. lastModifyDateRow.AddCell()
  553. minCol := k * 3
  554. sheetNew.SetColWidth(minCol, minCol, 15)
  555. if len(dataList) <= 0 {
  556. for n := 0; n < dataMax; n++ {
  557. rowIndex := setRowIndex + n
  558. row := sheetNew.Row(rowIndex)
  559. row.AddCell()
  560. row.AddCell()
  561. row.AddCell()
  562. }
  563. } else {
  564. endRowIndex := 0
  565. for rk, dv := range dataList {
  566. rowIndex := setRowIndex + rk
  567. row := sheetNew.Row(rowIndex)
  568. displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
  569. displayDateCell := row.AddCell()
  570. style := new(xlsx.Style)
  571. style.ApplyAlignment = true
  572. style.Alignment.WrapText = true
  573. displayDateCell.SetStyle(style)
  574. displayDateCell.SetDate(displayDate)
  575. row.AddCell().SetValue(dv.Value)
  576. row.AddCell()
  577. endRowIndex = rowIndex
  578. }
  579. if len(dataList) < dataMax {
  580. dataLen := dataMax - len(dataList)
  581. for n := 0; n < dataLen; n++ {
  582. rowIndex := (endRowIndex + 1) + n
  583. row := sheetNew.Row(rowIndex)
  584. row.AddCell()
  585. row.AddCell()
  586. row.AddCell()
  587. }
  588. }
  589. }
  590. }
  591. }*/
  592. err = xlsxFile.Save(downFile)
  593. if err != nil {
  594. //有指标无数据时先导出一遍空表
  595. sheet, err := xlsxFile.AddSheet("无数据")
  596. if err != nil {
  597. br.Msg = "新增Sheet失败"
  598. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  599. return
  600. }
  601. rowSecName := sheet.AddRow()
  602. celSecName := rowSecName.AddCell()
  603. celSecName.SetValue("")
  604. err = xlsxFile.Save(downFile)
  605. if err != nil {
  606. br.Msg = "保存文件失败"
  607. br.ErrMsg = "保存文件失败"
  608. return
  609. }
  610. }
  611. fileName := `CCF化纤信息`
  612. //if len(indexList) > 0 {
  613. // fileName = indexList[0].IndexName
  614. //}
  615. fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
  616. this.Ctx.Output.Download(downFile, fileName)
  617. defer func() {
  618. os.Remove(downFile)
  619. }()
  620. br.Ret = 200
  621. br.Success = true
  622. br.Msg = "success"
  623. }
  624. // CCFStockClassify
  625. // @Title CCF化纤信息-装置分类
  626. // @Description CCF化纤信息-装置分类
  627. // @Success 200 {object} data_manage.CCFStockClassify
  628. // @router /ccf/stock/classify [get]
  629. func (this *EdbInfoController) CCFStockClassify() {
  630. br := new(models.BaseResponse).Init()
  631. defer func() {
  632. if br.ErrMsg == "" {
  633. br.IsSendEmail = false
  634. }
  635. this.Data["json"] = br
  636. this.ServeJSON()
  637. }()
  638. sysUser := this.SysUser
  639. if sysUser == nil {
  640. br.Msg = "请登录"
  641. br.ErrMsg = "请登录,SysUser Is Empty"
  642. br.Ret = 408
  643. return
  644. }
  645. classifyOb := new(data_manage.CCFStockClassify)
  646. items, e := classifyOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "ccf_stock_classify_id ASC")
  647. if e != nil {
  648. br.Msg = "获取失败"
  649. br.ErrMsg = "获取CCF化纤分类列表失败, Err: " + e.Error()
  650. return
  651. }
  652. resp := make([]*data_manage.CCFStockClassifyItem, 0)
  653. for _, v := range items {
  654. resp = append(resp, v.Format2Item())
  655. }
  656. br.Ret = 200
  657. br.Success = true
  658. br.Msg = "获取成功"
  659. br.Data = resp
  660. }
  661. // CCFStockTable
  662. // @Title CCF化纤信息-装置表格详情
  663. // @Description CCF化纤信息-装置表格详情
  664. // @Param ClassifyId query int true "分类ID"
  665. // @Param TableDate query string false "表格日期"
  666. // @Success 200 {object} data_manage.CCFStockExcel
  667. // @router /ccf/stock/table [get]
  668. func (this *EdbInfoController) CCFStockTable() {
  669. br := new(models.BaseResponse).Init()
  670. defer func() {
  671. if br.ErrMsg == "" {
  672. br.IsSendEmail = false
  673. }
  674. this.Data["json"] = br
  675. this.ServeJSON()
  676. }()
  677. sysUser := this.SysUser
  678. if sysUser == nil {
  679. br.Msg = "请登录"
  680. br.ErrMsg = "请登录,SysUser Is Empty"
  681. br.Ret = 408
  682. return
  683. }
  684. classifyId, _ := this.GetInt("ClassifyId", 0)
  685. tableDate := this.GetString("TableDate")
  686. if tableDate != "" {
  687. _, e := time.ParseInLocation(utils.FormatDate, tableDate, time.Local)
  688. if e != nil {
  689. br.Msg = "日期格式有误"
  690. return
  691. }
  692. }
  693. excelOb := new(data_manage.CCFStockExcel)
  694. cond := ``
  695. pars := make([]interface{}, 0)
  696. if classifyId > 0 {
  697. cond += fmt.Sprintf(` AND %s = ?`, excelOb.Cols().ClassifyId)
  698. pars = append(pars, classifyId)
  699. }
  700. if tableDate != "" {
  701. cond += fmt.Sprintf(` AND %s = ?`, excelOb.Cols().ExcelDate)
  702. pars = append(pars, tableDate)
  703. }
  704. // 若无tableDate默认取最近的有数据的表格
  705. item, e := excelOb.GetItemByCondition(cond, pars, fmt.Sprintf("%s DESC", excelOb.Cols().ExcelDate))
  706. if e != nil {
  707. if e.Error() == utils.ErrNoRow() {
  708. br.Ret = 200
  709. br.Success = true
  710. br.Msg = "该日期暂无数据"
  711. br.Data = data_manage.CCFStockExcel{}
  712. return
  713. }
  714. br.Msg = "获取失败"
  715. br.ErrMsg = "获取CCF化纤装置表格失败, Err: " + e.Error()
  716. return
  717. }
  718. resp := item.Format2Item()
  719. br.Ret = 200
  720. br.Success = true
  721. br.Msg = "获取成功"
  722. br.Data = resp
  723. }
  724. // CCFIndexBatchSearch
  725. // @Title CCF化纤信息指标查询
  726. // @Description CCF化纤信息指标查询
  727. // @Param ClassifyIds query string true "分类id, 多个分类用英文"
  728. // @Param Keyword query string true "关键词, 指标ID/指标名称"
  729. // @Success 200 {object} data_manage.LzFrequency
  730. // @router /ccf/batch_search [get]
  731. func (this *EdbInfoController) CCFIndexBatchSearch() {
  732. br := new(models.BaseResponse).Init()
  733. defer func() {
  734. this.Data["json"] = br
  735. this.ServeJSON()
  736. }()
  737. sysUser := this.SysUser
  738. if sysUser == nil {
  739. br.Msg = "请登录"
  740. br.ErrMsg = "请登录,SysUser Is Empty"
  741. br.Ret = 408
  742. return
  743. }
  744. classifyIdStr := this.GetString("ClassifyIds")
  745. pageSize, _ := this.GetInt("PageSize")
  746. currentIndex, _ := this.GetInt("CurrentIndex")
  747. var startSize int
  748. if pageSize <= 0 {
  749. pageSize = utils.PageSize20
  750. }
  751. if currentIndex <= 0 {
  752. currentIndex = 1
  753. }
  754. startSize = utils.StartIndex(currentIndex, pageSize)
  755. resp := data_manage.BaseFromCCFIndexSearchList{}
  756. total := 0
  757. page := paging.GetPaging(currentIndex, pageSize, total)
  758. var list = make([]*data_manage.BaseFromCCFIndexList, 0)
  759. var condition string
  760. var pars []interface{}
  761. classifyIds := strings.Split(classifyIdStr, ",")
  762. if len(classifyIds) > 0 && classifyIds[0] != `` {
  763. condition += " AND classify_id IN (" + utils.GetOrmInReplace(len(classifyIds)) + " ) "
  764. pars = append(pars, classifyIds)
  765. }
  766. keyword := this.GetString("Keyword")
  767. if keyword != `` {
  768. condition += " AND (index_name like ? OR index_code like ?) "
  769. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  770. }
  771. frequencies := this.GetString("Frequencies")
  772. if frequencies != "" {
  773. frequencyList := strings.Split(frequencies, ",")
  774. condition += " AND frequency IN (" + utils.GetOrmInReplace(len(frequencyList)) + " ) "
  775. pars = append(pars, frequencyList)
  776. }
  777. condition += ` AND index_code not in (SELECT edb_code FROM edb_info WHERE source=?) `
  778. pars = append(pars, utils.DATA_SOURCE_CCF)
  779. list, err := data_manage.GetCCFIndexPage(condition, pars, startSize, pageSize)
  780. if err != nil {
  781. br.Msg = "获取失败"
  782. br.ErrMsg = "获取失败,Err:" + err.Error()
  783. return
  784. }
  785. // 获取最新值
  786. endTimeList := make([]string, 0)
  787. endValMap := make(map[int]string)
  788. indexIds := make([]int, 0)
  789. for _, v := range list {
  790. endTimeList = append(endTimeList, v.EndDate)
  791. indexIds = append(indexIds, v.BaseFromCcfIndexId)
  792. }
  793. if len(indexIds) > 0 {
  794. dataTmpList, e := data_manage.GetCCFIndexDataByIndexIdAndDataTime(indexIds, endTimeList)
  795. if e != nil {
  796. br.Msg = "获取失败"
  797. br.ErrMsg = "获取指标最新值失败,Err:" + e.Error()
  798. return
  799. }
  800. for _, v := range dataTmpList {
  801. endValMap[v.BaseFromCcfIndexId] = v.Value
  802. }
  803. }
  804. for _, v := range list {
  805. if val, ok := endValMap[v.BaseFromCcfIndexId]; ok {
  806. v.EndValue = val
  807. }
  808. }
  809. total, err = data_manage.GetCCFIndexPageCount(condition, pars)
  810. if err != nil {
  811. br.Msg = "获取数据失败"
  812. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  813. return
  814. }
  815. page = paging.GetPaging(currentIndex, pageSize, total)
  816. resp.Paging = page
  817. resp.List = list
  818. br.Ret = 200
  819. br.Success = true
  820. br.Msg = "获取成功"
  821. br.Data = resp
  822. }
  823. // CCFIndexBatchAdd
  824. // @Title CCF化纤信息批量新增
  825. // @Description CCF化纤信息批量新增
  826. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  827. // @Success 200 string "操作成功"
  828. // @router /ccf/batch_add [post]
  829. func (this *EdbInfoController) CCFIndexBatchAdd() {
  830. br := new(models.BaseResponse).Init()
  831. defer func() {
  832. if br.ErrMsg == "" {
  833. br.IsSendEmail = false
  834. }
  835. this.Data["json"] = br
  836. this.ServeJSON()
  837. }()
  838. sysUser := this.SysUser
  839. if sysUser == nil {
  840. br.Msg = "请登录"
  841. br.ErrMsg = "请登录,SysUser Is Empty"
  842. br.Ret = 408
  843. return
  844. }
  845. deleteCache := true
  846. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_CCF_" + strconv.Itoa(sysUser.AdminId)
  847. defer func() {
  848. if deleteCache {
  849. _ = utils.Rc.Delete(cacheKey)
  850. }
  851. }()
  852. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  853. deleteCache = false
  854. br.Msg = "系统处理中,请稍后重试!"
  855. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  856. return
  857. }
  858. var req []*data_manage.AddEdbInfoReq
  859. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  860. br.Msg = "参数解析异常!"
  861. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  862. return
  863. }
  864. if len(req) == 0 {
  865. br.Msg = "请选择指标"
  866. return
  867. }
  868. if len(req) > 30 {
  869. br.Msg = "批量添加指标数量不得超过30个"
  870. return
  871. }
  872. for _, v := range req {
  873. v.EdbCode = strings.TrimSpace(v.EdbCode)
  874. if v.EdbCode == "" {
  875. br.Msg = "指标ID不可为空"
  876. return
  877. }
  878. v.EdbName = strings.TrimSpace(v.EdbName)
  879. if v.EdbName == "" {
  880. br.Msg = "请输入指标名称"
  881. return
  882. }
  883. v.Frequency = strings.TrimSpace(v.Frequency)
  884. if v.Frequency == "" {
  885. br.Msg = "请选择频度"
  886. return
  887. }
  888. v.Unit = strings.TrimSpace(v.Unit)
  889. if v.Unit == "" {
  890. br.Msg = "请输入单位"
  891. return
  892. }
  893. if v.ClassifyId <= 0 {
  894. br.Msg = "请选择分类"
  895. return
  896. }
  897. }
  898. // 限定同一时间最多批量新增30个指标
  899. for _, v := range req {
  900. var r data_manage.CCFIndexSource2EdbReq
  901. r.EdbCode = v.EdbCode
  902. r.EdbName = v.EdbName
  903. r.Frequency = v.Frequency
  904. r.Unit = v.Unit
  905. r.ClassifyId = v.ClassifyId
  906. r.AdminId = sysUser.AdminId
  907. r.AdminRealName = sysUser.RealName
  908. edbInfo, e, errMsg, skip := data.CCFIndexSource2Edb(r, this.Lang)
  909. if e != nil {
  910. br.Msg = "操作失败"
  911. if errMsg != "" {
  912. br.Msg = errMsg
  913. }
  914. br.ErrMsg = e.Error()
  915. return
  916. }
  917. if skip {
  918. continue
  919. }
  920. // 试用平台更新用户累计新增指标数
  921. if utils.BusinessCode == utils.BusinessCodeSandbox {
  922. go func() {
  923. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  924. if e != nil {
  925. tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
  926. utils.FileLog.Info(tips)
  927. return
  928. }
  929. if adminItem.DepartmentName != "ETA试用客户" {
  930. return
  931. }
  932. var ur etaTrialService.EtaTrialUserReq
  933. ur.Mobile = adminItem.Mobile
  934. _, _ = etaTrialService.UpdateUserIndexNum(ur)
  935. }()
  936. }
  937. // 新增操作日志
  938. {
  939. edbLog := new(data_manage.EdbInfoLog)
  940. edbLog.EdbInfoId = edbInfo.EdbInfoId
  941. edbLog.SourceName = edbInfo.SourceName
  942. edbLog.Source = edbInfo.Source
  943. edbLog.EdbCode = edbInfo.EdbCode
  944. edbLog.EdbName = edbInfo.EdbName
  945. edbLog.ClassifyId = edbInfo.ClassifyId
  946. edbLog.SysUserId = sysUser.AdminId
  947. edbLog.SysUserRealName = sysUser.RealName
  948. edbLog.CreateTime = time.Now()
  949. edbLog.Content = string(this.Ctx.Input.RequestBody)
  950. edbLog.Status = "新增指标"
  951. edbLog.Method = this.Ctx.Input.URI()
  952. go data_manage.AddEdbInfoLog(edbLog)
  953. }
  954. }
  955. br.Msg = "操作成功"
  956. br.Ret = 200
  957. br.Success = true
  958. br.IsAddLog = true
  959. }
  960. // CCFIndexNameCheck
  961. // @Title 加入指标库的重名检测
  962. // @Description 加入指标库的重名检测
  963. // @Param ClassifyIds query string true "分类id, 多个分类用英文"
  964. // @Param Keyword query string true "关键词, 指标ID/指标名称"
  965. // @Success 200 {object} NameCheckResult
  966. // @router /ccf/edb_info/name_check [post]
  967. func (this *EdbInfoController) CCFIndexNameCheck() {
  968. br := new(models.BaseResponse).Init()
  969. defer func() {
  970. if br.ErrMsg == "" {
  971. br.IsSendEmail = false
  972. }
  973. this.Data["json"] = br
  974. this.ServeJSON()
  975. }()
  976. sysUser := this.SysUser
  977. if sysUser == nil {
  978. br.Msg = "请登录"
  979. br.ErrMsg = "请登录,SysUser Is Empty"
  980. br.Ret = 408
  981. return
  982. }
  983. var req []*data_manage.NameCheckEdbInfoReq
  984. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  985. br.Msg = "参数解析异常!"
  986. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  987. return
  988. }
  989. if len(req) == 0 {
  990. br.Msg = "请选择指标"
  991. return
  992. }
  993. codeMaxT := 30
  994. codeLen := len(req)
  995. if codeLen > codeMaxT {
  996. br.Msg = "批量添加指标数量不得超过30个"
  997. return
  998. }
  999. indexNames := make([]string, 0)
  1000. resp := make([]*data_manage.EdbNameCheckResult, 0)
  1001. for _, v := range req {
  1002. v.EdbCode = strings.TrimSpace(v.EdbCode)
  1003. if v.EdbCode == "" {
  1004. br.Msg = "指标ID不可为空"
  1005. return
  1006. }
  1007. v.EdbName = strings.TrimSpace(v.EdbName)
  1008. if v.EdbName == "" {
  1009. br.Msg = "请输入指标名称"
  1010. return
  1011. }
  1012. indexNames = append(indexNames, v.EdbName)
  1013. resp = append(resp, &data_manage.EdbNameCheckResult{
  1014. EdbCode: v.EdbCode,
  1015. EdbName: v.EdbName,
  1016. })
  1017. dataItems, err := data_manage.GetEdbDataAllByEdbCode(v.EdbCode, utils.DATA_SOURCE_CCF, 0, utils.EDB_DATA_LIMIT)
  1018. if err != nil && err.Error() != utils.ErrNoRow() {
  1019. br.Msg = "获取失败"
  1020. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1021. return
  1022. }
  1023. if len(dataItems) <= 0 {
  1024. respItem, err := data.AddEdbData(utils.DATA_SOURCE_CCF, v.EdbCode, v.Frequency)
  1025. if err != nil {
  1026. br.Msg = "获取失败"
  1027. br.ErrMsg = "获取失败,Err:" + err.Error()
  1028. return
  1029. }
  1030. if respItem.Ret != 200 {
  1031. br.Msg = "未搜索到该指标"
  1032. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + v.EdbCode
  1033. return
  1034. }
  1035. }
  1036. }
  1037. // 重名校验
  1038. edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
  1039. if e != nil {
  1040. br.Msg = "操作失败"
  1041. br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
  1042. return
  1043. }
  1044. nameExists := make(map[string]bool)
  1045. for _, v := range edbList {
  1046. nameExists[v.EdbName] = true
  1047. }
  1048. if len(nameExists) > 0 {
  1049. for _, v := range resp {
  1050. v.Exist = nameExists[v.EdbName]
  1051. }
  1052. }
  1053. br.Data = resp
  1054. br.Msg = "校验成功"
  1055. br.Ret = 200
  1056. br.Success = true
  1057. }
  1058. // CCFAddCheck
  1059. // @Title 加入指标库指标Id检测
  1060. // @Description 加入指标库指标Id检测
  1061. // @Param request body request.BatchAddCheckReq true "type json string"
  1062. // @Success 200 string "操作成功"
  1063. // @router /ccf/edb_info/add_check [post]
  1064. func (c *EdbInfoController) CCFAddCheck() {
  1065. br := new(models.BaseResponse).Init()
  1066. defer func() {
  1067. if br.ErrMsg == "" {
  1068. br.IsSendEmail = false
  1069. }
  1070. c.Data["json"] = br
  1071. c.ServeJSON()
  1072. }()
  1073. sysUser := c.SysUser
  1074. if sysUser == nil {
  1075. br.Msg = "请登录"
  1076. br.ErrMsg = "请登录,SysUser Is Empty"
  1077. br.Ret = 408
  1078. return
  1079. }
  1080. var req data_manage.BatchAddCheckReq
  1081. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  1082. br.Msg = "参数解析异常!"
  1083. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1084. return
  1085. }
  1086. codeMaxT := 30
  1087. codeLen := len(req.IndexCodes)
  1088. // 获取指标库已有指标
  1089. existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_CCF)
  1090. if e != nil {
  1091. br.Msg = "获取失败"
  1092. br.ErrMsg = "获取自有数据已添加的指标失败, Err: " + e.Error()
  1093. return
  1094. }
  1095. existMap := make(map[string]*data_manage.EdbInfo)
  1096. for _, v := range existsEdb {
  1097. existMap[v.EdbCode] = v
  1098. }
  1099. if codeLen == 0 {
  1100. br.Msg = "请选择指标"
  1101. return
  1102. }
  1103. if codeLen > codeMaxT {
  1104. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMaxT)
  1105. return
  1106. }
  1107. // 查询选中的指标
  1108. cond := fmt.Sprintf(` AND index_code IN (%s)`, utils.GetOrmInReplace(codeLen))
  1109. pars := make([]interface{}, 0)
  1110. pars = append(pars, req.IndexCodes)
  1111. list, err := data_manage.GetCCFIndex(cond, pars)
  1112. if err != nil {
  1113. br.Msg = "获取失败"
  1114. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1115. return
  1116. }
  1117. if len(list) > codeMaxT {
  1118. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMaxT)
  1119. return
  1120. }
  1121. resp := make([]*data_manage.BaseFromCCFIndexList, 0)
  1122. for _, v := range list {
  1123. if edb, ok := existMap[v.IndexCode]; ok {
  1124. v.EdbInfoId = edb.EdbInfoId
  1125. // todo 验证下面三个字段的用处
  1126. //v.EdbClassifyId = edb.ClassifyId
  1127. //v.EdbUniqueCode = edb.UniqueCode
  1128. v.EdbExist = 1
  1129. }
  1130. resp = append(resp, v)
  1131. }
  1132. br.Data = resp
  1133. br.Msg = "校验成功"
  1134. br.Ret = 200
  1135. br.Success = true
  1136. }
  1137. // CCFEdbInfoAdd
  1138. // @Title 新增指标接口
  1139. // @Description 新增指标接口
  1140. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1141. // @Success Ret=200 保存成功
  1142. // @router /ccf/edb_info/add [post]
  1143. func (this *EdbInfoController) CCFEdbInfoAdd() {
  1144. br := new(models.BaseResponse).Init()
  1145. defer func() {
  1146. this.Data["json"] = br
  1147. this.ServeJSON()
  1148. }()
  1149. sysUser := this.SysUser
  1150. if sysUser == nil {
  1151. br.Msg = "请登录"
  1152. br.ErrMsg = "请登录,SysUser Is Empty"
  1153. br.Ret = 408
  1154. return
  1155. }
  1156. deleteCache := true
  1157. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  1158. defer func() {
  1159. if deleteCache {
  1160. utils.Rc.Delete(cacheKey)
  1161. }
  1162. }()
  1163. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1164. deleteCache = false
  1165. br.Msg = "系统处理中,请稍后重试!"
  1166. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1167. return
  1168. }
  1169. var req data_manage.AddEdbInfoReq
  1170. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1171. if err != nil {
  1172. br.Msg = "参数解析异常!"
  1173. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1174. return
  1175. }
  1176. req.EdbName = strings.Trim(req.EdbName, " ")
  1177. req.EdbCode = strings.Trim(req.EdbCode, " ")
  1178. if req.EdbCode == "" {
  1179. br.Msg = "指标ID不能为空"
  1180. return
  1181. }
  1182. if req.EdbName == "" {
  1183. br.Msg = "指标名称不能为空"
  1184. return
  1185. }
  1186. if req.Frequency == "" {
  1187. br.Msg = "频率不能为空"
  1188. return
  1189. }
  1190. if req.Unit == "" {
  1191. br.Msg = "单位不能为空"
  1192. return
  1193. }
  1194. if req.ClassifyId <= 0 {
  1195. br.Msg = "请选择分类"
  1196. return
  1197. }
  1198. count, err := data_manage.GetCCFIndexDataCount(req.EdbCode)
  1199. if err != nil {
  1200. br.Msg = "获取失败"
  1201. br.ErrMsg = "获取失败,Err:" + err.Error()
  1202. return
  1203. }
  1204. if count == 0 {
  1205. br.Msg = "指标不存在"
  1206. }
  1207. // 指标入库
  1208. 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)
  1209. if err != nil {
  1210. br.Msg = "保存失败"
  1211. if errMsg != `` {
  1212. br.Msg = errMsg
  1213. }
  1214. br.ErrMsg = err.Error()
  1215. br.IsSendEmail = isSendEmail
  1216. return
  1217. }
  1218. // 试用平台更新用户累计新增指标数
  1219. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  1220. if e != nil {
  1221. br.Msg = "操作失败"
  1222. br.ErrMsg = "获取系统用户数据失败,Err:" + e.Error()
  1223. return
  1224. }
  1225. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  1226. go func() {
  1227. var r etaTrialService.EtaTrialUserReq
  1228. r.Mobile = adminItem.Mobile
  1229. _, _ = etaTrialService.UpdateUserIndexNum(r)
  1230. }()
  1231. }
  1232. //新增操作日志
  1233. {
  1234. edbLog := new(data_manage.EdbInfoLog)
  1235. edbLog.EdbInfoId = edbInfo.EdbInfoId
  1236. edbLog.SourceName = edbInfo.SourceName
  1237. edbLog.Source = edbInfo.Source
  1238. edbLog.EdbCode = edbInfo.EdbCode
  1239. edbLog.EdbName = edbInfo.EdbName
  1240. edbLog.ClassifyId = edbInfo.ClassifyId
  1241. edbLog.SysUserId = sysUser.AdminId
  1242. edbLog.SysUserRealName = sysUser.RealName
  1243. edbLog.CreateTime = time.Now()
  1244. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1245. edbLog.Status = "新增指标"
  1246. edbLog.Method = this.Ctx.Input.URI()
  1247. go data_manage.AddEdbInfoLog(edbLog)
  1248. }
  1249. // 更新es
  1250. go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  1251. resp := new(data_manage.AddEdbInfoResp)
  1252. resp.EdbInfoId = edbInfo.EdbInfoId
  1253. resp.UniqueCode = edbInfo.UniqueCode
  1254. br.Ret = 200
  1255. br.Success = true
  1256. br.Msg = "保存成功"
  1257. br.Data = resp
  1258. br.IsAddLog = true
  1259. }
  1260. // GetFrequency
  1261. // @Title CCF化纤信息数据频度
  1262. // @Description CCF化纤信息数据频度接口
  1263. // @Param ClassifyId query string true "分类Id"
  1264. // @Success 200 {object} data_manage.LzFrequency
  1265. // @router /ccf/frequency [get]
  1266. func (this *EdbInfoController) GetCCFFrequency() {
  1267. br := new(models.BaseResponse).Init()
  1268. defer func() {
  1269. this.Data["json"] = br
  1270. this.ServeJSON()
  1271. }()
  1272. sysUser := this.SysUser
  1273. if sysUser == nil {
  1274. br.Msg = "请登录"
  1275. br.ErrMsg = "请登录,SysUser Is Empty"
  1276. br.Ret = 408
  1277. return
  1278. }
  1279. classifyId, _ := this.GetInt("ClassifyId")
  1280. if classifyId < 0 {
  1281. br.Msg = "请选择分类"
  1282. br.ErrMsg = "请选择分类"
  1283. return
  1284. }
  1285. frequencyList, err := data_manage.GetCCFFrequencyByClassifyId(classifyId)
  1286. if err != nil {
  1287. br.Msg = "获取频度失败"
  1288. br.ErrMsg = "获取频度失败,Err:" + err.Error()
  1289. return
  1290. }
  1291. br.Ret = 200
  1292. br.Success = true
  1293. br.Msg = "获取成功"
  1294. br.Data = frequencyList
  1295. }
  1296. // BatchAddEdbCheck
  1297. // @Title 新增校验
  1298. // @Description 新增校验
  1299. // @Param request body data_manage.BatchManualEdbReq true "type json string"
  1300. // @Success 200 string "操作成功"
  1301. // @router /ccf/batch/add/check [post]
  1302. func (c *EdbInfoController) BatchAddEdbCheck() {
  1303. br := new(models.BaseResponse).Init()
  1304. defer func() {
  1305. if br.ErrMsg == "" {
  1306. br.IsSendEmail = false
  1307. }
  1308. c.Data["json"] = br
  1309. c.ServeJSON()
  1310. }()
  1311. sysUser := c.SysUser
  1312. if sysUser == nil {
  1313. br.Msg = "请登录"
  1314. br.ErrMsg = "请登录,SysUser Is Empty"
  1315. br.Ret = 408
  1316. return
  1317. }
  1318. // 最大批量添加的数量
  1319. codeMaxT := 31
  1320. var req data_manage.BatchCheckCCFEdbReq
  1321. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1322. if err != nil {
  1323. br.Msg = "参数错误"
  1324. br.ErrMsg = "参数错误,Err:" + err.Error()
  1325. return
  1326. }
  1327. req.Keyword = strings.TrimSpace(req.Keyword)
  1328. classifyIdStr := req.ClassifyIds
  1329. var list = make([]*data_manage.BaseFromCCFIndexList, 0)
  1330. var condition string
  1331. var pars []interface{}
  1332. if req.ListAll {
  1333. classifyIds := strings.Split(classifyIdStr, ",")
  1334. if len(classifyIds) > 0 && classifyIds[0] != `` {
  1335. condition += " AND classify_id IN (" + utils.GetOrmInReplace(len(classifyIds)) + " ) "
  1336. pars = append(pars, classifyIds)
  1337. }
  1338. keyword := req.Keyword
  1339. if keyword != `` {
  1340. condition += " AND (index_name like ? OR index_code like ?) "
  1341. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1342. }
  1343. frequencies := req.Frequencies
  1344. if frequencies != "" {
  1345. frequencyList := strings.Split(frequencies, ",")
  1346. condition += " AND frequency IN (" + utils.GetOrmInReplace(len(frequencyList)) + " ) "
  1347. pars = append(pars, frequencyList)
  1348. }
  1349. codes := req.TradeCodeList
  1350. codeList := make([]string, 0)
  1351. if codes != "" {
  1352. codeList = strings.Split(codes, ",")
  1353. }
  1354. if len(codeList) > 0 {
  1355. condition += ` AND index_code not in (` + utils.GetOrmInReplace(len(codeList)) + `) `
  1356. pars = append(pars, codeList)
  1357. }
  1358. } else {
  1359. codes := req.TradeCodeList
  1360. codeList := make([]string, 0)
  1361. if codes != "" {
  1362. codeList = strings.Split(codes, ",")
  1363. }
  1364. if len(codeList) <= 0 {
  1365. br.Msg = "请选择指标"
  1366. br.ErrMsg = "请选择指标"
  1367. return
  1368. }
  1369. // 指标
  1370. condition += ` AND index_code in (` + utils.GetOrmInReplace(len(codeList)) + `) `
  1371. pars = append(pars, codeList)
  1372. }
  1373. condition += ` AND index_code not in (SELECT edb_code FROM edb_info WHERE source=?) `
  1374. pars = append(pars, utils.DATA_SOURCE_CCF)
  1375. list, err = data_manage.GetCCFIndexPage(condition, pars, 0, codeMaxT)
  1376. if err != nil {
  1377. br.Msg = "获取失败"
  1378. br.ErrMsg = "获取失败,Err:" + err.Error()
  1379. return
  1380. }
  1381. if len(list) >= codeMaxT {
  1382. br.Msg = "批量添加指标数量不得超过30个"
  1383. return
  1384. }
  1385. br.Data = list
  1386. br.Msg = "校验成功"
  1387. br.Ret = 200
  1388. br.Success = true
  1389. }