1
81041
2019-06-20 ab3c4acf83f54f8449ca8664c4a2bb79bd30f297
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.fgkj.services;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.ServletContext;
 
import com.fgkj.actions.ActionUtil;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.BaseDAOFactory;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.UserClient;
import com.fgkj.dto.User_inf;
import com.fgkj.dto.Vip_user;
 
public class Vip_userService extends ActionUtil{
    private ServiceModel model;
    private BaseDAO dao;
    
    
    public Vip_userService() {
        model=new ServiceModel();
        dao=BaseDAOFactory.getBaseDAO(BaseDAO.VIP_USER);
    }
    
    public ServiceModel add(Object obj) {
        Boolean bl=dao.add(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }
        else{
            model.setMsg("添加失败!");
        }
        return model;
        
    }
    public ServiceModel update(Object obj) {
        Boolean bl=dao.update(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }
        else{
            model.setMsg("修改失败!");
        }
        return model;    
    }
    public ServiceModel delete(Object obj) {
        Boolean bl=dao.del(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("删除成功!");
        }
        else{
            model.setMsg("删除失败!");
        }
        return model;    
    }
    //根据vip账号查询密码
     public ServiceModel serchByCondition(Object obj){
         
        List list=dao.serchByCondition(obj);
//        for (Object object : list) {
//            System.out.println(object);
//        }
        if(list!=null && list.size()>0){
            model.setCode(1);
            model.setData(list);
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
//       System.out.println(model);        
        return model;
    } 
    
    //超级管理员登陆
    public ServiceModel login(Object obj){
        User_inf uinf=(User_inf)obj;
        //System.out.println(uinf.getUSnId()+"    "+usnId64+"   "+usnIdMd5+"     :service");
        Vip_user vuser=new Vip_user();
        vuser.setVipname(uinf.getUName());
        List<Vip_user> list = dao.serchByCondition(vuser);
        model=new ServiceModel();
        if(list!=null && list.size()>0){
            for(int i=0;i<list.size();i++){
                if(list.get(i).getVipname().equals(uinf.getUName()) && list.get(i).getVipPassword().equals(uinf.getUpassword())){
                    uinf.setUSnId(list.get(i).getVipSnId());
                    model.setCode(1);
                    model.setMsg("navConfig.jsp");
                    getSession().setAttribute("vip",list.get(i));
                    Map<String, UserClient> map = (Map) ActionUtil.getApplication().getAttribute("vips");
                    if (map == null) {
                        map = new HashMap<String, UserClient>();
                    } else {
                        UserClient client = map.get(list.get(i).getVipname());
                        if (client != null) {
                            map.remove(list.get(i).getVipname());
                        }
                    }
                    map.put(list.get(i).getVipname(), new UserClient(ActionUtil.getRequest().getRemoteAddr(), uinf));
                    ActionUtil.getApplication().setAttribute("vips", map);
                }
            }
        }
        return model;
    } 
    
    /**
     * 开始是否有另一台主机登陆当前账号
     * 
     * @return
     */
    
    public ServiceModel checkVip() {
        Map<String, UserClient> map = (Map) ActionUtil.getApplication().getAttribute("vips");
        // System.out.println(map);
        if (map != null && map.size() > 0) {
            Vip_user user = (Vip_user) ActionUtil.getSession().getAttribute(
                    "vip");
            if (user != null) {
                UserClient client = map.get(user.getVipname());
                if (client != null) {
                    if (!ActionUtil.getRequest().getRemoteAddr().equals(client.getIp())) {
                        model.setCode(1);
                        model.setMsg(getText("The landing on the account in another host, please log in again"));
                    }
                }
            } else {
                model.setCode(1);
                model.setMsg(getText("You are not logged in, please log in"));
            }
        } else {
            model.setCode(1);
            model.setMsg(getText("You are not logged in, please log in"));
        }
        return model;
    }
     
    public ServiceModel searchAll(){
        List list=dao.searchAll();
//        for (Object object : list) {
//            System.out.println(object);
//        }
        //System.out.println(list);
        if(list!=null && list.size()>0){
            model.setCode(1);
            model.setData(list);
        }
        //System.out.println(model);        
        return model;
    } 
    public static void main(String[] args) {
        Vip_userService vservice=new Vip_userService();
        //System.out.println(vservice.dao);
        Vip_user vuser=new Vip_user();
        vuser.setVipname("vip");
        vservice.serchByCondition(vuser);
    }
}