|
|
@@ -9,7 +9,10 @@ import com.uas.sso.entity.App;
|
|
|
import com.uas.sso.entity.User;
|
|
|
import com.uas.sso.entity.Userspace;
|
|
|
import com.uas.sso.entity.UserspaceValid;
|
|
|
+import com.uas.sso.sso.backend.dao.AdminChangeRecordDao;
|
|
|
import com.uas.sso.sso.backend.dto.UpdateSpaceInfo;
|
|
|
+import com.uas.sso.sso.backend.entity.AdminChangeRecord;
|
|
|
+import com.uas.sso.sso.backend.entity.AdminChangeType;
|
|
|
import com.uas.sso.sso.backend.exceptions.ValidationFailedException;
|
|
|
import com.uas.sso.sso.backend.service.UserSpaceService;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
@@ -19,9 +22,11 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Order;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
+import org.hibernate.jpa.criteria.OrderImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
@@ -47,13 +52,17 @@ public class UserSpaceServiceImpl implements UserSpaceService {
|
|
|
|
|
|
private final UserspaceValidDao spaceValidDao;
|
|
|
|
|
|
+ private final AdminChangeRecordDao recordDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
public UserSpaceServiceImpl(UserspaceDao userspaceDao, UserDao userDao,
|
|
|
- AppDao appDao, UserspaceValidDao spaceValidDao) {
|
|
|
+ AppDao appDao, UserspaceValidDao spaceValidDao,
|
|
|
+ AdminChangeRecordDao recordDao) {
|
|
|
this.userspaceDao = userspaceDao;
|
|
|
this.userDao = userDao;
|
|
|
this.appDao = appDao;
|
|
|
this.spaceValidDao = spaceValidDao;
|
|
|
+ this.recordDao = recordDao;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -91,6 +100,13 @@ public class UserSpaceServiceImpl implements UserSpaceService {
|
|
|
predicates.toArray(array);
|
|
|
Predicate predicate = builder.and(array);
|
|
|
query.where(predicate);
|
|
|
+
|
|
|
+ List<Order> orderList = new ArrayList<>();
|
|
|
+ Order order = new OrderImpl(root.get("registerDate"), false);
|
|
|
+ orderList.add(order);
|
|
|
+ order = new OrderImpl(root.get("validCode"), true);
|
|
|
+ orderList.add(order);
|
|
|
+ query.orderBy(orderList);
|
|
|
return null;
|
|
|
}
|
|
|
}, page);
|
|
|
@@ -141,6 +157,28 @@ public class UserSpaceServiceImpl implements UserSpaceService {
|
|
|
throw new ValidationFailedException("企业管理员必须是当前企业用户");
|
|
|
}
|
|
|
|
|
|
+ // 记录管理员更换记录
|
|
|
+ AdminChangeRecord record = new AdminChangeRecord();
|
|
|
+ record.setSpaceUU(spaceUu);
|
|
|
+
|
|
|
+ User oldAdmin = space.getAdmin();
|
|
|
+ record.setSponsorName("系统管理员");
|
|
|
+ record.setSponsorTel("123456789");
|
|
|
+ if (oldAdmin != null) {
|
|
|
+ record.setOldAdminName(oldAdmin.getVipName());
|
|
|
+ record.setOldAdminTel(oldAdmin.getMobile());
|
|
|
+ }
|
|
|
+ record.setLaunchTime(new Date());
|
|
|
+
|
|
|
+ record.setAuditorName("系统管理员");
|
|
|
+ record.setAuditorTel("123456789");
|
|
|
+ record.setAuditTime(new Date());
|
|
|
+ record.setNewAdminName(admin.getVipName());
|
|
|
+ record.setNewAdminTel(admin.getMobile());
|
|
|
+
|
|
|
+ record.setChangeType(AdminChangeType.ADMIN_OPERATION);
|
|
|
+ recordDao.save(record);
|
|
|
+
|
|
|
// 更新管理员信息
|
|
|
space.setAdminUU(userUU);
|
|
|
space.setAdmin(admin);
|
|
|
@@ -191,19 +229,9 @@ public class UserSpaceServiceImpl implements UserSpaceService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
|
public void addUserToSpace(Long spaceUu, Long userUu) {
|
|
|
- if (spaceUu == null || userUu == null) {
|
|
|
- throw new ValidationFailedException("企业UU和用户UU不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- Userspace space = userspaceDao.findOne(spaceUu);
|
|
|
- if (space == null) {
|
|
|
- throw new ValidationFailedException(String.format("UU %d 对应企业不存在", spaceUu));
|
|
|
- }
|
|
|
+ Userspace space = assertSpaceExist(spaceUu);
|
|
|
|
|
|
- User user = userDao.findOne(userUu);
|
|
|
- if (user == null) {
|
|
|
- throw new ValidationFailedException(String.format("UU %d 对应用户不存在", userUu));
|
|
|
- }
|
|
|
+ User user = assertUserExist(userUu);
|
|
|
|
|
|
List<User> users = space.getUsers();
|
|
|
if (!users.contains(user)) {
|