baiinfo_data.go 30 KB

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