package dormitoryes import ( "hr_server/overall" "strings" ) // 宿舍 type Dormitory struct { Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` Name string `json:"name" gorm:"column:name;type:varchar(255) ;comment:单元名称"` TotalFloor int64 `json:"totalfloor" gorm:"column:totalfloor;type:int(5) unsigned;default:1;not null;comment:床位数量"` SeatJson string `json:"seatjson" gorm:"column:seatjson;type:longtext ;comment:床位json布局"` UnitId int64 `json:"unitid" gorm:"column:unitid;type:bigint(20) unsigned;default:0;not null;comment:归属单元"` FloorId int64 `json:"floorid" gorm:"column:floorid;type:int(3) unsigned;default:1;not null;comment:归属楼层"` State int `json:"state" gorm:"column:state;type:int(2) unsigned;default:1;not null;comment:状态(1:新入;2:调出;3:调入;4:退宿;5:限制管控;6:封禁;7;废弃;8:重新启用;9:拆除)"` Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:写入时间"` } func (Dormitory *Dormitory) TableName() string { return "dormitory" } // 编辑内容 func (cont *Dormitory) EiteCont(whereMap interface{}, saveData interface{}) (err error) { err = overall.CONSTANT_DB_HR.Model(&cont).Where(whereMap).Updates(saveData).Error return } // 获取内容 func (cont *Dormitory) GetCont(whereMap interface{}, field ...string) (err error) { gormDb := overall.CONSTANT_DB_HR.Model(&cont) if len(field) > 0 { fieldStr := strings.Join(field, ",") gormDb = gormDb.Select(fieldStr) } gormDb = gormDb.Where(whereMap) err = gormDb.First(&cont).Error return } // 根据条件获取总数 func (cont *Dormitory) CountCont(whereMap interface{}) (countId int64) { overall.CONSTANT_DB_HR.Model(&cont).Where(whereMap).Count(&countId) return } // 读取全部信息 func (cont *Dormitory) ContMap(whereMap interface{}, field ...string) (countAry []Dormitory, err error) { gormDb := overall.CONSTANT_DB_HR.Model(&cont) if len(field) > 0 { fieldStr := strings.Join(field, ",") gormDb = gormDb.Select(fieldStr) } err = gormDb.Where(whereMap).Find(&countAry).Error return } // 删除内容 func (cont *Dormitory) DelCont(whereMap interface{}) (err error) { err = overall.CONSTANT_DB_HR.Where(whereMap).Delete(&cont).Error return }