From de1266ba6c3e3f98ab2a6420128d62c490bea461 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 12 Dec 2023 16:41:02 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?id=E6=94=B9=E4=B8=BAuuid=EF=BC=8C=E5=85=B3=E8=81=94=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 4 ++-- app/controllers/journals_controller.rb | 2 +- app/controllers/version_releases_controller.rb | 2 +- app/models/attachment.rb | 1 + app/models/identity_verification.rb | 16 ++++++++-------- app/models/journal.rb | 6 +++--- app/services/api/v1/issues/concerns/checkable.rb | 4 ++-- app/services/api/v1/issues/concerns/loadable.rb | 2 +- ...0231212012107_change_identity_verification.rb | 8 ++++++++ 9 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20231212012107_change_identity_verification.rb diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index cb7beb402..84219b89b 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -139,7 +139,7 @@ class IssuesController < ApplicationController SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) if Site.has_notice_menu? if params[:attachment_ids].present? params[:attachment_ids].each do |id| - attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) + attachment = Attachment.where_id_or_uuid(id).select(:id, :container_id, :container_type)&.first unless attachment.blank? attachment.container = @issue attachment.author_id = current_user.id @@ -232,7 +232,7 @@ class IssuesController < ApplicationController if issue_files.present? change_files = true issue_files.each do |id| - attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) + attachment = Attachment.where_id_or_uuid(id).select(:id, :container_id, :container_type)&.first unless attachment.blank? attachment.container = @issue attachment.author_id = current_user.id diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 8f7857567..6b9abd5c6 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -35,7 +35,7 @@ class JournalsController < ApplicationController if journal.save if params[:attachment_ids].present? params[:attachment_ids].each do |id| - attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) + attachment = Attachment.where_id_or_uuid(id).select(:id, :container_id, :container_type)&.first unless attachment.blank? attachment.container = journal attachment.author_id = current_user.id diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 62724c12d..ed608873e 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -152,7 +152,7 @@ class VersionReleasesController < ApplicationController def create_attachments(attachment_ids, target) attachment_ids.each do |id| - attachment = Attachment.select(:id, :container_id, :container_type).where(id: id).or(Attachment.where(uuid: id))&.first + attachment = Attachment.where_id_or_uuid(id).select(:id, :container_id, :container_type)&.first unless attachment.blank? attachment.container = target attachment.author_id = current_user.id diff --git a/app/models/attachment.rb b/app/models/attachment.rb index defc73662..49124a220 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -69,6 +69,7 @@ class Attachment < ApplicationRecord scope :simple_columns, -> { select(:id, :filename, :filesize, :created_on, :cloud_url, :author_id, :content_type, :container_type, :container_id) } scope :search_by_container, -> (ids) {where(container_id: ids)} scope :unified_setting, -> {where("unified_setting = ? ", 1)} + scope :where_id_or_uuid, -> (id) { where("id = ? or uuid= ? ", id, id) } validates_length_of :description, maximum: 100, message: "不能超过100个字符" diff --git a/app/models/identity_verification.rb b/app/models/identity_verification.rb index 6ea6e0547..8673a4a6d 100644 --- a/app/models/identity_verification.rb +++ b/app/models/identity_verification.rb @@ -6,10 +6,10 @@ # user_id :integer not null # number :string(255) not null # name :string(255) not null -# card_front :integer -# card_back :integer -# hold_card_front :integer -# hold_card_back :integer +# card_front :string(255) +# card_back :string(255) +# hold_card_front :string(255) +# hold_card_back :string(255) # state :integer default("0") # description :string(255) # created_at :datetime not null @@ -34,18 +34,18 @@ class IdentityVerification < ApplicationRecord end def card_front_attachment - Attachment.find_by_id card_front + Attachment.where_id_or_uuid.first card_front end def card_back_attachment - Attachment.find_by_id card_back + Attachment.where_id_or_uuid.first card_back end def hold_card_front_attachment - Attachment.find_by_id hold_card_front + Attachment.where_id_or_uuid.first hold_card_front end def hold_card_back_attachment - Attachment.find_by_id hold_card_back + Attachment.where_id_or_uuid hold_card_back end end diff --git a/app/models/journal.rb b/app/models/journal.rb index dad60cd71..2e754c51a 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -88,9 +88,9 @@ class Journal < ApplicationRecord when 'issue' return "创建了疑修" when 'attachment' - old_value = Attachment.where(id: detail.old_value.split(",")).pluck(:filename).join("、") - new_value = Attachment.where(id: detail.value.split(",")).pluck(:filename).join("、") - if old_value.nil? || old_value.blank? + old_value = Attachment.where("id in (?) or uuid in (?)", detail.old_value.to_s.split(","), detail.old_value.to_s.split(",")).pluck(:filename).join("、") + new_value = Attachment.where("id in (?) or uuid in (?)", detail.value.to_s.split(","), detail.value.to_s.split(",")).pluck(:filename).join("、") + if old_value.nil? || old_value.blank? content += "添加了#{new_value}附件" else new_value = "无" if new_value.blank? diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index 58fc6dc6d..7d163ada6 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -31,8 +31,8 @@ module Api::V1::Issues::Concerns::Checkable def check_attachments (attachment_ids) raise ApplicationService::Error, "请输入正确的附件ID数组!" unless attachment_ids.is_a?(Array) attachment_ids.each do |aid| - raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) || Attachment.exists?(uuid: aid) - end + raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.where("id=? or uuid=?", aid, aid).exists? + end end def check_atme_receivers(receivers_login) diff --git a/app/services/api/v1/issues/concerns/loadable.rb b/app/services/api/v1/issues/concerns/loadable.rb index ffd5ff4a7..547ff50d7 100644 --- a/app/services/api/v1/issues/concerns/loadable.rb +++ b/app/services/api/v1/issues/concerns/loadable.rb @@ -9,7 +9,7 @@ module Api::V1::Issues::Concerns::Loadable end def load_attachments(attachment_ids) - @attachments = Attachment.where(id: attachment_ids).or(Attachment.where(uuid: attachment_ids)) + @attachments = Attachment.where("id in (?) or uuid in (?)", attachment_ids, attachment_ids) end def load_atme_receivers(receivers_login) diff --git a/db/migrate/20231212012107_change_identity_verification.rb b/db/migrate/20231212012107_change_identity_verification.rb new file mode 100644 index 000000000..6a6ac4085 --- /dev/null +++ b/db/migrate/20231212012107_change_identity_verification.rb @@ -0,0 +1,8 @@ +class ChangeIdentityVerification < ActiveRecord::Migration[5.2] + def change + change_column :identity_verifications, :card_front, :string + change_column :identity_verifications, :card_back, :string + change_column :identity_verifications, :hold_card_front, :string + change_column :identity_verifications, :hold_card_back, :string + end +end