map.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. const Service = require('egg').Service;
  3. class MapService extends Service {
  4. async points( adcode )
  5. {
  6. if( adcode == undefined || adcode == "") return [];
  7. let mysql = this.app.mysql;
  8. let ret = await mysql.query("select id, name, longitude, latitude from area where parent_id in (select id from area where parent_id=?) or id in (select id from area where parent_id=?)", [adcode, adcode]);
  9. return {list:ret};
  10. }
  11. async search( query ) {
  12. let adcode = query.adcode;
  13. if( !adcode ) return { list:[] };
  14. let name = query.name;
  15. let where = name? `and name like '%${name}%'`:"";
  16. let mysql = this.app.mysql;
  17. let ret = await mysql.query(`select id, name, longitude, latitude from area where (parent_id in (select id from area where parent_id=?) or id in (select id from area where parent_id=?) ${where})`, [adcode, adcode]);
  18. return {list:ret};
  19. }
  20. /**
  21. *
  22. * @param {更新航线配置} data
  23. * data.id 任务id
  24. * data.config = '{
  25. * lines=[
  26. * [{lon,lat}],
  27. * []
  28. * ]
  29. * }'
  30. */
  31. async updateNaviConfig(data) {
  32. let id = data.id;
  33. if( !id ) throw "任务ID为空";
  34. let config = data.config?data.config:"";
  35. let mysql = this.app.mysql;
  36. let ret = await mysql.query(`update train_records set navi_config='${config}' where id=${id}`);
  37. return ret;
  38. }
  39. }
  40. module.exports = MapService;