2024-05-29 10:21:31 +08:00
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import func
|
|
|
|
|
|
|
|
|
|
from commons.models.fujian_survey import FujianSurvey
|
|
|
|
|
from commons.models.price_publish import PricePublish
|
|
|
|
|
from commons.models.price_result import PriceResult
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Collector:
|
|
|
|
|
|
|
|
|
|
def __init__(self, year, month):
|
|
|
|
|
self.year = year
|
|
|
|
|
self.month = month
|
|
|
|
|
|
2024-07-11 18:14:17 +08:00
|
|
|
|
# todo-2 材料id映射
|
|
|
|
|
|
2024-05-29 10:21:31 +08:00
|
|
|
|
def get_avg(self):
|
|
|
|
|
query = PricePublish.get_query(name_in=(
|
|
|
|
|
'杉原木',
|
|
|
|
|
'松原木',
|
|
|
|
|
'锯材',
|
|
|
|
|
'锯材',
|
|
|
|
|
'毛竹',
|
|
|
|
|
'冷轧带肋钢筋网',
|
|
|
|
|
'预应力粗钢筋',
|
|
|
|
|
'高强钢丝',
|
|
|
|
|
'钢板',
|
|
|
|
|
'钢板',
|
|
|
|
|
'圆钢',
|
|
|
|
|
'钢轨',
|
|
|
|
|
'钢管',
|
|
|
|
|
'镀锌钢管',
|
|
|
|
|
'镀锌无缝钢管',
|
|
|
|
|
'镀锌钢板',
|
|
|
|
|
'钢丝绳',
|
|
|
|
|
'波形钢板(双波)',
|
|
|
|
|
'波形钢板(三波)',
|
|
|
|
|
'四氟板式橡胶组合支座',
|
|
|
|
|
'板式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'模数式伸缩装置',
|
|
|
|
|
'模数式伸缩装置',
|
|
|
|
|
'钢绞线群锚(3孔)',
|
|
|
|
|
'钢绞线群锚(7孔)',
|
|
|
|
|
'钢绞线群锚(15孔)',
|
|
|
|
|
'不锈钢板',
|
|
|
|
|
'铁件',
|
|
|
|
|
'铝合金标志',
|
|
|
|
|
'铸铁管',
|
|
|
|
|
'钢板网',
|
|
|
|
|
'铁丝编织网',
|
|
|
|
|
'橡胶护舷',
|
|
|
|
|
'橡胶护舷',
|
|
|
|
|
'橡胶护舷',
|
|
|
|
|
'鼓型橡胶护舷',
|
|
|
|
|
'鼓型橡胶护舷',
|
|
|
|
|
'鼓型橡胶护舷',
|
|
|
|
|
'油漆',
|
|
|
|
|
'塑料排水板',
|
|
|
|
|
'路缘石',
|
|
|
|
|
'乳化炸药',
|
|
|
|
|
'硝铵炸药',
|
|
|
|
|
'导火线',
|
|
|
|
|
'普通雷管',
|
|
|
|
|
'电雷管',
|
|
|
|
|
'工业数码电子雷管',
|
|
|
|
|
'导爆索',
|
|
|
|
|
'引爆母线',
|
|
|
|
|
'重油',
|
|
|
|
|
|
|
|
|
|
'光圆钢筋',
|
|
|
|
|
'带肋钢筋',
|
|
|
|
|
'型钢',
|
|
|
|
|
'钢绞线',
|
|
|
|
|
'32.5级水泥',
|
|
|
|
|
'42.5级水泥',
|
|
|
|
|
'进口沥青',
|
|
|
|
|
'国产沥青',
|
|
|
|
|
'进口改性沥青',
|
|
|
|
|
'国产改性沥青',
|
|
|
|
|
'汽油(89)',
|
|
|
|
|
'汽油(92)',
|
|
|
|
|
'柴油(0)',
|
|
|
|
|
))
|
|
|
|
|
query = PricePublish.query_previous_month(query, start_date=datetime.date(self.year, self.month, 1), count=6)
|
|
|
|
|
query = query.with_entities(
|
|
|
|
|
PricePublish.material_id,
|
|
|
|
|
PricePublish.name,
|
|
|
|
|
PricePublish.spec,
|
|
|
|
|
func.avg(PricePublish.price),
|
|
|
|
|
func.avg(PricePublish.price_fuzhou),
|
|
|
|
|
func.avg(PricePublish.price_xiamen),
|
|
|
|
|
func.avg(PricePublish.price_putian),
|
|
|
|
|
func.avg(PricePublish.price_sanming),
|
|
|
|
|
func.avg(PricePublish.price_quanzhou),
|
|
|
|
|
func.avg(PricePublish.price_zhangzhou),
|
|
|
|
|
func.avg(PricePublish.price_nanpin),
|
|
|
|
|
func.avg(PricePublish.price_longyan),
|
|
|
|
|
func.avg(PricePublish.price_ningde),
|
|
|
|
|
func.avg(PricePublish.price_pintan),
|
2024-07-11 18:14:17 +08:00
|
|
|
|
func.avg(PricePublish.price_zhangzhoukfq),
|
2024-05-29 10:21:31 +08:00
|
|
|
|
PricePublish.tax,
|
|
|
|
|
PricePublish.unit,
|
|
|
|
|
)
|
2024-07-11 18:14:17 +08:00
|
|
|
|
query = query.filter(PricePublish.price != 0)
|
2024-05-29 10:21:31 +08:00
|
|
|
|
query = query.group_by(
|
|
|
|
|
PricePublish.material_id,
|
|
|
|
|
PricePublish.name,
|
|
|
|
|
PricePublish.spec,
|
|
|
|
|
PricePublish.tax,
|
|
|
|
|
PricePublish.unit,
|
|
|
|
|
)
|
|
|
|
|
data = query.all()
|
|
|
|
|
for item in data:
|
|
|
|
|
material_id, name, spec, price, price_fuzhou, price_xiamen, price_putian, price_sanming, price_quanzhou, \
|
2024-07-11 18:14:17 +08:00
|
|
|
|
price_zhangzhou, price_nanpin, price_longyan, price_ningde, price_pintan, price_zhangzhoukfq, tax, unit = item
|
2024-05-29 10:21:31 +08:00
|
|
|
|
PricePublish(
|
|
|
|
|
year=self.year,
|
|
|
|
|
month=self.month,
|
|
|
|
|
material_id=material_id,
|
|
|
|
|
name=name,
|
|
|
|
|
spec=spec,
|
2024-07-11 18:14:17 +08:00
|
|
|
|
price=round(price, 2),
|
|
|
|
|
price_fuzhou=round(price_fuzhou, 2),
|
|
|
|
|
price_xiamen=round(price_xiamen, 2),
|
|
|
|
|
price_putian=round(price_putian, 2),
|
|
|
|
|
price_sanming=round(price_sanming, 2),
|
|
|
|
|
price_quanzhou=round(price_quanzhou, 2),
|
|
|
|
|
price_zhangzhou=round(price_zhangzhou, 2),
|
|
|
|
|
price_nanpin=round(price_nanpin, 2),
|
|
|
|
|
price_longyan=round(price_longyan, 2),
|
|
|
|
|
price_ningde=round(price_ningde, 2),
|
|
|
|
|
price_pintan=round(price_pintan, 2),
|
|
|
|
|
price_zhangzhoukfq=round(price_zhangzhoukfq, 2),
|
2024-05-29 10:21:31 +08:00
|
|
|
|
tax=tax,
|
|
|
|
|
type=2,
|
|
|
|
|
unit=unit,
|
|
|
|
|
).upsert()
|
|
|
|
|
|
|
|
|
|
def get_from_survey(self):
|
|
|
|
|
query = FujianSurvey.get_query(self.year, self.month, name_in=(
|
|
|
|
|
'杉原木',
|
|
|
|
|
'松原木',
|
|
|
|
|
'锯材',
|
|
|
|
|
'锯材',
|
|
|
|
|
'毛竹',
|
|
|
|
|
'冷轧带肋钢筋网',
|
|
|
|
|
'预应力粗钢筋',
|
|
|
|
|
'高强钢丝',
|
|
|
|
|
'钢板',
|
|
|
|
|
'钢板',
|
|
|
|
|
'圆钢',
|
|
|
|
|
'钢轨',
|
|
|
|
|
'钢管',
|
|
|
|
|
'镀锌钢管',
|
|
|
|
|
'镀锌无缝钢管',
|
|
|
|
|
'镀锌钢板',
|
|
|
|
|
'钢丝绳',
|
|
|
|
|
'波形钢板(双波)',
|
|
|
|
|
'波形钢板(三波)',
|
|
|
|
|
'四氟板式橡胶组合支座',
|
|
|
|
|
'板式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'盆式橡胶支座',
|
|
|
|
|
'模数式伸缩装置',
|
|
|
|
|
'模数式伸缩装置',
|
|
|
|
|
'钢绞线群锚(3孔)',
|
|
|
|
|
'钢绞线群锚(7孔)',
|
|
|
|
|
'钢绞线群锚(15孔)',
|
|
|
|
|
'不锈钢板',
|
|
|
|
|
'铁件',
|
|
|
|
|
'铝合金标志',
|
|
|
|
|
'铸铁管',
|
|
|
|
|
'钢板网',
|
|
|
|
|
'铁丝编织网',
|
|
|
|
|
'橡胶护舷',
|
|
|
|
|
'橡胶护舷',
|
|
|
|
|
'橡胶护舷',
|
|
|
|
|
'鼓型橡胶护舷',
|
|
|
|
|
'鼓型橡胶护舷',
|
|
|
|
|
'鼓型橡胶护舷',
|
|
|
|
|
'油漆',
|
|
|
|
|
'塑料排水板',
|
|
|
|
|
'路缘石',
|
|
|
|
|
'乳化炸药',
|
|
|
|
|
'硝铵炸药',
|
|
|
|
|
'导火线',
|
|
|
|
|
'普通雷管',
|
|
|
|
|
'电雷管',
|
|
|
|
|
'工业数码电子雷管',
|
|
|
|
|
'导爆索',
|
|
|
|
|
'引爆母线',
|
|
|
|
|
'重油',
|
|
|
|
|
))
|
|
|
|
|
data = query.all()
|
|
|
|
|
for item in data:
|
|
|
|
|
PricePublish(
|
|
|
|
|
year=self.year,
|
|
|
|
|
month=self.month,
|
|
|
|
|
material_id=item.material_id,
|
|
|
|
|
name=item.name,
|
|
|
|
|
spec=item.spec,
|
|
|
|
|
price=item.price,
|
|
|
|
|
price_fuzhou=item.price,
|
|
|
|
|
price_xiamen=item.price,
|
|
|
|
|
price_putian=item.price,
|
|
|
|
|
price_sanming=item.price,
|
|
|
|
|
price_quanzhou=item.price,
|
|
|
|
|
price_zhangzhou=item.price,
|
|
|
|
|
price_nanpin=item.price,
|
|
|
|
|
price_longyan=item.price,
|
|
|
|
|
price_ningde=item.price,
|
|
|
|
|
price_pintan=item.price,
|
2024-07-11 18:14:17 +08:00
|
|
|
|
price_zhangzhoukfq=item.price,
|
2024-05-29 10:21:31 +08:00
|
|
|
|
tax=item.tax,
|
|
|
|
|
type=1,
|
|
|
|
|
unit=item.unit
|
|
|
|
|
).upsert()
|
|
|
|
|
|
|
|
|
|
def get_from_result(self):
|
|
|
|
|
query = PriceResult.get_query(self.year, self.month, name_in=(
|
|
|
|
|
'光圆钢筋',
|
|
|
|
|
'带肋钢筋',
|
|
|
|
|
'型钢',
|
|
|
|
|
'钢绞线',
|
|
|
|
|
'32.5级水泥',
|
|
|
|
|
'42.5级水泥',
|
|
|
|
|
'进口沥青',
|
|
|
|
|
'国产沥青',
|
|
|
|
|
'进口改性沥青',
|
|
|
|
|
'国产改性沥青',
|
|
|
|
|
'汽油(89)',
|
|
|
|
|
'汽油(92)',
|
|
|
|
|
'柴油(0)',
|
|
|
|
|
))
|
|
|
|
|
data = query.all()
|
|
|
|
|
for item in data:
|
|
|
|
|
PricePublish(
|
|
|
|
|
year=self.year,
|
|
|
|
|
month=self.month,
|
|
|
|
|
material_id=item.material_id,
|
|
|
|
|
name=item.name,
|
2024-07-11 18:14:17 +08:00
|
|
|
|
spec=item.spec,
|
2024-05-29 10:21:31 +08:00
|
|
|
|
price=item.price_recommend,
|
|
|
|
|
price_fuzhou=item.price_recommend,
|
|
|
|
|
price_xiamen=item.price_recommend,
|
|
|
|
|
price_putian=item.price_recommend,
|
|
|
|
|
price_sanming=item.price_recommend,
|
|
|
|
|
price_quanzhou=item.price_recommend,
|
|
|
|
|
price_zhangzhou=item.price_recommend,
|
|
|
|
|
price_nanpin=item.price_recommend,
|
|
|
|
|
price_longyan=item.price_recommend,
|
|
|
|
|
price_ningde=item.price_recommend,
|
|
|
|
|
price_pintan=item.price_recommend,
|
2024-07-11 18:14:17 +08:00
|
|
|
|
price_zhangzhoukfq=item.price_recommend,
|
2024-05-29 10:21:31 +08:00
|
|
|
|
tax=9.00,
|
|
|
|
|
type=1,
|
2024-07-11 18:14:17 +08:00
|
|
|
|
unit=item.unit,
|
2024-05-29 10:21:31 +08:00
|
|
|
|
).upsert()
|
|
|
|
|
|
|
|
|
|
def run(self):
|
2024-07-11 18:14:17 +08:00
|
|
|
|
# 当月价
|
2024-05-29 10:21:31 +08:00
|
|
|
|
self.get_from_survey()
|
|
|
|
|
self.get_from_result()
|
2024-07-11 18:14:17 +08:00
|
|
|
|
# 近半年平均价
|
2024-05-29 10:21:31 +08:00
|
|
|
|
self.get_avg()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
from core.factory import ClientApp
|
|
|
|
|
|
|
|
|
|
with ClientApp().app_context():
|
|
|
|
|
collector = Collector(2023, 11)
|
|
|
|
|
collector.run()
|