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));
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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…
Reference in new issue