作者 陈志颖

feat:创建合约接口调试

... ... @@ -2,46 +2,85 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CreateDividendsIncentivesRulesCommand struct {
DividendsIncentivesRuleId string `cname:"分红激励规则ID" json:"dividendsIncentivesRuleId"`
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber"`
ReferrerPercentage float64 `cname:"推荐人抽成" json:"referrerPercentage"`
SalesmanPercentage float64 `cname:"业务员抽成" json:"salesmanPercentage"`
DividendsIncentivesPercentage float64 `cname:"分红规则激励百分点" json:"dividendsIncentivesPercentage"`
DividendsIncentivesStage int `cname:"分红激励阶段" json:"dividendsIncentivesStage"`
DividendsIncentivesStageEnd time.Time `cname:"" json:"dividendsIncentivesStageEnd"`
DividendsIncentivesStageStart time.Time `cname:"" json:"dividendsIncentivesStageStart"`
}
type CreateMoneyIncentivesRulesCommand struct {
MoneyIncentivesRuleIdString string `cname:"" json:"moneyIncentivesRuleId,string"`
CooperationContractNumber string `cname:"" json:"cooperationContractNumber"`
MoneyIncentivesAmount int `cname:"" json:"moneyIncentivesAmount"`
MoneyIncentivesStage int `cname:"" json:"moneyIncentivesStage"`
MoneyIncentivesStageEnd time.Time `cname:"" json:"moneyIncentivesStageEnd"`
MoneyIncentivesStageStart time.Time `cname:"" json:"moneyIncentivesStageStart"`
MoneyIncentivesTime time.Time `cname:"" json:"moneyIncentivesTime"`
ReferrerPercentage float64 `cname:"" json:"referrerPercentage"`
SalesmanPercentage float64 `cname:"" json:"salesmanPercentage"`
}
type CreateUndertakersCommand struct {
UserId string `cname:"承接人UID" json:"userId"`
ContractAttachment []struct {
FileType string `json:"fileType"`
Name string `json:"name"`
Url string `json:"url"`
FileSize int64 `json:"fileSize"`
} `json:"contractAttachment"`
ReferrerId string `json:"referrerId"`
SalesmanId string `json:"salesmanId"`
}
type CreateRelevantPeopleCommand struct {
UserId string `json:"userId"`
}
type CreateCooperationContractCommand struct {
// 共创合约描述
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" valid:"Required"`
// 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
CooperationProjectNumber string `cname:"共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001" json:"cooperationProjectNumber" valid:"Required"`
CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber" valid:"Required"`
// 共创合约发起部门编码
DepartmentNumber string `cname:"共创合约发起部门编码" json:"departmentNumber" valid:"Required"`
DepartmentId string `cname:"共创合约发起部门ID" json:"departmentId" valid:"Required"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerType []int32 `cname:"共创合约承接对象,1员工,2共创用户,3公开" json:"cooperationContractUndertakerType" valid:"Required"`
CooperationContractUndertakerTypes []int32 `cname:"共创合约承接对象" json:"cooperationContractUndertakerTypes" valid:"Required"`
// 共创合约名称
CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName" valid:"Required"`
// 共创模式编码,手动输入,唯一确定
CooperationModeNumber string `cname:"共创模式编码,手动输入,唯一确定" json:"cooperationModeNumber" valid:"Required"`
// 共创模式编码
CooperationModeNumber string `cname:"共创模式编码" json:"cooperationModeNumber" valid:"Required"`
// 共创合约发起人uid
SponsorUid string `cname:"共创合约发起人uid" json:"sponsorUid,omitempty"`
// 业绩分红激励规则列表
DividendsIncentivesRules []*domain.DividendsIncentivesRule `cname:"业绩分红激励规则列表" json:"dividendsIncentivesRules,omitempty"`
DividendsIncentivesRules []*CreateDividendsIncentivesRulesCommand `cname:"业绩分红激励规则列表" json:"dividendsIncentivesRules,omitempty"`
// 金额激励规则列表
MoneyIncentivesRules []*domain.MoneyIncentivesRule `cname:"金额激励规则列表" json:"moneyIncentivesRules,omitempty"`
MoneyIncentivesRules []*CreateMoneyIncentivesRulesCommand `cname:"金额激励规则列表" json:"moneyIncentivesRules,omitempty"`
// 承接方列表
Undertakers []*domain.Undertaker `cname:"承接方列表" json:"undertakers,omitempty"`
Undertakers []*CreateUndertakersCommand `cname:"承接方列表" json:"undertakers,omitempty"`
// 相关人列表
RelevantPeople []*domain.Relevant `cname:"相关人列表" json:"relevantPeople,omitempty"`
RelevantPeople []string `cname:"相关人列表" json:"relevantPeople,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
UserId int64 `cname:"用户ID" json:"userId,string" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据is" json:"userBaseId,string" valid:"Required"`
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId,string" valid:"Required"`
}
func (createCooperationContractCommand *CreateCooperationContractCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -8,7 +8,9 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/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"
"strconv"
"time"
)
// CooperationContractService 共创合约服务
... ... @@ -31,90 +33,234 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
_ = transactionContext.RollbackTransaction()
}()
//userServiceGateway, err := factory.CreateUserServiceGateway(nil)
//if err != nil {
// fmt.Println(err.Error())
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
// 用户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
}
//userServiceGateway.GetUser(createCooperationContractCommand.SponsorUid)
// 获取操作人
var operator *domain.User
if data, err := userService.OperatorFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, createCooperationContractCommand.UserId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operator = data
}
newCooperationContract := &domain.CooperationContract{
CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
//CooperationProjectNumber: createCooperationContractCommand.CooperationProjectNumber,
//DepartmentNumber: createCooperationContractCommand.DepartmentNumber,
CooperationContractUndertakerTypes: createCooperationContractCommand.CooperationContractUndertakerType,
CooperationContractName: createCooperationContractCommand.CooperationContractName,
//CooperationModeNumber: createCooperationContractCommand.CooperationModeNumber,
//SponsorUid: createCooperationContractCommand.SponsorUid,
//DividendsIncentivesRules: createCooperationContractCommand.DividendsIncentivesRules,
//MoneyIncentivesRules: createCooperationContractCommand.MoneyIncentivesRules,
//Undertakers: createCooperationContractCommand.Undertakers,
//RelevantPeople: createCooperationContractCommand.RelevantPeople,
//CompanyId: createCooperationContractCommand.CompanyId,
//OrgId: createCooperationContractCommand.OrgId,
//UserId: createCooperationContractCommand.UserId,
// 获取发起人
var sponsor *domain.User
sponsorUid, _ := strconv.ParseInt(createCooperationContractCommand.SponsorUid, 10, 64)
if data, err := userService.OperatorFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, sponsorUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
sponsor = data
}
// 共创合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
// 公司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 {
cooperationContractRepository = value
companyService = value
}
// 获取公司信息
var company *domain.Company
if data, err := companyService.CompanyFrom(createCooperationContractCommand.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(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
organization = data
}
//// 共创合约承接人仓储初始化
//var cooperationContractUndertakerRepository domain.CooperationContractUndertakerRepository
//if value, err := factory.CreateCooperationContractUndertakerRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cooperationContractUndertakerRepository = value
//}
// 获取承接人
var undertakers []*domain.Undertaker
for _, undertaker := range createCooperationContractCommand.Undertakers {
var undertakerDomain *domain.Undertaker
undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64)
if data, err := userService.UndertakerFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, undertakerUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
undertakerDomain = data
}
//// 共创合约相关人仓储初始化
//var cooperationContractRelevantRepository domain.CooperationContractRelevantRepository
//if value, err := factory.CreateCooperationContractRelevantRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cooperationContractRelevantRepository = value
//}
// 获取推荐人
var referrerDomain *domain.Referrer
referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64)
if data, err := userService.ReferrerFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, referrerUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
referrerDomain = data
}
//// 分红激励规则仓储初始化
//var dividendsIncentivesRuleRepository domain.DividendsIncentivesRuleRepository
//if value, err := factory.CreateDividendsIncentivesRuleRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// dividendsIncentivesRuleRepository = value
//}
// 获取业务员
var salesmanDomain *domain.Salesman
salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
if data, err := userService.SalesmanFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, salesmanUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
salesmanDomain = data
}
//// 金额激励规则仓储初始化
//var moneyIncentivesRuleRepository domain.MoneyIncentivesRuleRepository
//if value, err := factory.CreateMoneyIncentivesRuleRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// moneyIncentivesRuleRepository = value
//}
undertakers = append(undertakers, &domain.Undertaker{
UndertakerId: 0,
UserId: undertakerDomain.UserId,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
UserInfo: undertakerDomain.UserInfo,
UserType: undertakerDomain.UserType,
Referrer: referrerDomain,
Salesman: salesmanDomain,
Status: 0,
Company: company,
ContractAttachment: nil,
})
}
// 获取相关人
var relevantPeople []*domain.Relevant
for _, relevantPersonUid := range createCooperationContractCommand.RelevantPeople {
var relevantDomain *domain.Relevant
relevantUid, _ := strconv.ParseInt(relevantPersonUid, 10, 64)
if data, err := userService.RelevantFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, relevantUid); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
relevantDomain = data
}
relevantPeople = append(relevantPeople, &domain.Relevant{
RelevantId: 0,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
UserId: relevantDomain.UserId,
UserBaseId: relevantDomain.UserBaseId,
Org: relevantDomain.Org,
Orgs: relevantDomain.Orgs,
Department: relevantDomain.Department,
Roles: relevantDomain.Roles,
UserInfo: relevantDomain.UserInfo,
UserType: relevantDomain.UserType,
Status: relevantDomain.Status,
Company: relevantDomain.Company,
})
}
if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
// 获取分红激励规则列表
var dividendsIncentivesRules []*domain.DividendsIncentivesRule
for _, dividendsIncentivesRule := range createCooperationContractCommand.DividendsIncentivesRules {
dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: 0,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
DividendsIncentivesStage: int64(dividendsIncentivesRule.DividendsIncentivesStage),
DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart,
Org: organization,
Company: company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
// 获取金额激励规则
var moneyIncentivesRules []*domain.MoneyIncentivesRule
for _, moneyIncentivesRule := range createCooperationContractCommand.MoneyIncentivesRules {
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: 0,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),
MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage),
MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
MoneyIncentivesTime: time.Now(),
ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage,
SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage,
Org: organization,
Company: company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
// 查找共创模式
var cooperationModeRepository domain.CooperationModeRepository
if value, err := factory.CreateCooperationModeRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); 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())
cooperationModeRepository = value
}
cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeNumber": createCooperationContractCommand.CooperationModeNumber})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationMode == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationContractCommand.CooperationModeNumber))
} else {
newCooperationContract := &domain.CooperationContract{
CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
CooperationContractName: createCooperationContractCommand.CooperationContractName,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractUndertakerTypes: createCooperationContractCommand.CooperationContractUndertakerTypes,
CooperationContractSponsor: sponsor,
CooperationMode: cooperationMode,
Status: 1,
Org: organization,
Company: company,
Operator: operator,
DividendsIncentivesRules: dividendsIncentivesRules,
MoneyIncentivesRules: moneyIncentivesRules,
Undertakers: undertakers,
RelevantPeople: relevantPeople,
OperateTime: time.Now(),
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
}
// 共创合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); 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 cooperationContract, nil
}
return cooperationContract, nil
}
}
... ...
... ... @@ -10,7 +10,7 @@ import (
type BatchOperateCooperationModeCommand struct {
// 共创模式ID
CooperationModeIds []string `cname:"共创模式id" json:"cooperationModeIds" valid:"Required"`
CooperationModeIds []string `cname:"共创模式id" json:"cooperationModeIds"`
// 共创模式状态,1启用,2禁用
Status int32 `cname:"状态" json:"status" valid:"Required"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -42,7 +42,7 @@ func (cooperationModeService *CooperationModeService) CreateCooperationMode(crea
userService = value
}
// 获取承接
// 获取操作
var operator *domain.User
if data, err := userService.OperatorFrom(createCooperationModeCommand.CompanyId, createCooperationModeCommand.OrgId, createCooperationModeCommand.UserId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type BatchEndCooperationProjectCommand struct {
// 共创项目ID
CooperationProjectIds []string `cname:"共创项目ID数组" json:"cooperationProjectIds" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据is" json:"userBaseId,string" valid:"Required"`
}
func (batchEndCooperationProjectCommand *BatchEndCooperationProjectCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchEndCooperationProjectCommand *BatchEndCooperationProjectCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchEndCooperationProjectCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchEndCooperationProjectCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -20,13 +20,13 @@ type CreateCooperationProjectCommand struct {
// 共创项目描述
CooperationProjectDescription string `cname:"共创项目描述" json:"cooperationProjectDescription,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
UserId int64 `cname:"用户ID" json:"userId,string" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据is" json:"userBaseId,string" valid:"Required"`
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId,string" valid:"Required"`
}
func (createCooperationProjectCommand *CreateCooperationProjectCommand) Valid(validation *validation.Validation) {
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type EndCooperationProjectCommand struct {
// 共创项目ID
CooperationProjectId string `cname:"共创项目ID" json:"cooperationProjectId" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据is" json:"userBaseId,string" valid:"Required"`
}
func (endCooperationProjectCommand *EndCooperationProjectCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (endCooperationProjectCommand *EndCooperationProjectCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(endCooperationProjectCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(endCooperationProjectCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -17,7 +17,7 @@ type Undertaker struct {
// 用户所属的部门
Department *Department `json:"department"`
// 用户角色
Role *Role `json:"role"`
Roles []*Role `json:"role"`
// 冗余字段,jsonb格式,不限制存放内容
UserInfo *UserInfo `json:"userInfo"`
// 用户类型,1员工,2共创用户,3公开
... ...
... ... @@ -20,10 +20,20 @@ func (service *UserService) UserFrom(companyId int64, orgId int64, userId int64)
return nil, err
} else {
if user != nil {
err := json.Unmarshal(user.([]byte), returnData)
if err != nil {
log.Logger.Debug("普通用户", map[string]interface{}{
"user interface": user,
})
userJson, err1 := json.Marshal(user)
if err1 != nil {
return nil, err
}
log.Logger.Debug("普通用户", map[string]interface{}{
"user json": userJson,
})
err2 := json.Unmarshal(userJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
... ... @@ -40,10 +50,20 @@ func (service *UserService) ReferrerFrom(companyId int64, orgId int64, userId in
return nil, err
} else {
if referrer != nil {
err := json.Unmarshal(referrer.([]byte), returnData)
if err != nil {
log.Logger.Debug("推荐人", map[string]interface{}{
"referrer interface": referrer,
})
referrerJson, err1 := json.Marshal(referrer)
if err1 != nil {
return nil, err
}
log.Logger.Debug("推荐人", map[string]interface{}{
"referrer json": referrerJson,
})
err2 := json.Unmarshal(referrerJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
... ... @@ -60,10 +80,20 @@ func (service *UserService) UndertakerFrom(companyId int64, orgId int64, userId
return nil, err
} else {
if undertaker != nil {
err := json.Unmarshal(undertaker.([]byte), returnData)
if err != nil {
log.Logger.Debug("承接人", map[string]interface{}{
"undertaker interface": undertaker,
})
undertakerJson, err1 := json.Marshal(undertaker)
if err1 != nil {
return nil, err
}
log.Logger.Debug("承接人", map[string]interface{}{
"undertaker json": undertakerJson,
})
err2 := json.Unmarshal(undertakerJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
... ... @@ -80,10 +110,20 @@ func (service *UserService) RelevantFrom(companyId int64, orgId int64, userId in
return nil, err
} else {
if relevant != nil {
err := json.Unmarshal(relevant.([]byte), returnData)
if err != nil {
log.Logger.Debug("相关人", map[string]interface{}{
"relevant interface": relevant,
})
relevantJson, err1 := json.Marshal(relevant)
if err1 != nil {
return nil, err
}
log.Logger.Debug("相关人", map[string]interface{}{
"relevant json": relevantJson,
})
err2 := json.Unmarshal(relevantJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
... ... @@ -100,10 +140,20 @@ func (service *UserService) SalesmanFrom(companyId int64, orgId int64, userId in
return nil, err
} else {
if salesman != nil {
err := json.Unmarshal(salesman.([]byte), returnData)
if err != nil {
log.Logger.Debug("业务员", map[string]interface{}{
"salesman interface": salesman,
})
salesmanJson, err1 := json.Marshal(salesman)
if err1 != nil {
return nil, err
}
log.Logger.Debug("业务员", map[string]interface{}{
"salesman json": salesmanJson,
})
err2 := json.Unmarshal(salesmanJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
... ...
... ... @@ -22,7 +22,7 @@ type CooperationContractUndertaker struct {
// 用户所属部门
Department *domain.Department `comment:"用户所属部门"`
// 用户角色
Role *domain.Role `comment:"用户角色"`
Roles []*domain.Role `comment:"用户角色"`
// 用户信息
UserInfo *domain.UserInfo `comment:"用户信息"`
// 用户类型
... ...
... ... @@ -76,7 +76,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
Org: undertaker.Org,
Orgs: undertaker.Orgs,
Department: undertaker.Department,
Role: undertaker.Role,
Roles: undertaker.Roles,
UserInfo: undertaker.UserInfo,
UserType: undertaker.UserType,
Status: undertaker.Status,
... ...
... ... @@ -15,7 +15,7 @@ func TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperation
Org: cooperationContractUndertakerModel.Org,
Orgs: cooperationContractUndertakerModel.Orgs,
Department: cooperationContractUndertakerModel.Department,
Role: cooperationContractUndertakerModel.Role,
Roles: cooperationContractUndertakerModel.Roles,
UserInfo: cooperationContractUndertakerModel.UserInfo,
UserType: cooperationContractUndertakerModel.UserType,
Referrer: cooperationContractUndertakerModel.Referrer,
... ...
... ... @@ -32,8 +32,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
"cooperation_contract_description",
"cooperation_contract_name",
"cooperation_contract_number",
"cooperation_contract_referrer",
"cooperation_contract_salesman",
"cooperation_contract_undertaker_types",
"cooperation_contract_sponsor",
"cooperation_mode_number",
... ... @@ -91,7 +89,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.Operator,
cooperationContract.OperateTime,
cooperationContract.CreatedAt,
cooperationContract.DeletedAt,
nil,
cooperationContract.UpdatedAt,
); err != nil {
return cooperationContract, err
... ... @@ -130,7 +128,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
Org: undertaker.Org,
Orgs: undertaker.Orgs,
Department: undertaker.Department,
Role: undertaker.Role,
Roles: undertaker.Roles,
UserInfo: undertaker.UserInfo,
UserType: undertaker.UserType,
Referrer: undertaker.Referrer,
... ... @@ -223,7 +221,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.Operator,
cooperationContract.OperateTime,
cooperationContract.CreatedAt,
cooperationContract.DeletedAt,
nil,
cooperationContract.UpdatedAt,
cooperationContract.Identify(),
); err != nil {
... ... @@ -352,7 +350,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Role: undertakerDomain.Role,
Roles: undertakerDomain.Roles,
UserInfo: undertakerDomain.UserInfo,
UserType: undertakerDomain.UserType,
Status: undertakerDomain.Status,
... ...
... ... @@ -67,7 +67,7 @@ func (repository *CooperationContractUndertakerRepository) Save(cooperationContr
&cooperationContractUndertaker.Undertaker.Org,
&cooperationContractUndertaker.Undertaker.Orgs,
&cooperationContractUndertaker.Undertaker.Department,
&cooperationContractUndertaker.Undertaker.Role,
&cooperationContractUndertaker.Undertaker.Roles,
&cooperationContractUndertaker.Undertaker.UserInfo,
&cooperationContractUndertaker.Undertaker.UserType,
&cooperationContractUndertaker.Undertaker.Referrer,
... ... @@ -87,7 +87,7 @@ func (repository *CooperationContractUndertakerRepository) Save(cooperationContr
&cooperationContractUndertaker.Undertaker.Org,
&cooperationContractUndertaker.Undertaker.Orgs,
&cooperationContractUndertaker.Undertaker.Department,
&cooperationContractUndertaker.Undertaker.Role,
&cooperationContractUndertaker.Undertaker.Roles,
&cooperationContractUndertaker.Undertaker.UserInfo,
&cooperationContractUndertaker.Undertaker.UserType,
&cooperationContractUndertaker.Undertaker.Referrer,
... ... @@ -111,7 +111,7 @@ func (repository *CooperationContractUndertakerRepository) Save(cooperationContr
&cooperationContractUndertaker.Undertaker.Org,
&cooperationContractUndertaker.Undertaker.Orgs,
&cooperationContractUndertaker.Undertaker.Department,
&cooperationContractUndertaker.Undertaker.Role,
&cooperationContractUndertaker.Undertaker.Roles,
&cooperationContractUndertaker.Undertaker.UserInfo,
&cooperationContractUndertaker.Undertaker.UserType,
&cooperationContractUndertaker.Undertaker.Referrer,
... ... @@ -131,7 +131,7 @@ func (repository *CooperationContractUndertakerRepository) Save(cooperationContr
cooperationContractUndertaker.Undertaker.Org,
cooperationContractUndertaker.Undertaker.Orgs,
cooperationContractUndertaker.Undertaker.Department,
cooperationContractUndertaker.Undertaker.Role,
cooperationContractUndertaker.Undertaker.Roles,
cooperationContractUndertaker.Undertaker.UserInfo,
cooperationContractUndertaker.Undertaker.UserType,
cooperationContractUndertaker.Undertaker.Referrer,
... ...
... ... @@ -94,7 +94,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
cooperationProject.OperateTime,
cooperationProject.Status,
cooperationProject.UpdatedAt,
cooperationProject.DeletedAt,
nil,
cooperationProject.CreatedAt,
); err != nil {
return cooperationProject, err
... ... @@ -136,7 +136,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
cooperationProject.OperateTime,
cooperationProject.Status,
cooperationProject.UpdatedAt,
cooperationProject.DeletedAt,
nil,
cooperationProject.CreatedAt,
cooperationProject.Identify(),
); err != nil {
... ...
... ... @@ -136,7 +136,7 @@ func (translator *UserTranslator) ToUndertakerFromRepresentation(user *UserDetai
Org: nil,
Orgs: nil,
Department: nil,
Role: nil,
Roles: nil,
UserInfo: nil,
UserType: 0,
Status: 0,
... ...
... ... @@ -14,7 +14,6 @@ func (controller *CooperationModeController) CreateCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
createCooperationModeCommand := &command.CreateCooperationModeCommand{}
_ = controller.Unmarshal(createCooperationModeCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
createCooperationModeCommand.CompanyId = header.CompanyId
createCooperationModeCommand.OrgId = header.OrgId
... ... @@ -28,7 +27,6 @@ func (controller *CooperationModeController) UpdateCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
updateCooperationModeCommand := &command.UpdateCooperationModeCommand{}
_ = controller.Unmarshal(updateCooperationModeCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
updateCooperationModeCommand.CompanyId = header.CompanyId
updateCooperationModeCommand.OrgId = header.OrgId
... ... @@ -43,7 +41,6 @@ func (controller *CooperationModeController) UpdateCooperationMode() {
func (controller *CooperationModeController) GetCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
getCooperationModeQuery := &query.GetCooperationModeQuery{}
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
getCooperationModeQuery.CompanyId = header.CompanyId
getCooperationModeQuery.OrgId = header.OrgId
... ... @@ -59,7 +56,6 @@ func (controller *CooperationModeController) RemoveCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
removeCooperationModeCommand := &command.RemoveCooperationModeCommand{}
_ = controller.Unmarshal(removeCooperationModeCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
removeCooperationModeCommand.CompanyId = header.CompanyId
removeCooperationModeCommand.OrgId = header.OrgId
... ... @@ -75,7 +71,6 @@ func (controller *CooperationModeController) BatchRemoveCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
batchRemoveCooperationModeCommand := &command.BatchRemoveCooperationModeCommand{}
_ = controller.Unmarshal(batchRemoveCooperationModeCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
batchRemoveCooperationModeCommand.CompanyId = header.CompanyId
batchRemoveCooperationModeCommand.OrgId = header.OrgId
... ... @@ -89,7 +84,6 @@ func (controller *CooperationModeController) SearchCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
searchCooperationModeQuery := &query.SearchCooperationModeQuery{}
_ = controller.Unmarshal(searchCooperationModeQuery)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
searchCooperationModeQuery.CompanyId = header.CompanyId
searchCooperationModeQuery.OrgId = header.OrgId
... ... @@ -102,7 +96,6 @@ func (controller *CooperationModeController) SearchCooperationMode() {
func (controller *CooperationModeController) ListCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
listCooperationModeQuery := &query.ListCooperationModeQuery{}
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
listCooperationModeQuery.CompanyId = header.CompanyId
listCooperationModeQuery.OrgId = header.OrgId
... ... @@ -120,7 +113,6 @@ func (controller *CooperationModeController) OperateCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
operateCooperationModeCommand := &command.OperateCooperationModeCommand{}
_ = controller.Unmarshal(operateCooperationModeCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
operateCooperationModeCommand.CompanyId = header.CompanyId
operateCooperationModeCommand.OrgId = header.OrgId
... ... @@ -134,7 +126,6 @@ func (controller *CooperationModeController) BatchOperateCooperationMode() {
cooperationModeService := service.NewCooperationModeService(nil)
batchOperateCooperationModeCommand := &command.BatchOperateCooperationModeCommand{}
_ = controller.Unmarshal(batchOperateCooperationModeCommand)
// 解析头部信息
header := controller.GetRequestHeader(controller.Ctx)
batchOperateCooperationModeCommand.CompanyId = header.CompanyId
batchOperateCooperationModeCommand.OrgId = header.OrgId
... ...