edb_source_stat.go 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. package data_stat
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/data_stat"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. "strings"
  12. "time"
  13. )
  14. // EdbSourceStatController 数据源统计表管理模块
  15. type EdbSourceStatController struct {
  16. controllers.BaseAuthController
  17. }
  18. // Column
  19. // @Title 数据源统计表自定义列列表
  20. // @Description 查询 数据源统计表自定义列列表
  21. // @Success 200 {object} data_stat.StatColumnList
  22. // @router /source_column [get]
  23. func (this *EdbSourceStatController) Column() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. br.Ret = 408
  34. return
  35. }
  36. columnType, _ := this.GetInt("ColumnType")
  37. if columnType <= 0 {
  38. br.Msg = "请选择表类型"
  39. return
  40. }
  41. tmpList, err := data_stat.GetStatColumn(columnType)
  42. if err != nil {
  43. br.Msg = "获取自定义列失败"
  44. br.ErrMsg = "获取自定义列失败,Err:" + err.Error()
  45. return
  46. }
  47. var list []*data_stat.EdbInfoStatColumnListItem
  48. for _, v := range tmpList {
  49. tmp := new(data_stat.EdbInfoStatColumnListItem)
  50. tmp.ColumnKey = v.ColumnKey
  51. tmp.IsShow = v.IsShow
  52. tmp.ColumnName = v.ColumnName
  53. tmp.ColumnNameEn = v.ColumnNameEn
  54. tmp.Id = v.Id
  55. tmp.IsMust = v.IsMust
  56. tmp.IsSort = v.IsSort
  57. tmp.Type = v.Type
  58. list = append(list, tmp)
  59. }
  60. var statColumnList data_stat.StatColumnList
  61. statColumnList.List = list
  62. br.Ret = 200
  63. br.Success = true
  64. br.Msg = "获取成功"
  65. br.Data = statColumnList
  66. }
  67. // EditColumn
  68. // @Title 编辑数据源统计表自定义列
  69. // @Description 编辑 数据源统计表自定义列列表
  70. // @Success 200 {object} data_stat.StatColumnList
  71. // @router /source_column/edit [post]
  72. func (this *EdbSourceStatController) EditColumn() {
  73. br := new(models.BaseResponse).Init()
  74. defer func() {
  75. this.Data["json"] = br
  76. this.ServeJSON()
  77. }()
  78. sysUser := this.SysUser
  79. if sysUser == nil {
  80. br.Msg = "请登录"
  81. br.ErrMsg = "请登录,SysUser Is Empty"
  82. br.Ret = 408
  83. return
  84. }
  85. var req data_stat.EditStatColumnReq
  86. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  87. if err != nil {
  88. br.Msg = "参数解析异常!"
  89. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  90. return
  91. }
  92. if len(req.List) <= 0 {
  93. br.Msg = "请选择要修改的列"
  94. br.IsSendEmail = false
  95. return
  96. }
  97. tmpList, err := data_stat.GetAllStatColumn()
  98. if err != nil {
  99. br.Msg = "获取自定义列失败"
  100. br.ErrMsg = "获取自定义列失败,Err:" + err.Error()
  101. return
  102. }
  103. isMustMap := make(map[int]data_stat.EdbInfoStatColumn)
  104. if len(tmpList) > 0 {
  105. for _, v := range tmpList {
  106. if v.IsMust == 1 {
  107. isMustMap[v.Id] = v
  108. }
  109. }
  110. }
  111. var list []*data_stat.EdbInfoStatColumn
  112. for k, v := range req.List {
  113. if v.Id == 0 {
  114. br.Msg = "列序号不能为空"
  115. return
  116. }
  117. if v.IsShow == 0 {
  118. if exist, ok := isMustMap[v.Id]; ok {
  119. br.Msg = exist.ColumnName + "为必选列!"
  120. return
  121. }
  122. }
  123. tmp := new(data_stat.EdbInfoStatColumn)
  124. tmp.Id = v.Id
  125. tmp.Sort = k + 1
  126. tmp.IsShow = v.IsShow
  127. list = append(list, tmp)
  128. }
  129. err = data_stat.UpdateStatColumn(list)
  130. if err != nil {
  131. br.Msg = "更新自定义列操作失败!"
  132. br.ErrMsg = "更新自定义列操作失败,Err:" + err.Error()
  133. return
  134. }
  135. br.Ret = 200
  136. br.Success = true
  137. br.Msg = "获取成功"
  138. return
  139. }
  140. // EdbDeleteLog
  141. // @Title 查询删除指标列表
  142. // @Description 查询删除指标列表接口
  143. // @Success 200 {object} data_stat.GetEdbDeleteLogResp
  144. // @router /edb_delete_log [get]
  145. func (this *EdbSourceStatController) EdbDeleteLog() {
  146. br := new(models.BaseResponse).Init()
  147. defer func() {
  148. this.Data["json"] = br
  149. this.ServeJSON()
  150. }()
  151. sysUser := this.SysUser
  152. if sysUser == nil {
  153. br.Msg = "请登录"
  154. br.ErrMsg = "请登录,SysUser Is Empty"
  155. br.Ret = 408
  156. return
  157. }
  158. sortParamReq := this.GetString("SortParam", "")
  159. sortType := this.GetString("SortType", "desc")
  160. createTime := this.GetString("CreateTime", "")
  161. pageSize, _ := this.GetInt("PageSize")
  162. currentIndex, _ := this.GetInt("CurrentIndex")
  163. var startSize int
  164. if pageSize <= 0 {
  165. pageSize = utils.PageSize20
  166. }
  167. if currentIndex <= 0 {
  168. currentIndex = 1
  169. }
  170. startSize = paging.StartIndex(currentIndex, pageSize)
  171. condition := " and source = ?"
  172. var pars []interface{}
  173. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  174. if createTime != "" {
  175. startT, err := time.ParseInLocation(utils.FormatDate, createTime, time.Local)
  176. if err != nil {
  177. br.Msg = "请求时间格式错误"
  178. return
  179. }
  180. endT := startT.AddDate(0, 0, 1)
  181. condition += " AND create_time >= ? AND create_time < ?"
  182. pars = append(pars, createTime, endT.Format(utils.FormatDate))
  183. }
  184. sortStr := ``
  185. sortParam := ``
  186. if sortParamReq != `` {
  187. switch sortParamReq {
  188. case "CreateTime":
  189. sortParam = "create_time"
  190. case "DataUpdateTime":
  191. sortParam = "data_update_time"
  192. case "ErDataUpdateDate":
  193. sortParam = "er_data_update_date"
  194. case "LatestDate":
  195. sortParam = "latest_date"
  196. case "StartDate":
  197. sortParam = "start_date"
  198. }
  199. if sortParam == "" {
  200. br.Msg = "请输入正确的排序字段"
  201. return
  202. }
  203. if strings.ToLower(sortType) != "asc" && strings.ToLower(sortType) != "desc" {
  204. br.Msg = "请输入正确的排序类型"
  205. return
  206. }
  207. sortStr = fmt.Sprintf(" order by %s %s, id desc ", sortParam, sortType)
  208. }
  209. total, err := data_stat.GetEdbDeleteLogCount(condition, pars)
  210. if err != nil {
  211. if err.Error() != utils.ErrNoRow() {
  212. br.Msg = "获取指标删除列表总数失败"
  213. br.ErrMsg = "获取指标删除列表总数失败,Err:" + err.Error()
  214. return
  215. } else {
  216. err = nil
  217. }
  218. }
  219. list := make([]*data_stat.EdbInfoDeleteLogItem, 0)
  220. page := paging.GetPaging(currentIndex, pageSize, total)
  221. if total == 0 {
  222. resp := data_stat.GetEdbDeleteLogResp{
  223. Paging: page,
  224. List: list,
  225. }
  226. br.Ret = 200
  227. br.Success = true
  228. br.Msg = "获取成功"
  229. br.Data = resp
  230. return
  231. }
  232. tmpList, err := data_stat.GetEdbDeleteLogByCondition(condition, pars, sortStr, pageSize, startSize)
  233. if err != nil {
  234. br.Msg = "获取指标删除列表失败"
  235. br.ErrMsg = "获取指标删除列表失败,Err:" + err.Error()
  236. return
  237. }
  238. for _, v := range tmpList {
  239. tmp := new(data_stat.EdbInfoDeleteLogItem)
  240. tmp.EdbCode = v.EdbCode
  241. tmp.EdbInfoId = v.EdbInfoId
  242. tmp.Id = v.Id
  243. tmp.StartDate = v.StartDate
  244. tmp.EndDate = v.EndDate
  245. tmp.Unit = v.Unit
  246. tmp.TerminalCode = v.TerminalCode
  247. tmp.CreateTime = v.CreateTime
  248. tmp.EdbCreateTime = v.EdbCreateTime
  249. tmp.Frequency = v.Frequency
  250. tmp.Source = v.Source
  251. tmp.SourceName = v.SourceName
  252. tmp.EdbName = v.EdbName
  253. tmp.EdbNameEn = v.EdbNameEn
  254. tmp.EdbNameSource = v.EdbNameSource
  255. tmp.LatestDate = v.LatestDate
  256. tmp.DelSysUserId = v.DelSysUserId
  257. tmp.DelSysUserRealName = v.DelSysUserRealName
  258. tmp.SysUserId = v.SysUserId
  259. tmp.SysUserRealName = v.SysUserRealName
  260. tmp.LatestValue = v.LatestValue
  261. if v.DataUpdateTime != utils.EmptyDateTimeStr {
  262. tmp.DataUpdateTime = v.DataUpdateTime
  263. }
  264. if v.ErDataUpdateDate != utils.EmptyDateStr {
  265. tmp.ErDataUpdateDate = v.ErDataUpdateDate
  266. }
  267. list = append(list, tmp)
  268. }
  269. resp := data_stat.GetEdbDeleteLogResp{
  270. Paging: page,
  271. List: list,
  272. }
  273. br.Ret = 200
  274. br.Success = true
  275. br.Msg = "获取成功"
  276. br.Data = resp
  277. }
  278. // EdbUpdateLog
  279. // @Title 查询指标信息变更列表
  280. // @Description 查询指标信息变更列表接口
  281. // @Success 200 {object} data_stat.GetEdbUpdateLogResp
  282. // @router /edb_update_log [get]
  283. func (this *EdbSourceStatController) EdbUpdateLog() {
  284. br := new(models.BaseResponse).Init()
  285. defer func() {
  286. this.Data["json"] = br
  287. this.ServeJSON()
  288. }()
  289. sysUser := this.SysUser
  290. if sysUser == nil {
  291. br.Msg = "请登录"
  292. br.ErrMsg = "请登录,SysUser Is Empty"
  293. br.Ret = 408
  294. return
  295. }
  296. sortParamReq := this.GetString("SortParam", "")
  297. sortType := this.GetString("SortType", "desc")
  298. createTime := this.GetString("CreateTime", "")
  299. updateType, _ := this.GetInt("UpdateType", -1)
  300. pageSize, _ := this.GetInt("PageSize")
  301. currentIndex, _ := this.GetInt("CurrentIndex")
  302. var startSize int
  303. if pageSize <= 0 {
  304. pageSize = utils.PageSize20
  305. }
  306. if currentIndex <= 0 {
  307. currentIndex = 1
  308. }
  309. startSize = paging.StartIndex(currentIndex, pageSize)
  310. condition := " and source = ? and (data_update_result=1 or data_update_result=0)"
  311. var pars []interface{}
  312. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  313. if createTime != "" {
  314. startT, err := time.ParseInLocation(utils.FormatDate, createTime, time.Local)
  315. if err != nil {
  316. br.Msg = "请求时间格式错误"
  317. return
  318. }
  319. endT := startT.AddDate(0, 0, 1)
  320. condition += " AND create_time >= ? AND create_time < ?"
  321. pars = append(pars, createTime, endT.Format(utils.FormatDate))
  322. }
  323. if updateType >= 0 {
  324. condition += " AND update_type =? "
  325. pars = append(pars, updateType)
  326. }
  327. sortStr := ``
  328. sortParam := ``
  329. if sortParamReq != `` {
  330. switch sortParamReq {
  331. case "CreateTime":
  332. sortParam = "create_time"
  333. case "DataUpdateTime":
  334. sortParam = "data_update_time"
  335. case "ErDataUpdateDate":
  336. sortParam = "er_data_update_date"
  337. case "LatestDate":
  338. sortParam = "latest_date"
  339. case "StartDate":
  340. sortParam = "start_date"
  341. }
  342. if sortParam == "" {
  343. br.Msg = "请输入正确的排序字段"
  344. return
  345. }
  346. if strings.ToLower(sortType) != "asc" && strings.ToLower(sortType) != "desc" {
  347. br.Msg = "请输入正确的排序类型"
  348. return
  349. }
  350. sortStr = fmt.Sprintf(" order by %s %s, id desc ", sortParam, sortType)
  351. }
  352. total, err := data_stat.GetEdbUpdateLogCount(condition, pars)
  353. if err != nil {
  354. if err.Error() != utils.ErrNoRow() {
  355. br.Msg = "获取指标删除列表总数失败"
  356. br.ErrMsg = "获取指标删除列表总数失败,Err:" + err.Error()
  357. return
  358. } else {
  359. err = nil
  360. }
  361. }
  362. list := make([]*data_stat.EdbInfoUpdateLogItem, 0)
  363. page := paging.GetPaging(currentIndex, pageSize, total)
  364. if total == 0 {
  365. resp := data_stat.GetEdbUpdateLogResp{
  366. Paging: page,
  367. List: list,
  368. }
  369. br.Ret = 200
  370. br.Success = true
  371. br.Msg = "获取成功"
  372. br.Data = resp
  373. return
  374. }
  375. tmpList, err := data_stat.GetEdbUpdateLogByCondition(condition, pars, sortStr, pageSize, startSize)
  376. if err != nil {
  377. br.Msg = "获取指标更新列表失败"
  378. br.ErrMsg = "获取指标更新列表失败,Err:" + err.Error()
  379. return
  380. }
  381. for _, v := range tmpList {
  382. tmp := new(data_stat.EdbInfoUpdateLogItem)
  383. tmp.Id = v.Id
  384. tmp.EdbInfoId = v.EdbInfoId
  385. tmp.SourceName = v.SourceName
  386. tmp.Source = v.Source
  387. tmp.EdbCode = v.EdbCode
  388. tmp.EdbName = v.EdbName
  389. tmp.EdbNameSource = v.EdbNameSource
  390. tmp.Frequency = v.Frequency
  391. tmp.Unit = v.Unit
  392. tmp.StartDate = v.StartDate
  393. tmp.EndDate = v.EndDate
  394. tmp.SysUserId = v.SysUserId
  395. tmp.SysUserRealName = v.SysUserRealName
  396. tmp.UpdateSysUserRealName = v.UpdateSysUserRealName
  397. tmp.UpdateSysUserId = v.UpdateSysUserId
  398. tmp.UniqueCode = v.UniqueCode
  399. tmp.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  400. tmp.LatestDate = v.LatestDate
  401. tmp.LatestValue = v.LatestValue
  402. tmp.TerminalCode = v.TerminalCode
  403. if v.DataUpdateTime != utils.EmptyDateTimeStr {
  404. tmp.DataUpdateTime = v.DataUpdateTime
  405. }
  406. if v.ErDataUpdateDate != utils.EmptyDateStr {
  407. tmp.ErDataUpdateDate = v.ErDataUpdateDate
  408. }
  409. tmp.UpdateType = v.UpdateType
  410. list = append(list, tmp)
  411. }
  412. resp := data_stat.GetEdbUpdateLogResp{
  413. Paging: page,
  414. List: list,
  415. }
  416. br.Ret = 200
  417. br.Success = true
  418. br.Msg = "获取成功"
  419. br.Data = resp
  420. }
  421. // EdbUpdateStat
  422. // @Title 查询数据源明细列表
  423. // @Description 查询数据源明细列表接口
  424. // @Success 200 {object} data_stat.GetEdbUpdateStatResp
  425. // @router /edb_update_stat [get]
  426. func (this *EdbSourceStatController) EdbUpdateStat() {
  427. br := new(models.BaseResponse).Init()
  428. defer func() {
  429. this.Data["json"] = br
  430. this.ServeJSON()
  431. }()
  432. sysUser := this.SysUser
  433. if sysUser == nil {
  434. br.Msg = "请登录"
  435. br.ErrMsg = "请登录,SysUser Is Empty"
  436. br.Ret = 408
  437. return
  438. }
  439. sortParamReq := this.GetString("SortParam", "")
  440. sortType := this.GetString("SortType", "desc")
  441. terminalCode := this.GetString("TerminalCode", "")
  442. sysUserId := this.GetString("SysUserId", "")
  443. frequency := this.GetString("Frequency", "")
  444. keyWord := this.GetString("KeyWord", "") //指标编码/指标名称
  445. createTime := this.GetString("CreateTime", "")
  446. pageSize, _ := this.GetInt("PageSize")
  447. currentIndex, _ := this.GetInt("CurrentIndex")
  448. var startSize int
  449. if pageSize <= 0 {
  450. pageSize = utils.PageSize20
  451. }
  452. if currentIndex <= 0 {
  453. currentIndex = 1
  454. }
  455. startSize = paging.StartIndex(currentIndex, pageSize)
  456. condition := " and source = ?"
  457. var pars []interface{}
  458. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  459. if createTime != "" {
  460. startT, err := time.ParseInLocation(utils.FormatDate, createTime, time.Local)
  461. if err != nil {
  462. br.Msg = "请求时间格式错误"
  463. return
  464. }
  465. endT := startT.AddDate(0, 0, 1)
  466. condition += " AND create_time >= ? AND create_time < ?"
  467. pars = append(pars, createTime, endT.Format(utils.FormatDate))
  468. }
  469. if terminalCode != "" {
  470. codeSlice := strings.Split(terminalCode, ",")
  471. condition += ` AND terminal_code IN (` + utils.GetOrmInReplace(len(codeSlice)) + `)`
  472. pars = append(pars, codeSlice)
  473. }
  474. if sysUserId != "" {
  475. sysUserIdSlice := strings.Split(sysUserId, ",")
  476. condition += ` AND sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)`
  477. pars = append(pars, sysUserIdSlice)
  478. }
  479. if frequency != "" {
  480. frequencySlice := strings.Split(frequency, ",")
  481. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
  482. pars = append(pars, frequencySlice)
  483. }
  484. if keyWord != "" {
  485. condition += ` AND (edb_name LIKE ? OR edb_code LIKE ? ) `
  486. pars = append(pars, "%"+keyWord+"%", "%"+keyWord+"%")
  487. }
  488. sortStr := ``
  489. sortParam := ``
  490. if sortParamReq != `` {
  491. switch sortParamReq {
  492. case "CreateTime":
  493. sortParam = "create_time"
  494. case "UpdateTime":
  495. sortParam = "update_time"
  496. case "DataUpdateTime":
  497. sortParam = "data_update_time"
  498. case "ErDataUpdateDate":
  499. sortParam = "er_data_update_date"
  500. case "LatestDate":
  501. sortParam = "latest_date"
  502. case "StartDate":
  503. sortParam = "start_date"
  504. }
  505. if sortParam == "" {
  506. br.Msg = "请输入正确的排序字段"
  507. return
  508. }
  509. if strings.ToLower(sortType) != "asc" && strings.ToLower(sortType) != "desc" {
  510. br.Msg = "请输入正确的排序类型"
  511. return
  512. }
  513. sortStr = fmt.Sprintf(" order by %s %s, id desc ", sortParam, sortType)
  514. }
  515. total, err := data_stat.GetEdbUpdateStatCount(condition, pars)
  516. if err != nil {
  517. if err.Error() != utils.ErrNoRow() {
  518. br.Msg = "获取指标列表总数失败"
  519. br.ErrMsg = "获取指标列表总数失败,Err:" + err.Error()
  520. return
  521. } else {
  522. err = nil
  523. }
  524. }
  525. list := make([]*data_stat.EdbInfoUpdateStatItemMore, 0)
  526. page := paging.GetPaging(currentIndex, pageSize, total)
  527. if total == 0 {
  528. resp := data_stat.GetEdbUpdateStatResp{
  529. Paging: page,
  530. List: list,
  531. }
  532. br.Ret = 200
  533. br.Success = true
  534. br.Msg = "获取成功"
  535. br.Data = resp
  536. return
  537. }
  538. tmpList, err := data_stat.GetEdbUpdateStatByCondition(condition, pars, sortStr, pageSize, startSize)
  539. if err != nil {
  540. br.Msg = "获取指标更新列表失败"
  541. br.ErrMsg = "获取指标更新列表失败,Err:" + err.Error()
  542. return
  543. }
  544. // 获取初始数据源名称
  545. var edbCodeList []string
  546. for _, v := range tmpList {
  547. edbCodeList = append(edbCodeList, v.EdbCode)
  548. }
  549. initSourceMap := make(map[string]string)
  550. if len(edbCodeList) > 0 {
  551. baseCond := " and index_code in (" + utils.GetOrmInReplace(len(edbCodeList)) + ")"
  552. var basePars []interface{}
  553. basePars = append(basePars, edbCodeList)
  554. indexList, tErr := data_manage.GetMysteelChemicalIndexList(baseCond, basePars, 0, 1000, "")
  555. if tErr != nil {
  556. br.Msg = "获取初始指标信息失败"
  557. br.ErrMsg = "获取初始指标信息失败,Err:" + tErr.Error()
  558. return
  559. }
  560. for _, v := range indexList {
  561. initSourceMap[v.IndexCode] = v.Source
  562. }
  563. }
  564. for _, v := range tmpList {
  565. tmp := new(data_stat.EdbInfoUpdateStatItemMore)
  566. tmp.Id = v.Id
  567. tmp.EdbInfoId = v.EdbInfoId
  568. tmp.SourceName = v.SourceName
  569. tmp.Source = v.Source
  570. tmp.EdbCode = v.EdbCode
  571. tmp.EdbName = v.EdbName
  572. tmp.EdbNameSource = v.EdbNameSource
  573. tmp.Frequency = v.Frequency
  574. tmp.Unit = v.Unit
  575. tmp.StartDate = v.StartDate
  576. tmp.SysUserId = v.SysUserId
  577. tmp.SysUserRealName = v.SysUserRealName
  578. tmp.LatestDate = v.LatestDate
  579. tmp.LatestValue = v.LatestValue
  580. tmp.TerminalCode = v.TerminalCode
  581. if v.DataUpdateTime != utils.EmptyDateTimeStr {
  582. tmp.DataUpdateTime = v.DataUpdateTime
  583. }
  584. if v.ErDataUpdateDate != utils.EmptyDateStr {
  585. tmp.ErDataUpdateDate = v.ErDataUpdateDate
  586. }
  587. tmp.DataUpdateResult = v.DataUpdateResult
  588. tmp.DataUpdateFailedReason = v.DataUpdateFailedReason
  589. if v.UpdateTime != utils.EmptyDateTimeStr {
  590. tmp.UpdateTime = v.UpdateTime
  591. }
  592. tmp.IsAdd = v.IsAdd
  593. tmp.NeedRefresh = v.NeedRefresh
  594. tmp.HasRefresh = v.HasRefresh
  595. tmp.InitSourceName, _ = initSourceMap[v.EdbCode]
  596. list = append(list, tmp)
  597. }
  598. resp := data_stat.GetEdbUpdateStatResp{
  599. Paging: page,
  600. List: list,
  601. }
  602. br.Ret = 200
  603. br.Success = true
  604. br.Msg = "获取成功"
  605. br.Data = resp
  606. }
  607. // EdbSourceStat
  608. // @Title 查询数据源统计列表
  609. // @Description 查询数据源统计列表接口
  610. // @Success 200 {object} data_stat.GetEdbUpdateLogResp
  611. // @router /source_stat [get]
  612. func (this *EdbSourceStatController) EdbSourceStat() {
  613. br := new(models.BaseResponse).Init()
  614. defer func() {
  615. this.Data["json"] = br
  616. this.ServeJSON()
  617. }()
  618. sysUser := this.SysUser
  619. if sysUser == nil {
  620. br.Msg = "请登录"
  621. br.ErrMsg = "请登录,SysUser Is Empty"
  622. br.Ret = 408
  623. return
  624. }
  625. sortParamReq := this.GetString("SortParam", "")
  626. sortType := this.GetString("SortType", "desc")
  627. createTime := this.GetString("CreateTime", "")
  628. pageSize, _ := this.GetInt("PageSize")
  629. currentIndex, _ := this.GetInt("CurrentIndex")
  630. var startSize int
  631. if pageSize <= 0 {
  632. pageSize = utils.PageSize20
  633. }
  634. if currentIndex <= 0 {
  635. currentIndex = 1
  636. }
  637. startSize = paging.StartIndex(currentIndex, pageSize)
  638. condition := " and source = ?"
  639. var pars []interface{}
  640. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  641. if createTime != "" {
  642. startT, err := time.ParseInLocation(utils.FormatDate, createTime, time.Local)
  643. if err != nil {
  644. br.Msg = "请求时间格式错误"
  645. return
  646. }
  647. endT := startT.AddDate(0, 0, 1)
  648. condition += " AND create_time >= ? AND create_time < ?"
  649. pars = append(pars, createTime, endT.Format(utils.FormatDate))
  650. }
  651. sortStr := ``
  652. sortParam := ``
  653. if sortParamReq != `` {
  654. switch sortParamReq {
  655. case "EdbNum":
  656. sortParam = "edb_num"
  657. case "NeedRefreshNum":
  658. sortParam = "need_refresh_num"
  659. case "hasRefreshNum":
  660. sortParam = "has_refresh_num"
  661. case "UpdateSuccessNum":
  662. sortParam = "update_success_num"
  663. case "UpdateFailedNum":
  664. sortParam = "update_failed_num"
  665. }
  666. if sortParam == "" {
  667. br.Msg = "请输入正确的排序字段"
  668. return
  669. }
  670. if strings.ToLower(sortType) != "asc" && strings.ToLower(sortType) != "desc" {
  671. br.Msg = "请输入正确的排序类型"
  672. return
  673. }
  674. sortStr = fmt.Sprintf(" order by %s %s, id desc ", sortParam, sortType)
  675. }
  676. total, err := data_stat.GetEdbSourceStatCount(condition, pars)
  677. if err != nil {
  678. if err.Error() != utils.ErrNoRow() {
  679. br.Msg = "获取数据源统计列表总数失败"
  680. br.ErrMsg = "获取数据源统计列表总数失败,Err:" + err.Error()
  681. return
  682. } else {
  683. err = nil
  684. }
  685. }
  686. list := make([]*data_stat.EdbInfoSourceStatItem, 0)
  687. page := paging.GetPaging(currentIndex, pageSize, total)
  688. if total == 0 {
  689. resp := data_stat.GetEdbSourceStatResp{
  690. Paging: page,
  691. List: list,
  692. }
  693. br.Ret = 200
  694. br.Success = true
  695. br.Msg = "获取成功"
  696. br.Data = resp
  697. return
  698. }
  699. tmpList, err := data_stat.GetEdbSourceStatByCondition(condition, pars, sortStr, pageSize, startSize)
  700. if err != nil {
  701. br.Msg = "获取指标删除列表失败"
  702. br.ErrMsg = "获取指标删除列表失败,Err:" + err.Error()
  703. return
  704. }
  705. for _, v := range tmpList {
  706. tmp := new(data_stat.EdbInfoSourceStatItem)
  707. tmp.Id = v.Id
  708. tmp.SourceName = v.SourceName
  709. tmp.Source = v.Source
  710. tmp.TerminalCode = v.TerminalCode
  711. tmp.EdbNum = v.EdbNum
  712. tmp.EdbNewNum = v.EdbNewNum
  713. tmp.EdbDelNum = v.EdbDelNum
  714. tmp.NeedRefreshNum = v.NeedRefreshNum
  715. tmp.HasRefreshNum = v.HasRefreshNum
  716. tmp.UpdateSuccessNum = v.UpdateSuccessNum
  717. tmp.UpdateFailedNum = v.UpdateFailedNum
  718. tmp.RefreshSuccessNum = v.RefreshSuccessNum
  719. tmp.RefreshFailedNum = v.RefreshFailedNum
  720. list = append(list, tmp)
  721. }
  722. resp := data_stat.GetEdbSourceStatResp{
  723. Paging: page,
  724. List: list,
  725. }
  726. br.Ret = 200
  727. br.Success = true
  728. br.Msg = "获取成功"
  729. br.Data = resp
  730. }
  731. // EdbUpdateFailedList
  732. // @Title 查询指标更新失败详情汇总列表
  733. // @Description 查询指标更新失败详情汇总列表
  734. // @Success 200 {object} data_stat.GetEdbUpdateLogResp
  735. // @router /edb_update_stat/failed [get]
  736. func (this *EdbSourceStatController) EdbUpdateFailedList() {
  737. br := new(models.BaseResponse).Init()
  738. defer func() {
  739. this.Data["json"] = br
  740. this.ServeJSON()
  741. }()
  742. sysUser := this.SysUser
  743. if sysUser == nil {
  744. br.Msg = "请登录"
  745. br.ErrMsg = "请登录,SysUser Is Empty"
  746. br.Ret = 408
  747. return
  748. }
  749. terminalCode := this.GetString("TerminalCode", "")
  750. createTime := this.GetString("CreateTime", "")
  751. if terminalCode == "" {
  752. br.Msg = "请选择对应的终端信息"
  753. return
  754. }
  755. terminalInfo, err := data_manage.GetEdbTerminalByTerminalCode(terminalCode)
  756. if err != nil {
  757. if err.Error() == utils.ErrNoRow() {
  758. br.Msg = "终端不存在"
  759. return
  760. }
  761. br.Msg = "查询终端信息出错"
  762. br.ErrMsg = "查询终端信息出错 Err:" + err.Error()
  763. return
  764. }
  765. condition := " and source = ? and terminal_code = ?"
  766. var pars []interface{}
  767. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, terminalCode)
  768. if createTime != "" {
  769. startT, err := time.ParseInLocation(utils.FormatDate, createTime, time.Local)
  770. if err != nil {
  771. br.Msg = "请求时间格式错误"
  772. return
  773. }
  774. endT := startT.AddDate(0, 0, 1)
  775. condition += " AND create_time >= ? AND create_time < ?"
  776. pars = append(pars, createTime, endT.Format(utils.FormatDate))
  777. }
  778. tmpList, err := data_stat.GetEdbUpdateStatFailedGroupByCondition(condition, pars)
  779. if err != nil {
  780. br.Msg = "获取指标更新失败详情列表 失败"
  781. br.ErrMsg = "获取指标更新失败详情列表 失败,Err:" + err.Error()
  782. return
  783. }
  784. list := make([]*data_stat.EdbUpdateFailedList, 0)
  785. successNum := 0
  786. failedNum := 0
  787. if len(tmpList) > 0 {
  788. for _, v := range tmpList {
  789. if v.SourceUpdateResult == 1 {
  790. successNum += v.Num
  791. } else {
  792. failedNum += v.Num
  793. list = append(list, v)
  794. }
  795. }
  796. }
  797. resp := data_stat.GetEdbUpdateFailedResp{
  798. List: list,
  799. Name: terminalInfo.Name,
  800. TerminalCode: terminalCode,
  801. DirPath: terminalInfo.DirPath,
  802. UpdateSuccessNum: successNum,
  803. UpdateFailedNum: failedNum,
  804. }
  805. br.Ret = 200
  806. br.Success = true
  807. br.Msg = "获取成功"
  808. br.Data = resp
  809. }
  810. // EdbUpdateFailedDetailList
  811. // @Title 查询指标更新失败详情列表
  812. // @Description 查询指标更新失败详情列表
  813. // @Success 200 {object} data_stat.GetEdbUpdateLogResp
  814. // @router /edb_update_stat/failed/detail [get]
  815. func (this *EdbSourceStatController) EdbUpdateFailedDetailList() {
  816. br := new(models.BaseResponse).Init()
  817. defer func() {
  818. this.Data["json"] = br
  819. this.ServeJSON()
  820. }()
  821. sysUser := this.SysUser
  822. if sysUser == nil {
  823. br.Msg = "请登录"
  824. br.ErrMsg = "请登录,SysUser Is Empty"
  825. br.Ret = 408
  826. return
  827. }
  828. pageSize, _ := this.GetInt("PageSize")
  829. currentIndex, _ := this.GetInt("CurrentIndex")
  830. var startSize int
  831. if pageSize <= 0 {
  832. pageSize = utils.PageSize20
  833. }
  834. if currentIndex <= 0 {
  835. currentIndex = 1
  836. }
  837. startSize = paging.StartIndex(currentIndex, pageSize)
  838. terminalCode := this.GetString("TerminalCode", "")
  839. createTime := this.GetString("CreateTime", "")
  840. frequency := this.GetString("Frequency", "")
  841. sourceUpdateFailedReason := this.GetString("SourceUpdateFailedReason", "")
  842. if createTime == "" {
  843. br.Msg = "请选择创建时间"
  844. return
  845. }
  846. if terminalCode == "" {
  847. br.Msg = "请选择对应的终端信息"
  848. return
  849. }
  850. if frequency == "" {
  851. br.Msg = "请选择对应的频度"
  852. return
  853. }
  854. condition := " and source = ? and terminal_code = ? and frequency=? and data_update_failed_reason=? and data_update_result = 2"
  855. var pars []interface{}
  856. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, terminalCode, frequency, sourceUpdateFailedReason)
  857. if createTime != "" {
  858. startT, err := time.ParseInLocation(utils.FormatDate, createTime, time.Local)
  859. if err != nil {
  860. br.Msg = "请求时间格式错误"
  861. return
  862. }
  863. endT := startT.AddDate(0, 0, 1)
  864. condition += " AND create_time >= ? AND create_time < ?"
  865. pars = append(pars, createTime, endT.Format(utils.FormatDate))
  866. }
  867. total, err := data_stat.GetEdbUpdateStatCount(condition, pars)
  868. if err != nil {
  869. if err.Error() != utils.ErrNoRow() {
  870. br.Msg = "获取指标列表总数失败"
  871. br.ErrMsg = "获取指标列表总数失败,Err:" + err.Error()
  872. return
  873. } else {
  874. err = nil
  875. }
  876. }
  877. list := make([]*data_stat.EdbInfoUpdateStatItemMore, 0)
  878. page := paging.GetPaging(currentIndex, pageSize, total)
  879. if total == 0 {
  880. resp := data_stat.GetEdbUpdateStatResp{
  881. Paging: page,
  882. List: list,
  883. }
  884. br.Ret = 200
  885. br.Success = true
  886. br.Msg = "获取成功"
  887. br.Data = resp
  888. return
  889. }
  890. tmpList, err := data_stat.GetEdbUpdateStatByCondition(condition, pars, "", pageSize, startSize)
  891. if err != nil {
  892. br.Msg = "获取指标更新列表失败"
  893. br.ErrMsg = "获取指标更新列表失败,Err:" + err.Error()
  894. return
  895. }
  896. for _, v := range tmpList {
  897. tmp := new(data_stat.EdbInfoUpdateStatItemMore)
  898. tmp.Id = v.Id
  899. tmp.EdbInfoId = v.EdbInfoId
  900. tmp.SourceName = v.SourceName
  901. tmp.Source = v.Source
  902. tmp.EdbCode = v.EdbCode
  903. tmp.EdbName = v.EdbName
  904. tmp.EdbNameSource = v.EdbNameSource
  905. tmp.Frequency = v.Frequency
  906. tmp.Unit = v.Unit
  907. tmp.StartDate = v.StartDate
  908. tmp.SysUserId = v.SysUserId
  909. tmp.SysUserRealName = v.SysUserRealName
  910. tmp.LatestDate = v.LatestDate
  911. tmp.LatestValue = v.LatestValue
  912. tmp.TerminalCode = v.TerminalCode
  913. tmp.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  914. if v.DataUpdateTime != utils.EmptyDateTimeStr {
  915. tmp.DataUpdateTime = v.DataUpdateTime
  916. }
  917. if v.ErDataUpdateDate != utils.EmptyDateStr {
  918. tmp.ErDataUpdateDate = v.ErDataUpdateDate
  919. }
  920. tmp.DataUpdateResult = v.DataUpdateResult
  921. tmp.DataUpdateFailedReason = v.DataUpdateFailedReason
  922. if v.UpdateTime != utils.EmptyDateTimeStr {
  923. tmp.UpdateTime = v.UpdateTime
  924. }
  925. tmp.IsAdd = v.IsAdd
  926. tmp.NeedRefresh = v.NeedRefresh
  927. tmp.HasRefresh = v.HasRefresh
  928. list = append(list, tmp)
  929. }
  930. resp := data_stat.GetEdbUpdateStatResp{
  931. Paging: page,
  932. List: list,
  933. }
  934. br.Ret = 200
  935. br.Success = true
  936. br.Msg = "获取成功"
  937. br.Data = resp
  938. }