package cn.flightfeather.supervision.lightshare.service.Impl
|
|
import cn.flightfeather.supervision.domain.entity.*
|
import cn.flightfeather.supervision.domain.enumeration.*
|
import cn.flightfeather.supervision.domain.mapper.*
|
import cn.flightfeather.supervision.infrastructure.utils.DateUtil
|
import cn.flightfeather.supervision.lightshare.service.OnLineQuestionService
|
import cn.flightfeather.supervision.lightshare.vo.*
|
import com.github.pagehelper.PageHelper
|
import org.springframework.beans.BeanUtils
|
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Service
|
import tk.mybatis.mapper.entity.Example
|
import java.util.*
|
import javax.annotation.Resource
|
import javax.servlet.http.HttpServletResponse
|
|
/**
|
* @Description: 月问题实现类
|
*/
|
@Service
|
@Component
|
class OnLineQuestionServiceImpl(
|
private val mgtFileMapper: MgtFileMapper,
|
private val mgtItemMapper: MgtItemMapper,
|
private val userinfoMapper: UserinfoMapper,
|
private val cstQuestionMapper: CstQuestionMapper,
|
private val settingAnswerMapper: SettingAnswerMapper,
|
private val enforceCaseMapper: EnforceCaseMapper
|
) : OnLineQuestionService {
|
@Resource
|
private val onLineQuestionMapper: OnLineQuestionMapper? = null
|
override fun addQuestions(userId: String, questions: List<OnLineQuestion>): Int {
|
var r = 0
|
for (q in questions) {
|
r += onLineQuestionMapper!!.insert(q)
|
}
|
return r
|
}
|
|
override fun getQuestions(userId: String, inUse: Boolean, page: Int, perPage: Int, httpServletResponse: HttpServletResponse): List<OnLineQuestion> {
|
|
// 1.计算出起始位置
|
val startPosition = (page - 1) * perPage
|
//2.分页的方法查询数据
|
PageHelper.startPage<Any>(startPosition, perPage)
|
val allMeetings: List<OnLineQuestion>
|
//3.分页显示数据
|
allMeetings = if (inUse) {
|
onLineQuestionMapper!!.findAll()
|
} else {
|
onLineQuestionMapper!!.findAllfalse()
|
}
|
val counts = onLineQuestionMapper.count()
|
val totalPage = Math.ceil(counts / perPage * 1.0).toInt()
|
httpServletResponse.setIntHeader("totalPage", totalPage)
|
httpServletResponse.setIntHeader("currentPage", page)
|
return allMeetings
|
}
|
|
override fun getQDescription(userId: String, questionId: String): String {
|
return onLineQuestionMapper!!.getQDescription(questionId)
|
}
|
|
override fun getQResource(userId: String, questionId: String, page: Int, perPage: Int, httpServletResponse: HttpServletResponse): List<String> {
|
// 1.计算出起始位置
|
val startPosition = (page - 1) * perPage
|
val getQDescription = onLineQuestionMapper!!.getQResource(questionId)
|
val lis = Arrays.asList(*getQDescription.split("、").toTypedArray())
|
val result: List<String>
|
result = if (startPosition + perPage < lis.size) {
|
lis.subList(startPosition, startPosition + perPage)
|
} else {
|
lis.subList(startPosition, lis.size)
|
}
|
val counts = lis.size
|
val totalPage = Math.ceil(counts / perPage * 1.0).toInt()
|
httpServletResponse.setIntHeader("totalPage", totalPage)
|
httpServletResponse.setIntHeader("currentPage", page)
|
return result
|
}
|
|
override fun getQByConditions(userId: String, inUse: Boolean, qCondition: QCondition, page: Int, perPage: Int, httpServletResponse: HttpServletResponse): List<OnLineQuestion> {
|
val keywords = qCondition.keywords
|
val factorType = qCondition.factorType
|
val resourceKind = qCondition.resourceKind
|
val showLevel = qCondition.showLevel
|
val worKind = qCondition.worKind
|
// 1.计算出起始位置
|
val startPosition = (page - 1) * perPage
|
//2.分页的方法查询数据
|
PageHelper.startPage<Any>(startPosition, perPage)
|
//3.分页显示数据 //模糊查询
|
val result = onLineQuestionMapper!!.getQByConditions(keywords, factorType, resourceKind, showLevel, worKind)
|
val counts = onLineQuestionMapper.getQByConditionsCounts(keywords, factorType, resourceKind, showLevel, worKind)
|
val totalPage = Math.ceil(counts / perPage * 1.0).toInt()
|
httpServletResponse.setIntHeader("totalPage", totalPage)
|
httpServletResponse.setIntHeader("currentPage", page)
|
return result
|
}
|
|
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
|
|
// 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)
|
// 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
|
})
|
}
|
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
|
|
// 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 }
|
}
|
|
override fun getTopicLaw(userId: String): List<MgtFileVo> {
|
val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return emptyList()
|
val perPage = 5
|
val p = PageHelper.startPage<MgtFile>(1, perPage)
|
val result = mutableListOf<MgtFileVo>()
|
mgtFileMapper.selectByExample(Example(MgtFile::class.java).apply {
|
createCriteria().orLike("mfExtension1", "%${userInfo.extension2}%")
|
.orEqualTo("mfExtension1", "")
|
.orIsNull("mfExtension1")
|
}).forEach {
|
val vo = MgtFileVo()
|
BeanUtils.copyProperties(it, vo)
|
vo.apply {
|
mfFileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
|
mfMgtLevel = ManageLevelType.getNameByValue(it.mfMgtLevel)
|
mfFileType = ConsultFileType.getNameByValue(it.mfFileType)
|
mfEpItemType = EnElementType.getNameByValue(it.mfEpItemType)
|
mfEpItemSubtype = EnElementSubType.getNameByValue(it.mfEpItemSubtype)
|
mfSaveType = FileSaveType.getNameByValue(it.mfSaveType)
|
}
|
result.add(vo)
|
}
|
return result
|
}
|
|
override fun getMgtFile(userId: String, fileId: String): MgtFileVo {
|
val result = MgtFileVo()
|
mgtFileMapper.selectByPrimaryKey(fileId)?.let {
|
BeanUtils.copyProperties(it, result)
|
result.apply {
|
mfFileIndustry = IndustryType.getNameByValue(it.mfFileIndustry)
|
mfMgtLevel = ManageLevelType.getNameByValue(it.mfMgtLevel)
|
mfFileType = ConsultFileType.getNameByValue(it.mfFileType)
|
mfEpItemType = EnElementType.getNameByValue(it.mfEpItemType)
|
mfEpItemSubtype = EnElementSubType.getNameByValue(it.mfEpItemSubtype)
|
mfSaveType = FileSaveType.getNameByValue(it.mfSaveType)
|
}
|
}
|
|
return result
|
}
|
|
override fun getTopicMgtItems(userId: String): List<MgtItem> {
|
val perPage = 5
|
val p = PageHelper.startPage<MgtFile>(1, perPage)
|
return mgtItemMapper.selectAll()
|
}
|
|
override fun getMgtItem(userId: String, itemId: String): MgtItem {
|
return mgtItemMapper.selectByPrimaryKey(itemId) ?: MgtItem()
|
}
|
|
override fun getTopicQA(userId: String): List<CstQuestionVo> {
|
val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return emptyList()
|
val perPage = 5
|
val p = PageHelper.startPage<CstQuestion>(1, perPage)
|
val result = mutableListOf<CstQuestionVo>()
|
cstQuestionMapper.selectByExample(Example(CstQuestion::class.java).apply {
|
createCriteria().orLike("cqScenes", "%${userInfo.extension2}%")
|
orderBy("cqTotalnum")
|
}).forEach {
|
val answers = settingAnswerMapper.selectByExample(Example(SettingAnswer::class.java).apply {
|
createCriteria().andEqualTo("cqGuid", it.cqGuid)
|
})
|
val vo = CstQuestionVo()
|
BeanUtils.copyProperties(it, vo)
|
vo.apply {
|
cqKind = EnElementType.getNameByValue(it.cqKind)
|
cqSubkind = EnElementSubType.getNameByValue(it.cqSubkind)
|
}
|
|
if (answers.isNotEmpty()) {
|
vo.answer = answers[0].saContent
|
}
|
result.add(vo)
|
}
|
return result
|
}
|
|
override fun getQuestionsByType(userId: String, kind: Byte?, subKind: Byte?, page: Int, perPage: Int): BaseResponse<List<ConsultResultVo>> {
|
val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return BaseResponse(false, "用户不存在")
|
val result = mutableListOf<ConsultResultVo>()
|
val p = PageHelper.startPage<CstQuestion>(page, perPage)
|
val example = Example(CstQuestion::class.java).apply {
|
createCriteria().apply {
|
kind?.let { andEqualTo("cqKind", kind) }
|
subKind?.let { andEqualTo("cqSubkind", subKind) }
|
}
|
.andLike("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
|
itemType = EnElementType.getNameByValue(it.cqKind)
|
itemSubType = EnElementSubType.getNameByValue(it.cqSubkind)
|
time = it.cqCreateTime
|
})
|
|
// val vo = CstQuestionVo()
|
// BeanUtils.copyProperties(it, vo)
|
// vo.apply {
|
// cqKind = EnElementType.getNameByValue(it.cqKind)
|
// cqSubkind = EnElementSubType.getNameByValue(it.cqSubkind)
|
// }
|
//
|
// if (answers.isNotEmpty()) {
|
// vo.answer = answers[0].saContent
|
// }
|
// result.add(vo)
|
}
|
val totalCount = cstQuestionMapper.selectCountByExample(example)
|
return BaseResponse(true, head = DataHead(p.pageNum, p.pages, totalCount), data = result)
|
}
|
|
override fun getQuestion(userId: String, qId: String): CstQuestionVo {
|
val result = CstQuestionVo()
|
cstQuestionMapper.selectByPrimaryKey(qId)?.let {
|
BeanUtils.copyProperties(it, result)
|
result.apply {
|
cqKind = EnElementType.getNameByValue(it.cqKind)
|
cqSubkind = EnElementSubType.getNameByValue(it.cqSubkind)
|
}
|
}
|
|
return result
|
}
|
|
override fun getAnswers(userId: String, qId: String): List<SettingAnswer> {
|
return settingAnswerMapper.selectByExample(Example(SettingAnswer::class.java).apply {
|
createCriteria().andEqualTo("cqGuid", qId)
|
})
|
}
|
|
override fun getTopicCase(userId: String): List<EnforceCaseVo> {
|
val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return emptyList()
|
val perPage = 5
|
val p = PageHelper.startPage<MgtFile>(1, perPage)
|
val result = mutableListOf<EnforceCaseVo>()
|
enforceCaseMapper.selectByExample(Example(EnforceCase::class.java).apply {
|
createCriteria().orLike("ecScenes", "%${userInfo.extension2}%")
|
.orEqualTo("ecScenes", "")
|
.orIsNull("ecScenes")
|
orderBy("ecOccurDate").desc()
|
}).forEach {
|
val vo = EnforceCaseVo()
|
BeanUtils.copyProperties(it, vo)
|
vo.apply {
|
ecEpItemType = EnElementType.getNameByValue(it.ecEpItemType)
|
ecEpItemSubtype = EnElementSubType.getNameByValue(it.ecEpItemSubtype)
|
ecType = EnforceCaseType.getNameByValue(it.ecType)
|
}
|
result.add(vo)
|
}
|
return result
|
}
|
|
override fun getCase(userId: String, caseId: String): EnforceCaseVo {
|
val result = EnforceCaseVo()
|
enforceCaseMapper.selectByPrimaryKey(caseId)?.let {
|
BeanUtils.copyProperties(it, result)
|
result.apply {
|
ecEpItemType = EnElementType.getNameByValue(it.ecEpItemType)
|
ecEpItemSubtype = EnElementSubType.getNameByValue(it.ecEpItemSubtype)
|
ecType = EnforceCaseType.getNameByValue(it.ecType)
|
}
|
}
|
|
return result
|
}
|
|
override fun getEnElementTypes(userId: String): List<Pair<String, Byte>> {
|
return listOf(
|
Pair(EnElementType.TYPE1.des, EnElementType.TYPE1.value),
|
Pair(EnElementType.TYPE2.des, EnElementType.TYPE2.value),
|
Pair(EnElementType.TYPE3.des, EnElementType.TYPE3.value),
|
Pair(EnElementType.TYPE4.des, EnElementType.TYPE4.value),
|
Pair(EnElementType.TYPE5.des, EnElementType.TYPE5.value),
|
Pair(EnElementType.TYPE6.des, EnElementType.TYPE6.value),
|
Pair(EnElementType.TYPE7.des, EnElementType.TYPE7.value),
|
Pair(EnElementType.TYPE8.des, EnElementType.TYPE8.value),
|
Pair(EnElementType.TYPE9.des, EnElementType.TYPE9.value),
|
Pair(EnElementType.TYPE10.des, EnElementType.TYPE10.value),
|
Pair(EnElementType.TYPE21.des, EnElementType.TYPE21.value),
|
Pair(EnElementType.TYPE31.des, EnElementType.TYPE31.value),
|
Pair(EnElementType.TYPE41.des, EnElementType.TYPE41.value),
|
Pair(EnElementType.TYPE51.des, EnElementType.TYPE51.value),
|
Pair(EnElementType.TYPE61.des, EnElementType.TYPE61.value),
|
Pair(EnElementType.TYPE99.des, EnElementType.TYPE99.value),
|
)
|
}
|
|
override fun getEnElementSubTypes(userId: String): List<List<Pair<String, Byte>>> {
|
val result = mutableListOf<List<Pair<String, Byte>>>()
|
EnElementSubType.subTypes.forEach { sList ->
|
val list = mutableListOf<Pair<String, Byte>>()
|
for (i in sList.indices) {
|
if (i == sList.lastIndex) {
|
list.add(Pair(sList[i], 99.toByte()))
|
} else {
|
list.add(Pair(sList[i], (i + 1).toByte()))
|
}
|
}
|
result.add(list)
|
}
|
return result
|
}
|
}
|