浏览代码

灯杆分组list submit

terry 3 年之前
父节点
当前提交
ad3e4480af

+ 21 - 0
app/controller/lampPoleGroupController.go

@@ -2,6 +2,10 @@ package controller
 
 import (
 	"github.com/gin-gonic/gin"
+	"iot_manager_service/app/model"
+	"iot_manager_service/app/service"
+	"iot_manager_service/app/utils"
+	"net/http"
 )
 
 // 灯杆分组管理对象
@@ -13,9 +17,26 @@ func (c *lampPoleGroupCtl) Detail(ctx *gin.Context) {
 }
 
 func (c *lampPoleGroupCtl) CreateOrUpdate(ctx *gin.Context) {
+	var req *model.ReqLampPoleGroupSubmit
+	if err := ctx.ShouldBindJSON(&req); err != nil {
+		ctx.JSON(http.StatusOK, utils.ParamsInvalidResponse(err.Error(), nil))
+		return
+	}
+	err := service.LampPoleGroupService.CreateOrUpdate(req)
+	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *lampPoleGroupCtl) List(ctx *gin.Context) {
+	var req *model.ReqLampPoleGroupList
+	if err := ctx.ShouldBindJSON(&req); err != nil {
+		ctx.JSON(http.StatusOK, utils.ParamsInvalidResponse(err.Error(), nil))
+		return
+	}
+	devices, err := service.LampPoleGroupService.List(req)
+	if err != nil {
+		ctx.JSON(http.StatusOK, err)
+	}
+	ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, devices))
 }
 
 func (c *lampPoleGroupCtl) Remove(ctx *gin.Context) {

+ 58 - 0
app/dao/lampPoleGroupDto.go

@@ -0,0 +1,58 @@
+package dao
+
+import (
+	"time"
+)
+
+//LampPoleGroup 灯杆分组
+type LampPoleGroup struct {
+	ID            int       `gorm:"type:int;primary_key"` //编号
+	PoleGroupName string    `gorm:"type:varchar(64)"`     //分组名称
+	TenantId      string    `gorm:"type:varchar(12)"`     //租户ID
+	CreateTime    time.Time `gorm:"type:datetime"`        //新增时间
+	CreateUser    string    `gorm:"type:varchar(60)"`     //新增记录操作用户ID
+	UpdateTime    time.Time `gorm:"type:datetime"`        //修改时间
+	UpdateUser    string    `gorm:"type:varchar(60)"`     //修改用户
+	IsDeleted     int       `gorm:"type:int;default 0"`   //是否删除 0=未删除,1=删除
+	Tag           string    `gorm:"type:varchar(255)"`    //标签,(备用,逗号区分)
+	Remark        string    `gorm:"type:varchar(255)"`    //备注
+}
+
+func (LampPoleGroup) TableName() string {
+	return "t_dev_lamp_pole_group"
+}
+
+func (c LampPoleGroup) Delete() error {
+	return GDb.Model(&c).Updates(map[string]interface{}{"state": 0}).Error
+}
+
+func (c LampPoleGroup) IsExistedByCode() (bool, error) {
+	var count = 0
+	err := GDb.Model(&c).Where(" id = ? ", c.ID).Count(&count).Error
+	return count > 0, err
+}
+
+func (c LampPoleGroup) GetDeviceID() (int, error) {
+	err := GDb.Model(&c).Where(" pole_group_name = ? and tenant_id = ? and is_deleted = ?", c.PoleGroupName, c.TenantId, c.IsDeleted).First(&c).Error
+	return c.ID, err
+}
+
+func (c LampPoleGroup) Create() error {
+	return GDb.Create(&c).Error
+}
+
+func (c LampPoleGroup) Update() error {
+	return GDb.Model(&c).Updates(map[string]interface{}{"pole_group_name": c.PoleGroupName,
+		"tenant_id": c.TenantId, "update_time": time.Now(), "update_user": "TODO", "is_deleted": 0}).Error
+}
+
+func (c LampPoleGroup) GetDevice() error {
+	err := GDb.Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
+	return err
+}
+
+func (c LampPoleGroup) GetDevices(offset, limit int) ([]LampPoleGroup, error) {
+	var devices []LampPoleGroup
+	err := GDb.Model(&c).Where(" id like '%?%'", c.PoleGroupName).Offset(offset).Limit(limit).Scan(&devices).Error
+	return devices, err
+}

+ 40 - 0
app/model/lampPoleGroup.go

@@ -0,0 +1,40 @@
+package model
+
+import "time"
+
+type ReqLampPoleGroupSubmit struct {
+	ID             int          `json:"id"`             //分组编码
+	PoleGroupName  string       `json:"poleGroupName"`  //分组名
+	CountLampPole  string       `json:"countLampPole"`  //灯杆数
+	Remark         string       `json:"remark"`         //备注
+	TenantId       string       `json:"tenant_id"`      //租户ID
+	CreateTime     time.Time    `json:"create_time"`    //新增时间
+	CreateUser     string       `json:"create_user"`    //新增记录操作用户ID
+	UpdateTime     time.Time    `json:"update_time"`    //修改时间
+	UpdateUser     string       `json:"update_user"`    //修改用户
+	IsDeleted      int          `json:"is_deleted"`     //是否删除 0=未删除,1=删除
+	Tag            string       `json:"tag"`            //标签,(备用,逗号区分)
+	PublicName     string       `json:"publicName"`     //标节目发布时使用
+	LampPoleVOList []lampPoleVO `json:"lampPoleVOList"` //分组下的所有灯杆集合
+	CameraList     []camera     `json:"cameraList"`     //智能安防中调用摄像头直播列表
+	SwitchBoxList  []switchBox  `json:"switchBoxList"`  //智能安防中调用配电箱直播列表
+	InfoBoardList  []infoBoard  `json:"infoBoardList"`  //节目组下查询分组下的信息屏集合
+}
+
+type lampPoleVO struct {
+}
+
+type camera struct {
+}
+
+type switchBox struct {
+}
+
+type infoBoard struct {
+}
+
+type ReqLampPoleGroupList struct {
+	PoleGroupName string `json:"poleGroupName"` //分组名
+	Current       int    `json:"current"`       //当前分页
+	Size          int    `json:"size"`          //每页数量
+}

+ 5 - 6
app/service/cameraService.go

@@ -13,12 +13,11 @@ type cameraService struct{}
 func (s *cameraService) CreateOrUpdate(req *model.ReqCamera) error {
 	// 创建查询实例
 	device := dao.CameraDevice{
-		ID:        req.Code, //设备ID,DID
-		Name:      req.Name, //集控器名称
-		GatewayId: req.GID,  //网关ID
-		DevType:   req.DevType,
-		Tenant:    req.Tenant,
-		Status:    req.State, //1启用,0禁用
+		ID:         req.Code, //设备ID,DID
+		DeviceName: req.Name, //集控器名称
+		GatewayId:  req.GID,  //网关ID
+		TenantId:   req.Tenant,
+		Status:     req.State, //1启用,0禁用
 	}
 	if err := device.SaveFromWeb(); err != nil {
 		return err

+ 61 - 0
app/service/lampPoleGroupService.go

@@ -0,0 +1,61 @@
+package service
+
+import (
+	"iot_manager_service/app/dao"
+	"iot_manager_service/app/model"
+	"iot_manager_service/app/utils"
+	"time"
+)
+
+// 中间件管理服务
+var LampPoleGroupService = new(lampPoleGroupService)
+
+type lampPoleGroupService struct{}
+
+func (s *lampPoleGroupService) CreateOrUpdate(req *model.ReqLampPoleGroupSubmit) *utils.Errors {
+	// 创建查询实例
+	device := dao.LampPoleGroup{
+		PoleGroupName: req.PoleGroupName,
+		TenantId:      "000000", // todo: 使用登录态
+		IsDeleted:     0,
+	}
+
+	if id, err := device.GetDeviceID(); err != nil || id == req.ID {
+		return utils.ParamsInvalidResponse("列表中存在重名,请更改灯杆分组名称!", nil)
+	}
+
+	if req.ID == 0 {
+		device.CreateTime = time.Now()
+		device.CreateUser = "TODO" // todo: 使用登录态
+		if err := device.Create(); err != nil {
+			return utils.FailResponse(err.Error(), nil)
+		}
+		return utils.SuccessResponse(utils.Succeeded, nil)
+	}
+	device.UpdateTime = time.Now()
+	device.UpdateUser = "TODO" // todo: 使用登录态
+	if err := device.Update(); err != nil {
+		return utils.FailResponse(err.Error(), nil)
+	}
+	return utils.SuccessResponse(utils.Succeeded, nil)
+}
+
+func (s *lampPoleGroupService) List(req *model.ReqLampPoleGroupList) ([]dao.LampPoleGroup, *utils.Errors) {
+	// 创建查询实例
+	device := dao.LampPoleGroup{
+		PoleGroupName: req.PoleGroupName,
+	}
+	if req.Current == 0 {
+		req.Current = 1
+	}
+	if req.Size < 0 || req.Size > 100 {
+		req.Size = 10
+	}
+	offset := (req.Current - 1) * req.Size
+	limit := req.Size
+	devices, err := device.GetDevices(offset, limit)
+	if err != nil {
+		return nil, utils.FailResponse(err.Error(), nil)
+	}
+	return devices, nil
+}

+ 8 - 6
app/utils/errors.go

@@ -7,7 +7,9 @@ type Errors struct {
 }
 
 const (
-	CodeSucceed       = 0
+	CodeSucceed  = 0
+	CodeInternal = 9999
+
 	CodeParamsInvalid = 10001
 )
 
@@ -16,18 +18,18 @@ const (
 	Failed    = "操作失败"
 )
 
-func SuccessResponse(data interface{}) *Errors {
+func SuccessResponse(msg string, data interface{}) *Errors {
 	return &Errors{
 		Code: CodeSucceed,
-		Msg:  Succeeded,
+		Msg:  msg,
 		Data: data,
 	}
 }
 
-func FailResponse(data interface{}) *Errors {
+func FailResponse(msg string, data interface{}) *Errors {
 	return &Errors{
-		Code: CodeSucceed,
-		Msg:  Failed,
+		Code: CodeInternal,
+		Msg:  msg,
 		Data: data,
 	}
 }