地质所 沉降监测网建设项目
chenhuan
2024-06-25 880c8f54cddc8533f00f674da3f14c2cf0d34340
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
package com.javaweb.app.common.base;
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javaweb.app.common.interceptor.AuthenticationInterceptor;
import com.javaweb.app.common.page.PageSupport;
import com.javaweb.app.common.page.ResultData;
import com.javaweb.common.core.domain.AjaxResult;
import com.javaweb.common.core.page.PageDomain;
import com.javaweb.common.utils.StringUtils;
 
import java.util.List;
 
/**
 * web层通用数据处理
 */
public class BaseAppController
{
    /**
     * 设置请求分页数据
     */
    protected void startPage()
    {
        PageDomain pageDomain = PageSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize))
        {
            String orderBy = pageDomain.getOrderBy();
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }
    }
 
    /**
     * 封装分页数据
     * @param list
     * @return
     * @author zmr
     */
    @SuppressWarnings({"unchecked", "rawtypes"})
    protected ResultData getDataPage(List<?> list)
    {
        ResultData rspData = new ResultData();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }
 
    /**
     * 响应返回结果
     * 
     * @param rows 影响行数
     * @return 操作结果
     */
    protected AjaxResult toAjax(int rows)
    {
        return rows > 0 ? success() : error();
    }
 
    /**
     * 返回成功
     */
    public AjaxResult success()
    {
        return AjaxResult.success();
    }
 
    /**
     * 返回失败消息
     */
    public AjaxResult error()
    {
        return AjaxResult.error();
    }
 
    /**
     * 返回成功消息
     */
    public AjaxResult success(String message)
    {
        return AjaxResult.success(message);
    }
 
    /**
     * 返回失败消息
     */
    public AjaxResult error(String message)
    {
        return AjaxResult.error(message);
    }
 
 
 
    /**
     * 页面跳转
     */
    public String redirect(String url)
    {
        return StringUtils.format("redirect:{}", url);
    }
 
    public static long getCurrentUserId()
    {
        Long userId = (Long) PageSupport.getRequest().getAttribute(AuthenticationInterceptor.USER_KEY);
        if (null == userId)
        {
            userId = 0l;
        }
        return userId;
    }
}