作者 陈志颖

feat:增加共创模式批量操作

... ... @@ -10,7 +10,7 @@ import (
type BatchOperateCooperationModeCommand struct {
// 共创模式ID
CooperationModeIds []string `cname:"共创模式id" json:"cooperationModeIds"`
CooperationModeIds []string `cname:"共创模式ID列表" json:"cooperationModeIds"`
// 共创模式状态,1启用,2禁用
Status int32 `cname:"状态" json:"status" valid:"Required"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -455,11 +455,29 @@ func (cooperationModeService *CooperationModeService) BatchOperateCooperationMod
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
// 共创模式DAO初始化
var cooperationModeDao *dao.CooperationModeDao
if value, err := factory.CreateCooperationModeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationModeDao = value
}
if len(batchOperateCooperationModeCommand.CooperationModeIds) == 0 {
return map[string]interface{}{}, nil
}
cooperationModeIds, _ := utils.SliceAtoi(batchOperateCooperationModeCommand.CooperationModeIds)
if cooperationModes, err := cooperationModeDao.UpdateCooperationModeSlice(cooperationModeIds, batchOperateCooperationModeCommand.Status); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"cooperationModes": cooperationModes,
}, nil
}
return nil, nil
}
func NewCooperationModeService(options map[string]interface{}) *CooperationModeService {
... ...
... ... @@ -55,8 +55,5 @@ func (cooperationMode *CooperationMode) Update(data map[string]interface{}) erro
if remarks, ok := data["remarks"]; ok {
cooperationMode.Remarks = remarks.(string)
}
if userId, ok := data["userId"]; ok {
cooperationMode.Operator.UserId = userId.(int64)
}
return nil
}
... ...
... ... @@ -2,8 +2,11 @@ package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
)
type CooperationModeDao struct {
... ... @@ -46,6 +49,36 @@ func (dao *CooperationModeDao) CheckModeNumberAvailable(queryOptions map[string]
return !ok, err
}
// UpdateCooperationModeSlice 更新多个共创模式
func (dao *CooperationModeDao) UpdateCooperationModeSlice(modeIds []int64, status int32) ([]*domain.CooperationMode, error) {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"UPDATE cooperation_modes SET status=? WHERE cooperation_mode_id IN (?)",
status, pg.In(modeIds))
if err != nil {
return nil, err
} else {
var cooperationModeModels []*models.CooperationMode
cooperationModes := make([]*domain.CooperationMode, 0)
query := tx.Model(&cooperationModeModels)
query.Where("cooperation_mode_id IN (?)", pg.In(modeIds))
query.Order("cooperation_mode_id DESC")
if _, err := query.SelectAndCount(); err != nil {
return cooperationModes, err
} else {
for _, cooperationModeModel := range cooperationModeModels {
if cooperationMode, err := transform.TransformToCooperationModeDomainModelFromPgModels(cooperationModeModel); err != nil {
return cooperationModes, err
} else {
cooperationModes = append(cooperationModes, cooperationMode)
}
}
return cooperationModes, nil
}
}
}
func NewCooperationModeDao(transactionContext *pgTransaction.TransactionContext) (*CooperationModeDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -109,6 +109,7 @@ func (controller *CooperationModeController) ListCooperationMode() {
controller.Response(data, err)
}
// OperateCooperationMode 启用或禁用共创模式
func (controller *CooperationModeController) OperateCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
operateCooperationModeCommand := &command.OperateCooperationModeCommand{}
... ... @@ -122,6 +123,7 @@ func (controller *CooperationModeController) OperateCooperationMode() {
controller.Response(data, err)
}
// BatchOperateCooperationMode 批量启用或禁用共创模式
func (controller *CooperationModeController) BatchOperateCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
batchOperateCooperationModeCommand := &command.BatchOperateCooperationModeCommand{}
... ...