|
@@ -207,7 +207,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) GetDividends |
|
@@ -207,7 +207,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) GetDividends |
207
|
}
|
207
|
}
|
208
|
}
|
208
|
}
|
209
|
|
209
|
|
210
|
-// ImportDividendsReturnedOrder TODO 导入分红退货单
|
210
|
+// ImportDividendsReturnedOrder 导入分红退货单
|
211
|
func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDividendsReturnedOrder(importDividendsReturnedOrderCommand *command.ImportDividendsReturnedOrderCommand) (interface{}, error) {
|
211
|
func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDividendsReturnedOrder(importDividendsReturnedOrderCommand *command.ImportDividendsReturnedOrderCommand) (interface{}, error) {
|
212
|
if err := importDividendsReturnedOrderCommand.ValidateCommand(); err != nil {
|
212
|
if err := importDividendsReturnedOrderCommand.ValidateCommand(); err != nil {
|
213
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
213
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
@@ -222,9 +222,141 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide |
|
@@ -222,9 +222,141 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide |
222
|
defer func() {
|
222
|
defer func() {
|
223
|
_ = transactionContext.RollbackTransaction()
|
223
|
_ = transactionContext.RollbackTransaction()
|
224
|
}()
|
224
|
}()
|
|
|
225
|
+
|
|
|
226
|
+ // 公司REST服务初始化
|
|
|
227
|
+ var companyService service.CompanyService
|
|
|
228
|
+ if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
|
|
|
229
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
230
|
+ } else {
|
|
|
231
|
+ companyService = value
|
|
|
232
|
+ }
|
|
|
233
|
+
|
|
|
234
|
+ // 获取公司信息
|
|
|
235
|
+ var company *domain.Company
|
|
|
236
|
+ if data, err := companyService.CompanyFrom(importDividendsReturnedOrderCommand.CompanyId); err != nil {
|
|
|
237
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
238
|
+ } else {
|
|
|
239
|
+ company = data
|
|
|
240
|
+ }
|
|
|
241
|
+
|
|
|
242
|
+ // 组织机构REST服务初始化
|
|
|
243
|
+ var organizationService service.OrgService
|
|
|
244
|
+ if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
|
|
|
245
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
246
|
+ } else {
|
|
|
247
|
+ organizationService = value
|
|
|
248
|
+ }
|
|
|
249
|
+
|
|
|
250
|
+ // 获取组织机构信息
|
|
|
251
|
+ var organization *domain.Org
|
|
|
252
|
+ if data, err := organizationService.OrgFrom(importDividendsReturnedOrderCommand.CompanyId, importDividendsReturnedOrderCommand.OrgId); err != nil {
|
|
|
253
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
254
|
+ } else {
|
|
|
255
|
+ organization = data
|
|
|
256
|
+ }
|
|
|
257
|
+
|
|
|
258
|
+ // 用户REST服务初始化
|
|
|
259
|
+ var userService service.UserService
|
|
|
260
|
+ if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
261
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
262
|
+ } else {
|
|
|
263
|
+ userService = value
|
|
|
264
|
+ }
|
|
|
265
|
+
|
|
|
266
|
+ // 获取操作人
|
|
|
267
|
+ var operator *domain.User
|
|
|
268
|
+ if data, err := userService.OperatorFrom(importDividendsReturnedOrderCommand.CompanyId, importDividendsReturnedOrderCommand.OrgId, importDividendsReturnedOrderCommand.UserId); err != nil {
|
|
|
269
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
270
|
+ } else {
|
|
|
271
|
+ operator = data
|
|
|
272
|
+ }
|
|
|
273
|
+
|
|
|
274
|
+ // 分红退货单DAO初始化
|
|
|
275
|
+ var dividendsReturnedOrderDao *dao.DividendsReturnedOrderDao
|
|
|
276
|
+ if value, err := factory.CreateDividendsReturnedOrderDao(map[string]interface{}{
|
|
|
277
|
+ "transactionContext": transactionContext,
|
|
|
278
|
+ }); err != nil {
|
|
|
279
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
280
|
+ } else {
|
|
|
281
|
+ dividendsReturnedOrderDao = value
|
|
|
282
|
+ }
|
|
|
283
|
+
|
|
|
284
|
+ // 分红退货单仓储初始化
|
|
|
285
|
+ var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
|
|
|
286
|
+ if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
|
|
|
287
|
+ "transactionContext": transactionContext,
|
|
|
288
|
+ }); err != nil {
|
|
|
289
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
290
|
+ } else {
|
|
|
291
|
+ dividendsReturnedOrderRepository = value
|
|
|
292
|
+ }
|
|
|
293
|
+
|
|
|
294
|
+ var dividendsReturnedOrderImportFailed []*domain.DividendsReturnedOrder
|
|
|
295
|
+ var dividendsReturnedOrderImportSuccessfully []*domain.DividendsReturnedOrder
|
|
|
296
|
+
|
|
|
297
|
+ for _, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData {
|
|
|
298
|
+ // 生成分红订单号
|
|
|
299
|
+ dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
|
|
|
300
|
+ if err != nil {
|
|
|
301
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
302
|
+ }
|
|
|
303
|
+
|
|
|
304
|
+ // 获取分红退货单产品
|
|
|
305
|
+ var orderGoods []*domain.OrderGood
|
|
|
306
|
+ for _, orderGood := range dividendsReturnedOrder.OrderGoods {
|
|
|
307
|
+ orderGoods = append(orderGoods, &domain.OrderGood{
|
|
|
308
|
+ OrderGoodId: 0,
|
|
|
309
|
+ OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
310
|
+ OrderGoodName: orderGood.OrderGoodName,
|
|
|
311
|
+ OrderGoodPrice: orderGood.OrderGoodPrice,
|
|
|
312
|
+ OrderGoodQuantity: orderGood.OrderGoodQuantity,
|
|
|
313
|
+ DividendsOrderNumber: "",
|
|
|
314
|
+ DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
|
|
|
315
|
+ CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
316
|
+ OrderGoodExpense: 0,
|
|
|
317
|
+ OrgId: importDividendsReturnedOrderCommand.OrgId,
|
|
|
318
|
+ CompanyId: importDividendsReturnedOrderCommand.CompanyId,
|
|
|
319
|
+ CreatedAt: time.Now(),
|
|
|
320
|
+ DeletedAt: time.Time{},
|
|
|
321
|
+ UpdatedAt: time.Time{},
|
|
|
322
|
+ })
|
|
|
323
|
+ }
|
|
|
324
|
+
|
|
|
325
|
+ newDividendsReturnedOrder := &domain.DividendsReturnedOrder{
|
|
|
326
|
+ DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
|
|
|
327
|
+ DividendsReturnedOrderRefund: dividendsReturnedOrder.DividendsReturnedOrderRefund,
|
|
|
328
|
+ OriginalOrderNum: dividendsReturnedOrder.OriginalOrderNum,
|
|
|
329
|
+ DividendsOrderNumber: "",
|
|
|
330
|
+ DividendsReturnedCustomerName: dividendsReturnedOrder.DividendsReturnedCustomerName,
|
|
|
331
|
+ DividendsReturnedDate: dividendsReturnedOrder.DividendsReturnedDate,
|
|
|
332
|
+ Region: &domain.RegionInfo{
|
|
|
333
|
+ RegionNumber: "",
|
|
|
334
|
+ RegionName: dividendsReturnedOrder.RegionName,
|
|
|
335
|
+ },
|
|
|
336
|
+ Goods: orderGoods,
|
|
|
337
|
+ Remarks: dividendsReturnedOrder.Remarks,
|
|
|
338
|
+ DividendStatus: domain.TO_BE_DIVIDENDED,
|
|
|
339
|
+ DividendTime: time.Time{},
|
|
|
340
|
+ Org: organization,
|
|
|
341
|
+ Company: company,
|
|
|
342
|
+ CreatedAt: time.Now(),
|
|
|
343
|
+ UpdatedAt: time.Time{},
|
|
|
344
|
+ Operator: operator,
|
|
|
345
|
+ OperateTime: time.Now(),
|
|
|
346
|
+ }
|
|
|
347
|
+
|
|
|
348
|
+ if dividendsReturnedOrderSaved, err := dividendsReturnedOrderRepository.Save(newDividendsReturnedOrder); err != nil {
|
|
|
349
|
+ dividendsReturnedOrderImportFailed = append(dividendsReturnedOrderImportFailed, newDividendsReturnedOrder)
|
|
|
350
|
+ } else {
|
|
|
351
|
+ dividendsReturnedOrderImportSuccessfully = append(dividendsReturnedOrderImportSuccessfully, dividendsReturnedOrderSaved)
|
|
|
352
|
+ }
|
|
|
353
|
+ }
|
|
|
354
|
+ if len(dividendsReturnedOrderImportFailed) == 0 {
|
225
|
if err := transactionContext.CommitTransaction(); err != nil {
|
355
|
if err := transactionContext.CommitTransaction(); err != nil {
|
226
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
356
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
227
|
}
|
357
|
}
|
|
|
358
|
+ return dividendsReturnedOrderImportSuccessfully, nil
|
|
|
359
|
+ }
|
228
|
return nil, nil
|
360
|
return nil, nil
|
229
|
}
|
361
|
}
|
230
|
|
362
|
|