@ -18,8 +18,9 @@ namespace :tfxy do
 
			
		
	
		
			
				
					    teach_data_last_row  =  teach_data . last_row 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    2 . upto ( teach_data_last_row )  do  | r | 
 
			
		
	
		
			
				
					      old_user  =  User . where ( " phone = ' #{ teach_data . cell ( r ,  5 ) } ' OR mail = ' #{ teach_data . cell ( r ,  6 ) } ' OR login = 'tfxy #{ teach_data . cell ( r ,  1 ) } '  "  ) . first 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					      if  ! User . where ( " phone = ' #{ teach_data . cell ( r ,  5 ) } ' OR mail = ' #{ teach_data . cell ( r ,  6 ) } ' OR login = 'tfxy #{ teach_data . cell ( r ,  1 ) } '  "  ) . exists 
 
			
		
	
		
			
				
					      if  ! old_user . present 
 
			
		
	
		
			
				
					        user  =  User . new ( 
 
			
		
	
		
			
				
					          phone :  teach_data . cell ( r ,  5 ) , 
 
			
		
	
		
			
				
					          login :  " tfxy #{ teach_data . cell ( r ,  1 ) } " , 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -32,8 +33,8 @@ namespace :tfxy do
 
			
		
	
		
			
				
					          profile_completed :  true , 
 
			
		
	
		
			
				
					          professional_certification :  1 , 
 
			
		
	
		
			
				
					          certification :  1 , 
 
			
		
	
		
			
				
					          laboratory_id:  Laboratory . first . id  
 
			
		
	
		
			
				
					
  
			
		
	
		
			
				
					          authentication:  true ,  
 
			
		
	
		
			
				
					          laboratory_id :  Laboratory . find ( 1 ) & . id   
			
		
	
		
			
				
					        ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        if   user . save! 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -49,13 +50,28 @@ namespace :tfxy do
 
			
		
	
		
			
				
					            department_id :  departemnt . id 
 
			
		
	
		
			
				
					          ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					          open_user  =  OpenUsers :: Cas . find_or_initialize_by ( uid :  student _data. cell ( r ,  1 ) )  do  | u | 
 
			
		
	
		
			
				
					            u . extra  =  { phone :  student _data. cell ( r ,  8 ) } 
 
			
		
	
		
			
				
					          open_user  =  OpenUsers :: Cas . find_or_initialize_by ( uid :  teach _data. cell ( r ,  1 ) )  do  | u | 
 
			
		
	
		
			
				
					            u . extra  =  { phone :  teach _data. cell ( r ,  8 ) } 
 
			
		
	
		
			
				
					            u . user_id  =  user . id 
 
			
		
	
		
			
				
					          end 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					          p  " -------user ----- #{ user . inspect } " 
 
			
		
	
		
			
				
					          open_user . save 
 
			
		
	
		
			
				
					       end 
 
			
		
	
		
			
				
					      else 
 
			
		
	
		
			
				
					        old_user . update ( 
 
			
		
	
		
			
				
					          lastname :  teach_data . cell ( r ,  2 ) , 
 
			
		
	
		
			
				
					          nickname :  teach_data . cell ( r ,  2 ) , 
 
			
		
	
		
			
				
					          certification :  true , 
 
			
		
	
		
			
				
					          professional_certification :  true , 
 
			
		
	
		
			
				
					          authentication :  true , 
 
			
		
	
		
			
				
					          profile_completed :  true ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        OpenUsers :: Cas . find_or_create_by ( uid :  teach_data . cell ( r ,  1 ) )  do  | u | 
 
			
		
	
		
			
				
					          u . extra  =  { phone :  teach_data . cell ( r ,  5 ) } 
 
			
		
	
		
			
				
					          u . user_id  =  old_user . id 
 
			
		
	
		
			
				
					        end 
 
			
		
	
		
			
				
					      end 
 
			
		
	
		
			
				
					    end 
 
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -70,19 +86,25 @@ namespace :tfxy do
 
			
		
	
		
			
				
					      d . city  =  '成都' 
 
			
		
	
		
			
				
					    end 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    course_info  =  { " C程序设计与实践 " = > 4 ,  " 数据库技术应用 " = > 2 ,  " 数据库应用 " = > 2 ,  " 数据库原理 " = > 2 ,  " 数据库实践 " = > 2 ,  " 面向对象程序设计与实践 " = > 2 ,  " JavaSE程序设计及实践( )  " = > 4 ,  " 编译原理 " = > 2 ,  " 电路与电子技术 " = > 3 ,  " 传感器原理与应用 " = > 3 ,  " 物联网技术与应用 " = > 2 ,  " 人工智能实践 " = > 3 ,  " 计算机组成原理 " = > 2 ,  " 移动应用开发实训 " = > 4 ,  " 面向对象程序课程设计 " = > 1 ,  " Web程序设计 " = > 2 ,  " 数据仓库与数据挖掘 " = > 2 ,  " 定量分析技术 " = > 4 ,  " Python程序设计 " = > 4 ,  " 信息系统分析与设计 " = > 3 ,  " 数据处理综合实训 " = > 2 ,  " 绘画基础Ⅱ(色彩构成) " = > 2 ,  " 数字图像处理 " = > 4 ,  " 虚拟现实技术及应用 " = > 4 ,  " 三维建模技术 " = > 4 ,  " 游戏技术基础 " = > 4 ,  " 传感器与单片机实训 " = > 2 ,  " 数据库原理与实践 " = > 4 ,  " 高级程序设计(二) " = > 4 ,  " 数据结构与算法分析 " = > 4 ,  " 实训 " = > 1 ,  " Linux 操作系统 " = > 4 ,  " Java Web程序设计与实践 " = > 8 ,  " 软件测试与项目管理 " = > 4 ,  " Android程序设计 " = > 8 ,  " 移动应用开发 " = > 4 ,  " 商业智能案例分析 " = > 4 ,  " 数据分析与挖掘 " = > 4 ,  " Oracle DBA " = > 4 ,  " 信息网络安全测试与评估 " = > 4 ,  " Android编程 " = > 8 ,  " 电子线路CAD设计 " = > 2 ,  " ARM接口技术 " = > 4 ,  " 嵌入式Linux应用系统设计 " = > 4 ,  " 信息系统开发实训 " = > 2 ,  " 绘画基础I( )  " = > 2 ,  " 智能信息处理技术 " = > 3 } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    course_data  =  xlsx . sheet ( 4 ) 
 
			
		
	
		
			
				
					    course_data_last_row  =  course_data . last_row 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    2 . upto ( course_data_last_row )  do  | r | 
 
			
		
	
		
			
				
					      course_group  =  CourseGroup . find_or_initialize_by ( invite_code :  " #{ course_data . cell ( r ,  1 ) } #{ course_data . cell ( r ,  3 ) } " ) 
 
			
		
	
		
			
				
					      course_group  =  CourseGroup . find_or_initialize_by ( invite_code :  course_data . cell ( r ,  3 ) ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					      teach_user  =  OpenUsers :: Cas . find_by ( uid :  course_data . cell ( r ,  5 ) ) & . user 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					      teach_user  =  User . find_by ( login :  " tfxy #{ course_data . cell ( r ,  5 ) } " ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					      if  ! course_group . persisted? 
 
			
		
	
		
			
				
					        course  =  Course . find_or_initialize_by ( school_id :  school . id ,  name :  course_data . cell ( r ,  2 ) )  do  | d | 
 
			
		
	
		
			
				
					      puts  " ----teach_user-----uid----- #{ course_data . cell ( r ,  5 ) } ------ #{ teach_user . inspect } --- " 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					      if  ! course_group . persisted?  &&  teach_user . present? 
 
			
		
	
		
			
				
					        course  =  Course . find_or_initialize_by ( school_id :  school . id ,  name :  course_data . cell ( r ,  2 ) ,  invite_code :  course_data . cell ( r ,  1 ) [ 3 .. 7 ] )  do  | d | 
 
			
		
	
		
			
				
					          d . is_public  =  0 
 
			
		
	
		
			
				
					          d . tea_id  =  teach_user . id 
 
			
		
	
		
			
				
					          d . laboratory_id  =  Laboratory . first . id 
 
			
		
	
		
			
				
					          d . laboratory_id  =  Laboratory . find ( 1 ) & . id 
 
			
		
	
		
			
				
					          d . credit  =  course_info [ course_data . cell ( r ,  1 ) ] 
 
			
		
	
		
			
				
					        end 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -94,23 +116,26 @@ namespace :tfxy do
 
			
		
	
		
			
				
					          end 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					          course . course_list  =  course_list 
 
			
		
	
		
			
				
					          course . invite_code  =  course_data . cell ( r ,  1 ) [ 3 .. 7 ] 
 
			
		
	
		
			
				
					          course . save! 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					          course . generate_invite_code 
 
			
		
	
		
			
				
					          CourseInfo . create! ( user_id :  teach_user . id ,  course_id :  course . id ) 
 
			
		
	
		
			
				
					          course . create_course_modules ( [ " shixun_homework " ,  " common_homework " ,  " group_homework " ,  " exercise " ,  " attachment " ,  " course_group " ,  " video " ] ) 
 
			
		
	
		
			
				
					        end 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        course_group . position  =  course . course_groups_count  +  1 
 
			
		
	
		
			
				
					        course_group . name  =  " #{ course_data . cell ( r ,  2) } #{ course_data . cell ( r ,  3 ) } "  
 
			
		
	
		
			
				
					        course_group . name  =  course_data . cell ( r ,  4)  
 
			
		
	
		
			
				
					        course_group . course  =  course 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        course_group . save! 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        puts  " ---course_group---- #{ course_group . inspect } " 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        course_member  =  CourseMember . find_or_initialize_by ( course_id :  course . id ,  user_id :  teach_user . id )  do  | d | 
 
			
		
	
		
			
				
					          d . role  =  2 
 
			
		
	
		
			
				
					          d . course_group_id  =  course_group . id 
 
			
		
	
		
			
				
					          d . course_group_id  =  0 
 
			
		
	
		
			
				
					        end 
 
			
		
	
		
			
				
					        course_member . save!  if  ! course_member . persisted? 
 
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -132,8 +157,8 @@ namespace :tfxy do
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    2 . upto ( student_data_last_row )  do  | r | 
 
			
		
	
		
			
				
					      # 邮箱存在 
 
			
		
	
		
			
				
					      if  student_data . cell ( r ,  9 ) . 
 
			
		
	
		
			
				
					        old_user  =  User . where ( " phone = ' #{ student_data . cell ( r ,  8 ) } ' OR mail = ' #{ student_data . cell ( r ,  9 ) } ' OR login = 'tfxy #{ student_data . cell ( r ,  1 ) } '  "  ) . first 
 
			
		
	
		
			
				
					      if  student_data . cell ( r ,  9 ) . strip.  present?
 
			
		
	
		
			
				
					        old_user  =  User . where ( " phone = ' #{ student_data . cell ( r ,  8 ) } ' OR mail = ' #{ student_data . cell ( r ,  9 ) . strip } ' OR login = 'tfxy #{ student_data . cell ( r ,  1 ) } '  "  ) . first 
 
			
		
	
		
			
				
					      else 
 
			
		
	
		
			
				
					        old_user  =  User . where ( " phone = ' #{ student_data . cell ( r ,  8 ) } ' OR login = 'tfxy #{ student_data . cell ( r ,  1 ) } '  "  ) . first 
 
			
		
	
		
			
				
					      end 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -147,13 +172,16 @@ namespace :tfxy do
 
			
		
	
		
			
				
					          lastname :  student_data . cell ( r ,  2 ) , 
 
			
		
	
		
			
				
					          nickname :  student_data . cell ( r ,  2 ) , 
 
			
		
	
		
			
				
					          password :  " Edu #{ student_data . cell ( r ,  1 ) } " , 
 
			
		
	
		
			
				
					          mail :  student_data . cell ( r ,  9 ) , 
 
			
		
	
		
			
				
					          mail :  student_data . cell ( r ,  9 ) . strip , 
 
			
		
	
		
			
				
					          profile_completed :  true , 
 
			
		
	
		
			
				
					          professional_certification :  1 , 
 
			
		
	
		
			
				
					          certification :  1 , 
 
			
		
	
		
			
				
					          laboratory_id :  Laboratory . first . id 
 
			
		
	
		
			
				
					          authentication :  true , 
 
			
		
	
		
			
				
					          laboratory_id :  Laboratory . find ( 1 ) & . id 
 
			
		
	
		
			
				
					        ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        puts  " ----user  #{ user . inspect } " 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        if  user . save! 
 
			
		
	
		
			
				
					          departemnt  =  school . departments . find_or_create_by! ( name :  student_data . cell ( r ,  4 ) ) 
 
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -163,6 +191,7 @@ namespace :tfxy do
 
			
		
	
		
			
				
					            location_city :  school . city , 
 
			
		
	
		
			
				
					            gender :  student_data . cell ( r ,  3 )  ==  '女'  ?  1  :  0 , 
 
			
		
	
		
			
				
					            identity :  1 , 
 
			
		
	
		
			
				
					            student_id :  student_data . cell ( r ,  1 ) , 
 
			
		
	
		
			
				
					            department_id :  departemnt . id 
 
			
		
	
		
			
				
					          ) 
 
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -175,7 +204,14 @@ namespace :tfxy do
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					      else 
 
			
		
	
		
			
				
					        # 系统已有用户,  
 
			
		
	
		
			
				
					        old_user . update ( login :  " tfxy #{ student_data . cell ( r ,  1 ) } " ) 
 
			
		
	
		
			
				
					        old_user . update ( 
 
			
		
	
		
			
				
					           login :  " tfxy #{ student_data . cell ( r ,  1 ) } " , 
 
			
		
	
		
			
				
					            lastname :  student_data . cell ( r ,  2 ) , 
 
			
		
	
		
			
				
					            nickname :  student_data . cell ( r ,  2 ) , 
 
			
		
	
		
			
				
					            certification :  true , 
 
			
		
	
		
			
				
					            professional_certification :  true , 
 
			
		
	
		
			
				
					            authentication :  true , 
 
			
		
	
		
			
				
					            profile_completed :  true ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        OpenUsers :: Cas . find_or_create_by ( uid :  student_data . cell ( r ,  1 ) )  do  | u | 
 
			
		
	
		
			
				
					          u . extra  =  { phone :  student_data . cell ( r ,  8 ) } 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -198,12 +234,21 @@ namespace :tfxy do
 
			
		
	
		
			
				
					    end 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    2 . upto ( course_member_data_last_row )  do  | r | 
 
			
		
	
		
			
				
					      course_group  =  CourseGroup . find_by ( invite_code :  " #{ course_member_data . cell ( r ,  3 ) } #{ course_member_data . cell ( r ,  5 ) } " ) 
 
			
		
	
		
			
				
					      student  =  User . find_by ( login :  " tfxy #{ course_member_data . cell ( r ,  1 ) } " ) 
 
			
		
	
		
			
				
					      course_group  =  CourseGroup . find_by ( invite_code :  course_member_data . cell ( r ,  5 ) ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					      student  =  OpenUsers :: Cas . find_by ( uid :  course_member_data . cell ( r ,  1 ) ) & . user 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					      CourseMember . find_or_create_by! ( course_id :  course_group . course_id ,  user_id :  student . id ,  course_group_id :  course_group . id )  do  | d | 
 
			
		
	
		
			
				
					        d . role  =  4 
 
			
		
	
		
			
				
					      end  if  student . present? 
 
			
		
	
		
			
				
					      puts  " ------student ---  #{ course_member_data . cell ( r ,  1 ) } --course group-- #{ course_member_data . cell ( r ,  5 ) } " 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					      if  student . present?  &&  course_group . present? 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        course_member  =  CourseMember . find_or_initialize_by ( course_id :  course_group . course_id ,  user_id :  student . id )  do  | d | 
 
			
		
	
		
			
				
					          d . role  =  4 
 
			
		
	
		
			
				
					          d . course_group_id  =  course_group . id 
 
			
		
	
		
			
				
					        end 
 
			
		
	
		
			
				
					        puts  " --------course_member  #{ course_member . inspect } " 
 
			
		
	
		
			
				
					        course_member . save!  if  ! course_member . persisted? 
 
			
		
	
		
			
				
					      end 
 
			
		
	
		
			
				
					   end 
 
			
		
	
		
			
				
					  end