作者 陈志颖

feat:分红订单仓储增加批量删除方法

... ... @@ -47,6 +47,7 @@ type DividendsOrder struct {
type DividendsOrderRepository interface {
Save(dividendsOrder *DividendsOrder) (*DividendsOrder, error)
Remove(dividendsOrder *DividendsOrder) (*DividendsOrder, error)
BatchRemove(dividendsOrders []*DividendsOrder) ([]*DividendsOrder, error)
FindOne(queryOptions map[string]interface{}) (*DividendsOrder, error)
Find(queryOptions map[string]interface{}) (int64, []*DividendsOrder, error)
}
... ...
... ... @@ -272,6 +272,28 @@ func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.Divide
return dividendsOrder, nil
}
func (repository *DividendsOrderRepository) BatchRemove(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) {
tx := repository.transactionContext.PgTx
var dividendsOrderModels []*models.DividendsOrder
for _, dividendsOrder := range dividendsOrders {
dividendsOrderModels = append(dividendsOrderModels, &models.DividendsOrder{
DividendsOrderId: dividendsOrder.Identify().(int64),
})
}
if _, err := tx.Model(&dividendsOrderModels).WherePK().Delete(); err != nil {
return dividendsOrders, err
} else {
for _, dividendsOrder := range dividendsOrders {
// 删除订单产品
var orderGoodModels []*models.OrderGood
if _, err := tx.Model(&orderGoodModels).Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil {
return nil, err
}
}
}
return dividendsOrders, nil
}
func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]interface{}) (*domain.DividendsOrder, error) {
tx := repository.transactionContext.PgTx
dividendsOrderModel := new(models.DividendsOrder)
... ... @@ -304,7 +326,10 @@ func (repository *DividendsOrderRepository) Find(queryOptions map[string]interfa
dividendsOrders := make([]*domain.DividendsOrder, 0)
query := sqlbuilder.BuildQuery(tx.Model(&dividendsOrderModels), queryOptions)
if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
query.Where("dividends_order_number like ?", fmt.Sprintf("%%%s%%", dividendsOrderNumber))
query.Where("dividends_order_number ilike ?", fmt.Sprintf("%%%s%%", dividendsOrderNumber))
}
if customerName, ok := queryOptions["customerName"]; ok && customerName != "" {
query.Where("customer_name like ?", fmt.Sprintf("%%%s%%", customerName))
}
offsetLimitFlag := true
if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
... ...
... ... @@ -70,6 +70,7 @@ func (controller *DividendsOrderController) RemoveDividendsOrder() {
func (controller *DividendsOrderController) SearchDividendsOrder() {
dividendsOrderService := service.NewDividendsOrderService(nil)
searchDividendsOrderQuery := &query.SearchDividendsOrderQuery{}
_ = controller.Unmarshal(searchDividendsOrderQuery)
header := controller.GetRequestHeader(controller.Ctx)
searchDividendsOrderQuery.CompanyId = header.CompanyId
searchDividendsOrderQuery.OrgId = header.OrgId
... ... @@ -82,6 +83,7 @@ func (controller *DividendsOrderController) SearchDividendsOrder() {
func (controller *DividendsOrderController) SearchDividendsOrderNumber() {
dividendsOrderService := service.NewDividendsOrderService(nil)
searchDividendsOrderNumberQuery := &query.SearchDividendsOrderNumberQuery{}
_ = controller.Unmarshal(searchDividendsOrderNumberQuery)
header := controller.GetRequestHeader(controller.Ctx)
searchDividendsOrderNumberQuery.CompanyId = header.CompanyId
searchDividendsOrderNumberQuery.OrgId = header.OrgId
... ...