作者 陈志颖

合并分支 'dev' 到 'test'

fix:分红预算单取消修改



查看合并请求 !79
... ... @@ -28,6 +28,8 @@ type SearchDividendsEstimateQuery struct {
PageNumber int64 `cname:"页码" json:"pageNumber,omitempty"`
// 页面大小
PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
// 是否取消(删除)
IsCanceled bool `cname:"是否取消" json:"isCanceled,omitempty"`
}
func (searchDividendsEstimateQuery *SearchDividendsEstimateQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -1233,7 +1233,10 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g
} else {
dividendsEstimateRepository = value
}
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": getDividendsEstimateQuery.DividendsEstimateId})
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{
"dividendsEstimateId": getDividendsEstimateQuery.DividendsEstimateId,
"isCanceled": false,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -1350,6 +1353,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsEstimat
} else {
dividendsEstimateRepository = value
}
searchDividendsEstimateQuery.IsCanceled = false
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(tool_funs.SimpleStructToMap(searchDividendsEstimateQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -1125,6 +1125,7 @@ func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeD
// BatchRemoveDividendsOrder 批量移除分红订单实体对象
func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(batchRemoveDividendsOrderCommand *command.BatchRemoveDividendsOrderCommand) (interface{}, error) {
start := time.Now()
if err := batchRemoveDividendsOrderCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -1169,19 +1170,42 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
dividendsEstimateRepository = value
}
// 分红预算单DAO初始化
//var dividendsEstimateDao *dao.DividendsEstimateDao
//if value, err := factory.CreateDividendsEstimateDao(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//} else {
// dividendsEstimateDao = value
//}
// 分红退货单DAO初始化
//var dividendsReturnedOrderDao *dao.DividendsReturnedOrderDao
//if value, err := factory.CreateDividendsReturnedOrderDao(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//} else {
// dividendsReturnedOrderDao = value
//}
dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误")
}
if count, dividendsOrders, err := dividendsOrderRepository.Find(map[string]interface{}{
"dividendsOrderIds": dividendsOrderIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
fmt.Println("截止目前耗时1:", time.Since(start))
if count > 0 {
// 校验分红订单是否有退货单关联
for _, dividendsOrder := range dividendsOrders {
// 校验分红订单是否有关联的退货单
startCount := time.Now()
if countReturnedOrder, _, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
"dividendsOrderNumber": dividendsOrder.DividendsOrderNumber,
"companyId": dividendsOrder.Company.CompanyId,
... ... @@ -1194,13 +1218,29 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsOrder.DividendsOrderNumber))
}
}
fmt.Println("退货单计数:", time.Since(startCount))
//startCount := time.Now()
//if returnedOrderExist, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderExist(map[string]interface{}{
// "dividendsOrderNumber": dividendsOrder.DividendsOrderNumber,
// "companyId": dividendsOrder.Company.CompanyId,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// if returnedOrderExist {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsOrder.DividendsOrderNumber))
// }
//}
//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,
"offsetLimit": false,
"limit": 1,
"offset": 0,
"isCanceled": false,
}); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
... ... @@ -1209,15 +1249,34 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
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{}{
// "companyId": dividendsOrder.Company.CompanyId,
// "orgId": dividendsOrder.Org.OrgId,
// "orderOrReturnedOrderNum": dividendsOrder.DividendsOrderNumber,
// "isCanceled": false,
//}); err3 != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
//} else {
// if estimateOrderExist {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber))
// }
//}
//fmt.Println("预算单计数:", time.Since(startEstimateCount))
}
fmt.Println("截止目前耗时2:", time.Since(start))
dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
fmt.Println("截止目前耗时3:", time.Since(start))
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
fmt.Println("截止目前耗时4:", time.Since(start))
return dividendsOrdersRemoved, nil
} else {
return map[string]interface{}{}, nil
... ...
... ... @@ -68,6 +68,31 @@ func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderNumberAvailable(quer
return !ok, err
}
// CheckDividendsEstimateOrderExist 判断是否存在分红预算单
func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderExist(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
if orderOrReturnedOrderNum, ok := queryOptions["orderOrReturnedOrderNum"]; ok && orderOrReturnedOrderNum != "" {
query = query.Where("order_or_returned_order_num = ?", orderOrReturnedOrderNum)
}
if isCanceled, ok := queryOptions["isCanceled"]; ok {
query.Where("is_canceled = ?", isCanceled.(bool))
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
}
count, err := query.Count()
if count > 0 {
return true, err
} else {
return false, err
}
}
// UserEstimated 判断金额激励用户是否已分红(已生成分红预算单)
func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
... ...
... ... @@ -38,6 +38,28 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber(query
}
}
// CheckDividendsEstimateOrderExist 判断是否存在分红预算单
func (dao *DividendsReturnedOrderDao) CheckDividendsReturnedOrderExist(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
query := tx.Model(&dividendsReturnedOrderModels)
if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
query = query.Where("dividends_order_number = ?", dividendsOrderNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_returned_order.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_returned_order.org @> '{"orgId":"?"}'`, orgId)
}
count, err := query.Count()
if count > 0 {
return true, err
} else {
return false, err
}
}
// CheckDividendsReturnedOrderNumberAvailable 校验分红订单是否唯一
func (dao *DividendsReturnedOrderDao) CheckDividendsReturnedOrderNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
... ...
... ... @@ -93,7 +93,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId)
orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum] = append(orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum], dividendsEstimatesRelative[i].OrderGoodId)
}
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative)
//dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative)
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
if err3 != nil {
return nil, err3
}
... ... @@ -119,7 +120,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
dividendsEstimatesRelative[i].IsCanceled = true
dividendsEstimatesRelative[i].Operator = operator
}
dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative)
//dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative)
dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
if err4 != nil {
return nil, err4
}
... ...
... ... @@ -316,6 +316,9 @@ func (repository *DividendsEstimateRepository) FindOne(queryOptions map[string]i
if orderOrReturnedOrderNum, ok := queryOptions["orderOrReturnedOrderNum"]; ok && orderOrReturnedOrderNum != "" {
query.Where("order_or_returned_order_num = ?", orderOrReturnedOrderNum)
}
if isCanceled, ok := queryOptions["isCanceled"]; ok {
query.Where("is_canceled = ?", isCanceled.(bool))
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("分红预算单不存在")
... ...
... ... @@ -490,15 +490,6 @@ func (repository *DividendsOrderRepository) BatchRemove(dividendsOrders []*domai
} else {
for _, dividendsOrder := range dividendsOrders {
// 删除订单产品
//var orderGoodModels []*models.OrderGood
//if _, err := tx.Model(&orderGoodModels).
// Where("company_id = ?", dividendsOrder.Company.CompanyId).
// Where("org_id = ?", dividendsOrder.Org.OrgId).
// Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).WherePK().Delete(); err != nil {
// return nil, err
//}
// 删除订单产品
var orderGoodModels []*models.OrderGood
orderGoodQuery := tx.Model(&orderGoodModels)
if err := orderGoodQuery.
... ...