Merge branch 'master' of https://e.coding.net/ctcdevteam/ehs/ehs_server
This commit is contained in:
commit
01539a32da
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -172,12 +172,12 @@ class Qct(CommonAModel):
|
|||
return QctMat.objects.filter(qct=self)
|
||||
|
||||
@classmethod
|
||||
def get(cls, material:Material, tag:str):
|
||||
def get(cls, materialId:str, tag:str):
|
||||
try:
|
||||
qct = Qct.objects.get(qctmat__material=material, tags__contains=tag)
|
||||
qct = Qct.objects.get(qctmat__material__id=materialId, tags__contains=tag)
|
||||
except Qct.DoesNotExist:
|
||||
try:
|
||||
qct = Qct.objects.ge(name="通用检验表")
|
||||
qct = Qct.objects.get(name="默认检验表")
|
||||
except Qct.DoesNotExist:
|
||||
qct = None
|
||||
except Qct.MultipleObjectsReturned:
|
||||
|
@ -198,7 +198,7 @@ class Qct(CommonAModel):
|
|||
def get_qs(cls, materialId:str, tag:str):
|
||||
qct_qs = Qct.objects.filter(qctmat__material__id=materialId, tags__contains=tag)
|
||||
if not qct_qs.exists():
|
||||
qct_qs = Qct.objects.filter(tags__contains="default")
|
||||
qct_qs = Qct.objects.filter(name="默认检验表")
|
||||
return qct_qs
|
||||
|
||||
class QctTestItem(BaseModel):
|
||||
|
|
|
@ -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])
|
|
@ -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.
|
||||
|
||||
|
@ -53,10 +52,15 @@ class QctViewSet(CustomModelViewSet):
|
|||
|
||||
@action(methods=['post'], detail=False, perms_map={'post': '*'}, serializer_class=QctGetSerializer)
|
||||
@transaction.atomic
|
||||
def get_qs(self, request, *args, **kwargs):
|
||||
def get_qct(self, request, *args, **kwargs):
|
||||
"""
|
||||
获取检验模板
|
||||
|
||||
获取检验模板
|
||||
"""
|
||||
data = request.data
|
||||
qct_qs = Qct.get_qs(data["material"], data["tag"])
|
||||
return QctSerializer(instance=qct_qs, many=True).data
|
||||
qct = Qct.get(data["material"], data["tag"])
|
||||
return Response(QctDetailSerializer(instance=qct).data)
|
||||
|
||||
|
||||
class QctTestItemViewSet(CustomModelViewSet):
|
||||
|
@ -282,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):
|
||||
|
@ -294,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)
|
||||
|
|
|
@ -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,15 +923,12 @@ 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):
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
获取某个批次的整体生产数据并保存
|
||||
|
|
Loading…
Reference in New Issue