From 42a4332b8794061301079e9f1c63ab311c94077b Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 11 Sep 2025 15:53:36 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20base=20=E6=97=A5=E5=BF=97=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=AE=B0=E5=BD=95=E8=80=97=E6=97=B6=E5=A4=A7=E4=BA=8E?= =?UTF-8?q?2s=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/utils/mixins.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/utils/mixins.py b/apps/utils/mixins.py index d19bc326..9e4a277f 100755 --- a/apps/utils/mixins.py +++ b/apps/utils/mixins.py @@ -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): """ From aa72b0780a7fce123b5d40f99c949e0f5c2bb0e1 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 12 Sep 2025 09:11:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E5=BF=AB=E9=80=9F=E6=8A=A5?= =?UTF-8?q?=E5=B7=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/views.py | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/apps/wpm/views.py b/apps/wpm/views.py index dda7f01c..962a7d21 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -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,35 +849,36 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust mlogbin = mlogbin_parent else: xcount = math.floor( (mlogbin.count_use-mlogbin.count_pn_jgqbl) / div_number) - d_count_real = xcount - d_count_ok = xcount - number_to_batch = process.number_to_batch - if not 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})) - mlogbout.count_json_from = mlogbin.count_json_from - mlogbout.save(update_fields=["count_json_from"]) - wpr_number_rule = process.wpr_number_rule - if material_out.tracking == Material.MA_TRACKING_SINGLE: - number = mlogbin.batch - if mlogbin.number_from: - number = mlogbin.number_from - if d_count_real == 1: - if wpr_number_rule: - 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 xcount >0: + d_count_real = xcount + d_count_ok = xcount + number_to_batch = process.number_to_batch + if not 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})) + mlogbout.count_json_from = mlogbin.count_json_from + mlogbout.save(update_fields=["count_json_from"]) + wpr_number_rule = process.wpr_number_rule + if material_out.tracking == Material.MA_TRACKING_SINGLE: + number = mlogbin.batch + if mlogbin.number_from: + number = mlogbin.number_from + if d_count_real == 1: if wpr_number_rule: - numberx = number_list[i] - else: - numberx = f'{number}-{i+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": numberx})) - Mlogbw.objects.get_or_create(number=numberx, mlogb=mlogbout) + 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: + 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: raise ParseError("不支持生成产出物料!") mlog.cal_mlog_count_from_mlogb() @@ -896,7 +898,7 @@ 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, @@ -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) # 如果是输入且输出追踪到个,需同步创建 From c4c61ff73734ab4f909579526fdb27402e760628 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 12 Sep 2025 09:19:57 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E4=BA=A7=E7=94=9F=E7=BC=96=E5=8F=B7?= =?UTF-8?q?=E6=97=B6=E5=AD=98=E5=9C=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wpm/views.py b/apps/wpm/views.py index 962a7d21..97c49e67 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -904,7 +904,7 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust 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: From c9a2daaa489c10bd94ec26bcab316e819d4a3f0e Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 12 Sep 2025 10:11:25 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E9=BB=98=E8=AE=A4=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=97=B6=E9=97=B4=E4=B8=BA=E7=BB=93=E6=9D=9F=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/services.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/wpm/services.py b/apps/wpm/services.py index d0f39472..e3951aeb 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -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() # 更新任务进度