summaryrefslogtreecommitdiff
path: root/src/main/java/com/mesasoft/cn/dao/sqlprovider/AuthSqlProvider.java
blob: 3c9c10fe73acbc49d5d716a8a5c5dc4f47ce5928 (plain)
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
package com.mesasoft.cn.dao.sqlprovider;

import com.mesasoft.cn.SketchApplication;
import com.mesasoft.cn.modules.constant.ConfigConsts;
import com.zhazhapan.util.Checker;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author pantao
 * @since 2018/1/19
 */
public class AuthSqlProvider {

    public String updateAuthById() {
        return CommonSqlProvider.updateAuthById("auth");
    }

    public String batchDelete(@Param("ids") String ids) {
        return "delete from auth where id in " + (ids.startsWith("(") ? "" : "(") + ids + (ids.endsWith(")") ? "" :
                ")");
    }

    public String getAuthBy(@Param("id") long id, @Param("userId") int userId, @Param("fileId") long fileId, @Param
            ("fileName") String fileName, @Param("offset") int offset) {
        String sql = new SQL() {{
            SELECT("a.id,a.user_id,a.file_id,u.username,f.name file_name,f.local_url,a.is_downloadable,a" + "" + "" +
                    ".is_uploadable,a.is_deletable,a.is_updatable,a.is_visible,a.create_time");
            FROM("auth a");
            JOIN("user u on u.id=a.user_id");
            JOIN("file f on f.id=a.file_id");
            if (id > 0) {
                WHERE("a.id=#{id}");
            }
            if (userId > 0) {
                WHERE("u.id=#{userId}");
            }
            if (fileId > 0) {
                WHERE("f.id=#{fileId}");
            } else if (Checker.isNotEmpty(fileName)) {
                WHERE("f.local_url like '%" + fileName + "%'");
            }
            ORDER_BY("a." + SketchApplication.settings.getStringUseEval(ConfigConsts.AUTH_ORDER_BY_OF_SETTINGS));
        }}.toString();
        int size = SketchApplication.settings.getIntegerUseEval(ConfigConsts.AUTH_PAGE_SIZE_OF_SETTINGS);
        return sql + " limit " + (offset * size) + "," + size;
    }
}