baiinfo_data.go 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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/data_manage/request"
  7. "eta/eta_api/services/alarm_msg"
  8. "eta/eta_api/services/data"
  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. "strings"
  16. "time"
  17. )
  18. // @Title 百川盈孚数据分类
  19. // @Description 百川盈孚数据分类接口
  20. // @Success 200 {object} data_manage.BaiinfoClassify
  21. // @router /baiinfo/classify [get]
  22. func (this *EdbInfoController) BaiinfoClassify() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sysUser := this.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. rootList, err := data_manage.GetBaseFromBaiinfoClassifyByParentId(0)
  36. if err != nil && err.Error() != utils.ErrNoRow() {
  37. br.Msg = "获取失败"
  38. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  39. return
  40. }
  41. classifyAll, err := data_manage.GetAllBaseFromBaiinfoClassify()
  42. if err != nil && err.Error() != utils.ErrNoRow() {
  43. br.Msg = "获取失败"
  44. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  45. return
  46. }
  47. baseFromBaiinfoIndexMap := make(map[int][]*data_manage.BaseFromBaiinfoClassifyItems)
  48. allBaseFromBaiinfoIndex, err := data_manage.GetBaiinfoIndexAll()
  49. if err != nil && err.Error() != utils.ErrNoRow() {
  50. br.Msg = "获取失败"
  51. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  52. return
  53. }
  54. for _, v := range allBaseFromBaiinfoIndex {
  55. baseFromBaiinfoIndexMap[v.ClassifyId] = append(baseFromBaiinfoIndexMap[v.ClassifyId], v)
  56. }
  57. rootChildMap := make(map[int][]*data_manage.BaseFromBaiinfoClassifyItems)
  58. for _, v := range classifyAll {
  59. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  60. if existItems, ok := baseFromBaiinfoIndexMap[v.ClassifyId]; ok {
  61. v.Children = existItems
  62. } else {
  63. items := make([]*data_manage.BaseFromBaiinfoClassifyItems, 0)
  64. v.Children = items
  65. }
  66. }
  67. var ret data_manage.BaseFromBaiinfoClassifyResp
  68. nodeAll := make([]*data_manage.BaseFromBaiinfoClassifyItems, 0)
  69. for _, v := range rootList {
  70. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  71. v.Children = existItems
  72. } else {
  73. items := make([]*data_manage.BaseFromBaiinfoClassifyItems, 0)
  74. v.Children = items
  75. }
  76. nodeAll = append(nodeAll, v)
  77. }
  78. //查询未分类的指标列表
  79. initClassify := &data_manage.BaseFromBaiinfoClassifyItems{
  80. ClassifyId: 0,
  81. BaseFromBaiinfoIndexId: 0,
  82. ClassifyName: "未分类",
  83. ClassifyNameEn: "Unclassified",
  84. ParentId: 0,
  85. Level: 1,
  86. Sort: 0,
  87. Children: nil,
  88. }
  89. initIndexList, err := data_manage.GetBaseFromBaiinfoIndexByClassifyId(initClassify.ClassifyId)
  90. if err != nil {
  91. br.Msg = "获取未分类指标失败"
  92. br.ErrMsg = "获取未分类指标失败,Err:" + err.Error()
  93. return
  94. }
  95. for _, v := range initIndexList {
  96. tmp := &data_manage.BaseFromBaiinfoClassifyItems{
  97. ClassifyId: v.ClassifyId,
  98. BaseFromBaiinfoIndexId: v.BaseFromBaiinfoIndexId,
  99. BaseFromBaiinfoIndexCode: v.IndexCode,
  100. ClassifyName: v.IndexName,
  101. ParentId: 0,
  102. Level: 0,
  103. Sort: 0,
  104. Children: nil,
  105. }
  106. initClassify.Children = append(initClassify.Children, tmp)
  107. }
  108. finalList := make([]*data_manage.BaseFromBaiinfoClassifyItems, 0)
  109. finalList = append(finalList, initClassify)
  110. finalList = append(finalList, nodeAll...)
  111. ret.List = finalList
  112. br.Ret = 200
  113. br.Success = true
  114. br.Msg = "获取成功"
  115. br.Data = ret
  116. }
  117. // BaiinfoClassifyName
  118. // @Title 百川盈孚数据分类名称查询
  119. // @Description 百川盈孚数据分类名称查询接口
  120. // @Success 200 {object} data_manage.BaiinfoClassify
  121. // @router /baiinfo/classify/name [get]
  122. func (this *EdbInfoController) BaiinfoClassifyName() {
  123. br := new(models.BaseResponse).Init()
  124. defer func() {
  125. this.Data["json"] = br
  126. this.ServeJSON()
  127. }()
  128. sysUser := this.SysUser
  129. if sysUser == nil {
  130. br.Msg = "请登录"
  131. br.ErrMsg = "请登录,SysUser Is Empty"
  132. br.Ret = 408
  133. return
  134. }
  135. rootList, err := data_manage.GetBaseFromBaiinfoClassifyByParentId(0)
  136. if err != nil && err.Error() != utils.ErrNoRow() {
  137. br.Msg = "获取失败"
  138. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  139. return
  140. }
  141. classifyAll, err := data_manage.GetAllBaseFromBaiinfoClassify()
  142. if err != nil && err.Error() != utils.ErrNoRow() {
  143. br.Msg = "获取失败"
  144. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  145. return
  146. }
  147. rootChildMap := make(map[int][]*data_manage.BaseFromBaiinfoClassifyNameItems)
  148. for _, v := range classifyAll {
  149. tmp := &data_manage.BaseFromBaiinfoClassifyNameItems{
  150. ClassifyId: v.ClassifyId,
  151. ClassifyName: v.ClassifyName,
  152. ParentId: v.ParentId,
  153. Children: nil,
  154. }
  155. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], tmp)
  156. }
  157. var ret data_manage.BaseFromBaiinfoClassifyNameResp
  158. nodeAll := make([]*data_manage.BaseFromBaiinfoClassifyNameItems, 0)
  159. for _, v := range rootList {
  160. tmp := &data_manage.BaseFromBaiinfoClassifyNameItems{
  161. ClassifyId: v.ClassifyId,
  162. ClassifyName: v.ClassifyName,
  163. ParentId: v.ParentId,
  164. Children: nil,
  165. }
  166. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  167. tmp.Children = existItems
  168. } else {
  169. items := make([]*data_manage.BaseFromBaiinfoClassifyNameItems, 0)
  170. tmp.Children = items
  171. }
  172. nodeAll = append(nodeAll, tmp)
  173. }
  174. ret.List = nodeAll
  175. br.Ret = 200
  176. br.Success = true
  177. br.Msg = "获取成功"
  178. br.Data = ret
  179. }
  180. // AddBaiinfoClassify
  181. // @Title 新增分类
  182. // @Description 新增分类接口
  183. // @Param request body data_manage.AddBaseFromBaiinfoClassifyReq true "type json string"
  184. // @Success 200 Ret=200 保存成功
  185. // @router /baiinfo/classify/add [post]
  186. func (this *EdbInfoController) AddBaiinfoClassify() {
  187. br := new(models.BaseResponse).Init()
  188. defer func() {
  189. this.Data["json"] = br
  190. this.ServeJSON()
  191. }()
  192. var req request.AddBaseFromBaiinfoClassifyReq
  193. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  194. if err != nil {
  195. br.Msg = "参数解析异常!"
  196. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  197. return
  198. }
  199. if req.ClassifyName == "" {
  200. br.Msg = "请输入分类名称"
  201. br.IsSendEmail = false
  202. return
  203. }
  204. req.ClassifyName = utils.TrimStr(req.ClassifyName)
  205. req.ClassifyName = strings.Replace(req.ClassifyName, "/t", "", -1)
  206. //添加指标
  207. baiinfoClassifyInfo, err, errMsg := data.AddBaiinfoClassify(req.ClassifyName, req.ParentId, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
  208. if errMsg != `` {
  209. br.Msg = errMsg
  210. br.ErrMsg = errMsg
  211. if err != nil {
  212. br.ErrMsg = errMsg + ";Err:" + err.Error()
  213. } else {
  214. br.IsSendEmail = false
  215. }
  216. return
  217. }
  218. // 如果是添加一级分类,那么默认加上 价格、供应、需求、库存 四个二级分类
  219. if baiinfoClassifyInfo.ParentId == 0 {
  220. secondClassifyList := []string{"价格", "供应", "需求", "库存"}
  221. for _, v := range secondClassifyList {
  222. _, _, tmpErrMsg := data.AddBaiinfoClassify(v, baiinfoClassifyInfo.ClassifyId, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
  223. if tmpErrMsg != `` {
  224. go alarm_msg.SendAlarmMsg("SCI原始数据-添加一级分类时,默认添加二级分类失败,一级分类名称:"+req.ClassifyName+",二级分类名称:"+v+", Err:"+tmpErrMsg, 3)
  225. return
  226. }
  227. }
  228. }
  229. resp := data_manage.AddBaiinfoClassifyResp{
  230. ClassifyId: baiinfoClassifyInfo.ClassifyId,
  231. //UniqueCode: fmt.Sprint(BaiinfoClassifyInfo.BaseFromBaiinfoClassifyId),
  232. }
  233. br.Data = resp
  234. br.Ret = 200
  235. br.Msg = "保存成功"
  236. br.Success = true
  237. br.IsAddLog = true
  238. }
  239. // EditBaiinfoClassify
  240. // @Title 修改分类
  241. // @Description 修改分类接口
  242. // @Param request body data_manage.EditBaseFromMysteelChemicalClassifyReq true "type json string"
  243. // @Success 200 Ret=200 修改成功
  244. // @router /baiinfo/classify/edit [post]
  245. func (this *EdbInfoController) EditBaiinfoClassify() {
  246. br := new(models.BaseResponse).Init()
  247. defer func() {
  248. this.Data["json"] = br
  249. this.ServeJSON()
  250. }()
  251. var req request.EditBaseFromBaiinfoClassifyReq
  252. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  253. if err != nil {
  254. br.Msg = "参数解析异常!"
  255. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  256. return
  257. }
  258. if req.ClassifyName == "" {
  259. br.Msg = "请输入分类名称"
  260. br.IsSendEmail = false
  261. return
  262. }
  263. if req.ClassifyId <= 0 {
  264. br.Msg = "参数错误"
  265. br.IsSendEmail = false
  266. return
  267. }
  268. err, errMsg := data.EditBaiinfoClassify(req.ClassifyId, req.ClassifyName, this.Lang, this.SysUser)
  269. if errMsg != `` {
  270. br.Msg = errMsg
  271. br.ErrMsg = errMsg
  272. if err != nil {
  273. br.ErrMsg = errMsg + ";Err:" + err.Error()
  274. } else {
  275. br.IsSendEmail = false
  276. }
  277. return
  278. }
  279. br.Ret = 200
  280. br.Msg = "保存成功"
  281. br.Success = true
  282. br.IsAddLog = true
  283. }
  284. // @Title 百川盈孚数据频度
  285. // @Description 百川盈孚数据频度接口
  286. // @Param ClassifyId query string true "分类Id"
  287. // @Success 200 {object} data_manage.LzFrequency
  288. // @router /baiinfo/frequency [get]
  289. func (this *EdbInfoController) BaiinfoFrequency() {
  290. br := new(models.BaseResponse).Init()
  291. defer func() {
  292. this.Data["json"] = br
  293. this.ServeJSON()
  294. }()
  295. sysUser := this.SysUser
  296. if sysUser == nil {
  297. br.Msg = "请登录"
  298. br.ErrMsg = "请登录,SysUser Is Empty"
  299. br.Ret = 408
  300. return
  301. }
  302. classifyId, _ := this.GetInt("ClassifyId")
  303. if classifyId < 0 {
  304. br.Msg = "请选择分类"
  305. br.ErrMsg = "请选择分类"
  306. return
  307. }
  308. frequencyList, err := data_manage.GetBaiinfoFrequencyByClassifyId(classifyId)
  309. if err != nil {
  310. br.Msg = "获取频度失败"
  311. br.ErrMsg = "获取频度失败,Err:" + err.Error()
  312. return
  313. }
  314. br.Ret = 200
  315. br.Success = true
  316. br.Msg = "获取成功"
  317. br.Data = frequencyList
  318. }
  319. // MoveBaiinfoClassify
  320. // @Title 分类移动接口
  321. // @Description 分类移动接口
  322. // @Success 200 {object} data_manage.MoveBaseFromMysteelChemicalClassifyReq
  323. // @router /baiinfo/classify/move [post]
  324. func (this *EdbInfoController) MoveBaiinfoClassify() {
  325. br := new(models.BaseResponse).Init()
  326. defer func() {
  327. this.Data["json"] = br
  328. this.ServeJSON()
  329. }()
  330. sysUser := this.SysUser
  331. if sysUser == nil {
  332. br.Msg = "请登录"
  333. br.ErrMsg = "请登录,SysUser Is Empty"
  334. br.Ret = 408
  335. return
  336. }
  337. var req request.MoveBaseFromBaiinfoClassifyReq
  338. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  339. if err != nil {
  340. br.Msg = "参数解析异常!"
  341. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  342. return
  343. }
  344. if req.ClassifyId <= 0 {
  345. br.Msg = "参数错误"
  346. br.ErrMsg = "分类id小于等于0"
  347. br.IsSendEmail = false
  348. return
  349. }
  350. err, errMsg := data.MoveBaiinfoClassify(req.ClassifyId, req.ParentId, req.PrevClassifyId, req.NextClassifyId)
  351. if errMsg != `` {
  352. br.Msg = errMsg
  353. br.ErrMsg = errMsg
  354. if err != nil {
  355. br.ErrMsg = err.Error()
  356. } else {
  357. br.IsSendEmail = false
  358. }
  359. return
  360. }
  361. br.Ret = 200
  362. br.Success = true
  363. br.IsAddLog = true
  364. br.Msg = "移动成功"
  365. }
  366. // DeleteBaiinfoClassify
  367. // @Title 删除分类
  368. // @Description 删除分类接口
  369. // @Param request body data_manage.DelBaseFromBaiinfoClassifyReq true "type json string"
  370. // @Success 200 Ret=200 删除成功
  371. // @router /baiinfo/classify/del [post]
  372. func (this *EdbInfoController) DeleteBaiinfoClassify() {
  373. br := new(models.BaseResponse).Init()
  374. defer func() {
  375. this.Data["json"] = br
  376. this.ServeJSON()
  377. }()
  378. var req request.DelBaseFromBaiinfoClassifyReq
  379. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  380. if err != nil {
  381. br.Msg = "参数解析异常!"
  382. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  383. return
  384. }
  385. if req.ClassifyId < 0 {
  386. br.Msg = "参数错误"
  387. br.IsSendEmail = false
  388. return
  389. }
  390. err, errMsg := data.DelBaiinfoClassify(req.ClassifyId, this.SysUser)
  391. if errMsg != `` {
  392. br.Msg = errMsg
  393. br.ErrMsg = errMsg
  394. if err != nil {
  395. br.ErrMsg = errMsg + ";Err:" + err.Error()
  396. } else {
  397. br.IsSendEmail = false
  398. }
  399. return
  400. }
  401. br.Ret = 200
  402. br.Msg = "删除成功"
  403. br.Success = true
  404. br.IsAddLog = true
  405. }
  406. // MoveBaiinfoData
  407. // @Title SCI指标移动接口
  408. // @Description SCI指标移动接口
  409. // @Success 200 {object} data_manage.MoveBaseFromBaiinfoReq
  410. // @router /baiinfo/move [post]
  411. func (this *EdbInfoController) MoveBaiinfoData() {
  412. br := new(models.BaseResponse).Init()
  413. defer func() {
  414. this.Data["json"] = br
  415. this.ServeJSON()
  416. }()
  417. sysUser := this.SysUser
  418. if sysUser == nil {
  419. br.Msg = "请登录"
  420. br.ErrMsg = "请登录,SysUser Is Empty"
  421. br.Ret = 408
  422. return
  423. }
  424. var req request.MoveBaseFromBaiinfoReq
  425. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  426. if err != nil {
  427. br.Msg = "参数解析异常!"
  428. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  429. return
  430. }
  431. if req.BaseFromBaiinfoIndexId <= 0 {
  432. br.Msg = "参数错误"
  433. br.ErrMsg = "指标id小于等于0"
  434. br.IsSendEmail = false
  435. return
  436. }
  437. if req.ClassifyId < 0 {
  438. br.Msg = "请选择分类"
  439. br.ErrMsg = "请选择分类"
  440. br.IsSendEmail = false
  441. return
  442. }
  443. err, errMsg := data.MoveBaiinfoData2(req.BaseFromBaiinfoIndexId, req.ClassifyId, req.PrevBaseFromBaiinfoIndexId, req.NextBaseFromBaiinfoIndexId)
  444. if errMsg != `` {
  445. br.Msg = errMsg
  446. br.ErrMsg = errMsg
  447. if err != nil {
  448. br.ErrMsg = err.Error()
  449. } else {
  450. br.IsSendEmail = false
  451. }
  452. return
  453. }
  454. br.Ret = 200
  455. br.Success = true
  456. br.IsAddLog = true
  457. br.Msg = "移动成功"
  458. }
  459. // EditBaiinfo
  460. // @Title 编辑百川盈孚指标
  461. // @Description 编辑百川盈孚指标接口
  462. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  463. // @Success 200 Ret=200 保存成功
  464. // @router /baiinfo/edit [post]
  465. func (this *EdbInfoController) EditBaiinfo() {
  466. br := new(models.BaseResponse).Init()
  467. defer func() {
  468. this.Data["json"] = br
  469. this.ServeJSON()
  470. }()
  471. var req request.EditBaseFromBaiinfoReq
  472. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  473. if err != nil {
  474. br.Msg = "参数解析异常!"
  475. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  476. return
  477. }
  478. if req.BaseFromBaiinfoIndexId <= 0 {
  479. br.Msg = "请选择指标"
  480. br.IsSendEmail = false
  481. return
  482. }
  483. if req.ClassifyId < 0 {
  484. br.Msg = "请选择分类"
  485. br.IsSendEmail = false
  486. return
  487. }
  488. //百川数据可能没有频度和单位
  489. //if req.Frequency == "" {
  490. // br.Msg = "请输入频度名称"
  491. // br.IsSendEmail = false
  492. // return
  493. //}
  494. //
  495. //if req.Unit == "" {
  496. // br.Msg = "请输入单位名称"
  497. // br.IsSendEmail = false
  498. // return
  499. //}
  500. //编辑指标
  501. baiinfoIndexInfo, err, errMsg := data.EditBaiinfoIndex(req.BaseFromBaiinfoIndexId, req.ClassifyId, req.Frequency, req.Unit, this.SysUser)
  502. if errMsg != `` {
  503. br.Msg = errMsg
  504. br.ErrMsg = errMsg
  505. if err != nil {
  506. br.ErrMsg = errMsg + ";Err:" + err.Error()
  507. } else {
  508. br.IsSendEmail = false
  509. }
  510. return
  511. }
  512. resp := data_manage.EditBaiinfoIndexInfoResp{
  513. BaseFromBaiinfoIndexId: baiinfoIndexInfo.BaseFromBaiinfoIndexId,
  514. IndexCode: baiinfoIndexInfo.IndexCode,
  515. }
  516. br.Data = resp
  517. br.Ret = 200
  518. br.Msg = "保存成功"
  519. br.Success = true
  520. br.IsAddLog = true
  521. }
  522. // @Title 获取钢联数据
  523. // @Description 获取钢联数据接口
  524. // @Param PageSize query int true "每页数据条数"
  525. // @Param CurrentIndex query int true "当前页页码,从1开始"
  526. // @Param ClassifyId query string true "分类id"
  527. // @Param Frequency query string true "频度名称"
  528. // @Success 200 {object} data_manage.LzFrequency
  529. // @router /baiinfo/data [get]
  530. func (this *EdbInfoController) BaiinfoData() {
  531. br := new(models.BaseResponse).Init()
  532. defer func() {
  533. this.Data["json"] = br
  534. this.ServeJSON()
  535. }()
  536. sysUser := this.SysUser
  537. if sysUser == nil {
  538. br.Msg = "请登录"
  539. br.ErrMsg = "请登录,SysUser Is Empty"
  540. br.Ret = 408
  541. return
  542. }
  543. pageSize, _ := this.GetInt("PageSize")
  544. currentIndex, _ := this.GetInt("CurrentIndex")
  545. var startSize int
  546. if pageSize <= 0 {
  547. pageSize = utils.PageSize20
  548. }
  549. if currentIndex <= 0 {
  550. currentIndex = 1
  551. }
  552. startSize = utils.StartIndex(currentIndex, pageSize)
  553. classifyId, _ := this.GetInt("ClassifyId")
  554. if classifyId < 0 {
  555. br.Msg = "请选择分类"
  556. br.ErrMsg = "请选择分类"
  557. return
  558. }
  559. frequency := this.GetString("Frequency")
  560. //if frequency == "" {
  561. // br.Msg = "请选择频度"
  562. // br.ErrMsg = "请选择频度"
  563. // return
  564. //}
  565. //获取指标
  566. var condition string
  567. var pars []interface{}
  568. if classifyId >= 0 {
  569. condition += ` AND classify_id=? `
  570. pars = append(pars, classifyId)
  571. }
  572. if frequency != "" {
  573. condition += ` AND frequency=? `
  574. pars = append(pars, frequency)
  575. }
  576. baiinfoList, err := data_manage.GetBaiinfoIndex(condition, pars)
  577. if err != nil {
  578. br.Msg = "获取数据失败"
  579. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  580. return
  581. }
  582. resultList := make([]*data_manage.BaiinfoIndexList, 0)
  583. for _, v := range baiinfoList {
  584. product := new(data_manage.BaiinfoIndexList)
  585. product.BaseFromBaiinfoIndexId = v.BaseFromBaiinfoIndexId
  586. product.Unit = v.Unit
  587. product.IndexCode = v.IndexCode
  588. product.IndexName = v.IndexName
  589. product.Frequency = v.Frequency
  590. product.ModifyTime = v.ModifyTime
  591. total, err := data_manage.GetBaiinfoIndexDataCount(v.IndexCode)
  592. page := paging.GetPaging(currentIndex, pageSize, total)
  593. dataList, err := data_manage.GetBaiinfoIndexData(v.IndexCode, startSize, pageSize)
  594. if err != nil {
  595. br.Msg = "获取数据失败"
  596. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  597. return
  598. }
  599. if dataList == nil {
  600. dataList = make([]*data_manage.BaiinfoIndexData, 0)
  601. }
  602. product.DataList = dataList
  603. product.Paging = page
  604. resultList = append(resultList, product)
  605. }
  606. br.Ret = 200
  607. br.Success = true
  608. br.Msg = "获取成功"
  609. br.Data = resultList
  610. }
  611. // BaiinfoSearchList
  612. // @Title SCI模糊搜索
  613. // @Description SCI模糊搜索
  614. // @Param Keyword query string ture "关键字搜索"
  615. // @Success 200 {object} models.BaseResponse
  616. // @router /baiinfo/search_list [get]
  617. func (this *EdbInfoController) BaiinfoSearchList() {
  618. br := new(models.BaseResponse).Init()
  619. defer func() {
  620. this.Data["json"] = br
  621. this.ServeJSON()
  622. }()
  623. sysUser := this.SysUser
  624. if sysUser == nil {
  625. br.Msg = "请重新登录"
  626. return
  627. }
  628. //关键字
  629. keyword := this.GetString("Keyword")
  630. list, err := data_manage.GetBaiinfoItemList(keyword)
  631. if err != nil {
  632. br.ErrMsg = "获取失败,Err:" + err.Error()
  633. br.Msg = "获取失败"
  634. return
  635. }
  636. br.Ret = 200
  637. br.Success = true
  638. br.Msg = "获取成功"
  639. br.Data = list
  640. }
  641. // BaiinfoSingleData
  642. // @Title 获取Baiinfo数据
  643. // @Description 获取baiinfo单条数据接口
  644. // @Param IndexCode query string true "指标唯一编码"
  645. // @Success 200 {object} models.BaseResponse
  646. // @router /baiinfo/single_data [get]
  647. func (this *EdbInfoController) BaiinfoSingleData() {
  648. br := new(models.BaseResponse).Init()
  649. defer func() {
  650. this.Data["json"] = br
  651. this.ServeJSON()
  652. }()
  653. sysUser := this.SysUser
  654. if sysUser == nil {
  655. br.Msg = "请登录"
  656. br.ErrMsg = "请登录,SysUser Is Empty"
  657. br.Ret = 408
  658. return
  659. }
  660. indexCode := this.GetString("IndexCode")
  661. indexInfo, err := data_manage.GetBaseFromBaiinfoIndexByIndexCode(indexCode)
  662. if err != nil {
  663. br.Msg = "获取指标信息失败"
  664. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  665. return
  666. }
  667. dataList, err := data_manage.GetBaiinfoIndexDataByCode(indexCode)
  668. if err != nil {
  669. br.Msg = "获取数据失败"
  670. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  671. return
  672. }
  673. var ret data_manage.BaiinfoSingleDataResp
  674. ret.ClassifyId = indexInfo.ClassifyId
  675. ret.BaseFromBaiinfoIndexId = indexInfo.BaseFromBaiinfoIndexId
  676. ret.IndexCode = indexInfo.IndexCode
  677. ret.IndexName = indexInfo.IndexName
  678. ret.Frequency = indexInfo.Frequency
  679. ret.Interface = indexInfo.Interface
  680. ret.CreateTime = indexInfo.CreateTime.Format(utils.FormatDateTime)
  681. ret.ModifyTime = indexInfo.ModifyTime.Format(utils.FormatDateTime)
  682. ret.Unit = indexInfo.Unit
  683. ret.Data = dataList
  684. br.Ret = 200
  685. br.Success = true
  686. br.Msg = "获取成功"
  687. br.Data = ret
  688. }
  689. // DeleteBaiinfoData
  690. // @Title 删除指标
  691. // @Description 删除指标接口
  692. // @Param request body data_manage.DelBaseFromBaiinfoReq true "type json string"
  693. // @Success 200 Ret=200 删除成功
  694. // @router /baiinfo/del [post]
  695. func (this *EdbInfoController) DeleteBaiinfoData() {
  696. br := new(models.BaseResponse).Init()
  697. defer func() {
  698. this.Data["json"] = br
  699. this.ServeJSON()
  700. }()
  701. var req request.DelBaseFromBaiinfoReq
  702. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  703. if err != nil {
  704. br.Msg = "参数解析异常!"
  705. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  706. return
  707. }
  708. if req.BaseFromBaiinfoIndexId < 0 {
  709. br.Msg = "参数错误"
  710. br.IsSendEmail = false
  711. return
  712. }
  713. err, errMsg := data.DelBaiinfoData(req.BaseFromBaiinfoIndexId)
  714. if errMsg != `` {
  715. br.Msg = errMsg
  716. br.ErrMsg = errMsg
  717. if err != nil {
  718. br.ErrMsg = errMsg + ";Err:" + err.Error()
  719. } else {
  720. br.IsSendEmail = false
  721. }
  722. return
  723. }
  724. br.Ret = 200
  725. br.Msg = "删除成功"
  726. br.Success = true
  727. br.IsAddLog = true
  728. }
  729. // ResetBaiinfoData
  730. // @Title 指标数据清除分类
  731. // @Description 指标数据清除分类
  732. // @Param request body data_manage.DelBaseFromBaiinfoReq true "type json string"
  733. // @Success 200 Ret=200 操作成功
  734. // @router /baiinfo/reset [post]
  735. func (this *EdbInfoController) ResetBaiinfoData() {
  736. br := new(models.BaseResponse).Init()
  737. defer func() {
  738. this.Data["json"] = br
  739. this.ServeJSON()
  740. }()
  741. var req request.DelBaseFromBaiinfoReq
  742. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  743. if err != nil {
  744. br.Msg = "参数解析异常!"
  745. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  746. return
  747. }
  748. if req.BaseFromBaiinfoIndexId < 0 {
  749. br.Msg = "参数错误"
  750. br.IsSendEmail = false
  751. return
  752. }
  753. err, errMsg := data.ResetBaiinfoData(req.BaseFromBaiinfoIndexId)
  754. if errMsg != `` {
  755. br.Msg = errMsg
  756. br.ErrMsg = errMsg
  757. if err != nil {
  758. br.ErrMsg = errMsg + ";Err:" + err.Error()
  759. } else {
  760. br.IsSendEmail = false
  761. }
  762. return
  763. }
  764. br.Ret = 200
  765. br.Msg = "操作成功"
  766. br.Success = true
  767. br.IsAddLog = true
  768. }
  769. // ExportBaiinfoList
  770. // @Title 导出Baiinfo数据
  771. // @Description 导出Baiinfo数据
  772. // @Param IndexName query string false "名称关键词"
  773. // @Param IndexCode query string false "指标唯一编码"
  774. // @Param ClassifyId query string true "分类"
  775. // @Param Frequency query string true "频度"
  776. // @Param UnitName query string false "单位"
  777. // @Param ModifyTime query string false "更新时间"
  778. // @Success 200 导出成功
  779. // @router /export/baiinfoList [get]
  780. func (this *EdbInfoController) ExportBaiinfoList() {
  781. br := new(models.BaseResponse).Init()
  782. defer func() {
  783. this.Data["json"] = br
  784. this.ServeJSON()
  785. }()
  786. sysUser := this.SysUser
  787. if sysUser == nil {
  788. br.Msg = "请重新登录"
  789. return
  790. }
  791. //typeName := this.GetString("TypeName") //分类
  792. //frequency := this.GetString("Frequency")
  793. indexCode := this.GetString("IndexCode") //指标唯一编码
  794. classifyId, _ := this.GetInt("ClassifyId")
  795. secNameList := make([]*models.EdbdataExportList, 0)
  796. dir, _ := os.Executable()
  797. exPath := filepath.Dir(dir)
  798. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  799. xlsxFile := xlsx.NewFile()
  800. if classifyId >= 0 && indexCode == "" {
  801. frequencies, err := data_manage.GetBaiinfoFrequency(classifyId)
  802. if err != nil {
  803. fmt.Println("GetBaiinfoFrequency err:", err.Error())
  804. utils.FileLog.Info("GetBaiinfoFrequency err:" + err.Error())
  805. return
  806. }
  807. for _, frequency := range frequencies {
  808. //获取指标
  809. var pars []interface{}
  810. pars = append(pars, classifyId)
  811. pars = append(pars, frequency)
  812. condition := " AND classify_id=? AND frequency=? "
  813. secNameList, err := data_manage.GetBaiinfoIndex(condition, pars)
  814. if err != nil {
  815. fmt.Println("获取数据失败,Err:" + err.Error())
  816. return
  817. }
  818. if len(secNameList) <= 0 {
  819. fmt.Println("secNameList长度为0")
  820. return
  821. }
  822. var sheetNew *xlsx.Sheet
  823. if *frequency == "" {
  824. newFrequency := "无频度"
  825. sheetNew, err = xlsxFile.AddSheet(newFrequency)
  826. } else {
  827. sheetNew, err = xlsxFile.AddSheet(*frequency)
  828. }
  829. if err != nil {
  830. fmt.Println("新增Sheet失败", err.Error())
  831. return
  832. }
  833. //sheetNew.SetColWidth()
  834. //获取指标数据
  835. windRow := sheetNew.AddRow()
  836. secNameRow := sheetNew.AddRow()
  837. indexCodeRow := sheetNew.AddRow()
  838. frequencyRow := sheetNew.AddRow()
  839. unitRow := sheetNew.AddRow()
  840. lastModifyDateRow := sheetNew.AddRow()
  841. //获取分类下指标最大数据量
  842. dataMax, err := data_manage.GetBaiinfoDataMaxCount(classifyId)
  843. if err != nil {
  844. fmt.Println("获取指标最大数据量失败", err.Error())
  845. return
  846. }
  847. fmt.Println("dataMax:", dataMax)
  848. setRowIndex := 6
  849. for k, sv := range secNameList {
  850. //获取数据
  851. dataList, err := data_manage.GetBaiinfoIndexDataByCode(sv.IndexCode)
  852. if err != nil {
  853. br.Msg = "获取数据失败"
  854. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  855. return
  856. }
  857. if len(dataList) > 0 {
  858. windRow.AddCell().SetValue("Baiinfo")
  859. secNameRow.AddCell().SetValue("指标名称")
  860. indexCodeRow.AddCell().SetValue("指标ID")
  861. frequencyRow.AddCell().SetValue("频率")
  862. unitRow.AddCell().SetValue("单位")
  863. lastModifyDateRow.AddCell().SetValue("更新时间")
  864. secNameRow.AddCell().SetValue(sv.IndexName)
  865. indexCodeRow.AddCell().SetValue(sv.IndexCode)
  866. frequencyRow.AddCell().SetValue(sv.Frequency)
  867. unitRow.AddCell().SetValue(sv.Unit)
  868. lastModifyDateRow.AddCell().SetValue(sv.ModifyTime)
  869. windRow.AddCell()
  870. windRow.AddCell()
  871. secNameRow.AddCell()
  872. indexCodeRow.AddCell()
  873. frequencyRow.AddCell()
  874. unitRow.AddCell()
  875. lastModifyDateRow.AddCell()
  876. min := k * 3
  877. sheetNew.SetColWidth(min, min, 15)
  878. if len(dataList) <= 0 {
  879. for n := 0; n < dataMax; n++ {
  880. rowIndex := setRowIndex + n
  881. row := sheetNew.Row(rowIndex)
  882. row.AddCell()
  883. row.AddCell()
  884. row.AddCell()
  885. }
  886. } else {
  887. endRowIndex := 0
  888. for rk, dv := range dataList {
  889. rowIndex := setRowIndex + rk
  890. row := sheetNew.Row(rowIndex)
  891. displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
  892. displayDateCell := row.AddCell()
  893. style := new(xlsx.Style)
  894. style.ApplyAlignment = true
  895. style.Alignment.WrapText = true
  896. displayDateCell.SetStyle(style)
  897. displayDateCell.SetDate(displayDate)
  898. row.AddCell().SetValue(dv.Value)
  899. row.AddCell()
  900. endRowIndex = rowIndex
  901. }
  902. if len(dataList) < dataMax {
  903. dataLen := dataMax - len(dataList)
  904. for n := 0; n < dataLen; n++ {
  905. rowIndex := (endRowIndex + 1) + n
  906. row := sheetNew.Row(rowIndex)
  907. row.AddCell()
  908. row.AddCell()
  909. row.AddCell()
  910. }
  911. }
  912. }
  913. }
  914. }
  915. }
  916. } else {
  917. frequencies, err := data_manage.GetBaiinfoFrequencyByCode(indexCode)
  918. if err != nil {
  919. fmt.Println("GetBaiinfoFrequencyByCode err:", err.Error())
  920. utils.FileLog.Info("GetBaiinfoFrequencyByCode err:" + err.Error())
  921. return
  922. }
  923. for _, frequency := range frequencies {
  924. //获取数据
  925. dataList, err := data_manage.GetBaiinfoIndexDataByCode(indexCode)
  926. if err != nil {
  927. br.Msg = "获取数据失败"
  928. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  929. return
  930. }
  931. if len(dataList) > 0 {
  932. name := this.GetString("IndexName")
  933. unit := this.GetString("UnitName")
  934. modifyTime := this.GetString("ModifyTime")
  935. var sheet *xlsx.Sheet
  936. if *frequency == "" {
  937. newFrequency := "无频度"
  938. sheet, err = xlsxFile.AddSheet(newFrequency)
  939. } else {
  940. sheet, err = xlsxFile.AddSheet(*frequency)
  941. }
  942. if err != nil {
  943. br.Msg = "新增Sheet失败"
  944. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  945. return
  946. }
  947. //获取指标数据
  948. windRow := sheet.AddRow()
  949. windRow.AddCell().SetValue("Baiinfo")
  950. rowSecName := sheet.AddRow()
  951. celSecName := rowSecName.AddCell()
  952. celSecName.SetValue("指标名称")
  953. cellSenName := rowSecName.AddCell()
  954. cellSenName.SetValue(name)
  955. indexCodeRow := sheet.AddRow()
  956. indexCodeRow.AddCell().SetValue("指标ID")
  957. indexCodeRow.AddCell().SetValue(indexCode)
  958. rowFrequency := sheet.AddRow()
  959. celFrequency := rowFrequency.AddCell()
  960. celFrequency.SetValue("频率")
  961. cellFrequency := rowFrequency.AddCell()
  962. cellFrequency.SetValue(*frequency)
  963. rowUnit := sheet.AddRow()
  964. celUnit := rowUnit.AddCell()
  965. celUnit.SetValue("单位")
  966. cellUnit := rowUnit.AddCell()
  967. cellUnit.SetValue(unit)
  968. rowModifyDate := sheet.AddRow()
  969. rowModifyCell := rowModifyDate.AddCell()
  970. rowModifyCell.SetValue("更新时间")
  971. rowModifyCell = rowModifyDate.AddCell()
  972. rowModifyCell.SetValue(modifyTime)
  973. dataMax, err := data_manage.GetBaiinfoIndexDataCount(indexCode)
  974. if err != nil {
  975. br.Msg = "查询数量失败"
  976. br.ErrMsg = "GetBaiinfoIndexDataCount,Err:" + err.Error()
  977. return
  978. }
  979. if len(dataList) <= 0 {
  980. for n := 0; n < dataMax; n++ {
  981. rowIndex := 6 + n
  982. row := sheet.Row(rowIndex)
  983. row.AddCell()
  984. row.AddCell()
  985. row.AddCell()
  986. }
  987. } else {
  988. endRowIndex := 0
  989. for rk, dv := range dataList {
  990. rowIndex := 6 + rk
  991. row := sheet.Row(rowIndex)
  992. displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
  993. displayDateCell := row.AddCell()
  994. style := new(xlsx.Style)
  995. style.ApplyAlignment = true
  996. style.Alignment.WrapText = true
  997. displayDateCell.SetStyle(style)
  998. displayDateCell.SetDate(displayDate)
  999. row.AddCell().SetValue(dv.Value)
  1000. row.AddCell()
  1001. endRowIndex = rowIndex
  1002. }
  1003. if len(dataList) < dataMax {
  1004. dataLen := dataMax - len(dataList)
  1005. for n := 0; n < dataLen; n++ {
  1006. rowIndex := (endRowIndex + 1) + n
  1007. row := sheet.Row(rowIndex)
  1008. row.AddCell()
  1009. row.AddCell()
  1010. row.AddCell()
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. err := xlsxFile.Save(downLoadnFilePath)
  1018. if err != nil {
  1019. //有指标无数据时先导出一遍空表
  1020. sheet, err := xlsxFile.AddSheet("无数据")
  1021. if err != nil {
  1022. br.Msg = "新增Sheet失败"
  1023. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1024. return
  1025. }
  1026. rowSecName := sheet.AddRow()
  1027. celSecName := rowSecName.AddCell()
  1028. celSecName.SetValue("")
  1029. err = xlsxFile.Save(downLoadnFilePath)
  1030. if err != nil {
  1031. br.Msg = "保存文件失败"
  1032. br.ErrMsg = "保存文件失败"
  1033. return
  1034. }
  1035. }
  1036. fileName := `Baiinfo数据`
  1037. if len(secNameList) > 0 {
  1038. fileName = secNameList[0].ClassifyName
  1039. }
  1040. fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
  1041. this.Ctx.Output.Download(downLoadnFilePath, fileName)
  1042. defer func() {
  1043. os.Remove(downLoadnFilePath)
  1044. }()
  1045. br.Ret = 200
  1046. br.Success = true
  1047. br.Msg = "success"
  1048. }