PageRenderTime 56ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/211AuthcenterProject/authcenter-web/src/main/java/com/fdhay/authcenter/web/controller/api/OrganizationRegisterAPI.java

http://java-hiking.googlecode.com/
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
  1. package com.fdhay.authcenter.web.controller.api;
  2. import javax.annotation.Resource;
  3. import org.apache.commons.lang.StringUtils;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestMethod;
  7. import org.springframework.web.servlet.ModelAndView;
  8. import com.alibaba.fastjson.JSON;
  9. import com.fdhay.authcenter.domain.OrganizationRegister;
  10. import com.fdhay.authcenter.domain.annotation.Authorization;
  11. import com.fdhay.authcenter.domain.base.json.JsonMessage;
  12. import com.fdhay.authcenter.domain.enums.AuthorizationType;
  13. import com.fdhay.authcenter.domain.enums.JsonMessageResultStatusEnum;
  14. import com.fdhay.authcenter.service.OrganizationRegisterService;
  15. import com.fdhay.authcenter.web.controller.OrganizationRegisterController;
  16. @Controller
  17. @RequestMapping("/api/organitionRegister")
  18. public class OrganizationRegisterAPI extends OrganizationRegisterController{
  19. @Resource private OrganizationRegisterService organizationRegisterService;
  20. /**
  21. * <pre>
  22. * API URL: http://url:port/api/organitionRegister
  23. * 请求方式: POST
  24. * 请求参数:email=xxx&password=xxx
  25. * 请求Header:APIToken=xxx
  26. * 参数说明:
  27. * email:注册时填入的邮箱地址,注册成功后,会往这个邮件里面发送注册信息。
  28. * password:登录时的密码
  29. * APIToken:API的访问需要具有正确APIToken的才接受
  30. * </pre>
  31. * <p>
  32. * Eg: http://127.0.0.1:8080/api/organitionRegister?email=xxx&password=xxx&APIToken=xxx
  33. * </p>
  34. * @return - json格式的返回数据。
  35. * <pre>
  36. * -成功返回json格式:
  37. * {
  38. * "resultStatusCode": "sucess",
  39. * "result": {
  40. * "organizationName": "组织机构名称,可能为空",
  41. * "applicantName": "申请人姓名,可能为空",
  42. * "mobilePhone": "移动电话,可能为空",
  43. * "email": "邮箱",
  44. * "remark": "备注,可能为空",
  45. * "organizationCode": "组织机构码,系统自动生成的,eg:org_123456789",
  46. * "userName": "用户名,系统自动生成的,eg:u_123456789"
  47. * }
  48. * }
  49. * -失败返回的json格式:
  50. * {
  51. * "resultStatusCode": "fail",
  52. * "result": "fail message description"
  53. * }
  54. * </pre>
  55. */
  56. @RequestMapping(value="", method={RequestMethod.POST})
  57. @Authorization(type=AuthorizationType.API, code="API_ORGANITION_REGISTER")
  58. public ModelAndView register(OrganizationRegister organizationRegister){
  59. if(StringUtils.isEmpty(organizationRegister.getEmail())){
  60. return toJSON(new JsonMessage(JsonMessageResultStatusEnum.FAIL, "邮件不能为空"));
  61. }
  62. if(StringUtils.isEmpty(organizationRegister.getPassword())){
  63. return toJSON(new JsonMessage(JsonMessageResultStatusEnum.FAIL, "密码不能为空"));
  64. }
  65. //添加到数据库
  66. super.addRecordToDB(organizationRegister);
  67. organizationRegister = organizationRegisterService.selectByPrimaryKey(organizationRegister.getId());
  68. if(organizationRegister == null){
  69. return toJSON(new JsonMessage(JsonMessageResultStatusEnum.FAIL, "机构申请注册记录不存在"));
  70. }
  71. try {
  72. doApproveInternal(organizationRegister);
  73. } catch (Exception e) {
  74. logger.error(e);
  75. String msg = e.getMessage() != null ? e.getMessage() : "";
  76. doRejectInternal(organizationRegister, msg);
  77. return toJSON(new JsonMessage(JsonMessageResultStatusEnum.FAIL, "申请被拒绝:" + msg));
  78. }
  79. JsonMessage message = new JsonMessage(JsonMessageResultStatusEnum.SUCESS, JSON.toJSONString(organizationRegister));
  80. return toJSON(message);
  81. }
  82. }