| | |
| | | package org.springblade.modules.system.service.impl; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.flowable.idm.engine.impl.persistence.entity.UserEntity; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springblade.common.cache.DictCache; |
| | | import org.springblade.common.cache.ParamCache; |
| | | import org.springblade.common.cache.SysCache; |
| | |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.common.constant.TenantConstant; |
| | | import org.springblade.common.enums.DictEnum; |
| | | import org.springblade.common.utils.SpinLockUtil; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.*; |
| | | import org.springblade.modules.auth.enums.UserEnum; |
| | | import org.springblade.modules.community.entity.CommunityEntity; |
| | | import org.springblade.modules.community.service.ICommunityService; |
| | | import org.springblade.modules.grid.service.IGridmanService; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | import org.springblade.modules.house.vo.HouseholdVO; |
| | | import org.springblade.modules.police.entity.PoliceAffairsGridEntity; |
| | | import org.springblade.modules.police.service.IPoliceAffairsGridService; |
| | | import org.springblade.modules.property.entity.PropertyCompanyEntity; |
| | |
| | | import org.springblade.modules.system.vo.UserDetailVO; |
| | | import org.springblade.modules.system.vo.UserVO; |
| | | import org.springblade.modules.system.wrapper.UserWrapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements IUserService { |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); |
| | | |
| | | private static final String GUEST_NAME = "guest"; |
| | | |
| | | private final IUserDeptService userDeptService; |
| | |
| | | private final IDeptService deptService; |
| | | private final BladeTenantProperties tenantProperties; |
| | | private final IPoliceAffairsGridService policeAffairsGridService; |
| | | |
| | | @Autowired |
| | | private SpinLockUtil spinLockUtil; |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | } |
| | | |
| | | private boolean submitUserDept(User user) { |
| | | List<Long> deptIdList = Func.toLongList(user.getDeptId()); |
| | | List<UserDept> userDeptList = new ArrayList<>(); |
| | | deptIdList.forEach(deptId -> { |
| | | UserDept userDept = new UserDept(); |
| | | userDept.setUserId(user.getId()); |
| | | userDept.setDeptId(deptId); |
| | | userDeptList.add(userDept); |
| | | }); |
| | | userDeptService.remove(Wrappers.<UserDept>update().lambda().eq(UserDept::getUserId, user.getId())); |
| | | boolean b = userDeptService.saveBatch(userDeptList); |
| | | return b; |
| | | try { |
| | | // 加锁 |
| | | boolean isLock = spinLockUtil.tryLock(user.getId().toString()); |
| | | boolean result = false; |
| | | List<Long> deptIdList = Func.toLongList(user.getDeptId()); |
| | | List<UserDept> userDeptList = new ArrayList<>(); |
| | | deptIdList.forEach(deptId -> { |
| | | UserDept userDept = new UserDept(); |
| | | userDept.setUserId(user.getId()); |
| | | userDept.setDeptId(deptId); |
| | | userDeptList.add(userDept); |
| | | }); |
| | | // 是否加锁成功 |
| | | logger.info("是否加锁成功:" + isLock); |
| | | if (isLock) { |
| | | userDeptService.remove(Wrappers.<UserDept>update().lambda().eq(UserDept::getUserId, user.getId())); |
| | | result = userDeptService.saveBatch(userDeptList); |
| | | } |
| | | // 释放锁 |
| | | spinLockUtil.unlock(user.getId().toString()); |
| | | return result; |
| | | } catch (Exception e) { |
| | | // 释放锁 |
| | | spinLockUtil.unlock(user.getId().toString()); |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public IPage<User> selectUserPage(IPage<User> page, User user, String deptId, String tenantId) { |
| | |
| | | * @param tenantId |
| | | * @param account |
| | | * @param password |
| | | * @param type 登录类型 2:pc 3:app |
| | | * @param type 登录类型 2:pc 3:app |
| | | * @return |
| | | */ |
| | | @Override |
| | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param user |
| | | * @param type 登录类型 2:pc 3:app |
| | | * @return |
| | |
| | | userInfo.setUser(user); |
| | | if (Func.isNotEmpty(user)) { |
| | | // 判断登录类型设置对应的角色id |
| | | user.setRoleId(Strings.join(roleService.getRoleIdStrByRoleIdAndType(user.getRoleId(),type), ',')); |
| | | user.setRoleId(Strings.join(roleService.getRoleIdStrByRoleIdAndType(user.getRoleId(), type), ',')); |
| | | // 设置角色别名 |
| | | List<String> roleAlias = roleService.getRoleAliases(user.getRoleId()); |
| | | userInfo.setRoles(roleAlias); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean registerUser(UserVO user) { |
| | | if (StringUtils.isEmpty(user.getAccount())) { |
| | | throw new ServiceException("账号不能为空!"); |
| | | } |
| | | if (StringUtils.isEmpty(user.getPassword())) { |
| | | throw new ServiceException("密码不能为空!"); |
| | | } |
| | | if (!StringUtils.equals(user.getPassword(), user.getPassword2())) { |
| | | throw new ServiceException("两次的密码不一致!"); |
| | | } |
| | | long count = count(Wrappers.<User>lambdaQuery().eq(User::getAccount, user.getAccount())); |
| | | if (count > 0) { |
| | | throw new ServiceException("改账号已存在,请更换其他账号!"); |
| | | } |
| | | |
| | | user.setPassword(DigestUtil.encrypt(user.getPassword())); |
| | | user.setRoleId("1717429059648606209"); |
| | | boolean oauthTemp = save(user); |
| | | return (oauthTemp); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updatePlatform(Long userId, Integer userType, String userExt) { |
| | | if (userType.equals(UserEnum.WEB.getCategory())) { |
| | | UserWeb userWeb = new UserWeb(); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 处理漏绑定的user_dept |
| | | */ |
| | |
| | | userInfo.setRoleId(userInfo.getRoleId() + ",1727864411451359233"); |
| | | } |
| | | // 设置性别 |
| | | setSex(userInfo,userExcel); |
| | | setSex(userInfo, userExcel); |
| | | // 更新机构 |
| | | setDeptId(userInfo, userExcel); |
| | | // 更新 |
| | |
| | | user.setPhone(userExcel.getPhone()); |
| | | user.setAccount(userExcel.getPhone()); |
| | | // 设置性别 |
| | | setSex(user,userExcel); |
| | | setSex(user, userExcel); |
| | | // 更新机构 |
| | | setDeptId(user, userExcel); |
| | | // 设置初始密码 |
| | |
| | | |
| | | /** |
| | | * 设置性别 |
| | | * |
| | | * @param user |
| | | * @param userExcel |
| | | */ |
| | | private void setSex(User user, PoliceUserExcel userExcel) { |
| | | if (userExcel.getSex().contains("男")){ |
| | | if (userExcel.getSex().contains("男")) { |
| | | user.setSex(1); |
| | | } |
| | | if (userExcel.getSex().contains("女")){ |
| | | if (userExcel.getSex().contains("女")) { |
| | | user.setSex(2); |
| | | } |
| | | } |