allied-creation-reporting-system_test_tables_view.sql
34.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
-- == 表【area_rel_expireds】建视图语句 ==
-- drop view view_area_rel_expireds;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_rel_expireds') THEN
-- 如果存在就删除视图
DROP VIEW view_area_rel_expireds;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_area_rel_expireds as select area_rel_expired_id as id,area_code,latest_update_time,created_at,area_rel_expired_id,remark,module,expired_at,latest_check_at,notice_times from area_rel_expireds;
-- pk
-- jsonb
-- == 表【belonging_regions】建视图语句 ==
-- drop view view_belonging_regions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_belonging_regions') THEN
-- 如果存在就删除视图
DROP VIEW view_belonging_regions;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_belonging_regions as select belonging_region_id as id,belonging_region_id,customer_rel_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,customer_id,area_code,operator_id from belonging_regions;
-- pk belonging_region_id
-- jsonb operator,areas
-- == 表【area_belongs】建视图语句 ==
-- drop view view_area_belongs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_belongs') THEN
-- 如果存在就删除视图
DROP VIEW view_area_belongs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_area_belongs as select area_belong_id as id,area_belong_id,begin_time,created_at,deleted_at,end_time,latest_update_time,updated_at,status,area_code,region_id,operator_id from area_belongs;
-- pk area_belong_id
-- jsonb
-- == 表【area_categorys】建视图语句 ==
-- drop view view_area_categorys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_area_categorys') THEN
-- 如果存在就删除视图
DROP VIEW view_area_categorys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_area_categorys as select area_category_id as id,area_code,area_category_id,category_type,tag,begin_time,created_at,deleted_at,end_time,latest_update_time,updated_at,status,operator_id from area_categorys;
-- pk
-- jsonb
-- == 表【channels】建视图语句 ==
-- drop view view_channels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_channels') THEN
-- 如果存在就删除视图
DROP VIEW view_channels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_channels as select channel_id as id,channel_id,channel_name,status,data_from,created_at,updated_at,deleted_at,latest_update_time from channels;
-- pk channel_id
-- jsonb operator
-- == 表【chart_style_configs】建视图语句 ==
-- drop view view_chart_style_configs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_chart_style_configs') THEN
-- 如果存在就删除视图
DROP VIEW view_chart_style_configs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_chart_style_configs as select id,conf,module,created_at,updated_at,data_conf from chart_style_configs;
-- pk
-- jsonb
-- == 表【corresponding_period】建视图语句 ==
-- drop view view_corresponding_period;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_period') THEN
-- 如果存在就删除视图
DROP VIEW view_corresponding_period;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_corresponding_period as select saleman_id as id,saleman_id,saleman_name,saleman_phone,saleman_year,saleman_month,opportunity,normal from corresponding_period;
-- pk saleman_id
-- jsonb
-- == 表【change_logs】建视图语句 ==
-- drop view view_change_logs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_change_logs') THEN
-- 如果存在就删除视图
DROP VIEW view_change_logs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_change_logs as select change_log_id as id,change_log_id,valid_period_begin,valid_period_end,rel_id,module_id,module,created_at,updated_at,deleted_at,latest_update_time,operator_id from change_logs;
-- pk change_log_id
-- jsonb change_log_content,operator
-- == 表【custom_relation_templates】建视图语句 ==
-- drop view view_custom_relation_templates;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_templates') THEN
-- 如果存在就删除视图
DROP VIEW view_custom_relation_templates;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_custom_relation_templates as select id,relation_main,relation_name,relation_type,is_require,created_at,latest_update_time,deleted_at from custom_relation_templates;
-- pk
-- jsonb relation_target,share_target
-- == 表【custom_relations】建视图语句 ==
-- drop view view_custom_relations;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relations') THEN
-- 如果存在就删除视图
DROP VIEW view_custom_relations;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_custom_relations as select id,relation_name,relation_main,relation_main_id,customer_id,product_id,channel_id,salesman_id,begin_time,end_time,area_code,regin_id,group_id,shared_value,shared_object,relation_object,operater_id,template_id,created_at,latest_update_time,deleted_at,status from custom_relations;
-- pk
-- jsonb areas
-- == 表【customer_rels】建视图语句 ==
-- drop view view_customer_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_customer_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customer_rels as select customer_rel_id as id,customer_rel_id,customer_id,customer_level,status,created_at,updated_at,deleted_at,latest_update_time,operator_id from customer_rels;
-- pk customer_rel_id
-- jsonb operator
-- == 表【customer_rewards】建视图语句 ==
-- drop view view_customer_rewards;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_rewards') THEN
-- 如果存在就删除视图
DROP VIEW view_customer_rewards;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customer_rewards as select customer_reward_id as id,customer_reward_id,data_from,reward_ratio,status,customer_id,salesman_id,created_at,updated_at,disabled_at,operator_id,latest_update_time from customer_rewards;
-- pk customer_reward_id
-- jsonb operator
-- == 表【customers】建视图语句 ==
-- drop view view_customers;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customers') THEN
-- 如果存在就删除视图
DROP VIEW view_customers;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customers as select customer_id as id,customer_id,customer_code,customer_name,data_from,status,company_id,created_at,updated_at,deleted_at,latest_update_time,operator_id from customers;
-- pk customer_id
-- jsonb operator
-- == 表【matched_relations】建视图语句 ==
-- drop view view_matched_relations;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_matched_relations') THEN
-- 如果存在就删除视图
DROP VIEW view_matched_relations;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_matched_relations as select matched_relation_id as id,matched_relation_id,matched_module_code,created_at,deleted_at,updated_at from matched_relations;
-- pk matched_relation_id
-- jsonb matched_fields,operator
-- == 表【notice_messages】建视图语句 ==
-- drop view view_notice_messages;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_notice_messages') THEN
-- 如果存在就删除视图
DROP VIEW view_notice_messages;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_notice_messages as select notice_message_id as id,notice_message_id,notice_message_title,notice_message_content,notice_message_module_id,notice_message_module,notice_message_sub_module_id,notice_message_sub_module,notice_message_type,status,created_at,updated_at,deleted_at,latest_update_time,operator_id from notice_messages;
-- pk notice_message_id
-- jsonb operator
-- == 表【performances】建视图语句 ==
-- drop view view_performances;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_performances') THEN
-- 如果存在就删除视图
DROP VIEW view_performances;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_performances as select performance_id as id,performance_id,performance_value,performance_type,data_from,salesman_id,region_id,year,month,operator_id,created_at,updated_at,deleted_at,latest_update_time from performances;
-- pk performance_id
-- jsonb
-- == 表【product_belongs】建视图语句 ==
-- drop view view_product_belongs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_belongs') THEN
-- 如果存在就删除视图
DROP VIEW view_product_belongs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_belongs as select product_belong_id as id,product_belong_id,begin_time,end_time,product_id,status,parent_product_id,operator_id,created_at,deleted_at,latest_update_time,updated_at from product_belongs;
-- pk product_belong_id
-- jsonb
-- == 表【corresponding_profit】建视图语句 ==
-- drop view view_corresponding_profit;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_corresponding_profit') THEN
-- 如果存在就删除视图
DROP VIEW view_corresponding_profit;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_corresponding_profit as select saleman_id as id,saleman_id,saleman_name,saleman_phone,saleman_year,saleman_month,opportunity,normal from corresponding_profit;
-- pk saleman_id
-- jsonb
-- == 表【custom_relation_historys】建视图语句 ==
-- drop view view_custom_relation_historys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_custom_relation_historys') THEN
-- 如果存在就删除视图
DROP VIEW view_custom_relation_historys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_custom_relation_historys as select id,created_at,custom_relation_id,group_id,template_id,updated_at,relation_main,relation_main_id from custom_relation_historys;
-- pk
-- jsonb body_data,head_field
-- == 表【product_rel_expireds】建视图语句 ==
-- drop view view_product_rel_expireds;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rel_expireds') THEN
-- 如果存在就删除视图
DROP VIEW view_product_rel_expireds;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_rel_expireds as select product_id as id,product_id,latest_update_time,created_at,product_rel_expired_id,remark,module,expired_at,latest_check_at,notice_times from product_rel_expireds;
-- pk product_id
-- jsonb
-- == 表【product_rels】建视图语句 ==
-- drop view view_product_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_product_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_rels as select product_rel_id as id,product_rel_id,product_id,product_level,operator_id,created_at,deleted_at,updated_at,latest_update_time from product_rels;
-- pk product_rel_id
-- jsonb
-- == 表【product_categorys】建视图语句 ==
-- drop view view_product_categorys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_categorys') THEN
-- 如果存在就删除视图
DROP VIEW view_product_categorys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_categorys as select product_category_id as id,product_category_id,begin_time,end_time,product_id,status,category_type,tag,operator_id,created_at,deleted_at,updated_at,latest_update_time from product_categorys;
-- pk product_category_id
-- jsonb
-- == 表【product_costs】建视图语句 ==
-- drop view view_product_costs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_costs') THEN
-- 如果存在就删除视图
DROP VIEW view_product_costs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_costs as select product_cost_id as id,product_cost_id,created_at,deleted_at,data_from,updated_at,product_id,begin_time,cost,end_time,operator_id,latest_update_time from product_costs;
-- pk product_cost_id
-- jsonb operator
-- == 表【profits】建视图语句 ==
-- drop view view_profits;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_profits') THEN
-- 如果存在就删除视图
DROP VIEW view_profits;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_profits as select profit_id as id,profit_id,profit_type,profit_value,data_from,salesman_id,region_id,operator_id,year,month,created_at,updated_at,deleted_at,latest_update_time from profits;
-- pk profit_id
-- jsonb
-- == 表【products】建视图语句 ==
-- drop view view_products;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_products') THEN
-- 如果存在就删除视图
DROP VIEW view_products;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_products as select product_id as id,product_id,created_at,data_from,updated_at,product_code,product_name,standard,status,operator_id,latest_update_time,disabled_at from products;
-- pk product_id
-- jsonb operator
-- == 表【region_rel_expireds】建视图语句 ==
-- drop view view_region_rel_expireds;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rel_expireds') THEN
-- 如果存在就删除视图
DROP VIEW view_region_rel_expireds;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_rel_expireds as select region_id as id,region_id,latest_update_time,created_at,region_rel_expired_id,remark,module,expired_at,latest_check_at,notice_times from region_rel_expireds;
-- pk region_id
-- jsonb
-- == 表【region_rels】建视图语句 ==
-- drop view view_region_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_region_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_rels as select region_rel_id as id,region_rel_id,region_id,region_level,operator_id,created_at,deleted_at,updated_at,latest_update_time from region_rels;
-- pk region_rel_id
-- jsonb
-- == 表【responsible_salesmans】建视图语句 ==
-- drop view view_responsible_salesmans;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_responsible_salesmans') THEN
-- 如果存在就删除视图
DROP VIEW view_responsible_salesmans;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_responsible_salesmans as select responsible_salesman_id as id,responsible_salesman_id,customer_rel_id,salesman_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,customer_id,operator_id from responsible_salesmans;
-- pk responsible_salesman_id
-- jsonb operator
-- == 表【sales_details】建视图语句 ==
-- drop view view_sales_details;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_details') THEN
-- 如果存在就删除视图
DROP VIEW view_sales_details;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_sales_details as select sales_detail_id as id,sales_detail_id,data_from,original_order_number,sale_date,salesman_id,region_id,superior_region_id,sales_method_id,customer_id,product_id,price,amount,is_returned,operator_id,company_id,created_at,updated_at,deleted_at,latest_update_time,address,department,total_price_and_tax from sales_details;
-- pk sales_detail_id
-- jsonb
-- == 表【sales_methods】建视图语句 ==
-- drop view view_sales_methods;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_sales_methods') THEN
-- 如果存在就删除视图
DROP VIEW view_sales_methods;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_sales_methods as select sales_method_id as id,created_at,data_from,sales_method_id,updated_at,method_name,operator_id,latest_update_time from sales_methods;
-- pk
-- jsonb operator
-- == 表【salesman_rels】建视图语句 ==
-- drop view view_salesman_rels;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesman_rels') THEN
-- 如果存在就删除视图
DROP VIEW view_salesman_rels;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_salesman_rels as select salesman_rel_id as id,salesman_rel_id,salesman_level,status,created_at,updated_at,deleted_at,latest_update_time,salesman_id,operator_id from salesman_rels;
-- pk salesman_rel_id
-- jsonb operator
-- == 表【salesmans】建视图语句 ==
-- drop view view_salesmans;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_salesmans') THEN
-- 如果存在就删除视图
DROP VIEW view_salesmans;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_salesmans as select salesman_id as id,salesman_id,salesman_code,salesman_name,data_from,status,phone,company_id,created_at,updated_at,deleted_at,latest_update_time,operator_id,disabled_at from salesmans;
-- pk salesman_id
-- jsonb operator
-- == 表【solution_groups】建视图语句 ==
-- drop view view_solution_groups;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solution_groups') THEN
-- 如果存在就删除视图
DROP VIEW view_solution_groups;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_solution_groups as select solution_group_id as id,solution_group_id,solution_group_name,created_at,updated_at,deleted_at,operator_id from solution_groups;
-- pk solution_group_id
-- jsonb operator
-- == 表【solutions】建视图语句 ==
-- drop view view_solutions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_solutions') THEN
-- 如果存在就删除视图
DROP VIEW view_solutions;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_solutions as select solution_id as id,solution_id,database_name,schema_name,solution_group_id,solution_name,latest_update_time,status,created_at,updated_at,deleted_at,compute_business_name,compute_business_id,operator_id,begin_time,end_time from solutions;
-- pk solution_id
-- jsonb operator,compute_items,salesmen
-- == 表【project_costs】建视图语句 ==
-- drop view view_project_costs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_project_costs') THEN
-- 如果存在就删除视图
DROP VIEW view_project_costs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_project_costs as select project_cost_id as id,project_cost_id,data_from,created_at,deleted_at,updated_at,product_id,happen_time,money,subject,region_id,salesman_id,customer_id,operator_id,latest_update_time,department from project_costs;
-- pk project_cost_id
-- jsonb operator
-- == 表【region_belongs】建视图语句 ==
-- drop view view_region_belongs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_belongs') THEN
-- 如果存在就删除视图
DROP VIEW view_region_belongs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_belongs as select region_belong_id as id,region_belong_id,begin_time,end_time,status,parent_region_id,region_id,operator_id,created_at,deleted_at,updated_at,latest_update_time from region_belongs;
-- pk region_belong_id
-- jsonb
-- == 表【region_categorys】建视图语句 ==
-- drop view view_region_categorys;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_categorys') THEN
-- 如果存在就删除视图
DROP VIEW view_region_categorys;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_categorys as select region_category_id as id,region_category_id,begin_time,end_time,status,category_type,tag,operator_id,created_at,deleted_at,latest_update_time,updated_at,region_id from region_categorys;
-- pk region_category_id
-- jsonb
-- == 表【region_salesmans】建视图语句 ==
-- drop view view_region_salesmans;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_region_salesmans') THEN
-- 如果存在就删除视图
DROP VIEW view_region_salesmans;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_region_salesmans as select region_salesman_id as id,region_salesman_id,region_id,salesman_id,begin_time,created_at,deleted_at,end_time,latest_update_time,updated_at,status,operator_id from region_salesmans;
-- pk region_salesman_id
-- jsonb
-- == 表【regions】建视图语句 ==
-- drop view view_regions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regions') THEN
-- 如果存在就删除视图
DROP VIEW view_regions;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_regions as select region_id as id,region_id,region_code,region_name,data_from,status,company_id,created_at,updated_at,deleted_at,latest_update_time,disabled_at from regions;
-- pk region_id
-- jsonb operator
-- == 表【superior_responsible_persons】建视图语句 ==
-- drop view view_superior_responsible_persons;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_responsible_persons') THEN
-- 如果存在就删除视图
DROP VIEW view_superior_responsible_persons;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_superior_responsible_persons as select superior_responsible_person_id as id,superior_responsible_person_id,salesman_rel_id,salesman_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,superior_salesman_id,operator_id from superior_responsible_persons;
-- pk superior_responsible_person_id
-- jsonb operator
-- == 表【type_tags】建视图语句 ==
-- drop view view_type_tags;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_type_tags') THEN
-- 如果存在就删除视图
DROP VIEW view_type_tags;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_type_tags as select type_tag_id as id,type_tag_id,rel_id,type_tag_module,type_tag_name,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,type_tag_code,operator_id from type_tags;
-- pk type_tag_id
-- jsonb operator
-- == 表【editor_module_confs】建视图语句 ==
-- drop view view_editor_module_confs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_module_confs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_module_confs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_module_confs as select id,name,report_id,is_checked,uri,created_at,updated_at from editor_module_confs;
-- pk
-- jsonb
-- == 表【editor_user_conf_logs】建视图语句 ==
-- drop view view_editor_user_conf_logs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_conf_logs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_user_conf_logs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_user_conf_logs as select id,user_id,user_name,report_id,report_name,module_name,created_at from editor_user_conf_logs;
-- pk
-- jsonb
-- == 表【product_shares】建视图语句 ==
-- drop view view_product_shares;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_product_shares') THEN
-- 如果存在就删除视图
DROP VIEW view_product_shares;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_product_shares as select product_share_id as id,product_share_id,customer_rel_id,shared_product_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,customer_id,salesman_type,salesman_id,salesman_share,operator_id,extra_attribute,group_id from product_shares;
-- pk product_share_id
-- jsonb operator
-- == 表【superior_customers】建视图语句 ==
-- drop view view_superior_customers;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_superior_customers') THEN
-- 如果存在就删除视图
DROP VIEW view_superior_customers;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_superior_customers as select superior_customer_id as id,superior_customer_id,customer_rel_id,customer_id,valid_period_begin,valid_period_end,status,created_at,updated_at,deleted_at,latest_update_time,superior_customer_uid,operator_id from superior_customers;
-- pk superior_customer_id
-- jsonb operator
-- == 表【editor_report_confs】建视图语句 ==
-- drop view view_editor_report_confs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_report_confs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_report_confs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_report_confs as select id,name,platform_id,created_at,updated_at,permission_flag from editor_report_confs;
-- pk
-- jsonb
-- == 表【areas】建视图语句 ==
-- drop view view_areas;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_areas') THEN
-- 如果存在就删除视图
DROP VIEW view_areas;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_areas as select area_code,city_code,parent_code,level,merger_name,name,short_name,zip_code,full_name,id,pinyin,lng,lat,full_area_code from areas;
-- pk
-- jsonb
-- == 表【editor_chart_confs】建视图语句 ==
-- drop view view_editor_chart_confs;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_chart_confs') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_chart_confs;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_chart_confs as select id,name,module_id,chart_conf,chart_data_conf,is_checked,is_default,created_at,updated_at,deleted_at from editor_chart_confs;
-- pk
-- jsonb
-- == 表【editor_user_chart_conf】建视图语句 ==
-- drop view view_editor_user_chart_conf;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_editor_user_chart_conf') THEN
-- 如果存在就删除视图
DROP VIEW view_editor_user_chart_conf;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_editor_user_chart_conf as select editor_user_chart_conf_id as id,editor_user_chart_conf_id,phone,report_id,module_id,module_permissions,chart_id,chart_checked,sort_by,created_at,updated_at,deleted_at,module_checked from editor_user_chart_conf;
-- pk editor_user_chart_conf_id
-- jsonb
-- == 表【users】建视图语句 ==
-- drop view view_users;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_users') THEN
-- 如果存在就删除视图
DROP VIEW view_users;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_users as select user_id as id,user_id,user_name,user_account,password,user_avatar,company_id,status,created_at,updated_at,deleted_at from users;
-- pk user_id
-- jsonb
-- == 表【offline_expenses】建视图语句 ==
-- drop view view_offline_expenses;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_offline_expenses') THEN
-- 如果存在就删除视图
DROP VIEW view_offline_expenses;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_offline_expenses as select project_cost_id as id,project_cost_id,data_from,created_at,deleted_at,updated_at,product_id,happen_time,money,subject,region_id,salesman_id,customer_id,operator_id,latest_update_time,department from offline_expenses;
-- pk project_cost_id
-- jsonb operator
-- == 表【regular_employee】建视图语句 ==
-- drop view view_regular_employee;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regular_employee') THEN
-- 如果存在就删除视图
DROP VIEW view_regular_employee;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_regular_employee as select regular_employee_id as id,regular_employee_id,salesman_code,salesman_name,confirmation_date,operator_id,created_at,updated_at,deleted_at,latest_update_time from regular_employee;
-- pk regular_employee_id
-- jsonb
-- == 表【employee_relations】建视图语句 ==
-- drop view view_employee_relations;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_employee_relations') THEN
-- 如果存在就删除视图
DROP VIEW view_employee_relations;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_employee_relations as select employee_relations_id as id,employee_relations_id,start_time,end_time,expense_area,expense_operator_code,primary_area_name,secondary_area_name,salesman_name,distribution_proportion,operator_id,created_at,updated_at,deleted_at,latest_update_time from employee_relations;
-- pk employee_relations_id
-- jsonb
-- == 表【operate_rules】建视图语句 ==
-- drop view view_operate_rules;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_operate_rules') THEN
-- 如果存在就删除视图
DROP VIEW view_operate_rules;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_operate_rules as select operate_rule_id as id,operate_rule_id,customer_code,product_code,area_code,allocation_proportion,primary_area_name,secondary_area_name,performance_type,opportunity_territory,start_time,end_time,operator_id,created_at,updated_at,deleted_at,latest_update_time from operate_rules;
-- pk operate_rule_id
-- jsonb
-- == 表【share_customer_expenses】建视图语句 ==
-- drop view view_share_customer_expenses;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_share_customer_expenses') THEN
-- 如果存在就删除视图
DROP VIEW view_share_customer_expenses;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_share_customer_expenses as select share_customer_expenses_id as id,share_customer_expenses_id,customer_code,primary_area_name,secondary_area_name,expense_type,start_time,end_time,operator_id,created_at,updated_at,deleted_at,latest_update_time from share_customer_expenses;
-- pk share_customer_expenses_id
-- jsonb
-- == 表【customer_comparisons】建视图语句 ==
-- drop view view_customer_comparisons;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_customer_comparisons') THEN
-- 如果存在就删除视图
DROP VIEW view_customer_comparisons;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_customer_comparisons as select customer_comparison_id as id,customer_comparison_id,customer_code,summary_area,primary_area_name,secondary_area_name,self_support_or_opportunity,start_time,end_time,operator_id,created_at,updated_at,deleted_at,rebate,latest_update_time from customer_comparisons;
-- pk customer_comparison_id
-- jsonb
-- == 表【regional_ownerships】建视图语句 ==
-- drop view view_regional_ownerships;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.views WHERE table_name = 'view_regional_ownerships') THEN
-- 如果存在就删除视图
DROP VIEW view_regional_ownerships;
RAISE NOTICE '视图已删除';
ELSE
RAISE NOTICE '视图不存在';
END IF;
END $$;
create view view_regional_ownerships as select regional_ownerships_id as id,regional_ownerships_id,start_time,end_time,area,secondary_area_name,salesman_code,salesman_name,is_incremental_commission,is_profit_increase_commission,operator_id,created_at,updated_at,deleted_at,latest_update_time from regional_ownerships;
-- pk regional_ownerships_id
-- jsonb