|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/query"
|
|
|
"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"
|
|
|
)
|
|
|
|
|
|
// CooperationApplicationService 共创申请服务
|
|
|
type CooperationApplicationService struct {
|
|
|
}
|
|
|
|
|
|
// ApplyForCooperation 申请共创
|
|
|
func (cooperationApplicationService *CooperationApplicationService) ApplyForCooperation(applyForCooperationCommand *command.ApplyForCooperationCommand) (interface{}, error) {
|
|
|
if err := applyForCooperationCommand.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
|
|
|
}
|
|
|
|
|
|
// 获取共创项目
|
|
|
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": applyForCooperationCommand.CooperationProjectId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目不存在")
|
|
|
}
|
|
|
if cooperationProject == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(applyForCooperationCommand.CooperationProjectId, 10)))
|
|
|
}
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
// 获取申请人
|
|
|
var applicant *domain.User
|
|
|
if data, err := userService.UserFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
|
|
|
} else {
|
|
|
applicant = data
|
|
|
}
|
|
|
|
|
|
// 公司REST服务初始化
|
|
|
var companyService service.CompanyService
|
|
|
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
companyService = value
|
|
|
}
|
|
|
|
|
|
// 获取公司信息
|
|
|
var company *domain.Company
|
|
|
if data, err := companyService.CompanyFrom(applyForCooperationCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")
|
|
|
} else {
|
|
|
company = data
|
|
|
}
|
|
|
|
|
|
// 组织机构REST服务初始化
|
|
|
var organizationService service.OrgService
|
|
|
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organizationService = value
|
|
|
}
|
|
|
|
|
|
// 获取组织机构信息
|
|
|
var organization *domain.Org
|
|
|
if data, err := organizationService.OrgFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构数据失败")
|
|
|
} else {
|
|
|
organization = data
|
|
|
}
|
|
|
|
|
|
newCooperationApplication := &domain.CooperationApplication{
|
|
|
CooperationApplicationApplicant: applicant,
|
|
|
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
|
|
|
CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
|
|
|
CooperationApplicationStatus: 1,
|
|
|
CooperationApplicationVerifier: nil,
|
|
|
CooperationApplicationVerifyDescription: "",
|
|
|
CooperationApplicationVerifyTime: time.Time{},
|
|
|
CooperationApplyTime: time.Now(),
|
|
|
CooperationProject: cooperationProject,
|
|
|
Org: organization,
|
|
|
IsCanceled: false,
|
|
|
Company: company,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); 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 cooperationApplication, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// ApprovalCooperationApplication 审核共创申请
|
|
|
func (cooperationApplicationService *CooperationApplicationService) ApprovalCooperationApplication(approvalCooperationApplicationCommand *command.ApprovalCooperationApplicationCommand) (interface{}, error) {
|
|
|
if err := approvalCooperationApplicationCommand.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 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
|
|
|
}
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
// 获取审核人
|
|
|
var verifier *domain.User
|
|
|
if data, err := userService.UserFrom(approvalCooperationApplicationCommand.CompanyId, approvalCooperationApplicationCommand.OrgId, approvalCooperationApplicationCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
|
|
|
} else {
|
|
|
verifier = data
|
|
|
}
|
|
|
|
|
|
// 共创申请ID转换
|
|
|
cooperationApplicationId, err := strconv.ParseInt(approvalCooperationApplicationCommand.CooperationApplicationId, 10, 64)
|
|
|
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, "共创申请不存在")
|
|
|
}
|
|
|
if cooperationApplication == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationApplicationId, 10)))
|
|
|
}
|
|
|
|
|
|
if approvalCooperationApplicationCommand.Action == 1 {
|
|
|
cooperationApplication.CooperationApplicationStatus = 2
|
|
|
} else if approvalCooperationApplicationCommand.Action == 2 {
|
|
|
cooperationApplication.CooperationApplicationStatus = 3
|
|
|
}
|
|
|
|
|
|
cooperationApplication.CooperationApplicationVerifier = verifier
|
|
|
cooperationApplication.CooperationApplicationVerifyTime = time.Now()
|
|
|
|
|
|
if err := cooperationApplication.Update(tool_funs.SimpleStructToMap(approvalCooperationApplicationCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if cooperationApplicationSaved, err := cooperationApplicationRepository.Save(cooperationApplication); 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 cooperationApplicationSaved, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// BatchApprovalCooperationApplication 批量审核共创申请
|
|
|
func (cooperationApplicationService *CooperationApplicationService) BatchApprovalCooperationApplication(batchApprovalCooperationApplicationCommand *command.BatchApprovalCooperationApplicationCommand) (interface{}, error) {
|
|
|
if err := batchApprovalCooperationApplicationCommand.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 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
|
|
|
}
|
|
|
|
|
|
// 共创申请ID类型转换
|
|
|
cooperationApplicationIds, err := utils.SliceAtoi(batchApprovalCooperationApplicationCommand.CooperationApplicationIds)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请ID列表类型错误")
|
|
|
}
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
// 获取审核人
|
|
|
var verifier *domain.User
|
|
|
if data, err := userService.UserFrom(batchApprovalCooperationApplicationCommand.CompanyId, batchApprovalCooperationApplicationCommand.OrgId, batchApprovalCooperationApplicationCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
|
|
|
} else {
|
|
|
verifier = data
|
|
|
}
|
|
|
|
|
|
// 获取共创申请
|
|
|
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].CooperationApplicationVerifyDescription = batchApprovalCooperationApplicationCommand.CooperationApplicationVerifyDescription
|
|
|
if batchApprovalCooperationApplicationCommand.Action == 1 { // 同意
|
|
|
cooperationApplications[i].CooperationApplicationStatus = 2
|
|
|
} else if batchApprovalCooperationApplicationCommand.Action == 2 { // 拒绝
|
|
|
cooperationApplications[i].CooperationApplicationStatus = 3
|
|
|
}
|
|
|
cooperationApplications[i].CooperationApplicationVerifier = verifier
|
|
|
cooperationApplications[i].CooperationApplicationVerifyTime = time.Now()
|
|
|
}
|
|
|
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 map[string]interface{}{
|
|
|
"cooperationApplications": cooperationApplicationsApproved,
|
|
|
}, nil
|
|
|
} else {
|
|
|
return map[string]interface{}{}, nil
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// OneClickApprovalCooperationApplication 一键审核共创申请
|
|
|
func (cooperationApplicationService *CooperationApplicationService) OneClickApprovalCooperationApplication(oneClickApprovalCooperationApplicationCommand *command.OneClickApprovalCooperationApplicationCommand) (interface{}, error) {
|
|
|
if err := oneClickApprovalCooperationApplicationCommand.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 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
|
|
|
}
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
// 获取审核人
|
|
|
var verifier *domain.User
|
|
|
if data, err := userService.UserFrom(oneClickApprovalCooperationApplicationCommand.CompanyId, oneClickApprovalCooperationApplicationCommand.OrgId, oneClickApprovalCooperationApplicationCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
|
|
|
} else {
|
|
|
verifier = data
|
|
|
}
|
|
|
|
|
|
// 查询共创申请
|
|
|
oneClickApprovalCooperationApplicationCommand.CooperationApplicationStatus = 1 // 待审核
|
|
|
if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(oneClickApprovalCooperationApplicationCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for i, _ := range cooperationApplications {
|
|
|
if oneClickApprovalCooperationApplicationCommand.Action == 1 {
|
|
|
cooperationApplications[i].CooperationApplicationStatus = 2
|
|
|
} else if oneClickApprovalCooperationApplicationCommand.Action == 2 {
|
|
|
cooperationApplications[i].CooperationApplicationStatus = 3
|
|
|
}
|
|
|
cooperationApplications[i].CooperationApplicationVerifyDescription = oneClickApprovalCooperationApplicationCommand.CooperationApplicationVerifyDescription
|
|
|
cooperationApplications[i].CooperationApplicationVerifier = verifier
|
|
|
cooperationApplications[i].CooperationApplicationVerifyTime = time.Now()
|
|
|
}
|
|
|
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 map[string]interface{}{
|
|
|
"cooperationApplications": cooperationApplicationsApproved,
|
|
|
}, nil
|
|
|
} else {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未找到待审核的共创申请")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// CreateCooperationApplication 创建共创申请服务
|
|
|
func (cooperationApplicationService *CooperationApplicationService) CreateCooperationApplication(createCooperationApplicationCommand *command.CreateCooperationApplicationCommand) (interface{}, error) {
|
|
|
if err := createCooperationApplicationCommand.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
|
|
|
}
|
|
|
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectNumber": createCooperationApplicationCommand.CooperationProjectNumber})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目不存在")
|
|
|
}
|
|
|
if cooperationProject == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationApplicationCommand.CooperationProjectNumber))
|
|
|
}
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
// 获取申请人
|
|
|
var applicant *domain.User
|
|
|
if data, err := userService.UserFrom(createCooperationApplicationCommand.CompanyId, createCooperationApplicationCommand.OrgId, createCooperationApplicationCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
applicant = data
|
|
|
}
|
|
|
|
|
|
// 公司REST服务初始化
|
|
|
var companyService service.CompanyService
|
|
|
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
companyService = value
|
|
|
}
|
|
|
|
|
|
// 获取公司信息
|
|
|
var company *domain.Company
|
|
|
if data, err := companyService.CompanyFrom(createCooperationApplicationCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
company = data
|
|
|
}
|
|
|
|
|
|
// 组织机构REST服务初始化
|
|
|
var organizationService service.OrgService
|
|
|
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organizationService = value
|
|
|
}
|
|
|
|
|
|
// 获取组织机构信息
|
|
|
var organization *domain.Org
|
|
|
if data, err := organizationService.OrgFrom(createCooperationApplicationCommand.CompanyId, createCooperationApplicationCommand.OrgId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organization = data
|
|
|
}
|
|
|
|
|
|
newCooperationApplication := &domain.CooperationApplication{
|
|
|
CooperationApplicationApplicant: applicant,
|
|
|
CooperationApplicationAttachment: createCooperationApplicationCommand.CooperationApplicationAttachment,
|
|
|
CooperationApplicationDescription: createCooperationApplicationCommand.CooperationApplicationDescription,
|
|
|
CooperationApplicationStatus: 1,
|
|
|
CooperationApplicationVerifier: nil,
|
|
|
CooperationApplicationVerifyDescription: "",
|
|
|
CooperationApplicationVerifyTime: time.Time{},
|
|
|
CooperationApplyTime: time.Now(),
|
|
|
CooperationProject: cooperationProject,
|
|
|
Org: organization,
|
|
|
IsCanceled: false,
|
|
|
Company: company,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); 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 cooperationApplication, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// GetCooperationApplication 返回共创申请服务
|
|
|
func (cooperationApplicationService *CooperationApplicationService) GetCooperationApplication(getCooperationApplicationQuery *query.GetCooperationApplicationQuery) (interface{}, error) {
|
|
|
if err := getCooperationApplicationQuery.ValidateQuery(); 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 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
|
|
|
}
|
|
|
cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": getCooperationApplicationQuery.CooperationApplicationId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请不存在")
|
|
|
}
|
|
|
if cooperationApplication == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getCooperationApplicationQuery.CooperationApplicationId, 10)))
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
coProjectDto := &dto.CooperationApplicationDto{}
|
|
|
coProjectDto.LoadDto(cooperationApplication)
|
|
|
return coProjectDto, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// ListCooperationApplication 返回共创申请服务列表
|
|
|
func (cooperationApplicationService *CooperationApplicationService) ListCooperationApplication(listCooperationApplicationQuery *query.ListCooperationApplicationQuery) (interface{}, error) {
|
|
|
if err := listCooperationApplicationQuery.ValidateQuery(); 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 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
|
|
|
}
|
|
|
if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(listCooperationApplicationQuery)); 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 map[string]interface{}{
|
|
|
"grid": map[string]interface{}{
|
|
|
"total": count,
|
|
|
"list": cooperationApplications,
|
|
|
},
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// RemoveCooperationApplication 移除共创申请服务
|
|
|
func (cooperationApplicationService *CooperationApplicationService) RemoveCooperationApplication(removeCooperationApplicationCommand *command.RemoveCooperationApplicationCommand) (interface{}, error) {
|
|
|
if err := removeCooperationApplicationCommand.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 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
|
|
|
}
|
|
|
cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": removeCooperationApplicationCommand.CooperationApplicationId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请不存在")
|
|
|
}
|
|
|
if cooperationApplication == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeCooperationApplicationCommand.CooperationApplicationId, 10)))
|
|
|
}
|
|
|
if cooperationApplication, err := cooperationApplicationRepository.Remove(cooperationApplication); 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 cooperationApplication, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// SearchCooperationApplication 查询共创申请
|
|
|
func (cooperationApplicationService *CooperationApplicationService) SearchCooperationApplication(searchCooperationApplicationQuery *query.SearchCooperationApplicationQuery) (interface{}, error) {
|
|
|
if err := searchCooperationApplicationQuery.ValidateQuery(); 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 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
|
|
|
}
|
|
|
if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(searchCooperationApplicationQuery)); 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())
|
|
|
}
|
|
|
var coProjectDtos []*dto.CooperationApplicationDto
|
|
|
for i := range cooperationApplications {
|
|
|
var coProjectDto = &dto.CooperationApplicationDto{}
|
|
|
coProjectDto.LoadDto(cooperationApplications[i])
|
|
|
coProjectDtos = append(coProjectDtos, coProjectDto)
|
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"grid": map[string]interface{}{
|
|
|
"total": count,
|
|
|
"list": coProjectDtos,
|
|
|
},
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// UpdateCooperationApplication 更新共创申请服务
|
|
|
func (cooperationApplicationService *CooperationApplicationService) UpdateCooperationApplication(updateCooperationApplicationCommand *command.UpdateCooperationApplicationCommand) (interface{}, error) {
|
|
|
if err := updateCooperationApplicationCommand.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 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
|
|
|
}
|
|
|
cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": updateCooperationApplicationCommand.CooperationApplicationId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请不存在")
|
|
|
}
|
|
|
if cooperationApplication == nil {
|
|
|
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())
|
|
|
}
|
|
|
if cooperationApplication, err := cooperationApplicationRepository.Save(cooperationApplication); 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 cooperationApplication, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// CancelCooperationApplication 取消共创申请
|
|
|
func (cooperationApplicationService *CooperationApplicationService) CancelCooperationApplication(cancelCooperationApplicationCommand *command.CancelCooperationApplicationCommand) (interface{}, error) {
|
|
|
if err := cancelCooperationApplicationCommand.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()
|
|
|
}()
|
|
|
//TODO 校验用户菜单模块权限
|
|
|
|
|
|
// 共创申请仓储初始化
|
|
|
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
|
|
|
}
|
|
|
cooperationApplicationId, err := strconv.ParseInt(cancelCooperationApplicationCommand.CooperationApplicationId, 10, 64)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请ID错误")
|
|
|
}
|
|
|
cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": cooperationApplicationId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创申请不存在")
|
|
|
}
|
|
|
if cooperationApplication == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationApplicationId, 10)))
|
|
|
}
|
|
|
if err := cooperationApplication.Update(map[string]interface{}{
|
|
|
"isCanceled": true,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if cooperationApplication, err := cooperationApplicationRepository.Save(cooperationApplication); 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 cooperationApplication, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func NewCooperationApplicationService(options map[string]interface{}) *CooperationApplicationService {
|
|
|
newCooperationApplicationService := &CooperationApplicationService{}
|
|
|
return newCooperationApplicationService
|
|
|
} |
...
|
...
|
|