设备分配组织

This commit is contained in:
XM-GO
2023-09-15 17:27:57 +08:00
parent 6562991f90
commit a0af16527e
3 changed files with 28 additions and 3 deletions

View File

@@ -59,6 +59,8 @@ func (p *DeviceApi) GetDeviceListAll(rc *restfulx.ReqCtx) {
data.Status = restfulx.QueryParam(rc, "status")
data.Pid = restfulx.QueryParam(rc, "pid")
data.DeviceType = restfulx.QueryParam(rc, "deviceType")
data.RoleId = rc.LoginAccount.RoleId
data.Owner = rc.LoginAccount.UserName
list := p.DeviceApp.FindList(data)
rc.ResData = list
@@ -133,11 +135,11 @@ func (p *DeviceApi) DownAttribute(rc *restfulx.ReqCtx) {
func (p *DeviceApi) InsertDevice(rc *restfulx.ReqCtx) {
var data entity.Device
restfulx.BindJsonAndValid(rc, &data)
data.Owner = rc.LoginAccount.UserName
data.OrgId = rc.LoginAccount.OrganizationId
list := p.DeviceApp.FindList(entity.Device{Name: data.Name})
biz.IsTrue(!(list != nil && len(*list) > 0), fmt.Sprintf("名称%s已存在设置其他命名", data.Name))
data.Id = kgo.KStr.Uniqid("d_")
data.Owner = rc.LoginAccount.UserName
data.OrgId = rc.LoginAccount.OrganizationId
data.LinkStatus = global.INACTIVE
data.LastAt = time.Now()
p.DeviceApp.Insert(data)
@@ -193,7 +195,9 @@ func (p *DeviceApi) ScreenTwinData(rc *restfulx.ReqCtx) {
}
rc.ResData = vp
} else {
findList, _ := p.DeviceApp.FindListPage(pageNum, pageSize, entity.Device{Pid: classId})
device := entity.Device{Pid: classId, RoleId: rc.LoginAccount.RoleId}
device.Owner = rc.LoginAccount.UserName
findList, _ := p.DeviceApp.FindListPage(pageNum, pageSize, device)
vt := make([]entity.VisualTwin, 0)
for _, device := range *findList {
vt = append(vt, entity.VisualTwin{
@@ -204,3 +208,14 @@ func (p *DeviceApi) ScreenTwinData(rc *restfulx.ReqCtx) {
rc.ResData = vt
}
}
func (p *DeviceApi) DeviceAllotOrg(rc *restfulx.ReqCtx) {
id := restfulx.PathParam(rc, "id")
orgId := restfulx.QueryInt(rc, "orgId", 0)
biz.IsTrue(orgId != 0, "请选择组织")
device := entity.Device{}
device.Id = id
device.OrgId = int64(orgId)
p.DeviceApp.Update(device)
}