Helius
2021-01-25 89e17a219d8a6d208e4cb32a43e90abb89b3c93b
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
package com.matrix.system.hive.action;
 
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.constance.SystemConstance;
import com.matrix.system.hive.bean.SysVipInfo;
import com.matrix.system.hive.plugin.util.BaseServices;
 
import java.util.List;
/**
 * @description 除了特殊的action一般业务action都继承这个action来实现
 * 基本增删改查功能
 * @author 姜友瑶
 * @email 935090232@qq.com
 * @date 2016-06-26
 */
public abstract class BaseController {
 
    public <T> AjaxResult add(BaseServices<T> baseServices, T t, String name) {
        int i = baseServices.add(t);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, name + "添加成功");
        } else {
            return new AjaxResult(AjaxResult.STATUS_FAIL, name + "添加失败");
        }
    }
 
    public <T> AjaxResult modify(BaseServices<T> baseServices, T t, String name) {
        int i = baseServices.modify(t);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, name +"修改成功");
        } else {
            return new AjaxResult(AjaxResult.STATUS_FAIL, name +"修改失败");
        }
    }
 
    public <T> AjaxResult remove(BaseServices<T> baseServices, String keys) {
        List<Long> ids = StringUtils.strToCollToLong(keys, ",");
        int i = baseServices.remove(ids);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "成功删除" + i + "条数据");
        } else {
            return new AjaxResult(AjaxResult.STATUS_FAIL, "删除失败");
        }
    }
 
    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;
    }
 
    public <T> AjaxResult findByModel(BaseServices<T> baseServices, T t) {
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS,  baseServices.findByModel(t), 0);
        return result;
    }
 
    public <T> T findById(BaseServices<T> baseServices, Long id) {
        return baseServices.findById(id);
    }
 
    
    /**
     * 获取登录员工登录对象
     * @author 姜友瑶
     * @date 2016/7/5
     */
    public SysUsers getMe() {
        return (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
    
    }
 
    /**
     * 获取当前操作的会员对象
     * @author 姜友瑶
     * @date 2016/7/5
     */
    public SysVipInfo getCurrentVioInfo() {
        return (SysVipInfo) (WebUtil.getSession().getAttribute(SystemConstance.CURRENT_CUSTOMER));
    }
 
 
}