jianye_data_insert.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. from excel_util import ExcelUtil
  2. import os
  3. class JianYeDataInsert(object):
  4. brand_id = 13
  5. file_path = r'E:\elab\建业小程序升级\0330\建业项目卡片信息合档3.29 补2.xlsx'
  6. sql_1 = """update t_city_management set `order` = {}, coordinate_x = {}, coordinate_y = {} where name = '{}';"""
  7. sql_1_2 = "insert into t_city_management (brand_id, name, `order`, coordinate_x, coordinate_y, is_recommend, default_city, is_application, status, creator, created) values ({}, '{}', {}, {}, {}, {}, {}, 1, 1, 'binren', now());"
  8. sql_2 = """insert into t_house_management(is_recommend, brand_id, house_id, `order`, sale_status, description, is_new_open, is_hide, is_application, status, creator, created) values({}, {}, {}, {}, {}, "{}", {}, -1, 1, 1, 'binren', now());"""
  9. sql_3 = """insert into t_house_image (brand_id, house_id, image_url, image_type, status, creator, created) values({}, {}, '{}', '{}', 1, 'binren', now());"""
  10. sql_4 = """insert into t_house_parameters (brand_id, house_id, area_min, area_max, open_time, coordinate_x, coordinate_y, status, creator, created) values ({}, {}, {}, {}, {}, {}, {}, 1, 'binren', now());"""
  11. sql_5 = """insert into t_house_paraments_price_data(brand_id, house_id, value_min, value_max, value_type, house_type, status, creator, created) values ({}, {}, {}, {}, {}, '{}', 1,'binren', now());"""
  12. sql_6 = """update t_house_management set is_recommend = 1 where brand_id = 13;"""
  13. def __init__(self):
  14. self.excel_util = ExcelUtil(file_name=self.file_path)
  15. # 项目信息
  16. def house_data(self):
  17. work_sheet = self.excel_util.read_excel_by_ox_name('项目信息补充')
  18. rows = [row for row in work_sheet.rows][1:]
  19. house_data = []
  20. params_data = []
  21. for row in rows:
  22. # 0:项目id 1:省份 2:城市 3:项目 4:项目地址 5:排序 6:最新开盘(1:是,-1:不是) 7:项目描述description
  23. # 8:销售状态(1:在售,2:待售,3:售完) 9:列表标签 10:推荐 11:状态(是否隐藏) 12:面积低值 13:面积高值
  24. # 14开盘时间 15:经度 16:纬度
  25. house_id = row[0].value
  26. order = row[5].value
  27. is_new_open = row[6].value
  28. description = row[7].value
  29. sale_status = row[8].value
  30. area_min = row[12].value
  31. area_max = row[13].value
  32. coordinate_x = row[15].value
  33. coordinate_y = row[16].value
  34. recommend = 'null' if row[10].value is None else row[10].value
  35. if order is None:
  36. order = 'null'
  37. if area_min == '待定' or area_min is None:
  38. area_min = 'null'
  39. if area_max == '待定' or area_max is None:
  40. area_max = 'null'
  41. if coordinate_x is None or coordinate_x == '待定':
  42. coordinate_x = 'null'
  43. if coordinate_y is None or coordinate_y == '待定':
  44. coordinate_y = 'null'
  45. if house_id:
  46. # house_id, `order`, sale_status, description, is_new_open
  47. house_data.append(self.sql_2.format(recommend, self.brand_id, house_id, order, sale_status, description, is_new_open))
  48. # house_id, area_min, area_max, open_time, coordinate_x, coordinate_y
  49. params_data.append(self.sql_4.format(self.brand_id, house_id, area_min, area_max, 'null', coordinate_x, coordinate_y))
  50. return house_data, params_data
  51. def params_prices(self):
  52. work_sheet = self.excel_util.read_excel_by_ox_name('项目参数单价')
  53. price_data = []
  54. rows = [row for row in work_sheet.rows][1:]
  55. for row in rows:
  56. house_id = row[0].value
  57. price_min = row[4].value
  58. if price_min == '待定':
  59. price_min = 'null'
  60. price_max = row[5].value
  61. if price_max == '待定':
  62. price_max = 'null'
  63. house_type = row[6].value
  64. if house_type is None:
  65. house_type = 'null'
  66. if house_id:
  67. price_data.append(self.sql_5.format(self.brand_id, house_id, price_min, price_max, 1, house_type))
  68. return price_data
  69. def total_price_data(self):
  70. work_sheet = self.excel_util.read_excel_by_ox_name('项目参数-总价')
  71. total_price_data = []
  72. rows = [row for row in work_sheet.rows][1:]
  73. for row in rows:
  74. house_id = row[0].value
  75. price_min = row[5].value
  76. if price_min == '待定' or price_min is None:
  77. price_min = 'null'
  78. price_max = row[6].value
  79. if price_max == '待定' or price_max is None:
  80. price_max = 'null'
  81. house_type = row[4].value
  82. if house_type is None:
  83. house_type = 'null'
  84. if house_id:
  85. total_price_data.append(self.sql_5.format(self.brand_id, house_id, price_min, price_max, 2, house_type))
  86. return total_price_data
  87. def get_city_data(self):
  88. work_sheet = self.excel_util.read_excel_by_ox_name('城市信息')
  89. city_data = []
  90. rows = [row for row in work_sheet.rows][1:]
  91. for row in rows:
  92. name = row[0].value
  93. order = row[1].value
  94. x = 'null' if row[4].value is None else row[4].value
  95. y = 'null' if row[5].value is None else row[5].value
  96. default = 'null' if row[7].value is None else row[7].value
  97. recommend = 'null' if row[2].value is None else row[2].value
  98. # brand_id, name, order, coordinate_x, coordinate_y,
  99. city_data.append(self.sql_1_2.format(self.brand_id, name, order, x, y, recommend, default))
  100. return city_data
  101. def search_image(self):
  102. work_sheet = self.excel_util.read_excel_by_ox_name('搜索主图')
  103. rows = [row for row in work_sheet.rows][1:]
  104. search_data = []
  105. for row in rows:
  106. search_data.append(self.sql_3.format(row[0].value, row[1].value, '3'))
  107. return search_data
  108. def recommend(self):
  109. work_sheet = self.excel_util.read_excel_by_ox_name('推荐主图')
  110. rows = [row for row in work_sheet.rows][1:]
  111. recommend_data = []
  112. for row in rows:
  113. recommend_data.append(self.sql_3.format(row[0].value, row[1].value, '2'))
  114. return recommend_data
  115. def list_image(self):
  116. work_sheet = self.excel_util.read_excel_by_ox_name('列表主图')
  117. rows = [row for row in work_sheet.rows][1:]
  118. list_data = []
  119. for row in rows:
  120. list_data.append(self.sql_3.format(row[0].value, row[1].value, '1'))
  121. return list_data
  122. def house_cards(self):
  123. work_sheet = self.excel_util.read_excel_by_ox_name('项目卡片')
  124. rows = [row for row in work_sheet.rows][1:]
  125. insert_data = []
  126. for row in rows:
  127. insert_data.append(self.sql_3.format(row[0].value, row[1].value, '3'))
  128. return insert_data
  129. def house_card_image(self):
  130. card_image = self.excel_util.read_excel_by_ox_name('项目卡片')
  131. card_rows = [row[0].value for row in card_image.rows]
  132. house_ids = self.excel_util.read_excel_by_ox_name('项目信息补充')
  133. ids = [row for row in house_ids]
  134. result = []
  135. for cr in card_rows:
  136. path, file_name = os.path.split(cr)
  137. house_name = file_name.split('.')[0]
  138. house_id_end = 0
  139. for row in ids:
  140. house_name_1 = row[3].value
  141. house_id = row[0].value
  142. if house_name == house_name_1:
  143. house_id_end = house_id
  144. else:
  145. pass
  146. result.append((house_id_end, cr))
  147. return result
  148. def update_recommend(self):
  149. work_sheet = self.excel_util.read_excel_by_ox_name('建业推荐参数3.14')
  150. rows = [row for row in work_sheet.rows][1:]
  151. list_data = []
  152. for row in rows:
  153. list_data.append(self.sql_6.format(row[1].value, row[0].value))
  154. return list_data
  155. if __name__ == '__main__':
  156. jy = JianYeDataInsert()
  157. house_data, params_data = jy.house_data()
  158. # price_data = jy.params_prices()
  159. # total_price_data = jy.total_price_data()
  160. # city_data = jy.get_city_data()
  161. # search_data = jy.search_image()
  162. # recommend_data = jy.recommend()
  163. # card_datas = jy.house_cards()
  164. # list_data = jy.list_image()
  165. # print(len(house_data), len(params_data), len(price_data), len(total_price_data), len(city_data))
  166. for sql in params_data:
  167. print(sql)