|
@@ -652,15 +652,22 @@ func (this *DeviceAPIController) CreateGroup() {
|
652
|
652
|
}
|
653
|
653
|
|
654
|
654
|
adminInfo := this.GetAdminUserInfo()
|
655
|
|
- group, createErr := service.CreateDeviceGroup(adminInfo.CurrentOrgId, name)
|
656
|
|
- if createErr != nil {
|
657
|
|
- this.ErrorLog("创建设备分组失败:%v", createErr)
|
658
|
|
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
|
659
|
|
- return
|
660
|
|
- }
|
661
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
662
|
|
- "group": group,
|
663
|
|
- })
|
|
655
|
+ _, errcode := service.GetDeviceGroupName(name, adminInfo.CurrentOrgId)
|
|
656
|
+ if errcode == gorm.ErrRecordNotFound{
|
|
657
|
+ group, createErr := service.CreateDeviceGroup(adminInfo.CurrentOrgId, name)
|
|
658
|
+ if createErr != nil {
|
|
659
|
+ this.ErrorLog("创建设备分组失败:%v", createErr)
|
|
660
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
|
|
661
|
+ return
|
|
662
|
+ }
|
|
663
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
664
|
+ "group": group,
|
|
665
|
+ })
|
|
666
|
+ }else if errcode == nil{
|
|
667
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
|
|
668
|
+ return
|
|
669
|
+ }
|
|
670
|
+
|
664
|
671
|
}
|
665
|
672
|
|
666
|
673
|
// /api/device/group/modify [post] ModifyGroup
|
|
@@ -687,8 +694,12 @@ func (this *DeviceAPIController) ModifyGroup() {
|
687
|
694
|
|
688
|
695
|
group.Name = name
|
689
|
696
|
group.ModifyTime = time.Now().Unix()
|
690
|
|
-
|
691
|
|
- updateErr := service.UpdateDeviceGroup(group)
|
|
697
|
+ byName, getGroupErr := service.GetUpdateDeviceGroupByName(name, adminInfo.CurrentOrgId)
|
|
698
|
+ if byName.ID > 0 && byName.ID != id {
|
|
699
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
700
|
+ return
|
|
701
|
+ }
|
|
702
|
+ updateErr := service.UpdateDeviceGroup(group)
|
692
|
703
|
if updateErr != nil {
|
693
|
704
|
this.ErrorLog("修改设备分组失败:%v", updateErr)
|
694
|
705
|
this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
|