作者 yangfu

业务表同步

  1 +-- == 表【belonging_regions】建视图语句 ==
  2 +-- drop view view_belonging_regions;
  3 +DO $$
  4 +BEGIN
  5 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_belonging_regions') THEN
  6 + -- 如果存在就删除视图
  7 +DROP VIEW view_belonging_regions;
  8 +RAISE NOTICE '视图已删除';
  9 +ELSE
  10 + RAISE NOTICE '视图不存在';
  11 +END IF;
  12 +END $$;
  13 +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;
  14 +-- pk belonging_region_id
  15 +-- jsonb operator,areas
  16 +
  17 +
  18 +-- == 表【area_belongs】建视图语句 ==
  19 +-- drop view view_area_belongs;
  20 +DO $$
  21 +BEGIN
  22 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_belongs') THEN
  23 + -- 如果存在就删除视图
  24 +DROP VIEW view_area_belongs;
  25 +RAISE NOTICE '视图已删除';
  26 +ELSE
  27 + RAISE NOTICE '视图不存在';
  28 +END IF;
  29 +END $$;
  30 +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;
  31 +-- pk area_belong_id
  32 +-- jsonb
  33 +
  34 +
  35 +-- == 表【area_rel_expireds】建视图语句 ==
  36 +-- drop view view_area_rel_expireds;
  37 +DO $$
  38 +BEGIN
  39 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_rel_expireds') THEN
  40 + -- 如果存在就删除视图
  41 +DROP VIEW view_area_rel_expireds;
  42 +RAISE NOTICE '视图已删除';
  43 +ELSE
  44 + RAISE NOTICE '视图不存在';
  45 +END IF;
  46 +END $$;
  47 +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;
  48 +-- pk
  49 +-- jsonb
  50 +
  51 +
  52 +-- == 表【area_categorys】建视图语句 ==
  53 +-- drop view view_area_categorys;
  54 +DO $$
  55 +BEGIN
  56 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_categorys') THEN
  57 + -- 如果存在就删除视图
  58 +DROP VIEW view_area_categorys;
  59 +RAISE NOTICE '视图已删除';
  60 +ELSE
  61 + RAISE NOTICE '视图不存在';
  62 +END IF;
  63 +END $$;
  64 +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;
  65 +-- pk
  66 +-- jsonb
  67 +
  68 +
  69 +-- == 表【corresponding_period】建视图语句 ==
  70 +-- drop view view_corresponding_period;
  71 +DO $$
  72 +BEGIN
  73 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_period') THEN
  74 + -- 如果存在就删除视图
  75 +DROP VIEW view_corresponding_period;
  76 +RAISE NOTICE '视图已删除';
  77 +ELSE
  78 + RAISE NOTICE '视图不存在';
  79 +END IF;
  80 +END $$;
  81 +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;
  82 +-- pk saleman_id
  83 +-- jsonb
  84 +
  85 +
  86 +-- == 表【change_logs】建视图语句 ==
  87 +-- drop view view_change_logs;
  88 +DO $$
  89 +BEGIN
  90 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_change_logs') THEN
  91 + -- 如果存在就删除视图
  92 +DROP VIEW view_change_logs;
  93 +RAISE NOTICE '视图已删除';
  94 +ELSE
  95 + RAISE NOTICE '视图不存在';
  96 +END IF;
  97 +END $$;
  98 +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;
  99 +-- pk change_log_id
  100 +-- jsonb change_log_content,operator
  101 +
  102 +
  103 +-- == 表【channels】建视图语句 ==
  104 +-- drop view view_channels;
  105 +DO $$
  106 +BEGIN
  107 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_channels') THEN
  108 + -- 如果存在就删除视图
  109 +DROP VIEW view_channels;
  110 +RAISE NOTICE '视图已删除';
  111 +ELSE
  112 + RAISE NOTICE '视图不存在';
  113 +END IF;
  114 +END $$;
  115 +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;
  116 +-- pk channel_id
  117 +-- jsonb operator
  118 +
  119 +
  120 +-- == 表【custom_relations】建视图语句 ==
  121 +-- drop view view_custom_relations;
  122 +DO $$
  123 +BEGIN
  124 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relations') THEN
  125 + -- 如果存在就删除视图
  126 +DROP VIEW view_custom_relations;
  127 +RAISE NOTICE '视图已删除';
  128 +ELSE
  129 + RAISE NOTICE '视图不存在';
  130 +END IF;
  131 +END $$;
  132 +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;
  133 +-- pk
  134 +-- jsonb areas
  135 +
  136 +
  137 +-- == 表【customer_rels】建视图语句 ==
  138 +-- drop view view_customer_rels;
  139 +DO $$
  140 +BEGIN
  141 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rels') THEN
  142 + -- 如果存在就删除视图
  143 +DROP VIEW view_customer_rels;
  144 +RAISE NOTICE '视图已删除';
  145 +ELSE
  146 + RAISE NOTICE '视图不存在';
  147 +END IF;
  148 +END $$;
  149 +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;
  150 +-- pk customer_rel_id
  151 +-- jsonb operator
  152 +
  153 +
  154 +-- == 表【customers】建视图语句 ==
  155 +-- drop view view_customers;
  156 +DO $$
  157 +BEGIN
  158 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customers') THEN
  159 + -- 如果存在就删除视图
  160 +DROP VIEW view_customers;
  161 +RAISE NOTICE '视图已删除';
  162 +ELSE
  163 + RAISE NOTICE '视图不存在';
  164 +END IF;
  165 +END $$;
  166 +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;
  167 +-- pk customer_id
  168 +-- jsonb operator
  169 +
  170 +
  171 +-- == 表【matched_relations】建视图语句 ==
  172 +-- drop view view_matched_relations;
  173 +DO $$
  174 +BEGIN
  175 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_matched_relations') THEN
  176 + -- 如果存在就删除视图
  177 +DROP VIEW view_matched_relations;
  178 +RAISE NOTICE '视图已删除';
  179 +ELSE
  180 + RAISE NOTICE '视图不存在';
  181 +END IF;
  182 +END $$;
  183 +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;
  184 +-- pk matched_relation_id
  185 +-- jsonb matched_fields,operator
  186 +
  187 +
  188 +-- == 表【notice_messages】建视图语句 ==
  189 +-- drop view view_notice_messages;
  190 +DO $$
  191 +BEGIN
  192 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_notice_messages') THEN
  193 + -- 如果存在就删除视图
  194 +DROP VIEW view_notice_messages;
  195 +RAISE NOTICE '视图已删除';
  196 +ELSE
  197 + RAISE NOTICE '视图不存在';
  198 +END IF;
  199 +END $$;
  200 +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;
  201 +-- pk notice_message_id
  202 +-- jsonb operator
  203 +
  204 +
  205 +-- == 表【product_belongs】建视图语句 ==
  206 +-- drop view view_product_belongs;
  207 +DO $$
  208 +BEGIN
  209 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_belongs') THEN
  210 + -- 如果存在就删除视图
  211 +DROP VIEW view_product_belongs;
  212 +RAISE NOTICE '视图已删除';
  213 +ELSE
  214 + RAISE NOTICE '视图不存在';
  215 +END IF;
  216 +END $$;
  217 +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;
  218 +-- pk product_belong_id
  219 +-- jsonb
  220 +
  221 +
  222 +-- == 表【product_categorys】建视图语句 ==
  223 +-- drop view view_product_categorys;
  224 +DO $$
  225 +BEGIN
  226 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_categorys') THEN
  227 + -- 如果存在就删除视图
  228 +DROP VIEW view_product_categorys;
  229 +RAISE NOTICE '视图已删除';
  230 +ELSE
  231 + RAISE NOTICE '视图不存在';
  232 +END IF;
  233 +END $$;
  234 +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;
  235 +-- pk product_category_id
  236 +-- jsonb
  237 +
  238 +
  239 +-- == 表【corresponding_profit】建视图语句 ==
  240 +-- drop view view_corresponding_profit;
  241 +DO $$
  242 +BEGIN
  243 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_profit') THEN
  244 + -- 如果存在就删除视图
  245 +DROP VIEW view_corresponding_profit;
  246 +RAISE NOTICE '视图已删除';
  247 +ELSE
  248 + RAISE NOTICE '视图不存在';
  249 +END IF;
  250 +END $$;
  251 +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;
  252 +-- pk saleman_id
  253 +-- jsonb
  254 +
  255 +
  256 +-- == 表【custom_relation_templates】建视图语句 ==
  257 +-- drop view view_custom_relation_templates;
  258 +DO $$
  259 +BEGIN
  260 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_templates') THEN
  261 + -- 如果存在就删除视图
  262 +DROP VIEW view_custom_relation_templates;
  263 +RAISE NOTICE '视图已删除';
  264 +ELSE
  265 + RAISE NOTICE '视图不存在';
  266 +END IF;
  267 +END $$;
  268 +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;
  269 +-- pk
  270 +-- jsonb relation_target,share_target
  271 +
  272 +
  273 +-- == 表【custom_relation_historys】建视图语句 ==
  274 +-- drop view view_custom_relation_historys;
  275 +DO $$
  276 +BEGIN
  277 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_historys') THEN
  278 + -- 如果存在就删除视图
  279 +DROP VIEW view_custom_relation_historys;
  280 +RAISE NOTICE '视图已删除';
  281 +ELSE
  282 + RAISE NOTICE '视图不存在';
  283 +END IF;
  284 +END $$;
  285 +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;
  286 +-- pk
  287 +-- jsonb body_data,head_field
  288 +
  289 +
  290 +-- == 表【product_rel_expireds】建视图语句 ==
  291 +-- drop view view_product_rel_expireds;
  292 +DO $$
  293 +BEGIN
  294 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rel_expireds') THEN
  295 + -- 如果存在就删除视图
  296 +DROP VIEW view_product_rel_expireds;
  297 +RAISE NOTICE '视图已删除';
  298 +ELSE
  299 + RAISE NOTICE '视图不存在';
  300 +END IF;
  301 +END $$;
  302 +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;
  303 +-- pk product_id
  304 +-- jsonb
  305 +
  306 +
  307 +-- == 表【product_rels】建视图语句 ==
  308 +-- drop view view_product_rels;
  309 +DO $$
  310 +BEGIN
  311 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rels') THEN
  312 + -- 如果存在就删除视图
  313 +DROP VIEW view_product_rels;
  314 +RAISE NOTICE '视图已删除';
  315 +ELSE
  316 + RAISE NOTICE '视图不存在';
  317 +END IF;
  318 +END $$;
  319 +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;
  320 +-- pk product_rel_id
  321 +-- jsonb
  322 +
  323 +
  324 +-- == 表【product_shares】建视图语句 ==
  325 +-- drop view view_product_shares;
  326 +DO $$
  327 +BEGIN
  328 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_shares') THEN
  329 + -- 如果存在就删除视图
  330 +DROP VIEW view_product_shares;
  331 +RAISE NOTICE '视图已删除';
  332 +ELSE
  333 + RAISE NOTICE '视图不存在';
  334 +END IF;
  335 +END $$;
  336 +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;
  337 +-- pk product_share_id
  338 +-- jsonb operator
  339 +
  340 +
  341 +-- == 表【project_costs】建视图语句 ==
  342 +-- drop view view_project_costs;
  343 +DO $$
  344 +BEGIN
  345 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_project_costs') THEN
  346 + -- 如果存在就删除视图
  347 +DROP VIEW view_project_costs;
  348 +RAISE NOTICE '视图已删除';
  349 +ELSE
  350 + RAISE NOTICE '视图不存在';
  351 +END IF;
  352 +END $$;
  353 +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;
  354 +-- pk project_cost_id
  355 +-- jsonb operator
  356 +
  357 +
  358 +-- == 表【region_categorys】建视图语句 ==
  359 +-- drop view view_region_categorys;
  360 +DO $$
  361 +BEGIN
  362 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_categorys') THEN
  363 + -- 如果存在就删除视图
  364 +DROP VIEW view_region_categorys;
  365 +RAISE NOTICE '视图已删除';
  366 +ELSE
  367 + RAISE NOTICE '视图不存在';
  368 +END IF;
  369 +END $$;
  370 +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;
  371 +-- pk region_category_id
  372 +-- jsonb
  373 +
  374 +
  375 +-- == 表【sales_details】建视图语句 ==
  376 +-- drop view view_sales_details;
  377 +DO $$
  378 +BEGIN
  379 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_details') THEN
  380 + -- 如果存在就删除视图
  381 +DROP VIEW view_sales_details;
  382 +RAISE NOTICE '视图已删除';
  383 +ELSE
  384 + RAISE NOTICE '视图不存在';
  385 +END IF;
  386 +END $$;
  387 +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;
  388 +-- pk sales_detail_id
  389 +-- jsonb
  390 +
  391 +
  392 +-- == 表【sales_methods】建视图语句 ==
  393 +-- drop view view_sales_methods;
  394 +DO $$
  395 +BEGIN
  396 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_methods') THEN
  397 + -- 如果存在就删除视图
  398 +DROP VIEW view_sales_methods;
  399 +RAISE NOTICE '视图已删除';
  400 +ELSE
  401 + RAISE NOTICE '视图不存在';
  402 +END IF;
  403 +END $$;
  404 +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;
  405 +-- pk
  406 +-- jsonb operator
  407 +
  408 +
  409 +-- == 表【salesman_rels】建视图语句 ==
  410 +-- drop view view_salesman_rels;
  411 +DO $$
  412 +BEGIN
  413 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesman_rels') THEN
  414 + -- 如果存在就删除视图
  415 +DROP VIEW view_salesman_rels;
  416 +RAISE NOTICE '视图已删除';
  417 +ELSE
  418 + RAISE NOTICE '视图不存在';
  419 +END IF;
  420 +END $$;
  421 +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;
  422 +-- pk salesman_rel_id
  423 +-- jsonb operator
  424 +
  425 +
  426 +-- == 表【solutions】建视图语句 ==
  427 +-- drop view view_solutions;
  428 +DO $$
  429 +BEGIN
  430 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solutions') THEN
  431 + -- 如果存在就删除视图
  432 +DROP VIEW view_solutions;
  433 +RAISE NOTICE '视图已删除';
  434 +ELSE
  435 + RAISE NOTICE '视图不存在';
  436 +END IF;
  437 +END $$;
  438 +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;
  439 +-- pk solution_id
  440 +-- jsonb operator,compute_items,salesmen
  441 +
  442 +
  443 +-- == 表【salesmans】建视图语句 ==
  444 +-- drop view view_salesmans;
  445 +DO $$
  446 +BEGIN
  447 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesmans') THEN
  448 + -- 如果存在就删除视图
  449 +DROP VIEW view_salesmans;
  450 +RAISE NOTICE '视图已删除';
  451 +ELSE
  452 + RAISE NOTICE '视图不存在';
  453 +END IF;
  454 +END $$;
  455 +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;
  456 +-- pk salesman_id
  457 +-- jsonb operator
  458 +
  459 +
  460 +-- == 表【superior_customers】建视图语句 ==
  461 +-- drop view view_superior_customers;
  462 +DO $$
  463 +BEGIN
  464 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_customers') THEN
  465 + -- 如果存在就删除视图
  466 +DROP VIEW view_superior_customers;
  467 +RAISE NOTICE '视图已删除';
  468 +ELSE
  469 + RAISE NOTICE '视图不存在';
  470 +END IF;
  471 +END $$;
  472 +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;
  473 +-- pk superior_customer_id
  474 +-- jsonb operator
  475 +
  476 +
  477 +-- == 表【superior_responsible_persons】建视图语句 ==
  478 +-- drop view view_superior_responsible_persons;
  479 +DO $$
  480 +BEGIN
  481 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_responsible_persons') THEN
  482 + -- 如果存在就删除视图
  483 +DROP VIEW view_superior_responsible_persons;
  484 +RAISE NOTICE '视图已删除';
  485 +ELSE
  486 + RAISE NOTICE '视图不存在';
  487 +END IF;
  488 +END $$;
  489 +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;
  490 +-- pk superior_responsible_person_id
  491 +-- jsonb operator
  492 +
  493 +
  494 +-- == 表【type_tags】建视图语句 ==
  495 +-- drop view view_type_tags;
  496 +DO $$
  497 +BEGIN
  498 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_type_tags') THEN
  499 + -- 如果存在就删除视图
  500 +DROP VIEW view_type_tags;
  501 +RAISE NOTICE '视图已删除';
  502 +ELSE
  503 + RAISE NOTICE '视图不存在';
  504 +END IF;
  505 +END $$;
  506 +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;
  507 +-- pk type_tag_id
  508 +-- jsonb operator
  509 +
  510 +
  511 +-- == 表【region_salesmans】建视图语句 ==
  512 +-- drop view view_region_salesmans;
  513 +DO $$
  514 +BEGIN
  515 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_salesmans') THEN
  516 + -- 如果存在就删除视图
  517 +DROP VIEW view_region_salesmans;
  518 +RAISE NOTICE '视图已删除';
  519 +ELSE
  520 + RAISE NOTICE '视图不存在';
  521 +END IF;
  522 +END $$;
  523 +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;
  524 +-- pk region_salesman_id
  525 +-- jsonb
  526 +
  527 +
  528 +-- == 表【region_rels】建视图语句 ==
  529 +-- drop view view_region_rels;
  530 +DO $$
  531 +BEGIN
  532 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rels') THEN
  533 + -- 如果存在就删除视图
  534 +DROP VIEW view_region_rels;
  535 +RAISE NOTICE '视图已删除';
  536 +ELSE
  537 + RAISE NOTICE '视图不存在';
  538 +END IF;
  539 +END $$;
  540 +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;
  541 +-- pk region_rel_id
  542 +-- jsonb
  543 +
  544 +
  545 +-- == 表【regions】建视图语句 ==
  546 +-- drop view view_regions;
  547 +DO $$
  548 +BEGIN
  549 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regions') THEN
  550 + -- 如果存在就删除视图
  551 +DROP VIEW view_regions;
  552 +RAISE NOTICE '视图已删除';
  553 +ELSE
  554 + RAISE NOTICE '视图不存在';
  555 +END IF;
  556 +END $$;
  557 +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;
  558 +-- pk region_id
  559 +-- jsonb operator
  560 +
  561 +
  562 +-- == 表【areas】建视图语句 ==
  563 +-- drop view view_areas;
  564 +DO $$
  565 +BEGIN
  566 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_areas') THEN
  567 + -- 如果存在就删除视图
  568 +DROP VIEW view_areas;
  569 +RAISE NOTICE '视图已删除';
  570 +ELSE
  571 + RAISE NOTICE '视图不存在';
  572 +END IF;
  573 +END $$;
  574 +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;
  575 +-- pk
  576 +-- jsonb
  577 +
  578 +
  579 +-- == 表【customer_rewards】建视图语句 ==
  580 +-- drop view view_customer_rewards;
  581 +DO $$
  582 +BEGIN
  583 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rewards') THEN
  584 + -- 如果存在就删除视图
  585 +DROP VIEW view_customer_rewards;
  586 +RAISE NOTICE '视图已删除';
  587 +ELSE
  588 + RAISE NOTICE '视图不存在';
  589 +END IF;
  590 +END $$;
  591 +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;
  592 +-- pk customer_reward_id
  593 +-- jsonb operator
  594 +
  595 +
  596 +-- == 表【chart_style_configs】建视图语句 ==
  597 +-- drop view view_chart_style_configs;
  598 +DO $$
  599 +BEGIN
  600 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_chart_style_configs') THEN
  601 + -- 如果存在就删除视图
  602 +DROP VIEW view_chart_style_configs;
  603 +RAISE NOTICE '视图已删除';
  604 +ELSE
  605 + RAISE NOTICE '视图不存在';
  606 +END IF;
  607 +END $$;
  608 +create view view_chart_style_configs as select id,conf,module,created_at,updated_at,data_conf from chart_style_configs;
  609 +-- pk
  610 +-- jsonb
  611 +
  612 +
  613 +-- == 表【performances】建视图语句 ==
  614 +-- drop view view_performances;
  615 +DO $$
  616 +BEGIN
  617 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_performances') THEN
  618 + -- 如果存在就删除视图
  619 +DROP VIEW view_performances;
  620 +RAISE NOTICE '视图已删除';
  621 +ELSE
  622 + RAISE NOTICE '视图不存在';
  623 +END IF;
  624 +END $$;
  625 +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;
  626 +-- pk performance_id
  627 +-- jsonb
  628 +
  629 +
  630 +-- == 表【products】建视图语句 ==
  631 +-- drop view view_products;
  632 +DO $$
  633 +BEGIN
  634 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_products') THEN
  635 + -- 如果存在就删除视图
  636 +DROP VIEW view_products;
  637 +RAISE NOTICE '视图已删除';
  638 +ELSE
  639 + RAISE NOTICE '视图不存在';
  640 +END IF;
  641 +END $$;
  642 +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;
  643 +-- pk product_id
  644 +-- jsonb operator
  645 +
  646 +
  647 +-- == 表【profits】建视图语句 ==
  648 +-- drop view view_profits;
  649 +DO $$
  650 +BEGIN
  651 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_profits') THEN
  652 + -- 如果存在就删除视图
  653 +DROP VIEW view_profits;
  654 +RAISE NOTICE '视图已删除';
  655 +ELSE
  656 + RAISE NOTICE '视图不存在';
  657 +END IF;
  658 +END $$;
  659 +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;
  660 +-- pk profit_id
  661 +-- jsonb
  662 +
  663 +
  664 +-- == 表【region_belongs】建视图语句 ==
  665 +-- drop view view_region_belongs;
  666 +DO $$
  667 +BEGIN
  668 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_belongs') THEN
  669 + -- 如果存在就删除视图
  670 +DROP VIEW view_region_belongs;
  671 +RAISE NOTICE '视图已删除';
  672 +ELSE
  673 + RAISE NOTICE '视图不存在';
  674 +END IF;
  675 +END $$;
  676 +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;
  677 +-- pk region_belong_id
  678 +-- jsonb
  679 +
  680 +
  681 +-- == 表【region_rel_expireds】建视图语句 ==
  682 +-- drop view view_region_rel_expireds;
  683 +DO $$
  684 +BEGIN
  685 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rel_expireds') THEN
  686 + -- 如果存在就删除视图
  687 +DROP VIEW view_region_rel_expireds;
  688 +RAISE NOTICE '视图已删除';
  689 +ELSE
  690 + RAISE NOTICE '视图不存在';
  691 +END IF;
  692 +END $$;
  693 +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;
  694 +-- pk region_id
  695 +-- jsonb
  696 +
  697 +
  698 +-- == 表【responsible_salesmans】建视图语句 ==
  699 +-- drop view view_responsible_salesmans;
  700 +DO $$
  701 +BEGIN
  702 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_responsible_salesmans') THEN
  703 + -- 如果存在就删除视图
  704 +DROP VIEW view_responsible_salesmans;
  705 +RAISE NOTICE '视图已删除';
  706 +ELSE
  707 + RAISE NOTICE '视图不存在';
  708 +END IF;
  709 +END $$;
  710 +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;
  711 +-- pk responsible_salesman_id
  712 +-- jsonb operator
  713 +
  714 +
  715 +-- == 表【solution_groups】建视图语句 ==
  716 +-- drop view view_solution_groups;
  717 +DO $$
  718 +BEGIN
  719 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solution_groups') THEN
  720 + -- 如果存在就删除视图
  721 +DROP VIEW view_solution_groups;
  722 +RAISE NOTICE '视图已删除';
  723 +ELSE
  724 + RAISE NOTICE '视图不存在';
  725 +END IF;
  726 +END $$;
  727 +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;
  728 +-- pk solution_group_id
  729 +-- jsonb operator
  730 +
  731 +
  732 +-- == 表【users】建视图语句 ==
  733 +-- drop view view_users;
  734 +DO $$
  735 +BEGIN
  736 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_users') THEN
  737 + -- 如果存在就删除视图
  738 +DROP VIEW view_users;
  739 +RAISE NOTICE '视图已删除';
  740 +ELSE
  741 + RAISE NOTICE '视图不存在';
  742 +END IF;
  743 +END $$;
  744 +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;
  745 +-- pk user_id
  746 +-- jsonb
  747 +
  748 +
  749 +-- == 表【product_costs】建视图语句 ==
  750 +-- drop view view_product_costs;
  751 +DO $$
  752 +BEGIN
  753 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_costs') THEN
  754 + -- 如果存在就删除视图
  755 +DROP VIEW view_product_costs;
  756 +RAISE NOTICE '视图已删除';
  757 +ELSE
  758 + RAISE NOTICE '视图不存在';
  759 +END IF;
  760 +END $$;
  761 +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;
  762 +-- pk product_cost_id
  763 +-- jsonb operator
  764 +
  765 +
  766 +-- == 表【editor_chart_confs】建视图语句 ==
  767 +-- drop view view_editor_chart_confs;
  768 +DO $$
  769 +BEGIN
  770 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_chart_confs') THEN
  771 + -- 如果存在就删除视图
  772 +DROP VIEW view_editor_chart_confs;
  773 +RAISE NOTICE '视图已删除';
  774 +ELSE
  775 + RAISE NOTICE '视图不存在';
  776 +END IF;
  777 +END $$;
  778 +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;
  779 +-- pk
  780 +-- jsonb
  781 +
  782 +
  783 +-- == 表【editor_user_chart_conf】建视图语句 ==
  784 +-- drop view view_editor_user_chart_conf;
  785 +DO $$
  786 +BEGIN
  787 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_chart_conf') THEN
  788 + -- 如果存在就删除视图
  789 +DROP VIEW view_editor_user_chart_conf;
  790 +RAISE NOTICE '视图已删除';
  791 +ELSE
  792 + RAISE NOTICE '视图不存在';
  793 +END IF;
  794 +END $$;
  795 +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;
  796 +-- pk editor_user_chart_conf_id
  797 +-- jsonb
  798 +
  799 +
  800 +-- == 表【editor_user_conf_logs】建视图语句 ==
  801 +-- drop view view_editor_user_conf_logs;
  802 +DO $$
  803 +BEGIN
  804 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_conf_logs') THEN
  805 + -- 如果存在就删除视图
  806 +DROP VIEW view_editor_user_conf_logs;
  807 +RAISE NOTICE '视图已删除';
  808 +ELSE
  809 + RAISE NOTICE '视图不存在';
  810 +END IF;
  811 +END $$;
  812 +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;
  813 +-- pk
  814 +-- jsonb
  815 +
  816 +
  817 +-- == 表【editor_module_confs】建视图语句 ==
  818 +-- drop view view_editor_module_confs;
  819 +DO $$
  820 +BEGIN
  821 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_module_confs') THEN
  822 + -- 如果存在就删除视图
  823 +DROP VIEW view_editor_module_confs;
  824 +RAISE NOTICE '视图已删除';
  825 +ELSE
  826 + RAISE NOTICE '视图不存在';
  827 +END IF;
  828 +END $$;
  829 +create view view_editor_module_confs as select id,name,report_id,is_checked,uri,created_at,updated_at from editor_module_confs;
  830 +-- pk
  831 +-- jsonb
  832 +
  833 +
  834 +-- == 表【editor_report_confs】建视图语句 ==
  835 +-- drop view view_editor_report_confs;
  836 +DO $$
  837 +BEGIN
  838 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_report_confs') THEN
  839 + -- 如果存在就删除视图
  840 +DROP VIEW view_editor_report_confs;
  841 +RAISE NOTICE '视图已删除';
  842 +ELSE
  843 + RAISE NOTICE '视图不存在';
  844 +END IF;
  845 +END $$;
  846 +create view view_editor_report_confs as select id,name,platform_id,created_at,updated_at,permission_flag from editor_report_confs;
  847 +-- pk
  848 +-- jsonb
  849 +
  850 +
  851 +-- == 表【operate_rules】建视图语句 ==
  852 +-- drop view view_operate_rules;
  853 +DO $$
  854 +BEGIN
  855 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_operate_rules') THEN
  856 + -- 如果存在就删除视图
  857 +DROP VIEW view_operate_rules;
  858 +RAISE NOTICE '视图已删除';
  859 +ELSE
  860 + RAISE NOTICE '视图不存在';
  861 +END IF;
  862 +END $$;
  863 +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;
  864 +-- pk operate_rule_id
  865 +-- jsonb
  866 +
  867 +
  868 +-- == 表【share_customer_expenses】建视图语句 ==
  869 +-- drop view view_share_customer_expenses;
  870 +DO $$
  871 +BEGIN
  872 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_share_customer_expenses') THEN
  873 + -- 如果存在就删除视图
  874 +DROP VIEW view_share_customer_expenses;
  875 +RAISE NOTICE '视图已删除';
  876 +ELSE
  877 + RAISE NOTICE '视图不存在';
  878 +END IF;
  879 +END $$;
  880 +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;
  881 +-- pk share_customer_expenses_id
  882 +-- jsonb
  883 +
  884 +
  885 +-- == 表【customer_comparisons】建视图语句 ==
  886 +-- drop view view_customer_comparisons;
  887 +DO $$
  888 +BEGIN
  889 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_comparisons') THEN
  890 + -- 如果存在就删除视图
  891 +DROP VIEW view_customer_comparisons;
  892 +RAISE NOTICE '视图已删除';
  893 +ELSE
  894 + RAISE NOTICE '视图不存在';
  895 +END IF;
  896 +END $$;
  897 +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;
  898 +-- pk customer_comparison_id
  899 +-- jsonb
  900 +
  901 +
  902 +-- == 表【employee_relations】建视图语句 ==
  903 +-- drop view view_employee_relations;
  904 +DO $$
  905 +BEGIN
  906 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_employee_relations') THEN
  907 + -- 如果存在就删除视图
  908 +DROP VIEW view_employee_relations;
  909 +RAISE NOTICE '视图已删除';
  910 +ELSE
  911 + RAISE NOTICE '视图不存在';
  912 +END IF;
  913 +END $$;
  914 +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;
  915 +-- pk employee_relations_id
  916 +-- jsonb
  917 +
  918 +
  919 +-- == 表【regular_employee】建视图语句 ==
  920 +-- drop view view_regular_employee;
  921 +DO $$
  922 +BEGIN
  923 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regular_employee') THEN
  924 + -- 如果存在就删除视图
  925 +DROP VIEW view_regular_employee;
  926 +RAISE NOTICE '视图已删除';
  927 +ELSE
  928 + RAISE NOTICE '视图不存在';
  929 +END IF;
  930 +END $$;
  931 +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;
  932 +-- pk regular_employee_id
  933 +-- jsonb
  934 +
  935 +
  936 +-- == 表【regional_ownerships】建视图语句 ==
  937 +-- drop view view_regional_ownerships;
  938 +DO $$
  939 +BEGIN
  940 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regional_ownerships') THEN
  941 + -- 如果存在就删除视图
  942 +DROP VIEW view_regional_ownerships;
  943 +RAISE NOTICE '视图已删除';
  944 +ELSE
  945 + RAISE NOTICE '视图不存在';
  946 +END IF;
  947 +END $$;
  948 +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;
  949 +-- pk regional_ownerships_id
  950 +-- jsonb
  951 +
  952 +
  953 +-- == 表【offline_expenses】建视图语句 ==
  954 +-- drop view view_offline_expenses;
  955 +DO $$
  956 +BEGIN
  957 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_offline_expenses') THEN
  958 + -- 如果存在就删除视图
  959 +DROP VIEW view_offline_expenses;
  960 +RAISE NOTICE '视图已删除';
  961 +ELSE
  962 + RAISE NOTICE '视图不存在';
  963 +END IF;
  964 +END $$;
  965 +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;
  966 +-- pk project_cost_id
  967 +-- jsonb operator
  968 +
  969 +
  1 +-- == 表【area_rel_expireds】建视图语句 ==
  2 +-- drop view view_area_rel_expireds;
  3 +DO $$
  4 +BEGIN
  5 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_rel_expireds') THEN
  6 + -- 如果存在就删除视图
  7 + DROP VIEW view_area_rel_expireds;
  8 + RAISE NOTICE '视图已删除';
  9 + ELSE
  10 + RAISE NOTICE '视图不存在';
  11 + END IF;
  12 +END $$;
  13 +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;
  14 +-- pk
  15 +-- jsonb
  16 +
  17 +
  18 +-- == 表【belonging_regions】建视图语句 ==
  19 +-- drop view view_belonging_regions;
  20 +DO $$
  21 +BEGIN
  22 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_belonging_regions') THEN
  23 + -- 如果存在就删除视图
  24 + DROP VIEW view_belonging_regions;
  25 + RAISE NOTICE '视图已删除';
  26 + ELSE
  27 + RAISE NOTICE '视图不存在';
  28 + END IF;
  29 +END $$;
  30 +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;
  31 +-- pk belonging_region_id
  32 +-- jsonb operator,areas
  33 +
  34 +
  35 +-- == 表【area_belongs】建视图语句 ==
  36 +-- drop view view_area_belongs;
  37 +DO $$
  38 +BEGIN
  39 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_belongs') THEN
  40 + -- 如果存在就删除视图
  41 + DROP VIEW view_area_belongs;
  42 + RAISE NOTICE '视图已删除';
  43 + ELSE
  44 + RAISE NOTICE '视图不存在';
  45 + END IF;
  46 +END $$;
  47 +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;
  48 +-- pk area_belong_id
  49 +-- jsonb
  50 +
  51 +
  52 +-- == 表【area_categorys】建视图语句 ==
  53 +-- drop view view_area_categorys;
  54 +DO $$
  55 +BEGIN
  56 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_categorys') THEN
  57 + -- 如果存在就删除视图
  58 + DROP VIEW view_area_categorys;
  59 + RAISE NOTICE '视图已删除';
  60 + ELSE
  61 + RAISE NOTICE '视图不存在';
  62 + END IF;
  63 +END $$;
  64 +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;
  65 +-- pk
  66 +-- jsonb
  67 +
  68 +
  69 +-- == 表【channels】建视图语句 ==
  70 +-- drop view view_channels;
  71 +DO $$
  72 +BEGIN
  73 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_channels') THEN
  74 + -- 如果存在就删除视图
  75 + DROP VIEW view_channels;
  76 + RAISE NOTICE '视图已删除';
  77 + ELSE
  78 + RAISE NOTICE '视图不存在';
  79 + END IF;
  80 +END $$;
  81 +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;
  82 +-- pk channel_id
  83 +-- jsonb operator
  84 +
  85 +
  86 +-- == 表【chart_style_configs】建视图语句 ==
  87 +-- drop view view_chart_style_configs;
  88 +DO $$
  89 +BEGIN
  90 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_chart_style_configs') THEN
  91 + -- 如果存在就删除视图
  92 + DROP VIEW view_chart_style_configs;
  93 + RAISE NOTICE '视图已删除';
  94 + ELSE
  95 + RAISE NOTICE '视图不存在';
  96 + END IF;
  97 +END $$;
  98 +create view view_chart_style_configs as select id,conf,module,created_at,updated_at,data_conf from chart_style_configs;
  99 +-- pk
  100 +-- jsonb
  101 +
  102 +
  103 +-- == 表【corresponding_period】建视图语句 ==
  104 +-- drop view view_corresponding_period;
  105 +DO $$
  106 +BEGIN
  107 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_period') THEN
  108 + -- 如果存在就删除视图
  109 + DROP VIEW view_corresponding_period;
  110 + RAISE NOTICE '视图已删除';
  111 + ELSE
  112 + RAISE NOTICE '视图不存在';
  113 + END IF;
  114 +END $$;
  115 +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;
  116 +-- pk saleman_id
  117 +-- jsonb
  118 +
  119 +
  120 +-- == 表【change_logs】建视图语句 ==
  121 +-- drop view view_change_logs;
  122 +DO $$
  123 +BEGIN
  124 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_change_logs') THEN
  125 + -- 如果存在就删除视图
  126 + DROP VIEW view_change_logs;
  127 + RAISE NOTICE '视图已删除';
  128 + ELSE
  129 + RAISE NOTICE '视图不存在';
  130 + END IF;
  131 +END $$;
  132 +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;
  133 +-- pk change_log_id
  134 +-- jsonb change_log_content,operator
  135 +
  136 +
  137 +-- == 表【custom_relation_templates】建视图语句 ==
  138 +-- drop view view_custom_relation_templates;
  139 +DO $$
  140 +BEGIN
  141 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_templates') THEN
  142 + -- 如果存在就删除视图
  143 + DROP VIEW view_custom_relation_templates;
  144 + RAISE NOTICE '视图已删除';
  145 + ELSE
  146 + RAISE NOTICE '视图不存在';
  147 + END IF;
  148 +END $$;
  149 +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;
  150 +-- pk
  151 +-- jsonb relation_target,share_target
  152 +
  153 +
  154 +-- == 表【custom_relations】建视图语句 ==
  155 +-- drop view view_custom_relations;
  156 +DO $$
  157 +BEGIN
  158 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relations') THEN
  159 + -- 如果存在就删除视图
  160 + DROP VIEW view_custom_relations;
  161 + RAISE NOTICE '视图已删除';
  162 + ELSE
  163 + RAISE NOTICE '视图不存在';
  164 + END IF;
  165 +END $$;
  166 +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;
  167 +-- pk
  168 +-- jsonb areas
  169 +
  170 +
  171 +-- == 表【customer_rels】建视图语句 ==
  172 +-- drop view view_customer_rels;
  173 +DO $$
  174 +BEGIN
  175 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rels') THEN
  176 + -- 如果存在就删除视图
  177 + DROP VIEW view_customer_rels;
  178 + RAISE NOTICE '视图已删除';
  179 + ELSE
  180 + RAISE NOTICE '视图不存在';
  181 + END IF;
  182 +END $$;
  183 +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;
  184 +-- pk customer_rel_id
  185 +-- jsonb operator
  186 +
  187 +
  188 +-- == 表【customer_rewards】建视图语句 ==
  189 +-- drop view view_customer_rewards;
  190 +DO $$
  191 +BEGIN
  192 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rewards') THEN
  193 + -- 如果存在就删除视图
  194 + DROP VIEW view_customer_rewards;
  195 + RAISE NOTICE '视图已删除';
  196 + ELSE
  197 + RAISE NOTICE '视图不存在';
  198 + END IF;
  199 +END $$;
  200 +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;
  201 +-- pk customer_reward_id
  202 +-- jsonb operator
  203 +
  204 +
  205 +-- == 表【customers】建视图语句 ==
  206 +-- drop view view_customers;
  207 +DO $$
  208 +BEGIN
  209 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customers') THEN
  210 + -- 如果存在就删除视图
  211 + DROP VIEW view_customers;
  212 + RAISE NOTICE '视图已删除';
  213 + ELSE
  214 + RAISE NOTICE '视图不存在';
  215 + END IF;
  216 +END $$;
  217 +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;
  218 +-- pk customer_id
  219 +-- jsonb operator
  220 +
  221 +
  222 +-- == 表【matched_relations】建视图语句 ==
  223 +-- drop view view_matched_relations;
  224 +DO $$
  225 +BEGIN
  226 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_matched_relations') THEN
  227 + -- 如果存在就删除视图
  228 + DROP VIEW view_matched_relations;
  229 + RAISE NOTICE '视图已删除';
  230 + ELSE
  231 + RAISE NOTICE '视图不存在';
  232 + END IF;
  233 +END $$;
  234 +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;
  235 +-- pk matched_relation_id
  236 +-- jsonb matched_fields,operator
  237 +
  238 +
  239 +-- == 表【notice_messages】建视图语句 ==
  240 +-- drop view view_notice_messages;
  241 +DO $$
  242 +BEGIN
  243 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_notice_messages') THEN
  244 + -- 如果存在就删除视图
  245 + DROP VIEW view_notice_messages;
  246 + RAISE NOTICE '视图已删除';
  247 + ELSE
  248 + RAISE NOTICE '视图不存在';
  249 + END IF;
  250 +END $$;
  251 +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;
  252 +-- pk notice_message_id
  253 +-- jsonb operator
  254 +
  255 +
  256 +-- == 表【performances】建视图语句 ==
  257 +-- drop view view_performances;
  258 +DO $$
  259 +BEGIN
  260 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_performances') THEN
  261 + -- 如果存在就删除视图
  262 + DROP VIEW view_performances;
  263 + RAISE NOTICE '视图已删除';
  264 + ELSE
  265 + RAISE NOTICE '视图不存在';
  266 + END IF;
  267 +END $$;
  268 +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;
  269 +-- pk performance_id
  270 +-- jsonb
  271 +
  272 +
  273 +-- == 表【product_belongs】建视图语句 ==
  274 +-- drop view view_product_belongs;
  275 +DO $$
  276 +BEGIN
  277 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_belongs') THEN
  278 + -- 如果存在就删除视图
  279 + DROP VIEW view_product_belongs;
  280 + RAISE NOTICE '视图已删除';
  281 + ELSE
  282 + RAISE NOTICE '视图不存在';
  283 + END IF;
  284 +END $$;
  285 +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;
  286 +-- pk product_belong_id
  287 +-- jsonb
  288 +
  289 +
  290 +-- == 表【corresponding_profit】建视图语句 ==
  291 +-- drop view view_corresponding_profit;
  292 +DO $$
  293 +BEGIN
  294 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_profit') THEN
  295 + -- 如果存在就删除视图
  296 + DROP VIEW view_corresponding_profit;
  297 + RAISE NOTICE '视图已删除';
  298 + ELSE
  299 + RAISE NOTICE '视图不存在';
  300 + END IF;
  301 +END $$;
  302 +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;
  303 +-- pk saleman_id
  304 +-- jsonb
  305 +
  306 +
  307 +-- == 表【custom_relation_historys】建视图语句 ==
  308 +-- drop view view_custom_relation_historys;
  309 +DO $$
  310 +BEGIN
  311 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_historys') THEN
  312 + -- 如果存在就删除视图
  313 + DROP VIEW view_custom_relation_historys;
  314 + RAISE NOTICE '视图已删除';
  315 + ELSE
  316 + RAISE NOTICE '视图不存在';
  317 + END IF;
  318 +END $$;
  319 +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;
  320 +-- pk
  321 +-- jsonb body_data,head_field
  322 +
  323 +
  324 +-- == 表【product_rel_expireds】建视图语句 ==
  325 +-- drop view view_product_rel_expireds;
  326 +DO $$
  327 +BEGIN
  328 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rel_expireds') THEN
  329 + -- 如果存在就删除视图
  330 + DROP VIEW view_product_rel_expireds;
  331 + RAISE NOTICE '视图已删除';
  332 + ELSE
  333 + RAISE NOTICE '视图不存在';
  334 + END IF;
  335 +END $$;
  336 +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;
  337 +-- pk product_id
  338 +-- jsonb
  339 +
  340 +
  341 +-- == 表【product_rels】建视图语句 ==
  342 +-- drop view view_product_rels;
  343 +DO $$
  344 +BEGIN
  345 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rels') THEN
  346 + -- 如果存在就删除视图
  347 + DROP VIEW view_product_rels;
  348 + RAISE NOTICE '视图已删除';
  349 + ELSE
  350 + RAISE NOTICE '视图不存在';
  351 + END IF;
  352 +END $$;
  353 +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;
  354 +-- pk product_rel_id
  355 +-- jsonb
  356 +
  357 +
  358 +-- == 表【product_categorys】建视图语句 ==
  359 +-- drop view view_product_categorys;
  360 +DO $$
  361 +BEGIN
  362 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_categorys') THEN
  363 + -- 如果存在就删除视图
  364 + DROP VIEW view_product_categorys;
  365 + RAISE NOTICE '视图已删除';
  366 + ELSE
  367 + RAISE NOTICE '视图不存在';
  368 + END IF;
  369 +END $$;
  370 +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;
  371 +-- pk product_category_id
  372 +-- jsonb
  373 +
  374 +
  375 +-- == 表【product_costs】建视图语句 ==
  376 +-- drop view view_product_costs;
  377 +DO $$
  378 +BEGIN
  379 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_costs') THEN
  380 + -- 如果存在就删除视图
  381 + DROP VIEW view_product_costs;
  382 + RAISE NOTICE '视图已删除';
  383 + ELSE
  384 + RAISE NOTICE '视图不存在';
  385 + END IF;
  386 +END $$;
  387 +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;
  388 +-- pk product_cost_id
  389 +-- jsonb operator
  390 +
  391 +
  392 +-- == 表【profits】建视图语句 ==
  393 +-- drop view view_profits;
  394 +DO $$
  395 +BEGIN
  396 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_profits') THEN
  397 + -- 如果存在就删除视图
  398 + DROP VIEW view_profits;
  399 + RAISE NOTICE '视图已删除';
  400 + ELSE
  401 + RAISE NOTICE '视图不存在';
  402 + END IF;
  403 +END $$;
  404 +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;
  405 +-- pk profit_id
  406 +-- jsonb
  407 +
  408 +
  409 +-- == 表【products】建视图语句 ==
  410 +-- drop view view_products;
  411 +DO $$
  412 +BEGIN
  413 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_products') THEN
  414 + -- 如果存在就删除视图
  415 + DROP VIEW view_products;
  416 + RAISE NOTICE '视图已删除';
  417 + ELSE
  418 + RAISE NOTICE '视图不存在';
  419 + END IF;
  420 +END $$;
  421 +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;
  422 +-- pk product_id
  423 +-- jsonb operator
  424 +
  425 +
  426 +-- == 表【region_rel_expireds】建视图语句 ==
  427 +-- drop view view_region_rel_expireds;
  428 +DO $$
  429 +BEGIN
  430 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rel_expireds') THEN
  431 + -- 如果存在就删除视图
  432 + DROP VIEW view_region_rel_expireds;
  433 + RAISE NOTICE '视图已删除';
  434 + ELSE
  435 + RAISE NOTICE '视图不存在';
  436 + END IF;
  437 +END $$;
  438 +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;
  439 +-- pk region_id
  440 +-- jsonb
  441 +
  442 +
  443 +-- == 表【region_rels】建视图语句 ==
  444 +-- drop view view_region_rels;
  445 +DO $$
  446 +BEGIN
  447 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rels') THEN
  448 + -- 如果存在就删除视图
  449 + DROP VIEW view_region_rels;
  450 + RAISE NOTICE '视图已删除';
  451 + ELSE
  452 + RAISE NOTICE '视图不存在';
  453 + END IF;
  454 +END $$;
  455 +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;
  456 +-- pk region_rel_id
  457 +-- jsonb
  458 +
  459 +
  460 +-- == 表【responsible_salesmans】建视图语句 ==
  461 +-- drop view view_responsible_salesmans;
  462 +DO $$
  463 +BEGIN
  464 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_responsible_salesmans') THEN
  465 + -- 如果存在就删除视图
  466 + DROP VIEW view_responsible_salesmans;
  467 + RAISE NOTICE '视图已删除';
  468 + ELSE
  469 + RAISE NOTICE '视图不存在';
  470 + END IF;
  471 +END $$;
  472 +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;
  473 +-- pk responsible_salesman_id
  474 +-- jsonb operator
  475 +
  476 +
  477 +-- == 表【sales_details】建视图语句 ==
  478 +-- drop view view_sales_details;
  479 +DO $$
  480 +BEGIN
  481 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_details') THEN
  482 + -- 如果存在就删除视图
  483 + DROP VIEW view_sales_details;
  484 + RAISE NOTICE '视图已删除';
  485 + ELSE
  486 + RAISE NOTICE '视图不存在';
  487 + END IF;
  488 +END $$;
  489 +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;
  490 +-- pk sales_detail_id
  491 +-- jsonb
  492 +
  493 +
  494 +-- == 表【sales_methods】建视图语句 ==
  495 +-- drop view view_sales_methods;
  496 +DO $$
  497 +BEGIN
  498 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_methods') THEN
  499 + -- 如果存在就删除视图
  500 + DROP VIEW view_sales_methods;
  501 + RAISE NOTICE '视图已删除';
  502 + ELSE
  503 + RAISE NOTICE '视图不存在';
  504 + END IF;
  505 +END $$;
  506 +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;
  507 +-- pk
  508 +-- jsonb operator
  509 +
  510 +
  511 +-- == 表【salesman_rels】建视图语句 ==
  512 +-- drop view view_salesman_rels;
  513 +DO $$
  514 +BEGIN
  515 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesman_rels') THEN
  516 + -- 如果存在就删除视图
  517 + DROP VIEW view_salesman_rels;
  518 + RAISE NOTICE '视图已删除';
  519 + ELSE
  520 + RAISE NOTICE '视图不存在';
  521 + END IF;
  522 +END $$;
  523 +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;
  524 +-- pk salesman_rel_id
  525 +-- jsonb operator
  526 +
  527 +
  528 +-- == 表【salesmans】建视图语句 ==
  529 +-- drop view view_salesmans;
  530 +DO $$
  531 +BEGIN
  532 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesmans') THEN
  533 + -- 如果存在就删除视图
  534 + DROP VIEW view_salesmans;
  535 + RAISE NOTICE '视图已删除';
  536 + ELSE
  537 + RAISE NOTICE '视图不存在';
  538 + END IF;
  539 +END $$;
  540 +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;
  541 +-- pk salesman_id
  542 +-- jsonb operator
  543 +
  544 +
  545 +-- == 表【solution_groups】建视图语句 ==
  546 +-- drop view view_solution_groups;
  547 +DO $$
  548 +BEGIN
  549 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solution_groups') THEN
  550 + -- 如果存在就删除视图
  551 + DROP VIEW view_solution_groups;
  552 + RAISE NOTICE '视图已删除';
  553 + ELSE
  554 + RAISE NOTICE '视图不存在';
  555 + END IF;
  556 +END $$;
  557 +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;
  558 +-- pk solution_group_id
  559 +-- jsonb operator
  560 +
  561 +
  562 +-- == 表【solutions】建视图语句 ==
  563 +-- drop view view_solutions;
  564 +DO $$
  565 +BEGIN
  566 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solutions') THEN
  567 + -- 如果存在就删除视图
  568 + DROP VIEW view_solutions;
  569 + RAISE NOTICE '视图已删除';
  570 + ELSE
  571 + RAISE NOTICE '视图不存在';
  572 + END IF;
  573 +END $$;
  574 +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;
  575 +-- pk solution_id
  576 +-- jsonb operator,compute_items,salesmen
  577 +
  578 +
  579 +-- == 表【project_costs】建视图语句 ==
  580 +-- drop view view_project_costs;
  581 +DO $$
  582 +BEGIN
  583 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_project_costs') THEN
  584 + -- 如果存在就删除视图
  585 + DROP VIEW view_project_costs;
  586 + RAISE NOTICE '视图已删除';
  587 + ELSE
  588 + RAISE NOTICE '视图不存在';
  589 + END IF;
  590 +END $$;
  591 +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;
  592 +-- pk project_cost_id
  593 +-- jsonb operator
  594 +
  595 +
  596 +-- == 表【region_belongs】建视图语句 ==
  597 +-- drop view view_region_belongs;
  598 +DO $$
  599 +BEGIN
  600 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_belongs') THEN
  601 + -- 如果存在就删除视图
  602 + DROP VIEW view_region_belongs;
  603 + RAISE NOTICE '视图已删除';
  604 + ELSE
  605 + RAISE NOTICE '视图不存在';
  606 + END IF;
  607 +END $$;
  608 +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;
  609 +-- pk region_belong_id
  610 +-- jsonb
  611 +
  612 +
  613 +-- == 表【region_categorys】建视图语句 ==
  614 +-- drop view view_region_categorys;
  615 +DO $$
  616 +BEGIN
  617 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_categorys') THEN
  618 + -- 如果存在就删除视图
  619 + DROP VIEW view_region_categorys;
  620 + RAISE NOTICE '视图已删除';
  621 + ELSE
  622 + RAISE NOTICE '视图不存在';
  623 + END IF;
  624 +END $$;
  625 +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;
  626 +-- pk region_category_id
  627 +-- jsonb
  628 +
  629 +
  630 +-- == 表【region_salesmans】建视图语句 ==
  631 +-- drop view view_region_salesmans;
  632 +DO $$
  633 +BEGIN
  634 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_salesmans') THEN
  635 + -- 如果存在就删除视图
  636 + DROP VIEW view_region_salesmans;
  637 + RAISE NOTICE '视图已删除';
  638 + ELSE
  639 + RAISE NOTICE '视图不存在';
  640 + END IF;
  641 +END $$;
  642 +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;
  643 +-- pk region_salesman_id
  644 +-- jsonb
  645 +
  646 +
  647 +-- == 表【regions】建视图语句 ==
  648 +-- drop view view_regions;
  649 +DO $$
  650 +BEGIN
  651 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regions') THEN
  652 + -- 如果存在就删除视图
  653 + DROP VIEW view_regions;
  654 + RAISE NOTICE '视图已删除';
  655 + ELSE
  656 + RAISE NOTICE '视图不存在';
  657 + END IF;
  658 +END $$;
  659 +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;
  660 +-- pk region_id
  661 +-- jsonb operator
  662 +
  663 +
  664 +-- == 表【superior_responsible_persons】建视图语句 ==
  665 +-- drop view view_superior_responsible_persons;
  666 +DO $$
  667 +BEGIN
  668 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_responsible_persons') THEN
  669 + -- 如果存在就删除视图
  670 + DROP VIEW view_superior_responsible_persons;
  671 + RAISE NOTICE '视图已删除';
  672 + ELSE
  673 + RAISE NOTICE '视图不存在';
  674 + END IF;
  675 +END $$;
  676 +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;
  677 +-- pk superior_responsible_person_id
  678 +-- jsonb operator
  679 +
  680 +
  681 +-- == 表【type_tags】建视图语句 ==
  682 +-- drop view view_type_tags;
  683 +DO $$
  684 +BEGIN
  685 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_type_tags') THEN
  686 + -- 如果存在就删除视图
  687 + DROP VIEW view_type_tags;
  688 + RAISE NOTICE '视图已删除';
  689 + ELSE
  690 + RAISE NOTICE '视图不存在';
  691 + END IF;
  692 +END $$;
  693 +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;
  694 +-- pk type_tag_id
  695 +-- jsonb operator
  696 +
  697 +
  698 +-- == 表【editor_module_confs】建视图语句 ==
  699 +-- drop view view_editor_module_confs;
  700 +DO $$
  701 +BEGIN
  702 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_module_confs') THEN
  703 + -- 如果存在就删除视图
  704 + DROP VIEW view_editor_module_confs;
  705 + RAISE NOTICE '视图已删除';
  706 + ELSE
  707 + RAISE NOTICE '视图不存在';
  708 + END IF;
  709 +END $$;
  710 +create view view_editor_module_confs as select id,name,report_id,is_checked,uri,created_at,updated_at from editor_module_confs;
  711 +-- pk
  712 +-- jsonb
  713 +
  714 +
  715 +-- == 表【editor_user_conf_logs】建视图语句 ==
  716 +-- drop view view_editor_user_conf_logs;
  717 +DO $$
  718 +BEGIN
  719 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_conf_logs') THEN
  720 + -- 如果存在就删除视图
  721 + DROP VIEW view_editor_user_conf_logs;
  722 + RAISE NOTICE '视图已删除';
  723 + ELSE
  724 + RAISE NOTICE '视图不存在';
  725 + END IF;
  726 +END $$;
  727 +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;
  728 +-- pk
  729 +-- jsonb
  730 +
  731 +
  732 +-- == 表【product_shares】建视图语句 ==
  733 +-- drop view view_product_shares;
  734 +DO $$
  735 +BEGIN
  736 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_shares') THEN
  737 + -- 如果存在就删除视图
  738 + DROP VIEW view_product_shares;
  739 + RAISE NOTICE '视图已删除';
  740 + ELSE
  741 + RAISE NOTICE '视图不存在';
  742 + END IF;
  743 +END $$;
  744 +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;
  745 +-- pk product_share_id
  746 +-- jsonb operator
  747 +
  748 +
  749 +-- == 表【superior_customers】建视图语句 ==
  750 +-- drop view view_superior_customers;
  751 +DO $$
  752 +BEGIN
  753 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_customers') THEN
  754 + -- 如果存在就删除视图
  755 + DROP VIEW view_superior_customers;
  756 + RAISE NOTICE '视图已删除';
  757 + ELSE
  758 + RAISE NOTICE '视图不存在';
  759 + END IF;
  760 +END $$;
  761 +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;
  762 +-- pk superior_customer_id
  763 +-- jsonb operator
  764 +
  765 +
  766 +-- == 表【editor_report_confs】建视图语句 ==
  767 +-- drop view view_editor_report_confs;
  768 +DO $$
  769 +BEGIN
  770 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_report_confs') THEN
  771 + -- 如果存在就删除视图
  772 + DROP VIEW view_editor_report_confs;
  773 + RAISE NOTICE '视图已删除';
  774 + ELSE
  775 + RAISE NOTICE '视图不存在';
  776 + END IF;
  777 +END $$;
  778 +create view view_editor_report_confs as select id,name,platform_id,created_at,updated_at,permission_flag from editor_report_confs;
  779 +-- pk
  780 +-- jsonb
  781 +
  782 +
  783 +-- == 表【areas】建视图语句 ==
  784 +-- drop view view_areas;
  785 +DO $$
  786 +BEGIN
  787 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_areas') THEN
  788 + -- 如果存在就删除视图
  789 + DROP VIEW view_areas;
  790 + RAISE NOTICE '视图已删除';
  791 + ELSE
  792 + RAISE NOTICE '视图不存在';
  793 + END IF;
  794 +END $$;
  795 +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;
  796 +-- pk
  797 +-- jsonb
  798 +
  799 +
  800 +-- == 表【editor_chart_confs】建视图语句 ==
  801 +-- drop view view_editor_chart_confs;
  802 +DO $$
  803 +BEGIN
  804 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_chart_confs') THEN
  805 + -- 如果存在就删除视图
  806 + DROP VIEW view_editor_chart_confs;
  807 + RAISE NOTICE '视图已删除';
  808 + ELSE
  809 + RAISE NOTICE '视图不存在';
  810 + END IF;
  811 +END $$;
  812 +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;
  813 +-- pk
  814 +-- jsonb
  815 +
  816 +
  817 +-- == 表【editor_user_chart_conf】建视图语句 ==
  818 +-- drop view view_editor_user_chart_conf;
  819 +DO $$
  820 +BEGIN
  821 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_chart_conf') THEN
  822 + -- 如果存在就删除视图
  823 + DROP VIEW view_editor_user_chart_conf;
  824 + RAISE NOTICE '视图已删除';
  825 + ELSE
  826 + RAISE NOTICE '视图不存在';
  827 + END IF;
  828 +END $$;
  829 +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;
  830 +-- pk editor_user_chart_conf_id
  831 +-- jsonb
  832 +
  833 +
  834 +-- == 表【users】建视图语句 ==
  835 +-- drop view view_users;
  836 +DO $$
  837 +BEGIN
  838 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_users') THEN
  839 + -- 如果存在就删除视图
  840 + DROP VIEW view_users;
  841 + RAISE NOTICE '视图已删除';
  842 + ELSE
  843 + RAISE NOTICE '视图不存在';
  844 + END IF;
  845 +END $$;
  846 +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;
  847 +-- pk user_id
  848 +-- jsonb
  849 +
  850 +
  851 +-- == 表【offline_expenses】建视图语句 ==
  852 +-- drop view view_offline_expenses;
  853 +DO $$
  854 +BEGIN
  855 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_offline_expenses') THEN
  856 + -- 如果存在就删除视图
  857 + DROP VIEW view_offline_expenses;
  858 + RAISE NOTICE '视图已删除';
  859 + ELSE
  860 + RAISE NOTICE '视图不存在';
  861 + END IF;
  862 +END $$;
  863 +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;
  864 +-- pk project_cost_id
  865 +-- jsonb operator
  866 +
  867 +
  868 +-- == 表【regular_employee】建视图语句 ==
  869 +-- drop view view_regular_employee;
  870 +DO $$
  871 +BEGIN
  872 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regular_employee') THEN
  873 + -- 如果存在就删除视图
  874 + DROP VIEW view_regular_employee;
  875 + RAISE NOTICE '视图已删除';
  876 + ELSE
  877 + RAISE NOTICE '视图不存在';
  878 + END IF;
  879 +END $$;
  880 +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;
  881 +-- pk regular_employee_id
  882 +-- jsonb
  883 +
  884 +
  885 +-- == 表【employee_relations】建视图语句 ==
  886 +-- drop view view_employee_relations;
  887 +DO $$
  888 +BEGIN
  889 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_employee_relations') THEN
  890 + -- 如果存在就删除视图
  891 + DROP VIEW view_employee_relations;
  892 + RAISE NOTICE '视图已删除';
  893 + ELSE
  894 + RAISE NOTICE '视图不存在';
  895 + END IF;
  896 +END $$;
  897 +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;
  898 +-- pk employee_relations_id
  899 +-- jsonb
  900 +
  901 +
  902 +-- == 表【operate_rules】建视图语句 ==
  903 +-- drop view view_operate_rules;
  904 +DO $$
  905 +BEGIN
  906 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_operate_rules') THEN
  907 + -- 如果存在就删除视图
  908 + DROP VIEW view_operate_rules;
  909 + RAISE NOTICE '视图已删除';
  910 + ELSE
  911 + RAISE NOTICE '视图不存在';
  912 + END IF;
  913 +END $$;
  914 +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;
  915 +-- pk operate_rule_id
  916 +-- jsonb
  917 +
  918 +
  919 +-- == 表【share_customer_expenses】建视图语句 ==
  920 +-- drop view view_share_customer_expenses;
  921 +DO $$
  922 +BEGIN
  923 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_share_customer_expenses') THEN
  924 + -- 如果存在就删除视图
  925 + DROP VIEW view_share_customer_expenses;
  926 + RAISE NOTICE '视图已删除';
  927 + ELSE
  928 + RAISE NOTICE '视图不存在';
  929 + END IF;
  930 +END $$;
  931 +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;
  932 +-- pk share_customer_expenses_id
  933 +-- jsonb
  934 +
  935 +
  936 +-- == 表【customer_comparisons】建视图语句 ==
  937 +-- drop view view_customer_comparisons;
  938 +DO $$
  939 +BEGIN
  940 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_comparisons') THEN
  941 + -- 如果存在就删除视图
  942 + DROP VIEW view_customer_comparisons;
  943 + RAISE NOTICE '视图已删除';
  944 + ELSE
  945 + RAISE NOTICE '视图不存在';
  946 + END IF;
  947 +END $$;
  948 +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;
  949 +-- pk customer_comparison_id
  950 +-- jsonb
  951 +
  952 +
  953 +-- == 表【regional_ownerships】建视图语句 ==
  954 +-- drop view view_regional_ownerships;
  955 +DO $$
  956 +BEGIN
  957 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regional_ownerships') THEN
  958 + -- 如果存在就删除视图
  959 + DROP VIEW view_regional_ownerships;
  960 + RAISE NOTICE '视图已删除';
  961 + ELSE
  962 + RAISE NOTICE '视图不存在';
  963 + END IF;
  964 +END $$;
  965 +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;
  966 +-- pk regional_ownerships_id
  967 +-- jsonb
  968 +
  969 +
  1 +-- == 表【files】建视图语句 ==
  2 +drop view view_files;
  3 +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;
  4 +-- pk file_id
  5 +-- jsonb file_info,context
  6 +
  7 +
  8 +-- == 表【mapping_rules】建视图语句 ==
  9 +drop view view_mapping_rules;
  10 +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;
  11 +-- pk mapping_rule_id
  12 +-- jsonb main_table_fields,verified_file_fields,mapping_fields,context
  13 +
  14 +
  15 +-- == 表【logs】建视图语句 ==
  16 +drop view view_logs;
  17 +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;
  18 +-- pk log_id
  19 +-- jsonb entry,context
  20 +
  21 +
  22 +-- == 表【query_sets】建视图语句 ==
  23 +drop view view_query_sets;
  24 +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;
  25 +-- pk query_set_id
  26 +-- jsonb query_set_info,query_components,context
  27 +
  28 +
  29 +-- == 表【query_sets_copy1】建视图语句 ==
  30 +drop view view_query_sets_copy1;
  31 +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;
  32 +-- pk query_set_id
  33 +-- jsonb query_set_info,query_components,context
  34 +
  35 +
  36 +-- == 表【tables】建视图语句 ==
  37 +drop view view_tables;
  38 +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;
  39 +-- pk table_id
  40 +-- jsonb pk,data_fields,manual_fields,context,table_info,order_fields
  41 +
  42 +
@@ -9,3 +9,9 @@ type GenerateBusinessTableViewRequest struct { @@ -9,3 +9,9 @@ type GenerateBusinessTableViewRequest struct {
9 SchemaName string `json:"schemaName,optional,default=public"` // 模式名称 9 SchemaName string `json:"schemaName,optional,default=public"` // 模式名称
10 DBType string `json:"dbType,optional,default=postgresql"` 10 DBType string `json:"dbType,optional,default=postgresql"`
11 } 11 }
  12 +
  13 +type DBTablesRequest struct {
  14 + GenerateBusinessTableViewRequest
  15 + ByteBankDBName string
  16 + ByteBankDBZhName string
  17 +}
@@ -28,7 +28,39 @@ func (tableService *TableService) ShowBusinessDatabases(ctx *domain.Context, cmd @@ -28,7 +28,39 @@ func (tableService *TableService) ShowBusinessDatabases(ctx *domain.Context, cmd
28 return response, err 28 return response, err
29 } 29 }
30 30
  31 +var GlobalDB []command.DBTablesRequest = []command.DBTablesRequest{
  32 + {
  33 + ByteBankDBName: "allied_creation_reporting_system_test.public",
  34 + ByteBankDBZhName: "销导报表系统",
  35 + GenerateBusinessTableViewRequest: command.GenerateBusinessTableViewRequest{
  36 + Host: "114.55.200.59",
  37 + Port: "31543",
  38 + User: "postgres",
  39 + Password: "eagle1010",
  40 + DBName: "allied-creation-reporting-system_test",
  41 + SchemaName: "public",
  42 + DBType: "postgresql",
  43 + },
  44 + },
  45 +}
  46 +
  47 +func getDB(databaseEnName string) (*command.DBTablesRequest, bool) {
  48 + for i := range GlobalDB {
  49 + if GlobalDB[i].ByteBankDBName == databaseEnName {
  50 + return &GlobalDB[i], true
  51 + }
  52 + }
  53 + return nil, false
  54 +}
31 func (tableService *TableService) ShowBusinessTables(ctx *domain.Context, cmd *query.ShowTablesRequest) (interface{}, error) { 55 func (tableService *TableService) ShowBusinessTables(ctx *domain.Context, cmd *query.ShowTablesRequest) (interface{}, error) {
  56 + req, ok := getDB(cmd.DatabaseEnName)
  57 + if !ok {
  58 + return nil, factory.FastError(fmt.Errorf("db " + cmd.DatabaseEnName + "未配置"))
  59 + }
  60 + return DBTables(req)
  61 +}
  62 +
  63 +func (tableService *TableService) ShowBusinessTables1(ctx *domain.Context, cmd *query.ShowTablesRequest) (interface{}, error) {
32 byteCoreService := domainService.ByteCoreService{} 64 byteCoreService := domainService.ByteCoreService{}
33 response, err := byteCoreService.ShowBusinessTables(bytelib.ReqShowBusinessTables{ 65 response, err := byteCoreService.ShowBusinessTables(bytelib.ReqShowBusinessTables{
34 DatabaseEnName: cmd.DatabaseEnName, 66 DatabaseEnName: cmd.DatabaseEnName,
@@ -224,6 +256,11 @@ func (tableService *TableService) GenerateBusinessTable(ctx *domain.Context, cmd @@ -224,6 +256,11 @@ func (tableService *TableService) GenerateBusinessTable(ctx *domain.Context, cmd
224 return nil, nil 256 return nil, nil
225 } 257 }
226 258
  259 +type Field struct {
  260 + Field string `json:"field"`
  261 + Type string `json:"type"`
  262 +}
  263 +
227 func (tableService *TableService) GenerateBusinessTablesView(ctx *domain.Context, cmd *command.GenerateBusinessTableViewRequest) (interface{}, error) { 264 func (tableService *TableService) GenerateBusinessTablesView(ctx *domain.Context, cmd *command.GenerateBusinessTableViewRequest) (interface{}, error) {
228 var ( 265 var (
229 db *gorm.DB 266 db *gorm.DB
@@ -247,10 +284,6 @@ func (tableService *TableService) GenerateBusinessTablesView(ctx *domain.Context @@ -247,10 +284,6 @@ func (tableService *TableService) GenerateBusinessTablesView(ctx *domain.Context
247 if tx := db.Raw(fmt.Sprintf(`select tablename from pg_tables where schemaname='%v';`, cmd.SchemaName)).Scan(&tables); tx.Error != nil { 284 if tx := db.Raw(fmt.Sprintf(`select tablename from pg_tables where schemaname='%v';`, cmd.SchemaName)).Scan(&tables); tx.Error != nil {
248 return nil, factory.FastError(tx.Error) 285 return nil, factory.FastError(tx.Error)
249 } 286 }
250 - type Field struct {  
251 - Field string `json:"field"`  
252 - Type string `json:"type"`  
253 - }  
254 var fields = make([]Field, 0) 287 var fields = make([]Field, 0)
255 for _, t := range tables { 288 for _, t := range tables {
256 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 289 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 { @@ -262,9 +295,15 @@ ORDER BY a.attnum;`, t)).Scan(&fields); tx.Error != nil {
262 var commonFields []string 295 var commonFields []string
263 var jsonbFields []string 296 var jsonbFields []string
264 var pkFields []string 297 var pkFields []string
  298 + var containPkId = false
  299 + for _, f := range fields {
  300 + if f.Field == "id" {
  301 + containPkId = true
  302 + }
  303 + }
265 for index, f := range fields { 304 for index, f := range fields {
266 - if index == 0 && strings.HasSuffix(f.Field, "id") {  
267 - //commonFields = append(commonFields, fmt.Sprintf("%v as id", f.Field)) 305 + if index == 0 && strings.HasSuffix(f.Field, "id") && !containPkId {
  306 + commonFields = append(commonFields, fmt.Sprintf("%v as id", f.Field))
268 pkFields = append(pkFields, f.Field) 307 pkFields = append(pkFields, f.Field)
269 } 308 }
270 if f.Type == "jsonb" || f.Type == "json" { 309 if f.Type == "jsonb" || f.Type == "json" {
@@ -274,7 +313,18 @@ ORDER BY a.attnum;`, t)).Scan(&fields); tx.Error != nil { @@ -274,7 +313,18 @@ ORDER BY a.attnum;`, t)).Scan(&fields); tx.Error != nil {
274 } 313 }
275 } 314 }
276 buf.WriteString(fmt.Sprintf("-- == 表【%v】建视图语句 ==\n", t)) 315 buf.WriteString(fmt.Sprintf("-- == 表【%v】建视图语句 ==\n", t))
277 - buf.WriteString(fmt.Sprintf("drop view view_%v;\n", t)) 316 + buf.WriteString(fmt.Sprintf("-- drop view view_%v;\n", t))
  317 + buf.WriteString(fmt.Sprintf(`DO $$
  318 +BEGIN
  319 + IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_%s') THEN
  320 + -- 如果存在就删除视图
  321 + DROP VIEW view_%s;
  322 + RAISE NOTICE '视图已删除';
  323 + ELSE
  324 + RAISE NOTICE '视图不存在';
  325 + END IF;
  326 +END $$;`, t, t))
  327 + buf.WriteString("\n")
278 buf.WriteString(fmt.Sprintf("create view view_%v as select %v from %v;\n", t, strings.Join(commonFields, ","), t)) 328 buf.WriteString(fmt.Sprintf("create view view_%v as select %v from %v;\n", t, strings.Join(commonFields, ","), t))
279 buf.WriteString(fmt.Sprintf("-- pk %v\n", strings.Join(pkFields, ","))) 329 buf.WriteString(fmt.Sprintf("-- pk %v\n", strings.Join(pkFields, ",")))
280 buf.WriteString(fmt.Sprintf("-- jsonb %v\n", strings.Join(jsonbFields, ","))) 330 buf.WriteString(fmt.Sprintf("-- jsonb %v\n", strings.Join(jsonbFields, ",")))
@@ -284,11 +334,95 @@ ORDER BY a.attnum;`, t)).Scan(&fields); tx.Error != nil { @@ -284,11 +334,95 @@ ORDER BY a.attnum;`, t)).Scan(&fields); tx.Error != nil {
284 } else if cmd.DBType == "mysql" { 334 } else if cmd.DBType == "mysql" {
285 db, err = gorm.Open(mysql.Open(fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local", 335 db, err = gorm.Open(mysql.Open(fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local",
286 cmd.User, cmd.Password, cmd.Host, cmd.Port, cmd.DBName)), &gorm.Config{PrepareStmt: false}) 336 cmd.User, cmd.Password, cmd.Host, cmd.Port, cmd.DBName)), &gorm.Config{PrepareStmt: false})
  337 + if err != nil {
  338 + return nil, factory.FastError(err)
  339 + }
  340 + var tables []string
  341 + if tx := db.Raw(fmt.Sprintf(`show tables;`)).Scan(&tables); tx.Error != nil {
  342 + return nil, factory.FastError(tx.Error)
  343 + }
  344 + var fields = make([]Field, 0)
  345 + for _, t := range tables {
  346 + if tx := db.Raw(fmt.Sprintf(`SHOW COLUMNS FROM %s;`, t)).Scan(&fields); tx.Error != nil {
  347 + return nil, factory.FastError(tx.Error)
  348 + }
  349 + writeToBuf(buf, t, fields)
  350 + }
  351 + generalWrite(cmd.DBName+"_tables_view.sql", buf)
287 } 352 }
288 353
289 return nil, nil 354 return nil, nil
290 } 355 }
291 356
  357 +func DBTables(cmd *command.DBTablesRequest) (interface{}, error) {
  358 + var (
  359 + result = make([]map[string]interface{}, 0)
  360 + tables []string
  361 + db *gorm.DB
  362 + err error
  363 + )
  364 + if cmd.DBType == "postgresql" {
  365 + db, err = gorm.Open(postgres.Open(fmt.Sprintf("user=%v password=%v host=%v port=%v dbname=%v sslmode=disable TimeZone=Asia/Shanghai",
  366 + cmd.User, cmd.Password, cmd.Host, cmd.Port, cmd.DBName)), &gorm.Config{PrepareStmt: false})
  367 + if err != nil {
  368 + return nil, factory.FastError(err)
  369 + }
  370 + if tx := db.Raw(fmt.Sprintf(`select tablename from pg_tables where schemaname='%v';`, cmd.SchemaName)).Scan(&tables); tx.Error != nil {
  371 + return nil, factory.FastError(tx.Error)
  372 + }
  373 + } else if cmd.DBType == "mysql" {
  374 + db, err = gorm.Open(mysql.Open(fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local",
  375 + cmd.User, cmd.Password, cmd.Host, cmd.Port, cmd.DBName)), &gorm.Config{PrepareStmt: false})
  376 + if err != nil {
  377 + return nil, factory.FastError(err)
  378 + }
  379 + if tx := db.Raw(fmt.Sprintf(`show tables;`)).Scan(&tables); tx.Error != nil {
  380 + return nil, factory.FastError(tx.Error)
  381 + }
  382 + }
  383 + for _, t := range tables {
  384 + viewT := "view_" + t
  385 + result = append(result, map[string]interface{}{
  386 + "name": fmt.Sprintf("%s.%s", cmd.ByteBankDBName, viewT), //返回所有视图 view开头
  387 + "simpleName": viewT,
  388 + })
  389 + }
  390 + return map[string]interface{}{
  391 + "list": result,
  392 + }, nil
  393 +}
  394 +
  395 +func writeToBuf(buf *bytes.Buffer, t string, fields []Field) {
  396 + var commonFields []string
  397 + var jsonbFields []string
  398 + var pkFields []string
  399 + var containPkId = false
  400 + for _, f := range fields {
  401 + if f.Field == "id" {
  402 + containPkId = true
  403 + }
  404 + }
  405 + for index, f := range fields {
  406 + if index == 0 && strings.HasSuffix(f.Field, "id") && !containPkId {
  407 + commonFields = append(commonFields, fmt.Sprintf("%v as id", f.Field))
  408 + pkFields = append(pkFields, f.Field)
  409 + }
  410 + if f.Type == "jsonb" || f.Type == "json" {
  411 + jsonbFields = append(jsonbFields, f.Field)
  412 + } else {
  413 + commonFields = append(commonFields, f.Field)
  414 + }
  415 + }
  416 + buf.WriteString(fmt.Sprintf("-- == 表【%v】建视图语句 ==\n", t))
  417 + buf.WriteString(fmt.Sprintf("-- drop view view_%v;\n", t))
  418 + buf.WriteString(fmt.Sprintf("DROP VIEW IF EXISTS %s;", t))
  419 + buf.WriteString("\n")
  420 + buf.WriteString(fmt.Sprintf("create view view_%v as select %v from %v;\n", t, strings.Join(commonFields, ","), t))
  421 + buf.WriteString(fmt.Sprintf("-- pk %v\n", strings.Join(pkFields, ",")))
  422 + buf.WriteString(fmt.Sprintf("-- jsonb %v\n", strings.Join(jsonbFields, ",")))
  423 + buf.WriteString("\n\n")
  424 +}
  425 +
292 func generalWrite(filename string, buf *bytes.Buffer) { 426 func generalWrite(filename string, buf *bytes.Buffer) {
293 f, err := os.OpenFile(filename, os.O_RDONLY|os.O_CREATE|os.O_APPEND, 0666) 427 f, err := os.OpenFile(filename, os.O_RDONLY|os.O_CREATE|os.O_APPEND, 0666)
294 if err != nil { 428 if err != nil {
  1 +-- == 表【cfg_salary_group】建视图语句 ==
  2 +-- drop view view_cfg_salary_group;
  3 +DROP VIEW IF EXISTS cfg_salary_group;
  4 +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;
  5 +-- pk
  6 +-- jsonb
  7 +
  8 +
  9 +-- == 表【cfg_subject】建视图语句 ==
  10 +-- drop view view_cfg_subject;
  11 +DROP VIEW IF EXISTS cfg_subject;
  12 +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;
  13 +-- pk
  14 +-- jsonb
  15 +
  16 +
  17 +-- == 表【role_income_rule】建视图语句 ==
  18 +-- drop view view_role_income_rule;
  19 +DROP VIEW IF EXISTS role_income_rule;
  20 +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;
  21 +-- pk
  22 +-- jsonb
  23 +
  24 +
  25 +-- == 表【salary_group_income_rule】建视图语句 ==
  26 +-- drop view view_salary_group_income_rule;
  27 +DROP VIEW IF EXISTS salary_group_income_rule;
  28 +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;
  29 +-- pk
  30 +-- jsonb
  31 +
  32 +
  33 +-- == 表【salary_group_rule】建视图语句 ==
  34 +-- drop view view_salary_group_rule;
  35 +DROP VIEW IF EXISTS salary_group_rule;
  36 +create view view_salary_group_rule as select id,subject_id,weight,company_id,create_time,enabled,salary_group_id from salary_group_rule;
  37 +-- pk
  38 +-- jsonb
  39 +
  40 +
  41 +-- == 表【salary_group_user】建视图语句 ==
  42 +-- drop view view_salary_group_user;
  43 +DROP VIEW IF EXISTS salary_group_user;
  44 +create view view_salary_group_user as select id,uid,salary_group_id,company_id,create_time,enabled,department_id from salary_group_user;
  45 +-- pk
  46 +-- jsonb
  47 +
  48 +
  49 +-- == 表【salary_month】建视图语句 ==
  50 +-- drop view view_salary_month;
  51 +DROP VIEW IF EXISTS salary_month;
  52 +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;
  53 +-- pk
  54 +-- jsonb
  55 +
  56 +
  57 +-- == 表【salary_month_history】建视图语句 ==
  58 +-- drop view view_salary_month_history;
  59 +DROP VIEW IF EXISTS salary_month_history;
  60 +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;
  61 +-- pk
  62 +-- jsonb
  63 +
  64 +
  65 +-- == 表【salary_record】建视图语句 ==
  66 +-- drop view view_salary_record;
  67 +DROP VIEW IF EXISTS salary_record;
  68 +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;
  69 +-- pk
  70 +-- jsonb
  71 +
  72 +
  73 +-- == 表【salary_record_history】建视图语句 ==
  74 +-- drop view view_salary_record_history;
  75 +DROP VIEW IF EXISTS salary_record_history;
  76 +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;
  77 +-- pk
  78 +-- jsonb
  79 +
  80 +
  81 +-- == 表【subject_pay_time】建视图语句 ==
  82 +-- drop view view_subject_pay_time;
  83 +DROP VIEW IF EXISTS subject_pay_time;
  84 +create view view_subject_pay_time as select id,subject_id,pay_time,company_id,create_time,enabled from subject_pay_time;
  85 +-- pk
  86 +-- jsonb
  87 +
  88 +
  89 +-- == 表【subject_state】建视图语句 ==
  90 +-- drop view view_subject_state;
  91 +DROP VIEW IF EXISTS subject_state;
  92 +create view view_subject_state as select id,subject_id,type,company_id,create_time,enabled from subject_state;
  93 +-- pk
  94 +-- jsonb
  95 +
  96 +
  97 +-- == 表【view_subject_state】建视图语句 ==
  98 +-- drop view view_view_subject_state;
  99 +DROP VIEW IF EXISTS view_subject_state;
  100 +create view view_view_subject_state as select id,type,company_id from view_subject_state;
  101 +-- pk
  102 +-- jsonb
  103 +
  104 +