jinpengyong
2024-06-19 32cc13189371ee1e367897a64fbc22f90b53add8
screen-api/src/main/java/com/moral/api/service/impl/HistorySecondUavServiceImpl.java
@@ -27,6 +27,7 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
 * <p>
@@ -59,28 +60,27 @@
    public List<Date> queryDate(Integer organizationId) {
        //构造查询条件
        QueryWrapper<HistorySecondUav> queryWrapper = new QueryWrapper<>();
        //List<Integer> childrenId = new ArrayList<>();
        List<Integer> children = organizationService.orgIdList(organizationId);
        //获取子组织id
        List<Organization> children = organizationService.getChildrenOrganizationsById(organizationId);
        /*List<Organization> children = organizationService.getChildrenOrganizationsById(organizationId);
        List<Integer> childrenId = new ArrayList<>();
        for (Organization child : children) {
            childrenId.add(child.getId());
        }
        childrenId.add(organizationId);
        queryWrapper.in("organization_id", childrenId);
        childrenId.add(organizationId);*/
        queryWrapper.in("organization_id", children);
        //设置查询时间范围为180天
        Date endDate = new Date();
        Date startDate = DateUtils.addDays(endDate, -180);
        queryWrapper.between("batch", startDate, endDate);
        //设置查询字段
        queryWrapper.select("DISTINCT batch");
        queryWrapper.select("DISTINCT DATE_FORMAT(batch,'%Y-%m-%d') batch ");
        queryWrapper.orderByDesc("batch");
        //查询结果
        List<HistorySecondUav> historySecondUavs = historySecondUavMapper.selectList(queryWrapper);
        //结果转为Date集合
        List<Date> result = new ArrayList<>();
        for (HistorySecondUav historySecondUav : historySecondUavs) {
            result.add(historySecondUav.getBatch());
        }
        List<Date> result = historySecondUavs.stream().map(HistorySecondUav::getBatch).collect(Collectors.toList());
        return result;
    }
@@ -94,12 +94,9 @@
        Date endDate = form.getEndDate();
        QueryWrapper<HistorySecondUav> wrapper = new QueryWrapper<>();
        //获取子组织id
        List<Organization> children = organizationService.getChildrenOrganizationsById(organizationId);
        List<Integer> children = organizationService.orgIdList(organizationId);
        List<Integer> childrenId = new ArrayList<>();
        for (Organization child : children) {
            childrenId.add(child.getId());
        }
        childrenId.add(organizationId);
        childrenId.addAll(children);
        childrenId.addAll(integerList);
        wrapper.in("organization_id", childrenId);
        //查询根据batch查,因为可能会有跨天飞行的情况。
@@ -366,7 +363,7 @@
        wrapper.select("value,mac,time,organization_id");
        wrapper.orderByAsc("time");
        List<HistorySecondUav> datas = historySecondUavMapper.selectList(wrapper);
        Date time =DateUtils.addDays(datas.get(2).getTime(),0);
        Date time = new Date();
        //String bat = "2023-08-08 14:42:20";
        for(HistorySecondUav g : datas){
            HistorySecondUav historySecondUav = new HistorySecondUav();
@@ -399,4 +396,49 @@
        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;
            Double a34004 = Double.parseDouble(data.get("a34004").toString());
            Double a34002 = Double.parseDouble(data.get("a34002").toString());
            dataResult.put("a34002",Double.parseDouble(String.format("%.4f",a34004)));
            dataResult.put("a34004",Double.parseDouble(String.format("%.4f",a34002)));
           /* if(a21026D>11){
               // Integer digit = a21026D % 10;
                Integer digit = new Random().nextInt(5)+8;
                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;
    }
    public static void main(String[] args) {
        for(int i = 0;i<10;i++){
            //选定随机数的生成区间为7~15
            //15-7=8
            //8+1=9
            int number = new Random().nextInt(5)+8;
            //随机数结果加上最初的首个数字
            System.out.println(number);
        }
    }
}