99	"github.com/eryajf/go-ldap-admin/public/tools" 
1010
1111	"github.com/thoas/go-funk" 
12+ 	"gorm.io/datatypes" 
1213	"gorm.io/gorm" 
1314)
1415
@@ -760,6 +761,18 @@ func InitData() {
760761			SourceDeptParentId : fmt .Sprintf ("%s_%d" , config .Conf .FeiShu .Flag , 0 ),
761762			GroupDN :            fmt .Sprintf ("ou=%s,%s" , config .Conf .FeiShu .Flag + "root" , config .Conf .Ldap .BaseDN ),
762763		},
764+ 		{
765+ 			Model :              gorm.Model {ID : 5 },
766+ 			GroupName :          "group" ,
767+ 			Remark :             "默认分组" ,
768+ 			Creator :            "system" ,
769+ 			GroupType :          "cn" ,
770+ 			ParentId :           1 ,
771+ 			SourceDeptId :       "platform_0" ,
772+ 			Source :             "platform" ,
773+ 			SourceDeptParentId : "openldap_1" ,
774+ 			GroupDN :            fmt .Sprintf ("cn=%s,%s" , "group" , config .Conf .Ldap .BaseDN ),
775+ 		},
763776	}
764777
765778	for  _ , group  :=  range  groups  {
@@ -774,4 +787,47 @@ func InitData() {
774787			Log .Errorf ("写入分组数据失败:%v" , err )
775788		}
776789	}
790+ 
791+ 	// 7.写入关系管理 
792+ 	filedRelation  :=  []model.FieldRelation {
793+ 		{
794+ 			Flag :       "dingtalk_group" ,
795+ 			Attributes : datatypes .JSON (`{"groupName":"custom_name_pinyin","remark":"name","sourceDeptId":"id","sourceDeptParentId":"parentid"}` ),
796+ 		},
797+ 		{
798+ 			Flag :       "dingtalk_user" ,
799+ 			Attributes : datatypes .JSON (`{"avatar":"avatar","givenName":"name","introduction":"remark","jobNumber":"job_number","mail":"email","mobile":"mobile","nickname":"name","position":"title","postalAddress":"work_place","sourceUnionId":"unionid","sourceUserId":"userid","username":"custom_name_pinyin"}` ),
800+ 		},
801+ 		{
802+ 			Flag :       "feishu_group" ,
803+ 			Attributes : datatypes .JSON (`{"groupName":"custom_name_pinyin","remark":"name","sourceDeptId":"open_department_id","sourceDeptParentId":"parent_department_id"}` ),
804+ 		},
805+ 		{
806+ 			Flag :       "feishu_user" ,
807+ 			Attributes : datatypes .JSON (`{"avatar":"avatar","givenName":"name","introduction":"name","jobNumber":"employee_no","mail":"email","mobile":"mobile","nickname":"name","position":"job_title","postalAddress":"work_station","sourceUnionId":"union_id","sourceUserId":"user_id","username":"custom_name_pinyin"}` ),
808+ 		},
809+ 		{
810+ 			Flag :       "wecom_group" ,
811+ 			Attributes : datatypes .JSON (`{"groupName":"custom_name_pinyin","remark":"name","sourceDeptId":"parentid","sourceDeptParentId":"id"}` ),
812+ 		},
813+ 		{
814+ 			Flag :       "wecom_user" ,
815+ 			Attributes : datatypes .JSON (`{"avatar":"avatar","givenName":"alias","introduction":"name","jobNumber":"mobile","mail":"email","mobile":"mobile","nickname":"name","position":"external_position","postalAddress":"address","sourceUnionId":"userid","sourceUserId":"userid","username":"custom_name_pinyin"}` ),
816+ 		},
817+ 	}
818+ 
819+ 	newFieldRelations  :=  make ([]model.FieldRelation , 0 )
820+ 	for  i , newFieldRelation  :=  range  filedRelation  {
821+ 		newFieldRelation .ID  =  uint (i  +  1 )
822+ 		err  :=  DB .First (& newFieldRelation , newFieldRelation .ID ).Error 
823+ 		if  errors .Is (err , gorm .ErrRecordNotFound ) {
824+ 			newFieldRelations  =  append (newFieldRelations , newFieldRelation )
825+ 		}
826+ 	}
827+ 
828+ 	if  len (newFieldRelations ) >  0  {
829+ 		if  err  :=  DB .Create (& newFieldRelations ).Error ; err  !=  nil  {
830+ 			Log .Errorf ("写入关系数据失败:%v" , err )
831+ 		}
832+ 	}
777833}
0 commit comments