作者 陈志颖

refactor:优化批量删除分红订单

... ... @@ -1161,14 +1161,14 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
}
// 分红预算单仓储初始化
var dividendsEstimateRepository domain.DividendsEstimateRepository
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsEstimateRepository = value
}
//var dividendsEstimateRepository domain.DividendsEstimateRepository
//if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// dividendsEstimateRepository = value
//}
// 分红预算单DAO初始化
//var dividendsEstimateDao *dao.DividendsEstimateDao
... ... @@ -1234,22 +1234,22 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
//fmt.Println("退货单计数:", time.Since(startCount))
// 校验分红订单是否有分红预算
startEstimateCount := time.Now()
if countRelative, _, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
"companyId": dividendsOrder.Company.CompanyId,
"orgId": dividendsOrder.Org.OrgId,
"orderOrReturnedOrderNum": dividendsOrder.DividendsOrderNumber,
"limit": 1,
"offset": 0,
"isCanceled": false,
}); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
} else {
if countRelative > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber))
}
}
fmt.Println("预算单计数:", time.Since(startEstimateCount))
//startEstimateCount := time.Now()
//if countRelative, _, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
// "companyId": dividendsOrder.Company.CompanyId,
// "orgId": dividendsOrder.Org.OrgId,
// "orderOrReturnedOrderNum": dividendsOrder.DividendsOrderNumber,
// "limit": 1,
// "offset": 0,
// "isCanceled": false,
//}); err2 != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
//} else {
// if countRelative > 0 {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber))
// }
//}
//fmt.Println("预算单计数:", time.Since(startEstimateCount))
//startEstimateCount := time.Now()
//if estimateOrderExist, err3 := dividendsEstimateDao.CheckDividendsEstimateOrderExist(map[string]interface{}{
... ... @@ -1265,6 +1265,10 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
// }
//}
//fmt.Println("预算单计数:", time.Since(startEstimateCount))
if dividendsOrder.DividendStatus != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber))
}
}
fmt.Println("截止目前耗时2:", time.Since(start))
... ...