code2000.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. from hub import methods, Global
  2. async def code2001(**sources):
  3. """
  4. 新增车辆
  5. """
  6. # --- check ---
  7. if not sources.get('pid'):
  8. return dict(code=1, details=f"something is wrong.")
  9. elif not sources.get('type'):
  10. return dict(code=2, details=f"something is wrong.")
  11. # --- check ---
  12. count = Global.mdb.get_count('VehicleInfo', {'pid': sources.get('pid')})
  13. if count != 0:
  14. return dict(code=3, details=f"something is wrong.")
  15. # --- save ---
  16. """
  17. VehicleInfo: 车辆信息表
  18. VehicleInfo.pid: 车牌号
  19. VehicleInfo.type: 车型号
  20. VehicleInfo.host_address: 工控机地址
  21. VehicleInfo.rtk_address: rtk地址
  22. VehicleInfo.cpe_address: cpe地址
  23. VehicleInfo.release_at: 出厂时期
  24. VehicleInfo.state: 当前状态 (1:离线 2:在线空闲 3: 现场驾驶中 4: 远程驾驶中)
  25. VehicleInfo.permit_state: 遥操状态 (0:允许 1:禁用)
  26. VehicleInfo.update_at: 更新时间
  27. """
  28. data = {
  29. 'pid': sources.get('pid'),
  30. 'type': sources.get('type'),
  31. 'host_address': sources.get('host_address'),
  32. 'rtk_address': sources.get('rtk_address'),
  33. 'cpe_address': sources.get('cpe_address'),
  34. 'release_at': sources.get('release_at'),
  35. 'update_at': methods.now_ts(),
  36. 'state': 1,
  37. 'permit_state': 0,
  38. }
  39. uuid = Global.mdb.add('VehicleInfo', data)
  40. return dict(code=0, data=uuid)
  41. async def code2002(**sources):
  42. """
  43. 查询车辆列表
  44. """
  45. # --- check ---
  46. if not sources.get('page'):
  47. return dict(code=1, details=f"something is wrong.")
  48. elif not sources.get('size'):
  49. return dict(code=2, details=f"something is wrong.")
  50. # --- fill d1 ---
  51. d1 = list()
  52. page = sources.get('page', 1)
  53. size = sources.get('size', 10)
  54. for item in Global.mdb.get_all('VehicleInfo', sort_field=[('update_at', -1)]):
  55. # --- check ---
  56. if sources.get('pid') and sources.get('pid') not in item.get('pid'):
  57. continue
  58. data = {
  59. 'uuid': str(item.get('_id')),
  60. 'pid': item.get('pid'),
  61. 'type': item.get('type'),
  62. 'host_address': item.get('host_address'),
  63. 'rtk_address': item.get('rtk_address'),
  64. 'cpe_address': item.get('cpe_address'),
  65. 'release_at': item.get('release_at'),
  66. 'state': item.get('state', 1),
  67. 'permit_state': item.get('permit_state', 0),
  68. }
  69. d1.append(data)
  70. return dict(code=0, data=d1[(page - 1) * size: page * size], total=len(d1), page=page, size=size)
  71. async def code2003(**sources):
  72. """
  73. 修改指定车辆信息
  74. """
  75. # --- check ---
  76. uuid = sources.get('uuid')
  77. if not uuid:
  78. return dict(code=1, details=f"something is wrong.")
  79. # --- check ---
  80. item = Global.mdb.get_one_by_id('VehicleInfo', uuid)
  81. if not item:
  82. return dict(code=2, details=f"something is wrong.")
  83. # --- check ---
  84. # count = Global.mdb.get_count('VehicleInfo', {'pid': sources.get('pid')})
  85. # if count != 0:
  86. # return dict(code=3, details=f"something is wrong.")
  87. # --- update ---
  88. """
  89. VehicleInfo: 车辆信息表
  90. VehicleInfo.pid: 车牌号
  91. VehicleInfo.type: 车型号
  92. VehicleInfo.host_address: 工控机地址
  93. VehicleInfo.rtk_address: rtk地址
  94. VehicleInfo.cpe_address: cpe地址
  95. VehicleInfo.release_at: 出厂时期
  96. VehicleInfo.state: 当前状态 (1:离线 2:在线空闲 3: 现场驾驶中 4: 远程驾驶中)
  97. VehicleInfo.permit_state: 遥操状态 (0:允许 1:禁用)
  98. VehicleInfo.update_at: 更新时间
  99. """
  100. update_dict = dict()
  101. update_dict['update_at'] = methods.now_ts()
  102. if sources.get('pid'):
  103. update_dict['pid'] = sources.get('pid')
  104. if sources.get('type'):
  105. update_dict['type'] = sources.get('type')
  106. if sources.get('host_address'):
  107. update_dict['host_address'] = sources.get('host_address')
  108. if sources.get('rtk_address'):
  109. update_dict['rtk_address'] = sources.get('rtk_address')
  110. if sources.get('cpe_address'):
  111. update_dict['cpe_address'] = sources.get('cpe_address')
  112. if sources.get('release_at'):
  113. update_dict['release_at'] = sources.get('release_at')
  114. Global.mdb.update_one_by_id('VehicleInfo', uuid, update_dict)
  115. return dict(code=0, data=uuid)
  116. async def code2004(**sources):
  117. """
  118. 禁止指定车辆远程操作
  119. """
  120. # --- check ---
  121. uuid = sources.get('uuid')
  122. if not uuid:
  123. return dict(code=1, details=f"something is wrong.")
  124. # --- check ---
  125. item = Global.mdb.get_one_by_id('VehicleInfo', uuid)
  126. if not item:
  127. return dict(code=2, details=f"something is wrong.")
  128. # --- update ---
  129. """
  130. VehicleInfo: 车辆信息表
  131. VehicleInfo.pid: 车牌号
  132. VehicleInfo.type: 车型号
  133. VehicleInfo.host_address: 工控机地址
  134. VehicleInfo.rtk_address: rtk地址
  135. VehicleInfo.cpe_address: cpe地址
  136. VehicleInfo.release_at: 出厂时期
  137. VehicleInfo.state: 当前状态 (1:离线 2:在线空闲 3: 现场驾驶中 4: 远程驾驶中)
  138. VehicleInfo.permit_state: 遥操状态 (0:允许 1:禁用)
  139. VehicleInfo.update_at: 更新时间
  140. """
  141. update_dict = dict()
  142. update_dict['permit_state'] = 1
  143. item = Global.mdb.update_one_by_id('VehicleInfo', uuid, update_dict, need_back=True)
  144. return dict(code=0, data=item)
  145. async def code2005(**sources):
  146. """
  147. 允许指定车辆远程操作
  148. """
  149. # --- check ---
  150. uuid = sources.get('uuid')
  151. if not uuid:
  152. return dict(code=1, details=f"something is wrong.")
  153. # --- check ---
  154. item = Global.mdb.get_one_by_id('VehicleInfo', uuid)
  155. if not item:
  156. return dict(code=2, details=f"something is wrong.")
  157. # --- update ---
  158. """
  159. VehicleInfo: 车辆信息表
  160. VehicleInfo.pid: 车牌号
  161. VehicleInfo.type: 车型号
  162. VehicleInfo.host_address: 工控机地址
  163. VehicleInfo.rtk_address: rtk地址
  164. VehicleInfo.cpe_address: cpe地址
  165. VehicleInfo.release_at: 出厂时期
  166. VehicleInfo.state: 当前状态 (1:离线 2:在线空闲 3: 现场驾驶中 4: 远程驾驶中)
  167. VehicleInfo.permit_state: 遥操状态 (0:允许 1:禁用)
  168. VehicleInfo.update_at: 更新时间
  169. """
  170. update_dict = dict()
  171. update_dict['permit_state'] = 0
  172. item = Global.mdb.update_one_by_id('VehicleInfo', uuid, update_dict, need_back=True)
  173. return dict(code=0, data=item)
  174. async def code2006(**sources):
  175. """
  176. 删除指定车辆
  177. """
  178. # --- check ---
  179. uuid = sources.get('uuid')
  180. if not uuid:
  181. return dict(code=1, details=f"something is wrong.")
  182. # --- check ---
  183. item = Global.mdb.get_one_by_id('VehicleInfo', uuid)
  184. if not item:
  185. return dict(code=2, details=f"something is wrong.")
  186. # --- clean ---
  187. Global.mdb.remove_one_by_id('VehicleInfo', uuid)
  188. return dict(code=0, data=uuid)
  189. async def code2007(**sources):
  190. """
  191. 获取指定作业车辆详情
  192. """
  193. uuid = sources.get('uuid')
  194. if not uuid:
  195. return dict(code=1, details=f"something is wrong.")
  196. item = Global.mdb.get_one_by_id('VehicleInfo', uuid)
  197. if not item:
  198. return dict(code=2, details=f"something is wrong.")
  199. # --- fill ---
  200. """
  201. VehicleInfo: 车辆信息表
  202. VehicleInfo.pid: 车牌号
  203. VehicleInfo.type: 车型号
  204. VehicleInfo.host_address: 工控机地址
  205. VehicleInfo.rtk_address: rtk地址
  206. VehicleInfo.cpe_address: cpe地址
  207. VehicleInfo.release_at: 出厂时期
  208. VehicleInfo.state: 当前状态 (1:离线 2:在线空闲 3: 现场驾驶中 4: 远程驾驶中)
  209. VehicleInfo.permit_state: 遥操状态 (0:允许 1:禁用)
  210. VehicleInfo.update_at: 更新时间
  211. """
  212. item.pop('_id')
  213. item['uuid'] = uuid
  214. return dict(code=0, data=item)