1.add update interface and pseudo implement

main
Gary 10 months ago
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,134 @@
package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import enums.DateTimePatternEnum;
import util.DateUtil;
import util.StringTools;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="tb_app_update")
public class AppUpdate implements Serializable {
private static final long serialVersionUID = 3346259101374338244L;
/**
* ID
*/
@Id
private String id;
/**
*
*/
private String version;
/**
*
*/
private String updateDesc;
/**
* 0: 1:
*/
private Integer updateType;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 0: 1: 2:
*/
private Integer status;
/**
* ID
*/
private String grayscaleDevice;
private String[] updateDescArray;
public String[] getUpdateDescArray() {
if (!StringTools.isEmpty(updateDesc)) {
return updateDesc.split("\\|");
}
return updateDescArray;
}
public void setUpdateDescArray(String[] updateDescArray) {
this.updateDescArray = updateDescArray;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
public void setVersion(String version) {
this.version = version;
}
public String getVersion() {
return this.version;
}
public void setUpdateDesc(String updateDesc) {
this.updateDesc = updateDesc;
}
public String getUpdateDesc() {
return this.updateDesc;
}
public void setUpdateType(Integer updateType) {
this.updateType = updateType;
}
public Integer getUpdateType() {
return this.updateType;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getCreateTime() {
return this.createTime;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getStatus() {
return this.status;
}
public void setGrayscaleDevice(String grayscaleDevice) {
this.grayscaleDevice = grayscaleDevice;
}
public String getGrayscaleDevice() {
return this.grayscaleDevice;
}
@Override
public String toString() {
return "自增ID:" + (id == null ? "空" : id) + ",版本号:" + (version == null ? "空" : version) + ",更新描述:" + (updateDesc == null ? "空" : updateDesc) + "更新类型0:全更新 1:局部热更新:" + (updateType == null ? "空" : updateType) + ",创建时间:" + (createTime == null ? "空" : DateUtil.format(createTime, DateTimePatternEnum.YYYY_MM_DD_HH_MM_SS.getPattern())) + "0:未发布 1:灰度发布 2:全网发布:" + (status == null ? "空" : status) + "灰度设备ID:" + (grayscaleDevice == null ? "空" : grayscaleDevice);
}
}

@ -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…
Cancel
Save