|
@@ -295,6 +295,80 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend |
|
@@ -295,6 +295,80 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend |
295
|
return dividendsOrder, nil
|
295
|
return dividendsOrder, nil
|
296
|
}
|
296
|
}
|
297
|
|
297
|
|
|
|
298
|
+func (repository *DividendsOrderRepository) SaveMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) {
|
|
|
299
|
+ tx := repository.transactionContext.PgTx
|
|
|
300
|
+ var dividendsOrderModels []*models.DividendsOrder
|
|
|
301
|
+ var orderGoodsModel []*models.OrderGood
|
|
|
302
|
+ for _, dividendsOrder := range dividendsOrders {
|
|
|
303
|
+ dividendsOrderModels = append(dividendsOrderModels, &models.DividendsOrder{
|
|
|
304
|
+ DividendsOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
305
|
+ DividendsOriginalOrderNum: dividendsOrder.DividendsOriginalOrderNum,
|
|
|
306
|
+ DividendsOrderAmount: dividendsOrder.DividendsOrderAmount,
|
|
|
307
|
+ OrderTime: dividendsOrder.OrderTime,
|
|
|
308
|
+ DividendTime: dividendsOrder.DividendTime,
|
|
|
309
|
+ DividendStatus: dividendsOrder.DividendStatus,
|
|
|
310
|
+ Region: dividendsOrder.Region,
|
|
|
311
|
+ CustomerName: dividendsOrder.CustomerName,
|
|
|
312
|
+ Org: dividendsOrder.Org,
|
|
|
313
|
+ Company: dividendsOrder.Company,
|
|
|
314
|
+ CreatedAt: time.Now(),
|
|
|
315
|
+ DeletedAt: dividendsOrder.DeletedAt,
|
|
|
316
|
+ UpdatedAt: dividendsOrder.UpdatedAt,
|
|
|
317
|
+ OperateTime: time.Now(),
|
|
|
318
|
+ Operator: dividendsOrder.Operator,
|
|
|
319
|
+ Remarks: dividendsOrder.Remarks,
|
|
|
320
|
+ })
|
|
|
321
|
+ for _, good := range dividendsOrder.Goods {
|
|
|
322
|
+ orderGoodsModel = append(orderGoodsModel, &models.OrderGood{
|
|
|
323
|
+ OrderGoodAmount: good.OrderGoodAmount,
|
|
|
324
|
+ OrderGoodName: good.OrderGoodName,
|
|
|
325
|
+ OrderGoodPrice: good.OrderGoodPrice,
|
|
|
326
|
+ OrderGoodQuantity: good.OrderGoodQuantity,
|
|
|
327
|
+ DividendsOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
328
|
+ DividendsReturnedOrderNumber: "",
|
|
|
329
|
+ CooperationContractNumber: good.CooperationContractNumber,
|
|
|
330
|
+ CompanyId: good.CompanyId,
|
|
|
331
|
+ OrgId: good.OrgId,
|
|
|
332
|
+ OrderGoodExpense: good.OrderGoodExpense,
|
|
|
333
|
+ OrderGoodDividendsStatus: good.OrderGoodDividendsStatus,
|
|
|
334
|
+ CreatedAt: time.Now(),
|
|
|
335
|
+ DeletedAt: time.Time{},
|
|
|
336
|
+ UpdatedAt: time.Time{},
|
|
|
337
|
+ })
|
|
|
338
|
+ }
|
|
|
339
|
+ }
|
|
|
340
|
+ if _, err := tx.Model(÷ndsOrderModels).Insert(); err != nil { // 新增分红订单
|
|
|
341
|
+ return nil, err
|
|
|
342
|
+ } else { // 新增分红订单产品
|
|
|
343
|
+ if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
|
|
|
344
|
+ return nil, err
|
|
|
345
|
+ }
|
|
|
346
|
+ }
|
|
|
347
|
+ var dividendsOrdersSaved []*domain.DividendsOrder
|
|
|
348
|
+ for _, dividendsOrderModel := range dividendsOrderModels {
|
|
|
349
|
+ //获取订单产品
|
|
|
350
|
+ var orderGoodModels []*models.OrderGood
|
|
|
351
|
+ orderGoodModelQuery := tx.Model(&orderGoodModels)
|
|
|
352
|
+ if err := orderGoodModelQuery.
|
|
|
353
|
+ Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
|
|
|
354
|
+ Where("org_id = ?", dividendsOrderModel.Org.OrgId).
|
|
|
355
|
+ Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).
|
|
|
356
|
+ Select(); err != nil {
|
|
|
357
|
+ log.Logger.Error("分红订单关联的产品不存在", map[string]interface{}{
|
|
|
358
|
+ "dividendsOrderModel": dividendsOrderModel,
|
|
|
359
|
+ })
|
|
|
360
|
+ return nil, fmt.Errorf("分红订单关联的产品不存在")
|
|
|
361
|
+ }
|
|
|
362
|
+ // 聚合分红订单
|
|
|
363
|
+ if dividendsOrder, err := transform.TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel, orderGoodModels); err != nil {
|
|
|
364
|
+ return dividendsOrders, err
|
|
|
365
|
+ } else {
|
|
|
366
|
+ dividendsOrders = append(dividendsOrders, dividendsOrder)
|
|
|
367
|
+ }
|
|
|
368
|
+ }
|
|
|
369
|
+ return dividendsOrdersSaved, nil
|
|
|
370
|
+}
|
|
|
371
|
+
|
298
|
func (repository *DividendsOrderRepository) UpdateMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) {
|
372
|
func (repository *DividendsOrderRepository) UpdateMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) {
|
299
|
tx := repository.transactionContext.PgTx
|
373
|
tx := repository.transactionContext.PgTx
|
300
|
var dividendsOrderModels []*models.DividendsOrder
|
374
|
var dividendsOrderModels []*models.DividendsOrder
|