123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package crm
- import (
- "hongze/hz_crm_eta/global"
- "time"
- )
- type SysDepartment struct {
- DepartmentId int `gorm:"primaryKey;column:department_id;type:int(11);not null" json:"department_id"`
- DepartmentName string `gorm:"unique;column:department_name;type:varchar(255);default:''" json:"department_name"` // 部门名称
- CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"` // 创建时间
- Sort int `gorm:"column:sort;type:int(10);not null;default:0" json:"sort"` // 排序
- }
- func (m *SysDepartment) TableName() string {
- return "sys_department"
- }
- // Create 新增部门
- func (m *SysDepartment) Create() (err error) {
- err = global.MYSQL["hz_crm"].Create(m).Error
- return
- }
- // Update 更新部门
- func (m *SysDepartment) Update(cols []string) (err error) {
- err = global.MYSQL["hz_crm"].Model(m).Select(cols).Updates(m).Error
- return
- }
- // GetDepartmentById 主键获取部门
- func GetDepartmentById(departmentId int) (item *SysDepartment, err error) {
- err = global.MYSQL["hz_crm"].Where("department_id = ?", departmentId).First(&item).Error
- return
- }
- // DeleteDepartmentById 主键删除部门
- func DeleteDepartmentById(departmentId int) (err error) {
- sql := `DELETE FROM sys_department WHERE department_id = ? LIMIT 1`
- err = global.MYSQL["hz_crm"].Exec(sql, departmentId).Error
- return
- }
|