作者 陈志颖

feat:增加分红订单批量移除服务

package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
)
type BatchRemoveDividendsOrderCommand struct {
// 分红订单ID列表
DividendsOrderIds []string `cname:"分红订单ID列表" json:"dividendsOrderIds,omitempty"`
// 公司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 (batchRemoveDividendsOrderCommand *BatchRemoveDividendsOrderCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchRemoveDividendsOrderCommand *BatchRemoveDividendsOrderCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchRemoveDividendsOrderCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchRemoveDividendsOrderCommand).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
}
... ...
... ... @@ -307,6 +307,51 @@ func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeD
}
}
// BatchRemoveDividendsOrder 批量移除分红订单实体对象
func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(batchRemoveDividendsOrderCommand *command.BatchRemoveDividendsOrderCommand) (interface{}, error) {
if err := batchRemoveDividendsOrderCommand.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 dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsOrderRepository = value
}
dividendsOrderIds, _ := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds)
if count, dividendsOrders, err := dividendsOrderRepository.Find(map[string]interface{}{
"dividendsOrderIds": dividendsOrderIds,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders)
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 dividendsOrdersRemoved, nil
} else {
return map[string]interface{}{}, nil
}
}
}
// SearchDividendsOrder 查询分红订单方法
func (dividendsOrderService *DividendsOrderService) SearchDividendsOrder(searchDividendsOrderQuery *query.SearchDividendsOrderQuery) (interface{}, error) {
if err := searchDividendsOrderQuery.ValidateQuery(); err != nil {
... ...
... ... @@ -67,6 +67,19 @@ func (controller *DividendsOrderController) RemoveDividendsOrder() {
controller.Response(data, err)
}
func (controller *DividendsOrderController) BatchRemoveDividendsOrder() {
dividendsOrderService := service.NewDividendsOrderService(nil)
batchRemoveDividendsOrderCommand := &command.BatchRemoveDividendsOrderCommand{}
_ = controller.Unmarshal(batchRemoveDividendsOrderCommand)
header := controller.GetRequestHeader(controller.Ctx)
batchRemoveDividendsOrderCommand.CompanyId = header.CompanyId
batchRemoveDividendsOrderCommand.OrgId = header.OrgId
batchRemoveDividendsOrderCommand.UserId = header.UserId
batchRemoveDividendsOrderCommand.UserBaseId = header.UserBaseId
data, err := dividendsOrderService.BatchRemoveDividendsOrder(batchRemoveDividendsOrderCommand)
controller.Response(data, err)
}
func (controller *DividendsOrderController) SearchDividendsOrder() {
dividendsOrderService := service.NewDividendsOrderService(nil)
searchDividendsOrderQuery := &query.SearchDividendsOrderQuery{}
... ...