| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.entity.*; |
| | | import com.moral.api.mapper.HistorySecondUavMapper; |
| | | import com.moral.api.pojo.dto.uav.UAVQueryTimeSlotDTO; |
| | | import com.moral.api.pojo.enums.SysDictTypeEnum; |
| | | import com.moral.api.pojo.form.uav.UAVQueryTimeSlotForm; |
| | | import com.moral.api.service.HistorySecondUavService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.service.OrganizationService; |
| | | import com.moral.api.service.SpecialDeviceService; |
| | | import com.moral.api.service.SysDictTypeService; |
| | | import com.moral.api.utils.UnitConvertUtils; |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.util.DateUtils; |
| | | import com.moral.util.GeodesyUtils; |
| | | import com.moral.util.MathUtils; |
| | | import com.moral.util.UnitConvertUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.function.Predicate; |
| | |
| | | OrganizationService organizationService; |
| | | @Autowired |
| | | SpecialDeviceService specialDeviceService; |
| | | @Autowired |
| | | private SysDictTypeService sysDictTypeService; |
| | | @Autowired |
| | | RedisTemplate redisTemplate; |
| | | |
| | |
| | | public List<UAVQueryTimeSlotDTO> queryTimeSlot(UAVQueryTimeSlotForm form) { |
| | | //取参 |
| | | Integer organizationId = form.getOrganizationId(); |
| | | |
| | | List<Integer> integerList = sysDictTypeService.dateValueList(SysDictTypeEnum.SYS_SECOND_UAV_RANGE.getValue()); |
| | | Date startDate = form.getStartDate(); |
| | | Date endDate = form.getEndDate(); |
| | | QueryWrapper<HistorySecondUav> wrapper = new QueryWrapper<>(); |
| | |
| | | childrenId.add(child.getId()); |
| | | } |
| | | childrenId.add(organizationId); |
| | | childrenId.addAll(integerList); |
| | | wrapper.in("organization_id", childrenId); |
| | | //查询根据batch查,因为可能会有跨天飞行的情况。 |
| | | wrapper.between("batch", startDate, endDate); |
| | |
| | | dateMap.put("startTime", slotStartDate); |
| | | dateMap.put("endTime", slotEndDate); |
| | | dateMap.put("batch", mKey); |
| | | dateMap.put("total",mValue.size()); |
| | | timeSlots.add(dateMap); |
| | | }); |
| | | }); |
| | |
| | | for (HistorySecondUav data : datas) { |
| | | String value = data.getValue(); |
| | | Map<String, Object> valueMap = JSON.parseObject(value, Map.class); |
| | | //判断value里面有没有高度 |
| | | if (!valueMap.containsKey("flyhig")|| !valueMap.containsKey("flylat")|| !valueMap.containsKey("flylon")){ |
| | | continue; |
| | | } |
| | | //获取高度 |
| | | Double height = Double.valueOf((String) valueMap.get("flyhig")); |
| | | if (height < lowestHeight) |
| | |
| | | for (HistorySecondUav data : datas) { |
| | | String value = data.getValue(); |
| | | Map<String, Object> valueMap = JSON.parseObject(value, Map.class); |
| | | //判断value里面有没有高度 |
| | | if (!valueMap.containsKey("flyhig")|| !valueMap.containsKey("flylat")|| !valueMap.containsKey("flylon")){ |
| | | continue; |
| | | } |
| | | //获取高度 |
| | | Double height = Double.valueOf((String) valueMap.get("flyhig")); |
| | | //加上最低点绝对值 |
| | |
| | | } |
| | | //筛选无人机数据,保持每个点之间的距离在2米以上 |
| | | datas = filterDatas(datas); |
| | | if (datas.size()<2){ |
| | | return null; |
| | | } |
| | | //转换单位 |
| | | unitConvert(datas); |
| | | return datas; |
| | |
| | | datas.remove(0); |
| | | for (HistorySecondUav data : datas) { |
| | | Double distance = getDistance(tempData, data); |
| | | if (distance==null){ |
| | | continue; |
| | | } |
| | | if (distance > filterDistance) { |
| | | result.add(data); |
| | | tempData = data; |
| | |
| | | String value2 = uav2.getValue(); |
| | | Map<String, Object> value1Map = JSON.parseObject(value1, Map.class); |
| | | Map<String, Object> value2Map = JSON.parseObject(value2, Map.class); |
| | | //判断这两个数据里面有没有经纬度 |
| | | if (!value1Map.containsKey("flylon")||!value1Map.containsKey("flylat")||!value1Map.containsKey("flyhig")|| |
| | | !value2Map.containsKey("flylon")||!value2Map.containsKey("flylat")||!value2Map.containsKey("flyhig")){ |
| | | return null; |
| | | } |
| | | //获取数据1的经纬度和高度 |
| | | Double longtitude1 = Double.valueOf((String) value1Map.get("flylon")); |
| | | Double latitude1 = Double.valueOf((String) value1Map.get("flylat")); |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean UAVTest(BigDecimal lat, BigDecimal lon, String batch) { |
| | | List<HistorySecondUav> list = new ArrayList<>(); |
| | | |
| | | QueryWrapper<HistorySecondUav> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("batch", batch); |
| | | wrapper.select("value,mac,time,organization_id"); |
| | | wrapper.orderByAsc("time"); |
| | | List<HistorySecondUav> datas = historySecondUavMapper.selectList(wrapper); |
| | | Date time = new Date(); |
| | | //String bat = "2023-08-08 14:42:20"; |
| | | for(HistorySecondUav g : datas){ |
| | | HistorySecondUav historySecondUav = new HistorySecondUav(); |
| | | historySecondUav.setTime(DateUtils.addDays(g.getTime(),0)); |
| | | historySecondUav.setMac(g.getMac()); |
| | | historySecondUav.setBatch(time); |
| | | historySecondUav.setOrganizationId(g.getOrganizationId()); |
| | | Map<String, Object> data = JSON.parseObject(g.getValue(), Map.class); |
| | | Map<String, Object> dataResult = new HashMap<>(); |
| | | dataResult = data; |
| | | dataResult.put("flylat",Objects.isNull(data.get("flylat"))||data.get("flylat").toString().equals("0")?0d:Double.parseDouble(String.format("%.10f",Double.parseDouble(data.get("flylat").toString())+lat.doubleValue()))); |
| | | dataResult.put("flylon",Objects.isNull(data.get("flylon"))||data.get("flylon").toString().equals("0")?0d:Double.parseDouble(String.format("%.10f",Double.parseDouble(data.get("flylon").toString())+lon.doubleValue()))); |
| | | /*if(Objects.nonNull(data.get("a21026"))&& !data.get("a21026").toString().equals("0")){ |
| | | Double a21026D = Double.parseDouble(data.get("a21026").toString()); |
| | | if( a21026D>15){ |
| | | a21026D = a21026D -10; |
| | | } |
| | | dataResult.put("a21026",Double.parseDouble(String.format("%.4f",a21026D))); |
| | | } |
| | | if(Objects.nonNull(data.get("a21004"))&& !data.get("a21004").toString().equals("0")){ |
| | | Double a21024D = Double.parseDouble(data.get("a21004").toString()); |
| | | if( a21024D>100){ |
| | | a21024D = a21024D -100; |
| | | } |
| | | dataResult.put("a21004",Double.parseDouble(String.format("%.4f",a21024D))); |
| | | }*/ |
| | | historySecondUav.setValue(JSONObject.toJSONString(dataResult)); |
| | | list.add(historySecondUav); |
| | | } |
| | | this.saveBatch(list); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public boolean UAVUpdateTest(String batch) { |
| | | List<HistorySecondUav> list = new ArrayList<>(); |
| | | QueryWrapper<HistorySecondUav> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("batch", batch); |
| | | wrapper.select("id,value,mac,time,organization_id"); |
| | | wrapper.orderByAsc("time"); |
| | | List<HistorySecondUav> datas = historySecondUavMapper.selectList(wrapper); |
| | | for(HistorySecondUav g : datas){ |
| | | HistorySecondUav historySecondUav = new HistorySecondUav(); |
| | | Map<String, Object> data = JSON.parseObject(g.getValue(), Map.class); |
| | | Map<String, Object> dataResult = new HashMap<>(); |
| | | dataResult = data; |
| | | int a21026D =(int) Math.round(Double.parseDouble(data.get("a21026").toString())); |
| | | if(a21026D>10){ |
| | | Integer digit = a21026D % 10; |
| | | dataResult.put("a21026",Double.parseDouble(digit.toString())); |
| | | }else { |
| | | continue; |
| | | } |
| | | historySecondUav.setId(g.getId()); |
| | | historySecondUav.setValue(JSONObject.toJSONString(dataResult)); |
| | | list.add(historySecondUav); |
| | | } |
| | | this.updateBatchById(list); |
| | | return true; |
| | | } |
| | | |
| | | } |