From 28f420ec22eab76f5edb0b26255dae7cd1e268ae Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 14:18:23 +0800 Subject: [PATCH 01/42] =?UTF-8?q?fixed=20=E5=AF=BC=E5=85=A5=E6=8C=91?= =?UTF-8?q?=E6=88=98=E6=9D=AF=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/sync_competition_tzb_user_job.rb | 38 +++++++++++++++++++ app/models/competition_tzb_user.rb | 5 +++ ...5132525119_create_competition_tzb_users.rb | 27 +++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 app/jobs/sync_competition_tzb_user_job.rb create mode 100644 app/models/competition_tzb_user.rb create mode 100644 db/migrate/202505132525119_create_competition_tzb_users.rb diff --git a/app/jobs/sync_competition_tzb_user_job.rb b/app/jobs/sync_competition_tzb_user_job.rb new file mode 100644 index 000000000..b05b546ce --- /dev/null +++ b/app/jobs/sync_competition_tzb_user_job.rb @@ -0,0 +1,38 @@ +class SyncCompetitionTzbUserJob < ApplicationJob + queue_as :default + + def perform(code=nil) + url = EduSetting.get("SyncCompetitionTzbUserUrl") || "https://www.tiaozhanbei.net/api/v1/ai_contest/123456/project_list/" + uri = URI.parse(url) + http = Net::HTTP.new(uri.hostname, uri.port) + if uri.scheme == 'https' + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + http.use_ssl = true + end + response = http.send_request('POST', uri.path, nil, {'Content-Type' => 'application/json'}) + result = JSON.parse(response.body) +# data = '{"Code":"Ok","Message":"成功","Data":[{"corp_id":123456,"match_id":666,"user_uid":"uid_y0gqNR3EesqZVgA", +# "project_pid":"pid_123001","activation_code":"V2nyoEYzl2zRaVySpldc","project_status":"not_finished", +# "project_status_text":"未提交","status_level":"school","status_level_text":"校级","school_code":"10003", +# "school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_JHnTBdt8GA3tziq","project_pid":"pid_123002","activation_code":"nde8u5HNQ7qqXjkBIQG0","project_status":"submit_to","project_status_text":"已提交","status_level":"school","status_level_text":"校级","school_code":"10003","school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_2tCNcoKX8T8oHvk","project_pid":"pid_123003","activation_code":"iZQCh3mfuJ8ESrUPwGRo","project_status":"pass_by","project_status_text":"审核通过","status_level":"school","status_level_text":"校级","school_code":"10001","school_name":"北京大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_DziaXaNTkyS1M05","project_pid":"pid_123004","activation_code":"c42BKyehYWAxeAqjLdc8","project_status":"not_pass_by","project_status_text":"审核未通过","status_level":"province","status_level_text":"省级","school_code":"10001","school_name":"北京大学","province_name":"北京"}]}' +# result = JSON.parse(data) + Rails.logger.info("SyncCompetitionTzbUserJob size===#{result["Data"].size}") + result["Data"].each do |row| + unless CompetitionTzbUser.find_by(user_uid: row["user_uid"]).present? + tzb_user = CompetitionTzbUser.new + tzb_user.corp_id = row["corp_id"] + tzb_user.match_id = row["match_id"] + tzb_user.user_uid = row["user_uid"] + tzb_user.project_pid = row["project_pid"] + tzb_user.activation_code = row["activation_code"] + tzb_user.project_status = row["project_status"] + tzb_user.status_level = row["status_level"] + tzb_user.project_status_text = row["project_status_text"] + tzb_user.school_code = row["school_code"] + tzb_user.school_name = row["school_name"] + tzb_user.province_name = row["province_name"] + tzb_user.save + end + end + end +end \ No newline at end of file diff --git a/app/models/competition_tzb_user.rb b/app/models/competition_tzb_user.rb new file mode 100644 index 000000000..aa07d3c4d --- /dev/null +++ b/app/models/competition_tzb_user.rb @@ -0,0 +1,5 @@ + +class CompetitionTzbUser < ApplicationRecord + + +end diff --git a/db/migrate/202505132525119_create_competition_tzb_users.rb b/db/migrate/202505132525119_create_competition_tzb_users.rb new file mode 100644 index 000000000..e9df67806 --- /dev/null +++ b/db/migrate/202505132525119_create_competition_tzb_users.rb @@ -0,0 +1,27 @@ +class CreateCompetitionTzbUsers < ActiveRecord::Migration[5.2] + def change + # data = '{"Code":"Ok","Message":"成功","Data":[{"corp_id":123456,"match_id":666,"user_uid":"uid_y0gqNR3EesqZVgA","project_pid":"pid_123001","activation_code":"V2nyoEYzl2zRaVySpldc","project_status":"not_finished","project_status_text":"未提交", + # "status_level":"school","status_level_text":"校级","school_code":"10003","school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_JHnTBdt8GA3tziq","project_pid":"pid_123002","activation_code":"nde8u5HNQ7qqXjkBIQG0","project_status":"submit_to","project_status_text":"已提交","status_level":"school","status_level_text":"校级","school_code":"10003","school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_2tCNcoKX8T8oHvk","project_pid":"pid_123003","activation_code":"iZQCh3mfuJ8ESrUPwGRo","project_status":"pass_by","project_status_text":"审核通过","status_level":"school","status_level_text":"校级","school_code":"10001","school_name":"北京大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_DziaXaNTkyS1M05","project_pid":"pid_123004","activation_code":"c42BKyehYWAxeAqjLdc8","project_status":"not_pass_by","project_status_text":"审核未通过","status_level":"province","status_level_text":"省级","school_code":"10001","school_name":"北京大学","province_name":"北京"}]}' + + create_table :competition_tzb_users do |t| + t.string :corp_id + t.string :match_id + t.string :user_uid + t.string :project_pid + t.string :activation_code + t.string :project_status + t.string :project_status_text + t.string :status_level + t.string :status_level_text + t.string :school_code + t.string :school_name + t.string :province_name + t.integer :user_id + t.timestamps + end + + add_index :competition_tzb_users, :user_uid + add_index :competition_tzb_users, :activation_code + add_index :competition_tzb_users, :user_id + end +end From efde54e76867af4e2126583890445e8b3da14f3e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 14:26:16 +0800 Subject: [PATCH 02/42] =?UTF-8?q?fixed=20=E5=AF=BC=E5=85=A5=E6=8C=91?= =?UTF-8?q?=E6=88=98=E6=9D=AF=E7=94=A8=E6=88=B7=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/sync_competition_tzb_user_job.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/jobs/sync_competition_tzb_user_job.rb b/app/jobs/sync_competition_tzb_user_job.rb index b05b546ce..2d5604514 100644 --- a/app/jobs/sync_competition_tzb_user_job.rb +++ b/app/jobs/sync_competition_tzb_user_job.rb @@ -10,13 +10,14 @@ class SyncCompetitionTzbUserJob < ApplicationJob http.use_ssl = true end response = http.send_request('POST', uri.path, nil, {'Content-Type' => 'application/json'}) + Rails.logger.info("SyncCompetitionTzbUserJob body===#{response.body}") result = JSON.parse(response.body) # data = '{"Code":"Ok","Message":"成功","Data":[{"corp_id":123456,"match_id":666,"user_uid":"uid_y0gqNR3EesqZVgA", # "project_pid":"pid_123001","activation_code":"V2nyoEYzl2zRaVySpldc","project_status":"not_finished", # "project_status_text":"未提交","status_level":"school","status_level_text":"校级","school_code":"10003", # "school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_JHnTBdt8GA3tziq","project_pid":"pid_123002","activation_code":"nde8u5HNQ7qqXjkBIQG0","project_status":"submit_to","project_status_text":"已提交","status_level":"school","status_level_text":"校级","school_code":"10003","school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_2tCNcoKX8T8oHvk","project_pid":"pid_123003","activation_code":"iZQCh3mfuJ8ESrUPwGRo","project_status":"pass_by","project_status_text":"审核通过","status_level":"school","status_level_text":"校级","school_code":"10001","school_name":"北京大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_DziaXaNTkyS1M05","project_pid":"pid_123004","activation_code":"c42BKyehYWAxeAqjLdc8","project_status":"not_pass_by","project_status_text":"审核未通过","status_level":"province","status_level_text":"省级","school_code":"10001","school_name":"北京大学","province_name":"北京"}]}' # result = JSON.parse(data) - Rails.logger.info("SyncCompetitionTzbUserJob size===#{result["Data"].size}") + Rails.logger.info("SyncCompetitionTzbUserJob size===#{result["Data"]}") result["Data"].each do |row| unless CompetitionTzbUser.find_by(user_uid: row["user_uid"]).present? tzb_user = CompetitionTzbUser.new From 59fb95032464ef348ef471f813fa2f0c2ae2f086 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 14:33:39 +0800 Subject: [PATCH 03/42] =?UTF-8?q?fixed=20=E5=AF=BC=E5=85=A5=E6=8C=91?= =?UTF-8?q?=E6=88=98=E6=9D=AF=E7=94=A8=E6=88=B7=20Get?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/sync_competition_tzb_user_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/sync_competition_tzb_user_job.rb b/app/jobs/sync_competition_tzb_user_job.rb index 2d5604514..53c689ae3 100644 --- a/app/jobs/sync_competition_tzb_user_job.rb +++ b/app/jobs/sync_competition_tzb_user_job.rb @@ -9,7 +9,7 @@ class SyncCompetitionTzbUserJob < ApplicationJob http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.use_ssl = true end - response = http.send_request('POST', uri.path, nil, {'Content-Type' => 'application/json'}) + response = http.send_request('GET', uri.path, nil, {'Content-Type' => 'application/json'}) Rails.logger.info("SyncCompetitionTzbUserJob body===#{response.body}") result = JSON.parse(response.body) # data = '{"Code":"Ok","Message":"成功","Data":[{"corp_id":123456,"match_id":666,"user_uid":"uid_y0gqNR3EesqZVgA", From 06afe5083c78b2dee7953cd3bc0aab65667e2c10 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 15:23:35 +0800 Subject: [PATCH 04/42] =?UTF-8?q?fixed=20=E5=AF=BC=E5=85=A5=E6=8C=91?= =?UTF-8?q?=E6=88=98=E6=9D=AF=E7=94=A8=E6=88=B7=E6=8E=A5=E5=8F=A3=E5=92=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../competition_infos_controller.rb | 8 ++++++++ app/jobs/sync_competition_tzb_user_job.rb | 19 ++++++------------- ...5132525119_create_competition_tzb_users.rb | 14 ++++---------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index c762451b8..e5b273f42 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -481,6 +481,14 @@ class CompetitionInfosController < ApplicationController end end + def tzb_actived + tip_exception "请输入挑战激活码" if param[:code].blank? + tzb_user = CompetitionTzbUser.find_by(activation_code: param[:code]) + tip_exception "激活码正在同步确认中,请稍后再试" if tzb_user.blank? + user = User.find_by(tzb_user.user_id) + render_ok({ user: { login: user.login, mail: user.mail, password: tzb_user.pwd } }) + end + def destroy if @competition_info.destroy! flash[:success] = '删除成功' diff --git a/app/jobs/sync_competition_tzb_user_job.rb b/app/jobs/sync_competition_tzb_user_job.rb index 53c689ae3..20a975826 100644 --- a/app/jobs/sync_competition_tzb_user_job.rb +++ b/app/jobs/sync_competition_tzb_user_job.rb @@ -2,36 +2,29 @@ class SyncCompetitionTzbUserJob < ApplicationJob queue_as :default def perform(code=nil) - url = EduSetting.get("SyncCompetitionTzbUserUrl") || "https://www.tiaozhanbei.net/api/v1/ai_contest/123456/project_list/" + url = EduSetting.get("SyncCompetitionTzbUserUrl") || "https://2025.tiaozhanbei.net/api/v1/ai_contest/3579510184/project_list/" uri = URI.parse(url) http = Net::HTTP.new(uri.hostname, uri.port) if uri.scheme == 'https' http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.use_ssl = true end - response = http.send_request('GET', uri.path, nil, {'Content-Type' => 'application/json'}) - Rails.logger.info("SyncCompetitionTzbUserJob body===#{response.body}") + response = http.send_request('GET', uri.path, nil, {'Content-Type' => 'application/json','Authorization' => 'Bearer sk-CQ5oe9UI14nlwYnMtsNV4MBMDLwQ67bQXIa2fDy5m0bSQ5Ts'}) + # Rails.logger.info("SyncCompetitionTzbUserJob body===#{response.body}") result = JSON.parse(response.body) # data = '{"Code":"Ok","Message":"成功","Data":[{"corp_id":123456,"match_id":666,"user_uid":"uid_y0gqNR3EesqZVgA", # "project_pid":"pid_123001","activation_code":"V2nyoEYzl2zRaVySpldc","project_status":"not_finished", # "project_status_text":"未提交","status_level":"school","status_level_text":"校级","school_code":"10003", # "school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_JHnTBdt8GA3tziq","project_pid":"pid_123002","activation_code":"nde8u5HNQ7qqXjkBIQG0","project_status":"submit_to","project_status_text":"已提交","status_level":"school","status_level_text":"校级","school_code":"10003","school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_2tCNcoKX8T8oHvk","project_pid":"pid_123003","activation_code":"iZQCh3mfuJ8ESrUPwGRo","project_status":"pass_by","project_status_text":"审核通过","status_level":"school","status_level_text":"校级","school_code":"10001","school_name":"北京大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_DziaXaNTkyS1M05","project_pid":"pid_123004","activation_code":"c42BKyehYWAxeAqjLdc8","project_status":"not_pass_by","project_status_text":"审核未通过","status_level":"province","status_level_text":"省级","school_code":"10001","school_name":"北京大学","province_name":"北京"}]}' # result = JSON.parse(data) - Rails.logger.info("SyncCompetitionTzbUserJob size===#{result["Data"]}") + Rails.logger.info("SyncCompetitionTzbUserJob size===#{result["Data"].size}") result["Data"].each do |row| unless CompetitionTzbUser.find_by(user_uid: row["user_uid"]).present? tzb_user = CompetitionTzbUser.new - tzb_user.corp_id = row["corp_id"] - tzb_user.match_id = row["match_id"] tzb_user.user_uid = row["user_uid"] - tzb_user.project_pid = row["project_pid"] + tzb_user.user_email = row["user_email"] tzb_user.activation_code = row["activation_code"] - tzb_user.project_status = row["project_status"] - tzb_user.status_level = row["status_level"] - tzb_user.project_status_text = row["project_status_text"] - tzb_user.school_code = row["school_code"] - tzb_user.school_name = row["school_name"] - tzb_user.province_name = row["province_name"] + tzb_user.info_json = row.to_json tzb_user.save end end diff --git a/db/migrate/202505132525119_create_competition_tzb_users.rb b/db/migrate/202505132525119_create_competition_tzb_users.rb index e9df67806..95a94f1d0 100644 --- a/db/migrate/202505132525119_create_competition_tzb_users.rb +++ b/db/migrate/202505132525119_create_competition_tzb_users.rb @@ -4,19 +4,13 @@ class CreateCompetitionTzbUsers < ActiveRecord::Migration[5.2] # "status_level":"school","status_level_text":"校级","school_code":"10003","school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_JHnTBdt8GA3tziq","project_pid":"pid_123002","activation_code":"nde8u5HNQ7qqXjkBIQG0","project_status":"submit_to","project_status_text":"已提交","status_level":"school","status_level_text":"校级","school_code":"10003","school_name":"清华大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_2tCNcoKX8T8oHvk","project_pid":"pid_123003","activation_code":"iZQCh3mfuJ8ESrUPwGRo","project_status":"pass_by","project_status_text":"审核通过","status_level":"school","status_level_text":"校级","school_code":"10001","school_name":"北京大学","province_name":"北京"},{"corp_id":123456,"match_id":666,"user_uid":"uid_DziaXaNTkyS1M05","project_pid":"pid_123004","activation_code":"c42BKyehYWAxeAqjLdc8","project_status":"not_pass_by","project_status_text":"审核未通过","status_level":"province","status_level_text":"省级","school_code":"10001","school_name":"北京大学","province_name":"北京"}]}' create_table :competition_tzb_users do |t| - t.string :corp_id - t.string :match_id t.string :user_uid - t.string :project_pid + t.string :user_email t.string :activation_code - t.string :project_status - t.string :project_status_text - t.string :status_level - t.string :status_level_text - t.string :school_code - t.string :school_name - t.string :province_name + t.text :info_json t.integer :user_id + t.string :pwd + t.boolean :actived, default: false t.timestamps end From e40f1866a46a6eac24425d61210aa7559b60dc0f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 15:54:21 +0800 Subject: [PATCH 05/42] =?UTF-8?q?fixed=20=E5=AF=BC=E5=85=A5=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=B8=94=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/sync_competition_tzb_user_job.rb | 42 ++++++++++++++++++++++- app/models/competition_tzb_user.rb | 9 ++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/jobs/sync_competition_tzb_user_job.rb b/app/jobs/sync_competition_tzb_user_job.rb index 20a975826..c65bce3dd 100644 --- a/app/jobs/sync_competition_tzb_user_job.rb +++ b/app/jobs/sync_competition_tzb_user_job.rb @@ -19,7 +19,8 @@ class SyncCompetitionTzbUserJob < ApplicationJob # result = JSON.parse(data) Rails.logger.info("SyncCompetitionTzbUserJob size===#{result["Data"].size}") result["Data"].each do |row| - unless CompetitionTzbUser.find_by(user_uid: row["user_uid"]).present? + tzb_user = CompetitionTzbUser.find_by(user_uid: row["user_uid"]) + if tzb_user.blank? tzb_user = CompetitionTzbUser.new tzb_user.user_uid = row["user_uid"] tzb_user.user_email = row["user_email"] @@ -27,6 +28,45 @@ class SyncCompetitionTzbUserJob < ApplicationJob tzb_user.info_json = row.to_json tzb_user.save end + if tzb_user.present? && tzb_user.user_id.blank? + password = generate_user_login('') + user_id = register_user(tzb_user, password) + tzb_user.update_attributes!(user_id: user_id, pwd: password) + end end end + + + def register_user(tzb_user, pwd) + user = User.find_by(mail: tzb_user.user_email) + return user.id if user.present? + username = generate_user_login('p') + email = tzb_user.user_email + email = "#{username}@example.org" if email.blank? + company_name = user_info("school_name") + user_type = row[4].to_s =="0" ? 3 : 4 + created_on = row[5].to_s + password = pwd + user = User.new(login: username, mail: email, password: password, type: 'User', company_name: company_name) + interactor = Gitea::RegisterInteractor.call({ username: username, email: email, password: password }) + gitea_user = interactor.result + result = Gitea::User::GenerateTokenService.call(username, password) + user.gitea_token = result['sha1'] + user.gitea_uid = gitea_user[:body]['id'] + user.user_type = user_type if company_name.present? && company_name.include?("大学") + user.created_on = created_on if created_on.present? + user.updated_on = created_on if created_on.present? + user.save! + UserExtension.create!(user_id: user.id) + user.id + end + + + # 生成邀请码 + def generate_user_login type + code = %W(0 1 2 3 4 5 6 7 8 9).sample(8).join + code = type + code.to_s + return generate_user_login(type) if User.where(login: code).present? + code + end end \ No newline at end of file diff --git a/app/models/competition_tzb_user.rb b/app/models/competition_tzb_user.rb index aa07d3c4d..da2137a2a 100644 --- a/app/models/competition_tzb_user.rb +++ b/app/models/competition_tzb_user.rb @@ -1,5 +1,12 @@ class CompetitionTzbUser < ApplicationRecord - + def user_info(attr) + return "" if self.info_json.blank? + data = JSON.parse(self.info_json) + data["#{attr}"] + rescue => err + Rails.logger.info("info_json is not json,error:#{err}") + "" + end end From 8359e8a5b2e2387f2d29b7092e5e070cd027efeb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 15:58:01 +0800 Subject: [PATCH 06/42] =?UTF-8?q?fixed=20=E5=AF=BC=E5=85=A5=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=B8=94=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/sync_competition_tzb_user_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/sync_competition_tzb_user_job.rb b/app/jobs/sync_competition_tzb_user_job.rb index c65bce3dd..9b673e9df 100644 --- a/app/jobs/sync_competition_tzb_user_job.rb +++ b/app/jobs/sync_competition_tzb_user_job.rb @@ -43,7 +43,7 @@ class SyncCompetitionTzbUserJob < ApplicationJob username = generate_user_login('p') email = tzb_user.user_email email = "#{username}@example.org" if email.blank? - company_name = user_info("school_name") + company_name = tzb_user.user_info("school_name") user_type = row[4].to_s =="0" ? 3 : 4 created_on = row[5].to_s password = pwd From 74158189a145616ce9098aba0470046c633dd794 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 16:04:25 +0800 Subject: [PATCH 07/42] =?UTF-8?q?fixed=20=E5=AF=BC=E5=85=A5=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=B8=94=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/sync_competition_tzb_user_job.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/jobs/sync_competition_tzb_user_job.rb b/app/jobs/sync_competition_tzb_user_job.rb index 9b673e9df..ab4af2866 100644 --- a/app/jobs/sync_competition_tzb_user_job.rb +++ b/app/jobs/sync_competition_tzb_user_job.rb @@ -44,8 +44,7 @@ class SyncCompetitionTzbUserJob < ApplicationJob email = tzb_user.user_email email = "#{username}@example.org" if email.blank? company_name = tzb_user.user_info("school_name") - user_type = row[4].to_s =="0" ? 3 : 4 - created_on = row[5].to_s + user_type = company_name.present? && company_name.include?("大学") ? 4 : 6 password = pwd user = User.new(login: username, mail: email, password: password, type: 'User', company_name: company_name) interactor = Gitea::RegisterInteractor.call({ username: username, email: email, password: password }) @@ -53,9 +52,7 @@ class SyncCompetitionTzbUserJob < ApplicationJob result = Gitea::User::GenerateTokenService.call(username, password) user.gitea_token = result['sha1'] user.gitea_uid = gitea_user[:body]['id'] - user.user_type = user_type if company_name.present? && company_name.include?("大学") - user.created_on = created_on if created_on.present? - user.updated_on = created_on if created_on.present? + user.user_type = user_type user.save! UserExtension.create!(user_id: user.id) user.id From e85fc2d9be76ec032d0d91110705244752a19405 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 16:45:06 +0800 Subject: [PATCH 08/42] =?UTF-8?q?fixed=20=E6=8C=91=E6=88=98=E6=9D=AF?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 1 + config/routes.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index e5b273f42..05ac5b355 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -485,6 +485,7 @@ class CompetitionInfosController < ApplicationController tip_exception "请输入挑战激活码" if param[:code].blank? tzb_user = CompetitionTzbUser.find_by(activation_code: param[:code]) tip_exception "激活码正在同步确认中,请稍后再试" if tzb_user.blank? + SyncCompetitionTzbUserJob.perform_later("code") user = User.find_by(tzb_user.user_id) render_ok({ user: { login: user.login, mail: user.mail, password: tzb_user.pwd } }) end diff --git a/config/routes.rb b/config/routes.rb index 2e81b6dc2..b4ae259e1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -480,6 +480,7 @@ Rails.application.routes.draw do get :recommend, on: :collection post :auto_score, on: :collection post :update_expert_audit, on: :collection + post :tzb_actived, on: :collection member do get :enroll_list get :ranking_list From ee5cf5ed638f603e42224413c7b77bd916e4860e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 16:47:58 +0800 Subject: [PATCH 09/42] =?UTF-8?q?fixed=20=E6=8C=91=E6=88=98=E6=9D=AF?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index 05ac5b355..dcbb456d7 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -482,11 +482,12 @@ class CompetitionInfosController < ApplicationController end def tzb_actived - tip_exception "请输入挑战激活码" if param[:code].blank? + tip_exception "请输入激活码" if param[:code].blank? tzb_user = CompetitionTzbUser.find_by(activation_code: param[:code]) tip_exception "激活码正在同步确认中,请稍后再试" if tzb_user.blank? SyncCompetitionTzbUserJob.perform_later("code") user = User.find_by(tzb_user.user_id) + tzb_user.update_attributes!(actived: true) render_ok({ user: { login: user.login, mail: user.mail, password: tzb_user.pwd } }) end From 1e72c4db72753dc9f58f422bfb35c85d688166ba Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 16:50:00 +0800 Subject: [PATCH 10/42] =?UTF-8?q?fixed=20=E6=8C=91=E6=88=98=E6=9D=AF?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index dcbb456d7..d694de01b 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -482,8 +482,8 @@ class CompetitionInfosController < ApplicationController end def tzb_actived - tip_exception "请输入激活码" if param[:code].blank? - tzb_user = CompetitionTzbUser.find_by(activation_code: param[:code]) + tip_exception "请输入激活码" if params[:code].blank? + tzb_user = CompetitionTzbUser.find_by(activation_code: params[:code]) tip_exception "激活码正在同步确认中,请稍后再试" if tzb_user.blank? SyncCompetitionTzbUserJob.perform_later("code") user = User.find_by(tzb_user.user_id) From c293202f7f67327f6bd40fcc303a161d677cda0e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 16:53:59 +0800 Subject: [PATCH 11/42] =?UTF-8?q?fixed=20=E6=8C=91=E6=88=98=E6=9D=AF?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index d694de01b..bafd20899 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -483,10 +483,10 @@ class CompetitionInfosController < ApplicationController def tzb_actived tip_exception "请输入激活码" if params[:code].blank? + SyncCompetitionTzbUserJob.perform_later("code") tzb_user = CompetitionTzbUser.find_by(activation_code: params[:code]) tip_exception "激活码正在同步确认中,请稍后再试" if tzb_user.blank? - SyncCompetitionTzbUserJob.perform_later("code") - user = User.find_by(tzb_user.user_id) + user = User.find_by(id: tzb_user.user_id) tzb_user.update_attributes!(actived: true) render_ok({ user: { login: user.login, mail: user.mail, password: tzb_user.pwd } }) end From f5ee9a9234bb407384d6cdb089774dbe85f39edd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 16:57:08 +0800 Subject: [PATCH 12/42] =?UTF-8?q?fixed=20=E6=8C=91=E6=88=98=E6=9D=AF?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=BF=80=E6=B4=BB=EF=BC=8C=E5=B9=B6=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index bafd20899..efac91118 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -487,6 +487,7 @@ class CompetitionInfosController < ApplicationController tzb_user = CompetitionTzbUser.find_by(activation_code: params[:code]) tip_exception "激活码正在同步确认中,请稍后再试" if tzb_user.blank? user = User.find_by(id: tzb_user.user_id) + successful_authentication(user) tzb_user.update_attributes!(actived: true) render_ok({ user: { login: user.login, mail: user.mail, password: tzb_user.pwd } }) end From bbc113b388916fc41458ac0b8bc5d00dd5a815e1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 17:25:32 +0800 Subject: [PATCH 13/42] =?UTF-8?q?fixed=20=E5=A2=9E=E5=8A=A0=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E9=A6=96=E9=A1=B5logo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/laboratory_settings_controller.rb | 2 +- app/models/laboratory_setting.rb | 4 ++++ .../admins/save_laboratory_setting_service.rb | 1 + .../admins/laboratory_settings/show.html.erb | 19 ++++++++++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/controllers/admins/laboratory_settings_controller.rb b/app/controllers/admins/laboratory_settings_controller.rb index d522a479b..681965f7c 100644 --- a/app/controllers/admins/laboratory_settings_controller.rb +++ b/app/controllers/admins/laboratory_settings_controller.rb @@ -23,7 +23,7 @@ class Admins::LaboratorySettingsController < Admins::BaseController def form_params params.permit(:identifier, :name, - :nav_logo, :login_logo, :tab_logo, :oj_banner, + :nav_logo, :login_logo, :tab_logo, :oj_banner, :index_logo, :subject_banner, :course_banner, :competition_banner, :moop_cases_banner, :footer, navbar: %i[name link hidden index]) end diff --git a/app/models/laboratory_setting.rb b/app/models/laboratory_setting.rb index 61c677def..9e6eb44f4 100644 --- a/app/models/laboratory_setting.rb +++ b/app/models/laboratory_setting.rb @@ -35,6 +35,10 @@ class LaboratorySetting < ApplicationRecord image_url('nav') end + def index_logo_url + image_url('index') + end + def tab_logo_url image_url('tab') end diff --git a/app/services/admins/save_laboratory_setting_service.rb b/app/services/admins/save_laboratory_setting_service.rb index ad040585f..c79f5bcfd 100644 --- a/app/services/admins/save_laboratory_setting_service.rb +++ b/app/services/admins/save_laboratory_setting_service.rb @@ -40,6 +40,7 @@ class Admins::SaveLaboratorySettingService < ApplicationService save_image_file(params[:nav_logo], 'nav') save_image_file(params[:login_logo], 'login') save_image_file(params[:tab_logo], 'tab') + save_image_file(params[:index_logo], 'index') save_image_file(params[:subject_banner], '_subject_banner') save_image_file(params[:course_banner], '_course_banner') save_image_file(params[:competition_banner], '_competition_banner') diff --git a/app/views/admins/laboratory_settings/show.html.erb b/app/views/admins/laboratory_settings/show.html.erb index 6fa3b6adf..b08a5ca12 100644 --- a/app/views/admins/laboratory_settings/show.html.erb +++ b/app/views/admins/laboratory_settings/show.html.erb @@ -46,7 +46,20 @@
Logo设置
-
+
+ <% nav_logo_img = setting.index_logo_url %> + +
+
网站首页logo
+
格式:PNG、JPG
+
尺寸:高度38px以内,宽等比例缩放
+
+
+
<% nav_logo_img = setting.nav_logo_url %>
-
+
<% login_logo_img = setting.login_logo_url %>
-
+
<% tab_logo_img = setting.tab_logo_url %>
From 819505d94139a246c5a17730edf3f66baae323df Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 13 May 2025 17:29:10 +0800 Subject: [PATCH 14/42] =?UTF-8?q?fixed=20=E5=A2=9E=E5=8A=A0=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E9=A6=96=E9=A1=B5logo,setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/settings/show.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 7b6e8fe8f..799d21aba 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -6,6 +6,7 @@ json.setting do json.name default_setting.name json.nav_logo_url default_setting.nav_logo_url&.[](1..-1) json.login_logo_url default_setting.login_logo_url&.[](1..-1) + json.index_logo_url default_setting.index_logo_url&.[](1..-1) json.tab_logo_url default_setting.tab_logo_url.present? ? default_setting.tab_logo_url&.[](1..-1) : "favicon.ico" json.site_page_deploy_domain @deploy_domain From cc4d808a84a056d22c65faa37be676aa799c9a0e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 14 May 2025 16:17:04 +0800 Subject: [PATCH 15/42] =?UTF-8?q?fixed=20tzb=E6=8F=90=E4=BA=A4=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E5=8D=B3=E6=8A=A5=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index efac91118..c89955f85 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -346,7 +346,16 @@ class CompetitionInfosController < ApplicationController def upload_apply_template competition_user = CompetitionUser.find_by(competition_info: @competition_info.id, user_id: current_user.id) - tip_exception "未报名,请先报名" if competition_user.blank? + # tip_exception "未报名,请先报名" if competition_user.blank? + if competition_user.blank? && @competition_info.identifier == "tzb2025" + competition_user = CompetitionUser.new + competition_user.competition_info = @competition_info + competition_user.user = current_user + competition_user.status = 1 + competition_user.save + else + tip_exception "未报名,请先报名" + end tip_exception "附件参数apply_template_id不能为空" if params[:apply_template_id].blank? competition_user.update_attributes!(ext2: params[:apply_template_id], ext3: 1) render_ok From afa84288e5bc7a6d8cae1ce696ed1890443d2516 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 14 May 2025 16:46:06 +0800 Subject: [PATCH 16/42] =?UTF-8?q?fixed=20tzb=E6=8F=90=E4=BA=A4=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E5=8D=B3=E6=8A=A5=E5=90=8Dstatus=20=3D=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index c89955f85..c1c8b6541 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -351,7 +351,7 @@ class CompetitionInfosController < ApplicationController competition_user = CompetitionUser.new competition_user.competition_info = @competition_info competition_user.user = current_user - competition_user.status = 1 + competition_user.status = 0 competition_user.save else tip_exception "未报名,请先报名" From 910914a4cc11242d2e9fddc2096da5b0fb8782f9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 15 May 2025 09:28:24 +0800 Subject: [PATCH 17/42] =?UTF-8?q?fixed=20tzb=E7=94=B3=E8=AF=B7=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=94=A8=E6=88=B7cron?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/sidekiq_cron.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/sidekiq_cron.yml b/config/sidekiq_cron.yml index 5dc45f1a1..9ae814d74 100644 --- a/config/sidekiq_cron.yml +++ b/config/sidekiq_cron.yml @@ -33,3 +33,8 @@ cache_async_reset: queue: cache args: - "platform_statistic_service" + +sync_competition_tzb_user: + cron: "*/5 * * * *" + class: "SyncCompetitionTzbUserJob" + queue: default From 15cd7e69ef871db7312b3a5acd929aeff3e325e2 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 15 May 2025 11:01:10 +0800 Subject: [PATCH 18/42] =?UTF-8?q?fixed=20tzb=E7=94=B3=E8=AF=B7=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=94=A8=E6=88=B7user=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index c1c8b6541..556021ea4 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -495,6 +495,7 @@ class CompetitionInfosController < ApplicationController SyncCompetitionTzbUserJob.perform_later("code") tzb_user = CompetitionTzbUser.find_by(activation_code: params[:code]) tip_exception "激活码正在同步确认中,请稍后再试" if tzb_user.blank? + tip_exception "激活码正在同步确认中,请稍后再试" if tzb_user.user_id.blank? user = User.find_by(id: tzb_user.user_id) successful_authentication(user) tzb_user.update_attributes!(actived: true) From 2c72aae408cfbc2da8f6b18c05e95d34c50c7c3e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 15 May 2025 16:52:26 +0800 Subject: [PATCH 19/42] =?UTF-8?q?fixed=20tzb=E6=9B=B4=E6=96=B0yys2025?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index 556021ea4..270aaf26b 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -347,7 +347,7 @@ class CompetitionInfosController < ApplicationController def upload_apply_template competition_user = CompetitionUser.find_by(competition_info: @competition_info.id, user_id: current_user.id) # tip_exception "未报名,请先报名" if competition_user.blank? - if competition_user.blank? && @competition_info.identifier == "tzb2025" + if competition_user.blank? && @competition_info.identifier == "yys2025" competition_user = CompetitionUser.new competition_user.competition_info = @competition_info competition_user.user = current_user From 3f65f5dd9bca8e01faebfa5bfadd3ecc9d04e427 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 16 May 2025 10:34:01 +0800 Subject: [PATCH 20/42] =?UTF-8?q?fixed=20=E5=8A=A8=E6=80=81=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=8D=E5=AD=98=E6=97=B6=E5=AE=B9=E9=94=99=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/project_trends/_detail.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/project_trends/_detail.json.jbuilder b/app/views/project_trends/_detail.json.jbuilder index b9febc107..ba26fb57e 100644 --- a/app/views/project_trends/_detail.json.jbuilder +++ b/app/views/project_trends/_detail.json.jbuilder @@ -16,7 +16,7 @@ end if trend.trend_type == "Issue" json.partial! "issues/simple_issue_item", locals: {issue: trend.trend} -elsif trend.trend_type == "VersionRelease" +elsif trend.trend_type == "VersionRelease" && trend.trend.present? json.partial! "version_releases/simple_version_release", locals: {version: trend.trend} elsif trend.trend_type == "CommitLog" commit_log = trend.trend From 8647778145ead2d785620f548b07c89d9803f8ce Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 16 May 2025 15:51:42 +0800 Subject: [PATCH 21/42] =?UTF-8?q?fixed=20=E5=8F=82=E8=B5=9B=E6=8A=A5?= =?UTF-8?q?=E5=90=8D=E8=A1=A8=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5=E4=B8=8D?= =?UTF-8?q?=E5=9C=A8execl=E4=B8=AD=E5=AF=BC=E5=87=BA=EF=BC=8C=E6=9C=89?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E7=9A=84=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/competition_infos_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index 270aaf26b..de62b9784 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -159,7 +159,7 @@ class CompetitionInfosController < ApplicationController enroll_fields = @competition_info.enroll_fields enroll_fields = enroll_fields.delete_if { |key, value| ["sub_item", "works_name", "works_url"].include?(value) } if params[:upload].to_s != "true" @table_columns = enroll_fields.keys - @table_columns = @table_columns + %w(参赛报名表下载链接) + # @table_columns = @table_columns + %w(参赛报名表下载链接) @table_columns = @table_columns + %w(作品下载链接) if params[:upload].to_s == "true" && !enroll_fields.values.include?("works_url") @table_columns = @table_columns + %w(申请表下载链接) if params[:apply_status].present? @table_columns = @table_columns + %w(bm审查下载链接) if @competition_info.identifier == "KXSYSJ-2024" && params[:upload].to_s == "true" @@ -171,8 +171,8 @@ class CompetitionInfosController < ApplicationController competition_users.each do |u| info_array = [] file_array = [] - file = Attachment.where_id_or_uuid(u.enroll_template_id).first - file_array = file_array + [file.blank? ? "" : "#{EduSetting.get('host_name')}/#{download_url(file)}"] + # file = Attachment.where_id_or_uuid(u.enroll_template_id).first + # file_array = file_array + [file.blank? ? "" : "#{EduSetting.get('host_name')}/#{download_url(file)}"] if params[:upload].to_s == "true" && !enroll_fields.values.include?("works_url") file_array = file_array + [u.attachments.blank? ? "" : "#{EduSetting.get('host_name')}/#{download_url(u.attachments.first)}"] end From 0664ad6995560d310579523cf86d1c1749d0c9fd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 16 May 2025 17:21:37 +0800 Subject: [PATCH 22/42] =?UTF-8?q?fixed=20topic=20=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E6=97=A0=E9=99=90=E5=A2=9E=E5=8A=A0=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/topics_controller.rb | 82 +++++++++++++++++ app/libs/util/file_manage.rb | 1 + app/models/topic.rb | 58 ++++++++++++ app/models/topic/ck_forum.rb | 2 +- app/models/topic/js_forum.rb | 2 +- app/models/topic/service_term.rb | 2 +- app/views/admins/topics/_form_modal.html.erb | 91 +++++++++++++++++++ .../topics/_form_modal_ck_case.html.erb | 51 +++++++++++ ...orm_modal_scientific_organization.html.erb | 60 ++++++++++++ app/views/admins/topics/_list.html.erb | 47 ++++++++++ .../admins/topics/_list_ck_case.html.erb | 37 ++++++++ .../_list_scientific_organization.html.erb | 35 +++++++ app/views/admins/topics/edit.js.erb | 23 +++++ app/views/admins/topics/index.html.erb | 28 ++++++ app/views/admins/topics/index.js.erb | 1 + app/views/admins/topics/new.js.erb | 23 +++++ app/views/topics/_all.json.jbuilder | 1 + app/views/topics/index.json.jbuilder | 4 +- config/routes.rb | 1 + 19 files changed, 544 insertions(+), 5 deletions(-) create mode 100644 app/controllers/admins/topics_controller.rb create mode 100644 app/views/admins/topics/_form_modal.html.erb create mode 100644 app/views/admins/topics/_form_modal_ck_case.html.erb create mode 100644 app/views/admins/topics/_form_modal_scientific_organization.html.erb create mode 100644 app/views/admins/topics/_list.html.erb create mode 100644 app/views/admins/topics/_list_ck_case.html.erb create mode 100644 app/views/admins/topics/_list_scientific_organization.html.erb create mode 100644 app/views/admins/topics/edit.js.erb create mode 100644 app/views/admins/topics/index.html.erb create mode 100644 app/views/admins/topics/index.js.erb create mode 100644 app/views/admins/topics/new.js.erb create mode 100644 app/views/topics/_all.json.jbuilder diff --git a/app/controllers/admins/topics_controller.rb b/app/controllers/admins/topics_controller.rb new file mode 100644 index 000000000..6c41c2729 --- /dev/null +++ b/app/controllers/admins/topics_controller.rb @@ -0,0 +1,82 @@ +class Admins::TopicsController < Admins::Topic::BaseController + before_action :require_business + before_action :find_type + before_action :find_topic, only: [:edit, :update, :destroy, :show] + + + + def index + + q = ::Topic.all + q = q.where(type: params[:type]) if params[:type].present? + q = q.ransack(title_cont: params[:search]) + topics = q.result(distinct: true) + @topics = paginate(topics) + end + + def new + @topic = topic_model.new + end + + def create + @topic = topic_model.new(topic_params) + if @topic.save + save_image_file(params[:image], @topic) if params[:image].present? + redirect_to admins_topics_path(type:@type) + flash[:success] = "新增成功" + else + redirect_to admins_topics_path(type:@type) + flash[:danger] = "新增失败" + end + end + + def show + end + + + def edit + end + + def update + @topic.attributes = topic_params + if @topic.save! + save_image_file(params[:image], @topic) if params[:image].present? + redirect_to admins_topics_path(type:@type) + flash[:success] = "更新成功" + return + else + redirect_to admins_topics_path(type:@type) + flash[:danger] = "更新失败" + return + end + end + + def destroy + if @topic.destroy + redirect_to admins_topics_path(type:@type) + flash[:success] = "删除成功" + else + redirect_to admins_topics_path(type:@type) + flash[:danger] = "删除失败" + end + end + + private + def find_topic + @topic = topic_model.find(params[:id]) + @type = @topic.type if @type.blank? + end + + def find_type + @type = params[:type] + end + + def topic_model + ::Topic + end + + def topic_params + params.require(:topic).permit(:type, :title, :uuid, :url, :order_index, + :location, :identifier, :labels, :description, :date) + end +end \ No newline at end of file diff --git a/app/libs/util/file_manage.rb b/app/libs/util/file_manage.rb index 2f87a3e86..fd7fccee7 100644 --- a/app/libs/util/file_manage.rb +++ b/app/libs/util/file_manage.rb @@ -15,6 +15,7 @@ module Util::FileManage end def source_disk_filename(source, suffix=nil) + Rails.logger.info "11111111111=========+#{source.class.name}" disk_filename(source.class.name, source.id, suffix) end diff --git a/app/models/topic.rb b/app/models/topic.rb index 4642fa3ed..25753e3da 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -18,6 +18,58 @@ class Topic < ApplicationRecord default_scope { order(order_index: :desc)} scope :with_single_type, ->(type){where(type: trans_simpletype_to_classtype(type))} + self.inheritance_column = nil + + def self.has_templates?(type) + type_simple_name = Topic.type_simple_name(type) + ["ck_case", "scientific_organization"].include?(type_simple_name) + end + + def self.sub_types + [ + ["Topic::ActivityForum", "activity_forum", "首页平台动态"], + ["Topic::Banner", "banner", "首页banner"], + ["Topic::Card", "card", "首页卡片内容"], + ["Topic::Cooperator", "cooperator", "首页合作伙伴"], + ["Topic::Organization", "organization", "首页组织logo"], + ["Topic::ScientificOrganization", "scientific_organization", "科研机构logo"], + ["Topic::School", "school", "首页高校logo"], + ["Topic::ExcellentProject", "excellent_project", "首页优秀项目"], + ["Topic::ExperienceForum", "experience_forum", "首页经验分享"], + ["Topic::GlccNews", "glcc_news", "GLCC新闻稿"], + ["Topic::PinnedForum", "pinned_forum", "首页精选文章"], + ["Topic::AppletBanner", "applet_banner", "Applet首页banner"], + ["Topic::FriendlyLink", "friendly_link", "底部友情链接"], + ["Topic::JoinUs", "Join_us", "底部加入我们"], + ["Topic::CkBanner", "ck_banner", "创客空间卡片内容"], + ["Topic::TechnicalDiscussion", "technical_discussion", "首页技术讨论"], + ["Topic::CkForum", "ck_forum", "创客首页-创客内容"], + ["Topic::JsForum", "js_forum", "创客首页-竞赛内容"], + ["Topic::ServiceTerm", "service_term", "服务条款"], + ["Topic::CkCase", "ck_case", "创客案例"], + ] + end + + def self.opt_select + Topic.sub_types.map{|s| [s[2],s[0]]} + end + + def type_cn_name + filter = Topic.sub_types.select { |s| s[0] == self.type } + filter.blank? ? self.type : filter.first[2] + end + + def self.type_simple_name(type) + filter = Topic.sub_types.select { |s| s[0] == type } + filter.blank? ? type : filter.first[1] + end + + + + def self.type_filter_cn_name(type) + filter = Topic.sub_types.select { |s| s[0] == type } + filter.blank? ? type : filter.first[2] + end def image image_url('image') @@ -59,6 +111,12 @@ class Topic < ApplicationRecord ['Topic::CkForum', 'Topic::JsForum'] when 'service_term' 'Topic::ServiceTerm' + when 'scientific_organization' + 'Topic::ScientificOrganization' + when 'ck_case' + 'Topic::CkCase' + else + type end end diff --git a/app/models/topic/ck_forum.rb b/app/models/topic/ck_forum.rb index f65d05dda..b0cc6bd9f 100644 --- a/app/models/topic/ck_forum.rb +++ b/app/models/topic/ck_forum.rb @@ -11,6 +11,6 @@ # location :integer default("0") # -# Applet首页banner +# 创客首页-创客内容 class Topic::CkForum < Topic end diff --git a/app/models/topic/js_forum.rb b/app/models/topic/js_forum.rb index da4bde5f1..284077a81 100644 --- a/app/models/topic/js_forum.rb +++ b/app/models/topic/js_forum.rb @@ -11,6 +11,6 @@ # location :integer default("0") # -# Applet首页banner +# 创客首页-竞赛内容 class Topic::JsForum < Topic end diff --git a/app/models/topic/service_term.rb b/app/models/topic/service_term.rb index 364e4968f..6bea4986a 100644 --- a/app/models/topic/service_term.rb +++ b/app/models/topic/service_term.rb @@ -11,6 +11,6 @@ # location :integer default("0") # -# 首页组织logo +# 服务条款 class Topic::ServiceTerm < Topic end \ No newline at end of file diff --git a/app/views/admins/topics/_form_modal.html.erb b/app/views/admins/topics/_form_modal.html.erb new file mode 100644 index 000000000..33bd1d85f --- /dev/null +++ b/app/views/admins/topics/_form_modal.html.erb @@ -0,0 +1,91 @@ + \ No newline at end of file diff --git a/app/views/admins/topics/_form_modal_ck_case.html.erb b/app/views/admins/topics/_form_modal_ck_case.html.erb new file mode 100644 index 000000000..7d52a1fc5 --- /dev/null +++ b/app/views/admins/topics/_form_modal_ck_case.html.erb @@ -0,0 +1,51 @@ + \ No newline at end of file diff --git a/app/views/admins/topics/_form_modal_scientific_organization.html.erb b/app/views/admins/topics/_form_modal_scientific_organization.html.erb new file mode 100644 index 000000000..4ad731426 --- /dev/null +++ b/app/views/admins/topics/_form_modal_scientific_organization.html.erb @@ -0,0 +1,60 @@ + \ No newline at end of file diff --git a/app/views/admins/topics/_list.html.erb b/app/views/admins/topics/_list.html.erb new file mode 100644 index 000000000..1b1cb8ca6 --- /dev/null +++ b/app/views/admins/topics/_list.html.erb @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + <% if topics.present? %> + <% topics.each_with_index do |topic, index| %> + + + + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
序号类型标题跳转地址内容信息ID显示位置标识标签排序等级操作
<%= list_index_no((params[:page] || 1).to_i, index) %><%= topic.type_cn_name %><%= topic.title %><%= topic.url %><%= topic.uuid %><%= ["首页", "竞赛", "底部"][Topic.locations[topic.location]] %><%= topic.identifier %> + <% if topic.labels.present? %> + <% topic.labels.split(",").each do |label| %> + <%= label %> + <% end %> + <% end %> + <%= topic.order_index %> + <%= link_to "编辑", edit_admins_topic_path(topic), remote: true, class: "action" %> + <%= link_to "删除", admins_topic_path(topic), method: :delete, data: { confirm: "确认删除的吗?" }, class: "action" %> +
+ +<%= render partial: 'admins/shared/paginate', locals: { objects: topics } %> \ No newline at end of file diff --git a/app/views/admins/topics/_list_ck_case.html.erb b/app/views/admins/topics/_list_ck_case.html.erb new file mode 100644 index 000000000..b9605b110 --- /dev/null +++ b/app/views/admins/topics/_list_ck_case.html.erb @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + <% if topics.present? %> + <% topics.each_with_index do |topic, index| %> + + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
序号标题描述id金额排序等级操作
<%= list_index_no((params[:page] || 1).to_i, index) %><%= topic.title %><%= topic.description %><%= topic.uuid %><%= topic.identifier %><%= topic.order_index %> + <%= link_to "编辑", edit_admins_topic_path(topic), remote: true, class: "action" %> + <%= link_to "删除", admins_topic_path(topic), method: :delete, data: { confirm: "确认删除的吗?" }, class: "action" %> +
+ +<%= render partial: 'admins/shared/paginate', locals: { objects: topics } %> \ No newline at end of file diff --git a/app/views/admins/topics/_list_scientific_organization.html.erb b/app/views/admins/topics/_list_scientific_organization.html.erb new file mode 100644 index 000000000..2206aea0f --- /dev/null +++ b/app/views/admins/topics/_list_scientific_organization.html.erb @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + <% if topics.present? %> + <% topics.each_with_index do |topic, index| %> + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
序号标题跳转地址图片排序等级操作
<%= list_index_no((params[:page] || 1).to_i, index) %><%= topic.title %><%= topic.url %><%= topic.order_index %> + <%= link_to "编辑", edit_admins_topic_path(topic), remote: true, class: "action" %> + <%= link_to "删除", admins_topic_path(topic), method: :delete, data: { confirm: "确认删除的吗?" }, class: "action" %> +
+ +<%= render partial: 'admins/shared/paginate', locals: { objects: topics } %> \ No newline at end of file diff --git a/app/views/admins/topics/edit.js.erb b/app/views/admins/topics/edit.js.erb new file mode 100644 index 000000000..2ce36cf4e --- /dev/null +++ b/app/views/admins/topics/edit.js.erb @@ -0,0 +1,23 @@ +<%if @type.present? && @type !=Topic.type_simple_name(@type) && Topic.has_templates?(@type) %> +$("#activity-forum-modals").html("<%= j render(partial: "admins/topics/form_modal_#{Topic.type_simple_name(@type)}", locals: {type: 'update'}) %>") +<%else %> +$("#activity-forum-modals").html("<%= j render(partial: 'admins/topics/form_modal', locals: {type: 'update'}) %>") +<%end %> +$(".activity-forum-change-modal").modal('show'); + + +$('.logo-item-left').on("change", 'input[type="file"]', function () { + var $fileInput = $(this); + var file = this.files[0]; + var imageType = /image.*/; + if (file && file.type.match(imageType)) { + var reader = new FileReader(); + reader.onload = function () { + var $box = $fileInput.parent(); + $box.find('img').attr('src', reader.result).css('display', 'block'); + $box.addClass('has-img'); + }; + reader.readAsDataURL(file); + } else { + } +}); \ No newline at end of file diff --git a/app/views/admins/topics/index.html.erb b/app/views/admins/topics/index.html.erb new file mode 100644 index 000000000..cbcb2a8f8 --- /dev/null +++ b/app/views/admins/topics/index.html.erb @@ -0,0 +1,28 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb("#{Topic.type_filter_cn_name(@type)}") %> +<% end %> + +
+ <%= form_tag(admins_topics_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> + <%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %> + + + + <%# user_type_options = Topic.opt_select %> + <%#= select_tag(:type, options_for_select(user_type_options), class: 'form-control') %> + + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> + + <% end %> + <%= link_to "新增", new_admins_topic_path(type:@type), remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %> +
+ +
+ <%if @type.present? && @type !=Topic.type_simple_name(@type) && Topic.has_templates?(@type) %> + <%= render partial: "admins/topics/list_#{Topic.type_simple_name(@type)}", locals: { topics: @topics } %> + <%else %> + <%= render partial: 'admins/topics/list', locals: { topics: @topics } %> + <%end %> +
+
+
diff --git a/app/views/admins/topics/index.js.erb b/app/views/admins/topics/index.js.erb new file mode 100644 index 000000000..c4fb477e4 --- /dev/null +++ b/app/views/admins/topics/index.js.erb @@ -0,0 +1 @@ +$('.activity-forum-list-container').html("<%= j( render partial: 'admins/topics/list', locals: { topics: @topics } ) %>"); \ No newline at end of file diff --git a/app/views/admins/topics/new.js.erb b/app/views/admins/topics/new.js.erb new file mode 100644 index 000000000..a3052c9a1 --- /dev/null +++ b/app/views/admins/topics/new.js.erb @@ -0,0 +1,23 @@ +<%if @type.present? && @type !=Topic.type_simple_name(@type) && Topic.has_templates?(@type) %> +$("#activity-forum-modals").html("<%= j render(partial: "admins/topics/form_modal_#{Topic.type_simple_name(@type)}", locals: {type: 'create'}) %>") +<%else %> +$("#activity-forum-modals").html("<%= j render(partial: 'admins/topics/form_modal', locals: {type: 'create'}) %>") +<%end %> + +$(".activity-forum-change-modal").modal('show'); + +$('.logo-item-left').on("change", 'input[type="file"]', function () { + var $fileInput = $(this); + var file = this.files[0]; + var imageType = /image.*/; + if (file && file.type.match(imageType)) { + var reader = new FileReader(); + reader.onload = function () { + var $box = $fileInput.parent(); + $box.find('img').attr('src', reader.result).css('display', 'block'); + $box.addClass('has-img'); + }; + reader.readAsDataURL(file); + } else { + } +}); diff --git a/app/views/topics/_all.json.jbuilder b/app/views/topics/_all.json.jbuilder new file mode 100644 index 000000000..2323199fc --- /dev/null +++ b/app/views/topics/_all.json.jbuilder @@ -0,0 +1 @@ +json.(topic, :id, :type, :title, :uuid, :url, :description, :identifier, :image, :location, :labels, :date) diff --git a/app/views/topics/index.json.jbuilder b/app/views/topics/index.json.jbuilder index e6a374507..79fbc8b2a 100644 --- a/app/views/topics/index.json.jbuilder +++ b/app/views/topics/index.json.jbuilder @@ -34,7 +34,7 @@ json.topics do when 'Topic::ServiceTerm' json.partial! 'service_term', locals: {service_term: topic} else - json.nil! + json.partial! 'all', locals: {topic: topic} end end end @@ -72,7 +72,7 @@ json.topics do when 'Topic::ServiceTerm' json.partial! 'service_term', locals: {service_term: topic} else - json.nil! + json.partial! 'all', locals: {topic: topic} end end end diff --git a/config/routes.rb b/config/routes.rb index b4ae259e1..12daa1cfb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -868,6 +868,7 @@ Rails.application.routes.draw do get '/', to: 'dashboards#index' get '/baidu_tongji', to: 'dashboards#baidu_tongji' get '/baidu_tongji_auth', to: 'dashboards#baidu_tongji_auth' + resources :topics namespace :topic do resources :service_terms resources :technical_discussions From 02db67fdf54338b1ca6a5583776fb9348c0122cf Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 16 May 2025 17:34:40 +0800 Subject: [PATCH 23/42] =?UTF-8?q?fixed=20topic=20=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E6=97=A0=E9=99=90=E5=A2=9E=E5=8A=A0=E7=B1=BB=E5=9E=8B,?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/topics_controller.rb | 1 + .../admins/topics/_form_modal_ck_case.html.erb | 14 ++++++++++---- app/views/admins/topics/_list_ck_case.html.erb | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/admins/topics_controller.rb b/app/controllers/admins/topics_controller.rb index 6c41c2729..a59713264 100644 --- a/app/controllers/admins/topics_controller.rb +++ b/app/controllers/admins/topics_controller.rb @@ -20,6 +20,7 @@ class Admins::TopicsController < Admins::Topic::BaseController def create @topic = topic_model.new(topic_params) + @type = @topic.type if @topic.save save_image_file(params[:image], @topic) if params[:image].present? redirect_to admins_topics_path(type:@type) diff --git a/app/views/admins/topics/_form_modal_ck_case.html.erb b/app/views/admins/topics/_form_modal_ck_case.html.erb index 7d52a1fc5..a20248e64 100644 --- a/app/views/admins/topics/_form_modal_ck_case.html.erb +++ b/app/views/admins/topics/_form_modal_ck_case.html.erb @@ -9,6 +9,12 @@
<%= form_for @topic, url: { controller: "topics", action: "#{type}" }, html: { enctype: 'multipart/form-data' } do |p| %>