作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !85
... ... @@ -7,6 +7,7 @@ import (
"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/event/subscriber"
"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"
... ... @@ -346,6 +347,32 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
cooperationApplicationRepository = value
}
// 同意共创申请消息推送领域服务初始化
var agreeContractApplicationService service.AgreeContractApplicationService
if value, err := factory.CreateAgreeContractApplicationService(map[string]interface{}{
//"transactionContext": transactionContext,
}); err != nil {
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
agreeContractApplicationService = value
_ = agreeContractApplicationService.Subscribe(&subscriber.MessageServiceSubscriber{
//TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
// 拒绝共创申请消息推送领域服务初始化
var rejectContractApplicationService service.RejectContractApplicationService
if value, err := factory.CreateRejectContractApplicationService(map[string]interface{}{
//"transactionContext": transactionContext,
}); err != nil {
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rejectContractApplicationService = value
_ = rejectContractApplicationService.Subscribe(&subscriber.MessageServiceSubscriber{
//TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
// 共创申请ID类型转换
cooperationApplicationIds, err := utils.SliceAtoi(batchApprovalCooperationApplicationCommand.CooperationApplicationIds)
if err != nil {
... ... @@ -379,7 +406,7 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
for i, cooperationApplication := range cooperationApplications {
// 校验共创申请是否已经审核过
if cooperationApplication.CooperationApplicationStatus != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "申请已经审核过")
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "申请已经审核过")
}
// 更新共创申请数据
cooperationApplications[i].CooperationApplicationVerifyDescription = batchApprovalCooperationApplicationCommand.CooperationApplicationVerifyDescription
... ... @@ -392,13 +419,45 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
cooperationApplications[i].CooperationApplicationVerifyTime = time.Now()
cooperationApplications[i].IsCanceled = 1
}
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())
}
// 推送消息
for _, cooperationApplicationApproved := range cooperationApplicationsApproved {
if cooperationApplicationApproved.CooperationApplicationStatus == 2 {
if err1 := agreeContractApplicationService.Agree(
cooperationApplicationApproved.CooperationProject.CooperationProjectId,
cooperationApplicationApproved.CooperationProject.CooperationProjectName,
cooperationApplicationApproved.CooperationProject.CooperationProjectNumber,
cooperationApplicationApproved.CooperationApplicationApplicant.UserId,
cooperationApplicationApproved.CooperationApplicationApplicant.UserBaseId,
cooperationApplicationApproved.CooperationProject.Org.OrgId,
cooperationApplicationApproved.CooperationProject.Company.CompanyId,
); err1 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err1.Error())
}
} else if cooperationApplicationApproved.CooperationApplicationStatus == 3 {
if err2 := rejectContractApplicationService.Reject(
cooperationApplicationApproved.CooperationProject.CooperationProjectId,
cooperationApplicationApproved.CooperationProject.CooperationProjectName,
cooperationApplicationApproved.CooperationProject.CooperationProjectNumber,
cooperationApplicationApproved.CooperationApplicationApplicant.UserId,
cooperationApplicationApproved.CooperationApplicationApplicant.UserBaseId,
cooperationApplicationApproved.CooperationProject.Org.OrgId,
cooperationApplicationApproved.CooperationProject.Company.CompanyId,
); err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
}
}
}
return map[string]interface{}{
"cooperationApplications": cooperationApplicationsApproved,
}, nil
... ...
... ... @@ -1019,14 +1019,14 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
CooperationContractNumber: cooperationContract.CooperationContractNumber,
UserId: relevantDomain.UserId,
UserBaseId: relevantDomain.UserBaseId,
Org: relevantDomain.Org,
Org: organization,
Orgs: relevantDomain.Orgs,
Department: relevantDomain.Department,
Roles: relevantDomain.Roles,
UserInfo: relevantDomain.UserInfo,
UserType: relevantDomain.UserType,
Status: relevantDomain.Status,
Company: relevantDomain.Company,
Company: company,
})
}
... ... @@ -1114,7 +1114,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
CooperationContractNumber: cooperationContract.CooperationContractNumber,
CooperationContractId: cooperationContract.CooperationContractId,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Org: organization,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
... ... @@ -1123,7 +1123,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
Referrer: referrerDomain,
Salesman: salesmanDomain,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
Company: company,
ContractAttachment: contractAttachments,
})
}
... ... @@ -1275,7 +1275,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, rule := range cooperationContractFound.DividendsIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
}
... ... @@ -1288,7 +1288,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, rule := range cooperationContract.DividendsIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractBytes = append(cooperationContractBytes, jsons...)
}
... ... @@ -1331,7 +1331,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, rule := range cooperationContractFound.MoneyIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
}
... ... @@ -1344,7 +1344,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, rule := range cooperationContract.MoneyIncentivesRules {
jsons, errs := json.Marshal(rule)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractBytes = append(cooperationContractBytes, jsons...)
}
... ... @@ -1388,7 +1388,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, undertaker := range cooperationContractFound.Undertakers {
jsons, errs := json.Marshal(undertaker)
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractFoundBytes = append(cooperationContractFoundBytes, jsons...)
}
... ... @@ -1400,7 +1400,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
for _, undertaker := range cooperationContract.Undertakers {
jsons, errs := json.Marshal(undertaker) //转换成JSON返回的是byte[]
if errs != nil {
(errs.Error())
fmt.Printf(errs.Error())
}
cooperationContractBytes = append(cooperationContractBytes, jsons...)
}
... ... @@ -1441,7 +1441,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
UserPhone: "",
}
}
undertakersOriginal = undertakersOriginal + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserInfo.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
undertakersOriginal = undertakersOriginal + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserInfo.UserName + "," + undertaker.Referrer.UserName + "" + undertaker.Salesman.UserName + ")"
}
undertakerChangeTmp1 := "【" + undertakersOriginal + "】"
... ... @@ -1478,7 +1478,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
UserPhone: "",
}
}
undertakersChanged = undertakersChanged + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserInfo.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
undertakersChanged = undertakersChanged + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserInfo.UserName + "," + undertaker.Referrer.UserName + "" + undertaker.Salesman.UserName + ")"
}
undertakerChangeTemp2 := "【" + undertakersChanged + "】"
// 拼接承接人变更记录
... ... @@ -1501,8 +1501,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
}
// 保存共创合约变更记录
if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
if newCooperationContractChangeLog.IncentivesRule != "" || newCooperationContractChangeLog.IncentivesRuleDetail != "" || newCooperationContractChangeLog.Undertakers != "" {
if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
}
}
if err21 := transactionContext.CommitTransaction(); err21 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error())
... ...
... ... @@ -2,14 +2,13 @@ package subscriber
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/event"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
)
type MessageServiceSubscriber struct {
TransactionContext *pgTransaction.TransactionContext
//TransactionContext *pgTransaction.TransactionContext
}
func (subscriber *MessageServiceSubscriber) HandleEvent(domainEvent coreDomain.DomainEvent) error {
... ...
... ... @@ -53,3 +53,21 @@ func CreateCancelDividendsEstimateService(options map[string]interface{}) (*doma
}
return domain_service.NewCancelDividendsEstimateService(transactionContext)
}
func CreateAgreeContractApplicationService(options map[string]interface{}) (*domain_service.AgreeContractApplicationService, error) {
//var transactionContext *pgTransaction.TransactionContext
//if value, ok := options["transactionContext"]; ok {
// transactionContext = value.(*pgTransaction.TransactionContext)
//}
//return domain_service.NewAgreeContractApplicationService(transactionContext)
return domain_service.NewAgreeContractApplicationService(nil)
}
func CreateRejectContractApplicationService(options map[string]interface{}) (*domain_service.RejectContractApplicationService, error) {
//var transactionContext *pgTransaction.TransactionContext
//if value, ok := options["transactionContext"]; ok {
// transactionContext = value.(*pgTransaction.TransactionContext)
//}
//return domain_service.NewRejectContractApplicationService(transactionContext)
return domain_service.NewRejectContractApplicationService(nil)
}
... ...
... ... @@ -4,5 +4,5 @@ import coreDomain "github.com/linmadan/egglib-go/core/domain"
type AgreeContractApplicationService interface {
coreDomain.DomainEventPublisher
Agree() error
Agree(creationProjectId int64, creationProjectName string, creationProjectNumber string, userId int64, userBaseId int64, orgId int64, companyId int64) error
}
... ...
... ... @@ -4,5 +4,5 @@ import coreDomain "github.com/linmadan/egglib-go/core/domain"
type RejectContractApplicationService interface {
coreDomain.DomainEventPublisher
Reject() error
Reject(creationProjectId int64, creationProjectName string, creationProjectNumber string, userId int64, userBaseId int64, orgId int64, companyId int64) error
}
... ...
package domain_service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/event"
)
type AgreeContractApplicationService struct {
coreDomain.BaseEventPublisher
//transactionContext *pgTransaction.TransactionContext
}
func (service *AgreeContractApplicationService) Agree(creationProjectId int64, creationProjectName string, creationProjectNumber string, userId int64, userBaseId int64, orgId int64, companyId int64) error {
cooperationApplicationAgreedEvent := new(event.CooperationApplicationAgreed)
cooperationApplicationAgreedEvent.CreationProjectId = creationProjectId
cooperationApplicationAgreedEvent.CreationProjectName = creationProjectName
cooperationApplicationAgreedEvent.CreationProjectNumber = creationProjectNumber
cooperationApplicationAgreedEvent.UserId = userId
cooperationApplicationAgreedEvent.UserBaseId = userBaseId
cooperationApplicationAgreedEvent.OrgId = orgId
cooperationApplicationAgreedEvent.CompanyId = companyId
if err := service.Publish(cooperationApplicationAgreedEvent); err != nil {
return err
}
return nil
}
func NewAgreeContractApplicationService(transactionContext *pgTransaction.TransactionContext) (*AgreeContractApplicationService, error) {
//if transactionContext == nil {
// return nil, fmt.Errorf("transactionContext参数不能为nil")
//} else {
// return &AgreeContractApplicationService{
// transactionContext: transactionContext,
// }, nil
//}
return &AgreeContractApplicationService{}, nil
}
... ...
package domain_service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/event"
)
type RejectContractApplicationService struct {
coreDomain.BaseEventPublisher
//transactionContext *pgTransaction.TransactionContext
}
func (service *RejectContractApplicationService) Reject(creationProjectId int64, creationProjectName string, creationProjectNumber string, userId int64, userBaseId int64, orgId int64, companyId int64) error {
cooperationApplicationRejectedEvent := new(event.CooperationApplicationRejected)
cooperationApplicationRejectedEvent.CreationProjectId = creationProjectId
cooperationApplicationRejectedEvent.CreationProjectName = creationProjectName
cooperationApplicationRejectedEvent.CreationProjectNumber = creationProjectNumber
cooperationApplicationRejectedEvent.UserId = userId
cooperationApplicationRejectedEvent.UserBaseId = userBaseId
cooperationApplicationRejectedEvent.OrgId = orgId
cooperationApplicationRejectedEvent.CompanyId = companyId
if err := service.Publish(cooperationApplicationRejectedEvent); err != nil {
return err
}
return nil
}
func NewRejectContractApplicationService(transactionContext *pgTransaction.TransactionContext) (*RejectContractApplicationService, error) {
//if transactionContext == nil {
// return nil, fmt.Errorf("transactionContext参数不能为nil")
//} else {
// return &RejectContractApplicationService{
// transactionContext: transactionContext,
// }, nil
//}
return &RejectContractApplicationService{}, nil
}
... ...
... ... @@ -82,6 +82,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
undertakersDomain = append(undertakersDomain, &domain.Undertaker{
UndertakerId: undertaker.CooperationContractUndertakerId,
CooperationContractNumber: undertaker.CooperationContractNumber,
CooperationContractId: undertaker.CooperationContractId,
UserId: undertaker.UserId,
UserBaseId: undertaker.UserBaseId,
Org: undertaker.Org,
... ...
... ... @@ -327,9 +327,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
var cooperationContractRelevantPeopleToAdd []*domain.Relevant
for _, relevant := range cooperationContract.RelevantPeople {
if relevant.RelevantId != 0 {
cooperationContractRelevantPeopleToUpdate = append(cooperationContractRelevantPeopleToUpdate, relevant)
cooperationContractRelevantPeopleToUpdate = append(cooperationContractRelevantPeopleToUpdate, relevant) // 提取待更新的相关人
} else {
cooperationContractRelevantPeopleToAdd = append(cooperationContractRelevantPeopleToAdd, relevant)
cooperationContractRelevantPeopleToAdd = append(cooperationContractRelevantPeopleToAdd, relevant) // 提取待添加的相关人
}
}
... ... @@ -379,13 +379,41 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 待更新的相关人id
relevantIdsToUpdate := utils.Intersect(cooperationContractRelevantIdsFetched, cooperationContractRelevantPeopleToUpdateOrDeleteIds)
var relevantModelsToUpdate []*models.CooperationContractRelevant
var relevantDomainsToUpdate []*domain.Relevant
for _, id := range relevantIdsToUpdate {
for _, relevantModel := range cooperationContractRelevantModelsFetched {
if relevantModel.CooperationContractRelevantId == id {
relevantModelsToUpdate = append(relevantModelsToUpdate, relevantModel)
//for _, relevantModel := range cooperationContractRelevantModelsFetched {
// if relevantModel.CooperationContractRelevantId == id {
// relevantModelsToUpdate = append(relevantModelsToUpdate, relevantModel)
// }
//}
for _, relevantDomain := range cooperationContract.RelevantPeople {
if relevantDomain.RelevantId == id {
relevantDomainsToUpdate = append(relevantDomainsToUpdate, relevantDomain)
}
}
}
// domain to model
for _, relevantDomainToUpdate := range relevantDomainsToUpdate {
relevantModelsToUpdate = append(relevantModelsToUpdate, &models.CooperationContractRelevant{
CooperationContractRelevantId: relevantDomainToUpdate.RelevantId,
CooperationContractNumber: relevantDomainToUpdate.CooperationContractNumber,
UserId: relevantDomainToUpdate.UserId,
UserBaseId: relevantDomainToUpdate.UserBaseId,
Org: relevantDomainToUpdate.Org,
Orgs: relevantDomainToUpdate.Orgs,
Department: relevantDomainToUpdate.Department,
Roles: relevantDomainToUpdate.Roles,
UserInfo: relevantDomainToUpdate.UserInfo,
UserType: relevantDomainToUpdate.UserType,
Status: relevantDomainToUpdate.Status,
Company: relevantDomainToUpdate.Company,
UpdatedAt: time.Now(),
DeletedAt: time.Time{},
CreatedAt: time.Time{},
})
}
if len(relevantModelsToUpdate) > 0 {
if _, err := tx.Model(&relevantModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
... ... @@ -410,6 +438,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return nil, err
}
}
/***************************************************************/
/************************* 更新承接人 ****************************/
// 获取承接人列表
... ... @@ -431,6 +460,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 待更新相关人
var cooperationContractUndertakersToUpdate []*domain.Undertaker
// 待添加相关人
var cooperationContractUndertakersToAdd []*domain.Undertaker
for _, undertaker := range cooperationContract.Undertakers {
... ... @@ -554,6 +584,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return nil, err
}
}
/*****************************************************************/
/************************ 更新分红激励规则 **************************/
// 获取分红激励规则列表
... ... @@ -687,6 +718,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return nil, err
}
}
/***************************************************************/
/********************** 更新金额激励规则 **************************/
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
... ...
... ... @@ -12,22 +12,35 @@ import (
// Intersect 返回两个数组的交集
func Intersect(nums1 []int64, nums2 []int64) []int64 {
if len(nums1) > len(nums2) {
return Intersect(nums2, nums1)
}
m := map[int64]int64{}
for _, num := range nums1 {
m[num]++
//if len(nums1) > len(nums2) {
// return Intersect(nums2, nums1)
//}
//m := map[int64]int64{}
//for _, num := range nums1 {
// m[num]++
//}
//
//var intersection []int64
//for _, num := range nums2 {
// if m[num] > 0 {
// intersection = append(intersection, num)
// m[num]--
// }
//}
//return intersection
m := make(map[int64]int)
nn := make([]int64, 0)
for _, v := range nums1 {
m[v]++
}
var intersection []int64
for _, num := range nums2 {
if m[num] > 0 {
intersection = append(intersection, num)
m[num]--
for _, v := range nums2 {
times, _ := m[v]
if times > 0 {
nn = append(nn, v)
}
}
return intersection
return nn
}
// Intersect32 返回两个数组的交集
... ... @@ -52,20 +65,34 @@ func Intersect32(nums1 []int32, nums2 []int32) []int32 {
// Difference 求差集 slice1-并集
func Difference(slice1, slice2 []int64) []int64 {
//m := make(map[int64]int)
//nn := make([]int64, 0)
//inter := Intersect(slice1, slice2)
//for _, v := range inter {
// m[v]++
//}
//
//for _, value := range slice1 {
// times, _ := m[value]
// if times == 0 {
// nn = append(nn, value)
// }
//}
//return nn
m := make(map[int64]int)
nn := make([]int64, 0)
inter := Intersect(slice1, slice2)
for _, v := range inter {
m[v]++
}
for _, value := range slice1 {
times, _ := m[value]
for _, v := range slice1 {
times, _ := m[v]
if times == 0 {
nn = append(nn, value)
nn = append(nn, v)
}
}
return nn
}
// SliceAtoi 字符创数组转数字数组
... ...