riku
2021-07-12 d978297ae85b2d7453054e616bbbe87bfabe9cbe
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/CompanyServiceImpl.kt
@@ -3,14 +3,71 @@
import com.flightfeather.uav.domain.entity.Company
import com.flightfeather.uav.domain.mapper.CompanyMapper
import com.flightfeather.uav.lightshare.bean.BaseResponse
import com.flightfeather.uav.lightshare.bean.CompanySOP
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) : CompanyService {
class CompanyServiceImpl(
    private val companyMapper: CompanyMapper, private val realTimeDataService: RealTimeDataService) : 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, page, 5000).apply {
                if (totalPage == -1) {
                    totalPage = head?.totalPage ?: 0
                }
                val dataList = data?: emptyList()
                epwModel.execute(dataList, companySOPList, true)
                page++
            }
        }
        val r = epwModel.outputResult()
        return BaseResponse(true, data = r)
    }
}