feat:自动化控制检索
This commit is contained in:
parent
2ed446c84b
commit
e6179bfaa0
34
goadmin/env_monitor/env_monitor_device_sensor.yaml
Normal file
34
goadmin/env_monitor/env_monitor_device_sensor.yaml
Normal file
@ -0,0 +1,34 @@
|
||||
- name: EnvMonitorDeviceSensor
|
||||
comment: 设备传感器表
|
||||
disable_pagination: false
|
||||
fill_gorm_commit: true
|
||||
fill_router_prefix: true
|
||||
fields:
|
||||
- name: EnvMonitorDeviceID
|
||||
type: int64
|
||||
comment: 环境监测设备ID
|
||||
gorm_tag: "index"
|
||||
form:
|
||||
binding_tag: "required"
|
||||
- name: TenantID
|
||||
type: string
|
||||
comment: 租户ID
|
||||
gorm_tag: "size:36"
|
||||
form:
|
||||
binding_tag: "required,max=36"
|
||||
- name: Name
|
||||
type: string
|
||||
comment: 传感器名称
|
||||
gorm_tag: "size:64"
|
||||
form:
|
||||
binding_tag: "required,max=64"
|
||||
- name: Status
|
||||
type: bool
|
||||
comment: 传感器状态(true=正常,false=异常)
|
||||
form:
|
||||
binding_tag: "required"
|
||||
- name: CurrentValue
|
||||
type: float64
|
||||
comment: 当前值
|
||||
form:
|
||||
binding_tag: "required"
|
65
goadmin/env_monitor/env_monitor_device_warning_log.yaml
Normal file
65
goadmin/env_monitor/env_monitor_device_warning_log.yaml
Normal file
@ -0,0 +1,65 @@
|
||||
- name: EnvMonitorDeviceWarningLog
|
||||
comment: 环境监测设备报警日志
|
||||
disable_pagination: false
|
||||
fill_gorm_commit: true
|
||||
fill_router_prefix: true
|
||||
fields:
|
||||
- name: TenantID
|
||||
type: string
|
||||
comment: 租户ID
|
||||
gorm_tag: "size:32"
|
||||
form:
|
||||
binding_tag: "required,max=32"
|
||||
- name: DeviceID
|
||||
type: string
|
||||
comment: 设备ID
|
||||
gorm_tag: "size:32"
|
||||
form:
|
||||
binding_tag: "required,max=32"
|
||||
- name: DeviceModel
|
||||
type: string
|
||||
comment: 设备型号
|
||||
gorm_tag: "size:64"
|
||||
form:
|
||||
binding_tag: "required,max=64"
|
||||
- name: DeviceName
|
||||
type: string
|
||||
comment: 设备名称
|
||||
gorm_tag: "size:64"
|
||||
form:
|
||||
binding_tag: "required,max=64"
|
||||
- name: RelatedPondIds
|
||||
type: string
|
||||
comment: 关联鱼池/车间ID
|
||||
gorm_tag: "type:text"
|
||||
form:
|
||||
binding_tag: "required"
|
||||
- name: RelatedPond
|
||||
type: string
|
||||
comment: 关联鱼池/车间
|
||||
gorm_tag: "type:text"
|
||||
form:
|
||||
binding_tag: "required"
|
||||
- name: Type
|
||||
type: string
|
||||
comment: 报警指标
|
||||
gorm_tag: "size:255"
|
||||
form:
|
||||
binding_tag: "required,max=255"
|
||||
- name: StandardRange
|
||||
type: string
|
||||
comment: 参考数值范围
|
||||
gorm_tag: "size:255"
|
||||
form:
|
||||
binding_tag: "required,max=255"
|
||||
- name: CurrentValue
|
||||
type: float64
|
||||
comment: 当前数值
|
||||
gorm_tag: "type:decimal(5,2)"
|
||||
form:
|
||||
binding_tag: "required"
|
||||
- name: WarningType
|
||||
type: int
|
||||
comment: 1偏高 2偏低
|
||||
form:
|
||||
binding_tag: "required"
|
@ -33,8 +33,8 @@ func (a *Device) Query(ctx context.Context, params schema.DeviceQueryParam, opts
|
||||
ctx = gormx.WithTenantID(ctx, consts.DefaultTenantID)
|
||||
db := GetDeviceDB(ctx, a.DB)
|
||||
db = db.Preload("DeviceFishPonds").Preload("DeviceConfigAeration").Preload("DeviceConfigFeeding").Preload("DeviceConfigWaterCirculation")
|
||||
if params.Name != "" {
|
||||
db = db.Where("name like ?", "%"+params.Name+"%")
|
||||
if params.DeviceName != "" {
|
||||
db = db.Where("name like ?", "%"+params.DeviceName+"%")
|
||||
}
|
||||
if params.Type != nil && *params.Type != 0 {
|
||||
db = db.Where("type=?", *params.Type)
|
||||
|
@ -36,8 +36,8 @@ type Device struct {
|
||||
// Defining the query parameters for the `Device` struct.
|
||||
type DeviceQueryParam struct {
|
||||
util.PaginationParam
|
||||
Name string `form:"name"`
|
||||
Type *int `form:"type"`
|
||||
DeviceName string `form:"device_name"`
|
||||
Type *int `form:"type"`
|
||||
}
|
||||
|
||||
// Defining the query options for the `Device` struct.
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type DeviceRunLog struct {
|
||||
ID int64 `json:"id" gorm:"primaryKey;autoIncrement;comment:Unique ID;"` // Unique ID
|
||||
TenantID string `json:"tenant_id" gorm:"size:32;"` // Tenant ID
|
||||
DeviceID string `json:"device_id" gorm:"size:32;index;comment:设备ID;"` // 设备ID
|
||||
DeviceID int64 `json:"device_id" gorm:"index;comment:设备ID;"` // 设备ID
|
||||
DeviceModel string `json:"device_model" gorm:"size:64;comment:设备型号;"` // 设备型号
|
||||
DeviceName string `json:"device_name" gorm:"size:64;comment:设备名称;"` // 设备名称
|
||||
RelatedPondIds string `json:"related_pond_ids" gorm:"type:text;comment:关联鱼池/车间ID;"` // 关联鱼池/车间ID
|
||||
@ -47,7 +47,7 @@ type DeviceRunLogs []*DeviceRunLog
|
||||
// Defining the data structure for creating a `DeviceRunLog` struct.
|
||||
type DeviceRunLogForm struct {
|
||||
TenantID string `json:"tenant_id"` // 租户ID
|
||||
DeviceID string `json:"device_id" binding:"required,max=32"` // 设备ID
|
||||
DeviceID int64 `json:"device_id" binding:"required"` // 设备ID
|
||||
DeviceModel string `json:"device_model" binding:"required,max=64"` // 设备型号
|
||||
DeviceName string `json:"device_name" binding:"required,max=64"` // 设备名称
|
||||
RelatedPondIds string `json:"related_pond_ids" binding:"required"` // 关联鱼池/车间ID
|
||||
|
132
internal/mods/envmonitor/api/env_monitor_device_sensor.api.go
Normal file
132
internal/mods/envmonitor/api/env_monitor_device_sensor.api.go
Normal file
@ -0,0 +1,132 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ifms/internal/mods/envmonitor/biz"
|
||||
"ifms/internal/mods/envmonitor/schema"
|
||||
"ifms/pkg/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 设备传感器表
|
||||
type EnvMonitorDeviceSensor struct {
|
||||
EnvMonitorDeviceSensorBIZ *biz.EnvMonitorDeviceSensor
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceSensorAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Query env monitor device sensor list
|
||||
// @Param current query int true "pagination index" default(1)
|
||||
// @Param pageSize query int true "pagination size" default(10)
|
||||
// @Success 200 {object} util.ResponseResult{data=[]schema.EnvMonitorDeviceSensor}
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-sensors [get]
|
||||
func (a *EnvMonitorDeviceSensor) Query(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
var params schema.EnvMonitorDeviceSensorQueryParam
|
||||
if err := util.ParseQuery(c, ¶ms); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := a.EnvMonitorDeviceSensorBIZ.Query(ctx, params)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResPage(c, result.Data, result.PageResult)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceSensorAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Get env monitor device sensor record by ID
|
||||
// @Param id path string true "unique id"
|
||||
// @Success 200 {object} util.ResponseResult{data=schema.EnvMonitorDeviceSensor}
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-sensors/{id} [get]
|
||||
func (a *EnvMonitorDeviceSensor) Get(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
item, err := a.EnvMonitorDeviceSensorBIZ.Get(ctx, c.Param("id"))
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResSuccess(c, item)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceSensorAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Create env monitor device sensor record
|
||||
// @Param body body schema.EnvMonitorDeviceSensorForm true "Request body"
|
||||
// @Success 200 {object} util.ResponseResult{data=schema.EnvMonitorDeviceSensor}
|
||||
// @Failure 400 {object} util.ResponseResult
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-sensors [post]
|
||||
func (a *EnvMonitorDeviceSensor) Create(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
item := new(schema.EnvMonitorDeviceSensorForm)
|
||||
if err := util.ParseJSON(c, item); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
} else if err := item.Validate(); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := a.EnvMonitorDeviceSensorBIZ.Create(ctx, item)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResSuccess(c, result)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceSensorAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Update env monitor device sensor record by ID
|
||||
// @Param id path string true "unique id"
|
||||
// @Param body body schema.EnvMonitorDeviceSensorForm true "Request body"
|
||||
// @Success 200 {object} util.ResponseResult
|
||||
// @Failure 400 {object} util.ResponseResult
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-sensors/{id} [put]
|
||||
func (a *EnvMonitorDeviceSensor) Update(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
item := new(schema.EnvMonitorDeviceSensorForm)
|
||||
if err := util.ParseJSON(c, item); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
} else if err := item.Validate(); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err := a.EnvMonitorDeviceSensorBIZ.Update(ctx, c.Param("id"), item)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResOK(c)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceSensorAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Delete env monitor device sensor record by ID
|
||||
// @Param id path string true "unique id"
|
||||
// @Success 200 {object} util.ResponseResult
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-sensors/{id} [delete]
|
||||
func (a *EnvMonitorDeviceSensor) Delete(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
err := a.EnvMonitorDeviceSensorBIZ.Delete(ctx, c.Param("id"))
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResOK(c)
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ifms/internal/mods/envmonitor/biz"
|
||||
"ifms/internal/mods/envmonitor/schema"
|
||||
"ifms/pkg/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 环境监测设备报警范围配置表
|
||||
type EnvMonitorDeviceWarningConfig struct {
|
||||
EnvMonitorDeviceWarningConfigBIZ *biz.EnvMonitorDeviceWarningConfig
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningConfigAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Query env monitor device warning config list
|
||||
// @Param current query int true "pagination index" default(1)
|
||||
// @Param pageSize query int true "pagination size" default(10)
|
||||
// @Success 200 {object} util.ResponseResult{data=[]schema.EnvMonitorDeviceWarningConfig}
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-configs [get]
|
||||
func (a *EnvMonitorDeviceWarningConfig) Query(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
var params schema.EnvMonitorDeviceWarningConfigQueryParam
|
||||
if err := util.ParseQuery(c, ¶ms); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := a.EnvMonitorDeviceWarningConfigBIZ.Query(ctx, params)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResPage(c, result.Data, result.PageResult)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningConfigAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Get env monitor device warning config record by ID
|
||||
// @Param id path string true "unique id"
|
||||
// @Success 200 {object} util.ResponseResult{data=schema.EnvMonitorDeviceWarningConfig}
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-configs/{id} [get]
|
||||
func (a *EnvMonitorDeviceWarningConfig) Get(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
item, err := a.EnvMonitorDeviceWarningConfigBIZ.Get(ctx, c.Param("id"))
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResSuccess(c, item)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningConfigAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Create env monitor device warning config record
|
||||
// @Param body body schema.EnvMonitorDeviceWarningConfigForm true "Request body"
|
||||
// @Success 200 {object} util.ResponseResult{data=schema.EnvMonitorDeviceWarningConfig}
|
||||
// @Failure 400 {object} util.ResponseResult
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-configs [post]
|
||||
func (a *EnvMonitorDeviceWarningConfig) Create(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
item := new(schema.EnvMonitorDeviceWarningConfigForm)
|
||||
if err := util.ParseJSON(c, item); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
} else if err := item.Validate(); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
user := util.FromLoginUser(ctx)
|
||||
item.TenantID = user.TenantID
|
||||
result, err := a.EnvMonitorDeviceWarningConfigBIZ.Create(ctx, item)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResSuccess(c, result)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningConfigAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Update env monitor device warning config record by ID
|
||||
// @Param id path string true "unique id"
|
||||
// @Param body body schema.EnvMonitorDeviceWarningConfigForm true "Request body"
|
||||
// @Success 200 {object} util.ResponseResult
|
||||
// @Failure 400 {object} util.ResponseResult
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-configs/{id} [put]
|
||||
func (a *EnvMonitorDeviceWarningConfig) Update(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
item := new(schema.EnvMonitorDeviceWarningConfigForm)
|
||||
if err := util.ParseJSON(c, item); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
} else if err := item.Validate(); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
user := util.FromLoginUser(ctx)
|
||||
item.TenantID = user.TenantID
|
||||
err := a.EnvMonitorDeviceWarningConfigBIZ.Update(ctx, c.Param("id"), item)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResOK(c)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningConfigAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Delete env monitor device warning config record by ID
|
||||
// @Param id path string true "unique id"
|
||||
// @Success 200 {object} util.ResponseResult
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-configs/{id} [delete]
|
||||
func (a *EnvMonitorDeviceWarningConfig) Delete(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
err := a.EnvMonitorDeviceWarningConfigBIZ.Delete(ctx, c.Param("id"))
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResOK(c)
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ifms/internal/mods/envmonitor/biz"
|
||||
"ifms/internal/mods/envmonitor/schema"
|
||||
"ifms/pkg/util"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// 环境监测设备报警日志
|
||||
type EnvMonitorDeviceWarningLog struct {
|
||||
EnvMonitorDeviceWarningLogBIZ *biz.EnvMonitorDeviceWarningLog
|
||||
}
|
||||
|
||||
// 导出
|
||||
// @Tags EnvMonitorDeviceWarningLogAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Export env monitor device warning log list
|
||||
// @Param body body schema.EnvMonitorDeviceWarningLogQueryParam true "Request body"
|
||||
// @Success 200 {object} util.ResponseResult{data=[]schema.EnvMonitorDeviceWarningLogExport}
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-logs/export [post]
|
||||
func (a *EnvMonitorDeviceWarningLog) Export(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
var params schema.EnvMonitorDeviceWarningLogQueryParam
|
||||
if err := util.ParseQuery(c, ¶ms); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := a.EnvMonitorDeviceWarningLogBIZ.All(ctx, params)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
// 生成excel
|
||||
title := []string{"序号", "设备名称", "设备类型", "关联鱼池/车间", "报警指标", "监测数据", "参考数值范围", "报警模式", "报警时间"}
|
||||
data := make([][]string, len(result))
|
||||
for i, item := range result {
|
||||
data[i] = []string{strconv.Itoa(i + 1), item.DeviceName, item.DeviceModel, item.RelatedPond, item.Type, fmt.Sprintf("%.2f", item.CurrentValue), item.StandardRange, cast.ToString(item.WarningType), item.CreatedAt.Format("2006-01-02 15:04:05")}
|
||||
}
|
||||
localFilePath := "./export" + cast.ToString(time.Now().Format("20060102150405")) + ".xlsx"
|
||||
objName := "export/excel/" + cast.ToString(time.Now().Format("20060102150405")) + ".xlsx"
|
||||
url, err := util.ExportDataToOSS(ctx, title, data, localFilePath, objName)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResSuccess(c, schema.EnvMonitorDeviceWarningLogExport{
|
||||
Url: url,
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningLogAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Query env monitor device warning log list
|
||||
// @Param current query int true "pagination index" default(1)
|
||||
// @Param pageSize query int true "pagination size" default(10)
|
||||
// @Success 200 {object} util.ResponseResult{data=[]schema.EnvMonitorDeviceWarningLog}
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-logs [get]
|
||||
func (a *EnvMonitorDeviceWarningLog) Query(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
var params schema.EnvMonitorDeviceWarningLogQueryParam
|
||||
if err := util.ParseQuery(c, ¶ms); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := a.EnvMonitorDeviceWarningLogBIZ.Query(ctx, params)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResPage(c, result.Data, result.PageResult)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningLogAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Get env monitor device warning log record by ID
|
||||
// @Param id path string true "unique id"
|
||||
// @Success 200 {object} util.ResponseResult{data=schema.EnvMonitorDeviceWarningLog}
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-logs/{id} [get]
|
||||
func (a *EnvMonitorDeviceWarningLog) Get(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
item, err := a.EnvMonitorDeviceWarningLogBIZ.Get(ctx, c.Param("id"))
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResSuccess(c, item)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningLogAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Create env monitor device warning log record
|
||||
// @Param body body schema.EnvMonitorDeviceWarningLogForm true "Request body"
|
||||
// @Success 200 {object} util.ResponseResult{data=schema.EnvMonitorDeviceWarningLog}
|
||||
// @Failure 400 {object} util.ResponseResult
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-logs [post]
|
||||
func (a *EnvMonitorDeviceWarningLog) Create(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
item := new(schema.EnvMonitorDeviceWarningLogForm)
|
||||
if err := util.ParseJSON(c, item); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
} else if err := item.Validate(); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
user := util.FromLoginUser(ctx)
|
||||
item.TenantID = user.TenantID
|
||||
|
||||
result, err := a.EnvMonitorDeviceWarningLogBIZ.Create(ctx, item)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResSuccess(c, result)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningLogAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Update env monitor device warning log record by ID
|
||||
// @Param id path string true "unique id"
|
||||
// @Param body body schema.EnvMonitorDeviceWarningLogForm true "Request body"
|
||||
// @Success 200 {object} util.ResponseResult
|
||||
// @Failure 400 {object} util.ResponseResult
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-logs/{id} [put]
|
||||
func (a *EnvMonitorDeviceWarningLog) Update(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
item := new(schema.EnvMonitorDeviceWarningLogForm)
|
||||
if err := util.ParseJSON(c, item); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
} else if err := item.Validate(); err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err := a.EnvMonitorDeviceWarningLogBIZ.Update(ctx, c.Param("id"), item)
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResOK(c)
|
||||
}
|
||||
|
||||
// @Tags EnvMonitorDeviceWarningLogAPI
|
||||
// @Security ApiKeyAuth
|
||||
// @Summary Delete env monitor device warning log record by ID
|
||||
// @Param id path string true "unique id"
|
||||
// @Success 200 {object} util.ResponseResult
|
||||
// @Failure 401 {object} util.ResponseResult
|
||||
// @Failure 500 {object} util.ResponseResult
|
||||
// @Router /api/v1/envmonitor/env-monitor-device-warning-logs/{id} [delete]
|
||||
func (a *EnvMonitorDeviceWarningLog) Delete(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
err := a.EnvMonitorDeviceWarningLogBIZ.Delete(ctx, c.Param("id"))
|
||||
if err != nil {
|
||||
util.ResError(c, err)
|
||||
return
|
||||
}
|
||||
util.ResOK(c)
|
||||
}
|
@ -17,6 +17,7 @@ type EnvMonitorDevice struct {
|
||||
Trans *util.Trans
|
||||
EnvMonitorDeviceDAL *dal.EnvMonitorDevice
|
||||
EnvMonitorDeviceFishPondDAL *dal.EnvMonitorDeviceFishPond
|
||||
EnvMonitorDeviceSensorDAL *dal.EnvMonitorDeviceSensor
|
||||
}
|
||||
|
||||
// Query env monitor devices from the data access object based on the provided parameters and options.
|
||||
@ -62,6 +63,7 @@ func (a *EnvMonitorDevice) Create(ctx context.Context, formItem *schema.EnvMonit
|
||||
if err := a.EnvMonitorDeviceDAL.Create(ctx, envMonitorDevice); err != nil {
|
||||
return err
|
||||
}
|
||||
// 关联鱼池
|
||||
if len(formItem.EnvMonitorDeviceDeviceFishPonds) > 0 {
|
||||
for _, fishPond := range formItem.EnvMonitorDeviceDeviceFishPonds {
|
||||
deviceFishPond := &schema.EnvMonitorDeviceFishPond{
|
||||
@ -75,6 +77,22 @@ func (a *EnvMonitorDevice) Create(ctx context.Context, formItem *schema.EnvMonit
|
||||
}
|
||||
}
|
||||
}
|
||||
// 关联传感器
|
||||
if len(formItem.EnvMonitorDeviceDeviceSensors) > 0 {
|
||||
for _, sensor := range formItem.EnvMonitorDeviceDeviceSensors {
|
||||
deviceSensor := &schema.EnvMonitorDeviceSensor{
|
||||
EnvMonitorDeviceID: envMonitorDevice.ID,
|
||||
Name: sensor.Name,
|
||||
Status: sensor.Status,
|
||||
CurrentValue: sensor.CurrentValue,
|
||||
TenantID: envMonitorDevice.TenantID,
|
||||
Type: sensor.Type,
|
||||
}
|
||||
if err := a.EnvMonitorDeviceSensorDAL.Create(ctx, deviceSensor); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@ -119,6 +137,26 @@ func (a *EnvMonitorDevice) Update(ctx context.Context, id string, formItem *sche
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 关联传感器
|
||||
if err := a.EnvMonitorDeviceSensorDAL.DeleteByDeviceID(ctx, envMonitorDevice.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(formItem.EnvMonitorDeviceDeviceSensors) > 0 {
|
||||
for _, sensor := range formItem.EnvMonitorDeviceDeviceSensors {
|
||||
deviceSensor := &schema.EnvMonitorDeviceSensor{
|
||||
EnvMonitorDeviceID: envMonitorDevice.ID,
|
||||
Name: sensor.Name,
|
||||
Status: sensor.Status,
|
||||
CurrentValue: sensor.CurrentValue,
|
||||
TenantID: envMonitorDevice.TenantID,
|
||||
Type: sensor.Type,
|
||||
}
|
||||
if err := a.EnvMonitorDeviceSensorDAL.Create(ctx, deviceSensor); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
106
internal/mods/envmonitor/biz/env_monitor_device_sensor.biz.go
Normal file
106
internal/mods/envmonitor/biz/env_monitor_device_sensor.biz.go
Normal file
@ -0,0 +1,106 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"ifms/internal/mods/envmonitor/dal"
|
||||
"ifms/internal/mods/envmonitor/schema"
|
||||
"ifms/pkg/errors"
|
||||
"ifms/pkg/util"
|
||||
)
|
||||
|
||||
// 设备传感器表
|
||||
type EnvMonitorDeviceSensor struct {
|
||||
Trans *util.Trans
|
||||
EnvMonitorDeviceSensorDAL *dal.EnvMonitorDeviceSensor
|
||||
}
|
||||
|
||||
// Query env monitor device sensors from the data access object based on the provided parameters and options.
|
||||
func (a *EnvMonitorDeviceSensor) Query(ctx context.Context, params schema.EnvMonitorDeviceSensorQueryParam) (*schema.EnvMonitorDeviceSensorQueryResult, error) {
|
||||
params.Pagination = true
|
||||
|
||||
result, err := a.EnvMonitorDeviceSensorDAL.Query(ctx, params, schema.EnvMonitorDeviceSensorQueryOptions{
|
||||
QueryOptions: util.QueryOptions{
|
||||
OrderFields: []util.OrderByParam{
|
||||
{Field: "created_at", Direction: util.DESC},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Get the specified env monitor device sensor from the data access object.
|
||||
func (a *EnvMonitorDeviceSensor) Get(ctx context.Context, id string) (*schema.EnvMonitorDeviceSensor, error) {
|
||||
envMonitorDeviceSensor, err := a.EnvMonitorDeviceSensorDAL.Get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if envMonitorDeviceSensor == nil {
|
||||
return nil, errors.NotFound("", "Env monitor device sensor not found")
|
||||
}
|
||||
return envMonitorDeviceSensor, nil
|
||||
}
|
||||
|
||||
// Create a new env monitor device sensor in the data access object.
|
||||
func (a *EnvMonitorDeviceSensor) Create(ctx context.Context, formItem *schema.EnvMonitorDeviceSensorForm) (*schema.EnvMonitorDeviceSensor, error) {
|
||||
envMonitorDeviceSensor := &schema.EnvMonitorDeviceSensor{
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
if err := formItem.FillTo(envMonitorDeviceSensor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err := a.Trans.Exec(ctx, func(ctx context.Context) error {
|
||||
if err := a.EnvMonitorDeviceSensorDAL.Create(ctx, envMonitorDeviceSensor); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return envMonitorDeviceSensor, nil
|
||||
}
|
||||
|
||||
// Update the specified env monitor device sensor in the data access object.
|
||||
func (a *EnvMonitorDeviceSensor) Update(ctx context.Context, id string, formItem *schema.EnvMonitorDeviceSensorForm) error {
|
||||
envMonitorDeviceSensor, err := a.EnvMonitorDeviceSensorDAL.Get(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if envMonitorDeviceSensor == nil {
|
||||
return errors.NotFound("", "Env monitor device sensor not found")
|
||||
}
|
||||
|
||||
if err := formItem.FillTo(envMonitorDeviceSensor); err != nil {
|
||||
return err
|
||||
}
|
||||
envMonitorDeviceSensor.UpdatedAt = time.Now()
|
||||
|
||||
return a.Trans.Exec(ctx, func(ctx context.Context) error {
|
||||
if err := a.EnvMonitorDeviceSensorDAL.Update(ctx, envMonitorDeviceSensor); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Delete the specified env monitor device sensor from the data access object.
|
||||
func (a *EnvMonitorDeviceSensor) Delete(ctx context.Context, id string) error {
|
||||
exists, err := a.EnvMonitorDeviceSensorDAL.Exists(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !exists {
|
||||
return errors.NotFound("", "Env monitor device sensor not found")
|
||||
}
|
||||
|
||||
return a.Trans.Exec(ctx, func(ctx context.Context) error {
|
||||
if err := a.EnvMonitorDeviceSensorDAL.Delete(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"ifms/internal/mods/envmonitor/dal"
|
||||
"ifms/internal/mods/envmonitor/schema"
|
||||
"ifms/pkg/errors"
|
||||
"ifms/pkg/util"
|
||||
)
|
||||
|
||||
// 环境监测设备报警范围配置表
|
||||
type EnvMonitorDeviceWarningConfig struct {
|
||||
Trans *util.Trans
|
||||
EnvMonitorDeviceWarningConfigDAL *dal.EnvMonitorDeviceWarningConfig
|
||||
}
|
||||
|
||||
// Query env monitor device warning configs from the data access object based on the provided parameters and options.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Query(ctx context.Context, params schema.EnvMonitorDeviceWarningConfigQueryParam) (*schema.EnvMonitorDeviceWarningConfigQueryResult, error) {
|
||||
params.Pagination = true
|
||||
|
||||
result, err := a.EnvMonitorDeviceWarningConfigDAL.Query(ctx, params, schema.EnvMonitorDeviceWarningConfigQueryOptions{
|
||||
QueryOptions: util.QueryOptions{
|
||||
OrderFields: []util.OrderByParam{
|
||||
{Field: "created_at", Direction: util.DESC},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Get the specified env monitor device warning config from the data access object.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Get(ctx context.Context, id string) (*schema.EnvMonitorDeviceWarningConfig, error) {
|
||||
envMonitorDeviceWarningConfig, err := a.EnvMonitorDeviceWarningConfigDAL.Get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if envMonitorDeviceWarningConfig == nil {
|
||||
return nil, errors.NotFound("", "Env monitor device warning config not found")
|
||||
}
|
||||
return envMonitorDeviceWarningConfig, nil
|
||||
}
|
||||
|
||||
// Create a new env monitor device warning config in the data access object.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Create(ctx context.Context, formItem *schema.EnvMonitorDeviceWarningConfigForm) (*schema.EnvMonitorDeviceWarningConfig, error) {
|
||||
envMonitorDeviceWarningConfig := &schema.EnvMonitorDeviceWarningConfig{
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
if err := formItem.FillTo(envMonitorDeviceWarningConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err := a.Trans.Exec(ctx, func(ctx context.Context) error {
|
||||
if err := a.EnvMonitorDeviceWarningConfigDAL.Create(ctx, envMonitorDeviceWarningConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return envMonitorDeviceWarningConfig, nil
|
||||
}
|
||||
|
||||
// Update the specified env monitor device warning config in the data access object.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Update(ctx context.Context, id string, formItem *schema.EnvMonitorDeviceWarningConfigForm) error {
|
||||
envMonitorDeviceWarningConfig, err := a.EnvMonitorDeviceWarningConfigDAL.Get(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if envMonitorDeviceWarningConfig == nil {
|
||||
return errors.NotFound("", "Env monitor device warning config not found")
|
||||
}
|
||||
|
||||
if err := formItem.FillTo(envMonitorDeviceWarningConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
envMonitorDeviceWarningConfig.UpdatedAt = time.Now()
|
||||
|
||||
return a.Trans.Exec(ctx, func(ctx context.Context) error {
|
||||
if err := a.EnvMonitorDeviceWarningConfigDAL.Update(ctx, envMonitorDeviceWarningConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Delete the specified env monitor device warning config from the data access object.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Delete(ctx context.Context, id string) error {
|
||||
exists, err := a.EnvMonitorDeviceWarningConfigDAL.Exists(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !exists {
|
||||
return errors.NotFound("", "Env monitor device warning config not found")
|
||||
}
|
||||
|
||||
return a.Trans.Exec(ctx, func(ctx context.Context) error {
|
||||
if err := a.EnvMonitorDeviceWarningConfigDAL.Delete(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"ifms/internal/mods/envmonitor/dal"
|
||||
"ifms/internal/mods/envmonitor/schema"
|
||||
"ifms/pkg/errors"
|
||||
"ifms/pkg/util"
|
||||
)
|
||||
|
||||
// 环境监测设备报警日志
|
||||
type EnvMonitorDeviceWarningLog struct {
|
||||
Trans *util.Trans
|
||||
EnvMonitorDeviceWarningLogDAL *dal.EnvMonitorDeviceWarningLog
|
||||
}
|
||||
|
||||
func (a *EnvMonitorDeviceWarningLog) All(ctx context.Context, params schema.EnvMonitorDeviceWarningLogQueryParam) ([]*schema.EnvMonitorDeviceWarningLog, error) {
|
||||
result, err := a.EnvMonitorDeviceWarningLogDAL.QueryAll(ctx, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Query env monitor device warning logs from the data access object based on the provided parameters and options.
|
||||
func (a *EnvMonitorDeviceWarningLog) Query(ctx context.Context, params schema.EnvMonitorDeviceWarningLogQueryParam) (*schema.EnvMonitorDeviceWarningLogQueryResult, error) {
|
||||
params.Pagination = true
|
||||
|
||||
result, err := a.EnvMonitorDeviceWarningLogDAL.Query(ctx, params, schema.EnvMonitorDeviceWarningLogQueryOptions{
|
||||
QueryOptions: util.QueryOptions{
|
||||
OrderFields: []util.OrderByParam{
|
||||
{Field: "created_at", Direction: util.DESC},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Get the specified env monitor device warning log from the data access object.
|
||||
func (a *EnvMonitorDeviceWarningLog) Get(ctx context.Context, id string) (*schema.EnvMonitorDeviceWarningLog, error) {
|
||||
envMonitorDeviceWarningLog, err := a.EnvMonitorDeviceWarningLogDAL.Get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if envMonitorDeviceWarningLog == nil {
|
||||
return nil, errors.NotFound("", "Env monitor device warning log not found")
|
||||
}
|
||||
return envMonitorDeviceWarningLog, nil
|
||||
}
|
||||
|
||||
// Create a new env monitor device warning log in the data access object.
|
||||
func (a *EnvMonitorDeviceWarningLog) Create(ctx context.Context, formItem *schema.EnvMonitorDeviceWarningLogForm) (*schema.EnvMonitorDeviceWarningLog, error) {
|
||||
envMonitorDeviceWarningLog := &schema.EnvMonitorDeviceWarningLog{
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
if err := formItem.FillTo(envMonitorDeviceWarningLog); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err := a.Trans.Exec(ctx, func(ctx context.Context) error {
|
||||
if err := a.EnvMonitorDeviceWarningLogDAL.Create(ctx, envMonitorDeviceWarningLog); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return envMonitorDeviceWarningLog, nil
|
||||
}
|
||||
|
||||
// Update the specified env monitor device warning log in the data access object.
|
||||
func (a *EnvMonitorDeviceWarningLog) Update(ctx context.Context, id string, formItem *schema.EnvMonitorDeviceWarningLogForm) error {
|
||||
envMonitorDeviceWarningLog, err := a.EnvMonitorDeviceWarningLogDAL.Get(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if envMonitorDeviceWarningLog == nil {
|
||||
return errors.NotFound("", "Env monitor device warning log not found")
|
||||
}
|
||||
|
||||
if err := formItem.FillTo(envMonitorDeviceWarningLog); err != nil {
|
||||
return err
|
||||
}
|
||||
envMonitorDeviceWarningLog.UpdatedAt = time.Now()
|
||||
|
||||
return a.Trans.Exec(ctx, func(ctx context.Context) error {
|
||||
if err := a.EnvMonitorDeviceWarningLogDAL.Update(ctx, envMonitorDeviceWarningLog); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Delete the specified env monitor device warning log from the data access object.
|
||||
func (a *EnvMonitorDeviceWarningLog) Delete(ctx context.Context, id string) error {
|
||||
exists, err := a.EnvMonitorDeviceWarningLogDAL.Exists(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !exists {
|
||||
return errors.NotFound("", "Env monitor device warning log not found")
|
||||
}
|
||||
|
||||
return a.Trans.Exec(ctx, func(ctx context.Context) error {
|
||||
if err := a.EnvMonitorDeviceWarningLogDAL.Delete(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
@ -31,7 +31,7 @@ func (a *EnvMonitorDevice) Query(ctx context.Context, params schema.EnvMonitorDe
|
||||
ctx = gormx.WithTenantID(ctx, consts.DefaultTenantID)
|
||||
|
||||
db := GetEnvMonitorDeviceDB(ctx, a.DB)
|
||||
db = db.Preload("EnvMonitorDeviceFishPond")
|
||||
db = db.Preload("EnvMonitorDeviceFishPond").Preload("EnvMonitorDeviceSensor")
|
||||
if params.Name != "" {
|
||||
db = db.Where("name like ?", "%"+params.Name+"%")
|
||||
}
|
||||
|
@ -0,0 +1,89 @@
|
||||
package dal
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"ifms/internal/mods/envmonitor/schema"
|
||||
"ifms/pkg/errors"
|
||||
"ifms/pkg/util"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Get env monitor device sensor storage instance
|
||||
func GetEnvMonitorDeviceSensorDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
|
||||
return util.GetDB(ctx, defDB).Model(new(schema.EnvMonitorDeviceSensor))
|
||||
}
|
||||
|
||||
// 设备传感器表
|
||||
type EnvMonitorDeviceSensor struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
// Query env monitor device sensors from the database based on the provided parameters and options.
|
||||
func (a *EnvMonitorDeviceSensor) Query(ctx context.Context, params schema.EnvMonitorDeviceSensorQueryParam, opts ...schema.EnvMonitorDeviceSensorQueryOptions) (*schema.EnvMonitorDeviceSensorQueryResult, error) {
|
||||
var opt schema.EnvMonitorDeviceSensorQueryOptions
|
||||
if len(opts) > 0 {
|
||||
opt = opts[0]
|
||||
}
|
||||
|
||||
db := GetEnvMonitorDeviceSensorDB(ctx, a.DB)
|
||||
|
||||
var list schema.EnvMonitorDeviceSensors
|
||||
pageResult, err := util.WrapPageQuery(ctx, db, params.PaginationParam, opt.QueryOptions, &list)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
queryResult := &schema.EnvMonitorDeviceSensorQueryResult{
|
||||
PageResult: pageResult,
|
||||
Data: list,
|
||||
}
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
// Get the specified env monitor device sensor from the database.
|
||||
func (a *EnvMonitorDeviceSensor) Get(ctx context.Context, id string, opts ...schema.EnvMonitorDeviceSensorQueryOptions) (*schema.EnvMonitorDeviceSensor, error) {
|
||||
var opt schema.EnvMonitorDeviceSensorQueryOptions
|
||||
if len(opts) > 0 {
|
||||
opt = opts[0]
|
||||
}
|
||||
|
||||
item := new(schema.EnvMonitorDeviceSensor)
|
||||
ok, err := util.FindOne(ctx, GetEnvMonitorDeviceSensorDB(ctx, a.DB).Where("id=?", id), opt.QueryOptions, item)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
} else if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// Exists checks if the specified env monitor device sensor exists in the database.
|
||||
func (a *EnvMonitorDeviceSensor) Exists(ctx context.Context, id string) (bool, error) {
|
||||
ok, err := util.Exists(ctx, GetEnvMonitorDeviceSensorDB(ctx, a.DB).Where("id=?", id))
|
||||
return ok, errors.WithStack(err)
|
||||
}
|
||||
|
||||
// Create a new env monitor device sensor.
|
||||
func (a *EnvMonitorDeviceSensor) Create(ctx context.Context, item *schema.EnvMonitorDeviceSensor) error {
|
||||
result := GetEnvMonitorDeviceSensorDB(ctx, a.DB).Create(item)
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
||||
|
||||
// Update the specified env monitor device sensor in the database.
|
||||
func (a *EnvMonitorDeviceSensor) Update(ctx context.Context, item *schema.EnvMonitorDeviceSensor) error {
|
||||
result := GetEnvMonitorDeviceSensorDB(ctx, a.DB).Where("id=?", item.ID).Select("*").Omit("created_at").Updates(item)
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
||||
|
||||
// Delete the specified env monitor device sensor from the database.
|
||||
func (a *EnvMonitorDeviceSensor) Delete(ctx context.Context, id string) error {
|
||||
result := GetEnvMonitorDeviceSensorDB(ctx, a.DB).Where("id=?", id).Delete(new(schema.EnvMonitorDeviceSensor))
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
||||
|
||||
func (a *EnvMonitorDeviceSensor) DeleteByDeviceID(ctx context.Context, deviceID int64) error {
|
||||
result := GetEnvMonitorDeviceFishPondDB(ctx, a.DB).Where("env_monitor_device_id=?", deviceID).Delete(new(schema.EnvMonitorDeviceFishPond))
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package dal
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"ifms/internal/consts"
|
||||
"ifms/internal/mods/envmonitor/schema"
|
||||
"ifms/pkg/errors"
|
||||
"ifms/pkg/gormx"
|
||||
"ifms/pkg/util"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Get env monitor device warning config storage instance
|
||||
func GetEnvMonitorDeviceWarningConfigDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
|
||||
return util.GetDB(ctx, defDB).Model(new(schema.EnvMonitorDeviceWarningConfig))
|
||||
}
|
||||
|
||||
// 环境监测设备报警范围配置表
|
||||
type EnvMonitorDeviceWarningConfig struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
// Query env monitor device warning configs from the database based on the provided parameters and options.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Query(ctx context.Context, params schema.EnvMonitorDeviceWarningConfigQueryParam, opts ...schema.EnvMonitorDeviceWarningConfigQueryOptions) (*schema.EnvMonitorDeviceWarningConfigQueryResult, error) {
|
||||
var opt schema.EnvMonitorDeviceWarningConfigQueryOptions
|
||||
if len(opts) > 0 {
|
||||
opt = opts[0]
|
||||
}
|
||||
ctx = gormx.WithTenantID(ctx, consts.DefaultTenantID)
|
||||
db := GetEnvMonitorDeviceWarningConfigDB(ctx, a.DB)
|
||||
|
||||
var list schema.EnvMonitorDeviceWarningConfigs
|
||||
pageResult, err := util.WrapPageQuery(ctx, db, params.PaginationParam, opt.QueryOptions, &list)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
queryResult := &schema.EnvMonitorDeviceWarningConfigQueryResult{
|
||||
PageResult: pageResult,
|
||||
Data: list,
|
||||
}
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
// Get the specified env monitor device warning config from the database.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Get(ctx context.Context, id string, opts ...schema.EnvMonitorDeviceWarningConfigQueryOptions) (*schema.EnvMonitorDeviceWarningConfig, error) {
|
||||
var opt schema.EnvMonitorDeviceWarningConfigQueryOptions
|
||||
if len(opts) > 0 {
|
||||
opt = opts[0]
|
||||
}
|
||||
|
||||
item := new(schema.EnvMonitorDeviceWarningConfig)
|
||||
ok, err := util.FindOne(ctx, GetEnvMonitorDeviceWarningConfigDB(ctx, a.DB).Where("id=?", id), opt.QueryOptions, item)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
} else if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// Exists checks if the specified env monitor device warning config exists in the database.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Exists(ctx context.Context, id string) (bool, error) {
|
||||
ok, err := util.Exists(ctx, GetEnvMonitorDeviceWarningConfigDB(ctx, a.DB).Where("id=?", id))
|
||||
return ok, errors.WithStack(err)
|
||||
}
|
||||
|
||||
// Create a new env monitor device warning config.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Create(ctx context.Context, item *schema.EnvMonitorDeviceWarningConfig) error {
|
||||
result := GetEnvMonitorDeviceWarningConfigDB(ctx, a.DB).Create(item)
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
||||
|
||||
// Update the specified env monitor device warning config in the database.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Update(ctx context.Context, item *schema.EnvMonitorDeviceWarningConfig) error {
|
||||
result := GetEnvMonitorDeviceWarningConfigDB(ctx, a.DB).Where("id=?", item.ID).Select("*").Omit("created_at").Updates(item)
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
||||
|
||||
// Delete the specified env monitor device warning config from the database.
|
||||
func (a *EnvMonitorDeviceWarningConfig) Delete(ctx context.Context, id string) error {
|
||||
result := GetEnvMonitorDeviceWarningConfigDB(ctx, a.DB).Where("id=?", id).Delete(new(schema.EnvMonitorDeviceWarningConfig))
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
@ -0,0 +1,235 @@
|
||||
package dal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"ifms/internal/consts"
|
||||
"ifms/internal/mods/envmonitor/schema"
|
||||
"ifms/pkg/errors"
|
||||
"ifms/pkg/gormx"
|
||||
"ifms/pkg/util"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Get env monitor device warning log storage instance
|
||||
func GetEnvMonitorDeviceWarningLogDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
|
||||
return util.GetDB(ctx, defDB).Model(new(schema.EnvMonitorDeviceWarningLog))
|
||||
}
|
||||
|
||||
// 环境监测设备报警日志
|
||||
type EnvMonitorDeviceWarningLog struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
// Query env monitor device warning logs from the database based on the provided parameters and options.
|
||||
func (a *EnvMonitorDeviceWarningLog) QueryAll(ctx context.Context, params schema.EnvMonitorDeviceWarningLogQueryParam) ([]*schema.EnvMonitorDeviceWarningLog, error) {
|
||||
ctx = gormx.WithTenantID(ctx, consts.DefaultTenantID)
|
||||
db := GetEnvMonitorDeviceWarningLogDB(ctx, a.DB)
|
||||
if params.DeviceName != "" {
|
||||
db = db.Where("device_name like ?", "%"+params.DeviceName+"%")
|
||||
}
|
||||
if params.StartTime != "" {
|
||||
db = db.Where("created_at >= ?", params.StartTime)
|
||||
}
|
||||
if params.EndTime != "" {
|
||||
db = db.Where("created_at <= ?", params.EndTime)
|
||||
}
|
||||
|
||||
var list []*schema.EnvMonitorDeviceWarningLog
|
||||
err := db.Find(&list).Error
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Query env monitor device warning logs from the database based on the provided parameters and options.
|
||||
func (a *EnvMonitorDeviceWarningLog) Query(ctx context.Context, params schema.EnvMonitorDeviceWarningLogQueryParam, opts ...schema.EnvMonitorDeviceWarningLogQueryOptions) (*schema.EnvMonitorDeviceWarningLogQueryResult, error) {
|
||||
var opt schema.EnvMonitorDeviceWarningLogQueryOptions
|
||||
if len(opts) > 0 {
|
||||
opt = opts[0]
|
||||
}
|
||||
ctx = gormx.WithTenantID(ctx, consts.DefaultTenantID)
|
||||
db := GetEnvMonitorDeviceWarningLogDB(ctx, a.DB)
|
||||
if params.DeviceName != "" {
|
||||
db = db.Where("device_name like ?", "%"+params.DeviceName+"%")
|
||||
}
|
||||
if params.StartTime != "" {
|
||||
db = db.Where("created_at >= ?", params.StartTime)
|
||||
}
|
||||
if params.EndTime != "" {
|
||||
db = db.Where("created_at <= ?", params.EndTime)
|
||||
}
|
||||
|
||||
var list schema.EnvMonitorDeviceWarningLogs
|
||||
pageResult, err := util.WrapPageQuery(ctx, db, params.PaginationParam, opt.QueryOptions, &list)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
queryResult := &schema.EnvMonitorDeviceWarningLogQueryResult{
|
||||
PageResult: pageResult,
|
||||
Data: list,
|
||||
}
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
// Get the specified env monitor device warning log from the database.
|
||||
func (a *EnvMonitorDeviceWarningLog) Get(ctx context.Context, id string, opts ...schema.EnvMonitorDeviceWarningLogQueryOptions) (*schema.EnvMonitorDeviceWarningLog, error) {
|
||||
var opt schema.EnvMonitorDeviceWarningLogQueryOptions
|
||||
if len(opts) > 0 {
|
||||
opt = opts[0]
|
||||
}
|
||||
|
||||
item := new(schema.EnvMonitorDeviceWarningLog)
|
||||
ok, err := util.FindOne(ctx, GetEnvMonitorDeviceWarningLogDB(ctx, a.DB).Where("id=?", id), opt.QueryOptions, item)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
} else if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// Exists checks if the specified env monitor device warning log exists in the database.
|
||||
func (a *EnvMonitorDeviceWarningLog) Exists(ctx context.Context, id string) (bool, error) {
|
||||
ok, err := util.Exists(ctx, GetEnvMonitorDeviceWarningLogDB(ctx, a.DB).Where("id=?", id))
|
||||
return ok, errors.WithStack(err)
|
||||
}
|
||||
|
||||
// Create a new env monitor device warning log.
|
||||
func (a *EnvMonitorDeviceWarningLog) Create(ctx context.Context, item *schema.EnvMonitorDeviceWarningLog) error {
|
||||
// 查询当前租户设置的值
|
||||
tenantID := item.TenantID
|
||||
envMonitorDeviceWarningConfig := &schema.EnvMonitorDeviceWarningConfig{}
|
||||
err := a.DB.Model(new(schema.EnvMonitorDeviceWarningConfig)).Where("tenant_id=?", tenantID).First(envMonitorDeviceWarningConfig).Error
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
if envMonitorDeviceWarningConfig.ID == 0 {
|
||||
return errors.New("env monitor device warning config not found", "env monitor device warning config not found", 400)
|
||||
}
|
||||
// 查询设备传感器
|
||||
envMonitorDeviceSensor := &schema.EnvMonitorDeviceSensor{}
|
||||
err = a.DB.Model(new(schema.EnvMonitorDeviceSensor)).Where("id=?", item.EnvMonitorDeviceSensorID).First(envMonitorDeviceSensor).Error
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
if envMonitorDeviceSensor.ID == 0 {
|
||||
return errors.New("env monitor device sensor not found", "env monitor device sensor not found", 400)
|
||||
}
|
||||
item.IsOk = true
|
||||
typeStr := ""
|
||||
switch envMonitorDeviceSensor.Type {
|
||||
case 1:
|
||||
typeStr = "水温"
|
||||
case 2:
|
||||
typeStr = "电导率"
|
||||
case 3:
|
||||
typeStr = "氨氮"
|
||||
case 4:
|
||||
typeStr = "溶解氧"
|
||||
case 5:
|
||||
typeStr = "PH值"
|
||||
case 6:
|
||||
typeStr = "视频监控"
|
||||
}
|
||||
item.Type = typeStr
|
||||
// 水温
|
||||
if item.Type == "水温" {
|
||||
waterLower := envMonitorDeviceWarningConfig.WaterTempMin
|
||||
waterUpper := envMonitorDeviceWarningConfig.WaterTempMax
|
||||
item.StandardRange = fmt.Sprintf("%.2f-%.2f", waterLower, waterUpper)
|
||||
if item.CurrentValue < waterLower || item.CurrentValue > waterUpper {
|
||||
item.IsOk = false
|
||||
if item.CurrentValue > waterUpper {
|
||||
item.WarningType = 1
|
||||
}
|
||||
if item.CurrentValue < waterLower {
|
||||
item.WarningType = 2
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 电导率
|
||||
if item.Type == "电导率" {
|
||||
conductivityLower := envMonitorDeviceWarningConfig.ConductivityMin
|
||||
conductivityUpper := envMonitorDeviceWarningConfig.ConductivityMax
|
||||
// 数值保留两位小数
|
||||
item.StandardRange = fmt.Sprintf("%.2f-%.2f", conductivityLower, conductivityUpper)
|
||||
if item.CurrentValue < conductivityLower || item.CurrentValue > conductivityUpper {
|
||||
item.IsOk = false
|
||||
if item.CurrentValue > conductivityUpper {
|
||||
item.WarningType = 1
|
||||
}
|
||||
if item.CurrentValue < conductivityLower {
|
||||
item.WarningType = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
// 氨氮
|
||||
if item.Type == "氨氮" {
|
||||
ammoniaNitrogenLower := envMonitorDeviceWarningConfig.AmmoniaNitrogenMin
|
||||
ammoniaNitrogenUpper := envMonitorDeviceWarningConfig.AmmoniaNitrogenMax
|
||||
item.StandardRange = fmt.Sprintf("%.2f-%.2f", ammoniaNitrogenLower, ammoniaNitrogenUpper)
|
||||
if item.CurrentValue < ammoniaNitrogenLower || item.CurrentValue > ammoniaNitrogenUpper {
|
||||
item.IsOk = false
|
||||
if item.CurrentValue > ammoniaNitrogenUpper {
|
||||
item.WarningType = 1
|
||||
}
|
||||
if item.CurrentValue < ammoniaNitrogenLower {
|
||||
item.WarningType = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 溶解氧
|
||||
if item.Type == "溶解氧" {
|
||||
dissolvedOxygenLower := envMonitorDeviceWarningConfig.DissolvedOxygenMin
|
||||
dissolvedOxygenUpper := envMonitorDeviceWarningConfig.DissolvedOxygenMax
|
||||
item.StandardRange = fmt.Sprintf("%.2f-%.2f", dissolvedOxygenLower, dissolvedOxygenUpper)
|
||||
if item.CurrentValue < dissolvedOxygenLower || item.CurrentValue > dissolvedOxygenUpper {
|
||||
item.IsOk = false
|
||||
if item.CurrentValue > dissolvedOxygenUpper {
|
||||
item.WarningType = 1
|
||||
}
|
||||
if item.CurrentValue < dissolvedOxygenLower {
|
||||
item.WarningType = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
// PH值
|
||||
if item.Type == "PH值" {
|
||||
phLower := envMonitorDeviceWarningConfig.PHMin
|
||||
phUpper := envMonitorDeviceWarningConfig.PHMax
|
||||
item.StandardRange = fmt.Sprintf("%.2f-%.2f", phLower, phUpper)
|
||||
if item.CurrentValue < phLower || item.CurrentValue > phUpper {
|
||||
item.IsOk = false
|
||||
if item.CurrentValue > phUpper {
|
||||
item.WarningType = 1
|
||||
}
|
||||
if item.CurrentValue < phLower {
|
||||
item.WarningType = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result := GetEnvMonitorDeviceWarningLogDB(ctx, a.DB).Create(item)
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
||||
|
||||
// Update the specified env monitor device warning log in the database.
|
||||
func (a *EnvMonitorDeviceWarningLog) Update(ctx context.Context, item *schema.EnvMonitorDeviceWarningLog) error {
|
||||
result := GetEnvMonitorDeviceWarningLogDB(ctx, a.DB).Where("id=?", item.ID).Select("*").Omit("created_at").Updates(item)
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
||||
|
||||
// Delete the specified env monitor device warning log from the database.
|
||||
func (a *EnvMonitorDeviceWarningLog) Delete(ctx context.Context, id string) error {
|
||||
result := GetEnvMonitorDeviceWarningLogDB(ctx, a.DB).Where("id=?", id).Delete(new(schema.EnvMonitorDeviceWarningLog))
|
||||
return errors.WithStack(result.Error)
|
||||
}
|
@ -12,14 +12,17 @@ import (
|
||||
)
|
||||
|
||||
type EnvMonitor struct {
|
||||
DB *gorm.DB
|
||||
EnvMonitorDeviceTypeInfoAPI *api.EnvMonitorDeviceTypeInfo
|
||||
EnvMonitorDeviceAPI *api.EnvMonitorDevice
|
||||
EnvMonitorDeviceFishPondAPI *api.EnvMonitorDeviceFishPond
|
||||
DB *gorm.DB
|
||||
EnvMonitorDeviceTypeInfoAPI *api.EnvMonitorDeviceTypeInfo
|
||||
EnvMonitorDeviceAPI *api.EnvMonitorDevice
|
||||
EnvMonitorDeviceFishPondAPI *api.EnvMonitorDeviceFishPond
|
||||
EnvMonitorDeviceWarningConfigAPI *api.EnvMonitorDeviceWarningConfig
|
||||
EnvMonitorDeviceSensorAPI *api.EnvMonitorDeviceSensor
|
||||
EnvMonitorDeviceWarningLogAPI *api.EnvMonitorDeviceWarningLog
|
||||
}
|
||||
|
||||
func (a *EnvMonitor) AutoMigrate(ctx context.Context) error {
|
||||
return a.DB.AutoMigrate(new(schema.EnvMonitorDeviceTypeInfo), new(schema.EnvMonitorDevice), new(schema.EnvMonitorDeviceFishPond))
|
||||
return a.DB.AutoMigrate(new(schema.EnvMonitorDeviceTypeInfo), new(schema.EnvMonitorDevice), new(schema.EnvMonitorDeviceFishPond), new(schema.EnvMonitorDeviceWarningConfig), new(schema.EnvMonitorDeviceSensor), new(schema.EnvMonitorDeviceWarningLog))
|
||||
}
|
||||
|
||||
func (a *EnvMonitor) Init(ctx context.Context) error {
|
||||
@ -49,14 +52,42 @@ func (a *EnvMonitor) RegisterV1Routers(ctx context.Context, v1 *gin.RouterGroup)
|
||||
envMonitorDevice.PUT(":id", a.EnvMonitorDeviceAPI.Update)
|
||||
envMonitorDevice.DELETE(":id", a.EnvMonitorDeviceAPI.Delete)
|
||||
}
|
||||
// envMonitorDeviceFishPond := v1.Group("env-monitor-device-fish-ponds")
|
||||
// {
|
||||
// envMonitorDeviceFishPond.GET("", a.EnvMonitorDeviceFishPondAPI.Query)
|
||||
// envMonitorDeviceFishPond.GET(":id", a.EnvMonitorDeviceFishPondAPI.Get)
|
||||
// envMonitorDeviceFishPond.POST("", a.EnvMonitorDeviceFishPondAPI.Create)
|
||||
// envMonitorDeviceFishPond.PUT(":id", a.EnvMonitorDeviceFishPondAPI.Update)
|
||||
// envMonitorDeviceFishPond.DELETE(":id", a.EnvMonitorDeviceFishPondAPI.Delete)
|
||||
// }
|
||||
envMonitorDeviceWarningConfig :=
|
||||
// envMonitorDeviceFishPond := v1.Group("env-monitor-device-fish-ponds")
|
||||
// {
|
||||
// envMonitorDeviceFishPond.GET("", a.EnvMonitorDeviceFishPondAPI.Query)
|
||||
// envMonitorDeviceFishPond.GET(":id", a.EnvMonitorDeviceFishPondAPI.Get)
|
||||
// envMonitorDeviceFishPond.POST("", a.EnvMonitorDeviceFishPondAPI.Create)
|
||||
// envMonitorDeviceFishPond.PUT(":id", a.EnvMonitorDeviceFishPondAPI.Update)
|
||||
// envMonitorDeviceFishPond.DELETE(":id", a.EnvMonitorDeviceFishPondAPI.Delete)
|
||||
// }
|
||||
v1.Group("env-monitor-device-warning-configs")
|
||||
{
|
||||
envMonitorDeviceWarningConfig.GET("", a.EnvMonitorDeviceWarningConfigAPI.Query)
|
||||
envMonitorDeviceWarningConfig.GET(":id", a.EnvMonitorDeviceWarningConfigAPI.Get)
|
||||
envMonitorDeviceWarningConfig.POST("", a.EnvMonitorDeviceWarningConfigAPI.Create)
|
||||
envMonitorDeviceWarningConfig.PUT(":id", a.EnvMonitorDeviceWarningConfigAPI.Update)
|
||||
envMonitorDeviceWarningConfig.DELETE(":id", a.EnvMonitorDeviceWarningConfigAPI.Delete)
|
||||
}
|
||||
envMonitorDeviceWarningLog :=
|
||||
// envMonitorDeviceSensor := v1.Group("env-monitor-device-sensors")
|
||||
// {
|
||||
// envMonitorDeviceSensor.GET("", a.EnvMonitorDeviceSensorAPI.Query)
|
||||
// envMonitorDeviceSensor.GET(":id", a.EnvMonitorDeviceSensorAPI.Get)
|
||||
// envMonitorDeviceSensor.POST("", a.EnvMonitorDeviceSensorAPI.Create)
|
||||
// envMonitorDeviceSensor.PUT(":id", a.EnvMonitorDeviceSensorAPI.Update)
|
||||
// envMonitorDeviceSensor.DELETE(":id", a.EnvMonitorDeviceSensorAPI.Delete)
|
||||
// }
|
||||
v1.Group("env-monitor-device-warning-logs")
|
||||
{
|
||||
envMonitorDeviceWarningLog.GET("", a.EnvMonitorDeviceWarningLogAPI.Query)
|
||||
// envMonitorDeviceWarningLog.GET(":id", a.EnvMonitorDeviceWarningLogAPI.Get)
|
||||
envMonitorDeviceWarningLog.POST("", a.EnvMonitorDeviceWarningLogAPI.Create)
|
||||
// envMonitorDeviceWarningLog.PUT(":id", a.EnvMonitorDeviceWarningLogAPI.Update)
|
||||
// envMonitorDeviceWarningLog.DELETE(":id", a.EnvMonitorDeviceWarningLogAPI.Delete)
|
||||
envMonitorDeviceWarningLog.GET("export", a.EnvMonitorDeviceWarningLogAPI.Export)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ type EnvMonitorDevice struct {
|
||||
CreatedAt time.Time `json:"created_at" gorm:"index;comment:Create time;"` // Create time
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"index;comment:Update time;"` // Update time
|
||||
EnvMonitorDeviceFishPond []*EnvMonitorDeviceFishPond `json:"env_monitor_device_fish_ponds" gorm:"foreignKey:EnvMonitorDeviceID;references:ID;comment:关联鱼池ID;"`
|
||||
EnvMonitorDeviceSensor []*EnvMonitorDeviceSensor `json:"env_monitor_device_sensors" gorm:"foreignKey:EnvMonitorDeviceID;references:ID;comment:关联传感器ID;"`
|
||||
}
|
||||
|
||||
// Defining the query parameters for the `EnvMonitorDevice` struct.
|
||||
@ -54,6 +55,7 @@ type EnvMonitorDeviceForm struct {
|
||||
TenantID string `json:"tenant_id"` // 租户ID
|
||||
WorkshopName string `json:"workshop_name" binding:"required"` // 关联车间名称
|
||||
EnvMonitorDeviceDeviceFishPonds []*EnvMonitorDeviceFishPond `json:"env_monitor_device_fish_ponds" gorm:"foreignKey:DeviceID;references:ID;comment:关联鱼池ID;"`
|
||||
EnvMonitorDeviceDeviceSensors []*EnvMonitorDeviceSensor `json:"env_monitor_device_device_sensors" gorm:"foreignKey:DeviceID;references:ID;comment:关联传感器ID;"`
|
||||
}
|
||||
|
||||
// A validation function for the `EnvMonitorDeviceForm` struct.
|
||||
|
65
internal/mods/envmonitor/schema/env_monitor_device_sensor.go
Normal file
65
internal/mods/envmonitor/schema/env_monitor_device_sensor.go
Normal file
@ -0,0 +1,65 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"ifms/pkg/util"
|
||||
)
|
||||
|
||||
// 设备传感器表
|
||||
type EnvMonitorDeviceSensor struct {
|
||||
ID int64 `json:"id" gorm:"size:20;primaryKey;comment:Unique ID;"` // Unique ID
|
||||
EnvMonitorDeviceID int64 `json:"env_monitor_device_id" gorm:"index;comment:环境监测设备ID;"` // 环境监测设备ID
|
||||
TenantID string `json:"tenant_id" gorm:"size:36;comment:租户ID;"` // 租户ID
|
||||
Name string `json:"name" gorm:"size:64;comment:传感器名称;"` // 传感器名称
|
||||
Type int64 `json:"type" gorm:"size:64;comment:传感器类型 1水温传感器、2溶解氧传感器、3氨氮传感器、4PH传感器、5电导率传感器 6视频监控;"` // 传感器类型
|
||||
Status bool `json:"status" gorm:"comment:传感器状态(true=正常,false=异常);"` // 传感器状态(true=正常,false=异常)
|
||||
CurrentValue float64 `json:"current_value" gorm:"comment:当前值;"` // 当前值
|
||||
CreatedAt time.Time `json:"created_at" gorm:"index;comment:Create time;"` // Create time
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"index;comment:Update time;"` // Update time
|
||||
}
|
||||
|
||||
// Defining the query parameters for the `EnvMonitorDeviceSensor` struct.
|
||||
type EnvMonitorDeviceSensorQueryParam struct {
|
||||
util.PaginationParam
|
||||
}
|
||||
|
||||
// Defining the query options for the `EnvMonitorDeviceSensor` struct.
|
||||
type EnvMonitorDeviceSensorQueryOptions struct {
|
||||
util.QueryOptions
|
||||
}
|
||||
|
||||
// Defining the query result for the `EnvMonitorDeviceSensor` struct.
|
||||
type EnvMonitorDeviceSensorQueryResult struct {
|
||||
Data EnvMonitorDeviceSensors
|
||||
PageResult *util.PaginationResult
|
||||
}
|
||||
|
||||
// Defining the slice of `EnvMonitorDeviceSensor` struct.
|
||||
type EnvMonitorDeviceSensors []*EnvMonitorDeviceSensor
|
||||
|
||||
// Defining the data structure for creating a `EnvMonitorDeviceSensor` struct.
|
||||
type EnvMonitorDeviceSensorForm struct {
|
||||
EnvMonitorDeviceID int64 `json:"env_monitor_device_id" binding:"required"` // 环境监测设备ID
|
||||
TenantID string `json:"tenant_id" binding:"required,max=36"` // 租户ID
|
||||
Status bool `json:"status" binding:"required"` // 传感器状态(true=正常,false=异常)
|
||||
CurrentValue float64 `json:"current_value" binding:"required"` // 当前值
|
||||
Type int64 `json:"type" binding:"required,max=64"` // 传感器类型
|
||||
Name string `json:"name" binding:"required,max=64"` // 传感器名称
|
||||
}
|
||||
|
||||
// A validation function for the `EnvMonitorDeviceSensorForm` struct.
|
||||
func (a *EnvMonitorDeviceSensorForm) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert `EnvMonitorDeviceSensorForm` to `EnvMonitorDeviceSensor` object.
|
||||
func (a *EnvMonitorDeviceSensorForm) FillTo(envMonitorDeviceSensor *EnvMonitorDeviceSensor) error {
|
||||
envMonitorDeviceSensor.EnvMonitorDeviceID = a.EnvMonitorDeviceID
|
||||
envMonitorDeviceSensor.TenantID = a.TenantID
|
||||
envMonitorDeviceSensor.Status = a.Status
|
||||
envMonitorDeviceSensor.CurrentValue = a.CurrentValue
|
||||
envMonitorDeviceSensor.Type = a.Type
|
||||
envMonitorDeviceSensor.Name = a.Name
|
||||
return nil
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"ifms/pkg/util"
|
||||
)
|
||||
|
||||
// 环境监测设备报警范围配置表
|
||||
type EnvMonitorDeviceWarningConfig struct {
|
||||
ID int64 `json:"id" gorm:"size:20;primaryKey;comment:Unique ID;"` // Unique ID
|
||||
TenantID string `json:"tenant_id" gorm:"index;comment:租户ID;"` // 租户ID
|
||||
EnvMonitorDeviceID int64 `json:"env_monitor_device_id" gorm:"index;comment:环境监测设备ID;"` // 环境监测设备ID
|
||||
WaterTempMin float64 `json:"water_temp_min" gorm:"comment:水温正常最小值(℃);"` // 水温正常最小值(℃)
|
||||
WaterTempMax float64 `json:"water_temp_max" gorm:"comment:水温正常最大值(℃);"` // 水温正常最大值(℃)
|
||||
DissolvedOxygenMin float64 `json:"dissolved_oxygen_min" gorm:"comment:溶解氧正常最小值(mg/l);"` // 溶解氧正常最小值(mg/l)
|
||||
DissolvedOxygenMax float64 `json:"dissolved_oxygen_max" gorm:"comment:溶解氧正常最大值(mg/l);"` // 溶解氧正常最大值(mg/l)
|
||||
AmmoniaNitrogenMin float64 `json:"ammonia_nitrogen_min" gorm:"comment:氨氮正常最小值(mg/l);"` // 氨氮正常最小值(mg/l)
|
||||
AmmoniaNitrogenMax float64 `json:"ammonia_nitrogen_max" gorm:"comment:氨氮正常最大值(mg/l);"` // 氨氮正常最大值(mg/l)
|
||||
PHMin float64 `json:"ph_min" gorm:"comment:PH值正常最小值;"` // PH值正常最小值
|
||||
PHMax float64 `json:"ph_max" gorm:"comment:PH值正常最大值;"` // PH值正常最大值
|
||||
ConductivityMin float64 `json:"conductivity_min" gorm:"comment:电导率正常最小值(μS);"` // 电导率正常最小值(μS)
|
||||
ConductivityMax float64 `json:"conductivity_max" gorm:"comment:电导率正常最大值(μS);"` // 电导率正常最大值(μS)
|
||||
CreatedAt time.Time `json:"created_at" gorm:"index;comment:Create time;"` // Create time
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"index;comment:Update time;"` // Update time
|
||||
}
|
||||
|
||||
// Defining the query parameters for the `EnvMonitorDeviceWarningConfig` struct.
|
||||
type EnvMonitorDeviceWarningConfigQueryParam struct {
|
||||
util.PaginationParam
|
||||
}
|
||||
|
||||
// Defining the query options for the `EnvMonitorDeviceWarningConfig` struct.
|
||||
type EnvMonitorDeviceWarningConfigQueryOptions struct {
|
||||
util.QueryOptions
|
||||
}
|
||||
|
||||
// Defining the query result for the `EnvMonitorDeviceWarningConfig` struct.
|
||||
type EnvMonitorDeviceWarningConfigQueryResult struct {
|
||||
Data EnvMonitorDeviceWarningConfigs
|
||||
PageResult *util.PaginationResult
|
||||
}
|
||||
|
||||
// Defining the slice of `EnvMonitorDeviceWarningConfig` struct.
|
||||
type EnvMonitorDeviceWarningConfigs []*EnvMonitorDeviceWarningConfig
|
||||
|
||||
// Defining the data structure for creating a `EnvMonitorDeviceWarningConfig` struct.
|
||||
type EnvMonitorDeviceWarningConfigForm struct {
|
||||
TenantID string `json:"tenant_id" gorm:"index;comment:租户ID;"` // 租户ID
|
||||
EnvMonitorDeviceID int64 `json:"env_monitor_device_id"` // 环境监测设备ID
|
||||
WaterTempMin float64 `json:"water_temp_min"` // 水温正常最小值(℃)
|
||||
WaterTempMax float64 `json:"water_temp_max"` // 水温正常最大值(℃)
|
||||
DissolvedOxygenMin float64 `json:"dissolved_oxygen_min"` // 溶解氧正常最小值(mg/l)
|
||||
DissolvedOxygenMax float64 `json:"dissolved_oxygen_max"` // 溶解氧正常最大值(mg/l)
|
||||
AmmoniaNitrogenMin float64 `json:"ammonia_nitrogen_min"` // 氨氮正常最小值(mg/l)
|
||||
AmmoniaNitrogenMax float64 `json:"ammonia_nitrogen_max"` // 氨氮正常最大值(mg/l)
|
||||
PHMin float64 `json:"ph_min"` // PH值正常最小值
|
||||
PHMax float64 `json:"ph_max"` // PH值正常最大值
|
||||
ConductivityMin float64 `json:"conductivity_min"` // 电导率正常最小值(μS)
|
||||
ConductivityMax float64 `json:"conductivity_max"` // 电导率正常最大值(μS)
|
||||
}
|
||||
|
||||
// A validation function for the `EnvMonitorDeviceWarningConfigForm` struct.
|
||||
func (a *EnvMonitorDeviceWarningConfigForm) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert `EnvMonitorDeviceWarningConfigForm` to `EnvMonitorDeviceWarningConfig` object.
|
||||
func (a *EnvMonitorDeviceWarningConfigForm) FillTo(envMonitorDeviceWarningConfig *EnvMonitorDeviceWarningConfig) error {
|
||||
envMonitorDeviceWarningConfig.EnvMonitorDeviceID = a.EnvMonitorDeviceID
|
||||
envMonitorDeviceWarningConfig.WaterTempMin = a.WaterTempMin
|
||||
envMonitorDeviceWarningConfig.WaterTempMax = a.WaterTempMax
|
||||
envMonitorDeviceWarningConfig.DissolvedOxygenMin = a.DissolvedOxygenMin
|
||||
envMonitorDeviceWarningConfig.DissolvedOxygenMax = a.DissolvedOxygenMax
|
||||
envMonitorDeviceWarningConfig.AmmoniaNitrogenMin = a.AmmoniaNitrogenMin
|
||||
envMonitorDeviceWarningConfig.AmmoniaNitrogenMax = a.AmmoniaNitrogenMax
|
||||
envMonitorDeviceWarningConfig.PHMin = a.PHMin
|
||||
envMonitorDeviceWarningConfig.PHMax = a.PHMax
|
||||
envMonitorDeviceWarningConfig.ConductivityMin = a.ConductivityMin
|
||||
envMonitorDeviceWarningConfig.ConductivityMax = a.ConductivityMax
|
||||
envMonitorDeviceWarningConfig.TenantID = a.TenantID
|
||||
return nil
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"ifms/pkg/util"
|
||||
)
|
||||
|
||||
// 环境监测设备报警日志
|
||||
type EnvMonitorDeviceWarningLog struct {
|
||||
ID int64 `json:"id" gorm:"size:20;primaryKey;comment:Unique ID;"` // Unique ID
|
||||
TenantID string `json:"tenant_id" gorm:"size:32;comment:租户ID;"` // 租户ID
|
||||
EnvMonitorDeviceID int64 `json:"env_monitor_device_id" gorm:"size:32;comment:设备ID;"` // 设备ID
|
||||
EnvMonitorDeviceSensorID int64 `json:"env_monitor_device_sensor_id" gorm:"size:32;comment:设备传感器ID;"` // 设备传感器ID
|
||||
DeviceModel string `json:"device_model" gorm:"size:64;comment:设备型号;"` // 设备型号
|
||||
DeviceName string `json:"device_name" gorm:"size:64;comment:设备名称;"` // 设备名称
|
||||
RelatedPondIds string `json:"related_pond_ids" gorm:"type:text;comment:关联鱼池/车间ID;"` // 关联鱼池/车间ID
|
||||
RelatedPond string `json:"related_pond" gorm:"type:text;comment:关联鱼池/车间;"` // 关联鱼池/车间
|
||||
Type string `json:"type" gorm:"size:255;comment:报警指标;"` // 报警指标
|
||||
StandardRange string `json:"standard_range" gorm:"size:255;comment:参考数值范围;"` // 参考数值范围
|
||||
CurrentValue float64 `json:"current_value" gorm:"type:decimal(5,2);comment:当前数值;"` // 当前数值
|
||||
WarningType int `json:"warning_type" gorm:"comment:1偏高 2偏低;"` // 1偏高 2偏低
|
||||
IsOk bool `json:"is_ok" gorm:"comment:是否正常;"` // 是否正常
|
||||
CreatedAt time.Time `json:"created_at" gorm:"index;comment:Create time;"` // Create time
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"index;comment:Update time;"` // Update time
|
||||
}
|
||||
|
||||
// Defining the query parameters for the `EnvMonitorDeviceWarningLog` struct.
|
||||
type EnvMonitorDeviceWarningLogQueryParam struct {
|
||||
util.PaginationParam
|
||||
DeviceName string `form:"device_name"` // 设备名称
|
||||
StartTime string `form:"start_time"` // 开始时间
|
||||
EndTime string `form:"end_time"` // 结束时间
|
||||
}
|
||||
|
||||
// Defining the query options for the `EnvMonitorDeviceWarningLog` struct.
|
||||
type EnvMonitorDeviceWarningLogQueryOptions struct {
|
||||
util.QueryOptions
|
||||
}
|
||||
|
||||
// Defining the query result for the `EnvMonitorDeviceWarningLog` struct.
|
||||
type EnvMonitorDeviceWarningLogQueryResult struct {
|
||||
Data EnvMonitorDeviceWarningLogs
|
||||
PageResult *util.PaginationResult
|
||||
}
|
||||
|
||||
// Defining the slice of `EnvMonitorDeviceWarningLog` struct.
|
||||
type EnvMonitorDeviceWarningLogs []*EnvMonitorDeviceWarningLog
|
||||
|
||||
// Defining the data structure for creating a `EnvMonitorDeviceWarningLog` struct.
|
||||
type EnvMonitorDeviceWarningLogForm struct {
|
||||
TenantID string `json:"tenant_id"` // 租户ID
|
||||
EnvMonitorDeviceID int64 `json:"env_monitor_device_id" binding:"required"` // 设备ID
|
||||
EnvMonitorDeviceSensorID int64 `json:"env_monitor_device_sensor_id" binding:"required"` // 设备传感器ID
|
||||
DeviceModel string `json:"device_model" binding:"required,max=64"` // 设备型号
|
||||
DeviceName string `json:"device_name" binding:"required,max=64"` // 设备名称
|
||||
RelatedPondIds string `json:"related_pond_ids" binding:"required"` // 关联鱼池/车间ID
|
||||
RelatedPond string `json:"related_pond" binding:"required"` // 关联鱼池/车间
|
||||
Type string `json:"type"` // 报警指标
|
||||
StandardRange string `json:"standard_range"` // 参考数值范围
|
||||
CurrentValue float64 `json:"current_value"` // 当前数值
|
||||
}
|
||||
|
||||
// A validation function for the `EnvMonitorDeviceWarningLogForm` struct.
|
||||
func (a *EnvMonitorDeviceWarningLogForm) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert `EnvMonitorDeviceWarningLogForm` to `EnvMonitorDeviceWarningLog` object.
|
||||
func (a *EnvMonitorDeviceWarningLogForm) FillTo(envMonitorDeviceWarningLog *EnvMonitorDeviceWarningLog) error {
|
||||
envMonitorDeviceWarningLog.TenantID = a.TenantID
|
||||
envMonitorDeviceWarningLog.EnvMonitorDeviceID = a.EnvMonitorDeviceID
|
||||
envMonitorDeviceWarningLog.EnvMonitorDeviceSensorID = a.EnvMonitorDeviceSensorID
|
||||
envMonitorDeviceWarningLog.DeviceModel = a.DeviceModel
|
||||
envMonitorDeviceWarningLog.DeviceName = a.DeviceName
|
||||
envMonitorDeviceWarningLog.RelatedPondIds = a.RelatedPondIds
|
||||
envMonitorDeviceWarningLog.RelatedPond = a.RelatedPond
|
||||
envMonitorDeviceWarningLog.Type = a.Type
|
||||
envMonitorDeviceWarningLog.StandardRange = a.StandardRange
|
||||
envMonitorDeviceWarningLog.CurrentValue = a.CurrentValue
|
||||
return nil
|
||||
}
|
||||
|
||||
type EnvMonitorDeviceWarningLogExport struct {
|
||||
Url string `json:"url"`
|
||||
}
|
@ -19,4 +19,13 @@ var Set = wire.NewSet(
|
||||
wire.Struct(new(dal.EnvMonitorDeviceFishPond), "*"),
|
||||
wire.Struct(new(biz.EnvMonitorDeviceFishPond), "*"),
|
||||
wire.Struct(new(api.EnvMonitorDeviceFishPond), "*"),
|
||||
wire.Struct(new(dal.EnvMonitorDeviceWarningConfig), "*"),
|
||||
wire.Struct(new(biz.EnvMonitorDeviceWarningConfig), "*"),
|
||||
wire.Struct(new(api.EnvMonitorDeviceWarningConfig), "*"),
|
||||
wire.Struct(new(dal.EnvMonitorDeviceSensor), "*"),
|
||||
wire.Struct(new(biz.EnvMonitorDeviceSensor), "*"),
|
||||
wire.Struct(new(api.EnvMonitorDeviceSensor), "*"),
|
||||
wire.Struct(new(dal.EnvMonitorDeviceWarningLog), "*"),
|
||||
wire.Struct(new(biz.EnvMonitorDeviceWarningLog), "*"),
|
||||
wire.Struct(new(api.EnvMonitorDeviceWarningLog), "*"),
|
||||
)
|
||||
|
@ -96,6 +96,22 @@ func (a *Mods) Release(ctx context.Context) error {
|
||||
Release(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.EnvMonitor.
|
||||
Release(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.EnvMonitor.
|
||||
Release(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.EnvMonitor.
|
||||
Release(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.EnvMonitor.
|
||||
Release(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -220,15 +220,18 @@ func BuildInjector(ctx context.Context) (*Injector, func(), error) {
|
||||
envMonitorDeviceFishPond := &dal4.EnvMonitorDeviceFishPond{
|
||||
DB: db,
|
||||
}
|
||||
envMonitorDeviceSensor := &dal4.EnvMonitorDeviceSensor{
|
||||
DB: db,
|
||||
}
|
||||
bizEnvMonitorDevice := &biz4.EnvMonitorDevice{
|
||||
Trans: trans,
|
||||
EnvMonitorDeviceDAL: envMonitorDevice,
|
||||
EnvMonitorDeviceFishPondDAL: envMonitorDeviceFishPond,
|
||||
Trans: trans,
|
||||
EnvMonitorDeviceDAL: envMonitorDevice,
|
||||
EnvMonitorDeviceFishPondDAL: envMonitorDeviceFishPond,
|
||||
EnvMonitorDeviceSensorDAL: envMonitorDeviceSensor,
|
||||
}
|
||||
apiEnvMonitorDevice := &api4.EnvMonitorDevice{
|
||||
EnvMonitorDeviceBIZ: bizEnvMonitorDevice,
|
||||
}
|
||||
|
||||
bizEnvMonitorDeviceFishPond := &biz4.EnvMonitorDeviceFishPond{
|
||||
Trans: trans,
|
||||
EnvMonitorDeviceFishPondDAL: envMonitorDeviceFishPond,
|
||||
@ -236,11 +239,41 @@ func BuildInjector(ctx context.Context) (*Injector, func(), error) {
|
||||
apiEnvMonitorDeviceFishPond := &api4.EnvMonitorDeviceFishPond{
|
||||
EnvMonitorDeviceFishPondBIZ: bizEnvMonitorDeviceFishPond,
|
||||
}
|
||||
envMonitorDeviceWarningConfig := &dal4.EnvMonitorDeviceWarningConfig{
|
||||
DB: db,
|
||||
}
|
||||
bizEnvMonitorDeviceWarningConfig := &biz4.EnvMonitorDeviceWarningConfig{
|
||||
Trans: trans,
|
||||
EnvMonitorDeviceWarningConfigDAL: envMonitorDeviceWarningConfig,
|
||||
}
|
||||
apiEnvMonitorDeviceWarningConfig := &api4.EnvMonitorDeviceWarningConfig{
|
||||
EnvMonitorDeviceWarningConfigBIZ: bizEnvMonitorDeviceWarningConfig,
|
||||
}
|
||||
bizEnvMonitorDeviceSensor := &biz4.EnvMonitorDeviceSensor{
|
||||
Trans: trans,
|
||||
EnvMonitorDeviceSensorDAL: envMonitorDeviceSensor,
|
||||
}
|
||||
apiEnvMonitorDeviceSensor := &api4.EnvMonitorDeviceSensor{
|
||||
EnvMonitorDeviceSensorBIZ: bizEnvMonitorDeviceSensor,
|
||||
}
|
||||
envMonitorDeviceWarningLog := &dal4.EnvMonitorDeviceWarningLog{
|
||||
DB: db,
|
||||
}
|
||||
bizEnvMonitorDeviceWarningLog := &biz4.EnvMonitorDeviceWarningLog{
|
||||
Trans: trans,
|
||||
EnvMonitorDeviceWarningLogDAL: envMonitorDeviceWarningLog,
|
||||
}
|
||||
apiEnvMonitorDeviceWarningLog := &api4.EnvMonitorDeviceWarningLog{
|
||||
EnvMonitorDeviceWarningLogBIZ: bizEnvMonitorDeviceWarningLog,
|
||||
}
|
||||
envMonitor := &envmonitor.EnvMonitor{
|
||||
DB: db,
|
||||
EnvMonitorDeviceTypeInfoAPI: apiEnvMonitorDeviceTypeInfo,
|
||||
EnvMonitorDeviceAPI: apiEnvMonitorDevice,
|
||||
EnvMonitorDeviceFishPondAPI: apiEnvMonitorDeviceFishPond,
|
||||
DB: db,
|
||||
EnvMonitorDeviceTypeInfoAPI: apiEnvMonitorDeviceTypeInfo,
|
||||
EnvMonitorDeviceAPI: apiEnvMonitorDevice,
|
||||
EnvMonitorDeviceFishPondAPI: apiEnvMonitorDeviceFishPond,
|
||||
EnvMonitorDeviceWarningConfigAPI: apiEnvMonitorDeviceWarningConfig,
|
||||
EnvMonitorDeviceSensorAPI: apiEnvMonitorDeviceSensor,
|
||||
EnvMonitorDeviceWarningLogAPI: apiEnvMonitorDeviceWarningLog,
|
||||
}
|
||||
modsMods := &mods.Mods{
|
||||
RBAC: rbacRBAC,
|
||||
|
90
pkg/util/export.go
Normal file
90
pkg/util/export.go
Normal file
@ -0,0 +1,90 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ifms/internal/config"
|
||||
"ifms/pkg/oss"
|
||||
"os"
|
||||
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
// ExportDataToOSS 生成带标题的 Excel 文件,上传到 OSS,并删除本地文件,返回 OSS 文件访问 URL。
|
||||
// title: Excel 表头(第一行)
|
||||
// data: Excel 数据内容(每一行是一个[]string)
|
||||
// localFilePath: 本地临时文件路径
|
||||
// ossObjectName: OSS 对象名(含路径)
|
||||
// 返回 OSS 文件访问 URL 或错误
|
||||
func ExportDataToOSS(ctx context.Context, title []string, data [][]string, localFilePath, ossObjectName string) (string, error) {
|
||||
// 1. 生成Excel(带标题)
|
||||
if err := GenerateExcelFile(title, data, localFilePath); err != nil {
|
||||
return "", err
|
||||
}
|
||||
// 2. 上传并删除本地文件
|
||||
url, err := UploadOss(ctx, localFilePath, ossObjectName, true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return url, nil
|
||||
}
|
||||
|
||||
// GenerateExcelFile 生成带标题的 Excel 文件并保存到本地。
|
||||
// title: Excel 表头(第一行)
|
||||
// data: Excel 数据内容(每一行是一个[]string)
|
||||
// filePath: 本地保存路径
|
||||
// 返回错误信息
|
||||
func GenerateExcelFile(title []string, data [][]string, filePath string) error {
|
||||
f := excelize.NewFile()
|
||||
sheet := "Sheet1"
|
||||
// 写入标题
|
||||
for j, cell := range title {
|
||||
cellName, _ := excelize.CoordinatesToCellName(j+1, 1)
|
||||
f.SetCellValue(sheet, cellName, cell)
|
||||
}
|
||||
// 写入数据
|
||||
for i, row := range data {
|
||||
for j, cell := range row {
|
||||
cellName, _ := excelize.CoordinatesToCellName(j+1, i+2) // 数据从第2行开始
|
||||
f.SetCellValue(sheet, cellName, cell)
|
||||
}
|
||||
}
|
||||
if err := f.SaveAs(filePath); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UploadAndDeleteLocalFile 上传本地文件到 OSS,上传成功后删除本地文件。
|
||||
// filePath: 本地文件路径
|
||||
// objectName: OSS 对象名(含路径)
|
||||
// deleteLocalFile: 是否删除本地文件
|
||||
// 返回 OSS 文件访问 URL 或错误
|
||||
func UploadOss(ctx context.Context, filePath, objectName string, deleteLocalFile bool) (string, error) {
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
fileInfo, err := file.Stat()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
fileSize := fileInfo.Size()
|
||||
|
||||
ossResult, err := oss.Ins.PutObject(ctx, config.C.AliyunOSS.Bucket, objectName, file, fileSize, oss.PutObjectOptions{
|
||||
UserMetadata: map[string]string{"name": fileInfo.Name()},
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 上传成功后删除本地文件
|
||||
if deleteLocalFile {
|
||||
if err := os.Remove(filePath); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
return ossResult.URL, nil
|
||||
}
|
@ -4,13 +4,14 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"ifms/internal/config"
|
||||
"ifms/pkg/logging"
|
||||
"ifms/pkg/oss"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 上传图片文件
|
||||
|
Loading…
x
Reference in New Issue
Block a user