/**
|
# __----~~~~~~~~~~~------___
|
# . . ~~//====...... __--~ ~~
|
# -. \_|// |||\\ ~~~~~~::::... /~
|
# ___-==_ _-~o~ \/ ||| \\ _/~~-
|
# __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~
|
# _-~~ .=~ | \\-_ '-~7 /- / || \ /
|
# .~ .~ | \\ -_ / /- / || \ /
|
# / ____ / | \\ ~-_/ /|- _/ .|| \ /
|
# |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\
|
# ' ~-| /| |-~\~~ __--~~
|
# |-~~-_/ | | ~\_ _-~ /\
|
# / \ \__ \/~ \__
|
# _--~ _/ | .-~~____--~-/ ~~==.
|
# ((->/~ '.|||' -_| ~~-/ , . _||
|
# -_ ~\ ~~---l__i__i__i--~~_/
|
# _-~-__ ~) \--______________--~~
|
# //.-~~~-~_--~- |-------~~~~~~~~
|
# //.-~~~--\
|
# 神兽保佑
|
# 永无BUG!
|
*/
|
package com.lunhan.xxx.repository.dao;
|
|
import com.lunhan.xxx.common.ConstantFactory;
|
import com.lunhan.xxx.common.PagerResult;
|
import com.lunhan.xxx.common.orm2.SqlBuilder;
|
import com.lunhan.xxx.common.util.ListUtil;
|
import com.lunhan.xxx.common.util.NumericUtil;
|
import com.lunhan.xxx.common.util.StringUtil;
|
import com.lunhan.xxx.entity.dto.OrderByDTO;
|
import com.lunhan.xxx.entity.dto.search.SearchTestInfo;
|
import com.lunhan.xxx.entity.enums.EOrderBy;
|
import com.lunhan.xxx.entity.enums.EState;
|
import com.lunhan.xxx.repository.BasicDao;
|
import com.lunhan.xxx.repository.columns.ETestInfo;
|
import com.lunhan.xxx.repository.po.TestInfoPO;
|
import org.springframework.stereotype.Repository;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 测试信息 数据访问类
|
* @author lin.liu
|
* @description 测试信息 数据访问类
|
* @date 2021/11/23
|
*/
|
|
@Repository
|
public class TestInfoDao extends BasicDao<TestInfoPO> {
|
TestInfoDao() {
|
super(ETestInfo.values());
|
}
|
|
public Boolean removeByListId(List<Long> listId) {
|
return super.remove(new SqlBuilder().where(ETestInfo.ID.in(listId)));
|
}
|
|
public PagerResult<TestInfoPO> search(SearchTestInfo search) {
|
SqlBuilder builder = new SqlBuilder()
|
// 分页参数
|
.page(NumericUtil.tryParseInt(search.getPage(), 1), NumericUtil.tryParseInt(search.getLimit(), 1))
|
|
// 状态 != 400
|
.and(ETestInfo.STATUS.notEqual(EState.DELETED.getValue()))
|
// 状态
|
.andIf(NumericUtil.tryParseInt(search.getStatus()).compareTo(0) > 0, ETestInfo.STATUS.equal(search.getStatus()))
|
// 状态列表
|
.andIf(ListUtil.isNotNullOrEmpty(search.getListStatus()), ETestInfo.STATUS.in(search.getListStatus()))
|
// id列表
|
.andIf(ListUtil.isNotNullOrEmpty(search.getListId()), ETestInfo.ID.in(search.getListId()))
|
// 关键字
|
.andIf(StringUtil.isNotNullOrEmpty(search.getKeywords()), ETestInfo.NAME.like(search.getKeywords()))
|
// 创建时间-起始
|
.andIf(NumericUtil.tryParseLong(search.getCreateTimeStart()).compareTo(0L) > 0, ETestInfo.CREATE_TIME.greaterOrEqual(search.getCreateTimeStart()))
|
// 创建时间-截止
|
.andIf(NumericUtil.tryParseLong(search.getCreateTimeEnd()).compareTo(0L) > 0, ETestInfo.CREATE_TIME.lessOrEqual(search.getCreateTimeEnd()))
|
;
|
|
|
if (ListUtil.isNotNullOrEmpty(search.getOrderBy())) {
|
List<String> listOrderBy = new ArrayList<>();
|
for (OrderByDTO item : search.getOrderBy()) {
|
EOrderBy orderBy = EOrderBy.getByValue(NumericUtil.tryParseInt(item.getOrderBy(), 1));
|
if (Objects.isNull(orderBy)) {
|
continue;
|
}
|
switch (orderBy) {
|
case ID:
|
listOrderBy.add(ETestInfo.ID.getColumnName() +
|
(item.getIsAsc() ? ConstantFactory.SQL_ASC : ConstantFactory.SQL_DESC)
|
);
|
break;
|
|
case CREATE_TIME:
|
listOrderBy.add(ETestInfo.CREATE_TIME.getColumnName() +
|
(item.getIsAsc() ? ConstantFactory.SQL_ASC : ConstantFactory.SQL_DESC)
|
);
|
break;
|
|
case UPDATE_TIME:
|
listOrderBy.add(ETestInfo.UPDATE_TIME.getColumnName() +
|
(item.getIsAsc() ? ConstantFactory.SQL_ASC : ConstantFactory.SQL_DESC)
|
);
|
break;
|
|
default:
|
break;
|
}
|
}
|
builder.orderBy(ListUtil.toArray(listOrderBy));
|
}
|
return super.getPageList(builder);
|
}
|
|
public List<TestInfoPO> getListById(List<Long> listId) {
|
return super.getList(new SqlBuilder()
|
.where(ETestInfo.ID.in(listId))
|
);
|
}
|
}
|