max_from_database.py 809 B

123456789101112131415161718
  1. from abstract_api import AbstractApi
  2. from apis.operate_mysql import OperateMysql
  3. class Max_from_database(AbstractApi):
  4. def operation(self, request):
  5. operate_mysql = OperateMysql()
  6. basic_data = request['basic_data']
  7. serial_number = basic_data.replace('c', '')
  8. res1 = operate_mysql.return_result(request, serial_number)
  9. sql1 = "SELECT %s, CAST(times AS CHAR) as times FROM %s WHERE times > \'%s\' and times < \'%s\' ORDER BY %s desc limit 1;" % (basic_data, res1['table_name'], res1['begin_time'], res1['end_time'], basic_data)
  10. res2 = operate_mysql.execute_sql(sql1)
  11. if len(res2) != 0:
  12. res = {request['keys'][0]: res2[0][basic_data], request['keys'][1]: res2[0]['times']}
  13. return res
  14. else:
  15. return None