update wxcode

dev_tj
tangjiang 5 years ago
commit 7c80902992

@ -21,6 +21,8 @@ class Weapps::CodeSessionsController < Weapps::BaseController
Rails.logger.info("[Weapp] code: #{params[:code]}") Rails.logger.info("[Weapp] code: #{params[:code]}")
user_info = Wechat::Weapp.decrypt(result['session_key'], params[:encrypted_data], params[:iv]) user_info = Wechat::Weapp.decrypt(result['session_key'], params[:encrypted_data], params[:iv])
# user_info.delete(:nickName)
# 老用户,已绑定 # 老用户,已绑定
open_user = OpenUsers::Wechat.find_by(uid: user_info['unionId']) open_user = OpenUsers::Wechat.find_by(uid: user_info['unionId'])
if open_user.present? && open_user.user if open_user.present? && open_user.user
@ -29,7 +31,7 @@ class Weapps::CodeSessionsController < Weapps::BaseController
end end
set_session_unionid(user_info['unionId']) set_session_unionid(user_info['unionId'])
user_info['nickname'] = user_info['nickName'] # user_info['nickname'] = user_info['nickName']
session[:wechat_user_extra] = user_info session[:wechat_user_extra] = user_info
end end

@ -15,8 +15,9 @@ class Weapps::SessionsController < Weapps::BaseController
return return
end end
# session[:wechat_user_extra].delete(:nickName)
# 绑定微信号 # 绑定微信号
OpenUsers::Wechat.create!(user: user, uid: session_unionid, extra: session[:wechat_user_extra]) if user.wechat_open_user.blank? OpenUsers::Wechat.create!(user: user, uid: session_unionid) if user.wechat_open_user.blank?
successful_authentication(user) successful_authentication(user)
end end

@ -68,8 +68,8 @@ class GitService
content = JSON.parse(body) content = JSON.parse(body)
if content["code"] != 0 if content["code"] != 0
raise("版本库异常")
logger.error("repository error: #{content['msg']}") logger.error("repository error: #{content['msg']}")
raise("版本库异常")
end end
#raise content["msg"] if content["code"] != 0 #raise content["msg"] if content["code"] != 0

@ -3,4 +3,5 @@ json.game @game
json.shixun @shixun json.shixun @shixun
json.shixun_env @env json.shixun_env @env
json.shixun_image @shixun.main_mirror_name
json.shixun_tags @shixun_tags json.shixun_tags @shixun_tags

@ -0,0 +1,13 @@
class Modify1WechatSupportForShixuns < ActiveRecord::Migration[5.2]
def change
shixuns = Shixun.joins(:challenges).where(is_wechat_support: true, status: 2)
.select("shixuns.*, challenges.path path")
shixuns.each do |shixun|
if shixun.path && shixun.path.split("").count > 1
shixun.update_attribute(:is_wechat_support, false)
end
end
Shixun.joins(:challenges).where(challenges: {st: 1}).update_all(is_wechat_support: false)
end
end

@ -9,8 +9,8 @@ namespace :subjects do
buffer_size = 0 buffer_size = 0
column_value = "subject_id, study_count, course_study_count, initiative_study, passed_count, course_used_count, " + column_value = "subject_id, study_count, course_study_count, initiative_study, passed_count, course_used_count, " +
"school_used_count, created_at, updated_at" "school_used_count, created_at, updated_at"
subjects.find_in_batches(batch_size: 50) do |s| subjects.find_in_batches(batch_size: 50) do |s, index|
Parallel.each(s, in_processes: 4) do |subject| Parallel.each_with_index(s, in_processes: 4) do |subject|
puts("---------------------data_statistic: #{subject.id}") puts("---------------------data_statistic: #{subject.id}")
Rails.logger.info("---------------------data_statistic: #{subject.id}") Rails.logger.info("---------------------data_statistic: #{subject.id}")
data = Subjects::DataStatisticService.new(subject) data = Subjects::DataStatisticService.new(subject)
@ -23,7 +23,7 @@ namespace :subjects do
"#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " + "#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " +
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
buffer_size += 1 buffer_size += 1
if buffer_size == 1000 if buffer_size == 1000 || subjects.count == (index+1)
sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}" sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}"
puts sql puts sql
ActiveRecord::Base.connection.execute sql ActiveRecord::Base.connection.execute sql
@ -55,14 +55,14 @@ namespace :subjects do
puts("---------------------course_info_statistic: #{subject.id}") puts("---------------------course_info_statistic: #{subject.id}")
Rails.logger.info("---------------------course_info_statistic: #{subject.id}") Rails.logger.info("---------------------course_info_statistic: #{subject.id}")
data = Subjects::CourseUsedInfoService.call(subject) data = Subjects::CourseUsedInfoService.call(subject)
Parallel.map(data) do |key| Parallel.map_with_index(data) do |key, index|
next if key[:school_id].nil? next if key[:school_id].nil?
str += ", " unless str.empty? str += ", " unless str.empty?
str += ("(#{subject.id}, #{key[:school_id]}, '#{key[:school_name]}', #{key[:course_count]}, " + str += ("(#{subject.id}, #{key[:school_id]}, '#{key[:school_name]}', #{key[:course_count]}, " +
"#{key[:student_count]}, #{key[:choice_shixun_num]}, #{key[:choice_shixun_frequency]}, " + "#{key[:student_count]}, #{key[:choice_shixun_num]}, #{key[:choice_shixun_frequency]}, " +
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
buffer_size += 1 buffer_size += 1
if buffer_size == 1000 if buffer_size == 1000 || (index + 1) == data.size
sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str}" sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str}"
puts sql puts sql
ActiveRecord::Base.connection.execute sql ActiveRecord::Base.connection.execute sql
@ -90,11 +90,11 @@ namespace :subjects do
column_value = "subject_id, shixun_id, stage, shixun_name, challenge_count, course_count, " + column_value = "subject_id, shixun_id, stage, shixun_name, challenge_count, course_count, " +
"school_count, used_count, passed_count, evaluate_count, passed_ave_time, created_at, updated_at" "school_count, used_count, passed_count, evaluate_count, passed_ave_time, created_at, updated_at"
subjects.find_in_batches(batch_size: 50) do |s| subjects.find_in_batches(batch_size: 50) do |s|
Parallel.each(s, in_processes: 4) do |subject| Parallel.each_with_index(s, in_processes: 4) do |subject|
puts("---------------------shixun_info_statistic: #{subject.id}") puts("---------------------shixun_info_statistic: #{subject.id}")
Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}") Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}")
data = Subjects::ShixunUsedInfoService.call(subject) data = Subjects::ShixunUsedInfoService.call(subject)
data.each do |key| data.each_with_index do |key, index|
next if key[:shixun_id].nil? next if key[:shixun_id].nil?
str += ", " unless str.empty? str += ", " unless str.empty?
str += ("(#{subject.id}, #{key[:shixun_id]}, '#{key[:stage]}', '#{key[:name]}', #{key[:challenge_count]}, " + str += ("(#{subject.id}, #{key[:shixun_id]}, '#{key[:stage]}', '#{key[:name]}', #{key[:challenge_count]}, " +
@ -102,7 +102,7 @@ namespace :subjects do
"#{key[:evaluate_count]}, #{key[:passed_ave_time]}, " + "#{key[:evaluate_count]}, #{key[:passed_ave_time]}, " +
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
buffer_size += 1 buffer_size += 1
if buffer_size == 1000 if buffer_size == 1000 || (index+1) == data.size
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str}" sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str}"
puts sql puts sql
ActiveRecord::Base.connection.execute sql ActiveRecord::Base.connection.execute sql
@ -131,7 +131,7 @@ namespace :subjects do
"code_line_count, evaluate_count, cost_time, created_at, updated_at" "code_line_count, evaluate_count, cost_time, created_at, updated_at"
subjects.find_in_batches(batch_size: 50) do |s| subjects.find_in_batches(batch_size: 50) do |s|
Parallel.each(s, in_processes: 4) do |subject| Parallel.each_with_index(s, in_processes: 4) do |subject, index|
puts("---------------------user_info_statistic: #{subject.id}") puts("---------------------user_info_statistic: #{subject.id}")
data = Subjects::UserUsedInfoService.call(subject) data = Subjects::UserUsedInfoService.call(subject)
data.each do |key| data.each do |key|
@ -141,7 +141,7 @@ namespace :subjects do
"#{key[:passed_games_count]}, #{key[:code_line_count]}, #{key[:evaluate_count]}, #{key[:cost_time]}, " + "#{key[:passed_games_count]}, #{key[:code_line_count]}, #{key[:evaluate_count]}, #{key[:cost_time]}, " +
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
buffer_size += 1 buffer_size += 1
if buffer_size == 1000 if buffer_size == 1000 || (index+1 == data.size)
sql = "REPLACE INTO subject_user_infos(#{column_value}) VALUES #{str}" sql = "REPLACE INTO subject_user_infos(#{column_value}) VALUES #{str}"
ActiveRecord::Base.connection.execute sql ActiveRecord::Base.connection.execute sql
str = "" str = ""

@ -38,9 +38,8 @@ namespace :zip_pack do
def zip_homework_pdf homeworks, folder, parallel_size def zip_homework_pdf homeworks, folder, parallel_size
Dir.mkdir(folder) unless File.directory?(folder) Dir.mkdir(folder) unless File.directory?(folder)
homeworks = homeworks.includes(:score_student_works)
Parallel.each(homeworks, in_processes: 2) do |homework| homeworks.includes(:score_student_works).each do |homework|
out_file_name = "#{Time.now.strftime("%Y%m%d%H%M%S").to_s}-#{homework.course_id}-#{homework.name}.zip" out_file_name = "#{Time.now.strftime("%Y%m%d%H%M%S").to_s}-#{homework.course_id}-#{homework.name}.zip"
out_file_name.gsub!(" ", "-") out_file_name.gsub!(" ", "-")
out_file_name.gsub!("/", "_") out_file_name.gsub!("/", "_")
@ -51,21 +50,26 @@ namespace :zip_pack do
if student_works.size > 0 if student_works.size > 0
pdfs = [] pdfs = []
file_paths = []
student_works.find_in_batches(batch_size: 500) do |sw|
Parallel.each(sw, in_threads: parallel_size) do |student_work|
export = ExportShixunReportService.new(homework, student_work)
pdf = export.to_pdf
pdfs << pdf
file_paths << {filename: export.filename, path: pdf.path}
puts "out: #{export.filename}_#{pdf.path}"
end
end
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zip| Zip::File.open(zipfile_name, Zip::File::CREATE) do |zip|
student_works.find_in_batches(batch_size: 500) do |sw| file_paths.each do |pdf|
Parallel.each(sw, in_processes: parallel_size) do |student_work| begin
export = ExportShixunReportService.new(homework, student_work) zip.add(pdf[:filename], pdf[:path])
pdf = export.to_pdf rescue => ex
pdfs << pdf Rails.logger.error(ex.message)
begin
zip.add(export.filename, pdf.path)
puts "out: #{export.filename}_#{pdf.path}"
rescue => ex
Rails.logger.error(ex.message)
zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") } zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") }
next next
end
end end
end end
end end

@ -5,6 +5,7 @@ import md5 from 'md5';
import { requestProxy } from "./indexEduplus2RequestProxy"; import { requestProxy } from "./indexEduplus2RequestProxy";
import { broadcastChannelOnmessage ,SetAppModel, isDev, queryString } from 'educoder'; import { broadcastChannelOnmessage ,SetAppModel, isDev, queryString } from 'educoder';
import { notification } from 'antd'; import { notification } from 'antd';
import cookie from 'react-cookies';
import './index.css'; import './index.css';
const $ = window.$; const $ = window.$;
const opens ="79e33abd4b6588941ab7622aed1e67e8"; const opens ="79e33abd4b6588941ab7622aed1e67e8";
@ -24,6 +25,18 @@ function locationurl(list){
} }
function setCookier(){
const _params = window.location.search;
if (_params) {
let _search = _params.split('?')[1];
_search.split('&').forEach(item => {
console.log(item);
const _arr = item.split('=');
cookie.save('_educoder_session',_arr[0]);
cookie.save('autologin_trustie',_arr[1]);
});
}
}
// TODO 开发期多个身份切换 // TODO 开发期多个身份切换
let debugType ="" let debugType =""
@ -96,7 +109,7 @@ export function initAxiosInterceptors(props) {
requestMap[keyName] = false; requestMap[keyName] = false;
} }
//响应前的设置
axios.interceptors.request.use( axios.interceptors.request.use(
config => { config => {
// config.headers['Content-Type']= 'no-cache' // config.headers['Content-Type']= 'no-cache'
@ -111,6 +124,33 @@ export function initAxiosInterceptors(props) {
// proxy = 'http://localhost:3000' // proxy = 'http://localhost:3000'
// } // }
// --------------------------------------------- // ---------------------------------------------
// console.log("开始请求了");
// console.log(config.url);
// console.log(window.location.pathname);
try {
const str =window.location.pathname;
if(str.indexOf("/wxcode") !== -1){
// console.log("开始重写cookis");
const _params = window.location.search;
// console.log("1111");
if (_params) {
// console.log("22222");
let _search = _params.split('?')[1];
_search.split('&').forEach(item => {
const _arr = item.split('=');
if(_arr[0]==='_educoder_session'){
cookie.save('_educoder_session',_arr[1],{ path: '/' });
}else{
cookie.save('autologin_trustie',_arr[1],{ path: '/' });
}
});
}
}
}catch (e) {
}
//
if (config.url.indexOf(proxy) != -1 || config.url.indexOf(':') != -1) { if (config.url.indexOf(proxy) != -1 || config.url.indexOf(':') != -1) {
return config return config
} }

@ -1,7 +1,7 @@
/* /*
* @Description: 微信端代码编辑器 * @Description: 微信端代码编辑器
* @Author: tangjiang * @Author: tangjiang
* @Github: * @Github:
* @Date: 2020-01-15 09:56:34 * @Date: 2020-01-15 09:56:34
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2020-01-17 21:03:15 * @LastEditTime : 2020-01-17 21:03:15
@ -38,9 +38,14 @@ const App = (props) => {
updateWXCodeForInterval, updateWXCodeForInterval,
evaluateWxCode, evaluateWxCode,
showWXCodeTextCase, showWXCodeTextCase,
<<<<<<< HEAD
changeWXCodeEvaluateLoading, changeWXCodeEvaluateLoading,
changeWXCodeEvaluateDialog changeWXCodeEvaluateDialog
} = props; } = props;
=======
changeWXCodeEvaluateLoading
} = props;
>>>>>>> e0ff4d13c62ce7f92a49387eff940448ed2057f3
const {identifier} = props.match.params; const {identifier} = props.match.params;
// 获取路径参数 // 获取路径参数
@ -120,7 +125,7 @@ const App = (props) => {
updateWXCodeForInterval(identifier, path); updateWXCodeForInterval(identifier, path);
}, 5000); }, 5000);
} }
} }
// 关闭单个测试集 // 关闭单个测试集
const handleCloseItem = (i, flag) => { const handleCloseItem = (i, flag) => {
@ -140,6 +145,7 @@ const App = (props) => {
evaluateWxCode(identifier, path); evaluateWxCode(identifier, path);
} }
<<<<<<< HEAD
// 关闭弹框 // 关闭弹框
const handleCloseDialog = () => { const handleCloseDialog = () => {
changeWXCodeEvaluateDialog(false); changeWXCodeEvaluateDialog(false);
@ -157,6 +163,8 @@ const App = (props) => {
loadResult(next_game); loadResult(next_game);
} }
=======
>>>>>>> e0ff4d13c62ce7f92a49387eff940448ed2057f3
const tcclasses = isShow ? `wx-code-test-case active` : 'wx-code-test-case'; const tcclasses = isShow ? `wx-code-test-case active` : 'wx-code-test-case';
const loading = showLoading ? 'code-evaluate-loading active' : 'code-evaluate-loading'; const loading = showLoading ? 'code-evaluate-loading active' : 'code-evaluate-loading';
const dialog = showDialog ? 'pass-dialog active' : 'pass-dialog'; const dialog = showDialog ? 'pass-dialog active' : 'pass-dialog';
@ -226,20 +234,25 @@ const App = (props) => {
测试集{i + 1} 测试集{i + 1}
</h2> </h2>
{ {
<<<<<<< HEAD
is_public && last_compile_output is_public && last_compile_output
? (result ? (result
=======
is_public
? (result
>>>>>>> e0ff4d13c62ce7f92a49387eff940448ed2057f3
? <span className="iconfont icon-wancheng case_item_success"></span> ? <span className="iconfont icon-wancheng case_item_success"></span>
: <span className="iconfont icon-jinggao1 case_item_fail"></span>) : <span className="iconfont icon-jinggao1 case_item_fail"></span>)
: (<span className="case-item-tips"> : (<span className="case-item-tips">
隐藏测试集暂不支持解锁和查看 隐藏测试集暂不支持解锁和查看
{/* {result {/* {result
? <span className="iconfont icon-wancheng case_item_success"></span> ? <span className="iconfont icon-wancheng case_item_success"></span>
: <span className="iconfont icon-jinggao1 case_item_fail"></span> : <span className="iconfont icon-jinggao1 case_item_fail"></span>
} */} } */}
</span>) </span>)
} }
</div> </div>
<div className={_classes}> <div className={_classes}>
<span className="desc-title">测试输入</span> <span className="desc-title">测试输入</span>
<span className="test-input">{input || '-'}</span> <span className="test-input">{input || '-'}</span>

@ -1,7 +1,7 @@
/* /*
* @Description: * @Description:
* @Author: tangjiang * @Author: tangjiang
* @Github: * @Github:
* @Date: 2020-01-15 15:44:36 * @Date: 2020-01-15 15:44:36
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2020-01-17 20:39:13 * @LastEditTime : 2020-01-17 20:39:13
@ -11,27 +11,27 @@ import cookie from 'react-cookies'
// axios.defaults.withCredentials = true; // axios.defaults.withCredentials = true;
const setCookier = () => { const setCookier = () => {
const _params = window.location.search; // const _params = window.location.search;
if (_params) { // if (_params) {
let _search = _params.split('?')[1]; // let _search = _params.split('?')[1];
_search.split('&').forEach(item => { // _search.split('&').forEach(item => {
// console.log(item); // // console.log(item);
const _arr = item.split('='); // const _arr = item.split('=');
cookie.remove(_arr[0], { // cookie.remove(_arr[0], {
path: '/', // path: '/',
domain: '.educoder.net' // domain: '.educoder.net'
}); // });
cookie.save(_arr[0], _arr[1], { // cookie.save(_arr[0], _arr[1], {
path: '/', // path: '/',
domain: '.educoder.net' // domain: '.educoder.net'
}); // });
}); // });
} // }
} }
// 获取代码块 // 获取代码块
export async function fetchWxCode (identifier, params) { export async function fetchWxCode (identifier, params) {
setCookier(); setCookier();
const url = `/tasks/${identifier}/rep_content.json`; const url = `/tasks/${identifier}/rep_content.json`;
params = Object.assign({}, params, {withCredentials: true}); params = Object.assign({}, params, {withCredentials: true});
return axios.get(url, {params}); return axios.get(url, {params});

Loading…
Cancel
Save