package com.flightfeather.uav.lightshare.service.impl
|
|
import com.flightfeather.uav.domain.entity.Assessment
|
import com.flightfeather.uav.domain.entity.Company
|
import com.flightfeather.uav.domain.mapper.AssessmentMapper
|
import com.flightfeather.uav.domain.mapper.CompanyMapper
|
import com.flightfeather.uav.domain.mapper.ComplaintMapper
|
import com.flightfeather.uav.lightshare.bean.*
|
import com.flightfeather.uav.lightshare.service.CompanyService
|
import com.flightfeather.uav.lightshare.service.RealTimeDataService
|
import com.flightfeather.uav.model.BaseModel
|
import com.flightfeather.uav.model.epw.EPWModel
|
import org.springframework.beans.BeanUtils
|
import org.springframework.stereotype.Service
|
import tk.mybatis.mapper.entity.Example
|
|
@Service
|
class CompanyServiceImpl(
|
private val companyMapper: CompanyMapper,
|
private val realTimeDataService: RealTimeDataService,
|
private val complaintMapper: ComplaintMapper,
|
private val assessmentMapper: AssessmentMapper
|
) : CompanyService {
|
|
|
override fun getCompanyInfo(): BaseResponse<List<Company>> {
|
val result = companyMapper.selectAll()
|
return BaseResponse(true, data = result)
|
}
|
|
override fun getCompany(cId: String): BaseResponse<Company> {
|
companyMapper.selectByPrimaryKey(cId)?.let {
|
return BaseResponse(true, data = it)
|
}
|
return BaseResponse(false, "企业id不存在")
|
}
|
|
override fun getEpwModelResult(
|
deviceCode: String,
|
startTime: String,
|
endTime: String,
|
companyIds: List<String>?
|
): BaseResponse<MutableMap<String, MutableMap<String, MutableMap<String, BaseModel.ResultCell>>>> {
|
val company = if (companyIds == null) {
|
companyMapper.selectAll()
|
} else {
|
companyMapper.selectByExample(Example(Company::class.java).apply {
|
createCriteria().apply {
|
companyIds.forEach { orEqualTo("ciGuid", it) }
|
}
|
})
|
}
|
val companySOPList = mutableListOf<CompanySOP>()
|
company.forEach {
|
val companySOP = CompanySOP(it.ciGuid, it.ciName, it.ciExtension1)
|
BeanUtils.copyProperties(it, companySOP)
|
companySOPList.add(companySOP)
|
}
|
|
val epwModel = EPWModel()
|
// TODO: 2021/7/6 部分设备是固定点监测设备,不会移动,因此数据中没有经纬度,需要额外设置监测点经纬度
|
// epwModel.defaultLocation =
|
|
var page = 1
|
var totalPage = -1
|
while (totalPage == -1 || page <= totalPage) {
|
realTimeDataService.getSecondData(deviceCode, startTime, endTime, 0, page, 5000).apply {
|
if (totalPage == -1) {
|
totalPage = head?.totalPage ?: 0
|
}
|
val dataList = data ?: emptyList()
|
|
// FIXME: 2021/7/13 此处为了测试暂时将站点经纬度写死,后续通过数据库配置获取
|
dataList.forEach {
|
if (it.lng == 0.0 && it.lat == 0.0) {
|
it.lng = 121.235813
|
it.lat = 30.835898
|
}
|
}
|
|
epwModel.execute(dataList, companySOPList, true)
|
page++
|
}
|
}
|
val r = epwModel.outputResult()
|
return BaseResponse(true, data = r)
|
}
|
|
override fun getComplaintInfo(): BaseResponse<List<ComplaintVo>> {
|
val map = mutableMapOf<String, ComplaintVo>()
|
complaintMapper.getComplaintInfo().apply { percent() }.forEach {
|
if (!map.containsKey(it.ciGuid)) {
|
map[it.ciGuid] = ComplaintVo(it.ciGuid, it.ciName, it.ciLng.toDouble(), it.ciLat.toDouble(), it.ciIndex.toIntOrNull() ?: 0, it.ciAddress)
|
}
|
map[it.ciGuid]?.result?.add(ComplaintType(it.coType, it.coTypeName, it.count.toInt(), it.percent))
|
}
|
return BaseResponse(true, data = map.values.toList())
|
}
|
|
override fun getAssessment(): BaseResponse<List<AssessmentVo>> {
|
val result = assessmentMapper.getAssessment()
|
return BaseResponse(true, data = result)
|
}
|
}
|