diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 6d46b2f59..e72daae6d 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -89,11 +89,15 @@ module Mobile tip = 0 #0班级1项目 type = params[:type] result = 1 + + #0回复 1回复的回复 + reply_type = params[:reply_type] + + update_id = 0 + if params[:content]!="" && current_user case type when "HomeworkCommon" - homework_common = HomeworkCommon.find(params[:id]) - #如果是私有的 并且不是成员则不能回复 # is_public = homework_common.course.is_public # if is_public == 0 && !current_user.member_of_course?(homework_common.course) @@ -106,15 +110,29 @@ module Mobile # result = 2 # end # end - feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) - if (feedback.errors.empty?) - homework_common.update_column(:updated_at, Time.now) - result = 2 + if reply_type == nil || reply_type == 0 + homework_common = HomeworkCommon.find(params[:id]) + feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) + if (feedback.errors.empty?) + homework_common.update_column(:updated_at, Time.now) + result = 2 + update_id = homework_common.id + end + else + #二级回复 + reply = JournalsForMessage.find params[:id].to_i + homework_common = HomeworkCommon.find reply.jour_id + + options = {:notes => params[:content], :reply_id => reply.user_id,:user_id => current_user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i} + feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], reply.jour_id, options) + if (feedback.errors.empty?) + homework_common.update_column(:updated_at, Time.now) + result = 2 + update_id = homework_common.id + end end when "News" - news = News.find(params[:id]) - # if news.project # if news.project.is_public == false && !current_user.member_of?(news.project) # status = -1 @@ -126,19 +144,28 @@ module Mobile # tip = 0 # end # end - if status == 0 - comment = Comment.new - comment.comments = params[:content] - comment.author = current_user - if news.comments << comment - result = 2 + if reply_type == nil || reply_type == 0 + news = News.find(params[:id]) + comment = Comment.new + comment.comments = params[:content] + comment.author = current_user + if news.comments << comment + result = 2 + update_id = news.id + end + else + #二级回复 + comment = Comment.find(params[:id]) + news = News.find comment.commented_id + new_comment = news.comments.build(:author_id => current_user.id, :reply_id => params[:id], :comments => params[:content], :parent_id => comment.id) + if new_comment.save + result = 2 + update_id = news.id + end end end when "Message" - message = Message.find(params[:id]) - board = Board.find(message.board_id) - # if message.project # if message.project.is_public == false && !current_user.member_of?(message.project) # status = -1 @@ -152,20 +179,26 @@ module Mobile # end if status == 0 - topic = message.root - reply = Message.new - reply.author = current_user - reply.board = board - reply.content = params[:content] - reply.parent_id = params[:id] - reply.subject = "RE: #{topic.subject}" - if topic.children << reply - result = 2 - end + # if reply_type == nil || reply_type == 0 + message = Message.find(params[:id]) + board = Board.find(message.board_id) + topic = message.root + reply = Message.new + reply.author = current_user + reply.board = board + reply.content = params[:content] + reply.parent_id = params[:id] + reply.subject = "RE: #{topic.subject}" + if message.children << reply + result = 2 + update_id = topic.id + end + # else + #二级回复 + + # end end when "JournalsForMessage" - jour = JournalsForMessage.find params[:id] - # if jour.jour_type == "Project" # if jour.project.is_public == false && !current_user.member_of?(jour.project) # status = -1 @@ -179,64 +212,108 @@ module Mobile # end if status == 0 - parent_id = params[:id] - author_id = current_user.id - reply_user_id = jour.user_id - reply_id = params[:id] - content = params[:content] - options = {:user_id => author_id, - :status => true, - :m_parent_id => parent_id, - :m_reply_id => reply_id, - :reply_id => reply_user_id, - :notes => content, - :is_readed => false} - jfm = jour.user.add_jour(nil, nil, nil, options) - if jfm.errors.empty? - (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) - result = 2 - end + # if reply_type == nil || reply_type == 0 + jour = JournalsForMessage.find(params[:id]).root + parent_id = params[:id] + author_id = current_user.id + reply_user_id = jour.user_id + reply_id = params[:id] + content = params[:content] + options = {:user_id => author_id, + :status => true, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + jfm = jour.user.add_jour(nil, nil, nil, options) + if jfm.errors.empty? + (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) + result = 2 + update_id = jour.id + end + # else + #二级回复 + + # end end when 'Issue' - issue = Issue.find params[:id] - # if issue.project.is_public == false && !current_user.member_of?(issue.project) # status = -1 # tip = 1 # end if status == 0 - is_jour = Journal.new - is_jour.user_id = current_user.id - is_jour.notes = params[:content] - is_jour.journalized = issue - if is_jour.save - result = 2 + if reply_type == nil || reply_type == 0 + issue = Issue.find params[:id] + is_jour = Journal.new + is_jour.user_id = current_user.id + is_jour.notes = params[:content] + is_jour.journalized = issue + if is_jour.save + result = 2 + update_id = issue.id + end + else + #二级回复 + jour = Journal.find(params[:id]) + issue = jour.journalized + is_jour = Journal.new + is_jour.user_id = current_user.id + is_jour.notes = params[:content] + is_jour.reply_id = params[:id] + is_jour.parent_id = params[:id] + is_jour.journalized = issue + if is_jour.save + result = 2 + update_id = issue.id + end end end when 'BlogComment' - blog = BlogComment.find(params[:id]).root - blogComment = BlogComment.new - blogComment.author = current_user - blogComment.blog = blog.blog - blogComment.content = params[:content] - blogComment.title = "RE: #{blog.title}" - if blog.children << blogComment - result = 2 + if reply_type == nil || reply_type == 0 + blog = BlogComment.find(params[:id]).root + blogComment = BlogComment.new + blogComment.author = current_user + blogComment.blog = blog.blog + blogComment.content = params[:content] + blogComment.title = "RE: #{blog.title}" + if blog.children << blogComment + result = 2 + update_id = blog.id + end + else + #二级回复 + blog = BlogComment.find(params[:id]).root + blogComment = BlogComment.new + blogComment.author = current_user + blogComment.blog = blog.blog + blogComment.content = params[:content] + blogComment.title = "RE: #{blog.title}" + parent = BlogComment.find params[:id] + blogComment.parent_id = params[:id] #被回复的回复 + blogComment.reply_id = parent.author.id #被回复者id + + if parent.children << blogComment + result = 2 + update_id = blog.id + end + end end if result == 2 - update_course_activity_api(type,params[:id]) - update_user_activity_api(type,params[:id]) - update_org_activity_api(type,params[:id]) - update_forge_activity_api(type,params[:id]) - update_principal_activity_api(type,params[:id]) + update_course_activity_api(type,update_id) + update_user_activity_api(type,update_id) + update_org_activity_api(type,update_id) + update_forge_activity_api(type,update_id) + update_principal_activity_api(type,update_id) end else result = 3 end present :result, result present :status, status + present :act_id, update_id present :tip, tip present :subscribe,subscribe end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 764dc957f..557b06cea 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -4,6 +4,61 @@ module Mobile class Users < Grape::API resource :users do + desc "我的资料" + params do + requires :token, type: String + end + + get 'get_userinfo' do + authenticate! + present :data, current_user, with: Mobile::Entities::User + present :status, 0 + end + + desc "上传头像" + params do + requires :token, type: String + requires :imgdata, type: String + end + + post 'upload_head' do + authenticate! + #直接生成头像 + dirPath = "public/images/avatars/User" + + fileDir = dirPath + "/"+current_user.id.to_s + imgdata = Base64.decode64(params[:imgdata].split(",")[1]) + if imgdata.length > 1024*1024 + present :message,"上传图片不能超过1M" + present :status, -1 + else + begin + File.open(fileDir,'wb'){ |f| f.write(imgdata) } + present :status, 0 + rescue + present :message,"上传失败" + present :status, -1 + end + end + end + + desc "解除绑定" + params do + requires :token, type: String + end + + post 'user_unbind' do + authenticate! + + user = current_user + uw = user.user_wechat + + us = UsersService.new + us.wechat_unbind user.user_wechat + + present :status, 0 + end + desc "查询是否已绑定" params do requires :openid, type: String, desc: 'wechat openid' @@ -221,6 +276,73 @@ module Mobile present :data,my_jours,with:Mobile::Entities::Jours present :status,0 end + + desc "修改我的资料" + + params do + requires :token, type: String + requires :lastname, type: String + requires :sex, type: Integer + requires :mail, type: String + end + + post 'edit_userinfo' do + authenticate! + user = current_user + status = 0 + message = "" + + #昵称 不能超过30个字符 + if params[:lastname].length > 30 then + message = "姓名不能超过30个字符!" + status = -1 + end + + if params[:mail].length > 60 then + message = "邮箱地址不能超过60个字符!" + status = -1 + end + + if !(params[:mail].match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i)) + message = "请输入正确的邮箱地址!" + status = -1 + end + + if status == 0 + # 修改邮箱的时候同步修改到gitlab + if user.mail != params[:mail] + g = Gitlab.client + begin + g.edit_user(user.gid, :email => params[:mail]) + rescue + Rails.logger.error "sync user's email of gitlab failed!" + end + end + + user.mail = params[:mail] + + user.lastname = params[:lastname] + + se = user.extensions + + se.gender = params[:sex] + + if user.save && se.save + status = 0 + else + message = "该邮箱地址已被使用!" + status = -1 + end + end + + if status == 0 + present :data, current_user, with: Mobile::Entities::User + present :status, 0 + else + present :status, -1 + present :message, message + end + end end end end diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index dcdf48d3b..30a2a7edd 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -30,15 +30,24 @@ module Mobile u.nil? ? "" : u.show_name when :roles_id u[:roles_id].nil? ? nil : u.roles_id + when :login + u.login + when :lastname + u.lastname + when :mail + u.mail end end end - end end expose :id #头像 + user_expose :login + user_expose :lastname + #邮箱地址 + user_expose :mail expose :nickname #真名 user_expose :img_url @@ -51,8 +60,6 @@ module Mobile #我的二维码 #工作单位 user_expose :work_unit - #邮箱地址 - user_expose :mail #地区 user_expose :location #签名 diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 64f85b5db..d1835408f 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -410,11 +410,11 @@ class StudentWorkController < ApplicationController #开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?) if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name end @show_all = true elsif User.current.member_of_course?(@course) @@ -476,11 +476,11 @@ class StudentWorkController < ApplicationController else if (@homework.is_open == 1 &&@course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?) if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name end @show_all = true elsif User.current.member_of_course?(@course) @@ -613,33 +613,21 @@ class StudentWorkController < ApplicationController student_work.work_status = 1 end if student_work.save - if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 - @student_work_project.student_work_id = student_work.id - @student_work_project.save - members = params[:group_member_ids].split(',') - for i in 1 .. members.count-1 - stu_project = StudentWorkProject.new - stu_project.homework_common_id = @homework.id - stu_project.student_work_id = student_work.id - stu_project.project_id = @student_work_project.project_id - stu_project.user_id = members[i].to_i - stu_project.is_leader = 0 + if @homework.homework_type == 3 + if @homework.homework_detail_group.base_on_project == 1 + @student_work_project.student_work_id = student_work.id + @student_work_project.save + elsif @homework.homework_detail_group.base_on_project == 0 + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => student_work.project_id, :user_id => student_work.user_id, :is_leader => 1) stu_project.save end - elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0 members = params[:group_member_ids].split(',') - for i in 0 .. members.count-1 - stu_project = StudentWorkProject.new - stu_project.homework_common_id = @homework.id - stu_project.student_work_id = student_work.id - stu_project.project_id = -1 - stu_project.user_id = members[i].to_i - if i == 0 - stu_project.is_leader = 1 - else - stu_project.is_leader = 0 + for i in 1 .. members.count-1 + stu_work = StudentWork.new(:name => student_work.name, :description => student_work.description,:user_id =>members[i].to_i, :homework_common_id => @homework.id,:project_id => student_work.project_id, :late_penalty => student_work.late_penalty,:work_status => 3, :commit_time => student_work.commit_time) + if stu_work.save + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0) + stu_project.save end - stu_project.save end end @homework.update_column(:updated_at, Time.now) @@ -687,20 +675,17 @@ class StudentWorkController < ApplicationController if @homework.homework_type == 3 @student_work_project = @homework.student_work_projects.where("user_id=?",User.current.id).first student_work_projects = @homework.student_work_projects.where("student_work_id=? and is_leader =?",@work.id,0) + user_ids = student_work_projects.empty? ? "(-1)" : "(" + student_work_projects.map{|stu|stu.user_id}.join(",") + ")" + student_works = @homework.student_works.where("user_id in #{user_ids}") + student_works.delete_all student_work_projects.delete_all members = params[:group_member_ids].split(',') for i in 1 .. members.count-1 - stu_project = StudentWorkProject.new - stu_project.homework_common_id = @homework.id - stu_project.student_work_id = @work.id - if @homework.homework_detail_group.base_on_project == 1 - stu_project.project_id = @student_work_project.project_id - else @homework.homework_detail_group.base_on_project == 0 - stu_project.project_id = -1 + stu_work = StudentWork.new(:name => @work.name, :description => @work.description,:user_id=> members[i].to_i, :homework_common_id => @homework.id, :project_id => @work.project_id, :late_penalty => @work.late_penalty,:work_status => 3, :commit_time => @work.commit_time) + if stu_work.save + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => @work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0) + stu_project.save end - stu_project.user_id = members[i].to_i - stu_project.is_leader = 0 - stu_project.save end end @@ -735,26 +720,25 @@ class StudentWorkController < ApplicationController def destroy if @homework.homework_type == 3 - if @work.destroy - if @homework.homework_detail_group.base_on_project == 1 - pros = @work.student_work_projects.where("is_leader = 0") - pros.each do |pro| - pro.destroy - end - project = @work.student_work_projects.where("is_leader = 1").first - project.update_attributes(:student_work_id => nil) - elsif @homework.homework_detail_group.base_on_project == 0 - @work.student_work_projects.each do |pro2| - pro2.destroy - end - end + pros = @work.student_work_projects.where("is_leader = 0") + user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" + student_works = @homework.student_works.where("user_id in #{user_ids}") + student_works.delete_all + pros.delete_all + + project = @work.student_work_projects.where("is_leader = 1").first + if @homework.homework_detail_group.base_on_project == 1 + project.update_attributes(:student_work_id => nil) + else + project.destroy end + @work.destroy else @work.attachments.destroy_all @work.student_works_scores.destroy_all @work.course_messages.destroy_all @work.student_work_tests.destroy_all - @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil,:final_score => nil,:teacher_score => nil,:student_score => nil,:teaching_asistant_score => nil,:system_score => 0,:work_score => nil) + @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil,:final_score => nil,:teacher_score => nil,:student_score => nil,:teaching_asistant_score => nil,:system_score => 0,:work_score => nil, :project_id => 0) @work.update_column("work_score",nil) end respond_to do |format| @@ -786,22 +770,21 @@ class StudentWorkController < ApplicationController def retry_work if @homework.homework_type == 3 - if @work.destroy - if @homework.homework_detail_group.base_on_project == 1 - pros = @work.student_work_projects.where("is_leader = 0") - pros.each do |pro| - pro.destroy - end - project = @work.student_work_projects.where("is_leader = 1").first - project.update_attributes(:student_work_id => nil) - elsif @homework.homework_detail_group.base_on_project == 0 - @work.student_work_projects.each do |pro2| - pro2.destroy - end - end + pros = @work.student_work_projects.where("is_leader = 0") + user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" + student_works = @homework.student_works.where("user_id in #{user_ids}") + student_works.delete_all + pros.delete_all + + project = @work.student_work_projects.where("is_leader = 1").first + if @homework.homework_detail_group.base_on_project == 1 + project.update_attributes(:student_work_id => nil) + else + project.destroy end - elsif @homework.homework_type == 1 - @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil) + @work.destroy + else + @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil, :project_id => 0) @work.attachments.destroy_all @work.course_messages.destroy_all end @@ -1096,9 +1079,13 @@ class StudentWorkController < ApplicationController #创建作业的关联项目 def student_work_project + @work = @homework.student_works.where("user_id = #{User.current.id} and work_status = 0").first + if @work + @work.update_column('project_id', params[:projectName].to_i) + end @project = StudentWorkProject.new @project.homework_common_id = @homework.id - @project.project_id = (Project.find params[:projectName].to_i).id + @project.project_id = params[:projectName].to_i @project.user_id = User.current.id @project.is_leader = 1 if @project.save @@ -1139,7 +1126,7 @@ class StudentWorkController < ApplicationController end all_students = User.where("id in #{all_student_ids}") student_work_id = @homework.student_work_projects.where("user_id=? and student_work_id is not null",User.current.id).first.nil? ? -1 : @homework.student_work_projects.where("user_id=?",User.current.id).first.student_work_id - @commit_student_ids = @homework.student_work_projects.where("student_work_id != #{student_work_id}").map{|student| student.user_id} + @commit_student_ids = @homework.student_works.where("id != #{student_work_id}").map{|student| student.user_id} @users = searchstudent_by_name all_students,name respond_to do |format| format.js @@ -1147,6 +1134,10 @@ class StudentWorkController < ApplicationController end def cancel_relate_project + @work = @homework.student_works.where("user_id = #{User.current.id} and work_status = 0").first + if @work + @work.update_column('project_id', 0) + end relate_pro = StudentWorkProject.where("user_id = #{User.current.id} and homework_common_id = #{@homework.id}").first if relate_pro.destroy @user_activity_id = params[:user_activity_id].to_i @@ -1586,6 +1577,10 @@ class StudentWorkController < ApplicationController end end end + if homework.homework_type == 3 + student_works = group_student_works student_work, homework + student_works.update_all(:final_score => student_work.final_score,:teacher_score => student_work.teacher_score,:student_score => student_work.student_score,:teaching_asistant_score => student_work.teaching_asistant_score,:work_score => student_work.work_score) + end end end end diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 54486221e..0c6eb0910 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -167,6 +167,27 @@ class WechatsController < ActionController::Base end end + on :click, with: 'UNBIND' do |request, key| + uw = user_binded?(request[:FromUserName]) + unless uw + request.reply.text "您还未绑定帐号" + else + #解除绑定 + us = UsersService.new + us.wechat_unbind uw + + tmpurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=login&connect_redirect=1#wechat_redirect" + news = (1..1).each_with_object([]) { |n, memo| memo << { title: '重新绑定提醒', + content: "尊敬的用户,您已解除绑定。\n解除时间:#{format_time(Time.now)}\n点击进入重新绑定!"} } + request.reply.news(news) do |article, n, index| # article is return object + url = tmpurl + article.item title: "#{n[:title]}", + description: n[:content], + url: url + end + end + end + def join_class_request(request) openid = request[:FromUserName] wl = WechatLog.where("openid = '#{openid}' and request_raw like '%\"Event\":\"click\"%'").order('id desc').first diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 2ecb5516f..1e7df6466 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -158,4 +158,11 @@ module StudentWorkHelper end return status end + + def group_student_works student_work, homework + pros = student_work.student_work_projects.where("is_leader = 0") + user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" + student_works = homework.student_works.where("user_id in #{user_ids}") + return student_works + end end \ No newline at end of file diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 183570081..59e5b76bc 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -1,4 +1,4 @@ -#学生提交作品表 +#学生提交作品表 #work_status :0 未提交 1 已提交 2 迟交 3 分组作品复制的组员作品 class StudentWork < ActiveRecord::Base attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time @@ -13,7 +13,8 @@ class StudentWork < ActiveRecord::Base has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :attachments, :dependent => :destroy - scope :has_committed, lambda{where("work_status != 0")} + scope :has_committed, lambda{where("work_status != 0 and work_status != 3")} + scope :no_copy, lambda{where("work_status != 3")} before_destroy :delete_praise before_save :set_program_score, :set_src @@ -31,7 +32,7 @@ class StudentWork < ActiveRecord::Base private def set_program_score - if homework_common.is_program_homework? #编程作业,学生提交作品后计算系统得分 + if self.homework_common.is_program_homework? #编程作业,学生提交作品后计算系统得分 #根据最后一次测试计算得分 unless last_test self.system_score = 0 @@ -169,6 +170,12 @@ class StudentWork < ActiveRecord::Base end end end + if homework.homework_type == 3 + pros = student_work.student_work_projects.where("is_leader = 0") + user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" + student_works = homework.student_works.where("user_id in #{user_ids}") + student_works.update_all(:final_score => student_work.final_score,:teacher_score => student_work.teacher_score,:student_score => student_work.student_score,:teaching_asistant_score => student_work.teaching_asistant_score,:work_score => student_work.work_score) + end end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f184fa923..24e15f369 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -941,46 +941,36 @@ class CoursesService :description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation} end - - def student_homework_score(groupid,course_id, nums, score_sort_by) - #teachers = find_course_teachers(@course) - #start_from = start_from * nums + def student_homework_score(groupid,course_id, nums, score_sort_by, sort_type = 'score') sql_select = "" if groupid == 0 - if nums == 0 - sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id - AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) GROUP BY members.user_id - UNION all - SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} AND - students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND - members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} ) - ) - GROUP BY members.user_id ORDER BY score #{score_sort_by}" - else - sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id - AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) GROUP BY members.user_id - UNION all - SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} AND - students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND - members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} ) - ) - GROUP BY members.user_id ORDER BY score #{score_sort_by} " #limit #{start_from}, #{nums}" - - end + sql_select = "SELECT members.*,( + SELECT SUM(student_works.work_score) + FROM student_works,homework_commons + WHERE student_works.homework_common_id = homework_commons.id + AND homework_commons.course_id = course_id + AND student_works.user_id = members.user_id + ) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + + resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = #{course_id} AND ccs.user_id = members.user_id + ) AS act_score + FROM members + JOIN students_for_courses + ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id + WHERE members.course_id = #{course_id} ORDER BY #{sort_type} #{score_sort_by}" else - sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id - and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) - GROUP BY members.user_id - UNION all - SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} - and members.course_group_id = #{groupid} AND - students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND - members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} ) - ) - GROUP BY members.user_id ORDER BY score #{score_sort_by}" + sql_select = "SELECT members.*,( + SELECT SUM(student_works.work_score) + FROM student_works,homework_commons + WHERE student_works.homework_common_id = homework_commons.id + AND homework_commons.course_id = #{course_id} + AND student_works.user_id = members.user_id + ) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + + resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = #{course_id} AND ccs.user_id = members.user_id + ) AS act_score + FROM members + JOIN students_for_courses + ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id + WHERE members.course_id = #{course_id} AND members.course_group_id = #{groupid} ORDER BY #{sort_type} #{score_sort_by}" end sql = ActiveRecord::Base.connection() homework_scores = Member.find_by_sql(sql_select) diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 5789befe5..540e1bbff 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -1,3 +1,4 @@ +#coding=utf-8 class UsersService include ApplicationHelper include AccountHelper @@ -319,8 +320,22 @@ class UsersService my_jours_arr end + def wechat_unbind uw + user = uw.user + #发重新绑定的微信模版消息 + type = "login" + title = "尊敬的用户,您已解除绑定。" + key1 = "个人原因" + remark = "点击进入重新绑定。" + ws = WechatService.new + ws.rebind_notice user.id, type, user.id, title, key1,format_time(Time.now), remark + + uw.user_id = nil + uw.delete + + end end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 8adc1392f..c11826896 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -445,4 +445,41 @@ class WechatService end end + def rebind_notice(user_id, type, id, first, key1, key2,remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = { + touser:uw.openid, + template_id:Wechat.config.rebind_notice, + url:Wechat.config.auto_openid_url_1+Wechat.config.auto_openid_url_2+"login"+Wechat.config.auto_openid_url_3, + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + remark:{ + value:remark, + color:"#707070" + } + } + } + #data = three_keys_template uw.openid,Wechat.config.create_class_notice, type, id, first, key1, key2, key3, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[rebind_notice] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + end \ No newline at end of file diff --git a/app/views/admin/leave_messages.html.erb b/app/views/admin/leave_messages.html.erb index 986823faa..a9acba903 100644 --- a/app/views/admin/leave_messages.html.erb +++ b/app/views/admin/leave_messages.html.erb @@ -62,9 +62,9 @@
序号 | -- | 姓名 | -学号 | -班级 | -- | - <%= link_to "时间",'',:class => "c_dark f14 fb" ,:remote => true%> - | -- <%= link_to "成绩",'',:class => "c_dark f14 fb",:remote => true%> - | -|
---|---|---|---|---|---|---|---|---|
<%=index + 1 %> | -- <%= link_to(image_tag(url_to_avatar(exercise.user),:width =>"40",:height => "40",:style => "display:block;", :class => "mt15"),user_activities_path(exercise.user)) %> - | -- <%=exercise.user.show_name %> - | -- <%= exercise.user.user_extensions.nil? ? "--" : exercise.user.user_extensions.student_id%> - | -- -- - | -- | - <% if exercise.created_at%> - <%= Time.parse(format_time(exercise.created_at)).strftime("%m-%d %H:%M")%> - <% if @exercise.end_time <= exercise.created_at %> - [未答] - <% end %> - <% end %> - | -- <%= exercise.score.nil? ? "--" : format("%.1f",exercise.score)%> - | -
序号 | ++ | 姓名 | +学号 | +班级 | ++ | + <%= link_to "时间",'',:class => "c_dark f14 fb" ,:remote => true%> + | ++ <%= link_to "成绩",'',:class => "c_dark f14 fb",:remote => true%> + | +|
---|---|---|---|---|---|---|---|---|
<%=index + 1 %> | ++ <%= link_to(image_tag(url_to_avatar(exercise.user),:width =>"40",:height => "40",:style => "display:block;", :class => "mt15"),user_activities_path(exercise.user)) %> + | ++ <%=exercise.user.show_name %> + | ++ <%= exercise.user.user_extensions.nil? ? "--" : exercise.user.user_extensions.student_id%> + | ++ -- + | ++ | + <% if exercise.created_at%> + <%= Time.parse(format_time(exercise.created_at)).strftime("%m-%d %H:%M")%> + <% if @exercise.end_time <= exercise.created_at %> + [未答] + <% end %> + <% end %> + | ++ <%= exercise.score.nil? ? "--" : format("%.1f",exercise.score)%> + | +
位置: - <%= link_to User.current, user_path(User.current.id), :class => 'sy_cgrey', :target => '_blank' %> + <%= link_to @syllabus.user.show_name, user_path(@syllabus.user), :class => 'sy_cgrey', :target => '_blank' %> > - <%= link_to '课程', user_courselist_user_path(User.current.id), :class => "sy_cgrey", :target => '_blank' %> + <%= link_to '课程', user_courselist_user_path(@syllabus.user), :class => "sy_cgrey", :target => '_blank' %> > <%= link_to @syllabus.title, syllabus_path(@syllabus.id), :class => "sy_cgrey" %>
diff --git a/app/views/student_work/_evaluation_un_work.html.erb b/app/views/student_work/_evaluation_un_work.html.erb index ed0ba5542..bb87bfde1 100644 --- a/app/views/student_work/_evaluation_un_work.html.erb +++ b/app/views/student_work/_evaluation_un_work.html.erb @@ -26,7 +26,11 @@ <%= link_to student_work.user.show_name,"javascript:void(0)" ,:title => student_work.user.show_name, :class => "StudentName break_word"%>