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

import api.common.pojo.common.ResponseBodyVO;
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.util.AuthUtil;
import com.css.simulation.resource.server.infra.feign.service.FileDownService;
import com.css.simulation.resource.server.infra.db.mysql.mapper.ScenePackageMapper;
import com.css.simulation.resource.server.infra.db.mysql.mapper.ScenePackageSublistMapper;
import com.css.simulation.resource.server.infra.db.mysql.mapper.SceneStandardsRegulationsMapper;
import com.css.simulation.resource.server.infra.db.mysql.mapper.SystemScenePackageSublistMapper;
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 SceneStandardsService {

    @Resource
    private SceneStandardsRegulationsMapper sceneStandardsRegulationsMapper;
    @Resource
    private ScenePackageSublistMapper scenePackageSublistMapper;
    @Resource
    private ScenePackageMapper scenePackageMapper;
    @Resource
    private SystemScenePackageSublistMapper systemScenePackageSublistMapper;

    @Resource
    private FileDownService fileDownService;
    @Resource
    LogService logService;

    @Resource
    private SceneEvaluationRuleService sceneEvaluationRuleService;

    /**
     * 获取标准法规场景数据：
     */
    @SneakyThrows
    public ResponseBodyVO<String> importBzFg(StandardsRegulationsParam param) {

        MinioParameter MI = new MinioParameter();
        MI.setObjectName(param.getJsonAddress());
        Response download = fileDownService.download(MI);
        String json = download.body().toString();
        ObjectMapper objMap = new ObjectMapper();
        JsonNode root = objMap.readTree(json);
        String sceneName = root.path("场景名称").asText();
        StandardsRegulationsPO standardsRegulationsPO = new StandardsRegulationsPO();
        standardsRegulationsPO.setShare("0");
        standardsRegulationsPO.setSceneName(sceneName);
        StandardsRegulationsPO PoByName = sceneStandardsRegulationsMapper.queryStandardsRegulationsByName(standardsRegulationsPO);


        standardsRegulationsPO = standardsRegulationsPO.builder()
                .regulationsId(StringUtil.getRandomUUID())
                .sceneName(sceneName)
                .regulationType(root.path("法规类型").asText())
                .standardType(root.path("标准类型").asText())
                .maxTime(root.path("max_time").asText())
                .isDeleted("0")
                .build();
        if (null != param.getJsonAddress() && !param.getJsonAddress().equals("")) {
            standardsRegulationsPO.setJsonAddress(param.getJsonAddress());
        }
        if (null != param.getXmlAddress() && !param.getXmlAddress().equals("")) {
            standardsRegulationsPO.setXmlAddress(param.getXmlAddress());
        }
        if (null != param.getXodrAddress() && !param.getXodrAddress().equals("")) {
            standardsRegulationsPO.setXodrAddress(param.getXodrAddress());
        }
        if (null != param.getOsgbAddress() && !param.getOsgbAddress().equals("")) {
            standardsRegulationsPO.setOsgbAddress(param.getOsgbAddress());
        }
        if (null != param.getVideoAddress() && !param.getVideoAddress().equals("")) {
            standardsRegulationsPO.setVideoAddress(param.getVideoAddress());
        }
        if (null != param.getVideoPreview() && !param.getVideoPreview().equals("")) {
            standardsRegulationsPO.setVideoPreview(param.getVideoPreview());
        }

        if (ObjectUtil.isNull(standardsRegulationsPO)) {
            // -------------------------------- 保存数据到 mysql --------------------------------
            standardsRegulationsPO.setCreateTime(TimeUtil.getNowForMysql());
            standardsRegulationsPO.setModifyTime(TimeUtil.getNowForMysql());
            standardsRegulationsPO.setCreateUserId(AuthUtil.getCurrentUserId());
            sceneStandardsRegulationsMapper.saveStandardsRegulations(standardsRegulationsPO);

            // return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "该场景名称" + sceneName + "已存在，请检查");
        } else {
            // -------------------------------- 修改数据到 mysql --------------------------------
            standardsRegulationsPO.setRegulationsId(standardsRegulationsPO.getRegulationsId());
            standardsRegulationsPO.setModifyTime(TimeUtil.getNowForMysql());
            standardsRegulationsPO.setModifyUserId(AuthUtil.getCurrentUserId());
            sceneStandardsRegulationsMapper.updateStandardsRegulations(standardsRegulationsPO);
        }
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
    }

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

    //查看列表
    public List<StandardsRegulationsPO> queryStandardsRegulationsList(StandardsRegulationsParam params) {
        if (StringUtil.isNotEmpty(params.getComplexityLevel()) || StringUtil.isNotEmpty(params.getMinComplexity()) || StringUtil.isNotEmpty(params.getMaxComplexity())) {
            params.setNeedComplexity("1");
        }
        if (StringUtil.isNotEmpty(params.getRiskLevel()) || StringUtil.isNotEmpty(params.getMinRisk()) || StringUtil.isNotEmpty(params.getMaxRisk())) {
            params.setNeedRisk("1");
        }

        List<StandardsRegulationsPO> list = new ArrayList<>();

        //添加权限
        String roleCode = AuthUtil.getCurrentUserRoleCode();
        log.info("标准法规------" + roleCode);
        String userId = AuthUtil.getCurrentUserId();
        if (DictConstants.ROLE_CODE_ADMIN.equals(roleCode) || DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)) { //管理员账户
            list = sceneStandardsRegulationsMapper.queryStandardsRegulationsList(params);
            log.info("标准法规---list---" + list.size() + "----------" + params);
        } else if (DictConstants.ROLE_CODE_SUBUESR.equals(roleCode)) {
            //查询父账户
            userId = AuthUtil.getCreateUserId();
            params.setUserId(userId);
            if (params.getShare().equals("0")) {
                list = sceneStandardsRegulationsMapper.queryStandardsRegulationsList(params);
            } else {
                list = sceneStandardsRegulationsMapper.queryStandardsRegulationsListByQx(params);
            }
        } else if (DictConstants.ROLE_CODE_UESR.equals(roleCode)) {
            //查询普通账户
            params.setUserId(userId);
            if (params.getShare().equals("0")) {
                list = sceneStandardsRegulationsMapper.queryStandardsRegulationsList(params);
            } else {
                list = sceneStandardsRegulationsMapper.queryStandardsRegulationsListByQx(params);
            }
        }
       /* if(params.getLabel()!=null&&params.getLabel().size()>0){
            if(params.getRegulationType()!=null&&params.getRegulationType().size()>0){
                List<String> regulationType= params.getRegulationType();
                regulationType.addAll(params.getLabel());
                params.setRegulationType(regulationType);
            }else{
                List<String> regulationType=new ArrayList<>();
                regulationType.addAll(params.getLabel());
                params.setRegulationType(regulationType);
            }
        }*/

        //获取权限并赋值
      /*  List<String> listType=  systemUserSceneService.querySystemUserSceneByType(DictConstants.SCENE_STANDARD);
        if(listType!=null&&listType.size()>0){
            params.setAllIds(listType);
        }else{
            List<String> listA=new ArrayList<>();
            listA.add("没有权限");
            params.setAllIds(listA);
        }*/
        return list;
    }

    @Transactional
    public void batchDeleteSceneStandards(List<String> sceneNames) {
        deleteStandardsRegulations(sceneNames);
    }

    @SneakyThrows
    @Transactional
    public void deleteStandardsRegulations(List<String> sceneNames) {
        Map<String, String> map = new HashMap<>();
        try {
            //* -------------------------------- 场景表 --------------------------------
            //1 根据场景名称查询出同名的所有场景id，包括公有和私有
            List<String> sceneIds = sceneStandardsRegulationsMapper.selectIdsByNames(sceneNames);
            if (CollectionUtil.isEmpty(sceneIds)) {
                return;
            }
            //2 删除场景数据
            SceneDeleteParam sceneDeleteParam = SceneDeleteParam.builder()
                    .sceneNames(sceneNames)
                    .modifyTime(TimeUtil.getNowForMysql())
                    .modifyUserId(AuthUtil.getCreateUserId())
                    .build();
            sceneStandardsRegulationsMapper.deleteBySceneNames(sceneDeleteParam);
            //* -------------------------------- 场景测试包指标表 & 场景测试包表 --------------------------------
            //1 根据自然驾驶场景ID查询场景测试包指标
            List<ScenePackageSublistPO> indexes = scenePackageSublistMapper.selectBySceneIds(ScenePackageSublistParam.builder()
                    .sceneIds(sceneIds)
                    .sceneType(DictConstants.SCENE_STANDARD)
                    .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();
            indexes.forEach(index -> {
                final String sceneNaturalIdsString = index.getSceneNaturalIds();
                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 String sceneReferenceLibIds = index.getSceneReferenceLibIds();
                List<String> sceneReferenceLibIdList = new ArrayList<>();
                if (StringUtil.isNotEmpty(sceneReferenceLibIds)) {
                    sceneReferenceLibIdList = CollectionUtil.sequenceStringToList(sceneReferenceLibIds, ",");
                }
                final Iterator<String> iterator = sceneStatueIds.iterator();
                while (iterator.hasNext()) {
                    final String sceneId = iterator.next();
                    if (sceneIds.contains(sceneId)) {
                        deleteNum.getAndIncrement();
                        iterator.remove();
                        testPackages.forEach(testPackage -> testPackage.setSceneNum(testPackage.getSceneNum() - 1));
                    }
                }
                index.setSceneNum(sceneNaturalIds.size() + sceneTrafficIds.size() + sceneStatueIds.size() + sceneGeneralizationIds.size() + sceneReferenceLibIdList.size());
//                index.setSceneNum(index.getSceneNum() - deleteNum.get());
                index.setSceneNaturalIds(CollectionUtil.listToSequence(sceneNaturalIds));
                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_STANDARD);
            logService.logSceneDelete(LogConstants.SYS_LOG_SCENE_DELETE, map);
        }
    }


    public ResponseBodyVO<List<String>> queryRegulationType() {
        //添加权限
        String roleCode = AuthUtil.getCurrentUserRoleCode();
        String userId = AuthUtil.getCurrentUserId();
        if (DictConstants.ROLE_CODE_ADMIN.equals(roleCode) || DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode)) { //管理员账户
            userId = "";
        } else if (DictConstants.ROLE_CODE_SUBUESR.equals(roleCode)) {
            //查询父账户
            userId = AuthUtil.getCreateUserId();
        }
        List<String> list = sceneStandardsRegulationsMapper.queryRegulationType(userId);

        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, list);

    }

    /**
     * 获取标准法规场景数据：
     */
    public SceneImportPO importMinio(SceneImportParam parms) {
        log.info("接到场景上传请求：" + parms);
        SceneImportPO sceneImportPO = new SceneImportPO();
        sceneImportPO.setId(parms.getId());
        try {
            MinioParameter MI = new MinioParameter();
            MI.setObjectName(parms.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 = null;
            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 = api.common.util.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();
                            StandardsRegulationsPO standardsRegulationsPO = new StandardsRegulationsPO();
                            String isupdate = null;
                            List<StandardsRegulationsPO> 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("场景名称").asText();
                                    sceneNames.add(sceneName);
                                    String regulationType = root.path("法规类型").asText();
                                    String standardType = root.path("标准类型").asText();
                                    String osgb = root.path("osgb").asText();
                                    String xodr = root.path("xodr").asText();
                                    if (StringUtil.isEmpty(sceneName) || (StringUtil.isEmpty(regulationType) && StringUtil.isEmpty(standardType))) {
                                        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;
//                                    standardsRegulationsPO.setShare("0");
                                    standardsRegulationsPO.setShare(null);// 覆盖全部场景，包括share为0、1、2
                                    standardsRegulationsPO.setSceneName(sceneName);
//                                    StandardsRegulationsPO PoByName = standardsRegulationsMapper.queryStandardsRegulationsByName(standardsRegulationsPO);
                                    scenes = sceneStandardsRegulationsMapper.selectAllByName(standardsRegulationsPO);
                                    if (CollectionUtil.isEmpty(scenes)) {  // 新增数据
                                        isupdate = "0";
                                    } else {    // 覆盖（更新）数据
                                        isupdate = "1";
                                    }
                                    standardsRegulationsPO.setRegulationType(regulationType);
                                    standardsRegulationsPO.setStandardType(standardType);
                                    standardsRegulationsPO.setMaxTime(root.path("max_time").asText());
                                    standardsRegulationsPO.setIsDeleted("0");
                                    if (ObjectUtil.isNull(standardsRegulationsPO.getOsgbAddress())) {
                                        standardsRegulationsPO.setOsgbAddress(osgbAdress);
                                    }
                                    if (ObjectUtil.isNull(standardsRegulationsPO.getXodrAddress())) {
                                        standardsRegulationsPO.setXodrAddress(xodrAdress);
                                    }
                                }
                                if (address.contains(".json")) {
                                    standardsRegulationsPO.setJsonAddress(address);
                                } else if (address.contains(".xml") || address.contains(".xosc")) {
                                    standardsRegulationsPO.setXmlAddress(address);
                                } else if (address.contains(".xodr")) {
                                    standardsRegulationsPO.setXodrAddress(address);
                                } else if (address.contains(".osgb")) {
                                    standardsRegulationsPO.setOsgbAddress(address);
                                } else if (address.contains(".mp4")) {
                                    standardsRegulationsPO.setVideoAddress(address);
                                }
                            }
                            if (isupdate.equals("0")) {
                                // -------------------------------- 新增数据到 mysql --------------------------------
                                standardsRegulationsPO.setShare(DictConstants.IS_NOT_SHARED);
                                standardsRegulationsPO.setRegulationsId(StringUtil.getRandomUUID());
                                standardsRegulationsPO.setCreateTime(TimeUtil.getNowForMysql());
                                standardsRegulationsPO.setCreateUserId(AuthUtil.getCurrentUserId());
                                standardsRegulationsPO.setModifyTime(TimeUtil.getNowForMysql());
                                sceneStandardsRegulationsMapper.saveStandardsRegulations(standardsRegulationsPO);

                            } else if (isupdate.equals("1")) {
                                // -------------------------------- 修改数据到 mysql --------------------------------
                                if (api.common.util.StringUtil.isEmpty(standardsRegulationsPO.getShare())) {
                                    standardsRegulationsPO.setShare(DictConstants.IS_NOT_SHARED);
                                }
                                scenes.forEach(scene -> {
                                    standardsRegulationsPO.setRegulationsId(scene.getRegulationsId());
                                    standardsRegulationsPO.setModifyTime(TimeUtil.getNowForMysql());
                                    standardsRegulationsPO.setModifyUserId(AuthUtil.getCurrentUserId());
                                    sceneStandardsRegulationsMapper.updateStandardsRegulations(standardsRegulationsPO);
                                });
                            }
                            successNum = successNum + 1;

                            // 计算复杂度
                            if (!StringUtils.isEmpty(parms.getSceneEvaluationRuleId())) {
                                SceneEvaluationComputeSubParam sceneEvaluationComputeSubParam = new SceneEvaluationComputeSubParam();
                                sceneEvaluationComputeSubParam.setSceneId(isupdate.equals("0") ? standardsRegulationsPO.getRegulationsId() : scenes.get(0).getRegulationsId());
                                sceneEvaluationComputeSubParam.setSceneXOSCPath(standardsRegulationsPO.getXmlAddress());
                                sceneEvaluationComputeSubParam.setSceneXODRPath(standardsRegulationsPO.getXodrAddress());
                                sceneEvaluationComputeSubParam.setSceneType(DictConstants.SCENE_STANDARD);
                                if (isupdate.equals("1")) {
                                    String tempSceneId = scenes.get(0).getRegulationsId();
                                    sceneEvaluationComputeSubParam.setCopySceneId(scenes.stream().map(StandardsRegulationsPO::getRegulationsId).filter(sceneId -> !StringUtils.equals(tempSceneId, sceneId)).collect(Collectors.toList()));
                                }
                                sceneComplexityEvaluationComputeParam.getSceneEvaluationComputeSubParam().add(sceneEvaluationComputeSubParam);
                                log.info("添加计算复杂度数据：" + sceneEvaluationComputeSubParam);
                            }
                        } catch (Exception e) {
                            errorMessage = e.getMessage();
                            e.printStackTrace();
                            falseNum = falseNum + 1;
                        }
                    }
                    try {
                        if (CollectionUtil.isNotEmpty(sceneComplexityEvaluationComputeParam.getSceneEvaluationComputeSubParam())) {
                            sceneComplexityEvaluationComputeParam.setTaskId(taskId);
                            sceneComplexityEvaluationComputeParam.setSceneEvaluationRuleId(parms.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("该文件地址：" + parms.getMinioDirectory() + "解析失败，请检查");
            return sceneImportPO;
        }
    }

    /**
     * 获取标准法规场景数据：
     */
    public void instStandardsRegulation(StandardsRegulationsPO po) {
        StandardsRegulationsPO syPo = sceneStandardsRegulationsMapper.queryStandardsRegulationsById(po.getRegulationsId());
        syPo.setShare("1");
        StandardsRegulationsPO PoByName = sceneStandardsRegulationsMapper.queryStandardsRegulationsByName(syPo);
        if (ObjectUtil.isNull(PoByName)) {
            // -------------------------------- 保存数据到 mysql --------------------------------
            syPo.setCreateTime(TimeUtil.getNowForMysql());
            syPo.setCreateUserId(AuthUtil.getCurrentUserId());
            syPo.setModifyTime(TimeUtil.getNowForMysql());
            syPo.setModifyUserId("");
            syPo.setRegulationsId(api.common.util.StringUtil.getRandomUUID());
            sceneStandardsRegulationsMapper.saveStandardsRegulations(syPo);
        } else {
            // -------------------------------- 修改数据到 mysql --------------------------------
            syPo.setModifyTime(TimeUtil.getNowForMysql());
            syPo.setModifyUserId(AuthUtil.getCurrentUserId());
            syPo.setRegulationsId(PoByName.getRegulationsId());
            sceneStandardsRegulationsMapper.updateStandardsRegulations(syPo);
        }

    }


}
