parent
1fdf6fe77c
commit
c4d802580e
@ -0,0 +1,90 @@
|
||||
|
||||
package com.luoo.user.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.luoo.user.dto.response.AppUpdateDTO;
|
||||
import com.luoo.user.pojo.AppUpdate;
|
||||
import com.luoo.user.service.AppUpdateService;
|
||||
|
||||
import annotation.GlobalInterceptor;
|
||||
import annotation.VerifyParam;
|
||||
import api.Result;
|
||||
import enums.AppUpdateTypeEnum;
|
||||
import enums.RequestFrequencyTypeEnum;
|
||||
import io.swagger.annotations.Api;
|
||||
import util.StringTools;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
@Api(tags = "UpdateController")
|
||||
@RestController
|
||||
@RequestMapping("/update")
|
||||
public class UpdateController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(UpdateController.class);
|
||||
@Autowired
|
||||
private AppUpdateService appUpdateService;
|
||||
|
||||
@PostMapping("/checkVersion")
|
||||
@GlobalInterceptor
|
||||
public Result checkVersion(@RequestParam("appVersion") String appVersion,
|
||||
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId) {
|
||||
if (StringTools.isEmpty(appVersion)) {
|
||||
return Result.success();
|
||||
}
|
||||
AppUpdate appUpdate = appUpdateService.getLatestUpdate(appVersion, deviceId);
|
||||
if (appUpdate == null) {
|
||||
return Result.success();
|
||||
}
|
||||
AppUpdateDTO appUpdateDTO = new AppUpdateDTO();
|
||||
BeanUtils.copyProperties(appUpdate, appUpdateDTO);
|
||||
AppUpdateTypeEnum typeEnum = AppUpdateTypeEnum.getByType(appUpdate.getUpdateType());
|
||||
appUpdateDTO.setSize(getFileSize(appUpdate.getId() , typeEnum.getSuffix()));
|
||||
appUpdateDTO.setUpdateList(Arrays.asList(appUpdate.getUpdateDescArray()));
|
||||
return Result.success(appUpdateDTO);
|
||||
}
|
||||
|
||||
private Long getFileSize(String id, String suffix) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
@GetMapping("/download/{id}")
|
||||
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 10)
|
||||
public void download(HttpServletResponse response, @VerifyParam(required = true) @PathVariable Integer id) {
|
||||
|
||||
/*
|
||||
* OutputStream out = null; FileInputStream in = null; try { AppUpdate appUpdate
|
||||
* = appUpdateService.getAppUpdateById(id); AppUpdateTypeEnum typeEnum =
|
||||
* AppUpdateTypeEnum.getByType(appUpdate.getUpdateType()); String fileName =
|
||||
* appConfig.getAppName() + "." + appUpdate.getVersion() + typeEnum.getSuffix();
|
||||
* File file = new File(appConfig.getProjectFolder() +
|
||||
* Constants.APP_UPDATE_FOLDER + appUpdate.getId() + typeEnum.getSuffix()); if
|
||||
* (!file.exists()) { return; }
|
||||
* response.setContentType("application/x-msdownload; charset=UTF-8");
|
||||
* response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName
|
||||
* + "\""); response.setContentLengthLong(file.length());
|
||||
*
|
||||
* in = new FileInputStream(file); byte[] byteData = new byte[1024]; out =
|
||||
* response.getOutputStream(); int len = 0; while ((len = in.read(byteData)) !=
|
||||
* -1) { out.write(byteData, 0, len); } out.flush(); } catch (Exception e) {
|
||||
* logger.error("读取文件异常", e); } finally { if (out != null) { try { out.close();
|
||||
* } catch (IOException e) { logger.error("IO异常", e); } } if (in != null) { try
|
||||
* { in.close(); } catch (IOException e) { logger.error("IO异常", e); } } }
|
||||
*/
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.luoo.user.dao;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
import com.luoo.user.pojo.AppUpdate;
|
||||
|
||||
public interface AppUpdateDao extends JpaRepository<AppUpdate, String>, JpaSpecificationExecutor<AppUpdate> {
|
||||
|
||||
//AppUpdate selectLatestUpdate(String appVersion, String deviceId);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.luoo.user.dto.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class AppUpdateDTO{
|
||||
@ApiModelProperty(value = "ID")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
@ApiModelProperty(value = "版本号")
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 更新描述
|
||||
*/
|
||||
@ApiModelProperty(value = "更新描述")
|
||||
private List<String> updateList;
|
||||
@ApiModelProperty(value = "大小")
|
||||
private Long size;
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package com.luoo.user.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.luoo.user.dao.AppUpdateDao;
|
||||
import com.luoo.user.pojo.AppUpdate;
|
||||
|
||||
@Service
|
||||
public class AppUpdateService {
|
||||
|
||||
@Autowired
|
||||
private AppUpdateDao appUpdateDao;
|
||||
|
||||
/**
|
||||
* 根据条件查询列表
|
||||
*/
|
||||
/*
|
||||
* @Override public List<AppUpdate> findListByParam(AppUpdateQuery param) {
|
||||
* return this.appUpdateDao.selectList(param); }
|
||||
*
|
||||
*//**
|
||||
* 根据条件查询列表
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer findCountByParam(AppUpdateQuery param) { return
|
||||
* this.appUpdateDao.selectCount(param); }
|
||||
*
|
||||
*//**
|
||||
* 分页查询方法
|
||||
*/
|
||||
/*
|
||||
* @Override public PaginationResultVO<AppUpdate> findListByPage(AppUpdateQuery
|
||||
* param) { int count = this.findCountByParam(param); int pageSize =
|
||||
* param.getPageSize() == null ? PageSize.SIZE15.getSize() :
|
||||
* param.getPageSize();
|
||||
*
|
||||
* SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
|
||||
* param.setSimplePage(page); List<AppUpdate> list =
|
||||
* this.findListByParam(param); PaginationResultVO<AppUpdate> result = new
|
||||
* PaginationResultVO(count, page.getPageSize(), page.getPageNo(),
|
||||
* page.getPageTotal(), list); return result; }
|
||||
*
|
||||
*//**
|
||||
* 新增
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer add(AppUpdate bean) { return
|
||||
* this.appUpdateDao.insert(bean); }
|
||||
*
|
||||
*//**
|
||||
* 批量新增
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer addBatch(List<AppUpdate> listBean) { if (listBean ==
|
||||
* null || listBean.isEmpty()) { return 0; } return
|
||||
* this.appUpdateDao.insertBatch(listBean); }
|
||||
*
|
||||
*//**
|
||||
* 批量新增或者修改
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer addOrUpdateBatch(List<AppUpdate> listBean) { if
|
||||
* (listBean == null || listBean.isEmpty()) { return 0; } return
|
||||
* this.appUpdateDao.insertOrUpdateBatch(listBean); }
|
||||
*
|
||||
*//**
|
||||
* 多条件更新
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer updateByParam(AppUpdate bean, AppUpdateQuery param)
|
||||
* { StringTools.checkParam(param); return this.appUpdateDao.updateByParam(bean,
|
||||
* param); }
|
||||
*
|
||||
*//**
|
||||
* 多条件删除
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer deleteByParam(AppUpdateQuery param) {
|
||||
* StringTools.checkParam(param); return this.appUpdateDao.deleteByParam(param);
|
||||
* }
|
||||
*
|
||||
*//**
|
||||
* 根据Id获取对象
|
||||
*/
|
||||
/*
|
||||
* @Override public AppUpdate getAppUpdateById(Integer id) { return
|
||||
* this.appUpdateDao.selectById(id); }
|
||||
*
|
||||
*//**
|
||||
* 根据Id修改
|
||||
*/
|
||||
|
||||
/*
|
||||
* @Override public Integer updateAppUpdateById(AppUpdate bean, Integer id) {
|
||||
* return this.appUpdateDao.updateById(bean, id); }
|
||||
*
|
||||
*//**
|
||||
* 根据Id删除
|
||||
*//*
|
||||
* @Override public Integer deleteAppUpdateById(Integer id) { return
|
||||
* this.appUpdateDao.deleteById(id); }
|
||||
*
|
||||
* @Override
|
||||
*
|
||||
* @Transactional(rollbackFor = Exception.class) public void
|
||||
* saveUpdate(AppUpdate appUpdate, MultipartFile file) { AppUpdateQuery
|
||||
* updateQuery = new AppUpdateQuery(); updateQuery.setOrderBy("id desc");
|
||||
* updateQuery.setSimplePage(new SimplePage(0, 1)); List<AppUpdate>
|
||||
* appUpdateList = appUpdateDao.selectList(updateQuery); if
|
||||
* (!appUpdateList.isEmpty()) { AppUpdate latest = appUpdateList.get(0); Long
|
||||
* dbVerion = Long.parseLong(latest.getVersion().replace(".", "")); Long
|
||||
* currentVersion = Long.parseLong(appUpdate.getVersion().replace(".", "")); if
|
||||
* (appUpdate.getId() == null && currentVersion <= dbVerion) { throw new
|
||||
* BusinessException("当前版本必须大于历史版本"); } if (appUpdate.getId() != null &&
|
||||
* currentVersion <= dbVerion &&
|
||||
* !appUpdate.getVersion().equals(latest.getVersion())) { throw new
|
||||
* BusinessException("当前版本必须大于历史版本"); } } if (appUpdate.getId() == null) {
|
||||
* appUpdate.setCreateTime(new Date());
|
||||
* appUpdate.setStatus(AppUpdateSatusEnum.INIT.getStatus());
|
||||
* appUpdateDao.insert(appUpdate); } else { appUpdate.setStatus(null);
|
||||
* appUpdate.setGrayscaleDevice(null); appUpdateDao.updateById(appUpdate,
|
||||
* appUpdate.getId()); } if (file != null) { File folder = new
|
||||
* File(appConfig.getProjectFolder() + Constants.APP_UPDATE_FOLDER); if
|
||||
* (!folder.exists()) { folder.mkdirs(); } AppUpdateTypeEnum typeEnum =
|
||||
* AppUpdateTypeEnum.getByType(appUpdate.getUpdateType()); try {
|
||||
* file.transferTo(new File(folder.getAbsolutePath() + "/" + appUpdate.getId() +
|
||||
* typeEnum.getSuffix())); } catch (IOException e) { throw new
|
||||
* BusinessException("更新App失败"); } } }
|
||||
*
|
||||
* @Override public void postUpdate(Integer id, Integer status, String
|
||||
* grayscaleDevice) { AppUpdateSatusEnum satusEnum =
|
||||
* AppUpdateSatusEnum.getByStatus(status); if (status == null) { throw new
|
||||
* BusinessException(ResponseCodeEnum.CODE_600); } if
|
||||
* (AppUpdateSatusEnum.GRAYSCALE == satusEnum &&
|
||||
* StringTools.isEmpty(grayscaleDevice)) { throw new
|
||||
* BusinessException(ResponseCodeEnum.CODE_600); } if
|
||||
* (AppUpdateSatusEnum.GRAYSCALE != satusEnum) { grayscaleDevice = ""; }
|
||||
* AppUpdate update = new AppUpdate(); update.setStatus(status);
|
||||
* update.setGrayscaleDevice(grayscaleDevice); appUpdateDao.updateById(update,
|
||||
* id); }
|
||||
*/
|
||||
|
||||
public AppUpdate getLatestUpdate(String appVersion, String deviceId) {
|
||||
//return appUpdateDao.selectLatestUpdate(appVersion, deviceId);
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue