作者 yangfu

业务表同步

-- == 表【belonging_regions】建视图语句 ==
-- drop view view_belonging_regions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_belonging_regions') THEN
-- 如果存在就删除视图
DROP VIEW view_belonging_regions;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_belonging_regions as select belonging_region_id as id,belonging_region_id,customer_rel_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,customer_id,area_code,operator_id from belonging_regions;
-- pk belonging_region_id
-- jsonb operator,areas
-- == 表【area_belongs】建视图语句 ==
-- drop view view_area_belongs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_belongs') THEN
-- 如果存在就删除视图
DROP VIEW view_area_belongs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_area_belongs as select area_belong_id as id,area_belong_id,begin_time,created_at,deleted_at,end_time,latest_update_time,updated_at,status,area_code,region_id,operator_id from area_belongs;
-- pk area_belong_id
-- jsonb
-- == 表【area_rel_expireds】建视图语句 ==
-- drop view view_area_rel_expireds;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_rel_expireds') THEN
-- 如果存在就删除视图
DROP VIEW view_area_rel_expireds;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_area_rel_expireds as select area_code as id,area_code,latest_update_time,created_at,area_rel_expired_id,remark,module,expired_at,latest_check_at,notice_times from area_rel_expireds;
-- pk
-- jsonb
-- == 表【area_categorys】建视图语句 ==
-- drop view view_area_categorys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_categorys') THEN
-- 如果存在就删除视图
DROP VIEW view_area_categorys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_area_categorys as select area_category_id as id,area_code,area_category_id,category_type,tag,begin_time,created_at,deleted_at,end_time,latest_update_time,updated_at,status,operator_id from area_categorys;
-- pk
-- jsonb
-- == 表【corresponding_period】建视图语句 ==
-- drop view view_corresponding_period;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_period') THEN
-- 如果存在就删除视图
DROP VIEW view_corresponding_period;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_corresponding_period as select saleman_id as id,saleman_id,saleman_name,saleman_phone,saleman_year,saleman_month,opportunity,normal from corresponding_period;
-- pk saleman_id
-- jsonb
-- == 表【change_logs】建视图语句 ==
-- drop view view_change_logs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_change_logs') THEN
-- 如果存在就删除视图
DROP VIEW view_change_logs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_change_logs as select change_log_id as id,change_log_id,valid_period_begin,valid_period_end,rel_id,module_id,module,created_at,updated_at,deleted_at,latest_update_time,operator_id from change_logs;
-- pk change_log_id
-- jsonb change_log_content,operator
-- == 表【channels】建视图语句 ==
-- drop view view_channels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_channels') THEN
-- 如果存在就删除视图
DROP VIEW view_channels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_channels as select channel_id as id,channel_id,channel_name,status,data_from,created_at,updated_at,deleted_at,latest_update_time from channels;
-- pk channel_id
-- jsonb operator
-- == 表【custom_relations】建视图语句 ==
-- drop view view_custom_relations;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relations') THEN
-- 如果存在就删除视图
DROP VIEW view_custom_relations;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_custom_relations as select id,relation_name,relation_main,relation_main_id,customer_id,product_id,channel_id,salesman_id,begin_time,end_time,area_code,regin_id,group_id,shared_value,shared_object,relation_object,operater_id,template_id,created_at,latest_update_time,deleted_at,status from custom_relations;
-- pk
-- jsonb areas
-- == 表【customer_rels】建视图语句 ==
-- drop view view_customer_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_customer_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customer_rels as select customer_rel_id as id,customer_rel_id,customer_id,customer_level,status,created_at,updated_at,deleted_at,latest_update_time,operator_id from customer_rels;
-- pk customer_rel_id
-- jsonb operator
-- == 表【customers】建视图语句 ==
-- drop view view_customers;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customers') THEN
-- 如果存在就删除视图
DROP VIEW view_customers;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customers as select customer_id as id,customer_id,customer_code,customer_name,data_from,status,company_id,created_at,updated_at,deleted_at,latest_update_time,operator_id from customers;
-- pk customer_id
-- jsonb operator
-- == 表【matched_relations】建视图语句 ==
-- drop view view_matched_relations;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_matched_relations') THEN
-- 如果存在就删除视图
DROP VIEW view_matched_relations;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_matched_relations as select matched_relation_id as id,matched_relation_id,matched_module_code,created_at,deleted_at,updated_at from matched_relations;
-- pk matched_relation_id
-- jsonb matched_fields,operator
-- == 表【notice_messages】建视图语句 ==
-- drop view view_notice_messages;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_notice_messages') THEN
-- 如果存在就删除视图
DROP VIEW view_notice_messages;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_notice_messages as select notice_message_id as id,notice_message_id,notice_message_title,notice_message_content,notice_message_module_id,notice_message_module,notice_message_sub_module_id,notice_message_sub_module,notice_message_type,status,created_at,updated_at,deleted_at,latest_update_time,operator_id from notice_messages;
-- pk notice_message_id
-- jsonb operator
-- == 表【product_belongs】建视图语句 ==
-- drop view view_product_belongs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_belongs') THEN
-- 如果存在就删除视图
DROP VIEW view_product_belongs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_belongs as select product_belong_id as id,product_belong_id,begin_time,end_time,product_id,status,parent_product_id,operator_id,created_at,deleted_at,latest_update_time,updated_at from product_belongs;
-- pk product_belong_id
-- jsonb
-- == 表【product_categorys】建视图语句 ==
-- drop view view_product_categorys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_categorys') THEN
-- 如果存在就删除视图
DROP VIEW view_product_categorys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_categorys as select product_category_id as id,product_category_id,begin_time,end_time,product_id,status,category_type,tag,operator_id,created_at,deleted_at,updated_at,latest_update_time from product_categorys;
-- pk product_category_id
-- jsonb
-- == 表【corresponding_profit】建视图语句 ==
-- drop view view_corresponding_profit;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_profit') THEN
-- 如果存在就删除视图
DROP VIEW view_corresponding_profit;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_corresponding_profit as select saleman_id as id,saleman_id,saleman_name,saleman_phone,saleman_year,saleman_month,opportunity,normal from corresponding_profit;
-- pk saleman_id
-- jsonb
-- == 表【custom_relation_templates】建视图语句 ==
-- drop view view_custom_relation_templates;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_templates') THEN
-- 如果存在就删除视图
DROP VIEW view_custom_relation_templates;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_custom_relation_templates as select id,relation_main,relation_name,relation_type,is_require,created_at,latest_update_time,deleted_at from custom_relation_templates;
-- pk
-- jsonb relation_target,share_target
-- == 表【custom_relation_historys】建视图语句 ==
-- drop view view_custom_relation_historys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_historys') THEN
-- 如果存在就删除视图
DROP VIEW view_custom_relation_historys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_custom_relation_historys as select id,created_at,custom_relation_id,group_id,template_id,updated_at,relation_main,relation_main_id from custom_relation_historys;
-- pk
-- jsonb body_data,head_field
-- == 表【product_rel_expireds】建视图语句 ==
-- drop view view_product_rel_expireds;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rel_expireds') THEN
-- 如果存在就删除视图
DROP VIEW view_product_rel_expireds;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_rel_expireds as select product_id as id,product_id,latest_update_time,created_at,product_rel_expired_id,remark,module,expired_at,latest_check_at,notice_times from product_rel_expireds;
-- pk product_id
-- jsonb
-- == 表【product_rels】建视图语句 ==
-- drop view view_product_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_product_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_rels as select product_rel_id as id,product_rel_id,product_id,product_level,operator_id,created_at,deleted_at,updated_at,latest_update_time from product_rels;
-- pk product_rel_id
-- jsonb
-- == 表【product_shares】建视图语句 ==
-- drop view view_product_shares;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_shares') THEN
-- 如果存在就删除视图
DROP VIEW view_product_shares;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_shares as select product_share_id as id,product_share_id,customer_rel_id,shared_product_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,customer_id,salesman_type,salesman_id,salesman_share,operator_id,extra_attribute,group_id from product_shares;
-- pk product_share_id
-- jsonb operator
-- == 表【project_costs】建视图语句 ==
-- drop view view_project_costs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_project_costs') THEN
-- 如果存在就删除视图
DROP VIEW view_project_costs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_project_costs as select project_cost_id as id,project_cost_id,data_from,created_at,deleted_at,updated_at,product_id,happen_time,money,subject,region_id,salesman_id,customer_id,operator_id,latest_update_time from project_costs;
-- pk project_cost_id
-- jsonb operator
-- == 表【region_categorys】建视图语句 ==
-- drop view view_region_categorys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_categorys') THEN
-- 如果存在就删除视图
DROP VIEW view_region_categorys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_categorys as select region_category_id as id,region_category_id,begin_time,end_time,status,category_type,tag,operator_id,created_at,deleted_at,latest_update_time,updated_at,region_id from region_categorys;
-- pk region_category_id
-- jsonb
-- == 表【sales_details】建视图语句 ==
-- drop view view_sales_details;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_details') THEN
-- 如果存在就删除视图
DROP VIEW view_sales_details;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_sales_details as select sales_detail_id as id,sales_detail_id,data_from,original_order_number,sale_date,salesman_id,region_id,superior_region_id,sales_method_id,customer_id,product_id,price,amount,is_returned,operator_id,company_id,created_at,updated_at,deleted_at,latest_update_time,address from sales_details;
-- pk sales_detail_id
-- jsonb
-- == 表【sales_methods】建视图语句 ==
-- drop view view_sales_methods;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_methods') THEN
-- 如果存在就删除视图
DROP VIEW view_sales_methods;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_sales_methods as select sales_method_id as id,created_at,data_from,sales_method_id,updated_at,method_name,operator_id,latest_update_time from sales_methods;
-- pk
-- jsonb operator
-- == 表【salesman_rels】建视图语句 ==
-- drop view view_salesman_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesman_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_salesman_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_salesman_rels as select salesman_rel_id as id,salesman_rel_id,salesman_level,status,created_at,updated_at,deleted_at,latest_update_time,salesman_id,operator_id from salesman_rels;
-- pk salesman_rel_id
-- jsonb operator
-- == 表【solutions】建视图语句 ==
-- drop view view_solutions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solutions') THEN
-- 如果存在就删除视图
DROP VIEW view_solutions;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_solutions as select solution_id as id,solution_id,database_name,schema_name,solution_group_id,solution_name,latest_update_time,status,created_at,updated_at,deleted_at,compute_business_name,compute_business_id,operator_id,begin_time,end_time from solutions;
-- pk solution_id
-- jsonb operator,compute_items,salesmen
-- == 表【salesmans】建视图语句 ==
-- drop view view_salesmans;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesmans') THEN
-- 如果存在就删除视图
DROP VIEW view_salesmans;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_salesmans as select salesman_id as id,salesman_id,salesman_code,salesman_name,data_from,status,phone,company_id,created_at,updated_at,deleted_at,latest_update_time,operator_id,disabled_at from salesmans;
-- pk salesman_id
-- jsonb operator
-- == 表【superior_customers】建视图语句 ==
-- drop view view_superior_customers;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_customers') THEN
-- 如果存在就删除视图
DROP VIEW view_superior_customers;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_superior_customers as select superior_customer_id as id,superior_customer_id,customer_rel_id,customer_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,superior_customer_uid,operator_id from superior_customers;
-- pk superior_customer_id
-- jsonb operator
-- == 表【superior_responsible_persons】建视图语句 ==
-- drop view view_superior_responsible_persons;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_responsible_persons') THEN
-- 如果存在就删除视图
DROP VIEW view_superior_responsible_persons;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_superior_responsible_persons as select superior_responsible_person_id as id,superior_responsible_person_id,salesman_rel_id,salesman_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,superior_salesman_id,operator_id from superior_responsible_persons;
-- pk superior_responsible_person_id
-- jsonb operator
-- == 表【type_tags】建视图语句 ==
-- drop view view_type_tags;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_type_tags') THEN
-- 如果存在就删除视图
DROP VIEW view_type_tags;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_type_tags as select type_tag_id as id,type_tag_id,rel_id,type_tag_module,type_tag_name,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,type_tag_code,operator_id from type_tags;
-- pk type_tag_id
-- jsonb operator
-- == 表【region_salesmans】建视图语句 ==
-- drop view view_region_salesmans;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_salesmans') THEN
-- 如果存在就删除视图
DROP VIEW view_region_salesmans;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_salesmans as select region_salesman_id as id,region_salesman_id,region_id,salesman_id,begin_time,created_at,deleted_at,end_time,latest_update_time,updated_at,status,operator_id from region_salesmans;
-- pk region_salesman_id
-- jsonb
-- == 表【region_rels】建视图语句 ==
-- drop view view_region_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_region_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_rels as select region_rel_id as id,region_rel_id,region_id,region_level,operator_id,created_at,deleted_at,updated_at,latest_update_time from region_rels;
-- pk region_rel_id
-- jsonb
-- == 表【regions】建视图语句 ==
-- drop view view_regions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regions') THEN
-- 如果存在就删除视图
DROP VIEW view_regions;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_regions as select region_id as id,region_id,region_code,region_name,data_from,status,company_id,created_at,updated_at,deleted_at,latest_update_time,disabled_at from regions;
-- pk region_id
-- jsonb operator
-- == 表【areas】建视图语句 ==
-- drop view view_areas;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_areas') THEN
-- 如果存在就删除视图
DROP VIEW view_areas;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_areas as select area_code,city_code,parent_code,level,merger_name,name,short_name,zip_code,full_name,id,pinyin,lng,lat,full_area_code from areas;
-- pk
-- jsonb
-- == 表【customer_rewards】建视图语句 ==
-- drop view view_customer_rewards;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rewards') THEN
-- 如果存在就删除视图
DROP VIEW view_customer_rewards;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customer_rewards as select customer_reward_id as id,customer_reward_id,data_from,reward_ratio,status,customer_id,salesman_id,created_at,updated_at,disabled_at,operator_id,latest_update_time from customer_rewards;
-- pk customer_reward_id
-- jsonb operator
-- == 表【chart_style_configs】建视图语句 ==
-- drop view view_chart_style_configs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_chart_style_configs') THEN
-- 如果存在就删除视图
DROP VIEW view_chart_style_configs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_chart_style_configs as select id,conf,module,created_at,updated_at,data_conf from chart_style_configs;
-- pk
-- jsonb
-- == 表【performances】建视图语句 ==
-- drop view view_performances;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_performances') THEN
-- 如果存在就删除视图
DROP VIEW view_performances;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_performances as select performance_id as id,performance_id,performance_value,performance_type,data_from,salesman_id,region_id,year,month,operator_id,created_at,updated_at,deleted_at,latest_update_time from performances;
-- pk performance_id
-- jsonb
-- == 表【products】建视图语句 ==
-- drop view view_products;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_products') THEN
-- 如果存在就删除视图
DROP VIEW view_products;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_products as select product_id as id,product_id,created_at,data_from,updated_at,product_code,product_name,standard,status,operator_id,latest_update_time,disabled_at from products;
-- pk product_id
-- jsonb operator
-- == 表【profits】建视图语句 ==
-- drop view view_profits;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_profits') THEN
-- 如果存在就删除视图
DROP VIEW view_profits;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_profits as select profit_id as id,profit_id,profit_type,profit_value,data_from,salesman_id,region_id,operator_id,year,month,created_at,updated_at,deleted_at,latest_update_time from profits;
-- pk profit_id
-- jsonb
-- == 表【region_belongs】建视图语句 ==
-- drop view view_region_belongs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_belongs') THEN
-- 如果存在就删除视图
DROP VIEW view_region_belongs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_belongs as select region_belong_id as id,region_belong_id,begin_time,end_time,status,parent_region_id,region_id,operator_id,created_at,deleted_at,updated_at,latest_update_time from region_belongs;
-- pk region_belong_id
-- jsonb
-- == 表【region_rel_expireds】建视图语句 ==
-- drop view view_region_rel_expireds;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rel_expireds') THEN
-- 如果存在就删除视图
DROP VIEW view_region_rel_expireds;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_rel_expireds as select region_id as id,region_id,latest_update_time,created_at,region_rel_expired_id,remark,module,expired_at,latest_check_at,notice_times from region_rel_expireds;
-- pk region_id
-- jsonb
-- == 表【responsible_salesmans】建视图语句 ==
-- drop view view_responsible_salesmans;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_responsible_salesmans') THEN
-- 如果存在就删除视图
DROP VIEW view_responsible_salesmans;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_responsible_salesmans as select responsible_salesman_id as id,responsible_salesman_id,customer_rel_id,salesman_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,customer_id,operator_id from responsible_salesmans;
-- pk responsible_salesman_id
-- jsonb operator
-- == 表【solution_groups】建视图语句 ==
-- drop view view_solution_groups;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solution_groups') THEN
-- 如果存在就删除视图
DROP VIEW view_solution_groups;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_solution_groups as select solution_group_id as id,solution_group_id,solution_group_name,created_at,updated_at,deleted_at,operator_id from solution_groups;
-- pk solution_group_id
-- jsonb operator
-- == 表【users】建视图语句 ==
-- drop view view_users;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_users') THEN
-- 如果存在就删除视图
DROP VIEW view_users;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_users as select user_id as id,user_id,user_name,user_account,password,user_avatar,company_id,status,created_at,updated_at,deleted_at from users;
-- pk user_id
-- jsonb
-- == 表【product_costs】建视图语句 ==
-- drop view view_product_costs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_costs') THEN
-- 如果存在就删除视图
DROP VIEW view_product_costs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_costs as select product_cost_id as id,product_cost_id,created_at,deleted_at,data_from,updated_at,product_id,begin_time,cost,end_time,operator_id,latest_update_time from product_costs;
-- pk product_cost_id
-- jsonb operator
-- == 表【editor_chart_confs】建视图语句 ==
-- drop view view_editor_chart_confs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_chart_confs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_chart_confs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_chart_confs as select id,name,module_id,chart_conf,chart_data_conf,is_checked,is_default,created_at,updated_at,deleted_at from editor_chart_confs;
-- pk
-- jsonb
-- == 表【editor_user_chart_conf】建视图语句 ==
-- drop view view_editor_user_chart_conf;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_chart_conf') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_user_chart_conf;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_user_chart_conf as select editor_user_chart_conf_id as id,editor_user_chart_conf_id,phone,report_id,module_id,module_permissions,chart_id,chart_checked,sort_by,created_at,updated_at,deleted_at,module_checked from editor_user_chart_conf;
-- pk editor_user_chart_conf_id
-- jsonb
-- == 表【editor_user_conf_logs】建视图语句 ==
-- drop view view_editor_user_conf_logs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_conf_logs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_user_conf_logs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_user_conf_logs as select id,user_id,user_name,report_id,report_name,module_name,created_at from editor_user_conf_logs;
-- pk
-- jsonb
-- == 表【editor_module_confs】建视图语句 ==
-- drop view view_editor_module_confs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_module_confs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_module_confs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_module_confs as select id,name,report_id,is_checked,uri,created_at,updated_at from editor_module_confs;
-- pk
-- jsonb
-- == 表【editor_report_confs】建视图语句 ==
-- drop view view_editor_report_confs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_report_confs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_report_confs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_report_confs as select id,name,platform_id,created_at,updated_at,permission_flag from editor_report_confs;
-- pk
-- jsonb
-- == 表【operate_rules】建视图语句 ==
-- drop view view_operate_rules;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_operate_rules') THEN
-- 如果存在就删除视图
DROP VIEW view_operate_rules;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_operate_rules as select operate_rule_id as id,operate_rule_id,customer_code,product_code,area_code,allocation_proportion,primary_area_name,secondary_area_name,performance_type,opportunity_territory,start_time,end_time,operator_id,created_at,updated_at,deleted_at from operate_rules;
-- pk operate_rule_id
-- jsonb
-- == 表【share_customer_expenses】建视图语句 ==
-- drop view view_share_customer_expenses;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_share_customer_expenses') THEN
-- 如果存在就删除视图
DROP VIEW view_share_customer_expenses;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_share_customer_expenses as select share_customer_expenses_id as id,share_customer_expenses_id,customer_code,primary_area_name,secondary_area_name,expense_type,start_time,end_time,operator_id,created_at,updated_at,deleted_at from share_customer_expenses;
-- pk share_customer_expenses_id
-- jsonb
-- == 表【customer_comparisons】建视图语句 ==
-- drop view view_customer_comparisons;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_comparisons') THEN
-- 如果存在就删除视图
DROP VIEW view_customer_comparisons;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customer_comparisons as select customer_comparison_id as id,customer_comparison_id,customer_code,summary_area,primary_area_name,secondary_area_name,self_support_or_opportunity,rebate,start_time,end_time,operator_id,created_at,updated_at,deleted_at from customer_comparisons;
-- pk customer_comparison_id
-- jsonb
-- == 表【employee_relations】建视图语句 ==
-- drop view view_employee_relations;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_employee_relations') THEN
-- 如果存在就删除视图
DROP VIEW view_employee_relations;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_employee_relations as select employee_relations_id as id,employee_relations_id,start_time,end_time,expense_area,expense_operator_code,primary_area_name,secondary_area_name,salesman_name,distribution_proportion,operator_id,created_at,updated_at,deleted_at from employee_relations;
-- pk employee_relations_id
-- jsonb
-- == 表【regular_employee】建视图语句 ==
-- drop view view_regular_employee;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regular_employee') THEN
-- 如果存在就删除视图
DROP VIEW view_regular_employee;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_regular_employee as select regular_employee_id as id,regular_employee_id,salesman_code,salesman_name,confirmation_date,operator_id,created_at,updated_at,deleted_at from regular_employee;
-- pk regular_employee_id
-- jsonb
-- == 表【regional_ownerships】建视图语句 ==
-- drop view view_regional_ownerships;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regional_ownerships') THEN
-- 如果存在就删除视图
DROP VIEW view_regional_ownerships;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_regional_ownerships as select regional_ownerships_id as id,regional_ownerships_id,start_time,end_time,area,secondary_area_name,salesman_code,salesman_name,is_incremental_commission,is_profit_increase_commission,operator_id,created_at,updated_at,deleted_at,latest_update_time from regional_ownerships;
-- pk regional_ownerships_id
-- jsonb
-- == 表【offline_expenses】建视图语句 ==
-- drop view view_offline_expenses;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_offline_expenses') THEN
-- 如果存在就删除视图
DROP VIEW view_offline_expenses;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_offline_expenses as select project_cost_id as id,project_cost_id,data_from,created_at,deleted_at,updated_at,product_id,happen_time,money,subject,region_id,salesman_id,customer_id,operator_id,latest_update_time,department from offline_expenses;
-- pk project_cost_id
-- jsonb operator
... ...
-- == 表【area_rel_expireds】建视图语句 ==
-- drop view view_area_rel_expireds;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_rel_expireds') THEN
-- 如果存在就删除视图
DROP VIEW view_area_rel_expireds;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_area_rel_expireds as select area_code,latest_update_time,created_at,area_rel_expired_id,remark,module,expired_at,latest_check_at,notice_times from area_rel_expireds;
-- pk
-- jsonb
-- == 表【belonging_regions】建视图语句 ==
-- drop view view_belonging_regions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_belonging_regions') THEN
-- 如果存在就删除视图
DROP VIEW view_belonging_regions;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_belonging_regions as select belonging_region_id as id,belonging_region_id,customer_rel_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,customer_id,area_code,operator_id from belonging_regions;
-- pk belonging_region_id
-- jsonb operator,areas
-- == 表【area_belongs】建视图语句 ==
-- drop view view_area_belongs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_belongs') THEN
-- 如果存在就删除视图
DROP VIEW view_area_belongs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_area_belongs as select area_belong_id as id,area_belong_id,begin_time,created_at,deleted_at,end_time,latest_update_time,updated_at,status,area_code,region_id,operator_id from area_belongs;
-- pk area_belong_id
-- jsonb
-- == 表【area_categorys】建视图语句 ==
-- drop view view_area_categorys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_categorys') THEN
-- 如果存在就删除视图
DROP VIEW view_area_categorys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_area_categorys as select area_code,area_category_id,category_type,tag,begin_time,created_at,deleted_at,end_time,latest_update_time,updated_at,status,operator_id from area_categorys;
-- pk
-- jsonb
-- == 表【channels】建视图语句 ==
-- drop view view_channels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_channels') THEN
-- 如果存在就删除视图
DROP VIEW view_channels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_channels as select channel_id as id,channel_id,channel_name,status,data_from,created_at,updated_at,deleted_at,latest_update_time from channels;
-- pk channel_id
-- jsonb operator
-- == 表【chart_style_configs】建视图语句 ==
-- drop view view_chart_style_configs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_chart_style_configs') THEN
-- 如果存在就删除视图
DROP VIEW view_chart_style_configs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_chart_style_configs as select id,conf,module,created_at,updated_at,data_conf from chart_style_configs;
-- pk
-- jsonb
-- == 表【corresponding_period】建视图语句 ==
-- drop view view_corresponding_period;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_period') THEN
-- 如果存在就删除视图
DROP VIEW view_corresponding_period;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_corresponding_period as select saleman_id as id,saleman_id,saleman_name,saleman_phone,saleman_year,saleman_month,opportunity,normal from corresponding_period;
-- pk saleman_id
-- jsonb
-- == 表【change_logs】建视图语句 ==
-- drop view view_change_logs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_change_logs') THEN
-- 如果存在就删除视图
DROP VIEW view_change_logs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_change_logs as select change_log_id as id,change_log_id,valid_period_begin,valid_period_end,rel_id,module_id,module,created_at,updated_at,deleted_at,latest_update_time,operator_id from change_logs;
-- pk change_log_id
-- jsonb change_log_content,operator
-- == 表【custom_relation_templates】建视图语句 ==
-- drop view view_custom_relation_templates;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_templates') THEN
-- 如果存在就删除视图
DROP VIEW view_custom_relation_templates;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_custom_relation_templates as select id,relation_main,relation_name,relation_type,is_require,created_at,latest_update_time,deleted_at from custom_relation_templates;
-- pk
-- jsonb relation_target,share_target
-- == 表【custom_relations】建视图语句 ==
-- drop view view_custom_relations;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relations') THEN
-- 如果存在就删除视图
DROP VIEW view_custom_relations;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_custom_relations as select id,relation_name,relation_main,relation_main_id,customer_id,product_id,channel_id,salesman_id,begin_time,end_time,area_code,regin_id,group_id,shared_value,shared_object,relation_object,operater_id,template_id,created_at,latest_update_time,deleted_at,status from custom_relations;
-- pk
-- jsonb areas
-- == 表【customer_rels】建视图语句 ==
-- drop view view_customer_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_customer_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customer_rels as select customer_rel_id as id,customer_rel_id,customer_id,customer_level,status,created_at,updated_at,deleted_at,latest_update_time,operator_id from customer_rels;
-- pk customer_rel_id
-- jsonb operator
-- == 表【customer_rewards】建视图语句 ==
-- drop view view_customer_rewards;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rewards') THEN
-- 如果存在就删除视图
DROP VIEW view_customer_rewards;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customer_rewards as select customer_reward_id as id,customer_reward_id,data_from,reward_ratio,status,customer_id,salesman_id,created_at,updated_at,disabled_at,operator_id,latest_update_time from customer_rewards;
-- pk customer_reward_id
-- jsonb operator
-- == 表【customers】建视图语句 ==
-- drop view view_customers;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customers') THEN
-- 如果存在就删除视图
DROP VIEW view_customers;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customers as select customer_id as id,customer_id,customer_code,customer_name,data_from,status,company_id,created_at,updated_at,deleted_at,latest_update_time,operator_id from customers;
-- pk customer_id
-- jsonb operator
-- == 表【matched_relations】建视图语句 ==
-- drop view view_matched_relations;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_matched_relations') THEN
-- 如果存在就删除视图
DROP VIEW view_matched_relations;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_matched_relations as select matched_relation_id as id,matched_relation_id,matched_module_code,created_at,deleted_at,updated_at from matched_relations;
-- pk matched_relation_id
-- jsonb matched_fields,operator
-- == 表【notice_messages】建视图语句 ==
-- drop view view_notice_messages;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_notice_messages') THEN
-- 如果存在就删除视图
DROP VIEW view_notice_messages;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_notice_messages as select notice_message_id as id,notice_message_id,notice_message_title,notice_message_content,notice_message_module_id,notice_message_module,notice_message_sub_module_id,notice_message_sub_module,notice_message_type,status,created_at,updated_at,deleted_at,latest_update_time,operator_id from notice_messages;
-- pk notice_message_id
-- jsonb operator
-- == 表【performances】建视图语句 ==
-- drop view view_performances;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_performances') THEN
-- 如果存在就删除视图
DROP VIEW view_performances;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_performances as select performance_id as id,performance_id,performance_value,performance_type,data_from,salesman_id,region_id,year,month,operator_id,created_at,updated_at,deleted_at,latest_update_time from performances;
-- pk performance_id
-- jsonb
-- == 表【product_belongs】建视图语句 ==
-- drop view view_product_belongs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_belongs') THEN
-- 如果存在就删除视图
DROP VIEW view_product_belongs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_belongs as select product_belong_id as id,product_belong_id,begin_time,end_time,product_id,status,parent_product_id,operator_id,created_at,deleted_at,latest_update_time,updated_at from product_belongs;
-- pk product_belong_id
-- jsonb
-- == 表【corresponding_profit】建视图语句 ==
-- drop view view_corresponding_profit;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_profit') THEN
-- 如果存在就删除视图
DROP VIEW view_corresponding_profit;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_corresponding_profit as select saleman_id as id,saleman_id,saleman_name,saleman_phone,saleman_year,saleman_month,opportunity,normal from corresponding_profit;
-- pk saleman_id
-- jsonb
-- == 表【custom_relation_historys】建视图语句 ==
-- drop view view_custom_relation_historys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_historys') THEN
-- 如果存在就删除视图
DROP VIEW view_custom_relation_historys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_custom_relation_historys as select id,created_at,custom_relation_id,group_id,template_id,updated_at,relation_main,relation_main_id from custom_relation_historys;
-- pk
-- jsonb body_data,head_field
-- == 表【product_rel_expireds】建视图语句 ==
-- drop view view_product_rel_expireds;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rel_expireds') THEN
-- 如果存在就删除视图
DROP VIEW view_product_rel_expireds;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_rel_expireds as select product_id as id,product_id,latest_update_time,created_at,product_rel_expired_id,remark,module,expired_at,latest_check_at,notice_times from product_rel_expireds;
-- pk product_id
-- jsonb
-- == 表【product_rels】建视图语句 ==
-- drop view view_product_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_product_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_rels as select product_rel_id as id,product_rel_id,product_id,product_level,operator_id,created_at,deleted_at,updated_at,latest_update_time from product_rels;
-- pk product_rel_id
-- jsonb
-- == 表【product_categorys】建视图语句 ==
-- drop view view_product_categorys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_categorys') THEN
-- 如果存在就删除视图
DROP VIEW view_product_categorys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_categorys as select product_category_id as id,product_category_id,begin_time,end_time,product_id,status,category_type,tag,operator_id,created_at,deleted_at,updated_at,latest_update_time from product_categorys;
-- pk product_category_id
-- jsonb
-- == 表【product_costs】建视图语句 ==
-- drop view view_product_costs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_costs') THEN
-- 如果存在就删除视图
DROP VIEW view_product_costs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_costs as select product_cost_id as id,product_cost_id,created_at,deleted_at,data_from,updated_at,product_id,begin_time,cost,end_time,operator_id,latest_update_time from product_costs;
-- pk product_cost_id
-- jsonb operator
-- == 表【profits】建视图语句 ==
-- drop view view_profits;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_profits') THEN
-- 如果存在就删除视图
DROP VIEW view_profits;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_profits as select profit_id as id,profit_id,profit_type,profit_value,data_from,salesman_id,region_id,operator_id,year,month,created_at,updated_at,deleted_at,latest_update_time from profits;
-- pk profit_id
-- jsonb
-- == 表【products】建视图语句 ==
-- drop view view_products;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_products') THEN
-- 如果存在就删除视图
DROP VIEW view_products;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_products as select product_id as id,product_id,created_at,data_from,updated_at,product_code,product_name,standard,status,operator_id,latest_update_time,disabled_at from products;
-- pk product_id
-- jsonb operator
-- == 表【region_rel_expireds】建视图语句 ==
-- drop view view_region_rel_expireds;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rel_expireds') THEN
-- 如果存在就删除视图
DROP VIEW view_region_rel_expireds;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_rel_expireds as select region_id as id,region_id,latest_update_time,created_at,region_rel_expired_id,remark,module,expired_at,latest_check_at,notice_times from region_rel_expireds;
-- pk region_id
-- jsonb
-- == 表【region_rels】建视图语句 ==
-- drop view view_region_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_region_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_rels as select region_rel_id as id,region_rel_id,region_id,region_level,operator_id,created_at,deleted_at,updated_at,latest_update_time from region_rels;
-- pk region_rel_id
-- jsonb
-- == 表【responsible_salesmans】建视图语句 ==
-- drop view view_responsible_salesmans;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_responsible_salesmans') THEN
-- 如果存在就删除视图
DROP VIEW view_responsible_salesmans;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_responsible_salesmans as select responsible_salesman_id as id,responsible_salesman_id,customer_rel_id,salesman_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,customer_id,operator_id from responsible_salesmans;
-- pk responsible_salesman_id
-- jsonb operator
-- == 表【sales_details】建视图语句 ==
-- drop view view_sales_details;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_details') THEN
-- 如果存在就删除视图
DROP VIEW view_sales_details;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_sales_details as select sales_detail_id as id,sales_detail_id,data_from,original_order_number,sale_date,salesman_id,region_id,superior_region_id,sales_method_id,customer_id,product_id,price,amount,is_returned,operator_id,company_id,created_at,updated_at,deleted_at,latest_update_time,address,department,total_price_and_tax from sales_details;
-- pk sales_detail_id
-- jsonb
-- == 表【sales_methods】建视图语句 ==
-- drop view view_sales_methods;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_methods') THEN
-- 如果存在就删除视图
DROP VIEW view_sales_methods;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_sales_methods as select created_at,data_from,sales_method_id,updated_at,method_name,operator_id,latest_update_time from sales_methods;
-- pk
-- jsonb operator
-- == 表【salesman_rels】建视图语句 ==
-- drop view view_salesman_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesman_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_salesman_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_salesman_rels as select salesman_rel_id as id,salesman_rel_id,salesman_level,status,created_at,updated_at,deleted_at,latest_update_time,salesman_id,operator_id from salesman_rels;
-- pk salesman_rel_id
-- jsonb operator
-- == 表【salesmans】建视图语句 ==
-- drop view view_salesmans;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesmans') THEN
-- 如果存在就删除视图
DROP VIEW view_salesmans;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_salesmans as select salesman_id as id,salesman_id,salesman_code,salesman_name,data_from,status,phone,company_id,created_at,updated_at,deleted_at,latest_update_time,operator_id,disabled_at from salesmans;
-- pk salesman_id
-- jsonb operator
-- == 表【solution_groups】建视图语句 ==
-- drop view view_solution_groups;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solution_groups') THEN
-- 如果存在就删除视图
DROP VIEW view_solution_groups;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_solution_groups as select solution_group_id as id,solution_group_id,solution_group_name,created_at,updated_at,deleted_at,operator_id from solution_groups;
-- pk solution_group_id
-- jsonb operator
-- == 表【solutions】建视图语句 ==
-- drop view view_solutions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solutions') THEN
-- 如果存在就删除视图
DROP VIEW view_solutions;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_solutions as select solution_id as id,solution_id,database_name,schema_name,solution_group_id,solution_name,latest_update_time,status,created_at,updated_at,deleted_at,compute_business_name,compute_business_id,operator_id,begin_time,end_time from solutions;
-- pk solution_id
-- jsonb operator,compute_items,salesmen
-- == 表【project_costs】建视图语句 ==
-- drop view view_project_costs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_project_costs') THEN
-- 如果存在就删除视图
DROP VIEW view_project_costs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_project_costs as select project_cost_id as id,project_cost_id,data_from,created_at,deleted_at,updated_at,product_id,happen_time,money,subject,region_id,salesman_id,customer_id,operator_id,latest_update_time,department from project_costs;
-- pk project_cost_id
-- jsonb operator
-- == 表【region_belongs】建视图语句 ==
-- drop view view_region_belongs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_belongs') THEN
-- 如果存在就删除视图
DROP VIEW view_region_belongs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_belongs as select region_belong_id as id,region_belong_id,begin_time,end_time,status,parent_region_id,region_id,operator_id,created_at,deleted_at,updated_at,latest_update_time from region_belongs;
-- pk region_belong_id
-- jsonb
-- == 表【region_categorys】建视图语句 ==
-- drop view view_region_categorys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_categorys') THEN
-- 如果存在就删除视图
DROP VIEW view_region_categorys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_categorys as select region_category_id as id,region_category_id,begin_time,end_time,status,category_type,tag,operator_id,created_at,deleted_at,latest_update_time,updated_at,region_id from region_categorys;
-- pk region_category_id
-- jsonb
-- == 表【region_salesmans】建视图语句 ==
-- drop view view_region_salesmans;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_salesmans') THEN
-- 如果存在就删除视图
DROP VIEW view_region_salesmans;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_salesmans as select region_salesman_id as id,region_salesman_id,region_id,salesman_id,begin_time,created_at,deleted_at,end_time,latest_update_time,updated_at,status,operator_id from region_salesmans;
-- pk region_salesman_id
-- jsonb
-- == 表【regions】建视图语句 ==
-- drop view view_regions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regions') THEN
-- 如果存在就删除视图
DROP VIEW view_regions;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_regions as select region_id as id,region_id,region_code,region_name,data_from,status,company_id,created_at,updated_at,deleted_at,latest_update_time,disabled_at from regions;
-- pk region_id
-- jsonb operator
-- == 表【superior_responsible_persons】建视图语句 ==
-- drop view view_superior_responsible_persons;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_responsible_persons') THEN
-- 如果存在就删除视图
DROP VIEW view_superior_responsible_persons;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_superior_responsible_persons as select superior_responsible_person_id as id,superior_responsible_person_id,salesman_rel_id,salesman_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,superior_salesman_id,operator_id from superior_responsible_persons;
-- pk superior_responsible_person_id
-- jsonb operator
-- == 表【type_tags】建视图语句 ==
-- drop view view_type_tags;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_type_tags') THEN
-- 如果存在就删除视图
DROP VIEW view_type_tags;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_type_tags as select type_tag_id as id,type_tag_id,rel_id,type_tag_module,type_tag_name,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,type_tag_code,operator_id from type_tags;
-- pk type_tag_id
-- jsonb operator
-- == 表【editor_module_confs】建视图语句 ==
-- drop view view_editor_module_confs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_module_confs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_module_confs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_module_confs as select id,name,report_id,is_checked,uri,created_at,updated_at from editor_module_confs;
-- pk
-- jsonb
-- == 表【editor_user_conf_logs】建视图语句 ==
-- drop view view_editor_user_conf_logs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_conf_logs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_user_conf_logs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_user_conf_logs as select id,user_id,user_name,report_id,report_name,module_name,created_at from editor_user_conf_logs;
-- pk
-- jsonb
-- == 表【product_shares】建视图语句 ==
-- drop view view_product_shares;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_shares') THEN
-- 如果存在就删除视图
DROP VIEW view_product_shares;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_shares as select product_share_id as id,product_share_id,customer_rel_id,shared_product_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,customer_id,salesman_type,salesman_id,salesman_share,operator_id,extra_attribute,group_id from product_shares;
-- pk product_share_id
-- jsonb operator
-- == 表【superior_customers】建视图语句 ==
-- drop view view_superior_customers;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_customers') THEN
-- 如果存在就删除视图
DROP VIEW view_superior_customers;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_superior_customers as select superior_customer_id as id,superior_customer_id,customer_rel_id,customer_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,superior_customer_uid,operator_id from superior_customers;
-- pk superior_customer_id
-- jsonb operator
-- == 表【editor_report_confs】建视图语句 ==
-- drop view view_editor_report_confs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_report_confs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_report_confs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_report_confs as select id,name,platform_id,created_at,updated_at,permission_flag from editor_report_confs;
-- pk
-- jsonb
-- == 表【areas】建视图语句 ==
-- drop view view_areas;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_areas') THEN
-- 如果存在就删除视图
DROP VIEW view_areas;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_areas as select area_code,city_code,parent_code,level,merger_name,name,short_name,zip_code,full_name,id,pinyin,lng,lat,full_area_code from areas;
-- pk
-- jsonb
-- == 表【editor_chart_confs】建视图语句 ==
-- drop view view_editor_chart_confs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_chart_confs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_chart_confs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_chart_confs as select id,name,module_id,chart_conf,chart_data_conf,is_checked,is_default,created_at,updated_at,deleted_at from editor_chart_confs;
-- pk
-- jsonb
-- == 表【editor_user_chart_conf】建视图语句 ==
-- drop view view_editor_user_chart_conf;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_chart_conf') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_user_chart_conf;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_user_chart_conf as select editor_user_chart_conf_id as id,editor_user_chart_conf_id,phone,report_id,module_id,module_permissions,chart_id,chart_checked,sort_by,created_at,updated_at,deleted_at,module_checked from editor_user_chart_conf;
-- pk editor_user_chart_conf_id
-- jsonb
-- == 表【users】建视图语句 ==
-- drop view view_users;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_users') THEN
-- 如果存在就删除视图
DROP VIEW view_users;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_users as select user_id as id,user_id,user_name,user_account,password,user_avatar,company_id,status,created_at,updated_at,deleted_at from users;
-- pk user_id
-- jsonb
-- == 表【offline_expenses】建视图语句 ==
-- drop view view_offline_expenses;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_offline_expenses') THEN
-- 如果存在就删除视图
DROP VIEW view_offline_expenses;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_offline_expenses as select project_cost_id as id,project_cost_id,data_from,created_at,deleted_at,updated_at,product_id,happen_time,money,subject,region_id,salesman_id,customer_id,operator_id,latest_update_time,department from offline_expenses;
-- pk project_cost_id
-- jsonb operator
-- == 表【regular_employee】建视图语句 ==
-- drop view view_regular_employee;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regular_employee') THEN
-- 如果存在就删除视图
DROP VIEW view_regular_employee;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_regular_employee as select regular_employee_id as id,regular_employee_id,salesman_code,salesman_name,confirmation_date,operator_id,created_at,updated_at,deleted_at,latest_update_time from regular_employee;
-- pk regular_employee_id
-- jsonb
-- == 表【employee_relations】建视图语句 ==
-- drop view view_employee_relations;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_employee_relations') THEN
-- 如果存在就删除视图
DROP VIEW view_employee_relations;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_employee_relations as select employee_relations_id as id,employee_relations_id,start_time,end_time,expense_area,expense_operator_code,primary_area_name,secondary_area_name,salesman_name,distribution_proportion,operator_id,created_at,updated_at,deleted_at,latest_update_time from employee_relations;
-- pk employee_relations_id
-- jsonb
-- == 表【operate_rules】建视图语句 ==
-- drop view view_operate_rules;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_operate_rules') THEN
-- 如果存在就删除视图
DROP VIEW view_operate_rules;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_operate_rules as select operate_rule_id as id,operate_rule_id,customer_code,product_code,area_code,allocation_proportion,primary_area_name,secondary_area_name,performance_type,opportunity_territory,start_time,end_time,operator_id,created_at,updated_at,deleted_at,latest_update_time from operate_rules;
-- pk operate_rule_id
-- jsonb
-- == 表【share_customer_expenses】建视图语句 ==
-- drop view view_share_customer_expenses;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_share_customer_expenses') THEN
-- 如果存在就删除视图
DROP VIEW view_share_customer_expenses;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_share_customer_expenses as select share_customer_expenses_id as id,share_customer_expenses_id,customer_code,primary_area_name,secondary_area_name,expense_type,start_time,end_time,operator_id,created_at,updated_at,deleted_at,latest_update_time from share_customer_expenses;
-- pk share_customer_expenses_id
-- jsonb
-- == 表【customer_comparisons】建视图语句 ==
-- drop view view_customer_comparisons;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_comparisons') THEN
-- 如果存在就删除视图
DROP VIEW view_customer_comparisons;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customer_comparisons as select customer_comparison_id as id,customer_comparison_id,customer_code,summary_area,primary_area_name,secondary_area_name,self_support_or_opportunity,start_time,end_time,operator_id,created_at,updated_at,deleted_at,rebate,latest_update_time from customer_comparisons;
-- pk customer_comparison_id
-- jsonb
-- == 表【regional_ownerships】建视图语句 ==
-- drop view view_regional_ownerships;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regional_ownerships') THEN
-- 如果存在就删除视图
DROP VIEW view_regional_ownerships;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_regional_ownerships as select regional_ownerships_id as id,regional_ownerships_id,start_time,end_time,area,secondary_area_name,salesman_code,salesman_name,is_incremental_commission,is_profit_increase_commission,operator_id,created_at,updated_at,deleted_at,latest_update_time from regional_ownerships;
-- pk regional_ownerships_id
-- jsonb
... ...
-- == 表【files】建视图语句 ==
drop view view_files;
create view view_files as select file_id as id,file_id,file_type,source_file_id,created_at,updated_at,deleted_at,version,file_from,app_key from files;
-- pk file_id
-- jsonb file_info,context
-- == 表【mapping_rules】建视图语句 ==
drop view view_mapping_rules;
create view view_mapping_rules as select mapping_rule_id as id,mapping_rule_id,name,table_id,file_id,created_at,updated_at,deleted_at from mapping_rules;
-- pk mapping_rule_id
-- jsonb main_table_fields,verified_file_fields,mapping_fields,context
-- == 表【logs】建视图语句 ==
drop view view_logs;
create view view_logs as select log_id as id,log_id,log_type,source_id,object_name,object_type,operation_type,content,operator_name,created_at,log_time from logs;
-- pk log_id
-- jsonb entry,context
-- == 表【query_sets】建视图语句 ==
drop view view_query_sets;
create view view_query_sets as select query_set_id as id,query_set_id,type,flag,name,pin_name,parent_id,status,sort,created_at,updated_at,deleted_at from query_sets;
-- pk query_set_id
-- jsonb query_set_info,query_components,context
-- == 表【query_sets_copy1】建视图语句 ==
drop view view_query_sets_copy1;
create view view_query_sets_copy1 as select query_set_id as id,query_set_id,type,flag,name,pin_name,parent_id,status,sort,created_at,updated_at,deleted_at from query_sets_copy1;
-- pk query_set_id
-- jsonb query_set_info,query_components,context
-- == 表【tables】建视图语句 ==
drop view view_tables;
create view view_tables as select table_id as id,table_id,table_catalog,table_type,table_schema,table_name,name,sql_name,table_type,parent_id,self_referencing_column_name,data_field_index,reference_generation,user_defined_type_catalog,user_defined_type_schema,user_defined_type_name,is_insertable_into,created_at,updated_at,is_typed,commit_action,deleted_at,version,row_count,apply_at from tables;
-- pk table_id
-- jsonb pk,data_fields,manual_fields,context,table_info,order_fields
... ...
... ... @@ -9,3 +9,9 @@ type GenerateBusinessTableViewRequest struct {
SchemaName string `json:"schemaName,optional,default=public"` // 模式名称
DBType string `json:"dbType,optional,default=postgresql"`
}
type DBTablesRequest struct {
GenerateBusinessTableViewRequest
ByteBankDBName string
ByteBankDBZhName string
}
... ...
... ... @@ -28,7 +28,39 @@ func (tableService *TableService) ShowBusinessDatabases(ctx *domain.Context, cmd
return response, err
}
var GlobalDB []command.DBTablesRequest = []command.DBTablesRequest{
{
ByteBankDBName: "allied_creation_reporting_system_test.public",
ByteBankDBZhName: "销导报表系统",
GenerateBusinessTableViewRequest: command.GenerateBusinessTableViewRequest{
Host: "114.55.200.59",
Port: "31543",
User: "postgres",
Password: "eagle1010",
DBName: "allied-creation-reporting-system_test",
SchemaName: "public",
DBType: "postgresql",
},
},
}
func getDB(databaseEnName string) (*command.DBTablesRequest, bool) {
for i := range GlobalDB {
if GlobalDB[i].ByteBankDBName == databaseEnName {
return &GlobalDB[i], true
}
}
return nil, false
}
func (tableService *TableService) ShowBusinessTables(ctx *domain.Context, cmd *query.ShowTablesRequest) (interface{}, error) {
req, ok := getDB(cmd.DatabaseEnName)
if !ok {
return nil, factory.FastError(fmt.Errorf("db " + cmd.DatabaseEnName + "未配置"))
}
return DBTables(req)
}
func (tableService *TableService) ShowBusinessTables1(ctx *domain.Context, cmd *query.ShowTablesRequest) (interface{}, error) {
byteCoreService := domainService.ByteCoreService{}
response, err := byteCoreService.ShowBusinessTables(bytelib.ReqShowBusinessTables{
DatabaseEnName: cmd.DatabaseEnName,
... ... @@ -224,6 +256,11 @@ func (tableService *TableService) GenerateBusinessTable(ctx *domain.Context, cmd
return nil, nil
}
type Field struct {
Field string `json:"field"`
Type string `json:"type"`
}
func (tableService *TableService) GenerateBusinessTablesView(ctx *domain.Context, cmd *command.GenerateBusinessTableViewRequest) (interface{}, error) {
var (
db *gorm.DB
... ... @@ -247,10 +284,6 @@ func (tableService *TableService) GenerateBusinessTablesView(ctx *domain.Context
if tx := db.Raw(fmt.Sprintf(`select tablename from pg_tables where schemaname='%v';`, cmd.SchemaName)).Scan(&tables); tx.Error != nil {
return nil, factory.FastError(tx.Error)
}
type Field struct {
Field string `json:"field"`
Type string `json:"type"`
}
var fields = make([]Field, 0)
for _, t := range tables {
if tx := db.Raw(fmt.Sprintf(`SELECT a.attnum,a.attname AS field,t.typname AS type,a.attlen AS length,a.atttypmod AS lengthvar,a.attnotnull AS notnull
... ... @@ -262,9 +295,15 @@ ORDER BY a.attnum;`, t)).Scan(&fields); tx.Error != nil {
var commonFields []string
var jsonbFields []string
var pkFields []string
var containPkId = false
for _, f := range fields {
if f.Field == "id" {
containPkId = true
}
}
for index, f := range fields {
if index == 0 && strings.HasSuffix(f.Field, "id") {
//commonFields = append(commonFields, fmt.Sprintf("%v as id", f.Field))
if index == 0 && strings.HasSuffix(f.Field, "id") && !containPkId {
commonFields = append(commonFields, fmt.Sprintf("%v as id", f.Field))
pkFields = append(pkFields, f.Field)
}
if f.Type == "jsonb" || f.Type == "json" {
... ... @@ -274,7 +313,18 @@ ORDER BY a.attnum;`, t)).Scan(&fields); tx.Error != nil {
}
}
buf.WriteString(fmt.Sprintf("-- == 表【%v】建视图语句 ==\n", t))
buf.WriteString(fmt.Sprintf("drop view view_%v;\n", t))
buf.WriteString(fmt.Sprintf("-- drop view view_%v;\n", t))
buf.WriteString(fmt.Sprintf(`DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_%s') THEN
-- 如果存在就删除视图
DROP VIEW view_%s;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;`, t, t))
buf.WriteString("\n")
buf.WriteString(fmt.Sprintf("create view view_%v as select %v from %v;\n", t, strings.Join(commonFields, ","), t))
buf.WriteString(fmt.Sprintf("-- pk %v\n", strings.Join(pkFields, ",")))
buf.WriteString(fmt.Sprintf("-- jsonb %v\n", strings.Join(jsonbFields, ",")))
... ... @@ -284,11 +334,95 @@ ORDER BY a.attnum;`, t)).Scan(&fields); tx.Error != nil {
} else if cmd.DBType == "mysql" {
db, err = gorm.Open(mysql.Open(fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local",
cmd.User, cmd.Password, cmd.Host, cmd.Port, cmd.DBName)), &gorm.Config{PrepareStmt: false})
if err != nil {
return nil, factory.FastError(err)
}
var tables []string
if tx := db.Raw(fmt.Sprintf(`show tables;`)).Scan(&tables); tx.Error != nil {
return nil, factory.FastError(tx.Error)
}
var fields = make([]Field, 0)
for _, t := range tables {
if tx := db.Raw(fmt.Sprintf(`SHOW COLUMNS FROM %s;`, t)).Scan(&fields); tx.Error != nil {
return nil, factory.FastError(tx.Error)
}
writeToBuf(buf, t, fields)
}
generalWrite(cmd.DBName+"_tables_view.sql", buf)
}
return nil, nil
}
func DBTables(cmd *command.DBTablesRequest) (interface{}, error) {
var (
result = make([]map[string]interface{}, 0)
tables []string
db *gorm.DB
err error
)
if cmd.DBType == "postgresql" {
db, err = gorm.Open(postgres.Open(fmt.Sprintf("user=%v password=%v host=%v port=%v dbname=%v sslmode=disable TimeZone=Asia/Shanghai",
cmd.User, cmd.Password, cmd.Host, cmd.Port, cmd.DBName)), &gorm.Config{PrepareStmt: false})
if err != nil {
return nil, factory.FastError(err)
}
if tx := db.Raw(fmt.Sprintf(`select tablename from pg_tables where schemaname='%v';`, cmd.SchemaName)).Scan(&tables); tx.Error != nil {
return nil, factory.FastError(tx.Error)
}
} else if cmd.DBType == "mysql" {
db, err = gorm.Open(mysql.Open(fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local",
cmd.User, cmd.Password, cmd.Host, cmd.Port, cmd.DBName)), &gorm.Config{PrepareStmt: false})
if err != nil {
return nil, factory.FastError(err)
}
if tx := db.Raw(fmt.Sprintf(`show tables;`)).Scan(&tables); tx.Error != nil {
return nil, factory.FastError(tx.Error)
}
}
for _, t := range tables {
viewT := "view_" + t
result = append(result, map[string]interface{}{
"name": fmt.Sprintf("%s.%s", cmd.ByteBankDBName, viewT), //返回所有视图 view开头
"simpleName": viewT,
})
}
return map[string]interface{}{
"list": result,
}, nil
}
func writeToBuf(buf *bytes.Buffer, t string, fields []Field) {
var commonFields []string
var jsonbFields []string
var pkFields []string
var containPkId = false
for _, f := range fields {
if f.Field == "id" {
containPkId = true
}
}
for index, f := range fields {
if index == 0 && strings.HasSuffix(f.Field, "id") && !containPkId {
commonFields = append(commonFields, fmt.Sprintf("%v as id", f.Field))
pkFields = append(pkFields, f.Field)
}
if f.Type == "jsonb" || f.Type == "json" {
jsonbFields = append(jsonbFields, f.Field)
} else {
commonFields = append(commonFields, f.Field)
}
}
buf.WriteString(fmt.Sprintf("-- == 表【%v】建视图语句 ==\n", t))
buf.WriteString(fmt.Sprintf("-- drop view view_%v;\n", t))
buf.WriteString(fmt.Sprintf("DROP VIEW IF EXISTS %s;", t))
buf.WriteString("\n")
buf.WriteString(fmt.Sprintf("create view view_%v as select %v from %v;\n", t, strings.Join(commonFields, ","), t))
buf.WriteString(fmt.Sprintf("-- pk %v\n", strings.Join(pkFields, ",")))
buf.WriteString(fmt.Sprintf("-- jsonb %v\n", strings.Join(jsonbFields, ",")))
buf.WriteString("\n\n")
}
func generalWrite(filename string, buf *bytes.Buffer) {
f, err := os.OpenFile(filename, os.O_RDONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
... ...
-- == 表【cfg_salary_group】建视图语句 ==
-- drop view view_cfg_salary_group;
DROP VIEW IF EXISTS cfg_salary_group;
create view view_cfg_salary_group as select id,name,period_month,salary_type,company_id,create_time,enabled,count,period_day from cfg_salary_group;
-- pk
-- jsonb
-- == 表【cfg_subject】建视图语句 ==
-- drop view view_cfg_subject;
DROP VIEW IF EXISTS cfg_subject;
create view view_cfg_subject as select id,name,parent_id,type,key_value,value_Type,company_id,update_time,create_time,enabled,description,pay_time from cfg_subject;
-- pk
-- jsonb
-- == 表【role_income_rule】建视图语句 ==
-- drop view view_role_income_rule;
DROP VIEW IF EXISTS role_income_rule;
create view view_role_income_rule as select id,role_id,push_rate,type,company_id,update_time,create_time,enabled,pushMoneyType,min_range,max_range from role_income_rule;
-- pk
-- jsonb
-- == 表【salary_group_income_rule】建视图语句 ==
-- drop view view_salary_group_income_rule;
DROP VIEW IF EXISTS salary_group_income_rule;
create view view_salary_group_income_rule as select id,salary_group_id,push_rate,rate_type,type,child_type,company_id,update_time,create_time,enabled,ranges,year,effect_type from salary_group_income_rule;
-- pk
-- jsonb
-- == 表【salary_group_rule】建视图语句 ==
-- drop view view_salary_group_rule;
DROP VIEW IF EXISTS salary_group_rule;
create view view_salary_group_rule as select id,subject_id,weight,company_id,create_time,enabled,salary_group_id from salary_group_rule;
-- pk
-- jsonb
-- == 表【salary_group_user】建视图语句 ==
-- drop view view_salary_group_user;
DROP VIEW IF EXISTS salary_group_user;
create view view_salary_group_user as select id,uid,salary_group_id,company_id,create_time,enabled,department_id from salary_group_user;
-- pk
-- jsonb
-- == 表【salary_month】建视图语句 ==
-- drop view view_salary_month;
DROP VIEW IF EXISTS salary_month;
create view view_salary_month as select id,uid,basic_wage,kpi_bonus,basic_bonus,increment_push_money,profit_push_money,other_bonus,profession_subsidy,new_rake,windfall,total,extra_text,option_uid,company_id,create_time,update_time,enabled,salary_group_id,year,month,annual_increment,real_increment,excellent_increment,pre_total,normal_increment,chance_increment,normal_profit,chance_profit,annual_profit,history,adjustment,system_subject from salary_month;
-- pk
-- jsonb
-- == 表【salary_month_history】建视图语句 ==
-- drop view view_salary_month_history;
DROP VIEW IF EXISTS salary_month_history;
create view view_salary_month_history as select id,uid,basic_wage,kpi_bonus,basic_bonus,increment_push_money,profit_push_money,other_bonus,profession_subsidy,new_rake,windfall,total,extra_text,option_uid,company_id,create_time,update_time,enabled,salary_group_id,year,month,annual_increment,real_increment,normal_increment,chance_increment,excellent_increment,pre_total,normal_profit,chance_profit,annual_profit from salary_month_history;
-- pk
-- jsonb
-- == 表【salary_record】建视图语句 ==
-- drop view view_salary_record;
DROP VIEW IF EXISTS salary_record;
create view view_salary_record as select id,uid,basic_wage,kpi_bonus,basic_bonus,increment_push_money,profit_push_money,other_bonus,profession_subsidy,new_rake,windfall,company_id,create_time,update_time,enabled,extra_text,option_uid,excellent_increment,annual_increment from salary_record;
-- pk
-- jsonb
-- == 表【salary_record_history】建视图语句 ==
-- drop view view_salary_record_history;
DROP VIEW IF EXISTS salary_record_history;
create view view_salary_record_history as select id,uid,basic_wage,kpi_bonus,basic_bonus,increment_push_money,profit_push_money,other_bonus,profession_subsidy,new_rake,windfall,company_id,create_time,enabled,extra_text,option_uid,excellent_increment,annual_increment from salary_record_history;
-- pk
-- jsonb
-- == 表【subject_pay_time】建视图语句 ==
-- drop view view_subject_pay_time;
DROP VIEW IF EXISTS subject_pay_time;
create view view_subject_pay_time as select id,subject_id,pay_time,company_id,create_time,enabled from subject_pay_time;
-- pk
-- jsonb
-- == 表【subject_state】建视图语句 ==
-- drop view view_subject_state;
DROP VIEW IF EXISTS subject_state;
create view view_subject_state as select id,subject_id,type,company_id,create_time,enabled from subject_state;
-- pk
-- jsonb
-- == 表【view_subject_state】建视图语句 ==
-- drop view view_view_subject_state;
DROP VIEW IF EXISTS view_subject_state;
create view view_view_subject_state as select id,type,company_id from view_subject_state;
-- pk
-- jsonb
... ...