You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.2 KiB
128 lines
4.2 KiB
/* |
|
* Copyright (C), 2018-2021 |
|
* Project: starter |
|
* FileName: DingTalkDecUserHelper |
|
* Author: Louis |
|
* Date: 2021/6/24 22:04 |
|
*/ |
|
package com.fr.plugin.xxxx.dingtalksyn.helper; |
|
|
|
import com.fanruan.api.log.LogKit; |
|
import com.fanruan.api.util.StringKit; |
|
import com.fr.decision.authority.AuthorityContext; |
|
import com.fr.decision.authority.data.User; |
|
import com.fr.decision.webservice.v10.user.UserService; |
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.stable.query.QueryFactory; |
|
import com.fr.stable.query.restriction.RestrictionFactory; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import java.util.ArrayList; |
|
import java.util.Iterator; |
|
import java.util.List; |
|
|
|
/** |
|
* <Function Description><br> |
|
* <DingTalkDecUserHelper> |
|
* |
|
* @author fr.open |
|
* @since 1.0.0 |
|
*/ |
|
public class DingTalkDecUserHelper { |
|
public DingTalkDecUserHelper() { |
|
} |
|
|
|
public static boolean isUserExist(String userName) { |
|
if (StringUtils.isEmpty(userName)) { |
|
return false; |
|
} |
|
try { |
|
List<User> userList = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
|
return userList != null && !userList.isEmpty(); |
|
} catch (Exception e) { |
|
LogKit.error(e.getMessage(), e); |
|
return false; |
|
} |
|
} |
|
|
|
public static List<User> getDecUsers() { |
|
List<User> userList = null; |
|
try { |
|
userList = AuthorityContext.getInstance().getUserController().find(QueryFactory.create()); |
|
} catch (Exception e) { |
|
LogKit.error(e.getMessage(), e); |
|
} |
|
return (userList == null ? new ArrayList<>() : userList); |
|
} |
|
|
|
public static String getDecUserNameById(String userId, List<User> userList) { |
|
String userName = StringKit.EMPTY; |
|
for (User user : userList) { |
|
if (ComparatorUtils.equals(user.getId(), userId)) { |
|
userName = user.getUserName(); |
|
break; |
|
} |
|
} |
|
return userName; |
|
} |
|
|
|
public static User getDecUserByName(String userName) { |
|
User User = null; |
|
if (StringUtils.isNotBlank(userName)) { |
|
try { |
|
List<User> userList = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
|
if (userList != null && !userList.isEmpty()) { |
|
User = userList.get(0); |
|
} |
|
} catch (Exception e) { |
|
LogKit.error(e.getMessage(), e); |
|
} |
|
} |
|
return User; |
|
} |
|
|
|
public static void filterEnableUserNames(List<String> userNames) { |
|
List<User> userList = getDecUsers(); |
|
Iterator<String> iterator = userNames.iterator(); |
|
while (iterator.hasNext()) { |
|
boolean enable = false; |
|
String userName = iterator.next(); |
|
for (User user : userList) { |
|
if (ComparatorUtils.equals(user.getUserName(), userName) && user.isEnable()) { |
|
enable = true; |
|
break; |
|
} |
|
} |
|
if (!enable) { |
|
iterator.remove(); |
|
} |
|
} |
|
} |
|
|
|
public static String userNameToRealName(String userName, List<User> userList) { |
|
String realName = StringKit.EMPTY; |
|
if (StringUtils.isNotEmpty(userName)) { |
|
for (User user : userList) { |
|
if (ComparatorUtils.equals(userName, user.getUserName())) { |
|
realName = user.getRealName(); |
|
break; |
|
} |
|
} |
|
} |
|
return realName; |
|
} |
|
|
|
public static String getCurrentUserId(HttpServletRequest request) { |
|
String currentUserId = StringKit.EMPTY; |
|
try { |
|
currentUserId = UserService.getInstance().getCurrentUserId(request); |
|
} catch (Exception e) { |
|
try { |
|
currentUserId = UserService.getInstance().getCurrentUserIdFromCookie(request); |
|
} catch (Exception e1) { |
|
} |
|
} |
|
return currentUserId; |
|
} |
|
} |