/*
 * *********************************************************************************************************************
 *
 *          !!
 *        .F88X
 *        X8888Y
 *      .}888888N;
 *        i888888N;        .:!              .I$WI:
 *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
 *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
 *            +888888N;  .8888888Y                                  "&&8Y.}8,
 *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
 *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
 *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
 *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
 *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
 *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
 *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
 *      .:R888888I
 *      .&888888I                                          Copyright (c) 2009-2020.  博锐尚格科技股份有限公司
 *        ~8888'
 *        .!88~                                                                     All rights reserved.
 *
 * *********************************************************************************************************************
 */

package com.persagy.server.services.dict.dictnew

import com.persagy.database.SFilter
import com.persagy.database.SPageQueryInfo
import com.persagy.database.SQueryBuilder
import com.persagy.mybatis.SMybatisDao
import com.persagy.server.Opt
import com.persagy.server.datacenter.datacenter.models.entities.dictnew.DefClass
import com.persagy.server.datacenter.datacenter.models.entities.dictnew.DictMajor
import com.persagy.server.datacenter.models.entities.dict.DictBatchProcessing
import com.persagy.server.datacenter.models.entities.dict.DictSQueryRequest
import com.persagy.server.datacenter.models.entities.dict.EquipFamily
import com.persagy.server.datacenter.models.entities.dict.Family
import com.persagy.server.datacenter.models.entities.dictnew.*
import com.persagy.server.datacenter.models.requests.CategoryRequest
import com.persagy.server.mappers.CustomMapper
import com.persagy.server.services.assistant.SchemeService
import com.persagy.server.services.graphtype.ConnectedBlockService
import com.persagy.service.SObjectService
import com.persagy.service.SPageContext
import com.persagy.service.models.enums.SResponseType
import com.persagy.service.models.requests.SCreateRequest
import com.persagy.service.models.responses.SBaseResponse
import com.persagy.service.models.responses.SCreateResponse
import com.persagy.service.models.responses.SQueryResponse
import com.persagy.service.utils.SSpringContextUtil
import org.slf4j.LoggerFactory

/**
 * 字典类型
 *
 * @author wx <zhangweixin@sagacloud.cn>
 * @date  2020/9/23 15:43
 */
object DictDefClassService : SObjectService<DefClass>(SMybatisDao(DefClass::class.java)){
    /** 自定义SQL 对象 */
    private val schemeService by lazy {
        SSpringContextUtil.getBean(SchemeService::class.java) as SchemeService
    }

    /** 自定义 sql */
    private val customMapper by lazy {
        SSpringContextUtil.getBean(CustomMapper::class.java) as CustomMapper
    }

    /** 日志 */
    private val logger = LoggerFactory.getLogger(ConnectedBlockService::class.java)

    /** 方案和项目的关系 */
    private val dictSchemeAndProjectService = SObjectService(SMybatisDao(DictSchemeAndProject::class.java))
    /** 方案下的类型 */
    private val dictSchemeCategotyService = SObjectService(SMybatisDao(DictSchemeCategoty::class.java))
    /** 项目所属的集团 */
    private val dictProjectService = SObjectService(SMybatisDao(DictProject::class.java))
    /** 平台集团对象类型 */
    private val defClassService = SObjectService(SMybatisDao(DefClass::class.java))
    /** 专业 */
    private val dictMajorService = SObjectService(SMybatisDao(DictMajor::class.java))
    /** 信息点 */
    private val dictDefFuncId = SObjectService(SMybatisDao(DefFuncId::class.java))
    /** 项目定制化服务 */
    private val defFuncIdProjectService = SObjectService(SMybatisDao(DefFuncIdProject::class.java))
    /** 设备族和设备类型对应表服务 */
    private val equipFamilyService = SObjectService(SMybatisDao(EquipFamily::class.java))
    /** 设备族 */
    private val familyService = SObjectService(SMybatisDao(Family::class.java))

    /**
     * 查询设备、部件、系统、专业类型
     *
     * @param categoryRequest   类型查询对象
     * @return 返回结果
     */
    fun equipQuery(categoryRequest: CategoryRequest): SQueryResponse<DefClass> {
        val sQueryResponse = SQueryResponse<DefClass>()
        if (!categoryRequest.type.isNullOrEmpty()){
            val projectId = SPageContext.getHeader("projectId")
            var dictSchemeCategoryList = ArrayList<DefClass>()
            // 查询项目所在的集团 然后取集团字典
//        val dictSchemeAndProject = dictSchemeAndProjectService.select(SFilter.eq("projectId", projectId!!)).entity()
            val dictProject = dictProjectService.select(SFilter.eq("id", projectId!!)).entity()
            if (dictProject != null){
                var queryBuilder : SQueryBuilder<DefClass>? = null
                var pageInfo : SPageQueryInfo<DefClass>? = null
                when (categoryRequest.type) {
                    "equipment" -> {
//                    queryBuilder = select(SFilter.eq(SLength("id"), 4), SFilter.not(SFilter.isNull("parentId")))
//                    pageInfo = queryBuilder.pageQuery(1, 1000)

                        dictSchemeCategoryList = defClassService.select(
                            SFilter.eq("parentCode","equipment"),
                            SFilter.eq("projectId",projectId!!)
                        ).exec()

                    }
                    "component" -> {
//                    queryBuilder = select(SFilter.eq(SLength("id"), 6), SFilter.not(SFilter.isNull("parentId")),
//                        SFilter.not(SFilter.eq("parentId","Space")),SFilter.not(SFilter.eq("name","租户"))
//                    )
//                    pageInfo = queryBuilder.pageQuery(1, 1000)
                        dictSchemeCategoryList = defClassService.select(
                            SFilter.eq("parentCode","component"),
                            SFilter.eq("projectId",projectId!!)
                        ).exec()
                    }
                    "system" -> {
//                    queryBuilder = select(SFilter.eq(SLength("id"), 2), SFilter.not(SFilter.eq("parentId","AllProfessionalSystemEquipment")))
//                    pageInfo = queryBuilder.pageQuery(1, 1000)
                        dictSchemeCategoryList = defClassService.select(
                            SFilter.eq("parentCode","system"),
                            SFilter.eq("projectId",projectId!!)
                        ).exec()
                    }
                    "major" -> {
//                    queryBuilder = select(SFilter.eq(SLength("id"), 2), SFilter.eq("parentId","AllProfessionalSystemEquipment"))
////                    pageInfo = queryBuilder.pageQuery(1, 1000)
                        val dictMajorList = dictMajorService.selectAll().exec()
                        if (dictMajorList.size>0){
                            for (dictMajor in dictMajorList){
                                val defClass = DefClass()
                                defClass.code = dictMajor.code
                                defClass.name = dictMajor.name
                                defClass.aliasName = dictMajor.aliasName
                                defClass.aliasCode = dictMajor.aliasCode
                                dictSchemeCategoryList.add(defClass)
                            }
                        }
                    }
                    "majorSystem" -> {
//                    val listClassDef = DClassDefService.select(SFilter.eq("parentId", "AllProfessionalSystemEquipment")).exec()
//                    for (classDef in listClassDef){
//                        val exec = DClassDefService.select(SFilter.eq("parentId", classDef.id!!)).exec()
//                        classDef.listClassDef = exec
//                    }
//                    pageInfo = SPageQueryInfo(1, 1000)
//                    pageInfo.content  = listClassDef
                        val dictMajorList = dictMajorService.selectAll().exec()
                        if (dictMajorList.size>0){
                            for (dictMajor in dictMajorList){
                                val defClass = DefClass()
                                defClass.code = dictMajor.code
                                defClass.name = dictMajor.name
                                defClass.aliasName = dictMajor.aliasName
                                defClass.aliasCode = dictMajor.aliasCode
                                val defClassList = defClassService.select(
                                    SFilter.eq("parentCode", "system"),
                                    SFilter.eq("projectId",projectId!!),
                                    SFilter.eq("majorCode", defClass.code!!)
                                ).exec()
                                defClass.children = defClassList
                                dictSchemeCategoryList.add(defClass)
                            }
                        }
                    }
                    "space" -> {
                        /** 业务空间类型 */
                        dictSchemeCategoryList = defClassService.select(
                            SFilter.eq("parentCode","space"),
                            SFilter.eq("projectId",projectId!!)
                        ).exec()
                    }
                    "majorEquipment" -> {
                        /** 专业下的设备 */
                        val dictMajorList = dictMajorService.selectAll().exec()
                        if (dictMajorList.size>0){
                            for (dictMajor in dictMajorList){
                                val defClass = DefClass()
                                defClass.code = dictMajor.code
                                defClass.name = dictMajor.name
                                defClass.aliasName = dictMajor.aliasName
                                defClass.aliasCode = dictMajor.aliasCode
                                val defClassList = defClassService.select(
                                    SFilter.eq("parentCode", "equipment"),
                                    SFilter.eq("projectId",projectId!!),
                                    SFilter.eq("majorCode", defClass.code!!)
                                ).exec()
                                defClass.children = defClassList
                                dictSchemeCategoryList.add(defClass)
                            }
                        }
                    }
                    "equipmentAndComponent" -> {
                        /** 设备和部件 */
                        dictSchemeCategoryList = defClassService.select(
                            SFilter.or(SFilter.eq("parentCode","component"),SFilter.eq("parentCode","equipment")), SFilter.eq("projectId",projectId!!)

                        ).exec()
                    }
                    "equipmentComponent" ->{
                        /** 设备下的部件 */
                        dictSchemeCategoryList = defClassService.select(
                            SFilter.eq("parentCode","equipment"), SFilter.eq("projectId",projectId!!)
                        ).exec()
                        val defClassList = defClassService.select(
                            SFilter.eq("parentCode", "component"),
                            SFilter.eq("projectId",projectId!!)
                        ).exec()
                        if (dictSchemeCategoryList.size > 0){
                            for (dictSchemeCategory in dictSchemeCategoryList){
                                var list = ArrayList<DefClass>()
                                for (defClass in defClassList){
                                    if (defClass.equipmentCode == dictSchemeCategory.code){
                                        list.add(defClass)
                                    }
                                }
                                if (list.size>0){
                                    dictSchemeCategory.children = list
                                }
                            }
                        }
                    }
                    "majorSystemEquip" -> {
                        /** 专业下的系统，系统下的设备 */
                        val dictMajorList = dictMajorService.selectAll().exec()
                        if (dictMajorList.size>0){
                            for (dictMajor in dictMajorList){
                                val defClass = DefClass()
                                defClass.code = dictMajor.code
                                defClass.name = dictMajor.name
                                defClass.aliasName = dictMajor.aliasName
                                defClass.aliasCode = dictMajor.aliasCode
                                dictSchemeCategoryList.add(defClass)
                            }
                        }
                        /** 系统 */
                        val systemList = defClassService.select(
                            SFilter.eq("parentCode", "system"), SFilter.eq("projectId",projectId!!)
                        ).exec()
                        /** 设备 */
                        val equipmentList = defClassService.select(
                            SFilter.eq("parentCode","equipment"), SFilter.eq("projectId",projectId!!)
                        ).exec()
                        /** 系统下的设备 */
                        for (system in systemList){
                            for (equipment in equipmentList){
                                if (system.code == equipment.systemCode){
                                    if (system.children.isNullOrEmpty()){
                                        system.children = ArrayList<DefClass>()
                                    }
                                    system.children!!.add(equipment)
                                }
                            }
                        }
                        /** 专业下的系统 */
                        for (system in systemList){
                            for (dictMajor in dictSchemeCategoryList){
                                if (dictMajor.code == system.majorCode ){
                                    if (dictMajor.children.isNullOrEmpty()){
                                        dictMajor.children = ArrayList<DefClass>()
                                    }
                                    dictMajor.children!!.add(system)
                                }
                            }
                        }
                    }
                    "property" -> {
                        /** 资产 */
                        val familyList = familyService.selectAll().exec()
                        for (family in familyList){
                            val defClass = DefClass()
                            defClass.code = family.code
                            defClass.name = family.name
                            defClass.aliasName = family.code
                            defClass.aliasCode = family.name
                            dictSchemeCategoryList.add(defClass)
                        }
                    }
                }
                sQueryResponse.result = SResponseType.success
                sQueryResponse.content = dictSchemeCategoryList
                sQueryResponse.total = dictSchemeCategoryList.size.toLong()
            }
        }else{
            sQueryResponse.result = SResponseType.failure
            sQueryResponse.message = "请输入查询类型"
        }
        return sQueryResponse
    } // Fun equipQuery()

    /**
     * 查询项目下对象类型对应的信息点
     *
     * @param request   查询条件
     * @return 返回结果
     */
    fun categoryInfoQuery(request: DictSQueryRequest): SQueryResponse<DefFuncId> {
        /** 项目id */
        val projectId = SPageContext.getHeader("projectId")
        /** 返回对象 */
        val sQueryResponse = SQueryResponse<DefFuncId>()
        sQueryResponse.result = SResponseType.failure
        /** 类型不能为空 */
        if (!request.type.isNullOrEmpty()) {
            val dictProject = dictProjectService.select(SFilter.eq("id", projectId!!)).entity()
            /** 项目对应的集团对象不为空 */
            if (dictProject!=null) {
//                val dictDefFuncBuilder01 = dictDefFuncId.select(request.filters).filter(SFilter.eq("projectId", projectId),
//                    SFilter.eq("classCode", request.type!!))

//                val dictDefFuncList01 = dictDefFuncBuilder01.table("dict.def_funcid_project").order("sort").exec()
//                logger.debug("测试 =${dictDefFuncList01.size}")
//                /** 项目定制已存在直接返回 */
//                if(dictDefFuncList01.size == 0&&request.type!!.length == 3){
//
//                    val familyList = equipFamilyService.select(SFilter.eq("family", request.type!!)).exec()
//                    if (familyList.size>0){
//                        val equipFamily = familyList[0]
//                        schemeService.dictInfoProperty(projectId, dictProject.groupCode!!, equipFamily.equipCode!!,request.type!!)
//                        val dictDefFuncBuilder = dictDefFuncId.select(
//                            SFilter.eq("projectId", projectId),
//                            SFilter.eq("classCode", request.type!!)
//                        )
//                        val dictDefFuncList = dictDefFuncBuilder.table("dict.def_funcid_project").order("sort").exec()
//                        sQueryResponse.content = dictDefFuncList
//                        sQueryResponse.total = dictDefFuncList.size.toLong()
//                    }
//                }else if (dictDefFuncList01.size == 0) {
//                    schemeService.dictInfo(projectId, dictProject.groupCode!!, request.type!!)
//                }
                val dictDefFuncBuilder = dictDefFuncId.select(request.filters).filter(SFilter.eq("projectId", projectId),
                    SFilter.eq("groupCode", dictProject.groupCode!!),
                    SFilter.eq("classCode", request.type!!))
                /** 过滤 */
                if (null != request.projection) {
                    dictDefFuncBuilder.projection(request.projection!!)
                }
                /** 排序 */
                if (null != request.orders) {
                    dictDefFuncBuilder.order(request.orders!!)
                }

                /** 去重 */
                if (null != request.distinct && request.distinct!!) {
                    dictDefFuncBuilder.distinct()
                }
                val dictDefFuncList = dictDefFuncBuilder.order("sort").exec()
                sQueryResponse.content = dictDefFuncList
                sQueryResponse.total = dictDefFuncList.size.toLong()
                sQueryResponse.result = SResponseType.success
            }
        }else {
           return  dictDefFuncId.pageQuery(request, arrayListOf(SFilter.eq("projectId", projectId!!)))
        }
        return sQueryResponse
    } // Fun categoryInfoQuery()

    /**
     * 项目定制化设置
     *
     * @param request   字典信息列表
     * @return 返回结果
     */
    fun settingDict(request: SCreateRequest<DefFuncIdProject>): SCreateResponse<DefFuncIdProject> {
        /** 返回对象实例 */
        val sCreateResponse = SCreateResponse<DefFuncIdProject>()
        sCreateResponse.result = SResponseType.failure
       return try {
            /** 数组不为空 */
            if (!request.content.isNullOrEmpty()) {
                /** 遍历字典信息列表 */
                for (dictProject in request.content) {
                    /** 项目id为空重新赋值 */
                    if (dictProject.projectId.isNullOrEmpty()) {
                        dictProject.projectId = Opt.projectId
                    }

                    try {
                        /** 插入字典信息数据 */
                        defFuncIdProjectService.update(dictProject)
                    } catch (e: Exception) {
                        e.printStackTrace()
                    }
                }

                sCreateResponse.result = SResponseType.success
                sCreateResponse.entityList = request.content
                sCreateResponse
            } else {
                sCreateResponse
            }
        } catch (e: Exception) {
            e.printStackTrace()
           sCreateResponse.message = e.message!!
           sCreateResponse
        }
    } // Fun settingDict()

    /**
     * 根据项目下的对象类型重置
     *
     * @param categoryRequest  类型对象
     * @return 返回结果
     */
    fun resetType(categoryRequest: CategoryRequest): SBaseResponse {
        return try {
            /** 项目id */
            val projectId = SPageContext.getHeader("projectId")
            /** 返回结果 */
            val sCreateResponse = SBaseResponse()
            /** 成功状态 */
            sCreateResponse.result = SResponseType.success
            /** 类型不为空 */
            if (!categoryRequest.type.isNullOrEmpty()){
                /** 删除项目下当前类型的信息点 */
                val delete = defFuncIdProjectService.delete(SFilter.eq("classCode", categoryRequest.type!!), SFilter.eq("projectId", projectId!!))
                /** 删除是否失败 */
                if (!delete){
                    /** 失败状态 */
                    sCreateResponse.result = SResponseType.failure
                }
            }else{
                /** 失败状态 */
                sCreateResponse.result = SResponseType.failure
            }

            /** 返回对象 */
            sCreateResponse
        } catch (e: Exception) {
            e.printStackTrace()
            /** 返回对象以及状态，报错信息 */
            SBaseResponse(SResponseType.failure,e.message!!)
        }
    } // Fun resetType()

    /**
     * 根据项目重置信息点
     *
     * @return 返回结果
     */
    fun resetProjectId(): SBaseResponse {
        return try {
            /** 返回结果对象 */
            val sCreateResponse = SBaseResponse()
            /** 项目 id */
            val projectId = SPageContext.getHeader("projectId")
            /** 根据项目 id 删除 */
            val isDelete = defFuncIdProjectService.delete(SFilter.eq("projectId", projectId!!))
            /** 判断删除是否成功 */
            if (isDelete) {
                sCreateResponse.result = SResponseType.success
                sCreateResponse.message = projectId
                sCreateResponse
            } else {
                val sCreateResponse = SBaseResponse()
                sCreateResponse.result = SResponseType.failure
                sCreateResponse.message = projectId
                sCreateResponse
            }
        } catch (e: Exception) {
            e.printStackTrace()
            SBaseResponse(SResponseType.failure, e.message!!)
        }

    } // Fun reset()

    /**
     * 方案设定
     *
     * @param request 条件
     * @return 返回结果
     */
    fun setSchemeProject(request: DictBatchProcessing): SCreateResponse<DictBatchProcessing>{
        val projectId = SPageContext.getHeader("projectId")
        return try {
            if (request.schemeId.isNullOrEmpty()) {
                val sCreateResponse = SCreateResponse<DictBatchProcessing>(SResponseType.failure)
                sCreateResponse.message = "schemeId:不能为空"
                sCreateResponse
            } else {
                val dictProject = dictProjectService.select(SFilter.eq("id", projectId!!)).entity()
                when(request.schemeId){
                    "schemeZero" -> {
                        if (!request.priorityList.isNullOrEmpty() && !request.firstNameList.isNullOrEmpty()) {
                            defFuncIdProjectService.delete(SFilter.eq("projectId",projectId))
                            customMapper.dictSchemeData(projectId,dictProject!!.groupCode!!)
                            val defFuncIdProject = DefFuncIdProject()
                            defFuncIdProject.visible = false
                            defFuncIdProject.projectId = projectId
                            defFuncIdProjectService.update(defFuncIdProject, arrayListOf("visible"),
                                arrayListOf(SFilter.eq("projectId",projectId),SFilter.not(SFilter.eq("unDisabled",false))))
                            /** 一级标签 */
                            for (firstName in request.firstNameList!!) {
                                val propertyDefProjectInfo = DefFuncIdProject()
                                propertyDefProjectInfo.visible = true
                                propertyDefProjectInfo.projectId = projectId
                                defFuncIdProjectService.update(propertyDefProjectInfo, arrayListOf("visible"),
                                    arrayListOf(SFilter.eq("projectId",projectId),SFilter.eq("firstName",firstName)))
                            }
                            /** 匹配优先级 */
                            for (priority in request.priorityList!!) {
                                val propertyDefProjectInfo = DefFuncIdProject()
                                propertyDefProjectInfo.visible = true
                                propertyDefProjectInfo.projectId = projectId
                                defFuncIdProjectService.update(propertyDefProjectInfo, arrayListOf("visible"),
                                    arrayListOf(SFilter.eq("projectId",projectId),SFilter.eq("priority",priority)))
                            }
                        }else if (!request.firstNameList.isNullOrEmpty() && request.firstNameList!!.size > 0) {
                            try {
                                /** 清除项目下的字典信息 */
                                defFuncIdProjectService.delete(SFilter.eq("projectId",projectId))
                                /** 导入原始字典数据 */
                                customMapper.dictSchemeData(projectId,dictProject!!.groupCode!!)
                                val propertyDefProjectInfo = DefFuncIdProject()
                                propertyDefProjectInfo.visible = false
                                propertyDefProjectInfo.projectId = projectId
                                defFuncIdProjectService.update(propertyDefProjectInfo, arrayListOf("visible"),
                                    arrayListOf(SFilter.eq("projectId",projectId), SFilter.not(SFilter.eq("unDisabled",false))))

                                /** 一级标签 */
                                for (firstName in request.firstNameList!!) {
                                    val propertyDefProjectInfo = DefFuncIdProject()
                                    propertyDefProjectInfo.visible = true
                                    propertyDefProjectInfo.projectId = projectId
                                    defFuncIdProjectService.update(propertyDefProjectInfo, arrayListOf("visible"),
                                        arrayListOf(SFilter.eq("projectId",projectId),SFilter.eq("firstName",firstName)))
                                }
                            } catch (e: Exception) {
                                e.printStackTrace()
                            }
                        } else if (!request.priorityList.isNullOrEmpty() && request.priorityList!!.size > 0) {
                            /** 设置优先级 */
                            try {
                                /** 清除项目下的字典信息 */
                                defFuncIdProjectService.delete(SFilter.eq("projectId",projectId))
                                /** 导入原始字典数据 */
                                customMapper.dictSchemeData(projectId,dictProject!!.groupCode!!)
                                val propertyDefProjectInfo = DefFuncIdProject()
                                propertyDefProjectInfo.visible = false
                                propertyDefProjectInfo.projectId = projectId
                                defFuncIdProjectService.update(propertyDefProjectInfo, arrayListOf("visible"),
                                    arrayListOf(SFilter.eq("projectId",projectId), SFilter.not(SFilter.eq("unDisabled",false))))

                                /** 匹配优先级 */
                                for (priority in request.priorityList!!) {
                                    val propertyDefProjectInfo = DefFuncIdProject()
                                    propertyDefProjectInfo.visible = true
                                    propertyDefProjectInfo.projectId = projectId
                                    defFuncIdProjectService.update(propertyDefProjectInfo, arrayListOf("visible"),
                                        arrayListOf(SFilter.eq("projectId",projectId),SFilter.eq("priority",priority)))
                                }
                            } catch (e: Exception) {
                                e.printStackTrace()
                            }
                        } else {
                            /** 清除项目下的字典信息 */
                            defFuncIdProjectService.delete(SFilter.eq("projectId",projectId))
                            /** 导入原始字典数据 */
                            customMapper.dictSchemeData(projectId,dictProject!!.groupCode!!)
                            val propertyDefProjectInfo = DefFuncIdProject()
                            propertyDefProjectInfo.visible = false
                            propertyDefProjectInfo.projectId = projectId
                            defFuncIdProjectService.update(propertyDefProjectInfo, arrayListOf("visible"),
                                arrayListOf(SFilter.eq("projectId",projectId), SFilter.not(SFilter.eq("unDisabled",false))))
                        }
                    }
                    "schemeOne" ->{
                        /** 清除项目下的字典信息 */
                        defFuncIdProjectService.delete(SFilter.eq("projectId",projectId))
                        /** 导入方案1 */
                        customMapper.dictSchemeDataTwo(projectId,dictProject!!.groupCode!!)
                    }
                    "schemeTwo" ->{
                        /** 清除项目下的字典信息 */
                        defFuncIdProjectService.delete(SFilter.eq("projectId",projectId))
                        /** 导入方案1 */
                        customMapper.dictSchemeDataWanDa(projectId,dictProject!!.groupCode!!)
                    }
                }
                SCreateResponse(SResponseType.success)
            }
        } catch (e: Exception) {
            e.printStackTrace()
            SCreateResponse(SResponseType.failure,e.message!!)
        }
    } // Fun setSchemeProject()





} // Object DictDefClassService