Browse Source

二级库仓库管理模块

mainqaq 2 years ago
parent
commit
3ae78dfd59

+ 543 - 0
controllers/secondary_order_api_contorller.go View File

@@ -1,9 +1,552 @@
1 1
 package controllers
2 2
 
3
+import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
6
+	"XT_New/service"
7
+	"XT_New/utils"
8
+	"encoding/json"
9
+	"fmt"
10
+	"github.com/astaxie/beego"
11
+	"github.com/jinzhu/gorm"
12
+	"time"
13
+)
14
+
3 15
 type SecondaryOrderApiController struct {
4 16
 	BaseAuthAPIController
5 17
 }
6 18
 
7 19
 func SecondaryOrderApiRegistRouters() {
20
+	beego.Router("/api/secondary/getcode", &SecondaryOrderApiController{}, "get:GetStoreCode")                      //获取仓库编码
21
+	beego.Router("/api/secondary/updatestatus", &SecondaryOrderApiController{}, "get:UpdateStatus")                 //修改仓库状态
22
+	beego.Router("/api/secondary/deletestorehouse", &SecondaryOrderApiController{}, "get:DeleteStorehouse")         //删除仓库
23
+	beego.Router("/api/secondary/isstorehousename", &SecondaryOrderApiController{}, "get:IsStorehouseName")         //仓库名称是否重复
24
+	beego.Router("/api/secondary/isstorehouseaddress", &SecondaryOrderApiController{}, "get:IsStorehouseAddress")   //仓库地址是否重复
25
+	beego.Router("/api/secondary/storehouselist", &SecondaryOrderApiController{}, "get:StorehouseList")             //分页
26
+	beego.Router("/api/secondary/addstorehouse", &SecondaryOrderApiController{}, "post:AddStorehouse")              //新增仓库
27
+	beego.Router("/api/secondary/updatestorehouse", &SecondaryOrderApiController{}, "post:UpdateStorehouse")        //修改
28
+	beego.Router("/api/secondary/getonestorehouse", &SecondaryOrderApiController{}, "get:GetOneStorehouse")         //查一条仓库的信息
29
+	beego.Router("/api/secondary/getallstorehousename", &SecondaryOrderApiController{}, "get:GetAllStorehouseName") //获取当前机构的所有可用仓库名称
30
+	beego.Router("/api/secondary/findstorehouseconfig", &SecondaryOrderApiController{}, "get:FindStorehouseConfig") //查询该机构的仓库配置
31
+	beego.Router("/api/secondary/updateinfo", &SecondaryOrderApiController{}, "get:UpdateInfo")                     //更改耗材自动入库仓库
32
+	beego.Router("/api/secondary/updateoutinfo", &SecondaryOrderApiController{}, "get:UpdateOutInfo")               //更改耗材自动出库仓库
33
+	beego.Router("/api/secondary/updatedruginfo", &SecondaryOrderApiController{}, "get:UpdateDrugInfo")             //更改药品自动入库仓库
34
+	beego.Router("/api/secondary/updatedrugout", &SecondaryOrderApiController{}, "get:UpdateDrugOut")               //更改药品自动出库仓库
35
+	beego.Router("/api/secondary/byliinit", &SecondaryOrderApiController{}, "get:Byliinit")                         //初始化旧数据
36
+
37
+}
38
+
39
+//获取仓库编码
40
+func (this *SecondaryOrderApiController) GetStoreCode() {
41
+	orgId := this.GetAdminUserInfo().CurrentOrgId
42
+	var code string
43
+	for a := true; a == true; {
44
+		code = service.CreateCode()
45
+		tmp := service.FindStorehouseCode(orgId, code)
46
+		//如果没有重复的编码结束循环
47
+		if tmp == false {
48
+			a = false
49
+		}
50
+	}
51
+	this.ServeSuccessJSON(map[string]interface{}{
52
+		"list": code,
53
+	})
54
+	return
55
+}
56
+
57
+//修改仓库状态
58
+func (this *SecondaryOrderApiController) UpdateStatus() {
59
+	orgId := this.GetAdminUserInfo().CurrentOrgId
60
+	check := map[string][]string{
61
+		"id": {"must", "int", "id"},
62
+	}
63
+	_, err := checkParams(this, &check)
64
+	if err != nil {
65
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
66
+		return
67
+	}
68
+	id, _ := this.GetInt64("id")
69
+	//判断该仓库的库存是否为零
70
+	boolean := service.IsStorehouseNil(id, orgId)
71
+	if boolean == false {
72
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
73
+		return
74
+	}
75
+	//判断该仓库是否在仓库配置表中
76
+	boolean = service.IsInConfig(orgId, id)
77
+	if boolean == true {
78
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
79
+		return
80
+	}
81
+	//修改仓库状态
82
+	err = service.UpdateStorehouseStatus(id)
83
+	if err != nil {
84
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
85
+		return
86
+	}
87
+	this.ServeSuccessJSON(map[string]interface{}{
88
+		"list": "修改成功",
89
+	})
90
+	return
91
+}
92
+
93
+//删除仓库
94
+func (this *SecondaryOrderApiController) DeleteStorehouse() {
95
+	orgId := this.GetAdminUserInfo().CurrentOrgId
96
+	check := map[string][]string{
97
+		"id": {"must", "int", "id"},
98
+	}
99
+	_, err := checkParams(this, &check)
100
+	if err != nil {
101
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
102
+		return
103
+	}
104
+	id, _ := this.GetInt64("id")
105
+	//判断该仓库的库存是否为零
106
+	boolean := service.IsStorehouseNil(id, orgId)
107
+	if boolean == false {
108
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
109
+		return
110
+	}
111
+	//判断该仓库是否在仓库配置表中
112
+	boolean = service.IsInConfig(orgId, id)
113
+	if boolean == true {
114
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
115
+		return
116
+	}
117
+	err = service.DeleteStorehouse(id)
118
+	if err != nil {
119
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
120
+		return
121
+	}
122
+	this.ServeSuccessJSON(map[string]interface{}{
123
+		"list": "删除成功",
124
+	})
125
+	return
126
+}
127
+
128
+//仓库名称是否重复
129
+func (this *SecondaryOrderApiController) IsStorehouseName() {
130
+	orgId := this.GetAdminUserInfo().CurrentOrgId
131
+	storehouse_name := this.GetString("storehouse_name")
132
+	check := map[string][]string{
133
+		"storehouse_name": {"must", "string", "storehouse_name"},
134
+	}
135
+	_, err := checkParams(this, &check)
136
+	if err != nil {
137
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
138
+		return
139
+	}
140
+	var bo bool
141
+	bo, err = service.IsStorehouseName(orgId, storehouse_name)
142
+	if bo == true {
143
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
144
+		return
145
+	}
146
+	this.ServeSuccessJSON(map[string]interface{}{
147
+		"list": "ok",
148
+	})
149
+	return
150
+
151
+}
152
+
153
+//仓库地址是否重复
154
+func (this *SecondaryOrderApiController) IsStorehouseAddress() {
155
+	orgId := this.GetAdminUserInfo().CurrentOrgId
156
+	storehouse_address := this.GetString("storehouse_address")
157
+	check := map[string][]string{
158
+		"storehouse_address": {"must", "string", "storehouse_address"},
159
+	}
160
+	_, err := checkParams(this, &check)
161
+	if err != nil {
162
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
163
+		return
164
+	}
165
+	var bo bool
166
+	bo, err = service.IsStorehouseAddress(orgId, storehouse_address)
167
+	if bo == true {
168
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
169
+		return
170
+	}
171
+	this.ServeSuccessJSON(map[string]interface{}{
172
+		"list": "ok",
173
+	})
174
+	return
175
+
176
+}
177
+
178
+//分页
179
+func (this *SecondaryOrderApiController) StorehouseList() {
180
+	page, _ := this.GetInt64("page")   //页码
181
+	limit, _ := this.GetInt64("limit") //每一页查出来的条数
182
+	check := map[string][]string{
183
+		"page":  {"must", "string", "page"},
184
+		"limit": {"must", "string", "limit"},
185
+	}
186
+	_, err := checkParams(this, &check)
187
+	keyword := this.GetString("keyword")
188
+	orgId := this.GetAdminUserInfo().CurrentOrgId
189
+	if err != nil {
190
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
191
+	}
192
+	//获取分页的数据
193
+	list, total, err := service.StorehouseList(page, limit, orgId, keyword)
194
+	this.ServeSuccessJSON(map[string]interface{}{
195
+		"list":  list,
196
+		"total": total,
197
+	})
198
+}
199
+
200
+//新增仓库
201
+func (this *SecondaryOrderApiController) AddStorehouse() {
202
+	orgId := this.GetAdminUserInfo().CurrentOrgId
203
+	dataBody := make(map[string]interface{}, 0)
204
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
205
+	if err != nil {
206
+		utils.ErrorLog(err.Error())
207
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
208
+		return
209
+	}
210
+	var storehouse_status, admin_id int64
211
+	var admin_name string
212
+	tmpstatus := dataBody["storehouse_status"]
213
+	tmpid := dataBody["storehouse_admin_id"]
214
+	tmpname := dataBody["storehouse_admin_name"]
215
+	if tmpstatus == nil {
216
+		storehouse_status = 1
217
+	} else {
218
+		storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
219
+	}
220
+	if tmpid == nil {
221
+		admin_id = 0
222
+	} else {
223
+		admin_id = int64(dataBody["storehouse_status"].(float64)) //管理员id
224
+	}
225
+	if tmpname == nil {
226
+		admin_name = "admin"
227
+	} else {
228
+		admin_name = dataBody["storehouse_status"].(string) //管理员名称
229
+	}
230
+
231
+	switch {
232
+	case dataBody["storehouse_code"] == nil:
233
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库编号不能为空")
234
+		return
235
+	case dataBody["storehouse_name"] == nil:
236
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
237
+		return
238
+	case dataBody["storehouse_address"] == nil:
239
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
240
+		return
241
+	}
242
+	code := dataBody["storehouse_code"].(string)       //仓库编号
243
+	name := dataBody["storehouse_name"].(string)       //仓库名称
244
+	address := dataBody["storehouse_address"].(string) //地址
245
+	switch {
246
+	case name == "":
247
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
248
+		return
249
+	case address == "":
250
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
251
+		return
252
+	}
253
+
254
+	//判断仓库名称是否重复
255
+	var bo bool
256
+	bo, err = service.IsStorehouseName(orgId, name)
257
+	if bo == true {
258
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
259
+		return
260
+	}
261
+	//判断仓库地址是否重复
262
+	bo, err = service.IsStorehouseAddress(orgId, address)
263
+	if bo == true {
264
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
265
+		return
266
+	}
267
+
268
+	//storehouse_admin := int64(dataBody["storehouse_admin"].(float64))//仓库管理员,暂时不用管
269
+	storehouse := models.Storehouse{
270
+		StorehouseCode:      code,
271
+		StorehouseName:      name,
272
+		StorehouseAddress:   address,
273
+		StorehouseStatus:    storehouse_status,
274
+		UserOrgId:           orgId,
275
+		Status:              1,
276
+		StorehouseAdminId:   admin_id,
277
+		StorehouseAdminName: admin_name,
278
+		Ctime:               time.Now().Unix(),
279
+	}
280
+	err = service.AddStroehouse(storehouse)
281
+	if err != nil {
282
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
283
+		return
284
+	}
285
+	this.ServeSuccessJSON(map[string]interface{}{
286
+		"list": "保存成功",
287
+	})
288
+	return
289
+}
290
+
291
+//修改仓库
292
+func (this *SecondaryOrderApiController) UpdateStorehouse() {
293
+	dataBody := make(map[string]interface{}, 0)
294
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
295
+	if err != nil {
296
+		utils.ErrorLog(err.Error())
297
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
298
+		return
299
+	}
300
+	var storehouse_status int64
301
+	tmpstatus := dataBody["storehouse_status"]
302
+	if tmpstatus == nil {
303
+		storehouse_status = 1
304
+	} else {
305
+		storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
306
+	}
307
+
308
+	switch {
309
+	case dataBody["id"] == nil:
310
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库id不能为空")
311
+		return
312
+	case dataBody["storehouse_name"] == nil:
313
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
314
+		return
315
+	case dataBody["storehouse_address"] == nil:
316
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
317
+		return
318
+	}
319
+	id := int64(dataBody["id"].(float64))
320
+	name := dataBody["storehouse_name"].(string)       //仓库名称
321
+	address := dataBody["storehouse_address"].(string) //地址
322
+
323
+	//storehouse_admin := int64(dataBody["storehouse_admin"].(float64))//仓库管理员,暂时不用管
324
+	storehouse := models.Storehouse{
325
+		ID:                id,
326
+		StorehouseName:    name,
327
+		StorehouseAddress: address,
328
+		StorehouseStatus:  storehouse_status,
329
+		Mtime:             time.Now().Unix(),
330
+	}
331
+	err = service.UpdateStroehouse(storehouse)
332
+	if err != nil {
333
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
334
+		return
335
+	}
336
+	this.ServeSuccessJSON(map[string]interface{}{
337
+		"list": "保存成功",
338
+	})
339
+	return
340
+
341
+}
342
+
343
+//查询一条仓库信息
344
+func (this *SecondaryOrderApiController) GetOneStorehouse() {
345
+	orgId := this.GetAdminUserInfo().CurrentOrgId
346
+	check := map[string][]string{
347
+		"id": {"must", "int", "id"},
348
+	}
349
+	_, err := checkParams(this, &check)
350
+	if err != nil {
351
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
352
+		return
353
+	}
354
+	id, _ := this.GetInt64("id")
355
+	var list models.Storehouse
356
+	list, err = service.GetOneStorehouse(id, orgId)
357
+	if err != nil {
358
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
359
+		return
360
+	}
361
+	this.ServeSuccessJSON(map[string]interface{}{
362
+		"list": list,
363
+	})
364
+	return
365
+}
366
+
367
+//获取当前机构所有可用仓库的名字
368
+func (this *SecondaryOrderApiController) GetAllStorehouseName() {
369
+	orgId := this.GetAdminUserInfo().CurrentOrgId
370
+	list, err := service.GetAllStorehouseName(orgId)
371
+	if err != nil {
372
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
373
+		return
374
+	}
375
+	this.ServeSuccessJSON(map[string]interface{}{
376
+		"list": list,
377
+	})
378
+
379
+}
380
+
381
+//根据机构id查询仓库配置
382
+func (this *SecondaryOrderApiController) FindStorehouseConfig() {
383
+	orgId := this.GetAdminUserInfo().CurrentOrgId
384
+	storehouse, err := service.FindStorehouseConfig(orgId)
385
+	//如果没有仓库配置信息就新建一个
386
+	if err == gorm.ErrRecordNotFound {
387
+		err := service.GetDefaultStorehouse(orgId)
388
+		if err != nil {
389
+			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
390
+			return
391
+		}
392
+		storehouse, err = service.FindStorehouseConfig(orgId)
393
+		if err != nil {
394
+			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
395
+			return
396
+		}
397
+	}
398
+	if err != nil && err.Error() != "record not found" {
399
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
400
+		return
401
+	}
402
+	var storehouse_info, storehouse_out_info, drug_storehouse_info, drug_storehouse_out models.Storehouse
403
+	storehouse_info, err = service.FindStorehouseName(storehouse.StorehouseInfo)
404
+	if err != nil {
405
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
406
+		return
407
+	}
408
+	storehouse_out_info, err = service.FindStorehouseName(storehouse.StorehouseOutInfo)
409
+	if err != nil {
410
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
411
+		return
412
+	}
413
+	drug_storehouse_info, err = service.FindStorehouseName(storehouse.DrugStorehouseInfo)
414
+	if err != nil {
415
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
416
+		return
417
+	}
418
+	drug_storehouse_out, err = service.FindStorehouseName(storehouse.DrugStorehouseOut)
419
+	if err != nil {
420
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
421
+		return
422
+	}
423
+	this.ServeSuccessJSON(map[string]interface{}{
424
+		"storehouse_info":      storehouse_info.StorehouseName,
425
+		"storehouse_out_info":  storehouse_out_info.StorehouseName,
426
+		"drug_storehouse_info": drug_storehouse_info.StorehouseName,
427
+		"drug_storehouse_out":  drug_storehouse_out.StorehouseName,
428
+	})
429
+	return
430
+}
431
+
432
+//更改耗材自动入库仓库
433
+func (this *SecondaryOrderApiController) UpdateInfo() {
434
+	orgId := this.GetAdminUserInfo().CurrentOrgId
435
+	check := map[string][]string{
436
+		"id": {"must", "int", "id"},
437
+	}
438
+	_, err := checkParams(this, &check)
439
+	if err != nil {
440
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
441
+		return
442
+	}
443
+	id, _ := this.GetInt64("id")
444
+	err = service.UpdateInfo(orgId, id)
445
+	if err != nil {
446
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
447
+		return
448
+	}
449
+	this.ServeSuccessJSON(map[string]interface{}{
450
+		"list": "修改成功",
451
+	})
452
+	return
453
+
454
+}
455
+
456
+//更改耗材自动出库仓库
457
+func (this *SecondaryOrderApiController) UpdateOutInfo() {
458
+	orgId := this.GetAdminUserInfo().CurrentOrgId
459
+	check := map[string][]string{
460
+		"id": {"must", "int", "id"},
461
+	}
462
+	_, err := checkParams(this, &check)
463
+	if err != nil {
464
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
465
+		return
466
+	}
467
+	id, _ := this.GetInt64("id")
468
+	err = service.UpdateOutInfo(orgId, id)
469
+	if err != nil {
470
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
471
+		return
472
+	}
473
+	this.ServeSuccessJSON(map[string]interface{}{
474
+		"list": "修改成功",
475
+	})
476
+	return
477
+
478
+}
479
+
480
+//更改药品自动入库仓库
481
+func (this *SecondaryOrderApiController) UpdateDrugInfo() {
482
+	orgId := this.GetAdminUserInfo().CurrentOrgId
483
+	check := map[string][]string{
484
+		"id": {"must", "int", "id"},
485
+	}
486
+	_, err := checkParams(this, &check)
487
+	if err != nil {
488
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
489
+		return
490
+	}
491
+	id, _ := this.GetInt64("id")
492
+	err = service.UpdateDrugInfo2(orgId, id)
493
+	if err != nil {
494
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
495
+		return
496
+	}
497
+	this.ServeSuccessJSON(map[string]interface{}{
498
+		"list": "修改成功",
499
+	})
500
+	return
501
+
502
+}
503
+
504
+//更改药品自动出库仓库
505
+func (this *SecondaryOrderApiController) UpdateDrugOut() {
506
+	orgId := this.GetAdminUserInfo().CurrentOrgId
507
+	check := map[string][]string{
508
+		"id": {"must", "int", "id"},
509
+	}
510
+	_, err := checkParams(this, &check)
511
+	if err != nil {
512
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
513
+		return
514
+	}
515
+	id, _ := this.GetInt64("id")
516
+	err = service.UpdateDrugOut(orgId, id)
517
+	if err != nil {
518
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
519
+		return
520
+	}
521
+	this.ServeSuccessJSON(map[string]interface{}{
522
+		"list": "修改成功",
523
+	})
524
+	return
525
+
526
+}
527
+
528
+//判断前端参数是否为空
529
+func checkParams(this *SecondaryOrderApiController, m *map[string][]string) (map[string]string, error) {
530
+	tmp := make(map[string]string)
531
+	for k, v := range *m {
532
+		t := this.GetString(k)
533
+		if v[0] == "must" && t == "" {
534
+			return nil, fmt.Errorf(v[2] + "不能为空")
535
+		}
536
+		tmp[k] = t
537
+	}
538
+	return tmp, nil
539
+}
8 540
 
541
+//兼容旧数据
542
+func (this *SecondaryOrderApiController) Byliinit() {
543
+	err := service.Byliinit()
544
+	if err != nil {
545
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
546
+		return
547
+	}
548
+	this.ServeSuccessJSON(map[string]interface{}{
549
+		"list": "初始化成功",
550
+	})
551
+	return
9 552
 }

+ 9 - 0
controllers/verify_login_controller.go View File

@@ -301,6 +301,15 @@ func (this *VerifyUserLoginAPIController) VerifyToken() {
301 301
 			}
302 302
 
303 303
 			subscibe, _ := service.GetOrgSubscibe(adminUserInfo.CurrentOrgId)
304
+			//判断该机构是否需要生成默认仓库
305
+			orgid := adminUserInfo.CurrentOrgId
306
+			boolean := service.IsStorehouse(orgid)
307
+			if boolean == false {
308
+				err = service.GetDefaultStorehouse(orgid)
309
+				if err != nil {
310
+					utils.ErrorLog("创建默认仓库失败,原因为:", err)
311
+				}
312
+			}
304 313
 
305 314
 			this.SetSession("admin_user_info", adminUserInfo)
306 315
 

+ 33 - 1
models/secondary_models.go View File

@@ -1,5 +1,37 @@
1 1
 package models
2 2
 
3
-func main() {
3
+//二级仓库
4
+type Storehouse struct {
5
+	ID                  int64  `gorm:"column:id" json:"id" form:"id"`
6
+	StorehouseCode      string `gorm:"column:storehouse_code" json:"storehouse_code" form:"storehouse_code"`                 //仓库编号
7
+	StorehouseName      string `gorm:"column:storehouse_name" json:"storehouse_name" form:"storehouse_name"`                 //仓库名称
8
+	StorehouseAddress   string `gorm:"column:storehouse_address" json:"storehouse_address" form:"storehouse_address"`        //仓库地址
9
+	StorehouseStatus    int64  `gorm:"column:storehouse_status" json:"storehouse_status" form:"storehouse_status"`           //仓库状态
10
+	Status              int64  `gorm:"column:status" json:"status" form:"status"`                                            //数据状态
11
+	StorehouseAdminId   int64  `gorm:"column:storehouse_admin_id" json:"storehouse_admin_id" form:"storehouse_admin_id"`     //仓库管理员id
12
+	StorehouseAdminName string `gorm:"column:storehouse_admin_name" json:"storehouse_admin_name" form:"storehouse_admin_id"` //仓库管理员名字
13
+	UserOrgId           int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
14
+	Ctime               int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
15
+	Mtime               int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
16
+}
17
+
18
+func (Storehouse) TableName() string {
19
+	return "xt_storehouse"
20
+}
21
+
22
+//仓库配置
23
+type StorehouseConfig struct {
24
+	ID                 int64 `gorm:"column:id" json:"id" form:"id"`
25
+	UserOrgId          int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`                         //机构id
26
+	StorehouseInfo     int64 `gorm:"column:storehouse_info" json:"storehouse_info" form:"storehouse_info"`             //耗材 自动入库 的仓库id
27
+	StorehouseOutInfo  int64 `gorm:"column:storehouse_out_info" json:"storehouse_out_info" form:"storehouse_out_info"` //耗材 自动出库 的仓库id
28
+	DrugStorehouseInfo int64 `gorm:"drug_storehouse_info" json:"drug_storehouse_info" form:"drug_storehouse_info"`     //药品 自动入库 的仓库id
29
+	DrugStorehouseOut  int64 `gorm:"drug_storehouse_out" json:"drug_storehouse_out" form:"drug_storehouse_out"`        //药品 自动出库 的仓库id
30
+	Status             int64 `gorm:"status" json:"status" form:"status"`
31
+	Ctime              int64 `gorm:"ctime" json:"ctime" form:"ctime"`
32
+	Mtime              int64 `gorm:"mtime" json:"mtime" form:"mtime"`
33
+}
4 34
 
35
+func (StorehouseConfig) TableName() string {
36
+	return "xt_storehouse_config"
5 37
 }

+ 1 - 0
models/self_drug_models.go View File

@@ -414,6 +414,7 @@ type XtDrugWarehouseInfo struct {
414 414
 	XtBaseDrug                XtBaseDrug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
415 415
 	SupplyWarehouseId         int64      `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
416 416
 	SupplyWarehouseDetailInfo int64      `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
417
+	StorehouseId              int64      `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
417 418
 }
418 419
 
419 420
 func (XtDrugWarehouseInfo) TableName() string {

+ 2 - 0
models/stock_models.go View File

@@ -135,6 +135,7 @@ type WarehousingInfo struct {
135 135
 	PackingPrice              float64     `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
136 136
 	SupplyWarehouseId         int64       `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
137 137
 	SupplyWarehouseDetailInfo int64       `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
138
+	StorehouseId              int64       `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
138 139
 }
139 140
 
140 141
 func (WarehousingInfo) TableName() string {
@@ -243,6 +244,7 @@ type WarehouseOutInfo struct {
243 244
 	SupplyCancelOutId       int64        `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
244 245
 	SupplyWarehouseId       int64        `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
245 246
 	IsSource                int64        `gorm:"column:is_source" json:"is_source" form:"is_source"`
247
+	StorehouseId            int64        `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
246 248
 }
247 249
 
248 250
 func (WarehouseOutInfo) TableName() string {

+ 668 - 1
service/secondary_service.go View File

@@ -1,5 +1,672 @@
1 1
 package service
2 2
 
3
-func main() {
3
+import (
4
+	"XT_New/models"
5
+	"XT_New/utils"
6
+	"fmt"
7
+	"github.com/jinzhu/gorm"
8
+	"math/rand"
9
+	"time"
10
+)
4 11
 
12
+//生成编号,规则为:"sh-"+4位随机数
13
+func CreateCode() string {
14
+	s := fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(10000))
15
+	code := "sh-" + s
16
+	return code
17
+}
18
+
19
+//查询编号是否重复
20
+func FindStorehouseCode(orgid int64, code string) bool {
21
+	var total int
22
+	XTReadDB().Model(&models.Storehouse{}).Where(" storehouse_code = ? and user_org_id = ? and status = 1", code, orgid).Count(&total)
23
+	if total > 0 {
24
+		return true
25
+	} else {
26
+		return false
27
+	}
28
+}
29
+
30
+//判断仓库的库存是否为零 true为零,false不为零
31
+func IsStorehouseNil(id, orgid int64) bool { //根据 id gro_id 查为零的库存
32
+	var h, y int
33
+	//判断耗材是否为零
34
+	XTReadDB().Model(&models.WarehousingInfo{}).Where("stock_count > 0 and status = 1 and org_id = ? and storehouse_id = ?", orgid, id).Count(&h)
35
+	if h > 0 {
36
+		return false
37
+	}
38
+	//判断药品是否为零
39
+	XTReadDB().Model(&models.XtDrugWarehouseInfo{}).Where("stock_max_number > 0 or stock_min_number > 0 ").Where(" org_id = ? and storehouse_id = ?", orgid, id).Count(&y)
40
+	if y > 0 {
41
+		return false
42
+	}
43
+	return true
44
+}
45
+
46
+//修改仓库状态
47
+func UpdateStorehouseStatus(id int64) error {
48
+	err := XTWriteDB().Exec("UPDATE xt_storehouse,(SELECT CASE storehouse_status WHEN 1 THEN 0 WHEN 0 THEN 1 END AS tt FROM xt_storehouse WHERE id=?)tmp SET storehouse_status = tmp.tt where id=?", id, id).Error
49
+	return err
50
+}
51
+
52
+//删除仓库
53
+func DeleteStorehouse(id int64) error {
54
+	err := XTWriteDB().Model(&models.Storehouse{}).Where("id = ?", id).Update("status", 0).Error
55
+	return err
56
+}
57
+
58
+//查询仓库名称是否重复
59
+func IsStorehouseName(orgid int64, storehouse_name string) (bool, error) {
60
+	var total int
61
+	var tmp bool
62
+	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_name = ? and user_org_id = ? and status = 1", storehouse_name, orgid).Count(&total).Error
63
+	if total > 0 {
64
+		tmp = true //有重复的
65
+	} else {
66
+		tmp = false
67
+	}
68
+	return tmp, err
69
+}
70
+
71
+//查询仓库地址是否重复
72
+func IsStorehouseAddress(orgid int64, storehouse_address string) (bool, error) {
73
+	var total int
74
+	var tmp bool
75
+	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_address = ? and user_org_id = ? and status = 1", storehouse_address, orgid).Count(&total).Error
76
+	if total > 0 {
77
+		tmp = true //有重复的
78
+	} else {
79
+		tmp = false
80
+	}
81
+	return tmp, err
82
+}
83
+
84
+//新增仓库
85
+func AddStroehouse(storehouse models.Storehouse) error {
86
+	tx := XTWriteDB().Begin()
87
+	defer func() {
88
+		if err != nil {
89
+			tx.Rollback()
90
+		} else {
91
+			tx.Commit()
92
+		}
93
+	}()
94
+	//创建仓库
95
+	err := tx.Create(&storehouse).Error
96
+	if err != nil {
97
+		return err
98
+	}
99
+	var id models.Storehouse
100
+	//获取创建仓库的id
101
+	err = tx.Model(&models.Storehouse{}).Select("id").Where("status = 1 and user_org_id = ?", storehouse.UserOrgId).Order("id desc").First(&id).Error
102
+	if err != nil {
103
+		return err
104
+	}
105
+	//判断是否存在仓库配置
106
+	boolean := IsStorehouseconfigXT(storehouse.UserOrgId, tx)
107
+	if boolean == false {
108
+		//创建仓库配置
109
+		err = CreateStorehouseConfigXT(storehouse.UserOrgId, id.ID, tx)
110
+	} else {
111
+		utils.ErrorLog("仓库配置已存在")
112
+	}
113
+
114
+	return err
115
+}
116
+
117
+//修改仓库
118
+func UpdateStroehouse(storehouse models.Storehouse) error {
119
+	err := XTWriteDB().Model(&models.Storehouse{}).Where("id = ? and status = 1", storehouse.ID).Updates(
120
+		map[string]interface{}{
121
+			"storehouse_name":    storehouse.StorehouseName,
122
+			"storehouse_address": storehouse.StorehouseAddress,
123
+			"storehouse_status":  storehouse.StorehouseStatus,
124
+			"mtime":              storehouse.Mtime,
125
+		}).Error
126
+	return err
127
+}
128
+
129
+//查询一条仓库的信息
130
+func GetOneStorehouse(id, orgid int64) (storehouse models.Storehouse, err error) {
131
+	err = XTReadDB().Model(&models.Storehouse{}).Where("id = ? and user_org_id = ?", id, orgid).Find(&storehouse).Error
132
+	return
133
+}
134
+
135
+//分页
136
+func StorehouseList(page, limit, orgid int64, keyword string) (storehouse []models.Storehouse, total int64, err error) {
137
+	db := XTReadDB().Model(&storehouse).Where("status = 1 and user_org_id = ?", orgid)
138
+	offset := (page - 1) * limit
139
+	if len(keyword) > 0 {
140
+		keyword = "%" + keyword + "%"
141
+		db = db.Where("storehouse_code like ? or storehouse_name like ? or storehouse_address like ? or storehouse_admin_name like ?", keyword, keyword, keyword, keyword)
142
+	}
143
+	err = db.Count(&total).Offset(offset).Order("id").Limit(limit).Find(&storehouse).Error
144
+	return storehouse, total, err
145
+}
146
+
147
+//获取当前机构所有可用的仓库名字
148
+func GetAllStorehouseName(orgid int64) (storehouse []models.Storehouse, err error) {
149
+	err = XTReadDB().Model(&models.Storehouse{}).Where("storehouse_status = 1 and status = 1 and user_org_id = ?", orgid).Find(&storehouse).Error
150
+	return
151
+}
152
+
153
+//根据机构id,生成一个默认仓库
154
+func GetDefaultStorehouse(orgid int64) error {
155
+	var code string
156
+	for a := true; a == true; {
157
+		code = CreateCode()
158
+		tmp := FindStorehouseCode(orgid, code)
159
+		//如果没有重复的编码结束循环
160
+		if tmp == false {
161
+			a = false
162
+		}
163
+	}
164
+	storehouse := models.Storehouse{
165
+		StorehouseCode:      code,
166
+		StorehouseName:      "默认仓库",
167
+		StorehouseAddress:   "",
168
+		StorehouseStatus:    1,
169
+		UserOrgId:           orgid,
170
+		StorehouseAdminName: "admin",
171
+		Status:              1,
172
+		Ctime:               time.Now().Unix(),
173
+	}
174
+	err := AddStroehouse(storehouse)
175
+	return err
176
+}
177
+
178
+//查找该机构id是否有仓库存在,ture存在,false不存在
179
+func IsStorehouse(orgid int64) bool {
180
+	var total int
181
+	XTReadDB().Model(&models.Storehouse{}).Where("user_org_id = ?", orgid).Count(&total)
182
+	if total > 0 {
183
+		return true
184
+	} else {
185
+		return false
186
+	}
187
+}
188
+
189
+//查找该机构id是否有仓库配置存在,ture存在,false不存在
190
+func IsStorehouseconfigXT(orgid int64, tx *gorm.DB) bool {
191
+	var total int
192
+	tx.Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Count(&total)
193
+	if total > 0 {
194
+		return true
195
+	} else {
196
+		return false
197
+	}
198
+}
199
+
200
+//  根据机构id查询仓库配置
201
+//storehouse_info:耗材 自动入库 的仓库id
202
+//storehouse_out_info:耗材 自动出库 的仓库id
203
+//drug_storehouse_info:药品 自动入库 的仓库id
204
+//drug_storehouse_out:药品 自动出库 的仓库id
205
+func FindStorehouseConfig(orgid int64) (storehouse_config models.StorehouseConfig, err error) {
206
+	err = XTReadDB().Model(&models.StorehouseConfig{}).Where("status = 1 and user_org_id = ?", orgid).Find(&storehouse_config).Error
207
+	return
208
+}
209
+
210
+//根据机构id,仓库id新建一个仓库配置
211
+func CreateStorehouseConfig(orgid, id int64) (err error) {
212
+	storeconfig := models.StorehouseConfig{
213
+		UserOrgId:          orgid,
214
+		StorehouseInfo:     id,
215
+		StorehouseOutInfo:  id,
216
+		DrugStorehouseInfo: id,
217
+		DrugStorehouseOut:  id,
218
+		Status:             1,
219
+		Ctime:              time.Now().Unix(),
220
+	}
221
+	err = XTWriteDB().Create(&storeconfig).Error
222
+	return
223
+}
224
+
225
+//根据机构id,仓库id新建一个仓库配置,带事务
226
+func CreateStorehouseConfigXT(orgid, id int64, tx *gorm.DB) (err error) {
227
+	storeconfig := models.StorehouseConfig{
228
+		UserOrgId:          orgid,
229
+		StorehouseInfo:     id,
230
+		StorehouseOutInfo:  id,
231
+		DrugStorehouseInfo: id,
232
+		DrugStorehouseOut:  id,
233
+		Status:             1,
234
+		Ctime:              time.Now().Unix(),
235
+	}
236
+	err = tx.Create(&storeconfig).Error
237
+	return
238
+}
239
+
240
+//更改耗材自动入库仓库
241
+func UpdateInfo(orgid, id int64) (err error) {
242
+	mtime := time.Now().Unix()
243
+	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"storehouse_info": id, "mtime": mtime}).Error
244
+	return
245
+}
246
+
247
+//更改耗材自动出库仓库
248
+func UpdateOutInfo(orgid, id int64) (err error) {
249
+	mtime := time.Now().Unix()
250
+	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"storehouse_out_info": id, "mtime": mtime}).Error
251
+	return
252
+}
253
+
254
+//更改药品自动入库仓库
255
+func UpdateDrugInfo2(orgid, id int64) (err error) {
256
+	mtime := time.Now().Unix()
257
+	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"drug_storehouse_info": id, "mtime": mtime}).Error
258
+	return
259
+}
260
+
261
+//更改药品自动出库仓库
262
+func UpdateDrugOut(orgid, id int64) (err error) {
263
+	mtime := time.Now().Unix()
264
+	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"drug_storehouse_out": id, "mtime": mtime}).Error
265
+	return
266
+}
267
+
268
+//根据id查询仓库名称
269
+func FindStorehouseName(id int64) (storehouse models.Storehouse, err error) {
270
+	err = XTReadDB().Model(&models.Storehouse{}).Where("id = ?", id).Find(&storehouse).Error
271
+	return
272
+}
273
+
274
+//判断该仓库是否在仓库配置表中
275
+func IsInConfig(orgid, id int64) bool {
276
+	var total int
277
+	XTReadDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Where(
278
+		"storehouse_info = ? or storehouse_out_info = ? or drug_storehouse_info = ? or drug_storehouse_out = ?", id, id, id, id).Count(&total)
279
+	if total > 0 {
280
+		return true //存在
281
+	} else {
282
+		return false
283
+	}
284
+}
285
+
286
+//兼容旧数据
287
+func Byliinit() (err error) {
288
+	tx := XTWriteDB().Begin()
289
+	defer func() {
290
+		if err != nil && err.Error() != "record not found" {
291
+			tx.Rollback()
292
+		} else {
293
+			tx.Commit()
294
+		}
295
+	}()
296
+	err = StoreReduceOrg(tx)
297
+	if err != nil && err.Error() != "record not found" {
298
+		return
299
+	}
300
+	err = StoreReduceConfig(tx)
301
+	if err != nil && err.Error() != "record not found" {
302
+		return
303
+	}
304
+	err = initxt_stock_flow(tx)
305
+	if err != nil && err.Error() != "record not found" {
306
+		return
307
+	}
308
+	err = initxt_drug_flow(tx)
309
+	if err != nil && err.Error() != "record not found" {
310
+		return
311
+	}
312
+	err = initdialysis_before_prepare(tx)
313
+	if err != nil && err.Error() != "record not found" {
314
+		return
315
+	}
316
+	err = initxt_automatic_reduce_detail(tx)
317
+	if err != nil && err.Error() != "record not found" {
318
+		return
319
+	}
320
+	err = initxt_drug_automatic_reduce_detail(tx)
321
+	if err != nil && err.Error() != "record not found" {
322
+		return
323
+	}
324
+	err = initxt_warehouse(tx)
325
+	if err != nil && err.Error() != "record not found" {
326
+		return
327
+	}
328
+	err = initxt_warehouse_info(tx)
329
+	if err != nil && err.Error() != "record not found" {
330
+		return
331
+	}
332
+	err = initxt_warehouse_out(tx)
333
+	if err != nil && err.Error() != "record not found" {
334
+		return
335
+	}
336
+	err = initxt_warehouse_out_info(tx)
337
+	if err != nil && err.Error() != "record not found" {
338
+		return
339
+	}
340
+	err = initxt_drug_warehouse(tx)
341
+	if err != nil && err.Error() != "record not found" {
342
+		return
343
+	}
344
+	err = initxt_drug_warehouse_info(tx)
345
+	if err != nil && err.Error() != "record not found" {
346
+		return
347
+	}
348
+	err = initxt_drug_warehouse_out(tx)
349
+	if err != nil && err.Error() != "record not found" {
350
+		return
351
+	}
352
+	err = initxt_drug_warehouse_out_info(tx)
353
+	if err != nil && err.Error() != "record not found" {
354
+		return
355
+	}
356
+	err = initxt_cancel_stock(tx)
357
+	if err != nil && err.Error() != "record not found" {
358
+		return
359
+	}
360
+	err = initxt_cancel_stock_info(tx)
361
+	if err != nil && err.Error() != "record not found" {
362
+		return
363
+	}
364
+	err = initxt_drug_cancel_stock(tx)
365
+	if err != nil && err.Error() != "record not found" {
366
+		return
367
+	}
368
+	err = initxt_drug_cancel_stock_info(tx)
369
+	if err != nil && err.Error() != "record not found" {
370
+		return
371
+	}
372
+	err = initxt_supplier_warehouse_info(tx)
373
+	if err != nil && err.Error() != "record not found" {
374
+		return
375
+	}
376
+	err = initxt_supplier_warehousing_info_order(tx)
377
+	if err != nil && err.Error() != "record not found" {
378
+		return
379
+	}
380
+	err = initxt_supplier_warehouse_out(tx)
381
+	if err != nil && err.Error() != "record not found" {
382
+		return
383
+	}
384
+	err = initxt_supplier_warehousing_out_order(tx)
385
+	if err != nil && err.Error() != "record not found" {
386
+		return
387
+	}
388
+	err = initxt_supplier_warehouse_cancel(tx)
389
+	if err != nil && err.Error() != "record not found" {
390
+		return
391
+	}
392
+	err = initxt_supplier_warehousing_cancel_order(tx)
393
+
394
+	return
395
+}
396
+
397
+//根据xt_gobal_template 获取的机构id减去仓库表存在的机构id,把结果插入到仓库表
398
+func StoreReduceOrg(tx *gorm.DB) (err error) {
399
+	err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse(storehouse_code,storehouse_name,user_org_id,ctime)" +
400
+		"SELECT CONCAT(\"sh-\",FLOOR(RAND()*9000+1000)),\"默认仓库\",tmp.id,UNIX_TIMESTAMP()" +
401
+		"FROM" +
402
+		"(select t1.org_id as id FROM sgj_xt.xt_gobal_template as t1 LEFT JOIN " +
403
+		"(SELECT distinct user_org_id as i FROM sgj_xt.xt_storehouse) as t2 on t1.org_id = t2.i WHERE t2.i is null and t1.status = 1)tmp").Error
404
+	//err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse(storehouse_code,storehouse_name,user_org_id,ctime)" +
405
+	//	"SELECT CONCAT(\"sh-\",FLOOR(RAND()*9000+1000)),\"默认仓库\",tmp.id,UNIX_TIMESTAMP()" +
406
+	//	"FROM" +
407
+	//	"(select t1.id FROM sgj_users.sgj_user_org as t1 LEFT JOIN " +
408
+	//	"(SELECT distinct user_org_id as i FROM sgj_xt.xt_storehouse) as t2 on t1.id = t2.i WHERE t2.i is null and t1.status != 0 and t1.import = 0)tmp").Error
409
+	return
410
+}
411
+
412
+//查找仓库表的orgid 减去仓库配置表的orgid,把结果插入到仓库配置表
413
+func StoreReduceConfig(tx *gorm.DB) (err error) {
414
+	err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse_config(user_org_id,storehouse_info,storehouse_out_info,drug_storehouse_info,drug_storehouse_out,ctime)" +
415
+		"SELECT tmp.user_org_id,tmp.id,tmp.id,tmp.id,tmp.id,UNIX_TIMESTAMP()" +
416
+		"FROM(select t1.id,t1.user_org_id FROM sgj_xt.xt_storehouse as t1 LEFT JOIN " +
417
+		"(SELECT user_org_id as i FROM sgj_xt.xt_storehouse_config) as t2 on t1.user_org_id = t2.i WHERE t2.i is null and t1.status = 1)tmp").Error
418
+	return
419
+}
420
+
421
+//初始化 xt_stock_flow(完成)
422
+func initxt_stock_flow(tx *gorm.DB) (err error) {
423
+	err = tx.Exec("UPDATE sgj_xt.xt_stock_flow as t," +
424
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
425
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_stock_flow  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
426
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
427
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
428
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
429
+	return
430
+}
431
+
432
+//初始化 xt_drug_flow(完成)
433
+func initxt_drug_flow(tx *gorm.DB) (err error) {
434
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_flow as t," +
435
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
436
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_drug_flow  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
437
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
438
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
439
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
440
+	return
441
+}
442
+
443
+//初始化 dialysis_before_prepare(完成)
444
+func initdialysis_before_prepare(tx *gorm.DB) (err error) {
445
+	err = tx.Exec("UPDATE sgj_xt.dialysis_before_prepare as t," +
446
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
447
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.dialysis_before_prepare  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
448
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
449
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
450
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
451
+	return
452
+}
453
+
454
+//初始化 xt_automatic_reduce_detail(完成)
455
+func initxt_automatic_reduce_detail(tx *gorm.DB) (err error) {
456
+	err = tx.Exec("UPDATE sgj_xt.xt_automatic_reduce_detail as t," +
457
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
458
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_automatic_reduce_detail  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
459
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
460
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
461
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
462
+	return
463
+}
464
+
465
+//初始化 xt_drug_automatic_reduce_detail(完成)
466
+func initxt_drug_automatic_reduce_detail(tx *gorm.DB) (err error) {
467
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_automatic_reduce_detail as t," +
468
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
469
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_automatic_reduce_detail  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
470
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
471
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
472
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
473
+	return
474
+}
475
+
476
+//初始化 xt_warehouse(完成)
477
+func initxt_warehouse(tx *gorm.DB) (err error) {
478
+	err = tx.Exec("UPDATE sgj_xt.xt_warehouse as t," +
479
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
480
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
481
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
482
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
483
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
484
+	return
485
+}
486
+
487
+//初始化 xt_warehouse_info(完成)
488
+func initxt_warehouse_info(tx *gorm.DB) (err error) {
489
+	err = tx.Exec("UPDATE sgj_xt.xt_warehouse_info as t," +
490
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
491
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
492
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
493
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
494
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
495
+	return
496
+}
497
+
498
+//初始化 xt_warehouse_out(完成)
499
+func initxt_warehouse_out(tx *gorm.DB) (err error) {
500
+	err = tx.Exec("UPDATE sgj_xt.xt_warehouse_out as t," +
501
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
502
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_out  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
503
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
504
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
505
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
506
+	return
507
+}
508
+
509
+//初始化 xt_warehouse_out_info(完成)
510
+func initxt_warehouse_out_info(tx *gorm.DB) (err error) {
511
+	err = tx.Exec("UPDATE sgj_xt.xt_warehouse_out_info as t," +
512
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
513
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_out_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
514
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
515
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
516
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
517
+	return
518
+}
519
+
520
+//初始化 xt_drug_warehouse(完成)
521
+func initxt_drug_warehouse(tx *gorm.DB) (err error) {
522
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse as t," +
523
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
524
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
525
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
526
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
527
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
528
+	return
529
+}
530
+
531
+//初始化 xt_drug_warehouse_info(完成)
532
+func initxt_drug_warehouse_info(tx *gorm.DB) (err error) {
533
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_info as t," +
534
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
535
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
536
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
537
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
538
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
539
+	return
540
+}
541
+
542
+//初始化 xt_drug_warehouse_out(完成)
543
+func initxt_drug_warehouse_out(tx *gorm.DB) (err error) {
544
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_out as t," +
545
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
546
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_out  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
547
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
548
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
549
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
550
+	return
551
+}
552
+
553
+//初始化 xt_drug_warehouse_out_info(完成)
554
+func initxt_drug_warehouse_out_info(tx *gorm.DB) (err error) {
555
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_out_info as t," +
556
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
557
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_out_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
558
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
559
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
560
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
561
+	return
562
+}
563
+
564
+//初始化 xt_cancel_stock(完成)
565
+func initxt_cancel_stock(tx *gorm.DB) (err error) {
566
+	err = tx.Exec("UPDATE sgj_xt.xt_cancel_stock as t," +
567
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
568
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_cancel_stock  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
569
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
570
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
571
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
572
+	return
573
+}
574
+
575
+//初始化 xt_cancel_stock_info(完成)
576
+func initxt_cancel_stock_info(tx *gorm.DB) (err error) {
577
+	err = tx.Exec("UPDATE sgj_xt.xt_cancel_stock_info as t," +
578
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
579
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_cancel_stock_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
580
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
581
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
582
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
583
+	return
584
+}
585
+
586
+//初始化 xt_drug_cancel_stock(完成)
587
+func initxt_drug_cancel_stock(tx *gorm.DB) (err error) {
588
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock as t," +
589
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
590
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
591
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
592
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
593
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
594
+	return
595
+}
596
+
597
+//初始化 xt_drug_cancel_stock_info(完成)
598
+func initxt_drug_cancel_stock_info(tx *gorm.DB) (err error) {
599
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock_info as t," +
600
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
601
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
602
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
603
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
604
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
605
+	return
606
+}
607
+
608
+//初始化 xt_supplier_warehouse_info(完成)
609
+func initxt_supplier_warehouse_info(tx *gorm.DB) (err error) {
610
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_info as t," +
611
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
612
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
613
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
614
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
615
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
616
+	return
617
+}
618
+
619
+//初始化 xt_supplier_warehousing_info_order(完成)
620
+func initxt_supplier_warehousing_info_order(tx *gorm.DB) (err error) {
621
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_info_order as t," +
622
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
623
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_info_order  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
624
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
625
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
626
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
627
+	return
628
+}
629
+
630
+//初始化 xt_supplier_warehouse_out(完成)
631
+func initxt_supplier_warehouse_out(tx *gorm.DB) (err error) {
632
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_out as t," +
633
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
634
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_out  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
635
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
636
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
637
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
638
+	return
639
+}
640
+
641
+//初始化 xt_supplier_warehousing_out_order(完成)
642
+func initxt_supplier_warehousing_out_order(tx *gorm.DB) (err error) {
643
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_out_order as t," +
644
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
645
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_out_order  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
646
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
647
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
648
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
649
+	return
650
+}
651
+
652
+//初始化 xt_supplier_warehouse_cancel(完成)
653
+func initxt_supplier_warehouse_cancel(tx *gorm.DB) (err error) {
654
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_cancel as t," +
655
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
656
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_cancel  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
657
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
658
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
659
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
660
+	return
661
+}
662
+
663
+//初始化 xt_supplier_warehousing_cancel_order(完成)
664
+func initxt_supplier_warehousing_cancel_order(tx *gorm.DB) (err error) {
665
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_cancel_order as t," +
666
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
667
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_cancel_order  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
668
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
669
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
670
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
671
+	return
5 672
 }