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
package cn.flightfeather.supervision.domain.ds1.repository
 
import cn.flightfeather.supervision.domain.ds1.entity.Task
import cn.flightfeather.supervision.domain.ds1.mapper.TaskMapper
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import org.springframework.stereotype.Repository
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.*
 
@Repository
class TaskRep(private val taskMapper: TaskMapper) {
 
    private fun exampleTask(areaVo: AreaVo): Task?{
        areaVo.starttime ?: return null
        val mStart = areaVo.starttime!!.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0)
        val mEnd = mStart.plusMonths(1).minusSeconds(1)
        return Task().apply {
            provincecode = areaVo.provincecode
            citycode = areaVo.citycode
            districtcode = areaVo.districtcode
            starttime = Date.from(mStart.atZone(ZoneId.systemDefault()).toInstant())
            endtime = Date.from(mEnd.atZone(ZoneId.systemDefault()).toInstant())
        }
    }
    /**
     * 查找一个总任务
     */
    fun findOneTask(areaVo: AreaVo): Task? {
        val example = exampleTask(areaVo) ?: return null
        return taskMapper.selectOne(example)
    }
 
    fun findTasks(areaVo: AreaVo): List<Task?> {
        val example = exampleTask(areaVo) ?: return emptyList()
        return taskMapper.select(example)
    }
}