|
@@ -11,6 +11,7 @@ import cn.com.ty.lift.system.user.service.*;
|
|
|
import cn.com.ty.lift.system.utils.PasswordUtils;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -25,6 +26,7 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author huangyuan
|
|
@@ -139,12 +141,12 @@ public class UserService implements IUserService {
|
|
|
|
|
|
@Override
|
|
|
public RestResponse addUser(UserRequest userRequest) {
|
|
|
- if(StringUtils.isBlank(userRequest.getMobile())) {
|
|
|
+ if (StringUtils.isBlank(userRequest.getMobile())) {
|
|
|
return RestResponse.fail(ApiConstants.RESULT_ERROR, "用户手机号为空");
|
|
|
}
|
|
|
UserAccount userAccount = userAccountService.getByMobile(userRequest.getMobile());
|
|
|
- if(userAccount != null) {
|
|
|
- return RestResponse.fail(ApiConstants.RESULT_ERROR, "手机号已经存在");
|
|
|
+ if (userAccount != null) {
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "手机号已经存在");
|
|
|
}
|
|
|
//保存用户信息,成功返回用户账户信息,失败返回空
|
|
|
userAccount = this.saveUserInfo(userRequest);
|
|
@@ -199,11 +201,19 @@ public class UserService implements IUserService {
|
|
|
@Override
|
|
|
public UserResponse getLoginUserInfo(Long userId) {
|
|
|
UserResponse userResponse = getBaseUserInfo(userId);
|
|
|
+ //获取用所在公司列表
|
|
|
List<MtCompanyUser> mtCompanyUserList = mtCompanyUserService.list(new QueryWrapper<MtCompanyUser>()
|
|
|
.eq("user_id", userId)
|
|
|
.eq("status", ApiConstants.ApplicationConstants.APPLY_PASS)
|
|
|
.eq("delete_flag", ApiConstants.DELETE_NO)
|
|
|
);
|
|
|
+ //获取上一次用户登录公司列表
|
|
|
+ List<MtCompanyUser> currentCompanyUserList = mtCompanyUserService.list(new QueryWrapper<MtCompanyUser>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("status", ApiConstants.ApplicationConstants.APPLY_PASS)
|
|
|
+ .eq("delete_flag", ApiConstants.DELETE_NO)
|
|
|
+ .eq("is_current_company", 1)
|
|
|
+ );
|
|
|
//获取用户所在公司的id列表
|
|
|
List<Long> companyIds = ProjectUtils.getAttrList(mtCompanyUserList, "mtCompanyId", null);
|
|
|
if (companyIds.size() > 0) {
|
|
@@ -213,10 +223,11 @@ public class UserService implements IUserService {
|
|
|
userResponse.setCompanyList(maintenanceCompanyList);
|
|
|
//用户进入后的默认团队信息
|
|
|
if (maintenanceCompanyList != null && maintenanceCompanyList.size() > 0) {
|
|
|
- MaintenanceCompany maintenanceCompany = maintenanceCompanyList.get(0);
|
|
|
- userResponse.setMaintenanceCompany(maintenanceCompany);
|
|
|
+ MaintenanceCompany currentCompany = getCurrentCompany(currentCompanyUserList, maintenanceCompanyList);
|
|
|
+ mtCompanyUserService.updateLoginCompanyFlag(userId, currentCompany.getId());
|
|
|
+ userResponse.setMaintenanceCompany(currentCompany);
|
|
|
//获取用户在默认团队中的角色信息
|
|
|
- Role role = roleService.getRoleByUserIdAndCompanyId(userId, maintenanceCompany.getId());
|
|
|
+ Role role = roleService.getRoleByUserIdAndCompanyId(userId, currentCompany.getId());
|
|
|
userResponse.setRole(role);
|
|
|
//获取用户在当前企业下的菜单
|
|
|
if (role != null) {
|
|
@@ -229,6 +240,25 @@ public class UserService implements IUserService {
|
|
|
return userResponse;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param currentCompanyUserList 用户所在当前公司列表
|
|
|
+ * @return 当前公司
|
|
|
+ * @description 获取当前公司
|
|
|
+ * @date 2020/5/22 3:11 下午
|
|
|
+ */
|
|
|
+ private MaintenanceCompany getCurrentCompany(List<MtCompanyUser> currentCompanyUserList,
|
|
|
+ List<MaintenanceCompany> maintenanceCompanyList) {
|
|
|
+ if (currentCompanyUserList != null && currentCompanyUserList.size() > 0) {
|
|
|
+ long currentCompanyId = currentCompanyUserList.get(0).getMtCompanyId();
|
|
|
+ List<MaintenanceCompany> currentCompanyList = maintenanceCompanyList.stream().filter(maintenanceCompany ->
|
|
|
+ maintenanceCompany.getId() == currentCompanyId).collect(Collectors.toList());
|
|
|
+ if (currentCompanyList.size() > 0) {
|
|
|
+ return currentCompanyList.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return maintenanceCompanyList.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Map<Long, UserResponse> getUserResponseByUserIdList(List<Long> userIdList) {
|
|
|
Map<Long, UserResponse> userIdToUserResponse = new HashMap<>();
|