ApkInfoController.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. *
  3. * ApkInfoController
  4. *
  5. */
  6. package com.szwl.controller;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  9. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  10. import com.szwl.model.bo.JsonMessage;
  11. import com.szwl.model.entity.TApkInfo;
  12. import com.szwl.model.entity.TEquipment;
  13. import com.szwl.model.utils.PushUtils;
  14. import com.szwl.service.TApkInfoService;
  15. import com.szwl.service.TEquipmentService;
  16. import org.apache.commons.lang.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Controller;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RequestMethod;
  21. import org.springframework.web.bind.annotation.ResponseBody;
  22. import javax.annotation.Resource;
  23. import java.util.List;
  24. /**
  25. * Controller - apk信息
  26. */
  27. @Controller("appApkInfoController")
  28. @RequestMapping("api/appApkInfo")
  29. public class ApkInfoController {
  30. @Autowired
  31. TApkInfoService tApkInfoService;
  32. @Autowired
  33. TEquipmentService equipmentService;
  34. /**
  35. * 获得最新的更新数据
  36. *
  37. * @param model 型号
  38. * @return
  39. */
  40. @ResponseBody
  41. @RequestMapping(value = "/apkinfo.htm", produces = "text/html;charset=utf-8")
  42. public String getApkInfo(String model) {
  43. if (StringUtils.isEmpty(model)) {
  44. // return JsonMessage.error("没有版本数据");
  45. return "没有版本数据";
  46. }
  47. LambdaQueryWrapper<TApkInfo> query = Wrappers.lambdaQuery();
  48. query.eq(TApkInfo::getModel,model);
  49. query.orderByDesc(TApkInfo::getVersion);
  50. List<TApkInfo> list = tApkInfoService.list(query);
  51. TApkInfo info = list.get(0);
  52. if (info != null) {
  53. // return JsonMessage.success(JSONObject.toJSONString(info));
  54. return JSONObject.toJSONString(info);
  55. }
  56. // return JsonMessage.error("没有版本数据");
  57. return "没有版本数据";
  58. }
  59. /**
  60. * 获得最新的更新数据
  61. *
  62. * @param model 型号
  63. * @return
  64. */
  65. @ResponseBody
  66. @RequestMapping(value = "/getApkinfoList.htm", produces = "text/html;charset=utf-8")
  67. public String getApkInfoList(String model) {
  68. if (StringUtils.isEmpty(model)) {
  69. // return JsonMessage.error("没有版本数据");
  70. return "没有版本数据";
  71. }
  72. LambdaQueryWrapper<TApkInfo> query = Wrappers.lambdaQuery();
  73. query.eq(TApkInfo::getModel,model);
  74. query.orderByDesc(TApkInfo::getVersion);
  75. List<TApkInfo> list = tApkInfoService.list(query);
  76. if (list.size()>0) {
  77. return JSONObject.toJSONString(list);
  78. }
  79. return "没有版本数据";
  80. }
  81. /**
  82. * 系统自动更新
  83. *
  84. * @param clientId
  85. * @return
  86. */
  87. @RequestMapping(value = "/updateApk", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  88. @ResponseBody
  89. public String separate(String clientId,String url) {
  90. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  91. query.eq(TEquipment::getClientId,clientId);
  92. List<TEquipment> list = equipmentService.list(query);
  93. TEquipment equipment = list.get(0);
  94. if (equipment == null) {
  95. return "该设备不存在";
  96. }
  97. equipmentService.sentMessage(clientId, PushUtils.buildJson("updateApk", url).toString());
  98. return "推送成功";
  99. }
  100. }