feiyu02
2024-07-19 4e20a1aaaba1bb843820fca844c20055a33febce
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
package cn.flightfeather.supervision.lightshare.service.impl
 
import cn.flightfeather.supervision.domain.ds1.entity.Problemtype
import cn.flightfeather.supervision.domain.ds1.mapper.ProblemtypeMapper
import cn.flightfeather.supervision.lightshare.service.ProblemtypeService
import cn.flightfeather.supervision.lightshare.vo.ProblemDetailVo
import cn.flightfeather.supervision.lightshare.vo.ProblemtypeVo
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
import tk.mybatis.mapper.util.StringUtil
 
@Service
class ProblemtypeServiceImpl(val problemtypeMapper: ProblemtypeMapper) : ProblemtypeService {
    //根据problemtype信息查询问题类别
    override fun search(problemtype: Problemtype): List<ProblemtypeVo> {
        val problemtypeVos = mutableListOf<ProblemtypeVo>()
        val name = problemtype.name ?: ""
        val example = Example(Problemtype::class.java)
        val criteria = example.createCriteria()
        if (StringUtil.isNotEmpty(problemtype.typename)) {
            criteria.andEqualTo("typename", problemtype.typename)
        }
        criteria.andLike("name", "%$name%")
        val re = problemtypeMapper.selectByExample(example)
        if (re.isNotEmpty()) {
            re.forEach {
                val problemtypeVo = ProblemtypeVo()
                BeanUtils.copyProperties(it, problemtypeVo)
                problemtypeVos.add(problemtypeVo)
            }
        }
        return problemtypeVos
    }
 
    //根据问题类别名称查询
    override fun findOneByName(name: String): Problemtype {
        val problemtype = Problemtype()
        problemtype.name = name
        val re = problemtypeMapper.select(problemtype)
        if (re.isNotEmpty()) {
            BeanUtils.copyProperties(re[0], problemtype)
        }
        return problemtype
    }
 
    override fun findOne(id: String): Problemtype = problemtypeMapper.selectByPrimaryKey(id)
 
    override fun findAll(): MutableList<Problemtype> = problemtypeMapper.selectAll()
 
    override fun save(problemtype: Problemtype): Int = problemtypeMapper.insert(problemtype)
 
    override fun update(problemtype: Problemtype): Int = problemtypeMapper.updateByPrimaryKey(problemtype)
 
    override fun delete(id: String): Int = problemtypeMapper.deleteByPrimaryKey(id)
 
    override fun getBySceneType(sceneTypeId: Int, districtCode: String): List<ProblemDetailVo> {
        val resultList = mutableListOf<ProblemDetailVo>()
 
        val map = mutableMapOf<String, MutableList<String>>()
        problemtypeMapper.selectByExample(Example(Problemtype::class.java).apply {
            createCriteria().andEqualTo("scensetypeid", sceneTypeId.toByte())
                .andEqualTo("districtcode", districtCode)
        }).forEach {
            if (!map.containsKey(it.typename)) {
                map[it.typename ?: ""] = mutableListOf()
            }
            map[it.typename]?.add(it.description ?: "")
        }
 
        map.forEach {
            resultList.add(ProblemDetailVo(it.key, it.value))
        }
 
        return resultList
    }
 
    override fun search(taskTypeId: Byte, cityCode: String, districtCode: String, sceneTypeId: Byte): List<Problemtype> {
        val result = problemtypeMapper.selectByExample(Example(Problemtype::class.java).apply {
            createCriteria().andEqualTo("tasktypeid", taskTypeId)
                .andEqualTo("citycode", cityCode)
                .andEqualTo("districtcode", districtCode)
                .andEqualTo("scensetypeid", sceneTypeId)
            orderBy("typeid")
        })
 
        return result
    }
}