diff --git a/src/components/universities/form_fields.cr b/src/components/universities/form_fields.cr index b10fcb7..58b1933 100644 --- a/src/components/universities/form_fields.cr +++ b/src/components/universities/form_fields.cr @@ -100,7 +100,7 @@ class Universities::FormFields < BaseComponent br div class: "row" do - mount Shared::Field, op.description, "附加信息", &.textarea(rows: 10, cols: 50, style: "min-width: 600px; min-height: 300px;", placeholder: "随便输入点啥, 可以方便的在首页模糊搜索", replace_class: "materialize-textarea") + mount Shared::Field, op.university_remark, "学校附加信息", &.textarea(rows: 10, cols: 50, style: "min-width: 600px; min-height: 300px;", placeholder: "随便输入点啥, 可以方便的在首页模糊搜索", replace_class: "materialize-textarea") end br diff --git a/src/components/universities/main.cr b/src/components/universities/main.cr index b357b31..6a38db1 100644 --- a/src/components/universities/main.cr +++ b/src/components/universities/main.cr @@ -304,7 +304,7 @@ then set (next ).value to my.value2 end td university.batch_level.display_name td style: "max-width: 100px;", class: "double-line" do - text university.description.to_s + text university.remark(current_user) end mount( ClickEditTD, diff --git a/src/models/university.cr b/src/models/university.cr index e19b9ef..39d3509 100644 --- a/src/models/university.cr +++ b/src/models/university.cr @@ -77,4 +77,16 @@ class University < BaseModel has_many chong_wen_baos : ChongWenBao end + + def remark(user) + cwb = chong_wen_baos.find do |x| + x.user_id == user.id + end + + if cwb.nil? + "" + else + cwb.university_remark.to_s + end + end end diff --git a/src/operations/save_university.cr b/src/operations/save_university.cr index fb765ce..c787219 100644 --- a/src/operations/save_university.cr +++ b/src/operations/save_university.cr @@ -1,7 +1,7 @@ class SaveUniversity < University::SaveOperation upsert_lookup_columns code, batch_level - permit_columns name, description, code, + permit_columns name, code, is_211, is_985, is_good, batch_level, score_2023_min, ranking_2023_min, score_2022_min, ranking_2022_min, @@ -28,6 +28,8 @@ class SaveUniversity < University::SaveOperation attribute bao_2021 : Bool attribute bao_2020 : Bool + attribute university_remark : String + attribute current_user_id : Int64 before_save do @@ -70,26 +72,22 @@ class SaveUniversity < University::SaveOperation private def update_chong_wen_bao_options(saved_record : University) user_id = current_user_id.value.not_nil! - - ChongWenBaoQuery.new - .university_id(saved_record.id) - .user_id(user_id) - .first?.try do |chong_wen_bao| - SaveChongWenBao.update!( - chong_wen_bao, - chong_2023: chong_2023.value.not_nil!, - chong_2022: chong_2022.value.not_nil!, - chong_2021: chong_2021.value.not_nil!, - chong_2020: chong_2020.value.not_nil!, - wen_2023: wen_2023.value.not_nil!, - wen_2022: wen_2022.value.not_nil!, - wen_2021: wen_2021.value.not_nil!, - wen_2020: wen_2020.value.not_nil!, - bao_2023: bao_2023.value.not_nil!, - bao_2022: bao_2022.value.not_nil!, - bao_2021: bao_2021.value.not_nil!, - bao_2020: bao_2020.value.not_nil!, - ) - end + SaveChongWenBao.upsert!( + university_id: saved_record.id, + user_id: user_id, + university_remark: university_remark.value, + chong_2023: chong_2023.value.not_nil!, + chong_2022: chong_2022.value.not_nil!, + chong_2021: chong_2021.value.not_nil!, + chong_2020: chong_2020.value.not_nil!, + wen_2023: wen_2023.value.not_nil!, + wen_2022: wen_2022.value.not_nil!, + wen_2021: wen_2021.value.not_nil!, + wen_2020: wen_2020.value.not_nil!, + bao_2023: bao_2023.value.not_nil!, + bao_2022: bao_2022.value.not_nil!, + bao_2021: bao_2021.value.not_nil!, + bao_2020: bao_2020.value.not_nil!, + ) end end