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
| package models
|
| import (
| "basic.com/valib/logger.git"
| "github.com/jinzhu/gorm"
| _ "github.com/jinzhu/gorm/dialects/sqlite"
| "time"
| "vamicro/config"
| )
|
| var db *gorm.DB
| var err error
|
| // Init creates a connection to mysql database and
| // migrates any new models
| func Init() {
| db, err = gorm.Open(config.DBconf.Name, "../config/comptable-service.db")
| if err != nil {
| logger.Debug("db open error ", err)
| }
| db.LogMode(true)
| //db.SetLogger(&DbLogger{})
| db.AutoMigrate(&Dictionary{}, &Dbtables{}, &Dbtablepersons{})
|
| go func() {
| time.Sleep(5 * time.Second)
| initDic()
| }()
| }
|
| //GetDB ...
| func GetDB() *gorm.DB {
| return db
| }
|
| func CloseDB() {
| db.Close()
| }
|
| func initDic() {
| //车身颜色 nVehicleColor
| db.Exec("INSERT INTO dictionary SELECT 'f69fab66-2b90-43b5-a1b2-168ae9ebed09', '0', '未知', 'nVehicleColor', '未知', 1, '0' where not exists (select 1 from dictionary where id='f69fab66-2b90-43b5-a1b2-168ae9ebed09')")
| db.Exec("INSERT INTO dictionary SELECT 'ad71764e-7d11-4f55-9f39-f253632353e6', '1', '黑色', 'nVehicleColor', '黑色', 2, '0' where not exists (select 1 from dictionary where id='ad71764e-7d11-4f55-9f39-f253632353e6')")
| db.Exec("INSERT INTO dictionary SELECT '64fb11e5-7fd5-4e99-bcde-28a7e5267271', '2', '白色', 'nVehicleColor', '白色', 3, '0' where not exists (select 1 from dictionary where id='64fb11e5-7fd5-4e99-bcde-28a7e5267271')")
| db.Exec("INSERT INTO dictionary SELECT 'e4ccb29d-5382-4249-83e7-56c21a31b484', '3', '灰色(银色)', 'nVehicleColor', '灰色(银色)', 4, '0' where not exists (select 1 from dictionary where id='e4ccb29d-5382-4249-83e7-56c21a31b484')")
| db.Exec("INSERT INTO dictionary SELECT 'b37b9974-c51f-4333-bd65-b7c411f7e231', '4', '红色', 'nVehicleColor', '红色', 5, '0' where not exists (select 1 from dictionary where id='b37b9974-c51f-4333-bd65-b7c411f7e231')")
| db.Exec("INSERT INTO dictionary SELECT 'fdb9783e-3df2-4146-9656-972bf95221b9', '5', '蓝色', 'nVehicleColor', '蓝色', 6, '0' where not exists (select 1 from dictionary where id='fdb9783e-3df2-4146-9656-972bf95221b9')")
| db.Exec("INSERT INTO dictionary SELECT '038ab226-4ac5-4825-b2bf-2dddc04bad29', '6', '黄色', 'nVehicleColor', '黄色', 7, '0' where not exists (select 1 from dictionary where id='038ab226-4ac5-4825-b2bf-2dddc04bad29')")
| db.Exec("INSERT INTO dictionary SELECT '8e2eadf7-47e0-4997-9661-2efc29e55f1a', '7', '橙色', 'nVehicleColor', '橙色', 8, '0' where not exists (select 1 from dictionary where id='8e2eadf7-47e0-4997-9661-2efc29e55f1a')")
| db.Exec("INSERT INTO dictionary SELECT 'a6e8eb97-64b9-46d9-a363-f461d62d93c6', '8', '棕色', 'nVehicleColor', '棕色', 9, '0' where not exists (select 1 from dictionary where id='a6e8eb97-64b9-46d9-a363-f461d62d93c6')")
| db.Exec("INSERT INTO dictionary SELECT 'bb8e2b10-f912-4996-bb2f-33196ecd0ac9', '9', '绿色', 'nVehicleColor', '绿色', 10, '0' where not exists (select 1 from dictionary where id='bb8e2b10-f912-4996-bb2f-33196ecd0ac9')")
| db.Exec("INSERT INTO dictionary SELECT '9ad30f42-dafe-40da-bf1e-935674465a08', '10', '紫色', 'nVehicleColor', '紫色', 11, '0' where not exists (select 1 from dictionary where id='9ad30f42-dafe-40da-bf1e-935674465a08')")
| db.Exec("INSERT INTO dictionary SELECT '093c8eb4-78b3-4eee-8980-feca6fa093e9', '11', '青色', 'nVehicleColor', '青色', 12, '0' where not exists (select 1 from dictionary where id='093c8eb4-78b3-4eee-8980-feca6fa093e9')")
| db.Exec("INSERT INTO dictionary SELECT 'ddd5c36b-c451-47f2-9798-fb5e4504db83', '12', '粉色', 'nVehicleColor', '粉色', 13, '0' where not exists (select 1 from dictionary where id='ddd5c36b-c451-47f2-9798-fb5e4504db83')")
|
| //车辆类型 nVehicleType
| db.Exec("INSERT INTO dictionary SELECT '1bf556a8-9c88-4b76-92f3-d86263417ea0', '0', '未知', 'nVehicleType', '未知', 1, '0' where not exists (select 1 from dictionary where id='1bf556a8-9c88-4b76-92f3-d86263417ea0')")
| db.Exec("INSERT INTO dictionary SELECT '77edea14-2831-4c85-a0d0-1d6a0860079c', '1', '轿车', 'nVehicleType', '轿车', 2, '0' where not exists (select 1 from dictionary where id='77edea14-2831-4c85-a0d0-1d6a0860079c')")
| db.Exec("INSERT INTO dictionary SELECT 'cdb6d99c-42d8-4432-a6a7-1dee3eb3b360', '2', '货车', 'nVehicleType', '货车', 3, '0' where not exists (select 1 from dictionary where id='cdb6d99c-42d8-4432-a6a7-1dee3eb3b360')")
| db.Exec("INSERT INTO dictionary SELECT 'e58ba309-a1a2-46ea-9827-6d30310566b5', '3', '客车', 'nVehicleType', '客车', 4, '0' where not exists (select 1 from dictionary where id='e58ba309-a1a2-46ea-9827-6d30310566b5')")
| db.Exec("INSERT INTO dictionary SELECT '51aa1f8d-d220-4f39-8b35-fd59fa55beda', '4', '面包车', 'nVehicleType', '面包车', 5, '0' where not exists (select 1 from dictionary where id='51aa1f8d-d220-4f39-8b35-fd59fa55beda')")
|
| //车辆品牌 nVehicleBrand
| db.Exec("INSERT INTO dictionary SELECT 'fc28e631-23c6-4cd2-b0ea-ab68bf2df277', '0', '未知', 'nVehicleBrand', '未知', 1, '0' where not exists (select 1 from dictionary where id='fc28e631-23c6-4cd2-b0ea-ab68bf2df277')")
| db.Exec("INSERT INTO dictionary SELECT '2f8d96d5-13ec-439f-94a0-3e8d9b6b38f8', '1', '吉普', 'nVehicleBrand', '吉普', 2, '0' where not exists (select 1 from dictionary where id='2f8d96d5-13ec-439f-94a0-3e8d9b6b38f8')")
| db.Exec("INSERT INTO dictionary SELECT 'd618720e-caf5-490b-8359-ef17eeb3c445', '2', '奔驰', 'nVehicleBrand', '奔驰', 3, '0' where not exists (select 1 from dictionary where id='d618720e-caf5-490b-8359-ef17eeb3c445')")
| db.Exec("INSERT INTO dictionary SELECT '3471834b-f81c-41cb-9694-811f6ff8e19f', '3', '宝马', 'nVehicleBrand', '宝马', 4, '0' where not exists (select 1 from dictionary where id='3471834b-f81c-41cb-9694-811f6ff8e19f')")
| db.Exec("INSERT INTO dictionary SELECT 'eb2d6596-f1c5-426b-b0c3-e5ee8e46737a', '4', '奥迪', 'nVehicleBrand', '奥迪', 5, '0' where not exists (select 1 from dictionary where id='eb2d6596-f1c5-426b-b0c3-e5ee8e46737a')")
| db.Exec("INSERT INTO dictionary SELECT '0ffc24fb-1de6-4b89-acc3-2a3b90fa2be8', '5', '大众', 'nVehicleBrand', '大众', 6, '0' where not exists (select 1 from dictionary where id='0ffc24fb-1de6-4b89-acc3-2a3b90fa2be8')")
| db.Exec("INSERT INTO dictionary SELECT '37eee0b4-8f24-4cf9-b10b-ec665db7d024', '6', '通用', 'nVehicleBrand', '通用', 7, '0' where not exists (select 1 from dictionary where id='37eee0b4-8f24-4cf9-b10b-ec665db7d024')")
| db.Exec("INSERT INTO dictionary SELECT '8d66a7b5-43b7-4bdb-9752-28b178ecbf0c', '7', '福特', 'nVehicleBrand', '福特', 8, '0' where not exists (select 1 from dictionary where id='8d66a7b5-43b7-4bdb-9752-28b178ecbf0c')")
| db.Exec("INSERT INTO dictionary SELECT '9a242898-6fd1-47d5-9e3a-563a412920a6', '8', '克莱斯勒', 'nVehicleBrand', '克莱斯勒', 9, '0' where not exists (select 1 from dictionary where id='9a242898-6fd1-47d5-9e3a-563a412920a6')")
| db.Exec("INSERT INTO dictionary SELECT '6741742a-cb9f-4ee9-bc3e-4a4ae8caa9fa', '9', '比亚迪', 'nVehicleBrand', '比亚迪', 10, '0' where not exists (select 1 from dictionary where id='6741742a-cb9f-4ee9-bc3e-4a4ae8caa9fa')")
| db.Exec("INSERT INTO dictionary SELECT '725fcb47-5150-4e8d-ae20-9f20124d0224', '10', '奇瑞', 'nVehicleBrand', '奇瑞', 11, '0' where not exists (select 1 from dictionary where id='725fcb47-5150-4e8d-ae20-9f20124d0224')")
| db.Exec("INSERT INTO dictionary SELECT '7645aa3a-e5b1-4ce8-b7ea-cdc78232c282', '11', '吉利', 'nVehicleBrand', '吉利', 12, '0' where not exists (select 1 from dictionary where id='7645aa3a-e5b1-4ce8-b7ea-cdc78232c282')")
| db.Exec("INSERT INTO dictionary SELECT '4178a12e-be48-4bee-a840-48799a4def39', '12', '长城', 'nVehicleBrand', '长城', 13, '0' where not exists (select 1 from dictionary where id='4178a12e-be48-4bee-a840-48799a4def39')")
| db.Exec("INSERT INTO dictionary SELECT '17c38072-c31b-47ee-a99b-b02f09ec727f', '13', '红旗', 'nVehicleBrand', '红旗', 14, '0' where not exists (select 1 from dictionary where id='17c38072-c31b-47ee-a99b-b02f09ec727f')")
| db.Exec("INSERT INTO dictionary SELECT '8878ffdb-af53-42cc-8892-42a34af532a0', '14', '江淮', 'nVehicleBrand', '江淮', 15, '0' where not exists (select 1 from dictionary where id='8878ffdb-af53-42cc-8892-42a34af532a0')")
| db.Exec("INSERT INTO dictionary SELECT 'a5945122-53dc-4805-8139-b84c83ec99d1', '15', '一汽', 'nVehicleBrand', '一汽', 16, '0' where not exists (select 1 from dictionary where id='a5945122-53dc-4805-8139-b84c83ec99d1')")
| db.Exec("INSERT INTO dictionary SELECT '05acfe72-ab9f-4d46-ac31-6a6446783130', '16', '本田', 'nVehicleBrand', '本田', 17, '0' where not exists (select 1 from dictionary where id='05acfe72-ab9f-4d46-ac31-6a6446783130')")
| db.Exec("INSERT INTO dictionary SELECT 'fff61bed-73a6-4214-b44f-a0040efa7ed7', '17', '丰田', 'nVehicleBrand', '丰田', 18, '0' where not exists (select 1 from dictionary where id='fff61bed-73a6-4214-b44f-a0040efa7ed7')")
| db.Exec("INSERT INTO dictionary SELECT '4cd06a99-84ee-4d10-98e6-0ff5211a4cb6', '18', '日产', 'nVehicleBrand', '日产', 19, '0' where not exists (select 1 from dictionary where id='4cd06a99-84ee-4d10-98e6-0ff5211a4cb6')")
| db.Exec("INSERT INTO dictionary SELECT '97ca4ba2-bd68-410c-8e58-f5a98fce98d3', '19', '三菱', 'nVehicleBrand', '三菱', 20, '0' where not exists (select 1 from dictionary where id='97ca4ba2-bd68-410c-8e58-f5a98fce98d3')")
| db.Exec("INSERT INTO dictionary SELECT 'f2364ecd-74d6-43d4-9124-2249f1032e81', '20', '铃木', 'nVehicleBrand', '铃木', 21, '0' where not exists (select 1 from dictionary where id='f2364ecd-74d6-43d4-9124-2249f1032e81')")
| db.Exec("INSERT INTO dictionary SELECT 'a3e06025-b11f-4724-b902-d69abcea77ed', '21', '马自达', 'nVehicleBrand', '马自达', 22, '0' where not exists (select 1 from dictionary where id='a3e06025-b11f-4724-b902-d69abcea77ed')")
|
| /*
| //车牌颜色
| db.Exec("INSERT INTO dictionary SELECT '18956c3e-e656-4e89-a3f3-a94d52e33def', '0', '未知', 'nColor', '颜色未知', 1, '0' where not exists (select 1 from dictionary where id='18956c3e-e656-4e89-a3f3-a94d52e33def')")
| db.Exec("INSERT INTO dictionary SELECT '63d64a19-9157-463a-95c6-ea6b13d73aeb', '1', '蓝色', 'nColor', '蓝色', 2, '0' where not exists (select 1 from dictionary where id='63d64a19-9157-463a-95c6-ea6b13d73aeb')")
| db.Exec("INSERT INTO dictionary SELECT 'b4cf0964-8468-48c6-a9c8-a75d29f0fd03', '2', '黑色', 'nColor', '黑色', 3, '0' where not exists (select 1 from dictionary where id='b4cf0964-8468-48c6-a9c8-a75d29f0fd03')")
| db.Exec("INSERT INTO dictionary SELECT 'ed4288b5-d91f-4ce0-81a6-199b62a6399d', '3', '黄色', 'nColor', '黄色', 4, '0' where not exists (select 1 from dictionary where id='ed4288b5-d91f-4ce0-81a6-199b62a6399d')")
| db.Exec("INSERT INTO dictionary SELECT '39fc01be-788e-4a28-949e-b3648a8dc353', '4', '白色', 'nColor', '白色', 5, '0' where not exists (select 1 from dictionary where id='39fc01be-788e-4a28-949e-b3648a8dc353')")
| db.Exec("INSERT INTO dictionary SELECT '5cd0269c-02e0-41da-a666-ea231dc68ff3', '5', '绿色', 'nColor', '绿色', 6, '0' where not exists (select 1 from dictionary where id='5cd0269c-02e0-41da-a666-ea231dc68ff3')")
| db.Exec("INSERT INTO dictionary SELECT '7f1bb3fb-98c5-4a67-ae1c-ff6670dc87a0', '6', '绿黄色', 'nColor', '绿黄色', 7, '0' where not exists (select 1 from dictionary where id='7f1bb3fb-98c5-4a67-ae1c-ff6670dc87a0')")
|
| //车牌类型
| db.Exec("INSERT INTO dictionary SELECT '69ae05f0-af3a-4c7b-bb96-f1e747fb2ac6', '0', '未知', 'nType', '未知', 1, '0' where not exists (select 1 from dictionary where id='69ae05f0-af3a-4c7b-bb96-f1e747fb2ac6')")
| db.Exec("INSERT INTO dictionary SELECT '847c52ec-589a-4ae0-9a2e-adc5c9853205', '1', '普通蓝牌', 'nType', '普通蓝牌', 2, '0' where not exists (select 1 from dictionary where id='847c52ec-589a-4ae0-9a2e-adc5c9853205')")
| db.Exec("INSERT INTO dictionary SELECT 'bd6b5fac-4609-4a53-82fb-f5f81a5be180', '2', '普通黑牌', 'nType', '普通黑牌', 3, '0' where not exists (select 1 from dictionary where id='bd6b5fac-4609-4a53-82fb-f5f81a5be180')")
| db.Exec("INSERT INTO dictionary SELECT '3015641f-cf4a-4332-91b4-1ece89fbe251', '3', '普通单层黄牌', 'nType', '普通单层黄牌', 4, '0' where not exists (select 1 from dictionary where id='3015641f-cf4a-4332-91b4-1ece89fbe251')")
| db.Exec("INSERT INTO dictionary SELECT '6e717abd-03f9-498f-90a0-bef382ef5067', '4', '双层黄牌', 'nType', '双层黄牌', 5, '0' where not exists (select 1 from dictionary where id='6e717abd-03f9-498f-90a0-bef382ef5067')")
| db.Exec("INSERT INTO dictionary SELECT '67109f4e-8a27-4a0a-b798-2ead906d625f', '5', '白色警牌', 'nType', '白色警牌', 6, '0' where not exists (select 1 from dictionary where id='67109f4e-8a27-4a0a-b798-2ead906d625f')")
| db.Exec("INSERT INTO dictionary SELECT 'd3273c8b-3ab3-4a4b-bbcc-adc15e11a222', '6', '白色武警', 'nType', '白色武警', 7, '0' where not exists (select 1 from dictionary where id='d3273c8b-3ab3-4a4b-bbcc-adc15e11a222')")
| db.Exec("INSERT INTO dictionary SELECT '1b9c4d09-301f-4591-a785-8907aec6266c', '7', '白色军牌', 'nType', '白色军牌', 8, '0' where not exists (select 1 from dictionary where id='1b9c4d09-301f-4591-a785-8907aec6266c')")
| db.Exec("INSERT INTO dictionary SELECT '731d677e-0308-4d91-87e7-1f47abe7d9ed', '8', '港牌', 'nType', '港牌', 9, '0' where not exists (select 1 from dictionary where id='731d677e-0308-4d91-87e7-1f47abe7d9ed')")
| db.Exec("INSERT INTO dictionary SELECT '889886ab-bdb0-4775-9101-648ab8c5960e', '9', '农用车牌', 'nType', '农用车牌', 10, '0' where not exists (select 1 from dictionary where id='889886ab-bdb0-4775-9101-648ab8c5960e')")
| db.Exec("INSERT INTO dictionary SELECT '3d809770-feaf-442e-bb12-faf216f49805', '10', '新能源车牌(纯绿色)', 'nType', '新能源车牌(纯绿色)', 11, '0' where not exists (select 1 from dictionary where id='3d809770-feaf-442e-bb12-faf216f49805')")
| db.Exec("INSERT INTO dictionary SELECT '5c203074-a846-4ed9-8e36-abc9e279756a', '11', '新能源车(黄绿色)', 'nType', '新能源车(黄绿色)', 12, '0' where not exists (select 1 from dictionary where id='5c203074-a846-4ed9-8e36-abc9e279756a')")
| db.Exec("INSERT INTO dictionary SELECT '33d77bbc-35e3-4e10-ae49-d2b89716fed6', '12', '个性化车牌', 'nType', '个性化车牌', 13, '0' where not exists (select 1 from dictionary where id='33d77bbc-35e3-4e10-ae49-d2b89716fed6')")
| db.Exec("INSERT INTO dictionary SELECT '0831061c-3240-48fd-812d-d1d1887b3e21', '13', '使馆车', 'nType', '使馆车', 14, '0' where not exists (select 1 from dictionary where id='0831061c-3240-48fd-812d-d1d1887b3e21')")
|
| db.Exec("INSERT INTO dictionary SELECT '620b3871-52a8-4eb4-a8ba-4f7aff2bf3d6', '0', '深色', 'nVehicleBright', '深色', 1, '0' where not exists (select 1 from dictionary where id='620b3871-52a8-4eb4-a8ba-4f7aff2bf3d6')")
| db.Exec("INSERT INTO dictionary SELECT 'fcdc4846-c529-456b-994b-06d8ad634871', '1', '浅色', 'nVehicleBright', '浅色', 2, '0' where not exists (select 1 from dictionary where id='fcdc4846-c529-456b-994b-06d8ad634871')")
| */
| }
|
|