# encoding:utf-8
class GroupMessage < ActiveRecord::Base
  has_paper_trail
  has_and_belongs_to_many :depart_record

  self.table_name = "group_messages"

  def get_push_count

    if self.push_count.to_i >0
      # return self.push_count
    end

      if self.user_id.start_with?("sql=select * ")
        sql = "select count(*) as sqlcount "
        item = WxUser.find_by_sql(sql)
        if !item.blank?
          c = item[0].sqlcount
          if self.push_count == 0 
            self.push_count  = c
            self.save
          end
          return c
        end
      end

   end



  rails_admin do
    navigation_label '推送管理'
    weight -220

    list do
      items_per_page 10
      filters [:id, :name, :code]
      field :id
      # field :get_push_count
      field :code
      field :name
      field :depart_record
      field :count
      field :keyword1
      field :keyword2
      field :keyword3
      # field :status
      field :remark
      field :created_at
    end

    show do
      field :id
      # field :get_push_count
      field :code
      field :name
      field :depart_record
      field :keyword1
      field :keyword2
      field :keyword3
      # field :status
      field :remark
      field :created_at
      field :updated_at
    end

    edit do

      field :code
      field :name
      field :depart_record
      field :keyword1
      field :keyword2
      field :keyword3
      field :remark
    end
  end

end
