| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ltkj.common.constant.CacheConstants; |
| | | import com.ltkj.common.core.domain.entity.SysDept; |
| | | import com.ltkj.common.exception.CustomException; |
| | | import com.ltkj.common.exception.user.CaptchaException; |
| | | import com.ltkj.common.exception.user.CaptchaExpireException; |
| | | import com.ltkj.common.exception.user.SecretKeyException; |
| | | import com.ltkj.common.utils.*; |
| | | import com.ltkj.common.utils.sign.RsaUtils; |
| | | import com.ltkj.framework.config.JwtUtils; |
| | | import com.ltkj.framework.config.UserHoder; |
| | | import com.ltkj.hosp.domain.DictHosp; |
| | | import com.ltkj.hosp.domain.TjCustomer; |
| | | import com.ltkj.hosp.service.IDictHospService; |
| | | import com.ltkj.hosp.service.ITjCustomerService; |
| | | import com.ltkj.system.service.ISysMenuService; |
| | | import com.ltkj.system.service.SysParametersDisposeService; |
| | | import com.ltkj.system.service.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | |
| | | import com.ltkj.framework.manager.AsyncManager; |
| | | import com.ltkj.framework.manager.factory.AsyncFactory; |
| | | import com.ltkj.framework.security.context.AuthenticationContextHolder; |
| | | import com.ltkj.system.service.ISysUserService; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | @Resource |
| | | private ISysMenuService menuService; |
| | | |
| | | @Resource |
| | | private IDictHospService hospService; |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | @Autowired |
| | | private SysParametersDisposeService parametersDisposeService; |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | // 是否允许账户多终端同时登录(true允许 false不允许) |
| | | @Value("${token.soloLogin}") |
| | | private boolean soloLogin; |
| | | |
| | | @Value("${token.secret_key}") |
| | | private String secret; |
| | | |
| | | @Value("${token.secret_key_login}") |
| | | private boolean secretKeyLogin; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | public String login(String username, String password, Boolean type,String code,String uuid) { |
| | | |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; |
| | | String captcha = redisCache.getCacheObject(verifyKey); |
| | | redisCache.deleteObject(verifyKey); |
| | | if (captcha == null) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); |
| | | throw new CaptchaExpireException(); |
| | | } |
| | | if (!code.equalsIgnoreCase(captcha)) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); |
| | | throw new CaptchaException(); |
| | | String aSwitch = configService.selectConfigByKey("captcha_switch"); |
| | | if(null !=aSwitch && aSwitch.equals("Y")){ |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; |
| | | String captcha = redisCache.getCacheObject(verifyKey); |
| | | redisCache.deleteObject(verifyKey); |
| | | if (captcha == null) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); |
| | | throw new CaptchaExpireException(); |
| | | } |
| | | if (!code.equalsIgnoreCase(captcha)) |
| | | { |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); |
| | | throw new CaptchaException(); |
| | | } |
| | | } |
| | | |
| | | // 用户验证 |
| | | Authentication authentication = null; |
| | | try { |
| | | //登录密码解密 |
| | | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, RsaUtils.decryptByPrivateKey(password)); |
| | | //UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); |
| | | String s = RsaUtils.decryptByPrivateKey(password); |
| | | if(username.equals("10001")){ |
| | | s=username+s; |
| | | } |
| | | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username,s); |
| | | AuthenticationContextHolder.setContext(authenticationToken); |
| | | // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername |
| | | authentication = authenticationManager.authenticate(authenticationToken); |
| | |
| | | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); |
| | | recordLoginInfo(Long.valueOf(loginUser.getUserId())); |
| | | |
| | | //校验商家过期否 |
| | | if (secretKeyLogin) |
| | | { |
| | | Long userId =loginUser.getUser().getUserId(); |
| | | SysUser user = userService.getById(userId); |
| | | if(null !=user && null !=user.getDeptId()){ |
| | | SysDept sysDept = deptService.getById(user.getDeptId()); |
| | | if (null != sysDept) { |
| | | DictHosp dictHosp = hospService.getById(sysDept.getHospId()); |
| | | if(null !=dictHosp){ |
| | | loginUser.setHospName(dictHosp.getHospAreaName()); |
| | | if(!SecurityUtils.isAdmin(user.getUserId())){ |
| | | if(dictHosp.getSecretKey() != null && dictHosp.getExpirationTime() != null){ |
| | | if (!SecurityUtils.matchesMallMerchantSecretKey(secret,dictHosp.getHospAreaId(),dictHosp.getHospAreaName(), |
| | | dictHosp.getExpirationTime(),dictHosp.getSecretKey()) || new Date().after(DateUtil.endOfDay(dictHosp.getExpirationTime()))) { |
| | | throw new SecretKeyException("商家已过期请续费使用"); |
| | | } |
| | | long between = DateUtil.between(new Date(), DateUtil.endOfDay(dictHosp.getExpirationTime()), DateUnit.DAY); |
| | | if(between<=30){ |
| | | loginUser.setMessage("还有 "+between+" 天到期 请注意续费! 以免影响正常使用!"); |
| | | }else { |
| | | loginUser.setMessage(null); |
| | | } |
| | | }else { |
| | | throw new SecretKeyException("请缴费使用"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | }else { |
| | | throw new CustomException("请绑定商家"); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 限制账户不允许多终端登录 |
| | | if (!soloLogin) { |
| | | // 如果用户不允许多终端同时登录,清除缓存信息 |