12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package wx_crm
- import (
- "eta/eta_bridge/global"
- "gorm.io/gorm/clause"
- )
- type DepartmentType string
- const (
- SubCompany DepartmentType = "sub"
- Department DepartmentType = "department"
- )
- type SysDepartment struct {
- SysDepartmentId int `gorm:"primaryKey;column:sys_department_id;type:int(11);not null" json:"department_id"`
- SysDepartmentName string `gorm:"unique;column:sys_department_name;type:varchar(255);default:''" json:"department_name"` // 部门名称
- OutId int `gorm:"column:out_id;type:int(11);not null" json:"out_id"`
- Type DepartmentType `gorm:"column:type;type:varchar(50);not null" json:"type"`
- Sort int `gorm:"column:sort;type:int(10);not null;default:0" json:"sort"` // 排序
- Level int `gorm:"column:level" json:"level"` // 外部id
- ParentId int `gorm:"column:parent_id;type:int(11);not null" json:"parent_id"`
- }
- func (m *SysDepartment) TableName() string {
- return "sys_department"
- }
- func BatchInsertOrUpdate(departments []SysDepartment) (err error) {
- db := global.MYSQL["ht_crm"]
- OnConflictFunc := clause.OnConflict{
- Columns: []clause.Column{{Name: "out_id"}, {Name: "type"}},
- DoUpdates: clause.AssignmentColumns([]string{"sys_department_name", "level", "sort", "parent_id"}),
- }
- // 执行批量插入或更新操作
- err = db.Clauses(OnConflictFunc).Create(&departments).Error
- return
- }
- func GetDepartmentList() (list []SysDepartment, err error) {
- db := global.MYSQL["ht_crm"]
- err = db.Select("*").Find(&list).Error
- if err != nil {
- global.FILE_LOG.Error("获取CRM部门列表失败", err.Error())
- }
- return
- }
|