| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.common.constant.TenantConstant; |
| | | 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.tenant.BladeTenantProperties; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import org.springblade.core.tool.jackson.JsonUtil; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.*; |
| | | import org.springblade.system.cache.DictCache; |
| | | import org.springblade.system.cache.ParamCache; |
| | | import org.springblade.system.cache.SysCache; |
| | | import org.springblade.system.entity.Strategy; |
| | | import org.springblade.system.entity.Tenant; |
| | | import org.springblade.system.enums.DictEnum; |
| | | import org.springblade.system.feign.ISysClient; |
| | |
| | | import org.springblade.system.user.wrapper.UserWrapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.DigestUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | |
| | | import static org.springblade.common.constant.CommonConstant.DEFAULT_PARAM_PASSWORD; |
| | | |
| | |
| | | user.setTenantId(BladeConstant.ADMIN_TENANT_ID); |
| | | } |
| | | String tenantId = user.getTenantId(); |
| | | Tenant tenant = SysCache.getTenant(tenantId); |
| | | if (Func.isNotEmpty(tenant)) { |
| | | Integer accountNumber = tenant.getAccountNumber(); |
| | | if (tenantProperties.getLicense()) { |
| | | String licenseKey = tenant.getLicenseKey(); |
| | | String decrypt = DesUtil.decryptFormHex(licenseKey, TenantConstant.DES_KEY); |
| | | accountNumber = JsonUtil.parse(decrypt, Tenant.class).getAccountNumber(); |
| | | } |
| | | Long tenantCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId)); |
| | | if (accountNumber != null && accountNumber > 0 && accountNumber <= tenantCount) { |
| | | throw new ServiceException("当前租户已到最大账号额度!"); |
| | | } |
| | | } |
| | | //Tenant tenant = SysCache.getTenant(tenantId); |
| | | if (Func.isNotEmpty(user.getPassword())) { |
| | | user.setPassword(DigestUtil.encrypt(user.getPassword())); |
| | | } |
| | |
| | | throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); |
| | | } |
| | | return save(user) && submitUserDept(user); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean submitList(List<User> users) { |
| | | Boolean flag = true; |
| | | for (User user : users){ |
| | | if (StringUtil.isBlank(user.getTenantId())) { |
| | | user.setTenantId(BladeConstant.ADMIN_TENANT_ID); |
| | | } |
| | | String tenantId = user.getTenantId(); |
| | | if (Func.isNotEmpty(user.getPassword())) { |
| | | user.setPassword(DigestUtil.encrypt(user.getPassword())); |
| | | } |
| | | Long userCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, user.getAccount())); |
| | | if (userCount > 0L && Func.isEmpty(user.getId())) { |
| | | throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); |
| | | } |
| | | flag = save(user) && submitUserDept(user); |
| | | |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public boolean updatePassword(Long userId, String oldPassword, String newPassword, String newPassword1) { |
| | | String hex = DigestUtil.hex(DigestUtils.md5DigestAsHex((newPassword1).getBytes())); |
| | | User user = getById(userId); |
| | | if (!newPassword.equals(newPassword1)) { |
| | | throw new ServiceException("请输入正确的确认密码!"); |
| | |
| | | if (!user.getPassword().equals(DigestUtil.hex(oldPassword))) { |
| | | throw new ServiceException("原密码不正确!"); |
| | | } |
| | | return this.update(Wrappers.<User>update().lambda().set(User::getPassword, DigestUtil.hex(newPassword)).eq(User::getId, userId)); |
| | | //获取用户采用的密码策略 |
| | | Strategy strategy = sysClient.getByUserId(userId).getData(); |
| | | String resException = "密码中必须含有【"+strategy.getCombinationIds()+"】中的【"+strategy.getRequiredType()+"】种密码组合方式,且密码长度必须在【"+strategy.getMinPwdLen()+"-"+strategy.getMaxPwdLen()+"】范围内"; |
| | | //密码长度校验 |
| | | if(newPassword1.length() < strategy.getMinPwdLen() || newPassword1.length() > strategy.getMaxPwdLen()){ |
| | | throw new ServiceException(resException); |
| | | } |
| | | //查询密码策略取值 |
| | | String regex = sysClient.getRegex(Arrays.asList(strategy.getCombinationIds().split(","))).getData(); |
| | | System.out.println("===============regex================"+regex); |
| | | regex = "^"+regex+"$"; |
| | | String result = RegexUtil.findResult(regex, newPassword); |
| | | System.out.println(result); |
| | | return this.update(Wrappers.<User>update().lambda().set(User::getPassword, DigestUtil.hex(DigestUtils.md5DigestAsHex((newPassword1).getBytes()))).eq(User::getId, userId)); |
| | | //return true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | return userVO; |
| | | } |
| | | |
| | | @Override |
| | | public Long checkRenAndExpr(Long userId) { |
| | | //获取到密码修改时间 |
| | | Date pwdUpdateTime = this.getOne(Wrappers.<User>query().eq("ID", userId)).getPwdUpdateTime(); |
| | | Long pwdupdateday = 0L; |
| | | if(!Func.isEmpty(pwdUpdateTime)){ |
| | | pwdupdateday = dateToDay(pwdUpdateTime); |
| | | } |
| | | Strategy strategy = sysClient.getByUserId(userId).getData(); |
| | | System.out.println("当前时间=================="+dateToDay(new Date())); |
| | | System.out.println("密码修改时间======================"+pwdupdateday); |
| | | System.out.println("提醒时间======================"+strategy.getReminderTime()); |
| | | System.out.println("过期时间======================="+strategy.getExpirationTime()); |
| | | //是否提醒通过最后一次修改密码的时间加上过期时间减去当前时间,如果小于过期提醒时间就进行提醒,如果<=0就提醒必须修改密码 |
| | | long reminder = pwdupdateday+strategy.getExpirationTime()-dateToDay(pwdUpdateTime); |
| | | //必须去修改密码 |
| | | if(reminder<=0){ |
| | | return -1L; |
| | | } |
| | | //提醒用户还有多久过期 |
| | | if(reminder<=strategy.getReminderTime()){ |
| | | long res = (strategy.getReminderTime()+pwdupdateday)-dateToDay(new Date()); |
| | | return res; |
| | | } |
| | | //代表正常状态还未到提醒与过期时间,既不提醒也不要求修改 |
| | | return 0L; |
| | | } |
| | | |
| | | private Long dateToDay(Date date){ |
| | | long time = date.getTime(); |
| | | return time/(1000 * 60 * 60 * 24); |
| | | } |
| | | |
| | | |
| | | } |