作者 陈志颖

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

@@ -13,6 +13,7 @@ require ( @@ -13,6 +13,7 @@ require (
13 github.com/google/go-querystring v1.1.0 // indirect 13 github.com/google/go-querystring v1.1.0 // indirect
14 github.com/gorilla/websocket v1.4.2 // indirect 14 github.com/gorilla/websocket v1.4.2 // indirect
15 github.com/imkira/go-interpol v1.1.0 // indirect 15 github.com/imkira/go-interpol v1.1.0 // indirect
  16 + github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
16 github.com/linmadan/egglib-go v0.0.0-20210527091316-06b0732fb5f6 17 github.com/linmadan/egglib-go v0.0.0-20210527091316-06b0732fb5f6
17 github.com/mattn/go-colorable v0.1.8 // indirect 18 github.com/mattn/go-colorable v0.1.8 // indirect
18 github.com/moul/http2curl v1.0.0 // indirect 19 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/ @@ -138,6 +138,8 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
138 github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= 138 github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
139 github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= 139 github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
140 github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 140 github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
  141 +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM=
  142 +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
141 github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= 143 github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
142 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 144 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
143 github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= 145 github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
@@ -11,6 +11,7 @@ import ( @@ -11,6 +11,7 @@ import (
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
  14 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
14 "strconv" 15 "strconv"
15 "time" 16 "time"
16 ) 17 )
@@ -529,42 +530,43 @@ func (cooperationProjectService *CooperationProjectService) BatchEndCooperationP @@ -529,42 +530,43 @@ func (cooperationProjectService *CooperationProjectService) BatchEndCooperationP
529 }() 530 }()
530 531
531 // 共创项目仓储初始化 532 // 共创项目仓储初始化
532 - //var cooperationProjectRepository domain.CooperationProjectRepository  
533 - //if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{  
534 - // "transactionContext": transactionContext,  
535 - //}); err != nil {  
536 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
537 - //} else {  
538 - // cooperationProjectRepository = value  
539 - //} 533 + var cooperationProjectRepository domain.CooperationProjectRepository
  534 + if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
  535 + "transactionContext": transactionContext,
  536 + }); err != nil {
  537 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  538 + } else {
  539 + cooperationProjectRepository = value
  540 + }
540 541
541 // 转换共创项目ID列表类型 542 // 转换共创项目ID列表类型
542 - //cooperationProjectIds, err := utils.SliceAtoi(batchEndCooperationProjectCommand.CooperationProjectIds)  
543 - //if err != nil {  
544 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
545 - //}  
546 -  
547 - //cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": batchEndCooperationProjectCommand.CooperationProjectId})  
548 - //if err != nil {  
549 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
550 - //}  
551 - //if cooperationProject == nil {  
552 - // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(batchEndCooperationProjectCommand.CooperationProjectId)))  
553 - //}  
554 -  
555 - //if err := cooperationProject.Update(tool_funs.SimpleStructToMap(batchEndCooperationProjectCommand)); err != nil {  
556 - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
557 - //}  
558 - //  
559 - //if cooperationProject, err := cooperationProjectRepository.Save(cooperationProject); err != nil {  
560 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
561 - //} else {  
562 - // if err := transactionContext.CommitTransaction(); err != nil {  
563 - // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
564 - // }  
565 - // return cooperationProject, nil  
566 - //}  
567 - return nil, nil 543 + cooperationProjectIds, err := utils.SliceAtoi(batchEndCooperationProjectCommand.CooperationProjectIds)
  544 + if err != nil {
  545 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  546 + }
  547 + if count, cooperationProjects, err := cooperationProjectRepository.Find(map[string]interface{}{
  548 + "cooperationProjectIds": cooperationProjectIds,
  549 + }); err != nil {
  550 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  551 + } else {
  552 + if count > 0 {
  553 + for i, _ := range cooperationProjects {
  554 + cooperationProjects[i].Status = 2
  555 + }
  556 + cooperationProjectsEnded, err := cooperationProjectRepository.UpdateMany(cooperationProjects)
  557 + if err != nil {
  558 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  559 + }
  560 + if err := transactionContext.CommitTransaction(); err != nil {
  561 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  562 + }
  563 + return map[string]interface{}{
  564 + "cooperationProjects": cooperationProjectsEnded,
  565 + }, nil
  566 + } else {
  567 + return map[string]interface{}{}, nil
  568 + }
  569 + }
568 } 570 }
569 571
570 func NewCooperationProjectService(options map[string]interface{}) *CooperationProjectService { 572 func NewCooperationProjectService(options map[string]interface{}) *CooperationProjectService {
@@ -46,6 +46,7 @@ type CooperationProject struct { @@ -46,6 +46,7 @@ type CooperationProject struct {
46 46
47 type CooperationProjectRepository interface { 47 type CooperationProjectRepository interface {
48 Save(cooperationProject *CooperationProject) (*CooperationProject, error) 48 Save(cooperationProject *CooperationProject) (*CooperationProject, error)
  49 + UpdateMany(cooperationProjects []*CooperationProject) ([]*CooperationProject, error)
49 Remove(cooperationProject *CooperationProject) (*CooperationProject, error) 50 Remove(cooperationProject *CooperationProject) (*CooperationProject, error)
50 FindOne(queryOptions map[string]interface{}) (*CooperationProject, error) 51 FindOne(queryOptions map[string]interface{}) (*CooperationProject, error)
51 Find(queryOptions map[string]interface{}) (int64, []*CooperationProject, error) 52 Find(queryOptions map[string]interface{}) (int64, []*CooperationProject, error)
@@ -3,6 +3,7 @@ package repository @@ -3,6 +3,7 @@ package repository
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg/v10" 5 "github.com/go-pg/pg/v10"
  6 + "time"
6 7
7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 8 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 9 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -156,6 +157,38 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain. @@ -156,6 +157,38 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
156 return cooperationProject, nil 157 return cooperationProject, nil
157 } 158 }
158 159
  160 +func (repository *CooperationProjectRepository) UpdateMany(cooperationProjects []*domain.CooperationProject) ([]*domain.CooperationProject, error) {
  161 + tx := repository.transactionContext.PgTx
  162 + var cooperationProjectModels []*models.CooperationProject
  163 + for _, cooperationProject := range cooperationProjects {
  164 + cooperationProjectModels = append(cooperationProjectModels, &models.CooperationProject{
  165 + CooperationProjectId: cooperationProject.CooperationProjectId,
  166 + CooperationProjectNumber: cooperationProject.CooperationProjectNumber,
  167 + CooperationProjectDescription: cooperationProject.CooperationProjectDescription,
  168 + CooperationProjectName: cooperationProject.CooperationProjectName,
  169 + CooperationProjectPublishTime: cooperationProject.CooperationProjectPublishTime,
  170 + CooperationProjectPublisher: cooperationProject.CooperationProjectPublisher,
  171 + CooperationProjectSponsor: cooperationProject.CooperationProjectSponsor,
  172 + CooperationModeNumber: cooperationProject.CooperationProjectNumber,
  173 + Department: cooperationProject.Department,
  174 + CooperationProjectUndertakerTypes: cooperationProject.CooperationProjectUndertakerTypes,
  175 + Attachment: cooperationProject.Attachment,
  176 + Org: cooperationProject.Org,
  177 + Company: cooperationProject.Company,
  178 + Operator: cooperationProject.Operator,
  179 + OperateTime: time.Now(),
  180 + Status: cooperationProject.Status,
  181 + UpdatedAt: time.Now(),
  182 + DeletedAt: cooperationProject.DeletedAt,
  183 + CreatedAt: cooperationProject.CreatedAt,
  184 + })
  185 + }
  186 + if _, err := tx.Model(&cooperationProjectModels).WherePK().Update(); err != nil {
  187 + return nil, err
  188 + }
  189 + return cooperationProjects, nil
  190 +}
  191 +
159 func (repository *CooperationProjectRepository) Remove(cooperationProject *domain.CooperationProject) (*domain.CooperationProject, error) { 192 func (repository *CooperationProjectRepository) Remove(cooperationProject *domain.CooperationProject) (*domain.CooperationProject, error) {
160 tx := repository.transactionContext.PgTx 193 tx := repository.transactionContext.PgTx
161 cooperationProjectModel := new(models.CooperationProject) 194 cooperationProjectModel := new(models.CooperationProject)