supply_analysis.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package controllers
  2. import (
  3. "eta/eta_hub/models"
  4. "eta/eta_hub/models/data_manage"
  5. "eta/eta_hub/utils"
  6. )
  7. // SupplyAnalysisController 供应分析
  8. type SupplyAnalysisController struct {
  9. BaseAuthController
  10. }
  11. // StockPlantVarietyList
  12. // @Title 装置检修-品种分类
  13. // @Description 装置检修-品种分类
  14. // @Success 200 {object} data_manage.VarietyItem
  15. // @router /stock_plant/variety/list [get]
  16. func (this *SupplyAnalysisController) StockPlantVarietyList() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. varietyOb := new(data_manage.Variety)
  23. cond := ``
  24. pars := make([]interface{}, 0)
  25. list, e := varietyOb.GetItemsByCondition(cond, pars, []string{}, "create_time ASC")
  26. if e != nil {
  27. br.Msg = "获取失败"
  28. br.ErrMsg = "StockPlantVarietyList GetItemsByCondition err: " + e.Error()
  29. return
  30. }
  31. resp := make([]*data_manage.VarietyItem, 0)
  32. for _, v := range list {
  33. resp = append(resp, data_manage.FormatVariety2Item(v))
  34. }
  35. br.Data = resp
  36. br.Ret = 200
  37. br.Msg = "获取成功"
  38. }
  39. // StockPlantEdbList
  40. // @Title 装置检修-指标列表
  41. // @Description 装置检修-指标列表
  42. // @Param VarietyId query int false "品种ID"
  43. // @Success 200 {object} data_manage.ChartInfoItem
  44. // @router /stock_plant/edb/list [get]
  45. func (this *SupplyAnalysisController) StockPlantEdbList() {
  46. br := new(models.BaseResponse).Init()
  47. defer func() {
  48. this.Data["json"] = br
  49. this.ServeJSON()
  50. }()
  51. varietyId, _ := this.GetInt("VarietyId", 0)
  52. // 只取加入指标库中的
  53. cond := ` AND edb_info_id > 0`
  54. pars := make([]interface{}, 0)
  55. if varietyId > 0 {
  56. cond += ` AND variety_id = ?`
  57. pars = append(pars, varietyId)
  58. }
  59. edbOb := new(data_manage.VarietyEdbInfo)
  60. list, e := edbOb.GetItemsByCondition(cond, pars, []string{}, "")
  61. if e != nil {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "StockPlantEdbList GetItemsByCondition err: " + e.Error()
  64. return
  65. }
  66. resp := make([]*data_manage.VarietyEdbInfoItem, 0)
  67. for _, v := range list {
  68. resp = append(resp, data_manage.FormatVarietyEdbInfo2Item(v))
  69. }
  70. br.Data = resp
  71. br.Ret = 200
  72. br.Msg = "获取成功"
  73. }
  74. // StockPlantEdbDetail
  75. // @Title 装置检修-指标详情
  76. // @Description 装置检修-指标详情
  77. // @Param EdbCode query string true "指标编码"
  78. // @Success 200 {object} data_manage.EdbInfoItem
  79. // @router /stock_plant/edb/detail [get]
  80. func (this *SupplyAnalysisController) StockPlantEdbDetail() {
  81. br := new(models.BaseResponse).Init()
  82. defer func() {
  83. this.Data["json"] = br
  84. this.ServeJSON()
  85. }()
  86. edbCode := this.GetString("EdbCode")
  87. if edbCode == "" {
  88. br.Msg = "参数有误"
  89. return
  90. }
  91. edbOb := new(data_manage.EdbInfo)
  92. edb, e := edbOb.GetItemByEdbCode(edbCode)
  93. if e != nil {
  94. if e.Error() == utils.ErrNoRow() {
  95. br.Msg = "指标不存在"
  96. return
  97. }
  98. br.Msg = "获取失败"
  99. br.ErrMsg = "StockPlantEdbDetail GetItemByCode err: " + e.Error()
  100. return
  101. }
  102. // 获取指标数据
  103. //dataOb := new(data_manage.EdbData)
  104. //dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.EdbCode, []string{}, "")
  105. //if e != nil {
  106. // br.Msg = "获取失败"
  107. // br.ErrMsg = "StockPlantEdbDetail GetItemsBySourceAndCode err: " + e.Error()
  108. // return
  109. //}
  110. //edbData := make([]*data_manage.EdbDataItem, 0)
  111. //for _, v := range dataList {
  112. // edbData = append(edbData, data_manage.FormatEdbData2Item(v))
  113. //}
  114. resp := data_manage.FormatEdbInfo2Item(edb)
  115. br.Data = resp
  116. br.Ret = 200
  117. br.Msg = "获取成功"
  118. }