作者 陈志颖

feat:共创合约增加批量操作和批量删除

package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
)
type BatchOperateCooperationContractCommand struct {
// 公司ID,通过集成REST上下文获取
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" json:"userId,string" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId,string" valid:"Required"`
}
func (batchOperateCooperationContractCommand *BatchOperateCooperationContractCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchOperateCooperationContractCommand *BatchOperateCooperationContractCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchOperateCooperationContractCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchOperateCooperationContractCommand).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
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
)
type BatchRemoveCooperationContractCommand struct {
// 公司ID,通过集成REST上下文获取
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" json:"userId,string" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId,string" valid:"Required"`
}
func (batchRemoveCooperationContractCommand *BatchRemoveCooperationContractCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchRemoveCooperationContractCommand *BatchRemoveCooperationContractCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchRemoveCooperationContractCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchRemoveCooperationContractCommand).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
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
)
type OperateCooperationContractCommand struct {
// 公司ID,通过集成REST上下文获取
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" json:"userId,string" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId,string" valid:"Required"`
}
func (operateCooperationContractCommand *OperateCooperationContractCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (operateCooperationContractCommand *OperateCooperationContractCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(operateCooperationContractCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(operateCooperationContractCommand).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
}
... ...
... ... @@ -427,6 +427,69 @@ func (cooperationContractService *CooperationContractService) RemoveCooperationC
}
}
// BatchRemoveCooperationContract TODO 批量移除共创合约
func (cooperationContractService *CooperationContractService) BatchRemoveCooperationContract(batchRemoveCooperationContractCommand *command.BatchRemoveCooperationContractCommand) (interface{}, error) {
if err := batchRemoveCooperationContractCommand.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// OperateRemoveCooperationContract TODO 暂停或恢复共创合约
func (cooperationContractService *CooperationContractService) OperateCooperationContract(operateCooperationContractCommand *command.OperateCooperationContractCommand) (interface{}, error) {
if err := operateCooperationContractCommand.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// BatchOperateCooperationContract TODO 批量暂停或恢复共创合约
func (cooperationContractService *CooperationContractService) BatchOperateCooperationContract(batchOperateCooperationContractCommand *command.BatchOperateCooperationContractCommand) (interface{}, error) {
if err := batchOperateCooperationContractCommand.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// SearchCooperationContract 查询共创合约
func (cooperationContractService *CooperationContractService) SearchCooperationContract(searchCooperationContractQuery *query.SearchCooperationContractQuery) (interface{}, error) {
if err := searchCooperationContractQuery.ValidateQuery(); err != nil {
... ...
... ... @@ -20,6 +20,8 @@ type DividendsIncentivesRule struct {
DividendsIncentivesStageEnd time.Time `json:"dividendsIncentivesStageEnd"`
// 分红规则激励阶段开始
DividendsIncentivesStageStart time.Time `json:"dividendsIncentivesStageStart"`
// 分红激励规则说明
Remarks string `json:"remarks"`
// 数据所属组织机构
Org *Org `json:"org"`
// 公司
... ...
... ... @@ -22,6 +22,8 @@ type MoneyIncentivesRule struct {
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
// 分红激励规则说明
Remarks string `json:"remarks"`
// 数据所属组织机构
Org *Org `json:"org"`
// 公司
... ...
... ... @@ -23,6 +23,8 @@ type DividendsIncentivesRule struct {
DividendsIncentivesStageEnd time.Time `comment:"分红规则激励阶段结束"`
// 分红规则激励阶段开始
DividendsIncentivesStageStart time.Time `comment:"分红规则激励阶段开始"`
// 分红激励规则说明
Remarks string `comment:"分红激励规则说明"`
// 数据所属组织机构
Org *domain.Org `comment:"数据所属组织机构"`
// 公司
... ...
... ... @@ -25,6 +25,8 @@ type MoneyIncentivesRule struct {
ReferrerPercentage float64 `comment:"推荐人抽成比例"`
// 业务员抽成比例
SalesmanPercentage float64 `comment:"业务员抽成比例"`
// 分红激励规则说明
Remarks string `comment:"分红激励规则说明"`
// 数据所属组织机构
Org *domain.Org `comment:"数据所属组织机构"`
// 公司
... ...
... ... @@ -15,6 +15,7 @@ func TransformToDividendsIncentivesRuleDomainModelFromPgModels(dividendsIncentiv
DividendsIncentivesStage: dividendsIncentivesRuleModel.DividendsIncentivesStage,
DividendsIncentivesStageEnd: dividendsIncentivesRuleModel.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: dividendsIncentivesRuleModel.DividendsIncentivesStageStart,
Remarks: dividendsIncentivesRuleModel.Remarks,
Org: dividendsIncentivesRuleModel.Org,
Company: dividendsIncentivesRuleModel.Company,
UpdatedAt: dividendsIncentivesRuleModel.UpdatedAt,
... ...
... ... @@ -16,6 +16,7 @@ func TransformToMoneyIncentivesRuleDomainModelFromPgModels(moneyIncentivesRuleMo
MoneyIncentivesTime: moneyIncentivesRuleModel.MoneyIncentivesTime,
ReferrerPercentage: moneyIncentivesRuleModel.ReferrerPercentage,
SalesmanPercentage: moneyIncentivesRuleModel.SalesmanPercentage,
Remarks: moneyIncentivesRuleModel.Remarks,
Org: moneyIncentivesRuleModel.Org,
Company: moneyIncentivesRuleModel.Company,
UpdatedAt: moneyIncentivesRuleModel.UpdatedAt,
... ...
... ... @@ -34,6 +34,7 @@ func (repository *DividendsIncentivesRuleRepository) Save(dividendsIncentivesRul
"dividends_incentives_stage",
"dividends_incentives_stage_end",
"dividends_incentives_stage_start",
"remarks",
"org",
"company",
"updated_at",
... ... @@ -63,6 +64,7 @@ func (repository *DividendsIncentivesRuleRepository) Save(dividendsIncentivesRul
&dividendsIncentivesRule.DividendsIncentivesStage,
&dividendsIncentivesRule.DividendsIncentivesStageEnd,
&dividendsIncentivesRule.DividendsIncentivesStageStart,
&dividendsIncentivesRule.Remarks,
&dividendsIncentivesRule.Org,
&dividendsIncentivesRule.Company,
&dividendsIncentivesRule.UpdatedAt,
... ... @@ -78,6 +80,7 @@ func (repository *DividendsIncentivesRuleRepository) Save(dividendsIncentivesRul
dividendsIncentivesRule.DividendsIncentivesStage,
dividendsIncentivesRule.DividendsIncentivesStageEnd,
dividendsIncentivesRule.DividendsIncentivesStageStart,
dividendsIncentivesRule.Remarks,
dividendsIncentivesRule.Org,
dividendsIncentivesRule.Company,
dividendsIncentivesRule.UpdatedAt,
... ... @@ -97,6 +100,7 @@ func (repository *DividendsIncentivesRuleRepository) Save(dividendsIncentivesRul
&dividendsIncentivesRule.DividendsIncentivesStage,
&dividendsIncentivesRule.DividendsIncentivesStageEnd,
&dividendsIncentivesRule.DividendsIncentivesStageStart,
&dividendsIncentivesRule.Remarks,
&dividendsIncentivesRule.Org,
&dividendsIncentivesRule.Company,
&dividendsIncentivesRule.UpdatedAt,
... ... @@ -112,6 +116,7 @@ func (repository *DividendsIncentivesRuleRepository) Save(dividendsIncentivesRul
dividendsIncentivesRule.DividendsIncentivesStage,
dividendsIncentivesRule.DividendsIncentivesStageEnd,
dividendsIncentivesRule.DividendsIncentivesStageStart,
dividendsIncentivesRule.Remarks,
dividendsIncentivesRule.Org,
dividendsIncentivesRule.Company,
dividendsIncentivesRule.UpdatedAt,
... ...
... ... @@ -67,6 +67,45 @@ func (controller *CooperationContractController) RemoveCooperationContract() {
controller.Response(data, err)
}
func (controller *CooperationContractController) BatchRemoveCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
batchRemoveCooperationContractCommand := &command.BatchRemoveCooperationContractCommand{}
_ = controller.Unmarshal(batchRemoveCooperationContractCommand)
header := controller.GetRequestHeader(controller.Ctx)
batchRemoveCooperationContractCommand.CompanyId = header.CompanyId
batchRemoveCooperationContractCommand.OrgId = header.OrgId
batchRemoveCooperationContractCommand.UserId = header.UserId
batchRemoveCooperationContractCommand.UserBaseId = header.UserBaseId
data, err := cooperationContractService.BatchRemoveCooperationContract(batchRemoveCooperationContractCommand)
controller.Response(data, err)
}
func (controller *CooperationContractController) OperateCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
opreateCooperationContractCommand := &command.OperateCooperationContractCommand{}
_ = controller.Unmarshal(opreateCooperationContractCommand)
header := controller.GetRequestHeader(controller.Ctx)
opreateCooperationContractCommand.CompanyId = header.CompanyId
opreateCooperationContractCommand.OrgId = header.OrgId
opreateCooperationContractCommand.UserId = header.UserId
opreateCooperationContractCommand.UserBaseId = header.UserBaseId
data, err := cooperationContractService.OperateCooperationContract(opreateCooperationContractCommand)
controller.Response(data, err)
}
func (controller *CooperationContractController) BatchOperateCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
batchOperateCooperationContractCommand := &command.BatchOperateCooperationContractCommand{}
_ = controller.Unmarshal(batchOperateCooperationContractCommand)
header := controller.GetRequestHeader(controller.Ctx)
batchOperateCooperationContractCommand.CompanyId = header.CompanyId
batchOperateCooperationContractCommand.OrgId = header.OrgId
batchOperateCooperationContractCommand.UserId = header.UserId
batchOperateCooperationContractCommand.UserBaseId = header.UserBaseId
data, err := cooperationContractService.BatchOperateCooperationContract(batchOperateCooperationContractCommand)
controller.Response(data, err)
}
func (controller *CooperationContractController) SearchCooperationContract() {
cooperationContractService := service.NewCooperationContractService(nil)
searchCooperationContractQuery := &query.SearchCooperationContractQuery{}
... ...
... ... @@ -6,11 +6,14 @@ import (
)
func init() {
web.Router("/cooperation-contracts/", &controllers.CooperationContractController{}, "Post:CreateCooperationContract")
web.Router("/cooperation-contracts/:cooperationContractId", &controllers.CooperationContractController{}, "Put:UpdateCooperationContract")
web.Router("/cooperation-contracts/:cooperationContractId", &controllers.CooperationContractController{}, "Get:GetCooperationContract")
web.Router("/cooperation-contracts/:cooperationContractId", &controllers.CooperationContractController{}, "Delete:RemoveCooperationContract")
web.Router("/cooperation-contracts/search", &controllers.CooperationContractController{}, "Post:SearchCooperationContract")
web.Router("/cooperation-contracts/search-by-undertaker", &controllers.CooperationContractController{}, "Post:SearchCooperationContractByUndertaker")
web.Router("/cooperation-contracts/", &controllers.CooperationContractController{}, "Get:ListCooperationContract")
web.Router("/cooperation-contracts/", &controllers.CooperationContractController{}, "Post:CreateCooperationContract") // 新增共创合约
web.Router("/cooperation-contracts/:cooperationContractId", &controllers.CooperationContractController{}, "Put:UpdateCooperationContract") // 编辑共创合约
web.Router("/cooperation-contracts/:cooperationContractId", &controllers.CooperationContractController{}, "Get:GetCooperationContract") // 返回共创合约详情
web.Router("/cooperation-contracts/:cooperationContractId", &controllers.CooperationContractController{}, "Delete:RemoveCooperationContract") // 移除共创合约
web.Router("/cooperation-contracts/batch-remove", &controllers.CooperationContractController{}, "Post:BatchRemoveCooperationContract") // 批量移除共创合约
web.Router("/cooperation-contracts/operate", &controllers.CooperationContractController{}, "Post:OperateCooperationContract") // 暂停或恢复共创合约
web.Router("/cooperation-contracts/batch-operate", &controllers.CooperationContractController{}, "Post:BatchOperateCooperationContract") // 批量暂停或恢复共创合约
web.Router("/cooperation-contracts/search", &controllers.CooperationContractController{}, "Post:SearchCooperationContract") // 查询共创合约
web.Router("/cooperation-contracts/search-by-undertaker", &controllers.CooperationContractController{}, "Post:SearchCooperationContractByUndertaker") // 通过承接人查询共创合约
web.Router("/cooperation-contracts/", &controllers.CooperationContractController{}, "Get:ListCooperationContract") // 返回共创合约列表
}
... ...