# -*- encoding=utf8 -*-


import pymysql

class sql_get_info(object):

    def get_mcms_stock_info(self,stock_name="东土城院区中心库房"):
        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 = "select id from mcms_stock_info where stock_name = '%s';"%stock_name
        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 get_mcms_stock_shelf_info(self,stock_id):

        connection = pymysql.connect(host="10.17.65.108", user="root", password="Cmic.2023", database="spd3_herp_test2",
                                     charset="utf8")
        cursor = connection.cursor()
        # 删除产品信息修改数据
        sql = "select shelf_code from mcms_stock_shelf where stock_id=%s and stock_type=0 and shelf_no='001';"%stock_id
        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

# stock_id=sql_get_info().get_mcms_stock_info()
#
# sql_get_info().get_mcms_stock_shelf_info(stock_id)
