| | |
| | | package org.springblade.modules.location.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.json.JSONArray; |
| | | import org.json.JSONObject; |
| | | import org.springblade.common.utils.InvestigateUtil; |
| | | import org.springblade.modules.equipage.entity.Gun; |
| | | import org.springblade.modules.equipage.service.GunService; |
| | | import org.springblade.modules.location.entity.LiveLocation; |
| | | import org.springblade.modules.location.mapper.LiveLocationMapper; |
| | | import org.springblade.modules.location.service.LiveLocationService; |
| | | import org.springblade.modules.location.vo.GunLiveLocationVO; |
| | | import org.springblade.modules.location.vo.LiveLocationVo; |
| | | import org.springblade.modules.location.vo.LocusVo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 实时位置服务实现类 |
| | |
| | | */ |
| | | @Service |
| | | public class LiveLocationServiceImpl extends ServiceImpl<LiveLocationMapper, LiveLocation> implements LiveLocationService { |
| | | |
| | | @Autowired |
| | | private GunService gunService; |
| | | |
| | | /** |
| | | * 实时位置分页信息 |
| | |
| | | } |
| | | //枪支 |
| | | if (liveLocationVo.getType()==3){ |
| | | return baseMapper.getGunLocusInfoList(liveLocationVo); |
| | | //获取枪支数据 |
| | | List<Gun> gunList = gunService.list(); |
| | | //创建集合 |
| | | List<LiveLocationVo> list = new ArrayList<>(); |
| | | if (gunList.size()>0){ |
| | | //遍历 |
| | | gunList.forEach(gun -> { |
| | | //远程调用 |
| | | String body = InvestigateUtil.httpGetGunPosition(gun.getCardNo(),null,null,null,null,null); |
| | | // System.out.println("body = " + body); |
| | | if (null != body && !body.equals("")) { |
| | | JSONObject jsonObject = new JSONObject(body); |
| | | Object data = jsonObject.get("data"); |
| | | JSONObject jsonData = new JSONObject(data.toString()); |
| | | JSONArray res = jsonData.getJSONArray("res"); |
| | | //转换string |
| | | String resToString = res.toString(); |
| | | if (res.length() == 0) { |
| | | } else { |
| | | LiveLocationVo locationVo = new LiveLocationVo(); |
| | | List<GunLiveLocationVO> gunLiveLocationVOS = JSON.parseArray(resToString, GunLiveLocationVO.class); |
| | | //按时间排序(降序) |
| | | List<GunLiveLocationVO> gunLiveLocationVOList = |
| | | gunLiveLocationVOS.stream().sorted(Comparator.comparing(GunLiveLocationVO::getDwsj).reversed()).collect(Collectors.toList()); |
| | | GunLiveLocationVO gunLiveLocationVO = gunLiveLocationVOList.get(0); |
| | | //取出第一个 |
| | | locationVo.setRecordTime(gunLiveLocationVO.getDwsj()); |
| | | locationVo.setLinkman(gunLiveLocationVO.getHwy()); |
| | | locationVo.setCardNo(gunLiveLocationVO.getHwysfzh()); |
| | | locationVo.setNumber(gunLiveLocationVO.getQzbh()); |
| | | locationVo.setQh(gunLiveLocationVO.getQh()); |
| | | locationVo.setLongitude(gunLiveLocationVO.getDwjd().toString()); |
| | | locationVo.setLatitude(gunLiveLocationVO.getDwwd().toString()); |
| | | locationVo.setCompany(gunLiveLocationVO.getSzdw()); |
| | | //存入集合 |
| | | list.add(locationVo); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | return list; |
| | | } |
| | | return baseMapper.selectSecurityAndCarAndGunLiveLocationPage(liveLocationVo); |
| | | } |