edb_source_stat.go 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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. condition := " and source = ? and terminal_code = ?"
  752. var pars []interface{}
  753. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, terminalCode)
  754. terminalName := ""
  755. terminalDir := ""
  756. if terminalCode != "" {
  757. terminalInfo, err := data_manage.GetEdbTerminalByTerminalCode(terminalCode)
  758. if err != nil {
  759. if err.Error() == utils.ErrNoRow() {
  760. br.Msg = "终端不存在"
  761. return
  762. }
  763. br.Msg = "查询终端信息出错"
  764. br.ErrMsg = "查询终端信息出错 Err:" + err.Error()
  765. return
  766. }
  767. terminalName = terminalInfo.Name
  768. terminalDir = terminalInfo.DirPath
  769. }
  770. if createTime != "" {
  771. startT, err := time.ParseInLocation(utils.FormatDate, createTime, time.Local)
  772. if err != nil {
  773. br.Msg = "请求时间格式错误"
  774. return
  775. }
  776. endT := startT.AddDate(0, 0, 1)
  777. condition += " AND create_time >= ? AND create_time < ?"
  778. pars = append(pars, createTime, endT.Format(utils.FormatDate))
  779. }
  780. tmpList, err := data_stat.GetEdbUpdateStatFailedGroupByCondition(condition, pars)
  781. if err != nil {
  782. br.Msg = "获取指标更新失败详情列表 失败"
  783. br.ErrMsg = "获取指标更新失败详情列表 失败,Err:" + err.Error()
  784. return
  785. }
  786. list := make([]*data_stat.EdbUpdateFailedList, 0)
  787. successNum := 0
  788. failedNum := 0
  789. if len(tmpList) > 0 {
  790. for _, v := range tmpList {
  791. if v.SourceUpdateResult == 1 {
  792. successNum += v.Num
  793. } else {
  794. failedNum += v.Num
  795. list = append(list, v)
  796. }
  797. }
  798. }
  799. resp := data_stat.GetEdbUpdateFailedResp{
  800. List: list,
  801. Name: terminalName,
  802. TerminalCode: terminalCode,
  803. DirPath: terminalDir,
  804. UpdateSuccessNum: successNum,
  805. UpdateFailedNum: failedNum,
  806. }
  807. br.Ret = 200
  808. br.Success = true
  809. br.Msg = "获取成功"
  810. br.Data = resp
  811. }
  812. // EdbUpdateFailedDetailList
  813. // @Title 查询指标更新失败详情列表
  814. // @Description 查询指标更新失败详情列表
  815. // @Success 200 {object} data_stat.GetEdbUpdateLogResp
  816. // @router /edb_update_stat/failed/detail [get]
  817. func (this *EdbSourceStatController) EdbUpdateFailedDetailList() {
  818. br := new(models.BaseResponse).Init()
  819. defer func() {
  820. this.Data["json"] = br
  821. this.ServeJSON()
  822. }()
  823. sysUser := this.SysUser
  824. if sysUser == nil {
  825. br.Msg = "请登录"
  826. br.ErrMsg = "请登录,SysUser Is Empty"
  827. br.Ret = 408
  828. return
  829. }
  830. pageSize, _ := this.GetInt("PageSize")
  831. currentIndex, _ := this.GetInt("CurrentIndex")
  832. var startSize int
  833. if pageSize <= 0 {
  834. pageSize = utils.PageSize20
  835. }
  836. if currentIndex <= 0 {
  837. currentIndex = 1
  838. }
  839. startSize = paging.StartIndex(currentIndex, pageSize)
  840. terminalCode := this.GetString("TerminalCode", "")
  841. createTime := this.GetString("CreateTime", "")
  842. frequency := this.GetString("Frequency", "")
  843. sourceUpdateFailedReason := this.GetString("SourceUpdateFailedReason", "")
  844. if createTime == "" {
  845. br.Msg = "请选择创建时间"
  846. return
  847. }
  848. if frequency == "" {
  849. br.Msg = "请选择对应的频度"
  850. return
  851. }
  852. condition := " and source = ? AND terminal_code = ? and frequency=? and data_update_failed_reason=? and data_update_result = 2"
  853. var pars []interface{}
  854. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, terminalCode, frequency, sourceUpdateFailedReason)
  855. if createTime != "" {
  856. startT, err := time.ParseInLocation(utils.FormatDate, createTime, time.Local)
  857. if err != nil {
  858. br.Msg = "请求时间格式错误"
  859. return
  860. }
  861. endT := startT.AddDate(0, 0, 1)
  862. condition += " AND create_time >= ? AND create_time < ?"
  863. pars = append(pars, createTime, endT.Format(utils.FormatDate))
  864. }
  865. total, err := data_stat.GetEdbUpdateStatCount(condition, pars)
  866. if err != nil {
  867. if err.Error() != utils.ErrNoRow() {
  868. br.Msg = "获取指标列表总数失败"
  869. br.ErrMsg = "获取指标列表总数失败,Err:" + err.Error()
  870. return
  871. } else {
  872. err = nil
  873. }
  874. }
  875. list := make([]*data_stat.EdbInfoUpdateStatItemMore, 0)
  876. page := paging.GetPaging(currentIndex, pageSize, total)
  877. if total == 0 {
  878. resp := data_stat.GetEdbUpdateStatResp{
  879. Paging: page,
  880. List: list,
  881. }
  882. br.Ret = 200
  883. br.Success = true
  884. br.Msg = "获取成功"
  885. br.Data = resp
  886. return
  887. }
  888. tmpList, err := data_stat.GetEdbUpdateStatByCondition(condition, pars, "", pageSize, startSize)
  889. if err != nil {
  890. br.Msg = "获取指标更新列表失败"
  891. br.ErrMsg = "获取指标更新列表失败,Err:" + err.Error()
  892. return
  893. }
  894. for _, v := range tmpList {
  895. tmp := new(data_stat.EdbInfoUpdateStatItemMore)
  896. tmp.Id = v.Id
  897. tmp.EdbInfoId = v.EdbInfoId
  898. tmp.SourceName = v.SourceName
  899. tmp.Source = v.Source
  900. tmp.EdbCode = v.EdbCode
  901. tmp.EdbName = v.EdbName
  902. tmp.EdbNameSource = v.EdbNameSource
  903. tmp.Frequency = v.Frequency
  904. tmp.Unit = v.Unit
  905. tmp.StartDate = v.StartDate
  906. tmp.SysUserId = v.SysUserId
  907. tmp.SysUserRealName = v.SysUserRealName
  908. tmp.LatestDate = v.LatestDate
  909. tmp.LatestValue = v.LatestValue
  910. tmp.TerminalCode = v.TerminalCode
  911. tmp.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  912. if v.DataUpdateTime != utils.EmptyDateTimeStr {
  913. tmp.DataUpdateTime = v.DataUpdateTime
  914. }
  915. if v.ErDataUpdateDate != utils.EmptyDateStr {
  916. tmp.ErDataUpdateDate = v.ErDataUpdateDate
  917. }
  918. tmp.DataUpdateResult = v.DataUpdateResult
  919. tmp.DataUpdateFailedReason = v.DataUpdateFailedReason
  920. if v.UpdateTime != utils.EmptyDateTimeStr {
  921. tmp.UpdateTime = v.UpdateTime
  922. }
  923. tmp.IsAdd = v.IsAdd
  924. tmp.NeedRefresh = v.NeedRefresh
  925. tmp.HasRefresh = v.HasRefresh
  926. list = append(list, tmp)
  927. }
  928. resp := data_stat.GetEdbUpdateStatResp{
  929. Paging: page,
  930. List: list,
  931. }
  932. br.Ret = 200
  933. br.Success = true
  934. br.Msg = "获取成功"
  935. br.Data = resp
  936. }