Selaa lähdekoodia

202410171957 #comment 筹划方案生成代码修改

lhq 8 kuukautta sitten
vanhempi
sitoutus
31d7d86354

+ 2 - 1
orbit-base-plan/base-plan-service/src/main/java/com/base/plan/constant/PassTypeEnum.java

@@ -18,7 +18,8 @@ public enum PassTypeEnum {
     private  String message;
 
     PassTypeEnum(int code, String message) {
-
+        this.code = code;
+        this.message = message;
     }
 
     public int getCode() {

+ 6 - 0
orbit-base-plan/base-plan-service/src/main/java/com/base/plan/mapper/StepWindowControlPassRelationMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.base.plan.model.entity.StepWindowControlPassRelation;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -23,4 +24,9 @@ public interface StepWindowControlPassRelationMapper extends BaseMapper<StepWind
         this.update(null, new UpdateWrapper<StepWindowControlPassRelation>().set("is_confirm",1).in("step_id",list));
     }
 
+    void initSelected(@Param("parentId") String parentIdSubstring);
+
+    void initSelectedByList(@Param("parentIds") List<String> parentIds);
+
+    void batchUpdateConfirmStatus(@Param("controlWindowIds") List<String> controlWindowIds);
 }

+ 6 - 0
orbit-base-plan/base-plan-service/src/main/java/com/base/plan/mapper/StepWindowDataPassRelationMapper.java

@@ -38,4 +38,10 @@ public interface StepWindowDataPassRelationMapper extends BaseMapper<StepWindowD
         //  .get().getId(),optionalDataAlgSchemeWindowPass.get().getSchemeStepWindowId()
         this.update(null, new UpdateWrapper<StepWindowDataPassRelation>().set("is_confirm", 1).eq("data_station_window_id", algSchemeWindowPass.getId()).eq("window_id", algSchemeWindowPass.getSchemeStepWindowId()));
     }
+
+    void initSelected(@Param("parentId") String parentIdSubstring);
+
+    void initSelectedByList(@Param("parentIds") List<String> parentIds);
+
+    void batchUpdateConfirmStatus(@Param("dataWindowIds") List<String> dataWindowIds);
 }

+ 6 - 0
orbit-base-plan/base-plan-service/src/main/java/com/base/plan/mapper/StripMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.base.plan.model.dto.QuerySelectedStripUpdateDTO;
 import com.base.plan.model.dto.request.StripDTOListReqDTO;
+import com.base.plan.model.entity.AlgSchemeStepWindow;
 import com.base.plan.model.entity.StripInfo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -25,4 +26,9 @@ public interface StripMapper extends BaseMapper<StripInfo> {
     void updateSelectedStatus(@Param("list") List<QuerySelectedStripUpdateDTO> list);
 
 
+    void initSelected(@Param("parentId") String parentIdSubstring);
+
+    void initSelectedByList(@Param("parentIds") List<String> parentIds);
+
+    void batchUpdateSelectedStatus(@Param("windowIds") List<String> windowIds);
 }

+ 118 - 9
orbit-base-plan/base-plan-service/src/main/java/com/base/plan/service/DemandService.java

@@ -26,7 +26,6 @@ import org.springframework.util.CollectionUtils;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
-import java.time.Duration;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -66,6 +65,12 @@ public class DemandService {
     private PayloadRpcService payloadRpcService;
     @Resource
     private AlgSchemeStepWindowService algSchemeStepWindowService;
+    @Resource
+    StripMapper stripMapper;
+    @Resource
+    StepWindowControlPassRelationMapper stepWindowControlPassRelationMapper;
+    @Resource
+    StepWindowDataPassRelationMapper stepWindowDataPassRelationMapper;
 
     private static final String DEMAND_TYPE_FULL = "1";
     
@@ -535,9 +540,17 @@ public class DemandService {
             String parentIdSub = demandParam.getParentIds().get(0);
             String parentIdSubstring = parentIdSub.substring(0, parentIdSub.lastIndexOf("_"));
             algSchemeStepWindowList = algSchemeStepWindowService.getAlgSchemeStepWindowByParentIdSubstring(parentIdSubstring);
+            //1.2 重置strip_info表、step_window_control_pass_relation表、step_window_data_pass_relation表数据
+            stripMapper.initSelected(parentIdSubstring);
+            stepWindowControlPassRelationMapper.initSelected(parentIdSubstring);
+            stepWindowDataPassRelationMapper.initSelected(parentIdSubstring);
         }else{
             //2.1 根据传入的parent_id集合查询alg_scheme_step_window中parent_id一致的数据,然后按照卫星冲突检测规则进行时间筛选
             algSchemeStepWindowList = algSchemeStepWindowService.getAlgSchemeStepWindowByParentIds(demandParam.getParentIds());
+            //2.2 重置strip_info表、step_window_control_pass_relation表、step_window_data_pass_relation表数据
+            stripMapper.initSelectedByList(demandParam.getParentIds());
+            stepWindowControlPassRelationMapper.initSelectedByList(demandParam.getParentIds());
+            stepWindowDataPassRelationMapper.initSelectedByList(demandParam.getParentIds());
         }
         //这里实现目标个数的统计
         long targetParentIdCount= algSchemeStepWindowList.stream().map(AlgSchemeStepWindow::getParentId).distinct().count();
@@ -548,18 +561,114 @@ public class DemandService {
         List<String> windowIds = selectedRecords.stream().map(AlgSchemeStepWindow::getId).collect(Collectors.toList());
         // 根据windowIds查询alg_scheme_window_pass表,获取对应的数传站与测控站资源
         List<AlgSchemeWindowPass> algSchemeWindowPassesByWindowIds = algSchemeWindowPassMapper.selectSchemeWindowPassByWindowIds(windowIds);
-        //筛选测控站数据
-        List<AlgSchemeWindowPass> controlWindowPass = algSchemeWindowPassesByWindowIds.stream().filter(e -> e.getPassType()==PassTypeEnum.DEMAND_CK.getCode()).collect(Collectors.toList());
-        //筛选数传站数据
-        List<AlgSchemeWindowPass> dataTransferWindowPass = algSchemeWindowPassesByWindowIds.stream().filter(e -> e.getPassType()==PassTypeEnum.DEMAND_SC.getCode()).collect(Collectors.toList());
         //处理选择的条带窗口数据
         Map<String,AlgSchemeStepWindow> stepWindowsMap = handleSelectedRecords(selectedRecords);
+        //这里处理获得对应条带窗口的测控数传资源
+        List<AlgSchemeWindowPass> ControlAndDataTransferPassList = getStripWindowControlAndDataTransferResource(stepWindowsMap, algSchemeWindowPassesByWindowIds);
+        //筛选测控站数据
+        List<AlgSchemeWindowPass> controlWindowPass = ControlAndDataTransferPassList.stream().filter(e -> e.getPassType()==PassTypeEnum.DEMAND_CK.getCode()).collect(Collectors.toList());
+        //筛选数传站数据
+        List<AlgSchemeWindowPass> dataTransferWindowPass = ControlAndDataTransferPassList.stream().filter(e -> e.getPassType()==PassTypeEnum.DEMAND_SC.getCode()).collect(Collectors.toList());
+
         //处理测控站数据
-        List<StepWindowControlPassRelation> stepWindowControlPassRelations = handleControlWindowPassData(stepWindowsMap, controlWindowPass);
+        List<StepWindowControlPassRelation> stepWindowControlPassRelations = controlWindowPass.stream().map(e -> {
+            AlgSchemeStepWindow algSchemeStepWindow = stepWindowsMap.get(e.getSchemeStepWindowId());
+            StepWindowControlPassRelation stepControlDataPassRelation = new StepWindowControlPassRelation();
+            stepControlDataPassRelation.setWindowId(e.getSchemeStepWindowId());
+            stepControlDataPassRelation.setStepId(algSchemeStepWindow.getSchemeStepId());
+            stepControlDataPassRelation.setControlStationWindowId(e.getId());
+            stepControlDataPassRelation.setIsConfirm(IS_CONFIRMED);
+            return stepControlDataPassRelation;
+        }).collect(Collectors.toList());
         //处理数传站数据
-        List<StepWindowDataPassRelation> stepWindowDataPassRelations = handleDataTransferWindowPassData(stepWindowsMap, dataTransferWindowPass);
-        //进行数据修改
-        return AjaxResult.success(windowIds);
+        List<StepWindowDataPassRelation> stepWindowDataPassRelations = dataTransferWindowPass.stream().map(e -> {
+            AlgSchemeStepWindow algSchemeStepWindow = stepWindowsMap.get(e.getSchemeStepWindowId());
+            StepWindowDataPassRelation stepWindowDataPassRelation = new StepWindowDataPassRelation();
+            stepWindowDataPassRelation.setStepId(algSchemeStepWindow.getSchemeStepId());
+            stepWindowDataPassRelation.setDataStationWindowId(e.getId());
+            stepWindowDataPassRelation.setWindowId(e.getSchemeStepWindowId());
+            stepWindowDataPassRelation.setIsConfirm(IS_CONFIRMED);
+            return stepWindowDataPassRelation;
+        }).collect(Collectors.toList());
+        //更新strip_info表、step_window_control_pass_relation表、step_window_data_pass_relation表数据
+        stripMapper.batchUpdateSelectedStatus(windowIds);
+        List<String> controlWindowIds = stepWindowControlPassRelations.stream().map(StepWindowControlPassRelation::getControlStationWindowId).collect(Collectors.toList());
+        List<String> dataWindowIds = stepWindowDataPassRelations.stream().map(StepWindowDataPassRelation::getDataStationWindowId).collect(Collectors.toList());
+        stepWindowControlPassRelationMapper.batchUpdateConfirmStatus(controlWindowIds);
+        stepWindowDataPassRelationMapper.batchUpdateConfirmStatus(dataWindowIds);
+        return AjaxResult.success("方案生成成功");
+    }
+
+    /**
+     * 处理地面站资源数据
+     * @param stepWindowsMap:条带窗口集合
+     * @param algSchemeWindowPassesByWindowIds:条带窗口对应地面站资源数据集合
+     * @return 处理完成的地面站资源数据
+     */
+    private List<AlgSchemeWindowPass> getStripWindowControlAndDataTransferResource(Map<String, AlgSchemeStepWindow> stepWindowsMap, List<AlgSchemeWindowPass> algSchemeWindowPassesByWindowIds) {
+        List<AlgSchemeWindowPass> algSchemeWindowPassList = new ArrayList<>();
+        //筛选测控站数据
+        List<AlgSchemeWindowPass> controlWindowPass = algSchemeWindowPassesByWindowIds.stream().filter(e -> e.getPassType() == PassTypeEnum.DEMAND_CK.getCode()).collect(Collectors.toList());
+        //筛选数传站数据
+        List<AlgSchemeWindowPass> dataTransferWindowPass = algSchemeWindowPassesByWindowIds.stream().filter(e -> e.getPassType() == PassTypeEnum.DEMAND_SC.getCode()).collect(Collectors.toList());
+
+        //将测控站集合转换为Map<String,AlgSchemeWindowPass>的结构
+        Map<String, List<AlgSchemeWindowPass>> controlWindowPassMap = controlWindowPass.stream()
+                .collect(Collectors.groupingBy(AlgSchemeWindowPass::getSchemeStepWindowId));
+        //将数传站集合转换为Map<String,AlgSchemeWindowPass>的结构
+        Map<String, List<AlgSchemeWindowPass>> dataTransferWindowPassMap = dataTransferWindowPass.stream()
+                .collect(Collectors.groupingBy(AlgSchemeWindowPass::getSchemeStepWindowId));
+
+        for (Map.Entry<String, AlgSchemeStepWindow> algSchemeStepWindowEntry : stepWindowsMap.entrySet()) {
+            String windowId = algSchemeStepWindowEntry.getKey();
+            AlgSchemeStepWindow algSchemeStepWindow = algSchemeStepWindowEntry.getValue();
+
+            List<AlgSchemeWindowPass> algSchemeWindowDataTransferPasses = dataTransferWindowPassMap.get(windowId);
+            List<AlgSchemeWindowPass> algSchemeWindowControlPasses = controlWindowPassMap.get(windowId);
+
+            //数传站资源按进站时间顺序排序
+            algSchemeWindowDataTransferPasses.sort(Comparator.comparing(AlgSchemeWindowPass::getStartTime));
+            //测控站资源按出站时间顺序排序
+            algSchemeWindowControlPasses.sort(Comparator.comparing(AlgSchemeWindowPass::getEndTime));
+
+            //找到对应的测控站
+            for (AlgSchemeWindowPass controlPass : algSchemeWindowControlPasses) {
+                // 判断选择的测控站时间与已选择了测控站的时间是否有冲突
+                if (isTimeConflict(algSchemeWindowPassList, controlPass)) {
+                    //不冲突则将其加入到已选择的地面站资源列表中
+                    algSchemeWindowPassList.add(controlPass);
+                    break;
+                }
+
+
+            }
+            //找到对应的数传站
+            for (AlgSchemeWindowPass dataTransferPass : algSchemeWindowDataTransferPasses) {
+                if (isTimeConflict(algSchemeWindowPassList, dataTransferPass)) {
+                    //不冲突则将其加入到已选择的地面站资源列表中
+                    algSchemeWindowPassList.add(dataTransferPass);
+                    break;
+                }
+            }
+        }
+        return algSchemeWindowPassList;
+    }
+
+    /**
+     * 判断地面站资源是否时间冲突
+     * @param algSchemeWindowPassList:已选择的地面站资源列表
+     * @param controlPass:需要选择的地面站资源
+     * @return 是否冲突
+     */
+    private boolean isTimeConflict(List<AlgSchemeWindowPass> algSchemeWindowPassList, AlgSchemeWindowPass controlPass) {
+        boolean isStationConflict = algSchemeWindowPassList.stream().anyMatch(obj -> obj.getStationId().equals(controlPass.getStationId()));
+        if(!isStationConflict){
+            return true;
+        }
+
+        return !algSchemeWindowPassList.stream()
+                .allMatch(existObj -> controlPass.getEndTime().before(existObj.getStartTime())
+                        || existObj.getEndTime().after(existObj.getEndTime()));
     }
 
     private Map<String, AlgSchemeStepWindow> handleSelectedRecords(List<AlgSchemeStepWindow> selectedRecords) {

+ 51 - 0
orbit-base-plan/base-plan-service/src/main/resources/mapper/StepWindowControlPassRelationMapper.xml

@@ -0,0 +1,51 @@
+<?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.StepWindowControlPassRelationMapper">
+
+    <update id="initSelected">
+        <bind name="parentId" value="parentId + '%'" />
+        update
+            step_window_control_pass_relation swcpr
+        set
+            swcpr.is_confirm = '1'
+        <where>
+            swcpr.window_id in (
+            select
+            assw.id from alg_scheme_step_window  assw
+            where assw.parent_id like #{parentId}
+            )
+            and
+            swcpr.is_confirm = '2'
+        </where>
+    </update>
+    <update id="initSelectedByList">
+        update
+            step_window_control_pass_relation swcpr
+        set
+            swcpr.is_confirm = '1'
+        <where>
+            swcpr.window_id in (
+            select
+                assw.id from alg_scheme_step_window  assw
+            where assw.parent_id in
+                <foreach collection="parentIds" item="parentId" open="(" separator="," close=")">
+                    #{parentId}
+                </foreach>
+            )
+            and
+            swcpr.is_confirm = '2'
+        </where>
+    </update>
+    <update id="batchUpdateConfirmStatus">
+        update
+            step_window_control_pass_relation swcpr
+        set
+            swcpr.is_confirm = '2'
+        <where>
+            swcpr.control_station_window_id in
+            <foreach collection="controlWindowIds" item="controlWindowId"  open="(" separator="," close=")">
+                #{controlWindowId}
+            </foreach>
+        </where>
+    </update>
+</mapper>

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

@@ -1,6 +1,53 @@
 <?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.StepWindowDataPassRelationMapper">
+    <update id="initSelected" parameterType="string">
+        <bind name="parentId" value="parentId + '%'" />
+        update
+            step_window_data_pass_relation swdpr
+        set
+            swdpr.is_confirm = '1'
+        <where>
+            swdpr.window_id in (
+                select
+                    assw.id from alg_scheme_step_window  assw
+                where assw.parent_id like #{parentId}
+            )
+            and
+            swdpr.is_confirm = '2'
+        </where>
+    </update>
+    <update id="initSelectedByList" parameterType="arraylist">
+        update
+            step_window_data_pass_relation swdpr
+        set
+            swdpr.is_confirm = '1'
+        <where>
+            swdpr.window_id in (
+                select
+                    assw.id from alg_scheme_step_window  assw
+                where assw.parent_id in
+                <foreach collection="parentIds" item="parentId" open="(" separator="," close=")">
+                    #{parentId}
+                </foreach>
+            )
+            and
+            swdpr.is_confirm = '2'
+        </where>
+    </update>
+
+    <update id="batchUpdateConfirmStatus">
+        update
+            step_window_data_pass_relation swdpr
+        set
+            swdpr.is_confirm = '2'
+        <where>
+            swdpr.data_station_window_id in
+            <foreach collection="dataWindowIds" item="dataWindowId"  open="(" separator="," close=")">
+                #{dataWindowId}
+            </foreach>
+        </where>
+    </update>
 
     <select id="selectIsUsedStepStationWindowDTOList" resultType="com.base.plan.model.dto.StepWindowDTO">
         SELECT

+ 39 - 0
orbit-base-plan/base-plan-service/src/main/resources/mapper/StripInfoMapper.xml

@@ -53,4 +53,43 @@
             where id = #{item.stripId}
         </foreach>
     </update>
+    <update id="initSelected" parameterType="string">
+        <bind name="parentId" value="parentId + '%'" />
+        update
+            strip_info si
+        set
+            si.is_selected = 1
+        <where>
+            si.parent_id like #{parentId}
+            and si.is_selected = 2
+        </where>
+    </update>
+    <update id="initSelectedByList" parameterType="arraylist">
+        update
+            strip_info si
+        set
+            si.is_selected = 1
+        <where>
+            si.parent_id in
+            <foreach collection="parentIds" item="parentId" open="(" separator="," close=")">
+                #{parentId}
+            </foreach>
+            and
+            si.is_selected = 2
+        </where>
+
+    </update>
+    <update id="batchUpdateSelectedStatus">
+        update
+            strip_info si
+        set
+            si.is_selected = 2
+        <where>
+            si.window_id in
+            <foreach collection="windowIds" item="windowId" open="(" separator="," close=")">
+                #{windowId}
+            </foreach>
+        </where>
+
+    </update>
 </mapper>