Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_ec
cxt 5 years ago
commit ebd825ade7

@ -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

@ -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

@ -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

@ -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

@ -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
# 课程等级

@ -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

@ -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

@ -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

@ -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

@ -212,7 +212,7 @@ function initOnlineOfflineListener() {
$(window).bind("online", () => {
notification.destroy()
notification.success({
duration: null,
duration: 2,
message: '网络恢复正常',
description:
'网络恢复正常,感谢使用。',

@ -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={
<div className="fl mt6 task_menu_ul">
<Menu mode="horizontal" defaultSelectedKeys="all" onClick={this.selectedStatus}>
<Menu mode="horizontal" selectedKeys={this.state.selectedKeys} onClick={this.selectedStatus}>
<Menu.Item key="all">全部</Menu.Item>
{isAdmin && <Menu.Item key="0">未发布</Menu.Item>}
<Menu.Item key="1">提交中</Menu.Item>

@ -302,7 +302,8 @@ class studentsList extends Component{
}
componentDidUpdate(prevProps) {
if (prevProps.match.params.course_group_id != this.props.match.params.course_group_id) {
this.setState({checkBoxValues: []})
this.setState({checkBoxValues: [], checkAllValue: false })
this.fetchAll(1)
}
// 加载了2次

Loading…
Cancel
Save