DatabaseSearchPickCmd.py 1.9 KB

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