smm_data.go 31 KB

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