package com.dky.calculate; import com.dky.utils.entity.SysDeviceHeatScene; import com.dky.utils.result.MatchedDevice; import java.util.ArrayList; import java.util.List; public class MaterialKilnScheme { public static List calSchemeByTechType(Double workArea, List sysDeviceHeatSceneList) { // 对技术类型下的设备list按照单台设备工作容积进行排序 sysDeviceHeatSceneList.sort((o1, o2) -> Double.compare(o2.getDevWorkArea(), o1.getDevWorkArea())); Double remainArea = workArea; // 遍历设备,根据工作容积进行匹配设备数量 List matchedDeviceList = new ArrayList<>(); for (SysDeviceHeatScene deviceHeatScene : sysDeviceHeatSceneList) { double v = remainArea / deviceHeatScene.getDevWorkArea(); int count = (int) (v); if (v < 1) { count = count + 1; } remainArea = remainArea - count * deviceHeatScene.getDevWorkArea(); matchedDeviceList.add(new MatchedDevice(count, deviceHeatScene)); if (remainArea <= 0) { // 当总供暖面积已经满足需求时,跳出循环,不再选择其他设备 break; } } return matchedDeviceList; } }