Commit 5501c50f by 岳巧源

add md

parent a8a044f1
import pymysql
if __name__ == '__main__':
conf = {
'host': "192.168.1.238",
'port': 3306,
'user': "europa_erp",
'password': "europa_erp#zsyM",
'db': "europa_erp",
'charset': 'utf8'
}
# sql = "select * from erp_goods where brand_id != 0"
db = pymysql.connect(**conf)
cursor = db.cursor()
goods_id = 0
while True:
pass
...@@ -48,7 +48,7 @@ CREATE TABLE `lie_shipping_intermediate_data` ( ...@@ -48,7 +48,7 @@ CREATE TABLE `lie_shipping_intermediate_data` (
- shipping_name - shipping_name
- shipment_number - shipment_number
- shipping_id - shipping_id
- lie_stock_in_items - lie_stock_in_items update + insert
- out_qty - out_qty
- in_qty - in_qty
......
import pymysql
item = ["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", "seller_uid", "seller_name",
"purchase_item_id"
]
item_str = ""
separator = ", "
for i in range(len(item)):
if i != len(item) - 1:
item_str = item_str + item[i] + separator
else:
item_str = item_str + item[i]
def migrate_from_lie_scm_order():
conf = {
'host': "master.db2.liexindev.me",
'port': 3306,
'user': "liexin_purchase",
'password': "liexin_purchase#zsyM",
'db': "liexin_purchase",
'charset': 'utf8'
}
frq_id = ""
erp_sn = ""
seller_uid = ""
seller_name = ""
purchase_sn = ""
erp_purchase_sn = ""
company_id = ""
company_name = ""
#先获取scm的主键还有 purchase_item_id
sql1 = "select scm_order_item_id, purchase_item_id, purchase_id, goods_id, goods_sn, goods_name, brand_id, brand_name, supplier_id, supplier_name, warehouse_receipt_sn, in_qty, goods_number, stock_in_status, create_name, shipping_id, create_uid, shipment_number, shipping_name, create_time, update_time, purchase_uid, purchase_name, purchase_item_id from lie_scm_order"
sql2 = "select frq_id from lie_purchase_items where purchase_item_id = "
sql3 = "select erp_sn, seller_uid, seller_name from lie_frq where frq_id = " #获取到的erp_sn作为 kingdee_sales_order_no
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() #sql的执行结果
for row in result1:
source_type = 2 #---------------------------
source_id = row[0] #------------------------
purchase_id = row[2]
purchase_item_id = str(row[1])
tmp_sql2 = sql2 + purchase_item_id
cursor.execute(tmp_sql2)
result2 = cursor.fetchall() #第二条sql的执行结果
if len(result2) != 0:
frq_id = result2[0][0]
tmp_sql3 = sql3 + str(frq_id)
cursor.execute(tmp_sql3)
result3 = cursor.fetchall()
if len(result3) != 0:
erp_sn = result3[0][0]
seller_uid = result3[0][1]
seller_name = result3[0][2]
kingdee_sales_order_no = str(erp_sn)
tmp_sql4 = sql4 + str(purchase_id)
cursor.execute(tmp_sql4)
result4 = cursor.fetchall()
if len(result4) != 0:
purchase_sn = result4[0][0]
erp_purchase_sn = result4[0][1]
company_id = result4[0][2]
company_name = result4[0][3]
kingdee_purchase_order_no = erp_purchase_sn
goods_id = row[3]
goods_sn = row[4]
goods_name = row[5]
brand_id = row[6]
brand_name = row[7]
supplier_id = row[8]
supplier_name = row[9]
warehouse_receipt_sn = row[10]
in_qty = row[11]
out_qty = row[12]
stock_in_status = row[13]
create_name = row[14]
shipping_id = row[15]
create_uid = row[16]
shipment_number = row[17]
shipping_name = row[18]
create_time = row[19]
update_time = row[20]
purchase_uid = row[21]
purchase_name = row[22]
purchase_item_id = row[23]
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, seller_uid, seller_name,
purchase_item_id
]
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(purchase_item_id)) != 0 and len(str(warehouse_receipt_sn)) != 0: #这两个字段不为空值
sql5 = "select id from lie_shipping_intermediate_data where purchase_item_id = " + "'" +str(purchase_item_id) + "'" + " and " + "warehouse_receipt_sn = " + "'" + str(warehouse_receipt_sn) + "'" + " and " + "source_type = " + "2"
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()
print(insert_sql)
try:
cursor.execute(insert_sql)
db.commit()
except Exception as e:
db.rollback()
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'
}
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 = ""
purchase_item_id = ""
erp_sn = ""
seller_uid = ""
seller_name = ""
purchase_sn = ""
erp_purchase_sn = ""
company_id = ""
company_name = ""
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, purchase_item_id from lie_stock_in_items where stock_in_id = "
sql3 = "select erp_sn, seller_uid, seller_name 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:
frq_id = result2[0][0]
purchase_id = result2[0][1]
stock_in_item_id = result2[0][2]
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]
warehouse_receipt_sn = result2[0][8]
in_qty = result2[0][9]
out_qty = result2[0][10]
create_time = result2[0][11]
update_time = result2[0][12]
purchase_item_id = result2[0][13]
tmp_sql3 = sql3 + str(frq_id)
cursor.execute(tmp_sql3)
result3 = cursor.fetchall()
if len(result3) != 0:
erp_sn = result3[0][0]
seller_uid = result3[0][1]
seller_name = result3[0][2]
tmp_sql4 = sql4 + str(purchase_id)
cursor.execute(tmp_sql4)
result4 = cursor.fetchall()
if len(result4) != 0:
purchase_sn = result4[0][0]
erp_purchase_sn = result4[0][1]
company_id = result4[0][2]
company_name = result4[0][3]
kingdee_sales_order_no = erp_sn
source_type = 1
kingdee_purchase_order_no = erp_purchase_sn
source_id = stock_in_item_id
supplier_id = row[1]
supplier_name = row[2]
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]
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, seller_uid, seller_name,
purchase_item_id
]
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(purchase_item_id)) != 0 and len(str(warehouse_receipt_sn)) != 0: #这两个字段不为空值
sql5 = "select id from lie_shipping_intermediate_data where purchase_item_id = " + "'" +str(purchase_item_id) + "'" + " and " + "warehouse_receipt_sn = " + "'" + str(warehouse_receipt_sn) + "'" + " and " + "source_type = " + "2"
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()
print(insert_sql)
try:
cursor.execute(insert_sql)
db.commit()
except Exception as e:
db.rollback()
print(e)
if __name__ == '__main__':
migrate_from_lie_scm_order()
migrate_from_stock_in_item()
\ No newline at end of file
...@@ -99,7 +99,7 @@ def pur(): ...@@ -99,7 +99,7 @@ def pur():
"create_uid": create_uid, # ok "create_uid": create_uid, # ok
"create_name": create_name, # ok "create_name": create_name, # ok
"address_data": [{ "address_data": [{
"source_id": "end_cust_id_" + str(end_cust_id), #也是主键id "source_id": "end_cust_id_en_" + str(end_cust_id), #也是主键id
"source_code": "", "source_code": "",
"address_type": "终端地址", "address_type": "终端地址",
"address": com_addr "address": com_addr
......
import json
import pymysql
if __name__ == '__main__':
conf = {
'host': "192.168.1.238",
'port': 3306,
'user': "europa_erp",
'password': "europa_erp#zsyM",
'db': "europa_erp",
'charset': 'utf8'
}
# 117183438154202117
sku_id = 0
# sql = "select * from erp_goods_sku where sku_id > %s order by sku_id limit 1000"
db = pymysql.connect(**conf)
cursor = db.cursor()
while True:
sql = "select * from erp_goods_sku where sku_id > %s order by sku_id limit 1000"
cursor.execute(sql, [str(sku_id)])
result = cursor.fetchall()
if len(result) > 0:
sku_id = result[-1][0]
for row in result:
flag = False
json_str = row[19]
skuId = row[0]
print("old: ----->" + json_str)
ans = json.loads(json_str)
for i in range(len(ans)):
if 'purchase' in ans[i]:
flag = True
break
if 'purchases' in ans[i]:
break
if flag:
new_str = str(json_str).replace("purchase", "purchases")
print("new str: ---->" + new_str)
update_sql = "update erp_goods_sku set ladder_price = %s where sku_id = %s limit 1"
try:
cursor.execute(update_sql, [str(new_str), str(skuId)])
db.commit()
except Exception as e:
db.rollback()
print(e)
else:
break
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