From 370cda6a41572b84b6451f801c127d2a217428c5 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 24 Jul 2024 14:28:29 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20base=20permission=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/system/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/system/views.py b/apps/system/views.py index eb2db1b7..e6cf46f6 100755 --- a/apps/system/views.py +++ b/apps/system/views.py @@ -301,7 +301,7 @@ class PermissionViewSet(CustomModelViewSet): create_serializer_class = PermissionCreateUpdateSerializer update_serializer_class = PermissionCreateUpdateSerializer partial_update_serializer_class = PermissionCreateUpdateSerializer - search_fields = ['name', 'code'] + search_fields = ['name', 'codes'] ordering = ['sort', 'create_time'] @action(methods=['get'], detail=False, permission_classes=[IsAuthenticated]) From eb81c2db2dedbc29dc7b34c923a46d7bbcf50244 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 25 Jul 2024 15:38:25 +0800 Subject: [PATCH 2/7] =?UTF-8?q?fix:=20base=20get=5Fticket=5Fstate=5Fpartic?= =?UTF-8?q?ipant=5Finfo=20=20=E9=80=9A=E8=BF=87=E5=B7=A5=E5=8D=95=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E8=8E=B7=E5=8F=96=E5=A4=84=E7=90=86=E4=BA=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wf/services.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/wf/services.py b/apps/wf/services.py index 4ac0ad69..739375d5 100755 --- a/apps/wf/services.py +++ b/apps/wf/services.py @@ -153,8 +153,12 @@ class WfService(object): multi_all_person_dict = {} destination_participant_type, destination_participant = state.participant_type, state.participant if destination_participant_type == State.PARTICIPANT_TYPE_FIELD: - destination_participant = new_ticket_data.get(destination_participant, 0) if destination_participant \ - in new_ticket_data else Ticket.ticket_data.get(destination_participant, 0) + if destination_participant in new_ticket_data: + destination_participant = new_ticket_data.get(destination_participant, 0) + elif destination_participant in ticket.ticket_data: + destination_participant = ticket.ticket_data.get(destination_participant, 0) + elif hasattr(ticket, destination_participant): + destination_participant = getattr(ticket, destination_participant) elif destination_participant_type == State.PARTICIPANT_TYPE_FORMCODE: # 代码获取 module, func = destination_participant.rsplit(".", 1) From cab46ea229ce8130234598a4c8509a536a2e9088 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 25 Jul 2024 18:40:55 +0800 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20base=20handle=5Fparent=E6=97=B6?= =?UTF-8?q?=E8=A6=81=E5=A4=84=E7=90=86=E6=89=80=E6=9C=89=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E7=88=B6=E5=AD=90=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/utils/models.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/utils/models.py b/apps/utils/models.py index 4add5eb4..0313c2cd 100755 --- a/apps/utils/models.py +++ b/apps/utils/models.py @@ -61,6 +61,10 @@ class ParentModel(models.Model): def init_parent_link(self): link = [] + try: + p = self.parent + except Exception: + self.parent = None if self.parent is not None: if self.parent == self: raise Exception(f'{self.__class__.__name__}-{self.id}-存在循环引用') @@ -87,9 +91,12 @@ class ParentModel(models.Model): 处理父级关系 """ self.parent_link = self.init_parent_link() - self.__class__.objects.filter(parent=self.id).update( - parent_link = self.parent_link + [self.id] - ) + # 处理相关的所有父子关系 + relats = self.__class__.objects.filter(parent_link__contains=[self.id]) + for relat in relats: + relat.parent_link = relat.init_parent_link() + relat.save() + class Meta: abstract = True From 7df2cbba1e134c950004ba4b27b29b766bfda047 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 26 Jul 2024 08:52:24 +0800 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20base=20=E5=A4=84=E7=90=86=E7=88=B6?= =?UTF-8?q?=E7=BA=A7=E5=BC=95=E7=94=A8parent=5Flink=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/utils/models.py | 50 ++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/apps/utils/models.py b/apps/utils/models.py index 0313c2cd..2ffd4464 100755 --- a/apps/utils/models.py +++ b/apps/utils/models.py @@ -61,10 +61,6 @@ class ParentModel(models.Model): def init_parent_link(self): link = [] - try: - p = self.parent - except Exception: - self.parent = None if self.parent is not None: if self.parent == self: raise Exception(f'{self.__class__.__name__}-{self.id}-存在循环引用') @@ -81,21 +77,18 @@ class ParentModel(models.Model): raise Exception(f'{self.__class__.__name__}-{self.id}-最多支持四级') return link - def handle_parent(self, is_create:bool): + def handle_parent(self): if hasattr(self, "parent_link"): - old_parent = None - if not is_create: - old_parent = self.__class__.objects.get(id=self.id).parent - if old_parent != self.parent: - """ - 处理父级关系 - """ - self.parent_link = self.init_parent_link() - # 处理相关的所有父子关系 - relats = self.__class__.objects.filter(parent_link__contains=[self.id]) - for relat in relats: - relat.parent_link = relat.init_parent_link() - relat.save() + """ + 处理父级关系 + """ + self.parent_link = self.init_parent_link() + self.save(update_fields=['parent_link']) + # 处理相关的所有父子关系 + relats = self.__class__.objects.filter(parent_link__contains=[self.id]) + for relat in relats: + relat.parent_link = relat.init_parent_link() + relat.save(update_fields=['parent_link']) class Meta: @@ -127,17 +120,28 @@ class BaseModel(models.Model): is_create = True self.id = idWorker.get_id() with transaction.atomic(): - # 处理父级 - self.handle_parent(is_create) - + old_parent = None + need_handle_parent = False + if hasattr(self, "parent"): + try: + old_parent = self.__class__.objects.get(id=self.id).parent + except Exception: + self.parent = None + need_handle_parent = True + if self.parent != old_parent: + need_handle_parent = True try: - return super().save(*args, **kwargs) + ins = super().save(*args, **kwargs) except IntegrityError as e: if is_create: time.sleep(0.01) self.id = idWorker.get_id() - return super().save(*args, **kwargs) + ins = super().save(*args, **kwargs) raise e + # 处理父级 + if need_handle_parent: + self.handle_parent() + return ins class SoftModel(BaseModel): From b6d4b38103efc6aab19cc7e246854b63b7233f59 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 25 Jul 2024 16:00:11 +0800 Subject: [PATCH 5/7] =?UTF-8?q?fix:=20base=20get=5Fticket=5Fstate=5Fpartic?= =?UTF-8?q?ipant=5Finfo=20=20=E9=80=9A=E8=BF=87=E5=B7=A5=E5=8D=95=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E8=8E=B7=E5=8F=96=E5=A4=84=E7=90=86=E4=BA=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wf/services.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wf/services.py b/apps/wf/services.py index 739375d5..fc17c0fb 100755 --- a/apps/wf/services.py +++ b/apps/wf/services.py @@ -158,7 +158,7 @@ class WfService(object): elif destination_participant in ticket.ticket_data: destination_participant = ticket.ticket_data.get(destination_participant, 0) elif hasattr(ticket, destination_participant): - destination_participant = getattr(ticket, destination_participant) + destination_participant = getattr(ticket, destination_participant).id elif destination_participant_type == State.PARTICIPANT_TYPE_FORMCODE: # 代码获取 module, func = destination_participant.rsplit(".", 1) From 23d452fe2c4e5961fe4bbb2b3d45f9e7644ad693 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 26 Jul 2024 10:06:31 +0800 Subject: [PATCH 6/7] =?UTF-8?q?fix:=20mgroup=5Frun=5Fchange=20=E5=86=8D?= =?UTF-8?q?=E4=BB=8E=E5=BC=80=E5=88=B0=E5=81=9C=E6=97=B6=E5=86=8D=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=B8=80=E6=AC=A1last=5Fstlog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/mtm/services.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/mtm/services.py b/apps/mtm/services.py index 1e8876d4..250ce679 100644 --- a/apps/mtm/services.py +++ b/apps/mtm/services.py @@ -122,7 +122,9 @@ def mgroup_run_change(mgroup: Mgroup, new_run: bool, last_timex: datetime): last_stlog.save() cal_exp_duration_sec(last_stlog.id) # 触发时间分配 elif last_stlog.end_time and new_run is False and last_timex > last_stlog.end_time: # 从开到停 - StLog.objects.create(title="停机", is_shutdown=True, mgroup=mgroup, end_time=None, start_time=last_timex, sflog=get_sflog(mgroup, last_timex)) + last_stlog2 = StLog.objects.filter(mgroup=mgroup, is_shutdown=True).order_by("-start_time").first() + if not last_stlog2: + StLog.objects.create(title="停机", is_shutdown=True, mgroup=mgroup, end_time=None, start_time=last_timex, sflog=get_sflog(mgroup, last_timex)) elif new_run is False: StLog.objects.create(title="停机", is_shutdown=True, mgroup=mgroup, end_time=None, start_time=last_timex, sflog=get_sflog(mgroup, last_timex)) mgroup.is_running = False From 9c27ffd7dde38700e182f734d878e0d40ce98a71 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 26 Jul 2024 16:56:29 +0800 Subject: [PATCH 7/7] =?UTF-8?q?feat:=20testitem=20=E5=A2=9E=E5=88=A0?= =?UTF-8?q?=E6=94=B9=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/qm/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/qm/views.py b/apps/qm/views.py index 334abb9d..6b976d86 100644 --- a/apps/qm/views.py +++ b/apps/qm/views.py @@ -16,13 +16,12 @@ from django.db import transaction # Create your views here. -class TestItemViewSet(ListModelMixin, CustomGenericViewSet): +class TestItemViewSet(CustomModelViewSet): """ list:质检项目 质检项目 """ - perms_map = {'get': '*'} queryset = TestItem.objects.all() serializer_class = TestItemSerializer filterset_class = TestItemFilter