正在显示
3 个修改的文件
包含
103 行增加
和
0 行删除
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/beego/beego/v2/core/validation" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | +) | ||
9 | + | ||
10 | +type BatchRemoveDividendsOrderCommand struct { | ||
11 | + // 分红订单ID列表 | ||
12 | + DividendsOrderIds []string `cname:"分红订单ID列表" json:"dividendsOrderIds,omitempty"` | ||
13 | + // 公司ID,通过集成REST上下文获取 | ||
14 | + CompanyId int64 `cname:"公司ID" json:"companyId,string" valid:"Required"` | ||
15 | + // 组织机构ID | ||
16 | + OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"` | ||
17 | + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 | ||
18 | + UserId int64 `cname:"用户ID" json:"userId,string" valid:"Required"` | ||
19 | + // 用户基础数据id | ||
20 | + UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId,string" valid:"Required"` | ||
21 | +} | ||
22 | + | ||
23 | +func (batchRemoveDividendsOrderCommand *BatchRemoveDividendsOrderCommand) Valid(validation *validation.Validation) { | ||
24 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
25 | +} | ||
26 | + | ||
27 | +func (batchRemoveDividendsOrderCommand *BatchRemoveDividendsOrderCommand) ValidateCommand() error { | ||
28 | + valid := validation.Validation{} | ||
29 | + b, err := valid.Valid(batchRemoveDividendsOrderCommand) | ||
30 | + if err != nil { | ||
31 | + return err | ||
32 | + } | ||
33 | + if !b { | ||
34 | + elem := reflect.TypeOf(batchRemoveDividendsOrderCommand).Elem() | ||
35 | + for _, validErr := range valid.Errors { | ||
36 | + field, isExist := elem.FieldByName(validErr.Field) | ||
37 | + if isExist { | ||
38 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
39 | + } else { | ||
40 | + return fmt.Errorf(validErr.Message) | ||
41 | + } | ||
42 | + } | ||
43 | + } | ||
44 | + return nil | ||
45 | +} |
@@ -307,6 +307,51 @@ func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeD | @@ -307,6 +307,51 @@ func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeD | ||
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | +// BatchRemoveDividendsOrder 批量移除分红订单实体对象 | ||
311 | +func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(batchRemoveDividendsOrderCommand *command.BatchRemoveDividendsOrderCommand) (interface{}, error) { | ||
312 | + if err := batchRemoveDividendsOrderCommand.ValidateCommand(); err != nil { | ||
313 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
314 | + } | ||
315 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
316 | + if err != nil { | ||
317 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
318 | + } | ||
319 | + if err := transactionContext.StartTransaction(); err != nil { | ||
320 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
321 | + } | ||
322 | + defer func() { | ||
323 | + _ = transactionContext.RollbackTransaction() | ||
324 | + }() | ||
325 | + var dividendsOrderRepository domain.DividendsOrderRepository | ||
326 | + if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{ | ||
327 | + "transactionContext": transactionContext, | ||
328 | + }); err != nil { | ||
329 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
330 | + } else { | ||
331 | + dividendsOrderRepository = value | ||
332 | + } | ||
333 | + | ||
334 | + dividendsOrderIds, _ := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds) | ||
335 | + if count, dividendsOrders, err := dividendsOrderRepository.Find(map[string]interface{}{ | ||
336 | + "dividendsOrderIds": dividendsOrderIds, | ||
337 | + }); err != nil { | ||
338 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
339 | + } else { | ||
340 | + if count > 0 { | ||
341 | + dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders) | ||
342 | + if err != nil { | ||
343 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
344 | + } | ||
345 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
346 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
347 | + } | ||
348 | + return dividendsOrdersRemoved, nil | ||
349 | + } else { | ||
350 | + return map[string]interface{}{}, nil | ||
351 | + } | ||
352 | + } | ||
353 | +} | ||
354 | + | ||
310 | // SearchDividendsOrder 查询分红订单方法 | 355 | // SearchDividendsOrder 查询分红订单方法 |
311 | func (dividendsOrderService *DividendsOrderService) SearchDividendsOrder(searchDividendsOrderQuery *query.SearchDividendsOrderQuery) (interface{}, error) { | 356 | func (dividendsOrderService *DividendsOrderService) SearchDividendsOrder(searchDividendsOrderQuery *query.SearchDividendsOrderQuery) (interface{}, error) { |
312 | if err := searchDividendsOrderQuery.ValidateQuery(); err != nil { | 357 | if err := searchDividendsOrderQuery.ValidateQuery(); err != nil { |
@@ -67,6 +67,19 @@ func (controller *DividendsOrderController) RemoveDividendsOrder() { | @@ -67,6 +67,19 @@ func (controller *DividendsOrderController) RemoveDividendsOrder() { | ||
67 | controller.Response(data, err) | 67 | controller.Response(data, err) |
68 | } | 68 | } |
69 | 69 | ||
70 | +func (controller *DividendsOrderController) BatchRemoveDividendsOrder() { | ||
71 | + dividendsOrderService := service.NewDividendsOrderService(nil) | ||
72 | + batchRemoveDividendsOrderCommand := &command.BatchRemoveDividendsOrderCommand{} | ||
73 | + _ = controller.Unmarshal(batchRemoveDividendsOrderCommand) | ||
74 | + header := controller.GetRequestHeader(controller.Ctx) | ||
75 | + batchRemoveDividendsOrderCommand.CompanyId = header.CompanyId | ||
76 | + batchRemoveDividendsOrderCommand.OrgId = header.OrgId | ||
77 | + batchRemoveDividendsOrderCommand.UserId = header.UserId | ||
78 | + batchRemoveDividendsOrderCommand.UserBaseId = header.UserBaseId | ||
79 | + data, err := dividendsOrderService.BatchRemoveDividendsOrder(batchRemoveDividendsOrderCommand) | ||
80 | + controller.Response(data, err) | ||
81 | +} | ||
82 | + | ||
70 | func (controller *DividendsOrderController) SearchDividendsOrder() { | 83 | func (controller *DividendsOrderController) SearchDividendsOrder() { |
71 | dividendsOrderService := service.NewDividendsOrderService(nil) | 84 | dividendsOrderService := service.NewDividendsOrderService(nil) |
72 | searchDividendsOrderQuery := &query.SearchDividendsOrderQuery{} | 85 | searchDividendsOrderQuery := &query.SearchDividendsOrderQuery{} |
-
请 注册 或 登录 后发表评论