DatabaseSearchPickCmd.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import time
  2. import pymysql as psql
  3. import message_pb2 as message
  4. import threading
  5. class DBSeacherPickCmd():
  6. def __init__(self,ip,port,database,user,password):
  7. self.ip=ip
  8. self.port=port
  9. self.database=database
  10. self.user=user
  11. self.password=password
  12. self._close=False
  13. self._opendoor_callback=None
  14. self.conn=psql.connect(host=ip,
  15. port=port,
  16. database=database,
  17. charset="utf8",
  18. user=user,
  19. passwd=password)
  20. def close(self):
  21. self._close=True
  22. self.join()
  23. self.conn.close()
  24. def search_pickcmd(self):
  25. # self.conn.begin()
  26. cursor=self.conn.cursor()
  27. SQL="select * from command_queue where statu=2 " #寻找已到出口的取车指令
  28. cursor.execute(SQL)
  29. pick_cmds=cursor.fetchall()
  30. self.conn.commit()
  31. cursor.close()
  32. return pick_cmds
  33. def delete_cmd(self,id):
  34. # self.conn.begin()
  35. cursor=self.conn.cursor()
  36. SQL1="select * from command_queue for update"
  37. cursor.execute(SQL1)
  38. SQL2="delete from command_queue where statu=2 and export_id=%d"%id
  39. cursor.execute(SQL2)
  40. self.conn.commit()
  41. cursor.close()
  42. '''
  43. def run(self):
  44. while self._close==False:
  45. cmds=self.search_pickcmd()
  46. for cmd in cmds:
  47. if len(cmd)>=9:
  48. table=message.pick_table()
  49. table.car_number=cmd[0]
  50. table.primary_key=cmd[1]
  51. table.unit=cmd[2]
  52. table.queue_id=cmd[3]
  53. table.type=cmd[4]
  54. table.statu=cmd[5]
  55. table.export_id=cmd[8]
  56. if not table.export_id==None:
  57. self._opendoor_callback(table.export_id,table)
  58. time.sleep(1)
  59. '''