package com.css.simulation.resource.server.app.service;

import api.common.pojo.constants.DictConstants;
import api.common.pojo.constants.LogConstants;
import api.common.pojo.param.MinioParameter;
import api.common.pojo.param.scene.*;
import api.common.pojo.po.scene.*;
import api.common.pojo.po.system.SceneImportPO;
import api.common.util.*;
import com.alibaba.druid.util.StringUtils;
import com.css.simulation.resource.server.infra.db.mysql.mapper.*;
import com.css.simulation.resource.server.infra.feign.service.FileDownService;
import com.css.simulation.resource.server.infra.util.AuthUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import feign.Response;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

@Slf4j
@Service
public class SceneReferenceLibService {

    @Resource
    private SceneReferenceLibMapper sceneReferenceLibMapper;

    @Resource
    private FileDownService fileDownService;

    @Resource
    private SceneEvaluationRuleService sceneEvaluationRuleService;

    @Resource
    private ScenePackageSublistMapper scenePackageSublistMapper;

    @Resource
    private ScenePackageMapper scenePackageMapper;

    @Resource
    private LogService logService;

    @Resource
    private SystemScenePackageSublistMapper systemScenePackageSublistMapper;

    public SceneEvaluationOperatePO getSceneEvaluationFirst(SceneReferenceLibParam params, List<String> sceneIdList) {
        // 添加复杂度 危险度数据
        SceneEvaluationForListParam sceneEvaluationForListParam = new SceneEvaluationForListParam();
        BeanUtils.copyProperties(params, sceneEvaluationForListParam);
        sceneEvaluationForListParam.setSceneIdList(sceneIdList);
        return sceneEvaluationRuleService.getSceneEvaluationFirst(sceneEvaluationForListParam);
    }

    private void copyEvaluationParams(SceneReferenceLibParam params, SceneReferenceLibSelectParam po) {
        po.setComplexityLevel(params.getComplexityLevel());
        po.setMinComplexity(params.getMinComplexity());
        po.setMaxComplexity(params.getMaxComplexity());
        po.setRiskLevel(params.getRiskLevel());
        po.setMinRisk(params.getMinRisk());
        po.setMaxRisk(params.getMaxRisk());
        if (StringUtil.isNotEmpty(params.getComplexityLevel()) || StringUtil.isNotEmpty(params.getMinComplexity()) || StringUtil.isNotEmpty(params.getMaxComplexity())) {
            po.setNeedComplexity("1");
        }
        if (StringUtil.isNotEmpty(params.getRiskLevel()) || StringUtil.isNotEmpty(params.getMinRisk()) || StringUtil.isNotEmpty(params.getMaxRisk())) {
            po.setNeedRisk("1");
        }
    }
    /**
     * 获取基准场景库列表
     *
     * @param params
     * @return
     */
    public List<SceneReferenceLibPO> querySceneReferenceLibList(SceneReferenceLibParam params) {

        SceneReferenceLibSelectParam srl = new SceneReferenceLibSelectParam();
        copyEvaluationParams(params, srl);
        // 场景名称
        String sceneName = params.getSceneName();
        // 主车行为
        String[][] mainBehavior = params.getMainBehavior();
        String[][] otherBehavior = params.getOtherBehavior();
        String[][] weather = params.getWeather();
        String[][] roadType = params.getRoadType();
        String[][] roadGeometryPlane = params.getRoadGeometryPlane();
        String[][] roadGeometryVertical = params.getRoadGeometryVertical();
        String[][] autoDriveFunction = params.getAutoDriveFunction();
        String[][] operationArea = params.getOperationArea();

        if (mainBehavior != null && mainBehavior.length > 0) {
            ParamUtil.arrConvertObj(mainBehavior, srl);
            for (String[] arr : mainBehavior) {
                if (arr != null && arr.length == 1) {
                    List<String> list = srl.getMainBehavior();
                    if (list == null) {
                        List<String> newList = new ArrayList<>();
                        newList.add(arr[0]);
                        srl.setMainBehavior(newList);
                    } else {
                        list.add(arr[0]);
                        srl.setMainBehavior(list);
                    }
                }
            }
        }
        srl.setSceneId(params.getSceneId());
        srl.setMinComplexity(params.getMinComplexity());
        srl.setMaxComplexity(params.getMaxComplexity());
        srl.setMinRisk(params.getMinRisk());
        srl.setMaxRisk(params.getMaxRisk());
        srl.setComplexityLevel(params.getComplexityLevel());
        srl.setRiskLevel(params.getRiskLevel());
        srl.setSceneDescription(params.getSceneDescription());
        srl.setLabel(params.getLabel());
        srl.setSceneName(sceneName);
        if (otherBehavior != null && otherBehavior.length > 0) {
            ParamUtil.arrConvertObj(otherBehavior, srl);
        }
        if (weather != null && weather.length > 0) {
            ParamUtil.arrConvertObj(weather, srl);
        }
        if (roadType != null && roadType.length > 0) {
            ParamUtil.arrConvertObj(roadType, srl);
        }
        if (roadGeometryPlane != null && roadGeometryPlane.length > 0) {
            ParamUtil.arrConvertObj(roadGeometryPlane, srl);
        }
        if (roadGeometryVertical != null && roadGeometryVertical.length > 0) {
            ParamUtil.arrConvertObj(roadGeometryVertical, srl);
        }
        if (autoDriveFunction != null && autoDriveFunction.length > 0) {
            ParamUtil.arrConvertObj(autoDriveFunction, srl);
        }
        if (operationArea != null && operationArea.length > 0) {
            ParamUtil.arrConvertObj(operationArea, srl);
        }

        // 查询
        List<SceneReferenceLibPO> sceneReferenceLibPOS = sceneReferenceLibMapper.querySceneReferenceLibList(srl);

        for (SceneReferenceLibPO po : sceneReferenceLibPOS) {
            if (po.getRoadType().equals("高速")) {
                if (ObjectUtil.isNull(po.getLabel())) {
                    po.setLabel("高速");
                } else {
                    po.setLabel(po.getLabel() + ",高速");
                }
            }
            if (po.getOtherBehavior().contains("机动车从左侧切入成功") || po.getOtherBehavior().contains("机动车从右侧切入成功")) {
                if (ObjectUtil.isNull(po.getLabel())) {
                    po.setLabel("切入");
                } else {
                    po.setLabel(po.getLabel() + ",切入");
                }
            }
            if (po.getOtherBehavior().equals("机动车向左侧切出成功") || po.getOtherBehavior().equals("机动车向右侧切出成功")) {
                if (ObjectUtil.isNull(po.getLabel())) {
                    po.setLabel("切出");
                } else {
                    po.setLabel(po.getLabel() + ",切出");
                }
            }
            if (po.getMainBehavior().contains("直路掉头") || po.getMainBehavior().contains("路口掉头")) {
                if (ObjectUtil.isNull(po.getLabel())) {
                    po.setLabel("掉头");
                } else {
                    po.setLabel(po.getLabel() + ",掉头");
                }
            }
            if (po.getMainBehavior().contains("向左变道成功") || po.getMainBehavior().equals("向右变道成功") || po.getMainBehavior().contains("向左连续变道") || po.getMainBehavior().indexOf("向右连续变道") > -1 || po.getMainBehavior().indexOf("向左变道超车") > -1 || po.getMainBehavior().indexOf("向右变道超车") > -1) {
                if (ObjectUtil.isNull(po.getLabel())) {
                    po.setLabel("变道");
                } else {
                    po.setLabel(po.getLabel() + ",变道");
                }
            }
        }

        return sceneReferenceLibPOS;
    }


    /**
     * 获取基准场景数据
     */
    public SceneImportPO importMinio(SceneImportParam params) {
        SceneImportPO sceneImportPO = new SceneImportPO();
        sceneImportPO.setId(params.getId());
        try {
            MinioParameter MI = new MinioParameter();
            MI.setObjectName(params.getMinioDirectory());
            List<String> list = fileDownService.listDeepOne(MI).getInfo();
            String OsgbPath = null;
            String XodrPath = null;
            int successNum = 0;
            int falseNum = 0;
            String errorMessage = "";
            for (String filePath : list) {
                if (filePath.contains("/OSGB")) {
                    OsgbPath = filePath;
                } else if (filePath.contains("/XODR")) {
                    XodrPath = filePath;
                }
            }
            String sceneName;
            List<String> sceneNames = new ArrayList<>();
            for (String filePath : list) {
                if (filePath.contains("/Scenarios")) {
                    MI.setObjectName(filePath);
                    List<String> listScene = fileDownService.listDeepOne(MI).getInfo();
                    log.info("importMinio() 共需要上传 " + listScene.size() + " 个基准场景");
                    String taskId = StringUtil.getRandomUUID();
                    SceneEvaluationComputeParam sceneComplexityEvaluationComputeParam = new SceneEvaluationComputeParam();
                    sceneComplexityEvaluationComputeParam.setSceneEvaluationComputeSubParam(new ArrayList<>());
                    for (String scenePath : listScene) {
                        try {
                            MI.setObjectName(scenePath);
                            List<String> addressList = fileDownService.listDeepOne(MI).getInfo();
                            SceneReferenceLibPO sceneReferenceLibPO = new SceneReferenceLibPO();
                            boolean isUpdate = false;
                            List<SceneReferenceLibPO> scenes = new ArrayList<>();
                            for (String address : addressList) {
                                if (address.contains(".json")) {
                                    MI.setObjectName(address);
                                    Response download = fileDownService.download(MI);
                                    // -------------------------------- label.json --------------------------------
                                    String json = download.body().toString();
                                    ObjectMapper objMap = new ObjectMapper();
                                    JsonNode root = objMap.readTree(json);
                                    // 判断场景名称唯一
                                    sceneName = root.path("scenario_name").asText();
                                    sceneNames.add(sceneName);
                                    String osgb = root.path("osgb").asText();
                                    String xodr = root.path("xodr").asText();
                                    if (StringUtil.isEmpty(sceneName)) {
                                        sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_2);
                                        String em = "文件 " + address + " 内容不符合标准格式（场景名称不为空）。";
                                        log.error(em);
                                        sceneImportPO.setErrorMessage(em);
                                        return sceneImportPO;
                                    }
                                    String osgbAdress = OsgbPath + "/" + osgb;
                                    String xodrAdress = XodrPath + "/" + xodr;
                                    sceneReferenceLibPO.setSceneName(sceneName);
                                    scenes = sceneReferenceLibMapper.selectAllByName(sceneReferenceLibPO);
                                    // 新增数据
                                    if (CollectionUtil.isNotEmpty(scenes)) {
                                        isUpdate = true;
                                    }
                                    String mainBehavior = root.path("ego_action").asText();
                                    String otherBehavior = root.path("target_action").asText();
                                    String replaceStr = "none";
                                    String maxTime = root.path("max_time").asText();
//                                    Iterator<JsonNode> weather = root.path("scenario_weather").elements();
//                                    List<String> weatherList = new ArrayList<>();
//                                    if (weather.hasNext()) {
//                                        JsonNode node = weather.next();
//                                        weatherList.add(node.asText());
//                                    }
                                    String rodeType = root.path("rode_type").asText();
                                    String weather = root.path("scenario_weather").asText();
                                    String roadPlaneGeometry = root.path("road_plane_geometry").asText();

//                                    Iterator<JsonNode> roadPlaneGeometry = root.path("road_plane_geometry").elements();
//                                    List<String> roadPlaneGeometryList = new ArrayList<>();
//                                    if (roadPlaneGeometry.hasNext()) {
//                                        JsonNode node = roadPlaneGeometry.next();
//                                        roadPlaneGeometryList.add(node.asText());
//                                    }

//                                    Iterator<JsonNode> roadProfileGeometry = root.path("road_profile_geometry").elements();
//                                    List<String> roadProfileGeometryList = new ArrayList<>();
//                                    if (roadProfileGeometry.hasNext()) {
//                                        JsonNode node = roadProfileGeometry.next();
//                                        roadProfileGeometryList.add(node.asText());
//                                    }
                                    String roadProfileGeometry = root.path("road_profile_geometry").asText();
                                    String autonomousDrivingFunction = root.path("supported_adas").asText();
                                    String drivingArea = root.path("rode_section").asText();
                                    String sceneDescription = root.path("scene_description").asText();
                                    String scenaroTag = root.path("label").asText();
                                    sceneReferenceLibPO.setMainBehavior(StringUtils.equals(mainBehavior, replaceStr) ? "" : mainBehavior);
                                    sceneReferenceLibPO.setOtherBehavior(StringUtils.equals(otherBehavior, replaceStr) ? "" : otherBehavior);
                                    sceneReferenceLibPO.setMaxTime(StringUtils.equals(maxTime, replaceStr) ? "" : maxTime);
//                                    sceneReferenceLibPO.setWeather(String.join(",", weatherList));
                                    sceneReferenceLibPO.setWeather(StringUtils.equals(weather, replaceStr) ? "" : weather);
                                    sceneReferenceLibPO.setRoadType(StringUtils.equals(rodeType, replaceStr) ? "" : rodeType);
                                    sceneReferenceLibPO.setRoadGeometryPlane(StringUtils.equals(roadPlaneGeometry, replaceStr) ? "" : roadPlaneGeometry);
                                    sceneReferenceLibPO.setRoadGeometryVertical(StringUtils.equals(roadProfileGeometry, replaceStr) ? "" : roadProfileGeometry);
                                    sceneReferenceLibPO.setAutoDriveFunction(StringUtils.equals(autonomousDrivingFunction, replaceStr) ? "" : autonomousDrivingFunction);
                                    sceneReferenceLibPO.setOperationArea(StringUtils.equals(drivingArea, replaceStr) ? "" : drivingArea);
                                    sceneReferenceLibPO.setSceneDescription(StringUtils.equals(sceneDescription, replaceStr) ? "" : sceneDescription);
                                    sceneReferenceLibPO.setLabel(StringUtils.equals(scenaroTag, replaceStr) ? "" : scenaroTag);
                                    sceneReferenceLibPO.setIsDeleted(DictConstants.IS_AVAILABLE);
                                    if (ObjectUtil.isNull(sceneReferenceLibPO.getOsgbAddress())) {
                                        sceneReferenceLibPO.setOsgbAddress(osgbAdress);
                                    }
                                    if (ObjectUtil.isNull(sceneReferenceLibPO.getXodrAddress())) {
                                        sceneReferenceLibPO.setXodrAddress(xodrAdress);
                                    }
                                    sceneReferenceLibPO.setJsonAddress(address);
                                } else if (address.contains(".xml") || address.contains(".xosc")) {
                                    sceneReferenceLibPO.setXmlAddress(address);
                                } else if (address.contains(".xodr")) {
                                    sceneReferenceLibPO.setXodrAddress(address);
                                } else if (address.contains(".osgb")) {
                                    sceneReferenceLibPO.setOsgbAddress(address);
                                } else if (address.contains("simulation.mp4")) {
                                    sceneReferenceLibPO.setVideoAddress(address);
                                } else if (address.contains(".mp4")) {
                                    sceneReferenceLibPO.setVideoPreview(address);
                                }
                            }
                            if (isUpdate) {
                                // -------------------------------- 修改数据到 mysql --------------------------------
                                scenes.forEach(scene -> {
                                    sceneReferenceLibPO.setSceneId(scene.getSceneId());
                                    sceneReferenceLibPO.setModifyTime(TimeUtil.getNowForMysql());
                                    sceneReferenceLibPO.setModifyUserId(AuthUtil.getCurrentUserId());
                                    sceneReferenceLibMapper.updateSceneReference(sceneReferenceLibPO);
                                });
                            } else {
                                // -------------------------------- 新增数据到 mysql --------------------------------
                                sceneReferenceLibPO.setSceneId(StringUtil.getRandomUUID());
                                sceneReferenceLibPO.setCreateTime(TimeUtil.getNowForMysql());
                                sceneReferenceLibPO.setCreateUserId(AuthUtil.getCurrentUserId());
                                sceneReferenceLibPO.setModifyTime(TimeUtil.getNowForMysql());
                                sceneReferenceLibMapper.saveSceneReference(sceneReferenceLibPO);

                            }
                            successNum += 1;
                            if (!StringUtils.isEmpty(params.getSceneEvaluationRuleId())) {
                                SceneEvaluationComputeSubParam sceneEvaluationComputeSubParam = new SceneEvaluationComputeSubParam();
                                sceneEvaluationComputeSubParam.setSceneId(isUpdate ? scenes.get(0).getSceneId() : sceneReferenceLibPO.getSceneId());
                                sceneEvaluationComputeSubParam.setSceneXOSCPath(sceneReferenceLibPO.getXmlAddress());
                                sceneEvaluationComputeSubParam.setSceneXODRPath(sceneReferenceLibPO.getXodrAddress());
                                sceneEvaluationComputeSubParam.setSceneType(DictConstants.SCENE_REFERENCE_LIB);
                                if (isUpdate) {
                                    String tempSceneId = scenes.get(0).getSceneId();
                                    sceneEvaluationComputeSubParam.setCopySceneId(scenes.stream().map(SceneReferenceLibPO::getSceneId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
                                }
                                sceneComplexityEvaluationComputeParam.getSceneEvaluationComputeSubParam().add(sceneEvaluationComputeSubParam);
                                log.info("添加计算复杂度数据：" + sceneEvaluationComputeSubParam);
                            }
                        } catch (Exception e) {
                            errorMessage = e.getMessage();
                            log.error("parse scene reference lib file failed.", e);
                            falseNum += 1;
                        }
                    }
                    // 计算复杂度
                    if (CollectionUtil.isNotEmpty(sceneComplexityEvaluationComputeParam.getSceneEvaluationComputeSubParam())) {
                        try {
                            sceneComplexityEvaluationComputeParam.setTaskId(taskId);
                            sceneComplexityEvaluationComputeParam.setSceneEvaluationRuleId(params.getSceneEvaluationRuleId());
                            sceneComplexityEvaluationComputeParam.setComputeType(DictConstants.COMPLEXITY);
                            sceneComplexityEvaluationComputeParam.setCreateUserId(AuthUtil.getCurrentUserId());
                            sceneEvaluationRuleService.computeSceneEvaluation(sceneComplexityEvaluationComputeParam);
                        } catch (Exception e) {
                            log.error("计算复杂度失败", e);
                        }
                    }
                }
            }
            sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_4);
            sceneImportPO.setSuccessNum(successNum);
            sceneImportPO.setFalseNum(falseNum);
            sceneImportPO.setErrorMessage(errorMessage);
            sceneImportPO.setSceneNames(CollectionUtil.listToSequence(sceneNames));
            return sceneImportPO;
        } catch (Exception e) {
            sceneImportPO.setStatus(DictConstants.SCENE_IMPORT_STATUS_2);
            sceneImportPO.setErrorMessage("该文件地址：" + params.getMinioDirectory() + "解析失败，请检查");
            return sceneImportPO;
        }
    }

    @SneakyThrows
    public void updateSceneReference(SceneReferenceLibPO sceneReferenceLibPO) {
        sceneReferenceLibPO.setModifyTime(TimeUtil.getNowForMysql());
        sceneReferenceLibPO.setModifyUserId(AuthUtil.getCurrentUserId());
        sceneReferenceLibMapper.updateSceneReference(sceneReferenceLibPO);
        LogUtil.update();
    }

    @Transactional
    public void batchDeleteSceneReference(List<String> sceneNames) {
        batchDeleteSceneReferenceBySceneId(sceneNames);
    }

    @Transactional
    @SneakyThrows
    public void batchDeleteSceneReferenceBySceneId(List<String> sceneNames) {
        Map<String, String> map = new HashMap<>();
        try {
            //* -------------------------------- 场景表 --------------------------------
            // 1 根据场景名称查询出同名的所有场景名称
            List<String> sceneIds = sceneReferenceLibMapper.selectIdsByNames(sceneNames);
            if (CollectionUtil.isEmpty(sceneIds)) {
                return;
            }
            // 2 删除场景数据
            SceneDeleteParam sceneDeleteParam = SceneDeleteParam.builder()
                    .sceneNames(sceneNames)
                    .modifyTime(TimeUtil.getNowForMysql())
                    .modifyUserId(AuthUtil.getCreateUserId())
                    .build();
            sceneReferenceLibMapper.deleteBySceneNames(sceneDeleteParam);
            //* -------------------------------- 场景测试包指标表 & 场景测试包表 --------------------------------
            // 1 根据自然驾驶场景ID查询场景测试包指标
            List<ScenePackageSublistPO> indexes = scenePackageSublistMapper.selectBySceneIds(ScenePackageSublistParam.builder()
                    .sceneIds(sceneIds)
                    .sceneType(DictConstants.SCENE_REFERENCE_LIB)
                    .build());
            if (CollectionUtil.isEmpty(indexes)) {
                return;
            }
            // 2 根据指标 ID 查询场景测试包
            List<ScenePackagePO> testPackages = scenePackageMapper.selectByIndexIds(ScenePackageParam.builder()
                    .indexIds(indexes.stream().map(ScenePackageSublistPO::getSublistId).collect(Collectors.toList()))
                    .build());
            // 3 设置包为已禁用
            testPackages.forEach(testPackage -> testPackage.setIsUnavailable(DictConstants.IS_UNAVAILABLE));
            // 4 遍历删除场景
            AtomicInteger deleteNum = new AtomicInteger();
            deleteNum.set(0);
            indexes.forEach(index -> {
                final String sceneReferenceLibIdsStr = index.getSceneReferenceLibIds();
                List<String> sceneReferenceLibIds = new ArrayList<>();
                if (StringUtil.isNotEmpty(sceneReferenceLibIdsStr)) {
                    sceneReferenceLibIds = CollectionUtil.sequenceStringToList(sceneReferenceLibIdsStr, ",");
                }

                final String sceneNaturalIdsString = index.getSceneReferenceLibIds();
                List<String> sceneNaturalIds = new ArrayList<>();
                if (StringUtil.isNotEmpty(sceneNaturalIdsString)) {
                    sceneNaturalIds = CollectionUtil.sequenceStringToList(sceneNaturalIdsString, ",");
                }
                final String sceneTrafficIdsString = index.getSceneTrafficIds();
                List<String> sceneTrafficIds = new ArrayList<>();
                if (StringUtil.isNotEmpty(sceneTrafficIdsString)) {
                    sceneTrafficIds = CollectionUtil.sequenceStringToList(sceneTrafficIdsString, ",");
                }
                final String sceneStatueIdsString = index.getSceneStatueIds();
                List<String> sceneStatueIds = new ArrayList<>();
                if (StringUtil.isNotEmpty(sceneStatueIdsString)) {
                    sceneStatueIds = CollectionUtil.sequenceStringToList(sceneStatueIdsString, ",");
                }
                final String sceneGeneralizationIdsString = index.getSceneGeneralizationIds();
                List<String> sceneGeneralizationIds = new ArrayList<>();
                if (StringUtil.isNotEmpty(sceneGeneralizationIdsString)) {
                    sceneGeneralizationIds = CollectionUtil.sequenceStringToList(sceneGeneralizationIdsString, ",");
                }
                final Iterator<String> iterator = sceneReferenceLibIds.iterator();
                while (iterator.hasNext()) {
                    final String sceneId = iterator.next();
                    if (sceneIds.contains(sceneId)) {
                        iterator.remove();
                        deleteNum.getAndIncrement();
                        testPackages.forEach(testPackage ->
                                testPackage.setSceneNum(testPackage.getSceneNum() - 1)
                        );
                    }
                }
                index.setSceneNum(sceneReferenceLibIds.size() + sceneNaturalIds.size() + sceneTrafficIds.size() +
                        sceneStatueIds.size() + sceneGeneralizationIds.size());
//                index.setSceneNum(index.getSceneNum() - deleteNum.get());
                index.setSceneReferenceLibIds(CollectionUtil.listToSequence(sceneReferenceLibIds));
                index.setModifyTime(TimeUtil.getNowForMysql());
                index.setModifyUserId(AuthUtil.getCurrentUserId());
            });
            // 5 更新指标
            scenePackageSublistMapper.update(indexes);
            // 6 更新包
            scenePackageMapper.update(testPackages);

            //* -------------------------------- 场景包表 --------------------------------
            // 1 将所有场景包中的该场景删除
            systemScenePackageSublistMapper.deleteBySceneNames(SystemScenePackageParam.builder()
                    .sceneNames(sceneNames)
                    .modifyTime(TimeUtil.getNowForMysql())
                    .modifyUserId(AuthUtil.getCurrentUserId())
                    .build());
        } finally {
            //* -------------------------------- 日志表 --------------------------------
            map.put("sceneNames", JsonUtil.listToJson(sceneNames));
            map.put("type", DictConstants.SCENE_REFERENCE_LIB);
            logService.logSceneDelete(LogConstants.SYS_LOG_SCENE_DELETE, map);
        }
    }


}
