123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package handler
- import (
- "GtDataStore/app/cmd/organization/internal/logic/job"
- "GtDataStore/app/cmd/organization/internal/svc"
- "GtDataStore/app/model"
- "context"
- "github.com/zeromicro/go-zero/core/logx"
- "time"
- )
- func DeviceRo(ctx context.Context, task *job.Task, technologyName string) error {
- // 1. 查询所有的设备
- devices, err := findDeviceRo(task.Job.SvcCtx, int64(task.Id))
- if err != nil {
- return err
- }
- // 2. 获得点位信息
- //var wg sync.WaitGroup
- //wg.Add(len(devices))
- //for _, device := range devices {
- // device := device
- // go func() {
- // defer wg.Done()
- // if err := device.Items.FillCurrentValue(); err != nil {
- // logx.Errorf("DeviceRo device.Items.FillCurrentValue error: %s", err.Error())
- // }
- // }()
- //}
- //
- //wg.Wait()
- // 3. 转换为存储对象
- workings, err := transDeviceRoData(devices)
- if err != nil {
- return err
- }
- // 4. 批量入库
- if _, err := task.Job.SvcCtx.WorkingRo.MultiInsert(context.Background(), workings); err != nil {
- logx.Errorf("DeviceRo task.Job.SvcCtx.WorkingRo.MultiInsert error: %s", err.Error())
- }
- return nil
- }
- func findDeviceRo(svcCtx *svc.ServiceContext, projectId int64) ([]model.DcDeviceBind, error) {
- if data := deviceBindCacheTable.GetCache(DEVICE_RO); data != nil {
- return data, nil
- }
- if devices, err := svcCtx.DeviceBind.FindByProjectIdDeviceType(context.Background(), projectId, DEVICE_RO); err != nil {
- logx.Infof("findDeviceRo not found devices")
- return nil, err
- } else {
- deviceBindCacheTable.SetCache(DEVICE_RO, devices, time.Now().Add(300*time.Second))
- return devices, nil
- }
- }
- func transDeviceRoData(datas []model.DcDeviceBind) ([]model.DcWorkingRo, error) {
- ts := make([]model.DcWorkingRo, len(datas))
- for i, data := range datas {
- ts[i] = model.DcWorkingRo{
- Id: 0,
- ProjectId: data.ProjectId,
- DeviceCode: data.DeviceCode,
- WaterTemperature: data.Items.GetItemFloat64Value("water_temperature"),
- FeedFlow1St: data.Items.GetItemFloat64Value("feed_flow_1st"),
- ConFlow1St: data.Items.GetItemFloat64Value("con_flow_1st"),
- ProductFlow1St: data.Items.GetItemFloat64Value("product_flow_1st"),
- FeedPressure1St: data.Items.GetItemFloat64Value("feed_pressure_1st"),
- ConPressure1St: data.Items.GetItemFloat64Value("con_pressure_1st"),
- ProductPressure1St: data.Items.GetItemFloat64Value("product_pressure_1st"),
- Tmp1St: data.Items.GetItemFloat64Value("tmp_1st"),
- Flux1St: data.Items.GetItemFloat64Value("flux_1st"),
- Permeability1St: data.Items.GetItemFloat64Value("permeability_1st"),
- FeedFlow2Nd: data.Items.GetItemFloat64Value("feed_flow_2nd"),
- ConFlow2Nd: data.Items.GetItemFloat64Value("con_flow_2nd"),
- ProductFlow2Nd: data.Items.GetItemFloat64Value("product_flow_2nd"),
- FeedPressure2Nd: data.Items.GetItemFloat64Value("feed_pressure_2nd"),
- ConPressure2Nd: data.Items.GetItemFloat64Value("con_pressure_2nd"),
- ProductPressure2Nd: data.Items.GetItemFloat64Value("product_pressure_2nd"),
- Tmp2Nd: data.Items.GetItemFloat64Value("tmp_2nd"),
- Flux2Nd: data.Items.GetItemFloat64Value("flux_2nd"),
- Permeability2Nd: data.Items.GetItemFloat64Value("permeability_2nd"),
- FeedFlow3Th: data.Items.GetItemFloat64Value("feed_flow_3th"),
- ConFlow3Th: data.Items.GetItemFloat64Value("con_flow_3th"),
- ProductFlow3Th: data.Items.GetItemFloat64Value("product_flow_3th"),
- FeedPressure3Th: data.Items.GetItemFloat64Value("feed_pressure_3th"),
- ConPressure3Th: data.Items.GetItemFloat64Value("con_pressure_3th"),
- ProductPressure3Th: data.Items.GetItemFloat64Value("product_pressure_3th"),
- Tmp3Th: data.Items.GetItemFloat64Value("tmp_3th"),
- Flux3Th: data.Items.GetItemFloat64Value("flux_3th"),
- Permeability3Th: data.Items.GetItemFloat64Value("permeability_3th"),
- FeedWqTurbidity: data.Items.GetItemFloat64Value("feed_wq_turbidity"),
- FeedWqPh: data.Items.GetItemInt64Value("feed_wq_ph"),
- ProductWqPh: data.Items.GetItemInt64Value("product_wq_ph"),
- FeedWqAl: data.Items.GetItemFloat64Value("feed_wq_al"),
- ProductWqAl: data.Items.GetItemFloat64Value("product_wq_al"),
- FeedWqFe: data.Items.GetItemFloat64Value("feed_wq_fe"),
- ProductWqFe: data.Items.GetItemFloat64Value("product_wq_fe"),
- FeedWqMn: data.Items.GetItemFloat64Value("feed_wq_mn"),
- ProductWqMn: data.Items.GetItemFloat64Value("product_wq_mn"),
- FeedWqSio2: data.Items.GetItemFloat64Value("feed_wq_sio2"),
- ProductWqSio2: data.Items.GetItemFloat64Value("product_wq_sio2"),
- FeedWqCod: data.Items.GetItemFloat64Value("feed_wq_cod"),
- ProductWqCod: data.Items.GetItemFloat64Value("product_wq_cod"),
- FeedWqP: data.Items.GetItemFloat64Value("feed_wq_p"),
- ProductWqP: data.Items.GetItemFloat64Value("product_wq_p"),
- Step: data.Items.GetItemInt64Value("step"),
- FilterTime: data.Items.GetItemFloat64Value("filter_time"),
- FilterCycle: data.Items.GetItemInt64Value("filter_cycle"),
- CTime: time.Now(),
- }
- }
- return ts, nil
- }
|