diff --git a/app/controllers/ecs/course_achievement_methods_controller.rb b/app/controllers/ecs/course_achievement_methods_controller.rb index 389169258..62d609ea7 100644 --- a/app/controllers/ecs/course_achievement_methods_controller.rb +++ b/app/controllers/ecs/course_achievement_methods_controller.rb @@ -5,13 +5,17 @@ class Ecs::CourseAchievementMethodsController < Ecs::CourseBaseController end def create - @course_target = Ecs::CreateCourseAchievementMethodsService.call(current_course_target, create_params) + Ecs::CreateCourseAchievementMethodsService.call(current_course_target, create_params) + render_ok end private def create_params - params.permit(course_achievement_methods: %i[id course_evaluation_id course_evaluation_subitem_ids score percentage]) + params.permit(course_achievement_methods: [ + :id, :course_evaluation_id, :score, :percentage, + course_evaluation_relates: %i[:subitem_id position] + ]) end def current_course_target diff --git a/app/controllers/wechats/js_sdk_signatures_controller.rb b/app/controllers/wechats/js_sdk_signatures_controller.rb index 0b66cc263..f6a01b0e2 100644 --- a/app/controllers/wechats/js_sdk_signatures_controller.rb +++ b/app/controllers/wechats/js_sdk_signatures_controller.rb @@ -5,7 +5,7 @@ class Wechats::JsSdkSignaturesController < ApplicationController signature = Util::Wechat.js_sdk_signature(params[:url], noncestr, timestamp) render_ok(appid: Util::Wechat.appid, timestamp: timestamp, noncestr: noncestr, signature: signature) - rescue Util::Wechat::Error => ex + rescue Util::WechatStore::Error => ex render_error(ex.message) end end \ No newline at end of file diff --git a/app/libs/util/wechat.rb b/app/libs/util/wechat.rb index 1b064ba94..cb7b9044d 100644 --- a/app/libs/util/wechat.rb +++ b/app/libs/util/wechat.rb @@ -13,63 +13,15 @@ module Util::Wechat end def access_token - # 7200s 有效时间 - Rails.cache.fetch(access_token_cache_key, expires_in: 100.minutes) do - result = request(:get, '/cgi-bin/token', appid: appid, secret: secret, grant_type: 'client_credential') - result['access_token'] - end - end - - def refresh_access_token - Rails.cache.delete(access_token_cache_key) - access_token + wechat_store.access_token end def jsapi_ticket - # 7200s 有效时间 - Rails.cache.fetch(jsapi_ticket_cache_key, expires_in: 100.minutes) do - result = request(:get, '/cgi-bin/ticket/getticket', access_token: access_token, type: 'jsapi') - result['ticket'] - end - end - - def refresh_jsapi_ticket - Rails.cache.delete(jsapi_ticket_cache_key) - jsapi_ticket - end - - def access_token_cache_key - "#{base_cache_key}/access_token" - end - - def jsapi_ticket_cache_key - "#{base_cache_key}/jsapi_ticket" + wechat_store.jsapi_ticket end - def base_cache_key - "wechat/#{appid}" - end - - private - - def request(method, url, **params) - Rails.logger.error("[wechat] request: #{method} #{url} #{params.inspect}") - - client = Faraday.new(url: BASE_SITE) - response = client.public_send(method, url, params) - result = JSON.parse(response.body) - - Rails.logger.error("[wechat] response:#{response.status} #{result.inspect}") - - if response.status != 200 - raise Error, result.inspect - end - - if result['errcode'].present? && result['errcode'].to_i.nonzero? - raise Error, result.inspect - end - - result + def wechat_store + @_wechat_store ||= ::Util::WechatStore.new(appid, secret) end end end \ No newline at end of file diff --git a/app/libs/util/wechat_store.rb b/app/libs/util/wechat_store.rb new file mode 100644 index 000000000..a6f3ac76a --- /dev/null +++ b/app/libs/util/wechat_store.rb @@ -0,0 +1,72 @@ +class Util::WechatStore + BASE_SITE = 'https://api.weixin.qq.com'.freeze + + Error = Class.new(StandardError) + + attr_reader :appid, :secret + + def initialize(appid, secret) + @appid = appid + @secret = secret + end + + def access_token + # 7200s 有效时间 + Rails.cache.fetch(access_token_cache_key, expires_in: 100.minutes) do + result = request(:get, '/cgi-bin/token', appid: appid, secret: secret, grant_type: 'client_credential') + result['access_token'] + end + end + + def refresh_access_token + Rails.cache.delete(access_token_cache_key) + access_token + end + + def jsapi_ticket + # 7200s 有效时间 + Rails.cache.fetch(jsapi_ticket_cache_key, expires_in: 100.minutes) do + result = request(:get, '/cgi-bin/ticket/getticket', access_token: access_token, type: 'jsapi') + result['ticket'] + end + end + + def refresh_jsapi_ticket + Rails.cache.delete(jsapi_ticket_cache_key) + jsapi_ticket + end + + def access_token_cache_key + "#{base_cache_key}/access_token" + end + + def jsapi_ticket_cache_key + "#{base_cache_key}/jsapi_ticket" + end + + def base_cache_key + "wechat/#{appid}" + end + + private + + def request(method, url, **params) + Rails.logger.error("[wechat] request: #{method} #{url} #{params.inspect}") + + client = Faraday.new(url: BASE_SITE) + response = client.public_send(method, url, params) + result = JSON.parse(response.body) + + Rails.logger.error("[wechat] response:#{response.status} #{result.inspect}") + + if response.status != 200 + raise Error, result.inspect + end + + if result['errcode'].present? && result['errcode'].to_i.nonzero? + raise Error, result.inspect + end + + result + end +end \ No newline at end of file diff --git a/app/models/ec_course.rb b/app/models/ec_course.rb index 6f5480ea8..4e7202f05 100644 --- a/app/models/ec_course.rb +++ b/app/models/ec_course.rb @@ -6,7 +6,7 @@ class EcCourse < ApplicationRecord has_many :ec_graduation_subitem_course_targets, through: :ec_course_targets # 课程负责教师 has_many :ec_course_users - has_many :course_managers, through: :ec_course_users, class_name: 'User' + has_many :course_managers, through: :ec_course_users, source: :user # 课程考核标准 has_many :ec_course_evaluations, dependent: :destroy # 课程等级 diff --git a/app/models/ec_course_evaluation.rb b/app/models/ec_course_evaluation.rb index e96f1c98b..40fd10dfa 100644 --- a/app/models/ec_course_evaluation.rb +++ b/app/models/ec_course_evaluation.rb @@ -16,4 +16,23 @@ class EcCourseEvaluation < ApplicationRecord def imported? import_status? end + + def evaluation_relates + # 总成绩支撑只有课程考核标准的名称, 分项成绩支撑是课程考核标准名称与考核分项的笛卡尔积 + if status == 1 + return evaluation_count.times.map { |index| { id: -1, name: "#{name}(#{index + 1})", position: index + 1 } } + end + + if is_course_type? + ec_course_evaluation_subitems.map.with_index { |item, index| { id: item.id, name: item.name, position: index + 1 } } + else + data = [] + ec_course_evaluation_subitems.each do |item| + evaluation_count.times do |i| + data << { id: item.id, name: "#{name}(#{i + 1})#{item.name}", position: i + 1 } + end + end + data + end + end end diff --git a/app/services/ecs/create_course_achievement_method_service.rb b/app/services/ecs/create_course_achievement_method_service.rb index 01f09ff2b..0c086631f 100644 --- a/app/services/ecs/create_course_achievement_method_service.rb +++ b/app/services/ecs/create_course_achievement_method_service.rb @@ -31,8 +31,8 @@ class Ecs::CreateCourseAchievementMethodsService < ApplicationService # 创建新的评价方法时,全部为新建 if item[:id].blank? || course_target.ec_course_achievement_methods.find_by(id: item[:id]).blank? item[:ec_achievement_evaluation_relates_attributes] = - Array(*item[:course_evaluation_subitem_ids]).uniq.map do |subitem_id| - { ec_course_evaluation_subitem_id: subitem_id.to_i } + item[:course_evaluation_relates].map do |relate| + { ec_course_evaluation_subitem_id: relate[:subitem_id].to_i, position: relate[:position] } end return end @@ -41,22 +41,22 @@ class Ecs::CreateCourseAchievementMethodsService < ApplicationService relates = achievement_method.ec_achievement_evaluation_relates # 获取传入的 subitem id数组和已存在的 subitem id数组 - old_subitem_ids = relates.map(&:ec_course_evaluation_subitem_id).uniq - new_subitem_ids = Array(*item[:course_evaluation_subitem_ids]).map(&:to_i).uniq + old_data = relates.map { |e| [e.ec_course_evaluation_subitem_id, e.position] } + new_data = item[:course_evaluation_relates].map { |e| [e[:subitem_id, e[:position]]] } # 分别得到需要移除的 subitem ID数组和需要创建的 subitem ID数组 - destroy_subitem_ids = old_subitem_ids - new_subitem_ids - create_subitem_ids = new_subitem_ids - old_subitem_ids + destroy_data = old_data - new_data + create_data = new_data - old_data # 生成需要创建关系的 subitem id 数据 - create_attributes = create_subitem_ids.map { |item_id| { ec_course_evaluation_subitem_id: item_id } } + create_attributes = create_data.map { |arr| { ec_course_evaluation_subitem_id: arr[0], position: arr[1] } } # 处理需要更新或者删除的记录 exists_attributes = relates.map do |relate| - if destroy_subitem_ids.include?(relate.ec_course_evaluation_subitem_id) + if destroy_data.include?([relate.ec_course_evaluation_subitem_id, relate.position]) { id: relate.id, _destroy: true } else - relate.as_json(only: %i[id ec_course_evaluation_subitem_id ec_course_achievement_method_id]) + relate.as_json(only: %i[id ec_course_evaluation_subitem_id ec_course_achievement_method_id position]) end end diff --git a/app/views/ecs/course_achievement_methods/shared/_ec_course_achievement_method.json.jbuilder b/app/views/ecs/course_achievement_methods/shared/_ec_course_achievement_method.json.jbuilder index 5cc3220a4..868e7822c 100644 --- a/app/views/ecs/course_achievement_methods/shared/_ec_course_achievement_method.json.jbuilder +++ b/app/views/ecs/course_achievement_methods/shared/_ec_course_achievement_method.json.jbuilder @@ -7,3 +7,5 @@ end json.course_evaluation_subitems ec_course_achievement_method.ec_course_evaluation_subitems, partial: 'ecs/shared/ec_course_evaluation_subitem', as: :ec_course_evaluation_subitem + +json.course_evaluation_relates ec_course_achievement_method.ec_course_evaluation.evaluation_relates diff --git a/app/views/ecs/course_evaluations/slimmer.json.jbuilder b/app/views/ecs/course_evaluations/slimmer.json.jbuilder index 6e0faef3e..1f4dc0cc0 100644 --- a/app/views/ecs/course_evaluations/slimmer.json.jbuilder +++ b/app/views/ecs/course_evaluations/slimmer.json.jbuilder @@ -1 +1,7 @@ -json.course_evaluations @course_evaluations, partial: 'ecs/course_evaluations/shared/ec_course_evaluation_slim', as: :ec_course_evaluation +json.course_evaluations do + json.array! @course_evaluations do |course_evaluation| + json.partial! 'ecs/course_evaluations/shared/ec_course_evaluation_slim', ec_course_evaluation: course_evaluation + + json.evaluation_relates course_evaluation.evaluation_relates + end +end \ No newline at end of file diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index 19563052c..e1d5da561 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -212,7 +212,7 @@ function initOnlineOfflineListener() { $(window).bind("online", () => { notification.destroy() notification.success({ - duration: null, + duration: 2, message: '网络恢复正常', description: '网络恢复正常,感谢使用。', diff --git a/public/react/src/modules/courses/busyWork/commonWork.js b/public/react/src/modules/courses/busyWork/commonWork.js index f8042d476..f6a989354 100644 --- a/public/react/src/modules/courses/busyWork/commonWork.js +++ b/public/react/src/modules/courses/busyWork/commonWork.js @@ -33,6 +33,7 @@ class commonWork extends Component{ modalsBottomval:"", modalCancel:"", mainList:undefined, + selectedKeys: 'all', order:"", page:1, search:"", @@ -77,7 +78,9 @@ class commonWork extends Component{ componentDidUpdate(prevProps, prevState) { if (prevProps.match.path != this.props.match.path) { this.clearSelection() - this._getList() + this.setState({ selectedKeys: 'all', order: '' }, () => { + this._getList() + }) } } @@ -143,6 +146,7 @@ class commonWork extends Component{ this.clearSelection() this.setState({ order:e.key==="all"?"":e.key, + selectedKeys: e.key, page:1, isSpin:true, checkBoxValues:[], @@ -403,7 +407,7 @@ class commonWork extends Component{ } secondRowBotton={