This commit is contained in:
zty 2025-09-12 10:19:50 +08:00
commit 6d36f3fa7d
3 changed files with 40 additions and 31 deletions

View File

@ -325,6 +325,7 @@ class MyLoggingMixin(object):
response = super().finalize_response(
request, response, *args, **kwargs
)
self.log["response_ms"] = self._get_response_ms()
# Ensure backward compatibility for those using _should_log hook
should_log = (
self._should_log if hasattr(self, "_should_log") else self.should_log
@ -353,7 +354,7 @@ class MyLoggingMixin(object):
"method": request.method,
"query_params": self._clean_data(request.query_params.dict()),
"user": self._get_user(request),
"response_ms": self._get_response_ms(),
# "response_ms": self._get_response_ms(),
"response": self._clean_data(rendered_content),
"status_code": response.status_code,
"agent": self._get_agent(request),
@ -447,7 +448,8 @@ class MyLoggingMixin(object):
By default, check if the request method is in logging_methods.
"""
return self.logging_methods == "__all__" or response.status_code > 404 or response.status_code == 400 \
or (request.method in self.logging_methods and response.status_code not in [401, 403, 404])
or (request.method in self.logging_methods and response.status_code not in [401, 403, 404])\
or (self.log.get("response_ms", 0) > 2000)
def _clean_data(self, data):
"""

View File

@ -385,6 +385,8 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
mlog.submit_user = user
mlog.stored_notok = stored_notok
mlog.stored_mgroup = stored_mgroup
if mlog.work_end_time is None:
mlog.work_end_time = now
mlog.save()
# 更新任务进度

View File

@ -454,6 +454,7 @@ class MlogViewSet(CustomModelViewSet):
return Response(res)
@action(methods=['post'], detail=False, perms_map={'post': 'mlog.create'}, serializer_class=MlogQuickSerializer)
@transaction.atomic
def quick(self, request, *args, **kwargs):
"""快速创建日志
@ -848,6 +849,7 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
mlogbin = mlogbin_parent
else:
xcount = math.floor( (mlogbin.count_use-mlogbin.count_pn_jgqbl) / div_number)
if xcount >0:
d_count_real = xcount
d_count_ok = xcount
number_to_batch = process.number_to_batch
@ -896,13 +898,13 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
m_model = material_out.model
# 按生产日志查询
wpr = Wpr.objects.filter(wpr_mlogbw__mlogb__material_out__isnull=False,
wpr_mlogbw__mlogb__mlog__mgroup=mlog.mgroup,
wpr_mlogbw__mlogb__mlog__mgroup__process=mlog.mgroup.process,
wpr_mlogbw__mlogb__mlog__is_fix=False,
wpr_mlogbw__mlogb__mlog__submit_time__isnull=False,
wpr_mlogbw__mlogb__mlog__handle_date__year=c_year,
wpr_mlogbw__mlogb__mlog__handle_date__month=c_month).order_by("number").last()
cq_w = 4
if '02d' in rule:
if 'n_count:02d' in rule:
cq_w = 2
n_count = 0
if wpr:
@ -997,7 +999,10 @@ class MlogbwViewSet(CustomModelViewSet):
else:
if mlog != ins.mlogb.mlog:
raise ParseError("所有记录必须属于同一张日志")
wpr:Wpr = ins.wpr
mlogb:Mlogb = ins.mlogb
if wpr.wm != mlogb.wm_in:
raise ParseError("单个与所属批次不一致")
route:Route = mlogb.route if mlogb.route else mlog.route
Mlogbw.cal_count_notok(mlogb)
# 如果是输入且输出追踪到个,需同步创建