PageRenderTime 105ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/web/src/main/java/com/fasheng/web/controller/UserController.java

https://github.com/dawnsait/holywar
Java | 78 lines | 55 code | 8 blank | 15 comment | 3 complexity | e7e5f11f1ab972e98d5d438988019154 MD5 | raw file
  1. /**
  2. * Project: web
  3. *
  4. * File Created at 2011-12-15
  5. * $Id$
  6. *
  7. * Copyright 2011 FashengOL Croporation Limited.
  8. * All rights reserved.
  9. *
  10. */
  11. package com.fasheng.web.controller;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.ui.ModelMap;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.ResponseBody;
  18. import com.alibaba.fastjson.JSON;
  19. import com.fasheng.common.constants.ResponseCodeEnum;
  20. import com.fasheng.service.dto.PartnerUserDTO;
  21. import com.fasheng.service.dto.UserDTO;
  22. import com.fasheng.service.service.DataServiceLocator;
  23. import com.fasheng.service.service.interfaces.PartnerUserService;
  24. import com.fasheng.service.service.interfaces.UserService;
  25. import com.fasheng.web.helper.UserHelper;
  26. import com.fasheng.web.request.user.PartnerUserLoginRequest;
  27. import com.fasheng.web.request.user.UserRequest;
  28. import com.fasheng.web.response.BaseResponse;
  29. import com.fasheng.web.response.user.UserResponse;
  30. /**
  31. * TODO Comment of UserController
  32. * @author ZY
  33. *
  34. */
  35. @Controller
  36. @RequestMapping("/user")
  37. public class UserController {
  38. PartnerUserService partnerUserService = DataServiceLocator.getPartnerUserService();
  39. UserService userService = DataServiceLocator.getUserService();
  40. @RequestMapping(value="/register", method=RequestMethod.POST)
  41. @ResponseBody
  42. public String register(@RequestParam("requestInfo") String requestInfo, ModelMap model) {
  43. UserRequest userRequest = JSON.parseObject(requestInfo, UserRequest.class);
  44. UserDTO userDTO = UserHelper.buildUserDTO(userRequest);
  45. userDTO = userService.insert(userDTO);
  46. UserResponse response = new UserResponse();
  47. if(userDTO != null) {
  48. response.setCode(ResponseCodeEnum.SUCCESS.getCode());
  49. response.setMsg(ResponseCodeEnum.SUCCESS.getDescription() + ", userId:" + userDTO.getUserId());
  50. } else {
  51. response.setCode(ResponseCodeEnum.DB_ERROR.getCode());
  52. response.setMsg(ResponseCodeEnum.DB_ERROR.getDescription());
  53. }
  54. return JSON.toJSONString(response);
  55. }
  56. @RequestMapping(value="/partner/login", method=RequestMethod.GET)
  57. @ResponseBody
  58. public String partnerLogin(@RequestParam("requestInfo") String requestInfo, ModelMap model) {
  59. PartnerUserLoginRequest request = UserHelper.getPartnerUserLoginRequest(requestInfo);
  60. PartnerUserDTO dto = UserHelper.buildPartnerUserDTO(request);
  61. partnerUserService.insert(dto);
  62. return JSON.toJSONString(dto);
  63. }
  64. public static void main(String[] args) {
  65. BaseResponse response = new BaseResponse();
  66. response.setCode(343);
  67. response.setMsg("aaaaaa");
  68. System.out.println(JSON.toJSONString(response));
  69. }
  70. }