feat: 触发批次统计分析在线程里sleep下

This commit is contained in:
caoqianming 2025-05-14 12:57:11 +08:00
parent f32adf3702
commit 356310db3f
5 changed files with 33 additions and 35 deletions

View File

@ -4,10 +4,9 @@ from apps.inm.models import (MIO, MIOItem,
from rest_framework.exceptions import ParseError
from apps.mtm.models import Material, Process
from apps.utils.tools import ranstr
from apps.utils.thread import MyThread
from apps.mtm.services_2 import cal_material_count
from apps.wpm.models import WMaterial, BatchSt, BatchLog
from apps.wpm.services_2 import get_alldata_with_batch_and_store
from apps.wpm.services_2 import ana_batch_thread
from apps.wpmw.models import Wpr
from apps.qm.models import Ftest, Defect
from django.db.models import Count, Q
@ -123,10 +122,7 @@ def do_out(item: MIOItem):
Wpr.change_or_new(wpr=mioitemw.wpr, wm=wm, old_mb=mb)
# 触发批次统计分析
xbatches = list(set(xbatches))
if xbatches:
for xbatch in xbatches:
MyThread(target=get_alldata_with_batch_and_store, args=(xbatch,)).start()
ana_batch_thread(xbatches)
def do_in(item: MIOItem):
@ -257,9 +253,7 @@ def do_in(item: MIOItem):
MaterialBatchA.objects.create(mb=mb, material=mia.material, batch=mia.batch, rate=mia.rate)
# 批次统计分析
xbatchs = list(set(xbatchs))
for xbatch in xbatchs:
MyThread(target=get_alldata_with_batch_and_store, args=(xbatch,)).start()
ana_batch_thread(xbatchs)
class InmService:
@ -442,9 +436,7 @@ class InmService:
raise ParseError("不支持的操作")
# 批次统计分析
xbatchs = list(set(xbatchs))
for xbatch in xbatchs:
MyThread(target=get_alldata_with_batch_and_store, args=(xbatch,)).start()
ana_batch_thread(xbatchs)
def daoru_mb(path: str):
"""

View File

@ -5,8 +5,7 @@ from rest_framework.exceptions import ParseError
from django.utils import timezone
from apps.wf.models import Ticket
from apps.qm.models import NotOkOption, Defect
from apps.utils.thread import MyThread
from apps.wpm.services_2 import get_alldata_with_batch_and_store
from apps.wpm.services_2 import ana_batch_thread
def ftestwork_submit_validate(ins: FtestWork):
wm:WMaterial = ins.wm
@ -149,5 +148,4 @@ def bind_ftestwork(ticket: Ticket, transition, new_ticket_data: dict):
def ftestwork_audit_end(ticket: Ticket):
ins = FtestWork.objects.get(id=ticket.ticket_data['t_id'])
ftestwork_submit(ins, ticket.create_by)
if ins.batch:
MyThread(target=get_alldata_with_batch_and_store, args=(ins.batch,)).start()
ana_batch_thread(xbatchs=[ins.batch])

View File

@ -18,8 +18,7 @@ from apps.wpm.models import SfLog
from apps.qm.filters import QuaStatFilter, TestItemFilter, FtestWorkFilter, QctFilter, FtestFilter
from django.db import transaction
from apps.qm.services import ftestwork_submit
from apps.utils.thread import MyThread
from apps.wpm.services_2 import get_alldata_with_batch_and_store
from apps.wpm.services_2 import ana_batch_thread
from apps.wf.models import State
# Create your views here.
@ -287,8 +286,7 @@ class FtestWorkViewSet(CustomModelViewSet):
raise ParseError('审批单已进行,无法修改')
x = super().update(request, *args, **kwargs)
# 触发批次统计分析
if ins.batch:
MyThread(target=get_alldata_with_batch_and_store, args=(ins.batch,)).start()
ana_batch_thread(xbatchs=[ins.batch])
return x
def destroy(self, request, *args, **kwargs):
@ -299,15 +297,13 @@ class FtestWorkViewSet(CustomModelViewSet):
raise ParseError('存在审批, 无法删除')
x = super().destroy(request, *args, **kwargs)
# 触发批次统计分析
if ins.batch:
MyThread(target=get_alldata_with_batch_and_store, args=(ins.batch,)).start()
ana_batch_thread(xbatchs=[ins.batch])
return x
def perform_create(self, serializer):
ins = serializer.save()
# 触发批次统计分析
if ins.batch:
MyThread(target=get_alldata_with_batch_and_store, args=(ins.batch,)).start()
ana_batch_thread(xbatchs=[ins.batch])
@action(methods=['post'], detail=True, perms_map={'post': 'ftestwork.submit'}, serializer_class=Serializer)

View File

@ -14,9 +14,8 @@ from apps.mtm.models import Mgroup, Shift, Material, Route, RoutePack, Team, Sru
from .models import SfLog, WMaterial, Mlog, Mlogb, Mlogbw, Handover, Handoverb, Handoverbw, MlogbDefect, BatchLog, BatchSt
from apps.mtm.services_2 import cal_material_count
from apps.wf.models import Ticket
from apps.utils.thread import MyThread
import logging
from apps.wpm.services_2 import get_alldata_with_batch_and_store
from apps.wpm.services_2 import ana_batch_thread
from datetime import timedelta
from apps.wpmw.models import Wpr, WprDefect
from ..qm.models import Defect, Ftest
@ -379,8 +378,8 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
cal_material_count_from_mlog(mlog)
# 触发批次统计分析
if mlog.batch:
MyThread(target=get_alldata_with_batch_and_store, args=(mlog.batch,)).start()
xbatches = list(Mlogb.objects.filter(mlog=mlog).values_list('batch', flat=True))
ana_batch_thread(xbatches)
def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
@ -590,8 +589,8 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
BatchLog.clear(mlog=mlog)
# 触发批次统计分析
if mlog.batch:
MyThread(target=get_alldata_with_batch_and_store, args=(mlog.batch,)).start()
xbatches = list(Mlogb.objects.filter(mlog=mlog).values_list('batch', flat=True))
ana_batch_thread(xbatches)
def cal_mtask_progress_from_mlog(mlog):
"""
@ -924,16 +923,13 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
handover.recive_user = user
handover.save()
batches = list(set(batches))
if batches:
for batch in batches:
MyThread(target=get_alldata_with_batch_and_store, args=(batch,)).start()
# 如果是改版交接需要触发统计数量
if handover.type == Handover.H_CHANGE:
mids.append(handover.material_changed.id)
cal_material_count(mids)
ana_batch_thread(xbatchs=batches)
def handover_revert(handover:Handover):
BatchLog.clear(handover=handover)

View File

@ -9,9 +9,25 @@ from django.conf import settings
import json
from apps.utils.tools import MyJSONEncoder
import decimal
from apps.utils.thread import MyThread
import logging
import time
myLogger = logging.getLogger('log')
# 批次统计分析
def ana_batch_thread(xbatchs: list):
MyThread(target=ana_batch, args=(xbatchs,)).start()
def ana_batch(xbatchs: list):
"""
批次统计分析
"""
time.sleep(3)
xbatchs = list(set(xbatchs))
for xbatch in xbatchs:
get_alldata_with_batch_and_store(xbatch)
def get_alldata_with_batch_and_store(batch: str):
"""
获取某个批次的整体生产数据并保存