:art: Opt refreshs2

huangqimin 5 年 前
コミット
75e246759d
共有1 個のファイルを変更した13 個の追加10 個の削除を含む
  1. 13 10
      pre/views.py

+ 13 - 10
pre/views.py

@@ -4,6 +4,7 @@ from __future__ import division
4 4
 
5 5
 import xlrd
6 6
 from django.conf import settings
7
+from django.db import transaction
7 8
 from pysnippets.strsnippets import strip
8 9
 from TimeConvert import TimeConvert as tc
9 10
 
@@ -239,6 +240,7 @@ def fill_ym():
239 240
             ssi.save()
240 241
 
241 242
 
243
+@transaction.atomic
242 244
 def refreshs():
243 245
     ConsumeUserStatisticInfo.objects.all().delete()
244 246
     ConsumeSaleStatisticInfo.objects.all().delete()
@@ -255,21 +257,21 @@ def refreshs():
255 257
         except ModelInfo.DoesNotExist:
256 258
             continue
257 259
 
258
-        cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(
260
+        cusi, _ = ConsumeUserStatisticInfo.objects.select_for_update().get_or_create(
259 261
             brand_id=mdl.brand_id,
260 262
             ymd=ymd,
261 263
         )
262 264
         cusi.users = list(set(cusi.users + [log.user_id]))
263 265
         cusi.num = len(cusi.users)
264 266
         cusi.save()
265
-        cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(
267
+        cusi, _ = ConsumeUserStatisticInfo.objects.select_for_update().get_or_create(
266 268
             brand_id=mdl.brand_id,
267 269
             ymd=ymd[:6],
268 270
         )
269 271
         cusi.users = list(set(cusi.users + [log.user_id]))
270 272
         cusi.num = len(cusi.users)
271 273
         cusi.save()
272
-        cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(
274
+        cusi, _ = ConsumeUserStatisticInfo.objects.select_for_update().get_or_create(
273 275
             brand_id=mdl.brand_id,
274 276
             ymd=ymd[:4],
275 277
         )
@@ -277,19 +279,19 @@ def refreshs():
277 279
         cusi.num = len(cusi.users)
278 280
         cusi.save()
279 281
 
280
-        cssi, _ = ConsumeSaleStatisticInfo.objects.get_or_create(
282
+        cssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(
281 283
             brand_id=mdl.brand_id,
282 284
             ymd=ymd,
283 285
         )
284 286
         cssi.num += 1
285 287
         cssi.save()
286
-        cssi, _ = ConsumeSaleStatisticInfo.objects.get_or_create(
288
+        cssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(
287 289
             brand_id=mdl.brand_id,
288 290
             ymd=ymd[:6],
289 291
         )
290 292
         cssi.num += 1
291 293
         cssi.save()
292
-        cssi, _ = ConsumeSaleStatisticInfo.objects.get_or_create(
294
+        cssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(
293 295
             brand_id=mdl.brand_id,
294 296
             ymd=ymd[:4],
295 297
         )
@@ -297,7 +299,7 @@ def refreshs():
297 299
         cssi.save()
298 300
 
299 301
         # 日型号销量统计
300
-        cmssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create(
302
+        cmssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(
301 303
             brand_id=mdl.brand_id,
302 304
             model_name=mdl.model_uni_name,
303 305
             ymd=ymd,
@@ -305,7 +307,7 @@ def refreshs():
305 307
         cmssi.num += 1
306 308
         cmssi.save()
307 309
         # 月型号销量统计
308
-        cmssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create(
310
+        cmssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(
309 311
             brand_id=mdl.brand_id,
310 312
             model_name=mdl.model_uni_name,
311 313
             ymd=ymd[:6],
@@ -313,7 +315,7 @@ def refreshs():
313 315
         cmssi.num += 1
314 316
         cmssi.save()
315 317
         # 年型号销量统计
316
-        cmssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create(
318
+        cmssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(
317 319
             brand_id=mdl.brand_id,
318 320
             model_name=mdl.model_uni_name,
319 321
             ymd=ymd[:4],
@@ -331,6 +333,7 @@ def refreshs():
331 333
         })
332 334
 
333 335
 
336
+@transaction.atomic
334 337
 def refreshs2():
335 338
     SaleStatisticInfo.objects.all().delete()
336 339
     ModelSaleStatisticInfo.objects.all().delete()
@@ -354,7 +357,7 @@ def refreshs2():
354 357
             continue
355 358
 
356 359
         try:
357
-            clerk = SaleclerkInfo.objects.select_for_update().get(clerk_id=log.clerk_id, status=True)
360
+            clerk = SaleclerkInfo.objects.get(clerk_id=log.clerk_id, status=True)
358 361
         except SaleclerkInfo.DoesNotExist:
359 362
             continue
360 363