Commit 055dd025 by 岳巧源

add sql

parent 8c04b90c
Showing with 124 additions and 5 deletions
...@@ -102,12 +102,15 @@ def migrate_from_lie_scm_order(): ...@@ -102,12 +102,15 @@ def migrate_from_lie_scm_order():
continue continue
value_str = value_str + "'" + str(value_arr[i]) + "'" value_str = value_str + "'" + str(value_arr[i]) + "'"
insert_sql = "insert into lie_shipping_intermediate_data (" + item_str + ") " + "values (" + value_str + ")" insert_sql = "insert into lie_shipping_intermediate_data (" + item_str + ") " + "values (" + value_str + ")"
#判断 goods_name + warehouse_receipt_sn 的组合是否出现过 没出现就 #判断 goods_name + warehouse_receipt_sn 还有shipment_number的组合是否出现过
if len(str(goods_name)) != 0 and len(str(warehouse_receipt_sn)) != 0: #这两个字段不为空值 if len(str(goods_name)) != 0 and len(str(warehouse_receipt_sn)) != 0 and len(str(shipment_number)) != 0: #这两个字段不为空值
sql5 = "select id from lie_shipping_intermediate_data where goods_name = " + "'" +str(goods_name) + "'" + " and " + "warehouse_receipt_sn = " + "'" + str(warehouse_receipt_sn) + "'" sql5 = "select id from lie_shipping_intermediate_data where goods_name = " + "'" +str(goods_name) + "'" + " and " + "warehouse_receipt_sn = " + "'" + str(warehouse_receipt_sn) + "'" + " and " + "shipment_number = " + "'" + str(shipment_number) + "'"
cursor.execute(sql5) cursor.execute(sql5)
result5 = cursor.fetchall() result5 = cursor.fetchall()
if len(result5) != 0: if len(result5) != 0:
delete_sql = "delete from lie_shipping_intermediate_data where id = " + str(result5[0][0]) + " limit 1"
cursor.execute(delete_sql)
db.commit()
continue #组合已存在 跳过插入 continue #组合已存在 跳过插入
print(insert_sql) print(insert_sql)
try: try:
...@@ -117,6 +120,122 @@ def migrate_from_lie_scm_order(): ...@@ -117,6 +120,122 @@ def migrate_from_lie_scm_order():
db.rollback() db.rollback()
print(e) print(e)
###################################################################################
def migrate_from_stock_in_item():
conf = {
'host': "master.db2.liexindev.me",
'port': 3306,
'user': "liexin_purchase",
'password': "liexin_purchase#zsyM",
'db': "liexin_purchase",
'charset': 'utf8'
}
sql1 = "select stock_in_id, supplier_id, supplier_name, status, create_name, shipping_id, create_uid, shipment_number, shipping_name, purchase_uid, purchase_name from lie_stock_in where stock_in_type in (1, 2)"
sql2 = "select frq_id, purchase_id, stock_in_item_id, goods_id, goods_sn, goods_name, brand_id, brand_name, warehouse_receipt_sn, in_qty, out_qty, create_time, update_time from lie_stock_in_items where stock_in_id = "
sql3 = "select erp_sn from lie_frq where frq_id = "
sql4 = "select purchase_sn, erp_purchase_sn, company_id, company_name from lie_purchase_order where purchase_id = "
db = pymysql.connect(**conf)
cursor = db.cursor()
cursor.execute(sql1)
result1 = cursor.fetchall()
for row in result1:
stock_in_id = row[0]
tmp_sql2 = sql2 + str(stock_in_id)
cursor.execute(tmp_sql2)
result2 = cursor.fetchall()
if len(result2) == 0:
continue
frq_id = result2[0][0]
purchase_id = result2[0][1]
tmp_sql3 = sql3 + str(frq_id)
cursor.execute(tmp_sql3)
result3 = cursor.fetchall()
if len(result3) == 0:
continue
erp_sn = result3[0][0]
kingdee_sales_order_no = erp_sn
source_type = 1
tmp_sql4 = sql4 + str(purchase_id)
cursor.execute(tmp_sql4)
result4 = cursor.fetchall()
if len(result4) == 0:
continue
purchase_sn = result4[0][0]
erp_purchase_sn = result4[0][1]
kingdee_purchase_order_no = erp_purchase_sn
company_id = result4[0][2]
company_name = result4[0][3]
stock_in_item_id = result2[0][2]
source_id = stock_in_item_id
goods_id = result2[0][3]
goods_sn = result2[0][4]
goods_name = result2[0][5]
brand_id = result2[0][6]
brand_name = result2[0][7]
supplier_id = row[1]
supplier_name = row[2]
warehouse_receipt_sn = result2[0][8]
in_qty = result2[0][9]
out_qty = result2[0][10]
status = row[3]
stock_in_status = status
create_name = row[4]
shipping_id = row[5]
create_uid = row[6]
shipment_number = row[7]
shipping_name = row[8]
create_time = result2[0][11]
update_time = result2[0][12]
purchase_uid = row[9]
purchase_name = row[10]
value_arr = [
source_type, source_id, kingdee_sales_order_no, purchase_sn,
kingdee_purchase_order_no, goods_id, goods_sn, goods_name,
brand_id, brand_name, company_id, company_name, supplier_id,
supplier_name, warehouse_receipt_sn, in_qty, out_qty,
stock_in_status, create_name, shipping_id, create_uid, shipment_number,
shipping_name, create_time, update_time, purchase_uid, purchase_name
]
value_str = ""
for i in range(len(value_arr)):
if i != len(value_arr) - 1:
if len(str(value_arr[i])) == 0:
value_str = value_str + "''" + ", "
continue
value_str = value_str + "'" +str(value_arr[i]) + "'" + ", "
else:
if len(str(value_arr[i])) == 0:
value_str = value_str + "''"
continue
value_str = value_str + "'" + str(value_arr[i]) + "'"
insert_sql = "insert into lie_shipping_intermediate_data (" + item_str + ") " + "values (" + value_str + ")"
#判断 goods_name + warehouse_receipt_sn 还有shipment_number的组合是否出现过
if len(str(goods_name)) != 0 and len(str(warehouse_receipt_sn)) != 0 and len(str(shipment_number)) != 0: #这两个字段不为空值
sql5 = "select id from lie_shipping_intermediate_data where goods_name = " + "'" +str(goods_name) + "'" + " and " + "warehouse_receipt_sn = " + "'" + str(warehouse_receipt_sn) + "'" + " and " + "shipment_number = " + "'" + str(shipment_number) + "'"
cursor.execute(sql5)
result5 = cursor.fetchall()
if len(result5) != 0:
delete_sql = "delete from lie_shipping_intermediate_data where id = " + str(result5[0][0]) + " limit 1"
cursor.execute(delete_sql)
db.commit()
continue #组合已存在 跳过插入
print(insert_sql)
try:
cursor.execute(insert_sql)
db.commit()
except Exception as e:
db.rollback()
print(e)
if __name__ == '__main__': if __name__ == '__main__':
migrate_from_lie_scm_order() migrate_from_lie_scm_order()
#migrate_from_lie_scm_order() migrate_from_stock_in_item()
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment