VersionController.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.yihu.wlyy.web.common.version;
  2. import io.swagger.annotations.Api;
  3. import org.json.JSONObject;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.ResponseBody;
  8. import com.yihu.wlyy.entity.Versions;
  9. import com.yihu.wlyy.service.app.version.VersionsService;
  10. import com.yihu.wlyy.web.BaseController;
  11. /**
  12. * 版本号控制类
  13. * @author George
  14. *
  15. */
  16. @Controller
  17. @RequestMapping(value = "/version")
  18. @Api(description = "版本")
  19. public class VersionController extends BaseController {
  20. @Autowired
  21. private VersionsService versionsService;
  22. /**
  23. * 校验APP版本号
  24. * @param code 版本类型编码
  25. * @param version 当前版本号
  26. * @return
  27. */
  28. @RequestMapping(value = "app")
  29. @ResponseBody
  30. public String appVersion(String code, double version) {
  31. try {
  32. Versions temp = versionsService.findVersionByCode(code);
  33. if (temp == null) {
  34. return error(-1, "无效的APP类型失败!");
  35. }
  36. if (version > 0) {
  37. if (temp.getVersionInt() > version) {
  38. // 有新的版本号
  39. return write(200, "发现新版本!", "url", temp.getUrl());
  40. } else {
  41. // 已是最新版本
  42. return write(200, "已是最新版本!");
  43. }
  44. } else {
  45. JSONObject json = new JSONObject();
  46. json.put("version_int", temp.getVersionInt());
  47. json.put("version_str", temp.getVersionStr());
  48. json.put("url", temp.getUrl());
  49. json.put("info", temp.getInfo());
  50. json.put("size", temp.getSize());
  51. return write(200, "读取版本号成功!", "data", json);
  52. }
  53. } catch (Exception e) {
  54. error(e);
  55. return error(-1, "版本号校验失败!");
  56. }
  57. }
  58. }