Browse Source

2024/6/17

28169 1 week ago
parent
commit
293aef7d20

BIN
XT_New.exe View File


+ 4 - 4
controllers/base_api_controller.go View File

@@ -83,7 +83,7 @@ func (this *BaseAuthAPIController) Prepare() {
83 83
 		userAdmin.ModifyTime = 1530786071
84 84
 		var subscibe models.ServeSubscibe
85 85
 		subscibe.ID = 11
86
-		subscibe.OrgId = 10164 //机构id
86
+		subscibe.OrgId = 10677 //机构id
87 87
 		subscibe.PeriodStart = 1547447814
88 88
 		subscibe.PeriodEnd = 1550039814
89 89
 		subscibe.State = 1
@@ -93,7 +93,7 @@ func (this *BaseAuthAPIController) Prepare() {
93 93
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
94 94
 		subscibes[4] = &subscibe
95 95
 		var adminUserInfo service.AdminUserInfo
96
-		adminUserInfo.CurrentOrgId = 10164 //机构id小英9675或4
96
+		adminUserInfo.CurrentOrgId = 10677 //机构id小英9675或4
97 97
 		adminUserInfo.CurrentAppId = 12123 //4
98 98
 		adminUserInfo.AdminUser = &userAdmin
99 99
 		adminUserInfo.Subscibes = subscibes
@@ -329,7 +329,7 @@ func (this *BaseServeAPIController) Prepare() {
329 329
 		userAdmin.ModifyTime = 1530786071
330 330
 		var subscibe models.ServeSubscibe
331 331
 		subscibe.ID = 11
332
-		subscibe.OrgId = 10164 //机构id小英9675或4
332
+		subscibe.OrgId = 10677 //机构id小英9675或4
333 333
 		subscibe.PeriodStart = 1538035409
334 334
 		subscibe.PeriodEnd = 1569571409
335 335
 		subscibe.State = 1
@@ -339,7 +339,7 @@ func (this *BaseServeAPIController) Prepare() {
339 339
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
340 340
 		subscibes[4] = &subscibe
341 341
 		var adminUserInfo service.AdminUserInfo
342
-		adminUserInfo.CurrentOrgId = 10164 //机构id小英9675或4
342
+		adminUserInfo.CurrentOrgId = 10677 //机构id小英9675或4
343 343
 		adminUserInfo.CurrentAppId = 12123 //4
344 344
 		adminUserInfo.AdminUser = &userAdmin
345 345
 		adminUserInfo.Subscibes = subscibes

+ 1 - 2
controllers/drug_pharmacy_management_controller.go View File

@@ -111,8 +111,7 @@ func (this *PharmacyApiController) UpdatePharmacyBaseDrug() {
111 111
 
112 112
 	idArrayOne := strings.Split(hisStr, ",")
113 113
 
114
-	fmt.Println("idArray23332233223", idArray)
115
-	fmt.Println("idArrayOne23332233223", idArrayOne)
114
+	fmt.Println("", idArrayOne)
116 115
 
117 116
 	orgId := this.GetAdminUserInfo().CurrentOrgId
118 117
 	service.UpdatePharmacyAdviceBaseDrug(idArray, orgId)

File diff suppressed because it is too large
+ 195 - 457
controllers/drug_stock_api_contorller.go


+ 2 - 2
controllers/his_api_controller.go View File

@@ -5778,7 +5778,7 @@ func (c *HisApiController) CreateHisPrescription() {
5778 5778
 						out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
5779 5779
 
5780 5780
 						if out.ID == 0 {
5781
-							service.AddSigleWarehouseOut(&warehouseOut)
5781
+							service.AddSigleWarehouseOutOne(&warehouseOut)
5782 5782
 						}
5783 5783
 
5784 5784
 						lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
@@ -10988,7 +10988,7 @@ func (c *HisApiController) GetUploadInfo() {
10988 10988
 					//查询是否生成出库单
10989 10989
 					out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
10990 10990
 					if out.ID == 0 {
10991
-						service.AddSigleWarehouseOut(&warehouseOut)
10991
+						service.AddSigleWarehouseOutOne(&warehouseOut)
10992 10992
 					}
10993 10993
 
10994 10994
 					lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)

+ 8 - 8
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -7356,7 +7356,7 @@ func (c *DialysisAPIController) CreateStockOutInfo() {
7356 7356
 				StorehouseId:            houseConfig.StorehouseOutInfo,
7357 7357
 				IsCheck:                 1,
7358 7358
 			}
7359
-			err := service.AddSigleWarehouseOut(&warehouseOut)
7359
+			err := service.AddSigleWarehouseOutOne(&warehouseOut)
7360 7360
 			if err != nil {
7361 7361
 				goodErrcode := models.XtGoodErrcode{
7362 7362
 					UserOrgId:      adminInfo.Org.Id,
@@ -7746,7 +7746,7 @@ func (c *DialysisAPIController) CreateStockOutInfo() {
7746 7746
 				StorehouseId:            houseConfig.StorehouseOutInfo,
7747 7747
 				IsCheck:                 1,
7748 7748
 			}
7749
-			err := service.AddSigleWarehouseOut(&warehouseOut)
7749
+			err := service.AddSigleWarehouseOutOne(&warehouseOut)
7750 7750
 			if err != nil {
7751 7751
 				goodErrcode := models.XtGoodErrcode{
7752 7752
 					UserOrgId:      adminInfo.Org.Id,
@@ -8292,7 +8292,7 @@ func (c *DialysisAPIController) EditConsumables() {
8292 8292
 						_, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
8293 8293
 
8294 8294
 						if errcod == gorm.ErrRecordNotFound {
8295
-							service.AddSigleWarehouseOutInfo(warehouseOutInfo)
8295
+							service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
8296 8296
 							//插入详情明细表
8297 8297
 							stockFlow := models.VmStockFlow{
8298 8298
 								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -8573,7 +8573,7 @@ func (c *DialysisAPIController) EditConsumables() {
8573 8573
 									StorehouseId:            houseConfig.StorehouseOutInfo,
8574 8574
 									IsCheck:                 1,
8575 8575
 								}
8576
-								service.AddSigleWarehouseOut(&warehouseOut)
8576
+								service.AddSigleWarehouseOutOne(&warehouseOut)
8577 8577
 
8578 8578
 							}
8579 8579
 							//出库
@@ -9599,7 +9599,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
9599 9599
 	_, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
9600 9600
 
9601 9601
 	if errcod == gorm.ErrRecordNotFound {
9602
-		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
9602
+		errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
9603 9603
 		//插入详情明细表
9604 9604
 		stockFlow := models.VmStockFlow{
9605 9605
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -9853,7 +9853,7 @@ func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int6
9853 9853
 				StorehouseId:            houseConfig.StorehouseOutInfo,
9854 9854
 				IsCheck:                 1,
9855 9855
 			}
9856
-			err := service.AddSigleWarehouseOut(&warehouseOut)
9856
+			err := service.AddSigleWarehouseOutOne(&warehouseOut)
9857 9857
 			if err != nil {
9858 9858
 				utils.TraceLog("创建出库单失败 err = %v", err)
9859 9859
 				return err
@@ -9933,7 +9933,7 @@ func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *mod
9933 9933
 		warehouseOutInfo.Count = delete_count
9934 9934
 		stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
9935 9935
 		warehouseOutInfo.Price = stockInInfo.Price
9936
-		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
9936
+		errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
9937 9937
 
9938 9938
 		if errOne != nil {
9939 9939
 			return errOne
@@ -10070,7 +10070,7 @@ func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *model
10070 10070
 	_, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
10071 10071
 
10072 10072
 	if errcod == gorm.ErrRecordNotFound {
10073
-		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
10073
+		errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
10074 10074
 
10075 10075
 		//插入详情明细表
10076 10076
 		if errOne != nil {

+ 1 - 1
controllers/mobile_api_controllers/dialysis_api_controller_extend.go View File

@@ -735,7 +735,7 @@ func (this *DialysisAPIController) AddUrgentSchedule() {
735 735
 	scheduleType, _ := this.GetInt64("schedule_type")
736 736
 	modeID, _ := this.GetInt64("mode")
737 737
 	bedID, _ := this.GetInt64("bed")
738
-	if patientID <= 0 || scheduleType < 1 || scheduleType > 3 || modeID < 1 || modeID > 14 || bedID <= 0 {
738
+	if patientID <= 0 || scheduleType < 1 || scheduleType > 3 || modeID < 1 || bedID <= 0 {
739 739
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
740 740
 		return
741 741
 	}

+ 9 - 8
controllers/secondary_order_api_contorller.go View File

@@ -1,19 +1,20 @@
1 1
 package controllers
2 2
 
3 3
 import (
4
-	"XT_New/enums"
5
-	"XT_New/models"
6
-	"XT_New/service"
7
-	"XT_New/utils"
8 4
 	"encoding/json"
9 5
 	"fmt"
10
-	"github.com/astaxie/beego"
11
-	"github.com/jinzhu/gorm"
12 6
 	"math/rand"
13 7
 	"reflect"
14 8
 	"strconv"
15 9
 	"strings"
16 10
 	"time"
11
+
12
+	"XT_New/enums"
13
+	"XT_New/models"
14
+	"XT_New/service"
15
+	"XT_New/utils"
16
+	"github.com/astaxie/beego"
17
+	"github.com/jinzhu/gorm"
17 18
 )
18 19
 
19 20
 type SecondaryOrderApiController struct {
@@ -1278,7 +1279,7 @@ func (this *SecondaryOrderApiController) CheckSecondOrer() {
1278 1279
 					//查询今日是否存在调拨出库
1279 1280
 					_, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
1280 1281
 					if errcodes == gorm.ErrRecordNotFound {
1281
-						service.AddSigleWarehouseOut(&warehouseOut)
1282
+						service.AddSigleWarehouseOutOne(&warehouseOut)
1282 1283
 					}
1283 1284
 
1284 1285
 					out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
@@ -1787,7 +1788,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1787 1788
 				//查询今日是否存在调拨出库
1788 1789
 				_, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
1789 1790
 				if errcodes == gorm.ErrRecordNotFound {
1790
-					service.AddSigleWarehouseOut(&warehouseOut)
1791
+					service.AddSigleWarehouseOutOne(&warehouseOut)
1791 1792
 				}
1792 1793
 
1793 1794
 				out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)

+ 8 - 8
controllers/sign_api_controller.go View File

@@ -1287,14 +1287,14 @@ func (this *SignApiController) ToAutoDiagnose() {
1287 1287
 	//	}
1288 1288
 	//}
1289 1289
 
1290
-	adviceList, _ := service.GetHisDoctorAdviceNoCheck(10721)
1291
-
1292
-	if len(adviceList) > 0 {
1293
-		for _, item := range adviceList {
1294
-			checkObj, _ := service.GetDobuleCheckOne(item.UserOrgId, item.AdviceDate, item.PatientId)
1295
-			service.UpdateHisAdvice(item.PatientId, item.AdviceDate, item.UserOrgId, checkObj.Creater, checkObj.CheckDate)
1296
-		}
1297
-	}
1290
+	//adviceList, _ := service.GetHisDoctorAdviceNoCheck(10721)
1291
+	//
1292
+	//if len(adviceList) > 0 {
1293
+	//	for _, item := range adviceList {
1294
+	//		checkObj, _ := service.GetDobuleCheckOne(item.UserOrgId, item.AdviceDate, item.PatientId)
1295
+	//		service.UpdateHisAdvice(item.PatientId, item.AdviceDate, item.UserOrgId, checkObj.Creater, checkObj.CheckDate)
1296
+	//	}
1297
+	//}
1298 1298
 
1299 1299
 	this.ServeSuccessJSON(map[string]interface{}{
1300 1300
 		"msg": "ok",

+ 193 - 331
controllers/stock_in_api_controller.go View File

@@ -274,15 +274,27 @@ func (c *StockManagerApiController) CreateWarehouse() {
274 274
 	ctime := time.Now().Unix()
275 275
 	adminUserInfo := c.GetAdminUserInfo()
276 276
 
277
+	// 开始外部循环的事务
278
+	db := service.XTWriteDB()
279
+	tx := db.Begin()
280
+
281
+	// 在函数结束时处理事务回滚
282
+	defer func() {
283
+		if r := recover(); r != nil {
284
+			tx.Rollback()
285
+		}
286
+	}()
287
+
277 288
 	warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
278 289
 	if parseDateErr != nil {
279 290
 		c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
280 291
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
281 292
 		return
282 293
 	}
294
+
283 295
 	timeStr := time.Now().Format("2006-01-02")
284 296
 	timeArr := strings.Split(timeStr, "-")
285
-	total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
297
+	total, _ := service.FindNewAllWarehouseTotal(adminUserInfo.CurrentOrgId, tx)
286 298
 	total = total + 1
287 299
 	warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
288 300
 	operation_time := time.Now().Unix()
@@ -300,12 +312,14 @@ func (c *StockManagerApiController) CreateWarehouse() {
300 312
 		IsCheck:          2,
301 313
 	}
302 314
 	if warehousing_info_id == 0 {
303
-		service.AddSigleWarehouse(&warehousing)
315
+
316
+		service.AddNewSigleWarehouse(&warehousing, tx)
304 317
 	}
305 318
 	if warehousing_info_id > 0 {
306
-		service.UpdateWarehouse(warehousing_info_id, storehouse_id)
319
+
320
+		service.UpdateNewWarehouse(warehousing_info_id, storehouse_id, tx)
307 321
 	}
308
-	info, _ := service.FindLastWarehousingSix(adminUserInfo.CurrentOrgId)
322
+	info, _ := service.FindNewLastWarehousingSix(adminUserInfo.CurrentOrgId, tx)
309 323
 	dataBody := make(map[string]interface{}, 0)
310 324
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
311 325
 	if err != nil {
@@ -446,16 +460,19 @@ func (c *StockManagerApiController) CreateWarehouse() {
446 460
 
447 461
 	for _, item := range warehousingInfo {
448 462
 		if item.ID == 0 {
449
-			service.CreatedWarehouseingDetail(item)
463
+			service.CreatedNewWarehouseingDetail(item, tx)
450 464
 		}
451 465
 		if item.ID > 0 {
452
-			service.UpdateWarehouseDetail(item, item.ID)
466
+
467
+			service.UpdateNewWarehouseDetail(item, item.ID, tx)
453 468
 		}
454 469
 
455 470
 	}
456 471
 
457 472
 	//查询入库数据
458
-	list, _ := service.GetGoodWarehouseInfoById(info.ID, info.OrgId)
473
+	list, _ := service.GetNewGoodWarehouseInfoById(info.ID, info.OrgId, tx)
474
+
475
+	tx.Commit()
459 476
 	dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
460 477
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
461 478
 
@@ -560,6 +577,18 @@ func (c *StockManagerApiController) GetWarehouseInfoList() {
560 577
 	}
561 578
 }
562 579
 func (c *StockManagerApiController) EditWarehouse() {
580
+
581
+	// 开始外部循环的事务
582
+	db := service.XTWriteDB()
583
+	tx := db.Begin()
584
+
585
+	// 在函数结束时处理事务回滚
586
+	defer func() {
587
+		if r := recover(); r != nil {
588
+			tx.Rollback()
589
+		}
590
+	}()
591
+
563 592
 	warehousing_time := c.GetString("warehousing_time")
564 593
 	id, _ := c.GetInt64("id", 0)
565 594
 	types, _ := c.GetInt64("type", 0)
@@ -580,7 +609,7 @@ func (c *StockManagerApiController) EditWarehouse() {
580 609
 		return
581 610
 	}
582 611
 
583
-	warehouse, _ := service.FindWarehousingById(id)
612
+	warehouse, _ := service.FindNewWarehousingById(id, tx)
584 613
 
585 614
 	warehousing := models.Warehousing{
586 615
 		WarehousingOrder: warehouse.WarehousingOrder,
@@ -593,7 +622,7 @@ func (c *StockManagerApiController) EditWarehouse() {
593 622
 		StorehouseId:     storehouse_id,
594 623
 	}
595 624
 
596
-	service.EditWarehousing(warehousing)
625
+	service.EditNewWarehousing(warehousing, tx)
597 626
 
598 627
 	dataBody := make(map[string]interface{}, 0)
599 628
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
@@ -605,8 +634,6 @@ func (c *StockManagerApiController) EditWarehouse() {
605 634
 
606 635
 	var warehousingInfo []*models.WarehousingInfo
607 636
 	var upDateWarehousingInfo []*models.WarehousingInfo
608
-	var stockFlow []*models.VmStockFlow
609
-
610 637
 	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
611 638
 		thisStockIn, _ := dataBody["stockIn"].([]interface{})
612 639
 		if len(thisStockIn) > 0 {
@@ -753,44 +780,22 @@ func (c *StockManagerApiController) EditWarehouse() {
753 780
 					}
754 781
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
755 782
 
756
-					flow := &models.VmStockFlow{
757
-						WarehousingOrder:    warehousing.WarehousingOrder,
758
-						WarehousingId:       id,
759
-						GoodId:              good_id,
760
-						Number:              number,
761
-						ProductDate:         productDates,
762
-						ExpireDate:          expiryDates,
763
-						Count:               warehousing_count,
764
-						Price:               price,
765
-						Status:              1,
766
-						Ctime:               ctime,
767
-						UserOrgId:           adminUserInfo.CurrentOrgId,
768
-						Manufacturer:        manufacturer,
769
-						Dealer:              dealer,
770
-						LicenseNumber:       license_number,
771
-						IsEdit:              2,
772
-						Creator:             adminUserInfo.AdminUser.Id,
773
-						SystemTime:          ctime,
774
-						ConsumableType:      1,
775
-						WarehousingDetailId: warehouseInfo.ID,
776
-						StorehouseId:        storehouse_id,
777
-						RegisterNumber:      register_number,
778
-						GoodCode:            good_code,
779
-					}
780
-
781
-					stockFlow = append(stockFlow, flow)
782 783
 				}
783 784
 			}
784 785
 		}
785 786
 	}
786 787
 	var errs error
787 788
 	if len(warehousingInfo) > 0 {
788
-		errs = service.CreateWarehousingInfo(warehousingInfo)
789
+
790
+		errs = service.CreateNewWarehousingInfo(warehousingInfo, tx)
789 791
 	}
790 792
 
791 793
 	if len(upDateWarehousingInfo) > 0 {
792 794
 		for _, item := range upDateWarehousingInfo {
793
-			service.UpdateWarehouseInfoByGoodIdOne(item, item.ID)
795
+			if item.ID > 0 {
796
+				service.UpdateNewWarehouseInfoByGoodIdOne(item, item.ID, tx)
797
+			}
798
+
794 799
 		}
795 800
 	}
796 801
 
@@ -800,7 +805,8 @@ func (c *StockManagerApiController) EditWarehouse() {
800 805
 		return
801 806
 	}
802 807
 
803
-	list, _ := service.GetAllStockInList(id, adminUserInfo.CurrentOrgId)
808
+	list, _ := service.GetNewAllStockInList(id, adminUserInfo.CurrentOrgId, tx)
809
+	tx.Commit()
804 810
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
805 811
 	dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
806 812
 	c.ServeSuccessJSON(map[string]interface{}{
@@ -1258,18 +1264,29 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1258 1264
 		return
1259 1265
 	}
1260 1266
 
1267
+	// 开始外部循环的事务
1268
+	db := service.XTWriteDB()
1269
+	tx := db.Begin()
1270
+
1271
+	// 在函数结束时处理事务回滚
1272
+	defer func() {
1273
+		if r := recover(); r != nil {
1274
+			tx.Rollback()
1275
+		}
1276
+	}()
1277
+
1261 1278
 	if warehouseOut_id == 0 {
1262 1279
 		//查询是否生成出库单
1263
-		warehouseOutObj, _ := service.FindStockOutByIsSysOne(adminUserInfo.CurrentOrgId, 0, operation_time, warehousing_out_order)
1280
+		warehouseOutObj, _ := service.FindStockOutByIsSysOne(adminUserInfo.CurrentOrgId, 0, operation_time, warehousing_out_order, tx)
1264 1281
 
1265 1282
 		if warehouseOutObj.ID == 0 {
1266
-			service.AddSigleWarehouseOut(&warehouseOut)
1283
+			service.AddSigleWarehouseOut(&warehouseOut, tx)
1267 1284
 		}
1268 1285
 
1269 1286
 	}
1270 1287
 
1271 1288
 	if warehouseOut_id > 0 {
1272
-		service.UpdateSingleWarehoseOut(warehouseOut_id, storehouse_id)
1289
+		service.UpdateSingleWarehoseOut(warehouseOut_id, storehouse_id, tx)
1273 1290
 	}
1274 1291
 
1275 1292
 	var warehousingOutInfo []*models.WarehouseOutInfo
@@ -1407,7 +1424,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1407 1424
 		}
1408 1425
 	}
1409 1426
 
1410
-	goodWarehouseOut, _ := service.GetLastGoodWarehouseOutTwenty(adminUserInfo.CurrentOrgId)
1427
+	goodWarehouseOut, _ := service.GetLastGoodWarehouseOutTwentyOne(adminUserInfo.CurrentOrgId, tx)
1411 1428
 
1412 1429
 	if len(warehousingOutInfo) > 0 {
1413 1430
 		for _, it := range warehousingOutInfo {
@@ -1445,24 +1462,25 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1445 1462
 			if it.ID == 0 {
1446 1463
 
1447 1464
 				//查询改耗材是否出库
1448
-				outInfo, _ := service.GetGoodsIsExsit(it.GoodId, it.SysRecordTime, it.OrgId, goodWarehouseOut.ID)
1465
+				outInfo, _ := service.GetGoodsIsExsit(it.GoodId, it.SysRecordTime, it.OrgId, goodWarehouseOut.ID, tx)
1449 1466
 				if outInfo.ID == 0 {
1450
-					service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1467
+					service.AddSigleWarehouseOutInfo(warehouseOutInfo, tx)
1451 1468
 				}
1452 1469
 
1453 1470
 			}
1454 1471
 			if it.ID > 0 {
1455
-				service.ModifyWarehouseOutInfo(it.ID, warehouseOutInfo)
1472
+				service.ModifyWarehouseOutInfo(it.ID, warehouseOutInfo, tx)
1456 1473
 			}
1457 1474
 		}
1458 1475
 	}
1459 1476
 
1460 1477
 	appId := adminUserInfo.CurrentAppId
1461 1478
 
1462
-	warehouseOutInfoList, _ := service.GetLastGoodWarehouseOutInfo(adminUserInfo.CurrentOrgId, goodWarehouseOut.ID)
1479
+	warehouseOutInfoList, _ := service.GetLastGoodWarehouseOutInfo(adminUserInfo.CurrentOrgId, goodWarehouseOut.ID, tx)
1463 1480
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
1464 1481
 	dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
1465 1482
 	doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
1483
+	tx.Commit()
1466 1484
 	c.ServeSuccessJSON(map[string]interface{}{
1467 1485
 		"msg":                  "2",
1468 1486
 		"good_name":            "",
@@ -1618,7 +1636,7 @@ func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
1618 1636
 func (c *StockManagerApiController) GetWarehouseOutInfoList() {
1619 1637
 	id, _ := c.GetInt64("id", 0)
1620 1638
 	warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
1621
-	warehouseOut, _ := service.FindWareHouseOutById(id)
1639
+	warehouseOut, _ := service.FindWareHouseOutByIdOne(id)
1622 1640
 	adminUserInfo := c.GetAdminUserInfo()
1623 1641
 	orgId := adminUserInfo.CurrentOrgId
1624 1642
 	wareoutList, _ := service.GetWareOutInfoById(id, orgId)
@@ -1630,6 +1648,7 @@ func (c *StockManagerApiController) GetWarehouseOutInfoList() {
1630 1648
 
1631 1649
 }
1632 1650
 func (c *StockManagerApiController) EditWarehouseOut() {
1651
+
1633 1652
 	warehouse_out_time := c.GetString("warehouse_out_time")
1634 1653
 	id, _ := c.GetInt64("id", 0)
1635 1654
 	types, _ := c.GetInt64("type", 0)
@@ -1650,7 +1669,18 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1650 1669
 		return
1651 1670
 	}
1652 1671
 
1653
-	warehouseOut, _ := service.FindWareHouseOutById(id)
1672
+	// 开始外部循环的事务
1673
+	db := service.XTWriteDB()
1674
+	tx := db.Begin()
1675
+
1676
+	// 在函数结束时处理事务回滚
1677
+	defer func() {
1678
+		if r := recover(); r != nil {
1679
+			tx.Rollback()
1680
+		}
1681
+	}()
1682
+
1683
+	warehouseOut, _ := service.FindWareHouseOutById(id, tx)
1654 1684
 
1655 1685
 	tempWarehouseOut := models.WarehouseOut{
1656 1686
 		ID:               warehouseOut.ID,
@@ -1659,7 +1689,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1659 1689
 		StorehouseId:     storehouse_id,
1660 1690
 	}
1661 1691
 
1662
-	service.EditWarehouseOut(tempWarehouseOut)
1692
+	service.EditWarehouseOut(tempWarehouseOut, tx)
1663 1693
 
1664 1694
 	dataBody := make(map[string]interface{}, 0)
1665 1695
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
@@ -1871,9 +1901,9 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1871 1901
 
1872 1902
 		for _, item := range warehousingOutInfo {
1873 1903
 			//查询改耗材是否出库
1874
-			outInfo, _ := service.GetGoodsIsExsit(item.GoodId, item.SysRecordTime, item.OrgId, item.WarehouseOutId)
1904
+			outInfo, _ := service.GetGoodsIsExsit(item.GoodId, item.SysRecordTime, item.OrgId, item.WarehouseOutId, tx)
1875 1905
 			if outInfo.ID == 0 {
1876
-				service.AddSigleWarehouseOutInfo(item)
1906
+				service.AddSigleWarehouseOutInfo(item, tx)
1877 1907
 			}
1878 1908
 
1879 1909
 		}
@@ -1881,10 +1911,14 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1881 1911
 
1882 1912
 	if len(upDateWarehouseOutInfos) > 0 {
1883 1913
 		for _, item := range upDateWarehouseOutInfos {
1884
-			service.UpDateWarehouseOutInfo(item)
1914
+			if item.ID > 0 {
1915
+				service.UpDateWarehouseOutInfo(item, tx)
1916
+			}
1917
+
1885 1918
 		}
1886 1919
 	}
1887 1920
 
1921
+	tx.Commit()
1888 1922
 	if errs != nil {
1889 1923
 		utils.ErrorLog(errs.Error())
1890 1924
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
@@ -5755,7 +5789,7 @@ func (this *StockManagerApiController) SaveCheckDamage() {
5755 5789
 	_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
5756 5790
 
5757 5791
 	if errcodes == gorm.ErrRecordNotFound {
5758
-		service.AddSigleWarehouseOut(&warehouseOut)
5792
+		service.AddSigleWarehouseOutOne(&warehouseOut)
5759 5793
 
5760 5794
 	}
5761 5795
 	out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
@@ -5796,8 +5830,8 @@ func (this *StockManagerApiController) SaveCheckDamage() {
5796 5830
 			LicenseNumber:           item.LicenseNumber,
5797 5831
 			GoodTypeId:              goodinfo.GoodTypeId,
5798 5832
 		}
5799
-		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5800
-		fmt.Println("99999999999999", errOne)
5833
+		errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
5834
+		fmt.Println("", errOne)
5801 5835
 
5802 5836
 		//更改库存
5803 5837
 		info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
@@ -6309,7 +6343,7 @@ func (this *StockManagerApiController) SaveCheckInventory() {
6309 6343
 				ProductDate:             warehouseInfo.ProductDate,
6310 6344
 				ExpireDate:              warehouseInfo.ExpiryDate,
6311 6345
 			}
6312
-			errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
6346
+			errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
6313 6347
 			fmt.Println(errOne)
6314 6348
 			//创建出库明细
6315 6349
 			service.CreateStockFlowOne(stockFlow)
@@ -7252,36 +7286,33 @@ func (this *StockManagerApiController) CheckWarehouseOut() {
7252 7286
 
7253 7287
 	id, _ := this.GetInt64("id")
7254 7288
 	orgId := this.GetAdminUserInfo().CurrentOrgId
7255
-	creater := this.GetAdminUserInfo().AdminUser.Id
7256
-	warehouseOut, _ := service.GetWarehouseById(id)
7289
+	// 开始外部循环的事务
7290
+	db := service.XTWriteDB()
7291
+	tx := db.Begin()
7292
+
7293
+	// 在函数结束时处理事务回滚
7294
+	defer func() {
7295
+		if r := recover(); r != nil {
7296
+			tx.Rollback()
7297
+		}
7298
+	}()
7299
+
7300
+	warehouseOut, _ := service.GetNewWarehouseById(id, tx)
7257 7301
 
7258 7302
 	//查询已保存的单据
7259
-	warehousingOutInfo, _ := service.GetWarehouseOutById(id, orgId)
7303
+	warehousingOutInfo, _ := service.GetNewWarehouseOutById(id, orgId, tx)
7260 7304
 
7261 7305
 	////出库逻辑
7262 7306
 	for _, item := range warehousingOutInfo {
7263 7307
 		// 查询该耗材是否有库存
7264
-		warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId, item.StorehouseId)
7265
-		storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
7308
+		warehouseOne, _ := service.FindNewWarehousingInfoTen(item.GoodId, item.StorehouseId, tx)
7309
+
7310
+		storehouse, _ := service.FindNewStoreHouseByStorehouseId(item.StorehouseId, item.OrgId, tx)
7266 7311
 
7267 7312
 		// 如果出库数量大于该批次剩余库存数量
7268 7313
 		if item.Count > warehouseOne.StockCount {
7269
-
7270
-			goodErrcode := models.XtGoodErrcode{
7271
-				UserOrgId:      orgId,
7272
-				Errcode:        "出库数量大于该批次剩余库存",
7273
-				GoodId:         0,
7274
-				Status:         0,
7275
-				Ctime:          0,
7276
-				Mtime:          0,
7277
-				Count:          0,
7278
-				StockCount:     0,
7279
-				Creater:        creater,
7280
-				BatchNumberId:  warehouseOne.ID,
7281
-				WarehouseOutId: item.ID,
7282
-			}
7283
-			service.CreateGoodErrcode(goodErrcode)
7284
-			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
7314
+			goodObj, _ := service.GetNewGoodInformationByGoodId(item.GoodId, tx)
7315
+			tx.Rollback()
7285 7316
 			this.ServeSuccessJSON(map[string]interface{}{
7286 7317
 				"msg":                "1",
7287 7318
 				"good_name":          goodObj.GoodName,
@@ -7297,93 +7328,37 @@ func (this *StockManagerApiController) CheckWarehouseOut() {
7297 7328
 		creater := this.GetAdminUserInfo().AdminUser.Id
7298 7329
 
7299 7330
 		//出库
7300
-		err := service.ConsumablesDeliveryThirty(orgId, item.SysRecordTime, item, &warehouseOut, item.Count, creater)
7331
+		err := service.ConsumablesNewDeliveryThirty(orgId, item.SysRecordTime, item, &warehouseOut, item.Count, creater, tx)
7332
+
7301 7333
 		if err != nil {
7302
-			goodErrcode := models.XtGoodErrcode{
7303
-				UserOrgId:      orgId,
7304
-				Errcode:        "调用出库接口报错",
7305
-				GoodId:         item.GoodId,
7306
-				Status:         1,
7307
-				Ctime:          time.Now().Unix(),
7308
-				Mtime:          0,
7309
-				Count:          0,
7310
-				StockCount:     0,
7311
-				Creater:        creater,
7312
-				BatchNumberId:  0,
7313
-				WarehouseOutId: 0,
7314
-			}
7315
-			service.CreateGoodErrcode(goodErrcode)
7334
+			tx.Rollback()
7335
+			return
7316 7336
 		}
7317 7337
 
7318
-		goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
7338
+		goodList, _ := service.GetNewSumGoodList(orgId, item.StorehouseId, item.GoodId, tx)
7319 7339
 		var flush_count int64
7320 7340
 		for _, it := range goodList {
7321 7341
 			flush_count += it.StockCount
7322 7342
 		}
7323
-		errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
7324
-		if errs != nil {
7325
-			goodErrcode := models.XtGoodErrcode{
7326
-				UserOrgId:      orgId,
7327
-				Errcode:        "手动出库更新剩余出库失败",
7328
-				GoodId:         item.GoodId,
7329
-				Status:         1,
7330
-				Ctime:          time.Now().Unix(),
7331
-				Mtime:          0,
7332
-				Count:          0,
7333
-				StockCount:     0,
7334
-				Creater:        creater,
7335
-				BatchNumberId:  0,
7336
-				WarehouseOutId: 0,
7337
-			}
7338
-			service.CreateGoodErrcode(goodErrcode)
7339
-		}
7343
+		service.UpdateNewSumGood(orgId, item.StorehouseId, item.GoodId, flush_count, tx)
7340 7344
 
7341 7345
 		orgId := this.GetAdminUserInfo().CurrentOrgId
7342 7346
 		//查询默认仓库
7343
-		storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7344
-		stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
7347
+		storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
7348
+		stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
7345 7349
 		var total_count int64
7346 7350
 		for _, it := range stockList {
7347 7351
 			total_count += it.StockCount
7348 7352
 		}
7349 7353
 		//基础库扣减库存
7350
-		errsum := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
7351
-		if errsum != nil {
7352
-			goodErrcode := models.XtGoodErrcode{
7353
-				UserOrgId:      orgId,
7354
-				Errcode:        "基础库扣减库存报错",
7355
-				GoodId:         item.GoodId,
7356
-				Status:         1,
7357
-				Ctime:          time.Now().Unix(),
7358
-				Mtime:          0,
7359
-				Count:          0,
7360
-				StockCount:     0,
7361
-				Creater:        creater,
7362
-				BatchNumberId:  0,
7363
-				WarehouseOutId: 0,
7364
-			}
7365
-			service.CreateGoodErrcode(goodErrcode)
7366
-		}
7354
+		service.UpdateNewGoodInfoReduceSumCount(item.GoodId, total_count, orgId, tx)
7355
+
7367 7356
 	}
7368 7357
 
7369 7358
 	//审核单据
7370
-	err := service.UpdatedWarehouseOut(id)
7371
-	if err != nil {
7372
-		goodErrcode := models.XtGoodErrcode{
7373
-			UserOrgId:      orgId,
7374
-			Errcode:        "审核单据报错",
7375
-			GoodId:         0,
7376
-			Status:         1,
7377
-			Ctime:          time.Now().Unix(),
7378
-			Mtime:          0,
7379
-			Count:          0,
7380
-			StockCount:     0,
7381
-			Creater:        creater,
7382
-			BatchNumberId:  0,
7383
-			WarehouseOutId: 0,
7384
-		}
7385
-		service.CreateGoodErrcode(goodErrcode)
7386
-	}
7359
+	err := service.UpdatedNewWarehouseOut(id, tx)
7360
+
7361
+	tx.Commit()
7387 7362
 	if err == nil {
7388 7363
 		this.ServeSuccessJSON(map[string]interface{}{
7389 7364
 			"msg":                "2",
@@ -7399,162 +7374,50 @@ func (this *StockManagerApiController) ReturnCheckWarehouseOut() {
7399 7374
 
7400 7375
 	id, _ := this.GetInt64("id")
7401 7376
 	orgId := this.GetAdminUserInfo().CurrentOrgId
7402
-	creater := this.GetAdminUserInfo().AdminUser.Id
7377
+
7378
+	// 开始外部循环的事务
7379
+	db := service.XTWriteDB()
7380
+	tx := db.Begin()
7381
+
7382
+	// 在函数结束时处理事务回滚
7383
+	defer func() {
7384
+		if r := recover(); r != nil {
7385
+			tx.Rollback()
7386
+		}
7387
+	}()
7403 7388
 	// 查询出库数据
7404
-	list, err := service.GetWarehouseOutById(id, orgId)
7405
-	if err != nil {
7406
-		goodErrcode := models.XtGoodErrcode{
7407
-			UserOrgId:      orgId,
7408
-			Errcode:        "反审核查询出库单报错",
7409
-			GoodId:         0,
7410
-			Status:         1,
7411
-			Ctime:          time.Now().Unix(),
7412
-			Mtime:          0,
7413
-			Count:          0,
7414
-			StockCount:     0,
7415
-			Creater:        creater,
7416
-			BatchNumberId:  0,
7417
-			WarehouseOutId: 0,
7418
-		}
7419
-		service.CreateGoodErrcode(goodErrcode)
7420
-	}
7389
+	list, err := service.GetNewWarehouseOutById(id, orgId, tx)
7421 7390
 	for _, item := range list {
7422 7391
 		//回退库存
7423
-		err := service.UpdateaGoodWarehouseInfo(item.Count, item.GoodId, item.OrgId, item.WarehouseInfotId)
7424
-		if err != nil {
7425
-			goodErrcode := models.XtGoodErrcode{
7426
-				UserOrgId:      orgId,
7427
-				Errcode:        "反审核回退库存报错",
7428
-				GoodId:         0,
7429
-				Status:         1,
7430
-				Ctime:          time.Now().Unix(),
7431
-				Mtime:          0,
7432
-				Count:          0,
7433
-				StockCount:     0,
7434
-				Creater:        creater,
7435
-				BatchNumberId:  0,
7436
-				WarehouseOutId: 0,
7437
-			}
7438
-			service.CreateGoodErrcode(goodErrcode)
7439
-		}
7392
+		service.UpdateaNewGoodWarehouseInfo(item.Count, item.GoodId, item.OrgId, item.WarehouseInfotId, tx)
7393
+
7440 7394
 		//查询默认仓库
7441
-		storeHouseConfig, errs := service.GetAllStoreHouseConfig(orgId)
7442
-		if errs != nil {
7443
-			goodErrcode := models.XtGoodErrcode{
7444
-				UserOrgId:      orgId,
7445
-				Errcode:        "反审核查询默认仓库报错",
7446
-				GoodId:         0,
7447
-				Status:         1,
7448
-				Ctime:          time.Now().Unix(),
7449
-				Mtime:          0,
7450
-				Count:          0,
7451
-				StockCount:     0,
7452
-				Creater:        creater,
7453
-				BatchNumberId:  0,
7454
-				WarehouseOutId: 0,
7455
-			}
7456
-			service.CreateGoodErrcode(goodErrcode)
7457
-		}
7458
-		stockList, errcodes := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
7459
-		if errcodes != nil {
7460
-			goodErrcode := models.XtGoodErrcode{
7461
-				UserOrgId:      orgId,
7462
-				Errcode:        "反审核查询默认仓库库存报错",
7463
-				GoodId:         0,
7464
-				Status:         1,
7465
-				Ctime:          time.Now().Unix(),
7466
-				Mtime:          0,
7467
-				Count:          0,
7468
-				StockCount:     0,
7469
-				Creater:        creater,
7470
-				BatchNumberId:  0,
7471
-				WarehouseOutId: 0,
7472
-			}
7473
-			service.CreateGoodErrcode(goodErrcode)
7474
-		}
7395
+		storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
7396
+
7397
+		stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
7398
+
7475 7399
 		var total_count int64
7476 7400
 		for _, it := range stockList {
7477 7401
 			total_count += it.StockCount
7478 7402
 		}
7479 7403
 		//基础库扣减库存
7480
-		errs = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
7481
-		if errs != nil {
7482
-			goodErrcode := models.XtGoodErrcode{
7483
-				UserOrgId:      orgId,
7484
-				Errcode:        "反审核基础库扣减库存报错",
7485
-				GoodId:         0,
7486
-				Status:         1,
7487
-				Ctime:          time.Now().Unix(),
7488
-				Mtime:          0,
7489
-				Count:          0,
7490
-				StockCount:     0,
7491
-				Creater:        creater,
7492
-				BatchNumberId:  0,
7493
-				WarehouseOutId: 0,
7494
-			}
7495
-			service.CreateGoodErrcode(goodErrcode)
7496
-		}
7404
+		service.UpdateNewGoodInfoReduceSumCount(item.GoodId, total_count, orgId, tx)
7497 7405
 
7498
-		goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
7406
+		goodList, _ := service.GetNewSumGoodList(orgId, item.StorehouseId, item.GoodId, tx)
7499 7407
 		var flush_count int64
7500 7408
 		for _, it := range goodList {
7501 7409
 			flush_count += it.StockCount
7502 7410
 		}
7503
-		erros := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
7504
-		if erros != nil {
7505
-			goodErrcode := models.XtGoodErrcode{
7506
-				UserOrgId:      orgId,
7507
-				Errcode:        "手动出库更新剩余库存报错",
7508
-				GoodId:         0,
7509
-				Status:         1,
7510
-				Ctime:          time.Now().Unix(),
7511
-				Mtime:          0,
7512
-				Count:          0,
7513
-				StockCount:     0,
7514
-				Creater:        creater,
7515
-				BatchNumberId:  0,
7516
-				WarehouseOutId: 0,
7517
-			}
7518
-			service.CreateGoodErrcode(goodErrcode)
7519
-		}
7411
+		service.UpdateNewSumGood(orgId, item.StorehouseId, item.GoodId, flush_count, tx)
7412
+
7520 7413
 		//扣减出库数据
7521
-		errcoeds := service.ModifyReduceGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId)
7522
-		if errcoeds != nil {
7523
-			goodErrcode := models.XtGoodErrcode{
7524
-				UserOrgId:      orgId,
7525
-				Errcode:        "反审核扣减出库数据报错",
7526
-				GoodId:         0,
7527
-				Status:         1,
7528
-				Ctime:          time.Now().Unix(),
7529
-				Mtime:          0,
7530
-				Count:          0,
7531
-				StockCount:     0,
7532
-				Creater:        creater,
7533
-				BatchNumberId:  0,
7534
-				WarehouseOutId: 0,
7535
-			}
7536
-			service.CreateGoodErrcode(goodErrcode)
7537
-		}
7414
+		service.ModifyNewReduceGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId, tx)
7538 7415
 
7539 7416
 	}
7540 7417
 	//删除流水,改变审核状态
7541
-	errcos := service.ModifyGoodWarehouseOut(id)
7542
-	if errcos != nil {
7543
-		goodErrcode := models.XtGoodErrcode{
7544
-			UserOrgId:      orgId,
7545
-			Errcode:        "反审核删除流水,改变审核状态报错",
7546
-			GoodId:         0,
7547
-			Status:         1,
7548
-			Ctime:          time.Now().Unix(),
7549
-			Mtime:          0,
7550
-			Count:          0,
7551
-			StockCount:     0,
7552
-			Creater:        creater,
7553
-			BatchNumberId:  0,
7554
-			WarehouseOutId: 0,
7555
-		}
7556
-		service.CreateGoodErrcode(goodErrcode)
7557
-	}
7418
+	service.ModifyNewGoodWarehouseOut(id, tx)
7419
+
7420
+	tx.Commit()
7558 7421
 
7559 7422
 	if err == nil {
7560 7423
 		this.ServeSuccessJSON(map[string]interface{}{
@@ -7568,20 +7431,32 @@ func (this *StockManagerApiController) CheckWarehouseInfo() {
7568 7431
 	warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
7569 7432
 	orgId := this.GetAdminUserInfo().CurrentOrgId
7570 7433
 	Creator := this.GetAdminUserInfo().AdminUser.Id
7434
+
7435
+	// 开始外部循环的事务
7436
+	db := service.XTWriteDB()
7437
+	tx := db.Begin()
7438
+
7439
+	// 在函数结束时处理事务回滚
7440
+	defer func() {
7441
+		if r := recover(); r != nil {
7442
+			tx.Rollback()
7443
+		}
7444
+	}()
7445
+
7571 7446
 	//查询默认仓库
7572
-	storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7447
+	storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
7573 7448
 
7574 7449
 	checker := this.GetAdminUserInfo().AdminUser.Id
7575 7450
 	//更改审核状态
7576
-	err := service.UpdateCheckWarehouseInfo(warehousing_info_id, checker)
7451
+	err := service.UpdateNewCheckWarehouseInfo(warehousing_info_id, checker, tx)
7577 7452
 	if err == nil {
7578
-		list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
7453
+		list, _ := service.GetNewWarehouseInfoList(warehousing_info_id, orgId, tx)
7579 7454
 
7580 7455
 		for _, item := range list {
7581
-			service.UpdateWarehouseInfoByIdListThree(item.WarehousingCount, item.ID)
7456
+			service.UpdateNewWarehouseInfoByIdListThree(item.WarehousingCount, item.ID, tx)
7582 7457
 
7583 7458
 			//查询该耗材剩余库存库
7584
-			stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
7459
+			stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
7585 7460
 			var total_count int64
7586 7461
 			var sum_in_count int64
7587 7462
 			for _, it := range stockList {
@@ -7589,11 +7464,12 @@ func (this *StockManagerApiController) CheckWarehouseInfo() {
7589 7464
 				sum_in_count += it.WarehousingCount
7590 7465
 			}
7591 7466
 			//基础库插入数据
7592
-			service.UpdateGoodInfoAddSumCount(item.GoodId, total_count, orgId, sum_in_count)
7467
+			service.UpdateNewGoodInfoAddSumCount(item.GoodId, total_count, orgId, sum_in_count, tx)
7593 7468
 
7594 7469
 			//查询该仓库是否有数据
7595
-			_, errcode := service.GetGoodStockCount(orgId, item.StorehouseId, item.GoodId)
7596
-			goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
7470
+			_, errcode := service.GetNewGoodStockCount(orgId, item.StorehouseId, item.GoodId, tx)
7471
+
7472
+			goodList, _ := service.GetNewSumGoodList(orgId, item.StorehouseId, item.GoodId, tx)
7597 7473
 			var flush_count int64
7598 7474
 			for _, it := range goodList {
7599 7475
 				flush_count += it.StockCount
@@ -7640,7 +7516,7 @@ func (this *StockManagerApiController) CheckWarehouseInfo() {
7640 7516
 				GoodCode:                item.GoodCode,
7641 7517
 			}
7642 7518
 			//创建出库流水
7643
-			service.CreateStockFlowOne(stockFlow)
7519
+			service.CreateNewStockFlowOne(stockFlow, tx)
7644 7520
 
7645 7521
 			if errcode == gorm.ErrRecordNotFound {
7646 7522
 
@@ -7657,14 +7533,16 @@ func (this *StockManagerApiController) CheckWarehouseInfo() {
7657 7533
 					FlushCount:       flush_count,
7658 7534
 					StockActOutCount: 0,
7659 7535
 				}
7660
-				service.CreateGoodCount(goodCount)
7536
+				service.CreateNewGoodCount(goodCount, tx)
7661 7537
 			}
7662 7538
 			if errcode == nil {
7663
-				service.UpdateGoodStockCount(orgId, item.StorehouseId, item.GoodId, item.WarehousingCount, flush_count)
7539
+				service.UpdateNewGoodStockCount(orgId, item.StorehouseId, item.GoodId, item.WarehousingCount, flush_count, tx)
7664 7540
 			}
7665 7541
 		}
7666 7542
 	}
7667 7543
 
7544
+	tx.Commit()
7545
+
7668 7546
 	if err == nil {
7669 7547
 		this.ServeSuccessJSON(map[string]interface{}{
7670 7548
 			"list": "list",
@@ -7676,49 +7554,33 @@ func (this *StockManagerApiController) ReturnCheckWarehouseInfo() {
7676 7554
 
7677 7555
 	warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
7678 7556
 	orgId := this.GetAdminUserInfo().CurrentOrgId
7557
+
7558
+	// 开始外部循环的事务
7559
+	db := service.XTWriteDB()
7560
+	tx := db.Begin()
7561
+
7562
+	// 在函数结束时处理事务回滚
7563
+	defer func() {
7564
+		if r := recover(); r != nil {
7565
+			tx.Rollback()
7566
+		}
7567
+	}()
7568
+
7679 7569
 	//查询入库数据
7680
-	list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
7570
+	list, _ := service.GetNewWarehouseInfoList(warehousing_info_id, orgId, tx)
7681 7571
 	for _, item := range list {
7682 7572
 		//查询该耗材 是否有出库数据
7683
-		outlist, _ := service.GetWarehouseOutByWarehouseInfoId(item.ID, item.GoodId, item.OrgId)
7573
+		outlist, _ := service.GetNewWarehouseOutByWarehouseInfoId(item.ID, item.GoodId, item.OrgId, tx)
7684 7574
 
7685 7575
 		if len(outlist) > 0 {
7576
+			tx.Rollback()
7686 7577
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
7687 7578
 			return
7688 7579
 		}
7689 7580
 	}
7690
-	//for _, item := range list {
7691
-	//
7692
-	//	//扣减数量
7693
-	//	service.UpdateWarehouseInfoByIdListTwo(item.WarehousingCount, item.ID)
7694
-	//
7695
-	//	//删除流水
7696
-	//	service.UpdateWarehouseInfoFlow(item.ID)
7697
-	//
7698
-	//	goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
7699
-	//	var flush_count int64
7700
-	//	for _, it := range goodList {
7701
-	//		flush_count += it.StockCount
7702
-	//	}
7703
-	//
7704
-	//	//扣减数量
7705
-	//	service.UpdateGoodInCount(item.WarehousingCount, item.OrgId, item.GoodId, item.StorehouseId, flush_count)
7706
-	//
7707
-	//	//查询默认仓库
7708
-	//	storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7709
-	//	//查询该耗材剩余多少库存
7710
-	//	stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
7711
-	//	var sum_count int64
7712
-	//	var sum_in_count int64
7713
-	//	for _, it := range stockList {
7714
-	//		sum_count += it.StockCount
7715
-	//		sum_in_count += it.WarehousingCount
7716
-	//	}
7717
-	//	service.UpdateGoodInfoAddSumCount(item.GoodId, sum_count, orgId, sum_in_count)
7718
-	//}
7719
-	//err := service.ReturnCheckWarehouseInfo(warehousing_info_id)
7720 7581
 
7721
-	err := service.UpdateWarehouseInfoMap(list, warehousing_info_id, orgId)
7582
+	err := service.UpdateNewWarehouseInfoMap(list, warehousing_info_id, orgId, tx)
7583
+	tx.Commit()
7722 7584
 	if err == nil {
7723 7585
 		this.ServeSuccessJSON(map[string]interface{}{
7724 7586
 			"msg": "反审核成功!",
@@ -8223,7 +8085,7 @@ func (this *StockManagerApiController) UpdateBaseDrugListByUserOrgID() {
8223 8085
 	//	service.UpdateDealerManufacturerOne(item.ID, manufacturer.ManufacturerName)
8224 8086
 	//}
8225 8087
 
8226
-	drugList, _ := service.GetAllBaseDrugListTwentyOne(10598)
8088
+	drugList, _ := service.GetAllBaseDrugListTwentyOne(10215)
8227 8089
 
8228 8090
 	for _, item := range drugList {
8229 8091
 		var drug_spec = item.Dose + item.DoseUnit + "*" + strconv.FormatInt(item.MinNumber, 10) + item.MinUnit + "/" + item.MaxUnit

+ 8 - 7
controllers/supply_order_api_contorller.go View File

@@ -1,18 +1,19 @@
1 1
 package controllers
2 2
 
3 3
 import (
4
-	"XT_New/enums"
5
-	"XT_New/models"
6
-	"XT_New/service"
7
-	"XT_New/utils"
8 4
 	"encoding/json"
9 5
 	"fmt"
10
-	"github.com/astaxie/beego"
11
-	"github.com/jinzhu/gorm"
12 6
 	"reflect"
13 7
 	"strconv"
14 8
 	"strings"
15 9
 	"time"
10
+
11
+	"XT_New/enums"
12
+	"XT_New/models"
13
+	"XT_New/service"
14
+	"XT_New/utils"
15
+	"github.com/astaxie/beego"
16
+	"github.com/jinzhu/gorm"
16 17
 )
17 18
 
18 19
 type SupplyOrderApiController struct {
@@ -3673,7 +3674,7 @@ func (this *SupplyOrderApiController) CheckReturnOrder() {
3673 3674
 			//查询是否生成出库单
3674 3675
 			_, errcodes := service.FindStockOutByIsSys(orgId, 0, record_date)
3675 3676
 			if errcodes == gorm.ErrRecordNotFound {
3676
-				service.AddSigleWarehouseOut(&warehouseOut)
3677
+				service.AddSigleWarehouseOutOne(&warehouseOut)
3677 3678
 			}
3678 3679
 			outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
3679 3680
 

+ 122 - 0
service/new_stock_service.go View File

@@ -19,6 +19,24 @@ func GetGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64) (*
19 19
 	return &goodStock, nil
20 20
 }
21 21
 
22
+func GetNewGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64, tx *gorm.DB) (*models.XtGoodStockCount, error) {
23
+
24
+	goodStock := models.XtGoodStockCount{}
25
+	var err error
26
+	err = tx.Where("user_org_id = ? and storehouse_id = ? and good_id = ?", user_org_id, storehouse_id, good_id).Find(&goodStock).Error
27
+	if err == gorm.ErrRecordNotFound {
28
+		if err != nil {
29
+			tx.Rollback()
30
+			return nil, err
31
+		}
32
+
33
+	}
34
+	if err != nil {
35
+		return nil, err
36
+	}
37
+	return &goodStock, nil
38
+}
39
+
22 40
 func CreateGoodCount(good models.XtGoodStockCount) error {
23 41
 
24 42
 	db := writeDb.Begin()
@@ -31,6 +49,16 @@ func CreateGoodCount(good models.XtGoodStockCount) error {
31 49
 	return err
32 50
 }
33 51
 
52
+func CreateNewGoodCount(good models.XtGoodStockCount, tx *gorm.DB) error {
53
+
54
+	err := tx.Create(&good).Error
55
+	if err != nil {
56
+		tx.Rollback()
57
+		return err
58
+	}
59
+	return err
60
+}
61
+
34 62
 func UpdateGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64, count int64, flush_count int64) error {
35 63
 
36 64
 	db := writeDb.Begin()
@@ -48,6 +76,22 @@ func UpdateGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64,
48 76
 	return err
49 77
 }
50 78
 
79
+func UpdateNewGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64, count int64, flush_count int64, tx *gorm.DB) error {
80
+
81
+	err = tx.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and good_id  = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count + ?", count)).Error
82
+	if err != nil {
83
+		tx.Rollback()
84
+		return err
85
+	}
86
+	err = tx.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
87
+	if err != nil {
88
+		tx.Rollback()
89
+		return err
90
+	}
91
+
92
+	return err
93
+}
94
+
51 95
 func UpdateGoodInCount(count int64, user_org_id int64, good_id int64, storehouse_id int64, flush_count int64) error {
52 96
 	db := writeDb.Begin()
53 97
 	err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id  = ? and storehouse_id = ? and status = 1", user_org_id, good_id, storehouse_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", count)).Error
@@ -128,6 +172,17 @@ func GetSumGoodList(orgid int64, storehouse_id int64, good_id int64) (info []*mo
128 172
 	return info, err
129 173
 }
130 174
 
175
+func GetNewSumGoodList(orgid int64, storehouse_id int64, good_id int64, tx *gorm.DB) (info []*models.WarehousingInfo, err error) {
176
+
177
+	err = tx.Where("org_id = ? and storehouse_id = ? and good_id = ? and status =1  and is_check = 1", orgid, storehouse_id, good_id).Find(&info).Error
178
+	if err != gorm.ErrRecordNotFound {
179
+		if err != nil {
180
+			return info, err
181
+		}
182
+	}
183
+	return info, err
184
+}
185
+
131 186
 func UpdateSumGood(orgid int64, storehouse_id int64, good_id int64, flush_count int64) error {
132 187
 	db := writeDb.Begin()
133 188
 	err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", orgid, storehouse_id, good_id).Updates(map[string]interface{}{"flush_count": flush_count}).Error
@@ -139,6 +194,16 @@ func UpdateSumGood(orgid int64, storehouse_id int64, good_id int64, flush_count
139 194
 	return err
140 195
 }
141 196
 
197
+func UpdateNewSumGood(orgid int64, storehouse_id int64, good_id int64, flush_count int64, tx *gorm.DB) error {
198
+
199
+	err := tx.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", orgid, storehouse_id, good_id).Updates(map[string]interface{}{"flush_count": flush_count}).Error
200
+	if err != nil {
201
+		tx.Rollback()
202
+		return err
203
+	}
204
+	return err
205
+}
206
+
142 207
 func ReduceSumOutCount(good_id int64, total_count int64, storehouse_id int64, user_org_id int64) error {
143 208
 	ut := XTWriteDB().Begin()
144 209
 
@@ -282,6 +347,23 @@ func GetDrugStockCount(storehouse_id int64, drug_id int64, org_id int64) (*model
282 347
 	return &drugStockCount, nil
283 348
 }
284 349
 
350
+func GetNewDrugStockCount(storehouse_id int64, drug_id int64, org_id int64, tx *gorm.DB) (*models.XtDrugStockCount, error) {
351
+	drugStockCount := models.XtDrugStockCount{}
352
+	var err error
353
+	err = tx.Where("storehouse_id = ? and drug_id = ? and user_org_id  = ? and status = 1", storehouse_id, drug_id, org_id).Find(&drugStockCount).Error
354
+	if err == gorm.ErrRecordNotFound {
355
+		if err != nil {
356
+			tx.Rollback()
357
+			return nil, err
358
+		}
359
+		return nil, err
360
+	}
361
+	if err != nil {
362
+		return nil, err
363
+	}
364
+	return &drugStockCount, nil
365
+}
366
+
285 367
 func GetDrugStockCountSix(storehouse_id int64, drug_id int64, org_id int64) (models.XtDrugStockCount, error) {
286 368
 
287 369
 	drugStockCount := models.XtDrugStockCount{}
@@ -301,6 +383,16 @@ func CreateDrugStockSum(drug models.XtDrugStockCount) error {
301 383
 	return err
302 384
 }
303 385
 
386
+func CreateNewDrugStockSum(drug models.XtDrugStockCount, tx *gorm.DB) error {
387
+
388
+	err := tx.Create(&drug).Error
389
+	if err != nil {
390
+		tx.Rollback()
391
+		return err
392
+	}
393
+	return err
394
+}
395
+
304 396
 func AddDrugStockSum(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
305 397
 
306 398
 	db := writeDb.Begin()
@@ -334,6 +426,21 @@ func UpdateDrugStockSum(storehouse_id int64, drug_id int64, user_org_id int64, w
334 426
 	return err
335 427
 }
336 428
 
429
+func UpdateNewDrugStockSum(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64, tx *gorm.DB) error {
430
+
431
+	err = tx.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id  = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"sum_in_count": waresing_count}).Error
432
+	if err != nil {
433
+		tx.Rollback()
434
+		return err
435
+	}
436
+	err = tx.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
437
+	if err != nil {
438
+		tx.Rollback()
439
+		return err
440
+	}
441
+	return err
442
+}
443
+
337 444
 func ReduceDrugStockCount(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
338 445
 	db := writeDb.Begin()
339 446
 	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", waresing_count)).Error
@@ -350,6 +457,21 @@ func ReduceDrugStockCount(storehouse_id int64, drug_id int64, user_org_id int64,
350 457
 	return err
351 458
 }
352 459
 
460
+func ReduceNewDrugStockCount(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64, tx *gorm.DB) error {
461
+
462
+	err = tx.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", waresing_count)).Error
463
+	if err != nil {
464
+		tx.Rollback()
465
+		return err
466
+	}
467
+	err = tx.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
468
+	if err != nil {
469
+		tx.Rollback()
470
+		return err
471
+	}
472
+	return err
473
+}
474
+
353 475
 func AddCancelSumCount(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64, over_count int64) error {
354 476
 
355 477
 	db := writeDb.Begin()

+ 17 - 2
service/new_warehouse_service.go View File

@@ -102,7 +102,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
102 102
 		}
103 103
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
104 104
 		if errcodes == gorm.ErrRecordNotFound {
105
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
105
+			errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
106 106
 			if errOne != nil {
107 107
 				return errOne
108 108
 			}
@@ -366,7 +366,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
366 366
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
367 367
 
368 368
 		if errcodes == gorm.ErrRecordNotFound {
369
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
369
+			errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
370 370
 			if errOne != nil {
371 371
 				return errOne
372 372
 			}
@@ -697,6 +697,21 @@ func ReduceDrugCount(drug_id int64, org_id int64, storehouse_id int64, out_count
697 697
 	return err
698 698
 }
699 699
 
700
+func ReduceNewDrugCount(drug_id int64, org_id int64, storehouse_id int64, out_count int64, tx *gorm.DB) error {
701
+
702
+	err := tx.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and drug_id = ?", storehouse_id, org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", out_count)).Error
703
+	if err != nil {
704
+		tx.Rollback()
705
+		return err
706
+	}
707
+	err = tx.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and drug_id = ?", storehouse_id, org_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count - ?", out_count)).Error
708
+	if err != nil {
709
+		tx.Rollback()
710
+		return err
711
+	}
712
+	return err
713
+}
714
+
700 715
 func ReduceDrugCountTwo(drug_id int64, org_id int64, storehouse_id int64, out_count int64) error {
701 716
 	ut := XTWriteDB().Begin()
702 717
 	err := ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and drug_id = ?", storehouse_id, org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", out_count)).Error

+ 26 - 0
service/secondary_service.go View File

@@ -829,6 +829,7 @@ func GetAllStoreHouseConfig(orgid int64) (models.XtStorehouseConfig, error) {
829 829
 
830 830
 	config := models.XtStorehouseConfig{}
831 831
 	err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).First(&config).Error
832
+
832 833
 	return config, err
833 834
 }
834 835
 
@@ -838,6 +839,18 @@ func FindStoreHouseByStorehouseId(id int64, user_org_id int64) (models.XtStoreho
838 839
 	return storehouse, err
839 840
 }
840 841
 
842
+func FindNewStoreHouseByStorehouseId(id int64, user_org_id int64, tx *gorm.DB) (models.XtStorehouse, error) {
843
+	storehouse := models.XtStorehouse{}
844
+	err := tx.Where("id = ? and user_org_id = ? and status = 1", id, user_org_id).Find(&storehouse).Error
845
+	if err != gorm.ErrRecordNotFound {
846
+		if err != nil {
847
+			tx.Rollback()
848
+			return storehouse, err
849
+		}
850
+	}
851
+	return storehouse, err
852
+}
853
+
841 854
 func GetSecondWarehouseByNumber(user_org_id int64, warehousing_order string) (*models.XtSecondWarehouse, error) {
842 855
 
843 856
 	warehouse := models.XtSecondWarehouse{}
@@ -1091,6 +1104,19 @@ func GetDrugSumCountByStorehouseId(storehouse_id int64, orgid int64, drug_id int
1091 1104
 	return info, err
1092 1105
 }
1093 1106
 
1107
+func GetNewDrugSumCountByStorehouseId(storehouse_id int64, orgid int64, drug_id int64, tx *gorm.DB) (info []*models.DrugWarehouseInfo, err error) {
1108
+
1109
+	err = tx.Where("storehouse_id = ? and org_id = ? and status = 1  and drug_id =? and is_check = 1", storehouse_id, orgid, drug_id).Find(&info).Error
1110
+	if err != gorm.ErrRecordNotFound {
1111
+		if err != nil {
1112
+			tx.Rollback()
1113
+			return info, err
1114
+		}
1115
+
1116
+	}
1117
+	return info, err
1118
+}
1119
+
1094 1120
 func GetDrugSumCountByStorehouseIdSix(storehouse_id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
1095 1121
 
1096 1122
 	err = XTReadDB().Where("storehouse_id = ? and org_id = ? and status = 1 and (stock_max_number >0 or stock_min_number>0)", storehouse_id, orgid).Find(&info).Error

+ 9 - 10
service/self_drug_service.go View File

@@ -138,14 +138,7 @@ func GetBaseDrugMedical(id int64) (models.XtBaseDrug, error) {
138 138
 	return drug, err
139 139
 }
140 140
 
141
-func GetDrugWarehosueInfoById(drug_id int64, org_id int64) (drugInfo []*models.XtDrugWarehouseInfo, err error) {
142
-
143
-	err = XTReadDB().Where("drug_id = ? and org_id = ? and status =1", drug_id, org_id).Find(&drugInfo).Error
144
-
145
-	return drugInfo, err
146
-}
147
-
148
-func GetBaseDrugMedicalOne(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
141
+func GetNewBaseDrugMedical(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
149 142
 	drug := models.XtBaseDrug{}
150 143
 	err := tx.Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
151 144
 	if err != gorm.ErrRecordNotFound {
@@ -153,12 +146,18 @@ func GetBaseDrugMedicalOne(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
153 146
 			tx.Rollback()
154 147
 			return drug, err
155 148
 		}
156
-
157 149
 	}
158 150
 	return drug, err
159 151
 }
160 152
 
161
-func GetNewBaseDrugMedical(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
153
+func GetDrugWarehosueInfoById(drug_id int64, org_id int64) (drugInfo []*models.XtDrugWarehouseInfo, err error) {
154
+
155
+	err = XTReadDB().Where("drug_id = ? and org_id = ? and status =1", drug_id, org_id).Find(&drugInfo).Error
156
+
157
+	return drugInfo, err
158
+}
159
+
160
+func GetBaseDrugMedicalOne(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
162 161
 	drug := models.XtBaseDrug{}
163 162
 	err := tx.Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
164 163
 	if err != gorm.ErrRecordNotFound {

File diff suppressed because it is too large
+ 1047 - 34
service/stock_service.go


+ 16 - 2
service/supply_service.go View File

@@ -1,11 +1,12 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	"XT_New/models"
5 4
 	"fmt"
6
-	"github.com/jinzhu/gorm"
7 5
 	"strings"
8 6
 	"time"
7
+
8
+	"XT_New/models"
9
+	"github.com/jinzhu/gorm"
9 10
 )
10 11
 
11 12
 // 根据供应商编号获取首要联系人
@@ -1172,6 +1173,19 @@ func GetWarehouseOutById(id int64, orgid int64) (out []*models.WarehouseOutInfo,
1172 1173
 	return out, err
1173 1174
 }
1174 1175
 
1176
+func GetNewWarehouseOutById(id int64, orgid int64, tx *gorm.DB) (out []*models.WarehouseOutInfo, err error) {
1177
+
1178
+	err = tx.Where("warehouse_out_id = ? and status= 1 and org_id = ?", id, orgid).Find(&out).Error
1179
+
1180
+	if err != gorm.ErrRecordNotFound {
1181
+		if err != nil {
1182
+			tx.Rollback()
1183
+			return out, err
1184
+		}
1185
+	}
1186
+	return out, err
1187
+}
1188
+
1175 1189
 func DeleteWarehouseOutById(id int64) error {
1176 1190
 
1177 1191
 	err := XTWriteDB().Model(&models.WarehouseOut{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error

+ 574 - 16
service/warhouse_service.go View File

@@ -1384,7 +1384,7 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1384 1384
 				StorehouseId:            houseConfig.StorehouseOutInfo,
1385 1385
 				IsCheck:                 1,
1386 1386
 			}
1387
-			err := AddSigleWarehouseOut(&warehouseOut)
1387
+			err := AddSigleWarehouseOutOne(&warehouseOut)
1388 1388
 			if err != nil {
1389 1389
 				utils.TraceLog("创建出库单失败 err = %v", err)
1390 1390
 				return err
@@ -1536,7 +1536,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1536 1536
 
1537 1537
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
1538 1538
 		if errcodes == gorm.ErrRecordNotFound {
1539
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1539
+			errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
1540 1540
 			if errOne != nil {
1541 1541
 				return errOne
1542 1542
 			}
@@ -1769,7 +1769,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1769 1769
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, goods.PatientId, record_time, goods.ProjectId)
1770 1770
 
1771 1771
 		if errcodes == gorm.ErrRecordNotFound {
1772
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1772
+			errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
1773 1773
 
1774 1774
 			if errOne != nil {
1775 1775
 				return errOne
@@ -2166,6 +2166,17 @@ func GetWarehouseById(id int64) (models.WarehouseOut, error) {
2166 2166
 	return out, err
2167 2167
 }
2168 2168
 
2169
+func GetNewWarehouseById(id int64, tx *gorm.DB) (models.WarehouseOut, error) {
2170
+	out := models.WarehouseOut{}
2171
+	err := tx.Where("id=? and status = 1", id).Find(&out).Error
2172
+	if err != gorm.ErrRecordNotFound {
2173
+		if err != nil {
2174
+			return out, err
2175
+		}
2176
+	}
2177
+	return out, err
2178
+}
2179
+
2169 2180
 // 耗材出库
2170 2181
 func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.WarehouseOutInfo, warehouseOut *models.WarehouseOut, count int64, creator int64) (err error) {
2171 2182
 
@@ -2220,7 +2231,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
2220 2231
 		}
2221 2232
 		warehouseOutInfo.Count = goods.Count
2222 2233
 		//添加出库单详情
2223
-		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
2234
+		errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
2224 2235
 		if errOne != nil {
2225 2236
 			return errOne
2226 2237
 		}
@@ -2335,7 +2346,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
2335 2346
 		info, errcodes := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, goods.SysRecordTime, goods.OrgId)
2336 2347
 		if errcodes == gorm.ErrRecordNotFound {
2337 2348
 			//创建出库单
2338
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
2349
+			errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
2339 2350
 			if errOne != nil {
2340 2351
 				return errOne
2341 2352
 			}
@@ -2460,7 +2471,7 @@ func ConsumablesDeliveryTwo(orgID int64, goods *models.WarehouseOutInfo, count i
2460 2471
 		}
2461 2472
 		warehouseOutInfo.Count = goods.Count
2462 2473
 
2463
-		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
2474
+		errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
2464 2475
 		if errOne != nil {
2465 2476
 			return errOne
2466 2477
 		}
@@ -2516,7 +2527,7 @@ func ConsumablesDeliveryTwo(orgID int64, goods *models.WarehouseOutInfo, count i
2516 2527
 		}
2517 2528
 		warehouseOutInfo.Count = stock_number
2518 2529
 
2519
-		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
2530
+		errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
2520 2531
 		if errOne != nil {
2521 2532
 			return errOne
2522 2533
 		}
@@ -3520,7 +3531,7 @@ func ConsumablesDeliveryNight(orgID int64, record_time int64, goods *models.Ware
3520 3531
 		}
3521 3532
 		warehouseOutInfo.Count = goods.Count
3522 3533
 		//添加出库单详情
3523
-		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
3534
+		errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
3524 3535
 		if errOne != nil {
3525 3536
 			return errOne
3526 3537
 		}
@@ -3615,7 +3626,7 @@ func ConsumablesDeliveryNight(orgID int64, record_time int64, goods *models.Ware
3615 3626
 		info, errcodes := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, goods.SysRecordTime, goods.OrgId)
3616 3627
 		if errcodes == gorm.ErrRecordNotFound {
3617 3628
 			//创建出库单
3618
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
3629
+			errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
3619 3630
 			if errOne != nil {
3620 3631
 				return errOne
3621 3632
 			}
@@ -4050,7 +4061,7 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
4050 4061
 
4051 4062
 		warehouseOutInfo.Count = goods.Count
4052 4063
 		//添加出库单详情
4053
-		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
4064
+		errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
4054 4065
 		if errOne != nil {
4055 4066
 			return errOne
4056 4067
 		}
@@ -4225,7 +4236,7 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
4225 4236
 		info, errcodes := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, goods.SysRecordTime, goods.OrgId)
4226 4237
 		if errcodes == gorm.ErrRecordNotFound {
4227 4238
 			//创建出库单
4228
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
4239
+			errOne := AddSigleWarehouseOutInfoOne(warehouseOutInfo)
4229 4240
 			if errOne != nil {
4230 4241
 				return errOne
4231 4242
 			}
@@ -6100,6 +6111,16 @@ func UpdateDrugWarehouseOutInfo(id int64, warehouse_info_id int64, org_id int64,
6100 6111
 	return err
6101 6112
 }
6102 6113
 
6114
+func UpdateNewDrugWarehouseOutInfo(id int64, warehouse_info_id int64, org_id int64, over_count int64, drug_price float64, tx *gorm.DB) error {
6115
+
6116
+	err = tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and org_id = ? and status = 1", id, org_id).Update(map[string]interface{}{"warehouse_info_id": warehouse_info_id, "over_count": over_count, "price": drug_price, "retail_price": drug_price}).Error
6117
+	if err != nil {
6118
+		tx.Rollback()
6119
+		return err
6120
+	}
6121
+	return err
6122
+}
6123
+
6103 6124
 func UpdateGoodWarehouseOutById(id int64, warehouse_info_id int64, org_id int64, over_count int64) error {
6104 6125
 	utx := XTWriteDB().Begin()
6105 6126
 	err := utx.Model(models.WarehouseOutInfo{}).Where("id = ?  and org_id = ? and status = 1", id, org_id).Update(map[string]interface{}{"warehouse_info_id": warehouse_info_id, "over_count": over_count}).Error
@@ -6227,6 +6248,18 @@ func FindDrugWarehouseInfoList(drugid int64, orgid int64) (info []*models.DrugWa
6227 6248
 	return info, err
6228 6249
 }
6229 6250
 
6251
+func FindNewDrugWarehouseInfoList(drugid int64, orgid int64, tx *gorm.DB) (info []*models.DrugWarehouseInfo, err error) {
6252
+
6253
+	err = tx.Where("drug_id = ? and org_id = ? and status =1 and is_check =1  and (stock_max_number>0 or stock_min_number>0)", drugid, orgid).Find(&info).Error
6254
+	if err != gorm.ErrRecordNotFound {
6255
+		if err != nil {
6256
+			tx.Rollback()
6257
+			return info, err
6258
+		}
6259
+	}
6260
+	return info, err
6261
+}
6262
+
6230 6263
 func CreatedDrugFlushInfo(info models.XtDrugWarehouseFlushInfo) error {
6231 6264
 	ut := writeDb.Begin()
6232 6265
 	err := ut.Create(&info).Error
@@ -6238,6 +6271,16 @@ func CreatedDrugFlushInfo(info models.XtDrugWarehouseFlushInfo) error {
6238 6271
 	return err
6239 6272
 }
6240 6273
 
6274
+func CreatedNewDrugFlushInfo(info models.XtDrugWarehouseFlushInfo, tx *gorm.DB) error {
6275
+
6276
+	err := tx.Create(&info).Error
6277
+	if err != nil {
6278
+		tx.Rollback()
6279
+		return err
6280
+	}
6281
+	return err
6282
+}
6283
+
6241 6284
 func UpdateWarehouseFlushInfo(warehouse_out_id int64, record_time int64, patient_id int64, batch_nubmer_id int64, good_id int64, sum_count int64, orgid int64) error {
6242 6285
 
6243 6286
 	err := XTWriteDB().Model(&models.XtWarehouseFlushInfo{}).Where("warehouse_out_id = ? and system_time = ? and patient_id = ? and batch_number_id = ? and good_id = ? and user_org_id = ?", warehouse_out_id, record_time, patient_id, batch_nubmer_id, good_id, orgid).Update(map[string]interface{}{"flush_count": sum_count}).Error
@@ -6323,6 +6366,16 @@ func ModifyReduceDrugInformation(id int64, count int64, orgid int64) error {
6323 6366
 	return err
6324 6367
 }
6325 6368
 
6369
+func ModifyNewReduceDrugInformation(id int64, count int64, orgid int64, tx *gorm.DB) error {
6370
+
6371
+	err = tx.Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", id, orgid).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", count)).Error
6372
+	if err != nil {
6373
+		tx.Rollback()
6374
+		return err
6375
+	}
6376
+	return err
6377
+}
6378
+
6326 6379
 func ModifyAddCancelAddInfomation(id int64, count int64, orgid int64, storehouse_id int64) error {
6327 6380
 	ut := XTWriteDB().Begin()
6328 6381
 	err = ut.Model(&models.XtDrugStockCount{}).Where("drug_id = ? and status = 1 and user_org_id = ? and storehouse_id = ?", id, orgid, storehouse_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", count)).Error
@@ -6424,6 +6477,23 @@ func ModifyReduceGoodSumCount(storehouse_id int64, count int64, user_org_id int6
6424 6477
 	return err
6425 6478
 }
6426 6479
 
6480
+func ModifyNewReduceGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64, tx *gorm.DB) error {
6481
+
6482
+	err = tx.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", count)).Error
6483
+	if err != nil {
6484
+		tx.Rollback()
6485
+		return err
6486
+	}
6487
+
6488
+	err = tx.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count - ?", count)).Error
6489
+	if err != nil {
6490
+		tx.Rollback()
6491
+		return err
6492
+	}
6493
+
6494
+	return err
6495
+}
6496
+
6427 6497
 func ModifyReduceGoodSumCountTwenty(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6428 6498
 	ut := XTWriteDB().Begin()
6429 6499
 
@@ -6512,12 +6582,36 @@ func FindDrugWarehouseInfoFlushCount(drug_id int64, orgid int64) (info []*models
6512 6582
 	return info, err
6513 6583
 }
6514 6584
 
6585
+func FindNewDrugWarehouseInfoFlushCount(drug_id int64, orgid int64, tx *gorm.DB) (info []*models.DrugWarehouseInfo, err error) {
6586
+
6587
+	err = tx.Where("drug_id = ? and org_id = ? and status = 1 and is_check = 1", drug_id, orgid).Find(&info).Error
6588
+	if err != gorm.ErrRecordNotFound {
6589
+		if err != nil {
6590
+			tx.Rollback()
6591
+			return info, err
6592
+		}
6593
+	}
6594
+	return info, err
6595
+}
6596
+
6515 6597
 func FindDrugWarehouseInfoFlushCountByStorehouse(drug_id int64, orgid int64, storehouse_id int64) (info []*models.DrugWarehouseInfo, err error) {
6516 6598
 
6517 6599
 	err = XTReadDB().Where("drug_id = ? and org_id = ? and status = 1 and is_check = 1 and storehouse_id =?", drug_id, orgid, storehouse_id).Find(&info).Error
6518 6600
 	return info, err
6519 6601
 }
6520 6602
 
6603
+func FindNewDrugWarehouseInfoFlushCountByStorehouse(drug_id int64, orgid int64, storehouse_id int64, tx *gorm.DB) (info []*models.DrugWarehouseInfo, err error) {
6604
+
6605
+	err = tx.Where("drug_id = ? and org_id = ? and status = 1 and is_check = 1 and storehouse_id =?", drug_id, orgid, storehouse_id).Find(&info).Error
6606
+	if err != gorm.ErrRecordNotFound {
6607
+		if err != nil {
6608
+			tx.Rollback()
6609
+			return info, err
6610
+		}
6611
+	}
6612
+	return info, err
6613
+}
6614
+
6521 6615
 // 结算出库
6522 6616
 func HisSettleDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdviceInfo, order_id int64) (err error) {
6523 6617
 
@@ -6719,10 +6813,10 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
6719 6813
 			RegisterNumber:          warehouse.RegisterNumber,
6720 6814
 			OrderId:                 order_id,
6721 6815
 		}
6722
-		fmt.Println("goods.count2323232233232233232322332322332", goods.Count)
6816
+
6723 6817
 		OutInfo.Count = goods.Count
6724 6818
 
6725
-		AddSigleWarehouseOutInfo(OutInfo)
6819
+		AddSigleWarehouseOutInfoOne(OutInfo)
6726 6820
 
6727 6821
 		stockFlow := models.VmStockFlow{
6728 6822
 			WarehousingId:           warehouse.ID,
@@ -6905,7 +6999,7 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
6905 6999
 		}
6906 7000
 		OutInfo.Count = stock_number
6907 7001
 
6908
-		AddSigleWarehouseOutInfo(OutInfo)
7002
+		AddSigleWarehouseOutInfoOne(OutInfo)
6909 7003
 
6910 7004
 		stockFlow := models.VmStockFlow{
6911 7005
 			WarehousingId:           warehouse.ID,
@@ -7159,7 +7253,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
7159 7253
 
7160 7254
 		_, errcodes := GetNewWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID)
7161 7255
 		if errcodes == gorm.ErrRecordNotFound {
7162
-			errOne := AddSigleWarehouseOutInfo(OutInfo)
7256
+			errOne := AddSigleWarehouseOutInfoOne(OutInfo)
7163 7257
 			if errOne != nil {
7164 7258
 				return errOne
7165 7259
 			}
@@ -7477,7 +7571,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
7477 7571
 
7478 7572
 		_, errcodes := GetNewWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID)
7479 7573
 		if errcodes == gorm.ErrRecordNotFound {
7480
-			errOne := AddSigleWarehouseOutInfo(OutInfo)
7574
+			errOne := AddSigleWarehouseOutInfoOne(OutInfo)
7481 7575
 			if errOne != nil {
7482 7576
 				return errOne
7483 7577
 			}
@@ -10723,3 +10817,467 @@ func AutoSelfDrugDeliverInfoFourtyThree(orgID int64, prescribingNumber int64, wa
10723 10817
 
10724 10818
 	return
10725 10819
 }
10820
+
10821
+// 耗材手动出库
10822
+func ConsumablesNewDeliveryThirty(orgID int64, record_time int64, goods *models.WarehouseOutInfo, warehouseOut *models.WarehouseOut, count int64, creator int64, tx *gorm.DB) (err error) {
10823
+
10824
+	var deliver_number int64 = 0
10825
+	var stock_number int64 = 0
10826
+	var maxNumber int64 = 0
10827
+
10828
+	deliver_number = goods.Count
10829
+
10830
+	// 根据先进先出原则,查询最先入库的批次,进行出库
10831
+
10832
+	// 如果没有对应的库存,则报错
10833
+	warehouse, err := FindNewFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId, tx)
10834
+
10835
+	stock_number = warehouse.StockCount
10836
+
10837
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
10838
+	if stock_number >= deliver_number {
10839
+		maxNumber = goods.Count
10840
+		warehouse.StockCount = warehouse.StockCount - maxNumber
10841
+		warehouse.Mtime = time.Now().Unix()
10842
+
10843
+		//扣减库存
10844
+		UpDateNewWarehouseInfoByStock(&warehouse, tx)
10845
+
10846
+		//查询剩余库存
10847
+		goodList, _ := GetNewAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId, tx)
10848
+		var sum_count int64
10849
+		for _, item := range goodList {
10850
+			sum_count += item.StockCount
10851
+		}
10852
+
10853
+		warehouseOutInfo := &models.WarehouseOutInfo{
10854
+			WarehouseInfotId: warehouse.ID,
10855
+		}
10856
+		//添加入库单详情ID
10857
+		UpdatedNewSigleWarehouseOutInfo(goods.ID, warehouseOutInfo, tx)
10858
+
10859
+		stockFlow := models.VmStockFlow{
10860
+			WarehousingId:           warehouse.ID,
10861
+			GoodId:                  goods.GoodId,
10862
+			Number:                  warehouse.Number,
10863
+			LicenseNumber:           goods.LicenseNumber,
10864
+			Count:                   goods.Count,
10865
+			UserOrgId:               goods.OrgId,
10866
+			PatientId:               goods.PatientId,
10867
+			SystemTime:              record_time,
10868
+			ConsumableType:          2,
10869
+			IsSys:                   goods.IsSys,
10870
+			WarehousingOrder:        warehouse.WarehousingOrder,
10871
+			WarehouseOutId:          warehouseOut.ID,
10872
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
10873
+			IsEdit:                  1,
10874
+			CancelStockId:           0,
10875
+			CancelOrderNumber:       "",
10876
+			Manufacturer:            goods.Manufacturer,
10877
+			Dealer:                  goods.Dealer,
10878
+			Creator:                 creator,
10879
+			UpdateCreator:           0,
10880
+			Status:                  1,
10881
+			Ctime:                   record_time,
10882
+			Mtime:                   time.Now().Unix(),
10883
+			Price:                   warehouse.PackingPrice, //零售价
10884
+			WarehousingDetailId:     warehouse.ID,
10885
+			WarehouseOutDetailId:    goods.ID,
10886
+			CancelOutDetailId:       0,
10887
+			ProductDate:             goods.ProductDate,
10888
+			ExpireDate:              goods.ExpiryDate,
10889
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
10890
+			StorehouseId:            warehouse.StorehouseId,
10891
+			AdminUserId:             goods.AdminUserId,
10892
+			BuyPrice:                warehouse.Price, //进货价
10893
+			StockCount:              goods.StockCount,
10894
+			BatchNumberCount:        warehouse.StockCount - goods.Count,
10895
+			IsCheck:                 1,
10896
+			OverCount:               sum_count,
10897
+			RegisterNumber:          goods.RegisterNumber,
10898
+			Remark:                  goods.Remark,
10899
+		}
10900
+		//创建出库流水
10901
+		CreateNewStockFlowOne(stockFlow, tx)
10902
+
10903
+		//添加入库ID
10904
+		UpdateNewGoodWarehouseOutById(goods.ID, warehouse.ID, goods.OrgId, sum_count, tx)
10905
+
10906
+		//更新出库数量
10907
+		ModifyNewGoodSumCount(goods.StorehouseId, goods.Count, goods.OrgId, goods.GoodId, tx)
10908
+
10909
+		if warehouse.StockCount < maxNumber {
10910
+			tx.Rollback()
10911
+			return errors.New("库存数量不足")
10912
+
10913
+		}
10914
+
10915
+		return nil
10916
+	} else {
10917
+		// 出库完成后,要将该批次库存清零
10918
+		warehouse.StockCount = 0
10919
+		warehouse.Mtime = time.Now().Unix()
10920
+
10921
+		UpDateNewWarehouseInfoByStock(&warehouse, tx)
10922
+
10923
+		//查询剩余库存
10924
+		goodList, _ := GetNewAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId, tx)
10925
+		var sum_count int64
10926
+		for _, item := range goodList {
10927
+			sum_count += item.StockCount
10928
+		}
10929
+
10930
+		stockFlow := models.VmStockFlow{
10931
+			WarehousingId:           warehouse.ID,
10932
+			GoodId:                  goods.GoodId,
10933
+			Number:                  warehouse.Number,
10934
+			LicenseNumber:           goods.LicenseNumber,
10935
+			Count:                   stock_number,
10936
+			UserOrgId:               goods.OrgId,
10937
+			PatientId:               goods.PatientId,
10938
+			SystemTime:              record_time,
10939
+			ConsumableType:          2,
10940
+			IsSys:                   goods.IsSys,
10941
+			WarehousingOrder:        warehouse.WarehousingOrder,
10942
+			WarehouseOutId:          warehouseOut.ID,
10943
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
10944
+			IsEdit:                  1,
10945
+			CancelStockId:           0,
10946
+			CancelOrderNumber:       "",
10947
+			Manufacturer:            goods.Manufacturer,
10948
+			Dealer:                  goods.Dealer,
10949
+			Creator:                 creator,
10950
+			UpdateCreator:           0,
10951
+			Status:                  1,
10952
+			Ctime:                   record_time,
10953
+			Mtime:                   time.Now().Unix(),
10954
+			Price:                   warehouse.PackingPrice, //零售价
10955
+			WarehousingDetailId:     warehouse.ID,
10956
+			WarehouseOutDetailId:    goods.ID,
10957
+			CancelOutDetailId:       0,
10958
+			ProductDate:             goods.ProductDate,
10959
+			ExpireDate:              goods.ExpiryDate,
10960
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
10961
+			StorehouseId:            warehouse.StorehouseId,
10962
+			AdminUserId:             goods.AdminUserId,
10963
+			BuyPrice:                warehouse.Price, //进货价
10964
+			StockCount:              goods.StockCount,
10965
+			BatchNumberCount:        0,
10966
+			IsCheck:                 1,
10967
+			OverCount:               sum_count,
10968
+			RegisterNumber:          goods.RegisterNumber,
10969
+			Remark:                  goods.Remark,
10970
+		}
10971
+		//创建出库流水
10972
+		CreateNewStockFlowOne(stockFlow, tx)
10973
+
10974
+		UpdateNewGoodWarehouseOutById(goods.ID, warehouse.ID, goods.OrgId, sum_count, tx)
10975
+
10976
+		//更新出库数量
10977
+		ModifyNewGoodSumCount(goods.StorehouseId, stock_number, goods.OrgId, goods.GoodId, tx)
10978
+
10979
+		goods.Count = deliver_number - stock_number
10980
+		ConsumablesNewDeliveryThirty(orgID, record_time, goods, warehouseOut, count, creator, tx)
10981
+	}
10982
+	return nil
10983
+}
10984
+
10985
+// 药品手动出库 递归方式
10986
+func AutoNewDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo, unit string, tx *gorm.DB) (err error) {
10987
+
10988
+	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
10989
+	var deliver_number int64 = 0
10990
+
10991
+	var stock_number int64 = 0
10992
+
10993
+	var drug_price float64
10994
+	if advice.CountUnit == drup.MaxUnit {
10995
+		deliver_number = prescribingNumber * drup.MinNumber
10996
+
10997
+	} else {
10998
+		deliver_number = prescribingNumber
10999
+
11000
+	}
11001
+	if advice.CountUnit == drup.MaxUnit {
11002
+		drug_price = drup.RetailPrice
11003
+	}
11004
+	fmt.Println(drug_price)
11005
+
11006
+	if advice.CountUnit == drup.MinUnit {
11007
+		drug_price = drup.MinPrice
11008
+	}
11009
+
11010
+	if advice.CountUnit != drup.MaxUnit || advice.CountUnit != drup.MinUnit {
11011
+		drug_price = drup.RetailPrice
11012
+	}
11013
+
11014
+	// 根据先进先出原则,查询最先入库的批次,进行出库
11015
+	// 如果没有对应的库存,则报错
11016
+	lastWarehouse, _ := FindNewLastDrugWarehousingInfoByID(advice.DrugId, advice.StorehouseId, tx)
11017
+
11018
+	if lastWarehouse.MaxUnit != lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
11019
+		if lastWarehouse.StockMinNumber >= drup.MinNumber {
11020
+			var stockMax int64
11021
+			var stockMin int64
11022
+			stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
11023
+			stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
11024
+
11025
+			ChangeNewMaxNumberOne(lastWarehouse.ID, stockMax, tx)
11026
+			UpdateNewMinNumber(lastWarehouse.ID, stockMin, tx)
11027
+
11028
+		}
11029
+	}
11030
+
11031
+	if lastWarehouse.MaxUnit == lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
11032
+
11033
+		lastWarehouse.StockMaxNumber = lastWarehouse.StockMaxNumber + lastWarehouse.StockMinNumber
11034
+		ChangeNewMaxNumberOne(lastWarehouse.ID, lastWarehouse.StockMaxNumber, tx)
11035
+
11036
+	}
11037
+
11038
+	warehouse, err := FindNewLastDrugWarehousingInfoByID(advice.DrugId, advice.StorehouseId, tx)
11039
+
11040
+	// 将该批次的剩余库存数量转换为拆零数量
11041
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
11042
+
11043
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
11044
+
11045
+	}
11046
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
11047
+
11048
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
11049
+
11050
+	}
11051
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
11052
+
11053
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
11054
+
11055
+	}
11056
+	if stock_number >= deliver_number {
11057
+
11058
+		var maxNumber int64 = 0
11059
+		var minNumber int64 = 0
11060
+
11061
+		maxNumber = deliver_number / drup.MinNumber
11062
+		minNumber = deliver_number % drup.MinNumber
11063
+
11064
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
11065
+			minNumber = maxNumber
11066
+		}
11067
+
11068
+		if drup.MaxUnit != drup.MinUnit {
11069
+			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
11070
+				return errors.New("库存数量不足")
11071
+			}
11072
+		}
11073
+
11074
+		if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
11075
+			//fmt.Println("金1")
11076
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
11077
+		}
11078
+
11079
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
11080
+			//fmt.Println("金2")
11081
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
11082
+		}
11083
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
11084
+			//fmt.Println("金3")
11085
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
11086
+		}
11087
+
11088
+		if warehouse.StockMaxNumber < 0 {
11089
+			warehouse.StockMaxNumber = 0
11090
+		}
11091
+		if warehouse.StockMinNumber < 0 {
11092
+			warehouse.StockMinNumber = 0
11093
+		}
11094
+
11095
+		warehouse.Mtime = time.Now().Unix()
11096
+
11097
+		if warehouse.StockMinNumber < minNumber {
11098
+			//fmt.Println("金4")
11099
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
11100
+			if warehouse.MaxUnit != warehouse.MinUnit {
11101
+				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
11102
+			}
11103
+			if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
11104
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
11105
+			}
11106
+		} else {
11107
+			//fmt.Println("金5")
11108
+			if minNumber > 0 {
11109
+				if (warehouse.StockMinNumber - minNumber) >= 0 {
11110
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
11111
+				}
11112
+
11113
+			}
11114
+
11115
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
11116
+				//fmt.Println("6")
11117
+				if warehouse.StockMinNumber > 0 {
11118
+					if warehouse.StockMinNumber-deliver_number >= 0 {
11119
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
11120
+					}
11121
+
11122
+				}
11123
+
11124
+			}
11125
+
11126
+		}
11127
+
11128
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
11129
+			if (warehouse.StockMinNumber - deliver_number) >= 0 {
11130
+				//fmt.Println("金7")
11131
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
11132
+			}
11133
+
11134
+		}
11135
+
11136
+		if drup.MaxUnit != drup.MinUnit {
11137
+			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
11138
+				return errors.New("库存数量不足")
11139
+			}
11140
+		}
11141
+		if warehouse.StockMinNumber <= 0 {
11142
+			warehouse.StockMinNumber = 0
11143
+		}
11144
+
11145
+		errThree := UpDateNewDrugWarehouseInfoByStock(&warehouse, tx)
11146
+
11147
+		if errThree != nil {
11148
+			return errors.New("扣减库存失败")
11149
+		}
11150
+
11151
+		//查询该药品剩余库存
11152
+		infolist, _ := FindNewDrugWarehouseInfoFlushCount(advice.DrugId, advice.OrgId, tx)
11153
+		var over_count int64
11154
+		for _, its := range infolist {
11155
+			if its.MaxUnit == drup.MaxUnit {
11156
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
11157
+			}
11158
+			over_count += its.StockMaxNumber + its.StockMinNumber
11159
+		}
11160
+
11161
+		drugWareInfo, _ := GetLastNewWarehouseOutInfoById(advice.DrugId, tx)
11162
+		drugflow := models.DrugFlow{
11163
+			WarehouseOutId:          warehouseout.ID,
11164
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
11165
+			DrugId:                  advice.DrugId,
11166
+			Number:                  warehouse.Number,
11167
+			ProductDate:             advice.ProductDate,
11168
+			ExpireDate:              advice.ExpiryDate,
11169
+			Count:                   deliver_number,
11170
+			Price:                   warehouse.RetailPrice,
11171
+			Status:                  1,
11172
+			Ctime:                   advice.SysRecordTime,
11173
+			Mtime:                   time.Now().Unix(),
11174
+			UserOrgId:               advice.OrgId,
11175
+			Manufacturer:            advice.Manufacturer,
11176
+			Dealer:                  advice.Dealer,
11177
+			BatchNumber:             warehouse.BatchNumber,
11178
+			MaxUnit:                 drup.MinUnit,
11179
+			ConsumableType:          2,
11180
+			IsEdit:                  1,
11181
+			Creator:                 0,
11182
+			IsSys:                   0,
11183
+			WarehouseOutDetailId:    drugWareInfo.ID,
11184
+			AdviceId:                advice.ID,
11185
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
11186
+			StorehouseId:            advice.StorehouseId,
11187
+			AdminUserId:             advice.AdminUserId,
11188
+			LastPrice:               warehouse.Price,
11189
+			StockCount:              advice.StockCount,
11190
+			WarehousingDetailId:     warehouse.ID,
11191
+			OverCount:               over_count,
11192
+			RetailPrice:             drug_price, //手动出库出库价格
11193
+			WarehousingId:           warehouse.ID,
11194
+			SystemTime:              advice.SysRecordTime,
11195
+			PatientId:               advice.PatientId,
11196
+			Remark:                  advice.Remark,
11197
+		}
11198
+		if warehouse.RetailPrice == 0 {
11199
+			drugflow.Price = advice.Price
11200
+		}
11201
+
11202
+		CreateDrugFlowOne(drugflow)
11203
+
11204
+		//更新出库id
11205
+		UpdateNewDrugWarehouseOutInfo(advice.ID, warehouse.ID, advice.OrgId, over_count, drug_price, tx)
11206
+
11207
+		return nil
11208
+
11209
+	} else {
11210
+		stock_number_int := strconv.FormatInt(stock_number, 10)
11211
+		stock_number_int_count, _ := strconv.ParseFloat(stock_number_int, 64)
11212
+		drug_price = stock_number_int_count * advice.Price
11213
+		//扣减库存
11214
+		warehouse.StockMaxNumber = 0
11215
+		warehouse.StockMinNumber = 0
11216
+		warehouse.Mtime = time.Now().Unix()
11217
+
11218
+		errThree := UpDateNewDrugWarehouseInfoByStock(&warehouse, tx)
11219
+		if errThree != nil {
11220
+			return errThree
11221
+		}
11222
+
11223
+		//查询该药品剩余库存
11224
+		infolist, _ := FindNewDrugWarehouseInfoFlushCount(advice.DrugId, advice.OrgId, tx)
11225
+		var over_count int64
11226
+		for _, its := range infolist {
11227
+			if its.MaxUnit == drup.MaxUnit {
11228
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
11229
+			}
11230
+			over_count += its.StockMaxNumber + its.StockMinNumber
11231
+		}
11232
+		drugWareInfo, _ := GetLastNewWarehouseOutInfoById(advice.DrugId, tx)
11233
+		drugflow := models.DrugFlow{
11234
+			WarehouseOutId:          warehouseout.ID,
11235
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
11236
+			DrugId:                  advice.DrugId,
11237
+			Number:                  warehouse.Number,
11238
+			ProductDate:             advice.ProductDate,
11239
+			ExpireDate:              advice.ExpiryDate,
11240
+			Count:                   stock_number,
11241
+			Price:                   warehouse.RetailPrice,
11242
+			Status:                  1,
11243
+			Ctime:                   advice.SysRecordTime,
11244
+			Mtime:                   time.Now().Unix(),
11245
+			UserOrgId:               advice.OrgId,
11246
+			Manufacturer:            advice.Manufacturer,
11247
+			Dealer:                  advice.Dealer,
11248
+			BatchNumber:             warehouse.BatchNumber,
11249
+			MaxUnit:                 drup.MinUnit,
11250
+			ConsumableType:          2,
11251
+			IsEdit:                  1,
11252
+			Creator:                 0,
11253
+			IsSys:                   0,
11254
+			WarehouseOutDetailId:    drugWareInfo.ID,
11255
+			AdviceId:                advice.ID,
11256
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
11257
+			StorehouseId:            advice.StorehouseId,
11258
+			AdminUserId:             advice.AdminUserId,
11259
+			LastPrice:               warehouse.Price,
11260
+			StockCount:              advice.StockCount,
11261
+			OverCount:               over_count,
11262
+			RetailPrice:             drug_price, //手动出库出库价格
11263
+			WarehousingId:           warehouse.ID,
11264
+			WarehousingDetailId:     warehouse.ID,
11265
+			SystemTime:              advice.SysRecordTime,
11266
+			PatientId:               advice.PatientId,
11267
+			Remark:                  advice.Remark,
11268
+		}
11269
+
11270
+		CreateNewDrugFlowOne(drugflow, tx)
11271
+		//更新出库id
11272
+		UpdateNewDrugWarehouseOutInfo(advice.ID, warehouse.ID, advice.OrgId, over_count, drug_price, tx)
11273
+		// 出库完成后,要将该批次库存清零
11274
+
11275
+		prescribingNumber_two_temp := deliver_number - stock_number
11276
+
11277
+		advice.CountUnit = drup.MinUnit
11278
+
11279
+		AutoNewDrugDeliverInfoFourtyOne(orgID, prescribingNumber_two_temp, warehouseout, drup, advice, unit, tx)
11280
+	}
11281
+
11282
+	return
11283
+}