package cn.flightfeather.supervision.lightshare.service.impl
|
|
import cn.flightfeather.supervision.common.utils.*
|
import cn.flightfeather.supervision.domain.ds1.entity.*
|
import cn.flightfeather.supervision.domain.ds1.mapper.*
|
import cn.flightfeather.supervision.lightshare.service.SearchService
|
import cn.flightfeather.supervision.lightshare.vo.*
|
import com.github.pagehelper.PageHelper
|
import org.springframework.beans.BeanUtils
|
import org.springframework.stereotype.Service
|
import tk.mybatis.mapper.entity.Example
|
import java.io.File
|
import java.io.FileInputStream
|
import java.io.FileOutputStream
|
import java.nio.charset.StandardCharsets
|
import java.util.*
|
import javax.servlet.http.HttpServletResponse
|
|
/**
|
* @author riku
|
* Date: 2020/6/12
|
*/
|
@Service
|
class SearchServiceImpl(
|
val userinfoMapper: UserinfoMapper,
|
val subtaskMapper: SubtaskMapper,
|
val scenseMapper: ScenseMapper,
|
val problemlistMapper: ProblemlistMapper,
|
val problemtypeMapper: ProblemtypeMapper,
|
val townMapper: TownMapper,
|
val mediafileMapper: MediafileMapper,
|
val scoreMapper: ScoreMapper,
|
val inspectionMapper: InspectionMapper,
|
val taskMapper: TaskMapper
|
): SearchService {
|
|
private val dateUtil = DateUtil()
|
|
override fun writeToFile(config: ExcelConfigVo) {
|
val fileName = "e:/${DateUtil().DateToString(Date(), "yyyy-MM-ddhhmmss")}.xls"
|
val out = FileOutputStream(fileName)
|
val heads = getTableTitles()
|
val contents = getTableContents(config)
|
ExcelUtil.write2(out, heads, contents)
|
}
|
|
override fun getExcel(config: ExcelConfigVo, response: HttpServletResponse): HttpServletResponse {
|
|
val fileName = "${DateUtil().DateToString(Date(), "yyyy-MM-dd hh:mm:ss")}.xls"
|
response.apply {
|
setHeader("Content-Disposition", "attachment;filename=$fileName")
|
setHeader("fileName", fileName)
|
contentType = "application/vnd.ms-excel;charset=UTF-8"
|
setHeader("Pragma", "no-cache")
|
setHeader("Cache-Control", "no-cache")
|
setDateHeader("Expires", 0)
|
}
|
|
val heads = getTableTitles()
|
val contents = getTableContents(config)
|
|
val out = response.outputStream
|
ExcelUtil.write2(out, heads, contents)
|
|
return response
|
}
|
|
override fun getSubTaskDetail(config: ExcelConfigVo): SubTaskTableVo {
|
val titles = getTableTitles2()
|
val content = getTableContents2(config)
|
|
return SubTaskTableVo(titles, content)
|
}
|
|
override fun downloadPic(config: ExcelConfigVo, response: HttpServletResponse): HttpServletResponse {
|
val townName = if (config.townCode == null) {
|
null
|
} else {
|
val l = townMapper.selectByExample(Example(Town::class.java).apply {
|
createCriteria().andEqualTo("towncode", config.townCode)
|
})
|
if (l.isNotEmpty()) {
|
l[0].townname
|
} else {
|
null
|
}
|
}
|
val subTaskExample = Example(Subtask::class.java).apply {
|
if (config.subTaskIdList != null && config.subTaskIdList.isNotEmpty()) {
|
createCriteria().apply {
|
config.subTaskIdList.forEach {
|
orEqualTo("stguid", it)
|
}
|
}
|
} else {
|
createCriteria()
|
.andEqualTo("tguid", config.topTaskGuid)
|
.andGreaterThanOrEqualTo("planstarttime", config.startTime)
|
.andLessThanOrEqualTo("planendtime", config.endTime).apply {
|
config.provinceCode?.let {
|
andEqualTo("provincecode", it)
|
}
|
config.cityCode?.let {
|
andEqualTo("citycode", it)
|
}
|
config.districtCode?.let {
|
andEqualTo("districtcode", it)
|
}
|
}
|
}
|
orderBy("planstarttime")
|
}
|
|
val subTasks = mutableMapOf<String, MutableList<Problemlist>>()
|
subtaskMapper.selectByExample(subTaskExample).forEach {
|
//查询该任务对应的场景
|
val scene = scenseMapper.selectByPrimaryKey(it.scenseid)
|
|
//根据场景条件筛选
|
val need = if (config.sceneType != null) {
|
scene.typeid == config.sceneType.toByte()
|
} else {
|
true
|
}
|
if (need) {
|
val problems = mutableListOf<Problemlist>()
|
//查询子任务对应的问题,并且根据条件进行筛选
|
val problemlistExample = Example(Problemlist::class.java).apply {
|
createCriteria().andEqualTo("stguid", it.stguid).apply {
|
config.problemName?.let { p ->
|
andEqualTo("problemname", p)
|
}
|
townName?.let { t ->
|
andLike("location", "%$t%")
|
}
|
}
|
}
|
|
problemlistMapper.selectByExample(problemlistExample).forEach problemType@{ p ->
|
val result = problemtypeMapper.selectByPrimaryKey(p.ptguid)
|
if (config.problemTypeName != null) {
|
if (result.typename != config.problemTypeName) {
|
return@problemType
|
}
|
}
|
problems.add(p)
|
}
|
|
if (problems.isNotEmpty()) {
|
subTasks[it.name ?: "未知任务"] = problems
|
}
|
}
|
}
|
|
//建立第一层目录,包含所有的任务
|
val time = DateUtil().DateToString(Date(), "yyyy-MM-dd_HH-mm-ss")
|
var basePath = Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + "temp" + File.separator + time
|
var file = File(basePath)
|
var i = 1
|
while (file.exists() && i <= 100) {
|
basePath += "($i)"
|
file = File(basePath)
|
i++
|
}
|
if (file.exists()) {
|
FileUtil().delAllFile(basePath)
|
} else {
|
file.mkdirs()
|
}
|
//循环建立第二层目录,每个任务单独建立一个文件夹
|
subTasks.forEach {
|
|
//建立一个子任务文件夹
|
var subTaskFilePath = basePath + File.separator + it.key
|
var sFile = File(subTaskFilePath)
|
i = 1
|
while (sFile.exists() && i <= 100) {
|
subTaskFilePath += "($i)"
|
sFile = File(subTaskFilePath)
|
i++
|
}
|
if (sFile.exists()) {
|
FileUtil().delAllFile(subTaskFilePath)
|
} else {
|
sFile.mkdirs()
|
}
|
|
//循环建立第三层目录,每个问题单独建立一个文件夹
|
it.value.forEach { p ->
|
var pPath = subTaskFilePath + File.separator + p.problemname
|
var pFile = File(pPath)
|
i = 1
|
while (pFile.exists() && i <= 100) {
|
pPath += "($i)"
|
pFile = File(pPath)
|
i++
|
}
|
if (pFile.exists()) {
|
FileUtil().delAllFile(pPath)
|
} else {
|
pFile.mkdirs()
|
}
|
|
var y = 1
|
mediafileMapper.selectByExample(Example(Mediafile::class.java).apply {
|
createCriteria().andEqualTo("businessguid", p.guid)
|
}).forEach { m ->
|
val picPath = Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + m.extension1 + m.guid + ".jpg"
|
val fromFile = File(picPath)
|
val picName = p.problemname + "_" + p.location + "($y).jpg"
|
val toFile = File(pPath + File.separator + picName)
|
FileUtil().copy(fromFile, toFile)
|
y++
|
}
|
}
|
}
|
|
response.apply {
|
setHeader("Content-Disposition", "attachment;filename=$time.zip")
|
contentType = "application/octet-stream"
|
characterEncoding = StandardCharsets.UTF_8.name()
|
}
|
|
val zipFile = File("$basePath.zip")
|
val fos1 = FileOutputStream(zipFile)
|
ZipUtils.toZip(basePath, fos1, true)
|
|
val out = response.outputStream
|
val fis = FileInputStream(zipFile)
|
|
val buf = ByteArray(2 * 1024)
|
var len = fis.read(buf)
|
while (len != -1) {
|
out.write(buf, 0, len)
|
len = fis.read(buf)
|
}
|
out.flush()
|
out.close()
|
fis.close()
|
|
return response
|
}
|
|
override fun downloadPic2(
|
sceneType: Int,
|
topTaskId: String,
|
response: HttpServletResponse
|
): HttpServletResponse {
|
//建立第一层目录,包含所有的任务
|
val topTask = taskMapper.selectByPrimaryKey(topTaskId)
|
val time = DateUtil().DateToString(Date(), "yyyy-MM-dd_HH-mm-ss")
|
val basePath = Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + "temp" + File.separator + topTask.name
|
val file = File(basePath)
|
if (!file.exists()) {
|
file.mkdirs()
|
//循环建立第二层目录,每个任务单独建立一个文件夹
|
val subtaskList = subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
|
createCriteria().andEqualTo("tguid", topTaskId)
|
})
|
var i: Int
|
subtaskList.forEach {
|
|
scenseMapper.selectByPrimaryKey(it.scenseid).run {
|
if (typeid != sceneType.toByte()) {
|
return@forEach
|
}
|
}
|
|
//建立一个子任务文件夹
|
var subTaskFilePath = "${basePath}${File.separator}(${
|
dateUtil.DateToString(
|
it.planstarttime,
|
DateUtil.DateStyle.YYYY_MM_DD_CN
|
)
|
})(${it.deployerrealname})${it.scensename}"
|
var sFile = File(subTaskFilePath)
|
i = 1
|
while (sFile.exists() && i <= 100) {
|
subTaskFilePath += "($i)"
|
sFile = File(subTaskFilePath)
|
i++
|
}
|
if (sFile.exists()) {
|
FileUtil().delAllFile(subTaskFilePath)
|
} else {
|
sFile.mkdirs()
|
}
|
|
inspectionMapper.selectByExample(Example(Inspection::class.java).apply {
|
createCriteria().andEqualTo("stguid", it.stguid)
|
}).forEach { ins ->
|
val fileMap = mutableMapOf<String, MutableList<Mediafile>>()
|
mediafileMapper.selectByExample(Example(Mediafile::class.java).apply {
|
createCriteria().andEqualTo("iguid", ins.guid)
|
}).forEach { m ->
|
val key = m.businesstype ?: "未分类"
|
if (!fileMap.containsKey(key)) {
|
fileMap[key] = mutableListOf()
|
}
|
fileMap[key]?.add(m)
|
}
|
|
//循环建立第三层目录,每种类型单独建立一个文件夹
|
fileMap.forEach { t, u ->
|
var pPath = subTaskFilePath + File.separator + t
|
var pFile = File(pPath)
|
i = 1
|
while (pFile.exists() && i <= 100) {
|
pPath += "($i)"
|
pFile = File(pPath)
|
i++
|
}
|
if (pFile.exists()) {
|
FileUtil().delAllFile(pPath)
|
} else {
|
pFile.mkdirs()
|
}
|
|
u.forEach { f ->
|
val picPath =
|
Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + f.extension1 + f.guid + ".jpg"
|
val fromFile = File(picPath)
|
val picName = f.description
|
val toFile = File(pPath + File.separator + picName)
|
FileUtil().copy(fromFile, toFile)
|
}
|
}
|
}
|
}
|
}
|
|
response.apply {
|
setHeader("Content-Disposition", "attachment;filename=${topTask.name}.zip")
|
contentType = "application/octet-stream"
|
characterEncoding = StandardCharsets.UTF_8.name()
|
}
|
|
val zipFile = File("$basePath.zip")
|
|
if (!zipFile.exists()) {
|
val fos1 = FileOutputStream(zipFile)
|
ZipUtils.toZip(basePath, fos1, true)
|
}
|
|
val out = response.outputStream
|
val fis = FileInputStream(zipFile)
|
|
val buf = ByteArray(2 * 1024)
|
var len = fis.read(buf)
|
while (len != -1) {
|
out.write(buf, 0, len)
|
len = fis.read(buf)
|
}
|
out.flush()
|
out.close()
|
fis.close()
|
|
return response
|
}
|
|
override fun searchScore4JingAn(token: String, year: Int, month: Int, page: Int?, perPage: Int?): BaseResponse<List<ScoreVo>> {
|
if (token != "jingan") {
|
return BaseResponse(false)
|
}
|
|
val pn = page ?: 1
|
val ps = perPage ?: 100
|
val p = PageHelper.startPage<Score>(pn, ps)
|
|
val result = mutableListOf<ScoreVo>()
|
|
scoreMapper.selectByExample(Example(Score::class.java).apply {
|
createCriteria().andEqualTo("districtCode", "310106")
|
.andEqualTo("year", year).andEqualTo("month", month)
|
}).forEach {
|
val vo = ScoreVo()
|
BeanUtils.copyProperties(it, vo)
|
result.add(vo)
|
}
|
|
return BaseResponse(true, head = DataHead(p.pageNum, p.pages), data = result)
|
}
|
|
|
|
private fun getTableTitles(): List<String> = listOf(
|
"序号", "任务", "场景", "经度", "纬度",
|
"类型",
|
"开始时间", "结束时间",
|
"状态", "组长",
|
"组员", "问题类型","问题详情", "街镇", "审核"
|
)
|
|
/**
|
* 相比于getTableContents() ,删减了部分列
|
*/
|
private fun getTableTitles2(): List<String> = listOf(
|
// "序号",
|
"任务",
|
// "场景", "经度", "纬度",
|
"类型",
|
"开始时间",
|
// "结束时间",
|
"状态", "组长",
|
"组员", "问题类型","问题详情", "街镇", "审核"
|
)
|
|
private fun getTableContents(config: ExcelConfigVo): List<Array<Any>> {
|
val townName = if (config.townCode == null) {
|
null
|
} else {
|
val l = townMapper.selectByExample(Example(Town::class.java).apply {
|
createCriteria().andEqualTo("towncode", config.townCode)
|
})
|
if (l.isNotEmpty()) {
|
l[0].townname
|
} else {
|
null
|
}
|
}
|
val subTaskExample = Example(Subtask::class.java).apply {
|
if (config.subTaskIdList != null && config.subTaskIdList.isNotEmpty()) {
|
createCriteria().apply {
|
config.subTaskIdList.forEach {
|
orEqualTo("stguid", it)
|
}
|
}
|
} else {
|
createCriteria()
|
.andEqualTo("tguid", config.topTaskGuid)
|
.andGreaterThanOrEqualTo("planstarttime", config.startTime)
|
.andLessThanOrEqualTo("planendtime", config.endTime).apply {
|
config.provinceCode?.let {
|
andEqualTo("provincecode", it)
|
}
|
config.cityCode?.let {
|
andEqualTo("citycode", it)
|
}
|
config.districtCode?.let {
|
andEqualTo("districtcode", it)
|
}
|
// config.townCode?.let {
|
// andEqualTo("towncode", it)
|
// }
|
}
|
}
|
orderBy("planstarttime")
|
}
|
|
val contents = mutableListOf<Array<Any>>()
|
|
val subTasks = mutableListOf<Subtask>()
|
var i = 1
|
subtaskMapper.selectByExample(subTaskExample).forEach {
|
//查询该任务对应的场景
|
val scene = scenseMapper.selectByPrimaryKey(it.scenseid)
|
|
//根据场景条件筛选
|
val need = if (config.sceneType != null) {
|
scene.typeid == config.sceneType.toByte()
|
} else {
|
true
|
}
|
if (need) {
|
//记录查询到子任务
|
subTasks.add(it)
|
|
val problemTypes = mutableListOf<String>()
|
val problems = mutableListOf<String>()
|
val districts = mutableListOf<String>()
|
val checkStatus= mutableListOf<String>()
|
|
//查询子任务对应的问题,并且根据条件进行筛选
|
val problemlistExample = Example(Problemlist::class.java).apply {
|
createCriteria().andEqualTo("stguid", it.stguid).apply {
|
config.problemName?.let {p->
|
andEqualTo("problemname", p)
|
}
|
townName?.let {t->
|
andLike("location", "%$t%")
|
}
|
}
|
}
|
|
var y=1
|
problemlistMapper.selectByExample(problemlistExample).forEach problemType@{p->
|
val result = problemtypeMapper.selectByPrimaryKey(p.ptguid)
|
if (config.problemTypeName != null) {
|
if (result.typename != config.problemTypeName) {
|
return@problemType
|
}
|
}
|
problemTypes.add(result.typename ?: "")
|
problems.add("$y、${p.problemname}")
|
districts.add(p.location ?: "")
|
val status = when (p.extension3) {
|
Constant.PROBLEM_UNCHECKED -> "未审核"
|
Constant.PROBLEM_CHECK_PASS-> "通过"
|
Constant.PROBLEM_CHECK_FAIL -> "未通过"
|
else->"未审核"
|
}
|
checkStatus.add(status)
|
y++
|
}
|
|
|
//当有问题作为筛选条件时,如果没有找到对应问题,则该次任务去除
|
if ( (config.problemTypeName != null || config.problemName != null || townName != null)
|
&& (problemTypes.isEmpty() && problems.isEmpty())) {
|
return@forEach
|
}
|
|
val rowContent = arrayOf<Any>(
|
"$i", it.name ?: "", it.scensename ?: "", scene.longitude.toString(), scene.latitude.toString(),
|
scene.type ?: "",
|
DateUtil().DateToString(it.executionstarttime, "yyyy-MM-dd HH:mm:ss") ?: "", DateUtil().DateToString(it.executionendtime, "yyyy-MM-dd hh:mm:ss") ?: "",
|
it.status ?: "", it.assessorrealname?.replace("#", "、") ?: "",
|
it.executorrealtimes?.replace("#", "、") ?: "", problemTypes.toTypedArray(), problems.toTypedArray(), districts.toTypedArray(), checkStatus.toTypedArray()
|
)
|
|
contents.add(rowContent)
|
i++
|
}
|
}
|
|
return contents
|
}
|
|
/**
|
* 相比于getTableContents() ,删减了部分列
|
*/
|
private fun getTableContents2(config: ExcelConfigVo): List<Array<Any>> {
|
val townName = if (config.townCode == null) {
|
null
|
} else {
|
val l = townMapper.selectByExample(Example(Town::class.java).apply {
|
createCriteria().andEqualTo("towncode", config.townCode)
|
})
|
if (l.isNotEmpty()) {
|
l[0].townname
|
} else {
|
null
|
}
|
}
|
val subTaskExample = Example(Subtask::class.java).apply {
|
if (config.subTaskIdList != null && config.subTaskIdList.isNotEmpty()) {
|
createCriteria().apply {
|
config.subTaskIdList.forEach {
|
orEqualTo("stguid", it)
|
}
|
}
|
} else {
|
createCriteria()
|
.andEqualTo("tguid", config.topTaskGuid)
|
.andGreaterThanOrEqualTo("planstarttime", config.startTime)
|
.andLessThanOrEqualTo("planendtime", config.endTime).apply {
|
config.provinceCode?.let {
|
andEqualTo("provincecode", it)
|
}
|
config.cityCode?.let {
|
andEqualTo("citycode", it)
|
}
|
config.districtCode?.let {
|
andEqualTo("districtcode", it)
|
}
|
// config.townCode?.let {
|
// andEqualTo("towncode", it)
|
// }
|
}
|
}
|
orderBy("planstarttime")
|
}
|
|
val contents = mutableListOf<Array<Any>>()
|
|
val subTasks = mutableListOf<Subtask>()
|
var i = 1
|
subtaskMapper.selectByExample(subTaskExample).forEach {
|
//查询该任务对应的场景
|
val scene = scenseMapper.selectByPrimaryKey(it.scenseid)
|
|
//根据场景条件筛选
|
val need = if (config.sceneType != null) {
|
scene.typeid == config.sceneType.toByte()
|
} else {
|
true
|
}
|
if (need) {
|
//记录查询到子任务
|
subTasks.add(it)
|
|
val problemTypes = mutableListOf<String>()
|
val problems = mutableListOf<String>()
|
val districts = mutableListOf<String>()
|
val checkStatus= mutableListOf<String>()
|
|
//查询子任务对应的问题,并且根据条件进行筛选
|
val problemlistExample = Example(Problemlist::class.java).apply {
|
createCriteria().andEqualTo("stguid", it.stguid).apply {
|
config.problemName?.let {p->
|
andEqualTo("problemname", p)
|
}
|
townName?.let {t->
|
andLike("location", "%$t%")
|
}
|
}
|
}
|
|
var y=1
|
problemlistMapper.selectByExample(problemlistExample).forEach problemType@{p->
|
val result = problemtypeMapper.selectByPrimaryKey(p.ptguid)
|
if (config.problemTypeName != null) {
|
if (result?.typename != config.problemTypeName) {
|
return@problemType
|
}
|
}
|
problemTypes.add(result?.typename ?: "")
|
problems.add("$y、${p.problemname}")
|
districts.add(p.location ?: "")
|
val status = when (p.extension3) {
|
Constant.PROBLEM_UNCHECKED -> "未审核"
|
Constant.PROBLEM_CHECK_PASS-> "通过"
|
Constant.PROBLEM_CHECK_FAIL -> "未通过"
|
else->"未审核"
|
}
|
checkStatus.add(status)
|
y++
|
}
|
|
|
//当有问题作为筛选条件时,如果没有找到对应问题,则该次任务去除
|
if ( (config.problemTypeName != null || config.problemName != null || townName != null)
|
&& (problemTypes.isEmpty() && problems.isEmpty())) {
|
return@forEach
|
}
|
|
// val lineMaxSize =3
|
//
|
// val leader = it.assessorrealname?.split("#")
|
// val leaderStr = StringBuilder()
|
// for (t in 0 until (leader?.size ?: 0)) {
|
// if (t > 0) {
|
// leaderStr.append("、")
|
// }
|
// if (t == lineMaxSize - 1) {
|
// leaderStr.append("\r\n")
|
// }
|
// leaderStr.append(leader?.get(t))
|
// }
|
//
|
// val member = it.executorrealtimes?.split("#")
|
// val memberStr = StringBuilder()
|
// for (t in 0 until (member?.size ?: 0)) {
|
// if (t > 0) {
|
// memberStr.append("、")
|
// }
|
// if (t == lineMaxSize - 1) {
|
// memberStr.append("\r\n")
|
// }
|
// memberStr.append(member?.get(t))
|
// }
|
|
val rowContent = arrayOf<Any>(
|
// "$i",
|
it.name ?: "",
|
// it.scensename ?: "", scene.longitude.toString(), scene.latitude.toString(),
|
scene.type ?: "",
|
DateUtil().DateToString(it.executionstarttime, "yyyy-MM-dd HH:mm:ss") ?: "",
|
// DateUtil().DateToString(it.executionendtime, "yyyy-MM-dd hh:mm:ss") ?: "",
|
it.status ?: "", it.assessorrealname?.replace("#", "、") ?: "",
|
it.executorrealtimes?.replace("#", "、") ?: "", problemTypes.toTypedArray(), problems.toTypedArray(), districts.toTypedArray(), checkStatus.toTypedArray()
|
)
|
|
contents.add(rowContent)
|
i++
|
}
|
}
|
|
return contents
|
}
|
|
override fun searchSubTaskByKeyword(userId: String, keyword: String, page: Int, perPage: Int): BaseResponse<List<SubtaskVo>> {
|
val userInfo = userinfoMapper.selectByPrimaryKey(userId)
|
if (userInfo.usertypeid?.toInt() == 3) return BaseResponse(false, "企业用户无查询权限")//企业用户无法查询
|
val result = mutableListOf<SubtaskVo>()
|
val pageInfo = PageHelper.startPage<Subtask>(page, perPage)
|
subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
|
createCriteria().andLike("name", "%${keyword}%")
|
.apply {
|
when (userInfo.usertypeid?.toInt()) {
|
0 -> {} //管理员用户查询无其他限制
|
1 -> andLike("executorguids", "%${userId}%")//对于一般的巡查人员,只能查询到自己参与的子任务
|
2 -> andEqualTo("districtcode", userInfo.dGuid)//此处对于政府用户,dGuid存储的是区县编号
|
}
|
}
|
orderBy("planstarttime").desc()
|
}).forEach {
|
val vo = SubtaskVo()
|
BeanUtils.copyProperties(it, vo)
|
result.add(vo)
|
}
|
|
return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages) ,data = result)
|
}
|
}
|