feiyu02
2022-10-21 f22c4b9230808fed4fec80c435eccb4c833349a0
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.Law
import cn.flightfeather.supervision.domain.entity.LawsRegulations
import cn.flightfeather.supervision.domain.enumeration.SceneType
import cn.flightfeather.supervision.domain.mapper.LawMapper
import cn.flightfeather.supervision.domain.mapper.LawsRegulationsMapper
import cn.flightfeather.supervision.lightshare.service.LawService
import cn.flightfeather.supervision.lightshare.vo.LawVo
import cn.flightfeather.supervision.lightshare.vo.LawsRegulationsCondition
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
import javax.servlet.http.HttpServletResponse
 
@Service
class LawServiceImpl(val lawMapper: LawMapper, val lawsRegulationsMapper: LawsRegulationsMapper) : LawService {
 
    override fun getLaws(page: Int, per_page: Int, response: HttpServletResponse): ArrayList<LawVo> {
        val counts = lawMapper.selectCountByExample(Example(Law::class.java))
        val totalPage = Math.ceil(counts.toDouble() / per_page.toDouble()).toInt()
        response.setIntHeader("totalPage", totalPage)
        response.setIntHeader("currentPage", page)
 
        val laws = lawMapper.selectAll()
        val resultList = ArrayList<LawVo>()
        laws.forEach {
            val l = LawVo().apply {
                id = it.laGuid
                authorId = it.laAuthorid
                authorName = it.laAuthorname
                typeId = it.laTypeid
                typeName = it.laTypename
                title = it.laTitle
                abstract = it.laAbstract
                picUrl = it.laPicurl
                bodyUrl = it.laBodyurl
            }
            resultList.add(l)
        }
        return if (page == 1) {
            resultList
        } else {
            ArrayList()
        }
    }
 
    override fun getLawText(lawId: String): String {
        val law = lawMapper.selectByPrimaryKey(lawId)
        return law.laText
    }
 
    override fun getLawsRegulations(
            condition: LawsRegulationsCondition, page: Int, per_page: Int, response: HttpServletResponse): List<LawsRegulations> {
        val example = Example(LawsRegulations::class.java).apply {
            createCriteria().apply {
                condition.apply {
                    level?.let {
                        andEqualTo("lrResourcelevel", it)
                    }
                    andEqualTo("lrIsforeign", isForeign)
                    category?.let {
                        andEqualTo("lrResourcetypeid", it)
                    }
                    keywords?.let {
                        andLike("lrKeywords", it)
                    }
                    andEqualTo("lrIsopen", isOpen)
                    andEqualTo("lrIsuse", isUsing)
                    fileType?.let {
                        andEqualTo("lrResourcefiletype", it)
                    }
                }
            }
            condition.sceneTypeId?.let {
                if (it != SceneType.NoType.value) {
                    and(
                            createCriteria().orIsNull("lrExtension1")
                                    .orLike("lrExtension1", "%$it%")
                    )
                }
            }
            orderBy("lrPublishdate").desc()
        }
 
        val counts = lawsRegulationsMapper.selectCountByExample(example)
        val totalPage = Math.ceil(counts.toDouble() / per_page.toDouble()).toInt()
        response.setIntHeader("totalPage", totalPage)
        response.setIntHeader("currentPage", page)
 
        val offset = per_page.times(page - 1)
        PageHelper.offsetPage<LawsRegulations>(offset, per_page)
 
        return lawsRegulationsMapper.selectByExample(example)
    }
 
    override fun getLawsRegulationsWithEachType(condition: LawsRegulationsCondition): List<LawsRegulations> {
        return lawsRegulationsMapper.getLawsRegulations(condition.level,
                condition.isForeign, condition.category, condition.keywords,
                condition.isOpen, condition.isUsing, condition.count, condition.sceneTypeId)
    }
 
    override fun getSeries(userId: String, seriesId: String): List<LawsRegulations> {
        return lawsRegulationsMapper.selectByExample(Example(LawsRegulations::class.java).apply {
            createCriteria().andEqualTo("lrExtension2", seriesId)
            orderBy("lrExtension3")
        })
    }
}