guodj 4 lat temu
rodzic
commit
f38d05cb15

+ 107 - 4
common/data1.json

@@ -3,18 +3,121 @@
     {
       "laboratory_id": 1,
       "laboratory_name": "实验室1",
+
       "base_equipment": 14,
       "laboratory_equipment": 56,
       "use_time": 134.2,
-      "experimental_data": 1523
-    },{
+      "experimental_data": 1523,
+
+      "list": [
+        {
+          "year": 2016,
+          "quantity": 500
+        },
+        {
+          "year": 2017,
+          "quantity": 508
+        },
+        {
+          "year": 2018,
+          "quantity": 512.3
+        },
+        {
+          "year": 2018,
+          "quantity": 523.4
+        },
+        {
+          "year": 2019,
+          "quantity": 533.3
+        },
+        {
+          "year": 2020,
+          "quantity": 555.6
+        },
+        {
+          "year": 2021,
+          "quantity": 588.9
+        }
+      ],
+
+      "total":350,
+      "week_appointment":350,
+      "month_appointment":350,
+      "year_appointment":350,
+      "usage_rate":75,
+      "week_compliance":80,
+      "month_compliance":60,
+      "year_compliance":55,
+
+      "peak_hours":[
+        "10:00am--11:00am",
+        "14:00am--15:00am"
+      ],
+
+      "equipment":[
+        "共聚焦显微镜",
+        "凝胶成像仪",
+        "流式细胞仪"
+      ]
+    },
+    {
       "laboratory_id": 2,
       "laboratory_name": "实验室2",
       "base_equipment": 16,
       "laboratory_equipment": 26,
       "use_time": 232.2,
-      "experimental_data": 243
+      "experimental_data": 243,
+
+      "list": [
+        {
+          "year": 2016,
+          "quantity": 600
+        },
+        {
+          "year": 2017,
+          "quantity": 608
+        },
+        {
+          "year": 2018,
+          "quantity": 612.3
+        },
+        {
+          "year": 2018,
+          "quantity": 623.4
+        },
+        {
+          "year": 2019,
+          "quantity": 633.3
+        },
+        {
+          "year": 2020,
+          "quantity": 655.6
+        },
+        {
+          "year": 2021,
+          "quantity": 688.9
+        }
+      ],
+
+      "total":230,
+      "week_appointment":250,
+      "month_appointment":250,
+      "year_appointment":230,
+      "usage_rate":67,
+      "week_compliance":87,
+      "month_compliance":62,
+      "year_compliance":65,
+
+      "peak_hours":[
+        "9:00am--10:00am",
+        "13:00am--14:00am"
+      ],
+
+      "equipment":[
+        "共聚焦显微镜",
+        "凝胶成像仪",
+        "流式细胞仪"
+      ]
     }
   ]
 }
-

+ 96 - 0
common/data2.json

@@ -0,0 +1,96 @@
+{
+  "scale":{
+    "subject_total": 12,
+    "results_total": 43,
+    "organization_total": 13,
+    "researcher" : 567
+  },
+  "subject":
+    [
+      {
+        "year":"2019",
+        "total": 12,
+        "growth_rate": 32
+      },
+      {
+        "year":"2020",
+        "total": 15,
+        "growth_rate": 32
+      },
+      {
+        "year":"2021",
+        "total": 18,
+        "growth_rate": 32
+      }
+    ],
+  "result_statistics": [
+    {
+      "platform_name": "基因工程平台",
+      "subject_total": 23,
+      "result_total": 43
+    },
+    {
+      "platform_name": "基因编辑平台",
+      "subject_total": 23,
+      "result_total": 43
+    },
+    {
+      "platform_name": "药物选择平台",
+      "subject_total": 23,
+      "result_total": 43
+    },
+    {
+      "platform_name": "分子筛选平台",
+      "subject_total": 23,
+      "result_total": 43
+    },
+    {
+      "platform_name": "药物创新平台",
+      "subject_total": 23,
+      "result_total": 43
+    },
+    {
+      "platform_name": "实验动物平台",
+      "subject_total": 23,
+      "result_total": 43
+    },
+    {
+      "platform_name": "临床试验平台",
+      "subject_total": 23,
+      "result_total": 43
+    }
+  ],
+  "result": [
+    {
+      "name": "2021年实验室已申请专利",
+      "plan_number": 42,
+      "completed_number": 35
+    },
+    {
+      "name": "2021年实验室已发表临床医学论文数量",
+      "plan_number": 10,
+      "completed_number": 7
+    },
+    {
+      "name": "2021年实验室已发表基础医学论文数量",
+      "plan_number": 23,
+      "completed_number": 10
+    },
+    {
+      "name": "2021年实验室已发表急诊医学论文数量",
+      "plan_number": 42,
+      "completed_number": 35
+    },
+    {
+      "name": "2021年实验室已申请软件著作权数量",
+      "plan_number": 22,
+      "completed_number": 12
+    }
+  ],
+  "message": [
+    {
+      "publish_time": "2021/01/24",
+      "msg": "来访文员:xxx大学来访通知"
+    }
+  ]
+}

+ 95 - 0
common/data3.json

@@ -0,0 +1,95 @@
+{
+  "data":[
+    {
+      "equipment_id": 1,
+      "equipment_code":"XY01",
+      "equipment_name":"双分子共聚焦显微镜",
+      "brand_model":"Lecica SP8 DIVE",
+      "device_status":"运行",
+      "norm":"功率 100w 使用"
+
+    },{
+      "equipment_id": 2,
+      "equipment_code":"XY02",
+      "equipment_name":"二氧化碳培养箱",
+      "brand_model":"Lecica SP8 DIVE",
+      "device_status":"运行",
+      "norm":"功率 100w 使用"
+    },{
+      "equipment_id": 3,
+      "equipment_code":"XY03",
+      "equipment_name":"双分子共聚焦显微镜",
+      "brand_model":"Lecica SP8 DIVE",
+      "device_status":"运行",
+      "norm":"功率 100w 使用"
+    }
+  ],
+  "equipment_statistics":[{
+    "equipment_xid":"XY01",
+    "equipment_name":"双分子共聚焦显微镜",
+    "equipment_code":"XY01",
+    "carbon_dioxide_concentration":"7.6%",
+    "equipment_temperature":"36.1",
+    "equipment_humidity":"62%",
+    "equipment_building":"二号楼",
+    "equipment_room":"2021",
+    "next_calibration_time":"2021-01-01",
+    "next_maintenance_time":"2022-03-21"
+  },{
+    "equipment_xid":"XY01",
+    "equipment_name":"二氧化碳培养箱",
+    "equipment_code":"XY02",
+    "carbon_dioxide_concentration":"7.6%",
+    "equipment_temperature":"36.1",
+    "equipment_humidity":"62%",
+    "equipment_building":"二号楼",
+    "equipment_room":"2021",
+    "next_calibration_time":"2021-01-01",
+    "next_maintenance_time":"2022-03-21"
+  },{
+    "equipment_xid":"XY01",
+    "equipment_name":"双分子共聚焦显微镜",
+    "equipment_code":"XY03",
+    "carbon_dioxide_concentration":"7.6%",
+    "equipment_temperature":"36.1",
+    "equipment_humidity":"62%",
+    "equipment_building":"二号楼",
+    "equipment_room":"2021",
+    "next_calibration_time":"2021-01-01",
+    "next_maintenance_time":"2022-03-21"
+  }
+
+  ],
+  "equipment_status":
+    {
+      "equipment_number":"300",
+      "no_alarm_processing":"74",
+      "operating_equipment":"74",
+      "deactivation_equipment":"74",
+      "maintenance_equipment":"74"
+    },
+  "alarm_statistics":[
+    {
+      "abnormal_temperature":"300",
+      "abnormal_liquid_level":"74",
+      "door_opening_closing_alarm":"74",
+      "other_alarms":"74",
+      "Call_police":"74",
+      "operation_violation":"74",
+      "abnormal_gas_concentration":"74"
+    }
+  ],
+  "monitoring_type_statistics":[
+    {
+      "temperature_humidity":"30%",
+      "level":"30%",
+      "oxygen":"30%",
+      "carbon_dioxide":"30%",
+      "air_quality":"30%",
+      "pecial_gas":"30%",
+      "video_capture":"30%",
+      "instrument_data":"30%",
+      "other":"30%"
+    }
+  ]
+}

+ 4 - 33
common/json.go

@@ -1,49 +1,20 @@
 package common
 
 import (
-	"encoding/json"
-	"io/ioutil"
-	"os"
+	"github.com/gogf/gf/encoding/gjson"
 )
 
-type ReadData struct {
-	Data interface{} `json:"data"`
-}
-
-type BaseModel struct {
-	LaboratoryId   int    `json:"laboratory_id"`   // 实验室ID
-	LaboratoryName string `json:"laboratory_name"` // 实验室名称
-}
-
-// DeviceStatistics 实验设备使用数据
-type DeviceStatistics struct {
-	BaseModel
-	BaseEquipment       int `json:"base_equipment"`       // 基础科研设备
-	LaboratoryEquipment int `json:"laboratory_equipment"` // 实验室设备
-	UseTime             int `json:"use_time"`             // 使用时长
-	ExperimentalData    int `json:"experimental_data"`    // 实验数据
-}
-
 // ReadJson 从配置文件中读取json
-func ReadJson(entity interface{}, path ...string) error {
+func ReadJson(entity interface{}, pattern string, path ...string) error {
 	jPath := "data1.json"
 	if len(path) > 0 {
 		jPath = path[0]
 	}
-	// 打开json文件
-	jsonFile, err := os.Open(jPath)
-	if err != nil {
-		return err
-	}
-	var rdata ReadData
-	rdata.Data = &entity
-	// 要记得关闭
-	defer jsonFile.Close()
-	byteValue, err := ioutil.ReadAll(jsonFile)
+	js, err := gjson.Load(jPath)
 	if err != nil {
 		return err
 	}
-	err = json.Unmarshal([]byte(byteValue), &rdata)
+	err = js.GetScan(pattern, entity)
 	if err != nil {
 		return err
 	}

+ 2 - 2
config/config.toml

@@ -10,8 +10,8 @@
 [service_registry]
 #    registry = "etcd"  # consul 或 peer2peer 或 etcd
 #    server-addr = "192.168.0.252:12379"
-    registry = "peer2peer"  # consul 或 peer2peer 或 etcd
-    server-addr = "192.168.0.252:12379"
+    registry = "consul"  # consul 或 peer2peer 或 etcd
+    server-addr = "192.168.0.252:18500"
 #    registry = "consul"  # consul 或 peer2peer 或 etcd
 #    server-addr = "192.168.0.63:8500"
 

+ 63 - 6
hander/equipment.go

@@ -2,7 +2,6 @@ package hander
 
 import (
 	"context"
-	"dashoo.cn/common_definition/comm_def"
 	myerrors "dashoo.cn/micro_libary/errors"
 	"lims_zju/model"
 	"lims_zju/service"
@@ -10,16 +9,74 @@ import (
 
 type Equipment struct{}
 
-// UsageStatistics 实验设备统计数据
+// UsageStatistics 实验设备使用数据
 func (e *Equipment) UsageStatistics(ctx context.Context, req *model.BaseModel, resp *model.Resp) error {
-	resp.CommonMsg = new(comm_def.CommonMsg)
 	res, err := new(service.DeviceStatistics).GetDeviceStatistics(ctx, req)
 	if err != nil {
 		return err
 	}
-	_, err, code, msg := myerrors.CheckError(err, myerrors.ConvErr)
-	resp.CommonMsg.Code = code
-	resp.CommonMsg.Msg = msg
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// ExperimentalStatistics 实验数据
+func (e *Equipment) ExperimentalStatistics(ctx context.Context, req *model.BaseModel, resp *model.Resp) error {
+	res, err := new(service.DeviceStatistics).GetExperimentalData(ctx, req)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// AppointmentStatistics 实验室预约信息
+func (e *Equipment) AppointmentStatistics(ctx context.Context, req *model.BaseModel, resp *model.Resp) error {
+	res, err := new(service.DeviceStatistics).GetAppointment(ctx, req)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// PeakHoursStatistics 设备使用高峰时段
+func (e *Equipment) PeakHoursStatistics(ctx context.Context, req *model.BaseModel, resp *model.Resp) error {
+	res, err := new(service.DeviceStatistics).GetPeakHours(ctx, req)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// HighEquipmentStatistics 实验数据统计
+func (e *Equipment) HighEquipmentStatistics(ctx context.Context, req *model.BaseModel, resp *model.Resp) error {
+	res, err := new(service.DeviceStatistics).GetHighEquipment(ctx, req)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
 	resp.Data = res
 	if err != nil {
 		return err

+ 86 - 0
hander/equiptment_three.go

@@ -0,0 +1,86 @@
+package hander
+
+import (
+	"context"
+	"lims_zju/model"
+	"lims_zju/service"
+
+	myerrors "dashoo.cn/micro_libary/errors"
+)
+
+type EquipmentStatistics struct{}
+
+// UseEquipmentList 设备质控管理
+func (e *EquipmentStatistics) UseEquipmentList(ctx context.Context, req *model.DataModel, resp *model.Resp) error {
+	res, err := new(service.DataStatistics).GetDataModel(ctx, req)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// UseEquipmentStatistics 设备详情
+func (e *EquipmentStatistics) UseEquipmentStatistics(ctx context.Context, req *model.DataModel, resp *model.Resp) error {
+	res, err := new(service.DataStatistics).GetDataStatistics(ctx, req)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// UseEquipmentStatus 设备状态统计
+func (e *EquipmentStatistics) UseEquipmentStatus(ctx context.Context, req *model.DataModel, resp *model.Resp) error {
+	res, err := new(service.DataStatistics).GetDataStatus(ctx, req)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// UseEquipmentAlarm 报警统计
+func (e *EquipmentStatistics) UseEquipmentAlarm(ctx context.Context, req *model.DataModel, resp *model.Resp) error {
+	res, err := new(service.DataStatistics).GetDataAlarm(ctx, req)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// UseEquipmentMonitoring 监控类型统计
+func (e *EquipmentStatistics) UseEquipmentMonitoring(ctx context.Context, req *model.DataModel, resp *model.Resp) error {
+	res, err := new(service.DataStatistics).GetDataMonitoring(ctx, req)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 80 - 0
hander/platform.go

@@ -0,0 +1,80 @@
+package hander
+
+import (
+	"context"
+	myerrors "dashoo.cn/micro_libary/errors"
+	"lims_zju/model"
+	"lims_zju/service"
+)
+
+type Platform struct{}
+
+func (p *Platform) GetScaleTotal(ctx context.Context, req interface{}, resp *model.Resp) error {
+	res, err := new(service.Platform).GetScaleTotal(ctx)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func (p *Platform) GetSubjectTotal(ctx context.Context, req *model.BaseModel, resp *model.Resp) error {
+	res, err := new(service.Platform).GetSubjectTotal(ctx)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func (p *Platform) GetResultStatistics(ctx context.Context, req *model.BaseModel, resp *model.Resp) error {
+	res, err := new(service.Platform).GetResultStatistics(ctx)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func (p *Platform) GetResult(ctx context.Context, req *model.BaseModel, resp *model.Resp) error {
+	res, err := new(service.Platform).GetResult(ctx)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func (p *Platform) GetMessage(ctx context.Context, req *model.BaseModel, resp *model.Resp) error {
+	res, err := new(service.Platform).GetMessage(ctx)
+	if err != nil {
+		return err
+	}
+	_, err, code, _ := myerrors.CheckError(err, myerrors.ConvErr)
+	resp.Code = code
+	resp.Data = res
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 4 - 1
main.go

@@ -4,6 +4,7 @@ import (
 	"dashoo.cn/micro_libary/micro_srv"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/util/gconv"
+	"lims_zju/hander"
 )
 
 var (
@@ -25,7 +26,9 @@ func main() {
 	s := micro_srv.CreateAndInitService(basePath)
 
 	// 注册服务对象
-	//s.RegisterName("VisitResult", new(handler.VisitResult), "")
+	s.RegisterName("Platform", new(hander.Platform), "")
+	s.RegisterName("Equipment", new(hander.Equipment), "")
+	s.RegisterName("EquipmentStatistics", new(hander.EquipmentStatistics), "")
 
 	// 运行服务
 	if err := s.Serve("tcp", srvAddr); err != nil {

+ 36 - 4
model/equipment.go

@@ -1,7 +1,5 @@
 package model
 
-import "dashoo.cn/common_definition/comm_def"
-
 type BaseModel struct {
 	LaboratoryId   int    `json:"laboratory_id"`   // 实验室ID
 	LaboratoryName string `json:"laboratory_name"` // 实验室名称
@@ -23,6 +21,40 @@ type ExperimentalData struct {
 }
 
 type Resp struct {
-	CommonMsg   *comm_def.CommonMsg `json:"common_msg"`
-	Data  interface{}
+	Code int32       `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
+	Data interface{} `json:"data"`
+}
+
+// ExperimentalData 实验数据
+type ExperimentalDatas struct {
+	BaseModel
+	List []ExperimentalData `json:"list"`
+}
+
+// 实验室预约信息
+
+type Appointment struct {
+	BaseModel
+	Total            int `json:"total"`             // 设备总数
+	WeekAppointment  int `json:"week_appointment"`  // 本周预约
+	MonthAppointment int `json:"month_appointment"` // 本月预约
+	YearAppointment  int `json:"year_appointment"`  // 本年预约
+	UsageRate        int `json:"usage_rate"`        //使用率
+	WeekCompliance   int `json:"week_compliance"`   // 本周履约率
+	MonthCompliance  int `json:"month_compliance"`  // 本月履约率
+	YearCompliance   int `json:"year_compliance"`   // 本年履约率
+}
+
+//设备使用高峰时段
+
+type PeakHours struct {
+	BaseModel
+	PeakHours string `json:"peak_hours"` //高峰时段
+}
+
+// 高频使用设备
+
+type HighEquipment struct {
+	BaseModel
+	Equipment string `json:"equipment"` //高频设备
 }

+ 58 - 0
model/equipment_three.go

@@ -0,0 +1,58 @@
+package model
+
+//设备基本信息
+type DataModel struct {
+	EquipmentId   int    `json:"equipment_id"`   //设备ID
+	EquipmentCode string `json:"equipment_code"` //设备编码
+	EquipmentName string `json:"equipment_name"` //设备名称
+	BrandModel    string `json:"brand_model"`    //品牌型号
+	DeviceStatus  string `json:"device_status"`  //设备状态
+	Norm          string `json:"norm"`           //指标
+}
+
+//设备详细信息
+type EquipmentStatistics struct {
+	EquipmentId                int    `json:"equipment_id"`                 //设备ID
+	EquipmentCode              string `json:"equipment_code"`               //设备编码
+	EquipmentName              string `json:"equipment_name"`               //设备名称
+	CarbonDioxideConcentration string `json:"carbon_dioxide_concentration"` //co2浓度
+	EquipmentTemperature       string `json:"equipment_temperature"`        //设备温度
+	EquipmentHumidity          string `json:"equipment_humidity"`           //设备湿度
+	EquipmentBuilding          string `json:"equipment_building"`           //设备所在楼宇
+	EquipmentRoom              string `json:"equipment_room"`               //设备所在房间
+	NextCalibrationTime        string `json:"next_calibration_time"`        //下次校准时间
+	NextMaintenanceTime        string `json:"next_maintenance_time"`        //下次维保时间
+}
+
+//设备状态统计
+type EquipmentStatusStatistics struct {
+	EquipmentNumber       string `json:"equipment_number"`       //设备数量
+	NoAlarmProcessing     string `json:"no_alarm_processing"`    //未报警处理
+	OperatingEquipment    string `json:"operating_equipment"`    //运行设备
+	DeactivationEquipment string `json:"deactivation_equipment"` //停用设备
+	MaintenanceEquipment  string `json:"maintenance_equipment"`  //检修设备
+}
+
+//报警统计
+type AlarmTatistics struct {
+	AbnormalTemperature      string `json:"abnormal_temperature"`       //温度异常
+	AbnormalLiquidlevel      string `json:"abnormal_liquidlevel"`       //液位异常
+	DoorOpeningClosingAlarm  string `json:"door_opening_closing_alarm"` //开关门报警
+	OtherAlarms              string `json:"other_alarms"`               //其他报警
+	CallPolice               string `json:"call_police"`                //人员报警
+	OperationViolation       string `json:"operation_violation"`        //操作违规
+	AbnormalGasConcentration string `json:"abnormal_gas_concentration"` //气体浓度异常
+}
+
+//监控类型统计
+type MonitoringTypeStatistics struct {
+	TemperatureHumidity string `json:"temperature_humidity"` //温湿度
+	Level               string `json:"level"`                //液位
+	Oxygen              string `json:"oxygen"`               //氧气
+	CarbonDioxide       string `json:"carbon_dioxide"`       //co2
+	AirQuality          string `json:"air_quality"`          //空气质量
+	PecialGas           string `json:"pecial_gas"`           //特殊气体
+	VideoCapture        string `json:"video_capture"`        //视频捕捉
+	InstrumentData      string `json:"instrument_data"`      //仪器数据
+	Other               string `json:"other"`                //其他
+}

+ 36 - 0
model/platform.go

@@ -0,0 +1,36 @@
+package model
+
+// ScaleTotal 实验室规模统计
+type ScaleTotal struct {
+	SubjectTotal      int `json:"subject_total"`      //课题数量
+	ResultsTotal      int `json:"results_total"`      // 成果数量
+	OrganizationTotal int `json:"organization_total"` // 合作机构
+	Researcher        int `json:"researcher"`         // 科研人员
+}
+
+// SubjectTotal 课题总量统计
+type SubjectTotal struct {
+	Year       string  `json:"year"`        // 年
+	Total      int     `json:"total"`       // 课题总量
+	GrowthRate float64 `json:"growth_rate"` // 课题年度增长率
+}
+
+// ResultStatistics 平台数量
+type ResultStatistics struct {
+	PlatformName string `json:"platform_name"` //平台名称
+	SubjectTotal int    `json:"subject_total"` // 课题数量
+	ResultTotal  int    `json:"result_total"`  // 成果数量
+}
+
+// Result 成果展示
+type Result struct {
+	Name            string `json:"name"`             // 成果标题
+	PlanNumber      int    `json:"plan_number"`      // 年度计划数量
+	CompletedNumber int    `json:"completed_number"` // 完成数量
+}
+
+// Message 合作交流
+type Message struct {
+	PublishTime string `json:"publish_time"` // 时间
+	Msg         string `json:"msg"`          // 信息
+}

+ 71 - 2
service/equipment.go

@@ -8,10 +8,79 @@ import (
 
 type DeviceStatistics struct{}
 
+type ReadData struct {
+	Data interface{} `json:"data"`
+}
+
 // GetDeviceStatistics 获取实验设备数据使用信息
-func (d *DeviceStatistics) GetDeviceStatistics(ctx context.Context, req *model.BaseModel) (*model.DeviceStatistics, error) {
+func (d *DeviceStatistics) GetDeviceStatistics(ctx context.Context, req *model.BaseModel) (
+	*model.DeviceStatistics, error) {
 	list := make([]model.DeviceStatistics, 0)
-	err := common.ReadJson(&list, "/home/desdemo/wp/code/lims_zju/common/data1.json")
+	err := common.ReadJson(&list, "data", "common/data1.json")
+	if err != nil {
+		return nil, err
+	}
+	for _, v := range list {
+		if v.LaboratoryId == req.LaboratoryId {
+			return &v, nil
+		}
+	}
+	return nil, nil
+}
+
+// GetExperimentalData 获取实验数据
+func (d *DeviceStatistics) GetExperimentalData(ctx context.Context, req *model.BaseModel) (
+	*model.ExperimentalDatas, error) {
+	list := make([]model.ExperimentalDatas, 0)
+	err := common.ReadJson(&list, "data", "common/data1.json")
+	if err != nil {
+		return nil, err
+	}
+	for _, v := range list {
+		if v.LaboratoryId == req.LaboratoryId {
+			return &v, nil
+		}
+	}
+	return nil, nil
+}
+
+// GetAppointment 获取预约信息
+func (d *DeviceStatistics) GetAppointment(ctx context.Context, req *model.BaseModel) (
+	*model.Appointment, error) {
+	list := make([]model.Appointment, 0)
+	err := common.ReadJson(&list, "data", "common/data1.json")
+	if err != nil {
+		return nil, err
+	}
+	for _, v := range list {
+		if v.LaboratoryId == req.LaboratoryId {
+			return &v, nil
+		}
+	}
+	return nil, nil
+}
+
+// GetPeakHours 获取高峰时段
+func (d *DeviceStatistics) GetPeakHours(ctx context.Context, req *model.BaseModel) (
+	*model.PeakHours, error) {
+	list := make([]model.PeakHours, 0)
+	err := common.ReadJson(&list, "data", "common/data1.json")
+	if err != nil {
+		return nil, err
+	}
+	for _, v := range list {
+		if v.LaboratoryId == req.LaboratoryId {
+			return &v, nil
+		}
+	}
+	return nil, nil
+}
+
+// GetHighEquipment 获取高频使用设备
+func (d *DeviceStatistics) GetHighEquipment(ctx context.Context, req *model.BaseModel) (
+	*model.HighEquipment, error) {
+	list := make([]model.HighEquipment, 0)
+	err := common.ReadJson(&list, "data", "common/data1.json")
 	if err != nil {
 		return nil, err
 	}

+ 58 - 51
service/equipment_test.go

@@ -1,54 +1,61 @@
 package service
 
-import (
-	"context"
-	"reflect"
-	"testing"
-)
+//func TestDeviceStatistics_GetDeviceStatistics(t *testing.T) {
+//	type fields struct {
+//		BaseModel           BaseModel
+//		BaseEquipment       int
+//		LaboratoryEquipment int
+//		UseTime             float64
+//		ExperimentalData    int
+//	}
+//	type args struct {
+//		ctx context.Context
+//		req *BaseModel
+//	}
+//	base := new(DeviceStatistics)
+//	arg := args{
+//		ctx: context.TODO(),
+//		req: &BaseModel{LaboratoryId: 1},
+//	}
+//	tests := []struct {
+//		name    string
+//		fields  *DeviceStatistics
+//		args    args
+//		want    *DeviceStatistics
+//		wantErr bool
+//	}{
+//		{"读取实验数据测试1", base, arg, nil, false},
+//	}
+//	for _, tt := range tests {
+//		t.Run(tt.name, func(t *testing.T) {
+//			d := &DeviceStatistics{
+//				BaseModel:           tt.fields.BaseModel,
+//				BaseEquipment:       tt.fields.BaseEquipment,
+//				LaboratoryEquipment: tt.fields.LaboratoryEquipment,
+//				UseTime:             tt.fields.UseTime,
+//				ExperimentalData:    tt.fields.ExperimentalData,
+//			}
+//			got, err := d.GetDeviceStatistics(tt.args.ctx, tt.args.req)
+//			if (err != nil) != tt.wantErr {
+//				t.Errorf("GetDeviceStatistics() error = %v, wantErr %v", err, tt.wantErr)
+//				return
+//			}
+//			if !reflect.DeepEqual(got, tt.want) {
+//				t.Errorf("GetDeviceStatistics() got = %v, want %v", got, tt.want)
+//			}
+//		})
+//	}
+//}
 
-func TestDeviceStatistics_GetDeviceStatistics(t *testing.T) {
-	type fields struct {
-		BaseModel           BaseModel
-		BaseEquipment       int
-		LaboratoryEquipment int
-		UseTime             float64
-		ExperimentalData    int
-	}
-	type args struct {
-		ctx context.Context
-		req *BaseModel
-	}
-	base := new(DeviceStatistics)
-	arg := args{
-		ctx: context.TODO(),
-		req: &BaseModel{LaboratoryId: 1},
-	}
-	tests := []struct {
-		name    string
-		fields  *DeviceStatistics
-		args    args
-		want    *DeviceStatistics
-		wantErr bool
-	}{
-		{"读取实验数据测试1", base, arg, nil, false},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			d := &DeviceStatistics{
-				BaseModel:           tt.fields.BaseModel,
-				BaseEquipment:       tt.fields.BaseEquipment,
-				LaboratoryEquipment: tt.fields.LaboratoryEquipment,
-				UseTime:             tt.fields.UseTime,
-				ExperimentalData:    tt.fields.ExperimentalData,
-			}
-			got, err := d.GetDeviceStatistics(tt.args.ctx, tt.args.req)
-			if (err != nil) != tt.wantErr {
-				t.Errorf("GetDeviceStatistics() error = %v, wantErr %v", err, tt.wantErr)
-				return
-			}
-			if !reflect.DeepEqual(got, tt.want) {
-				t.Errorf("GetDeviceStatistics() got = %v, want %v", got, tt.want)
-			}
-		})
-	}
-}
+//func Test_Open(t *testing.T) {
+//	var producer *nsq.Producer
+//	cfg := nsq.NewConfig()
+//	nsqdtcpaddr := "47.92.249.239:9150"
+//	//nsqdtcpaddr := "127.0.0.1:4150"
+//	producer, _ = nsq.NewProducer(nsqdtcpaddr, cfg)
+//	now := gtime.Now().String()
+//	//data := `{"operation_type":"1","sign_type":"1","mac":"33343538","device_type":"2","upload_time":"`+now+`","tenant":"CU7zm9WhZm","data":{"socket":"01","socket_hole":"01","uuid":"1394819d","operate":"01"}}`
+//	data := `{"operation_type":"1","sign_type":"1","tenant":"vojPzh3Ct9","mac":"1181","device_type":"","upload_time":"`+now+`","uuid":"uuid","data":{"socket":"30303030","socket_hole":"01","uuid":"ab077b7b","operate":"01","last_time":""}}`
+//	//data := `{"operation_type":"1","sign_type":"2","tenant":"CU7zm9WhZm","mac":"33343538","device_type":"2","ad_time":"`+now+`","data":{"socket":"01","socket_hole":"01","uuid":"ab077b7b","operate":"01"}}`
+//	producer.Publish("socket02_cmd", []byte(data))
+//}

+ 64 - 0
service/equipment_three.go

@@ -0,0 +1,64 @@
+package service
+
+import (
+	"context"
+	"lims_zju/common"
+	"lims_zju/model"
+)
+
+type DataStatistics struct{}
+
+//設備列表信息
+func (d *DataStatistics) GetDataModel(ctx context.Context, req *model.DataModel) ([]model.DataModel, error) {
+	list := make([]model.DataModel, 0)
+	err := common.ReadJson(&list, "data", "common/data3.json")
+	if err != nil {
+		return nil, err
+	}
+	return list, nil
+}
+
+//設備詳細信息
+func (d *DataStatistics) GetDataStatistics(ctx context.Context, req *model.DataModel) (*model.EquipmentStatistics, error) {
+	list := make([]model.EquipmentStatistics, 0)
+	err := common.ReadJson(&list, "equipment_statistics", "common/data3.json")
+	if err != nil {
+		return nil, err
+	}
+	for _, v := range list {
+		if v.EquipmentCode == req.EquipmentCode {
+			return &v, nil
+		}
+	}
+	return nil, nil
+}
+
+//設備狀態統計
+func (d *DataStatistics) GetDataStatus(ctx context.Context, req *model.DataModel) (*model.EquipmentStatusStatistics, error) {
+	entity := new(model.EquipmentStatusStatistics)
+	err := common.ReadJson(entity, "equipment_status", "common/data3.json")
+	if err != nil {
+		return nil, err
+	}
+	return entity, nil
+}
+
+//報警統計
+func (d *DataStatistics) GetDataAlarm(ctx context.Context, req *model.DataModel) ([]model.AlarmTatistics, error) {
+	list := make([]model.AlarmTatistics, 0)
+	err := common.ReadJson(&list, "alarm_statistics", "common/data3.json")
+	if err != nil {
+		return nil, err
+	}
+	return list, nil
+}
+
+//監控統計
+func (d *DataStatistics) GetDataMonitoring(ctx context.Context, req *model.DataModel) ([]model.MonitoringTypeStatistics, error) {
+	list := make([]model.MonitoringTypeStatistics, 0)
+	err := common.ReadJson(&list, "monitoring_type_statistics", "common/data3.json")
+	if err != nil {
+		return nil, err
+	}
+	return list, nil
+}

+ 54 - 0
service/platform.go

@@ -0,0 +1,54 @@
+package service
+
+import (
+	"context"
+	"lims_zju/common"
+	"lims_zju/model"
+)
+
+type Platform struct{}
+
+func (p *Platform) GetScaleTotal(ctx context.Context) (*model.ScaleTotal, error) {
+	entity := new(model.ScaleTotal)
+	err := common.ReadJson(entity, "scale", "common/data2.json")
+	if err != nil {
+		return nil, err
+	}
+	return entity, nil
+}
+
+func (p *Platform) GetSubjectTotal(ctx context.Context) ([]model.SubjectTotal, error) {
+	entity := make([]model.SubjectTotal, 0)
+	err := common.ReadJson(&entity, "subject", "common/data2.json")
+	if err != nil {
+		return nil, err
+	}
+	return entity, nil
+}
+
+func (p *Platform) GetResultStatistics(ctx context.Context) ([]model.ResultStatistics, error) {
+	entity := make([]model.ResultStatistics, 0)
+	err := common.ReadJson(&entity, "result_statistics", "common/data2.json")
+	if err != nil {
+		return nil, err
+	}
+	return entity, nil
+}
+
+func (p *Platform) GetResult(ctx context.Context) ([]model.Result, error) {
+	entity := make([]model.Result, 0)
+	err := common.ReadJson(&entity, "result", "common/data2.json")
+	if err != nil {
+		return nil, err
+	}
+	return entity, nil
+}
+
+func (p *Platform) GetMessage(ctx context.Context) ([]model.Message, error) {
+	entity := make([]model.Message, 0)
+	err := common.ReadJson(&entity, "message", "common/data2.json")
+	if err != nil {
+		return nil, err
+	}
+	return entity, nil
+}