From 752e00503f672ddfe2066afb6c235721a3a912b5 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期二, 19 十一月 2024 10:25:55 +0800 Subject: [PATCH] 2024.11.19 各项修正 --- src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/UserinfoServiceImpl.kt | 284 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 239 insertions(+), 45 deletions(-) diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/UserinfoServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/UserinfoServiceImpl.kt index 21c3102..5548748 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/UserinfoServiceImpl.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/UserinfoServiceImpl.kt @@ -1,26 +1,39 @@ package cn.flightfeather.supervision.lightshare.service.Impl -import cn.flightfeather.supervision.domain.entity.Userinfo +import cn.flightfeather.supervision.domain.entity.* import cn.flightfeather.supervision.domain.enumeration.SceneType +import cn.flightfeather.supervision.domain.enumeration.UserType import cn.flightfeather.supervision.domain.mapper.* +import cn.flightfeather.supervision.domain.repository.UserInfoRep import cn.flightfeather.supervision.infrastructure.utils.FileUtil import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator +import cn.flightfeather.supervision.domain.repository.UserConfigRep import cn.flightfeather.supervision.lightshare.service.UserinfoService import cn.flightfeather.supervision.lightshare.vo.* import com.github.pagehelper.PageHelper +import org.apache.poi.hssf.usermodel.HSSFWorkbook import org.springframework.beans.BeanUtils import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional import org.springframework.web.multipart.MultipartFile import tk.mybatis.mapper.entity.Example +import java.math.BigDecimal +import java.util.* import javax.servlet.http.HttpServletResponse @Service class UserinfoServiceImpl( - val userinfoMapper: UserinfoMapper, - val baseInfoMapper: BaseInfoMapper, - val companyMapper: CompanyMapper, - val restaurantBaseInfoMapper: RestaurantBaseInfoMapper, - val vehicleBaseInfoMapper: VehicleBaseInfoMapper + val userinfoMapper: UserinfoMapper, + val baseInfoMapper: BaseInfoMapper, + val companyMapper: CompanyMapper, + val restaurantBaseInfoMapper: RestaurantBaseInfoMapper, + val vehicleBaseInfoMapper: VehicleBaseInfoMapper, + val industrialBaseInfoMapper: IndustrialBaseInfoMapper, + val userMapMapper: UserMapMapper, + val personalInfoMapper: PersonalInfoMapper, + val userInfoWxMapper: UserInfoWxMapper, + val userInfoRep: UserInfoRep, + val userConfigRep: UserConfigRep, ) : UserinfoService { //鏍规嵁userinfo鏉′欢鏌ヨ @@ -30,31 +43,106 @@ criteria.andEqualTo("acountname", userinfo.acountname) val result = userinfoMapper.selectByExample(example) return if (result.isNotEmpty()) { - result[0] + result?.get(0) ?: Userinfo() } else { Userinfo() } } - override fun findOne(id: String): Userinfo = userinfoMapper.selectByPrimaryKey(id) + override fun findOne(id: String): Userinfo { + val userInfo = userinfoMapper.selectByPrimaryKey(id) +// userInfo?.password = null + userMapMapper.selectByPrimaryKey(id)?.let { + userInfo?.extension3 = it.svUserId + } + return userInfo ?: Userinfo() + } - override fun findAll(): MutableList<Userinfo> = userinfoMapper.selectAll() + override fun findAll(): MutableList<Userinfo?> = userinfoMapper.selectAll() - override fun save(userinfo: Userinfo): Int = userinfoMapper.insert(userinfo) + override fun save(userinfo: Userinfo): BaseResponse<Int> { + userinfoMapper.selectByPrimaryKey(userinfo.guid)?.run { return BaseResponse(false, "鐢ㄦ埛宸插瓨鍦�", data = 0) } + userinfoMapper.selectByExample(Example(Userinfo::class.java).apply { + createCriteria().andEqualTo("acountname", userinfo.acountname) + }).run { if (isNotEmpty()) return BaseResponse(false, "鐢ㄦ埛鐧诲綍璐︽埛鍚嶇О宸插瓨鍦�", data = 0) } + userinfoMapper.selectByExample(Example(Userinfo::class.java).apply { + createCriteria().andEqualTo("realname", userinfo.realname) + }).run { if (isNotEmpty()) return BaseResponse(false, "鐢ㄦ埛鏄电О宸插瓨鍦�", data = 0) } - override fun update(userinfo: Userinfo): Int = userinfoMapper.updateByPrimaryKeySelective(userinfo) + userinfo.apply { + guid = UUIDGenerator.generate16ShortUUID() + headIconUrl = "" + password = "123456" + if (isenable == null) isenable = true + uiCreateTime = Date() + } + val res = userinfoMapper.insert(userinfo) + return if (res == 1) { + BaseResponse(true, data = res) + } else { + BaseResponse(false, "鎻掑叆鏁版嵁搴撳け璐�", data = res) + } + } + + @Transactional + override fun save2(info: UserBaseInfo): BaseResponse<Int> { + info.userInfo ?: return BaseResponse(false, "鐢ㄦ埛淇℃伅缂哄け锛屾棤娉曟柊寤虹敤鎴�") + info.baseInfo ?: return BaseResponse(false, "鐢ㄦ埛淇℃伅缂哄け锛屾棤娉曟柊寤虹敤鎴�") + val repeatRes = userInfoRep.checkIsRepeat(info.userInfo) + if (repeatRes.first) return BaseResponse(false, repeatRes.second) + + info.userInfo.apply { + guid = UUIDGenerator.generate16ShortUUID() + headIconUrl = "" + password = "123456" + if (isenable == null) isenable = true + uiCreateTime = Date() + } + info.baseInfo.apply { + biGuid = info.userInfo.guid + biName = info.userInfo.realname + biCreateTime = info.userInfo.uiCreateTime + biExtension1 = info.userInfo.acountname + } + userinfoMapper.insert(info.userInfo) + baseInfoMapper.insert(info.baseInfo) + return BaseResponse(true) + } + + override fun resetPassword(userId: String): BaseResponse<Boolean> { + val info = userinfoMapper.selectByPrimaryKey(userId) ?: return BaseResponse(false, "鐢ㄦ埛涓嶅瓨鍦�") + info.password = "123456" + val r = userinfoMapper.updateByPrimaryKeySelective(info) + return BaseResponse(r == 1) + } + + override fun update(userinfo: Userinfo): BaseResponse<Int> { + val res = userinfoMapper.updateByPrimaryKeySelective(userinfo) + return if (res == 1) { + BaseResponse(true, data = res) + } else { + BaseResponse(false, "鎻掑叆鏁版嵁搴撳け璐�", data = res) + } + } override fun delete(id: String): Int = userinfoMapper.deleteByPrimaryKey(id) override fun login(loginRequestVo: LoginRequestVo): AccessToken { + if (loginRequestVo.userName.isNullOrEmpty() || loginRequestVo.password.isNullOrEmpty()) return AccessToken() val example = Example(Userinfo::class.java) val criteria = example.createCriteria() criteria.andEqualTo("acountname", loginRequestVo.userName) - .andEqualTo("password",loginRequestVo.password) + .andEqualTo("password", loginRequestVo.password) val result = userinfoMapper.selectByExample(example) return AccessToken().apply { if (result.isNotEmpty()) { - userId = result[0].guid + val u = result?.get(0) + u?.uiLoginTime = Date() + userinfoMapper.updateByPrimaryKeySelective(u) + userInfoRep.loginLog(u?.guid) + userId = u?.guid + val sUser = userMapMapper.selectByPrimaryKey(userId) + sUserId = sUser?.svUserId success = true } else { success = false @@ -87,6 +175,55 @@ } } + override fun register2(loginRequestVo: LoginRequestVo): AccessToken { + val result = userinfoMapper.selectByExample(Example(Userinfo::class.java).apply { + createCriteria().andEqualTo("realname", loginRequestVo.userName) + }) + 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 + extension2 = loginRequestVo.sceneType + } + val company = Company().apply { + ciGuid = UUIDGenerator.generate16ShortUUID() + ciName = loginRequestVo.department + ciAddress = loginRequestVo.address + ciLongitude = BigDecimal.ZERO + ciLatitude = BigDecimal.ZERO + ciOrgCode = loginRequestVo.orgCode + ciBuildDate = Date() + ciTelephone = loginRequestVo.telephone + } + val baseInfo = BaseInfo().apply { + biGuid = userInfo.guid + biName = userInfo.realname + ciGuid = company.ciGuid + ciName = company.ciName + biTelephone = loginRequestVo.telephone + biAddress + biCreateTime = Date() + biUpdateTime = Date() + biExtension1 = userInfo.acountname + } + save(userInfo) + baseInfoMapper.insert(baseInfo) + companyMapper.insert(company) + + return AccessToken().apply { + userId = userInfo.guid + success = true + } + } + } + override fun getAddressBook(userId: String): List<FriendVo> { val resultList = mutableListOf<FriendVo>() val userInfo = findOne(userId) @@ -94,24 +231,24 @@ 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)}" + .forEach { + val groupName = if (it?.extension1.isNullOrEmpty()) { + "鏈垎缁�" + } else { + "${it?.extension1!!}-${it.usertype}-${SceneType.getByValue(it.extension2?.toInt() ?: -1).des}" + } + 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) + } } - 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 } @@ -123,7 +260,7 @@ val path = "accounts/$userId/" try { //璋冪敤鏂囦欢淇濆瓨鏂规硶 - FileUtil().uploadFile(file.bytes, basePath + path, fileName!!) + FileUtil.uploadFile(file.bytes, basePath + path, fileName!!) } catch (e: Exception) { e.printStackTrace() } @@ -139,29 +276,38 @@ } } - override fun changePassword(userId: String, oldPassword: String, newPassword: String): Int { + override fun changePassword(userId: String, oldPassword: String, newPassword: String): BaseResponse<String> { + if (newPassword.trim() == "") return BaseResponse(false, "鏂板瘑鐮佷笉鑳戒负绌�") + if (oldPassword == newPassword) return BaseResponse(false, "鏂板瘑鐮佷笉鑳藉拰鍘熷瘑鐮佺浉鍚�") + val userInfo = findOne(userId) return if (oldPassword != userInfo.password) { - 0 + BaseResponse(false, "鍘熷瘑鐮侀敊璇�") } else { val newUserInfo = Userinfo().apply { guid = userInfo.guid password = newPassword + remark = "pwChanged" } update(newUserInfo) + BaseResponse(true, "瀵嗙爜淇敼鎴愬姛") } } - override fun searchUser(userId: String, condition: UserSearchCondition, page: Int, perPage: Int, response: HttpServletResponse): List<Userinfo> { + 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 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()) { + if (condition.searchText?.isNotBlank() == true) { and(createCriteria() - .orLike("acountname", "%${condition.searchText}%") - .orLike("realname", "%${condition.searchText}%") + .orLike("acountname", "%${condition.searchText}%") + .orLike("realname", "%${condition.searchText}%") ) } if (condition.sceneTypes.isNotEmpty()) { @@ -172,29 +318,77 @@ }) } and(createCriteria().andEqualTo("extension1", districtName) - .andEqualTo("isenable", true)) + .andEqualTo("isenable", true).apply { + condition.userTypeId?.let { andEqualTo("usertypeid", it) } + }) //todo 2020.8.19 琛楅晣鐨勬潯浠舵煡璇㈤渶瑕佹墿鍏匓aseInfo鏁版嵁琛ㄥ瓧娈靛悗鍐嶅疄鐜� }) response.setIntHeader("totalPage", p.pages) response.setIntHeader("currentPage", p.pageNum) + response.setIntHeader("totalCount", p.total.toInt()) return result } - override fun getBaseInfo(userId: String): UserBaseInfo { + override fun getBaseInfo(userId: String, wxUserId: String?): UserBaseInfo { val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return UserBaseInfo(userId) - val baseInfo = baseInfoMapper.selectByPrimaryKey(userId) ?: return UserBaseInfo(userId) + userInfo.password = null + val baseInfo = baseInfoMapper.selectByPrimaryKey(userId) + val wxUser = if (wxUserId != null) userInfoWxMapper.selectByPrimaryKey(wxUserId) else null val mapper = when (userInfo.extension2) { SceneType.Restaurant.value.toString() -> restaurantBaseInfoMapper SceneType.VehicleRepair.value.toString() -> vehicleBaseInfoMapper - else -> restaurantBaseInfoMapper + SceneType.Industrial.value.toString() -> industrialBaseInfoMapper + else -> null } - val specialInfo = mapper.selectByPrimaryKey(baseInfo.biGuid) - val companyInfo = companyMapper.selectByPrimaryKey(baseInfo.ciGuid) + val specialInfo = mapper?.selectByPrimaryKey(baseInfo?.biGuid) + val companyInfo = + companyMapper.selectByPrimaryKey(if (baseInfo?.ciGuid != null) baseInfo.ciGuid else wxUser?.ciGuid) + val personalInfo = personalInfoMapper.selectByExample(Example(PersonalInfo::class.java).apply { + createCriteria().andEqualTo("piSceneId", userId).andEqualTo("piWxId", wxUser?.uiOpenId) + }).takeIf { it.isNotEmpty() }?.get(0) - return UserBaseInfo(userId, userInfo.realname, baseInfo, companyInfo, specialInfo) + return UserBaseInfo(userId, userInfo.realname, userInfo, baseInfo, companyInfo, specialInfo, personalInfo) + } + + override fun search(district: String?, sceneType: Int?, userType: Int?, page: Int, perPage: Int): + BaseResponse<List<Userinfo?>> { + val result = userinfoMapper.selectByExample(Example(Userinfo::class.java).apply { + createCriteria().apply { + district?.let { andEqualTo("extension1", it) } + sceneType?.let { andEqualTo("extension2", it) } + userType?.let { andEqualTo("usertypeid", it) } + } + }) + + return BaseResponse(true, data = result) + } + + override fun getSceneCount(userId: String, condition: UserSearchCondition): BaseResponse<Triple<Int, Int, Int>> { +// val user = userinfoMapper.selectByPrimaryKey(userId) +// val baseInfo = baseInfoMapper.selectByPrimaryKey(userId) +// condition.districtName = condition.districtName ?: user?.extension1 + + val config = userConfigRep.getUserConfigBySubType(userId) + val c = UserSearchCondition.fromUserConfig(config, condition).apply { + userTypeId = UserType.Enterprise.value.toByte() +// sceneTypes = condition.sceneTypes + } + + val result = userinfoMapper.searchUser(c) + val total = result.size + val enabled = result.filter { u -> + return@filter u.isenable == true + }.size + val disabled = total - enabled + + return BaseResponse(true, data = Triple(total, enabled, disabled)) + } + + override fun createUsers(workbook: HSSFWorkbook) { + TODO("Not yet implemented") } } \ No newline at end of file -- Gitblit v1.9.3