| | |
| | | package com.ruoyi.sy.controller; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.ruoyi.client.ARDCarGPSLogInClient; |
| | | import com.ruoyi.client.ARDCarSYGPSClient; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.sy.param.ArdSyCarParam; |
| | | import com.ruoyi.sy.vo.ArdSyCarVo; |
| | | import com.ruoyi.sy.domain.ArdSyUser; |
| | | import com.ruoyi.sy.gps31.PositionContainer; |
| | | import com.ruoyi.sy.gps31.PushClientImplAlarm; |
| | | import com.ruoyi.sy.gps31.PushClientImplPosition; |
| | | import com.ruoyi.sy.service.IArdSyUserService; |
| | | import com.ruoyi.sy.service.SysParaService; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | | import com.ruoyi.common.core.domain.entity.SysConfig; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.utils.httpclient.SYCarClient; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.utils.forest.SYClient; |
| | | import com.ruoyi.utils.result.Results; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.bytedeco.javacv.CanvasFrame; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | import com.ruoyi.sy.domain.ArdSyCar; |
| | | import com.ruoyi.sy.service.IArdSyCarService; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * 三一车辆Controller |
| | | * |
| | | * |
| | | * @author ard |
| | | * @date 2023-06-26 |
| | | */ |
| | |
| | | |
| | | private Map<Integer,Map<String,String>> logInMap = new HashMap(); |
| | | |
| | | @Autowired |
| | | private SysParaService sysParaService; |
| | | |
| | | @Autowired |
| | | private IArdSyUserService iArdSyUserService; |
| | | |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService sysDeptService; |
| | | |
| | | @Resource |
| | | private SYClient sYClient; |
| | | |
| | | private ArdSyCarController ardSyCarController; |
| | | |
| | | @Value("${syCar.enabled}") |
| | | private Boolean syCarEnabled; |
| | | |
| | | @PostConstruct |
| | | public void init(){ |
| | | ardSyCarController = this; |
| | | ardSyCarController.sysConfigService = this.sysConfigService; |
| | | ardSyCarController.iArdSyUserService = this.iArdSyUserService; |
| | | SysConfig config = new SysConfig(); |
| | | config.setConfigKey("syCarPT"); |
| | | List<SysConfig> sysConfigResult = sysConfigService.selectConfigList(config); |
| | | String syURL = ""; |
| | | //if(sysConfigResult.size() == 0){ |
| | | if(!syCarEnabled){//三一车辆加入开关 |
| | | return; |
| | | }else{ |
| | | syURL = sysConfigResult.get(0).getConfigValue(); |
| | | } |
| | | String ip = syURL.split(":")[1].replace("//", ""); |
| | | List<ArdSyUser> ardSyUserList = iArdSyUserService.selectSyUser(); |
| | | //车辆实时位置线程 |
| | | if(ardSyUserList.size()==0) |
| | | { |
| | | return; |
| | | } |
| | | PushClientImplPosition pushClientImplPosition = new PushClientImplPosition(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword()); |
| | | Thread pushClientImplPositionThread = new Thread(pushClientImplPosition); |
| | | pushClientImplPositionThread.start(); |
| | | |
| | | Date date = new Date(); |
| | | Timer carPositionTimer = new Timer();//定时推送实时位置 |
| | | TimerTask carPositionTask =new TimerTask(){ |
| | | @Override |
| | | public void run(){ |
| | | ardSyCarService.sendArdSyCarPosition(); |
| | | } |
| | | }; |
| | | //carPositionTimer.scheduleAtFixedRate(carPositionTask,date,3*1000);//弃用 |
| | | //车辆实时报警线程 |
| | | PushClientImplAlarm pushClientImplAlarm = new PushClientImplAlarm(ip,ardSyUserList.get(0).getUserId(),ardSyUserList.get(0).getPassword()); |
| | | Thread pushClientImplAlarmThread = new Thread(pushClientImplAlarm); |
| | | pushClientImplAlarmThread.start(); |
| | | } |
| | | |
| | | /** |
| | | * 查询三一车辆列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(ArdSyCar ardSyCar) |
| | | @ApiOperation("查询三一车辆列表") |
| | | public AjaxResult list(ArdSyCarParam ardSyCarParam) |
| | | { |
| | | startPage(); |
| | | List<ArdSyCar> list = ardSyCarService.selectArdSyCarList(ardSyCar); |
| | | return getDataTable(list); |
| | | PageHelper.startPage(ardSyCarParam.getPageNum(),ardSyCarParam.getPageSize()); |
| | | String userId = SecurityUtils.getUserId(); |
| | | Map<String,Object> result = ardSyCarService.getArdSyCarAll(userId); |
| | | return ardSyCarService.ardSyCarList(ardSyCarParam,result); |
| | | } |
| | | |
| | | /** |
| | |
| | | return error("三一车辆url没有录入"); |
| | | }else{ |
| | | syURL = sysConfigResult.get(0).getConfigValue(); |
| | | Map<String,Object> result = SYCarClient.logIn(syURL,userId, password); |
| | | //Map<String,Object> result = SYCarClient.logIn(syURL,userId, password); |
| | | String passwordMd5 = DigestUtils.md5Hex(password); |
| | | Map<String,Object> result = sYClient.logIn(syURL,passwordMd5,userId); |
| | | return success(result); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 获取未挂接权限的三一车辆 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarNoRight')") |
| | | // @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarNoRight')") |
| | | @PostMapping("/getArdSyCarNoRight") |
| | | @ApiOperation("获取未挂接权限的三一车辆") |
| | | public Map<String,Object> getArdSyCarNoRight(){ |
| | |
| | | /** |
| | | * 获取全部的三一车辆 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarAll')") |
| | | // @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarAll')") |
| | | @PostMapping("/getArdSyCarAll") |
| | | @ApiOperation("获取全部的三一车辆") |
| | | public Map<String,Object> getArdSyCarAll(){ |
| | |
| | | /** |
| | | * 获取全部车辆模型 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:getAllCarModel')") |
| | | // @PreAuthorize("@ss.hasPermi('sy:syCar:getAllCarModel')") |
| | | @PostMapping("/getAllCarModel") |
| | | @ApiOperation("获取全部车辆模型") |
| | | public Map<String,Object> getAllCarModel(){ |
| | |
| | | public Map<String,Object> allListByUser(){ |
| | | String usersId = SecurityUtils.getUserId(); |
| | | ArdSyUser ardSyUser = iArdSyUserService.userById(usersId); |
| | | Map<String,Object> result0 = new HashMap(); |
| | | //判断关联表是否有数据 |
| | | if(ardSyUser!=null){ |
| | | //31用户名密码 |
| | | String username31 = ardSyUser.getUserId(); |
| | | String password31 = ardSyUser.getPassword(); |
| | | //查询地址 |
| | | Map<String, String> result = logInMap.get(Integer.parseInt(usersId)); |
| | | String syURL = sysParaService.getSYURL(); |
| | | Map<String, Object> result1 = ARDCarGPSLogInClient.loginIn(syURL,username31, password31); |
| | | result = new HashMap(); |
| | | result.put("userId", username31); |
| | | result.put("sessionId", (String) result1.get("sessionId")); |
| | | try { |
| | | result0 = ARDCarSYGPSClient.getCarGPSTeamList(syURL,result.get("userId"),result.get("sessionId"));// |
| | | } catch (Exception e) { |
| | | Map<String,Object> map = new HashMap(); |
| | | map.put("rspCode", 0); |
| | | map.put("list", new ArrayList()); |
| | | return map; |
| | | } |
| | | int online = 0; |
| | | for(Map<String,Object> map : (List<Map<String,Object>>) result0.get("list")){ |
| | | Map<String,Object> resultMap = (Map<String, Object>) ARDCarSYGPSClient.getCarListByTeamId(syURL,(String)map.get("teamId"),result.get("sessionId")); |
| | | List<Map<String,Object>> carList = (List<Map<String, Object>>) resultMap.get("carList"); |
| | | for(Map<String,Object> m : carList){ |
| | | if(((String) m.get("stateCn")).contains("在线")){ |
| | | online = online + 1; |
| | | }else{ |
| | | continue; |
| | | } |
| | | } |
| | | for(Map<String,Object> m : (List<Map<String,Object>>) result0.get("list")){ |
| | | if(((String) m.get("teamId")).equals(((String) map.get("teamId")))){ |
| | | map.put("count", Integer.parseInt((String) m.get("carNum"))); |
| | | } |
| | | } |
| | | map.put("online", online); |
| | | online = 0; |
| | | } |
| | | }else { |
| | | result0.put("列表为空!","无关联账号!"); |
| | | } |
| | | return result0; |
| | | String syURL = sysConfigService.getSYURL(); |
| | | //根据userId查询部门Id |
| | | SysUser sysUser = sysUserService.selectUserById(usersId); |
| | | //根据当前deptId或者当前及所属下级的所有deptId |
| | | List<Long> deptList = sysDeptService.deptIdBySub(sysUser.getDeptId()); |
| | | return ardSyCarService.allListByUser(ardSyUser,syURL,usersId,deptList); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:carListById')") |
| | | @GetMapping("carListById") |
| | | @ApiOperation("根据车辆ID获取车辆列表") |
| | | public List<ArdSyCar> carListById(String carId){ |
| | | return ardSyCarService.carListById(carId); |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:carList')") |
| | | @PostMapping("carList") |
| | | @ApiOperation("根据teamId获取车辆列表") |
| | | public Results getCarList(@RequestBody Map<String,String> map){ |
| | | String usersId = SecurityUtils.getUserId(); |
| | | ArdSyUser ardSyUser = iArdSyUserService.userById(usersId); |
| | | String syURL = sysConfigService.getSYURL(); |
| | | String teamId = map.get("teamId"); |
| | | //判断关联表是否有数据 |
| | | if(ardSyUser!=null) { |
| | | //查询出31的车辆数据 |
| | | List<Map<String,String>> list = ardSyCarService.getCarList(ardSyUser,syURL,usersId,teamId); |
| | | if(list.isEmpty()){ |
| | | return Results.succeed(new ArrayList()); |
| | | } |
| | | //根据userId查询部门Id |
| | | SysUser sysUser = sysUserService.selectUserById(usersId); |
| | | //根据当前deptId或者当前及所属下级的所有deptId |
| | | List<Long> deptList = sysDeptService.deptIdBySub(sysUser.getDeptId()); |
| | | //根据dept集合查询出所有对应的车辆列表并赋值 |
| | | return Results.succeed(ardSyCarService.carIdByDeptList(deptList,list)); |
| | | }else { |
| | | return Results.error("列表为空!无关联账号!"); |
| | | } |
| | | } |
| | | |
| | | // @PreAuthorize("@ss.hasPermi('sy:syCar:carListById')") |
| | | @PostMapping("/carListById/{id}") |
| | | @ApiOperation("根据车辆ID获取车辆列表") |
| | | public Results carListById(@PathVariable String id){ |
| | | return ardSyCarService.carListById(id); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:getCarGPSHistory')") |
| | | @PostMapping("getCarGPSHistory") |
| | | @ApiOperation("根据车辆ID获取历史轨迹") |
| | | public Results getCarGPSTrack(@RequestBody Map<String,String> map) { |
| | | String usersId = SecurityUtils.getUserId(); |
| | | ArdSyUser ardSyUser = iArdSyUserService.userById(usersId); |
| | | String syURL = sysConfigService.getSYURL(); |
| | | return ardSyCarService.getCarGPSTrack(map,syURL, ardSyUser); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyUserByUsersId')") |
| | | @PostMapping("getArdSyUserByUsersId") |
| | | @ApiOperation("获取三一平台对应用户名密码") |
| | | public Results getArdSyUserByUsersId() { |
| | | String usersId = SecurityUtils.getUserId(); |
| | | ArdSyUser ardSyUser = iArdSyUserService.userById(usersId); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | if(ardSyUser==null){ |
| | | return Results.succeed(); |
| | | }else { |
| | | map.put("userId",ardSyUser.getUserId()); |
| | | map.put("password",ardSyUser.getPassword()); |
| | | map.put("passwords",DigestUtils.md5Hex(ardSyUser.getPassword())); |
| | | } |
| | | return Results.succeed(map); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:getSDKCarPositionByRight')") |
| | | @PostMapping("getSDKCarPositionByRight") |
| | | @ApiOperation("获取部门权限下所有车辆位置") |
| | | public Results getSDKCarPositionByRight(){ |
| | | String usersId = SecurityUtils.getUserId(); |
| | | //根据userId查询部门Id |
| | | SysUser sysUser = sysUserService.selectUserById(usersId); |
| | | Map<String, Map<String,Map<String,Object>>> deptPositionMap = PositionContainer.getDeptPositionMap(); |
| | | if(deptPositionMap.isEmpty()){ |
| | | return Results.succeed(); |
| | | }else { |
| | | // return Results.succeed(deptPositionMap.get(sysUser.getDeptId().toString()).get(map.get("carId"))); |
| | | return Results.succeed(deptPositionMap.get(sysUser.getDeptId().toString())); |
| | | } |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:getCarNearPositionByCarId')") |
| | | @PostMapping("getCarNearPositionByCarId") |
| | | @ApiOperation("获取单个车辆位置") |
| | | public Results getCarNearPositionByCarId(@RequestBody Map<String,String> map){ |
| | | String usersId = SecurityUtils.getUserId(); |
| | | ArdSyUser ardSyUser = iArdSyUserService.userById(usersId); |
| | | String carId = map.get("carId"); |
| | | String syURL = sysConfigService.getSYURL(); |
| | | return Results.succeed(ardSyCarService.getCarGPSBycarId(usersId,carId,syURL,ardSyUser)); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:chaseCarByCarId')") |
| | | @PostMapping("chaseCarByCarId") |
| | | @ApiOperation("根据车辆主键追踪车辆") |
| | | public Results chaseCarByCarId(@RequestBody Map<String,String> map){ |
| | | String usersId = SecurityUtils.getUserId(); |
| | | String carId = map.get("carId"); |
| | | String cycle = map.get("cycle"); |
| | | return ardSyCarService.chaseCarByCarId(usersId,carId,cycle); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:getExistTraceByCarIdAndMonth')") |
| | | @PostMapping("getExistTraceByCarIdAndMonth") |
| | | @ApiOperation("根据车辆主键及月份查询轨迹存在") |
| | | public Results getExistTraceByCarIdAndMonth(@RequestBody Map<String,String> map){ |
| | | String userId = SecurityUtils.getUserId(); |
| | | String carId = map.get("carId"); |
| | | String time = map.get("time"); |
| | | return ardSyCarService.getExistTraceByCarIdAndMonth(userId,carId,time); |
| | | } |
| | | |
| | | @GetMapping("getCarPicture") |
| | | @ApiOperation("清淤获取照片") |
| | | public AjaxResult getCarNearPositionByCarId(String carId) throws UnsupportedEncodingException { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | Date currentTime = new Date(); |
| | | long tenSeconds = 1000L; |
| | | Date beforeTenSeconds = new Date(currentTime.getTime() - tenSeconds); |
| | | String startTime = sdf.format(beforeTenSeconds); |
| | | String usersId = SecurityUtils.getUserId(); |
| | | ArdSyUser ardSyUser = iArdSyUserService.userById(usersId); |
| | | String syURL = sysConfigService.getSYURL(); |
| | | String sessionId = ardSyCarService.getSessionId(syURL,ardSyUser); |
| | | System.out.println("sessionId:"+sessionId); |
| | | //获取摄像通道信息 |
| | | Map<String, Object> result = ardSyCarService.getCarPicture(carId,syURL,sessionId); |
| | | String vs = ""; |
| | | try { |
| | | //提取通道信息 |
| | | Map<String,Object> map = ((List<Map<String,Object>>)result.get("list")).get(0); |
| | | Map<String, Object> videos = (Map<String, Object>) JSON.parse((String) map.get("videos")); |
| | | System.out.println("通道:"+videos); |
| | | vs = (String) videos.get("vs"); |
| | | } catch (Exception e) { |
| | | return AjaxResult.error("该车辆没有摄像通道无照片数据!"); |
| | | } |
| | | //筛选通道信息 |
| | | String[] vsArray = vs.split(","); |
| | | List<String> channelList = new ArrayList<>(); |
| | | for (int i = 0; i < vsArray.length; i++) { |
| | | channelList.add(vsArray[i].substring(0,1)); |
| | | } |
| | | //拍照 |
| | | Map<String,Object> sendCmdMap = ardSyCarService.sendCmd(ardSyUser.getUserId(),syURL,sessionId,carId,channelList); |
| | | System.out.println("拍照:"+sendCmdMap); |
| | | //获取照片 |
| | | Map<String,Object> photoMap = ardSyCarService.getPhoto(syURL,carId,sessionId,startTime); |
| | | System.out.println("获取照片:"+photoMap); |
| | | return AjaxResult.success(photoMap); |
| | | } |
| | | |
| | | @GetMapping("getVideo") |
| | | @ApiOperation("清淤获取视频") |
| | | public AjaxResult getVideo(String carId){ |
| | | String usersId = SecurityUtils.getUserId(); |
| | | ArdSyUser ardSyUser = iArdSyUserService.userById(usersId); |
| | | String syURL = sysConfigService.getSYURL(); |
| | | Map<String,Object> video = ardSyCarService.getVideo(syURL,carId,ardSyUser); |
| | | return AjaxResult.success(video); |
| | | } |
| | | |
| | | @GetMapping("getThreeOne") |
| | | @ApiOperation("获取三一视频地址") |
| | | public AjaxResult getThreeOne() { |
| | | return AjaxResult.success("获取地址成功!",sysConfigService.getSYVideo()); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('sy:syCar:getAlarmHPfmCountDetail')") |
| | | @PostMapping("getAlarmHPfmCountDetail") |
| | | @ApiOperation("根据车辆和时间段查询报警历史记录详情") |
| | | public AjaxResult getAlarmHPfmCountDetail(@RequestBody Map<String,String> map){ |
| | | String usersId = SecurityUtils.getUserId(); |
| | | ArdSyUser ardSyUser = iArdSyUserService.userById(usersId); |
| | | String carId = map.get("carId"); |
| | | String startTime = map.get("startTime"); |
| | | String endTime = map.get("endTime"); |
| | | String syURL = sysConfigService.getSYURL(); |
| | | String sessionId = ardSyCarService.getSessionId(syURL,ardSyUser); |
| | | Map<String, Object> mapDetail = ardSyCarService.getAlarmHPfmCountDetail(sessionId,usersId,carId,startTime,endTime,syURL); |
| | | return AjaxResult.success(mapDetail); |
| | | } |
| | | |
| | | @GetMapping("/getOnlineSYCarPosition") |
| | | @ApiOperation("单兵端查看已通过审批的在线三一车辆位置") |
| | | public AjaxResult getOnlineSYCarPosition() { |
| | | String soilderId = SecurityUtils.getUserId(); |
| | | try{ |
| | | Map<String,Object> result = ardSyCarService.getOnlineSYCarPosition(soilderId); |
| | | return AjaxResult.success(result); |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | return AjaxResult.error(); |
| | | } |
| | | } |
| | | |
| | | } |