新增测点 创建维护模块
This commit is contained in:
@@ -3,20 +3,52 @@ package v1
|
|||||||
import (
|
import (
|
||||||
"energy-management-system/form"
|
"energy-management-system/form"
|
||||||
"energy-management-system/request"
|
"energy-management-system/request"
|
||||||
|
"energy-management-system/response"
|
||||||
|
"energy-management-system/service"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DevicePoint struct{}
|
type DevicePoint struct{}
|
||||||
|
|
||||||
// 获取测点名称select
|
// 获取测点名称select
|
||||||
// PointNameSelect 季度列表
|
|
||||||
|
// PointNameSelect 测点名称选择数据
|
||||||
func (r *DevicePoint) PointNameSelect(c *gin.Context) {
|
func (r *DevicePoint) PointNameSelect(c *gin.Context) {
|
||||||
var req form.PointNameSelectReq
|
var req form.PointNameSelectReq
|
||||||
request.BindParam(c, &req)
|
request.BindParam(c, &req)
|
||||||
//respData := service.GroupServices.PeakValley.PeakValleyQuarterPage(&req)
|
respData := service.GroupServices.DevicePoint.PointNameSelect(&req)
|
||||||
//response.SuccessData(respData, c)
|
response.SuccessData(respData, c)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建设备测点
|
func (r *DevicePoint) DevicePointPage(c *gin.Context) {
|
||||||
// 修改设备测点
|
var req form.DevicePointListReq
|
||||||
|
request.BindParam(c, &req)
|
||||||
|
respData := service.GroupServices.DevicePoint.DevicePointPage(&req)
|
||||||
|
response.SuccessData(respData, c)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// DevicePointEditDetail 查看测点
|
||||||
|
func (r *DevicePoint) DevicePointEditDetail(c *gin.Context) {
|
||||||
|
var req form.DevicePointEditDetailReq
|
||||||
|
request.BindParam(c, &req)
|
||||||
|
respData := service.GroupServices.DevicePoint.DevicePointEditDetail(&req)
|
||||||
|
response.SuccessData(respData, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDevicePoint 创建测点
|
||||||
|
func (r *DevicePoint) CreateDevicePoint(c *gin.Context) {
|
||||||
|
var req form.CreateDevicePointReq
|
||||||
|
request.BindJson(c, &req)
|
||||||
|
service.GroupServices.DevicePoint.CreateDevicePoint(&req)
|
||||||
|
response.Success(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateDevicePoint 修改测点
|
||||||
|
func (r *DevicePoint) UpdateDevicePoint(c *gin.Context) {
|
||||||
|
var req form.UpdateDevicePointReq
|
||||||
|
request.BindJson(c, &req)
|
||||||
|
service.GroupServices.DevicePoint.UpdateDevicePoint(&req)
|
||||||
|
response.Success(c)
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package gorm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"energy-management-system/global"
|
"energy-management-system/global"
|
||||||
"energy-management-system/model"
|
"energy-management-system/model/device-point"
|
||||||
"energy-management-system/model/init-db-data"
|
"energy-management-system/model/init-db-data"
|
||||||
peak_valley "energy-management-system/model/peak-valley"
|
peak_valley "energy-management-system/model/peak-valley"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -68,8 +68,8 @@ func AutoMigrate(db *gorm.DB) {
|
|||||||
new(peak_valley.PeakValleyQuarter),
|
new(peak_valley.PeakValleyQuarter),
|
||||||
new(peak_valley.PeakValleyRule),
|
new(peak_valley.PeakValleyRule),
|
||||||
|
|
||||||
new(model.DevicePoint),
|
new(device_point.DevicePoint),
|
||||||
new(model.PointName),
|
new(device_point.PointName),
|
||||||
//new(model.Role),
|
//new(model.Role),
|
||||||
//new(model.UserRole),
|
//new(model.UserRole),
|
||||||
//new(model.Api),
|
//new(model.Api),
|
||||||
|
|||||||
@@ -3,3 +3,26 @@ package form
|
|||||||
type PointNameSelectReq struct {
|
type PointNameSelectReq struct {
|
||||||
Keyword string `form:"keyword" json:"keyword"`
|
Keyword string `form:"keyword" json:"keyword"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DevicePointListReq struct {
|
||||||
|
Page `form:"page" json:"page"`
|
||||||
|
DriverId int `form:"driver_id" json:"driver_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DevicePointEditDetailReq struct {
|
||||||
|
Id int `form:"id" json:"id"`
|
||||||
|
}
|
||||||
|
type CreateDevicePointReq struct {
|
||||||
|
DriverId int `json:"driver_id"`
|
||||||
|
PointId int `json:"point_id"`
|
||||||
|
EnergyType int `json:"energy_type"`
|
||||||
|
PointNameId int `json:"point_name_id" `
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateDevicePointReq struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
DriverId int `json:"driver_id"`
|
||||||
|
PointId int `json:"point_id"`
|
||||||
|
EnergyType int `json:"energy_type"`
|
||||||
|
PointNameId int `json:"point_name_id" `
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package device_point
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"energy-management-system/global"
|
"energy-management-system/global"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package device_point
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"energy-management-system/global"
|
"energy-management-system/global"
|
||||||
@@ -2,7 +2,7 @@ package init_db_data
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"energy-management-system/global"
|
"energy-management-system/global"
|
||||||
"energy-management-system/model"
|
"energy-management-system/model/device-point"
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -29,7 +29,7 @@ var initPointNameData = new(InitPointNameData)
|
|||||||
// return dataList
|
// return dataList
|
||||||
//}
|
//}
|
||||||
|
|
||||||
var pointNames = []model.PointName{
|
var pointNames = []device_point.PointName{
|
||||||
{Name: "测点-用电量"},
|
{Name: "测点-用电量"},
|
||||||
{Name: "测点-用水量"},
|
{Name: "测点-用水量"},
|
||||||
}
|
}
|
||||||
@@ -37,9 +37,9 @@ var pointNames = []model.PointName{
|
|||||||
// Init 初始化用户数据
|
// Init 初始化用户数据
|
||||||
func (i *InitPointNameData) Init() error {
|
func (i *InitPointNameData) Init() error {
|
||||||
return global.Db.Transaction(func(tx *gorm.DB) error {
|
return global.Db.Transaction(func(tx *gorm.DB) error {
|
||||||
m := &model.PointName{}
|
m := &device_point.PointName{}
|
||||||
var count int64
|
var count int64
|
||||||
err := tx.Model(&model.PointName{}).Count(&count).Error
|
err := tx.Model(&device_point.PointName{}).Count(&count).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
61
repository/device-point/device_point.go
Normal file
61
repository/device-point/device_point.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package device_point
|
||||||
|
|
||||||
|
import (
|
||||||
|
"energy-management-system/form"
|
||||||
|
"energy-management-system/global"
|
||||||
|
device_point_model "energy-management-system/model/device-point"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DevicePoint struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPeriodicals 根据自定义条件查询多条
|
||||||
|
|
||||||
|
func (r *DevicePoint) GetDevicePointPage(req *form.DevicePointListReq) (count int64, list []*device_point_model.DevicePoint, err error) {
|
||||||
|
db := global.Db.Model(&device_point_model.DevicePoint{})
|
||||||
|
//for key, value := range qr {
|
||||||
|
// db = db.Where(key, value)
|
||||||
|
//}
|
||||||
|
if req.DriverId > 0 {
|
||||||
|
db = db.Where("driver_id = ?", req.DriverId)
|
||||||
|
}
|
||||||
|
err = db.Count(&count).Error
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//err = db.Offset((req.Page.GetPageIndex() - 1) * req.Page.GetPageSize()).Limit(req.Page.GetPageSize()).Order("id desc").Preload("Rule").Find(&list).Error
|
||||||
|
err = db.Offset((req.Page.GetPageIndex() - 1) * req.Page.GetPageSize()).Limit(req.Page.GetPageSize()).Order("id desc").Find(&list).Error
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *DevicePoint) CreateDevicePoint(d *device_point_model.DevicePoint) error {
|
||||||
|
return global.Db.Create(d).Error
|
||||||
|
}
|
||||||
|
func (r *DevicePoint) UpdateDevicePoint(d *device_point_model.DevicePoint) error {
|
||||||
|
return global.Db.Save(d).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *DevicePoint) GetOneDevicePoint(qr map[string]interface{}) (d *device_point_model.DevicePoint, err error) {
|
||||||
|
db := global.Db
|
||||||
|
for key, value := range qr {
|
||||||
|
db = db.Where(key, value)
|
||||||
|
}
|
||||||
|
err = db.First(&d).Error
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//// DevicePoint 设备测点配置
|
||||||
|
//type DevicePoint struct {
|
||||||
|
// Id int `gorm:"column:id;primaryKey" json:"id"`
|
||||||
|
// DriverId int `gorm:"column:driver_id;comment:设备ID" json:"driver_id"`
|
||||||
|
// PointId int `gorm:"column:point_id;comment:测点ID" json:"point_id"`
|
||||||
|
// EnergyType int `gorm:"column:energy_type;comment:能源类型" json:"energy_type"`
|
||||||
|
// PointNameId int `gorm:"column:point_name_id;comment:测点名称ID" json:"point_name_id"`
|
||||||
|
// Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
|
||||||
|
// Updated time.Time `gorm:"column:updated;autoUpdateTime;comment:修改时间" json:"updated"`
|
||||||
|
// DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//func (r *DevicePoint) TableName() string {
|
||||||
|
// return global.AppConf.Db.TablePrefix + "device_point_configs"
|
||||||
|
//}
|
||||||
29
repository/device-point/point_name.go
Normal file
29
repository/device-point/point_name.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package device_point
|
||||||
|
|
||||||
|
import (
|
||||||
|
"energy-management-system/global"
|
||||||
|
device_point_model "energy-management-system/model/device-point"
|
||||||
|
)
|
||||||
|
|
||||||
|
// // PointName 测点名称
|
||||||
|
//
|
||||||
|
// type PointName struct {
|
||||||
|
// Id int `gorm:"column:id;primaryKey" json:"id"`
|
||||||
|
// Name string `gorm:"column:name;comment:测点名称" json:"name"`
|
||||||
|
// Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
|
||||||
|
// Updated time.Time `gorm:"column:updated;autoUpdateTime;comment:修改时间" json:"updated"`
|
||||||
|
// DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// func (r *PointName) TableName() string {
|
||||||
|
// return global.AppConf.Db.TablePrefix + "point_names"
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (r *DevicePoint) GetPointNameList(qr map[string]interface{}) (p []*device_point_model.PointName, err error) {
|
||||||
|
db := global.Db
|
||||||
|
for key, value := range qr {
|
||||||
|
db = db.Where(key, value)
|
||||||
|
}
|
||||||
|
err = db.Order("id DESC").Find(&p).Error
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import "energy-management-system/repository/peak-valley"
|
import (
|
||||||
|
device_point "energy-management-system/repository/device-point"
|
||||||
|
"energy-management-system/repository/peak-valley"
|
||||||
|
)
|
||||||
|
|
||||||
type groupRepository struct {
|
type groupRepository struct {
|
||||||
peak_valley.PeakValley
|
peak_valley.PeakValley
|
||||||
|
device_point.DevicePoint
|
||||||
}
|
}
|
||||||
|
|
||||||
var GroupRepositorys = new(groupRepository)
|
var GroupRepositorys = new(groupRepository)
|
||||||
|
|||||||
@@ -13,5 +13,9 @@ func (r *DevicePoint) InitDevicePoint(Router *gin.RouterGroup) {
|
|||||||
|
|
||||||
devicePointApi.GET("pointNameSelect", v1.Controllers.DevicePoint.PointNameSelect)
|
devicePointApi.GET("pointNameSelect", v1.Controllers.DevicePoint.PointNameSelect)
|
||||||
|
|
||||||
|
devicePointApi.GET("devicePointPage", v1.Controllers.DevicePoint.DevicePointPage)
|
||||||
|
devicePointApi.POST("createDevicePoint", v1.Controllers.DevicePoint.CreateDevicePoint)
|
||||||
|
devicePointApi.PUT("updateDevicePoint", v1.Controllers.DevicePoint.UpdateDevicePoint)
|
||||||
|
devicePointApi.GET("devicePointEditDetail", v1.Controllers.DevicePoint.DevicePointEditDetail)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
61
service/device_point.go
Normal file
61
service/device_point.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"energy-management-system/form"
|
||||||
|
device_point_model "energy-management-system/model/device-point"
|
||||||
|
"energy-management-system/repository"
|
||||||
|
"energy-management-system/utils/exception"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DevicePoint struct{}
|
||||||
|
|
||||||
|
func (r *DevicePoint) PointNameSelect(req *form.PointNameSelectReq) (list []*device_point_model.PointName) {
|
||||||
|
queryParams := make(map[string]interface{})
|
||||||
|
if req.Keyword != "" {
|
||||||
|
queryParams["name LIKE ?"] = "%" + req.Keyword + "%"
|
||||||
|
}
|
||||||
|
list, err := repository.GroupRepositorys.DevicePoint.GetPointNameList(queryParams)
|
||||||
|
exception.PEM(err, "获取测点名称失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// DevicePointPage 测点列表
|
||||||
|
func (r *DevicePoint) DevicePointPage(req *form.DevicePointListReq) map[string]interface{} {
|
||||||
|
count, list, err := repository.GroupRepositorys.DevicePoint.GetDevicePointPage(req)
|
||||||
|
exception.PEM(err, "获取列表失败")
|
||||||
|
ListRsp := make(map[string]interface{})
|
||||||
|
ListRsp["total"] = count
|
||||||
|
ListRsp["list"] = list
|
||||||
|
return ListRsp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *DevicePoint) DevicePointEditDetail(req *form.DevicePointEditDetailReq) *device_point_model.DevicePoint {
|
||||||
|
dp, err := repository.GroupRepositorys.DevicePoint.GetOneDevicePoint(map[string]interface{}{"id": req.Id})
|
||||||
|
exception.PBM(err != nil, "获取测点详情失败")
|
||||||
|
return dp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *DevicePoint) CreateDevicePoint(req *form.CreateDevicePointReq) {
|
||||||
|
var err error
|
||||||
|
dp := &device_point_model.DevicePoint{}
|
||||||
|
dp.DriverId = req.DriverId
|
||||||
|
dp.PointId = req.PointId
|
||||||
|
dp.PointNameId = req.PointNameId
|
||||||
|
dp.EnergyType = req.EnergyType
|
||||||
|
err = repository.GroupRepositorys.DevicePoint.CreateDevicePoint(dp)
|
||||||
|
exception.PBM(err != nil, "创建测点失败")
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
func (r *DevicePoint) UpdateDevicePoint(req *form.UpdateDevicePointReq) {
|
||||||
|
var err error
|
||||||
|
dp, err := repository.GroupRepositorys.DevicePoint.GetOneDevicePoint(map[string]interface{}{"id": req.Id})
|
||||||
|
exception.PBM(err != nil, "修改测点失败")
|
||||||
|
dp.DriverId = req.DriverId
|
||||||
|
dp.PointId = req.PointId
|
||||||
|
dp.PointNameId = req.PointNameId
|
||||||
|
dp.EnergyType = req.EnergyType
|
||||||
|
err = repository.GroupRepositorys.DevicePoint.UpdateDevicePoint(dp)
|
||||||
|
exception.PBM(err != nil, "修改测点失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package service
|
|||||||
type groupService struct {
|
type groupService struct {
|
||||||
Common
|
Common
|
||||||
PeakValley
|
PeakValley
|
||||||
|
DevicePoint
|
||||||
}
|
}
|
||||||
|
|
||||||
var GroupServices = new(groupService)
|
var GroupServices = new(groupService)
|
||||||
|
|||||||
Reference in New Issue
Block a user