liulin
2024-07-29 b65029f9d6e351a714682c110343a8c23eb4e793
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
#                                                    __----~~~~~~~~~~~------___
#                                   .  .   ~~//====......          __--~ ~~
#                   -.            \_|//     |||\\  ~~~~~~::::... /~
#                ___-==_       _-~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))
        );
    }
}