XMLWAN 3 lat temu
rodzic
commit
0e2266868c

+ 66 - 28
controllers/drug_stock_api_contorller.go Wyświetl plik

@@ -183,15 +183,29 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
183 183
 
184 184
 				}
185 185
 
186
-				if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
187
-					utils.ErrorLog("number")
186
+				if items["lot_number"] == nil || reflect.TypeOf(items["lot_number"]).String() != "string" {
187
+					utils.ErrorLog("lot_number")
188 188
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
189 189
 					return
190 190
 				}
191
-				number, _ := items["number"].(string)
191
+				lot_number, _ := items["lot_number"].(string)
192
+
193
+				if items["batch_number"] == nil || reflect.TypeOf(items["batch_number"]).String() != "string" {
194
+					utils.ErrorLog("batch_number")
195
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
196
+					return
197
+				}
198
+				batch_number, _ := items["batch_number"].(string)
199
+
200
+				if items["packing_unit"] == nil || reflect.TypeOf(items["packing_unit"]).String() != "string" {
201
+					utils.ErrorLog("packing_unit")
202
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
203
+					return
204
+				}
205
+				packing_unit, _ := items["packing_unit"].(string)
192 206
 
193 207
 				var remark string
194
-				if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
208
+				if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
195 209
 					remark = ""
196 210
 				} else {
197 211
 					remark = items["remark"].(string)
@@ -201,7 +215,7 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
201 215
 					WarehousingOrder: warehousing.WarehousingOrder,
202 216
 					WarehousingId:    warehousing.ID,
203 217
 					DrugId:           drug_id,
204
-					Number:           number,
218
+					Number:           lot_number,
205 219
 					ProductDate:      productDates,
206 220
 					ExpiryDate:       expiryDates,
207 221
 					WarehousingCount: warehousing_count,
@@ -215,7 +229,10 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
215 229
 					Manufacturer:     manufacturer_id,
216 230
 					Dealer:           dealer_id,
217 231
 					//RetailPrice:      retail_price,
232
+					StockMaxNumber:   warehousing_count,
218 233
 					RetailTotalPrice: retail_price_total,
234
+					BatchNumber:      batch_number,
235
+					MaxUnit:          packing_unit,
219 236
 				}
220 237
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
221 238
 
@@ -429,6 +446,7 @@ func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
429 446
 
430 447
 	warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
431 448
 
449
+	manufacturerList, _ := service.GetAllDrugLibList(admin.CurrentOrgId)
432 450
 	if err != nil {
433 451
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
434 452
 		return
@@ -441,8 +459,9 @@ func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
441 459
 	warehousingInfo, err := service.FindDrugWarehousingInfoById(id, admin.CurrentOrgId)
442 460
 	if err == nil {
443 461
 		c.ServeSuccessJSON(map[string]interface{}{
444
-			"info":        warehousingInfo,
445
-			"warehousing": warehousing,
462
+			"info":             warehousingInfo,
463
+			"warehousing":      warehousing,
464
+			"manufacturerList": manufacturerList,
446 465
 		})
447 466
 	} else {
448 467
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -450,11 +469,12 @@ func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
450 469
 }
451 470
 
452 471
 func (c *StockDrugApiController) EditDrugWarehouse() {
472
+
453 473
 	warehousing_time := c.GetString("warehousing_time")
454 474
 	id, _ := c.GetInt64("id", 0)
455 475
 	types, _ := c.GetInt64("type", 0)
456
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
457
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
476
+	//manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
477
+	//dealer_id, _ := c.GetInt64("dealer_id", 0)
458 478
 
459 479
 	if id == 0 {
460 480
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -482,8 +502,8 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
482 502
 		Status:           1,
483 503
 		WarehousingTime:  warehousingDate.Unix(),
484 504
 		Type:             warehouse.Type,
485
-		Dealer:           dealer_id,
486
-		Manufacturer:     manufacturer_id,
505
+		//Dealer:           dealer_id,
506
+		//Manufacturer:     manufacturer_id,
487 507
 	}
488 508
 
489 509
 	service.EditDrugWarehousingOne(warehousing, id)
@@ -501,6 +521,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
501 521
 
502 522
 	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
503 523
 		thisStockIn, _ := dataBody["stockIn"].([]interface{})
524
+
504 525
 		if len(thisStockIn) > 0 {
505 526
 			for _, item := range thisStockIn {
506 527
 				items := item.(map[string]interface{})
@@ -528,13 +549,22 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
528 549
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
529 550
 				total := float64(warehousing_count) * price
530 551
 
531
-				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
532
-					utils.ErrorLog("retail_price")
552
+				//if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
553
+				//	utils.ErrorLog("retail_price")
554
+				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
555
+				//	return
556
+				//}
557
+				//retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
558
+				//retail_price_total := float64(warehousing_count) * last_price
559
+
560
+				if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
561
+					utils.ErrorLog("last_price")
533 562
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
534 563
 					return
535 564
 				}
536
-				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
537
-				retail_price_total := float64(warehousing_count) * retail_price
565
+				last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
566
+
567
+				retail_price_total := float64(warehousing_count) * last_price
538 568
 
539 569
 				var productDates int64
540 570
 				var expiryDates int64
@@ -551,8 +581,8 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
551 581
 						expiryDates = expiry_date.Unix()
552 582
 
553 583
 					}
554
-
555 584
 				}
585
+
556 586
 				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
557 587
 					productDates = 0
558 588
 				} else {
@@ -574,8 +604,15 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
574 604
 				}
575 605
 				number, _ := items["number"].(string)
576 606
 
607
+				if items["batch_number"] == nil || reflect.TypeOf(items["batch_number"]).String() != "string" {
608
+					utils.ErrorLog("batch_number")
609
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
610
+					return
611
+				}
612
+				batch_number, _ := items["batch_number"].(string)
613
+
577 614
 				var remark string
578
-				if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
615
+				if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
579 616
 					remark = ""
580 617
 				} else {
581 618
 					remark = items["remark"].(string)
@@ -588,13 +625,13 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
588 625
 				}
589 626
 				id := int64(items["id"].(float64))
590 627
 
591
-				if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "float64" {
592
-					utils.ErrorLog("dealer")
593
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
594
-					return
595
-				}
596
-				dealer := int64(items["dealer"].(float64))
597
-
628
+				//if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "float64" {
629
+				//	utils.ErrorLog("dealer")
630
+				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
631
+				//	return
632
+				//}
633
+				//dealer := int64(items["dealer"].(float64))
634
+				//
598 635
 				if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
599 636
 					utils.ErrorLog("manufacturer")
600 637
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -618,9 +655,10 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
618 655
 						OrgId:            adminUserInfo.CurrentOrgId,
619 656
 						Type:             types,
620 657
 						Manufacturer:     manufacturer,
621
-						Dealer:           dealer,
622
-						RetailPrice:      retail_price,
658
+						//Dealer:           dealer,
659
+						RetailPrice:      last_price,
623 660
 						RetailTotalPrice: retail_price_total,
661
+						BatchNumber:      batch_number,
624 662
 					}
625 663
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
626 664
 
@@ -642,8 +680,8 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
642 680
 						OrgId:            adminUserInfo.CurrentOrgId,
643 681
 						Type:             types,
644 682
 						Manufacturer:     manufacturer,
645
-						Dealer:           dealer,
646
-						RetailPrice:      retail_price,
683
+						//Dealer:           dealer,
684
+						RetailPrice:      last_price,
647 685
 						RetailTotalPrice: retail_price_total,
648 686
 					}
649 687
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)

+ 194 - 193
controllers/patient_api_controller.go Wyświetl plik

@@ -1653,205 +1653,206 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1653 1653
 			//查询已经执行的医嘱
1654 1654
 			advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1655 1655
 			for _, item := range advices {
1656
-				fmt.Println("非自备要22222")
1657
-				if item.Way == 1 {
1658
-					out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
1659
-					if err == gorm.ErrRecordNotFound {
1660
-						//没有记录,则创建出库单
1661
-						timeStr := time.Now().Format("2006-01-02")
1662
-						timeArr := strings.Split(timeStr, "-")
1663
-						total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
1664
-						total = total + 1
1665
-						warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1666
-						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1667
-						number = number + total
1668
-						warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1669
-						creater := adminUserInfo.AdminUser.Id
1670
-						warehouseOut := models.DrugWarehouseOut{
1671
-							WarehouseOutOrderNumber: warehousing_out_order,
1672
-							OperationTime:           time.Now().Unix(),
1673
-							OrgId:                   adminUserInfo.CurrentOrgId,
1674
-							Creater:                 creater,
1675
-							Ctime:                   time.Now().Unix(),
1676
-							Status:                  1,
1677
-							WarehouseOutTime:        item.RecordDate,
1678
-							Dealer:                  0,
1679
-							Manufacturer:            0,
1680
-							Type:                    1,
1681
-							IsSys:                   1,
1682
-						}
1683
-
1684
-						err := service.AddSigleDrugWarehouseOut(&warehouseOut)
1685
-						if err != nil {
1686
-							utils.TraceLog("创建出库单失败 err = %v", err)
1687
-						} else {
1688
-							if item.Way == 1 {
1689
-								if item.PrescribingNumber > 0 {
1690
-									warehouseOutInfo := &models.DrugWarehouseOutInfo{
1691
-										WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1692
-										WarehouseOutId:          warehouseOut.ID,
1693
-										Status:                  1,
1694
-										Ctime:                   time.Now().Unix(),
1695
-										Remark:                  "",
1696
-										OrgId:                   adminUserInfo.CurrentOrgId,
1697
-										Type:                    1,
1698
-										Manufacturer:            0,
1699
-										Dealer:                  0,
1700
-										IsSys:                   1,
1701
-										SysRecordTime:           item.RecordDate,
1702
-										DrugId:                  item.DrugId,
1703
-									}
1704
-									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1705
-									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1706
-									warehouseOutInfo.Count = count
1707
-									stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1708
-									warehouseOutInfo.Price = stockInInfo.Price
1709
-									err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1710
-									if err == nil {
1711
-										details := &models.DrugAutomaticReduceDetail{
1712
-											WarehouseOutId:          warehouseOutInfo.ID,
1713
-											WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1714
-											PatientId:               item.PatientId,
1715
-											Ctime:                   time.Now().Unix(),
1716
-											Mtime:                   time.Now().Unix(),
1717
-											Status:                  1,
1718
-											RecordTime:              item.RecordDate,
1719
-											OrgId:                   adminUserInfo.CurrentOrgId,
1720
-											DrugId:                  item.DrugId,
1721
-											Count:                   count,
1722
-										}
1723
-										service.AddSigleDrugAutoReduceRecordInfo(details)
1724
-										if err != nil {
1725
-											utils.TraceLog("创建出库单失败 err = %v", err)
1726
-										} else {
1727
-											if item.Way == 1 {
1728
-												if item.PrescribingNumber > 0 {
1729
-													warehouseOutInfo := &models.DrugWarehouseOutInfo{
1730
-														WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1731
-														WarehouseOutId:          warehouseOut.ID,
1732
-														Status:                  1,
1733
-														Ctime:                   time.Now().Unix(),
1734
-														Remark:                  "",
1735
-														OrgId:                   adminUserInfo.CurrentOrgId,
1736
-														Type:                    1,
1737
-														Manufacturer:            0,
1738
-														Dealer:                  0,
1739
-														IsSys:                   1,
1740
-														SysRecordTime:           item.RecordDate,
1741
-														DrugId:                  item.DrugId,
1742
-													}
1743
-													prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1744
-													count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1745
-													warehouseOutInfo.Count = count
1746
-													stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1747
-													warehouseOutInfo.Price = stockInInfo.Price
1748
-													err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1749
-													if err == nil {
1750
-														details := &models.DrugAutomaticReduceDetail{
1751
-															WarehouseOutId:          warehouseOutInfo.ID,
1752
-															WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1753
-															PatientId:               item.PatientId,
1754
-															Ctime:                   time.Now().Unix(),
1755
-															Mtime:                   time.Now().Unix(),
1756
-															Status:                  1,
1757
-															RecordTime:              item.RecordDate,
1758
-															OrgId:                   adminUserInfo.CurrentOrgId,
1759
-															DrugId:                  item.DrugId,
1760
-															Count:                   count,
1761
-														}
1762
-														service.AddSigleDrugAutoReduceRecordInfo(details)
1763
-													}
1764
-												}
1765
-											}
1766
-										}
1767
-
1768
-									}
1769
-								}
1770
-							}
1771
-						}
1772
-					} else if err == nil {
1773
-						if item.Way == 1 {
1774
-							outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
1775
-							if err == gorm.ErrRecordNotFound {
1776
-								warehouseOutInfo := &models.DrugWarehouseOutInfo{
1777
-									WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
1778
-									WarehouseOutId:          out.ID,
1779
-									Status:                  1,
1780
-									Ctime:                   time.Now().Unix(),
1781
-									Remark:                  "",
1782
-									OrgId:                   adminUserInfo.CurrentOrgId,
1783
-									Type:                    1,
1784
-									Manufacturer:            0,
1785
-									Dealer:                  0,
1786
-									IsSys:                   1,
1787
-									SysRecordTime:           item.RecordDate,
1788
-								}
1789
-
1790
-								stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1791
-								warehouseOutInfo.Price = stockInInfo.Price
1792
-								warehouseOutInfo.DrugId = item.DrugId
1793
-								prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1794
-								count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1795
-								warehouseOutInfo.Count = count
1796
-								err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1797
-								if err == nil {
1798
-									details := &models.DrugAutomaticReduceDetail{
1799
-										WarehouseOutId:          warehouseOutInfo.ID,
1800
-										WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1801
-										PatientId:               item.PatientId,
1802
-										Ctime:                   time.Now().Unix(),
1803
-										Mtime:                   time.Now().Unix(),
1804
-										Status:                  1,
1805
-										RecordTime:              item.RecordDate,
1806
-										OrgId:                   adminUserInfo.CurrentOrgId,
1807
-										DrugId:                  item.DrugId,
1808
-										Count:                   count,
1809
-									}
1810
-									service.AddSigleDrugAutoReduceRecordInfo(details)
1811
-								}
1812
-
1813
-							} else if err == nil { //记录存在,则将增加数量
1814
-								if outInfo.ID > 0 {
1815
-									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1816
-									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1817
-									service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
1818
-								}
1819
-
1820
-								count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
1821
-								if count == 0 {
1822
-									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1823
-									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1824
-									details := &models.DrugAutomaticReduceDetail{
1825
-										WarehouseOutId:          outInfo.ID,
1826
-										WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
1827
-										PatientId:               item.PatientId,
1828
-										Ctime:                   time.Now().Unix(),
1829
-										Mtime:                   time.Now().Unix(),
1830
-										Status:                  1,
1831
-										RecordTime:              item.RecordDate,
1832
-										OrgId:                   adminUserInfo.CurrentOrgId,
1833
-										DrugId:                  item.DrugId,
1834
-										Count:                   count,
1835
-									}
1836
-									service.AddSigleDrugAutoReduceRecordInfo(details)
1837
-								} else if count == 1 {
1838
-									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1839
-									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1840
-									service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
1841
-								}
1842 1656
 
1843
-							}
1844
-						}
1845
-					}
1846
-				}
1657
+				//调用药品出库接口
1658
+				service.DrugsDelivery(item.UserOrgId, item)
1659
+
1660
+				//if item.Way == 1 {
1661
+				//	out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
1662
+				//	if err == gorm.ErrRecordNotFound {
1663
+				//		//没有记录,则创建出库单
1664
+				//		timeStr := time.Now().Format("2006-01-02")
1665
+				//		timeArr := strings.Split(timeStr, "-")
1666
+				//		total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
1667
+				//		total = total + 1
1668
+				//		warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1669
+				//		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1670
+				//		number = number + total
1671
+				//		warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1672
+				//		creater := adminUserInfo.AdminUser.Id
1673
+				//		warehouseOut := models.DrugWarehouseOut{
1674
+				//			WarehouseOutOrderNumber: warehousing_out_order,
1675
+				//			OperationTime:           time.Now().Unix(),
1676
+				//			OrgId:                   adminUserInfo.CurrentOrgId,
1677
+				//			Creater:                 creater,
1678
+				//			Ctime:                   time.Now().Unix(),
1679
+				//			Status:                  1,
1680
+				//			WarehouseOutTime:        item.RecordDate,
1681
+				//			Dealer:                  0,
1682
+				//			Manufacturer:            0,
1683
+				//			Type:                    1,
1684
+				//			IsSys:                   1,
1685
+				//		}
1686
+				//
1687
+				//		err := service.AddSigleDrugWarehouseOut(&warehouseOut)
1688
+				//		if err != nil {
1689
+				//			utils.TraceLog("创建出库单失败 err = %v", err)
1690
+				//		} else {
1691
+				//			if item.Way == 1 {
1692
+				//				if item.PrescribingNumber > 0 {
1693
+				//					warehouseOutInfo := &models.DrugWarehouseOutInfo{
1694
+				//						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1695
+				//						WarehouseOutId:          warehouseOut.ID,
1696
+				//						Status:                  1,
1697
+				//						Ctime:                   time.Now().Unix(),
1698
+				//						Remark:                  "",
1699
+				//						OrgId:                   adminUserInfo.CurrentOrgId,
1700
+				//						Type:                    1,
1701
+				//						Manufacturer:            0,
1702
+				//						Dealer:                  0,
1703
+				//						IsSys:                   1,
1704
+				//						SysRecordTime:           item.RecordDate,
1705
+				//						DrugId:                  item.DrugId,
1706
+				//					}
1707
+				//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1708
+				//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1709
+				//					warehouseOutInfo.Count = count
1710
+				//					stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1711
+				//					warehouseOutInfo.Price = stockInInfo.Price
1712
+				//					err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1713
+				//					if err == nil {
1714
+				//						details := &models.DrugAutomaticReduceDetail{
1715
+				//							WarehouseOutId:          warehouseOutInfo.ID,
1716
+				//							WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1717
+				//							PatientId:               item.PatientId,
1718
+				//							Ctime:                   time.Now().Unix(),
1719
+				//							Mtime:                   time.Now().Unix(),
1720
+				//							Status:                  1,
1721
+				//							RecordTime:              item.RecordDate,
1722
+				//							OrgId:                   adminUserInfo.CurrentOrgId,
1723
+				//							DrugId:                  item.DrugId,
1724
+				//							Count:                   count,
1725
+				//						}
1726
+				//						service.AddSigleDrugAutoReduceRecordInfo(details)
1727
+				//						if err != nil {
1728
+				//							utils.TraceLog("创建出库单失败 err = %v", err)
1729
+				//						} else {
1730
+				//							if item.Way == 1 {
1731
+				//								if item.PrescribingNumber > 0 {
1732
+				//									warehouseOutInfo := &models.DrugWarehouseOutInfo{
1733
+				//										WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1734
+				//										WarehouseOutId:          warehouseOut.ID,
1735
+				//										Status:                  1,
1736
+				//										Ctime:                   time.Now().Unix(),
1737
+				//										Remark:                  "",
1738
+				//										OrgId:                   adminUserInfo.CurrentOrgId,
1739
+				//										Type:                    1,
1740
+				//										Manufacturer:            0,
1741
+				//										Dealer:                  0,
1742
+				//										IsSys:                   1,
1743
+				//										SysRecordTime:           item.RecordDate,
1744
+				//										DrugId:                  item.DrugId,
1745
+				//									}
1746
+				//									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1747
+				//									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1748
+				//									warehouseOutInfo.Count = count
1749
+				//									stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1750
+				//									warehouseOutInfo.Price = stockInInfo.Price
1751
+				//									err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1752
+				//									if err == nil {
1753
+				//										details := &models.DrugAutomaticReduceDetail{
1754
+				//											WarehouseOutId:          warehouseOutInfo.ID,
1755
+				//											WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1756
+				//											PatientId:               item.PatientId,
1757
+				//											Ctime:                   time.Now().Unix(),
1758
+				//											Mtime:                   time.Now().Unix(),
1759
+				//											Status:                  1,
1760
+				//											RecordTime:              item.RecordDate,
1761
+				//											OrgId:                   adminUserInfo.CurrentOrgId,
1762
+				//											DrugId:                  item.DrugId,
1763
+				//											Count:                   count,
1764
+				//										}
1765
+				//										service.AddSigleDrugAutoReduceRecordInfo(details)
1766
+				//									}
1767
+				//								}
1768
+				//							}
1769
+				//						}
1770
+				//
1771
+				//					}
1772
+				//				}
1773
+				//			}
1774
+				//		}
1775
+				//	} else if err == nil {
1776
+				//		if item.Way == 1 {
1777
+				//			outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
1778
+				//			if err == gorm.ErrRecordNotFound {
1779
+				//				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1780
+				//					WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
1781
+				//					WarehouseOutId:          out.ID,
1782
+				//					Status:                  1,
1783
+				//					Ctime:                   time.Now().Unix(),
1784
+				//					Remark:                  "",
1785
+				//					OrgId:                   adminUserInfo.CurrentOrgId,
1786
+				//					Type:                    1,
1787
+				//					Manufacturer:            0,
1788
+				//					Dealer:                  0,
1789
+				//					IsSys:                   1,
1790
+				//					SysRecordTime:           item.RecordDate,
1791
+				//				}
1792
+				//
1793
+				//				stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1794
+				//				warehouseOutInfo.Price = stockInInfo.Price
1795
+				//				warehouseOutInfo.DrugId = item.DrugId
1796
+				//				prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1797
+				//				count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1798
+				//				warehouseOutInfo.Count = count
1799
+				//				err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1800
+				//				if err == nil {
1801
+				//					details := &models.DrugAutomaticReduceDetail{
1802
+				//						WarehouseOutId:          warehouseOutInfo.ID,
1803
+				//						WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1804
+				//						PatientId:               item.PatientId,
1805
+				//						Ctime:                   time.Now().Unix(),
1806
+				//						Mtime:                   time.Now().Unix(),
1807
+				//						Status:                  1,
1808
+				//						RecordTime:              item.RecordDate,
1809
+				//						OrgId:                   adminUserInfo.CurrentOrgId,
1810
+				//						DrugId:                  item.DrugId,
1811
+				//						Count:                   count,
1812
+				//					}
1813
+				//					service.AddSigleDrugAutoReduceRecordInfo(details)
1814
+				//				}
1815
+				//
1816
+				//			} else if err == nil { //记录存在,则将增加数量
1817
+				//				if outInfo.ID > 0 {
1818
+				//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1819
+				//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1820
+				//					service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
1821
+				//				}
1822
+				//
1823
+				//				count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
1824
+				//				if count == 0 {
1825
+				//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1826
+				//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1827
+				//					details := &models.DrugAutomaticReduceDetail{
1828
+				//						WarehouseOutId:          outInfo.ID,
1829
+				//						WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
1830
+				//						PatientId:               item.PatientId,
1831
+				//						Ctime:                   time.Now().Unix(),
1832
+				//						Mtime:                   time.Now().Unix(),
1833
+				//						Status:                  1,
1834
+				//						RecordTime:              item.RecordDate,
1835
+				//						OrgId:                   adminUserInfo.CurrentOrgId,
1836
+				//						DrugId:                  item.DrugId,
1837
+				//						Count:                   count,
1838
+				//					}
1839
+				//					service.AddSigleDrugAutoReduceRecordInfo(details)
1840
+				//				} else if count == 1 {
1841
+				//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1842
+				//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1843
+				//					service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
1844
+				//				}
1845
+				//
1846
+				//			}
1847
+				//		}
1848
+				//	}
1849
+				//}
1847 1850
 			}
1848 1851
 		}
1849 1852
 
1850 1853
 		advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1851 1854
 		for _, item := range advices {
1852
-			fmt.Println("33333", item.ExecutionState)
1853
-			fmt.Println("医嘱名称", item.AdviceName)
1854
-			fmt.Println("item", item.Way)
1855
+
1855 1856
 			if item.Way == 2 {
1856 1857
 				if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
1857 1858
 

+ 7 - 2
models/drug_stock.go Wyświetl plik

@@ -42,6 +42,11 @@ type DrugWarehouseInfo struct {
42 42
 	Type             int64   `gorm:"column:type" json:"type" form:"type"`
43 43
 	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
44 44
 	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
45
+	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
46
+	MaxUnit          string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
47
+	MinUnit          string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
48
+	StockMaxNumber   int64   `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
49
+	StockMinNumber   int64   `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
45 50
 }
46 51
 
47 52
 func (DrugWarehouseInfo) TableName() string {
@@ -78,7 +83,7 @@ type DrugWarehouseOutInfo struct {
78 83
 	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
79 84
 	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
80 85
 	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
81
-	CountUnit               string   `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
86
+	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
82 87
 	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
83 88
 	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
84 89
 	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
@@ -211,7 +216,7 @@ type DrugAutomaticReduceDetail struct {
211 216
 	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
212 217
 	DrugId                  int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
213 218
 	Count                   int64  `gorm:"column:count" json:"count" form:"count"`
214
-	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
219
+	CountUnit               string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
215 220
 }
216 221
 
217 222
 func (DrugAutomaticReduceDetail) TableName() string {

+ 1 - 0
models/his_models.go Wyświetl plik

@@ -233,6 +233,7 @@ type HisDoctorAdviceInfo struct {
233 233
 	ChildDoctorAdvice     []*HisDoctorAdviceInfo `gorm:"ForeignKey:ParentId;AssociationForeignKey:ID" json:"child"`
234 234
 	Drug                  Drug                   `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
235 235
 	Diagnosis             int64                  `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
236
+	Way                   int64                  `gorm:"column:way" json:"way" form:"way"`
236 237
 }
237 238
 
238 239
 func (HisDoctorAdviceInfo) TableName() string {

+ 2 - 0
models/self_drug_models.go Wyświetl plik

@@ -387,6 +387,8 @@ type XtDrugWarehouseInfo struct {
387 387
 	Type             int64   `gorm:"column:type" json:"type" form:"type"`
388 388
 	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
389 389
 	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
390
+	StockMaxNumber   int64   `gorm:"column:stock_max_number" json:"stock_max_number"`
391
+	StockMinNumber   int64   `gorm:"column:stock_min_number" json:"stock_min_number"`
390 392
 }
391 393
 
392 394
 func (XtDrugWarehouseInfo) TableName() string {

+ 16 - 3
service/stock_service.go Wyświetl plik

@@ -458,12 +458,17 @@ func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err err
458 458
 
459 459
 }
460 460
 
461
+//药品先进先出,找出最先入库的批次
462
+
463
+func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {
464
+	err = readDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) ", drug_id).Order("ctime").First(&info).Error
465
+	return info, err
466
+}
467
+
461 468
 // 出库时先进先出,找出最先入库的批次
462 469
 func FindLastWarehousingInfoByID(drug_id int64) (info models.WarehousingInfo, err error) {
463 470
 	err = readDb.Model(&models.WarehousingInfo{}).Where("drup_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) ", drug_id).Order("ctime").First(&info).Error
464
-
465 471
 	return info, err
466
-
467 472
 }
468 473
 
469 474
 func FindLastDrugWarehousingInfo(order string) (info models.DrugWarehouseInfo, err error) {
@@ -540,6 +545,7 @@ type VMDrugWarehouseInfo struct {
540 545
 	Type             int64   `gorm:"column:type" json:"type" form:"type"`
541 546
 	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
542 547
 	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
548
+	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
543 549
 	Drug             *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
544 550
 }
545 551
 
@@ -566,6 +572,9 @@ type Drug struct {
566 572
 	PackingUnit     string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
567 573
 	PackingPrice    float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
568 574
 	DrugDay         string  `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
575
+	MaxUnit         string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
576
+	MinUnit         string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
577
+	LastPrice       float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
569 578
 }
570 579
 
571 580
 func (Drug) TableName() string {
@@ -1422,7 +1431,6 @@ func UpDateDrugWarehousingInfo(info *models.DrugWarehouseInfo) (err error) {
1422 1431
 	return err
1423 1432
 }
1424 1433
 
1425
-
1426 1434
 func EditWarehousing(warehouse models.Warehousing) {
1427 1435
 	err = readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", warehouse.WarehousingOrder).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehousing_time": warehouse.WarehousingTime, "modifier": warehouse.Modifier, "dealer": warehouse.Dealer, "manufacturer": warehouse.Manufacturer}).Error
1428 1436
 
@@ -1601,6 +1609,11 @@ func UpDateWarehouseOutStatus(id int64) (err error) {
1601 1609
 	return
1602 1610
 }
1603 1611
 
1612
+func UpDateDrugWarehouseInfoByStock(info *models.XtDrugWarehouseInfo) (err error) {
1613
+	err = writeDb.Save(&info).Error
1614
+	return err
1615
+}
1616
+
1604 1617
 func UpDateWarehouseInfoByStock(info *models.WarehousingInfo) (err error) {
1605 1618
 	err = writeDb.Save(&info).Error
1606 1619
 	return err

+ 5 - 3
service/warhouse_service.go Wyświetl plik

@@ -4,6 +4,7 @@ import (
4 4
 	"XT_New/models"
5 5
 	"XT_New/utils"
6 6
 	"errors"
7
+	"fmt"
7 8
 	_ "fmt"
8 9
 	"github.com/jinzhu/gorm"
9 10
 	"math"
@@ -91,7 +92,8 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
91 92
 
92 93
 	// 根据先进先出原则,查询最先入库的批次,进行出库
93 94
 	// 如果没有对应的库存,则报错
94
-	warehouse, err := FindLastWarehousingInfoByID(advice.DrugId)
95
+	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId)
96
+	fmt.Println("查询222222222222222222222222222222222222222222222222", err)
95 97
 	if err != nil {
96 98
 		return err
97 99
 	}
@@ -167,7 +169,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
167 169
 		if warehouse.StockMaxNumber < 0 {
168 170
 			return errors.New("库存数量不足")
169 171
 		}
170
-		errThree := UpDateWarehouseInfoByStock(&warehouse)
172
+		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
171 173
 		if errThree != nil {
172 174
 			return errThree
173 175
 		}
@@ -220,7 +222,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
220 222
 		warehouse.StockMaxNumber = 0
221 223
 		warehouse.StockMinNumber = 0
222 224
 		warehouse.Mtime = time.Now().Unix()
223
-		errThree := UpDateWarehouseInfoByStock(&warehouse)
225
+		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
224 226
 		if errThree != nil {
225 227
 			return errThree
226 228
 		}