feiyu02
2024-08-15 196bb14112448857a885e32dc4149e308e00b01a
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/OnLineQuestionServiceImpl.kt
@@ -1,5 +1,6 @@
package cn.flightfeather.supervision.lightshare.service.Impl
import cn.flightfeather.supervision.common.nlp.NlpController
import cn.flightfeather.supervision.domain.entity.*
import cn.flightfeather.supervision.domain.enumeration.*
import cn.flightfeather.supervision.domain.mapper.*
@@ -26,7 +27,8 @@
    private val userinfoMapper: UserinfoMapper,
    private val cstQuestionMapper: CstQuestionMapper,
    private val settingAnswerMapper: SettingAnswerMapper,
    private val enforceCaseMapper: EnforceCaseMapper
    private val enforceCaseMapper: EnforceCaseMapper,
    private val nlpController: NlpController
) : OnLineQuestionService {
    @Resource
    private val onLineQuestionMapper: OnLineQuestionMapper? = null
@@ -100,154 +102,56 @@
    }
    override fun searchLaw(userId: String, keyword: String, type: Byte?, page: Int, perPage: Int): BaseResponse<List<ConsultResultVo>> {
        val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return BaseResponse(false)
        val response = BaseResponse<List<ConsultResultVo>>(false, head = DataHead(page, perPage))
        val result = mutableListOf<ConsultResultVo>()
        //当搜索不限制类型时,默认每种类型只获取前5项;当限制类型时,则根据前端请求分页数返回
        val _perPage = if (type == null) 5 else perPage
        val _page = page
        //法律法规文件
        if (type == null || type == ConsultResultType.TYPE1.value) {
            val p = PageHelper.startPage<MgtFile>(_page, _perPage)
            val example = Example(MgtFile::class.java).apply {
                if (keyword.isNotBlank()) {
                    createCriteria().orLike("mfName", "%${keyword}%")
                        .orLike("mfShortName", "%${keyword}%")
                        .orLike("mfSummary", "%${keyword}%")
                        .orLike("mfKeywordLv1", "%${keyword}%")
                        .orLike("mfKeywordLv2", "%${keyword}%")
                        .orLike("mfKeywordLv3", "%${keyword}%")
                        .orLike("mfKeywordLv4", "%${keyword}%")
                } else {
                    // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取
                    createCriteria().orLike("mfExtension1", "%${userInfo.extension2}%")
                        .orEqualTo("mfExtension1", "")
                        .orIsNull("mfExtension1")
                }
            }
            mgtFileMapper.selectByExample(example).forEach {
                result.add(ConsultResultFileVo().apply {
                    id = it.mfGuid
                    name = it.mfName
                    des = it.mfSummary
                    typeId = ConsultResultType.TYPE1.value
                    typeName = ConsultResultType.TYPE1.des
                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
                    itemType = EnElementType.getNameByValue(it.mfEpItemType)
                    itemSubType = EnElementSubType.getNameByValue(it.mfEpItemSubtype)
                    fileUrl = it.mfFileUrl
                    val keyList = it.mfKeywordLv1.split("、")
                    for (i in keyList.indices) {
                        if (i < 5) {
                            keywords.add(keyList[i])
                        } else {
                            break
                        }
                    }
                    time = it.mfUpdateTime
                    fileType = ConsultFileType.getNameByValue(it.mfFileType)
                    referenceNumber = it.mfReferenceNumber
                    effectiveDate = DateUtil.DateToString(it.mfEffectiveDate, DateUtil.DateStyle.YYYY_MM_DD)
                    closingDate = DateUtil.DateToString(it.mfClosingDate, DateUtil.DateStyle.YYYY_MM_DD)
                    effective = Date().time > (it.mfClosingDate?.time ?: 0)
                })
            }
            response.success = true
            response.head?.run {
                this.page = p.pageNum
                this.totalPage = p.pages
            }
        }
        //法律法规条目
        if (type == null || type == ConsultResultType.TYPE2.value) {
            val map = mutableMapOf<String, MgtFile>()
            val p = PageHelper.startPage<MgtItem>(_page, _perPage)
            val example = Example(MgtItem::class.java).apply {
                if (keyword.isNotBlank()) {
                    createCriteria().orLike("miChapterKeyword", "%${keyword}%")
                        .orLike("miKeyword", "%${keyword}%")
                } else {
                    // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取条目
                }
            }
            mgtItemMapper.selectByExample(example).forEach {
                if (!map.containsKey(it.mfGuid)) {
                    map[it.mfGuid] = mgtFileMapper.selectByPrimaryKey(it.mfGuid)
                }
                result.add(ConsultResultItemVo().apply {
                    id = it.miGuid
                    name = it.miItemName
                    des = it.miItemContent
                    typeId = ConsultResultType.TYPE2.value
                    typeName = ConsultResultType.TYPE2.des
//        val keywordList = if (keyword.isBlank()) {
//            emptyList()
//        } else {
//            nlpController.execute(keyword)
//        }
//        val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return BaseResponse(false)
//        val response = BaseResponse<List<ConsultResultVo>>(false, head = DataHead(page, perPage))
//        val result = mutableListOf<ConsultResultVo>()
//
//        //当搜索不限制类型时,默认每种类型只获取前5项;当限制类型时,则根据前端请求分页数返回
//        val _perPage = if (type == null) 5 else perPage
//        val _page = page
//
//        //法律法规文件
//        if (type == null || type == ConsultResultType.TYPE1.value) {
//            val p = PageHelper.startPage<MgtFile>(_page, _perPage)
//            val example = Example(MgtFile::class.java).apply {
//                if (keywordList.isNotEmpty()) {
//                    createCriteria().apply {
//                        keywordList.forEach { k ->
//                            orLike("mfName", "%${k}%")
//                            orLike("mfShortName", "%${k}%")
//                            orLike("mfSummary", "%${k}%")
//                            orLike("mfKeywordLv1", "%${k}%")
//                            orLike("mfKeywordLv2", "%${k}%")
//                            orLike("mfKeywordLv3", "%${k}%")
//                            orLike("mfKeywordLv4", "%${k}%")
//                        }
//                    }
//                    and(createCriteria().orLike("mfExtension1", "%${userInfo.extension2}%")
//                        .orEqualTo("mfExtension1", "")
//                        .orIsNull("mfExtension1"))
//                } else {
//                    // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取
//                    createCriteria().orLike("mfExtension1", "%${userInfo.extension2}%")
//                        .orEqualTo("mfExtension1", "")
//                        .orIsNull("mfExtension1")
//                }
//            }
//            mgtFileMapper.selectByExample(example).forEach {
//                result.add(ConsultResultFileVo().apply {
//                    id = it.mfGuid
//                    name = it.mfName
//                    des = it.mfSummary
//                    typeId = ConsultResultType.TYPE1.value
//                    typeName = ConsultResultType.TYPE1.des
//
//                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
//                    itemType = EnElementType.getNameByValue(it.mfEpItemType)
//                    fileUrl = it.mfFileUrl
                    val keyList = it.miKeyword.split("、")
                    for (i in keyList.indices) {
                        if (i < 5) {
                            keywords.add(keyList[i])
                        } else {
                            break
                        }
                    }
                    time = it.miUpdateTime
                    chapterName = it.miChapterName
                    fileId = it.mfGuid
                    fileName = it.mfName
                    referenceNumber = it.mfReferenceNumber
                    effectiveDate = DateUtil.DateToString(map[it.mfGuid]?.mfEffectiveDate, DateUtil.DateStyle.YYYY_MM_DD)
                    closingDate = DateUtil.DateToString(map[it.mfGuid]?.mfClosingDate, DateUtil.DateStyle.YYYY_MM_DD)
                    effective = Date().time > (map[it.mfGuid]?.mfClosingDate?.time ?: 0)
                    relatedItems = it.miRelatedItems?.split(";")?.size ?: 0
                })
            }
            response.success = true
            response.head?.run {
                this.page = p.pageNum
                this.totalPage = p.pages
            }
        }
        //环保问题
        if (type == null || type == ConsultResultType.TYPE4.value) {
            val p = PageHelper.startPage<CstQuestion>(_page, _perPage)
            val example = Example(CstQuestion::class.java).apply {
                if (keyword.isNotBlank()) {
                    createCriteria().orLike("cqScenes", "%${userInfo.extension2}%")
                        .orEqualTo("cqScenes", "")
                        .orIsNull("cqScenes")
                    and(
                        createCriteria().orLike("cqContent", "%${keyword}%")
                            .orLike("cqKeywords", "%${keyword}%")
                    )
                } else {
                    // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取
                    createCriteria().orLike("cqScenes", "%${userInfo.extension2}%")
                    orderBy("cqTotalnum")
                }
            }
            cstQuestionMapper.selectByExample(example).forEach {
                val answers = settingAnswerMapper.selectByExample(Example(SettingAnswer::class.java).apply {
                    createCriteria().andEqualTo("cqGuid", it.cqGuid)
                })
                result.add(ConsultResultQAVo().apply {
                    id = it.cqGuid
                    name = it.cqContent
                    if (answers.isNotEmpty()) {
                        des = answers[0].saContent
                    }
                    typeId = ConsultResultType.TYPE4.value
                    typeName = ConsultResultType.TYPE4.des
//                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
                    itemType = EnElementType.getNameByValue(it.cqKind)
                    itemSubType = EnElementSubType.getNameByValue(it.cqSubkind)
//                    itemSubType = EnElementSubType.getSubType(it.mfEpItemType, it.mfEpItemSubtype)
//                    fileUrl = it.mfFileUrl
//                    val keyList = it.mfKeywordLv1.split("、")
//                    for (i in keyList.indices) {
@@ -257,69 +161,199 @@
//                            break
//                        }
//                    }
                    time = it.cqCreateTime
                })
            }
            response.success = true
            response.head?.run {
                this.page = p.pageNum
                this.totalPage = p.pages
            }
        }
        //执法案例
        if (type == null || type == ConsultResultType.TYPE3.value) {
            val p = PageHelper.startPage<EnforceCase>(_page, _perPage)
            val example = Example(EnforceCase::class.java).apply {
                if (keyword.isNotBlank()) {
                    createCriteria().orLike("ecScenes", "%${userInfo.extension2}%")
                        .orEqualTo("ecScenes", "")
                        .orIsNull("ecScenes")
                    and(
                        createCriteria().orLike("ecTitle", "%${keyword}%")
                            .orLike("ecKeywords", "%${keyword}%")
                    )
                } else {
                    // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取
                    createCriteria().orLike("ecScenes", "%${userInfo.extension2}%")
                        .orEqualTo("ecScenes", "")
                        .orIsNull("ecScenes")
                    orderBy("ecOccurDate").desc()
                }
            }
            enforceCaseMapper.selectByExample(example).forEach {
                result.add(ConsultResultCaseVo().apply {
                    id = it.ecGuid
                    name = it.ecTitle
                    des = it.ecSummary
                    typeId = ConsultResultType.TYPE3.value
                    typeName = ConsultResultType.TYPE3.des
//                    time = it.mfUpdateTime
//                    fileType = ConsultFileType.getNameByValue(it.mfFileType)
//                    referenceNumber = it.mfReferenceNumber
//                    effectiveDate = DateUtil.DateToString(it.mfEffectiveDate, DateUtil.DateStyle.YYYY_MM_DD)
//                    closingDate = DateUtil.DateToString(it.mfClosingDate, DateUtil.DateStyle.YYYY_MM_DD)
//                    effective = Date().time > (it.mfClosingDate?.time ?: 0)
//                })
//            }
//            response.success = true
//            response.head?.run {
//                this.page = p.pageNum
//                this.totalPage = p.pages
//            }
//        }
//        //法律法规条目
//        if (type == null || type == ConsultResultType.TYPE2.value) {
//            val map = mutableMapOf<String, MgtFile>()
//            val p = PageHelper.startPage<MgtItem>(_page, _perPage)
//            val example = Example(MgtItem::class.java).apply {
//                if (keywordList.isNotEmpty()) {
//                    createCriteria().apply {
//                        keywordList.forEach { k ->
//                            orLike("miChapterKeyword", "%${k}%")
//                            orLike("miKeyword", "%${k}%")
//                            orLike("miItemContent", "%${k}%")
//                        }
//                    }
//                } else {
//                    // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取条目
//                }
//            }
//            mgtItemMapper.selectByExample(example).forEach {
//
//                if (!map.containsKey(it.mfGuid)) {
//                    map[it.mfGuid] = mgtFileMapper.selectByPrimaryKey(it.mfGuid)
//                }
//                result.add(ConsultResultItemVo().apply {
//                    id = it.miGuid
//                    name = it.miItemName
//                    des = it.miItemContent
//                    typeId = ConsultResultType.TYPE2.value
//                    typeName = ConsultResultType.TYPE2.des
//
////                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
////                    itemType = EnElementType.getNameByValue(it.mfEpItemType)
////                    fileUrl = it.mfFileUrl
//                    val keyList = it.miKeyword.split("、")
//                    for (i in keyList.indices) {
//                        if (i < 5) {
//                            keywords.add(keyList[i])
//                        } else {
//                            break
//                        }
//                    }
//                    time = it.miUpdateTime
//
//                    chapterName = it.miChapterName
//                    fileId = it.mfGuid
//                    fileName = it.mfName
//                    referenceNumber = it.mfReferenceNumber
//                    effectiveDate = DateUtil.DateToString(map[it.mfGuid]?.mfEffectiveDate, DateUtil.DateStyle.YYYY_MM_DD)
//                    closingDate = DateUtil.DateToString(map[it.mfGuid]?.mfClosingDate, DateUtil.DateStyle.YYYY_MM_DD)
//                    effective = Date().time > (map[it.mfGuid]?.mfClosingDate?.time ?: 0)
//                    relatedItems = it.miRelatedItems?.split(";")?.size ?: 0
//                })
//            }
//            response.success = true
//            response.head?.run {
//                this.page = p.pageNum
//                this.totalPage = p.pages
//            }
//        }
//        //环保问题
//        if (type == null || type == ConsultResultType.TYPE4.value) {
//            val p = PageHelper.startPage<CstQuestion>(_page, _perPage)
//            val example = Example(CstQuestion::class.java).apply {
//                if (keywordList.isNotEmpty()) {
//                    createCriteria().orLike("cqScenes", "%${userInfo.extension2}%")
//                        .orEqualTo("cqScenes", "")
//                        .orIsNull("cqScenes")
//                    and(
//                        createCriteria().apply {
//                            keywordList.forEach { k ->
//                                orLike("cqContent", "%${k}%")
//                                orLike("cqKeywords", "%${k}%")
//                            }
//                        }
//                    )
//                } else {
//                    // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取
//                    createCriteria().orLike("cqScenes", "%${userInfo.extension2}%")
//                    orderBy("cqTotalnum")
//                }
//            }
//            cstQuestionMapper.selectByExample(example).forEach {
//                val answers = settingAnswerMapper.selectByExample(Example(SettingAnswer::class.java).apply {
//                    createCriteria().andEqualTo("cqGuid", it.cqGuid)
//                })
//
//                result.add(ConsultResultQAVo().apply {
//                    id = it.cqGuid
//                    name = it.cqContent
//                    if (answers.isNotEmpty()) {
//                        des = answers[0].saContent
//                    }
//                    typeId = ConsultResultType.TYPE4.value
//                    typeName = ConsultResultType.TYPE4.des
//
////                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
//                    itemType = EnElementType.getNameByValue(it.cqKind)
//                    itemSubType = EnElementSubType.getSubType(it.cqKind, it.cqSubkind)
////                    fileUrl = it.mfFileUrl
////                    val keyList = it.mfKeywordLv1.split("、")
////                    for (i in keyList.indices) {
////                        if (i < 5) {
////                            keywords.add(keyList[i])
////                        } else {
////                            break
////                        }
////                    }
//                    time = it.cqCreateTime
//                    punish = it.cqIsPunish
//                    illegal = it.cqIsIllegal
//                    shotSpot = it.cqIsShotspot
//                    supervise = it.cqIsSupervise
//                })
//            }
//            response.success = true
//            response.head?.run {
//                this.page = p.pageNum
//                this.totalPage = p.pages
//            }
//        }
//        //执法案例
//        if (type == null || type == ConsultResultType.TYPE3.value) {
//            val p = PageHelper.startPage<EnforceCase>(_page, _perPage)
//            val example = Example(EnforceCase::class.java).apply {
//                if (keywordList.isNotEmpty()) {
//                    createCriteria().orLike("ecScenes", "%${userInfo.extension2}%")
//                        .orEqualTo("ecScenes", "")
//                        .orIsNull("ecScenes")
//                    and(
//                        createCriteria().apply {
//                            keywordList.forEach { k ->
//                                orLike("ecTitle", "%${k}%")
//                                orLike("ecKeywords", "%${k}%")
//                            }
//                        }
//                    )
//                } else {
//                    // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取
//                    createCriteria().orLike("ecScenes", "%${userInfo.extension2}%")
//                        .orEqualTo("ecScenes", "")
//                        .orIsNull("ecScenes")
//                    orderBy("ecOccurDate").desc()
//                }
//            }
//            enforceCaseMapper.selectByExample(example).forEach {
//                result.add(ConsultResultCaseVo().apply {
//                    id = it.ecGuid
//                    name = it.ecTitle
//                    des = it.ecSummary
//                    typeId = ConsultResultType.TYPE3.value
//                    typeName = ConsultResultType.TYPE3.des
//
////                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
//                    itemType = EnElementType.getNameByValue(it.ecEpItemType)
//                    itemSubType = EnElementSubType.getSubType(it.ecEpItemType, it.ecEpItemSubtype)
//                    imgUrl = it.ecAppendixUrl?.split(";")?.get(0)
//                    time = it.ecCreateTime
//
//                    provinceName = it.ecProvinceName
//                    cityName = it.ecCityName
//                    occurDate = DateUtil.DateToString(it.ecOccurDate, DateUtil.DateStyle.YYYY_MM_DD)
//                    punish = it.ecIsPunish
//                    detained = it.ecIsDetained
//                    illegal = it.ecIsIllegal
//                    shotSpot = it.ecIsShotspot
//                    supervise = it.ecIsSupervise
//                    minor = it.ecIsMinor
//                })
//            }
//            response.success = true
//            response.head?.run {
//                this.page = p.pageNum
//                this.totalPage = p.pages
//            }
//        }
//
//
//        return response.apply { data = result }
//                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
                    itemType = EnElementType.getNameByValue(it.ecEpItemType)
                    itemSubType = EnElementSubType.getNameByValue(it.ecEpItemSubtype)
                    imgUrl = it.ecAppendixUrl?.split(";")?.get(0)
                    time = it.ecCreateTime
                    provinceName = it.ecProvinceName
                    cityName = it.ecCityName
                    occurDate = DateUtil.DateToString(it.ecOccurDate, DateUtil.DateStyle.YYYY_MM_DD)
                    punish = it.ecIsPunish
                    detained = it.ecIsDetained
                    illegal = it.ecIsIllegal
                    shotSpot = it.ecIsShotspot
                    supervise = it.ecIsSupervise
                    minor = it.ecIsMinor
                })
            }
            response.success = true
            response.head?.run {
                this.page = p.pageNum
                this.totalPage = p.pages
            }
        }
        return response.apply { data = result }
        return searchLaw2(userId, keyword, type, page, perPage)
    }
    override fun getTopicLaw(userId: String): List<MgtFileVo> {
@@ -339,7 +373,7 @@
                mfMgtLevel = ManageLevelType.getNameByValue(it.mfMgtLevel)
                mfFileType = ConsultFileType.getNameByValue(it.mfFileType)
                mfEpItemType = EnElementType.getNameByValue(it.mfEpItemType)
                mfEpItemSubtype = EnElementSubType.getNameByValue(it.mfEpItemSubtype)
                mfEpItemSubtype = EnElementSubType.getSubType(it.mfEpItemType, it.mfEpItemSubtype)
                mfSaveType = FileSaveType.getNameByValue(it.mfSaveType)
            }
            result.add(vo)
@@ -356,7 +390,7 @@
                mfMgtLevel = ManageLevelType.getNameByValue(it.mfMgtLevel)
                mfFileType = ConsultFileType.getNameByValue(it.mfFileType)
                mfEpItemType = EnElementType.getNameByValue(it.mfEpItemType)
                mfEpItemSubtype = EnElementSubType.getNameByValue(it.mfEpItemSubtype)
                mfEpItemSubtype = EnElementSubType.getSubType(it.mfEpItemType, it.mfEpItemSubtype)
                mfSaveType = FileSaveType.getNameByValue(it.mfSaveType)
            }
        }
@@ -390,7 +424,7 @@
            BeanUtils.copyProperties(it, vo)
            vo.apply {
                cqKind = EnElementType.getNameByValue(it.cqKind)
                cqSubkind = EnElementSubType.getNameByValue(it.cqSubkind)
                cqSubkind = EnElementSubType.getSubType(it.cqKind, it.cqSubkind)
            }
            if (answers.isNotEmpty()) {
@@ -427,7 +461,7 @@
                typeId = ConsultResultType.TYPE4.value
                typeName = ConsultResultType.TYPE4.des
                itemType = EnElementType.getNameByValue(it.cqKind)
                itemSubType = EnElementSubType.getNameByValue(it.cqSubkind)
                itemSubType = EnElementSubType.getSubType(it.cqKind, it.cqSubkind)
                time = it.cqCreateTime
            })
@@ -435,7 +469,7 @@
//            BeanUtils.copyProperties(it, vo)
//            vo.apply {
//                cqKind = EnElementType.getNameByValue(it.cqKind)
//                cqSubkind = EnElementSubType.getNameByValue(it.cqSubkind)
//                cqSubkind = EnElementSubType.getSubType(it.ecEpItemType, it.cqSubkind)
//            }
//
//            if (answers.isNotEmpty()) {
@@ -443,8 +477,7 @@
//            }
//            result.add(vo)
        }
        val totalCount = cstQuestionMapper.selectCountByExample(example)
        return BaseResponse(true, head = DataHead(p.pageNum, p.pages, totalCount), data = result)
        return BaseResponse(true, head = DataHead(p.pageNum, p.pages, p.total), data = result)
    }
    override fun getQuestion(userId: String, qId: String): CstQuestionVo {
@@ -453,7 +486,7 @@
            BeanUtils.copyProperties(it, result)
            result.apply {
                cqKind = EnElementType.getNameByValue(it.cqKind)
                cqSubkind = EnElementSubType.getNameByValue(it.cqSubkind)
                cqSubkind = EnElementSubType.getSubType(it.cqKind, it.cqSubkind)
            }
        }
@@ -481,7 +514,7 @@
            BeanUtils.copyProperties(it, vo)
            vo.apply {
                ecEpItemType = EnElementType.getNameByValue(it.ecEpItemType)
                ecEpItemSubtype = EnElementSubType.getNameByValue(it.ecEpItemSubtype)
                ecEpItemSubtype = EnElementSubType.getSubType(it.ecEpItemType, it.ecEpItemSubtype)
                ecType = EnforceCaseType.getNameByValue(it.ecType)
            }
            result.add(vo)
@@ -495,7 +528,7 @@
            BeanUtils.copyProperties(it, result)
            result.apply {
                ecEpItemType = EnElementType.getNameByValue(it.ecEpItemType)
                ecEpItemSubtype = EnElementSubType.getNameByValue(it.ecEpItemSubtype)
                ecEpItemSubtype = EnElementSubType.getSubType(it.ecEpItemType, it.ecEpItemSubtype)
                ecType = EnforceCaseType.getNameByValue(it.ecType)
            }
        }
@@ -539,4 +572,353 @@
        }
        return result
    }
    private fun searchLaw2(userId: String, keyword: String, type: Byte?, page: Int, perPage: Int): BaseResponse<List<ConsultResultVo>> {
        val keywordList = if (keyword.isBlank()) {
            emptyList()
        } else {
            nlpController.execute(keyword)
        }
        val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return BaseResponse(false)
        val response = BaseResponse<List<ConsultResultVo>>(false, head = DataHead(page, perPage))
        val result = mutableListOf<ConsultResultVo>()
        //当搜索不限制类型时,默认每种类型只获取前5项;当限制类型时,则根据前端请求分页数返回
        val _perPage = if (type == null) 5 else perPage
        val _page = page
        //法律法规文件
        if (type == null || type == ConsultResultType.TYPE1.value) {
            val p = PageHelper.startPage<MgtFile>(_page, _perPage)
            val resultMap = mutableMapOf<String, Pair<MgtFile, Int>>()
            val tempList = mutableListOf<Pair<MgtFile, Int>>()
            if (keywordList.isNotEmpty()) {
                keywordList.forEach { k ->
                    mgtFileMapper.selectByExample(Example(MgtFile::class.java).apply {
                        createCriteria().orLike("mfName", "%${k}%")
                            .orLike("mfShortName", "%${k}%")
                            .orLike("mfSummary", "%${k}%")
                            .orLike("mfKeywordLv1", "%${k}%")
                            .orLike("mfKeywordLv2", "%${k}%")
                            .orLike("mfKeywordLv3", "%${k}%")
                            .orLike("mfKeywordLv4", "%${k}%")
                    }).forEach { f ->
                        if (!resultMap.containsKey(f.mfGuid)) {
                            resultMap[f.mfGuid] = Pair(f, 0)
                        }
                        resultMap[f.mfGuid] = Pair(f, resultMap[f.mfGuid]?.second?.plus(1) ?: 0)
                    }
                }
                resultMap.forEach { (_, u) ->
                    tempList.add(u)
                }
                tempList.sortWith { o1, o2 ->
                    //排序条件一:关键词匹配次数
                    if (o1.second != o2.second) {
                        return@sortWith o2.second - o1.second
                    }
                    //排序条件二:浏览量
                    if (o1.first.mfRemark != o2.first.mfRemark) {
                        return@sortWith o2.first.mfRemark.toIntOrNull()?.minus(o1.first.mfRemark.toIntOrNull() ?: 0) ?: 0
                    }
                    //排序条件三:文件发布时间
                    (o2.first.mfReleaseDate.time - o1.first.mfReleaseDate.time).toInt()
                }
            } else {
                mgtFileMapper.selectByExample(Example(MgtFile::class.java).apply {
                    createCriteria().orLike("mfExtension1", "%${userInfo.extension2}%")
                        .orEqualTo("mfExtension1", "")
                        .orIsNull("mfExtension1")
                }).forEach {
                    tempList.add(Pair(it, 0))
                }
            }
            tempList.forEach {p ->
                val it = p.first
                result.add(ConsultResultFileVo().apply {
                    id = it.mfGuid
                    name = it.mfName
                    des = it.mfSummary
                    typeId = ConsultResultType.TYPE1.value
                    typeName = ConsultResultType.TYPE1.des
                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
                    itemType = EnElementType.getNameByValue(it.mfEpItemType)
                    itemSubType = EnElementSubType.getSubType(it.mfEpItemType, it.mfEpItemSubtype)
                    fileUrl = it.mfFileUrl
                    val keyList = it.mfKeywordLv1.split("、")
                    for (i in keyList.indices) {
                        if (i < 5) {
                            keywords.add(keyList[i])
                        } else {
                            break
                        }
                    }
                    time = it.mfUpdateTime
                    fileType = ConsultFileType.getNameByValue(it.mfFileType)
                    referenceNumber = it.mfReferenceNumber
                    effectiveDate = DateUtil.DateToString(it.mfEffectiveDate, DateUtil.DateStyle.YYYY_MM_DD)
                    closingDate = DateUtil.DateToString(it.mfClosingDate, DateUtil.DateStyle.YYYY_MM_DD)
                    effective = Date().time > (it.mfClosingDate?.time ?: 0)
                })
            }
            response.success = true
            response.head?.run {
                this.page = p.pageNum
                this.totalPage = p.pages
            }
        }
        //法律法规条目
        if (type == null || type == ConsultResultType.TYPE2.value) {
            val map = mutableMapOf<String, MgtFile>()
            val p = PageHelper.startPage<MgtItem>(_page, _perPage)
            val resultMap = mutableMapOf<String, Pair<MgtItem, Int>>()
            val tempList = mutableListOf<Pair<MgtItem, Int>>()
            if (keywordList.isNotEmpty()) {
                mgtItemMapper.selectByExample(Example(MgtItem::class.java).apply {
                    createCriteria().apply {
                        keywordList.forEach { k ->
                            orLike("miChapterKeyword", "%${k}%")
                            orLike("miKeyword", "%${k}%")
                            orLike("miItemContent", "%${k}%")
                        }
                    }
                }).forEach { f ->
                    if (!resultMap.containsKey(f.miGuid)) {
                        resultMap[f.miGuid] = Pair(f, 0)
                    }
                    resultMap[f.miGuid] = Pair(f, resultMap[f.miGuid]?.second?.plus(1) ?: 0)
                }
                resultMap.forEach { (_, u) ->
                    tempList.add(u)
                }
                tempList.sortWith { o1, o2 ->
                    //排序条件一:关键词匹配次数
                    if (o1.second != o2.second) {
                        return@sortWith o2.second - o1.second
                    }
                    //排序条件二:浏览量
                    return@sortWith o2.first.miRemark.toIntOrNull()?.minus(o1.first.miRemark.toIntOrNull() ?: 0) ?: 0
                }
            } else {
                // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取条目
                mgtItemMapper.selectByExample(Example(MgtItem::class.java).apply {
                    orderBy("miCreateTime").desc()
                }).forEach {
                    tempList.add(Pair(it, 0))
                }
            }
            tempList.forEach {p ->
                val it = p.first
                if (!map.containsKey(it.mfGuid)) {
                    map[it.mfGuid] = mgtFileMapper.selectByPrimaryKey(it.mfGuid)
                }
                result.add(ConsultResultItemVo().apply {
                    id = it.miGuid
                    name = it.miItemName
                    des = it.miItemContent
                    typeId = ConsultResultType.TYPE2.value
                    typeName = ConsultResultType.TYPE2.des
//                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
//                    itemType = EnElementType.getNameByValue(it.mfEpItemType)
//                    fileUrl = it.mfFileUrl
                    val keyList = it.miKeyword.split("、")
                    for (i in keyList.indices) {
                        if (i < 5) {
                            keywords.add(keyList[i])
                        } else {
                            break
                        }
                    }
                    time = it.miUpdateTime
                    chapterName = it.miChapterName
                    fileId = it.mfGuid
                    fileName = it.mfName
                    referenceNumber = it.mfReferenceNumber
                    effectiveDate = DateUtil.DateToString(map[it.mfGuid]?.mfEffectiveDate, DateUtil.DateStyle.YYYY_MM_DD)
                    closingDate = DateUtil.DateToString(map[it.mfGuid]?.mfClosingDate, DateUtil.DateStyle.YYYY_MM_DD)
                    effective = Date().time > (map[it.mfGuid]?.mfClosingDate?.time ?: 0)
                    relatedItems = it.miRelatedItems?.split(";")?.size ?: 0
                })
            }
            response.success = true
            response.head?.run {
                this.page = p.pageNum
                this.totalPage = p.pages
            }
        }
        //环保问题
        if (type == null || type == ConsultResultType.TYPE4.value) {
            val p = PageHelper.startPage<CstQuestion>(_page, _perPage)
            val resultMap = mutableMapOf<String, Pair<CstQuestion, Int>>()
            val tempList = mutableListOf<Pair<CstQuestion, Int>>()
            if (keywordList.isNotEmpty()) {
                cstQuestionMapper.selectByExample(Example(CstQuestion::class.java).apply {
                    createCriteria().orLike("cqScenes", "%${userInfo.extension2}%")
                        .orEqualTo("cqScenes", "")
                        .orIsNull("cqScenes")
                    and(
                        createCriteria().apply {
                            keywordList.forEach { k ->
                                orLike("cqContent", "%${k}%")
                                orLike("cqKeywords", "%${k}%")
                            }
                        }
                    )
                }).forEach { f ->
                    if (!resultMap.containsKey(f.cqGuid)) {
                        resultMap[f.cqGuid] = Pair(f, 0)
                    }
                    resultMap[f.cqGuid] = Pair(f, resultMap[f.cqGuid]?.second?.plus(1) ?: 0)
                }
                resultMap.forEach { (_, u) ->
                    tempList.add(u)
                }
                tempList.sortWith { o1, o2 ->
                    //排序条件一:关键词匹配次数
                    if (o1.second != o2.second) {
                        return@sortWith o2.second - o1.second
                    }
                    //排序条件二:浏览量
                    return@sortWith o2.first.cqRemark?.toIntOrNull()?.minus(o1.first.cqRemark.toIntOrNull() ?: 0) ?: 0
                }
            } else {
                // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取
                cstQuestionMapper.selectByExample(Example(CstQuestion::class.java).apply {
                    createCriteria().orLike("cqScenes", "%${userInfo.extension2}%")
                    orderBy("cqTotalnum")
                }).forEach {
                    tempList.add(Pair(it, 0))
                }
            }
            tempList.forEach {p ->
                val it = p.first
                val answers = settingAnswerMapper.selectByExample(Example(SettingAnswer::class.java).apply {
                    createCriteria().andEqualTo("cqGuid", it.cqGuid)
                })
                result.add(ConsultResultQAVo().apply {
                    id = it.cqGuid
                    name = it.cqContent
                    if (answers.isNotEmpty()) {
                        des = answers[0].saContent
                    }
                    typeId = ConsultResultType.TYPE4.value
                    typeName = ConsultResultType.TYPE4.des
//                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
                    itemType = EnElementType.getNameByValue(it.cqKind)
                    itemSubType = EnElementSubType.getSubType(it.cqKind, it.cqSubkind)
//                    fileUrl = it.mfFileUrl
//                    val keyList = it.mfKeywordLv1.split("、")
//                    for (i in keyList.indices) {
//                        if (i < 5) {
//                            keywords.add(keyList[i])
//                        } else {
//                            break
//                        }
//                    }
                    time = it.cqCreateTime
                    punish = it.cqIsPunish
                    illegal = it.cqIsIllegal
                    shotSpot = it.cqIsShotspot
                    supervise = it.cqIsSupervise
                })
            }
            response.success = true
            response.head?.run {
                this.page = p.pageNum
                this.totalPage = p.pages
            }
        }
        //执法案例
        if (type == null || type == ConsultResultType.TYPE3.value) {
            val p = PageHelper.startPage<EnforceCase>(_page, _perPage)
            val resultMap = mutableMapOf<String, Pair<EnforceCase, Int>>()
            val tempList = mutableListOf<Pair<EnforceCase, Int>>()
            if (keywordList.isNotEmpty()) {
                enforceCaseMapper.selectByExample(Example(EnforceCase::class.java).apply {
                    createCriteria().orLike("ecScenes", "%${userInfo.extension2}%")
                        .orEqualTo("ecScenes", "")
                        .orIsNull("ecScenes")
                    and(
                        createCriteria().apply {
                            keywordList.forEach { k ->
                                orLike("ecTitle", "%${k}%")
                                orLike("ecKeywords", "%${k}%")
                            }
                        }
                    )
                }).forEach { f ->
                    if (!resultMap.containsKey(f.ecGuid)) {
                        resultMap[f.ecGuid] = Pair(f, 0)
                    }
                    resultMap[f.ecGuid] = Pair(f, resultMap[f.ecGuid]?.second?.plus(1) ?: 0)
                }
                resultMap.forEach { (_, u) ->
                    tempList.add(u)
                }
                tempList.sortWith { o1, o2 ->
                    //排序条件一:关键词匹配次数
                    if (o1.second != o2.second) {
                        return@sortWith o2.second - o1.second
                    }
                    //排序条件二:浏览量
                    return@sortWith o2.first.ecRemark.toIntOrNull()?.minus(o1.first.ecRemark.toIntOrNull() ?: 0) ?: 0
                }
            } else {
                // TODO: 2022/9/8 没有关键字时,按照热门获取机制获取
                enforceCaseMapper.selectByExample(Example(EnforceCase::class.java).apply {
                    createCriteria().orLike("ecScenes", "%${userInfo.extension2}%")
                        .orEqualTo("ecScenes", "")
                        .orIsNull("ecScenes")
                    orderBy("ecOccurDate").desc()
                }).forEach {
                    tempList.add(Pair(it, 0))
                }
            }
            tempList.forEach {p ->
                val it = p.first
                result.add(ConsultResultCaseVo().apply {
                    id = it.ecGuid
                    name = it.ecTitle
                    des = it.ecSummary
                    typeId = ConsultResultType.TYPE3.value
                    typeName = ConsultResultType.TYPE3.des
//                    fileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
                    itemType = EnElementType.getNameByValue(it.ecEpItemType)
                    itemSubType = EnElementSubType.getSubType(it.ecEpItemType, it.ecEpItemSubtype)
                    imgUrl = it.ecAppendixUrl?.split(";")?.get(0)
                    time = it.ecCreateTime
                    provinceName = it.ecProvinceName
                    cityName = it.ecCityName
                    occurDate = DateUtil.DateToString(it.ecOccurDate, DateUtil.DateStyle.YYYY_MM_DD)
                    punish = it.ecIsPunish
                    detained = it.ecIsDetained
                    illegal = it.ecIsIllegal
                    shotSpot = it.ecIsShotspot
                    supervise = it.ecIsSupervise
                    minor = it.ecIsMinor
                })
            }
            response.success = true
            response.head?.run {
                this.page = p.pageNum
                this.totalPage = p.pages
            }
        }
        return response.apply { data = result }
    }
}