swb
2024-07-03 5ef407e617576a83c9b8c25ce510f263ed031d03
screen-api/src/main/java/com/moral/api/service/impl/DustldServiceImpl.java
@@ -1,7 +1,9 @@
package com.moral.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.moral.api.config.Interceptor.UserHelper;
import com.moral.api.entity.SecondCruiserSort;
import com.moral.api.entity.SysDictData;
import com.moral.api.exception.BusinessException;
import com.moral.api.mapper.*;
@@ -51,6 +53,9 @@
    @Autowired
    private DustldMapper dustldMapper;
    @Autowired
    private SecondCruiserSortMapper secondCruiserSortMapper;
    /**
     * 保存日报信息
@@ -467,74 +472,14 @@
     * @return
     */
    @Override
    public List<DustForm> sort(String mac, String startTime, String endTime) {
        SysDictData list = sysDictTypeService.listOne(SysDictTypeEnum.SYS_SECOND_CRUISER.getValue(),"dustld");
        Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo();
        Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization");
        Integer orgId = (Integer) orgInfo.get("id");
        List<Integer> orgList = organizationMapper.orgIdSpecialDevList(orgId,mac);
        if(CollectionUtils.isEmpty(orgList)){
            throw new BusinessException("该设备没有路段组织信息!");
        }
        HashMap<String, Object> params = new HashMap<>();
        params.put("mac",mac);
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        List<Map<String, Object>> dusts = historySecondCruiserMapper.getDusts(params);
        Map<String, List<DustldDTO>> collect = manageCoordinateMapper.CompareTo(orgList.get(0)).stream().collect(Collectors.groupingBy(o -> o.getName()));
        if (ObjectUtils.isEmpty(dusts) || ObjectUtils.isEmpty(collect)){
            return null;
        }
        Set<String> strings = collect.keySet();
        ArrayList<DustForm> list1 = new ArrayList<>();
        for (String string : strings) {
            DustForm dustForm = new DustForm();
            ArrayList<Double> doubleArrayList = new ArrayList<>();
            List<DustldDTO> dustldDTOS = collect.get(string);
            for (DustldDTO dustldDTO : dustldDTOS) {
                String flyLat = dustldDTO.getFlyLat();
                String flyLon = dustldDTO.getFlyLon();
                if (flyLon==null && flyLat==null){
                    continue;
                }
                double latDouble1 = Double.parseDouble(flyLat);
                double lonDouble1 = Double.parseDouble(flyLon);
                for (Map<String, Object> dust : dusts) {
                    String flyLat1 = Objects.nonNull(dust.get("flyLat")) ? dust.get("flyLat").toString() :"0";
                    String flyLon1 = Objects.nonNull(dust.get("flyLon")) ? dust.get("flyLon").toString() :"0";
                    double latDouble = Double.parseDouble(flyLat1);
                    double lonDouble = Double.parseDouble(flyLon1);
//                    String flyLon1 = dust.get("flyLon").toString();
                    if (latDouble1==latDouble && lonDouble1==lonDouble){
                        Double dustld = Objects.nonNull(dust.get("dustld"))?Double.parseDouble(dust.get("dustld").toString()):0d;
                        if(list.getDataValue().contains(",")){
                            List<String> resultStr = Arrays.asList(list.getDataValue().split(","));
                            if(resultStr.size() % 2 ==0){
                                dustld = numAvg(resultStr,BigDecimal.valueOf(dustld)).doubleValue();
                            }
                        }else {
                            BigDecimal dataValue = Objects.nonNull(list.getDataValue())?BigDecimal.valueOf(Double.parseDouble(list.getDataValue())):BigDecimal.ZERO;
                            dustld = BigDecimal.valueOf(dustld).add(dataValue).doubleValue();
                        }
                        doubleArrayList.add(dustld);
                        break;
                    }
                }
            }
            if (ObjectUtils.isEmpty(doubleArrayList)){
                continue;
            }
            Double ListAva = doubleArrayList.stream() .collect(Collectors.averagingDouble(Double::doubleValue));
            double rsAvg = new BigDecimal(ListAva/1000).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
            dustForm.setRoad(string);
            dustForm.setValue(rsAvg);
            list1.add(dustForm);
        }
        //排序
        list1.sort(Comparator.comparing(DustForm::getValue).reversed());
        return list1;
    public List<SecondCruiserSort> sort(String mac, String startTime, String endTime) {
        String s = DateUtils.stringToDateString(startTime, "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd");
        LambdaQueryWrapper<SecondCruiserSort> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SecondCruiserSort::getMac,mac);
        wrapper.eq(SecondCruiserSort::getTime,s);
        wrapper.orderByDesc(SecondCruiserSort::getValue);
        List<SecondCruiserSort> secondCruiserSorts = secondCruiserSortMapper.selectList(wrapper);
        return secondCruiserSorts;
    }