Browse Source

202410222000 #comment 筹划方案生成代码加入冲突检测条件,能够使生成的方案通过冲突检测

lhq 1 month ago
parent
commit
61dd51532b

+ 14 - 0
orbit-base-plan/base-plan-service/src/main/java/com/base/plan/mapper/StepWindowRelationMapper.java

@@ -30,4 +30,18 @@ public interface StepWindowRelationMapper extends BaseMapper<StepWindowRelation>
     default void confirmWindow(List<String> list){
         this.update(null, new UpdateWrapper<StepWindowRelation>().set("is_confirm",1).in("step_id",list));
     }
+
+    /**
+     * 初始化方案确认状态
+     * @param parentIdSubstring:parentId截取字符串
+     */
+    void initConfirmStatus(@Param("parentId") String parentIdSubstring);
+
+    /**
+     * 初始化方案确认状态
+     * @param parentIds:parentId集合
+     */
+    void initConfirmStatusByList(@Param("parentIds") List<String> parentIds);
+
+    void batchUpdateConfirmStatus(@Param("windowIds") List<String> windowIds);
 }

+ 3 - 3
orbit-base-plan/base-plan-service/src/main/java/com/base/plan/service/AlgSchemeService.java

@@ -43,10 +43,10 @@ public class AlgSchemeService {
 
     //  地面站冲突阈值15分钟,中继冲突阈值30分钟
     //    @Value("${target.mutex.station}")
-    private Integer stationMutexTime = 900;
+    private Integer stationMutexTime = 15;
     //    @Value("${target.mutex.satellite}")
     //  卫星冲突阈值默认3分钟
-    private Integer satelliteMutexTime = 180;
+    private Integer satelliteMutexTime = 3;
 
     @Resource
     private AlgSchemeStepMapper algSchemeStepMapper;
@@ -485,7 +485,7 @@ public class AlgSchemeService {
         if (CollectionUtils.isEmpty(stepWindowDTOList)) {
             return res;
         }
-        List<SatelliteRpcDTO> satellites = satelliteRpcService.queryAllSatelliteByIds(stepWindowDTOList.stream().map(StepWindowDTO::getSatelliteId).collect(Collectors.toList()));
+        List<SatelliteRpcDTO> satellites = satelliteRpcService.queryAllSatelliteByIds(stepWindowDTOList.stream().map(StepWindowDTO::getSatelliteId).distinct().collect(Collectors.toList()));
         if (CollectionUtils.isEmpty(satellites)) return new ArrayList<>();
         stepWindowDTOList.forEach(e -> e.setUniqueKey(e.getStationId()));
         Map<String, List<StepWindowDTO>> map = windowsMutexCheckBiz.getMutexList(1, stepWindowDTOList, stationMutexTime, stationMutexTime);

+ 44 - 8
orbit-base-plan/base-plan-service/src/main/java/com/base/plan/service/DemandService.java

@@ -18,6 +18,7 @@ import com.base.plan.model.dto.request.QueryDemandDTO;
 import com.base.plan.model.dto.request.QueryKjckDTO;
 import com.base.plan.model.entity.*;
 import com.base.plan.model.param.DemandParam;
+import com.base.plan.utils.PropertiesUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
@@ -544,6 +545,7 @@ public class DemandService {
             stripMapper.initSelected(parentIdSubstring);
             stepWindowControlPassRelationMapper.initSelected(parentIdSubstring);
             stepWindowDataPassRelationMapper.initSelected(parentIdSubstring);
+            stepWindowRelationMapper.initConfirmStatus(parentIdSubstring);
         }else{
             //2.1 根据传入的parent_id集合查询alg_scheme_step_window中parent_id一致的数据,然后按照卫星冲突检测规则进行时间筛选
             algSchemeStepWindowList = algSchemeStepWindowService.getAlgSchemeStepWindowByParentIds(demandParam.getParentIds());
@@ -551,6 +553,7 @@ public class DemandService {
             stripMapper.initSelectedByList(demandParam.getParentIds());
             stepWindowControlPassRelationMapper.initSelectedByList(demandParam.getParentIds());
             stepWindowDataPassRelationMapper.initSelectedByList(demandParam.getParentIds());
+            stepWindowRelationMapper.initConfirmStatusByList(demandParam.getParentIds());
         }
         //这里实现目标个数的统计
         long targetParentIdCount= algSchemeStepWindowList.stream().map(AlgSchemeStepWindow::getParentId).distinct().count();
@@ -596,6 +599,7 @@ public class DemandService {
         List<String> dataWindowIds = stepWindowDataPassRelations.stream().map(StepWindowDataPassRelation::getDataStationWindowId).collect(Collectors.toList());
         stepWindowControlPassRelationMapper.batchUpdateConfirmStatus(controlWindowIds);
         stepWindowDataPassRelationMapper.batchUpdateConfirmStatus(dataWindowIds);
+        stepWindowRelationMapper.batchUpdateConfirmStatus(windowIds);
         return AjaxResult.success("方案生成成功");
     }
 
@@ -661,14 +665,28 @@ public class DemandService {
      * @return 是否冲突
      */
     private boolean isTimeConflict(List<AlgSchemeWindowPass> algSchemeWindowPassList, AlgSchemeWindowPass controlPass) {
+        // 判断卫星编号是否重复
+        boolean isSatelliteConflict = algSchemeWindowPassList.stream().anyMatch(obj -> obj.getSatelliteId().equals(controlPass.getSatelliteId()));
+        if(!isSatelliteConflict){
+            return true;
+        }
+        //判断地面站是否重复
         boolean isStationConflict = algSchemeWindowPassList.stream().anyMatch(obj -> obj.getStationId().equals(controlPass.getStationId()));
         if(!isStationConflict){
             return true;
         }
+        for (AlgSchemeWindowPass existObj : algSchemeWindowPassList) {
+            long existPassStartTime = existObj.getStartTime().getTime() - 15 * 60 * 1000;
+            long existPassEndTime = existObj.getEndTime().getTime() + 15 * 60 * 1000;
+
+            long checkPassStartTime = controlPass.getStartTime().getTime();
+            long checkPassEndTime = controlPass.getEndTime().getTime();
 
-        return !algSchemeWindowPassList.stream()
-                .allMatch(existObj -> controlPass.getEndTime().before(existObj.getStartTime())
-                        || existObj.getEndTime().after(existObj.getEndTime()));
+            if(checkPassStartTime <= existPassEndTime && existPassStartTime <= checkPassEndTime){
+                return false;
+            }
+        }
+        return true;
     }
 
     private Map<String, AlgSchemeStepWindow> handleSelectedRecords(List<AlgSchemeStepWindow> selectedRecords) {
@@ -813,6 +831,7 @@ public class DemandService {
 
         Set<String> usedParentIds = new HashSet<>();
         List<AlgSchemeStepWindow> selectedWindowList = new ArrayList<>();
+        Map<String, List<AlgSchemeStepWindow>> recordStepWindowMap = new HashMap<>();
         //设置一个数,避免死循环
         int loopCount = 0;
 
@@ -820,21 +839,30 @@ public class DemandService {
             for (Map.Entry<String, List<AlgSchemeStepWindow>> entry : algSchemeStepWindowSortMap.entrySet()) {
                 String satelliteId = entry.getKey();
                 List<AlgSchemeStepWindow> satelliteData = entry.getValue();
-
+                //获取卫星拍摄前置时间与后置时间
+                int leadTime = PropertiesUtil.getSatelliteConstraintInfo(satelliteId);
+                // 按照startTime降序排序
                 satelliteData.sort(Comparator.comparing(AlgSchemeStepWindow::getStartTime).reversed());
 
-                List<AlgSchemeStepWindow> nonOverlappingRecords = new ArrayList<>();
+                if(recordStepWindowMap.get(satelliteId) == null){
+                    List<AlgSchemeStepWindow> nonOverlappingRecords = new ArrayList<>();
+                    recordStepWindowMap.put(satelliteId, nonOverlappingRecords);
+                }
 
+                List<AlgSchemeStepWindow> nonOverlappingRecords = recordStepWindowMap.get(satelliteId);
                 for (AlgSchemeStepWindow record : satelliteData) {
                     if (usedParentIds.contains(record.getParentId())) {
                         continue;
                     }
 
-                    if (!isOverlapping(nonOverlappingRecords, record)) {
+                    if (!isOverlapping(nonOverlappingRecords, record, leadTime, leadTime)) {
                         nonOverlappingRecords.add(record);
                         usedParentIds.add(record.getParentId());
                         selectedWindowList.add(record);
 
+                        // 更新每个星对应的条带窗口数据
+                        recordStepWindowMap.put(satelliteId, nonOverlappingRecords);
+
                         if (selectedWindowList.size() >= limit) {
                             return selectedWindowList;
                         }
@@ -853,9 +881,17 @@ public class DemandService {
         return selectedWindowList;
     }
 
-    private static boolean isOverlapping(List<AlgSchemeStepWindow> records, AlgSchemeStepWindow newRecord) {
+    private boolean isOverlapping(List<AlgSchemeStepWindow> records, AlgSchemeStepWindow newRecord, int leadTime, int postTime) {
+        if(newRecord.getParentId().equals("240906_XQCH_10017_0025") || newRecord.getParentId().equals("240906_XQCH_10017_0020")){
+            log.info("进入了断点");
+        }
         for (AlgSchemeStepWindow record : records) {
-            if (!(newRecord.getEndTime().before(record.getStartTime()))) {
+            long existStartTime = record.getStartTime().getTime() - (long) leadTime * 60 * 1000;
+            long existEndTime = record.getEndTime().getTime() + (long) postTime * 60 * 1000;
+            long checkStartTime = newRecord.getStartTime().getTime();
+            long checkEndTime = newRecord.getEndTime().getTime();
+
+            if(checkStartTime <= existEndTime && existStartTime <= checkEndTime){
                 return true;
             }
         }

+ 7 - 1
orbit-base-plan/base-plan-service/src/main/java/com/base/plan/utils/PropertiesUtil.java

@@ -19,7 +19,13 @@ public class PropertiesUtil {
             ClassPathResource resource = new ClassPathResource("SatelliteTimeConstraint.properties");
             InputStream inputStream = resource.getInputStream();
             property.load(inputStream);
-            satParamter = Integer.parseInt(property.getProperty(satCode).trim()) * 60;
+            String trim = property.getProperty(satCode).trim();
+            if(trim.contains(".")){
+                satParamter = (int) (Double.parseDouble(trim) * 60);
+            } else {
+                satParamter = Integer.parseInt(trim) * 60;
+            }
+
         } catch (FileNotFoundException e1) {
             // TODO Auto-generated catch block
             e1.printStackTrace();

+ 201 - 1
orbit-base-plan/base-plan-service/src/main/resources/SatelliteTimeConstraint.properties

@@ -70,4 +70,204 @@ DMC3F3=3
 DMC3F2=3
 DMC3F1=3
 YH3A-01xvd=3
-YH3A-02xvd=3
+YH3A-02xvd=3
+TEST-SA1=0.05
+TEST-SA2=0.05
+TEST-SA3=0.05
+TEST-SA4=0.05
+TEST-SA5=0.05
+TEST-SA6=0.05
+TEST-SA7=0.05
+TEST-SA8=0.05
+TEST-SA9=0.05
+TEST-SA10=0.05
+TEST-SB1=0.05
+TEST-SB2=0.05
+TEST-SB3=0.05
+TEST-SB4=0.05
+TEST-SB5=0.05
+TEST-SB6=0.05
+TEST-SB7=0.05
+TEST-SB8=0.05
+TEST-SB9=0.05
+TEST-SB10=0.05
+TEST-SC1=0.05
+TEST-SC2=0.05
+TEST-SC3=0.05
+TEST-SC4=0.05
+TEST-SC5=0.05
+TEST-SC6=0.05
+TEST-SC7=0.05
+TEST-SC8=0.05
+TEST-SC9=0.05
+TEST-SC10=0.05
+TEST-SD1=0.05
+TEST-SD2=0.05
+TEST-SD3=0.05
+TEST-SD4=0.05
+TEST-SD5=0.05
+TEST-SD6=0.05
+TEST-SD7=0.05
+TEST-SD8=0.05
+TEST-SD9=0.05
+TEST-SD10=0.05
+TEST-SE1=0.05
+TEST-SE2=0.05
+TEST-SE3=0.05
+TEST-SE4=0.05
+TEST-SE5=0.05
+TEST-SE6=0.05
+TEST-SE7=0.05
+TEST-SE8=0.05
+TEST-SE9=0.05
+TEST-SE10=0.05
+TEST-SF1=0.05
+TEST-SF2=0.05
+TEST-SF3=0.05
+TEST-SF4=0.05
+TEST-SF5=0.05
+TEST-SF6=0.05
+TEST-SF7=0.05
+TEST-SF8=0.05
+TEST-SF9=0.05
+TEST-SF10=0.05
+TEST-SG1=0.05
+TEST-SG2=0.05
+TEST-SG3=0.05
+TEST-SG4=0.05
+TEST-SG5=0.05
+TEST-SG6=0.05
+TEST-SG7=0.05
+TEST-SG8=0.05
+TEST-SG9=0.05
+TEST-SG10=0.05
+TEST-SH1=0.05
+TEST-SH2=0.05
+TEST-SH3=0.05
+TEST-SH4=0.05
+TEST-SH5=0.05
+TEST-SH6=0.05
+TEST-SH7=0.05
+TEST-SH8=0.05
+TEST-SH9=0.05
+TEST-SH10=0.05
+TEST-SH11=0.05
+TEST-SH12=0.05
+TEST-SH13=0.05
+TEST-SH14=0.05
+TEST-SH15=0.05
+TEST-SH16=0.05
+TEST-SH17=0.05
+TEST-SH18=0.05
+TEST-SH19=0.05
+TEST-SH20=0.05
+TEST-SH21=0.05
+TEST-SH22=0.05
+TEST-SH23=0.05
+TEST-SH24=0.05
+TEST-SH25=0.05
+TEST-SH26=0.05
+TEST-SH27=0.05
+TEST-SH28=0.05
+TEST-SH29=0.05
+TEST-SH30=0.05
+TEST-SH31=0.05
+TEST-SH32=0.05
+TEST-SH33=0.05
+TEST-SH34=0.05
+TEST-SH35=0.05
+TEST-SI1=0.05
+TEST-SI2=0.05
+TEST-SI3=0.05
+TEST-SI4=0.05
+TEST-SI5=0.05
+TEST-SI6=0.05
+TEST-SI7=0.05
+TEST-SI8=0.05
+TEST-SI9=0.05
+TEST-SI10=0.05
+TEST-SI11=0.05
+TEST-SI12=0.05
+TEST-SI13=0.05
+TEST-SI14=0.05
+TEST-SI15=0.05
+TEST-SI16=0.05
+TEST-SI17=0.05
+TEST-SI18=0.05
+TEST-SI19=0.05
+TEST-SI20=0.05
+TEST-SI21=0.05
+TEST-SI22=0.05
+TEST-SI23=0.05
+TEST-SI24=0.05
+TEST-SI25=0.05
+TEST-SI26=0.05
+TEST-SI27=0.05
+TEST-SI28=0.05
+TEST-SI29=0.05
+TEST-SI30=0.05
+TEST-SI31=0.05
+TEST-SI32=0.05
+TEST-SI33=0.05
+TEST-SI34=0.05
+TEST-SI35=0.05
+TEST-SJ1=0.05
+TEST-SJ2=0.05
+TEST-SJ3=0.05
+TEST-SJ4=0.05
+TEST-SJ5=0.05
+TEST-SJ6=0.05
+TEST-SJ7=0.05
+TEST-SJ8=0.05
+TEST-SJ9=0.05
+TEST-SJ10=0.05
+TEST-SJ11=0.05
+TEST-SJ12=0.05
+TEST-SJ13=0.05
+TEST-SJ14=0.05
+TEST-SJ15=0.05
+TEST-SJ16=0.05
+TEST-SJ17=0.05
+TEST-SJ18=0.05
+TEST-SJ19=0.05
+TEST-SJ20=0.05
+TEST-SJ21=0.05
+TEST-SJ22=0.05
+TEST-SJ23=0.05
+TEST-SJ24=0.05
+TEST-SJ25=0.05
+TEST-SJ26=0.05
+TEST-SJ27=0.05
+TEST-SJ28=0.05
+TEST-SJ29=0.05
+TEST-SJ30=0.05
+TEST-SK1=0.05
+TEST-SK2=0.05
+TEST-SK3=0.05
+TEST-SK4=0.05
+TEST-SK5=0.05
+TEST-SK6=0.05
+TEST-SK7=0.05
+TEST-SK8=0.05
+TEST-SK9=0.05
+TEST-SK10=0.05
+TEST-SK11=0.05
+TEST-SK12=0.05
+TEST-SK13=0.05
+TEST-SK14=0.05
+TEST-SK15=0.05
+TEST-SK16=0.05
+TEST-SK17=0.05
+TEST-SK18=0.05
+TEST-SK19=0.05
+TEST-SK20=0.05
+TEST-SK21=0.05
+TEST-SK22=0.05
+TEST-SK23=0.05
+TEST-SK24=0.05
+TEST-SK25=0.05
+TEST-SK26=0.05
+TEST-SK27=0.05
+TEST-SK28=0.05
+TEST-SK29=0.05
+TEST-SK30=0.05

+ 10 - 10
orbit-base-plan/base-plan-service/src/main/resources/mapper/StepWindowDataPassRelationMapper.xml

@@ -53,24 +53,24 @@
         SELECT
             step.id stepId,
             step.step_name,
-            window.satellite_id satelliteId,
-            window.start_time startTime,
-            window.end_time endTime,
-            window.id stationWindowId,
-            window.station_code stationCode,
-            window.station_id  stationId
+            aswp.satellite_id satelliteId,
+            aswp.start_time startTime,
+            aswp.end_time endTime,
+            aswp.id stationWindowId,
+            aswp.station_code stationCode,
+            aswp.station_id stationId
         FROM
             alg_scheme_step step
-                LEFT JOIN step_window_data_pass_relation relation ON step.id = relation.step_id
-                LEFT JOIN alg_scheme_window_pass window ON window.id = relation.data_station_window_id
+            LEFT JOIN step_window_data_pass_relation swdpr ON step.id = swdpr.step_id
+            LEFT JOIN alg_scheme_window_pass aswp ON aswp.id = swdpr.data_station_window_id
         <where>
             <if test="list!=null and list.size!=0">
-            step_id in
+                step.id in
                 <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                     #{item}
                 </foreach>
             </if>
-            and relation.is_confirm=#{isConfirm}
+            and swdpr.is_confirm=#{isConfirm}
         </where>
     </select>
 

+ 64 - 7
orbit-base-plan/base-plan-service/src/main/resources/mapper/StepWindowRelationMapper.xml

@@ -1,26 +1,83 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.base.plan.mapper.StepWindowRelationMapper">
+    <update id="initConfirmStatus">
+        <bind name="parentId" value="parentId + '%'" />
+        update
+            step_window_relation swr
+        set
+            swr.is_confirm = 1
+        <where>
+            swr.id in (
+                select
+                    *
+                from
+                (
+                    select
+                        swr.id
+                    from
+                        step_window_relation swr
+                    left join alg_scheme_step_window assw on
+                        swr.window_id = assw.id
+                    and assw.parent_id like
+                        #{parentId}
+                    where
+                        swr.is_confirm = 2
+                ) t1
+            )
+        </where>
+    </update>
+    <update id="initConfirmStatusByList">
+        update
+            step_window_relation swr1
+        set
+            swr1.is_confirm = 1
+        <where>
+            swr1.id in (
+                select
+                    swr.id
+                from
+                    step_window_relation swr
+                        left join alg_scheme_step_window assw on
+                        swr.window_id = assw.id
+                            and assw.parent_id in
+                            <foreach collection="parentIds" item="parentId"  open="(" separator="," close=")">
+                                #{parentId}
+                            </foreach>
+                where
+                    swr.is_confirm = 2)
+        </where>
+    </update>
+    <update id="batchUpdateConfirmStatus">
+        update step_window_relation swr
+        set swr.is_confirm = 2
+        <where>
+            swr.window_id in
+            <foreach collection="windowIds" item="windowId" open="(" separator="," close=")">
+                #{windowId}
+            </foreach>
+        </where>
+    </update>
 
     <select id="selectIsUsedStepWindowDTOList" resultType="com.base.plan.model.dto.StepWindowDTO">
         SELECT
         step.id stepId,
         step.step_name,
-        window.id windowId,
-        window.satellite_id satelliteId,
-        window.start_time startTime,
-        window.end_time endTime,
+        assw.id windowId,
+        assw.satellite_id satelliteId,
+        assw.start_time startTime,
+        assw.end_time endTime,
         strip.cir_cle circle,
         strip.roll_angle rollAngle
         FROM
         alg_scheme_step step
         LEFT JOIN step_window_relation wr ON step.id = wr.step_id
-        LEFT JOIN alg_scheme_step_window window ON wr.window_id = window.id
+        LEFT JOIN alg_scheme_step_window assw ON wr.window_id = assw.id
         <!-- 新增关联条带,获取侧摆和圈号 -->
-        LEFT JOIN strip_info strip ON strip.window_id=window.id
+        LEFT JOIN strip_info strip ON strip.window_id=assw.id
         <where>
             <if test="list!=null and list.size!=0">
-                step_id in
+                step.id in
                 <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                     #{item}
                 </foreach>