TaskService.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.fdkankan.manage_jp.task;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.fdkankan.manage_jp.entity.Project;
  4. import com.fdkankan.manage_jp.entity.ProjectSceneGps;
  5. import com.fdkankan.manage_jp.entity.ScenePlus;
  6. import com.fdkankan.manage_jp.httpClient.service.LaserService;
  7. import com.fdkankan.manage_jp.service.IProjectSceneGpsService;
  8. import com.fdkankan.manage_jp.service.ISceneProService;
  9. import com.fdkankan.manage_jp.vo.response.SceneGpsDb;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.scheduling.annotation.Scheduled;
  13. import org.springframework.stereotype.Service;
  14. import java.util.ArrayList;
  15. import java.util.Date;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.stream.Collectors;
  19. @Service
  20. @Slf4j
  21. public class TaskService {
  22. @Autowired
  23. IProjectSceneGpsService projectSceneGpsService;
  24. @Autowired
  25. LaserService laserService;
  26. @Autowired
  27. ISceneProService sceneProService;
  28. @Scheduled(initialDelay = 2000, fixedDelay = 1000 * 60 )
  29. public void run() {
  30. addLaserData();
  31. }
  32. private void addLaserData() {
  33. List<SceneGpsDb> sceneGpsDbs1 = projectSceneGpsService.getNotGpsScene();
  34. if(sceneGpsDbs1.isEmpty()){
  35. log.info("没有需要更新GPS数据的场景");
  36. return;
  37. }
  38. List<ProjectSceneGps> laserssList = new ArrayList<>();
  39. List<ProjectSceneGps> lasersgList = new ArrayList<>();
  40. for (SceneGpsDb sceneGpsDb : sceneGpsDbs1) {
  41. ProjectSceneGps sceneGps = projectSceneGpsService.addGps(sceneGpsDb);
  42. if(sceneGps != null){
  43. log.info("num:{}gps:{}",sceneGpsDb.getNum(),sceneGps);
  44. if(sceneGps.getSceneSource() == 4 ) {
  45. laserssList.add(sceneGps);
  46. }else if( sceneGps.getSceneSource() == 5){
  47. lasersgList.add(sceneGps);
  48. }
  49. }
  50. }
  51. addLaserList(laserssList,4);
  52. addLaserList(lasersgList,5);
  53. }
  54. private void addLaserList(List<ProjectSceneGps> laserssList,Integer sceneSource) {
  55. List<String> sceneMapShowList = new ArrayList<>();
  56. if(!laserssList.isEmpty()){
  57. List<String> numList1 = laserssList.stream().map(ProjectSceneGps::getNum).collect(Collectors.toList());
  58. HashMap<String, JSONObject> ssSceneMap = laserService.list(numList1,sceneSource);
  59. for (ProjectSceneGps sceneGps : laserssList) {
  60. JSONObject ssObj = ssSceneMap.get(sceneGps.getNum());
  61. if(ssObj!=null ){
  62. sceneGps.setWebSite(ssObj.getString("webSite"));
  63. projectSceneGpsService.save(sceneGps);
  64. if(sceneGps.getGpsSource() == 2){
  65. sceneMapShowList.add(sceneGps.getNum());
  66. }
  67. }
  68. }
  69. }
  70. sceneProService.openMapShow(sceneMapShowList);
  71. }
  72. }