edb_source_stat.go 26 KB

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