import pymysql
import datetime
import json
import decimal
import requests
import warnings
import time
"""
:1、product supplier supply_introduce
2、 supply_introduce
ps: 、
"""
class DecimalEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, decimal.Decimal): # decimal , json
return float(obj)
elif isinstance(obj, datetime.datetime): # datetime , json
return obj.__str__()
return super(DecimalEncoder, self).default(obj)
class RUNSQL(object):
def run_sql(self):
db = pymysql.connect(host=' ', port=3306, user=' ', password=' ',
db=' ', charset='utf8')
self.db_cursor1 = db.cursor()
self.db_cursor2 = db.cursor()
self.db_cursor3 = db.cursor()
self.db_cursor4 = db.cursor()
self.db_cursor1.execute("SELECT id,cooperate_area_ids FROM `supplier`;")
self.db_cursor2.execute("SELECT id,supplier_id FROM `product`;")
self.db_cursor3.execute("SELECT product_id,area_id FROM `supply_introduce`;")
self.db_cursor4.execute("SELECT product_id,area_id,product_status FROM supply_introduce;")
db.close()
def run_data(self):
self.run_sql()
sup_data = []
new_sup_data = []
# supplier
for i in self.db_cursor1.fetchall():
if '1' in i[1] and '2' not in i[1]:
str_s = json.dumps(i[1], cls=DecimalEncoder, ensure_ascii=False)
str_s = str_s.replace('1', '2')
sup_data.append([i[0], str_s.strip('"')])
elif '1' in i[1] and '2' in i[1]:
str_s = json.dumps(i[1], cls=DecimalEncoder, ensure_ascii=False)
if '1,' in i[1]:
str_s1 = str_s.replace('1,', '')
sup_data.append([i[0], str_s1.strip('"')])
if ',1' in i[1]:
str_s2 = str_s.replace(',1', '')
sup_data.append([i[0], str_s2.strip('"')])
else:
sup_data.append([i[0], i[1]])
# print(data)
# print(len(data))
for line in sup_data:
if ',' in line[1]:
lines = line[1].split(',')
# print(lines)
for j in lines:
new_sup_data.append([line[0], j])
else:
new_sup_data.append([line[0], line[1]])
# print(new_sup_data)
# print(len(new_sup_data))
# product , supplier product id
a, b = [], []
sql2 = self.db_cursor2.fetchall()
for i in sql2:
a.append(i[1])
for i in new_sup_data:
b.append(i[0])
for i in a:
if i not in b:
print('supplier id:', i)
for i in b:
if i not in a:
print('product supplier_id:', i)
pro_data = []
for i in sql2:
for line in new_sup_data:
if i[1] == line[0]: #
# pro_data.append([i[0],line[0],line[1]])
pro_data.append([i[0], line[1]])
else:
pass
# print(pro_data)
# print(len(pro_data))
# supply_introduce
supin_data = []
for i in self.db_cursor3.fetchall():
supin_data.append([i[0], str(i[1])])
# print(supin_data)
# print(len(supin_data))
#
for j in range(len(pro_data)):
for i in pro_data:
if i in supin_data:
pro_data.remove(i)
supin_data.remove(i)
print('pro_data supin_data(supply_introduce ):', pro_data)
print('supin_data pro_data(product ):', supin_data)
# supply_introduce
supin_datas = []
for i in self.db_cursor4.fetchall():
supin_datas.append([i[0], str(i[1]), i[2]])
warnings.filterwarnings('ignore')
url = 'https://sit-hlj.rainbowcn.com/api/login-adapter/user/login'
data = {
"account": "127458", # wuyanwen
"password": "lss@123456"
}
session = requests.session() #
session.post(url, verify=False, json=data)
all_data = []
url_1 = 'https://sit-hlj.rainbowcn.com/scm-admin-api/supplier/listByPager'
url_text_1 = session.post(url_1, verify=False, json={})
for i in range(1, int(url_text_1.json()["pagerInfo"]["pages"]) + 1):
url_text_all = session.post(url_1, verify=False, json={"pageNum": i})
for j in range(len(url_text_all.json()["pagerInfo"]["list"])):
# print(url_text_all.json()["pagerInfo"]["list"][j]["productId"],url_text_all.json()["pagerInfo"]["list"][j]["cooperateAreaIds"],url_text_all.json()["pagerInfo"]["list"][j]["cooperateStatus"])
all_data.append([url_text_all.json()["pagerInfo"]["list"][j]["productId"],
url_text_all.json()["pagerInfo"]["list"][j]["cooperateAreaIds"],
url_text_all.json()["pagerInfo"]["list"][j]["cooperateStatus"]])
print(sorted(all_data))
print(sorted(supin_datas))
if sorted(all_data) == sorted(supin_datas):
print(' supply_introduce ')
else:
for j in range(len(all_data)):
for i in all_data:
if i in supin_datas:
all_data.remove(i)
supin_datas.remove(i)
print('supply_introduce :', all_data)
print(' :', supin_datas)
if __name__ == '__main__':
start = time.time()
s = RUNSQL()
s.run_data()
end = time.time()
print(end - start)