%% ---------------------------------------------------------------------------
%% @doc sql_guild.hrl

%% @author  hjh
%% @email  hejiahua@163.com
%% @since  2016-12-27
%% @deprecated 公会数据库
%% ---------------------------------------------------------------------------

%% ---------------------------
%% status_guild 所需
%% ---------------------------

-define(sql_guild_member_select_login, <<"select guild_id, position, create_time from guild_member where id = ~p">>).
-define(sql_guild_select_login, <<"select name,lv,flag,badges from guild where id = ~p">>).
-define(sql_guild_select_player_guild, <<"select leave_time, red_packet, red_gold_packet,`support_id`,`is_support_asker`, `guild_reputation` from player_guild where id = ~p">>).
-define(sql_guild_update_leave_time, <<"update player_guild set leave_time = ~p where id = ~p">>).
-define(sql_guild_update_red_packet, <<"update player_guild set red_packet = ~p, red_gold_packet = ~p where id = ~p">>).
-define(sql_guild_update_all_midnight, <<"update player_guild set red_packet = ~p, red_gold_packet = ~p">>).
-define(sql_insert_null_player_guild, <<"insert into player_guild(id) values(~p)">>).

%% ---------------------------
%% 公会记录所需sql
%% ---------------------------

-define(sql_guild_select_all, <<"
    select
        id,name,announce,chief_id,chief_name,agent,agent_time,lv,exp,division,funds,arrears,flag,create_time,
        modify_times,approve_type,auto_approve_lv,auto_approve_power,disband_warnning_time,
        week_labor,week_labor_refresh,week_labor_last,c_rename,c_rename_time,badges,party_num,assist,war_win,last_renew
    from guild">>).

-define(sql_guild_insert, <<"
    insert into
        guild(id,name,announce,chief_id,chief_name,agent,agent_time,lv,exp,division,funds,arrears,flag,create_time,
        modify_times,approve_type,auto_approve_lv,auto_approve_power,disband_warnning_time,
        week_labor,week_labor_refresh,week_labor_last,c_rename,c_rename_time,badges,party_num,assist,war_win,last_renew)
    values(~p, '~ts', '~ts', ~p, '~ts', ~p, ~p, ~p, ~p, ~p,~p, ~p, ~p, ~p, ~p, ~p,~p,~p,~p,~p, ~p, ~p,~p,~p,'~ts',~p,~p,~p,~p)">>).

-define(sql_guild_update_tenet, <<"update guild set tenet='~s' where id=~p">>).
-define(sql_guild_update_announce, <<"update guild set announce='~ts' where id=~p">>).
-define(sql_guild_update_approve, <<"update guild set approve_type=~p, auto_approve_lv=~p, auto_approve_power=~p where id=~p">>).
-define(sql_guild_update_chief, <<"update guild set chief_id=~p, chief_name='~ts',agent=~p,agent_time=~p where id=~p">>).
-define(sql_guild_update_funds, <<"update guild set funds=~p where id=~p">>).
-define(sql_guild_update_badges, <<"update guild set badges='~ts' where id=~p">>).
-define(sql_guild_update_party_num, <<"update guild set party_num=~p where id=~p">>).
-define(sql_guild_update_badge_need,<<"update guild set party_num=~p,assist=~p,war_win=~p,last_renew=~p where id=~p">>).
-define(sql_guild_update_create_time, <<"update guild set create_time=~p where id = ~p">>).
-define(sql_guild_update_agent, <<"update guild set agent=~p,agent_time=~p where id=~p">>).

-define(sql_guild_delete_by_guild_id, <<"delete from guild where id = ~p">>).
-define(sql_guild_update_lv_and_funds, <<"update guild set lv = ~p, funds = ~p where id = ~p">>).
-define(sql_guild_reset_announce_modify_times, <<"update guild set modify_times = 0">>).
-define(sql_guild_update_announce_modify_times, <<"update guild set modify_times = ~p where id = ~p">>).
-define(sql_guild_update_disband_warnning_time, <<"update guild set disband_warnning_time = ~p where id = ~p">>).

-define(sql_guild_update_funds_arrears, <<"update guild set funds = ~p,arrears=~p where id = ~p">>).

%%新加
-define(sql_guild_update_building_guild_lv, <<"update guild set lv = ~p, funds = ~p where id = ~p">>).
%% ---------------------------
%% 公会成员记录所需sql
%% ---------------------------

-define(sql_guild_member_select_by_guild_id, <<"
    select
        id, guild_name, position,precursor,week_labor, week_labor_refresh, labors, create_time
    from guild_member where guild_id = ~p">>).

-define(sql_guild_member_insert, <<"
    insert into
        guild_member(id, guild_id, guild_name, position,precursor, week_labor, week_labor_refresh, labors, create_time)
    values(~p, ~p, '~ts',~p,~p, ~p, ~p,~p,~p)">>).

-define(sql_guild_member_delete, <<"delete from guild_member where id = ~p">>).

-define(sql_guild_member_update_position, <<"update guild_member set position = ~p,precursor=~p where id = ~p">>).

-define(sql_guild_member_delete_by_guild_id, <<"delete from guild_member where guild_id = ~p">>).

-define(sql_guild_member_update_by_guild_id, <<"update guild_member set  guild_id = ~p,guild_name='~ts',precursor=0,position=5,labors=0 where guild_id=~p">>).


%% ---------------------------
%% 公会申请
%% ---------------------------

-define(sql_guild_apply_replace, <<"insert into guild_apply(role_id, guild_id, create_time,position) values(~p, ~p, ~p,~p)">>).
-define(sql_guild_apply_select, <<"select role_id, guild_id, create_time, position from guild_apply">>).

-define(sql_guild_merge_replace, <<"replace into guild_merge(guild_id,tapply,fapplys,notes) values (~p,~p,'~ts','~ts')">>).
-define(sql_guild_merge_select, <<"select guild_id,tapply,fapplys,notes from guild_merge">>).

-define(sql_guild_apply_delete, <<"delete from guild_apply where guild_id = ~p">>).
-define(sql_guild_apply_delete_by_guild_id, <<"delete from guild_apply where guild_id = ~p and position = ~p">>).
-define(sql_guild_apply_delete_by_role_id, <<"delete from guild_apply where role_id = ~p">>).
-define(sql_guild_apply_delete_by_key, <<"delete from guild_apply where role_id = ~p and guild_id = ~p">>).
-define(sql_guild_apply_delete_by_create_time, <<"delete from guild_apply where create_time <= ~p">>).

%% ---------------------------
%% 公会职位名字
%% ---------------------------
-define(sql_position_name_select, <<"select position, position_name from guild_position_name where guild_id = ~p">>).
-define(sql_position_name_select_by_position, <<"select position_name from guild_position_name where guild_id = ~p AND position = ~p">>).
-define(sql_position_name_delete, <<"delete from guild_position_name where guild_id = ~p">>).
-define(sql_position_name_delete_by_key, <<"delete from guild_position_name where guild_id = ~p and position = ~p">>).
-define(sql_position_name_replace, <<"replace into guild_position_name(guild_id, position, position_name) values(~p, ~p, '~ts')">>).

-define(sql_position_name_delete_by_guild_id, <<"delete from guild_position_name where guild_id = ~p">>).

%% ---------------------------
%% 公会职位权限
%% ---------------------------
-define(sql_position_permission_select, <<"select position, permission_type, is_allow from guild_position_permission where guild_id = ~p">>).
-define(sql_position_permission_delete, <<"delete from guild_position_permission where guild_id = ~p">>).
-define(sql_position_permission_replace, <<"
    replace into guild_position_permission(guild_id, position, permission_type, is_allow) values(~p, ~p, ~p, ~p)"
    >>).

-define(sql_position_permission_by_guild_id, <<"delete from guild_position_permission where guild_id = ~p">>).


%%--------------------------------------------------
%% 公会技能
%%--------------------------------------------------
-define(sql_player_guild_skill_select,
    <<"select skill_id, lv from player_guild_skill where role_id = ~p">>).
-define(sql_guild_skill_select,
    <<"select guild_id, skill_id, lv from guild_skill">>).
-define(sql_guild_skill_insert,
    <<"insert into guild_skill(guild_id, skill_id, lv) values(~p, ~p, ~p)">>).
-define(sql_update_guild_skill_lv,
    <<"update guild_skill set lv = ~p where guild_id = ~p and skill_id = ~p">>).
-define(sql_delete_guild_skill_by_guild_id,
    <<"delete from guild_skill where guild_id = ~p">>).
-define(sql_update_player_guild_skill_lv,
    <<"replace into player_guild_skill(role_id, skill_id, lv) values(~p, ~p, ~p)">>).


%% ----社团拼单
-define(sql_guild_order_select_all, <<"select id,cfgid,status,content,teams,finish_time from guild_order where rid = ~p">>).
-define(sql_guild_order_insert, <<"replace into guild_order(id,rid,cfgid,status,content,teams,finish_time)values(~p,~p, ~p, ~p,'~ts','~ts',~p)">>).
-define(sql_guild_del_order, <<"delete from guild_order where id = ~p">>).
-define(sql_guild_order_update, <<"update guild_order set status=~p, content='~ts',finish_time=~p where `id`=~p and `rid`=~p">>).

%% 协助
-define(sql_guild_support_insert, <<"replace into guild_support (support_sid, guild_id, support_cfgid, ask_id, support_list, scene, x, y, content, extra, status, create_time)
                                    values (~p, ~p, ~p, ~p, '~ts', ~p, ~p, ~p, '~ts', '~ts', ~p, ~p)">>).
-define(sql_guild_support_select, <<"select `support_sid`, `support_cfgid`, `ask_id`, `support_list`, `scene`, `x`, `y`, `content`, `extra`, `status`, `create_time` from guild_support where `guild_id` = ~p">>).
-define(sql_guild_support_delete, <<"delete from guild_support where `support_sid` = ~p">>).
-define(sql_guild_support_role_list_update, <<"update guild_support set `support_list` = '~ts' where `guild_id` = ~p and `support_sid` = ~p ">>).
-define(sql_guild_support_status_update, <<"update guild_support set `status` = ~p where `guild_id` = ~p and `support_sid` = ~p ">>).
-define(sql_guild_support_asker_scene_info, <<"update guild_support set `scene` = ~p, `x` = ~p, `y` = ~p where `guild_id` = ~p and `support_sid` = ~p ">>).
-define(sql_guild_update_support, <<"update player_guild set `support_id` = ~p, `is_support_asker` = ~p where id = ~p">>).
-define(sql_guild_update_guild_reputation, <<"update player_guild set `guild_reputation` = ~p where id = ~p">>).
-define(sql_guild_support_update_by_guild_id, <<"update guild_support set  guild_id = ~p where guild_id=~p">>).
-define(sql_guild_delete_supports, "delete from guild_support where `guild_id` = ~p").
