f4655bd2a9b791302c9cb2a3f5df0ad103a88332.svn-base 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.iamberry.app.api.controller;
  2. import java.util.List;
  3. import org.springframework.stereotype.Controller;
  4. import org.springframework.web.bind.WebDataBinder;
  5. import org.springframework.web.bind.annotation.InitBinder;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RequestMethod;
  8. import org.springframework.web.bind.annotation.RequestParam;
  9. import org.springframework.web.bind.annotation.ResponseBody;
  10. import com.iamberry.app.api.util.Utility;
  11. import com.iamberry.app.config.Response;
  12. import com.iamberry.app.core.entity.Machine;
  13. /**
  14. * 机器操作接口
  15. * @author Moon Cheng
  16. * @date 2016年3月23日 下午2:22:25
  17. */
  18. @Controller
  19. @RequestMapping("/secure/machine")
  20. public class MachineController extends BaseController {
  21. @InitBinder("machine")
  22. public void initBinderMachine(WebDataBinder binder) {
  23. binder.setFieldDefaultPrefix("machine.");
  24. }
  25. /**
  26. * 设置机器信息
  27. *
  28. * @author Moon Cheng
  29. * @param machine 机器信息
  30. * @param token 用户token
  31. * @return
  32. */
  33. @RequestMapping(value = "/set_machine", method = RequestMethod.POST)
  34. @ResponseBody
  35. private Response setMachine(Machine machine, @RequestParam("token") String token) {
  36. String ip = Utility.getIp(request);
  37. machine = machineService.setMachine(machine, token, ip);
  38. if (machine == null) {
  39. return Response.INVALID_TOKEN;
  40. }
  41. return Response.SUCCESS.setData(machine, 1);
  42. }
  43. /**
  44. * 更新机器状态
  45. * @author Moon Cheng
  46. * @param machineId 机器id
  47. * @param status 机器状态
  48. * @param token 唯一标识符
  49. * @return 2100:无效token; 1000:请求成功;
  50. */
  51. @RequestMapping(value = "/update_machine_status", method = RequestMethod.POST)
  52. @ResponseBody
  53. private Response updateMachineStatus(@RequestParam("machine_id") Long machineId,
  54. @RequestParam("status") String status, @RequestParam("token") String token) {
  55. int reslut = machineService.updateMachineStatus(machineId, status, token);
  56. if (reslut == -1) {
  57. return Response.INVALID_TOKEN;
  58. }
  59. return Response.SUCCESS.setData(null);
  60. }
  61. /**
  62. * 更新机器地理位置
  63. * @author Moon Cheng
  64. * @param machineId 机器id
  65. * @param location 机器位置
  66. * @param token 唯一标识符
  67. * @return
  68. */
  69. @RequestMapping(value = "/update_machine_location", method = RequestMethod.POST)
  70. @ResponseBody
  71. private Response updateMachineLocation(@RequestParam("machine_id") Long machineId,
  72. @RequestParam("location") String location, @RequestParam("token") String token) {
  73. int reslut = machineService.updateMachineLocation(machineId, location, token);
  74. if (reslut == -1) {
  75. return Response.INVALID_TOKEN;
  76. }
  77. return Response.SUCCESS.setData(null);
  78. }
  79. /**
  80. * 按用户,查询机器
  81. * @author Moon Cheng
  82. * @param owner 用户id
  83. * @param token 唯一标识符
  84. * @return
  85. */
  86. @RequestMapping(value = "/search_machine_by_owner", method = RequestMethod.POST)
  87. @ResponseBody
  88. private Response searchMachineByOwner(@RequestParam("user_id") Long owner, @RequestParam("token") String token) {
  89. List<Machine> machines = machineService.searchMachineByOwner(owner, token);
  90. if (machines == null) {
  91. return Response.INVALID_TOKEN;
  92. }
  93. return Response.SUCCESS.setData(machines, machines.size());
  94. }
  95. /**
  96. * 按机器id,查询机器
  97. * @author Moon Cheng
  98. * @param machineId 机器id
  99. * @param token 用户唯一标识符
  100. * @return
  101. */
  102. @RequestMapping(value = "/search_machine_by_id", method = RequestMethod.POST)
  103. @ResponseBody
  104. private Response searchMachineById(@RequestParam("machine_id") Long machineId,
  105. @RequestParam("token") String token) {
  106. Machine machine = machineService.searchMachineById(machineId, token);
  107. if (machine == null) {
  108. return Response.INVALID_TOKEN;
  109. }
  110. return Response.SUCCESS.setData(machine, 1);
  111. }
  112. /**
  113. * updateStatus
  114. * 更改机器在线状态
  115. * @param status
  116. * @return
  117. */
  118. @RequestMapping(value = "/update_status", method = RequestMethod.POST)
  119. @ResponseBody
  120. private Response updateStatus(@RequestParam("status") String status) {
  121. machineService.updateStatus(status);
  122. return Response.SUCCESS;
  123. }
  124. }