|
@@ -10,21 +10,22 @@ import com.github.microservice.auth.security.model.AuthDetails;
|
|
|
import com.github.microservice.auth.security.type.AuthType;
|
|
import com.github.microservice.auth.security.type.AuthType;
|
|
|
import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
|
|
import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
|
|
|
import com.github.microservice.core.util.net.IPUtil;
|
|
import com.github.microservice.core.util.net.IPUtil;
|
|
|
-import com.zhongshu.card.client.model.login.LoginBusModel;
|
|
|
|
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
import com.zhongshu.card.client.model.login.LoginCommonModel;
|
|
import com.zhongshu.card.client.model.login.LoginCommonModel;
|
|
|
-import com.zhongshu.card.client.model.org.*;
|
|
|
|
|
-import com.zhongshu.card.client.model.org.orgUser.OrganizationUserModel;
|
|
|
|
|
|
|
+import com.zhongshu.card.client.model.org.GetPhoneModel;
|
|
|
|
|
+import com.zhongshu.card.client.model.org.LoginParam;
|
|
|
|
|
+import com.zhongshu.card.client.model.org.UserCountSimpleModel;
|
|
|
import com.zhongshu.card.client.model.setting.PlatFormLoginConfig;
|
|
import com.zhongshu.card.client.model.setting.PlatFormLoginConfig;
|
|
|
import com.zhongshu.card.client.model.wechat.PhoneModel;
|
|
import com.zhongshu.card.client.model.wechat.PhoneModel;
|
|
|
import com.zhongshu.card.client.model.wechat.WechatPhoneNumber;
|
|
import com.zhongshu.card.client.model.wechat.WechatPhoneNumber;
|
|
|
-import com.github.microservice.net.ResultContent;
|
|
|
|
|
import com.zhongshu.card.client.type.LoginFromType;
|
|
import com.zhongshu.card.client.type.LoginFromType;
|
|
|
-import com.zhongshu.card.client.type.OrganizationState;
|
|
|
|
|
import com.zhongshu.card.client.type.UserState;
|
|
import com.zhongshu.card.client.type.UserState;
|
|
|
import com.zhongshu.card.client.type.setting.SettingType;
|
|
import com.zhongshu.card.client.type.setting.SettingType;
|
|
|
|
|
+import com.zhongshu.card.client.type.user.OrgUserState;
|
|
|
import com.zhongshu.card.server.core.dao.org.*;
|
|
import com.zhongshu.card.server.core.dao.org.*;
|
|
|
import com.zhongshu.card.server.core.domain.org.*;
|
|
import com.zhongshu.card.server.core.domain.org.*;
|
|
|
import com.zhongshu.card.server.core.service.base.RedisService;
|
|
import com.zhongshu.card.server.core.service.base.RedisService;
|
|
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.service.setting.PlatFormConfigInfoService;
|
|
import com.zhongshu.card.server.core.service.setting.PlatFormConfigInfoService;
|
|
|
import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
|
|
import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
@@ -41,7 +42,11 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StopWatch;
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author TRX
|
|
* @author TRX
|
|
@@ -49,7 +54,7 @@ import java.util.*;
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
-public class IndexService {
|
|
|
|
|
|
|
+public class IndexService extends SuperService {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private UserCountDao userCountDao;
|
|
private UserCountDao userCountDao;
|
|
@@ -102,6 +107,9 @@ public class IndexService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
PlatFormConfigInfoService platFormConfigInfoService;
|
|
PlatFormConfigInfoService platFormConfigInfoService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OrganizationUserServiceImpl organizationUserServiceImpl;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 物联网登录
|
|
* 物联网登录
|
|
|
*
|
|
*
|
|
@@ -114,7 +122,7 @@ public class IndexService {
|
|
|
|
|
|
|
|
String phone = param.getLoginValue();
|
|
String phone = param.getLoginValue();
|
|
|
UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
|
- UserCountModel userCountModel = userAccountService.toModel(userAccount);
|
|
|
|
|
|
|
+ UserCountSimpleModel userCountModel = userAccountService.toSimpleModel(userAccount);
|
|
|
|
|
|
|
|
UserAuthLoginModel userAuthLoginModel = new UserAuthLoginModel();
|
|
UserAuthLoginModel userAuthLoginModel = new UserAuthLoginModel();
|
|
|
BeanUtils.copyProperties(param, userAuthLoginModel);
|
|
BeanUtils.copyProperties(param, userAuthLoginModel);
|
|
@@ -156,53 +164,6 @@ public class IndexService {
|
|
|
return ResultContent.buildSuccess(commonModel);
|
|
return ResultContent.buildSuccess(commonModel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 商户小程序登录
|
|
|
|
|
- *
|
|
|
|
|
- * @param param
|
|
|
|
|
- * @return
|
|
|
|
|
- */
|
|
|
|
|
- public ResultContent<LoginBusModel> busLogin(LoginParam param) {
|
|
|
|
|
- StopWatch stopWatch = new StopWatch();
|
|
|
|
|
- stopWatch.start("1");
|
|
|
|
|
-
|
|
|
|
|
- UserAuthLoginModel userAuthLoginModel = new UserAuthLoginModel();
|
|
|
|
|
- BeanUtils.copyProperties(param, userAuthLoginModel);
|
|
|
|
|
- // 登录
|
|
|
|
|
- ResultContent<LoginTokenModel> resultContent = commonLogin(userAuthLoginModel);
|
|
|
|
|
- if (resultContent.isFailed()) {
|
|
|
|
|
- return ResultContent.buildFail(resultContent.getMsg());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- String phone = param.getLoginValue();
|
|
|
|
|
- UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
|
|
|
- UserCountModel userCountModel = userAccountService.toModel(userAccount);
|
|
|
|
|
-
|
|
|
|
|
- // 用户加入的商户列表
|
|
|
|
|
- List<UserJoinBusOrgModel> busModels = organizationService.getUserAboutShopList(userAccount.getUserId());
|
|
|
|
|
- if (ObjectUtils.isEmpty(busModels)) {
|
|
|
|
|
- return ResultContent.buildFail("用户未关联商户,登录失败");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- LoginBusModel commonModel = new LoginBusModel();
|
|
|
|
|
- LoginTokenModel loginTokenModel = resultContent.getContent();
|
|
|
|
|
- com.zhongshu.card.server.core.util.BeanUtils.copyProperties(loginTokenModel, commonModel);
|
|
|
|
|
- stopWatch.stop();
|
|
|
|
|
- commonModel.setBusList(busModels);
|
|
|
|
|
-
|
|
|
|
|
- stopWatch.start("2");
|
|
|
|
|
- commonModel.setUserInfo(userCountModel);
|
|
|
|
|
- stopWatch.stop();
|
|
|
|
|
-
|
|
|
|
|
- stopWatch.start("3");
|
|
|
|
|
- // 用户所有的权限
|
|
|
|
|
-// Set<String> auth = roleServiceImpl.getUserAllAuths(userAccount.getUserId());
|
|
|
|
|
-// commonModel.setAuths(auth);
|
|
|
|
|
- stopWatch.stop();
|
|
|
|
|
- log.info(stopWatch.prettyPrint());
|
|
|
|
|
- return ResultContent.buildSuccess(commonModel);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 通用用户登录(返回所有权限数据)
|
|
* 通用用户登录(返回所有权限数据)
|
|
|
*
|
|
*
|
|
@@ -234,7 +195,7 @@ public class IndexService {
|
|
|
stopWatch.start("2");
|
|
stopWatch.start("2");
|
|
|
|
|
|
|
|
UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
|
- UserCountModel userCountModel = userAccountService.toModel(userAccount);
|
|
|
|
|
|
|
+ UserCountSimpleModel userCountModel = userAccountService.toSimpleModel(userAccount);
|
|
|
commonModel.setUserInfo(userCountModel);
|
|
commonModel.setUserInfo(userCountModel);
|
|
|
|
|
|
|
|
// 平台信息
|
|
// 平台信息
|
|
@@ -293,100 +254,53 @@ public class IndexService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 微信普通用户登录
|
|
|
|
|
- *
|
|
|
|
|
- * @param param
|
|
|
|
|
- * @return
|
|
|
|
|
- */
|
|
|
|
|
- public ResultContent wxUserLogin(LoginParam param) {
|
|
|
|
|
- return login(param);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 平台端用户登录
|
|
|
|
|
- *
|
|
|
|
|
|
|
+ * 小程序登录
|
|
|
* @param param
|
|
* @param param
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public ResultContent loginPlatform(LoginParam param) {
|
|
|
|
|
- String phone = param.getLoginValue();
|
|
|
|
|
- UserAuthLoginModel userAuthLoginModel = new UserAuthLoginModel();
|
|
|
|
|
- BeanUtils.copyProperties(param, userAuthLoginModel);
|
|
|
|
|
- ResultContent<LoginTokenModel> resultContent = commonLogin(userAuthLoginModel);
|
|
|
|
|
- if (resultContent.isFailed()) {
|
|
|
|
|
- return resultContent;
|
|
|
|
|
|
|
+ public ResultContent wxXcxlogin(LoginParam param) {
|
|
|
|
|
+ String projectOid = getCurrentProjectOid();
|
|
|
|
|
+ if (ObjectUtils.isEmpty(projectOid)) {
|
|
|
|
|
+ return ResultContent.buildFail("当前项目信息为空");
|
|
|
}
|
|
}
|
|
|
- Organization organization = organizationDao.findTopByAuthType(AuthType.Platform);
|
|
|
|
|
- if (ObjectUtils.isEmpty(organization)) {
|
|
|
|
|
- return ResultContent.buildFail(String.format("平台未初始化,请联系管理员"));
|
|
|
|
|
|
|
+ String phone = param.getLoginValue();
|
|
|
|
|
+ UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
|
|
|
+ if (ObjectUtils.isEmpty(userAccount)) {
|
|
|
|
|
+ return ResultContent.buildFail("用户名或密码错误.");
|
|
|
}
|
|
}
|
|
|
- if (organization.getState() == OrganizationState.Locked || organization.getState() == OrganizationState.Frozen) {
|
|
|
|
|
- return ResultContent.buildFail(String.format("平台已被锁定,不能登录"));
|
|
|
|
|
|
|
+ List<OrganizationUser> list = organizationUserServiceImpl.getUserOrgList(userAccount.getUserId(), projectOid);
|
|
|
|
|
+ if (ObjectUtils.isEmpty(list)) {
|
|
|
|
|
+ return ResultContent.buildFail("用户未加入项目");
|
|
|
}
|
|
}
|
|
|
- UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
|
|
|
- OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, userAccount);
|
|
|
|
|
- if (ObjectUtils.isEmpty(organizationUser)) {
|
|
|
|
|
- return ResultContent.buildFail(String.format("该用户不属于平台端用户:%s", phone));
|
|
|
|
|
|
|
+ if (list.size() == 1) {
|
|
|
|
|
+ OrgUserState orgUserState = list.get(0).getOrgUserState();
|
|
|
|
|
+ if (orgUserState == OrgUserState.Unaudited) {
|
|
|
|
|
+ return ResultContent.buildFail("用户正在审核中,登录失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (orgUserState == OrgUserState.Refusal) {
|
|
|
|
|
+ return ResultContent.buildFail("用户已拒绝,登录失败");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- LoginTokenModel loginTokenModel = resultContent.getContent();
|
|
|
|
|
- LoginPlatformTokenModel tokenModel = new LoginPlatformTokenModel();
|
|
|
|
|
- com.zhongshu.card.server.core.util.BeanUtils.copyProperties(loginTokenModel, tokenModel);
|
|
|
|
|
-
|
|
|
|
|
- tokenModel.setPlatformOid(organization.getOid());
|
|
|
|
|
-
|
|
|
|
|
- OrganizationUserModel userModel = userAccountService.toOrgUserModel(organizationUser);
|
|
|
|
|
- tokenModel.setUserInfo(userModel);
|
|
|
|
|
|
|
+ list = list.stream().filter(it -> {
|
|
|
|
|
+ if (it.getOrgUserState() == null || it.getOrgUserState() == OrgUserState.Formal) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }).collect(Collectors.toUnmodifiableList());
|
|
|
|
|
|
|
|
- return ResultContent.buildSuccess(tokenModel);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (ObjectUtils.isEmpty(list)) {
|
|
|
|
|
+ return ResultContent.buildFail("用户未加入项目.");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 登录--验证用户名和密码 + 是否在指定的机构
|
|
|
|
|
- *
|
|
|
|
|
- * @param param
|
|
|
|
|
- * @return
|
|
|
|
|
- */
|
|
|
|
|
- public ResultContent loginToOid(LoginParam param) {
|
|
|
|
|
- String phone = param.getLoginValue();
|
|
|
|
|
|
|
+ // 验证用户名密码
|
|
|
UserAuthLoginModel userAuthLoginModel = new UserAuthLoginModel();
|
|
UserAuthLoginModel userAuthLoginModel = new UserAuthLoginModel();
|
|
|
BeanUtils.copyProperties(param, userAuthLoginModel);
|
|
BeanUtils.copyProperties(param, userAuthLoginModel);
|
|
|
- ResultContent<LoginTokenModel> resultContent = commonLogin(userAuthLoginModel);
|
|
|
|
|
|
|
+ ResultContent resultContent = commonLogin(userAuthLoginModel);
|
|
|
|
|
+
|
|
|
if (resultContent.isFailed()) {
|
|
if (resultContent.isFailed()) {
|
|
|
return resultContent;
|
|
return resultContent;
|
|
|
}
|
|
}
|
|
|
- // web 端的登录用户数据验证
|
|
|
|
|
- UserAccount userAccount = userCountDao.findTopByLoginName(phone);
|
|
|
|
|
- Organization organization = organizationDao.findTopByOid(param.getOid());
|
|
|
|
|
- if (ObjectUtils.isEmpty(organization)) {
|
|
|
|
|
- return ResultContent.buildFail(String.format("oid不存在:%s", param.getOid()));
|
|
|
|
|
- }
|
|
|
|
|
- OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUserAndState(organization, userAccount, UserState.Normal);
|
|
|
|
|
- if (ObjectUtils.isEmpty(organizationUser)) {
|
|
|
|
|
- String msg = String.format("用户不属于该机构:%s", organization.getName());
|
|
|
|
|
- if (param.getLoginFromType() == LoginFromType.Platform) {
|
|
|
|
|
- msg = String.format("用户不属于平台端用户,登录失败:%s", organization.getName());
|
|
|
|
|
- } else if (param.getLoginFromType() == LoginFromType.School) {
|
|
|
|
|
- msg = String.format("用户不属于学校端用户,登录失败:%s", organization.getName());
|
|
|
|
|
- } else if (param.getLoginFromType() == LoginFromType.Shop) {
|
|
|
|
|
- msg = String.format("用户不属于商户端用户,登录失败:%s", organization.getName());
|
|
|
|
|
- }
|
|
|
|
|
- return ResultContent.buildFail(msg);
|
|
|
|
|
- }
|
|
|
|
|
- LoginTokenModel loginTokenModel = resultContent.getContent();
|
|
|
|
|
- LoginPlatformTokenModel tokenModel = new LoginPlatformTokenModel();
|
|
|
|
|
- com.zhongshu.card.server.core.util.BeanUtils.copyProperties(loginTokenModel, tokenModel);
|
|
|
|
|
- tokenModel.setPlatformOid(organization.getOid());
|
|
|
|
|
-
|
|
|
|
|
- // 查询用户信息
|
|
|
|
|
- OrganizationUserModel userModel = userAccountService.toOrgUserModel(organizationUser);
|
|
|
|
|
- tokenModel.setUserInfo(userModel);
|
|
|
|
|
-
|
|
|
|
|
- // 得到用户在企业的权限列表
|
|
|
|
|
- ResultContent<Set<String>> authContent = roleServiceImpl.getOrganizationAuth(organization.getOid(), userModel.getUserId());
|
|
|
|
|
- if (authContent.isSuccess()) {
|
|
|
|
|
- tokenModel.setAuths(authContent.getContent());
|
|
|
|
|
- }
|
|
|
|
|
- return ResultContent.buildSuccess(tokenModel);
|
|
|
|
|
|
|
+ return resultContent;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|