riku
2022-06-17 3a5c011d9509d3bc0367921f463676c81ff2e374
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
74
75
76
77
78
79
package cn.flightfeather.supervision.lightshare.service.impl
 
import cn.flightfeather.supervision.domain.ds1.entity.NightConstruction
import cn.flightfeather.supervision.domain.ds1.mapper.NightConstructionMapper
import cn.flightfeather.supervision.domain.ds1.mapper.UserinfoMapper
import cn.flightfeather.supervision.lightshare.service.NightConstructionService
import cn.flightfeather.supervision.lightshare.vo.BaseResponse
import cn.flightfeather.supervision.lightshare.vo.DataHead
import cn.flightfeather.supervision.lightshare.vo.NightWorkSummary
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
 
@Service
class NightConstructionImpl(
        val nightConstructionMapper: NightConstructionMapper,
        val userinfoMapper: UserinfoMapper
) : NightConstructionService {
 
    override fun getRecord(cityCode: String?, districtCode: String, page: Int, perPage: Int): BaseResponse<List<NightConstruction?>> {
        val p = PageHelper.startPage<NightConstruction>(page, perPage)
        val result = nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
            createCriteria().andEqualTo("ncCityCode", cityCode ?: "3100")
                    .andEqualTo("ncDistrictCode", districtCode)
            orderBy("ncRead").orderBy("ncId").desc()
        })
        return BaseResponse(true, head = DataHead(p.pageNum, p.pages), data = result)
    }
 
    override fun getNightWorkFile(userId: String, isRead: Boolean?, page: Int, perPage: Int): BaseResponse<List<NightConstruction?>> {
        val userInfo = userinfoMapper.selectByPrimaryKey(userId)
        val p = PageHelper.startPage<NightConstruction>(page, perPage)
        val result = nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
            createCriteria().orEqualTo("ncUserId", userId)
                    .orEqualTo("ncSceneId", userInfo.dGuid)
            and(createCriteria().apply {
                isRead?.let {
                    if (isRead) {
                        andEqualTo("ncRead", true)
                    } else {
                        orEqualTo("ncRead", false)
                                .orIsNull("ncRead")
                    }
                }
            })
            orderBy("ncCreateTime").desc()
        })
 
        return BaseResponse(true, head = DataHead(p.pageNum, p.pages), data = result)
    }
 
    override fun signFile(userId: String, fileNum: String, id: Int): BaseResponse<Int> {
        val record = nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
            createCriteria().andEqualTo("ncId", id)
                    .andEqualTo("ncNum", fileNum)
                    .andEqualTo("ncUserId", userId)
        })
        return if (record.isNotEmpty()) {
            record[0]?.ncRead = true
            val result = nightConstructionMapper.updateByPrimaryKey(record[0])
            BaseResponse(true, data = result)
        } else {
            BaseResponse(false, "夜间许可证记录不存在")
        }
    }
 
    override fun getSummary(cityCode: String?, districtCode: String): BaseResponse<NightWorkSummary> {
        val total = nightConstructionMapper.selectCountByExample(Example(NightConstruction::class.java).apply {
            createCriteria().andEqualTo("ncCityCode", cityCode ?: "3100")
                    .andEqualTo("ncDistrictCode", districtCode)
        })
        val signed = nightConstructionMapper.selectCountByExample(Example(NightConstruction::class.java).apply {
            createCriteria().andEqualTo("ncCityCode", cityCode ?: "3100")
                    .andEqualTo("ncDistrictCode", districtCode)
                    .andEqualTo("ncRead", true)
        })
        return BaseResponse(true, data = NightWorkSummary(total, signed))
    }
}