ProjectSceneGpsServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. package com.fdkankan.manage_jp.service.impl;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  10. import com.fdkankan.manage_jp.common.PageInfo;
  11. import com.fdkankan.manage_jp.entity.*;
  12. import com.fdkankan.manage_jp.httpClient.service.LaserService;
  13. import com.fdkankan.manage_jp.mapper.IProjectSceneGpsMapper;
  14. import com.fdkankan.manage_jp.mapper.ISceneProMapper;
  15. import com.fdkankan.manage_jp.service.*;
  16. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  17. import com.fdkankan.manage_jp.vo.request.ProjectParam;
  18. import com.fdkankan.manage_jp.vo.request.SceneGpsParam;
  19. import com.fdkankan.manage_jp.vo.request.SceneParam;
  20. import com.fdkankan.manage_jp.vo.response.*;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.springframework.beans.BeanUtils;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26. import java.util.*;
  27. import java.util.stream.Collectors;
  28. /**
  29. * <p>
  30. * 服务实现类
  31. * </p>
  32. *
  33. * @author
  34. * @since 2024-08-16
  35. */
  36. @Service
  37. @Slf4j
  38. public class ProjectSceneGpsServiceImpl extends ServiceImpl<IProjectSceneGpsMapper, ProjectSceneGps> implements IProjectSceneGpsService {
  39. @Autowired
  40. IScenePlusService scenePlusService;
  41. @Autowired
  42. IScenePlusExtService scenePlusExtService;
  43. @Autowired
  44. FYunFileServiceInterface fYunFileServiceInterface;
  45. @Autowired
  46. LaserService laserService;
  47. @Autowired
  48. IUserRoleService userRoleService;
  49. @Override
  50. public List<SceneGpsDb> getNotGpsScene() {
  51. return this.getBaseMapper().getNotGpsScene();
  52. }
  53. @Override
  54. public ProjectSceneGps addGps(SceneGpsDb sceneGpsDb) {
  55. SceneGpsVo sceneGpsVo = getByLaserEdit(sceneGpsDb.getNum());
  56. // if(sceneGpsDb.getSceneSource() == 4 || sceneGpsDb.getSceneSource() == 5){
  57. // sceneGpsVo = getByLaserEdit(sceneGpsDb.getNum());
  58. // }else {
  59. // sceneGpsVo = getByHomeParameters(sceneGpsDb.getDataSource());
  60. // }
  61. if(sceneGpsVo == null && StrUtil.isNotBlank(sceneGpsDb.getGps())){
  62. String gps = sceneGpsDb.getGps();
  63. SceneExtGpsVo extGpsVo = JSONObject.parseObject(gps,SceneExtGpsVo.class);
  64. sceneGpsVo = new SceneGpsVo(extGpsVo.getLatitude(),extGpsVo.getLongitude(),extGpsVo.getAltitude(),1);
  65. }
  66. if(sceneGpsVo != null
  67. && StrUtil.isNotBlank(sceneGpsVo.getLat())
  68. && StrUtil.isNotBlank(sceneGpsVo.getLon())
  69. && StrUtil.isNotBlank(sceneGpsVo.getAlt())){
  70. ProjectSceneGps sceneGps = new ProjectSceneGps();
  71. sceneGps.setNum(sceneGpsDb.getNum());
  72. sceneGps.setWebSite(sceneGpsDb.getWebSite());
  73. sceneGps.setLat(sceneGpsVo.getLat());
  74. sceneGps.setLon(sceneGpsVo.getLon());
  75. sceneGps.setAlt(sceneGpsVo.getAlt());
  76. sceneGps.setGpsSource(sceneGpsVo.getGpsSource());
  77. sceneGps.setSceneSource(sceneGpsDb.getSceneSource());
  78. return sceneGps;
  79. }
  80. return null;
  81. }
  82. private SceneGpsVo getByLaserEdit(String num) {
  83. return laserService.getLocation(num);
  84. }
  85. private SceneGpsVo getByHomeParameters(String dataSource) {
  86. dataSource = dataSource.replaceAll("/mnt/data", "home");
  87. boolean parametersFlag = fYunFileServiceInterface.fileExist(dataSource+"/parameters.json");
  88. if (parametersFlag) {
  89. JSONObject parameters = JSONObject.parseObject(fYunFileServiceInterface.getFileContent(dataSource+"/parameters.json"));
  90. JSONArray parametersArray = parameters.getJSONArray("parameters");
  91. for (Object o : parametersArray) {
  92. JSONObject parameter = (JSONObject) o;
  93. JSONObject ggaLocation = parameter.getJSONObject("value").getJSONObject("ggaLocation");
  94. if (ObjectUtil.isNotEmpty(ggaLocation)
  95. && StrUtil.isNotEmpty(ggaLocation.getString("lon"))
  96. && StrUtil.isNotEmpty(ggaLocation.getString("lat"))
  97. && StrUtil.isNotEmpty(ggaLocation.getString("alt"))) {
  98. log.info("从rtk获取gps信息:{}", parameters);
  99. return new SceneGpsVo(ggaLocation.getString("lat"),ggaLocation.getString("lon"),ggaLocation.getString("alt"),0);
  100. }
  101. }
  102. }
  103. return null;
  104. }
  105. @Override
  106. public void updateGps(String num,String lat,String lon,Integer type) {
  107. LambdaUpdateWrapper<ProjectSceneGps> wrapper = new LambdaUpdateWrapper<>();
  108. wrapper.eq(ProjectSceneGps::getNum,num);
  109. wrapper.set(ProjectSceneGps::getLat,lat);
  110. wrapper.set(ProjectSceneGps::getLon,lon);
  111. wrapper.set(ProjectSceneGps::getGpsSource,type);
  112. this.update(wrapper);
  113. }
  114. @Autowired
  115. ISceneProMapper sceneProMapper;
  116. @Autowired
  117. ITmContractorNumService tmContractorNumService;
  118. @Autowired
  119. IProjectService projectService;
  120. @Autowired
  121. IProjectNumService projectNumService;
  122. private void commonParam(SceneGpsParam param){
  123. }
  124. @Override
  125. public Object listSceneGps(SceneGpsParam param){
  126. if(param.getUserId() == null){
  127. return new ArrayList<>();
  128. }
  129. List<UserRole> roleIdList = userRoleService.getByUserId((param.getUserId()));
  130. List<Long> roleIds = roleIdList.stream().map(UserRole::getRoleId).collect(Collectors.toList());
  131. if(roleIds.contains(5L)) { //平台管理员
  132. param.setUserId(null);
  133. param.setCompanyId(null);
  134. }
  135. List<String> numList = tmContractorNumService.getNumListByCompanyId(param.getCompanyId());
  136. param.setCooperateSceneCodes(numList);
  137. Page<SceneGpsDbVp> sceneGpsDbVpPage = this.getBaseMapper().listGps(new Page<>(param.getPageNum(), param.getPageSize()), param);
  138. return PageInfo.PageInfo(sceneGpsDbVpPage);
  139. }
  140. @Override
  141. public Object allSceneGps(SceneGpsParam param) {
  142. if(param.getUserId() == null){
  143. return new ArrayList<>();
  144. }
  145. List<UserRole> roleIdList = userRoleService.getByUserId((param.getUserId()));
  146. List<Long> roleIds = roleIdList.stream().map(UserRole::getRoleId).collect(Collectors.toList());
  147. HashMap<Integer,List<String>> projectNumMap = new HashMap<>();
  148. HashMap<Integer,Project> projectMap = new HashMap<>();
  149. if(param.getType() == 0){ //项目场景
  150. List<Project> projectList = new ArrayList<>();
  151. if(!roleIds.contains(5L) && param.getProjectId() == null) { //平台管理员
  152. projectList = projectService.listByCompanyId(param.getCompanyId());
  153. }else if(param.getProjectId() == null){
  154. projectList = projectService.listShow();
  155. }else {
  156. Project project = projectService.getById(param.getProjectId());
  157. projectList = Arrays.asList(project);
  158. }
  159. if(projectList == null || projectList.isEmpty()){
  160. return new ArrayList<>();
  161. }
  162. for (Project project : projectList) {
  163. projectMap.put(project.getId(),project);
  164. }
  165. List<Integer> projectIds = projectList.stream().map(Project::getId).collect(Collectors.toList());
  166. List<ProjectNum> projectNums = projectNumService.getByProjectId(projectIds);
  167. for (ProjectNum projectNum : projectNums) {
  168. if(projectNumMap.get(projectNum.getProjectId()) == null){
  169. List<String> proNumList = new ArrayList<>();
  170. proNumList.add(projectNum.getNum());
  171. projectNumMap.put(projectNum.getProjectId(),proNumList);
  172. }else {
  173. projectNumMap.get(projectNum.getProjectId()).add(projectNum.getNum());
  174. }
  175. }
  176. List<String> numList = projectNums.stream().map(ProjectNum::getNum).collect(Collectors.toList());
  177. param.setNumList(numList);
  178. }
  179. if(param.getType() == 1 ){
  180. if(roleIds.contains(5L)) { //平台管理员
  181. param.setUserId(null);
  182. param.setCompanyId(null);
  183. }
  184. List<String> numList = tmContractorNumService.getNumListByCompanyId(param.getCompanyId());
  185. param.setCooperateSceneCodes(numList);
  186. if(param.getProjectId() != null){
  187. Project project = projectService.getById(param.getProjectId());
  188. if(project == null){
  189. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  190. }
  191. List<ProjectNum> projectNumList = projectNumService.getByProjectId(Arrays.asList(param.getProjectId()));
  192. if(projectNumList== null || projectNumList.isEmpty()){
  193. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  194. }
  195. List<String> projectNums = projectNumList.stream().map(ProjectNum::getNum).collect(Collectors.toList());
  196. param.setNumList(projectNums);
  197. }
  198. }
  199. Page<SceneGpsDbVp> sceneGpsDbVpPage = this.getBaseMapper().listGps(new Page<>(1, Integer.MAX_VALUE), param);
  200. List<SceneGpsDbVp> sceneGpsDbVps = sceneGpsDbVpPage.getRecords();
  201. if(param.getType() == 1){
  202. return sceneGpsDbVps;
  203. }
  204. if(param.getType() == 0){
  205. List< ProjectSceneMapVo> voList = new ArrayList<>();
  206. HashMap<String,SceneGpsDbVp> scenMap = new HashMap<>();
  207. for (SceneGpsDbVp sceneGpsDbVp : sceneGpsDbVps) {
  208. scenMap.put(sceneGpsDbVp.getNum(),sceneGpsDbVp);
  209. }
  210. for (Integer projectId : projectMap.keySet()) {
  211. ProjectSceneMapVo vo = new ProjectSceneMapVo();
  212. BeanUtils.copyProperties(projectMap.get(projectId),vo);
  213. vo.setTitle(projectMap.get(projectId).getProjectName());
  214. vo.setId(projectId);
  215. List<String> list = projectNumMap.get(projectId);
  216. List<SceneGpsDbVp> listScene = new ArrayList<>();
  217. if(list != null){
  218. for (String num : list) {
  219. SceneGpsDbVp sceneGpsDbVp = scenMap.get(num);
  220. if(sceneGpsDbVp != null){
  221. listScene.add(sceneGpsDbVp);
  222. }
  223. }
  224. }
  225. vo.setSceneList(listScene);
  226. voList.add(vo);
  227. }
  228. return voList;
  229. }
  230. return new ArrayList<>();
  231. }
  232. @Override
  233. public ProjectSceneGps getByNum(String num) {
  234. LambdaQueryWrapper<ProjectSceneGps> wrapper = new LambdaQueryWrapper<>();
  235. wrapper.eq(ProjectSceneGps::getNum,num);
  236. return this.getOne(wrapper);
  237. }
  238. @Override
  239. public void deleteByNumList(List<String> numList) {
  240. if(numList == null || numList.isEmpty()){
  241. return;
  242. }
  243. LambdaQueryWrapper<ProjectSceneGps> wrapper = new LambdaQueryWrapper<>();
  244. wrapper.in(ProjectSceneGps::getNum,numList);
  245. this.remove(wrapper);
  246. }
  247. }