# -*- encoding=utf8 -*-


import pymysql

class delData(object):

    def Delete_branch_by_id(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除新增的院区数据,减少垃圾数据的产生,保证脚本下次还可以正常运行,接口脚本每次都使用新增数据
        # sql = "DELETE from mcms_branch_info where id = '%s';" % id
        sql = "DELETE  from mcms_branch_info where  name  like '%东土城路院区_____';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('院区数据已删除成功')
        cursor.close()

    def Delete_goods_change_info(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除产品信息修改数据
        sql = "DELETE from mcms_goods_chg_main where create_user='UID-050151';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('产品调价和产品信息变更数据已删除成功')
        cursor.close()

    def Delete_sys_config(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除产品信息修改数据
        sql = "delete from sys_config  where  create_user = 'UID-050151';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('系统配置信息已经删除成功 ')
        cursor.close()

    def Delete_sysrAtomDet(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除产品信息修改数据
        sql = "delete from sysr_atom_det where create_user='UID-050151';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('编码规则信息已经删除成功 ')
        cursor.close()

    def Delete_sys_message_template(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除产品信息修改数据
        sql = "delete from sys_message_type where create_user='UID-050151' and template_type_name='test2';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('消息通知模板类型已经删除成功 ')
        cursor.close()

    def Delete_goods_pur_template(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除产品信息修改数据
        sql = "delete from mcms_goods_pur_template where create_user ='UID-050151';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('请领模板删除成功 ')
        cursor.close()

    def get_shelf_name_version(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 获取库区version
        sql = "select version from  mcms_stock_shelf where shelf_name like '%自动化测试%';"
        print(sql)
        cursor.execute(sql)
        results = cursor.fetchone()
        str1 = str(results)
        new_str1 = str1.replace('(', '')
        new_str1 = new_str1.replace(')', '')
        new_str1 = new_str1.replace(',', '')
        print(new_str1)
        cursor.close()
        return new_str1

    def Delete_probeInfo(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除货位信息
        sql = "delete from mcms_stock_shelf where shelf_no like '%自动化测试-2%';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('货位信息删除成功 ')
        # 删除库区信息
        sql = "delete  from mcms_stock_shelf where shelf_name like '%自动化测试%';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('库区信息删除成功 ')
        # 删除多余库房信息
        # sql = "delete  from mcms_stock_info where stock_name like '%东土城路院区_____中心库房';"
        # print(sql)
        # cursor.execute(sql)
        # cursor.execute("commit;")
        # print('多余库房信息删除成功 ')
        cursor.close()
    def Delete_probeInfo_other(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除多余库房信息
        sql = "delete  from mcms_stock_info where stock_name like '%东土城路院区_____中心库房';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('多余库房信息删除成功 ')
        cursor.close()
    def Delete_role(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除角色信息
        sql = "delete from  sys_role where cname like '%自动化测试2%';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('角色信息删除成功 ')
        cursor.close()
    def Delete_user(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除用户信息
        sql = "delete from  sys_user where user_code like '%自动化测试%';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('用户信息删除成功 ')
        cursor.close()
    def Delete_lcTask(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除用户信息
        sql = "delete from mcms_temporary_purchase_detail where pid in(select id from  mcms_temporary_purchase where task_name like '%自动化测试%');"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('临采任务子表信息删除成功 ')
        sql = "delete from mcms_temporary_purchase where task_name like '%自动化测试%';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('临采任务主表信息删除成功 ')
        cursor.close()
    def Delete_ld_directory(self):
        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除用户信息
        sql = "delete from mcms_vbp_detail where pid in(select id from  mcms_vbp where project_name like '%自动化测试%');"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('带量项目子表信息删除成功 ')
        sql = "delete from mcms_vbp where project_name like '%自动化测试%';"
        print(sql)
        cursor.execute(sql)
        cursor.execute("commit;")
        print('带量项目主表信息删除成功 ')
        cursor.close()
# delData().Delete_branch_by_id()
# delData().Delete_goods_change_info()
# delData().Delete_sys_config()
# delData().Delete_sys_message_template()
# delData().get_shelf_name_version()
# delData().Delete_role()
# delData().Delete_user()