lxw
2021-02-20 f7345a0dcb8435b2d627f694d3d22b0dd75d5a22
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package com.fgkj.actions;
 
 
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.Cookie;
 
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.BaseDAOFactory;
import com.fgkj.db.DBUtil;
import com.fgkj.db.IDatabaseName;
import com.fgkj.dto.UserClient;
import com.fgkj.dto.User_inf;
import com.fgkj.dto.User_log;
import com.fgkj.services.ServiceModel;
import com.fgkj.services.User_infService;
import com.fgkj.services.User_logService;
import com.google.gson.reflect.TypeToken;
import com.opensymphony.xwork2.ActionSupport;
 
 
public class LoginAction extends ActionUtil{
    private String json;
    private String result;
    private String identify;
    private User_infService service=new User_infService();
    
    
    //获取sessionid
    public String  serchSessionID(){
        ServiceModel model=new ServiceModel();
        model.setMsg(ActionUtil.getSession().getId());
        model.setData((User_inf)ActionUtil.getUser());
        result=ActionUtil.tojson(model);    
        return SUCCESS;
    }
    //进度归0
    public String  clearProgress(){
        ServiceModel model=new ServiceModel();
        ActionUtil.getSession().setAttribute("percent",0);//导出文件先清空百分比
        //ActionUtil.getSession().setAttribute("createpercent",0);//导出文件先清空百分比
        model.setCode(1);
        model.setMsg("进度归0");
        result=ActionUtil.tojson(model);    
        return SUCCESS;
    }
    //获取导出文件的进度
    public String  serchFileProgress(){
        ServiceModel model=new ServiceModel();
        List list=new ArrayList();
        //list.add(ActionUtil.getSession().getAttribute("createpercent"));
        list.add(ActionUtil.getSession().getAttribute("percent"));
        model.setData(list);
        result=ActionUtil.tojson(model);    
        return SUCCESS;
    }
    //web版登录 
    public String login() {
        ServiceModel model=new ServiceModel();
        //System.out.println(ActionUtil.getSession().getAttribute("sssss")+"sessionid"+ActionUtil.getSession().getId());
        /*Map<String,String> map = ActionUtil.getGson().fromJson(ActionUtil.getSession().getAttribute("sssss").toString(), new TypeToken<HashMap<String, String>>(){}.getType());
        //String identify_session=String.valueOf(ActionUtil.getSession().getAttribute("sssss"));
        //System.out.println(identify_session+" "+identify);
        String identify_session = map.get("sssss");
        //System.out.println(identify_session.toLowerCase()+"   "+identify.toLowerCase() );
        if(!identify_session.toLowerCase().equals(identify.toLowerCase())){
            model.setCode(0);
            model.setMsg("验证码错误");
        }else{*/
            User_inf uinf=ActionUtil.getGson(ActionUtil.time_yyyyMMddHHmmss).fromJson(json, User_inf.class);
            if(uinf!=null&&uinf.getUName().equals("sys")) {
                model.setCode(0);
                model.setMsg(this.getText("用户名不可用"));
            }else {
                model=service.login(uinf);    
            }
            
            /*if(model.code == 1){
                User_inf u = (User_inf) ActionUtil.getUser();
                if(u!=null){    
                    recordUserlogin(u);            //记录当前用户的登录记录
                }
            }*/
        //}
        result=ActionUtil.tojson(model);    
        return SUCCESS;
    }
    
    
    
    /**
     * 判断是否有另一同一账号登陆的用户
     * @return
     */
    public String check(){
        ServiceModel model=service.checkUser();
        User_inf uinf=(User_inf)ActionUtil.getSession().getAttribute("user");        
        if(model.code == 1){
            ActionUtil.getSession().invalidate();        //清除当前的session;                //清除session
        }
        result=ActionUtil.tojson(model);
        return "success";
    }
    
    /**
     * 退出登录
     * @return
     */
    
    public String exitUser(){    
        //将当前用户从所有的登陆用户中移除
        Map<String, UserClient> map = (Map) ActionUtil.getApplication().getAttribute("users");
        if(map!=null && map.size()>0){
            User_inf user = (User_inf) ActionUtil.getSession().getAttribute("user");
            if(user!=null){
                //System.out.println(user);
                UserClient client = map.get(user.getUName());
                //System.out.println(client);
                if(client!=null){
                    map.remove(user.getUName());
                }
                User_logService logservice= new User_logService();
                User_log log = new User_log();
                log.setuId(user.getUId());
                log.setuOprateDay(new Date());
                log.setuOprateMsg("登出系统");
                log.setuOprateType(UserUtil.LOGOUT);
                log.setuTerminalIp(ActionUtil.getRequest().getLocalAddr());
                logservice.add(log);
            }
            ActionUtil.getSession().invalidate();        //清除session
        }
        
        return "success";
    }
    
    /**
     * 记录用户的登录记录
     * @param u
     */
    public void recordUserlogin(User_inf u){
        try {
            User_logService logservice= new User_logService();
            User_log log = new User_log();
            log.setuId(u.getUId());
            log.setuOprateDay(new Date());
            log.setuOprateMsg("登录PC系统");
            log.setuOprateType(UserUtil.LOGIN);
            log.setuTerminalIp(ActionUtil.getRequest().getRemoteAddr());
            logservice.add(log);
        } catch (Exception e) {
            System.out.println("记录用户的登录信息出错");
            e.printStackTrace();
        }
    }
    
    
    /**
     * 退出登录
     * @return
     */
    public String exitVUser(){
        ActionUtil.getSession().invalidate();
        return SUCCESS;
    }
    
    //通过制定的字符串获取session
    public String getSessionByString(){
        Object obj = ActionUtil.getSession().getAttribute(json);
        if(obj != null){
            result = ActionUtil.tojson(obj);
        }else{
            result = "";
        }
        return SUCCESS;
    }
    
    /**
     * 初始化数据库连接池
     * @return
     */
    public String initDBPool(){
        DBUtil.initPool();
        return SUCCESS;
    }
 
    public String getResult() {
        return result;
    }
 
   
    
    public void setIdentify(String identify) {
        this.identify = identify;
    }
 
 
 
    public void setJson(String json) {
        this.json = json;
    }
 
 
        
}