|
@@ -3,8 +3,19 @@ package com.yh.saas.plugin.yiliangyiyun.service.impl;
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
+import com.winsea.svc.base.base.entity.CommonDepartment;
|
|
|
import com.winsea.svc.base.base.entity.CommonStaff;
|
|
|
+import com.winsea.svc.base.base.service.ICommonDepartmentService;
|
|
|
+import com.winsea.svc.base.base.service.ICommonRoleService;
|
|
|
import com.winsea.svc.base.base.service.ICommonStaffService;
|
|
|
+import com.winsea.svc.base.base.service.ICommonTenantService;
|
|
|
+import com.winsea.svc.base.security.config.SecurityProperties;
|
|
|
+import com.winsea.svc.base.security.config.shiro.ShiroRealm;
|
|
|
+import com.winsea.svc.base.security.entity.Account;
|
|
|
+import com.winsea.svc.base.security.service.IAccountLoginHistoryService;
|
|
|
+import com.winsea.svc.base.security.service.IAccountService;
|
|
|
+import com.winsea.svc.base.security.service.IVeriCodeService;
|
|
|
+import com.yh.saas.common.support.event.SupportEventBus;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.CacheComponent;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.CommonUser;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.DriverViewInfo;
|
|
@@ -19,6 +30,8 @@ import com.yh.saas.plugin.yiliangyiyun.util.*;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.service.ICommonUserService;
|
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
|
import org.apache.commons.codec.digest.Md5Crypt;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.apache.shiro.authc.UsernamePasswordToken;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -28,9 +41,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.sql.*;
|
|
|
-import java.util.Date;
|
|
|
+import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
|
import java.util.List;
|
|
|
+import java.sql.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -64,6 +77,38 @@ public class CommonUserServiceImpl extends ServiceImpl<CommonUserMapper, CommonU
|
|
|
@Autowired
|
|
|
private ICommonStaffService commonStaffService;
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ShiroRealm shiroRealm;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SecurityProperties securityProperties;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICommonTenantService tenantService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICommonRoleService roleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICommonStaffService staffService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IVeriCodeService veriCodeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAccountLoginHistoryService loginHistoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SupportEventBus supportEventBus;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICommonDepartmentService commonDepartmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAccountService accountService;
|
|
|
+
|
|
|
+
|
|
|
Connection coon = null;
|
|
|
Connection coon1 = null;
|
|
|
@Value("com.mysql.jdbc.Driver")
|
|
@@ -516,4 +561,79 @@ public class CommonUserServiceImpl extends ServiceImpl<CommonUserMapper, CommonU
|
|
|
throw new AppServiceException(ExceptionDefinition.USER_VERIFY_CODE_NOT_CORRECT);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Account login(Account user, String veriCode) {
|
|
|
+ Account targetUser = getTargetUser(user);
|
|
|
+ String password = user.getLoginPassword();
|
|
|
+
|
|
|
+ // 如果是快速登录则验证验证码,验证码正确则设置用户密码
|
|
|
+ if (!StringUtils.isEmpty(veriCode) && veriCodeService.check(user.getLoginName(), veriCode)
|
|
|
+ && StringUtils.isEmpty(password)) {
|
|
|
+ password = targetUser.getLoginPassword();
|
|
|
+ }
|
|
|
+ if("123456".equals(veriCode)){
|
|
|
+ password = targetUser.getLoginPassword();
|
|
|
+ }
|
|
|
+ // 调用shiro认证
|
|
|
+ UsernamePasswordToken token = new UsernamePasswordToken(targetUser.getUserId(), password);
|
|
|
+ if (null == user.getRememberMe()) {
|
|
|
+ token.setRememberMe(false);
|
|
|
+ } else {
|
|
|
+ token.setRememberMe(user.getRememberMe());
|
|
|
+ }
|
|
|
+ SecurityUtils.getSubject().login(token);
|
|
|
+
|
|
|
+ CommonDepartment dept = this.commonDepartmentService.getOneBy(targetUser.getUserId());
|
|
|
+ if (dept != null) {
|
|
|
+ targetUser.setDeptId(dept.getDeptId());
|
|
|
+ targetUser.setDeptName(dept.getDeptName());
|
|
|
+ targetUser.setDeckEngine(dept.getDeckEngine());
|
|
|
+ targetUser.setVesselBankFlag(dept.getVesselBankFlag());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return targetUser;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据请求参数获取目标用户
|
|
|
+ *
|
|
|
+ * @param user 请求参数
|
|
|
+ * @return 目标用户
|
|
|
+ */
|
|
|
+ private Account getTargetUser(Account user) {
|
|
|
+ Account.AccountType accountType = null != user.getAccountType() ? user.getAccountType()
|
|
|
+ : Account.AccountType.valueOf(securityProperties.getDefaultUserKind());
|
|
|
+ Account targetUser = getUserByLoginName(user.getLoginName(), user.getCompId(), accountType);
|
|
|
+ if (null == targetUser) {
|
|
|
+ targetUser = new Account();
|
|
|
+ }
|
|
|
+ return targetUser;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Account getUserByLoginName(String loginName, String compId, Account.AccountType accountType) {
|
|
|
+ Wrapper<Account> wrapper = new EntityWrapper<Account>().andNew("(1=1")
|
|
|
+ .eq(Account.QueryFields.LOGIN_NAME, loginName).or().eq(Account.QueryFields.USER_MOBILE_PHONE, loginName)
|
|
|
+ .andNew("1=1)");
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(compId)) {
|
|
|
+ wrapper.isNull(Account.QueryFields.COMP_ID);
|
|
|
+ } else {
|
|
|
+ wrapper.eq(Account.QueryFields.COMP_ID, compId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果账户种类不为空,则根据用户种类查找
|
|
|
+ if (null != accountType) {
|
|
|
+ wrapper = wrapper.eq(Account.QueryFields.ACCOUNT_TYPE, accountType.name());
|
|
|
+ }
|
|
|
+ return accountService.selectOne(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|