/*
 * *********************************************************************************************************************
 *
 *          !!
 *        .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.syn.services.dict

import com.persagy.base.extensions.toJson
import com.persagy.database.SFilter
import com.persagy.mybatis.SMybatisDao
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.dictnew.*
import com.persagy.server.syn.models.api.dict.DictTypeApi
import com.persagy.server.syn.task.SyncTaskDict
import com.persagy.server.datacenter.syn.utils.ParamTools
import com.persagy.service.SBaseService
import com.persagy.service.SObjectService
import com.persagy.service.models.enums.SResponseType
import com.persagy.service.models.responses.SBaseResponse
import org.slf4j.LoggerFactory
import java.util.concurrent.Executors

/**
 * 字典类型
 *
 * @author 张维新  <zhangweixin@sagacloud.cn>
 */
object DClassDefService : SObjectService<DefClass>(SMybatisDao(DefClass::class.java)) {



    /** 日志 */
    val logger = LoggerFactory.getLogger(DClassDefService::class.java)
    /** 集团服务 */
    private val groupService = SBaseService(SMybatisDao(Group::class.java))
    /** 字典项目服务 */
    private val dictProjectService = SBaseService(SMybatisDao(DictProject::class.java))
    /** 字典平台对象类型 */
    private val defClassService = SBaseService(SMybatisDao(DefClass::class.java))
    /** 详细信息点 */
    private val defFuncIdService = SBaseService(SMybatisDao(DefFuncId::class.java))
    /** 专业 */
    private val dictMajorService = SBaseService(SMybatisDao(DictMajor::class.java))
    /** 方案 */
    private val dictSchemeService = SBaseService(SMybatisDao(DictScheme::class.java))
    /** 方案内对象类型 */
    private val dictSchemeCategotyService = SBaseService(SMybatisDao(DictSchemeCategoty::class.java))
    /** 方案内对象包含的信息点 */
    private val dictSchemeCategotyInfoService = SBaseService(SMybatisDao(DictSchemeCategotyInfo::class.java))
    /** 方案内对象包含的信息点 */
    private val dictSchemeAndProjectService = SBaseService(SMybatisDao(DictSchemeAndProject::class.java))
    /** 创建线程池  */
    val executorService = Executors.newFixedThreadPool(20)

    /**
     * 创建字典类型
     */
    fun create() {
        DictTypeApi.dictTypeHttp()

    } //

    /**
     * 查询集团信息
     */
    fun groupQuerys(): SBaseResponse {
        val sBaseResponse = SBaseResponse()
        val groupQueryList = DictTypeApi.groupQuery()
        logger.debug("集团结果:${groupQueryList.toJson()}")
        if (groupQueryList.size > 0) {
//            groupService.deleteAll()
            for (groupQuery in groupQueryList) {
                val group = Group()
                group.id = groupQuery.id
                group.name = groupQuery.name
                group.code = groupQuery.code
                group.createUser = groupQuery.createUser
                group.updateUser = groupQuery.updateUser
                group.remark = groupQuery.remark
                group.status = groupQuery.status
                groupService.replace(group)
            }
        } else {
            sBaseResponse.result = SResponseType.failure
            return sBaseResponse
        }
        sBaseResponse.result = SResponseType.success
        return sBaseResponse
    } // Fun groupQuerys()

    /**
     * 集团下的项目
     */
    fun dictProject(): SBaseResponse {
        val sBaseResponse = SBaseResponse()
        try {
            val selectAllList = groupService.selectAll().exec()
            logger.debug("集团信息:${selectAllList.toJson()}")
            if (!selectAllList.isNullOrEmpty()) {
                for (group in selectAllList) {

                    val dictProjectQueryList = DictTypeApi.dictProjectQuery(group.code!!)
                    if (dictProjectQueryList.size > 0) {
//                        dictProjectService.deleteAll()
                        logger.debug("项目结果:${dictProjectQueryList.toJson()}")
//                        dictProjectService.delete(SFilter.eq("groupCode",group.id!!))
                        for (dictProjectQuery in dictProjectQueryList) {
                            val dictProject = DictProject()
                            dictProject.id = dictProjectQuery.id
                            dictProject.name = dictProjectQuery.name
                            dictProject.groupCode = dictProjectQuery.groupCode
                            dictProject.createUser = dictProjectQuery.createUser
                            dictProject.updateUser = dictProjectQuery.updateUser
                            dictProject.status = dictProjectQuery.status
                            dictProjectService.replace(dictProject)
                        }
                    }
                }
                sBaseResponse.result = SResponseType.success
                return sBaseResponse
            } else {
                sBaseResponse.result = SResponseType.failure
                sBaseResponse.message = "请先获取集团信息"
                return sBaseResponse
            }
        } catch (e: Exception) {
            e.printStackTrace()
            sBaseResponse.result = SResponseType.failure
            return sBaseResponse
        }
    } // Fun dictProject()

    /**
     * 平台字典 对象类型
     */
    fun dictPlatform(): SBaseResponse {
        val sBaseResponse = SBaseResponse()
        val dictPlatformList = DictTypeApi.dictPlatform()
        if (dictPlatformList.size>0){
            defClassService.delete(SFilter.eq("type","common"))
            for (dictPlatform in dictPlatformList){
                val defClass = DefClass()
                defClass.id = dictPlatform.id
                defClass.aliasCode = dictPlatform.aliasCode
                defClass.aliasName = dictPlatform.aliasName
                defClass.code = dictPlatform.code
                defClass.equipmentCode = dictPlatform.equipmentCode
                defClass.groupCode = if (dictPlatform.groupCode.isNullOrEmpty())  "0" else dictPlatform.groupCode
                defClass.majorCode = dictPlatform.majorCode
                defClass.name = dictPlatform.name
                defClass.parentCode = dictPlatform.parentCode
                defClass.projectId = if (dictPlatform.projectId.isNullOrEmpty())  "0" else dictPlatform.projectId
                defClass.systemCode = dictPlatform.systemCode
                defClass.objType = dictPlatform.objType
                defClass.type = "common"
                defClassService.replace(defClass)
            }
            sBaseResponse.result = SResponseType.success
        } else {
            sBaseResponse.result = SResponseType.failure
        }
        return sBaseResponse
    } // fun dictPlatform()

    /**
     * 字典对象的详细信息点
     */
    fun dictPlatformInfo(): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        val defClassList = defClassService.select(SFilter.eq("type", "common")).exec()
        if (defClassList.size>0){
//            defFuncIdService.delete(SFilter.eq("groupId", "0"))
            for (defClass in defClassList){
                val dictPlatformInfoList = DictTypeApi.dictPlatformInfo(defClass.code!!, defClass.type!!)
                defFuncIdService.delete(SFilter.eq("classCode", defClass.code!!),SFilter.eq("groupCode", "0"))
                if (!dictPlatformInfoList.isNullOrEmpty()){
                    for (dictPlatformInfo in dictPlatformInfoList){
                        /** 开头字母大写转小写 */
//                        val str1: String = dictPlatformInfo.code!!.substring(0, 1).toLowerCase() //直接bai将du字符zhi串第一个不管是数字还是字母都小写
//                        val str2: String = dictPlatformInfo.code!!.substring(1, dictPlatformInfo.code!!.length) //截取字符串第二个以后
//                        var str=str1+str2
                        val defFuncId = DefFuncId()
                        defFuncId.canSub = dictPlatformInfo.canSub
                        defFuncId.category = dictPlatformInfo.category
                        defFuncId.classCode = defClass.code
                        if (dictPlatformInfo.code == "equipLocalID"){
                            defFuncId.code = "localId"
                        }else if (dictPlatformInfo.code == "equipLocalName"){
                            defFuncId.code = "localName"
                        }else if (dictPlatformInfo.code == "sysLocalID"){
                            defFuncId.code = "localId"
                        }else if (dictPlatformInfo.code == "sysLocalName"){
                            defFuncId.code = "localName"
                        }else if (dictPlatformInfo.code == "tenantLocalID"){
                            defFuncId.code = "localId"
                        }else if (dictPlatformInfo.code =="tenantLocalName"){
                            defFuncId.code = "localName"
                        }else if (dictPlatformInfo.code == "roomLocalID"){
                            defFuncId.code = "localId"
                        }else if (dictPlatformInfo.code == "roomLocalName"){
                            defFuncId.code = "localName"
                        }else if (dictPlatformInfo.code == "shaftLocalID"){
                            defFuncId.code = "localId"
                        }else if (dictPlatformInfo.code == "shaftLocalName"){
                            defFuncId.code = "localName"
                        }else if (dictPlatformInfo.code == "shaftID"){
                            defFuncId.code = "id"
                        }else if (dictPlatformInfo.code == "shaftName"){
                            defFuncId.code = "name"
                        }else if (dictPlatformInfo.code == "equipID"){
                            defFuncId.code = "id"
                        }else if (dictPlatformInfo.code == "equipName"){
                            defFuncId.code = "name"
                        }else if (dictPlatformInfo.code == "sysID"){
                            defFuncId.code = "id"
                        }else if (dictPlatformInfo.code == "sysName"){
                            defFuncId.code = "name"
                        }else if (dictPlatformInfo.code == "tenantID"){
                            defFuncId.code = "id"
                        }else if (dictPlatformInfo.code == "tenantName"){
                            defFuncId.code = "name"
                        }else if (dictPlatformInfo.code == "roomID"){
                            defFuncId.code = "id"
                        }else if (dictPlatformInfo.code == "roomName"){
                            defFuncId.code = "name"
                        }else if (dictPlatformInfo.code == "projID"){
                            defFuncId.code = "id"
                        }else if (dictPlatformInfo.code == "projName"){
                            defFuncId.code = "name"
                        }else if (dictPlatformInfo.code == "projLocalName"){
                            defFuncId.code = "localId"
                        }else if (dictPlatformInfo.code == "projLocalName"){
                            defFuncId.code = "localName"
                        }else if (dictPlatformInfo.code == "flootID"){
                            defFuncId.code = "id"
                        }else if (dictPlatformInfo.code == "flootName"){
                            defFuncId.code = "name"
                        }else if (dictPlatformInfo.code == "floorLocalName"){
                            defFuncId.code = "localId"
                        }else if (dictPlatformInfo.code == "floorLocalName"){
                            defFuncId.code = "localName"
                        }else if (dictPlatformInfo.code == "buildID"){
                            defFuncId.code = "id"
                        }else if (dictPlatformInfo.code == "buildName"){
                            defFuncId.code = "name"
                        }else if (dictPlatformInfo.code == "buildLocalID"){
                            defFuncId.code = "localId"
                        }else if (dictPlatformInfo.code == "buildLocalName"){
                            defFuncId.code = "localName"
                        }else{
                            defFuncId.code = dictPlatformInfo.code
                        }

                        defFuncId.id = dictPlatformInfo.id
//                        defFuncId.code = dictPlatformInfo.code
                        defFuncId.dataSource = dictPlatformInfo.dataSource
                        logger.debug("数据= ${dictPlatformInfo.dataSource?.toJson()}")
                        defFuncId.dataType = dictPlatformInfo.dataType
                        defFuncId.firstName = dictPlatformInfo.firstTag
                        if (!dictPlatformInfo.firstTag.isNullOrEmpty()){
                            defFuncId.firstTag = ParamTools.TwoLevelCode(dictPlatformInfo.firstTag!!)
                        }
                        defFuncId.formater = dictPlatformInfo.formater
                        defFuncId.groupCode = if (dictPlatformInfo.groupCode.isNullOrEmpty()) "0" else dictPlatformInfo.groupCode
                        defFuncId.idx = dictPlatformInfo.idx
                        defFuncId.inputMode = dictPlatformInfo.inputMode
                        defFuncId.isMultiple = dictPlatformInfo.isMultiple
                        defFuncId.isRegion = dictPlatformInfo.isRegion
                        defFuncId.name = dictPlatformInfo.name
                        defFuncId.note = dictPlatformInfo.note
                        defFuncId.priority = dictPlatformInfo.priority
                        defFuncId.projectId = if (dictPlatformInfo.projectId.isNullOrEmpty()) "0" else dictPlatformInfo.projectId
                        defFuncId.readonly = dictPlatformInfo.readonly
                        defFuncId.secondName = dictPlatformInfo.secondTag
                        if (!dictPlatformInfo.secondTag.isNullOrEmpty()){
                            defFuncId.secondTag = ParamTools.TwoLevelCode(dictPlatformInfo.secondTag!!)
                        }
                        defFuncId.subFlag = dictPlatformInfo.subFlag
                        defFuncId.type = dictPlatformInfo.type
                        defFuncId.unit = dictPlatformInfo.unit
                        defFuncId.origCode = dictPlatformInfo.origCode
                        defFuncId.origDataType = dictPlatformInfo.origDataType
                        defFuncId.aliasCode = dictPlatformInfo.aliasCode
                        defFuncId.aliasName = dictPlatformInfo.aliasName
                        if (!defFuncId.name.isNullOrEmpty()){
                            /** 排序 */
                            if (defFuncId.name!! == "设备本地编码"||defFuncId.name!! == "楼层本地编码"){
                                defFuncId.sort = 2
                            }else if (defFuncId.name!! == "设备本地名称"|| defFuncId.name!! == "楼层本地名称"){
                                defFuncId.sort = 1
                            }else if (defFuncId.name!! == "设备二维码图片"){
                                defFuncId.sort = 3
                            }else if (defFuncId.name!! == "设计图纸中编码"){
                                defFuncId.sort = 4
                            }else if (defFuncId.name!! == "设备ID"){
                                defFuncId.sort = 101
                            }else if (defFuncId.name!! == "设备名称"){
                                defFuncId.sort = 102
                            }else if (defFuncId.name!! == "BIM模型中编码"){
                                defFuncId.sort = 103
                            }else if (defFuncId.name!! == "BIM模型中坐标"){
                                defFuncId.sort = 104
                            }else if (defFuncId.firstName != null&& defFuncId.firstName == "台账参数"){
                                defFuncId.sort = 10
                            }else if(defFuncId.firstName != null&& defFuncId.firstName == "通讯参数"){
                                defFuncId.sort = 20
                            }else {
                                defFuncId.sort = 60
                            }
                        }

                        val dicConfigureEditable = ParamTools.dicConfigureEditable()
                        val containsKey = dicConfigureEditable.containsKey(defFuncId.code!!)
                        if (containsKey){
                            defFuncId.editable = false
                            defFuncId.unDisabled = false
                            defFuncId.visible = false
                        }


                        val dicConfigure = ParamTools.dicConfigure()
                        if (defFuncId.code!=null){
                            val containsKey = dicConfigure.containsKey(defFuncId.code!!)
                            if (containsKey){
                                defFuncId.editable = true
                                defFuncId.unDisabled = false
                                defFuncId.visible = true
                            }
                        }

                        defFuncIdService.replace(defFuncId)
                    }
                }
            }
            sBaseResponse.result = SResponseType.success
        } else {
            sBaseResponse.result = SResponseType.failure
        }
        return sBaseResponse
    } // Fun dictPlatformInfo()

    /**
     * 专业
     */
    fun dictMajor(): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        val dictMajorList = DictTypeApi.dictMajor("major")
        dictMajorService.delete(SFilter.eq("type","major"))
        if (dictMajorList.size>0){
            for (dictMajor in dictMajorList){

                val dictMajor1 = DictMajor()
                dictMajor1.aliasCode = dictMajor.code
                dictMajor1.aliasName = dictMajor.label
                dictMajor1.code = dictMajor.code
                dictMajor1.groupCode = dictMajor.groupId
                dictMajor1.id = dictMajor.id
                dictMajor1.name = dictMajor.label
                dictMajor1.note = dictMajor.note
                dictMajor1.type = dictMajor.type
                dictMajorService.insert(dictMajor1)
            }
            sBaseResponse.result = SResponseType.success
        } else {
            sBaseResponse.result = SResponseType.failure
        }
        return  sBaseResponse
    } // Fun dictMajor()

    /**
     * 集团下的方案
     */
    fun dictGroupScheme(): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        val groupList = groupService.selectAll().exec()
        if (groupList.size>0){

            for (group in groupList){
                dictSchemeService.delete(SFilter.eq("groupCode",group.id!!))
                val dictGroupSchemeList = DictTypeApi.dictGroupScheme(group.id!!)
                if (dictGroupSchemeList.size>0){
                    for (dictGroupScheme in dictGroupSchemeList){
                        val dictScheme = DictScheme()
                        dictScheme.groupId = dictGroupScheme.groupId
                        dictScheme.id = dictGroupScheme.id
                        dictScheme.name = dictGroupScheme.name
                        dictScheme.note = dictGroupScheme.note
                        dictSchemeService.insert(dictScheme)
                    }
                }
            }
            sBaseResponse.result = SResponseType.success
        } else {
            sBaseResponse.result = SResponseType.failure
        }
        return  sBaseResponse
    } // Fun dictGroupScheme()

    /**
     * 方案下的对象类型
     */
    fun dictSchemeCategoty(): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        val dictSchemeList = dictSchemeService.selectAll().exec()
        if (dictSchemeList.size>0){
            for (dictScheme in dictSchemeList){

                val dictSchemeCategotyList = DictTypeApi.dictSchemeCategoty(dictScheme.id!!)
                if (dictSchemeCategotyList.size>0){
                    dictSchemeCategotyService.delete(SFilter.eq("schemeId",dictScheme.id!!))
                    for (dictSchemeCategoty in dictSchemeCategotyList){
                        val dictSchemeCategoty1 = DictSchemeCategoty()
                        dictSchemeCategoty1.classCode = dictSchemeCategoty.classCode
                        dictSchemeCategoty1.id = dictSchemeCategoty.id
                        dictSchemeCategoty1.schemeId = dictSchemeCategoty.schemeId
                        dictSchemeCategotyService.replace(dictSchemeCategoty1)
                    }
                }
            }
            sBaseResponse.result = SResponseType.success
        } else {
            sBaseResponse.result = SResponseType.failure
        }
        return  sBaseResponse
    } // Fun dictSchemeCategoty()

    /**
     * 方案下的对象的信息点
     */
    fun dictSchemeCategotyInfo(): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        val dictSchemeCategotyList = dictSchemeCategotyService.selectAll().exec()
        if (dictSchemeCategotyList.size>0){
            for (dictSchemeCategoty in dictSchemeCategotyList){
                val dictSchemeCategotyInfoList =
                    DictTypeApi.dictSchemeCategotyInfo(dictSchemeCategoty.schemeId!!, dictSchemeCategoty.classCode!!)
                dictSchemeCategotyInfoService.delete(SFilter.eq("schemeId",dictSchemeCategoty.schemeId!!),SFilter.eq("classCode",dictSchemeCategoty.classCode!!))
                if (dictSchemeCategotyInfoList.size>0){
                    for (dictSchemeCategotyInfo in dictSchemeCategotyInfoList){
                        val dictSchemeCategotyInfo1 = DictSchemeCategotyInfo()
                        dictSchemeCategotyInfo1.classCode = dictSchemeCategotyInfo.classCode
                        dictSchemeCategotyInfo1.id = dictSchemeCategotyInfo.id
                        dictSchemeCategotyInfo1.infoCode = dictSchemeCategotyInfo.infoCode
                        dictSchemeCategotyInfo1.schemeId = dictSchemeCategotyInfo.schemeId
                        dictSchemeCategotyInfoService.insert(dictSchemeCategotyInfo1)
                    }
                }
            }
            sBaseResponse.result = SResponseType.success
        } else {
            sBaseResponse.result = SResponseType.failure
        }
        return  sBaseResponse
    } // Fun dictSchemeCategotyInfo()

    /**
     * 查询项目和方案的关系
     */
    fun dictSchemeAndProject(): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        val dictProjectList = dictProjectService.selectAll().exec()
        if (dictProjectList.size>0){
            dictSchemeAndProjectService.deleteAll()
            for (dictProject in dictProjectList){
                val dictSchemeAndProjectList = DictTypeApi.dictSchemeAndProject(dictProject.id!!)
                if (dictSchemeAndProjectList.size>0){
                    for (dictScheme in dictSchemeAndProjectList){
                        val dictSchemeAndProject = DictSchemeAndProject()
                        dictSchemeAndProject.id = dictScheme.id
                        dictSchemeAndProject.projectId = dictScheme.projectId
                        dictSchemeAndProject.schemeId = dictScheme.schemeId
                        dictSchemeAndProjectService.insert(dictSchemeAndProject)
                    }
                }
            }
            sBaseResponse.result = SResponseType.success
        } else {
            sBaseResponse.result = SResponseType.failure
        }
        return  sBaseResponse
    } // Fun dictSchemeAndProject()

    /**
     * 集团下的对象类型
     */
    fun dictGroup(): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        val groupList = groupService.selectAll().exec()
        if (groupList.size>0){
            for (group in groupList){
                val dictGroupList = DictTypeApi.dictGroup(group.code!!)
                if (dictGroupList.size>0){
                    defClassService.delete(SFilter.eq("type","group"),SFilter.eq("groupCode",group.code!!),SFilter.eq("projectId","0"))
                    for (dictGroup in dictGroupList){
                        val defClass = DefClass()
                        defClass.id = dictGroup.id
                        defClass.aliasCode = dictGroup.aliasCode
                        defClass.aliasName = dictGroup.aliasName
                        defClass.code = dictGroup.code
                        defClass.equipmentCode = dictGroup.equipmentCode
                        defClass.groupCode = group.code
                        defClass.majorCode = dictGroup.majorCode
                        defClass.name = dictGroup.name
                        defClass.parentCode = dictGroup.parentCode
                        defClass.projectId = "0"
                        defClass.systemCode = dictGroup.systemCode
                        defClass.type = "group"
                        defClass.objType = dictGroup.objType
                        defClassService.replace(defClass)
                    }
                }
            }
            sBaseResponse.result = SResponseType.success
        }else{
            sBaseResponse.result = SResponseType.failure
        }
        return sBaseResponse
    } // Fun

    /**
     * 集团下对象信息点
     */
    fun dictGroupInfo(): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        val defClassList = defClassService.select(SFilter.eq("type", "group")).exec()
        if (defClassList.size>0){


            val groupList = groupService.selectAll().exec()
            if (groupList.size>0){
                for (group in groupList){
                    for (defClass in defClassList){
                        val dictGroupInfoList = DictTypeApi.dictGroupInfo(group.code!!, defClass.code!!)
                        defFuncIdService.delete(SFilter.eq("groupCode",group.code!!),SFilter.eq("classCode",defClass.code!!),SFilter.eq("projectId","0"))
                        if (dictGroupInfoList.size>0){
                            for (dictGroupInfo in dictGroupInfoList){
                                /** 开头字母大写转小写 */
                                val str1: String = dictGroupInfo.code!!.substring(0, 1).toLowerCase() //直接bai将du字符zhi串第一个不管是数字还是字母都小写
                                val str2: String = dictGroupInfo.code!!.substring(1, dictGroupInfo.code!!.length) //截取字符串第二个以后
                                var str=str1+str2;
                                val defFuncId = DefFuncId()

                                if (str == "equipLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "equipLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "sysLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "sysLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "tenantLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str =="tenantLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "roomLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "roomLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "shaftLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "shaftLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "shaftID"){
                                    defFuncId.code = "id"
                                }else if (str == "shaftName"){
                                    defFuncId.code = "name"
                                }else if (str == "equipID"){
                                    defFuncId.code = "id"
                                }else if (str == "equipName"){
                                    defFuncId.code = "name"
                                }else if (str == "sysID"){
                                    defFuncId.code = "id"
                                }else if (str == "sysName"){
                                    defFuncId.code = "name"
                                }else if (str == "tenantID"){
                                    defFuncId.code = "id"
                                }else if (str == "tenantName"){
                                    defFuncId.code = "name"
                                }else if (str == "roomID"){
                                    defFuncId.code = "id"
                                }else if (str == "roomName"){
                                    defFuncId.code = "name"
                                }else if (str == "projID"){
                                    defFuncId.code = "id"
                                }else if (str == "projName"){
                                    defFuncId.code = "name"
                                }else if (str == "projLocalName"){
                                    defFuncId.code = "localId"
                                }else if (str == "projLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "flootID"){
                                    defFuncId.code = "id"
                                }else if (str == "flootName"){
                                    defFuncId.code = "name"
                                }else if (str == "floorLocalName"){
                                    defFuncId.code = "localId"
                                }else if (str == "floorLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "buildID"){
                                    defFuncId.code = "id"
                                }else if (str == "buildName"){
                                    defFuncId.code = "name"
                                }else if (str == "buildLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "buildLocalName"){
                                    defFuncId.code = "localName"
                                }else{
                                    defFuncId.code = str
                                }
                                defFuncId.code = dictGroupInfo.code
                                defFuncId.id = dictGroupInfo.id
                                defFuncId.canSub = dictGroupInfo.canSub
                                defFuncId.category = dictGroupInfo.category
                                defFuncId.classCode = defClass.code
//                        defFuncId.code = str
                                defFuncId.dataSource = dictGroupInfo.dataSource
                                defFuncId.dataType = dictGroupInfo.dataType
                                if (!dictGroupInfo.firstTag.isNullOrEmpty()){
                                    defFuncId.firstTag = ParamTools.TwoLevelCode(dictGroupInfo.firstTag!!)
                                }
                                defFuncId.firstName = dictGroupInfo.firstTag
                                defFuncId.formater = dictGroupInfo.formater
                                defFuncId.groupCode = group.code
                                defFuncId.idx = dictGroupInfo.idx
                                defFuncId.inputMode = dictGroupInfo.inputMode
                                defFuncId.isMultiple = dictGroupInfo.isMultiple
                                defFuncId.isRegion = dictGroupInfo.isRegion
                                defFuncId.name = dictGroupInfo.name
                                logger.debug("name: ${ dictGroupInfo.name} *******************************************************")
                                defFuncId.note = dictGroupInfo.note
                                defFuncId.priority = dictGroupInfo.priority
                                defFuncId.projectId = if (dictGroupInfo.projectId.isNullOrEmpty()) "0" else dictGroupInfo.projectId
                                defFuncId.readonly = dictGroupInfo.readonly
                                if (!dictGroupInfo.secondTag.isNullOrEmpty()){
                                    defFuncId.secondTag = ParamTools.TwoLevelCode(dictGroupInfo.secondTag!!)
                                }
                                defFuncId.secondName = dictGroupInfo.secondTag
                                defFuncId.subFlag = dictGroupInfo.subFlag
                                defFuncId.type = "group"
                                defFuncId.unit = dictGroupInfo.unit
                                defFuncId.origCode = dictGroupInfo.origCode
                                defFuncId.origDataType = dictGroupInfo.origDataType
                                defFuncId.aliasCode = dictGroupInfo.aliasCode
                                defFuncId.aliasName = dictGroupInfo.aliasName

                                if (!defFuncId.name.isNullOrEmpty()){
                                    /** 排序 */
                                    if (defFuncId.name!! == "设备本地编码"||defFuncId.name!! == "楼层本地编码"||defFuncId.name!! == "本地编码"){
                                        defFuncId.sort = 2
                                    }else if (defFuncId.name!! == "设备本地名称"|| defFuncId.name!! == "楼层本地名称"||defFuncId.name!! == "本地名称"){
                                        defFuncId.sort = 1
                                    }else if (defFuncId.name!! == "设备二维码图片"||defFuncId.name!! == "二维码图片"||defFuncId.name!! == "二维码内容"){
                                        defFuncId.sort = 3
                                    }else if (defFuncId.name!! == "设计图纸中编码"){
                                        defFuncId.sort = 4
                                    }else if (defFuncId.name!! == "设备ID"||defFuncId.name!! =="编码"){
                                        defFuncId.sort = 101
                                    }else if (defFuncId.name!! == "设备名称"||defFuncId.name!! =="名称"){
                                        defFuncId.sort = 102
                                    }else if (defFuncId.name!! == "BIM模型中编码"){
                                        defFuncId.sort = 103
                                    }else if (defFuncId.name!! == "BIM模型中坐标"){
                                        defFuncId.sort = 104
                                    }else if (defFuncId.firstName != null&& defFuncId.firstName == "台账参数"){
                                        defFuncId.sort = 10
                                    }else if(defFuncId.firstName != null&& defFuncId.firstName == "通讯参数"){
                                        defFuncId.sort = 20
                                    }else {
                                        defFuncId.sort = 60
                                    }
                                }

                                val dicConfigureEditable = ParamTools.dicConfigureEditable()
                                val containsKey = dicConfigureEditable.containsKey(defFuncId.code!!)
                                if (containsKey){
                                    defFuncId.editable = false
                                    defFuncId.unDisabled = false
                                    defFuncId.visible = false
                                }

                                val dicConfigure = ParamTools.dicConfigure()
                                if (defFuncId.code!=null){
                                    val containsKey = dicConfigure.containsKey(defFuncId.code!!)
                                    if (containsKey){
                                        defFuncId.editable = true
                                        defFuncId.unDisabled = false
                                        defFuncId.visible = true
                                    }
                                }

                                defFuncIdService.replace(defFuncId)
                            }
                        }
                    }
                }
                sBaseResponse.result = SResponseType.success
            }else{
                sBaseResponse.result = SResponseType.failure
            }
        }else{
            sBaseResponse.result = SResponseType.failure
        }
        return sBaseResponse
    }

    /**
     * 项目下的对象类型
     */
    fun dictProjectType(projectId: String?): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        if (!projectId.isNullOrEmpty()) {
            val project = dictProjectService.select(SFilter.eq("id", projectId)).entity()
            val dictGroupList = DictTypeApi.dictProject(project!!.groupCode!!,project.id!!)
            if (dictGroupList.size>0){
                defClassService.delete(SFilter.eq("type","project"),SFilter.eq("groupCode",project.groupCode!!),SFilter.eq("projectId",project.id!!))
                for (dictGroup in dictGroupList){
                    val defClass = DefClass()
                    defClass.id = dictGroup.id
                    defClass.aliasCode = dictGroup.aliasCode
                    defClass.aliasName = dictGroup.aliasName
                    defClass.code = dictGroup.code
                    defClass.equipmentCode = dictGroup.equipmentCode
                    defClass.groupCode = project.groupCode
                    defClass.majorCode = dictGroup.majorCode
                    defClass.name = dictGroup.name
                    defClass.parentCode = dictGroup.parentCode
                    defClass.projectId = project.id
                    defClass.systemCode = dictGroup.systemCode
                    defClass.type = "project"
                    defClass.objType = dictGroup.objType
                    defClassService.replace(defClass)
                }
            }
            sBaseResponse.result = SResponseType.success
        } else {

        val dictProjectList = dictProjectService.selectAll().exec()
        if (dictProjectList.size>0){
            for (project in dictProjectList){
                val dictGroupList = DictTypeApi.dictProject(project.groupCode!!,project.id!!)
                if (dictGroupList.size>0){
                    defClassService.delete(SFilter.eq("type","project"),SFilter.eq("groupCode",project.groupCode!!),SFilter.eq("projectId",project.id!!))
                    for (dictGroup in dictGroupList){
                        val defClass = DefClass()
                        defClass.id = dictGroup.id
                        defClass.aliasCode = dictGroup.aliasCode
                        defClass.aliasName = dictGroup.aliasName
                        defClass.code = dictGroup.code
                        defClass.equipmentCode = dictGroup.equipmentCode
                        defClass.groupCode = project.groupCode
                        defClass.majorCode = dictGroup.majorCode
                        defClass.name = dictGroup.name
                        defClass.parentCode = dictGroup.parentCode
                        defClass.projectId = project.id
                        defClass.systemCode = dictGroup.systemCode
                        defClass.type = "project"
                        defClass.objType = dictGroup.objType
                        defClassService.replace(defClass)
                    }
                }
            }
            sBaseResponse.result = SResponseType.success
        }else{
            sBaseResponse.result = SResponseType.failure
        }
        }
        return sBaseResponse
    } // Fun

    /**
     * 项目下的对象类型
     */
    fun dictProjectTypeId(projectId: String): SBaseResponse{
        val sBaseResponse = SBaseResponse()
        val dictProject = dictProjectService.select(SFilter.eq("id",projectId)).entity()
        if (dictProject!=null){

            val dictGroupList = DictTypeApi.dictProject(dictProject.groupCode!!,projectId)
            if (dictGroupList.size>0){
                defClassService.delete(SFilter.eq("type","project"),SFilter.eq("groupCode",dictProject.groupCode!!),SFilter.eq("projectId",projectId))
                for (dictGroup in dictGroupList){
                    val defClass = DefClass()
                    defClass.id = dictGroup.id
                    defClass.aliasCode = dictGroup.aliasCode
                    defClass.aliasName = dictGroup.aliasName
                    defClass.code = dictGroup.code
                    defClass.equipmentCode = dictGroup.equipmentCode
                    defClass.groupCode = dictProject.groupCode
                    defClass.majorCode = dictGroup.majorCode
                    defClass.name = dictGroup.name
                    defClass.parentCode = dictGroup.parentCode
                    defClass.projectId = projectId
                    defClass.systemCode = dictGroup.systemCode
                    defClass.type = "project"
                    defClass.objType = dictGroup.objType
                    defClassService.replace(defClass)
                }
            }

            sBaseResponse.result = SResponseType.success
        }else{
            sBaseResponse.result = SResponseType.failure
        }
        return sBaseResponse
    } // Fun



    /**
     * 项目下对象信息点
     */
    fun dictProjectInfo(projectId: String): SBaseResponse {
        val sBaseResponse = SBaseResponse()

        val defClassList = defClassService.select(SFilter.eq("projectId", projectId)).exec()
        if (defClassList.size>0){
            val dictProject = dictProjectService.select(SFilter.eq("id", projectId)).entity()
//            val groupList = groupService.selectAll().exec()
            if (dictProject!=null){
//                for (group in groupList){

                    for (defClass in defClassList){
                        val dictGroupInfoList = DictTypeApi.dictProjectInfo(dictProject.groupCode!!, defClass.code!!,projectId)

                        if (dictGroupInfoList.size>0){
                            defFuncIdService.delete(SFilter.eq("projectId",projectId!!),SFilter.eq("classCode",defClass.code!!))
                            for (dictGroupInfo in dictGroupInfoList){
                                /** 开头字母大写转小写 */
                                val str1: String = dictGroupInfo.code!!.substring(0, 1).toLowerCase() //直接bai将du字符zhi串第一个不管是数字还是字母都小写
                                val str2: String = dictGroupInfo.code!!.substring(1, dictGroupInfo.code!!.length) //截取字符串第二个以后
                                var str=str1+str2;
                                val defFuncId = DefFuncId()

                                if (str == "equipLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "equipLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "sysLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "sysLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "tenantLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str =="tenantLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "roomLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "roomLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "shaftLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "shaftLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "shaftID"){
                                    defFuncId.code = "id"
                                }else if (str == "shaftName"){
                                    defFuncId.code = "name"
                                }else if (str == "equipID"){
                                    defFuncId.code = "id"
                                }else if (str == "equipName"){
                                    defFuncId.code = "name"
                                }else if (str == "sysID"){
                                    defFuncId.code = "id"
                                }else if (str == "sysName"){
                                    defFuncId.code = "name"
                                }else if (str == "tenantID"){
                                    defFuncId.code = "id"
                                }else if (str == "tenantName"){
                                    defFuncId.code = "name"
                                }else if (str == "roomID"){
                                    defFuncId.code = "id"
                                }else if (str == "roomName"){
                                    defFuncId.code = "name"
                                }else if (str == "projID"){
                                    defFuncId.code = "id"
                                }else if (str == "projName"){
                                    defFuncId.code = "name"
                                }else if (str == "projLocalName"){
                                    defFuncId.code = "localId"
                                }else if (str == "projLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "flootID"){
                                    defFuncId.code = "id"
                                }else if (str == "flootName"){
                                    defFuncId.code = "name"
                                }else if (str == "floorLocalName"){
                                    defFuncId.code = "localId"
                                }else if (str == "floorLocalName"){
                                    defFuncId.code = "localName"
                                }else if (str == "buildID"){
                                    defFuncId.code = "id"
                                }else if (str == "buildName"){
                                    defFuncId.code = "name"
                                }else if (str == "buildLocalID"){
                                    defFuncId.code = "localId"
                                }else if (str == "buildLocalName"){
                                    defFuncId.code = "localName"
                                }else{
                                    defFuncId.code = str
                                }
                                defFuncId.code = dictGroupInfo.code
                                defFuncId.id = dictGroupInfo.id
                                defFuncId.canSub = dictGroupInfo.canSub
                                defFuncId.category = dictGroupInfo.category
                                defFuncId.classCode = defClass.code
//                        defFuncId.code = str
                                defFuncId.dataSource = dictGroupInfo.dataSource
                                logger.debug("数据001 = ${dictGroupInfo.dataSource?.toJson()} ***********************************************************")
                                defFuncId.dataType = dictGroupInfo.dataType
                                if (!dictGroupInfo.firstTag.isNullOrEmpty()){
                                    defFuncId.firstTag = ParamTools.TwoLevelCode(dictGroupInfo.firstTag!!)
                                }
                                defFuncId.firstName = dictGroupInfo.firstTag
                                defFuncId.formater = dictGroupInfo.formater
                                defFuncId.groupCode = dictProject.groupCode
                                defFuncId.idx = dictGroupInfo.idx
                                defFuncId.inputMode = dictGroupInfo.inputMode
                                defFuncId.isMultiple = dictGroupInfo.isMultiple
                                defFuncId.isRegion = dictGroupInfo.isRegion
                                defFuncId.name = dictGroupInfo.name
                                logger.debug("name: ${ dictGroupInfo.name} *******************************************************")
                                defFuncId.note = dictGroupInfo.note
                                defFuncId.priority = dictGroupInfo.priority
                                defFuncId.projectId = projectId
                                defFuncId.readonly = dictGroupInfo.readonly
                                if (!dictGroupInfo.secondTag.isNullOrEmpty()){
                                    defFuncId.secondTag = ParamTools.TwoLevelCode(dictGroupInfo.secondTag!!)
                                }
                                defFuncId.secondName = dictGroupInfo.secondTag
                                defFuncId.subFlag = dictGroupInfo.subFlag
                                defFuncId.type = "project"
                                defFuncId.unit = dictGroupInfo.unit
                                defFuncId.origCode = dictGroupInfo.origCode
                                defFuncId.origDataType = dictGroupInfo.origDataType
                                defFuncId.aliasCode = dictGroupInfo.aliasCode
                                defFuncId.aliasName = dictGroupInfo.aliasName

                                if (!defFuncId.name.isNullOrEmpty()){
                                    /** 排序 */
                                    if (defFuncId.name!! == "设备本地编码"||defFuncId.name!! == "楼层本地编码"||defFuncId.name!! == "本地编码"){
                                        defFuncId.sort = 2
                                    }else if (defFuncId.name!! == "设备本地名称"|| defFuncId.name!! == "楼层本地名称"||defFuncId.name!! == "本地名称"){
                                        defFuncId.sort = 1
                                    }else if (defFuncId.name!! == "设备二维码图片"||defFuncId.name!! == "二维码图片"||defFuncId.name!! == "二维码内容"){
                                        defFuncId.sort = 3
                                    }else if (defFuncId.name!! == "设计图纸中编码"){
                                        defFuncId.sort = 4
                                    }else if (defFuncId.name!! == "设备ID"||defFuncId.name!! =="编码"){
                                        defFuncId.sort = 101
                                    }else if (defFuncId.name!! == "设备名称"||defFuncId.name!! =="名称"){
                                        defFuncId.sort = 102
                                    }else if (defFuncId.name!! == "BIM模型中编码"){
                                        defFuncId.sort = 103
                                    }else if (defFuncId.name!! == "BIM模型中坐标"){
                                        defFuncId.sort = 104
                                    }else if (defFuncId.firstName != null&& defFuncId.firstName == "台账参数"){
                                        defFuncId.sort = 10
                                    }else if(defFuncId.firstName != null&& defFuncId.firstName == "通讯参数"){
                                        defFuncId.sort = 20
                                    }else {
                                        defFuncId.sort = 60
                                    }
                                }

                                val dicConfigureEditable = ParamTools.dicConfigureEditable()
                                val containsKey = dicConfigureEditable.containsKey(defFuncId.code!!)
                                if (containsKey){
                                    defFuncId.editable = false
                                    defFuncId.unDisabled = false
                                    defFuncId.visible = false
                                }

                                val dicConfigure = ParamTools.dicConfigure()
                                if (defFuncId.code!=null){
                                    val containsKey = dicConfigure.containsKey(defFuncId.code!!)
                                    if (containsKey){
                                        defFuncId.editable = true
                                        defFuncId.unDisabled = false
                                        defFuncId.visible = true
                                    }
                                }

                                defFuncIdService.replace(defFuncId)
                            }
                        }
                    }
//                }
                sBaseResponse.result = SResponseType.success
            }else{
                sBaseResponse.result = SResponseType.failure
            }
        }else{
            sBaseResponse.result = SResponseType.failure
        }
        return sBaseResponse
    }

    /**
     * 项目下对象信息点
     */
    fun dictProjectInfoType(groupCode: String, projectId: String,type: String): SBaseResponse {
        val sBaseResponse = SBaseResponse()

        val dictGroupInfoList = DictTypeApi.dictProjectInfo(groupCode!!, type,projectId)
        defFuncIdService.delete(SFilter.eq("projectId",projectId),SFilter.eq("classCode",type))
        if (dictGroupInfoList.size>0){
            for (dictGroupInfo in dictGroupInfoList){
                /** 开头字母大写转小写 */
                val str1: String = dictGroupInfo.code!!.substring(0, 1).toLowerCase() //直接bai将du字符zhi串第一个不管是数字还是字母都小写
                val str2: String = dictGroupInfo.code!!.substring(1, dictGroupInfo.code!!.length) //截取字符串第二个以后
                var str=str1+str2;
                val defFuncId = DefFuncId()

                if (str == "equipLocalID"){
                    defFuncId.code = "localId"
                }else if (str == "equipLocalName"){
                    defFuncId.code = "localName"
                }else if (str == "sysLocalID"){
                    defFuncId.code = "localId"
                }else if (str == "sysLocalName"){
                    defFuncId.code = "localName"
                }else if (str == "tenantLocalID"){
                    defFuncId.code = "localId"
                }else if (str =="tenantLocalName"){
                    defFuncId.code = "localName"
                }else if (str == "roomLocalID"){
                    defFuncId.code = "localId"
                }else if (str == "roomLocalName"){
                    defFuncId.code = "localName"
                }else if (str == "shaftLocalID"){
                    defFuncId.code = "localId"
                }else if (str == "shaftLocalName"){
                    defFuncId.code = "localName"
                }else if (str == "shaftID"){
                    defFuncId.code = "id"
                }else if (str == "shaftName"){
                    defFuncId.code = "name"
                }else if (str == "equipID"){
                    defFuncId.code = "id"
                }else if (str == "equipName"){
                    defFuncId.code = "name"
                }else if (str == "sysID"){
                    defFuncId.code = "id"
                }else if (str == "sysName"){
                    defFuncId.code = "name"
                }else if (str == "tenantID"){
                    defFuncId.code = "id"
                }else if (str == "tenantName"){
                    defFuncId.code = "name"
                }else if (str == "roomID"){
                    defFuncId.code = "id"
                }else if (str == "roomName"){
                    defFuncId.code = "name"
                }else if (str == "projID"){
                    defFuncId.code = "id"
                }else if (str == "projName"){
                    defFuncId.code = "name"
                }else if (str == "projLocalName"){
                    defFuncId.code = "localId"
                }else if (str == "projLocalName"){
                    defFuncId.code = "localName"
                }else if (str == "flootID"){
                    defFuncId.code = "id"
                }else if (str == "flootName"){
                    defFuncId.code = "name"
                }else if (str == "floorLocalName"){
                    defFuncId.code = "localId"
                }else if (str == "floorLocalName"){
                    defFuncId.code = "localName"
                }else if (str == "buildID"){
                    defFuncId.code = "id"
                }else if (str == "buildName"){
                    defFuncId.code = "name"
                }else if (str == "buildLocalID"){
                    defFuncId.code = "localId"
                }else if (str == "buildLocalName"){
                    defFuncId.code = "localName"
                }else{
                    defFuncId.code = str
                }
                defFuncId.code = dictGroupInfo.code
                defFuncId.id = dictGroupInfo.id
                defFuncId.canSub = dictGroupInfo.canSub
                defFuncId.category = dictGroupInfo.category
                defFuncId.classCode = type
//                        defFuncId.code = str
                defFuncId.dataSource = dictGroupInfo.dataSource
                defFuncId.dataType = dictGroupInfo.dataType
                if (!dictGroupInfo.firstTag.isNullOrEmpty()){
                    defFuncId.firstTag = ParamTools.TwoLevelCode(dictGroupInfo.firstTag!!)
                }
                defFuncId.firstName = dictGroupInfo.firstTag
                defFuncId.formater = dictGroupInfo.formater
                defFuncId.groupCode = groupCode
                defFuncId.idx = dictGroupInfo.idx
                defFuncId.inputMode = dictGroupInfo.inputMode
                defFuncId.isMultiple = dictGroupInfo.isMultiple
                defFuncId.isRegion = dictGroupInfo.isRegion
                defFuncId.name = dictGroupInfo.name
                logger.debug("name: ${ dictGroupInfo.name} *******************************************************")
                defFuncId.note = dictGroupInfo.note
                defFuncId.priority = dictGroupInfo.priority
                defFuncId.projectId = projectId
                defFuncId.readonly = dictGroupInfo.readonly
                if (!dictGroupInfo.secondTag.isNullOrEmpty()){
                    defFuncId.secondTag = ParamTools.TwoLevelCode(dictGroupInfo.secondTag!!)
                }
                defFuncId.secondName = dictGroupInfo.secondTag
                defFuncId.subFlag = dictGroupInfo.subFlag
                defFuncId.type = "project"
                defFuncId.unit = dictGroupInfo.unit
                defFuncId.origCode = dictGroupInfo.origCode
                defFuncId.origDataType = dictGroupInfo.origDataType
                defFuncId.aliasCode = dictGroupInfo.aliasCode
                defFuncId.aliasName = dictGroupInfo.aliasName

                if (!defFuncId.name.isNullOrEmpty()){
                    /** 排序 */
                    if (defFuncId.name!! == "设备本地编码"||defFuncId.name!! == "楼层本地编码"||defFuncId.name!! == "本地编码"){
                        defFuncId.sort = 1
                    }else if (defFuncId.name!! == "设备本地名称"|| defFuncId.name!! == "楼层本地名称"||defFuncId.name!! == "本地名称"){
                        defFuncId.sort = 2
                    }else if (defFuncId.name!! == "设备二维码图片"||defFuncId.name!! == "二维码图片"||defFuncId.name!! == "二维码内容"){
                        defFuncId.sort = 3
                    }else if (defFuncId.name!! == "设计图纸中编码"){
                        defFuncId.sort = 4
                    }else if (defFuncId.name!! == "设备ID"||defFuncId.name!! =="编码"){
                        defFuncId.sort = 101
                    }else if (defFuncId.name!! == "设备名称"||defFuncId.name!! =="名称"){
                        defFuncId.sort = 102
                    }else if (defFuncId.name!! == "BIM模型中编码"){
                        defFuncId.sort = 103
                    }else if (defFuncId.name!! == "BIM模型中坐标"){
                        defFuncId.sort = 104
                    }else if (defFuncId.firstName != null&& defFuncId.firstName == "台账参数"){
                        defFuncId.sort = 10
                    }else if(defFuncId.firstName != null&& defFuncId.firstName == "通讯参数"){
                        defFuncId.sort = 20
                    }else {
                        defFuncId.sort = 60
                    }
                }

                val dicConfigureEditable = ParamTools.dicConfigureEditable()
                val containsKey = dicConfigureEditable.containsKey(defFuncId.code!!)
                if (containsKey){
                    defFuncId.editable = false
                    defFuncId.unDisabled = false
                    defFuncId.visible = false
                }

                val dicConfigure = ParamTools.dicConfigure()
                if (defFuncId.code!=null){
                    val containsKey = dicConfigure.containsKey(defFuncId.code!!)
                    if (containsKey){
                        defFuncId.editable = true
                        defFuncId.unDisabled = false
                        defFuncId.visible = true
                    }
                }
                defFuncIdService.replace(defFuncId)
            }
        }


        sBaseResponse.result = SResponseType.success
        return sBaseResponse
    }


    fun projectAllInfo(): SBaseResponse {
        val dictProjectList = dictProjectService.selectAll().exec()
        if (dictProjectList.size>0){
            for (project in dictProjectList){
                dictProjectInfo(project.id!!)
            }
        }
        return SBaseResponse(SResponseType.success)
    }


    /**
     * 项目字典
     */
    fun dictProjectTypeInfoAll(projectId: String, switch: Boolean = true): SBaseResponse{
        if (switch){
            /** 项目下的类型 */
            dictProjectTypeId(projectId)
            /** 创建 */
            val dictProject = dictProjectService.select(SFilter.eq("id", projectId)).entity()
            val defClassList = defClassService.select(SFilter.eq("projectId", projectId)).exec()
            for (defClass in defClassList) {
                executorService.execute(SyncTaskDict(dictProject!!.groupCode!!,projectId,defClass.code!!))
            }
        } else {
            val dictProjectList = dictProjectService.selectAll().exec()
            for (dictProject in dictProjectList){
                /** 项目下的类型 */
                dictProjectTypeId(dictProject.id!!)
                val defClassList = defClassService.select(SFilter.eq("projectId", dictProject.id!!)).exec()
                for (defClass in defClassList) {
                    executorService.execute(SyncTaskDict(dictProject!!.groupCode!!,dictProject.id!!,defClass.code!!))
                }
            }
        }
        return SBaseResponse(SResponseType.success)
    }


} // Object DClassDefService
