/* * * ApkInfoController * */ package com.szwl.controller; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.szwl.model.bo.JsonMessage; import com.szwl.model.entity.TApkInfo; import com.szwl.model.entity.TEquipment; import com.szwl.model.utils.PushUtils; import com.szwl.service.TApkInfoService; import com.szwl.service.TEquipmentService; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.util.List; /** * Controller - apk信息 */ @Controller("appApkInfoController") @RequestMapping("api/appApkInfo") public class ApkInfoController { @Autowired TApkInfoService tApkInfoService; @Autowired TEquipmentService equipmentService; /** * 获得最新的更新数据 * * @param model 型号 * @return */ @ResponseBody @RequestMapping(value = "/apkinfo.htm", produces = "text/html;charset=utf-8") public String getApkInfo(String model) { if (StringUtils.isEmpty(model)) { // return JsonMessage.error("没有版本数据"); return "没有版本数据"; } LambdaQueryWrapper query = Wrappers.lambdaQuery(); query.eq(TApkInfo::getModel,model); query.orderByDesc(TApkInfo::getVersion); List list = tApkInfoService.list(query); TApkInfo info = list.get(0); if (info != null) { // return JsonMessage.success(JSONObject.toJSONString(info)); return JSONObject.toJSONString(info); } // return JsonMessage.error("没有版本数据"); return "没有版本数据"; } /** * 获得最新的更新数据 * * @param model 型号 * @return */ @ResponseBody @RequestMapping(value = "/getApkinfoList.htm", produces = "text/html;charset=utf-8") public String getApkInfoList(String model) { if (StringUtils.isEmpty(model)) { // return JsonMessage.error("没有版本数据"); return "没有版本数据"; } LambdaQueryWrapper query = Wrappers.lambdaQuery(); query.eq(TApkInfo::getModel,model); query.orderByDesc(TApkInfo::getVersion); List list = tApkInfoService.list(query); if (list.size()>0) { return JSONObject.toJSONString(list); } return "没有版本数据"; } /** * 系统自动更新 * * @param clientId * @return */ @RequestMapping(value = "/updateApk", method = RequestMethod.GET, produces = "text/html;charset=utf-8") @ResponseBody public String separate(String clientId,String url) { LambdaQueryWrapper query = Wrappers.lambdaQuery(); query.eq(TEquipment::getClientId,clientId); List list = equipmentService.list(query); TEquipment equipment = list.get(0); if (equipment == null) { return "该设备不存在"; } equipmentService.sentMessage(clientId, PushUtils.buildJson("updateApk", url).toString()); return "推送成功"; } }