diff --git a/app/controllers/ecloud_controller.rb b/app/controllers/ecloud_controller.rb index 412a5545..a64fce66 100644 --- a/app/controllers/ecloud_controller.rb +++ b/app/controllers/ecloud_controller.rb @@ -1,4 +1,16 @@ #encoding=utf-8 +# 云启训练场(EduCoder)个人版 产品编码(appId) 9200108 +# 产品名称 计费类型 套餐编码 +# 云启训练场(EduCoder)个人版 固定包月 9200108001 +# 固定包月 9200108002 +# 固定包月 9200108003 +# --------------------------------------------------- +# 产品名称 计费类型 套餐编码 +# 云启训练场(EduCoder))院校版 包月+按license 9200109001 +# 包月+按license 9200109002 + +# 云启训练场(EduCoder))院校版 产品编码(appId) 9200109 + require 'net/http' require 'digest' @@ -6,6 +18,7 @@ class EcloudController < ApplicationController skip_before_filter :verify_authenticity_token # before_filter :check_sign, only: [:ps_new, :ps_update, :bs_new, :bs_update] + before_filter :save_para before_filter :user_setup # before_filter :require_login, only: [:authorize] @@ -30,21 +43,65 @@ class EcloudController < ApplicationController Digest::MD5.hexdigest("client_id=#{CLIENT_ID}client_key=#{CLIENT_SECRET}timestamp=#{timestamp}").upcase end - # 企业开通 + + # 企业/个人业务开通 # applyno 申请单号,唯一 # ecordercode 唯一标志一个企业的订购关系 + # params['opttype']:操作类型。0开通;1变更;2试用转商用;4再次开通 def bs_new ActiveRecord::Base.transaction do begin - ecloud = Ecloud.create!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], - trial: params['trial'], bossorderid: params['bossorderid'], custid: params['custid'], custtype: params['custtype'], - custcode: params['custcode'], registersource: params['registersource'], custname: params['custname'], - userid: params['userid'], username: params['username'], useralias: params['useralias'], mobile: params['mobile'], - email: params['email'], productcode: params['productcode'], begintime: params['begintime'], - endtime: params['endtime']) - services = params['services'].first - EcloudService.create(opttype: services['opttype'], code: services['code'], begintime: services['begintime'], - endtime: services['endtime'], ecloud_id: ecloud.try(:id)) + ecloud_id = 0 + if params['opttype'] == 0 # 开通企业/个人业务 + ecloud = Ecloud.create!(eloud_params) + ecloud_id = ecloud.try(:id) + elsif params['opttype'] == 2 # 试用转商用 # 变更企业/个人业务 + ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode']).first + ecloud.update_attributes!(eloud_params) + ecloud.ecloud_productparas.destroy + ecloud.ecloud_services.destroy + ecloud_id = ecloud.try(:id) + elsif params['opttype'] == 1 # 业务变更 + ecloud = Ecloud.where(bossorderid: params['bossorderid']).first + ecloud.update_attributes!(eloud_params) + ecloud.ecloud_productparas.destroy + ecloud.ecloud_services.destroy + + ecloud_id = ecloud.try(:id) + + elsif params['opttype'] == 4 # 再次重复开通 + REDO + ecloud = Ecloud.where(bossorderid: params['bossorderid']).first + end + + # 业务列表 + services = params['services'] + if services.present? + services.each do |service| + es = EcloudService.create(opttype: service['opttype'], code: service['code'], begintime: service['begintime'], + endtime: service['endtime'], ecloud_id: ecloud_id) + if service['serviceparas'].present? + service['serviceparas'].each do |servicepara| + EcloudServieceServicepara.create!(ecloud_service_id: es.id, key: servicepara['key'], value: servicepara['value']) + end + end + end + end + + # 应用开通参数 + productparas = params['productparas'] + if productparas.present? + productparas.each do |productpara| + EcloudProductpara.create!(key: productpara['key'], value: productpara['value'], ecloud_id: ecloud_id) + end + end + + # 非试用情况下,为管理员单独创建一条账号,企业账号 + unless params['trial'] + EcloudUser.create!(ecloud_id: ecloud.try(:id), opttype: params['opttype'], userid: params['userid'], + username: params['username'], useralias: params['useralias'], + mobile: params['mobile'], email: params['email']) + end render :json => {result: true, errmsg: ""} rescue Exception => e @@ -55,11 +112,11 @@ class EcloudController < ApplicationController end end - # 企业更新 + # 企业/个人业务变更、注销 def bs_update ActiveRecord::Base.transaction do begin - ecloud = Ecloud.where(applyno: params['applyno']).first + ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode']).first ecloud.update_attributes!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], custid: params['custid'], custcode: params['custcode'], productcode: params['productcode'], operatime: params['operatime'], effecttime: params['effecttime']) @@ -76,6 +133,7 @@ class EcloudController < ApplicationController end # 用户业务开通与变更接口 + # 授权statu为1,取消授权status为0 def ps_new begin user_params = params['users'] @@ -202,6 +260,16 @@ class EcloudController < ApplicationController end private + def eloud_params + return {applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], + trial: params['trial'], bossorderid: params['bossorderid'], custid: params['custid'], custtype: params['custtype'], + custcode: params['custcode'], registersource: params['registersource'], custname: params['custname'], + userid: params['userid'], username: params['username'], useralias: params['useralias'], mobile: params['mobile'], + email: params['email'], productcode: params['productcode'], begintime: params['begintime'], + endtime: params['endtime']} + end + + def check_sign sign = sign(params['timestamp']) if sign != params['sign'] @@ -210,4 +278,8 @@ class EcloudController < ApplicationController end end + def save_para + EcloudLog.create(url: request.url, para_value: params, applyno: params['applyno'], custid: params['custid'], custcode: params['custcode']) + end + end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 8ca31926..a7a7d8c0 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -671,6 +671,7 @@ class HomeworkCommonController < ApplicationController def destroy if @homework.destroy + StudentWork.where(:homework_common_id => @homework.id).destroy_all #更新CourseHomeworkStatistics中每个学生的未交作品数、已交作品数、迟交作品数 # hw_count = @course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").count # homework_ids = @course.homework_commons.empty? ? "(-1)" : "(" + @course.homework_commons.map{|hw| hw.id}.join(",") + ")" @@ -1347,7 +1348,7 @@ class HomeworkCommonController < ApplicationController def find_homework @homework = HomeworkCommon.find params[:id] @homework_detail_manual = @homework.homework_detail_manual - @homework_detail_programing = @homework.homework_detail_programing + # @homework_detail_programing = @homework.homework_detail_programing @homework_detail_group = @homework.homework_detail_group @course = @homework.course rescue diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2e6c2865..d431cbfd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -6793,7 +6793,9 @@ def update_myshixun_work_score myshixun end work.update_time = Time.now - work.final_score = final_score + + # 为迁移的数据做特殊处理, 若分数小于当前通关分数则不更新 + work.final_score = final_score if work.final_score.nil? || final_score > work.final_score score = work.final_score + work.eff_score - work.late_penalty work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score #logger.info("#############work_score: #{score}") diff --git a/app/models/ecloud.rb b/app/models/ecloud.rb index fc23d00a..293948f3 100644 --- a/app/models/ecloud.rb +++ b/app/models/ecloud.rb @@ -1,7 +1,11 @@ +#encoding=utf-8 class Ecloud < ActiveRecord::Base attr_accessible :applyno, :begintime, :bossorderid, :custcode, :custid, :custname, :custtype, :ecordercode, :endtime, :mobile, :opttype, :productcode, :registersource, :string, :trial, :useralias, :userid, :username, :email, :effecttime, :operatime + + has_many :ecloud_services, :dependent => :destroy # 业务列表 + has_many :ecloud_productparas, :dependent => :destroy # 开通参数列表 + has_one :ecloud_user - has_one :ecloud_service end diff --git a/app/models/ecloud_log.rb b/app/models/ecloud_log.rb new file mode 100644 index 00000000..4e187aa5 --- /dev/null +++ b/app/models/ecloud_log.rb @@ -0,0 +1,3 @@ +class EcloudLog < ActiveRecord::Base + attr_accessible :para_value, :url, :applyno, :custid, :custcode +end diff --git a/app/models/ecloud_productpara.rb b/app/models/ecloud_productpara.rb new file mode 100644 index 00000000..ec1b94bc --- /dev/null +++ b/app/models/ecloud_productpara.rb @@ -0,0 +1,4 @@ +class EcloudProductpara < ActiveRecord::Base + attr_accessible :key, :value, :ecloud_id + belongs_to :ecloud +end diff --git a/app/models/ecloud_service.rb b/app/models/ecloud_service.rb index 596ad684..4a388ed4 100644 --- a/app/models/ecloud_service.rb +++ b/app/models/ecloud_service.rb @@ -1,3 +1,5 @@ class EcloudService < ActiveRecord::Base attr_accessible :begintime, :code, :endtime, :opttype, :ecloud_id, :packagecode, :bossorderid + belongs_to :ecloud + has_many :ecloud_serviece_serviceparas end diff --git a/app/models/ecloud_serviece_servicepara.rb b/app/models/ecloud_serviece_servicepara.rb new file mode 100644 index 00000000..91bb0a0d --- /dev/null +++ b/app/models/ecloud_serviece_servicepara.rb @@ -0,0 +1,4 @@ +class EcloudServieceServicepara < ActiveRecord::Base + attr_accessible :key, :value, :ecloud_service_id + belongs_to :ecloud_service +end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 6bcdb8fd..7d75daa2 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -15,7 +15,7 @@ class HomeworkCommon < ActiveRecord::Base belongs_to :homework_bank has_many :homework_group_settings, :dependent => :destroy has_one :homework_detail_manual, :dependent => :destroy - has_one :homework_detail_programing, :dependent => :destroy + # has_one :homework_detail_programing, :dependent => :destroy has_one :homework_detail_group, :dependent => :destroy has_one :homework_commons_shixuns, :dependent => :destroy has_many :homework_challenge_settings, :dependent => :destroy @@ -24,21 +24,21 @@ class HomeworkCommon < ActiveRecord::Base has_many :homework_review_results, :dependent => :destroy # 学生的查重情况 belongs_to :course_homework_category - has_many :student_work_projects, :dependent => :destroy - has_many :homework_tests, :dependent => :destroy - has_many :homework_samples, :dependent => :destroy - has_many :student_works, :dependent => :destroy, :conditions => "student_works.is_test=0 and student_works.is_delete != 1" + has_many :student_work_projects + # has_many :homework_tests, :dependent => :destroy + # has_many :homework_samples, :dependent => :destroy + has_many :student_works, :conditions => "student_works.is_test=0 and student_works.is_delete != 1" has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 has_many :journals_for_messages, :as => :jour, :dependent => :destroy - has_many :apply_homeworks, :dependent => :destroy + has_many :apply_homeworks has_many :praise_tread, as: :praise_tread_object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy - has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动 + # has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动 has_and_belongs_to_many :shixuns # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy # 课程消息 - has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + # has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :tidings, as: :container, dependent: :destroy acts_as_attachable acts_as_event :title => Proc.new {|o| "#{l(:label_course_homework)} ##{o.id}: #{o.name}" }, @@ -48,7 +48,7 @@ class HomeworkCommon < ActiveRecord::Base # after_create :act_as_activity after_update :update_activity after_save :act_as_course_activity - after_destroy :delete_kindeditor_assets + # after_destroy :delete_kindeditor_assets before_destroy :update_homework_bank_quotes #删除时更新题库中的引用数 diff --git a/app/models/student_work.rb b/app/models/student_work.rb index b6b64523..573b2cbe 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -13,9 +13,9 @@ class StudentWork < ActiveRecord::Base has_many :student_works_scores, :dependent => :destroy has_many :challenge_work_scores, :dependent => :destroy belongs_to :project - has_many :student_work_tests, order: 'id desc' + # has_many :student_work_tests, order: 'id desc' # course's message - has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + # has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :attachments, :dependent => :destroy has_many :tidings, as: :container, dependent: :destroy belongs_to :myshixun diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index f9a52452..f7a6dbc4 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -51,23 +51,12 @@ - -
-
-

精选实训

-

SELECTED TRAINING

-
- 更多 -
- <%= render :partial => "shixuns/shixun_item", :locals => {:shixuns => @shixuns} %> -
-

实训课程

-

TRAINING PATH

+

TRAINING COURSE

更多
@@ -77,6 +66,20 @@
+ +
+
+

开发社区

+

DEVELOPMENT COMMUNITY

+
+ 更多 +
+ <%= render :partial => "shixuns/shixun_item", :locals => {:shixuns => @shixuns} %> +
+
+ + +
diff --git a/db/migrate/20190313090326_create_ecloud_productpara.rb b/db/migrate/20190313090326_create_ecloud_productpara.rb new file mode 100644 index 00000000..df1271d6 --- /dev/null +++ b/db/migrate/20190313090326_create_ecloud_productpara.rb @@ -0,0 +1,11 @@ +class CreateEcloudProductpara < ActiveRecord::Migration + def change + create_table :ecloud_productparas do |t| + t.string :key + t.string :value + t.integer :ecloud_id + + t.timestamps + end + end +end diff --git a/db/migrate/20190313090416_create_ecloud_serviece_servicepara.rb b/db/migrate/20190313090416_create_ecloud_serviece_servicepara.rb new file mode 100644 index 00000000..22da21dd --- /dev/null +++ b/db/migrate/20190313090416_create_ecloud_serviece_servicepara.rb @@ -0,0 +1,11 @@ +class CreateEcloudServieceServicepara < ActiveRecord::Migration + def change + create_table :ecloud_serviece_serviceparas do |t| + t.string :key + t.string :value + t.integer :ecloud_service_id + + t.timestamps + end + end +end diff --git a/db/migrate/20190313115011_create_ecloud_logs.rb b/db/migrate/20190313115011_create_ecloud_logs.rb new file mode 100644 index 00000000..c5a9f3a8 --- /dev/null +++ b/db/migrate/20190313115011_create_ecloud_logs.rb @@ -0,0 +1,13 @@ +class CreateEcloudLogs < ActiveRecord::Migration + def change + create_table :ecloud_logs do |t| + t.string :url + t.string :applyno + t.integer :custid + t.string :custcode + t.string :para_value + + t.timestamps + end + end +end diff --git a/db/migrate/20190313120249_change_clo.rb b/db/migrate/20190313120249_change_clo.rb new file mode 100644 index 00000000..794aa56c --- /dev/null +++ b/db/migrate/20190313120249_change_clo.rb @@ -0,0 +1,16 @@ +class ChangeClo < ActiveRecord::Migration + def up + change_column :eclouds, :begintime, :bigint, :limit => 20 + change_column :eclouds, :endtime, :bigint, :limit => 20 + change_column :eclouds, :operatime, :bigint, :limit => 20 + change_column :eclouds, :effecttime, :bigint, :limit => 20 + change_column :ecloud_services, :endtime, :bigint, :limit => 20 + change_column :ecloud_services, :begintime, :bigint, :limit => 20 + change_column :ecloud_users, :begintime, :bigint, :limit => 20 + change_column :ecloud_users, :endtime, :bigint, :limit => 20 + change_column :ecloud_logs, :para_value, :longtext + end + + def down + end +end diff --git a/db/migrate/20190314010614_add_index_to_homework.rb b/db/migrate/20190314010614_add_index_to_homework.rb new file mode 100644 index 00000000..a6db7a29 --- /dev/null +++ b/db/migrate/20190314010614_add_index_to_homework.rb @@ -0,0 +1,8 @@ +class AddIndexToHomework < ActiveRecord::Migration + def change + add_index :homework_detail_manuals, :homework_common_id + add_index :homework_commons_shixuns, :homework_common_id + add_index :student_works_evaluation_distributions, :student_work_id + add_index :tidings, :container_id + end +end diff --git a/db/migrate/20190314025104_migration_shixun_student_work.rb b/db/migrate/20190314025104_migration_shixun_student_work.rb new file mode 100644 index 00000000..c74b7379 --- /dev/null +++ b/db/migrate/20190314025104_migration_shixun_student_work.rb @@ -0,0 +1,30 @@ +class MigrationShixunStudentWork < ActiveRecord::Migration + def up + works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and (work_score is null or work_score = 0)") + works.update_all(:myshixun_id => 0, :work_status => 0, :work_score => nil, :final_score => nil, + :cost_time => 0, :update_time => nil, :compelete_status => 0, :commit_time => nil) + + shixun_works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0") + shixun_works.each do |work| + if work.homework_common && work.homework_common.homework_commons_shixuns.try(:shixun) + shixun = work.homework_common.homework_commons_shixuns.try(:shixun) + + # 创建新的myshixun和games + myshixun = nil + + work_score = work.final_score + work.homework_common.homework_challenge_settings.each do |setting| + if work_score > 1 + myshixun.games.where(:challenge_id => setting.challenge_id).first.update_attributes(:status => 2) + work_score -= setting.score + end + end + + work.update_column("myshixun_id", myshixun.id) + end + end + end + + def down + end +end diff --git a/spec/factories/ecloud_logs.rb b/spec/factories/ecloud_logs.rb new file mode 100644 index 00000000..e442e25d --- /dev/null +++ b/spec/factories/ecloud_logs.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :ecloud_log do + url "MyString" +params "" + end + +end diff --git a/spec/factories/ecloud_productparas.rb b/spec/factories/ecloud_productparas.rb new file mode 100644 index 00000000..c206a57f --- /dev/null +++ b/spec/factories/ecloud_productparas.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :ecloud_productpara, :class => 'EcloudProductparas' do + key "MyString" +value "MyString" + end + +end diff --git a/spec/factories/ecloud_serviece_serviceparas.rb b/spec/factories/ecloud_serviece_serviceparas.rb new file mode 100644 index 00000000..5a1f5e7d --- /dev/null +++ b/spec/factories/ecloud_serviece_serviceparas.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :ecloud_serviece_servicepara, :class => 'EcloudServieceServicepara' do + key "MyString" +value "MyString" + end + +end diff --git a/spec/models/ecloud_log_spec.rb b/spec/models/ecloud_log_spec.rb new file mode 100644 index 00000000..25126a65 --- /dev/null +++ b/spec/models/ecloud_log_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe EcloudLog, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/ecloud_productparas_spec.rb b/spec/models/ecloud_productparas_spec.rb new file mode 100644 index 00000000..ec9a177f --- /dev/null +++ b/spec/models/ecloud_productparas_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe EcloudProductparas, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/ecloud_serviece_servicepara_spec.rb b/spec/models/ecloud_serviece_servicepara_spec.rb new file mode 100644 index 00000000..0ea7e787 --- /dev/null +++ b/spec/models/ecloud_serviece_servicepara_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe EcloudServieceServicepara, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end