jinpengyong
2024-06-19 32cc13189371ee1e367897a64fbc22f90b53add8
fix:尘负荷排序接口提交
3 files modified
93 ■■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/CruiserController.java 11 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/DustldService.java 4 ●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/DustldServiceImpl.java 78 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/CruiserController.java
@@ -23,6 +23,7 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
@@ -290,6 +291,16 @@
    }
    @GetMapping("sort")
    @ApiOperation("路段排序")
    public ResultMessage sectionRanking(@RequestParam @ApiParam(value = "mac",name = "mac号") String mac,
                                        @RequestParam @ApiParam(value = "startTime",name = "开始时间") String startTime,
                                        @RequestParam @ApiParam(value = "endTime",name = "结束时间") String endTime){
        List<DustForm> sort = dustldService.sort(mac, startTime, endTime);
        return ResultMessage.ok(sort);
    }
    public static void downloadWord(String fileName, Map<String, Object> params, HttpServletResponse response, String newFileName) {
screen-api/src/main/java/com/moral/api/service/DustldService.java
@@ -7,6 +7,7 @@
import java.util.Map;
import com.moral.api.entity.Dustld;
import com.moral.api.pojo.dust.DustForm;
public interface DustldService {
@@ -26,6 +27,7 @@
    List<Dustld>  selectAll(Map<String, Object> params);
    //路段排序
    List<DustForm> sort(String mac,String startTime,String endTime);
}
screen-api/src/main/java/com/moral/api/service/impl/DustldServiceImpl.java
@@ -459,6 +459,84 @@
        return dustlds;
    }
    /**
     * 路段排序
     * @param mac
     * @param startTime
     * @param endTime
     * @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;
    }
    //获取图片地址
    private String getList(String path, List<MultipartFile> files1) {