123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- package gn
- import (
- "eta_gn/eta_bridge/global"
- "eta_gn/eta_bridge/utils"
- "fmt"
- "strings"
- "time"
- )
- // MDM_COMSTRU MDM组织机构
- type MDM_COMSTRU struct {
- Id int `gorm:"column:Id;primaryKey;autoIncrement" json:"-"`
- MainFieldComstruCode string `gorm:"column:Main_Field_Comstru_Code" json:"Main_Field_Comstru_Code"`
- MainFieldComstruCodeHR string `gorm:"column:Main_Field_Comstru_Code_HR" json:"Main_Field_Comstru_Code_HR"`
- MainFieldComstruTypeHR string `gorm:"column:Main_Field_Comstru_Type_HR" json:"Main_Field_Comstru_Type_HR"`
- ZDWLX string `gorm:"column:ZDWLX" json:"ZDWLX"`
- MainFieldComstruNameHR string `gorm:"column:Main_Field_Comstru_Name_HR" json:"Main_Field_Comstru_Name_HR"`
- MainFieldComstruShortNameHR string `gorm:"column:Main_Field_Comstru_Short_Name_HR" json:"Main_Field_Comstru_Short_Name_HR"`
- MainFieldParentAdminComstruCodeHR string `gorm:"column:Main_Field_ParentAdmin_Comstru_Code_HR" json:"Main_Field_ParentAdmin_Comstru_Code_HR"`
- MainFieldParentAdminComstruCode string `gorm:"column:Main_Field_ParentAdmin_Comstru_Code" json:"Main_Field_ParentAdmin_Comstru_Code"`
- MainFieldParentAdminComstruName string `gorm:"column:Main_Field_ParentAdmin_Comstru_Name" json:"Main_Field_ParentAdmin_Comstru_Name"`
- MainFieldCompanyLevel string `gorm:"column:Main_Field_Company_Level" json:"Main_Field_Company_Level"`
- MainFieldSecondcomstrucodehr string `gorm:"column:Main_Field_Secondcomstrucodehr" json:"Main_Field_Secondcomstrucodehr"`
- MainFieldShBusinessType string `gorm:"column:Main_Field_Sh_Business_Type" json:"Main_Field_Sh_Business_Type"`
- MainFieldYZGDWZCNDGX string `gorm:"column:Main_Field_YZGDWZCNDGX" json:"Main_Field_YZGDWZCNDGX"`
- MainFieldOrderHR string `gorm:"column:Main_Field_Order_HR" json:"Main_Field_Order_HR"`
- MainFieldCompanyCode string `gorm:"column:Main_Field_Company_Code" json:"Main_Field_Company_Code"`
- MainFieldCompanyChain string `gorm:"column:Main_Field_Company_Chain" json:"Main_Field_Company_Chain"`
- MainFieldPARENTCOMPANYVIRTUAL string `gorm:"column:Main_Field_PARENTCOMPANYVIRTUAL" json:"Main_Field_PARENTCOMPANYVIRTUAL"`
- ZQYZT string `gorm:"column:ZQYZT" json:"ZQYZT"`
- CreateTime time.Time `gorm:"column:create_time" json:"create_time"`
- ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time"`
- }
- func (m *MDM_COMSTRU) TableName() string {
- return "MDM_COMSTRU"
- }
- func (m *MDM_COMSTRU) Create() (err error) {
- err = global.MYSQL["hz_eta"].Create(m).Error
- return
- }
- func (m *MDM_COMSTRU) Update(cols []string) (err error) {
- err = global.MYSQL["hz_eta"].Select(cols).Updates(m).Error
- return
- }
- func (m *MDM_COMSTRU) GetItemByCondition(condition string, pars []interface{}) (item *MDM_COMSTRU, err error) {
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
- err = global.MYSQL["hz_eta"].Raw(sql, pars...).First(&item).Error
- return
- }
- func (m *MDM_COMSTRU) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*MDM_COMSTRU, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := ``
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.MYSQL["hz_eta"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // MDM_EMPLOYEE MDM员工表
- type MDM_EMPLOYEE struct {
- Id int `gorm:"column:Id;primaryKey;autoIncrement" json:"-"`
- MainFieldEmployeeCode string `gorm:"column:Main_Field_Employee_Code" json:"Main_Field_Employee_Code"`
- MainFieldEmployeeFirstName string `gorm:"column:Main_Field_Employee_FirstName" json:"Main_Field_Employee_FirstName"`
- MainFieldEmployeeLastName string `gorm:"column:Main_Field_Employee_LastName" json:"Main_Field_Employee_LastName"`
- MainFieldGender string `gorm:"column:Main_Field_Gender" json:"Main_Field_Gender"`
- MainFieldEmpolyeeGroup string `gorm:"column:Main_Field_Empolyee_Group" json:"Main_Field_Empolyee_Group"`
- MainFieldOfficeTelephone string `gorm:"column:Main_Field_Office_Telephone" json:"Main_Field_Office_Telephone"`
- MainFieldDateType string `gorm:"column:Main_Field_Date_Type" json:"Main_Field_Date_Type"`
- MainFieldEmployeeStatus string `gorm:"column:Main_Field_Employee_Status" json:"Main_Field_Employee_Status"`
- MainFieldDeleteFlag string `gorm:"column:Main_Field_Delete_Flag" json:"Main_Field_Delete_Flag"`
- MainFieldEmail string `gorm:"column:Main_Field_Email" json:"Main_Field_Email"`
- MainFieldCompanyCode string `gorm:"column:Main_Field_Company_code" json:"Main_Field_Company_code"`
- MainFieldSecondcomstrucodehr string `gorm:"column:Main_Field_Secondcomstrucodehr" json:"Main_Field_Secondcomstrucodehr"`
- MainFieldCompanyChain string `gorm:"column:Main_Field_Company_Chain" json:"Main_Field_Company_Chain"`
- CreateTime time.Time `gorm:"column:create_time" json:"create_time"`
- ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time"`
- }
- func (m *MDM_EMPLOYEE) TableName() string {
- return "MDM_EMPLOYEE"
- }
- func (m *MDM_EMPLOYEE) Create() (err error) {
- err = global.MYSQL["hz_eta"].Create(m).Error
- return
- }
- func (m *MDM_EMPLOYEE) Update(cols []string) (err error) {
- err = global.MYSQL["hz_eta"].Select(cols).Updates(m).Error
- return
- }
- func (m *MDM_EMPLOYEE) GetItemByCondition(condition string, pars []interface{}) (item *MDM_EMPLOYEE, err error) {
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
- err = global.MYSQL["hz_eta"].Raw(sql, pars...).First(&item).Error
- return
- }
- func (m *MDM_EMPLOYEE) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*MDM_EMPLOYEE, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := ``
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.MYSQL["hz_eta"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // CreateEmployee 新增员工及组织关系
- func (m *MDM_EMPLOYEE) CreateEmployee(employee *MDM_EMPLOYEE, employeeRelation []*MDM_RELA_COMSTRU_EMPLOYEE) (err error) {
- if employee == nil {
- err = fmt.Errorf("employee is nil")
- return
- }
- tx := global.MYSQL["hz_eta"].Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- if e := tx.Create(employee).Error; e != nil {
- err = fmt.Errorf("create employee err, %v", e)
- return
- }
- if len(employeeRelation) == 0 {
- return
- }
- if e := tx.CreateInBatches(employeeRelation, utils.MultiAddNum).Error; e != nil {
- err = fmt.Errorf("create employee relations err, %v", e)
- return
- }
- return
- }
- // UpdateEmployee 更新员工及组织关系
- func (m *MDM_EMPLOYEE) UpdateEmployee(employee *MDM_EMPLOYEE, updateCols []string, employeeRelation []*MDM_RELA_COMSTRU_EMPLOYEE) (err error) {
- if employee == nil {
- err = fmt.Errorf("employee is nil")
- return
- }
- tx := global.MYSQL["hz_eta"].Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- if e := tx.Select(updateCols).Updates(employee).Error; e != nil {
- err = fmt.Errorf("update employee err, %v", e)
- return
- }
- sql := `DELETE FROM MDM_RELA_COMSTRU_EMPLOYEE WHERE Main_Field_Employee_Code = ?`
- if e := tx.Exec(sql, employee.MainFieldEmployeeCode); e != nil {
- err = fmt.Errorf("delete employee relations err, %v", e)
- return
- }
- if len(employeeRelation) == 0 {
- return
- }
- if e := tx.CreateInBatches(employeeRelation, utils.MultiAddNum).Error; e != nil {
- err = fmt.Errorf("create employee relations err, %v", e)
- return
- }
- return
- }
- // MDM_RELA_COMSTRU_EMPLOYEE MDM员工组织关系表
- type MDM_RELA_COMSTRU_EMPLOYEE struct {
- Id int `gorm:"column:Id;primaryKey;autoIncrement" json:"-"`
- Main_Field_Employee_Code string `gorm:"column:Main_Field_Employee_Code" json:"Main_Field_Employee_Code"`
- TuplesFieldCompanyCode string `gorm:"column:Tuples_Field_Company_Code" json:"Tuples_Field_Company_Code"`
- TuplesFieldCompanyName string `gorm:"column:Tuples_Field_Company_Name" json:"Tuples_Field_Company_Name"`
- TuplesFieldDepartmentCode string `gorm:"column:Tuples_Field_Department_Code" json:"Tuples_Field_Department_Code"`
- TuplesFieldDepartmentName string `gorm:"column:Tuples_Field_Department_Name" json:"Tuples_Field_Department_Name"`
- TuplesFieldPositionCode string `gorm:"column:Tuples_Field_Position_Code" json:"Tuples_Field_Position_Code"`
- TuplesFieldPositionName string `gorm:"column:Tuples_Field_Position_Name" json:"Tuples_Field_Position_Name"`
- TuplesFieldPostFlag string `gorm:"column:Tuples_Field_Post_Flag" json:"Tuples_Field_Post_Flag"`
- CreateTime time.Time `gorm:"column:create_time" json:"create_time"`
- ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time"`
- }
- func (m *MDM_RELA_COMSTRU_EMPLOYEE) TableName() string {
- return "MDM_RELA_COMSTRU_EMPLOYEE"
- }
|