作者 陈志颖

feat:批量操作共创模式应用服务修改

... ... @@ -24,7 +24,7 @@ type BatchOperateCooperationModeCommand struct {
}
func (batchOperateCooperationModeCommand *BatchOperateCooperationModeCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchOperateCooperationModeCommand *BatchOperateCooperationModeCommand) ValidateCommand() error {
... ...
... ... @@ -10,7 +10,7 @@ import (
type BatchRemoveCooperationModeCommand struct {
// 共创模式ID数组
CooperationModeIds []string `cname:"共创模式ID数组" json:"cooperationModeIds,string" valid:"Required"`
CooperationModeIds []string `cname:"共创模式ID数组" json:"cooperationModeIds,string"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId,string" valid:"Required"`
// 组织机构ID
... ... @@ -22,7 +22,19 @@ type BatchRemoveCooperationModeCommand struct {
}
func (batchRemoveCooperationModeCommand *BatchRemoveCooperationModeCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
if len(batchRemoveCooperationModeCommand.CooperationModeIds) > 0 {
for _, cooperationModeId := range batchRemoveCooperationModeCommand.CooperationModeIds {
switch v := reflect.ValueOf(cooperationModeId); v.Kind() {
case reflect.String:
fmt.Println(v.String())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
fmt.Println(v.Int())
_ = validation.SetError("CustomValid", "共创模式ID类型错误")
default:
fmt.Printf("unhandled kind %s", v.Kind())
}
}
}
}
func (batchRemoveCooperationModeCommand *BatchRemoveCooperationModeCommand) ValidateCommand() error {
... ...
... ... @@ -464,10 +464,13 @@ func (cooperationModeService *CooperationModeService) BatchOperateCooperationMod
} else {
cooperationModeDao = value
}
if len(batchOperateCooperationModeCommand.CooperationModeIds) == 0 {
if len(batchOperateCooperationModeCommand.CooperationModeIds) <= 0 {
return map[string]interface{}{}, nil
}
cooperationModeIds, _ := utils.SliceAtoi(batchOperateCooperationModeCommand.CooperationModeIds)
cooperationModeIds, err := utils.SliceAtoi(batchOperateCooperationModeCommand.CooperationModeIds)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "共创模式ID错误")
}
if cooperationModes, err := cooperationModeDao.UpdateCooperationModeSlice(cooperationModeIds, batchOperateCooperationModeCommand.Status); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
... ...
... ... @@ -36,6 +36,7 @@ type CooperationModeRepository interface {
BatchRemove(cooperationModes []*CooperationMode) ([]*CooperationMode, error)
FindOne(queryOptions map[string]interface{}) (*CooperationMode, error)
Find(queryOptions map[string]interface{}) (int64, []*CooperationMode, error)
FindAll(queryOptions map[string]interface{}) (int64, []*CooperationMode, error)
}
func (cooperationMode *CooperationMode) Identify() interface{} {
... ...
... ... @@ -191,6 +191,32 @@ func (repository *CooperationModeRepository) Find(queryOptions map[string]interf
}
}
func (repository *CooperationModeRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.CooperationMode, error) {
tx := repository.transactionContext.PgTx
var cooperationModeModels []*models.CooperationMode
cooperationModes := make([]*domain.CooperationMode, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationModeModels), queryOptions)
if cooperationModeName, ok := queryOptions["cooperationModeName"]; ok && cooperationModeName != "" {
query.Where("cooperation_mode_name like ?", fmt.Sprintf("%%%s%%", cooperationModeName))
}
if organizationName, ok := queryOptions["organizationName"]; ok && organizationName != "" {
query.Where("org->>'orgName' like ?", fmt.Sprintf("%%%s%%", organizationName))
}
query.SetOrderDirect("cooperation_mode_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationModes, err
} else {
for _, cooperationModeModel := range cooperationModeModels {
if cooperationMode, err := transform.TransformToCooperationModeDomainModelFromPgModels(cooperationModeModel); err != nil {
return 0, cooperationModes, err
} else {
cooperationModes = append(cooperationModes, cooperationMode)
}
}
return int64(count), cooperationModes, nil
}
}
func NewCooperationModeRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationModeRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...