package com.gkhy.safePlatform.account.service.baseService.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.safePlatform.account.entity.user.UserInfo; import com.gkhy.safePlatform.account.entity.user.UserInfoDO; import com.gkhy.safePlatform.account.enums.UserStatusEnum; import com.gkhy.safePlatform.account.model.query.db.AccountDBQuery; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.exception.BusinessException; import com.gkhy.safePlatform.commons.utils.StringUtils; import com.gkhy.safePlatform.account.repository.UserInfoRepository; import com.gkhy.safePlatform.account.service.baseService.UserInfoService; import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service("userInfoService") public class UserInfoServiceImpl extends ServiceImpl implements UserInfoService { @Autowired private UserInfoRepository userInfoRepository; @Override public UserInfo getUserByUsername(String username) { if (StringUtils.isBlank(username)) throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); return userInfoRepository.getUserInfoByUsername(username); } @Override public UserInfo getUserByUserId(Long userId) { if (userId == null) throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); return userInfoRepository.getUserInfoByUserId(userId); } @Override public void abandonAccount(Long userId) { if (userId == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } int i = userInfoRepository.updateStatus(userId,UserStatusEnum.ABANDONED.getCode()); if (i == 0) { throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE); } if (i > 1) { throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR); } } @Override public void saveUserInfo(UserInfo userInfo) { if (userInfo == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } int i = userInfoRepository.insertUserInfo(userInfo); if (i != 1) { throw new BusinessException(ResultCodes.SERVER_ADD_ERROR); } } @Override public void updateUserInfo(UserInfo userInfo) { if (userInfo == null || userInfo.getUid() == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } int i = userInfoRepository.updateUserInfo(userInfo); if (i == 0) { throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE); } if (i > 1) { throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR); } } @Override public List listPage(Page page, AccountDBQuery accountDBQuery) { if (page == null || accountDBQuery == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.listPage(page, accountDBQuery); } @Override public List getDepUserList(Long depId) { if (depId == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.getDepUserList(depId); } @Override public long countByDepId(Long depId) { if (depId == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.selectCount(new LambdaQueryWrapper() // 部门id .eq(UserInfo::getDepId,depId) // 状态 .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode())); } @Override public long countByPositionId(Long positionId) { if (positionId == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.selectCount(new LambdaQueryWrapper() // 岗位id .eq(UserInfo::getPositionId,positionId) // 状态 .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode()) ); } @Override public long countByIdentify(String identify) { if (StringUtils.isBlank(identify)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.selectCount(new LambdaQueryWrapper() // 身份证 .eq(UserInfo::getIdentify,identify) // 状态 .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode())); } @Override public long countByRealName(String realName) { if (StringUtils.isBlank(realName)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.selectCount(new LambdaQueryWrapper() // 真名 .eq(UserInfo::getRealName,realName)); } @Override public UserInfoDO getUserByPhone(String phone) { if (StringUtils.isBlank(phone)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.getUserByPhone(phone); } @Override public long countByPhone(String phone) { if (StringUtils.isBlank(phone)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.selectCount(new LambdaQueryWrapper() // 手机号 .eq(UserInfo::getPhone,phone) // 状态 .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode())); } @Override public List listAllUser() { return userInfoRepository.listAllUser(); } @Override public List listUserByUids(List uids) { return userInfoRepository.listUserInfoDOByUids(uids); } @Override public List listUserByRealName(String realName) { if (StringUtils.isBlank(realName)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.listUserByRealName(realName); } @Override public long countByRoleId(Long roleId) { if (roleId == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.selectCount(new LambdaQueryWrapper() // 角色id .eq(UserInfo::getRoleId,roleId) // 状态 .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode())); } @Override public void resetRoleToNullByRoleId(Long roleId) { if (roleId == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } userInfoRepository.resetRoleToNullByRoleId(roleId); } @Override public UserInfo getUserInfoByIdentify(String identify) { if (StringUtils.isBlank(identify)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } List userInfos = userInfoRepository.selectList(new LambdaQueryWrapper() // 身份证 .eq(UserInfo::getIdentify, identify) // 状态 .eq(UserInfo::getStatus, UserStatusEnum.VALID.getCode())); if (userInfos.size() == 0) { return null; } if (userInfos.size() > 1) { throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED); } return userInfos.get(0); } @Override public UserInfo getUserInfoByPhone(String phone) { if (StringUtils.isBlank(phone)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } List userInfos = userInfoRepository.selectList(new LambdaQueryWrapper() // 手机号 .eq(UserInfo::getPhone, phone) // 状态 .eq(UserInfo::getStatus, UserStatusEnum.VALID.getCode())); if (userInfos.size() == 0) { return null; } if (userInfos.size() > 1) { throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED); } return userInfos.get(0); } @Override public UserInfo getUserInfoByEmail(String email) { if (StringUtils.isBlank(email)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } List userInfos = userInfoRepository.selectList(new LambdaQueryWrapper() // 手机号 .eq(UserInfo::getEmail, email) // 状态 .eq(UserInfo::getStatus, UserStatusEnum.VALID.getCode())); if (userInfos.size() == 0) { return null; } if (userInfos.size() > 1) { throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED); } return userInfos.get(0); } @Override public long countByEmail(String email) { if (StringUtils.isBlank(email)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return userInfoRepository.selectCount(new LambdaQueryWrapper() // email .eq(UserInfo::getEmail,email) // 状态 .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode())); } @Override public void updatePassword(Long uid, String salt, String hash) { if (uid == null || StringUtils.isBlank(salt) || StringUtils.isBlank(hash)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } int i = userInfoRepository.updatePassword(uid, salt, hash); if (i == 0) { throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE); } if (i > 1) { throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR); } } }