| 
					
				 | 
			
			
				@@ -261,6 +261,23 @@ func (s *StoreEntry) OutboundApply(ctx context.Context, req *pasturePb.OutboundA 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if len(req.Goods) <= 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return xerr.Custom("请选择要出库商品") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	var outbound *model.Outbound 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if req.Id > 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		outbound, err = s.GetOutboundById(ctx, int64(req.Id)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if err != nil || outbound == nil || outbound.Id <= 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return xerr.Customf("该出库单不存在") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if currentUser.Id != int64(outbound.ApplicantId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return xerr.Custom("非申请人,无权修改该出库单") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if outbound.AuditStatus != pasturePb.AuditStatus_Pending { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return xerr.Custom("该出库单不能修改") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		// 创建出库申请 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		outbound = model.NewOutbound(req, currentUser) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	goodsItems := make([]*pasturePb.OutboundApplyGoodsItem, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	switch req.OutType { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	case pasturePb.OutType_Drugs: 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -321,13 +338,26 @@ func (s *StoreEntry) OutboundApply(ctx context.Context, req *pasturePb.OutboundA 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return xerr.Custom("未知的出库类型") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	unitMap := s.UnitMap() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err = s.DB.Transaction(func(tx *gorm.DB) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		// 创建出库申请 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		outbound := model.NewOutbound(req, currentUser) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if err = tx.Create(outbound).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			return xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if req.Id > 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if err = tx.Model(new(model.Outbound)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Where("id = ?", req.Id). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Update("applicant_remarks", req.ApplicantRemarks).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				return xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if err = tx.Model(new(model.OutboundDetail)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Where("outbound_id = ?", req.Id). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Update("is_delete = ?", pasturePb.IsShow_No).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				return xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if err = tx.Create(outbound).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				return xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		outboundLog := model.NewOutboundLogList(outbound.Id, goodsItems, unitMap) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		outboundLog := model.NewOutboundDetailList(outbound.Id, goodsItems, unitMap) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if err = tx.Create(outboundLog).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -415,12 +445,12 @@ func (s *StoreEntry) OutboundAudit(ctx context.Context, req *pasturePb.OutboundA 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return xerr.Custom("登录人信息失效") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	outboundLogs, err := s.GetOutboundLogsByOutboundId(ctx, outbound.Id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	outboundDetails, err := s.GetOutboundDetailByOutboundId(ctx, outbound.Id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if len(outboundLogs) <= 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if len(outboundDetails) <= 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return xerr.Custom("出库单商品不存在") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -451,7 +481,7 @@ func (s *StoreEntry) OutboundAudit(ctx context.Context, req *pasturePb.OutboundA 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		for _, v := range outboundLogs { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		for _, v := range outboundDetails { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			if err = tx.Table(tableName). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				Where("id = ?", v.GoodsId). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				Updates(map[string]interface{}{ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -473,7 +503,7 @@ func (s *StoreEntry) OutboundDetail(ctx context.Context, id int64) (*pasturePb.O 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return nil, xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	outboundLogs, err := s.GetOutboundLogsByOutboundId(ctx, id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	outboundLogs, err := s.GetOutboundDetailByOutboundId(ctx, id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return nil, xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -504,13 +534,45 @@ func (s *StoreEntry) OutboundDetail(ctx context.Context, id int64) (*pasturePb.O 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			ExamineAtFormat:   examineAtFormat, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			GoodsItem: &pasturePb.OutboundApplyItem{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				OutType:          outbound.OutType, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				Goods:            model.OutboundLogSlice(outboundLogs).ToPB(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Goods:            model.OutboundDetailSlice(outboundLogs).ToPB(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				ApplicantRemarks: outbound.ApplicantRemarks, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	}, nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func (s *StoreEntry) OutboundDelete(ctx context.Context, id int64) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	outbound, err := s.GetOutboundById(ctx, id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if outbound == nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return xerr.Custom("出库单不存在") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	currUser, err := s.GetCurrentSystemUser(ctx) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return xerr.Custom("登录信息失效") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if !(outbound.AuditStatus == pasturePb.AuditStatus_Pending || outbound.AuditStatus == pasturePb.AuditStatus_Cancel) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return xerr.Custom("出库单无法删除") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if currUser.Id != int64(outbound.ApplicantId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return xerr.Custom("非申请人,无权删除出库单") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	outbound.Delete() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err = s.DB.Model(new(model.Outbound)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Select("audit_status"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Updates(outbound).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return xerr.WithStack(err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func (s *StoreEntry) FrozenSemenList(ctx context.Context, req *pasturePb.FrozenSemenRequest, pagination *pasturePb.PaginationModel) (*pasturePb.FrozenSemenResponse, error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	frozenSemenList := make([]*model.FrozenSemen, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	var count int64 = 0 
			 |