package cn.flightfeather.supervision.lightshare.service.Impl
|
|
import cn.flightfeather.supervision.domain.entity.Userinfo
|
import cn.flightfeather.supervision.domain.enumeration.SceneType
|
import cn.flightfeather.supervision.domain.mapper.*
|
import cn.flightfeather.supervision.infrastructure.utils.FileUtil
|
import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator
|
import cn.flightfeather.supervision.lightshare.service.UserinfoService
|
import cn.flightfeather.supervision.lightshare.vo.*
|
import com.github.pagehelper.PageHelper
|
import org.springframework.beans.BeanUtils
|
import org.springframework.stereotype.Service
|
import org.springframework.web.multipart.MultipartFile
|
import tk.mybatis.mapper.entity.Example
|
import javax.servlet.http.HttpServletResponse
|
|
@Service
|
class UserinfoServiceImpl(
|
val userinfoMapper: UserinfoMapper,
|
val baseInfoMapper: BaseInfoMapper,
|
val companyMapper: CompanyMapper,
|
val restaurantBaseInfoMapper: RestaurantBaseInfoMapper,
|
val vehicleBaseInfoMapper: VehicleBaseInfoMapper,
|
val userMapMapper: UserMapMapper
|
) : UserinfoService {
|
|
//根据userinfo条件查询
|
override fun findOneByName(userinfo: Userinfo): Userinfo {
|
val example = Example(Userinfo::class.java)
|
val criteria = example.createCriteria()
|
criteria.andEqualTo("acountname", userinfo.acountname)
|
val result = userinfoMapper.selectByExample(example)
|
return if (result.isNotEmpty()) {
|
result[0]
|
} else {
|
Userinfo()
|
}
|
}
|
|
override fun findOne(id: String): Userinfo{
|
val userInfo = userinfoMapper.selectByPrimaryKey(id)
|
userMapMapper.selectByPrimaryKey(id)?.let {
|
userInfo?.extension3 = it.svUserId
|
}
|
return userInfo ?: Userinfo()
|
}
|
|
override fun findAll(): MutableList<Userinfo> = userinfoMapper.selectAll()
|
|
override fun save(userinfo: Userinfo): Int = userinfoMapper.insert(userinfo)
|
|
override fun update(userinfo: Userinfo): Int = userinfoMapper.updateByPrimaryKeySelective(userinfo)
|
|
override fun delete(id: String): Int = userinfoMapper.deleteByPrimaryKey(id)
|
|
override fun login(loginRequestVo: LoginRequestVo): AccessToken {
|
val example = Example(Userinfo::class.java)
|
val criteria = example.createCriteria()
|
criteria.andEqualTo("acountname", loginRequestVo.userName)
|
.andEqualTo("password",loginRequestVo.password)
|
val result = userinfoMapper.selectByExample(example)
|
return AccessToken().apply {
|
if (result.isNotEmpty()) {
|
userId = result[0].guid
|
val sUser = userMapMapper.selectByPrimaryKey(userId)
|
sUserId = sUser?.svUserId
|
success = true
|
} else {
|
success = false
|
}
|
}
|
}
|
|
override fun register(loginRequestVo: LoginRequestVo): AccessToken {
|
val example = Example(Userinfo::class.java)
|
val criteria = example.createCriteria()
|
criteria.andEqualTo("acountname", loginRequestVo.userName)
|
val result = userinfoMapper.selectByExample(example)
|
if (result.isNotEmpty()) {
|
return AccessToken().apply { success = false }
|
} else {
|
val userInfo = Userinfo().apply {
|
guid = UUIDGenerator.generate16ShortUUID()
|
acountname = loginRequestVo.userName
|
realname = loginRequestVo.userName
|
password = loginRequestVo.password
|
usertypeid = 3
|
usertype = "企业"
|
isenable = true
|
}
|
save(userInfo)
|
return AccessToken().apply {
|
userId = userInfo.guid
|
success = true
|
}
|
}
|
}
|
|
override fun getAddressBook(userId: String): List<FriendVo> {
|
val resultList = mutableListOf<FriendVo>()
|
val userInfo = findOne(userId)
|
userinfoMapper.selectByExample(Example(Userinfo::class.java).apply {
|
createCriteria().andEqualTo("extension1", userInfo.extension1)
|
.andGreaterThanOrEqualTo("usertypeid", userInfo.usertypeid)
|
})
|
.forEach {
|
val groupName = if (it.extension1.isNullOrEmpty()){
|
"未分组"
|
} else {
|
"${it.extension1!!}-${it.usertype}-${SceneType.getNameByValue(it.extension2?.toInt() ?: -1)}"
|
}
|
val friend = if (it.guid != userId) {
|
FriendVo(groupName)
|
} else {
|
FriendVo("我")
|
}
|
BeanUtils.copyProperties(it, friend)
|
if (it.guid == userId) {
|
resultList.add(0, friend)
|
} else {
|
resultList.add(friend)
|
}
|
}
|
return resultList
|
}
|
|
override fun upLoadAccountPic(userId: String, files: Array<MultipartFile>): String {
|
if (files.isNotEmpty()) {
|
val file = files[0]
|
val fileName = files[0].originalFilename
|
val basePath = "D:/02product/05ledger/images/"
|
val path = "accounts/$userId/"
|
try {
|
//调用文件保存方法
|
FileUtil().uploadFile(file.bytes, basePath + path, fileName!!)
|
} catch (e: Exception) {
|
e.printStackTrace()
|
}
|
|
val user = Userinfo().apply {
|
guid = userId
|
headIconUrl = "$path$fileName"
|
}
|
userinfoMapper.updateByPrimaryKeySelective(user)
|
return "$path$fileName"
|
} else {
|
return ""
|
}
|
}
|
|
override fun changePassword(userId: String, oldPassword: String, newPassword: String): Int {
|
val userInfo = findOne(userId)
|
return if (oldPassword != userInfo.password) {
|
0
|
} else {
|
val newUserInfo = Userinfo().apply {
|
guid = userInfo.guid
|
password = newPassword
|
}
|
update(newUserInfo)
|
}
|
}
|
|
override fun searchUser(userId: String, condition: UserSearchCondition, page: Int, perPage: Int, response: HttpServletResponse): List<Userinfo> {
|
val user = userinfoMapper.selectByPrimaryKey(userId)
|
val districtName = condition.districtName ?: user.extension1
|
|
val p = PageHelper.startPage<Userinfo>(page, perPage)
|
val result = userinfoMapper.selectByExample(Example(Userinfo::class.java).apply {
|
if (condition.searchText.isNotBlank()) {
|
and(createCriteria()
|
.orLike("acountname", "%${condition.searchText}%")
|
.orLike("realname", "%${condition.searchText}%")
|
)
|
}
|
if (condition.sceneTypes.isNotEmpty()) {
|
and(createCriteria().apply {
|
condition.sceneTypes.forEach {
|
orEqualTo("extension2", it)
|
}
|
})
|
}
|
and(createCriteria().andEqualTo("extension1", districtName)
|
.andEqualTo("isenable", true))
|
//todo 2020.8.19 街镇的条件查询需要扩充BaseInfo数据表字段后再实现
|
})
|
|
response.setIntHeader("totalPage", p.pages)
|
response.setIntHeader("currentPage", p.pageNum)
|
|
return result
|
}
|
|
override fun getBaseInfo(userId: String): UserBaseInfo {
|
val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return UserBaseInfo(userId)
|
val baseInfo = baseInfoMapper.selectByPrimaryKey(userId) ?: return UserBaseInfo(userId)
|
|
val mapper = when (userInfo.extension2) {
|
SceneType.Restaurant.value.toString() -> restaurantBaseInfoMapper
|
SceneType.VehicleRepair.value.toString() -> vehicleBaseInfoMapper
|
else -> restaurantBaseInfoMapper
|
}
|
|
val specialInfo = mapper.selectByPrimaryKey(baseInfo.biGuid)
|
val companyInfo = companyMapper.selectByPrimaryKey(baseInfo.ciGuid)
|
|
return UserBaseInfo(userId, userInfo.realname, baseInfo, companyInfo, specialInfo)
|
}
|
}
|