DatabaseSearchPickCmd.py 2.2 KB

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