# 政策法规 删除 重复数据 重复量为2条 其中一条是1666

import cx_Oracle
# 连接数据库
conn = cx_Oracle.connect('cis/ZZsn9988_1qaz@114.116.91.1:1521/orcl')
# 执行查询
cursor = conn.cursor()
cursor.execute('SELECT sourceaddress FROM  ( \
select t.sourceaddress,count(1) cnn from CIS_LAW_DATA t where t.typeid in (select id from cis_law_type start with id=1622 connect by prior id=PID) \
group by t.sourceaddress \
order by cnn desc \
) T WHERE SOURCEADDRESS IS NOT NULL AND CNN>1')
result = cursor.fetchall()
i=0
for row in result:
     i=i+1
     url=row[0]
     cursor.execute(f"select typeid,id from CIS_LAW_DATA where sourceaddress='{url}'")
     lawInfoList = cursor.fetchall()
     count = len(lawInfoList)
     if count==2:
         pass
     else:
         continue
     id1=lawInfoList[0][1]
     typeid1 = lawInfoList[0][0]
     id2 = lawInfoList[1][1]
     typeid2 = lawInfoList[1][0]
     if typeid1==typeid2:
         cursor.execute(f"delete from CIS_LAW_DATA where id='{id1}'")
         conn.commit()
         print(f"{i}---typeid 重复 删除第一个-----{id1}--{typeid1}--{id2}--{typeid2}")
         continue
     else:
         if(typeid1==1666):
             cursor.execute(f"delete from CIS_LAW_DATA where id='{id1}'")
             conn.commit()
             print(f"{i}---typeid1为1666 重复 删除第一个-----{id1}--{typeid1}--{id2}--{typeid2}")
             continue
         if typeid2==1666:
             cursor.execute(f"delete from CIS_LAW_DATA where id='{id2}'")
             conn.commit()
             print(f"{i}---typeid2为1666 重复 删除第二个-----{id1}--{typeid1}--{id2}--{typeid2}")
             continue
     print(f"{i}----不能够删除----{id1}--{typeid1}--{id2}--{typeid2}")
# 关闭数据库连接
cursor.close()
conn.close()
