Bladeren bron

更新代码

XMLWAN 4 jaren geleden
bovenliggende
commit
2a8db1c3a2
4 gewijzigde bestanden met toevoegingen van 55 en 34 verwijderingen
  1. 14 6
      controllers/device_api_controller.go
  2. 24 24
      models/dialysis.go
  3. 13 0
      service/device_service.go
  4. 4 4
      service/dialysis_service.go

+ 14 - 6
controllers/device_api_controller.go Bestand weergeven

@@ -2,6 +2,7 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/utils"
5
+	"github.com/jinzhu/gorm"
5 6
 	"time"
6 7
 
7 8
 	"XT_New/enums"
@@ -525,15 +526,22 @@ func (this *DeviceAPIController) CreateZone() {
525 526
 	}
526 527
 
527 528
 	adminInfo := this.GetAdminUserInfo()
528
-	zone, createErr := service.CreateDeviceZone(adminInfo.CurrentOrgId, name, type_)
529
-	if createErr != nil {
530
-		this.ErrorLog("创建设备分区失败:%v", createErr)
529
+	_, errcode := service.GetZoneByName(name, adminInfo.CurrentOrgId)
530
+	fmt.Println("errcode=----------", errcode)
531
+	if errcode == gorm.ErrRecordNotFound {
532
+		zone, createErr := service.CreateDeviceZone(adminInfo.CurrentOrgId, name, type_)
533
+		if createErr != nil {
534
+			this.ErrorLog("创建设备分区失败:%v", createErr)
535
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
536
+			return
537
+		}
538
+		this.ServeSuccessJSON(map[string]interface{}{
539
+			"zone": zone,
540
+		})
541
+	} else if errcode == nil {
531 542
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
532 543
 		return
533 544
 	}
534
-	this.ServeSuccessJSON(map[string]interface{}{
535
-		"zone": zone,
536
-	})
537 545
 }
538 546
 
539 547
 // /api/device/zone/modify [post] ModifyZone

+ 24 - 24
models/dialysis.go Bestand weergeven

@@ -808,30 +808,6 @@ func (GobalTemplate) TableName() string {
808 808
 	return "xt_gobal_template"
809 809
 }
810 810
 
811
-type UserAdminRoles struct {
812
-	ID            int64  `gorm:"column:id" json:"id" form:"id"`
813
-	AdminUserId   int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
814
-	OrgId         int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
815
-	AppId         int64  `gorm:"column:app_id" json:"app_id" form:"app_id"`
816
-	RoleId        int64  `gorm:"column:role_id" json:"role_id" form:"role_id"`
817
-	UserName      string `gorm:"column:user_name" json:"user_name" form:"user_name"`
818
-	Avatar        string `gorm:"column:avatar" json:"avatar" form:"avatar"`
819
-	UserType      int64  `gorm:"column:user_type" json:"user_type" form:"user_type"`
820
-	UserTitle     int64  `gorm:"column:user_title" json:"user_title" form:"user_title"`
821
-	Intro         string `gorm:"column:intro" json:"intro" form:"intro"`
822
-	Status        int64  `gorm:"column:status" json:"status" form:"status"`
823
-	Ctime         int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
824
-	Mtime         int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
825
-	UserTitleName string `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
826
-	RoleIds       string `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
827
-	Message       string `gorm:"column:message" json:"message" form:"message"`
828
-	Sex           int64  `gorm:"column:sex" json:"sex" form:"sex"`
829
-	Birthday      int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
830
-	Creator       int64  `gorm:"column:creator" json:"creator" form:"creator"`
831
-	Url           string `gorm:"column:url" json:"url" form:"url"`
832
-	Hash          string `gorm:"column:hash" json:"hash" form:"hash"`
833
-}
834
-
835 811
 type SgjUserAdminRole struct {
836 812
 	ID            int64  `gorm:"column:id" json:"id" form:"id"`
837 813
 	AdminUserId   int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
@@ -878,3 +854,27 @@ type SgjUserAdmin struct {
878 854
 func (SgjUserAdmin) TableName() string {
879 855
 	return "sgj_user_admin"
880 856
 }
857
+
858
+type UserAdminRoles struct {
859
+	ID            int64  `gorm:"column:id" json:"id" form:"id"`
860
+	AdminUserId   int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
861
+	OrgId         int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
862
+	AppId         int64  `gorm:"column:app_id" json:"app_id" form:"app_id"`
863
+	RoleId        int64  `gorm:"column:role_id" json:"role_id" form:"role_id"`
864
+	UserName      string `gorm:"column:user_name" json:"user_name" form:"user_name"`
865
+	Avatar        string `gorm:"column:avatar" json:"avatar" form:"avatar"`
866
+	UserType      int64  `gorm:"column:user_type" json:"user_type" form:"user_type"`
867
+	UserTitle     int64  `gorm:"column:user_title" json:"user_title" form:"user_title"`
868
+	Intro         string `gorm:"column:intro" json:"intro" form:"intro"`
869
+	Status        int64  `gorm:"column:status" json:"status" form:"status"`
870
+	Ctime         int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
871
+	Mtime         int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
872
+	UserTitleName string `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
873
+	RoleIds       string `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
874
+	Message       string `gorm:"column:message" json:"message" form:"message"`
875
+	Sex           int64  `gorm:"column:sex" json:"sex" form:"sex"`
876
+	Birthday      int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
877
+	Creator       int64  `gorm:"column:creator" json:"creator" form:"creator"`
878
+	Url           string `gorm:"column:url" json:"url" form:"url"`
879
+	Hash          string `gorm:"column:hash" json:"hash" form:"hash"`
880
+}

+ 13 - 0
service/device_service.go Bestand weergeven

@@ -272,6 +272,19 @@ func GetDeviceZoneByID(orgID int64, zoneID int64) (*models.DeviceZone, error) {
272 272
 	return &zone, nil
273 273
 }
274 274
 
275
+func GetZoneByName(name string, orgid int64) (*models.DeviceZone, error) {
276
+	zones := models.DeviceZone{}
277
+	err := XTReadDB().Model(&zones).Where("name = ? and org_id = ? and status = 1", name, orgid).Find(&zones).Error
278
+	if err != nil {
279
+		if err == gorm.ErrRecordNotFound {
280
+			return nil, nil
281
+		} else {
282
+			return nil, err
283
+		}
284
+	}
285
+	return &zones, nil
286
+}
287
+
275 288
 func CreateDeviceZone(orgID int64, name string, type_ int) (*models.DeviceZone, error) {
276 289
 	now := time.Now().Unix()
277 290
 	zone := models.DeviceZone{

+ 4 - 4
service/dialysis_service.go Bestand weergeven

@@ -695,13 +695,13 @@ func GetAdminUserES(orgID int64, appID int64, ids []int64) (es []*models.AdminUs
695 695
 	return
696 696
 }
697 697
 
698
-func GetAdminUserEsOne(orgid int64) (adminrole []*models.UserAdminRoles, err error) {
698
+func GetAdminUserEsOne(orgid int64) (admin []*models.UserAdminRoles, err error) {
699 699
 
700 700
 	db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1")
701 701
 	table := readUserDb.Table("sgj_user_admin_electronic_signature as s")
702
-	fmt.Println(table)
703
-	err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ?", orgid).Scan(&adminrole).Error
704
-	return adminrole, err
702
+	fmt.Println("table", table)
703
+	err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ?", orgid).Scan(&admin).Error
704
+	return admin, err
705 705
 }
706 706
 
707 707
 func UpDateDialysisPrescriptionDoctorSign(patient int64, date int64, orgId int64, doctor_id int64) (err error) {