删除博客为空的数据

This commit is contained in:
cxt 2016-04-08 15:59:23 +08:00
parent bd19913db8
commit fcddaf403c
6 changed files with 83 additions and 19 deletions

View File

@ -13,6 +13,7 @@ module Mobile
end end
post do post do
user = UserWechat.find_by_openid(params[:openid]).user user = UserWechat.find_by_openid(params[:openid]).user
=begin
shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
page = params[:page] ? params[:page] : 0 page = params[:page] ? params[:page] : 0
@ -27,6 +28,26 @@ module Mobile
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " +
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc') "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc')
=end
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
page = params[:page] ? params[:page] : 0
user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
principal_types = "JournalsForMessage"
watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(','))
user_ids = "(" + user.id.to_s + watched_user_ids + ")"
watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",")
blog_ids = "(" + watched_user_blog_ids + ")"
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " +
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc')
all_count = activities.count all_count = activities.count
activities = activities.limit(10).offset(page * 10) activities = activities.limit(10).offset(page * 10)
count = activities.count count = activities.count

View File

@ -23,7 +23,7 @@ module Mobile
homework_common = HomeworkCommon.find(params[:id]) homework_common = HomeworkCommon.find(params[:id])
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
if (feedback.errors.empty?) if (feedback.errors.empty?)
homework_common.update_attributes(:updated_at => Time.now) homework_common.update_column(:updated_at, Time.now)
result = 2 result = 2
end end
when "News" when "News"

View File

@ -30,7 +30,6 @@ module Mobile
ac.nil? || ac.act.nil? ? 0 : ac.act.journals.where("notes is not null and notes != ''").count ac.nil? || ac.act.nil? ? 0 : ac.act.journals.where("notes is not null and notes != ''").count
end end
when :subject when :subject
unless ac.act.nil?
if ac.act_type == "HomeworkCommon" if ac.act_type == "HomeworkCommon"
ac.act.name unless ac.nil? || ac.act.nil? ac.act.name unless ac.nil? || ac.act.nil?
elsif ac.act_type == "News" || ac.act_type == "BlogComment" elsif ac.act_type == "News" || ac.act_type == "BlogComment"
@ -40,7 +39,6 @@ module Mobile
elsif ac.act_type == "JournalsForMessage" elsif ac.act_type == "JournalsForMessage"
ac.act.private == 0 ? "留言" : "私信" unless ac.nil? || ac.act.nil? ac.act.private == 0 ? "留言" : "私信" unless ac.nil? || ac.act.nil?
end end
end
when :description when :description
if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News" if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News"
ac.act.description unless ac.nil? || ac.act.nil? ac.act.description unless ac.nil? || ac.act.nil?
@ -135,6 +133,7 @@ module Mobile
act_expose :course_project_name #课程/项目名字 act_expose :course_project_name #课程/项目名字
act_expose :activity_type_name #课程问答区/项目缺陷等 act_expose :activity_type_name #课程问答区/项目缺陷等
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
if instance.act_type == "HomeworkCommon" || instance.act_type == "News" || instance.act_type == "Message" || instance.act_type == "BlogComment" || instance.act_type == "JournalsForMessage" || instance.act_type == "Issue"
has_praise = false has_praise = false
current_user = options[:user] current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.act_id,instance.act_type.to_s,current_user.id) obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.act_id,instance.act_type.to_s,current_user.id)
@ -144,3 +143,4 @@ module Mobile
end end
end end
end end
end

View File

@ -0,0 +1,21 @@
class DeleteBlogUserActivity < ActiveRecord::Migration
def up
UserActivity.all.each do |activity|
if activity.act_type == 'BlogComment'
if activity.act
unless activity.act.parent_id.nil?
parent_act = UserActivity.where("act_id = #{activity.act.parent.id} and act_type='BlogComment'").first
parent_act.created_at = activity.act.parent.children.maximum("created_on")
parent_act.save
activity.destroy
end
else
activity.destroy
end
end
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160317090350) do ActiveRecord::Schema.define(:version => 20160408074854) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -405,6 +405,8 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
add_index "course_activities", ["course_id", "course_act_id", "course_act_type", "created_at"], :name => "course_act_index"
create_table "course_attachments", :force => true do |t| create_table "course_attachments", :force => true do |t|
t.string "filename" t.string "filename"
t.string "disk_filename" t.string "disk_filename"
@ -465,6 +467,9 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
t.integer "status" t.integer "status"
end end
add_index "course_messages", ["course_message_type"], :name => "index_course_messages_on_course_message_type"
add_index "course_messages", ["user_id", "course_id", "created_at"], :name => "index_course_messages_on_user_id_and_course_id_and_created_at"
create_table "course_statuses", :force => true do |t| create_table "course_statuses", :force => true do |t|
t.integer "changesets_count" t.integer "changesets_count"
t.integer "watchers_count" t.integer "watchers_count"
@ -728,6 +733,7 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
end end
add_index "forge_activities", ["forge_act_id"], :name => "index_forge_activities_on_forge_act_id" add_index "forge_activities", ["forge_act_id"], :name => "index_forge_activities_on_forge_act_id"
add_index "forge_activities", ["project_id", "forge_act_id", "created_at", "forge_act_type"], :name => "forge_act_index"
create_table "forge_messages", :force => true do |t| create_table "forge_messages", :force => true do |t|
t.integer "user_id" t.integer "user_id"
@ -741,6 +747,9 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
t.integer "status" t.integer "status"
end end
add_index "forge_messages", ["forge_message_id", "forge_message_type"], :name => "index_forge_messages_on_forge_message_id_and_forge_message_type"
add_index "forge_messages", ["user_id", "project_id", "created_at"], :name => "index_forge_messages_on_user_id_and_project_id_and_created_at"
create_table "forums", :force => true do |t| create_table "forums", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
t.text "description" t.text "description"
@ -1055,6 +1064,9 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
add_index "memo_messages", ["memo_id", "memo_type"], :name => "index_memo_messages_on_memo_id_and_memo_type"
add_index "memo_messages", ["user_id", "forum_id", "created_at"], :name => "index_memo_messages_on_user_id_and_forum_id_and_created_at"
create_table "memos", :force => true do |t| create_table "memos", :force => true do |t|
t.integer "forum_id", :null => false t.integer "forum_id", :null => false
t.integer "parent_id" t.integer "parent_id"
@ -1078,6 +1090,9 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
add_index "message_alls", ["message_type"], :name => "index_message_alls_on_message_type"
add_index "message_alls", ["user_id", "message_id", "created_at"], :name => "index_message_alls_on_user_id_and_message_id_and_created_at"
create_table "messages", :force => true do |t| create_table "messages", :force => true do |t|
t.integer "board_id", :null => false t.integer "board_id", :null => false
t.integer "parent_id" t.integer "parent_id"
@ -1274,6 +1289,7 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.string "field_type" t.string "field_type"
t.integer "hide", :default => 0 t.integer "hide", :default => 0
t.integer "status", :default => 1
end end
create_table "organizations", :force => true do |t| create_table "organizations", :force => true do |t|
@ -1286,6 +1302,7 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.boolean "allow_guest_download", :default => true t.boolean "allow_guest_download", :default => true
t.integer "visits", :default => 0 t.integer "visits", :default => 0
t.integer "show_mode", :default => 0
end end
create_table "phone_app_versions", :force => true do |t| create_table "phone_app_versions", :force => true do |t|
@ -1800,6 +1817,8 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
t.integer "user_id" t.integer "user_id"
end end
add_index "user_activities", ["act_id", "act_type", "container_id", "created_at"], :name => "user_act_index"
create_table "user_extensions", :force => true do |t| create_table "user_extensions", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.date "birthday" t.date "birthday"
@ -1830,6 +1849,9 @@ ActiveRecord::Schema.define(:version => 20160317090350) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
add_index "user_feedback_messages", ["journals_for_message_id"], :name => "index_user_feedback_messages_on_journals_for_message_id"
add_index "user_feedback_messages", ["user_id", "created_at"], :name => "index_user_feedback_messages_on_user_id_and_created_at"
create_table "user_grades", :force => true do |t| create_table "user_grades", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.integer "project_id", :null => false t.integer "project_id", :null => false

View File

@ -10,7 +10,7 @@ app.factory('auth', function($http,$routeParams, $cookies, $q){
var _openid = ''; var _openid = '';
if(debug===true){ if(debug===true){
_openid = "oCnvgv1erQGHzv5GlNZ3sxa2hnSo"; _openid = "6";
} }
var getOpenId = function() { var getOpenId = function() {
@ -68,7 +68,7 @@ app.controller('ActivityController',function($scope, $http, auth, rms, common){
console.log("ActivityController load"); console.log("ActivityController load");
$scope.activities = rms.get("activities") || []; $scope.activities = rms.get("activities") || [];
$scope.page = 1; $scope.page = 0;
var loadActData = function(page){ var loadActData = function(page){
$scope.page = page; $scope.page = page;