正在显示
5 个修改的文件
包含
56 行增加
和
6 行删除
| @@ -10,7 +10,7 @@ import ( | @@ -10,7 +10,7 @@ import ( | ||
| 10 | 10 | ||
| 11 | type BatchOperateCooperationModeCommand struct { | 11 | type BatchOperateCooperationModeCommand struct { |
| 12 | // 共创模式ID | 12 | // 共创模式ID |
| 13 | - CooperationModeIds []string `cname:"共创模式id" json:"cooperationModeIds"` | 13 | + CooperationModeIds []string `cname:"共创模式ID列表" json:"cooperationModeIds"` |
| 14 | // 共创模式状态,1启用,2禁用 | 14 | // 共创模式状态,1启用,2禁用 |
| 15 | Status int32 `cname:"状态" json:"status" valid:"Required"` | 15 | Status int32 `cname:"状态" json:"status" valid:"Required"` |
| 16 | // 公司ID,通过集成REST上下文获取 | 16 | // 公司ID,通过集成REST上下文获取 |
| @@ -455,11 +455,29 @@ func (cooperationModeService *CooperationModeService) BatchOperateCooperationMod | @@ -455,11 +455,29 @@ func (cooperationModeService *CooperationModeService) BatchOperateCooperationMod | ||
| 455 | defer func() { | 455 | defer func() { |
| 456 | _ = transactionContext.RollbackTransaction() | 456 | _ = transactionContext.RollbackTransaction() |
| 457 | }() | 457 | }() |
| 458 | - | 458 | + // 共创模式DAO初始化 |
| 459 | + var cooperationModeDao *dao.CooperationModeDao | ||
| 460 | + if value, err := factory.CreateCooperationModeDao(map[string]interface{}{ | ||
| 461 | + "transactionContext": transactionContext, | ||
| 462 | + }); err != nil { | ||
| 463 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 464 | + } else { | ||
| 465 | + cooperationModeDao = value | ||
| 466 | + } | ||
| 467 | + if len(batchOperateCooperationModeCommand.CooperationModeIds) == 0 { | ||
| 468 | + return map[string]interface{}{}, nil | ||
| 469 | + } | ||
| 470 | + cooperationModeIds, _ := utils.SliceAtoi(batchOperateCooperationModeCommand.CooperationModeIds) | ||
| 471 | + if cooperationModes, err := cooperationModeDao.UpdateCooperationModeSlice(cooperationModeIds, batchOperateCooperationModeCommand.Status); err != nil { | ||
| 472 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 473 | + } else { | ||
| 459 | if err := transactionContext.CommitTransaction(); err != nil { | 474 | if err := transactionContext.CommitTransaction(); err != nil { |
| 460 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 475 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 461 | } | 476 | } |
| 462 | - return nil, nil | 477 | + return map[string]interface{}{ |
| 478 | + "cooperationModes": cooperationModes, | ||
| 479 | + }, nil | ||
| 480 | + } | ||
| 463 | } | 481 | } |
| 464 | 482 | ||
| 465 | func NewCooperationModeService(options map[string]interface{}) *CooperationModeService { | 483 | func NewCooperationModeService(options map[string]interface{}) *CooperationModeService { |
| @@ -55,8 +55,5 @@ func (cooperationMode *CooperationMode) Update(data map[string]interface{}) erro | @@ -55,8 +55,5 @@ func (cooperationMode *CooperationMode) Update(data map[string]interface{}) erro | ||
| 55 | if remarks, ok := data["remarks"]; ok { | 55 | if remarks, ok := data["remarks"]; ok { |
| 56 | cooperationMode.Remarks = remarks.(string) | 56 | cooperationMode.Remarks = remarks.(string) |
| 57 | } | 57 | } |
| 58 | - if userId, ok := data["userId"]; ok { | ||
| 59 | - cooperationMode.Operator.UserId = userId.(int64) | ||
| 60 | - } | ||
| 61 | return nil | 58 | return nil |
| 62 | } | 59 | } |
| @@ -2,8 +2,11 @@ package dao | @@ -2,8 +2,11 @@ package dao | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "github.com/go-pg/pg/v10" | ||
| 5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" |
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" | ||
| 7 | ) | 10 | ) |
| 8 | 11 | ||
| 9 | type CooperationModeDao struct { | 12 | type CooperationModeDao struct { |
| @@ -46,6 +49,36 @@ func (dao *CooperationModeDao) CheckModeNumberAvailable(queryOptions map[string] | @@ -46,6 +49,36 @@ func (dao *CooperationModeDao) CheckModeNumberAvailable(queryOptions map[string] | ||
| 46 | return !ok, err | 49 | return !ok, err |
| 47 | } | 50 | } |
| 48 | 51 | ||
| 52 | +// UpdateCooperationModeSlice 更新多个共创模式 | ||
| 53 | +func (dao *CooperationModeDao) UpdateCooperationModeSlice(modeIds []int64, status int32) ([]*domain.CooperationMode, error) { | ||
| 54 | + tx := dao.transactionContext.PgTx | ||
| 55 | + _, err := tx.QueryOne( | ||
| 56 | + pg.Scan(), | ||
| 57 | + "UPDATE cooperation_modes SET status=? WHERE cooperation_mode_id IN (?)", | ||
| 58 | + status, pg.In(modeIds)) | ||
| 59 | + if err != nil { | ||
| 60 | + return nil, err | ||
| 61 | + } else { | ||
| 62 | + var cooperationModeModels []*models.CooperationMode | ||
| 63 | + cooperationModes := make([]*domain.CooperationMode, 0) | ||
| 64 | + query := tx.Model(&cooperationModeModels) | ||
| 65 | + query.Where("cooperation_mode_id IN (?)", pg.In(modeIds)) | ||
| 66 | + query.Order("cooperation_mode_id DESC") | ||
| 67 | + if _, err := query.SelectAndCount(); err != nil { | ||
| 68 | + return cooperationModes, err | ||
| 69 | + } else { | ||
| 70 | + for _, cooperationModeModel := range cooperationModeModels { | ||
| 71 | + if cooperationMode, err := transform.TransformToCooperationModeDomainModelFromPgModels(cooperationModeModel); err != nil { | ||
| 72 | + return cooperationModes, err | ||
| 73 | + } else { | ||
| 74 | + cooperationModes = append(cooperationModes, cooperationMode) | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + return cooperationModes, nil | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | +} | ||
| 81 | + | ||
| 49 | func NewCooperationModeDao(transactionContext *pgTransaction.TransactionContext) (*CooperationModeDao, error) { | 82 | func NewCooperationModeDao(transactionContext *pgTransaction.TransactionContext) (*CooperationModeDao, error) { |
| 50 | if transactionContext == nil { | 83 | if transactionContext == nil { |
| 51 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 84 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
| @@ -109,6 +109,7 @@ func (controller *CooperationModeController) ListCooperationMode() { | @@ -109,6 +109,7 @@ func (controller *CooperationModeController) ListCooperationMode() { | ||
| 109 | controller.Response(data, err) | 109 | controller.Response(data, err) |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | +// OperateCooperationMode 启用或禁用共创模式 | ||
| 112 | func (controller *CooperationModeController) OperateCooperationMode() { | 113 | func (controller *CooperationModeController) OperateCooperationMode() { |
| 113 | cooperationModeService := service.NewCooperationModeService(nil) | 114 | cooperationModeService := service.NewCooperationModeService(nil) |
| 114 | operateCooperationModeCommand := &command.OperateCooperationModeCommand{} | 115 | operateCooperationModeCommand := &command.OperateCooperationModeCommand{} |
| @@ -122,6 +123,7 @@ func (controller *CooperationModeController) OperateCooperationMode() { | @@ -122,6 +123,7 @@ func (controller *CooperationModeController) OperateCooperationMode() { | ||
| 122 | controller.Response(data, err) | 123 | controller.Response(data, err) |
| 123 | } | 124 | } |
| 124 | 125 | ||
| 126 | +// BatchOperateCooperationMode 批量启用或禁用共创模式 | ||
| 125 | func (controller *CooperationModeController) BatchOperateCooperationMode() { | 127 | func (controller *CooperationModeController) BatchOperateCooperationMode() { |
| 126 | cooperationModeService := service.NewCooperationModeService(nil) | 128 | cooperationModeService := service.NewCooperationModeService(nil) |
| 127 | batchOperateCooperationModeCommand := &command.BatchOperateCooperationModeCommand{} | 129 | batchOperateCooperationModeCommand := &command.BatchOperateCooperationModeCommand{} |
-
请 注册 或 登录 后发表评论