123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- package com.fdkankan.manage_jp.service.impl;
- import cn.hutool.core.util.ObjectUtil;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.manage_jp.common.PageInfo;
- import com.fdkankan.manage_jp.entity.*;
- import com.fdkankan.manage_jp.httpClient.service.LaserService;
- import com.fdkankan.manage_jp.mapper.IProjectSceneGpsMapper;
- import com.fdkankan.manage_jp.mapper.ISceneProMapper;
- import com.fdkankan.manage_jp.service.*;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.manage_jp.vo.request.ProjectParam;
- import com.fdkankan.manage_jp.vo.request.SceneGpsParam;
- import com.fdkankan.manage_jp.vo.request.SceneParam;
- import com.fdkankan.manage_jp.vo.response.*;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2024-08-16
- */
- @Service
- @Slf4j
- public class ProjectSceneGpsServiceImpl extends ServiceImpl<IProjectSceneGpsMapper, ProjectSceneGps> implements IProjectSceneGpsService {
- @Autowired
- IScenePlusService scenePlusService;
- @Autowired
- IScenePlusExtService scenePlusExtService;
- @Autowired
- FYunFileServiceInterface fYunFileServiceInterface;
- @Autowired
- LaserService laserService;
- @Autowired
- IUserRoleService userRoleService;
- @Override
- public List<SceneGpsDb> getNotGpsScene() {
- return this.getBaseMapper().getNotGpsScene();
- }
- @Override
- public ProjectSceneGps addGps(SceneGpsDb sceneGpsDb) {
- SceneGpsVo sceneGpsVo = getByLaserEdit(sceneGpsDb.getNum());
- // if(sceneGpsDb.getSceneSource() == 4 || sceneGpsDb.getSceneSource() == 5){
- // sceneGpsVo = getByLaserEdit(sceneGpsDb.getNum());
- // }else {
- // sceneGpsVo = getByHomeParameters(sceneGpsDb.getDataSource());
- // }
- if(sceneGpsVo == null && StrUtil.isNotBlank(sceneGpsDb.getGps())){
- String gps = sceneGpsDb.getGps();
- SceneExtGpsVo extGpsVo = JSONObject.parseObject(gps,SceneExtGpsVo.class);
- sceneGpsVo = new SceneGpsVo(extGpsVo.getLatitude(),extGpsVo.getLongitude(),extGpsVo.getAltitude(),1);
- }
- if(sceneGpsVo != null
- && StrUtil.isNotBlank(sceneGpsVo.getLat())
- && StrUtil.isNotBlank(sceneGpsVo.getLon())
- && StrUtil.isNotBlank(sceneGpsVo.getAlt())){
- ProjectSceneGps sceneGps = new ProjectSceneGps();
- sceneGps.setNum(sceneGpsDb.getNum());
- sceneGps.setWebSite(sceneGpsDb.getWebSite());
- sceneGps.setLat(sceneGpsVo.getLat());
- sceneGps.setLon(sceneGpsVo.getLon());
- sceneGps.setAlt(sceneGpsVo.getAlt());
- sceneGps.setGpsSource(sceneGpsVo.getGpsSource());
- sceneGps.setSceneSource(sceneGpsDb.getSceneSource());
- return sceneGps;
- }
- return null;
- }
- private SceneGpsVo getByLaserEdit(String num) {
- return laserService.getLocation(num);
- }
- private SceneGpsVo getByHomeParameters(String dataSource) {
- dataSource = dataSource.replaceAll("/mnt/data", "home");
- boolean parametersFlag = fYunFileServiceInterface.fileExist(dataSource+"/parameters.json");
- if (parametersFlag) {
- JSONObject parameters = JSONObject.parseObject(fYunFileServiceInterface.getFileContent(dataSource+"/parameters.json"));
- JSONArray parametersArray = parameters.getJSONArray("parameters");
- for (Object o : parametersArray) {
- JSONObject parameter = (JSONObject) o;
- JSONObject ggaLocation = parameter.getJSONObject("value").getJSONObject("ggaLocation");
- if (ObjectUtil.isNotEmpty(ggaLocation)
- && StrUtil.isNotEmpty(ggaLocation.getString("lon"))
- && StrUtil.isNotEmpty(ggaLocation.getString("lat"))
- && StrUtil.isNotEmpty(ggaLocation.getString("alt"))) {
- log.info("从rtk获取gps信息:{}", parameters);
- return new SceneGpsVo(ggaLocation.getString("lat"),ggaLocation.getString("lon"),ggaLocation.getString("alt"),0);
- }
- }
- }
- return null;
- }
- @Override
- public void updateGps(String num,String lat,String lon,Integer type) {
- LambdaUpdateWrapper<ProjectSceneGps> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(ProjectSceneGps::getNum,num);
- wrapper.set(ProjectSceneGps::getLat,lat);
- wrapper.set(ProjectSceneGps::getLon,lon);
- wrapper.set(ProjectSceneGps::getGpsSource,type);
- this.update(wrapper);
- }
- @Autowired
- ISceneProMapper sceneProMapper;
- @Autowired
- ITmContractorNumService tmContractorNumService;
- @Autowired
- IProjectService projectService;
- @Autowired
- IProjectNumService projectNumService;
- private void commonParam(SceneGpsParam param){
- }
- @Override
- public Object listSceneGps(SceneGpsParam param){
- if(param.getUserId() == null){
- return new ArrayList<>();
- }
- List<UserRole> roleIdList = userRoleService.getByUserId((param.getUserId()));
- List<Long> roleIds = roleIdList.stream().map(UserRole::getRoleId).collect(Collectors.toList());
- if(roleIds.contains(5L)) { //平台管理员
- param.setUserId(null);
- param.setCompanyId(null);
- }
- List<String> numList = tmContractorNumService.getNumListByCompanyId(param.getCompanyId());
- param.setCooperateSceneCodes(numList);
- Page<SceneGpsDbVp> sceneGpsDbVpPage = this.getBaseMapper().listGps(new Page<>(param.getPageNum(), param.getPageSize()), param);
- return PageInfo.PageInfo(sceneGpsDbVpPage);
- }
- @Override
- public Object allSceneGps(SceneGpsParam param) {
- if(param.getUserId() == null){
- return new ArrayList<>();
- }
- List<UserRole> roleIdList = userRoleService.getByUserId((param.getUserId()));
- List<Long> roleIds = roleIdList.stream().map(UserRole::getRoleId).collect(Collectors.toList());
- HashMap<Integer,List<String>> projectNumMap = new HashMap<>();
- HashMap<Integer,Project> projectMap = new HashMap<>();
- if(param.getType() == 0){ //项目场景
- List<Project> projectList = new ArrayList<>();
- if(!roleIds.contains(5L) && param.getProjectId() == null) { //平台管理员
- projectList = projectService.listByCompanyId(param.getCompanyId());
- }else if(param.getProjectId() == null){
- projectList = projectService.listShow();
- }else {
- Project project = projectService.getById(param.getProjectId());
- projectList = Arrays.asList(project);
- }
- if(projectList == null || projectList.isEmpty()){
- return new ArrayList<>();
- }
- for (Project project : projectList) {
- projectMap.put(project.getId(),project);
- }
- List<Integer> projectIds = projectList.stream().map(Project::getId).collect(Collectors.toList());
- List<ProjectNum> projectNums = projectNumService.getByProjectId(projectIds);
- for (ProjectNum projectNum : projectNums) {
- if(projectNumMap.get(projectNum.getProjectId()) == null){
- List<String> proNumList = new ArrayList<>();
- proNumList.add(projectNum.getNum());
- projectNumMap.put(projectNum.getProjectId(),proNumList);
- }else {
- projectNumMap.get(projectNum.getProjectId()).add(projectNum.getNum());
- }
- }
- List<String> numList = projectNums.stream().map(ProjectNum::getNum).collect(Collectors.toList());
- param.setNumList(numList);
- }
- if(param.getType() == 1 ){
- if(roleIds.contains(5L)) { //平台管理员
- param.setUserId(null);
- param.setCompanyId(null);
- }
- List<String> numList = tmContractorNumService.getNumListByCompanyId(param.getCompanyId());
- param.setCooperateSceneCodes(numList);
- if(param.getProjectId() != null){
- Project project = projectService.getById(param.getProjectId());
- if(project == null){
- return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
- }
- List<ProjectNum> projectNumList = projectNumService.getByProjectId(Arrays.asList(param.getProjectId()));
- if(projectNumList== null || projectNumList.isEmpty()){
- return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
- }
- List<String> projectNums = projectNumList.stream().map(ProjectNum::getNum).collect(Collectors.toList());
- param.setNumList(projectNums);
- }
- }
- Page<SceneGpsDbVp> sceneGpsDbVpPage = this.getBaseMapper().listGps(new Page<>(1, Integer.MAX_VALUE), param);
- List<SceneGpsDbVp> sceneGpsDbVps = sceneGpsDbVpPage.getRecords();
- if(param.getType() == 1){
- return sceneGpsDbVps;
- }
- if(param.getType() == 0){
- List< ProjectSceneMapVo> voList = new ArrayList<>();
- HashMap<String,SceneGpsDbVp> scenMap = new HashMap<>();
- for (SceneGpsDbVp sceneGpsDbVp : sceneGpsDbVps) {
- scenMap.put(sceneGpsDbVp.getNum(),sceneGpsDbVp);
- }
- for (Integer projectId : projectMap.keySet()) {
- ProjectSceneMapVo vo = new ProjectSceneMapVo();
- BeanUtils.copyProperties(projectMap.get(projectId),vo);
- vo.setTitle(projectMap.get(projectId).getProjectName());
- vo.setId(projectId);
- List<String> list = projectNumMap.get(projectId);
- List<SceneGpsDbVp> listScene = new ArrayList<>();
- if(list != null){
- for (String num : list) {
- SceneGpsDbVp sceneGpsDbVp = scenMap.get(num);
- if(sceneGpsDbVp != null){
- listScene.add(sceneGpsDbVp);
- }
- }
- }
- vo.setSceneList(listScene);
- voList.add(vo);
- }
- return voList;
- }
- return new ArrayList<>();
- }
- @Override
- public ProjectSceneGps getByNum(String num) {
- LambdaQueryWrapper<ProjectSceneGps> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ProjectSceneGps::getNum,num);
- return this.getOne(wrapper);
- }
- @Override
- public void deleteByNumList(List<String> numList) {
- if(numList == null || numList.isEmpty()){
- return;
- }
- LambdaQueryWrapper<ProjectSceneGps> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(ProjectSceneGps::getNum,numList);
- this.remove(wrapper);
- }
- }
|