作者 陈志颖

feat:增加共创结束和批量结束功能

... ... @@ -19,6 +19,8 @@ type EndCooperationProjectCommand struct {
UserId int64 `cname:"用户ID" json:"userId" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId" valid:"Required"`
// 状态
Status int32 `cname:"状态" json:"status"`
}
func (endCooperationProjectCommand *EndCooperationProjectCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -463,6 +463,110 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
}
}
// EndCooperationProject 结束共创项目
func (cooperationProjectService *CooperationProjectService) EndCooperationProject(updateCooperationProjectCommand *command.EndCooperationProjectCommand) (interface{}, error) {
if err := updateCooperationProjectCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
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
}
cooperationProjectId, err := strconv.ParseInt(updateCooperationProjectCommand.CooperationProjectId, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": 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", updateCooperationProjectCommand.CooperationProjectId))
}
// 设置结束状态
updateCooperationProjectCommand.Status = 2
if err := cooperationProject.Update(tool_funs.SimpleStructToMap(updateCooperationProjectCommand)); 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
}
}
// BatchEndCooperationProject 批量结束共创项目
func (cooperationProjectService *CooperationProjectService) BatchEndCooperationProject(batchEndCooperationProjectCommand *command.BatchEndCooperationProjectCommand) (interface{}, error) {
if err := batchEndCooperationProjectCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 共创项目仓储初始化
//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
}
func NewCooperationProjectService(options map[string]interface{}) *CooperationProjectService {
newCooperationProjectService := &CooperationProjectService{}
return newCooperationProjectService
... ...
... ... @@ -574,6 +574,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
log.Logger.Info("新增的分红预算单", map[string]interface{}{
"dividendsEstimates": dividendsEstimates,
})
// 创建成功的分红预算单
var dividendsEstimatesSavedSuccessfully []*domain.DividendsEstimate
// 创建失败的分红预算单
var dividendsEstimateSaveFailed []*domain.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
dividendsEstimateSaveFailed = append(dividendsEstimateSaveFailed, dividendsEstimate)
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else if dividendsEstimateSaved != nil {
dividendsEstimatesSavedSuccessfully = append(dividendsEstimatesSavedSuccessfully, dividendsEstimate)
}
}
dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -581,6 +595,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 分析成功和失败原因
return dividendsEstimatesSaved, nil
}
}
... ...
... ... @@ -27,7 +27,7 @@ type OrderGood struct {
// 订单产品支出费用
OrderGoodExpense float64 `comment:"订单产品支出费用"`
// 订单产品分红状态, 1待分红,2已分红
OrderGoodDividendsStatus int32 `comment:"订单产品分红状态"`
OrderGoodDividendsStatus int32 `comment:"订单产品分红状态" pg:",default:1"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 删除时间
... ...
... ... @@ -56,12 +56,12 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if dividendsEstimate.Identify() == nil {
dividendsEstimateId, err := repository.nextIdentify()
if err != nil {
return dividendsEstimate, err
} else {
dividendsEstimate.DividendsEstimateId = dividendsEstimateId
}
//dividendsEstimateId, err := repository.nextIdentify()
//if err != nil {
// return dividendsEstimate, err
//} else {
// dividendsEstimate.DividendsEstimateId = dividendsEstimateId
//}
if _, err := tx.QueryOne(
pg.Scan(
&dividendsEstimate.DividendsEstimateId,
... ...
... ... @@ -83,7 +83,7 @@ func (controller *CooperationProjectController) RemoveCooperationProject() {
func (controller *CooperationProjectController) SearchCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
searchCooperationProjectQuery := &query.SearchCooperationProjectQuery{}
controller.Unmarshal(searchCooperationProjectQuery)
_ = controller.Unmarshal(searchCooperationProjectQuery)
header := controller.GetRequestHeader(controller.Ctx)
searchCooperationProjectQuery.CompanyId = header.CompanyId
searchCooperationProjectQuery.OrgId = header.OrgId
... ... @@ -120,3 +120,29 @@ func (controller *CooperationProjectController) ListCooperationProject() {
data, err := cooperationProjectService.ListCooperationProject(listCooperationProjectQuery)
controller.Response(data, err)
}
func (controller *CooperationProjectController) EndCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
endCooperationProjectCommand := &command.EndCooperationProjectCommand{}
_ = controller.Unmarshal(endCooperationProjectCommand)
header := controller.GetRequestHeader(controller.Ctx)
endCooperationProjectCommand.CompanyId = header.CompanyId
endCooperationProjectCommand.OrgId = header.OrgId
endCooperationProjectCommand.UserId = header.UserId
endCooperationProjectCommand.UserBaseId = header.UserBaseId
data, err := cooperationProjectService.EndCooperationProject(endCooperationProjectCommand)
controller.Response(data, err)
}
func (controller *CooperationProjectController) BatchEndCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
batchEndCooperationProjectCommand := &command.BatchEndCooperationProjectCommand{}
_ = controller.Unmarshal(batchEndCooperationProjectCommand)
header := controller.GetRequestHeader(controller.Ctx)
batchEndCooperationProjectCommand.CompanyId = header.CompanyId
batchEndCooperationProjectCommand.OrgId = header.OrgId
batchEndCooperationProjectCommand.UserId = header.UserId
batchEndCooperationProjectCommand.UserBaseId = header.UserBaseId
data, err := cooperationProjectService.BatchEndCooperationProject(batchEndCooperationProjectCommand)
controller.Response(data, err)
}
... ...
... ... @@ -6,12 +6,14 @@ import (
)
func init() {
web.Router("/cooperation-projects/release-cooperation-project", &controllers.CooperationProjectController{}, "Post:ReleaseCooperationProject")
web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Post:CreateCooperationProject")
web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Put:UpdateCooperationProject")
web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Get:GetCooperationProject")
web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Delete:RemoveCooperationProject")
web.Router("/cooperation-projects/search", &controllers.CooperationProjectController{}, "Post:SearchCooperationProject")
web.Router("/cooperation-projects/check", &controllers.CooperationProjectController{}, "Post:CheckUndertaker")
web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Get:ListCooperationProject")
web.Router("/cooperation-projects/release-cooperation-project", &controllers.CooperationProjectController{}, "Post:ReleaseCooperationProject") // 发布共创项目
web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Post:CreateCooperationProject") // 新增共创项目
web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Put:UpdateCooperationProject") // 编辑共创项目
web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Get:GetCooperationProject") // 获取共创项目详情
web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Delete:RemoveCooperationProject") // 移除共创项目
web.Router("/cooperation-projects/search", &controllers.CooperationProjectController{}, "Post:SearchCooperationProject") // 查找共创项目
web.Router("/cooperation-projects/check", &controllers.CooperationProjectController{}, "Post:CheckUndertaker") //
web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Get:ListCooperationProject") // 返回共创项目列表
web.Router("/cooperation-projects/end", &controllers.CooperationProjectController{}, "Post:EndCooperationProject") // 结束共创项目
web.Router("/cooperation-projects/batch-end", &controllers.CooperationProjectController{}, "Post:BatchEndCooperationProject") // 批量结束共创项目
}
... ...