fix: 修复发布价材料重复的问题
This commit is contained in:
@@ -20,6 +20,9 @@ class Collector:
|
|||||||
self.material_codes = [m.code for m in self.materials if m.code]
|
self.material_codes = [m.code for m in self.materials if m.code]
|
||||||
# 缓存材料税率信息
|
# 缓存材料税率信息
|
||||||
self.tax_map = {m.code: m.tax for m in self.materials if m.code}
|
self.tax_map = {m.code: m.tax for m in self.materials if m.code}
|
||||||
|
self.unit_map = {m.code: m.unit for m in self.materials if m.code}
|
||||||
|
self.name_map = {m.code: m.name for m in self.materials if m.code}
|
||||||
|
self.spec_map = {m.code: m.spec for m in self.materials if m.code}
|
||||||
|
|
||||||
def get_avg(self):
|
def get_avg(self):
|
||||||
query = PricePublish.get_query(material_id_in=self.material_codes)
|
query = PricePublish.get_query(material_id_in=self.material_codes)
|
||||||
@@ -27,8 +30,8 @@ class Collector:
|
|||||||
query = query.filter(PricePublish.type == '1')
|
query = query.filter(PricePublish.type == '1')
|
||||||
query = query.with_entities(
|
query = query.with_entities(
|
||||||
PricePublish.material_id,
|
PricePublish.material_id,
|
||||||
PricePublish.name,
|
# PricePublish.name,
|
||||||
PricePublish.spec,
|
# PricePublish.spec,
|
||||||
func.avg(PricePublish.price),
|
func.avg(PricePublish.price),
|
||||||
func.avg(PricePublish.price_fuzhou),
|
func.avg(PricePublish.price_fuzhou),
|
||||||
func.avg(PricePublish.price_xiamen),
|
func.avg(PricePublish.price_xiamen),
|
||||||
@@ -41,28 +44,28 @@ class Collector:
|
|||||||
func.avg(PricePublish.price_ningde),
|
func.avg(PricePublish.price_ningde),
|
||||||
func.avg(PricePublish.price_pintan),
|
func.avg(PricePublish.price_pintan),
|
||||||
func.avg(PricePublish.price_zhangzhoukfq),
|
func.avg(PricePublish.price_zhangzhoukfq),
|
||||||
PricePublish.tax,
|
# PricePublish.tax,
|
||||||
PricePublish.unit,
|
# PricePublish.unit,
|
||||||
)
|
)
|
||||||
query = query.filter(PricePublish.price != 0)
|
query = query.filter(PricePublish.price != 0)
|
||||||
query = query.group_by(
|
query = query.group_by(
|
||||||
PricePublish.material_id,
|
PricePublish.material_id,
|
||||||
PricePublish.name,
|
# PricePublish.name,
|
||||||
PricePublish.spec,
|
# PricePublish.spec,
|
||||||
PricePublish.tax,
|
# PricePublish.tax,
|
||||||
PricePublish.unit,
|
# PricePublish.unit,
|
||||||
)
|
)
|
||||||
data = query.all()
|
data = query.all()
|
||||||
for item in data:
|
for item in data:
|
||||||
material_id, name, spec, price, price_fuzhou, price_xiamen, price_putian, price_sanming, price_quanzhou, \
|
material_id, price, price_fuzhou, price_xiamen, price_putian, price_sanming, price_quanzhou, \
|
||||||
price_zhangzhou, price_nanpin, price_longyan, price_ningde, price_pintan, price_zhangzhoukfq, tax, unit, = item
|
price_zhangzhou, price_nanpin, price_longyan, price_ningde, price_pintan, price_zhangzhoukfq = item
|
||||||
display_digit = self.digit_map.get(material_id, 1)
|
display_digit = self.digit_map.get(material_id, 1)
|
||||||
PricePublish(
|
PricePublish(
|
||||||
year=self.year,
|
year=self.year,
|
||||||
month=self.month,
|
month=self.month,
|
||||||
material_id=material_id,
|
material_id=material_id,
|
||||||
name=name,
|
name=self.name_map.get(material_id, ''),
|
||||||
spec=spec,
|
spec=self.spec_map.get(material_id, ''),
|
||||||
price=round(price, 2),
|
price=round(price, 2),
|
||||||
price_fuzhou=round(price_fuzhou or 0, 2),
|
price_fuzhou=round(price_fuzhou or 0, 2),
|
||||||
price_xiamen=round(price_xiamen or 0, 2),
|
price_xiamen=round(price_xiamen or 0, 2),
|
||||||
@@ -75,9 +78,9 @@ class Collector:
|
|||||||
price_ningde=round(price_ningde or 0, 2),
|
price_ningde=round(price_ningde or 0, 2),
|
||||||
price_pintan=round(price_pintan or 0, 2),
|
price_pintan=round(price_pintan or 0, 2),
|
||||||
price_zhangzhoukfq=round(price_zhangzhoukfq or 0, 2),
|
price_zhangzhoukfq=round(price_zhangzhoukfq or 0, 2),
|
||||||
tax=self.tax_map.get(material_id, tax), # 从材料表获取税率
|
tax=self.tax_map.get(material_id, 0), # 从材料表获取税率
|
||||||
type=2,
|
type=2,
|
||||||
unit=unit,
|
unit=self.unit_map.get(material_id, ''),
|
||||||
display_digit=display_digit,
|
display_digit=display_digit,
|
||||||
).upsert()
|
).upsert()
|
||||||
|
|
||||||
|
@@ -15,11 +15,11 @@ if __name__ == '__main__':
|
|||||||
from core.factory import ClientApp
|
from core.factory import ClientApp
|
||||||
|
|
||||||
with ClientApp().app_context():
|
with ClientApp().app_context():
|
||||||
# collect(2025, 4)
|
collect(2025, 4)
|
||||||
|
|
||||||
# for i in range(4):
|
# for i in range(4):
|
||||||
# collect(2025, i + 1)
|
# collect(2025, i + 1)
|
||||||
for i in range(9,12):
|
# for i in range(9,12):
|
||||||
collect(2023, i + 1)
|
# collect(2023, i + 1)
|
||||||
for i in range(12):
|
# for i in range(12):
|
||||||
collect(2024, i + 1)
|
# collect(2024, i + 1)
|
||||||
|
Reference in New Issue
Block a user