feat: 移除mgroups_allocate字段

This commit is contained in:
caoqianming 2024-05-08 12:09:21 +08:00
parent 895b8c1810
commit 30974d90b0
5 changed files with 34 additions and 33 deletions

View File

@ -158,19 +158,19 @@ class CorrectViewSet(CustomGenericViewSet):
Opl.objects.filter(id=opl.id).update(number=sn)
return Response()
@action(methods=['post'], detail=False, serializer_class=Serializer)
def mgroups_allocate(self, request, pk=None):
"""矫正测点分配
# @action(methods=['post'], detail=False, serializer_class=Serializer)
# def mgroups_allocate(self, request, pk=None):
# """矫正测点分配
矫正测点分配
"""
from apps.enm.models import Mpoint
for mpoint in Mpoint.objects.exclude(mgroup=None):
mgroup = mpoint.mgroup
mpoint.mgroups_allocate = [
{'mgroup': mgroup.id, 'mgroup_name': mgroup.name, 'ratio': 1}]
mpoint.save()
return Response()
# 矫正测点分配
# """
# from apps.enm.models import Mpoint
# for mpoint in Mpoint.objects.exclude(mgroup=None):
# mgroup = mpoint.mgroup
# mpoint.mgroups_allocate = [
# {'mgroup': mgroup.id, 'mgroup_name': mgroup.name, 'ratio': 1}]
# mpoint.save()
# return Response()
@action(methods=['post'], detail=False, serializer_class=Serializer)
def mpointstat(self, request, pk=None):

View File

@ -0,0 +1,17 @@
# Generated by Django 3.2.12 on 2024-05-08 04:08
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('enm', '0032_mpoint_mpoint_affect'),
]
operations = [
migrations.RemoveField(
model_name='mpoint',
name='mgroups_allocate',
),
]

View File

@ -23,7 +23,6 @@ class Mpoint(CommonBModel):
material = models.ForeignKey(Material, verbose_name="计量某种物料", on_delete=models.CASCADE, null=True, blank=True)
ep_belong = models.ForeignKey("em.equipment", verbose_name="所属设备", related_name="mp_ep_belong", on_delete=models.SET_NULL, null=True, blank=True)
mgroup = models.ForeignKey("mtm.mgroup", verbose_name="所在集合", on_delete=models.SET_NULL, null=True, blank=True)
mgroups_allocate = models.JSONField("各工段分配", default=list, blank=True, help_text='[{"mgroup":"x", "ratio": 1}]')
is_rep_mgroup = models.BooleanField("是否代表所分配集合数据", default=False)
formula = models.TextField("计算公式", default="")
func_on_change = models.CharField("数据变动时执行方法", max_length=100, default="", blank=True) # 废弃字段暂时不用

View File

@ -35,18 +35,6 @@ class MpointSerializer(CustomModelSerializer):
attrs["cate"] = "material"
if "mgroup" in attrs and attrs["mgroup"]:
attrs["belong_dept"] = attrs["mgroup"].belong_dept
# attrs['mgroups_allocate'] = [{'mgroup': attrs['mgroup'].id, 'mgroup_name': attrs['mgroup'].name, 'ratio': 1}]
ratio_ = 0
mgroupIds = []
for i in attrs["mgroups_allocate"]:
if i["mgroup"]:
ratio_ = ratio_ + i["ratio"]
if i["mgroup"] in mgroupIds:
raise ParseError("分配集错误")
mgroupIds.append(i["mgroup"])
i["mgroup_name"] = Mgroup.objects.get(id=i["mgroup"]).name
if attrs["mgroups_allocate"] and round(ratio_, 3) != 1.0:
raise ParseError("比例合计错误")
return attrs

View File

@ -153,11 +153,8 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in
ms_year.val = sum_dict_year["sum"]
ms_year.save()
if mpoint.mgroups_allocate: # 如果有分配系数
for allocate in mpoint.mgroups_allocate:
mgroup = Mgroup.objects.get(id=allocate["mgroup"])
ratio = allocate["ratio"]
# 查找并绑定值班记录
mgroup = mpoint.mgroup
if mgroup:
sflog = get_sflog(mgroup, dt)
if sflog is None:
myLogger.error(f'{mgroup.name}--{dt}')
@ -177,7 +174,7 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in
"hour": hour,
}
ms_hour_s, _ = MpointStat.objects.get_or_create(**params_hour_s, defaults=params_hour_s)
ms_hour_s.val = ms.val * ratio
ms_hour_s.val = ms.val
ms_hour_s.save()
# 开始往上计算
@ -218,7 +215,7 @@ def cal_mpointstats(is_now=1, year=None, month=None, day=None, hour=None):
cal_mpointstat_hour(item.id, year, month, day, hour)
# 再统计计算测点
mpoints_compute = Mpoint.objects.filter(type=Mpoint.MT_COMPUTE, enabled=True).exclude(formula="").order_by('report_sortstr', 'create_time')
mpoints_compute = Mpoint.objects.filter(type=Mpoint.MT_COMPUTE, enabled=True, material__isnull=False).exclude(formula="").order_by('report_sortstr', 'create_time')
# mpoints_other_group = []
for item in mpoints_compute:
# mpoints_other_group.append(cal_mpointstat_hour.s(item.id, year, month, day, hour))
@ -607,7 +604,7 @@ def cal_enstat2(type: str, year_s: int, month_s: int, day_s: int, cascade=True):
# 全厂电量
# 全厂的耗电量和水量都得单独处理
use_mpoint_elec_val = False
mp_elecs = Mpoint.objects.filter(material__code="elec", code__endswith='__all', mgroups_allocate=[])
mp_elecs = Mpoint.objects.filter(material__code="elec", code__endswith='__all')
if mp_elecs.exists(): #
use_mpoint_elec_val = True
if type == "month_s":