feat: checkVersion api

main
itao 10 months ago
parent ff07475aa3
commit d8c4df9cff

@ -1,11 +1,43 @@
package com.luoo.user.dao; package com.luoo.user.dao;
import com.luoo.user.pojo.AppUpdate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.luoo.user.pojo.AppUpdate; import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;
public interface AppUpdateDao extends JpaRepository<AppUpdate, String>, JpaSpecificationExecutor<AppUpdate> { public interface AppUpdateDao extends JpaRepository<AppUpdate, String>, JpaSpecificationExecutor<AppUpdate> {
//AppUpdate selectLatestUpdate(String appVersion, String deviceId); default AppUpdate selectLatestUpdate(String appVersion, String deviceId){
Specification<AppUpdate> appUpdateSpecification = createAppUpdateSpecification(appVersion, deviceId);
Sort createTimeDescSort = Sort.by(Sort.Direction.DESC, "createTime");
Page<AppUpdate> appUpdatePage = this.findAll(appUpdateSpecification, PageRequest.of(0, 1, createTimeDescSort));
if(appUpdatePage.getContent().isEmpty()){
return null;
}
return appUpdatePage.getContent().get(0);
}
default Specification<AppUpdate> createAppUpdateSpecification(String appVersion, String deviceId) {
return (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
predicateList.add(criteriaBuilder.greaterThan(root.get("version"), appVersion));
Predicate allPublishPredicate = criteriaBuilder.equal(root.get("status"), 2);
Predicate grayPublishPredicate = criteriaBuilder.equal(root.get("status"), 1);
Expression<Integer> grayDeviceExpress = criteriaBuilder
.function("find_in_set", Integer.class, criteriaBuilder.literal(deviceId), root.get("grayscaleDevice"));
Predicate grayDevicePredicate = criteriaBuilder.gt(grayDeviceExpress, 0);
Predicate grayScalePredicate = criteriaBuilder.and(grayPublishPredicate, grayDevicePredicate);
predicateList.add(criteriaBuilder.or(allPublishPredicate, grayScalePredicate));
Predicate[] predicates = new Predicate[predicateList.size()];
return criteriaBuilder.and(predicateList.toArray(predicates));
};
}
} }

@ -11,9 +11,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import javax.persistence.Entity; import javax.persistence.*;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity @Entity
@ -58,6 +56,7 @@ public class AppUpdate implements Serializable {
*/ */
private String grayscaleDevice; private String grayscaleDevice;
@Transient
private String[] updateDescArray; private String[] updateDescArray;
public String[] getUpdateDescArray() { public String[] getUpdateDescArray() {

@ -151,7 +151,6 @@ public class AppUpdateService {
*/ */
public AppUpdate getLatestUpdate(String appVersion, String deviceId) { public AppUpdate getLatestUpdate(String appVersion, String deviceId) {
//return appUpdateDao.selectLatestUpdate(appVersion, deviceId); return appUpdateDao.selectLatestUpdate(appVersion, deviceId);
return null;
} }
} }

@ -0,0 +1,14 @@
-- 创建表
drop table if exists indie_user.tb_app_update;
create table if not exists indie_user.tb_app_update (
id varchar(100) not null comment 'ID' primary key,
version varchar(10) default '' not null comment '版本号',
update_desc varchar(500) default '' not null comment '更新描述',
update_type tinyint(1) default 0 not null comment '更新类型(0=全更新, 1=局部热更新)',
status tinyint(1) default 1 not null comment '状态(0=未发布, 1=灰度发布, 2=全网发布)',
grayscale_device varchar(4000) default '' not null comment '灰度设备ID集合(英文逗号相隔)',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间'
) comment '应用版本更新记录表';
create index idx_version on indie_user.tb_app_update (version);
create index idx_create_time on indie_user.tb_app_update (create_time);
Loading…
Cancel
Save