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)
|
}
|
}
|
}
|