作者 陈志颖

feat:共创申请增加批量审核

... ... @@ -10,6 +10,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"strconv"
"time"
)
... ... @@ -152,6 +153,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApprovalCoop
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 共创申请仓储初始化
var cooperationApplicationRepository domain.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -164,6 +166,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApprovalCoop
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请ID类型错误")
}
// 获取共创申请
cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": approvalCooperationApplicationCommand.CooperationApplicationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -199,10 +202,45 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// 共创申请仓储初始化
var cooperationApplicationRepository domain.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationApplicationRepository = value
}
cooperationApplicationIds, err := utils.SliceAtoi(batchApprovalCooperationApplicationCommand.CooperationApplicationIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请ID列表类型错误")
}
if count, cooperationApplications, err := cooperationApplicationRepository.Find(map[string]interface{}{
"cooperationApplicationIds": cooperationApplicationIds,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for i, _ := range cooperationApplications {
cooperationApplications[i].CooperationApplicationDescription = batchApprovalCooperationApplicationCommand.CooperationApplicationVerifyDescription
if batchApprovalCooperationApplicationCommand.Action == 1 { // 同意
cooperationApplications[i].CooperationApplicationStatus = 2
} else if batchApprovalCooperationApplicationCommand.Action == 2 { // 拒绝
cooperationApplications[i].CooperationApplicationStatus = 3
}
}
cooperationApplicationsApproved, err := cooperationApplicationRepository.UpdateMany(cooperationApplications)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationApplicationsApproved, nil
} else {
return map[string]interface{}{}, nil
}
}
return nil, nil
}
// OneClickApprovalCooperationApplication 一键审核共创申请
... ... @@ -256,8 +294,6 @@ func (cooperationApplicationService *CooperationApplicationService) CreateCooper
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationApplicationCommand.CooperationProjectNumber))
} else {
}
// 用户REST服务初始化
... ... @@ -534,7 +570,7 @@ func (cooperationApplicationService *CooperationApplicationService) UpdateCooper
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationApplication == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationApplicationCommand.CooperationApplicationId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateCooperationApplicationCommand.CooperationApplicationId, 10)))
}
if err := cooperationApplication.Update(tool_funs.SimpleStructToMap(updateCooperationApplicationCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -226,6 +226,9 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
if cooperationApplicationStatus, ok := queryOptions["cooperationApplicationStatus"]; ok && cooperationApplicationStatus.(int32) != 0 {
query.Where("cooperation_application_status = ?", cooperationApplicationStatus)
}
if cooperationApplicationIds, ok := queryOptions["cooperationApplicationIds"]; ok && len(cooperationApplicationIds.([]int64)) > 0 {
query.Where("cooperation_application_id IN (?)", pg.In(cooperationApplicationIds))
}
offsetLimitFlag := true
if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
offsetLimitFlag = offsetLimit.(bool)
... ...