## 查询公司名称
methodlists="SELECT * FROM `tbl_uts_manage_company` where ID=@ID;"
## 获取数据库表
getDbName="SHOW DATABASES;"
getCompany = "SELECT CustomerName FROM `tbl_uts_manage_company`;"
## 获取@TBName数据库表结构
getTable = '''
USE @DBName ;
SELECT 
    COLUMN_NAME AS 'name',
    DATA_TYPE AS 'type',
    COLUMN_COMMENT AS 'notes',
    CHARACTER_MAXIMUM_LENGTH AS 'long'
FROM 
    INFORMATION_SCHEMA.COLUMNS
WHERE 
    TABLE_SCHEMA = '@DBName' 
    AND TABLE_NAME = '@TBName'
ORDER BY 
    TABLE_NAME, 
    ORDINAL_POSITION;
'''
## 添加@TBName数据库表字段
addTable = '''
USE @dbName;
ALTER TABLE @TBName
ADD COLUMN @name @type@long COMMENT '@notes';
'''
## 修改@TBName数据库表字段
updateTable = '''
USE @dbName;
ALTER TABLE @TBName
CHANGE COLUMN @oldName @name @type@long COMMENT '@notes';
'''
## 删除@TBName数据库表字段
deleteTable = '''
USE @dbName;
ALTER TABLE @TBName DROP COLUMN @name;
'''

## 查询tbl_uts_useroperation表数据
getLoginLogCount = "SELECT MAX(ID) AS LogCount FROM uts_manage.tbl_uts_useroperation;"
def getLoginLog(last_id = ""):
    # 如果没有提供last_id，则查询最新的25条记录
    if last_id == "":
        SQL1 = f"SELECT * FROM uts_manage.tbl_uts_useroperation ORDER BY ID DESC LIMIT 25;"
        return SQL1
    else:
        # 如果提供了last_id，则从该ID之后查询最新的25条记录
        SQL2 = f"SELECT * FROM uts_manage.tbl_uts_useroperation WHERE ID < {last_id} ORDER BY ID DESC LIMIT 25;"
        return SQL2


## 查询utsTestLog数据
## 查询机型列表
getModelList = '''
SELECT * FROM @dbName.tbl_project WHERE IsValid = TRUE;
'''
## 查询站位列表
getStationList = '''
SELECT * FROM @dbName.tbl_stationlist WHERE ProjectID = @ProjectID AND IsValid = TRUE ORDER BY ArtworkOrder;
'''
## 查询测试机台列表
getTestDeviceList = '''
SELECT * FROM uts_manage.tbl_uts_manage_dataservicelist AS ser 
WHERE ID IN (SELECT log.ServiceID FROM @dbName.@tbName AS log GROUP BY log.ServiceID) AND ser.ServiceValid = TRUE;
'''
## 查询错误步骤列表
getFailStepsList = '''
SELECT FailSteps FROM @dbName.@tbName WHERE FailSteps IS NOT NULL AND FailSteps != '' GROUP BY FailSteps;
'''
##查询筛选字段列表
getColumnNameList = '''
SHOW COLUMNS FROM @dbName.@tbName 
WHERE Field NOT IN ('ID', 'ServiceID', 'StartTime', 'DUT_SN', 'TestResult', 'Failsteps');
'''