feat: 记录batchst 最后操作时间

This commit is contained in:
caoqianming 2024-12-02 14:13:17 +08:00
parent 17697d6482
commit de6e5d315a
4 changed files with 38 additions and 7 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2024-12-02 06:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('wpm', '0075_auto_20241128_1703'),
]
operations = [
migrations.AddField(
model_name='batchst',
name='last_time',
field=models.DateTimeField(blank=True, null=True, verbose_name='最后操作时间'),
),
]

View File

@ -22,6 +22,7 @@ class BatchSt(BaseModel):
批次统计表
"""
batch = models.TextField("批次号")
last_time = models.DateTimeField("最后操作时间", null=True, blank=True)
data = models.JSONField("数据", default=list, blank=True)
class SfLog(CommonADModel):

View File

@ -3,13 +3,18 @@ from apps.mtm.models import Mgroup
from apps.system.models import Dept
from apps.inm.models import MIOItem
from apps.qm.models import FtestWork
from django.utils import timezone
from datetime import datetime
def get_alldata_with_batch_and_store(batch: str):
"""
获取某个批次某个仓库的整体生产数据并保存
"""
data = get_alldata_with_batch(batch)
bobj, _ = BatchSt.objects.get_or_create(batch=batch)
last_time, data = get_alldata_with_batch(batch)
bobj, _ = BatchSt.objects.get_or_create(batch=batch, defaults={
"last_time": last_time
})
bobj.last_time = last_time
bobj.data = data
bobj.save()
@ -17,6 +22,7 @@ def get_alldata_with_batch(batch: str):
"""
获取某个批次的整体生产数据
"""
last_time = timezone.make_aware(datetime(1990, 4, 4, 0, 0, 0))
data = {"产品批次编号": batch}
dept7 = Dept.objects.get(name='7车间')
dept6 = Dept.objects.get(name='6车间')
@ -31,6 +37,7 @@ def get_alldata_with_batch(batch: str):
data["棒料成型-切料人"] = []
data["棒料成型-备注"] = ""
for item in mlogs_blcx_qs:
last_time = item.update_time if item.update_time > last_time else last_time
data["产品规格"].append(item.material_out) # 对象
if item.handle_user:
data["棒料成型-出料人"].append(item.handle_user) # 对象
@ -39,7 +46,7 @@ def get_alldata_with_batch(batch: str):
if item.note:
data["棒料成型-备注"] = ";".join([data["棒料成型-备注"], item.note])
for field in mlog_count_fields:
if getattr(item, field) > 0:
if getattr(item, field) > 0 or field in ["count_real", "count_ok"]:
if f'棒料成型-{field}' not in data:
data[f'棒料成型-{field}'] = getattr(item, field)
else:
@ -57,6 +64,7 @@ def get_alldata_with_batch(batch: str):
mioitem_count_fields = MIOItem.count_fields()
mioitem_qs = MIOItem.objects.filter(mio__belong_dept=dept7, mio__type="do_in", batch=batch, mio__submit_time__isnull=False)
if mioitem_qs.exists():
last_time = item.update_time if item.update_time > last_time else last_time
data["7车间入库-日期"] = []
data["7车间入库-车间执行人"] = []
data["7车间入库-仓库执行人"] = []
@ -67,7 +75,7 @@ def get_alldata_with_batch(batch: str):
if item.mio.do_user:
data["7车间入库-仓库执行人"].append(item.mio.do_user)
for field in mioitem_count_fields:
if getattr(item, field) > 0:
if getattr(item, field) > 0 or field in ["count", "count_notok"]:
if f'7车间入库-{field}' not in data:
data[f'7车间入库-{field}'] = int(getattr(item, field))
else:
@ -85,6 +93,7 @@ def get_alldata_with_batch(batch: str):
batch=batch,
mio__submit_time__isnull=False)
if mioitem6_qs.exists():
last_time = item.update_time if item.update_time > last_time else last_time
data["6车间生产领料-日期"] = []
for item in mioitem6_qs:
data["6车间生产领料-日期"].append(item.mio.inout_date)
@ -103,6 +112,7 @@ def get_alldata_with_batch(batch: str):
mgroup = Mgroup.objects.get(name=mgroup_name)
mlogs_qs = Mlog.objects.filter(submit_time__isnull=False, mgroup=mgroup, batch=batch)
if mlogs_qs.exists():
last_time = item.update_time if item.update_time > last_time else last_time
data[f'6车间-{mgroup_name}-日期'] = []
data[f'6车间-{mgroup_name}-操作人'] = []
for item in mlogs_qs:
@ -111,7 +121,7 @@ def get_alldata_with_batch(batch: str):
if item.handle_user:
data[f'6车间-{mgroup_name}-操作人'].append(item.handle_user)
for field in mlog_count_fields:
if getattr(item, field) > 0:
if getattr(item, field) > 0 or field in ["count_ok", "count_real"]:
if f'6车间-{mgroup_name}-{field}' not in data:
data[f'6车间-{mgroup_name}-{field}'] = getattr(item, field)
else:
@ -146,6 +156,7 @@ def get_alldata_with_batch(batch: str):
data["成品检验-日期"] = []
data['成品检验-检验人'] = []
for item in ftestwork_qs:
last_time = item.update_time if item.update_time > last_time else last_time
if item.test_date:
data["成品检验-日期"].append(item.test_date)
if item.test_user:
@ -158,7 +169,7 @@ def get_alldata_with_batch(batch: str):
else:
data[f'成品检验-{k}'] += v
else:
if getattr(item, field) > 0:
if getattr(item, field) > 0 or field in ["count", "count_ok"]:
if f'成品检验-{field}' not in data:
data[f'成品检验-{field}'] = getattr(item, field)
else:
@ -169,5 +180,5 @@ def get_alldata_with_batch(batch: str):
data['成品检验-检验人'] = ";".join([item.name for item in data['成品检验-检验人']])
data['成品检验-合格率'] = round(data['成品检验-count_ok'] * 100/ data['成品检验-count'], 1)
return data
return last_time, data

View File

@ -523,5 +523,6 @@ class BatchStViewSet(ListModelMixin, CustomGenericViewSet):
serializer_class = BatchStSerializer
filterset_fields = {
"batch": ["exact", "contains"],
"last_time": ["exact", "gte", "lte"],
"update_time": ["exact", "gte", "lte"]
}