|
|
@@ -1,23 +1,31 @@
|
|
|
package com.uas.sso.sso.backend.service.impl;
|
|
|
|
|
|
import com.uas.sso.dao.AppealDao;
|
|
|
+import com.uas.sso.dao.UserDao;
|
|
|
+import com.uas.sso.dao.UserspaceDao;
|
|
|
import com.uas.sso.entity.Appeal;
|
|
|
+import com.uas.sso.entity.User;
|
|
|
import com.uas.sso.entity.Userspace;
|
|
|
import com.uas.sso.sso.backend.exceptions.ValidationFailedException;
|
|
|
import com.uas.sso.sso.backend.service.AppealService;
|
|
|
+import com.uas.sso.sso.backend.util.JacksonUtils;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
@@ -29,11 +37,26 @@ import org.springframework.util.StringUtils;
|
|
|
@Service
|
|
|
public class AppealServiceImpl implements AppealService {
|
|
|
|
|
|
+ private static final Logger logger = Logger.getLogger(AppealServiceImpl.class);
|
|
|
+
|
|
|
+ private static final String RESET_PASS = "resetPassword";
|
|
|
+
|
|
|
+ private static final String VALID_MOBILE = "validAccount";
|
|
|
+
|
|
|
+ private static final String CHANGE_ADMIN = "changeAdmin";
|
|
|
+
|
|
|
private final AppealDao appealDao;
|
|
|
|
|
|
+ private final UserDao userDao;
|
|
|
+
|
|
|
+ private final UserspaceDao spaceDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
- public AppealServiceImpl(AppealDao appealDao) {
|
|
|
+ public AppealServiceImpl(AppealDao appealDao, UserDao userDao,
|
|
|
+ UserspaceDao spaceDao) {
|
|
|
this.appealDao = appealDao;
|
|
|
+ this.userDao = userDao;
|
|
|
+ this.spaceDao = spaceDao;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -78,6 +101,7 @@ public class AppealServiceImpl implements AppealService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
public void approveAppealRequest(Long appealId, Boolean isPass) {
|
|
|
Assert.notNull(isPass, "审核状态不能为空");
|
|
|
Appeal appeal = assertAppealExist(appealId);
|
|
|
@@ -87,7 +111,42 @@ public class AppealServiceImpl implements AppealService {
|
|
|
appeal.setStatus((short) (isPass ? 2 : 3));
|
|
|
appealDao.save(appeal);
|
|
|
|
|
|
- // TODO 处理对应的用户信息
|
|
|
+ // 审核通过之后,更新用户和企业信息
|
|
|
+ if (isPass) {
|
|
|
+ Map map = JacksonUtils.fromJson(appeal.getSubmitInfo(), Map.class);
|
|
|
+ Assert.notNull(map, "申诉提交信息不能为空");
|
|
|
+
|
|
|
+ if (RESET_PASS.equals(appeal.getType()) || VALID_MOBILE.equals(appeal.getType())) {
|
|
|
+ User user = assertUserExist(appeal.getSubmitterUU());
|
|
|
+ user.setMobile(appeal.getMobile());
|
|
|
+
|
|
|
+ if (RESET_PASS.equals(appeal.getType())) {
|
|
|
+ String password = (String) map.get("password");
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(password) || password.length() < 32) {
|
|
|
+ throw new ValidationFailedException("重置密码不存在或密码未被加密");
|
|
|
+ }
|
|
|
+ user.setPassword(password);
|
|
|
+ }
|
|
|
+ userDao.save(user);
|
|
|
+ } else if (CHANGE_ADMIN.equals(appeal.getType())) {
|
|
|
+ Long spaceUU = ((Integer) map.get("spaceUU")).longValue();
|
|
|
+ Assert.notNull(map, "更换管理员申诉企业UU不能为空");
|
|
|
+
|
|
|
+ Userspace space = assertSpaceExist(spaceUU);
|
|
|
+ User user = userDao.findByMobile(appeal.getMobile());
|
|
|
+ if (user == null) {
|
|
|
+ throw new ValidationFailedException(
|
|
|
+ String.format("拥有手机号[%s]的用户不存在", appeal.getMobile()));
|
|
|
+ }
|
|
|
+
|
|
|
+ space.setAdmin(user);
|
|
|
+ space.setAdminUU(user.getUserUU());
|
|
|
+ spaceDao.save(space);
|
|
|
+ } else {
|
|
|
+ logger.info("暂无支持申诉类型");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private Appeal assertAppealExist(Long appealId) {
|
|
|
@@ -97,4 +156,25 @@ public class AppealServiceImpl implements AppealService {
|
|
|
}
|
|
|
return appeal;
|
|
|
}
|
|
|
+
|
|
|
+ private User assertUserExist(Long userUU) {
|
|
|
+ User user = userDao.findOne(userUU);
|
|
|
+ if (user == null) {
|
|
|
+ throw new ValidationFailedException(String.format("用户[%d]不存在", userUU));
|
|
|
+ }
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 业务逻辑校验-企业UU对应企业是否存在
|
|
|
+ *
|
|
|
+ * @param spaceUu 企业UU
|
|
|
+ */
|
|
|
+ private Userspace assertSpaceExist(@NotNull Long spaceUu) {
|
|
|
+ Userspace space = spaceDao.findOne(spaceUu);
|
|
|
+ if (space == null) {
|
|
|
+ throw new ValidationFailedException(String.format("企业[%d]不存在", spaceUu));
|
|
|
+ }
|
|
|
+ return space;
|
|
|
+ }
|
|
|
}
|