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( response = super().finalize_response(
request, response, *args, **kwargs request, response, *args, **kwargs
) )
self.log["response_ms"] = self._get_response_ms()
# Ensure backward compatibility for those using _should_log hook # Ensure backward compatibility for those using _should_log hook
should_log = ( should_log = (
self._should_log if hasattr(self, "_should_log") else self.should_log self._should_log if hasattr(self, "_should_log") else self.should_log
@ -353,7 +354,7 @@ class MyLoggingMixin(object):
"method": request.method, "method": request.method,
"query_params": self._clean_data(request.query_params.dict()), "query_params": self._clean_data(request.query_params.dict()),
"user": self._get_user(request), "user": self._get_user(request),
"response_ms": self._get_response_ms(), # "response_ms": self._get_response_ms(),
"response": self._clean_data(rendered_content), "response": self._clean_data(rendered_content),
"status_code": response.status_code, "status_code": response.status_code,
"agent": self._get_agent(request), "agent": self._get_agent(request),
@ -447,7 +448,8 @@ class MyLoggingMixin(object):
By default, check if the request method is in logging_methods. 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 \ 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): 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.submit_user = user
mlog.stored_notok = stored_notok mlog.stored_notok = stored_notok
mlog.stored_mgroup = stored_mgroup mlog.stored_mgroup = stored_mgroup
if mlog.work_end_time is None:
mlog.work_end_time = now
mlog.save() mlog.save()
# 更新任务进度 # 更新任务进度

View File

@ -454,6 +454,7 @@ class MlogViewSet(CustomModelViewSet):
return Response(res) return Response(res)
@action(methods=['post'], detail=False, perms_map={'post': 'mlog.create'}, serializer_class=MlogQuickSerializer) @action(methods=['post'], detail=False, perms_map={'post': 'mlog.create'}, serializer_class=MlogQuickSerializer)
@transaction.atomic
def quick(self, request, *args, **kwargs): def quick(self, request, *args, **kwargs):
"""快速创建日志 """快速创建日志
@ -848,35 +849,36 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
mlogbin = mlogbin_parent mlogbin = mlogbin_parent
else: else:
xcount = math.floor( (mlogbin.count_use-mlogbin.count_pn_jgqbl) / div_number) xcount = math.floor( (mlogbin.count_use-mlogbin.count_pn_jgqbl) / div_number)
d_count_real = xcount if xcount >0:
d_count_ok = xcount d_count_real = xcount
number_to_batch = process.number_to_batch d_count_ok = xcount
if not number_to_batch: number_to_batch = process.number_to_batch
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok, "count_ok_full": d_count_ok})) if not number_to_batch:
mlogbout.count_json_from = mlogbin.count_json_from mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok, "count_ok_full": d_count_ok}))
mlogbout.save(update_fields=["count_json_from"]) mlogbout.count_json_from = mlogbin.count_json_from
wpr_number_rule = process.wpr_number_rule mlogbout.save(update_fields=["count_json_from"])
if material_out.tracking == Material.MA_TRACKING_SINGLE: wpr_number_rule = process.wpr_number_rule
number = mlogbin.batch if material_out.tracking == Material.MA_TRACKING_SINGLE:
if mlogbin.number_from: number = mlogbin.batch
number = mlogbin.number_from if mlogbin.number_from:
if d_count_real == 1: number = mlogbin.number_from
if wpr_number_rule: if d_count_real == 1:
number = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog)
if number_to_batch:
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": number}))
Mlogbw.objects.get_or_create(number=number, mlogb=mlogbout)
else:
if wpr_number_rule:
number_list = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog, gen_count=d_count_real)
for i in range(d_count_real):
if wpr_number_rule: if wpr_number_rule:
numberx = number_list[i] number = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog)
else:
numberx = f'{number}-{i+1}'
if number_to_batch: if number_to_batch:
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": numberx})) mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": number}))
Mlogbw.objects.get_or_create(number=numberx, mlogb=mlogbout) Mlogbw.objects.get_or_create(number=number, mlogb=mlogbout)
else:
if wpr_number_rule:
number_list = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog, gen_count=d_count_real)
for i in range(d_count_real):
if wpr_number_rule:
numberx = number_list[i]
else:
numberx = f'{number}-{i+1}'
if number_to_batch:
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": numberx}))
Mlogbw.objects.get_or_create(number=numberx, mlogb=mlogbout)
else: else:
raise ParseError("不支持生成产出物料!") raise ParseError("不支持生成产出物料!")
mlog.cal_mlog_count_from_mlogb() mlog.cal_mlog_count_from_mlogb()
@ -896,13 +898,13 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
m_model = material_out.model m_model = material_out.model
# 按生产日志查询 # 按生产日志查询
wpr = Wpr.objects.filter(wpr_mlogbw__mlogb__material_out__isnull=False, 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__is_fix=False,
wpr_mlogbw__mlogb__mlog__submit_time__isnull=False, wpr_mlogbw__mlogb__mlog__submit_time__isnull=False,
wpr_mlogbw__mlogb__mlog__handle_date__year=c_year, wpr_mlogbw__mlogb__mlog__handle_date__year=c_year,
wpr_mlogbw__mlogb__mlog__handle_date__month=c_month).order_by("number").last() wpr_mlogbw__mlogb__mlog__handle_date__month=c_month).order_by("number").last()
cq_w = 4 cq_w = 4
if '02d' in rule: if 'n_count:02d' in rule:
cq_w = 2 cq_w = 2
n_count = 0 n_count = 0
if wpr: if wpr:
@ -997,7 +999,10 @@ class MlogbwViewSet(CustomModelViewSet):
else: else:
if mlog != ins.mlogb.mlog: if mlog != ins.mlogb.mlog:
raise ParseError("所有记录必须属于同一张日志") raise ParseError("所有记录必须属于同一张日志")
wpr:Wpr = ins.wpr
mlogb:Mlogb = ins.mlogb mlogb:Mlogb = ins.mlogb
if wpr.wm != mlogb.wm_in:
raise ParseError("单个与所属批次不一致")
route:Route = mlogb.route if mlogb.route else mlog.route route:Route = mlogb.route if mlogb.route else mlog.route
Mlogbw.cal_count_notok(mlogb) Mlogbw.cal_count_notok(mlogb)
# 如果是输入且输出追踪到个,需同步创建 # 如果是输入且输出追踪到个,需同步创建