|
|
@@ -6,18 +6,26 @@ import com.uas.platform.b2b.dao.UserDao;
|
|
|
import com.uas.platform.b2b.model.Enterprise;
|
|
|
import com.uas.platform.b2b.model.Role;
|
|
|
import com.uas.platform.b2b.model.User;
|
|
|
+import com.uas.platform.b2b.v2.service.EnterpriseService;
|
|
|
import com.uas.platform.b2b.v2.service.UserService;
|
|
|
import com.uas.platform.core.model.Constant;
|
|
|
import com.uas.platform.core.util.encry.Md5Utils;
|
|
|
import com.uas.sso.entity.UserView;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
|
|
|
+/**
|
|
|
+ * UserServiceImpl
|
|
|
+ *
|
|
|
+ * @author US50
|
|
|
+ */
|
|
|
@Service("v2.UserService")
|
|
|
public class UserServiceImpl implements UserService {
|
|
|
|
|
|
@@ -27,13 +35,17 @@ public class UserServiceImpl implements UserService {
|
|
|
private RoleDao roleDao;
|
|
|
@Autowired
|
|
|
private EnterpriseDao enterpriseDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EnterpriseService enterpriseService;
|
|
|
|
|
|
static final String defaultPassword = "111111";
|
|
|
|
|
|
@Override
|
|
|
public User save(UserView user) {
|
|
|
User oldUser = getUser(user);
|
|
|
- if (oldUser == null) { // 如果是新用户,就新增一个user
|
|
|
+ // 如果是新用户,就新增一个user
|
|
|
+ if (oldUser == null) {
|
|
|
oldUser = new com.uas.platform.b2b.model.User(user);
|
|
|
oldUser.setEnable(Constant.YES);
|
|
|
oldUser.setUserPwd(Md5Utils.encode(defaultPassword, oldUser.getUserUU()));
|
|
|
@@ -45,17 +57,36 @@ public class UserServiceImpl implements UserService {
|
|
|
oldUser.setUserTel(user.getMobile());
|
|
|
oldUser.setUserIMId(StringUtils.isEmpty(user.getImId()) ? null : Long.valueOf(user.getImId()));
|
|
|
if (user.getPassword() != null) {
|
|
|
- if (user.getPassword().length() < 32) { // 传过来的是明文
|
|
|
+ // 传过来的是明文
|
|
|
+ if (user.getPassword().length() < 32) {
|
|
|
oldUser.setUserPwd(Md5Utils.encode(user.getPassword(), user.getUserUU()));
|
|
|
} else {
|
|
|
- oldUser.setUserPwd(user.getPassword());// 传过来的是密文
|
|
|
+ // 传过来的是密文
|
|
|
+ oldUser.setUserPwd(user.getPassword());
|
|
|
}
|
|
|
}
|
|
|
oldUser = userDao.save(oldUser);
|
|
|
+ // 判断新注册用户是否绑定企业并且设置成管理员
|
|
|
+ if (!CollectionUtils.isEmpty(oldUser.getEnterprises()) && oldUser.getEnterprises().size() == 1) {
|
|
|
+ checkIsAdmin(oldUser);
|
|
|
+ }
|
|
|
return oldUser;
|
|
|
}
|
|
|
|
|
|
- private com.uas.platform.b2b.model.User getUser(UserView user) {
|
|
|
+ /**
|
|
|
+ * 设置用户角色
|
|
|
+ *
|
|
|
+ * @param oldUser 用户信息
|
|
|
+ */
|
|
|
+ private void checkIsAdmin(User oldUser) {
|
|
|
+ oldUser.getEnterprises().forEach(enterprise -> {
|
|
|
+ if (Objects.equals(enterprise.getEnAdminuu(), oldUser.getUserUU())) {
|
|
|
+ enterpriseService.setUserRole(oldUser, enterprise);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private com.uas.platform.b2b.model.User getUser(UserView user) {
|
|
|
com.uas.platform.b2b.model.User oldUser = null;
|
|
|
if (user.getUserUU() != null) {
|
|
|
oldUser = userDao.findOne(user.getUserUU());
|