feiyu02
2024-08-15 196bb14112448857a885e32dc4149e308e00b01a
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
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.Company
import cn.flightfeather.supervision.domain.mapper.BaseInfoMapper
import cn.flightfeather.supervision.domain.mapper.CompanyMapper
import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator
import cn.flightfeather.supervision.lightshare.service.CompanyService
import cn.flightfeather.supervision.lightshare.vo.BaseResponse
import org.springframework.stereotype.Service
 
@Service
class CompanyServiceImpl(
    private val companyMapper: CompanyMapper,
    private val baseInfoMapper: BaseInfoMapper,
) : CompanyService {
 
    override fun findOne(id: String): BaseResponse<Company> {
        val res = companyMapper.selectByPrimaryKey(id) ?: return BaseResponse(false, "用户id不存在")
        return BaseResponse(true, data = res)
    }
 
    override fun save(userId: String, info: Company): BaseResponse<Int> {
        if (info.ciGuid != null) return BaseResponse(false, "用户企业主键不能自行创建")
        val baseInfo = baseInfoMapper.selectByPrimaryKey(userId) ?: return BaseResponse(false, "创建公司信息之前请先创建用户基本信息")
        info.ciGuid = UUIDGenerator.generate16ShortUUID()
        baseInfo.ciGuid = info.ciGuid
        baseInfo.ciName = info.ciName
        baseInfoMapper.updateByPrimaryKeySelective(baseInfo)
        val res = companyMapper.insert(info)
        return if (res == 1) {
            BaseResponse(true, data = res)
        } else {
            BaseResponse(false, "插入数据库失败", data = res)
        }
    }
 
    override fun update(userId: String, info: Company): BaseResponse<Int> {
        val baseInfo = baseInfoMapper.selectByPrimaryKey(userId)
        if (baseInfo.ciGuid == info.ciGuid) {
            baseInfo.ciName = info.ciName
            baseInfoMapper.updateByPrimaryKeySelective(baseInfo)
        }
        val res = companyMapper.updateByPrimaryKeySelective(info)
        return if (res == 1) {
            BaseResponse(true, data = res)
        } else {
            BaseResponse(false, "更新数据库失败", data = res)
        }
    }
}