min_from_database.py 810 B

12345678910111213141516171819
  1. from abstract_api import AbstractApi
  2. from apis.operate_mysql import OperateMysql
  3. class Min_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 limit 1;" % (
  10. basic_data, res1['table_name'], res1['begin_time'], res1['end_time'], basic_data)
  11. res2 = operate_mysql.execute_sql(sql1)
  12. if len(res2) != 0:
  13. res = {request['keys'][0]: res2[0][basic_data], request['keys'][1]: res2[0]['times']}
  14. return res
  15. else:
  16. return None