VersionController.java 1.9 KB

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