|
@@ -1,18 +1,20 @@
|
|
|
package com.mooctest.crowd.site.service.impl;
|
|
|
|
|
|
-import com.fasterxml.jackson.databind.ser.Serializers;
|
|
|
+import com.mooctest.crowd.domain.domainobject.AuthenticationStatus;
|
|
|
import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
|
|
|
import com.mooctest.crowd.domain.domainobject.Role;
|
|
|
import com.mooctest.crowd.domain.domainobject.User;
|
|
|
import com.mooctest.crowd.domain.exception.BaseException;
|
|
|
-import com.mooctest.crowd.domain.factory.UserFactory;
|
|
|
+import com.mooctest.crowd.domain.exception.UserNotExistException;
|
|
|
import com.mooctest.crowd.domain.repository.UserRepo;
|
|
|
import com.mooctest.crowd.site.anticorruption.UserAntiCorruption;
|
|
|
import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
|
|
|
import com.mooctest.crowd.site.data.dto.UserDTO;
|
|
|
import com.mooctest.crowd.site.data.vo.AgencyVO;
|
|
|
import com.mooctest.crowd.site.data.vo.UserVO;
|
|
|
+import com.mooctest.crowd.site.mediator.ViewMediator;
|
|
|
import com.mooctest.crowd.site.service.AgencyService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -24,6 +26,7 @@ import java.util.List;
|
|
|
* @Email: 171256175@qq.com
|
|
|
* @date 2019-08-12 01:20
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class AgencyServiceImpl implements AgencyService {
|
|
|
|
|
@@ -33,15 +36,28 @@ public class AgencyServiceImpl implements AgencyService {
|
|
|
@Autowired
|
|
|
private UserRepo userRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ViewMediator mediator;
|
|
|
+
|
|
|
@Override
|
|
|
public UserDTO applyAgency(Long userId, ApplyAgencyAuthCommand command) {
|
|
|
- return null;
|
|
|
+ EvaluationAgency agency = command.toAgency();
|
|
|
+ User user = userRepo.getByID(userId);
|
|
|
+ user.applyAgencyAuthentication(agency);
|
|
|
+ return mediator.renderUser(userRepo.saveUser(user));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public UserDTO generateAgency(ApplyAgencyAuthCommand command) {
|
|
|
- if (userRepo.getByMobileNum(command.getMobile()) != null)
|
|
|
- throw new BaseException("该电话已存在");
|
|
|
+ boolean mobileExists = false;
|
|
|
+ try {
|
|
|
+ userRepo.getByMobileNum(command.getMobile());
|
|
|
+ mobileExists = true;
|
|
|
+ }catch (UserNotExistException u){
|
|
|
+ log.info("电话号码不存在,可以生成新用户");
|
|
|
+ }
|
|
|
+ if (mobileExists)
|
|
|
+ throw new BaseException("手机号码已经存在,无法生成新用户");
|
|
|
User user = userAnti.register(command.getEvaluationAgencyName(), command.getMobile(), command.getMobile());
|
|
|
EvaluationAgency agency = command.toAgency();
|
|
|
List<Role> roles = new ArrayList<>();
|
|
@@ -49,6 +65,7 @@ public class AgencyServiceImpl implements AgencyService {
|
|
|
roles.add(userRepo.getRole("generalUser"));
|
|
|
user.setRoleList(roles);
|
|
|
agency.setUserId(user.getId());
|
|
|
+ agency.setIsAuthentication(AuthenticationStatus.isAuthenticated);
|
|
|
user.setEvaluationAgency(agency);
|
|
|
user = userRepo.saveUser(user);
|
|
|
UserDTO userDTO = new UserDTO();
|
|
@@ -57,4 +74,13 @@ public class AgencyServiceImpl implements AgencyService {
|
|
|
userDTO.getUserVO().setPassword(command.getMobile());
|
|
|
return userDTO;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserDTO updateAgencyStatus(Long userId, Integer status) {
|
|
|
+ User user = userRepo.getByID(userId);
|
|
|
+ if (user.getEvaluationAgency()==null)
|
|
|
+ throw new BaseException("该用户未申请认证机构");
|
|
|
+ user.getEvaluationAgency().setIsAuthentication(status);
|
|
|
+ return mediator.renderUser(userRepo.saveUser(user));
|
|
|
+ }
|
|
|
}
|