feiyu02
2024-11-19 752e00503f672ddfe2066afb6c235721a3a912b5
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
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.BaseInfo
import cn.flightfeather.supervision.domain.mapper.BaseInfoMapper
import cn.flightfeather.supervision.domain.mapper.UserinfoMapper
import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator
import cn.flightfeather.supervision.lightshare.service.BaseInfoService
import cn.flightfeather.supervision.lightshare.vo.BaseInfoVo
import cn.flightfeather.supervision.lightshare.vo.BaseResponse
import cn.flightfeather.supervision.lightshare.vo.DataHead
import cn.flightfeather.supervision.lightshare.vo.UserSearchCondition
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Service
import java.util.*
 
@Service
class BaseInfoServiceImpl(
    private val baseInfoMapper: BaseInfoMapper,
    private val userinfoMapper: UserinfoMapper,
) : BaseInfoService {
 
    override fun findOne(id: String): BaseResponse<BaseInfo> {
        val res = baseInfoMapper.selectByPrimaryKey(id) ?: return BaseResponse(false, "用户id不存在")
        return BaseResponse(true, data = res)
    }
 
    override fun save(info: BaseInfo): BaseResponse<Int> {
        if (info.biGuid == null) return BaseResponse(false, "用户主键不能为空")
        baseInfoMapper.selectByPrimaryKey(info.biGuid)?.run { return BaseResponse(false, "用户基本信息不能重复创建") }
        userinfoMapper.selectByPrimaryKey(info.biGuid) ?: return BaseResponse(false, "该用户id账号不存在")
        info.biCreateTime = Date()
        info.biUpdateTime = info.biCreateTime
        val res = baseInfoMapper.insert(info)
        return if (res == 1) {
            BaseResponse(true, data = res)
        } else {
            BaseResponse(false, "插入数据库失败", data = res)
        }
    }
 
    override fun update(info: BaseInfo): BaseResponse<Int> {
        info.biUpdateTime = Date()
        val res = baseInfoMapper.updateByPrimaryKeySelective(info)
        return if (res == 1) {
            BaseResponse(true, data = res)
        } else {
            BaseResponse(false, "更新数据库失败", data = res)
        }
    }
 
    override fun searchUser(condition: UserSearchCondition, page: Int, perPage: Int,): BaseResponse<List<BaseInfoVo?>> {
        val p = PageHelper.startPage<BaseInfoVo>(page, perPage)
        baseInfoMapper.searchUser(condition)
        return BaseResponse(true, head = DataHead(p.pageNum, p.pages, p.total), data = p.result)
    }
}