riku
2021-07-12 d978297ae85b2d7453054e616bbbe87bfabe9cbe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.flightfeather.uav.lightshare.service.impl
 
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, 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)
    }
}