c851b9c00950093e9785e660ffbafec917bb12ea.svn-base 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.yihu.jkedu.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import net.sf.json.JSONObject;
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import com.yihu.base.ConfigUtil;
  8. import com.yihu.utils.ApiUtil;
  9. import com.yihu.utils.StringUtil;
  10. import com.yihu.wsgw.api.ServiceBus;
  11. @Controller
  12. @RequestMapping("/user")
  13. public class UserControl
  14. {
  15. @RequestMapping(value = "/queryUserInfoByID")
  16. public void queryUserInfoByID(HttpServletRequest request,
  17. HttpServletResponse response) throws Exception {
  18. try {
  19. response.setContentType("application/json;charset=UTF-8");
  20. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  21. if(StringUtil.isEmpty(userId)){
  22. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  23. return;
  24. }
  25. JSONObject params = new JSONObject();
  26. params.put("userId", userId);
  27. String formResult = ServiceBus.getInstance(
  28. null,
  29. ConfigUtil.getInstance().getAppId()).call(
  30. "UserMgmt.User.queryUserInfoByID", params.toString(), false);
  31. System.out.println(formResult);
  32. JSONObject formResultObj = JSONObject.fromObject(formResult);
  33. int code = formResultObj.getInt("Code");
  34. String msg = formResultObj.getString("Message");
  35. JSONObject resultJson = new JSONObject();
  36. if (code == 10000) {// 成功
  37. JSONObject arrform = formResultObj.getJSONObject("Result");
  38. if(arrform!=null){
  39. resultJson.put("Code", 10000);
  40. resultJson.put("Message", msg);
  41. resultJson.put("Result", arrform);
  42. response.getWriter().write(resultJson.toString());
  43. return ;
  44. }
  45. }
  46. resultJson.put("Code", -10000);
  47. resultJson.put("Message", msg);
  48. resultJson.put("Result", null);
  49. response.getWriter().write(resultJson.toString());
  50. return ;
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取用户信息异常").toString());
  54. return ;
  55. }
  56. }
  57. }