/211AuthcenterProject/authcenter-web/src/main/java/com/fdhay/authcenter/web/controller/api/OrganizationRegisterAPI.java
Java | 91 lines | 45 code | 9 blank | 37 comment | 5 complexity | 0326ef7a600f916a2e40574a74524350 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
- package com.fdhay.authcenter.web.controller.api;
-
- import javax.annotation.Resource;
-
- import org.apache.commons.lang.StringUtils;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.servlet.ModelAndView;
-
- import com.alibaba.fastjson.JSON;
- import com.fdhay.authcenter.domain.OrganizationRegister;
- import com.fdhay.authcenter.domain.annotation.Authorization;
- import com.fdhay.authcenter.domain.base.json.JsonMessage;
- import com.fdhay.authcenter.domain.enums.AuthorizationType;
- import com.fdhay.authcenter.domain.enums.JsonMessageResultStatusEnum;
- import com.fdhay.authcenter.service.OrganizationRegisterService;
- import com.fdhay.authcenter.web.controller.OrganizationRegisterController;
-
- @Controller
- @RequestMapping("/api/organitionRegister")
- public class OrganizationRegisterAPI extends OrganizationRegisterController{
-
- @Resource private OrganizationRegisterService organizationRegisterService;
-
- /**
- * <pre>
- * API URL: http://url:port/api/organitionRegister
- * 请求方式: POST
- * 请求参数:email=xxx&password=xxx
- * 请求Header:APIToken=xxx
- * 参数说明:
- * email:注册时填入的邮箱地址,注册成功后,会往这个邮件里面发送注册信息。
- * password:登录时的密码
- * APIToken:API的访问需要具有正确APIToken的才接受
- * </pre>
- * <p>
- * Eg: http://127.0.0.1:8080/api/organitionRegister?email=xxx&password=xxx&APIToken=xxx
- * </p>
- * @return - json格式的返回数据。
- * <pre>
- * -成功返回json格式:
- * {
- * "resultStatusCode": "sucess",
- * "result": {
- * "organizationName": "组织机构名称,可能为空",
- * "applicantName": "申请人姓名,可能为空",
- * "mobilePhone": "移动电话,可能为空",
- * "email": "邮箱",
- * "remark": "备注,可能为空",
- * "organizationCode": "组织机构码,系统自动生成的,eg:org_123456789",
- * "userName": "用户名,系统自动生成的,eg:u_123456789"
- * }
- * }
- * -失败返回的json格式:
- * {
- * "resultStatusCode": "fail",
- * "result": "fail message description"
- * }
- * </pre>
- */
- @RequestMapping(value="", method={RequestMethod.POST})
- @Authorization(type=AuthorizationType.API, code="API_ORGANITION_REGISTER")
- public ModelAndView register(OrganizationRegister organizationRegister){
- if(StringUtils.isEmpty(organizationRegister.getEmail())){
- return toJSON(new JsonMessage(JsonMessageResultStatusEnum.FAIL, "邮件不能为空"));
- }
- if(StringUtils.isEmpty(organizationRegister.getPassword())){
- return toJSON(new JsonMessage(JsonMessageResultStatusEnum.FAIL, "密码不能为空"));
- }
- //添加到数据库
- super.addRecordToDB(organizationRegister);
-
- organizationRegister = organizationRegisterService.selectByPrimaryKey(organizationRegister.getId());
- if(organizationRegister == null){
- return toJSON(new JsonMessage(JsonMessageResultStatusEnum.FAIL, "机构申请注册记录不存在"));
- }
- try {
- doApproveInternal(organizationRegister);
- } catch (Exception e) {
- logger.error(e);
- String msg = e.getMessage() != null ? e.getMessage() : "";
- doRejectInternal(organizationRegister, msg);
- return toJSON(new JsonMessage(JsonMessageResultStatusEnum.FAIL, "申请被拒绝:" + msg));
- }
-
- JsonMessage message = new JsonMessage(JsonMessageResultStatusEnum.SUCESS, JSON.toJSONString(organizationRegister));
- return toJSON(message);
- }
-
- }