nf.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package handler
  2. import (
  3. "GtDataStore/app/cmd/organization/internal/logic/job"
  4. "GtDataStore/app/cmd/organization/internal/svc"
  5. "GtDataStore/app/model"
  6. "context"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. "sync"
  9. "time"
  10. )
  11. func DeviceNf(ctx context.Context, task *job.Task, technologyName string) error {
  12. // 1. 查询所有的设备
  13. devices, err := findDeviceNf(task.Job.SvcCtx, int64(task.Id))
  14. if err != nil {
  15. return err
  16. }
  17. // 2. 获得点位信息
  18. var wg sync.WaitGroup
  19. wg.Add(len(devices))
  20. for _, device := range devices {
  21. device := device
  22. go func() {
  23. defer wg.Done()
  24. if err := device.Items.FillCurrentValue(); err != nil {
  25. logx.Errorf("DeviceNf device.Items.FillCurrentValue error: %s", err.Error())
  26. }
  27. }()
  28. }
  29. wg.Wait()
  30. // 3. 转换为存储对象
  31. workings, err := transDeviceNfData(devices)
  32. if err != nil {
  33. return err
  34. }
  35. // 4. 批量入库
  36. if _, err := task.Job.SvcCtx.WorkingNf.MultiInsert(context.Background(), workings); err != nil {
  37. logx.Errorf("DeviceNf task.Job.SvcCtx.WorkingNf.MultiInsert error: %s", err.Error())
  38. }
  39. return nil
  40. }
  41. func findDeviceNf(svcCtx *svc.ServiceContext, projectId int64) ([]model.DcDeviceBind, error) {
  42. if devices, err := svcCtx.DeviceBind.FindByProjectIdDeviceType(context.Background(), projectId, DEVICE_UF); err != nil {
  43. logx.Infof("findDeviceNf not found devices")
  44. return nil, err
  45. } else {
  46. return devices, nil
  47. }
  48. }
  49. func transDeviceNfData(datas []model.DcDeviceBind) ([]model.DcWorkingNf, error) {
  50. ts := make([]model.DcWorkingNf, len(datas))
  51. for i, data := range datas {
  52. ts[i] = model.DcWorkingNf{
  53. Id: 0,
  54. ProjectId: data.ProjectId,
  55. DeviceCode: data.DeviceCode,
  56. WaterTemperature: data.Items.GetItemFloat64Value("water_temperature"),
  57. FeedFlow1St: data.Items.GetItemFloat64Value("feed_flow_1st"),
  58. ConFlow1St: data.Items.GetItemFloat64Value("con_flow_1st"),
  59. ProductFlow1St: data.Items.GetItemFloat64Value("product_flow_1st"),
  60. FeedPressure1St: data.Items.GetItemFloat64Value("feed_pressure_1st"),
  61. ConPressure1St: data.Items.GetItemFloat64Value("con_pressure_1st"),
  62. ProductPressure1St: data.Items.GetItemFloat64Value("product_pressure_1st"),
  63. Tmp1St: data.Items.GetItemFloat64Value("tmp_1st"),
  64. Flux1St: data.Items.GetItemFloat64Value("flux_1st"),
  65. Permeability1St: data.Items.GetItemFloat64Value("permeability_1st"),
  66. FeedFlow2Nd: data.Items.GetItemFloat64Value("feed_flow_2nd"),
  67. ConFlow2Nd: data.Items.GetItemFloat64Value("con_flow_2nd"),
  68. ProductFlow2Nd: data.Items.GetItemFloat64Value("product_flow_2nd"),
  69. FeedPressure2Nd: data.Items.GetItemFloat64Value("feed_pressure_2nd"),
  70. ConPressure2Nd: data.Items.GetItemFloat64Value("con_pressure_2nd"),
  71. ProductPressure2Nd: data.Items.GetItemFloat64Value("product_pressure_2nd"),
  72. Tmp2Nd: data.Items.GetItemFloat64Value("tmp_2nd"),
  73. Flux2Nd: data.Items.GetItemFloat64Value("flux_2nd"),
  74. Permeability2Nd: data.Items.GetItemFloat64Value("permeability_2nd"),
  75. FeedFlow3Th: data.Items.GetItemFloat64Value("feed_flow_3th"),
  76. ConFlow3Th: data.Items.GetItemFloat64Value("con_flow_3th"),
  77. ProductFlow3Th: data.Items.GetItemFloat64Value("product_flow_3th"),
  78. FeedPressure3Th: data.Items.GetItemFloat64Value("feed_pressure_3th"),
  79. ConPressure3Th: data.Items.GetItemFloat64Value("con_pressure_3th"),
  80. ProductPressure3Th: data.Items.GetItemFloat64Value("product_pressure_3th"),
  81. Tmp3Th: data.Items.GetItemFloat64Value("tmp_3th"),
  82. Flux3Th: data.Items.GetItemFloat64Value("flux_3th"),
  83. Permeability3Th: data.Items.GetItemFloat64Value("permeability_3th"),
  84. FeedWqTurbidity: data.Items.GetItemFloat64Value("feed_wq_turbidity"),
  85. FeedWqPh: data.Items.GetItemInt64Value("feed_wq_ph"),
  86. ProductWqPh: data.Items.GetItemInt64Value("product_wq_ph"),
  87. FeedWqAl: data.Items.GetItemFloat64Value("feed_wq_al"),
  88. ProductWqAl: data.Items.GetItemFloat64Value("product_wq_al"),
  89. FeedWqFe: data.Items.GetItemFloat64Value("feed_wq_fe"),
  90. ProductWqFe: data.Items.GetItemFloat64Value("product_wq_fe"),
  91. FeedWqMn: data.Items.GetItemFloat64Value("feed_wq_mn"),
  92. ProductWqMn: data.Items.GetItemFloat64Value("product_wq_mn"),
  93. FeedWqSio2: data.Items.GetItemFloat64Value("feed_wq_sio2"),
  94. ProductWqSio2: data.Items.GetItemFloat64Value("product_wq_sio2"),
  95. FeedWqCod: data.Items.GetItemFloat64Value("feed_wq_cod"),
  96. ProductWqCod: data.Items.GetItemFloat64Value("product_wq_cod"),
  97. FeedWqP: data.Items.GetItemFloat64Value("feed_wq_p"),
  98. ProductWqP: data.Items.GetItemFloat64Value("product_wq_p"),
  99. Step: data.Items.GetItemInt64Value("step"),
  100. CTime: time.Now(),
  101. }
  102. }
  103. return ts, nil
  104. }