作者 陈志颖

合并分支 'dev' 到 'test'

fix:分红预算单取消修改



查看合并请求 !79
@@ -28,6 +28,8 @@ type SearchDividendsEstimateQuery struct { @@ -28,6 +28,8 @@ type SearchDividendsEstimateQuery struct {
28 PageNumber int64 `cname:"页码" json:"pageNumber,omitempty"` 28 PageNumber int64 `cname:"页码" json:"pageNumber,omitempty"`
29 // 页面大小 29 // 页面大小
30 PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"` 30 PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
  31 + // 是否取消(删除)
  32 + IsCanceled bool `cname:"是否取消" json:"isCanceled,omitempty"`
31 } 33 }
32 34
33 func (searchDividendsEstimateQuery *SearchDividendsEstimateQuery) Valid(validation *validation.Validation) { 35 func (searchDividendsEstimateQuery *SearchDividendsEstimateQuery) Valid(validation *validation.Validation) {
@@ -1233,7 +1233,10 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g @@ -1233,7 +1233,10 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g
1233 } else { 1233 } else {
1234 dividendsEstimateRepository = value 1234 dividendsEstimateRepository = value
1235 } 1235 }
1236 - dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": getDividendsEstimateQuery.DividendsEstimateId}) 1236 + dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{
  1237 + "dividendsEstimateId": getDividendsEstimateQuery.DividendsEstimateId,
  1238 + "isCanceled": false,
  1239 + })
1237 if err != nil { 1240 if err != nil {
1238 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1241 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1239 } 1242 }
@@ -1350,6 +1353,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsEstimat @@ -1350,6 +1353,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsEstimat
1350 } else { 1353 } else {
1351 dividendsEstimateRepository = value 1354 dividendsEstimateRepository = value
1352 } 1355 }
  1356 + searchDividendsEstimateQuery.IsCanceled = false
1353 if count, dividendsEstimates, err := dividendsEstimateRepository.Find(tool_funs.SimpleStructToMap(searchDividendsEstimateQuery)); err != nil { 1357 if count, dividendsEstimates, err := dividendsEstimateRepository.Find(tool_funs.SimpleStructToMap(searchDividendsEstimateQuery)); err != nil {
1354 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1358 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1355 } else { 1359 } else {
@@ -1125,6 +1125,7 @@ func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeD @@ -1125,6 +1125,7 @@ func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeD
1125 1125
1126 // BatchRemoveDividendsOrder 批量移除分红订单实体对象 1126 // BatchRemoveDividendsOrder 批量移除分红订单实体对象
1127 func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(batchRemoveDividendsOrderCommand *command.BatchRemoveDividendsOrderCommand) (interface{}, error) { 1127 func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(batchRemoveDividendsOrderCommand *command.BatchRemoveDividendsOrderCommand) (interface{}, error) {
  1128 + start := time.Now()
1128 if err := batchRemoveDividendsOrderCommand.ValidateCommand(); err != nil { 1129 if err := batchRemoveDividendsOrderCommand.ValidateCommand(); err != nil {
1129 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1130 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
1130 } 1131 }
@@ -1169,19 +1170,42 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba @@ -1169,19 +1170,42 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
1169 dividendsEstimateRepository = value 1170 dividendsEstimateRepository = value
1170 } 1171 }
1171 1172
  1173 + // 分红预算单DAO初始化
  1174 + //var dividendsEstimateDao *dao.DividendsEstimateDao
  1175 + //if value, err := factory.CreateDividendsEstimateDao(map[string]interface{}{
  1176 + // "transactionContext": transactionContext,
  1177 + //}); err != nil {
  1178 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1179 + //} else {
  1180 + // dividendsEstimateDao = value
  1181 + //}
  1182 +
  1183 + // 分红退货单DAO初始化
  1184 + //var dividendsReturnedOrderDao *dao.DividendsReturnedOrderDao
  1185 + //if value, err := factory.CreateDividendsReturnedOrderDao(map[string]interface{}{
  1186 + // "transactionContext": transactionContext,
  1187 + //}); err != nil {
  1188 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1189 + //} else {
  1190 + // dividendsReturnedOrderDao = value
  1191 + //}
  1192 +
1172 dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds) 1193 dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds)
1173 if err != nil { 1194 if err != nil {
1174 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误") 1195 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误")
1175 } 1196 }
  1197 +
1176 if count, dividendsOrders, err := dividendsOrderRepository.Find(map[string]interface{}{ 1198 if count, dividendsOrders, err := dividendsOrderRepository.Find(map[string]interface{}{
1177 "dividendsOrderIds": dividendsOrderIds, 1199 "dividendsOrderIds": dividendsOrderIds,
1178 "offsetLimit": false, 1200 "offsetLimit": false,
1179 }); err != nil { 1201 }); err != nil {
1180 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1202 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1181 } else { 1203 } else {
  1204 + fmt.Println("截止目前耗时1:", time.Since(start))
1182 if count > 0 { 1205 if count > 0 {
1183 - // 校验分红订单是否有退货单关联  
1184 for _, dividendsOrder := range dividendsOrders { 1206 for _, dividendsOrder := range dividendsOrders {
  1207 + // 校验分红订单是否有关联的退货单
  1208 + startCount := time.Now()
1185 if countReturnedOrder, _, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{ 1209 if countReturnedOrder, _, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
1186 "dividendsOrderNumber": dividendsOrder.DividendsOrderNumber, 1210 "dividendsOrderNumber": dividendsOrder.DividendsOrderNumber,
1187 "companyId": dividendsOrder.Company.CompanyId, 1211 "companyId": dividendsOrder.Company.CompanyId,
@@ -1194,13 +1218,29 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba @@ -1194,13 +1218,29 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
1194 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsOrder.DividendsOrderNumber)) 1218 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsOrder.DividendsOrderNumber))
1195 } 1219 }
1196 } 1220 }
  1221 + fmt.Println("退货单计数:", time.Since(startCount))
  1222 +
  1223 + //startCount := time.Now()
  1224 + //if returnedOrderExist, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderExist(map[string]interface{}{
  1225 + // "dividendsOrderNumber": dividendsOrder.DividendsOrderNumber,
  1226 + // "companyId": dividendsOrder.Company.CompanyId,
  1227 + //}); err != nil {
  1228 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1229 + //} else {
  1230 + // if returnedOrderExist {
  1231 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsOrder.DividendsOrderNumber))
  1232 + // }
  1233 + //}
  1234 + //fmt.Println("退货单计数:", time.Since(startCount))
1197 1235
1198 // 校验分红订单是否有分红预算 1236 // 校验分红订单是否有分红预算
  1237 + startEstimateCount := time.Now()
1199 if countRelative, _, err2 := dividendsEstimateRepository.Find(map[string]interface{}{ 1238 if countRelative, _, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
1200 "companyId": dividendsOrder.Company.CompanyId, 1239 "companyId": dividendsOrder.Company.CompanyId,
1201 "orgId": dividendsOrder.Org.OrgId, 1240 "orgId": dividendsOrder.Org.OrgId,
1202 "orderOrReturnedOrderNum": dividendsOrder.DividendsOrderNumber, 1241 "orderOrReturnedOrderNum": dividendsOrder.DividendsOrderNumber,
1203 - "offsetLimit": false, 1242 + "limit": 1,
  1243 + "offset": 0,
1204 "isCanceled": false, 1244 "isCanceled": false,
1205 }); err2 != nil { 1245 }); err2 != nil {
1206 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) 1246 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
@@ -1209,15 +1249,34 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba @@ -1209,15 +1249,34 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
1209 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber)) 1249 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber))
1210 } 1250 }
1211 } 1251 }
  1252 + fmt.Println("预算单计数:", time.Since(startEstimateCount))
  1253 +
  1254 + //startEstimateCount := time.Now()
  1255 + //if estimateOrderExist, err3 := dividendsEstimateDao.CheckDividendsEstimateOrderExist(map[string]interface{}{
  1256 + // "companyId": dividendsOrder.Company.CompanyId,
  1257 + // "orgId": dividendsOrder.Org.OrgId,
  1258 + // "orderOrReturnedOrderNum": dividendsOrder.DividendsOrderNumber,
  1259 + // "isCanceled": false,
  1260 + //}); err3 != nil {
  1261 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
  1262 + //} else {
  1263 + // if estimateOrderExist {
  1264 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber))
  1265 + // }
  1266 + //}
  1267 + //fmt.Println("预算单计数:", time.Since(startEstimateCount))
1212 } 1268 }
  1269 + fmt.Println("截止目前耗时2:", time.Since(start))
1213 1270
1214 dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders) 1271 dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders)
1215 if err != nil { 1272 if err != nil {
1216 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1273 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1217 } 1274 }
  1275 + fmt.Println("截止目前耗时3:", time.Since(start))
1218 if err := transactionContext.CommitTransaction(); err != nil { 1276 if err := transactionContext.CommitTransaction(); err != nil {
1219 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1277 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1220 } 1278 }
  1279 + fmt.Println("截止目前耗时4:", time.Since(start))
1221 return dividendsOrdersRemoved, nil 1280 return dividendsOrdersRemoved, nil
1222 } else { 1281 } else {
1223 return map[string]interface{}{}, nil 1282 return map[string]interface{}{}, nil
@@ -68,6 +68,31 @@ func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderNumberAvailable(quer @@ -68,6 +68,31 @@ func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderNumberAvailable(quer
68 return !ok, err 68 return !ok, err
69 } 69 }
70 70
  71 +// CheckDividendsEstimateOrderExist 判断是否存在分红预算单
  72 +func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderExist(queryOptions map[string]interface{}) (bool, error) {
  73 + tx := dao.transactionContext.PgTx
  74 + var dividendsEstimateModels []*models.DividendsEstimate
  75 + query := tx.Model(&dividendsEstimateModels)
  76 + if orderOrReturnedOrderNum, ok := queryOptions["orderOrReturnedOrderNum"]; ok && orderOrReturnedOrderNum != "" {
  77 + query = query.Where("order_or_returned_order_num = ?", orderOrReturnedOrderNum)
  78 + }
  79 + if isCanceled, ok := queryOptions["isCanceled"]; ok {
  80 + query.Where("is_canceled = ?", isCanceled.(bool))
  81 + }
  82 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  83 + query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
  84 + }
  85 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  86 + query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
  87 + }
  88 + count, err := query.Count()
  89 + if count > 0 {
  90 + return true, err
  91 + } else {
  92 + return false, err
  93 + }
  94 +}
  95 +
71 // UserEstimated 判断金额激励用户是否已分红(已生成分红预算单) 96 // UserEstimated 判断金额激励用户是否已分红(已生成分红预算单)
72 func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface{}) (bool, error) { 97 func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface{}) (bool, error) {
73 tx := dao.transactionContext.PgTx 98 tx := dao.transactionContext.PgTx
@@ -38,6 +38,28 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber(query @@ -38,6 +38,28 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber(query
38 } 38 }
39 } 39 }
40 40
  41 +// CheckDividendsEstimateOrderExist 判断是否存在分红预算单
  42 +func (dao *DividendsReturnedOrderDao) CheckDividendsReturnedOrderExist(queryOptions map[string]interface{}) (bool, error) {
  43 + tx := dao.transactionContext.PgTx
  44 + var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
  45 + query := tx.Model(&dividendsReturnedOrderModels)
  46 + if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
  47 + query = query.Where("dividends_order_number = ?", dividendsOrderNumber)
  48 + }
  49 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  50 + query = query.Where(`dividends_returned_order.company @> '{"companyId":"?"}'`, companyId)
  51 + }
  52 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  53 + query = query.Where(`dividends_returned_order.org @> '{"orgId":"?"}'`, orgId)
  54 + }
  55 + count, err := query.Count()
  56 + if count > 0 {
  57 + return true, err
  58 + } else {
  59 + return false, err
  60 + }
  61 +}
  62 +
41 // CheckDividendsReturnedOrderNumberAvailable 校验分红订单是否唯一 63 // CheckDividendsReturnedOrderNumberAvailable 校验分红订单是否唯一
42 func (dao *DividendsReturnedOrderDao) CheckDividendsReturnedOrderNumberAvailable(queryOptions map[string]interface{}) (bool, error) { 64 func (dao *DividendsReturnedOrderDao) CheckDividendsReturnedOrderNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
43 tx := dao.transactionContext.PgTx 65 tx := dao.transactionContext.PgTx
@@ -93,7 +93,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -93,7 +93,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
93 orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId) 93 orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId)
94 orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum] = append(orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum], dividendsEstimatesRelative[i].OrderGoodId) 94 orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum] = append(orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum], dividendsEstimatesRelative[i].OrderGoodId)
95 } 95 }
96 - dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative) 96 + //dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative)
  97 + dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
97 if err3 != nil { 98 if err3 != nil {
98 return nil, err3 99 return nil, err3
99 } 100 }
@@ -119,7 +120,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -119,7 +120,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
119 dividendsEstimatesRelative[i].IsCanceled = true 120 dividendsEstimatesRelative[i].IsCanceled = true
120 dividendsEstimatesRelative[i].Operator = operator 121 dividendsEstimatesRelative[i].Operator = operator
121 } 122 }
122 - dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative) 123 + //dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative)
  124 + dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
123 if err4 != nil { 125 if err4 != nil {
124 return nil, err4 126 return nil, err4
125 } 127 }
@@ -316,6 +316,9 @@ func (repository *DividendsEstimateRepository) FindOne(queryOptions map[string]i @@ -316,6 +316,9 @@ func (repository *DividendsEstimateRepository) FindOne(queryOptions map[string]i
316 if orderOrReturnedOrderNum, ok := queryOptions["orderOrReturnedOrderNum"]; ok && orderOrReturnedOrderNum != "" { 316 if orderOrReturnedOrderNum, ok := queryOptions["orderOrReturnedOrderNum"]; ok && orderOrReturnedOrderNum != "" {
317 query.Where("order_or_returned_order_num = ?", orderOrReturnedOrderNum) 317 query.Where("order_or_returned_order_num = ?", orderOrReturnedOrderNum)
318 } 318 }
  319 + if isCanceled, ok := queryOptions["isCanceled"]; ok {
  320 + query.Where("is_canceled = ?", isCanceled.(bool))
  321 + }
319 if err := query.First(); err != nil { 322 if err := query.First(); err != nil {
320 if err.Error() == "pg: no rows in result set" { 323 if err.Error() == "pg: no rows in result set" {
321 return nil, fmt.Errorf("分红预算单不存在") 324 return nil, fmt.Errorf("分红预算单不存在")
@@ -490,15 +490,6 @@ func (repository *DividendsOrderRepository) BatchRemove(dividendsOrders []*domai @@ -490,15 +490,6 @@ func (repository *DividendsOrderRepository) BatchRemove(dividendsOrders []*domai
490 } else { 490 } else {
491 for _, dividendsOrder := range dividendsOrders { 491 for _, dividendsOrder := range dividendsOrders {
492 // 删除订单产品 492 // 删除订单产品
493 - //var orderGoodModels []*models.OrderGood  
494 - //if _, err := tx.Model(&orderGoodModels).  
495 - // Where("company_id = ?", dividendsOrder.Company.CompanyId).  
496 - // Where("org_id = ?", dividendsOrder.Org.OrgId).  
497 - // Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).WherePK().Delete(); err != nil {  
498 - // return nil, err  
499 - //}  
500 -  
501 - // 删除订单产品  
502 var orderGoodModels []*models.OrderGood 493 var orderGoodModels []*models.OrderGood
503 orderGoodQuery := tx.Model(&orderGoodModels) 494 orderGoodQuery := tx.Model(&orderGoodModels)
504 if err := orderGoodQuery. 495 if err := orderGoodQuery.