Helius
2020-12-17 f76c9c5beb39916771402de95f05be18f39a9db6
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package com.matrix.core.web;
 
import java.util.List;
 
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.constance.SystemMessageCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.InternationaUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
 
/**
 * @description 除了特殊的action一般业务action都继承这个action来实现 基本增删改查功能
 * @author 姜友瑶
 * @email 935090232@qq.com
 * @date 2016-06-26
 */
public abstract class BaseAction {
 
    /**
     * 新增记录
     * @author JIANGYOUYAO
     * @email 935090232@qq.com
     * @date 2017年11月30日
     * @param baseServices
     * @param t
     * @param name
     * @return
     */
    public <T> AjaxResult add(BaseServices<T> baseServices, T t, String name) {
        int i = baseServices.add(t);
        if (i > 0) {
            name=InternationaUtil.getMesssge(name);
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, name);
        } else {
            throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL);
        }
    }
 
    /**
     * 修改记录
     * @author JIANGYOUYAO
     * @email 935090232@qq.com
     * @date 2017年11月30日
     * @param baseServices
     * @param oldValue
     * @param newValue
     * @param name
     * @return
     */
    @SuppressWarnings("unchecked")
    public <T> AjaxResult modify(BaseServices<T> baseServices, Object oldValue, T newValue, String name) {
        int i = baseServices.modifyByMap((T) oldValue, newValue);
        if (i > 0) {
            name=InternationaUtil.getMesssge(name);
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, name);
        } else {
            throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL);
        }
    }
 
    /**
     * 批量删除
     * @author JIANGYOUYAO
     * @email 935090232@qq.com
     * @date 2017年11月30日
     * @param baseServices
     * @param keys
     * @return
     */
    public <T> AjaxResult remove(BaseServices<T> baseServices, String keys) {
        List<String> ids = StringUtils.strToCollToString(keys, ",");
        int i = baseServices.remove(ids);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i);
        } else {
            throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL);
        }
    }
 
    /**
     * 分页查询
     * @author JIANGYOUYAO
     * @email 935090232@qq.com
     * @date 2017年11月30日
     * @param baseServices
     * @param t
     * @param pageVo
     * @return
     */
    public <T> AjaxResult showList(BaseServices<T> baseServices, T t, PaginationVO pageVo) {
 
        List<T> dataList = baseServices.findInPage(t, pageVo);
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, baseServices.findTotal(t));
        return result;
    }
 
    /**
     * 带条件查询,不分页
     * @author JIANGYOUYAO
     * @email 935090232@qq.com
     * @date 2017年11月30日
     * @param baseServices
     * @param t
     * @return
     */
    public <T> AjaxResult findByModel(BaseServices<T> baseServices, T t) {
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, baseServices.findByModel(t), 0);
        return result;
    }
 
    /**
     * 根据id查询
     * @author JIANGYOUYAO
     * @email 935090232@qq.com
     * @date 2017年11月30日
     * @param baseServices
     * @param id
     * @return
     */
    public <T> T findById(BaseServices<T> baseServices, String id) {
        return baseServices.findById(id);
    }
 
    /**
     * 获取登录对象
     * 
     * @author 姜友瑶
     * @date 2016/7/5
     */
    public <T> T getSessionUser() {
        return WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
    }
 
}