Browse Source

Merge branch 'Dev' into 'Test'

Dev

See merge request crowd-2019/crowd-test-service-backend!13
薛晓波 6 years ago
parent
commit
95e084c46f

+ 26 - 0
Jenkinsfile

@@ -0,0 +1,26 @@
+pipeline {
+    agent any
+    stages {
+        stage('拉取代码') {
+            //拉后端代码
+            steps{
+                echo "[backend] git pull..."
+                git branch: 'Test', credentialsId: '74f4c153-f4fa-4ccd-83c5-1597c8dce407', url: 'ssh://git@git.mooctest.com:1022/crowd-2019/crowd-test-service-backend.git'
+            }
+
+        }
+        stage('Maven构建') {
+            //后端构建
+            steps{
+                echo "[backend] mvn package..."
+                sh 'mvn clean package -DskipTests'
+                //target/mooctest-site-server.jar
+                sh 'cp ./site/target/site-0.0.1-SNAPSHOT.jar ./tool4deploy/'
+            }
+        }
+        stage('发布') {
+            //上传服务器,部署Docker
+            sh 'scp -r ./tool4deploy/ ubuntu@129.211.26.227:~/crowd_service_pre/'
+        }
+    }
+}

+ 1 - 1
site/src/main/java/com/mooctest/crowd/site/anticorruption/UserAntiCorruption.java

@@ -8,7 +8,7 @@ import com.mooctest.crowd.domain.domainobject.User;
  * @date 2019-08-08 23:40
  * @date 2019-08-08 23:40
  */
  */
 public interface UserAntiCorruption {
 public interface UserAntiCorruption {
-    User register(String name, String mobile, String password);
+    User register(String name,String email, String mobile, String password);
 
 
     User getUserInfo(Long userId);
     User getUserInfo(Long userId);
 }
 }

+ 2 - 2
site/src/main/java/com/mooctest/crowd/site/anticorruption/impl/UserAntiCorruptionImpl.java

@@ -42,13 +42,13 @@ public class UserAntiCorruptionImpl implements UserAntiCorruption {
     private String userServiceUrl;
     private String userServiceUrl;
 
 
     @Override
     @Override
-    public User register(String name, String mobile, String password) {
+    public User register(String name, String email, String mobile, String password) {
         HttpHeaders httpHeaders = new HttpHeaders();
         HttpHeaders httpHeaders = new HttpHeaders();
         httpHeaders.setContentType(MediaType.APPLICATION_JSON);
         httpHeaders.setContentType(MediaType.APPLICATION_JSON);
         JSONObject params = new JSONObject();
         JSONObject params = new JSONObject();
         params.put("name", name);
         params.put("name", name);
         params.put("mobile", mobile);
         params.put("mobile", mobile);
-        params.put("email", name+"."+mobile+"@mooctest.net");
+        params.put("email", email);
         params.put("password", EncryptionUtil.encryptMD5(password));
         params.put("password", EncryptionUtil.encryptMD5(password));
         params.put("createTime", System.currentTimeMillis());
         params.put("createTime", System.currentTimeMillis());
 
 

+ 7 - 0
site/src/main/java/com/mooctest/crowd/site/command/ApplyAgencyAuthCommand.java

@@ -6,6 +6,7 @@ import lombok.Data;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 
 
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
 
 
 /**
 /**
  * @author: Diors.Po
  * @author: Diors.Po
@@ -15,8 +16,14 @@ import javax.validation.constraints.NotNull;
 @Data
 @Data
 public class ApplyAgencyAuthCommand {
 public class ApplyAgencyAuthCommand {
 
 
+    @NotNull(message = "邮箱不可为空")
+    @Pattern(regexp = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$", message = "邮箱非法")
+    private String email;
+
     @NotNull(message = "手机号不可为空")
     @NotNull(message = "手机号不可为空")
+    @Pattern(regexp = "^1[3|4|5|7|8][0-9]\\d{4,8}$", message = "手机号非法")
     private String mobile;
     private String mobile;
+
     @NotNull(message = "机构名称不可为空")
     @NotNull(message = "机构名称不可为空")
     private String evaluationAgencyName;
     private String evaluationAgencyName;
     @NotNull(message = "银行卡号不可为空")
     @NotNull(message = "银行卡号不可为空")

+ 8 - 1
site/src/main/java/com/mooctest/crowd/site/controller/AgencyController.java

@@ -5,7 +5,12 @@ import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
 import com.mooctest.crowd.site.data.dto.UserDTO;
 import com.mooctest.crowd.site.data.dto.UserDTO;
 import com.mooctest.crowd.site.service.AgencyService;
 import com.mooctest.crowd.site.service.AgencyService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
 /**
 /**
  * @author: Diors.Po
  * @author: Diors.Po
  * @Email: 171256175@qq.com
  * @Email: 171256175@qq.com
@@ -24,7 +29,9 @@ public class AgencyController {
      * @return
      * @return
      */
      */
     @RequestMapping(value = "/greenChannel/agency", method = RequestMethod.POST)
     @RequestMapping(value = "/greenChannel/agency", method = RequestMethod.POST)
-    public UserDTO generateAgency(@RequestBody ApplyAgencyAuthCommand command){
+    public UserDTO generateAgency(@RequestBody @Validated ApplyAgencyAuthCommand command, BindingResult result){
+        if (result.hasErrors())
+            throw new BaseException(result.getFieldError().getDefaultMessage());
         return agencyService.generateAgency(command);
         return agencyService.generateAgency(command);
     }
     }
 
 

+ 9 - 9
site/src/main/java/com/mooctest/crowd/site/controller/advice/ExceptionAdvice.java

@@ -19,22 +19,22 @@ public class ExceptionAdvice {
 
 
     @ExceptionHandler(BaseException.class)
     @ExceptionHandler(BaseException.class)
     @ResponseStatus(HttpStatus.BAD_REQUEST)
     @ResponseStatus(HttpStatus.BAD_REQUEST)
-    public ResponseMessage handleException(Exception e){
-        log.error("出错!", e);
+    public String handleException(Exception e){
+        log.error("访问出错:"+e.getMessage(), e);
         if (e instanceof AccountNotExistException){
         if (e instanceof AccountNotExistException){
-            return new ResponseMessage(ResponseConstant.FAIL, ResponseConstant.USER_NOT_EXISTS);
+            return ResponseConstant.USER_NOT_EXISTS;
         } else if (e instanceof CrowdTestProjectNotExistException){
         } else if (e instanceof CrowdTestProjectNotExistException){
-            return new ResponseMessage(ResponseConstant.FAIL, "项目不存在");
+            return "项目不存在";
         } else if (e instanceof CrowdTestTaskNotExistException){
         } else if (e instanceof CrowdTestTaskNotExistException){
-            return new ResponseMessage(ResponseConstant.FAIL, "任务不存在");
+            return "任务不存在";
         } else if (e instanceof CrowdTestReportNotExistException){
         } else if (e instanceof CrowdTestReportNotExistException){
-            return new ResponseMessage(ResponseConstant.FAIL, "报告不存在");
+            return "报告不存在";
         } else if (e instanceof CrowdTestTaskNoPriceException){
         } else if (e instanceof CrowdTestTaskNoPriceException){
-            return new ResponseMessage(ResponseConstant.FAIL, "项目未设置价格");
+            return "项目未设置价格";
         } else if (e instanceof PasswordErrorException){
         } else if (e instanceof PasswordErrorException){
-            return new ResponseMessage(ResponseConstant.UNAUTH, "密码错误");
+            return "密码错误";
         } else
         } else
-            return new ResponseMessage(ResponseConstant.FAIL, e.getMessage());
+            return e.getMessage();
     }
     }
 
 
     @ExceptionHandler(UnauthorizedException.class)
     @ExceptionHandler(UnauthorizedException.class)

+ 2 - 1
site/src/main/java/com/mooctest/crowd/site/data/vo/UserVO.java

@@ -19,7 +19,8 @@ public class UserVO {
     private String name;
     private String name;
     private String userName;
     private String userName;
     private String gender;
     private String gender;
-    private String mobileNum;
+    private String email;
+    private String mobile;
     private String password;
     private String password;
     private String province;
     private String province;
     private String city;
     private String city;

+ 3 - 2
site/src/main/java/com/mooctest/crowd/site/service/impl/AgencyServiceImpl.java

@@ -57,8 +57,8 @@ public class AgencyServiceImpl implements AgencyService {
             log.info("电话号码不存在,可以生成新用户");
             log.info("电话号码不存在,可以生成新用户");
         }
         }
         if (mobileExists)
         if (mobileExists)
-            throw new BaseException("手机号码已经存在,无法生成新用户");
-        User user = userAnti.register(command.getEvaluationAgencyName(), command.getMobile(), command.getMobile());
+            throw new BaseException("手机号码已经存在,请直接登录");
+        User user = userAnti.register(command.getEvaluationAgencyName(),command.getEmail(), command.getMobile(), command.getMobile());
         EvaluationAgency agency = command.toAgency();
         EvaluationAgency agency = command.toAgency();
         List<Role> roles = new ArrayList<>();
         List<Role> roles = new ArrayList<>();
         roles.add(userRepo.getRole("evaluationAgency"));
         roles.add(userRepo.getRole("evaluationAgency"));
@@ -72,6 +72,7 @@ public class AgencyServiceImpl implements AgencyService {
         userDTO.setUserVO(new UserVO(userRepo.getByID(user.getId())));
         userDTO.setUserVO(new UserVO(userRepo.getByID(user.getId())));
         userDTO.setAgencyVO(new AgencyVO(userRepo.getByID(user.getId()).getEvaluationAgency()));
         userDTO.setAgencyVO(new AgencyVO(userRepo.getByID(user.getId()).getEvaluationAgency()));
         userDTO.getUserVO().setPassword(command.getMobile());
         userDTO.getUserVO().setPassword(command.getMobile());
+        userDTO.getUserVO().setEmail(command.getEmail());
         return userDTO;
         return userDTO;
     }
     }
 
 

+ 0 - 0
tool4deploy/Dockerfile