|
@@ -12,16 +12,22 @@ import com.uas.platform.b2c.core.config.MessageConf;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.exception.SystemException;
|
|
import com.uas.platform.core.exception.SystemException;
|
|
|
|
|
+import com.uas.platform.core.model.Constant;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.model.PageParams;
|
|
import com.uas.platform.core.model.PageParams;
|
|
|
import com.uas.platform.core.util.AgentUtils;
|
|
import com.uas.platform.core.util.AgentUtils;
|
|
|
import com.uas.platform.core.util.encry.Md5Utils;
|
|
import com.uas.platform.core.util.encry.Md5Utils;
|
|
|
import com.uas.sso.entity.UserView;
|
|
import com.uas.sso.entity.UserView;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.support.ManagedMap;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
+import org.springframework.security.access.ConfigAttribute;
|
|
|
|
|
+import org.springframework.security.core.GrantedAuthority;
|
|
|
|
|
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
import com.uas.sso.util.AccountUtils;
|
|
import com.uas.sso.util.AccountUtils;
|
|
@@ -60,9 +66,6 @@ public class UserServiceImpl implements UserService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private EnterpriseDao enterpriseDao;
|
|
private EnterpriseDao enterpriseDao;
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private CommonDao commonDao;
|
|
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private UserCacheEnterpriseDao userCacheEnterpriseDao;
|
|
private UserCacheEnterpriseDao userCacheEnterpriseDao;
|
|
|
|
|
|
|
@@ -72,51 +75,6 @@ public class UserServiceImpl implements UserService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private MessageConf messageConf;
|
|
private MessageConf messageConf;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public Page<User> findUsersPageByEnUUAndKeyword(final PageInfo pageInfo , Long enUU , String keyword) {
|
|
|
|
|
- List<Long> usersId = new ArrayList<>();
|
|
|
|
|
- if (keyword.contains("@")) { // 按邮箱查找
|
|
|
|
|
- usersId = userDao.findUserByUserEmailAndEnUU(keyword, enUU);
|
|
|
|
|
- } else if (keyword.matches(TEL_REGEXP)) { // 按手机号查找
|
|
|
|
|
- usersId = userDao.findUserByUserTelAndEnUU(keyword, enUU);
|
|
|
|
|
- } else if (keyword.matches(UU_REGEXP)) { // 按UU号查找
|
|
|
|
|
- usersId = userDao.findUserByEnUUAndUserUU(enUU, Long.parseLong(keyword));
|
|
|
|
|
- } else if (!keyword.contains("@") && (keyword.matches(CHINESE_REGEXP) || keyword.matches(ENGLISH_REGEXP))) {// 按名字查找
|
|
|
|
|
- usersId = userDao.findUserByUserNameAndEnUU(keyword, enUU);
|
|
|
|
|
- } else{
|
|
|
|
|
- usersId = userDao.findUserByUserNameAndEnUU(keyword, enUU);
|
|
|
|
|
- }
|
|
|
|
|
- final List<Long> users = usersId;
|
|
|
|
|
- if (users.size()>0) {
|
|
|
|
|
- Page<User> pUser = userDao.findAll(new Specification<User>() {
|
|
|
|
|
- public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
|
|
- Predicate predicateId = root.get("userUU").in(users);
|
|
|
|
|
- query.where(predicateId);
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- }, pageInfo);
|
|
|
|
|
- for (User user : pUser) {
|
|
|
|
|
- Set<Role> roles = user.getRoles();
|
|
|
|
|
- Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
|
|
- if (!CollectionUtils.isEmpty(roles)) {
|
|
|
|
|
- Iterator<Role> iterator = roles.iterator();
|
|
|
|
|
- while (iterator.hasNext()) {
|
|
|
|
|
- Role role = iterator.next();
|
|
|
|
|
- if (!role.getEnUU().equals(enuu)) {
|
|
|
|
|
- iterator.remove();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return pUser;
|
|
|
|
|
- }else{
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public User findUserByUserUU(Long uu) {
|
|
public User findUserByUserUU(Long uu) {
|
|
|
List<User> users = userDao.findUserByUserUU(uu);
|
|
List<User> users = userDao.findUserByUserUU(uu);
|
|
@@ -178,18 +136,6 @@ public class UserServiceImpl implements UserService {
|
|
|
return users;
|
|
return users;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public User findUserByEnUUAndUserUU(Long enUU, Long userUU) {
|
|
|
|
|
- List<User> users = userDao.findByEnUUAndUserUU(enUU, userUU);
|
|
|
|
|
- return CollectionUtils.isEmpty(users) ? null : users.get(0);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public List<User> findUsersByEnUU(Long enUU) {
|
|
|
|
|
- List<User> users = userDao.findByEnUU(enUU);
|
|
|
|
|
- return users;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Page<User> findUsersPageByEnUU(final PageInfo pageInfo , Long enUU) {
|
|
public Page<User> findUsersPageByEnUU(final PageInfo pageInfo , Long enUU) {
|
|
|
final List<Long> usersId = userDao.findIdByEnUU(enUU);
|
|
final List<Long> usersId = userDao.findIdByEnUU(enUU);
|
|
@@ -396,7 +342,62 @@ public class UserServiceImpl implements UserService {
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
userOld = userDao.save(userOld);
|
|
userOld = userDao.save(userOld);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (SystemSession.getUser().getUserUU().equals(userOld.getUserUU())) {
|
|
|
|
|
+ userOld.setCurrentEnterprise(SystemSession.getUser().getEnterprise().getUu());
|
|
|
|
|
+ userOld.setCurrentEnterpriseRoles();
|
|
|
|
|
+ SystemSession.setUser(userOld);
|
|
|
|
|
+ }
|
|
|
|
|
+ return userOld;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new IllegalOperatorException("修改的用户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public User saveUserRole(User user) {
|
|
|
|
|
+ User userOld = userDao.findOne(user.getUserUU());
|
|
|
|
|
+ if (userOld != null) {
|
|
|
|
|
+ userOld.setUserEmail(user.getUserEmail());
|
|
|
|
|
+ userOld.setUserTel(user.getUserTel());
|
|
|
|
|
+ userOld.setUserName(user.getUserName());
|
|
|
|
|
+ // 修改用户角色,只对用户的当前企业的角色进行修改
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(user.getRoles())) {
|
|
|
|
|
+ Set<Role> existRoles = userOld.getRoles();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(existRoles)) {// 保留用户在其他企业的角色
|
|
|
|
|
+ Iterator<Role> iterator = existRoles.iterator();
|
|
|
|
|
+ Long currentEnuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
|
+ Role role = iterator.next();
|
|
|
|
|
+ if (role.getEnUU().equals(currentEnuu)) {
|
|
|
|
|
+ iterator.remove();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ existRoles = new HashSet<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Role role : user.getRoles()) {
|
|
|
|
|
+ existRoles.add(role);
|
|
|
|
|
+ }
|
|
|
|
|
+ userOld.setRoles(existRoles);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Set<Role> existRoles = userOld.getRoles();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(existRoles)) {// 保留用户在其他企业的角色
|
|
|
|
|
+ Iterator<Role> iterator = existRoles.iterator();
|
|
|
|
|
+ Long currentEnuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
|
+ Role role = iterator.next();
|
|
|
|
|
+ if (role.getEnUU().equals(currentEnuu)) {
|
|
|
|
|
+ iterator.remove();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ userOld.setRoles(existRoles);
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ userOld = userDao.save(userOld);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e.getMessage());
|
|
throw new RuntimeException(e.getMessage());
|
|
|
}
|
|
}
|
|
@@ -649,4 +650,31 @@ public class UserServiceImpl implements UserService {
|
|
|
Long userUU = SystemSession.getUser().getUserUU();
|
|
Long userUU = SystemSession.getUser().getUserUU();
|
|
|
userDao.updateUserImageUrl(userUU, imageUrl);
|
|
userDao.updateUserImageUrl(userUU, imageUrl);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ModelMap anthority(User user,String resUrl) {
|
|
|
|
|
+ Set<ResourceItem> resourceItems = new HashSet<>();
|
|
|
|
|
+ user.setCurrentEnterpriseRoles();
|
|
|
|
|
+ Set<Role> roles = user.getRoles();
|
|
|
|
|
+ if (!org.apache.commons.collections.CollectionUtils.isEmpty(roles)) {
|
|
|
|
|
+ for (Role role : roles) {
|
|
|
|
|
+ resourceItems = role.getResourceItems();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //匹配当前访问权限;
|
|
|
|
|
+ if (!org.apache.commons.collections.CollectionUtils.isEmpty(resourceItems)) {
|
|
|
|
|
+ for (ResourceItem re : resourceItems) {
|
|
|
|
|
+ if (resUrl.equals(re.getUrl())) {
|
|
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
|
|
+ map.put("status","sucess");
|
|
|
|
|
+ map.put("msg",re.getDesc());
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
|
|
+ map.put("status","fail");
|
|
|
|
|
+ map.put("msg","没有该导出权限,请联系管理员");
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|