作者 陈志颖

feat:增加共创项目批量结束服务

... ... @@ -13,6 +13,7 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/linmadan/egglib-go v0.0.0-20210527091316-06b0732fb5f6
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/moul/http2curl v1.0.0 // indirect
... ...
... ... @@ -138,6 +138,8 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
... ...
... ... @@ -11,6 +11,7 @@ import (
"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/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"strconv"
"time"
)
... ... @@ -529,42 +530,43 @@ func (cooperationProjectService *CooperationProjectService) BatchEndCooperationP
}()
// 共创项目仓储初始化
//var cooperationProjectRepository domain.CooperationProjectRepository
//if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cooperationProjectRepository = value
//}
var cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
// 转换共创项目ID列表类型
//cooperationProjectIds, err := utils.SliceAtoi(batchEndCooperationProjectCommand.CooperationProjectIds)
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": batchEndCooperationProjectCommand.CooperationProjectId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if cooperationProject == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(batchEndCooperationProjectCommand.CooperationProjectId)))
//}
//if err := cooperationProject.Update(tool_funs.SimpleStructToMap(batchEndCooperationProjectCommand)); err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
//
//if cooperationProject, err := cooperationProjectRepository.Save(cooperationProject); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return cooperationProject, nil
//}
return nil, nil
cooperationProjectIds, err := utils.SliceAtoi(batchEndCooperationProjectCommand.CooperationProjectIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count, cooperationProjects, err := cooperationProjectRepository.Find(map[string]interface{}{
"cooperationProjectIds": cooperationProjectIds,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for i, _ := range cooperationProjects {
cooperationProjects[i].Status = 2
}
cooperationProjectsEnded, err := cooperationProjectRepository.UpdateMany(cooperationProjects)
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 map[string]interface{}{
"cooperationProjects": cooperationProjectsEnded,
}, nil
} else {
return map[string]interface{}{}, nil
}
}
}
func NewCooperationProjectService(options map[string]interface{}) *CooperationProjectService {
... ...
... ... @@ -46,6 +46,7 @@ type CooperationProject struct {
type CooperationProjectRepository interface {
Save(cooperationProject *CooperationProject) (*CooperationProject, error)
UpdateMany(cooperationProjects []*CooperationProject) ([]*CooperationProject, error)
Remove(cooperationProject *CooperationProject) (*CooperationProject, error)
FindOne(queryOptions map[string]interface{}) (*CooperationProject, error)
Find(queryOptions map[string]interface{}) (int64, []*CooperationProject, error)
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -156,6 +157,38 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
return cooperationProject, nil
}
func (repository *CooperationProjectRepository) UpdateMany(cooperationProjects []*domain.CooperationProject) ([]*domain.CooperationProject, error) {
tx := repository.transactionContext.PgTx
var cooperationProjectModels []*models.CooperationProject
for _, cooperationProject := range cooperationProjects {
cooperationProjectModels = append(cooperationProjectModels, &models.CooperationProject{
CooperationProjectId: cooperationProject.CooperationProjectId,
CooperationProjectNumber: cooperationProject.CooperationProjectNumber,
CooperationProjectDescription: cooperationProject.CooperationProjectDescription,
CooperationProjectName: cooperationProject.CooperationProjectName,
CooperationProjectPublishTime: cooperationProject.CooperationProjectPublishTime,
CooperationProjectPublisher: cooperationProject.CooperationProjectPublisher,
CooperationProjectSponsor: cooperationProject.CooperationProjectSponsor,
CooperationModeNumber: cooperationProject.CooperationProjectNumber,
Department: cooperationProject.Department,
CooperationProjectUndertakerTypes: cooperationProject.CooperationProjectUndertakerTypes,
Attachment: cooperationProject.Attachment,
Org: cooperationProject.Org,
Company: cooperationProject.Company,
Operator: cooperationProject.Operator,
OperateTime: time.Now(),
Status: cooperationProject.Status,
UpdatedAt: time.Now(),
DeletedAt: cooperationProject.DeletedAt,
CreatedAt: cooperationProject.CreatedAt,
})
}
if _, err := tx.Model(&cooperationProjectModels).WherePK().Update(); err != nil {
return nil, err
}
return cooperationProjects, nil
}
func (repository *CooperationProjectRepository) Remove(cooperationProject *domain.CooperationProject) (*domain.CooperationProject, error) {
tx := repository.transactionContext.PgTx
cooperationProjectModel := new(models.CooperationProject)
... ...